Setting tag linux-2.6-22-50
[linux-2.6.git] / linux-2.6-620-kdb.patch
1 diff -Nurp linux-2.6.22-590/arch/i386/Kconfig.debug linux-2.6.22-600/arch/i386/Kconfig.debug
2 --- linux-2.6.22-590/arch/i386/Kconfig.debug    2007-07-09 01:32:17.000000000 +0200
3 +++ linux-2.6.22-600/arch/i386/Kconfig.debug    2008-04-09 18:16:14.000000000 +0200
4 @@ -85,4 +85,82 @@ config DOUBLEFAULT
5            option saves about 4k and might cause you much additional grey
6            hair.
7  
8 +config KDB
9 +       bool "Built-in Kernel Debugger support"
10 +       depends on DEBUG_KERNEL
11 +       select KALLSYMS
12 +       select KALLSYMS_ALL
13 +       help
14 +         This option provides a built-in kernel debugger.  The built-in
15 +         kernel debugger contains commands which allow memory to be examined,
16 +         instructions to be disassembled and breakpoints to be set.  For details,
17 +         see Documentation/kdb/kdb.mm and the manual pages kdb_bt, kdb_ss, etc.
18 +         Kdb can also be used via the serial port.  Set up the system to
19 +         have a serial console (see Documentation/serial-console.txt).
20 +         The key sequence <escape>KDB on the serial port will cause the
21 +         kernel debugger to be entered with input from the serial port and
22 +         output to the serial console.  If unsure, say N.
23 +
24 +config KDB_MODULES
25 +       tristate "KDB modules"
26 +       depends on KDB
27 +       help
28 +         KDB can be extended by adding your own modules, in directory
29 +         kdb/modules.  This option selects the way that these modules should
30 +         be compiled, as free standing modules (select M) or built into the
31 +         kernel (select Y).  If unsure say M.
32 +
33 +config KDB_OFF
34 +       bool "KDB off by default"
35 +       depends on KDB
36 +       help
37 +         Normally kdb is activated by default, as long as CONFIG_KDB is set.
38 +         If you want to ship a kernel with kdb support but only have kdb
39 +         turned on when the user requests it then select this option.  When
40 +         compiled with CONFIG_KDB_OFF, kdb ignores all events unless you boot
41 +         with kdb=on or you echo "1" > /proc/sys/kernel/kdb.  This option also
42 +         works in reverse, if kdb is normally activated, you can boot with
43 +         kdb=off or echo "0" > /proc/sys/kernel/kdb to deactivate kdb. If
44 +         unsure, say N.
45 +
46 +config KDB_CONTINUE_CATASTROPHIC
47 +       int "KDB continues after catastrophic errors"
48 +       depends on KDB
49 +       default "0"
50 +       help
51 +         This integer controls the behaviour of kdb when the kernel gets a
52 +         catastrophic error, i.e. for a panic, oops, NMI or other watchdog
53 +         tripping.  CONFIG_KDB_CONTINUE_CATASTROPHIC interacts with
54 +         /proc/sys/kernel/kdb and CONFIG_LKCD_DUMP (if your kernel has the
55 +         LKCD patch).
56 +         When KDB is active (/proc/sys/kernel/kdb == 1) and a catastrophic
57 +         error occurs, nothing extra happens until you type 'go'.
58 +         CONFIG_KDB_CONTINUE_CATASTROPHIC == 0 (default).  The first time
59 +         you type 'go', kdb warns you.  The second time you type 'go', KDB
60 +         tries to continue - no guarantees that the kernel is still usable.
61 +         CONFIG_KDB_CONTINUE_CATASTROPHIC == 1.  KDB tries to continue - no
62 +         guarantees that the kernel is still usable.
63 +         CONFIG_KDB_CONTINUE_CATASTROPHIC == 2.  If your kernel has the LKCD
64 +         patch and LKCD is configured to take a dump then KDB forces a dump.
65 +         Whether or not a dump is taken, KDB forces a reboot.
66 +         When KDB is not active (/proc/sys/kernel/kdb == 0) and a catastrophic
67 +         error occurs, the following steps are automatic, no human
68 +         intervention is required.
69 +         CONFIG_KDB_CONTINUE_CATASTROPHIC == 0 (default) or 1.  KDB attempts
70 +         to continue - no guarantees that the kernel is still usable.
71 +         CONFIG_KDB_CONTINUE_CATASTROPHIC == 2.  If your kernel has the LKCD
72 +         patch and LKCD is configured to take a dump then KDB automatically
73 +         forces a dump.  Whether or not a dump is taken, KDB forces a
74 +         reboot.
75 +         If you are not sure, say 0.  Read Documentation/kdb/dump.txt before
76 +         setting to 2.
77 +
78 +config KDB_USB
79 +       bool "Support for USB Keyboard in KDB (OHCI only)"
80 +       depends on KDB && USB_OHCI_HCD
81 +       help
82 +         If you want to use kdb from a OHCI USB keyboard then say Y here.  If you
83 +         say N then kdb can only be used from a PC (AT) keyboard or a serial
84 +         console.
85 +
86  endmenu
87 diff -Nurp linux-2.6.22-590/arch/i386/kdb/ChangeLog linux-2.6.22-600/arch/i386/kdb/ChangeLog
88 --- linux-2.6.22-590/arch/i386/kdb/ChangeLog    1970-01-01 01:00:00.000000000 +0100
89 +++ linux-2.6.22-600/arch/i386/kdb/ChangeLog    2008-04-09 18:16:14.000000000 +0200
90 @@ -0,0 +1,805 @@
91 +2007-07-26 Keith Owens  <kaos@sgi.com>
92 +
93 +       * New x86 backtrace code.
94 +       * kdb v4.4-2.6.22-i386-2.
95 +
96 +2007-07-09 Keith Owens  <kaos@sgi.com>
97 +
98 +       * kdb v4.4-2.6.22-i386-1.
99 +
100 +2007-07-02 Keith Owens  <kaos@sgi.com>
101 +
102 +       * kdb v4.4-2.6.22-rc7-i386-1.
103 +
104 +2007-06-20 Keith Owens  <kaos@sgi.com>
105 +
106 +       * kdb v4.4-2.6.22-rc5-i386-1.
107 +
108 +2007-06-08 Keith Owens  <kaos@sgi.com>
109 +
110 +       * kdb v4.4-2.6.22-rc4-i386-1.
111 +
112 +2007-05-28 Keith Owens  <kaos@sgi.com>
113 +
114 +       * kdb v4.4-2.6.22-rc3-i386-1.
115 +
116 +2007-05-22 Keith Owens  <kaos@sgi.com>
117 +
118 +       * Register KDBENTER_VECTOR early on the boot cpu.
119 +       * kdb v4.4-2.6.22-rc2-i386-2.
120 +
121 +2007-05-22 Keith Owens  <kaos@sgi.com>
122 +
123 +       * kdb v4.4-2.6.22-rc2-i386-1.
124 +
125 +2007-05-22 Keith Owens  <kaos@sgi.com>
126 +
127 +       * kdb v4.4-2.6.22-rc1-i386-1.
128 +
129 +2007-05-17 Keith Owens  <kaos@sgi.com>
130 +
131 +       * Update dumpregs comments for rdmsr and wrmsr commands.
132 +         Bernardo Innocenti.
133 +       * kdb v4.4-2.6.21-i386-3.
134 +
135 +2007-05-15 Keith Owens  <kaos@sgi.com>
136 +
137 +       * Change kdba_late_init to kdba_arch_init so KDB_ENTER() can be used
138 +         earlier.
139 +       * kdb v4.4-2.6.21-i386-2.
140 +
141 +2007-04-29 Keith Owens  <kaos@sgi.com>
142 +
143 +       * kdb v4.4-2.6.21-i386-1.
144 +
145 +2007-04-16 Keith Owens  <kaos@sgi.com>
146 +
147 +       * kdb v4.4-2.6.21-rc7-i386-1.
148 +
149 +2007-04-10 Keith Owens  <kaos@sgi.com>
150 +
151 +       * kdb v4.4-2.6.21-rc6-i386-1.
152 +
153 +2007-04-02 Keith Owens  <kaos@sgi.com>
154 +
155 +       * kdb v4.4-2.6.21-rc5-i386-1.
156 +
157 +2007-03-19 Keith Owens  <kaos@sgi.com>
158 +
159 +       * kdb v4.4-2.6.21-rc4-i386-1.
160 +
161 +2007-03-14 Keith Owens  <kaos@sgi.com>
162 +
163 +       * kdb v4.4-2.6.21-rc3-i386-1.
164 +
165 +2007-03-14 Keith Owens  <kaos@sgi.com>
166 +
167 +       * kdb v4.4-2.6.21-rc2-i386-1.
168 +
169 +2007-03-01 Keith Owens  <kaos@sgi.com>
170 +
171 +       * kdb v4.4-2.6.21-rc1-i386-1.
172 +
173 +2007-03-01 Keith Owens  <kaos@sgi.com>
174 +
175 +       * Remove sparse warnings.
176 +       * kdb v4.4-2.6.20-i386-3.
177 +
178 +2007-02-16 Keith Owens  <kaos@sgi.com>
179 +
180 +       * Initialise variable bits of struct disassemble_info each time.
181 +       * kdb v4.4-2.6.20-i386-2.
182 +
183 +2007-02-06 Keith Owens  <kaos@sgi.com>
184 +
185 +       * kdb v4.4-2.6.20-i386-1.
186 +
187 +2007-02-01 Keith Owens  <kaos@sgi.com>
188 +
189 +       * kdb v4.4-2.6.20-rc7-i386-1.
190 +
191 +2007-01-08 Keith Owens  <kaos@sgi.com>
192 +
193 +       * kdb v4.4-2.6.20-rc4-i386-1.
194 +
195 +2007-01-02 Keith Owens  <kaos@sgi.com>
196 +
197 +       * kdb v4.4-2.6.20-rc3-i386-1.
198 +
199 +2006-12-20 Keith Owens  <kaos@sgi.com>
200 +
201 +       * kdb v4.4-2.6.20-rc1-i386-1.
202 +
203 +2006-11-30 Keith Owens  <kaos@sgi.com>
204 +
205 +       * kdb v4.4-2.6.19-i386-1.
206 +
207 +2006-11-27 Keith Owens  <kaos@sgi.com>
208 +
209 +       * Only use VT keyboard if the command line allows it and ACPI indicates
210 +         that there is an i8042.
211 +       * kdb v4.4-2.6.19-rc6-i386-2.
212 +
213 +2006-11-20 Keith Owens  <kaos@sgi.com>
214 +
215 +       * kdb v4.4-2.6.19-rc6-i386-1.
216 +
217 +2006-11-09 Keith Owens  <kaos@sgi.com>
218 +
219 +       * Change kdb() to fastcall.
220 +       * Add unwind info to kdb_call().  Steve Lord.
221 +       * Only use VT console if the command line allows it.
222 +       * kdb v4.4-2.6.19-rc5-i386-2.
223 +
224 +2006-11-08 Keith Owens  <kaos@sgi.com>
225 +
226 +       * kdb v4.4-2.6.19-rc5-i386-1.
227 +
228 +2006-11-01 Keith Owens  <kaos@sgi.com>
229 +
230 +       * kdb v4.4-2.6.19-rc4-i386-1.
231 +
232 +2006-10-24 Keith Owens  <kaos@sgi.com>
233 +
234 +       * kdb v4.4-2.6.19-rc3-i386-1.
235 +
236 +2006-10-24 Keith Owens  <kaos@sgi.com>
237 +
238 +       * Remove redundant regs and envp parameters.
239 +       * kdb v4.4-2.6.19-rc2-i386-2.
240 +
241 +2006-10-18 Keith Owens  <kaos@sgi.com>
242 +
243 +       * kdb v4.4-2.6.19-rc2-i386-1.
244 +
245 +2006-10-11 Keith Owens  <kaos@sgi.com>
246 +
247 +       * Move kdbm_x86.c from the i386 to the common KDB patch.
248 +       * Make the KDBENTER_VECTOR an interrupt gate instead of a trap gate, it
249 +         simplifies the code and disables interrupts on KDBENTER().
250 +       * Exclude the KDBENTER_VECTOR from irq assignment.
251 +       * kdb v4.4-2.6.19-rc1-i386-2.
252 +
253 +2006-10-09 Keith Owens  <kaos@sgi.com>
254 +
255 +       * kdb v4.4-2.6.19-rc1-i386-1.
256 +
257 +2006-10-06 Keith Owens  <kaos@sgi.com>
258 +
259 +       * Remove #include <linux/config.h>
260 +       * kdb v4.4-2.6.18-i386-2.
261 +
262 +2006-09-20 Keith Owens  <kaos@sgi.com>
263 +
264 +       * kdb v4.4-2.6.18-i386-1.
265 +
266 +2006-09-15 Keith Owens  <kaos@sgi.com>
267 +
268 +       * kdb v4.4-2.6.18-rc7-i386-1.
269 +
270 +2006-08-30 Keith Owens  <kaos@sgi.com>
271 +
272 +       * Add warning for problems when following alternate stacks.
273 +       * kdb v4.4-2.6.18-rc5-i386-3.
274 +
275 +2006-08-29 Keith Owens  <kaos@sgi.com>
276 +
277 +       * Rewrite all backtrace code.
278 +       * kdb v4.4-2.6.18-rc5-i386-2.
279 +
280 +2006-08-28 Keith Owens  <kaos@sgi.com>
281 +
282 +       * kdb v4.4-2.6.18-rc5-i386-1.
283 +
284 +2006-08-08 Keith Owens  <kaos@sgi.com>
285 +
286 +       * kdb v4.4-2.6.18-rc4-i386-1.
287 +
288 +2006-08-04 Keith Owens  <kaos@sgi.com>
289 +
290 +       * kdb v4.4-2.6.18-rc3-i386-1.
291 +
292 +2006-07-18 Keith Owens  <kaos@sgi.com>
293 +
294 +       * kdb v4.4-2.6.18-rc2-i386-1.
295 +
296 +2006-07-12 Keith Owens  <kaos@sgi.com>
297 +
298 +       * Remove dead KDB_REASON codes.
299 +       * sparse cleanups.
300 +       * kdb v4.4-2.6.18-rc1-i386-2.
301 +
302 +2006-07-07 Keith Owens  <kaos@sgi.com>
303 +
304 +       * kdb v4.4-2.6.18-rc1-i386-1.
305 +
306 +2006-07-04 Keith Owens  <kaos@sgi.com>
307 +
308 +       * Make KDB rendezvous on i386 a two stage approach.
309 +       * Clean up generation of KDB interrupt code.
310 +       * Move smp_kdb_stop() and smp_kdb_interrupt() to kdbasupport.c.
311 +       * Move setting of interrupt traps to kdbasupport.c.
312 +       * Remove KDB hooks from arch/i386/kernel smp.c, smpboot.c, i8259.c,
313 +         io_apic.c.
314 +       * Add KDB_REASON_CPU_UP support.
315 +       * Move per cpu setup to kdba_cpu_up().
316 +       * Rework support for 4K stacks to make backtrace more accurate.
317 +       * Add BTSP option to get the full backtrace, including kdb routines.
318 +       * Delete kdba_enable_mce, architectures now do their own setup.
319 +       * Delete kdba_enable_lbr, kdba_disable_lbr, kdba_print_lbr,
320 +         page_fault_mca.  Only ever implemented on x86, difficult to maintain
321 +         and rarely used in the field.
322 +       * Replace #ifdef KDB_HAVE_LONGJMP with #ifdef kdba_setjmp.
323 +       * kdb v4.4-2.6.17-i386-2.
324 +
325 +2006-06-19 Keith Owens  <kaos@sgi.com>
326 +
327 +       * kdb v4.4-2.6.17-i386-1.
328 +
329 +2006-05-25 Keith Owens  <kaos@sgi.com>
330 +
331 +       * kdb v4.4-2.6.17-rc5-i386-1.
332 +
333 +2006-05-15 Keith Owens  <kaos@sgi.com>
334 +
335 +       * Refresh bfd related files from binutils 2.16.91.0.2.
336 +       * kdb v4.4-2.6.17-rc4-i386-2.
337 +
338 +2006-05-12 Keith Owens  <kaos@sgi.com>
339 +
340 +       * kdb v4.4-2.6.17-rc4-i386-1.
341 +
342 +2006-04-28 Keith Owens  <kaos@sgi.com>
343 +
344 +       * kdb v4.4-2.6.17-rc3-i386-1.
345 +
346 +2006-04-22 Keith Owens  <kaos@sgi.com>
347 +
348 +       * kdb v4.4-2.6.17-rc2-i386-1.
349 +
350 +2006-04-11 Keith Owens  <kaos@sgi.com>
351 +
352 +       * kdb v4.4-2.6.17-rc1-i386-1.
353 +
354 +2006-03-30 Keith Owens  <kaos@sgi.com>
355 +
356 +       * Change CONFIG_LKCD to CONFIG_LKCD_DUMP.
357 +       * kdb v4.4-2.6.16-i386-3.
358 +
359 +2006-03-24 Keith Owens  <kaos@sgi.com>
360 +
361 +       * Define a dummy kdba_wait_for_cpus().
362 +       * kdb v4.4-2.6.16-i386-2.
363 +
364 +2006-03-21 Keith Owens  <kaos@sgi.com>
365 +
366 +       * kdb v4.4-2.6.16-i386-1.
367 +
368 +2006-03-14 Nathan Scott  <nathans@sgi.com>
369 +
370 +       * kdb v4.4-2.6.16-rc6-i386-1.
371 +
372 +2006-02-28 Nathan Scott  <nathans@sgi.com>
373 +
374 +       * kdb v4.4-2.6.16-rc5-i386-1.
375 +
376 +2006-02-20 Nathan Scott  <nathans@sgi.com>
377 +
378 +       * kdb v4.4-2.6.16-rc4-i386-1.
379 +
380 +2006-02-06 Keith Owens  <kaos@sgi.com>
381 +
382 +       * Change CONFIG_CRASH_DUMP to CONFIG_LKCD.
383 +       * kdb v4.4-2.6.16-rc2-i386-2.
384 +
385 +2006-02-06 Keith Owens  <kaos@sgi.com>
386 +
387 +       * kdb v4.4-2.6.16-rc2-i386-1.
388 +
389 +2006-01-18 Keith Owens  <kaos@sgi.com>
390 +
391 +       * kdb v4.4-2.6.16-rc1-i386-1.
392 +
393 +2006-01-08 Keith Owens  <kaos@sgi.com>
394 +
395 +       * Add DIE_KDEBUG_ENTER and DIE_KDEBUG_LEAVE to notify_die.
396 +       * kdb v4.4-2.6.15-i386-2.
397 +
398 +2006-01-04 Keith Owens  <kaos@sgi.com>
399 +
400 +       * Remove some inlines and the last vestige of CONFIG_NUMA_REPLICATE.
401 +       * Read the keyboard acknowledgment after sending a character.  SuSE
402 +         Bugzilla 60240.
403 +       * kdb v4.4-2.6.15-i386-1.
404 +
405 +2005-12-25 Keith Owens  <kaos@sgi.com>
406 +
407 +       * kdb v4.4-2.6.15-rc7-i386-1.
408 +
409 +2005-12-20 Keith Owens  <kaos@sgi.com>
410 +
411 +       * kdb v4.4-2.6.15-rc6-i386-1.
412 +
413 +2005-12-05 Keith Owens  <kaos@sgi.com>
414 +
415 +       * kdb v4.4-2.6.15-rc5-i386-1.
416 +
417 +2005-12-02 Keith Owens  <kaos@sgi.com>
418 +
419 +       * kdb v4.4-2.6.15-rc4-i386-1.
420 +
421 +2005-11-30 Keith Owens  <kaos@sgi.com>
422 +
423 +       * kdb v4.4-2.6.15-rc3-i386-1.
424 +
425 +2005-11-21 Keith Owens  <kaos@sgi.com>
426 +
427 +       * kdb v4.4-2.6.15-rc2-i386-1.
428 +
429 +2005-11-15 Keith Owens  <kaos@sgi.com>
430 +
431 +       * kdb v4.4-2.6.15-rc1-i386-1.
432 +
433 +2005-10-28 Keith Owens  <kaos@sgi.com>
434 +
435 +       * kdb v4.4-2.6.14-i386-1.
436 +
437 +2005-10-21 Keith Owens  <kaos@sgi.com>
438 +
439 +       * kdb v4.4-2.6.14-rc5-i386-1.
440 +
441 +2005-10-11 Keith Owens  <kaos@sgi.com>
442 +
443 +       * kdb v4.4-2.6.14-rc4-i386-1.
444 +
445 +2005-10-04 Keith Owens  <kaos@sgi.com>
446 +
447 +       * kdb v4.4-2.6.14-rc3-i386-1.
448 +
449 +2005-09-21 Keith Owens  <kaos@sgi.com>
450 +
451 +       * Support kdb_current_task in register display and modify commands.
452 +       * kdb v4.4-2.6.14-rc2-i386-1.
453 +
454 +2005-09-20 Keith Owens  <kaos@sgi.com>
455 +
456 +       * Remove use of __STDC_VERSION__ in ansidecl.h.
457 +       * kdb v4.4-2.6.14-rc1-i386-1.
458 +
459 +2005-08-29 Keith Owens  <kaos@sgi.com>
460 +
461 +       * kdb v4.4-2.6.13-i386-1.
462 +
463 +2005-08-24 Keith Owens  <kaos@sgi.com>
464 +
465 +       * kdb v4.4-2.6.13-rc7-i386-1.
466 +
467 +2005-08-08 Keith Owens  <kaos@sgi.com>
468 +
469 +       * kdb v4.4-2.6.13-rc6-i386-1.
470 +
471 +2005-08-02 Keith Owens  <kaos@sgi.com>
472 +
473 +       * kdb v4.4-2.6.13-rc5-i386-1.
474 +
475 +2005-07-30 Keith Owens  <kaos@sgi.com>
476 +
477 +       * kdb v4.4-2.6.13-rc4-i386-1.
478 +
479 +2005-07-22 Keith Owens  <kaos@sgi.com>
480 +
481 +       * Compile fix for kprobes.
482 +       * kdb v4.4-2.6.13-rc3-i386-2.
483 +
484 +2005-07-19 Keith Owens  <kaos@sgi.com>
485 +
486 +       * Add support for USB keyboard (OHCI only).  Aaron Young, SGI.
487 +       * kdb v4.4-2.6.13-rc3-i386-1.
488 +
489 +2005-07-08 Keith Owens  <kaos@sgi.com>
490 +
491 +       * kdb v4.4-2.6.13-rc2-i386-1.
492 +
493 +2005-07-01 Keith Owens  <kaos@sgi.com>
494 +
495 +       * kdb v4.4-2.6.13-rc1-i386-1.
496 +
497 +2005-06-19 Keith Owens  <kaos@sgi.com>
498 +
499 +       * gcc 4 compile fix, remove extern kdb_hardbreaks.  Steve Lord.
500 +       * kdb v4.4-2.6.12-i386-2.
501 +
502 +2005-06-18 Keith Owens  <kaos@sgi.com>
503 +
504 +       * kdb v4.4-2.6.12-i386-1.
505 +
506 +2005-06-08 Keith Owens  <kaos@sgi.com>
507 +
508 +       * kdb v4.4-2.6.12-rc6-i386-1.
509 +
510 +2005-05-25 Keith Owens  <kaos@sgi.com>
511 +
512 +       * kdb v4.4-2.6.12-rc5-i386-1.
513 +
514 +2005-05-08 Keith Owens  <kaos@sgi.com>
515 +
516 +       * kdb v4.4-2.6.12-rc4-i386-1.
517 +
518 +2005-04-21 Keith Owens  <kaos@sgi.com>
519 +
520 +       * kdb v4.4-2.6.12-rc3-i386-1.
521 +
522 +2005-04-06 Keith Owens  <kaos@sgi.com>
523 +
524 +       * kdb v4.4-2.6.12-rc2-i386-1.
525 +
526 +2005-03-29 Keith Owens  <kaos@sgi.com>
527 +
528 +       * Replace __copy_to_user with __copy_to_user_inatomic.
529 +       * kdb v4.4-2.6.12-rc1-i386-1.
530 +
531 +2005-03-08 Keith Owens  <kaos@sgi.com>
532 +
533 +       * Coexistence patches for lkcd.
534 +       * kdb v4.4-2.6.11-i386-2.
535 +
536 +2005-03-03 Keith Owens  <kaos@sgi.com>
537 +
538 +       * kdb v4.4-2.6.11-i386-1.
539 +
540 +2005-02-14 Keith Owens  <kaos@sgi.com>
541 +
542 +       * kdb v4.4-2.6.11-rc4-i386-1.
543 +
544 +2005-02-08 Keith Owens  <kaos@sgi.com>
545 +
546 +       * kdb v4.4-2.6.11-rc3-bk4-i386-1.
547 +
548 +2005-02-03 Keith Owens  <kaos@sgi.com>
549 +
550 +       * kdb v4.4-2.6.11-rc3-i386-1.
551 +
552 +2005-01-27 Keith Owens  <kaos@sgi.com>
553 +
554 +       * kdb v4.4-2.6.11-rc2-i386-1.
555 +
556 +2005-01-12 Keith Owens  <kaos@sgi.com>
557 +
558 +       * kdb v4.4-2.6.11-rc1-i386-1.
559 +
560 +2004-12-25 Keith Owens  <kaos@sgi.com>
561 +
562 +       * kdb v4.4-2.6.10-i386-1.
563 +
564 +2004-12-07 Keith Owens  <kaos@sgi.com>
565 +
566 +       * kdb v4.4-2.6.10-rc3-i386-1.
567 +
568 +2004-11-23 Keith Owens  <kaos@sgi.com>
569 +
570 +       * Coexist with asmlinkage/fastcall changes.
571 +       * kdb v4.4-2.6.10-rc2-i386-1.
572 +
573 +2004-10-29 Keith Owens  <kaos@sgi.com>
574 +
575 +       * Handle change defintions for hard and soft irq context.
576 +       * Make stack switch in kdb backtrace look more like the oops output.
577 +       * kdb v4.4-2.6.10-rc1-i386-1.
578 +
579 +2004-10-19 Keith Owens  <kaos@sgi.com>
580 +
581 +       * kdb v4.4-2.6.9-i386-1.
582 +
583 +2004-10-12 Keith Owens  <kaos@sgi.com>
584 +
585 +       * kdb v4.4-2.6.9-rc4-i386-1.
586 +
587 +2004-10-01 Keith Owens  <kaos@sgi.com>
588 +
589 +       * kdb v4.4-2.6.9-rc3-i386-1.
590 +
591 +2004-09-30 Keith Owens  <kaos@sgi.com>
592 +
593 +       * Add stackdepth command.
594 +       * Handle backtrace with separate soft and hard irq stacks
595 +         (CONFIG_4KSTACKS).
596 +       * Work around RESTORE_ALL macro, which can only be used once.
597 +       * Export kdba_dumpregs.  Bryan Cardillo, UPenn.
598 +       * kdb v4.4-2.6.9-rc2-i386-2.
599 +
600 +2004-09-14 Keith Owens  <kaos@sgi.com>
601 +
602 +       * kdb v4.4-2.6.9-rc2-i386-1.
603 +
604 +2004-08-27 Keith Owens  <kaos@sgi.com>
605 +
606 +       * kdb v4.4-2.6.9-rc1-i386-1.
607 +
608 +2004-08-14 Keith Owens  <kaos@sgi.com>
609 +
610 +       * kdb v4.4-2.6.8-i386-1.
611 +
612 +2004-08-12 Keith Owens  <kaos@sgi.com>
613 +
614 +       * kdb v4.4-2.6.8-rc4-i386-1.
615 +
616 +2004-08-04 Keith Owens  <kaos@sgi.com>
617 +
618 +       * kdb v4.4-2.6.8-rc3-i386-1.
619 +
620 +2004-07-18 Keith Owens  <kaos@sgi.com>
621 +
622 +       * kdb v4.4-2.6.8-rc2-i386-1.
623 +
624 +2004-07-12 Keith Owens  <kaos@sgi.com>
625 +
626 +       * kdb v4.4-2.6.8-rc1-i386-1.
627 +
628 +2004-06-16 Keith Owens  <kaos@sgi.com>
629 +
630 +       * kdb v4.4-2.6.7-i386-1.
631 +
632 +2004-06-10 Keith Owens  <kaos@sgi.com>
633 +
634 +       * kdb v4.4-2.6.7-rc3-i386-1.
635 +
636 +2004-06-09 Keith Owens  <kaos@sgi.com>
637 +
638 +       * Namespace clean up.  Mark code/variables as static when it is only
639 +         used in one file, delete dead code/variables.
640 +       * kdb v4.4-2.6.7-rc2-i386-3.
641 +
642 +2004-06-08 Keith Owens  <kaos@sgi.com>
643 +
644 +       * Whitespace clean up, no code changes.
645 +       * kdb v4.4-2.6.7-rc2-i386-2.
646 +
647 +2004-06-07 Keith Owens  <kaos@sgi.com>
648 +
649 +       * Force KALLSYMS and KALLSYMS_ALL for CONFIG_KDB.
650 +       * kdb v4.4-2.6.7-rc2-i386-1.
651 +
652 +2004-06-06 Keith Owens  <kaos@sgi.com>
653 +
654 +       * Correct Kconfig help text.
655 +       * Coexist with CONFIG_REGPARM.
656 +       * Add standard archkdb commands.
657 +       * Move kdb_{get,put}userarea_size definitions to linux/kdb.h.
658 +       * kdb v4.4-2.6.6-i386-2.
659 +
660 +2004-05-23 Keith Owens  <kaos@sgi.com>
661 +
662 +       * Move bfd.h and ansidecl.h from arch/$(ARCH)/kdb to include/asm-$(ARCH).
663 +       * Update copyright notices.
664 +       * kdb v4.4-2.6.6-i386-1.
665 +
666 +2004-05-10 Keith Owens  <kaos@sgi.com>
667 +
668 +       * kdb v4.3-2.6.6-i386-1.
669 +
670 +2004-05-06 Keith Owens  <kaos@sgi.com>
671 +
672 +       * kdb v4.3-2.6.6-rc3-i386-1.
673 +
674 +2004-05-06 Keith Owens  <kaos@sgi.com>
675 +
676 +       * kdb v4.3-2.6.6-rc2-i386-1.
677 +
678 +2004-04-30 Keith Owens  <kaos@sgi.com>
679 +
680 +       * kdb v4.3-2.6.6-rc1-i386-1.
681 +
682 +2004-04-05 Keith Owens  <kaos@sgi.com>
683 +
684 +       * kdb v4.3-2.6-5-i386-1.
685 +
686 +2004-02-29 Keith Owens  <kaos@sgi.com>
687 +
688 +       * kdb v4.3-2.6-4-rc1-i386-1.
689 +
690 +2004-02-18 Keith Owens  <kaos@sgi.com>
691 +
692 +       * kdb v4.3-2.6-3-i386-1.
693 +
694 +2004-02-17 Keith Owens  <kaos@sgi.com>
695 +
696 +       * Pick up changes from Jim Houston for 2.6.
697 +       * Sync with kdb v4.3-2.4.25-rc1-i386-1.
698 +       * Adjust for LDT changes in i386 mainline.
699 +       * Convert longjmp buffers from static to dynamic allocation, for large
700 +         cpu counts.
701 +       * Do not use USB keyboard if it has not been probed.
702 +       * Do not print section data, 2.6 kallsyms does not support sections :(.
703 +       * kdb v4.3-2.6-3-rc3-i386-1.
704 +
705 +2003-08-29 Keith Owens  <kaos@sgi.com>
706 +
707 +       * kdb v4.3-2.4.22-i386-1.
708 +
709 +2003-08-05 Keith Owens  <kaos@sgi.com>
710 +
711 +       * Remove duplicate setting of trap for machine_check.
712 +       * Only reset keyboard when CONFIG_VT_CONSOLE is defined.
713 +
714 +2003-07-27 Keith Owens  <kaos@sgi.com>
715 +
716 +       * kdb v4.3-2.4.22-pre8-i386-5.
717 +
718 +2003-07-20 Keith Owens  <kaos@sgi.com>
719 +
720 +       * Remove compile warning on x86 commands.
721 +       * kdb v4.3-2.4.21-i386-5.
722 +
723 +2003-07-08 Keith Owens  <kaos@sgi.com>
724 +
725 +       * Add new x86 commands - rdv, gdt, idt, ldt, ldtp, ptex.
726 +         Vamsi Krishna S., IBM.
727 +       * kdb v4.3-2.4.21-i386-4.
728 +
729 +2003-07-01 Keith Owens  <kaos@sgi.com>
730 +
731 +       * Convert kdba_find_return() to two passes to reduce false positives.
732 +       * Correct jmp disp8 offset calculation for out of line lock code.
733 +       * Use NMI for kdb IPI in clustered APIC mode.  Sachin Sant, IBM.
734 +       * kdb v4.3-2.4.21-i386-3.
735 +
736 +2003-06-23 Keith Owens  <kaos@sgi.com>
737 +
738 +       * Sync with XFS 2.4.21 tree.
739 +       * kdb v4.3-2.4.21-i386-2.
740 +
741 +2003-06-20 Keith Owens  <kaos@sgi.com>
742 +
743 +       * kdb v4.3-2.4.21-i386-1.
744 +
745 +2003-06-20 Keith Owens  <kaos@sgi.com>
746 +
747 +       * Add CONFIG_KDB_CONTINUE_CATASTROPHIC.
748 +       * Correct KDB_ENTER() definition.
749 +       * kdb v4.3-2.4.20-i386-1.
750 +
751 +2003-05-02 Keith Owens  <kaos@sgi.com>
752 +
753 +       * Add kdba_fp_value().
754 +       * Limit backtrace size to catch loops.
755 +       * Add read/write access to user pages.  Vamsi Krishna S., IBM
756 +       * Clean up USB keyboard support.  Steven Dake.
757 +       * kdb v4.2-2.4.20-i386-1.
758 +
759 +2003-04-04 Keith Owens  <kaos@sgi.com>
760 +
761 +       * Workarounds for scheduler bugs.
762 +       * kdb v4.1-2.4.20-i386-1.
763 +
764 +2003-03-16 Keith Owens  <kaos@sgi.com>
765 +
766 +       * Each cpu saves its state as it enters kdb or before it enters code
767 +         which cannot call kdb, converting kdb from a pull to a push model.
768 +       * Clean up kdb interaction with CONFIG_SERIAL_CONSOLE.
769 +       * Removal of special cases for i386 backtrace from common code
770 +         simplifies the architecture code.
771 +       * Add command to dump i386 struct pt_regs.
772 +       * kdb v4.0-2.4.20-i386-1.
773 +
774 +2003-02-03 Keith Owens  <kaos@sgi.com>
775 +
776 +       * Register kdb commands early.
777 +       * Handle KDB_ENTER() when kdb=off.
778 +       * Optimize __kdba_getarea_size when width is a constant.
779 +       * Decode oops via kallsyms if it is available.
780 +       * Update copyright notices to 2003.
781 +       * Handle call *disp32(%reg) in backtrace.
782 +       * Correct keyboard freeze.  Ashish Kalra.
783 +       * Add command history and editing.  Sonic Zhang.
784 +       * kdb_toggleled is conditional on KDB_BLINK_LED.  Bernhard Fischer.
785 +       * Allow tab on serial line for symbol completion.
786 +       * Ignore KDB_ENTER() when kdb is already running.
787 +       * kdb v3.0-2.4.20-i386-1.
788 +
789 +2002-11-29 Keith Owens  <kaos@sgi.com>
790 +
791 +       * Upgrade to 2.4.20.
792 +       * kdb v2.5-2.4.20-i386-1.
793 +
794 +2002-11-14 Keith Owens  <kaos@sgi.com>
795 +
796 +       * Upgrade to 2.4.20-rc1.
797 +       * kdb v2.5-2.4.20-rc1-i386-1.
798 +
799 +2002-11-14 Keith Owens  <kaos@sgi.com>
800 +
801 +       * General clean up of handling for breakpoints and single stepping over
802 +         software breakpoints.
803 +       * Accept ff 1x as well as ff dx for call *(%reg) in backtrace.
804 +       * kdb v2.5-2.4.19-i386-1.
805 +
806 +2002-11-01 Keith Owens  <kaos@sgi.com>
807 +
808 +       * Prevent SMP IRQ overwriting KDB_ENTER().
809 +       * kdb v2.4-2.4.19-i386-2.
810 +
811 +2002-10-31 Keith Owens  <kaos@sgi.com>
812 +
813 +       * Avoid KDB_VECTOR conflict with DUMP_VECTOR.
814 +       * Remove kdb_eframe_t.
815 +       * Sanity check if we have pt_regs.
816 +       * Remove kdba_getcurrentframe().
817 +       * Reinstate missing nmi_watchdog/kdb hook.
818 +       * kdb v2.4-2.4.19-i386-1.
819 +
820 +2002-10-17 Keith Owens  <kaos@sgi.com>
821 +
822 +       * Correct compile with CONFIG_VT_CONSOLE=n.
823 +       * kdb v2.3-2.4.19-i386-5.
824 +
825 +2002-10-04 Keith Owens  <kaos@sgi.com>
826 +
827 +       * Add USB keyboard option.
828 +       * Minimize differences between patches for 2.4 and 2.5 kernels.
829 +       * kdb v2.3-2.4.19-i386-4.
830 +
831 +2002-08-10 Keith Owens  <kaos@sgi.com>
832 +
833 +       * Replace kdb_port with kdb_serial to support memory mapped I/O.
834 +         Note: This needs kdb v2.3-2.4.19-common-2 or later.
835 +       * kdb v2.3-2.4.19-i386-3.
836 +
837 +2002-08-09 Keith Owens  <kaos@sgi.com>
838 +
839 +       * Use -fno-optimize-sibling-calls for kdb if gcc supports it.
840 +       * .text.lock does not consume an activation frame.
841 +       * kdb v2.3-2.4.19-i386-2.
842 +
843 +2002-08-07 Keith Owens  <kaos@sgi.com>
844 +
845 +       * Upgrade to 2.4.19.
846 +       * Remove individual SGI copyrights, the general SGI copyright applies.
847 +       * New .text.lock name.  Hugh Dickins.
848 +       * Set KERNEL_CS in kdba_getcurrentframe.  Hugh Dickins.
849 +       * Clean up disassembly layout.  Hugh Dickins, Keith Owens.
850 +       * Replace hard coded stack size with THREAD_SIZE.  Hugh Dickins.
851 +       * Better stack layout on bt with no frame pointers.  Hugh Dickins.
852 +       * Make i386 IO breakpoints (bpha <address> IO) work again.
853 +         Martin Wilck, Keith Owens.
854 +       * Remove fixed KDB_MAX_COMMANDS size.
855 +       * Add set_fs() around __copy_to_user on kernel addresses.
856 +         Randolph Chung.
857 +       * Position i386 for CONFIG_NUMA_REPLICATE.
858 +       * kdb v2.3-2.4.19-i386-1.
859 +
860 +2002-07-09 Keith Owens  <kaos@sgi.com>
861 +
862 +       * Upgrade to 2.4.19-rc1.
863 +
864 +2002-06-14 Keith Owens  <kaos@sgi.com>
865 +
866 +       * Upgrade to 2.4.19-pre10.
867 +       * kdb v2.1-2.4.19-pre10-i386-1.
868 +
869 +2002-04-09 Keith Owens  <kaos@sgi.com>
870 +
871 +       * Upgrade to 2.4.19-pre6.
872 +       * kdb v2.1-2.4.19-pre6-i386-1.
873 +
874 +2002-02-26 Keith Owens  <kaos@sgi.com>
875 +
876 +       * Upgrade to 2.4.18.
877 +       * kdb v2.1-2.4.18-i386-1.
878 +
879 +2002-01-18 Keith Owens  <kaos@sgi.com>
880 +
881 +       * Use new kdb_get/put functions.
882 +       * Define kdba_{get,put}area_size functions for i386.
883 +       * Remove over-engineered dblist callback functions.
884 +       * Correctly handle failing call disp32 in backtrace.
885 +       * Remove bp_instvalid flag, redundant code.
886 +       * Remove dead code.
887 +       * kdb v2.1-2.4.17-i386-1.
888 +
889 +2002-01-04 Keith Owens  <kaos@sgi.com>
890 +
891 +       * Sync xfs <-> kdb i386 code.
892 +
893 +2001-12-22 Keith Owens  <kaos@sgi.com>
894 +
895 +       * Split kdb for i386 as kdb v2.0-2.4.17-i386-1.
896 diff -Nurp linux-2.6.22-590/arch/i386/kdb/i386-dis.c linux-2.6.22-600/arch/i386/kdb/i386-dis.c
897 --- linux-2.6.22-590/arch/i386/kdb/i386-dis.c   1970-01-01 01:00:00.000000000 +0100
898 +++ linux-2.6.22-600/arch/i386/kdb/i386-dis.c   2008-04-09 18:16:14.000000000 +0200
899 @@ -0,0 +1,4686 @@
900 +/* Print i386 instructions for GDB, the GNU debugger.
901 +   Copyright 1988, 1989, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
902 +   2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
903 +
904 +   This file is part of GDB.
905 +
906 +   This program is free software; you can redistribute it and/or modify
907 +   it under the terms of the GNU General Public License as published by
908 +   the Free Software Foundation; either version 2 of the License, or
909 +   (at your option) any later version.
910 +
911 +   This program is distributed in the hope that it will be useful,
912 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
913 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
914 +   GNU General Public License for more details.
915 +
916 +   You should have received a copy of the GNU General Public License
917 +   along with this program; if not, write to the Free Software
918 +   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
919 +
920 +/* Extracted from binutils 2.16.91.0.2 (OpenSUSE 10.0) and modified for kdb use.
921 + * Any trailing whitespace was removed and #ifdef/ifndef __KERNEL__ added as
922 + * required.
923 + * Keith Owens <kaos@sgi.com> 15 May 2006
924 + */
925 +
926 +/* 80386 instruction printer by Pace Willisson (pace@prep.ai.mit.edu)
927 +   July 1988
928 +    modified by John Hassey (hassey@dg-rtp.dg.com)
929 +    x86-64 support added by Jan Hubicka (jh@suse.cz)
930 +    VIA PadLock support by Michal Ludvig (mludvig@suse.cz).  */
931 +
932 +/* The main tables describing the instructions is essentially a copy
933 +   of the "Opcode Map" chapter (Appendix A) of the Intel 80386
934 +   Programmers Manual.  Usually, there is a capital letter, followed
935 +   by a small letter.  The capital letter tell the addressing mode,
936 +   and the small letter tells about the operand size.  Refer to
937 +   the Intel manual for details.  */
938 +
939 +#ifdef __KERNEL__
940 +#include <linux/kernel.h>
941 +#include <linux/string.h>
942 +#include <linux/dis-asm.h>
943 +#include <linux/kdb.h>
944 +#define abort() BUG()
945 +#else  /* __KERNEL__ */
946 +#include "dis-asm.h"
947 +#include "sysdep.h"
948 +#include "opintl.h"
949 +#endif /* __KERNEL__ */
950 +
951 +#define MAXLEN 20
952 +
953 +#ifndef __KERNEL__
954 +#include <setjmp.h>
955 +#endif /* __KERNEL__ */
956 +
957 +#ifndef UNIXWARE_COMPAT
958 +/* Set non-zero for broken, compatible instructions.  Set to zero for
959 +   non-broken opcodes.  */
960 +#define UNIXWARE_COMPAT 1
961 +#endif
962 +
963 +static int fetch_data (struct disassemble_info *, bfd_byte *);
964 +static void ckprefix (void);
965 +static const char *prefix_name (int, int);
966 +static int print_insn (bfd_vma, disassemble_info *);
967 +static void dofloat (int);
968 +static void OP_ST (int, int);
969 +static void OP_STi (int, int);
970 +static int putop (const char *, int);
971 +static void oappend (const char *);
972 +static void append_seg (void);
973 +static void OP_indirE (int, int);
974 +static void print_operand_value (char *, int, bfd_vma);
975 +static void OP_E (int, int);
976 +static void OP_G (int, int);
977 +static bfd_vma get64 (void);
978 +static bfd_signed_vma get32 (void);
979 +static bfd_signed_vma get32s (void);
980 +static int get16 (void);
981 +static void set_op (bfd_vma, int);
982 +static void OP_REG (int, int);
983 +static void OP_IMREG (int, int);
984 +static void OP_I (int, int);
985 +static void OP_I64 (int, int);
986 +static void OP_sI (int, int);
987 +static void OP_J (int, int);
988 +static void OP_SEG (int, int);
989 +static void OP_DIR (int, int);
990 +static void OP_OFF (int, int);
991 +static void OP_OFF64 (int, int);
992 +static void ptr_reg (int, int);
993 +static void OP_ESreg (int, int);
994 +static void OP_DSreg (int, int);
995 +static void OP_C (int, int);
996 +static void OP_D (int, int);
997 +static void OP_T (int, int);
998 +static void OP_Rd (int, int);
999 +static void OP_MMX (int, int);
1000 +static void OP_XMM (int, int);
1001 +static void OP_EM (int, int);
1002 +static void OP_EX (int, int);
1003 +static void OP_MS (int, int);
1004 +static void OP_XS (int, int);
1005 +static void OP_M (int, int);
1006 +static void OP_VMX (int, int);
1007 +static void OP_0fae (int, int);
1008 +static void OP_0f07 (int, int);
1009 +static void NOP_Fixup (int, int);
1010 +static void OP_3DNowSuffix (int, int);
1011 +static void OP_SIMD_Suffix (int, int);
1012 +static void SIMD_Fixup (int, int);
1013 +static void PNI_Fixup (int, int);
1014 +static void SVME_Fixup (int, int);
1015 +static void INVLPG_Fixup (int, int);
1016 +static void BadOp (void);
1017 +static void SEG_Fixup (int, int);
1018 +static void VMX_Fixup (int, int);
1019 +
1020 +struct dis_private {
1021 +  /* Points to first byte not fetched.  */
1022 +  bfd_byte *max_fetched;
1023 +  bfd_byte the_buffer[MAXLEN];
1024 +  bfd_vma insn_start;
1025 +  int orig_sizeflag;
1026 +#ifndef __KERNEL__
1027 +  jmp_buf bailout;
1028 +#endif /* __KERNEL__ */
1029 +};
1030 +
1031 +/* The opcode for the fwait instruction, which we treat as a prefix
1032 +   when we can.  */
1033 +#define FWAIT_OPCODE (0x9b)
1034 +
1035 +/* Set to 1 for 64bit mode disassembly.  */
1036 +static int mode_64bit;
1037 +
1038 +/* Flags for the prefixes for the current instruction.  See below.  */
1039 +static int prefixes;
1040 +
1041 +/* REX prefix the current instruction.  See below.  */
1042 +static int rex;
1043 +/* Bits of REX we've already used.  */
1044 +static int rex_used;
1045 +#define REX_MODE64     8
1046 +#define REX_EXTX       4
1047 +#define REX_EXTY       2
1048 +#define REX_EXTZ       1
1049 +/* Mark parts used in the REX prefix.  When we are testing for
1050 +   empty prefix (for 8bit register REX extension), just mask it
1051 +   out.  Otherwise test for REX bit is excuse for existence of REX
1052 +   only in case value is nonzero.  */
1053 +#define USED_REX(value)                                        \
1054 +  {                                                    \
1055 +    if (value)                                         \
1056 +      rex_used |= (rex & value) ? (value) | 0x40 : 0;  \
1057 +    else                                               \
1058 +      rex_used |= 0x40;                                        \
1059 +  }
1060 +
1061 +/* Flags for prefixes which we somehow handled when printing the
1062 +   current instruction.  */
1063 +static int used_prefixes;
1064 +
1065 +/* Flags stored in PREFIXES.  */
1066 +#define PREFIX_REPZ 1
1067 +#define PREFIX_REPNZ 2
1068 +#define PREFIX_LOCK 4
1069 +#define PREFIX_CS 8
1070 +#define PREFIX_SS 0x10
1071 +#define PREFIX_DS 0x20
1072 +#define PREFIX_ES 0x40
1073 +#define PREFIX_FS 0x80
1074 +#define PREFIX_GS 0x100
1075 +#define PREFIX_DATA 0x200
1076 +#define PREFIX_ADDR 0x400
1077 +#define PREFIX_FWAIT 0x800
1078 +
1079 +/* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
1080 +   to ADDR (exclusive) are valid.  Returns 1 for success, longjmps
1081 +   on error.  */
1082 +#define FETCH_DATA(info, addr) \
1083 +  ((addr) <= ((struct dis_private *) (info->private_data))->max_fetched \
1084 +   ? 1 : fetch_data ((info), (addr)))
1085 +
1086 +static int
1087 +fetch_data (struct disassemble_info *info, bfd_byte *addr)
1088 +{
1089 +  int status;
1090 +  struct dis_private *priv = (struct dis_private *) info->private_data;
1091 +  bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
1092 +
1093 +  status = (*info->read_memory_func) (start,
1094 +                                     priv->max_fetched,
1095 +                                     addr - priv->max_fetched,
1096 +                                     info);
1097 +  if (status != 0)
1098 +    {
1099 +      /* If we did manage to read at least one byte, then
1100 +        print_insn_i386 will do something sensible.  Otherwise, print
1101 +        an error.  We do that here because this is where we know
1102 +        STATUS.  */
1103 +      if (priv->max_fetched == priv->the_buffer)
1104 +       (*info->memory_error_func) (status, start, info);
1105 +#ifndef __KERNEL__
1106 +      longjmp (priv->bailout, 1);
1107 +#else  /* __KERNEL__ */
1108 +       /* XXX - what to do? */
1109 +       kdb_printf("Hmm. longjmp.\n");
1110 +#endif /* __KERNEL__ */
1111 +    }
1112 +  else
1113 +    priv->max_fetched = addr;
1114 +  return 1;
1115 +}
1116 +
1117 +#define XX NULL, 0
1118 +
1119 +#define Eb OP_E, b_mode
1120 +#define Ev OP_E, v_mode
1121 +#define Ed OP_E, d_mode
1122 +#define Eq OP_E, q_mode
1123 +#define Edq OP_E, dq_mode
1124 +#define Edqw OP_E, dqw_mode
1125 +#define indirEv OP_indirE, branch_v_mode
1126 +#define indirEp OP_indirE, f_mode
1127 +#define Em OP_E, m_mode
1128 +#define Ew OP_E, w_mode
1129 +#define Ma OP_E, v_mode
1130 +#define M OP_M, 0              /* lea, lgdt, etc. */
1131 +#define Mp OP_M, f_mode                /* 32 or 48 bit memory operand for LDS, LES etc */
1132 +#define Gb OP_G, b_mode
1133 +#define Gv OP_G, v_mode
1134 +#define Gd OP_G, d_mode
1135 +#define Gdq OP_G, dq_mode
1136 +#define Gm OP_G, m_mode
1137 +#define Gw OP_G, w_mode
1138 +#define Rd OP_Rd, d_mode
1139 +#define Rm OP_Rd, m_mode
1140 +#define Ib OP_I, b_mode
1141 +#define sIb OP_sI, b_mode      /* sign extened byte */
1142 +#define Iv OP_I, v_mode
1143 +#define Iq OP_I, q_mode
1144 +#define Iv64 OP_I64, v_mode
1145 +#define Iw OP_I, w_mode
1146 +#define I1 OP_I, const_1_mode
1147 +#define Jb OP_J, b_mode
1148 +#define Jv OP_J, v_mode
1149 +#define Cm OP_C, m_mode
1150 +#define Dm OP_D, m_mode
1151 +#define Td OP_T, d_mode
1152 +#define Sv SEG_Fixup, v_mode
1153 +
1154 +#define RMeAX OP_REG, eAX_reg
1155 +#define RMeBX OP_REG, eBX_reg
1156 +#define RMeCX OP_REG, eCX_reg
1157 +#define RMeDX OP_REG, eDX_reg
1158 +#define RMeSP OP_REG, eSP_reg
1159 +#define RMeBP OP_REG, eBP_reg
1160 +#define RMeSI OP_REG, eSI_reg
1161 +#define RMeDI OP_REG, eDI_reg
1162 +#define RMrAX OP_REG, rAX_reg
1163 +#define RMrBX OP_REG, rBX_reg
1164 +#define RMrCX OP_REG, rCX_reg
1165 +#define RMrDX OP_REG, rDX_reg
1166 +#define RMrSP OP_REG, rSP_reg
1167 +#define RMrBP OP_REG, rBP_reg
1168 +#define RMrSI OP_REG, rSI_reg
1169 +#define RMrDI OP_REG, rDI_reg
1170 +#define RMAL OP_REG, al_reg
1171 +#define RMAL OP_REG, al_reg
1172 +#define RMCL OP_REG, cl_reg
1173 +#define RMDL OP_REG, dl_reg
1174 +#define RMBL OP_REG, bl_reg
1175 +#define RMAH OP_REG, ah_reg
1176 +#define RMCH OP_REG, ch_reg
1177 +#define RMDH OP_REG, dh_reg
1178 +#define RMBH OP_REG, bh_reg
1179 +#define RMAX OP_REG, ax_reg
1180 +#define RMDX OP_REG, dx_reg
1181 +
1182 +#define eAX OP_IMREG, eAX_reg
1183 +#define eBX OP_IMREG, eBX_reg
1184 +#define eCX OP_IMREG, eCX_reg
1185 +#define eDX OP_IMREG, eDX_reg
1186 +#define eSP OP_IMREG, eSP_reg
1187 +#define eBP OP_IMREG, eBP_reg
1188 +#define eSI OP_IMREG, eSI_reg
1189 +#define eDI OP_IMREG, eDI_reg
1190 +#define AL OP_IMREG, al_reg
1191 +#define AL OP_IMREG, al_reg
1192 +#define CL OP_IMREG, cl_reg
1193 +#define DL OP_IMREG, dl_reg
1194 +#define BL OP_IMREG, bl_reg
1195 +#define AH OP_IMREG, ah_reg
1196 +#define CH OP_IMREG, ch_reg
1197 +#define DH OP_IMREG, dh_reg
1198 +#define BH OP_IMREG, bh_reg
1199 +#define AX OP_IMREG, ax_reg
1200 +#define DX OP_IMREG, dx_reg
1201 +#define indirDX OP_IMREG, indir_dx_reg
1202 +
1203 +#define Sw OP_SEG, w_mode
1204 +#define Ap OP_DIR, 0
1205 +#define Ob OP_OFF, b_mode
1206 +#define Ob64 OP_OFF64, b_mode
1207 +#define Ov OP_OFF, v_mode
1208 +#define Ov64 OP_OFF64, v_mode
1209 +#define Xb OP_DSreg, eSI_reg
1210 +#define Xv OP_DSreg, eSI_reg
1211 +#define Yb OP_ESreg, eDI_reg
1212 +#define Yv OP_ESreg, eDI_reg
1213 +#define DSBX OP_DSreg, eBX_reg
1214 +
1215 +#define es OP_REG, es_reg
1216 +#define ss OP_REG, ss_reg
1217 +#define cs OP_REG, cs_reg
1218 +#define ds OP_REG, ds_reg
1219 +#define fs OP_REG, fs_reg
1220 +#define gs OP_REG, gs_reg
1221 +
1222 +#define MX OP_MMX, 0
1223 +#define XM OP_XMM, 0
1224 +#define EM OP_EM, v_mode
1225 +#define EX OP_EX, v_mode
1226 +#define MS OP_MS, v_mode
1227 +#define XS OP_XS, v_mode
1228 +#define VM OP_VMX, q_mode
1229 +#define OPSUF OP_3DNowSuffix, 0
1230 +#define OPSIMD OP_SIMD_Suffix, 0
1231 +
1232 +#define cond_jump_flag NULL, cond_jump_mode
1233 +#define loop_jcxz_flag NULL, loop_jcxz_mode
1234 +
1235 +/* bits in sizeflag */
1236 +#define SUFFIX_ALWAYS 4
1237 +#define AFLAG 2
1238 +#define DFLAG 1
1239 +
1240 +#define b_mode 1  /* byte operand */
1241 +#define v_mode 2  /* operand size depends on prefixes */
1242 +#define w_mode 3  /* word operand */
1243 +#define d_mode 4  /* double word operand  */
1244 +#define q_mode 5  /* quad word operand */
1245 +#define t_mode 6  /* ten-byte operand */
1246 +#define x_mode 7  /* 16-byte XMM operand */
1247 +#define m_mode 8  /* d_mode in 32bit, q_mode in 64bit mode.  */
1248 +#define cond_jump_mode 9
1249 +#define loop_jcxz_mode 10
1250 +#define dq_mode 11 /* operand size depends on REX prefixes.  */
1251 +#define dqw_mode 12 /* registers like dq_mode, memory like w_mode.  */
1252 +#define f_mode 13 /* 4- or 6-byte pointer operand */
1253 +#define const_1_mode 14
1254 +#define branch_v_mode 15 /* v_mode for branch.  */
1255 +
1256 +#define es_reg 100
1257 +#define cs_reg 101
1258 +#define ss_reg 102
1259 +#define ds_reg 103
1260 +#define fs_reg 104
1261 +#define gs_reg 105
1262 +
1263 +#define eAX_reg 108
1264 +#define eCX_reg 109
1265 +#define eDX_reg 110
1266 +#define eBX_reg 111
1267 +#define eSP_reg 112
1268 +#define eBP_reg 113
1269 +#define eSI_reg 114
1270 +#define eDI_reg 115
1271 +
1272 +#define al_reg 116
1273 +#define cl_reg 117
1274 +#define dl_reg 118
1275 +#define bl_reg 119
1276 +#define ah_reg 120
1277 +#define ch_reg 121
1278 +#define dh_reg 122
1279 +#define bh_reg 123
1280 +
1281 +#define ax_reg 124
1282 +#define cx_reg 125
1283 +#define dx_reg 126
1284 +#define bx_reg 127
1285 +#define sp_reg 128
1286 +#define bp_reg 129
1287 +#define si_reg 130
1288 +#define di_reg 131
1289 +
1290 +#define rAX_reg 132
1291 +#define rCX_reg 133
1292 +#define rDX_reg 134
1293 +#define rBX_reg 135
1294 +#define rSP_reg 136
1295 +#define rBP_reg 137
1296 +#define rSI_reg 138
1297 +#define rDI_reg 139
1298 +
1299 +#define indir_dx_reg 150
1300 +
1301 +#define FLOATCODE 1
1302 +#define USE_GROUPS 2
1303 +#define USE_PREFIX_USER_TABLE 3
1304 +#define X86_64_SPECIAL 4
1305 +
1306 +#define FLOAT    NULL, NULL, FLOATCODE, NULL, 0, NULL, 0
1307 +
1308 +#define GRP1b    NULL, NULL, USE_GROUPS, NULL,  0, NULL, 0
1309 +#define GRP1S    NULL, NULL, USE_GROUPS, NULL,  1, NULL, 0
1310 +#define GRP1Ss   NULL, NULL, USE_GROUPS, NULL,  2, NULL, 0
1311 +#define GRP2b    NULL, NULL, USE_GROUPS, NULL,  3, NULL, 0
1312 +#define GRP2S    NULL, NULL, USE_GROUPS, NULL,  4, NULL, 0
1313 +#define GRP2b_one NULL, NULL, USE_GROUPS, NULL,  5, NULL, 0
1314 +#define GRP2S_one NULL, NULL, USE_GROUPS, NULL,  6, NULL, 0
1315 +#define GRP2b_cl  NULL, NULL, USE_GROUPS, NULL,  7, NULL, 0
1316 +#define GRP2S_cl  NULL, NULL, USE_GROUPS, NULL,  8, NULL, 0
1317 +#define GRP3b    NULL, NULL, USE_GROUPS, NULL,  9, NULL, 0
1318 +#define GRP3S    NULL, NULL, USE_GROUPS, NULL, 10, NULL, 0
1319 +#define GRP4     NULL, NULL, USE_GROUPS, NULL, 11, NULL, 0
1320 +#define GRP5     NULL, NULL, USE_GROUPS, NULL, 12, NULL, 0
1321 +#define GRP6     NULL, NULL, USE_GROUPS, NULL, 13, NULL, 0
1322 +#define GRP7     NULL, NULL, USE_GROUPS, NULL, 14, NULL, 0
1323 +#define GRP8     NULL, NULL, USE_GROUPS, NULL, 15, NULL, 0
1324 +#define GRP9     NULL, NULL, USE_GROUPS, NULL, 16, NULL, 0
1325 +#define GRP10    NULL, NULL, USE_GROUPS, NULL, 17, NULL, 0
1326 +#define GRP11    NULL, NULL, USE_GROUPS, NULL, 18, NULL, 0
1327 +#define GRP12    NULL, NULL, USE_GROUPS, NULL, 19, NULL, 0
1328 +#define GRP13    NULL, NULL, USE_GROUPS, NULL, 20, NULL, 0
1329 +#define GRP14    NULL, NULL, USE_GROUPS, NULL, 21, NULL, 0
1330 +#define GRPAMD   NULL, NULL, USE_GROUPS, NULL, 22, NULL, 0
1331 +#define GRPPADLCK1 NULL, NULL, USE_GROUPS, NULL, 23, NULL, 0
1332 +#define GRPPADLCK2 NULL, NULL, USE_GROUPS, NULL, 24, NULL, 0
1333 +
1334 +#define PREGRP0   NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  0, NULL, 0
1335 +#define PREGRP1   NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  1, NULL, 0
1336 +#define PREGRP2   NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  2, NULL, 0
1337 +#define PREGRP3   NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  3, NULL, 0
1338 +#define PREGRP4   NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  4, NULL, 0
1339 +#define PREGRP5   NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  5, NULL, 0
1340 +#define PREGRP6   NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  6, NULL, 0
1341 +#define PREGRP7   NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  7, NULL, 0
1342 +#define PREGRP8   NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  8, NULL, 0
1343 +#define PREGRP9   NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  9, NULL, 0
1344 +#define PREGRP10  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 10, NULL, 0
1345 +#define PREGRP11  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 11, NULL, 0
1346 +#define PREGRP12  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 12, NULL, 0
1347 +#define PREGRP13  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 13, NULL, 0
1348 +#define PREGRP14  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 14, NULL, 0
1349 +#define PREGRP15  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 15, NULL, 0
1350 +#define PREGRP16  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 16, NULL, 0
1351 +#define PREGRP17  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 17, NULL, 0
1352 +#define PREGRP18  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 18, NULL, 0
1353 +#define PREGRP19  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 19, NULL, 0
1354 +#define PREGRP20  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 20, NULL, 0
1355 +#define PREGRP21  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 21, NULL, 0
1356 +#define PREGRP22  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 22, NULL, 0
1357 +#define PREGRP23  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 23, NULL, 0
1358 +#define PREGRP24  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 24, NULL, 0
1359 +#define PREGRP25  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 25, NULL, 0
1360 +#define PREGRP26  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 26, NULL, 0
1361 +#define PREGRP27  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 27, NULL, 0
1362 +#define PREGRP28  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 28, NULL, 0
1363 +#define PREGRP29  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 29, NULL, 0
1364 +#define PREGRP30  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 30, NULL, 0
1365 +#define PREGRP31  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 31, NULL, 0
1366 +#define PREGRP32  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 32, NULL, 0
1367 +
1368 +#define X86_64_0  NULL, NULL, X86_64_SPECIAL, NULL,  0, NULL, 0
1369 +
1370 +typedef void (*op_rtn) (int bytemode, int sizeflag);
1371 +
1372 +struct dis386 {
1373 +  const char *name;
1374 +  op_rtn op1;
1375 +  int bytemode1;
1376 +  op_rtn op2;
1377 +  int bytemode2;
1378 +  op_rtn op3;
1379 +  int bytemode3;
1380 +};
1381 +
1382 +/* Upper case letters in the instruction names here are macros.
1383 +   'A' => print 'b' if no register operands or suffix_always is true
1384 +   'B' => print 'b' if suffix_always is true
1385 +   'C' => print 's' or 'l' ('w' or 'd' in Intel mode) depending on operand
1386 +   .      size prefix
1387 +   'E' => print 'e' if 32-bit form of jcxz
1388 +   'F' => print 'w' or 'l' depending on address size prefix (loop insns)
1389 +   'H' => print ",pt" or ",pn" branch hint
1390 +   'I' => honor following macro letter even in Intel mode (implemented only
1391 +   .      for some of the macro letters)
1392 +   'J' => print 'l'
1393 +   'L' => print 'l' if suffix_always is true
1394 +   'N' => print 'n' if instruction has no wait "prefix"
1395 +   'O' => print 'd', or 'o'
1396 +   'P' => print 'w', 'l' or 'q' if instruction has an operand size prefix,
1397 +   .      or suffix_always is true.  print 'q' if rex prefix is present.
1398 +   'Q' => print 'w', 'l' or 'q' if no register operands or suffix_always
1399 +   .      is true
1400 +   'R' => print 'w', 'l' or 'q' ("wd" or "dq" in intel mode)
1401 +   'S' => print 'w', 'l' or 'q' if suffix_always is true
1402 +   'T' => print 'q' in 64bit mode and behave as 'P' otherwise
1403 +   'U' => print 'q' in 64bit mode and behave as 'Q' otherwise
1404 +   'W' => print 'b' or 'w' ("w" or "de" in intel mode)
1405 +   'X' => print 's', 'd' depending on data16 prefix (for XMM)
1406 +   'Y' => 'q' if instruction has an REX 64bit overwrite prefix
1407 +
1408 +   Many of the above letters print nothing in Intel mode.  See "putop"
1409 +   for the details.
1410 +
1411 +   Braces '{' and '}', and vertical bars '|', indicate alternative
1412 +   mnemonic strings for AT&T, Intel, X86_64 AT&T, and X86_64 Intel
1413 +   modes.  In cases where there are only two alternatives, the X86_64
1414 +   instruction is reserved, and "(bad)" is printed.
1415 +*/
1416 +
1417 +static const struct dis386 dis386[] = {
1418 +  /* 00 */
1419 +  { "addB",            Eb, Gb, XX },
1420 +  { "addS",            Ev, Gv, XX },
1421 +  { "addB",            Gb, Eb, XX },
1422 +  { "addS",            Gv, Ev, XX },
1423 +  { "addB",            AL, Ib, XX },
1424 +  { "addS",            eAX, Iv, XX },
1425 +  { "push{T|}",                es, XX, XX },
1426 +  { "pop{T|}",         es, XX, XX },
1427 +  /* 08 */
1428 +  { "orB",             Eb, Gb, XX },
1429 +  { "orS",             Ev, Gv, XX },
1430 +  { "orB",             Gb, Eb, XX },
1431 +  { "orS",             Gv, Ev, XX },
1432 +  { "orB",             AL, Ib, XX },
1433 +  { "orS",             eAX, Iv, XX },
1434 +  { "push{T|}",                cs, XX, XX },
1435 +  { "(bad)",           XX, XX, XX },   /* 0x0f extended opcode escape */
1436 +  /* 10 */
1437 +  { "adcB",            Eb, Gb, XX },
1438 +  { "adcS",            Ev, Gv, XX },
1439 +  { "adcB",            Gb, Eb, XX },
1440 +  { "adcS",            Gv, Ev, XX },
1441 +  { "adcB",            AL, Ib, XX },
1442 +  { "adcS",            eAX, Iv, XX },
1443 +  { "push{T|}",                ss, XX, XX },
1444 +  { "popT|}",          ss, XX, XX },
1445 +  /* 18 */
1446 +  { "sbbB",            Eb, Gb, XX },
1447 +  { "sbbS",            Ev, Gv, XX },
1448 +  { "sbbB",            Gb, Eb, XX },
1449 +  { "sbbS",            Gv, Ev, XX },
1450 +  { "sbbB",            AL, Ib, XX },
1451 +  { "sbbS",            eAX, Iv, XX },
1452 +  { "push{T|}",                ds, XX, XX },
1453 +  { "pop{T|}",         ds, XX, XX },
1454 +  /* 20 */
1455 +  { "andB",            Eb, Gb, XX },
1456 +  { "andS",            Ev, Gv, XX },
1457 +  { "andB",            Gb, Eb, XX },
1458 +  { "andS",            Gv, Ev, XX },
1459 +  { "andB",            AL, Ib, XX },
1460 +  { "andS",            eAX, Iv, XX },
1461 +  { "(bad)",           XX, XX, XX },   /* SEG ES prefix */
1462 +  { "daa{|}",          XX, XX, XX },
1463 +  /* 28 */
1464 +  { "subB",            Eb, Gb, XX },
1465 +  { "subS",            Ev, Gv, XX },
1466 +  { "subB",            Gb, Eb, XX },
1467 +  { "subS",            Gv, Ev, XX },
1468 +  { "subB",            AL, Ib, XX },
1469 +  { "subS",            eAX, Iv, XX },
1470 +  { "(bad)",           XX, XX, XX },   /* SEG CS prefix */
1471 +  { "das{|}",          XX, XX, XX },
1472 +  /* 30 */
1473 +  { "xorB",            Eb, Gb, XX },
1474 +  { "xorS",            Ev, Gv, XX },
1475 +  { "xorB",            Gb, Eb, XX },
1476 +  { "xorS",            Gv, Ev, XX },
1477 +  { "xorB",            AL, Ib, XX },
1478 +  { "xorS",            eAX, Iv, XX },
1479 +  { "(bad)",           XX, XX, XX },   /* SEG SS prefix */
1480 +  { "aaa{|}",          XX, XX, XX },
1481 +  /* 38 */
1482 +  { "cmpB",            Eb, Gb, XX },
1483 +  { "cmpS",            Ev, Gv, XX },
1484 +  { "cmpB",            Gb, Eb, XX },
1485 +  { "cmpS",            Gv, Ev, XX },
1486 +  { "cmpB",            AL, Ib, XX },
1487 +  { "cmpS",            eAX, Iv, XX },
1488 +  { "(bad)",           XX, XX, XX },   /* SEG DS prefix */
1489 +  { "aas{|}",          XX, XX, XX },
1490 +  /* 40 */
1491 +  { "inc{S|}",         RMeAX, XX, XX },
1492 +  { "inc{S|}",         RMeCX, XX, XX },
1493 +  { "inc{S|}",         RMeDX, XX, XX },
1494 +  { "inc{S|}",         RMeBX, XX, XX },
1495 +  { "inc{S|}",         RMeSP, XX, XX },
1496 +  { "inc{S|}",         RMeBP, XX, XX },
1497 +  { "inc{S|}",         RMeSI, XX, XX },
1498 +  { "inc{S|}",         RMeDI, XX, XX },
1499 +  /* 48 */
1500 +  { "dec{S|}",         RMeAX, XX, XX },
1501 +  { "dec{S|}",         RMeCX, XX, XX },
1502 +  { "dec{S|}",         RMeDX, XX, XX },
1503 +  { "dec{S|}",         RMeBX, XX, XX },
1504 +  { "dec{S|}",         RMeSP, XX, XX },
1505 +  { "dec{S|}",         RMeBP, XX, XX },
1506 +  { "dec{S|}",         RMeSI, XX, XX },
1507 +  { "dec{S|}",         RMeDI, XX, XX },
1508 +  /* 50 */
1509 +  { "pushS",           RMrAX, XX, XX },
1510 +  { "pushS",           RMrCX, XX, XX },
1511 +  { "pushS",           RMrDX, XX, XX },
1512 +  { "pushS",           RMrBX, XX, XX },
1513 +  { "pushS",           RMrSP, XX, XX },
1514 +  { "pushS",           RMrBP, XX, XX },
1515 +  { "pushS",           RMrSI, XX, XX },
1516 +  { "pushS",           RMrDI, XX, XX },
1517 +  /* 58 */
1518 +  { "popS",            RMrAX, XX, XX },
1519 +  { "popS",            RMrCX, XX, XX },
1520 +  { "popS",            RMrDX, XX, XX },
1521 +  { "popS",            RMrBX, XX, XX },
1522 +  { "popS",            RMrSP, XX, XX },
1523 +  { "popS",            RMrBP, XX, XX },
1524 +  { "popS",            RMrSI, XX, XX },
1525 +  { "popS",            RMrDI, XX, XX },
1526 +  /* 60 */
1527 +  { "pusha{P|}",       XX, XX, XX },
1528 +  { "popa{P|}",                XX, XX, XX },
1529 +  { "bound{S|}",       Gv, Ma, XX },
1530 +  { X86_64_0 },
1531 +  { "(bad)",           XX, XX, XX },   /* seg fs */
1532 +  { "(bad)",           XX, XX, XX },   /* seg gs */
1533 +  { "(bad)",           XX, XX, XX },   /* op size prefix */
1534 +  { "(bad)",           XX, XX, XX },   /* adr size prefix */
1535 +  /* 68 */
1536 +  { "pushT",           Iq, XX, XX },
1537 +  { "imulS",           Gv, Ev, Iv },
1538 +  { "pushT",           sIb, XX, XX },
1539 +  { "imulS",           Gv, Ev, sIb },
1540 +  { "ins{b||b|}",      Yb, indirDX, XX },
1541 +  { "ins{R||R|}",      Yv, indirDX, XX },
1542 +  { "outs{b||b|}",     indirDX, Xb, XX },
1543 +  { "outs{R||R|}",     indirDX, Xv, XX },
1544 +  /* 70 */
1545 +  { "joH",             Jb, XX, cond_jump_flag },
1546 +  { "jnoH",            Jb, XX, cond_jump_flag },
1547 +  { "jbH",             Jb, XX, cond_jump_flag },
1548 +  { "jaeH",            Jb, XX, cond_jump_flag },
1549 +  { "jeH",             Jb, XX, cond_jump_flag },
1550 +  { "jneH",            Jb, XX, cond_jump_flag },
1551 +  { "jbeH",            Jb, XX, cond_jump_flag },
1552 +  { "jaH",             Jb, XX, cond_jump_flag },
1553 +  /* 78 */
1554 +  { "jsH",             Jb, XX, cond_jump_flag },
1555 +  { "jnsH",            Jb, XX, cond_jump_flag },
1556 +  { "jpH",             Jb, XX, cond_jump_flag },
1557 +  { "jnpH",            Jb, XX, cond_jump_flag },
1558 +  { "jlH",             Jb, XX, cond_jump_flag },
1559 +  { "jgeH",            Jb, XX, cond_jump_flag },
1560 +  { "jleH",            Jb, XX, cond_jump_flag },
1561 +  { "jgH",             Jb, XX, cond_jump_flag },
1562 +  /* 80 */
1563 +  { GRP1b },
1564 +  { GRP1S },
1565 +  { "(bad)",           XX, XX, XX },
1566 +  { GRP1Ss },
1567 +  { "testB",           Eb, Gb, XX },
1568 +  { "testS",           Ev, Gv, XX },
1569 +  { "xchgB",           Eb, Gb, XX },
1570 +  { "xchgS",           Ev, Gv, XX },
1571 +  /* 88 */
1572 +  { "movB",            Eb, Gb, XX },
1573 +  { "movS",            Ev, Gv, XX },
1574 +  { "movB",            Gb, Eb, XX },
1575 +  { "movS",            Gv, Ev, XX },
1576 +  { "movQ",            Sv, Sw, XX },
1577 +  { "leaS",            Gv, M, XX },
1578 +  { "movQ",            Sw, Sv, XX },
1579 +  { "popU",            Ev, XX, XX },
1580 +  /* 90 */
1581 +  { "nop",             NOP_Fixup, 0, XX, XX },
1582 +  { "xchgS",           RMeCX, eAX, XX },
1583 +  { "xchgS",           RMeDX, eAX, XX },
1584 +  { "xchgS",           RMeBX, eAX, XX },
1585 +  { "xchgS",           RMeSP, eAX, XX },
1586 +  { "xchgS",           RMeBP, eAX, XX },
1587 +  { "xchgS",           RMeSI, eAX, XX },
1588 +  { "xchgS",           RMeDI, eAX, XX },
1589 +  /* 98 */
1590 +  { "cW{tR||tR|}",     XX, XX, XX },
1591 +  { "cR{tO||tO|}",     XX, XX, XX },
1592 +  { "Jcall{T|}",       Ap, XX, XX },
1593 +  { "(bad)",           XX, XX, XX },   /* fwait */
1594 +  { "pushfT",          XX, XX, XX },
1595 +  { "popfT",           XX, XX, XX },
1596 +  { "sahf{|}",         XX, XX, XX },
1597 +  { "lahf{|}",         XX, XX, XX },
1598 +  /* a0 */
1599 +  { "movB",            AL, Ob64, XX },
1600 +  { "movS",            eAX, Ov64, XX },
1601 +  { "movB",            Ob64, AL, XX },
1602 +  { "movS",            Ov64, eAX, XX },
1603 +  { "movs{b||b|}",     Yb, Xb, XX },
1604 +  { "movs{R||R|}",     Yv, Xv, XX },
1605 +  { "cmps{b||b|}",     Xb, Yb, XX },
1606 +  { "cmps{R||R|}",     Xv, Yv, XX },
1607 +  /* a8 */
1608 +  { "testB",           AL, Ib, XX },
1609 +  { "testS",           eAX, Iv, XX },
1610 +  { "stosB",           Yb, AL, XX },
1611 +  { "stosS",           Yv, eAX, XX },
1612 +  { "lodsB",           AL, Xb, XX },
1613 +  { "lodsS",           eAX, Xv, XX },
1614 +  { "scasB",           AL, Yb, XX },
1615 +  { "scasS",           eAX, Yv, XX },
1616 +  /* b0 */
1617 +  { "movB",            RMAL, Ib, XX },
1618 +  { "movB",            RMCL, Ib, XX },
1619 +  { "movB",            RMDL, Ib, XX },
1620 +  { "movB",            RMBL, Ib, XX },
1621 +  { "movB",            RMAH, Ib, XX },
1622 +  { "movB",            RMCH, Ib, XX },
1623 +  { "movB",            RMDH, Ib, XX },
1624 +  { "movB",            RMBH, Ib, XX },
1625 +  /* b8 */
1626 +  { "movS",            RMeAX, Iv64, XX },
1627 +  { "movS",            RMeCX, Iv64, XX },
1628 +  { "movS",            RMeDX, Iv64, XX },
1629 +  { "movS",            RMeBX, Iv64, XX },
1630 +  { "movS",            RMeSP, Iv64, XX },
1631 +  { "movS",            RMeBP, Iv64, XX },
1632 +  { "movS",            RMeSI, Iv64, XX },
1633 +  { "movS",            RMeDI, Iv64, XX },
1634 +  /* c0 */
1635 +  { GRP2b },
1636 +  { GRP2S },
1637 +  { "retT",            Iw, XX, XX },
1638 +  { "retT",            XX, XX, XX },
1639 +  { "les{S|}",         Gv, Mp, XX },
1640 +  { "ldsS",            Gv, Mp, XX },
1641 +  { "movA",            Eb, Ib, XX },
1642 +  { "movQ",            Ev, Iv, XX },
1643 +  /* c8 */
1644 +  { "enterT",          Iw, Ib, XX },
1645 +  { "leaveT",          XX, XX, XX },
1646 +  { "lretP",           Iw, XX, XX },
1647 +  { "lretP",           XX, XX, XX },
1648 +  { "int3",            XX, XX, XX },
1649 +  { "int",             Ib, XX, XX },
1650 +  { "into{|}",         XX, XX, XX },
1651 +  { "iretP",           XX, XX, XX },
1652 +  /* d0 */
1653 +  { GRP2b_one },
1654 +  { GRP2S_one },
1655 +  { GRP2b_cl },
1656 +  { GRP2S_cl },
1657 +  { "aam{|}",          sIb, XX, XX },
1658 +  { "aad{|}",          sIb, XX, XX },
1659 +  { "(bad)",           XX, XX, XX },
1660 +  { "xlat",            DSBX, XX, XX },
1661 +  /* d8 */
1662 +  { FLOAT },
1663 +  { FLOAT },
1664 +  { FLOAT },
1665 +  { FLOAT },
1666 +  { FLOAT },
1667 +  { FLOAT },
1668 +  { FLOAT },
1669 +  { FLOAT },
1670 +  /* e0 */
1671 +  { "loopneFH",                Jb, XX, loop_jcxz_flag },
1672 +  { "loopeFH",         Jb, XX, loop_jcxz_flag },
1673 +  { "loopFH",          Jb, XX, loop_jcxz_flag },
1674 +  { "jEcxzH",          Jb, XX, loop_jcxz_flag },
1675 +  { "inB",             AL, Ib, XX },
1676 +  { "inS",             eAX, Ib, XX },
1677 +  { "outB",            Ib, AL, XX },
1678 +  { "outS",            Ib, eAX, XX },
1679 +  /* e8 */
1680 +  { "callT",           Jv, XX, XX },
1681 +  { "jmpT",            Jv, XX, XX },
1682 +  { "Jjmp{T|}",                Ap, XX, XX },
1683 +  { "jmp",             Jb, XX, XX },
1684 +  { "inB",             AL, indirDX, XX },
1685 +  { "inS",             eAX, indirDX, XX },
1686 +  { "outB",            indirDX, AL, XX },
1687 +  { "outS",            indirDX, eAX, XX },
1688 +  /* f0 */
1689 +  { "(bad)",           XX, XX, XX },   /* lock prefix */
1690 +  { "icebp",           XX, XX, XX },
1691 +  { "(bad)",           XX, XX, XX },   /* repne */
1692 +  { "(bad)",           XX, XX, XX },   /* repz */
1693 +  { "hlt",             XX, XX, XX },
1694 +  { "cmc",             XX, XX, XX },
1695 +  { GRP3b },
1696 +  { GRP3S },
1697 +  /* f8 */
1698 +  { "clc",             XX, XX, XX },
1699 +  { "stc",             XX, XX, XX },
1700 +  { "cli",             XX, XX, XX },
1701 +  { "sti",             XX, XX, XX },
1702 +  { "cld",             XX, XX, XX },
1703 +  { "std",             XX, XX, XX },
1704 +  { GRP4 },
1705 +  { GRP5 },
1706 +};
1707 +
1708 +static const struct dis386 dis386_twobyte[] = {
1709 +  /* 00 */
1710 +  { GRP6 },
1711 +  { GRP7 },
1712 +  { "larS",            Gv, Ew, XX },
1713 +  { "lslS",            Gv, Ew, XX },
1714 +  { "(bad)",           XX, XX, XX },
1715 +  { "syscall",         XX, XX, XX },
1716 +  { "clts",            XX, XX, XX },
1717 +  { "sysretP",         XX, XX, XX },
1718 +  /* 08 */
1719 +  { "invd",            XX, XX, XX },
1720 +  { "wbinvd",          XX, XX, XX },
1721 +  { "(bad)",           XX, XX, XX },
1722 +  { "ud2a",            XX, XX, XX },
1723 +  { "(bad)",           XX, XX, XX },
1724 +  { GRPAMD },
1725 +  { "femms",           XX, XX, XX },
1726 +  { "",                        MX, EM, OPSUF }, /* See OP_3DNowSuffix.  */
1727 +  /* 10 */
1728 +  { PREGRP8 },
1729 +  { PREGRP9 },
1730 +  { PREGRP30 },
1731 +  { "movlpX",          EX, XM, SIMD_Fixup, 'h' },
1732 +  { "unpcklpX",                XM, EX, XX },
1733 +  { "unpckhpX",                XM, EX, XX },
1734 +  { PREGRP31 },
1735 +  { "movhpX",          EX, XM, SIMD_Fixup, 'l' },
1736 +  /* 18 */
1737 +  { GRP14 },
1738 +  { "(bad)",           XX, XX, XX },
1739 +  { "(bad)",           XX, XX, XX },
1740 +  { "(bad)",           XX, XX, XX },
1741 +  { "(bad)",           XX, XX, XX },
1742 +  { "(bad)",           XX, XX, XX },
1743 +  { "(bad)",           XX, XX, XX },
1744 +  { "(bad)",           XX, XX, XX },
1745 +  /* 20 */
1746 +  { "movL",            Rm, Cm, XX },
1747 +  { "movL",            Rm, Dm, XX },
1748 +  { "movL",            Cm, Rm, XX },
1749 +  { "movL",            Dm, Rm, XX },
1750 +  { "movL",            Rd, Td, XX },
1751 +  { "(bad)",           XX, XX, XX },
1752 +  { "movL",            Td, Rd, XX },
1753 +  { "(bad)",           XX, XX, XX },
1754 +  /* 28 */
1755 +  { "movapX",          XM, EX, XX },
1756 +  { "movapX",          EX, XM, XX },
1757 +  { PREGRP2 },
1758 +  { "movntpX",         Ev, XM, XX },
1759 +  { PREGRP4 },
1760 +  { PREGRP3 },
1761 +  { "ucomisX",         XM,EX, XX },
1762 +  { "comisX",          XM,EX, XX },
1763 +  /* 30 */
1764 +  { "wrmsr",           XX, XX, XX },
1765 +  { "rdtsc",           XX, XX, XX },
1766 +  { "rdmsr",           XX, XX, XX },
1767 +  { "rdpmc",           XX, XX, XX },
1768 +  { "sysenter",                XX, XX, XX },
1769 +  { "sysexit",         XX, XX, XX },
1770 +  { "(bad)",           XX, XX, XX },
1771 +  { "(bad)",           XX, XX, XX },
1772 +  /* 38 */
1773 +  { "(bad)",           XX, XX, XX },
1774 +  { "(bad)",           XX, XX, XX },
1775 +  { "(bad)",           XX, XX, XX },
1776 +  { "(bad)",           XX, XX, XX },
1777 +  { "(bad)",           XX, XX, XX },
1778 +  { "(bad)",           XX, XX, XX },
1779 +  { "(bad)",           XX, XX, XX },
1780 +  { "(bad)",           XX, XX, XX },
1781 +  /* 40 */
1782 +  { "cmovo",           Gv, Ev, XX },
1783 +  { "cmovno",          Gv, Ev, XX },
1784 +  { "cmovb",           Gv, Ev, XX },
1785 +  { "cmovae",          Gv, Ev, XX },
1786 +  { "cmove",           Gv, Ev, XX },
1787 +  { "cmovne",          Gv, Ev, XX },
1788 +  { "cmovbe",          Gv, Ev, XX },
1789 +  { "cmova",           Gv, Ev, XX },
1790 +  /* 48 */
1791 +  { "cmovs",           Gv, Ev, XX },
1792 +  { "cmovns",          Gv, Ev, XX },
1793 +  { "cmovp",           Gv, Ev, XX },
1794 +  { "cmovnp",          Gv, Ev, XX },
1795 +  { "cmovl",           Gv, Ev, XX },
1796 +  { "cmovge",          Gv, Ev, XX },
1797 +  { "cmovle",          Gv, Ev, XX },
1798 +  { "cmovg",           Gv, Ev, XX },
1799 +  /* 50 */
1800 +  { "movmskpX",                Gdq, XS, XX },
1801 +  { PREGRP13 },
1802 +  { PREGRP12 },
1803 +  { PREGRP11 },
1804 +  { "andpX",           XM, EX, XX },
1805 +  { "andnpX",          XM, EX, XX },
1806 +  { "orpX",            XM, EX, XX },
1807 +  { "xorpX",           XM, EX, XX },
1808 +  /* 58 */
1809 +  { PREGRP0 },
1810 +  { PREGRP10 },
1811 +  { PREGRP17 },
1812 +  { PREGRP16 },
1813 +  { PREGRP14 },
1814 +  { PREGRP7 },
1815 +  { PREGRP5 },
1816 +  { PREGRP6 },
1817 +  /* 60 */
1818 +  { "punpcklbw",       MX, EM, XX },
1819 +  { "punpcklwd",       MX, EM, XX },
1820 +  { "punpckldq",       MX, EM, XX },
1821 +  { "packsswb",                MX, EM, XX },
1822 +  { "pcmpgtb",         MX, EM, XX },
1823 +  { "pcmpgtw",         MX, EM, XX },
1824 +  { "pcmpgtd",         MX, EM, XX },
1825 +  { "packuswb",                MX, EM, XX },
1826 +  /* 68 */
1827 +  { "punpckhbw",       MX, EM, XX },
1828 +  { "punpckhwd",       MX, EM, XX },
1829 +  { "punpckhdq",       MX, EM, XX },
1830 +  { "packssdw",                MX, EM, XX },
1831 +  { PREGRP26 },
1832 +  { PREGRP24 },
1833 +  { "movd",            MX, Edq, XX },
1834 +  { PREGRP19 },
1835 +  /* 70 */
1836 +  { PREGRP22 },
1837 +  { GRP10 },
1838 +  { GRP11 },
1839 +  { GRP12 },
1840 +  { "pcmpeqb",         MX, EM, XX },
1841 +  { "pcmpeqw",         MX, EM, XX },
1842 +  { "pcmpeqd",         MX, EM, XX },
1843 +  { "emms",            XX, XX, XX },
1844 +  /* 78 */
1845 +  { "vmread",          Em, Gm, XX },
1846 +  { "vmwrite",         Gm, Em, XX },
1847 +  { "(bad)",           XX, XX, XX },
1848 +  { "(bad)",           XX, XX, XX },
1849 +  { PREGRP28 },
1850 +  { PREGRP29 },
1851 +  { PREGRP23 },
1852 +  { PREGRP20 },
1853 +  /* 80 */
1854 +  { "joH",             Jv, XX, cond_jump_flag },
1855 +  { "jnoH",            Jv, XX, cond_jump_flag },
1856 +  { "jbH",             Jv, XX, cond_jump_flag },
1857 +  { "jaeH",            Jv, XX, cond_jump_flag },
1858 +  { "jeH",             Jv, XX, cond_jump_flag },
1859 +  { "jneH",            Jv, XX, cond_jump_flag },
1860 +  { "jbeH",            Jv, XX, cond_jump_flag },
1861 +  { "jaH",             Jv, XX, cond_jump_flag },
1862 +  /* 88 */
1863 +  { "jsH",             Jv, XX, cond_jump_flag },
1864 +  { "jnsH",            Jv, XX, cond_jump_flag },
1865 +  { "jpH",             Jv, XX, cond_jump_flag },
1866 +  { "jnpH",            Jv, XX, cond_jump_flag },
1867 +  { "jlH",             Jv, XX, cond_jump_flag },
1868 +  { "jgeH",            Jv, XX, cond_jump_flag },
1869 +  { "jleH",            Jv, XX, cond_jump_flag },
1870 +  { "jgH",             Jv, XX, cond_jump_flag },
1871 +  /* 90 */
1872 +  { "seto",            Eb, XX, XX },
1873 +  { "setno",           Eb, XX, XX },
1874 +  { "setb",            Eb, XX, XX },
1875 +  { "setae",           Eb, XX, XX },
1876 +  { "sete",            Eb, XX, XX },
1877 +  { "setne",           Eb, XX, XX },
1878 +  { "setbe",           Eb, XX, XX },
1879 +  { "seta",            Eb, XX, XX },
1880 +  /* 98 */
1881 +  { "sets",            Eb, XX, XX },
1882 +  { "setns",           Eb, XX, XX },
1883 +  { "setp",            Eb, XX, XX },
1884 +  { "setnp",           Eb, XX, XX },
1885 +  { "setl",            Eb, XX, XX },
1886 +  { "setge",           Eb, XX, XX },
1887 +  { "setle",           Eb, XX, XX },
1888 +  { "setg",            Eb, XX, XX },
1889 +  /* a0 */
1890 +  { "pushT",           fs, XX, XX },
1891 +  { "popT",            fs, XX, XX },
1892 +  { "cpuid",           XX, XX, XX },
1893 +  { "btS",             Ev, Gv, XX },
1894 +  { "shldS",           Ev, Gv, Ib },
1895 +  { "shldS",           Ev, Gv, CL },
1896 +  { GRPPADLCK2 },
1897 +  { GRPPADLCK1 },
1898 +  /* a8 */
1899 +  { "pushT",           gs, XX, XX },
1900 +  { "popT",            gs, XX, XX },
1901 +  { "rsm",             XX, XX, XX },
1902 +  { "btsS",            Ev, Gv, XX },
1903 +  { "shrdS",           Ev, Gv, Ib },
1904 +  { "shrdS",           Ev, Gv, CL },
1905 +  { GRP13 },
1906 +  { "imulS",           Gv, Ev, XX },
1907 +  /* b0 */
1908 +  { "cmpxchgB",                Eb, Gb, XX },
1909 +  { "cmpxchgS",                Ev, Gv, XX },
1910 +  { "lssS",            Gv, Mp, XX },
1911 +  { "btrS",            Ev, Gv, XX },
1912 +  { "lfsS",            Gv, Mp, XX },
1913 +  { "lgsS",            Gv, Mp, XX },
1914 +  { "movz{bR|x|bR|x}", Gv, Eb, XX },
1915 +  { "movz{wR|x|wR|x}", Gv, Ew, XX }, /* yes, there really is movzww ! */
1916 +  /* b8 */
1917 +  { "(bad)",           XX, XX, XX },
1918 +  { "ud2b",            XX, XX, XX },
1919 +  { GRP8 },
1920 +  { "btcS",            Ev, Gv, XX },
1921 +  { "bsfS",            Gv, Ev, XX },
1922 +  { "bsrS",            Gv, Ev, XX },
1923 +  { "movs{bR|x|bR|x}", Gv, Eb, XX },
1924 +  { "movs{wR|x|wR|x}", Gv, Ew, XX }, /* yes, there really is movsww ! */
1925 +  /* c0 */
1926 +  { "xaddB",           Eb, Gb, XX },
1927 +  { "xaddS",           Ev, Gv, XX },
1928 +  { PREGRP1 },
1929 +  { "movntiS",         Ev, Gv, XX },
1930 +  { "pinsrw",          MX, Edqw, Ib },
1931 +  { "pextrw",          Gdq, MS, Ib },
1932 +  { "shufpX",          XM, EX, Ib },
1933 +  { GRP9 },
1934 +  /* c8 */
1935 +  { "bswap",           RMeAX, XX, XX },
1936 +  { "bswap",           RMeCX, XX, XX },
1937 +  { "bswap",           RMeDX, XX, XX },
1938 +  { "bswap",           RMeBX, XX, XX },
1939 +  { "bswap",           RMeSP, XX, XX },
1940 +  { "bswap",           RMeBP, XX, XX },
1941 +  { "bswap",           RMeSI, XX, XX },
1942 +  { "bswap",           RMeDI, XX, XX },
1943 +  /* d0 */
1944 +  { PREGRP27 },
1945 +  { "psrlw",           MX, EM, XX },
1946 +  { "psrld",           MX, EM, XX },
1947 +  { "psrlq",           MX, EM, XX },
1948 +  { "paddq",           MX, EM, XX },
1949 +  { "pmullw",          MX, EM, XX },
1950 +  { PREGRP21 },
1951 +  { "pmovmskb",                Gdq, MS, XX },
1952 +  /* d8 */
1953 +  { "psubusb",         MX, EM, XX },
1954 +  { "psubusw",         MX, EM, XX },
1955 +  { "pminub",          MX, EM, XX },
1956 +  { "pand",            MX, EM, XX },
1957 +  { "paddusb",         MX, EM, XX },
1958 +  { "paddusw",         MX, EM, XX },
1959 +  { "pmaxub",          MX, EM, XX },
1960 +  { "pandn",           MX, EM, XX },
1961 +  /* e0 */
1962 +  { "pavgb",           MX, EM, XX },
1963 +  { "psraw",           MX, EM, XX },
1964 +  { "psrad",           MX, EM, XX },
1965 +  { "pavgw",           MX, EM, XX },
1966 +  { "pmulhuw",         MX, EM, XX },
1967 +  { "pmulhw",          MX, EM, XX },
1968 +  { PREGRP15 },
1969 +  { PREGRP25 },
1970 +  /* e8 */
1971 +  { "psubsb",          MX, EM, XX },
1972 +  { "psubsw",          MX, EM, XX },
1973 +  { "pminsw",          MX, EM, XX },
1974 +  { "por",             MX, EM, XX },
1975 +  { "paddsb",          MX, EM, XX },
1976 +  { "paddsw",          MX, EM, XX },
1977 +  { "pmaxsw",          MX, EM, XX },
1978 +  { "pxor",            MX, EM, XX },
1979 +  /* f0 */
1980 +  { PREGRP32 },
1981 +  { "psllw",           MX, EM, XX },
1982 +  { "pslld",           MX, EM, XX },
1983 +  { "psllq",           MX, EM, XX },
1984 +  { "pmuludq",         MX, EM, XX },
1985 +  { "pmaddwd",         MX, EM, XX },
1986 +  { "psadbw",          MX, EM, XX },
1987 +  { PREGRP18 },
1988 +  /* f8 */
1989 +  { "psubb",           MX, EM, XX },
1990 +  { "psubw",           MX, EM, XX },
1991 +  { "psubd",           MX, EM, XX },
1992 +  { "psubq",           MX, EM, XX },
1993 +  { "paddb",           MX, EM, XX },
1994 +  { "paddw",           MX, EM, XX },
1995 +  { "paddd",           MX, EM, XX },
1996 +  { "(bad)",           XX, XX, XX }
1997 +};
1998 +
1999 +static const unsigned char onebyte_has_modrm[256] = {
2000 +  /*       0 1 2 3 4 5 6 7 8 9 a b c d e f        */
2001 +  /*       -------------------------------        */
2002 +  /* 00 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0, /* 00 */
2003 +  /* 10 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0, /* 10 */
2004 +  /* 20 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0, /* 20 */
2005 +  /* 30 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0, /* 30 */
2006 +  /* 40 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 40 */
2007 +  /* 50 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 50 */
2008 +  /* 60 */ 0,0,1,1,0,0,0,0,0,1,0,1,0,0,0,0, /* 60 */
2009 +  /* 70 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 70 */
2010 +  /* 80 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 80 */
2011 +  /* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 90 */
2012 +  /* a0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* a0 */
2013 +  /* b0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* b0 */
2014 +  /* c0 */ 1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0, /* c0 */
2015 +  /* d0 */ 1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1, /* d0 */
2016 +  /* e0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* e0 */
2017 +  /* f0 */ 0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1  /* f0 */
2018 +  /*       -------------------------------        */
2019 +  /*       0 1 2 3 4 5 6 7 8 9 a b c d e f        */
2020 +};
2021 +
2022 +static const unsigned char twobyte_has_modrm[256] = {
2023 +  /*       0 1 2 3 4 5 6 7 8 9 a b c d e f        */
2024 +  /*       -------------------------------        */
2025 +  /* 00 */ 1,1,1,1,0,0,0,0,0,0,0,0,0,1,0,1, /* 0f */
2026 +  /* 10 */ 1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0, /* 1f */
2027 +  /* 20 */ 1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1, /* 2f */
2028 +  /* 30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 3f */
2029 +  /* 40 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 4f */
2030 +  /* 50 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 5f */
2031 +  /* 60 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 6f */
2032 +  /* 70 */ 1,1,1,1,1,1,1,0,1,1,0,0,1,1,1,1, /* 7f */
2033 +  /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */
2034 +  /* 90 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 9f */
2035 +  /* a0 */ 0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1, /* af */
2036 +  /* b0 */ 1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1, /* bf */
2037 +  /* c0 */ 1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, /* cf */
2038 +  /* d0 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* df */
2039 +  /* e0 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* ef */
2040 +  /* f0 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0  /* ff */
2041 +  /*       -------------------------------        */
2042 +  /*       0 1 2 3 4 5 6 7 8 9 a b c d e f        */
2043 +};
2044 +
2045 +static const unsigned char twobyte_uses_SSE_prefix[256] = {
2046 +  /*       0 1 2 3 4 5 6 7 8 9 a b c d e f        */
2047 +  /*       -------------------------------        */
2048 +  /* 00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0f */
2049 +  /* 10 */ 1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0, /* 1f */
2050 +  /* 20 */ 0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,0, /* 2f */
2051 +  /* 30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 3f */
2052 +  /* 40 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 4f */
2053 +  /* 50 */ 0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1, /* 5f */
2054 +  /* 60 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1, /* 6f */
2055 +  /* 70 */ 1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1, /* 7f */
2056 +  /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */
2057 +  /* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 9f */
2058 +  /* a0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* af */
2059 +  /* b0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* bf */
2060 +  /* c0 */ 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, /* cf */
2061 +  /* d0 */ 1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0, /* df */
2062 +  /* e0 */ 0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0, /* ef */
2063 +  /* f0 */ 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0  /* ff */
2064 +  /*       -------------------------------        */
2065 +  /*       0 1 2 3 4 5 6 7 8 9 a b c d e f        */
2066 +};
2067 +
2068 +static char obuf[100];
2069 +static char *obufp;
2070 +static char scratchbuf[100];
2071 +static unsigned char *start_codep;
2072 +static unsigned char *insn_codep;
2073 +static unsigned char *codep;
2074 +static disassemble_info *the_info;
2075 +static int mod;
2076 +static int rm;
2077 +static int reg;
2078 +static unsigned char need_modrm;
2079 +
2080 +/* If we are accessing mod/rm/reg without need_modrm set, then the
2081 +   values are stale.  Hitting this abort likely indicates that you
2082 +   need to update onebyte_has_modrm or twobyte_has_modrm.  */
2083 +#define MODRM_CHECK  if (!need_modrm) abort ()
2084 +
2085 +static const char **names64;
2086 +static const char **names32;
2087 +static const char **names16;
2088 +static const char **names8;
2089 +static const char **names8rex;
2090 +static const char **names_seg;
2091 +static const char **index16;
2092 +
2093 +static const char *intel_names64[] = {
2094 +  "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
2095 +  "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
2096 +};
2097 +static const char *intel_names32[] = {
2098 +  "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
2099 +  "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d"
2100 +};
2101 +static const char *intel_names16[] = {
2102 +  "ax", "cx", "dx", "bx", "sp", "bp", "si", "di",
2103 +  "r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w"
2104 +};
2105 +static const char *intel_names8[] = {
2106 +  "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh",
2107 +};
2108 +static const char *intel_names8rex[] = {
2109 +  "al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil",
2110 +  "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b"
2111 +};
2112 +static const char *intel_names_seg[] = {
2113 +  "es", "cs", "ss", "ds", "fs", "gs", "?", "?",
2114 +};
2115 +static const char *intel_index16[] = {
2116 +  "bx+si", "bx+di", "bp+si", "bp+di", "si", "di", "bp", "bx"
2117 +};
2118 +
2119 +static const char *att_names64[] = {
2120 +  "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
2121 +  "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15"
2122 +};
2123 +static const char *att_names32[] = {
2124 +  "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
2125 +  "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d"
2126 +};
2127 +static const char *att_names16[] = {
2128 +  "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di",
2129 +  "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w"
2130 +};
2131 +static const char *att_names8[] = {
2132 +  "%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh",
2133 +};
2134 +static const char *att_names8rex[] = {
2135 +  "%al", "%cl", "%dl", "%bl", "%spl", "%bpl", "%sil", "%dil",
2136 +  "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b"
2137 +};
2138 +static const char *att_names_seg[] = {
2139 +  "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "%?", "%?",
2140 +};
2141 +static const char *att_index16[] = {
2142 +  "%bx,%si", "%bx,%di", "%bp,%si", "%bp,%di", "%si", "%di", "%bp", "%bx"
2143 +};
2144 +
2145 +static const struct dis386 grps[][8] = {
2146 +  /* GRP1b */
2147 +  {
2148 +    { "addA",  Eb, Ib, XX },
2149 +    { "orA",   Eb, Ib, XX },
2150 +    { "adcA",  Eb, Ib, XX },
2151 +    { "sbbA",  Eb, Ib, XX },
2152 +    { "andA",  Eb, Ib, XX },
2153 +    { "subA",  Eb, Ib, XX },
2154 +    { "xorA",  Eb, Ib, XX },
2155 +    { "cmpA",  Eb, Ib, XX }
2156 +  },
2157 +  /* GRP1S */
2158 +  {
2159 +    { "addQ",  Ev, Iv, XX },
2160 +    { "orQ",   Ev, Iv, XX },
2161 +    { "adcQ",  Ev, Iv, XX },
2162 +    { "sbbQ",  Ev, Iv, XX },
2163 +    { "andQ",  Ev, Iv, XX },
2164 +    { "subQ",  Ev, Iv, XX },
2165 +    { "xorQ",  Ev, Iv, XX },
2166 +    { "cmpQ",  Ev, Iv, XX }
2167 +  },
2168 +  /* GRP1Ss */
2169 +  {
2170 +    { "addQ",  Ev, sIb, XX },
2171 +    { "orQ",   Ev, sIb, XX },
2172 +    { "adcQ",  Ev, sIb, XX },
2173 +    { "sbbQ",  Ev, sIb, XX },
2174 +    { "andQ",  Ev, sIb, XX },
2175 +    { "subQ",  Ev, sIb, XX },
2176 +    { "xorQ",  Ev, sIb, XX },
2177 +    { "cmpQ",  Ev, sIb, XX }
2178 +  },
2179 +  /* GRP2b */
2180 +  {
2181 +    { "rolA",  Eb, Ib, XX },
2182 +    { "rorA",  Eb, Ib, XX },
2183 +    { "rclA",  Eb, Ib, XX },
2184 +    { "rcrA",  Eb, Ib, XX },
2185 +    { "shlA",  Eb, Ib, XX },
2186 +    { "shrA",  Eb, Ib, XX },
2187 +    { "(bad)", XX, XX, XX },
2188 +    { "sarA",  Eb, Ib, XX },
2189 +  },
2190 +  /* GRP2S */
2191 +  {
2192 +    { "rolQ",  Ev, Ib, XX },
2193 +    { "rorQ",  Ev, Ib, XX },
2194 +    { "rclQ",  Ev, Ib, XX },
2195 +    { "rcrQ",  Ev, Ib, XX },
2196 +    { "shlQ",  Ev, Ib, XX },
2197 +    { "shrQ",  Ev, Ib, XX },
2198 +    { "(bad)", XX, XX, XX },
2199 +    { "sarQ",  Ev, Ib, XX },
2200 +  },
2201 +  /* GRP2b_one */
2202 +  {
2203 +    { "rolA",  Eb, I1, XX },
2204 +    { "rorA",  Eb, I1, XX },
2205 +    { "rclA",  Eb, I1, XX },
2206 +    { "rcrA",  Eb, I1, XX },
2207 +    { "shlA",  Eb, I1, XX },
2208 +    { "shrA",  Eb, I1, XX },
2209 +    { "(bad)", XX, XX, XX },
2210 +    { "sarA",  Eb, I1, XX },
2211 +  },
2212 +  /* GRP2S_one */
2213 +  {
2214 +    { "rolQ",  Ev, I1, XX },
2215 +    { "rorQ",  Ev, I1, XX },
2216 +    { "rclQ",  Ev, I1, XX },
2217 +    { "rcrQ",  Ev, I1, XX },
2218 +    { "shlQ",  Ev, I1, XX },
2219 +    { "shrQ",  Ev, I1, XX },
2220 +    { "(bad)", XX, XX, XX},
2221 +    { "sarQ",  Ev, I1, XX },
2222 +  },
2223 +  /* GRP2b_cl */
2224 +  {
2225 +    { "rolA",  Eb, CL, XX },
2226 +    { "rorA",  Eb, CL, XX },
2227 +    { "rclA",  Eb, CL, XX },
2228 +    { "rcrA",  Eb, CL, XX },
2229 +    { "shlA",  Eb, CL, XX },
2230 +    { "shrA",  Eb, CL, XX },
2231 +    { "(bad)", XX, XX, XX },
2232 +    { "sarA",  Eb, CL, XX },
2233 +  },
2234 +  /* GRP2S_cl */
2235 +  {
2236 +    { "rolQ",  Ev, CL, XX },
2237 +    { "rorQ",  Ev, CL, XX },
2238 +    { "rclQ",  Ev, CL, XX },
2239 +    { "rcrQ",  Ev, CL, XX },
2240 +    { "shlQ",  Ev, CL, XX },
2241 +    { "shrQ",  Ev, CL, XX },
2242 +    { "(bad)", XX, XX, XX },
2243 +    { "sarQ",  Ev, CL, XX }
2244 +  },
2245 +  /* GRP3b */
2246 +  {
2247 +    { "testA", Eb, Ib, XX },
2248 +    { "(bad)", Eb, XX, XX },
2249 +    { "notA",  Eb, XX, XX },
2250 +    { "negA",  Eb, XX, XX },
2251 +    { "mulA",  Eb, XX, XX },   /* Don't print the implicit %al register,  */
2252 +    { "imulA", Eb, XX, XX },   /* to distinguish these opcodes from other */
2253 +    { "divA",  Eb, XX, XX },   /* mul/imul opcodes.  Do the same for div  */
2254 +    { "idivA", Eb, XX, XX }    /* and idiv for consistency.               */
2255 +  },
2256 +  /* GRP3S */
2257 +  {
2258 +    { "testQ", Ev, Iv, XX },
2259 +    { "(bad)", XX, XX, XX },
2260 +    { "notQ",  Ev, XX, XX },
2261 +    { "negQ",  Ev, XX, XX },
2262 +    { "mulQ",  Ev, XX, XX },   /* Don't print the implicit register.  */
2263 +    { "imulQ", Ev, XX, XX },
2264 +    { "divQ",  Ev, XX, XX },
2265 +    { "idivQ", Ev, XX, XX },
2266 +  },
2267 +  /* GRP4 */
2268 +  {
2269 +    { "incA",  Eb, XX, XX },
2270 +    { "decA",  Eb, XX, XX },
2271 +    { "(bad)", XX, XX, XX },
2272 +    { "(bad)", XX, XX, XX },
2273 +    { "(bad)", XX, XX, XX },
2274 +    { "(bad)", XX, XX, XX },
2275 +    { "(bad)", XX, XX, XX },
2276 +    { "(bad)", XX, XX, XX },
2277 +  },
2278 +  /* GRP5 */
2279 +  {
2280 +    { "incQ",  Ev, XX, XX },
2281 +    { "decQ",  Ev, XX, XX },
2282 +    { "callT", indirEv, XX, XX },
2283 +    { "JcallT",        indirEp, XX, XX },
2284 +    { "jmpT",  indirEv, XX, XX },
2285 +    { "JjmpT", indirEp, XX, XX },
2286 +    { "pushU", Ev, XX, XX },
2287 +    { "(bad)", XX, XX, XX },
2288 +  },
2289 +  /* GRP6 */
2290 +  {
2291 +    { "sldtQ", Ev, XX, XX },
2292 +    { "strQ",  Ev, XX, XX },
2293 +    { "lldt",  Ew, XX, XX },
2294 +    { "ltr",   Ew, XX, XX },
2295 +    { "verr",  Ew, XX, XX },
2296 +    { "verw",  Ew, XX, XX },
2297 +    { "(bad)", XX, XX, XX },
2298 +    { "(bad)", XX, XX, XX }
2299 +  },
2300 +  /* GRP7 */
2301 +  {
2302 +    { "sgdtIQ", VMX_Fixup, 0, XX, XX },
2303 +    { "sidtIQ", PNI_Fixup, 0, XX, XX },
2304 +    { "lgdt{Q|Q||}",    M, XX, XX },
2305 +    { "lidt{Q|Q||}",    SVME_Fixup, 0, XX, XX },
2306 +    { "smswQ", Ev, XX, XX },
2307 +    { "(bad)", XX, XX, XX },
2308 +    { "lmsw",  Ew, XX, XX },
2309 +    { "invlpg",        INVLPG_Fixup, w_mode, XX, XX },
2310 +  },
2311 +  /* GRP8 */
2312 +  {
2313 +    { "(bad)", XX, XX, XX },
2314 +    { "(bad)", XX, XX, XX },
2315 +    { "(bad)", XX, XX, XX },
2316 +    { "(bad)", XX, XX, XX },
2317 +    { "btQ",   Ev, Ib, XX },
2318 +    { "btsQ",  Ev, Ib, XX },
2319 +    { "btrQ",  Ev, Ib, XX },
2320 +    { "btcQ",  Ev, Ib, XX },
2321 +  },
2322 +  /* GRP9 */
2323 +  {
2324 +    { "(bad)", XX, XX, XX },
2325 +    { "cmpxchg8b", Eq, XX, XX },
2326 +    { "(bad)", XX, XX, XX },
2327 +    { "(bad)", XX, XX, XX },
2328 +    { "(bad)", XX, XX, XX },
2329 +    { "(bad)", XX, XX, XX },
2330 +    { "",      VM, XX, XX },           /* See OP_VMX.  */
2331 +    { "vmptrst", Eq, XX, XX },
2332 +  },
2333 +  /* GRP10 */
2334 +  {
2335 +    { "(bad)", XX, XX, XX },
2336 +    { "(bad)", XX, XX, XX },
2337 +    { "psrlw", MS, Ib, XX },
2338 +    { "(bad)", XX, XX, XX },
2339 +    { "psraw", MS, Ib, XX },
2340 +    { "(bad)", XX, XX, XX },
2341 +    { "psllw", MS, Ib, XX },
2342 +    { "(bad)", XX, XX, XX },
2343 +  },
2344 +  /* GRP11 */
2345 +  {
2346 +    { "(bad)", XX, XX, XX },
2347 +    { "(bad)", XX, XX, XX },
2348 +    { "psrld", MS, Ib, XX },
2349 +    { "(bad)", XX, XX, XX },
2350 +    { "psrad", MS, Ib, XX },
2351 +    { "(bad)", XX, XX, XX },
2352 +    { "pslld", MS, Ib, XX },
2353 +    { "(bad)", XX, XX, XX },
2354 +  },
2355 +  /* GRP12 */
2356 +  {
2357 +    { "(bad)", XX, XX, XX },
2358 +    { "(bad)", XX, XX, XX },
2359 +    { "psrlq", MS, Ib, XX },
2360 +    { "psrldq",        MS, Ib, XX },
2361 +    { "(bad)", XX, XX, XX },
2362 +    { "(bad)", XX, XX, XX },
2363 +    { "psllq", MS, Ib, XX },
2364 +    { "pslldq",        MS, Ib, XX },
2365 +  },
2366 +  /* GRP13 */
2367 +  {
2368 +    { "fxsave", Ev, XX, XX },
2369 +    { "fxrstor", Ev, XX, XX },
2370 +    { "ldmxcsr", Ev, XX, XX },
2371 +    { "stmxcsr", Ev, XX, XX },
2372 +    { "(bad)", XX, XX, XX },
2373 +    { "lfence", OP_0fae, 0, XX, XX },
2374 +    { "mfence", OP_0fae, 0, XX, XX },
2375 +    { "clflush", OP_0fae, 0, XX, XX },
2376 +  },
2377 +  /* GRP14 */
2378 +  {
2379 +    { "prefetchnta", Ev, XX, XX },
2380 +    { "prefetcht0", Ev, XX, XX },
2381 +    { "prefetcht1", Ev, XX, XX },
2382 +    { "prefetcht2", Ev, XX, XX },
2383 +    { "(bad)", XX, XX, XX },
2384 +    { "(bad)", XX, XX, XX },
2385 +    { "(bad)", XX, XX, XX },
2386 +    { "(bad)", XX, XX, XX },
2387 +  },
2388 +  /* GRPAMD */
2389 +  {
2390 +    { "prefetch", Eb, XX, XX },
2391 +    { "prefetchw", Eb, XX, XX },
2392 +    { "(bad)", XX, XX, XX },
2393 +    { "(bad)", XX, XX, XX },
2394 +    { "(bad)", XX, XX, XX },
2395 +    { "(bad)", XX, XX, XX },
2396 +    { "(bad)", XX, XX, XX },
2397 +    { "(bad)", XX, XX, XX },
2398 +  },
2399 +  /* GRPPADLCK1 */
2400 +  {
2401 +    { "xstore-rng", OP_0f07, 0, XX, XX },
2402 +    { "xcrypt-ecb", OP_0f07, 0, XX, XX },
2403 +    { "xcrypt-cbc", OP_0f07, 0, XX, XX },
2404 +    { "xcrypt-ctr", OP_0f07, 0, XX, XX },
2405 +    { "xcrypt-cfb", OP_0f07, 0, XX, XX },
2406 +    { "xcrypt-ofb", OP_0f07, 0, XX, XX },
2407 +    { "(bad)", OP_0f07, 0, XX, XX },
2408 +    { "(bad)", OP_0f07, 0, XX, XX },
2409 +  },
2410 +  /* GRPPADLCK2 */
2411 +  {
2412 +    { "montmul", OP_0f07, 0, XX, XX },
2413 +    { "xsha1",   OP_0f07, 0, XX, XX },
2414 +    { "xsha256", OP_0f07, 0, XX, XX },
2415 +    { "(bad)",  OP_0f07, 0, XX, XX },
2416 +    { "(bad)",   OP_0f07, 0, XX, XX },
2417 +    { "(bad)",   OP_0f07, 0, XX, XX },
2418 +    { "(bad)",  OP_0f07, 0, XX, XX },
2419 +    { "(bad)",  OP_0f07, 0, XX, XX },
2420 +  }
2421 +};
2422 +
2423 +static const struct dis386 prefix_user_table[][4] = {
2424 +  /* PREGRP0 */
2425 +  {
2426 +    { "addps", XM, EX, XX },
2427 +    { "addss", XM, EX, XX },
2428 +    { "addpd", XM, EX, XX },
2429 +    { "addsd", XM, EX, XX },
2430 +  },
2431 +  /* PREGRP1 */
2432 +  {
2433 +    { "", XM, EX, OPSIMD },    /* See OP_SIMD_SUFFIX.  */
2434 +    { "", XM, EX, OPSIMD },
2435 +    { "", XM, EX, OPSIMD },
2436 +    { "", XM, EX, OPSIMD },
2437 +  },
2438 +  /* PREGRP2 */
2439 +  {
2440 +    { "cvtpi2ps", XM, EM, XX },
2441 +    { "cvtsi2ssY", XM, Ev, XX },
2442 +    { "cvtpi2pd", XM, EM, XX },
2443 +    { "cvtsi2sdY", XM, Ev, XX },
2444 +  },
2445 +  /* PREGRP3 */
2446 +  {
2447 +    { "cvtps2pi", MX, EX, XX },
2448 +    { "cvtss2siY", Gv, EX, XX },
2449 +    { "cvtpd2pi", MX, EX, XX },
2450 +    { "cvtsd2siY", Gv, EX, XX },
2451 +  },
2452 +  /* PREGRP4 */
2453 +  {
2454 +    { "cvttps2pi", MX, EX, XX },
2455 +    { "cvttss2siY", Gv, EX, XX },
2456 +    { "cvttpd2pi", MX, EX, XX },
2457 +    { "cvttsd2siY", Gv, EX, XX },
2458 +  },
2459 +  /* PREGRP5 */
2460 +  {
2461 +    { "divps", XM, EX, XX },
2462 +    { "divss", XM, EX, XX },
2463 +    { "divpd", XM, EX, XX },
2464 +    { "divsd", XM, EX, XX },
2465 +  },
2466 +  /* PREGRP6 */
2467 +  {
2468 +    { "maxps", XM, EX, XX },
2469 +    { "maxss", XM, EX, XX },
2470 +    { "maxpd", XM, EX, XX },
2471 +    { "maxsd", XM, EX, XX },
2472 +  },
2473 +  /* PREGRP7 */
2474 +  {
2475 +    { "minps", XM, EX, XX },
2476 +    { "minss", XM, EX, XX },
2477 +    { "minpd", XM, EX, XX },
2478 +    { "minsd", XM, EX, XX },
2479 +  },
2480 +  /* PREGRP8 */
2481 +  {
2482 +    { "movups", XM, EX, XX },
2483 +    { "movss", XM, EX, XX },
2484 +    { "movupd", XM, EX, XX },
2485 +    { "movsd", XM, EX, XX },
2486 +  },
2487 +  /* PREGRP9 */
2488 +  {
2489 +    { "movups", EX, XM, XX },
2490 +    { "movss", EX, XM, XX },
2491 +    { "movupd", EX, XM, XX },
2492 +    { "movsd", EX, XM, XX },
2493 +  },
2494 +  /* PREGRP10 */
2495 +  {
2496 +    { "mulps", XM, EX, XX },
2497 +    { "mulss", XM, EX, XX },
2498 +    { "mulpd", XM, EX, XX },
2499 +    { "mulsd", XM, EX, XX },
2500 +  },
2501 +  /* PREGRP11 */
2502 +  {
2503 +    { "rcpps", XM, EX, XX },
2504 +    { "rcpss", XM, EX, XX },
2505 +    { "(bad)", XM, EX, XX },
2506 +    { "(bad)", XM, EX, XX },
2507 +  },
2508 +  /* PREGRP12 */
2509 +  {
2510 +    { "rsqrtps", XM, EX, XX },
2511 +    { "rsqrtss", XM, EX, XX },
2512 +    { "(bad)", XM, EX, XX },
2513 +    { "(bad)", XM, EX, XX },
2514 +  },
2515 +  /* PREGRP13 */
2516 +  {
2517 +    { "sqrtps", XM, EX, XX },
2518 +    { "sqrtss", XM, EX, XX },
2519 +    { "sqrtpd", XM, EX, XX },
2520 +    { "sqrtsd", XM, EX, XX },
2521 +  },
2522 +  /* PREGRP14 */
2523 +  {
2524 +    { "subps", XM, EX, XX },
2525 +    { "subss", XM, EX, XX },
2526 +    { "subpd", XM, EX, XX },
2527 +    { "subsd", XM, EX, XX },
2528 +  },
2529 +  /* PREGRP15 */
2530 +  {
2531 +    { "(bad)", XM, EX, XX },
2532 +    { "cvtdq2pd", XM, EX, XX },
2533 +    { "cvttpd2dq", XM, EX, XX },
2534 +    { "cvtpd2dq", XM, EX, XX },
2535 +  },
2536 +  /* PREGRP16 */
2537 +  {
2538 +    { "cvtdq2ps", XM, EX, XX },
2539 +    { "cvttps2dq",XM, EX, XX },
2540 +    { "cvtps2dq",XM, EX, XX },
2541 +    { "(bad)", XM, EX, XX },
2542 +  },
2543 +  /* PREGRP17 */
2544 +  {
2545 +    { "cvtps2pd", XM, EX, XX },
2546 +    { "cvtss2sd", XM, EX, XX },
2547 +    { "cvtpd2ps", XM, EX, XX },
2548 +    { "cvtsd2ss", XM, EX, XX },
2549 +  },
2550 +  /* PREGRP18 */
2551 +  {
2552 +    { "maskmovq", MX, MS, XX },
2553 +    { "(bad)", XM, EX, XX },
2554 +    { "maskmovdqu", XM, EX, XX },
2555 +    { "(bad)", XM, EX, XX },
2556 +  },
2557 +  /* PREGRP19 */
2558 +  {
2559 +    { "movq", MX, EM, XX },
2560 +    { "movdqu", XM, EX, XX },
2561 +    { "movdqa", XM, EX, XX },
2562 +    { "(bad)", XM, EX, XX },
2563 +  },
2564 +  /* PREGRP20 */
2565 +  {
2566 +    { "movq", EM, MX, XX },
2567 +    { "movdqu", EX, XM, XX },
2568 +    { "movdqa", EX, XM, XX },
2569 +    { "(bad)", EX, XM, XX },
2570 +  },
2571 +  /* PREGRP21 */
2572 +  {
2573 +    { "(bad)", EX, XM, XX },
2574 +    { "movq2dq", XM, MS, XX },
2575 +    { "movq", EX, XM, XX },
2576 +    { "movdq2q", MX, XS, XX },
2577 +  },
2578 +  /* PREGRP22 */
2579 +  {
2580 +    { "pshufw", MX, EM, Ib },
2581 +    { "pshufhw", XM, EX, Ib },
2582 +    { "pshufd", XM, EX, Ib },
2583 +    { "pshuflw", XM, EX, Ib },
2584 +  },
2585 +  /* PREGRP23 */
2586 +  {
2587 +    { "movd", Edq, MX, XX },
2588 +    { "movq", XM, EX, XX },
2589 +    { "movd", Edq, XM, XX },
2590 +    { "(bad)", Ed, XM, XX },
2591 +  },
2592 +  /* PREGRP24 */
2593 +  {
2594 +    { "(bad)", MX, EX, XX },
2595 +    { "(bad)", XM, EX, XX },
2596 +    { "punpckhqdq", XM, EX, XX },
2597 +    { "(bad)", XM, EX, XX },
2598 +  },
2599 +  /* PREGRP25 */
2600 +  {
2601 +    { "movntq", EM, MX, XX },
2602 +    { "(bad)", EM, XM, XX },
2603 +    { "movntdq", EM, XM, XX },
2604 +    { "(bad)", EM, XM, XX },
2605 +  },
2606 +  /* PREGRP26 */
2607 +  {
2608 +    { "(bad)", MX, EX, XX },
2609 +    { "(bad)", XM, EX, XX },
2610 +    { "punpcklqdq", XM, EX, XX },
2611 +    { "(bad)", XM, EX, XX },
2612 +  },
2613 +  /* PREGRP27 */
2614 +  {
2615 +    { "(bad)", MX, EX, XX },
2616 +    { "(bad)", XM, EX, XX },
2617 +    { "addsubpd", XM, EX, XX },
2618 +    { "addsubps", XM, EX, XX },
2619 +  },
2620 +  /* PREGRP28 */
2621 +  {
2622 +    { "(bad)", MX, EX, XX },
2623 +    { "(bad)", XM, EX, XX },
2624 +    { "haddpd", XM, EX, XX },
2625 +    { "haddps", XM, EX, XX },
2626 +  },
2627 +  /* PREGRP29 */
2628 +  {
2629 +    { "(bad)", MX, EX, XX },
2630 +    { "(bad)", XM, EX, XX },
2631 +    { "hsubpd", XM, EX, XX },
2632 +    { "hsubps", XM, EX, XX },
2633 +  },
2634 +  /* PREGRP30 */
2635 +  {
2636 +    { "movlpX", XM, EX, SIMD_Fixup, 'h' }, /* really only 2 operands */
2637 +    { "movsldup", XM, EX, XX },
2638 +    { "movlpd", XM, EX, XX },
2639 +    { "movddup", XM, EX, XX },
2640 +  },
2641 +  /* PREGRP31 */
2642 +  {
2643 +    { "movhpX", XM, EX, SIMD_Fixup, 'l' },
2644 +    { "movshdup", XM, EX, XX },
2645 +    { "movhpd", XM, EX, XX },
2646 +    { "(bad)", XM, EX, XX },
2647 +  },
2648 +  /* PREGRP32 */
2649 +  {
2650 +    { "(bad)", XM, EX, XX },
2651 +    { "(bad)", XM, EX, XX },
2652 +    { "(bad)", XM, EX, XX },
2653 +    { "lddqu", XM, M, XX },
2654 +  },
2655 +};
2656 +
2657 +static const struct dis386 x86_64_table[][2] = {
2658 +  {
2659 +    { "arpl", Ew, Gw, XX },
2660 +    { "movs{||lq|xd}", Gv, Ed, XX },
2661 +  },
2662 +};
2663 +
2664 +#ifdef __KERNEL__
2665 +#define INTERNAL_DISASSEMBLER_ERROR "<internal disassembler error>"
2666 +#else  /* __KERNEL__ */
2667 +#define INTERNAL_DISASSEMBLER_ERROR _("<internal disassembler error>")
2668 +#endif /* __KERNEL__ */
2669 +
2670 +static void
2671 +ckprefix (void)
2672 +{
2673 +  int newrex;
2674 +  rex = 0;
2675 +  prefixes = 0;
2676 +  used_prefixes = 0;
2677 +  rex_used = 0;
2678 +  while (1)
2679 +    {
2680 +      FETCH_DATA (the_info, codep + 1);
2681 +      newrex = 0;
2682 +      switch (*codep)
2683 +       {
2684 +       /* REX prefixes family.  */
2685 +       case 0x40:
2686 +       case 0x41:
2687 +       case 0x42:
2688 +       case 0x43:
2689 +       case 0x44:
2690 +       case 0x45:
2691 +       case 0x46:
2692 +       case 0x47:
2693 +       case 0x48:
2694 +       case 0x49:
2695 +       case 0x4a:
2696 +       case 0x4b:
2697 +       case 0x4c:
2698 +       case 0x4d:
2699 +       case 0x4e:
2700 +       case 0x4f:
2701 +           if (mode_64bit)
2702 +             newrex = *codep;
2703 +           else
2704 +             return;
2705 +         break;
2706 +       case 0xf3:
2707 +         prefixes |= PREFIX_REPZ;
2708 +         break;
2709 +       case 0xf2:
2710 +         prefixes |= PREFIX_REPNZ;
2711 +         break;
2712 +       case 0xf0:
2713 +         prefixes |= PREFIX_LOCK;
2714 +         break;
2715 +       case 0x2e:
2716 +         prefixes |= PREFIX_CS;
2717 +         break;
2718 +       case 0x36:
2719 +         prefixes |= PREFIX_SS;
2720 +         break;
2721 +       case 0x3e:
2722 +         prefixes |= PREFIX_DS;
2723 +         break;
2724 +       case 0x26:
2725 +         prefixes |= PREFIX_ES;
2726 +         break;
2727 +       case 0x64:
2728 +         prefixes |= PREFIX_FS;
2729 +         break;
2730 +       case 0x65:
2731 +         prefixes |= PREFIX_GS;
2732 +         break;
2733 +       case 0x66:
2734 +         prefixes |= PREFIX_DATA;
2735 +         break;
2736 +       case 0x67:
2737 +         prefixes |= PREFIX_ADDR;
2738 +         break;
2739 +       case FWAIT_OPCODE:
2740 +         /* fwait is really an instruction.  If there are prefixes
2741 +            before the fwait, they belong to the fwait, *not* to the
2742 +            following instruction.  */
2743 +         if (prefixes)
2744 +           {
2745 +             prefixes |= PREFIX_FWAIT;
2746 +             codep++;
2747 +             return;
2748 +           }
2749 +         prefixes = PREFIX_FWAIT;
2750 +         break;
2751 +       default:
2752 +         return;
2753 +       }
2754 +      /* Rex is ignored when followed by another prefix.  */
2755 +      if (rex)
2756 +       {
2757 +         oappend (prefix_name (rex, 0));
2758 +         oappend (" ");
2759 +       }
2760 +      rex = newrex;
2761 +      codep++;
2762 +    }
2763 +}
2764 +
2765 +/* Return the name of the prefix byte PREF, or NULL if PREF is not a
2766 +   prefix byte.  */
2767 +
2768 +static const char *
2769 +prefix_name (int pref, int sizeflag)
2770 +{
2771 +  switch (pref)
2772 +    {
2773 +    /* REX prefixes family.  */
2774 +    case 0x40:
2775 +      return "rex";
2776 +    case 0x41:
2777 +      return "rexZ";
2778 +    case 0x42:
2779 +      return "rexY";
2780 +    case 0x43:
2781 +      return "rexYZ";
2782 +    case 0x44:
2783 +      return "rexX";
2784 +    case 0x45:
2785 +      return "rexXZ";
2786 +    case 0x46:
2787 +      return "rexXY";
2788 +    case 0x47:
2789 +      return "rexXYZ";
2790 +    case 0x48:
2791 +      return "rex64";
2792 +    case 0x49:
2793 +      return "rex64Z";
2794 +    case 0x4a:
2795 +      return "rex64Y";
2796 +    case 0x4b:
2797 +      return "rex64YZ";
2798 +    case 0x4c:
2799 +      return "rex64X";
2800 +    case 0x4d:
2801 +      return "rex64XZ";
2802 +    case 0x4e:
2803 +      return "rex64XY";
2804 +    case 0x4f:
2805 +      return "rex64XYZ";
2806 +    case 0xf3:
2807 +      return "repz";
2808 +    case 0xf2:
2809 +      return "repnz";
2810 +    case 0xf0:
2811 +      return "lock";
2812 +    case 0x2e:
2813 +      return "cs";
2814 +    case 0x36:
2815 +      return "ss";
2816 +    case 0x3e:
2817 +      return "ds";
2818 +    case 0x26:
2819 +      return "es";
2820 +    case 0x64:
2821 +      return "fs";
2822 +    case 0x65:
2823 +      return "gs";
2824 +    case 0x66:
2825 +      return (sizeflag & DFLAG) ? "data16" : "data32";
2826 +    case 0x67:
2827 +      if (mode_64bit)
2828 +       return (sizeflag & AFLAG) ? "addr32" : "addr64";
2829 +      else
2830 +       return (sizeflag & AFLAG) ? "addr16" : "addr32";
2831 +    case FWAIT_OPCODE:
2832 +      return "fwait";
2833 +    default:
2834 +      return NULL;
2835 +    }
2836 +}
2837 +
2838 +static char op1out[100], op2out[100], op3out[100];
2839 +static int op_ad, op_index[3];
2840 +static int two_source_ops;
2841 +static bfd_vma op_address[3];
2842 +static bfd_vma op_riprel[3];
2843 +static bfd_vma start_pc;
2844 +\f
2845 +/*
2846 + *   On the 386's of 1988, the maximum length of an instruction is 15 bytes.
2847 + *   (see topic "Redundant prefixes" in the "Differences from 8086"
2848 + *   section of the "Virtual 8086 Mode" chapter.)
2849 + * 'pc' should be the address of this instruction, it will
2850 + *   be used to print the target address if this is a relative jump or call
2851 + * The function returns the length of this instruction in bytes.
2852 + */
2853 +
2854 +static char intel_syntax;
2855 +static char open_char;
2856 +static char close_char;
2857 +static char separator_char;
2858 +static char scale_char;
2859 +
2860 +/* Here for backwards compatibility.  When gdb stops using
2861 +   print_insn_i386_att and print_insn_i386_intel these functions can
2862 +   disappear, and print_insn_i386 be merged into print_insn.  */
2863 +int
2864 +print_insn_i386_att (bfd_vma pc, disassemble_info *info)
2865 +{
2866 +  intel_syntax = 0;
2867 +
2868 +  return print_insn (pc, info);
2869 +}
2870 +
2871 +int
2872 +print_insn_i386_intel (bfd_vma pc, disassemble_info *info)
2873 +{
2874 +  intel_syntax = 1;
2875 +
2876 +  return print_insn (pc, info);
2877 +}
2878 +
2879 +int
2880 +print_insn_i386 (bfd_vma pc, disassemble_info *info)
2881 +{
2882 +  intel_syntax = -1;
2883 +
2884 +  return print_insn (pc, info);
2885 +}
2886 +
2887 +static int
2888 +print_insn (bfd_vma pc, disassemble_info *info)
2889 +{
2890 +  const struct dis386 *dp;
2891 +  int i;
2892 +  char *first, *second, *third;
2893 +  int needcomma;
2894 +  unsigned char uses_SSE_prefix, uses_LOCK_prefix;
2895 +  int sizeflag;
2896 +  const char *p;
2897 +  struct dis_private priv;
2898 +
2899 +  mode_64bit = (info->mach == bfd_mach_x86_64_intel_syntax
2900 +               || info->mach == bfd_mach_x86_64);
2901 +
2902 +  if (intel_syntax == (char) -1)
2903 +    intel_syntax = (info->mach == bfd_mach_i386_i386_intel_syntax
2904 +                   || info->mach == bfd_mach_x86_64_intel_syntax);
2905 +
2906 +  if (info->mach == bfd_mach_i386_i386
2907 +      || info->mach == bfd_mach_x86_64
2908 +      || info->mach == bfd_mach_i386_i386_intel_syntax
2909 +      || info->mach == bfd_mach_x86_64_intel_syntax)
2910 +    priv.orig_sizeflag = AFLAG | DFLAG;
2911 +  else if (info->mach == bfd_mach_i386_i8086)
2912 +    priv.orig_sizeflag = 0;
2913 +  else
2914 +    abort ();
2915 +
2916 +  for (p = info->disassembler_options; p != NULL; )
2917 +    {
2918 +      if (strncmp (p, "x86-64", 6) == 0)
2919 +       {
2920 +         mode_64bit = 1;
2921 +         priv.orig_sizeflag = AFLAG | DFLAG;
2922 +       }
2923 +      else if (strncmp (p, "i386", 4) == 0)
2924 +       {
2925 +         mode_64bit = 0;
2926 +         priv.orig_sizeflag = AFLAG | DFLAG;
2927 +       }
2928 +      else if (strncmp (p, "i8086", 5) == 0)
2929 +       {
2930 +         mode_64bit = 0;
2931 +         priv.orig_sizeflag = 0;
2932 +       }
2933 +      else if (strncmp (p, "intel", 5) == 0)
2934 +       {
2935 +         intel_syntax = 1;
2936 +       }
2937 +      else if (strncmp (p, "att", 3) == 0)
2938 +       {
2939 +         intel_syntax = 0;
2940 +       }
2941 +      else if (strncmp (p, "addr", 4) == 0)
2942 +       {
2943 +         if (p[4] == '1' && p[5] == '6')
2944 +           priv.orig_sizeflag &= ~AFLAG;
2945 +         else if (p[4] == '3' && p[5] == '2')
2946 +           priv.orig_sizeflag |= AFLAG;
2947 +       }
2948 +      else if (strncmp (p, "data", 4) == 0)
2949 +       {
2950 +         if (p[4] == '1' && p[5] == '6')
2951 +           priv.orig_sizeflag &= ~DFLAG;
2952 +         else if (p[4] == '3' && p[5] == '2')
2953 +           priv.orig_sizeflag |= DFLAG;
2954 +       }
2955 +      else if (strncmp (p, "suffix", 6) == 0)
2956 +       priv.orig_sizeflag |= SUFFIX_ALWAYS;
2957 +
2958 +      p = strchr (p, ',');
2959 +      if (p != NULL)
2960 +       p++;
2961 +    }
2962 +
2963 +  if (intel_syntax)
2964 +    {
2965 +      names64 = intel_names64;
2966 +      names32 = intel_names32;
2967 +      names16 = intel_names16;
2968 +      names8 = intel_names8;
2969 +      names8rex = intel_names8rex;
2970 +      names_seg = intel_names_seg;
2971 +      index16 = intel_index16;
2972 +      open_char = '[';
2973 +      close_char = ']';
2974 +      separator_char = '+';
2975 +      scale_char = '*';
2976 +    }
2977 +  else
2978 +    {
2979 +      names64 = att_names64;
2980 +      names32 = att_names32;
2981 +      names16 = att_names16;
2982 +      names8 = att_names8;
2983 +      names8rex = att_names8rex;
2984 +      names_seg = att_names_seg;
2985 +      index16 = att_index16;
2986 +      open_char = '(';
2987 +      close_char =  ')';
2988 +      separator_char = ',';
2989 +      scale_char = ',';
2990 +    }
2991 +
2992 +  /* The output looks better if we put 7 bytes on a line, since that
2993 +     puts most long word instructions on a single line.  */
2994 +  info->bytes_per_line = 7;
2995 +
2996 +  info->private_data = &priv;
2997 +  priv.max_fetched = priv.the_buffer;
2998 +  priv.insn_start = pc;
2999 +
3000 +  obuf[0] = 0;
3001 +  op1out[0] = 0;
3002 +  op2out[0] = 0;
3003 +  op3out[0] = 0;
3004 +
3005 +  op_index[0] = op_index[1] = op_index[2] = -1;
3006 +
3007 +  the_info = info;
3008 +  start_pc = pc;
3009 +  start_codep = priv.the_buffer;
3010 +  codep = priv.the_buffer;
3011 +
3012 +#ifndef __KERNEL__
3013 +  if (setjmp (priv.bailout) != 0)
3014 +    {
3015 +      const char *name;
3016 +
3017 +      /* Getting here means we tried for data but didn't get it.  That
3018 +        means we have an incomplete instruction of some sort.  Just
3019 +        print the first byte as a prefix or a .byte pseudo-op.  */
3020 +      if (codep > priv.the_buffer)
3021 +       {
3022 +         name = prefix_name (priv.the_buffer[0], priv.orig_sizeflag);
3023 +         if (name != NULL)
3024 +           (*info->fprintf_func) (info->stream, "%s", name);
3025 +         else
3026 +           {
3027 +             /* Just print the first byte as a .byte instruction.  */
3028 +             (*info->fprintf_func) (info->stream, ".byte 0x%x",
3029 +                                    (unsigned int) priv.the_buffer[0]);
3030 +           }
3031 +
3032 +         return 1;
3033 +       }
3034 +
3035 +      return -1;
3036 +    }
3037 +#endif /* __KERNEL__ */
3038 +
3039 +  obufp = obuf;
3040 +  ckprefix ();
3041 +
3042 +  insn_codep = codep;
3043 +  sizeflag = priv.orig_sizeflag;
3044 +
3045 +  FETCH_DATA (info, codep + 1);
3046 +  two_source_ops = (*codep == 0x62) || (*codep == 0xc8);
3047 +
3048 +  if ((prefixes & PREFIX_FWAIT)
3049 +      && ((*codep < 0xd8) || (*codep > 0xdf)))
3050 +    {
3051 +      const char *name;
3052 +
3053 +      /* fwait not followed by floating point instruction.  Print the
3054 +        first prefix, which is probably fwait itself.  */
3055 +      name = prefix_name (priv.the_buffer[0], priv.orig_sizeflag);
3056 +      if (name == NULL)
3057 +       name = INTERNAL_DISASSEMBLER_ERROR;
3058 +      (*info->fprintf_func) (info->stream, "%s", name);
3059 +      return 1;
3060 +    }
3061 +
3062 +  if (*codep == 0x0f)
3063 +    {
3064 +      FETCH_DATA (info, codep + 2);
3065 +      dp = &dis386_twobyte[*++codep];
3066 +      need_modrm = twobyte_has_modrm[*codep];
3067 +      uses_SSE_prefix = twobyte_uses_SSE_prefix[*codep];
3068 +      uses_LOCK_prefix = (*codep & ~0x02) == 0x20;
3069 +    }
3070 +  else
3071 +    {
3072 +      dp = &dis386[*codep];
3073 +      need_modrm = onebyte_has_modrm[*codep];
3074 +      uses_SSE_prefix = 0;
3075 +      uses_LOCK_prefix = 0;
3076 +    }
3077 +  codep++;
3078 +
3079 +  if (!uses_SSE_prefix && (prefixes & PREFIX_REPZ))
3080 +    {
3081 +      oappend ("repz ");
3082 +      used_prefixes |= PREFIX_REPZ;
3083 +    }
3084 +  if (!uses_SSE_prefix && (prefixes & PREFIX_REPNZ))
3085 +    {
3086 +      oappend ("repnz ");
3087 +      used_prefixes |= PREFIX_REPNZ;
3088 +    }
3089 +  if (!uses_LOCK_prefix && (prefixes & PREFIX_LOCK))
3090 +    {
3091 +      oappend ("lock ");
3092 +      used_prefixes |= PREFIX_LOCK;
3093 +    }
3094 +
3095 +  if (prefixes & PREFIX_ADDR)
3096 +    {
3097 +      sizeflag ^= AFLAG;
3098 +      if (dp->bytemode3 != loop_jcxz_mode || intel_syntax)
3099 +       {
3100 +         if ((sizeflag & AFLAG) || mode_64bit)
3101 +           oappend ("addr32 ");
3102 +         else
3103 +           oappend ("addr16 ");
3104 +         used_prefixes |= PREFIX_ADDR;
3105 +       }
3106 +    }
3107 +
3108 +  if (!uses_SSE_prefix && (prefixes & PREFIX_DATA))
3109 +    {
3110 +      sizeflag ^= DFLAG;
3111 +      if (dp->bytemode3 == cond_jump_mode
3112 +         && dp->bytemode1 == v_mode
3113 +         && !intel_syntax)
3114 +       {
3115 +         if (sizeflag & DFLAG)
3116 +           oappend ("data32 ");
3117 +         else
3118 +           oappend ("data16 ");
3119 +         used_prefixes |= PREFIX_DATA;
3120 +       }
3121 +    }
3122 +
3123 +  if (need_modrm)
3124 +    {
3125 +      FETCH_DATA (info, codep + 1);
3126 +      mod = (*codep >> 6) & 3;
3127 +      reg = (*codep >> 3) & 7;
3128 +      rm = *codep & 7;
3129 +    }
3130 +
3131 +  if (dp->name == NULL && dp->bytemode1 == FLOATCODE)
3132 +    {
3133 +      dofloat (sizeflag);
3134 +    }
3135 +  else
3136 +    {
3137 +      int index;
3138 +      if (dp->name == NULL)
3139 +       {
3140 +         switch (dp->bytemode1)
3141 +           {
3142 +           case USE_GROUPS:
3143 +             dp = &grps[dp->bytemode2][reg];
3144 +             break;
3145 +
3146 +           case USE_PREFIX_USER_TABLE:
3147 +             index = 0;
3148 +             used_prefixes |= (prefixes & PREFIX_REPZ);
3149 +             if (prefixes & PREFIX_REPZ)
3150 +               index = 1;
3151 +             else
3152 +               {
3153 +                 used_prefixes |= (prefixes & PREFIX_DATA);
3154 +                 if (prefixes & PREFIX_DATA)
3155 +                   index = 2;
3156 +                 else
3157 +                   {
3158 +                     used_prefixes |= (prefixes & PREFIX_REPNZ);
3159 +                     if (prefixes & PREFIX_REPNZ)
3160 +                       index = 3;
3161 +                   }
3162 +               }
3163 +             dp = &prefix_user_table[dp->bytemode2][index];
3164 +             break;
3165 +
3166 +           case X86_64_SPECIAL:
3167 +             dp = &x86_64_table[dp->bytemode2][mode_64bit];
3168 +             break;
3169 +
3170 +           default:
3171 +             oappend (INTERNAL_DISASSEMBLER_ERROR);
3172 +             break;
3173 +           }
3174 +       }
3175 +
3176 +      if (putop (dp->name, sizeflag) == 0)
3177 +       {
3178 +         obufp = op1out;
3179 +         op_ad = 2;
3180 +         if (dp->op1)
3181 +           (*dp->op1) (dp->bytemode1, sizeflag);
3182 +
3183 +         obufp = op2out;
3184 +         op_ad = 1;
3185 +         if (dp->op2)
3186 +           (*dp->op2) (dp->bytemode2, sizeflag);
3187 +
3188 +         obufp = op3out;
3189 +         op_ad = 0;
3190 +         if (dp->op3)
3191 +           (*dp->op3) (dp->bytemode3, sizeflag);
3192 +       }
3193 +    }
3194 +
3195 +  /* See if any prefixes were not used.  If so, print the first one
3196 +     separately.  If we don't do this, we'll wind up printing an
3197 +     instruction stream which does not precisely correspond to the
3198 +     bytes we are disassembling.  */
3199 +  if ((prefixes & ~used_prefixes) != 0)
3200 +    {
3201 +      const char *name;
3202 +
3203 +      name = prefix_name (priv.the_buffer[0], priv.orig_sizeflag);
3204 +      if (name == NULL)
3205 +       name = INTERNAL_DISASSEMBLER_ERROR;
3206 +      (*info->fprintf_func) (info->stream, "%s", name);
3207 +      return 1;
3208 +    }
3209 +  if (rex & ~rex_used)
3210 +    {
3211 +      const char *name;
3212 +      name = prefix_name (rex | 0x40, priv.orig_sizeflag);
3213 +      if (name == NULL)
3214 +       name = INTERNAL_DISASSEMBLER_ERROR;
3215 +      (*info->fprintf_func) (info->stream, "%s ", name);
3216 +    }
3217 +
3218 +  obufp = obuf + strlen (obuf);
3219 +  for (i = strlen (obuf); i < 6; i++)
3220 +    oappend (" ");
3221 +  oappend (" ");
3222 +  (*info->fprintf_func) (info->stream, "%s", obuf);
3223 +
3224 +  /* The enter and bound instructions are printed with operands in the same
3225 +     order as the intel book; everything else is printed in reverse order.  */
3226 +  if (intel_syntax || two_source_ops)
3227 +    {
3228 +      first = op1out;
3229 +      second = op2out;
3230 +      third = op3out;
3231 +      op_ad = op_index[0];
3232 +      op_index[0] = op_index[2];
3233 +      op_index[2] = op_ad;
3234 +    }
3235 +  else
3236 +    {
3237 +      first = op3out;
3238 +      second = op2out;
3239 +      third = op1out;
3240 +    }
3241 +  needcomma = 0;
3242 +  if (*first)
3243 +    {
3244 +      if (op_index[0] != -1 && !op_riprel[0])
3245 +       (*info->print_address_func) ((bfd_vma) op_address[op_index[0]], info);
3246 +      else
3247 +       (*info->fprintf_func) (info->stream, "%s", first);
3248 +      needcomma = 1;
3249 +    }
3250 +  if (*second)
3251 +    {
3252 +      if (needcomma)
3253 +       (*info->fprintf_func) (info->stream, ",");
3254 +      if (op_index[1] != -1 && !op_riprel[1])
3255 +       (*info->print_address_func) ((bfd_vma) op_address[op_index[1]], info);
3256 +      else
3257 +       (*info->fprintf_func) (info->stream, "%s", second);
3258 +      needcomma = 1;
3259 +    }
3260 +  if (*third)
3261 +    {
3262 +      if (needcomma)
3263 +       (*info->fprintf_func) (info->stream, ",");
3264 +      if (op_index[2] != -1 && !op_riprel[2])
3265 +       (*info->print_address_func) ((bfd_vma) op_address[op_index[2]], info);
3266 +      else
3267 +       (*info->fprintf_func) (info->stream, "%s", third);
3268 +    }
3269 +  for (i = 0; i < 3; i++)
3270 +    if (op_index[i] != -1 && op_riprel[i])
3271 +      {
3272 +       (*info->fprintf_func) (info->stream, "        # ");
3273 +       (*info->print_address_func) ((bfd_vma) (start_pc + codep - start_codep
3274 +                                               + op_address[op_index[i]]), info);
3275 +      }
3276 +  return codep - priv.the_buffer;
3277 +}
3278 +
3279 +static const char *float_mem[] = {
3280 +  /* d8 */
3281 +  "fadd{s||s|}",
3282 +  "fmul{s||s|}",
3283 +  "fcom{s||s|}",
3284 +  "fcomp{s||s|}",
3285 +  "fsub{s||s|}",
3286 +  "fsubr{s||s|}",
3287 +  "fdiv{s||s|}",
3288 +  "fdivr{s||s|}",
3289 +  /* d9 */
3290 +  "fld{s||s|}",
3291 +  "(bad)",
3292 +  "fst{s||s|}",
3293 +  "fstp{s||s|}",
3294 +  "fldenvIC",
3295 +  "fldcw",
3296 +  "fNstenvIC",
3297 +  "fNstcw",
3298 +  /* da */
3299 +  "fiadd{l||l|}",
3300 +  "fimul{l||l|}",
3301 +  "ficom{l||l|}",
3302 +  "ficomp{l||l|}",
3303 +  "fisub{l||l|}",
3304 +  "fisubr{l||l|}",
3305 +  "fidiv{l||l|}",
3306 +  "fidivr{l||l|}",
3307 +  /* db */
3308 +  "fild{l||l|}",
3309 +  "fisttp{l||l|}",
3310 +  "fist{l||l|}",
3311 +  "fistp{l||l|}",
3312 +  "(bad)",
3313 +  "fld{t||t|}",
3314 +  "(bad)",
3315 +  "fstp{t||t|}",
3316 +  /* dc */
3317 +  "fadd{l||l|}",
3318 +  "fmul{l||l|}",
3319 +  "fcom{l||l|}",
3320 +  "fcomp{l||l|}",
3321 +  "fsub{l||l|}",
3322 +  "fsubr{l||l|}",
3323 +  "fdiv{l||l|}",
3324 +  "fdivr{l||l|}",
3325 +  /* dd */
3326 +  "fld{l||l|}",
3327 +  "fisttp{ll||ll|}",
3328 +  "fst{l||l|}",
3329 +  "fstp{l||l|}",
3330 +  "frstorIC",
3331 +  "(bad)",
3332 +  "fNsaveIC",
3333 +  "fNstsw",
3334 +  /* de */
3335 +  "fiadd",
3336 +  "fimul",
3337 +  "ficom",
3338 +  "ficomp",
3339 +  "fisub",
3340 +  "fisubr",
3341 +  "fidiv",
3342 +  "fidivr",
3343 +  /* df */
3344 +  "fild",
3345 +  "fisttp",
3346 +  "fist",
3347 +  "fistp",
3348 +  "fbld",
3349 +  "fild{ll||ll|}",
3350 +  "fbstp",
3351 +  "fistp{ll||ll|}",
3352 +};
3353 +
3354 +static const unsigned char float_mem_mode[] = {
3355 +  /* d8 */
3356 +  d_mode,
3357 +  d_mode,
3358 +  d_mode,
3359 +  d_mode,
3360 +  d_mode,
3361 +  d_mode,
3362 +  d_mode,
3363 +  d_mode,
3364 +  /* d9 */
3365 +  d_mode,
3366 +  0,
3367 +  d_mode,
3368 +  d_mode,
3369 +  0,
3370 +  w_mode,
3371 +  0,
3372 +  w_mode,
3373 +  /* da */
3374 +  d_mode,
3375 +  d_mode,
3376 +  d_mode,
3377 +  d_mode,
3378 +  d_mode,
3379 +  d_mode,
3380 +  d_mode,
3381 +  d_mode,
3382 +  /* db */
3383 +  d_mode,
3384 +  d_mode,
3385 +  d_mode,
3386 +  d_mode,
3387 +  0,
3388 +  t_mode,
3389 +  0,
3390 +  t_mode,
3391 +  /* dc */
3392 +  q_mode,
3393 +  q_mode,
3394 +  q_mode,
3395 +  q_mode,
3396 +  q_mode,
3397 +  q_mode,
3398 +  q_mode,
3399 +  q_mode,
3400 +  /* dd */
3401 +  q_mode,
3402 +  q_mode,
3403 +  q_mode,
3404 +  q_mode,
3405 +  0,
3406 +  0,
3407 +  0,
3408 +  w_mode,
3409 +  /* de */
3410 +  w_mode,
3411 +  w_mode,
3412 +  w_mode,
3413 +  w_mode,
3414 +  w_mode,
3415 +  w_mode,
3416 +  w_mode,
3417 +  w_mode,
3418 +  /* df */
3419 +  w_mode,
3420 +  w_mode,
3421 +  w_mode,
3422 +  w_mode,
3423 +  t_mode,
3424 +  q_mode,
3425 +  t_mode,
3426 +  q_mode
3427 +};
3428 +
3429 +#define ST OP_ST, 0
3430 +#define STi OP_STi, 0
3431 +
3432 +#define FGRPd9_2 NULL, NULL, 0, NULL, 0, NULL, 0
3433 +#define FGRPd9_4 NULL, NULL, 1, NULL, 0, NULL, 0
3434 +#define FGRPd9_5 NULL, NULL, 2, NULL, 0, NULL, 0
3435 +#define FGRPd9_6 NULL, NULL, 3, NULL, 0, NULL, 0
3436 +#define FGRPd9_7 NULL, NULL, 4, NULL, 0, NULL, 0
3437 +#define FGRPda_5 NULL, NULL, 5, NULL, 0, NULL, 0
3438 +#define FGRPdb_4 NULL, NULL, 6, NULL, 0, NULL, 0
3439 +#define FGRPde_3 NULL, NULL, 7, NULL, 0, NULL, 0
3440 +#define FGRPdf_4 NULL, NULL, 8, NULL, 0, NULL, 0
3441 +
3442 +static const struct dis386 float_reg[][8] = {
3443 +  /* d8 */
3444 +  {
3445 +    { "fadd",  ST, STi, XX },
3446 +    { "fmul",  ST, STi, XX },
3447 +    { "fcom",  STi, XX, XX },
3448 +    { "fcomp", STi, XX, XX },
3449 +    { "fsub",  ST, STi, XX },
3450 +    { "fsubr", ST, STi, XX },
3451 +    { "fdiv",  ST, STi, XX },
3452 +    { "fdivr", ST, STi, XX },
3453 +  },
3454 +  /* d9 */
3455 +  {
3456 +    { "fld",   STi, XX, XX },
3457 +    { "fxch",  STi, XX, XX },
3458 +    { FGRPd9_2 },
3459 +    { "(bad)", XX, XX, XX },
3460 +    { FGRPd9_4 },
3461 +    { FGRPd9_5 },
3462 +    { FGRPd9_6 },
3463 +    { FGRPd9_7 },
3464 +  },
3465 +  /* da */
3466 +  {
3467 +    { "fcmovb",        ST, STi, XX },
3468 +    { "fcmove",        ST, STi, XX },
3469 +    { "fcmovbe",ST, STi, XX },
3470 +    { "fcmovu",        ST, STi, XX },
3471 +    { "(bad)", XX, XX, XX },
3472 +    { FGRPda_5 },
3473 +    { "(bad)", XX, XX, XX },
3474 +    { "(bad)", XX, XX, XX },
3475 +  },
3476 +  /* db */
3477 +  {
3478 +    { "fcmovnb",ST, STi, XX },
3479 +    { "fcmovne",ST, STi, XX },
3480 +    { "fcmovnbe",ST, STi, XX },
3481 +    { "fcmovnu",ST, STi, XX },
3482 +    { FGRPdb_4 },
3483 +    { "fucomi",        ST, STi, XX },
3484 +    { "fcomi", ST, STi, XX },
3485 +    { "(bad)", XX, XX, XX },
3486 +  },
3487 +  /* dc */
3488 +  {
3489 +    { "fadd",  STi, ST, XX },
3490 +    { "fmul",  STi, ST, XX },
3491 +    { "(bad)", XX, XX, XX },
3492 +    { "(bad)", XX, XX, XX },
3493 +#if UNIXWARE_COMPAT
3494 +    { "fsub",  STi, ST, XX },
3495 +    { "fsubr", STi, ST, XX },
3496 +    { "fdiv",  STi, ST, XX },
3497 +    { "fdivr", STi, ST, XX },
3498 +#else
3499 +    { "fsubr", STi, ST, XX },
3500 +    { "fsub",  STi, ST, XX },
3501 +    { "fdivr", STi, ST, XX },
3502 +    { "fdiv",  STi, ST, XX },
3503 +#endif
3504 +  },
3505 +  /* dd */
3506 +  {
3507 +    { "ffree", STi, XX, XX },
3508 +    { "(bad)", XX, XX, XX },
3509 +    { "fst",   STi, XX, XX },
3510 +    { "fstp",  STi, XX, XX },
3511 +    { "fucom", STi, XX, XX },
3512 +    { "fucomp",        STi, XX, XX },
3513 +    { "(bad)", XX, XX, XX },
3514 +    { "(bad)", XX, XX, XX },
3515 +  },
3516 +  /* de */
3517 +  {
3518 +    { "faddp", STi, ST, XX },
3519 +    { "fmulp", STi, ST, XX },
3520 +    { "(bad)", XX, XX, XX },
3521 +    { FGRPde_3 },
3522 +#if UNIXWARE_COMPAT
3523 +    { "fsubp", STi, ST, XX },
3524 +    { "fsubrp",        STi, ST, XX },
3525 +    { "fdivp", STi, ST, XX },
3526 +    { "fdivrp",        STi, ST, XX },
3527 +#else
3528 +    { "fsubrp",        STi, ST, XX },
3529 +    { "fsubp", STi, ST, XX },
3530 +    { "fdivrp",        STi, ST, XX },
3531 +    { "fdivp", STi, ST, XX },
3532 +#endif
3533 +  },
3534 +  /* df */
3535 +  {
3536 +    { "ffreep",        STi, XX, XX },
3537 +    { "(bad)", XX, XX, XX },
3538 +    { "(bad)", XX, XX, XX },
3539 +    { "(bad)", XX, XX, XX },
3540 +    { FGRPdf_4 },
3541 +    { "fucomip",ST, STi, XX },
3542 +    { "fcomip", ST, STi, XX },
3543 +    { "(bad)", XX, XX, XX },
3544 +  },
3545 +};
3546 +
3547 +static char *fgrps[][8] = {
3548 +  /* d9_2  0 */
3549 +  {
3550 +    "fnop","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
3551 +  },
3552 +
3553 +  /* d9_4  1 */
3554 +  {
3555 +    "fchs","fabs","(bad)","(bad)","ftst","fxam","(bad)","(bad)",
3556 +  },
3557 +
3558 +  /* d9_5  2 */
3559 +  {
3560 +    "fld1","fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz","(bad)",
3561 +  },
3562 +
3563 +  /* d9_6  3 */
3564 +  {
3565 +    "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp","fincstp",
3566 +  },
3567 +
3568 +  /* d9_7  4 */
3569 +  {
3570 +    "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos",
3571 +  },
3572 +
3573 +  /* da_5  5 */
3574 +  {
3575 +    "(bad)","fucompp","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
3576 +  },
3577 +
3578 +  /* db_4  6 */
3579 +  {
3580 +    "feni(287 only)","fdisi(287 only)","fNclex","fNinit",
3581 +    "fNsetpm(287 only)","(bad)","(bad)","(bad)",
3582 +  },
3583 +
3584 +  /* de_3  7 */
3585 +  {
3586 +    "(bad)","fcompp","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
3587 +  },
3588 +
3589 +  /* df_4  8 */
3590 +  {
3591 +    "fNstsw","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
3592 +  },
3593 +};
3594 +
3595 +static void
3596 +dofloat (int sizeflag)
3597 +{
3598 +  const struct dis386 *dp;
3599 +  unsigned char floatop;
3600 +
3601 +  floatop = codep[-1];
3602 +
3603 +  if (mod != 3)
3604 +    {
3605 +      int fp_indx = (floatop - 0xd8) * 8 + reg;
3606 +
3607 +      putop (float_mem[fp_indx], sizeflag);
3608 +      obufp = op1out;
3609 +      OP_E (float_mem_mode[fp_indx], sizeflag);
3610 +      return;
3611 +    }
3612 +  /* Skip mod/rm byte.  */
3613 +  MODRM_CHECK;
3614 +  codep++;
3615 +
3616 +  dp = &float_reg[floatop - 0xd8][reg];
3617 +  if (dp->name == NULL)
3618 +    {
3619 +      putop (fgrps[dp->bytemode1][rm], sizeflag);
3620 +
3621 +      /* Instruction fnstsw is only one with strange arg.  */
3622 +      if (floatop == 0xdf && codep[-1] == 0xe0)
3623 +       strcpy (op1out, names16[0]);
3624 +    }
3625 +  else
3626 +    {
3627 +      putop (dp->name, sizeflag);
3628 +
3629 +      obufp = op1out;
3630 +      if (dp->op1)
3631 +       (*dp->op1) (dp->bytemode1, sizeflag);
3632 +      obufp = op2out;
3633 +      if (dp->op2)
3634 +       (*dp->op2) (dp->bytemode2, sizeflag);
3635 +    }
3636 +}
3637 +
3638 +static void
3639 +OP_ST (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
3640 +{
3641 +  oappend ("%st");
3642 +}
3643 +
3644 +static void
3645 +OP_STi (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
3646 +{
3647 +  sprintf (scratchbuf, "%%st(%d)", rm);
3648 +  oappend (scratchbuf + intel_syntax);
3649 +}
3650 +
3651 +/* Capital letters in template are macros.  */
3652 +static int
3653 +putop (const char *template, int sizeflag)
3654 +{
3655 +  const char *p;
3656 +  int alt = 0;
3657 +
3658 +  for (p = template; *p; p++)
3659 +    {
3660 +      switch (*p)
3661 +       {
3662 +       default:
3663 +         *obufp++ = *p;
3664 +         break;
3665 +       case '{':
3666 +         alt = 0;
3667 +         if (intel_syntax)
3668 +           alt += 1;
3669 +         if (mode_64bit)
3670 +           alt += 2;
3671 +         while (alt != 0)
3672 +           {
3673 +             while (*++p != '|')
3674 +               {
3675 +                 if (*p == '}')
3676 +                   {
3677 +                     /* Alternative not valid.  */
3678 +                     strcpy (obuf, "(bad)");
3679 +                     obufp = obuf + 5;
3680 +                     return 1;
3681 +                   }
3682 +                 else if (*p == '\0')
3683 +                   abort ();
3684 +               }
3685 +             alt--;
3686 +           }
3687 +         /* Fall through.  */
3688 +       case 'I':
3689 +         alt = 1;
3690 +         continue;
3691 +       case '|':
3692 +         while (*++p != '}')
3693 +           {
3694 +             if (*p == '\0')
3695 +               abort ();
3696 +           }
3697 +         break;
3698 +       case '}':
3699 +         break;
3700 +       case 'A':
3701 +         if (intel_syntax)
3702 +           break;
3703 +         if (mod != 3 || (sizeflag & SUFFIX_ALWAYS))
3704 +           *obufp++ = 'b';
3705 +         break;
3706 +       case 'B':
3707 +         if (intel_syntax)
3708 +           break;
3709 +         if (sizeflag & SUFFIX_ALWAYS)
3710 +           *obufp++ = 'b';
3711 +         break;
3712 +       case 'C':
3713 +         if (intel_syntax && !alt)
3714 +           break;
3715 +         if ((prefixes & PREFIX_DATA) || (sizeflag & SUFFIX_ALWAYS))
3716 +           {
3717 +             if (sizeflag & DFLAG)
3718 +               *obufp++ = intel_syntax ? 'd' : 'l';
3719 +             else
3720 +               *obufp++ = intel_syntax ? 'w' : 's';
3721 +             used_prefixes |= (prefixes & PREFIX_DATA);
3722 +           }
3723 +         break;
3724 +       case 'E':               /* For jcxz/jecxz */
3725 +         if (mode_64bit)
3726 +           {
3727 +             if (sizeflag & AFLAG)
3728 +               *obufp++ = 'r';
3729 +             else
3730 +               *obufp++ = 'e';
3731 +           }
3732 +         else
3733 +           if (sizeflag & AFLAG)
3734 +             *obufp++ = 'e';
3735 +         used_prefixes |= (prefixes & PREFIX_ADDR);
3736 +         break;
3737 +       case 'F':
3738 +         if (intel_syntax)
3739 +           break;
3740 +         if ((prefixes & PREFIX_ADDR) || (sizeflag & SUFFIX_ALWAYS))
3741 +           {
3742 +             if (sizeflag & AFLAG)
3743 +               *obufp++ = mode_64bit ? 'q' : 'l';
3744 +             else
3745 +               *obufp++ = mode_64bit ? 'l' : 'w';
3746 +             used_prefixes |= (prefixes & PREFIX_ADDR);
3747 +           }
3748 +         break;
3749 +       case 'H':
3750 +         if (intel_syntax)
3751 +           break;
3752 +         if ((prefixes & (PREFIX_CS | PREFIX_DS)) == PREFIX_CS
3753 +             || (prefixes & (PREFIX_CS | PREFIX_DS)) == PREFIX_DS)
3754 +           {
3755 +             used_prefixes |= prefixes & (PREFIX_CS | PREFIX_DS);
3756 +             *obufp++ = ',';
3757 +             *obufp++ = 'p';
3758 +             if (prefixes & PREFIX_DS)
3759 +               *obufp++ = 't';
3760 +             else
3761 +               *obufp++ = 'n';
3762 +           }
3763 +         break;
3764 +       case 'J':
3765 +         if (intel_syntax)
3766 +           break;
3767 +         *obufp++ = 'l';
3768 +         break;
3769 +       case 'L':
3770 +         if (intel_syntax)
3771 +           break;
3772 +         if (sizeflag & SUFFIX_ALWAYS)
3773 +           *obufp++ = 'l';
3774 +         break;
3775 +       case 'N':
3776 +         if ((prefixes & PREFIX_FWAIT) == 0)
3777 +           *obufp++ = 'n';
3778 +         else
3779 +           used_prefixes |= PREFIX_FWAIT;
3780 +         break;
3781 +       case 'O':
3782 +         USED_REX (REX_MODE64);
3783 +         if (rex & REX_MODE64)
3784 +           *obufp++ = 'o';
3785 +         else
3786 +           *obufp++ = 'd';
3787 +         break;
3788 +       case 'T':
3789 +         if (intel_syntax)
3790 +           break;
3791 +         if (mode_64bit)
3792 +           {
3793 +             *obufp++ = 'q';
3794 +             break;
3795 +           }
3796 +         /* Fall through.  */
3797 +       case 'P':
3798 +         if (intel_syntax)
3799 +           break;
3800 +         if ((prefixes & PREFIX_DATA)
3801 +             || (rex & REX_MODE64)
3802 +             || (sizeflag & SUFFIX_ALWAYS))
3803 +           {
3804 +             USED_REX (REX_MODE64);
3805 +             if (rex & REX_MODE64)
3806 +               *obufp++ = 'q';
3807 +             else
3808 +               {
3809 +                  if (sizeflag & DFLAG)
3810 +                     *obufp++ = 'l';
3811 +                  else
3812 +                    *obufp++ = 'w';
3813 +                  used_prefixes |= (prefixes & PREFIX_DATA);
3814 +               }
3815 +           }
3816 +         break;
3817 +       case 'U':
3818 +         if (intel_syntax)
3819 +           break;
3820 +         if (mode_64bit)
3821 +           {
3822 +             *obufp++ = 'q';
3823 +             break;
3824 +           }
3825 +         /* Fall through.  */
3826 +       case 'Q':
3827 +         if (intel_syntax && !alt)
3828 +           break;
3829 +         USED_REX (REX_MODE64);
3830 +         if (mod != 3 || (sizeflag & SUFFIX_ALWAYS))
3831 +           {
3832 +             if (rex & REX_MODE64)
3833 +               *obufp++ = 'q';
3834 +             else
3835 +               {
3836 +                 if (sizeflag & DFLAG)
3837 +                   *obufp++ = intel_syntax ? 'd' : 'l';
3838 +                 else
3839 +                   *obufp++ = 'w';
3840 +                 used_prefixes |= (prefixes & PREFIX_DATA);
3841 +               }
3842 +           }
3843 +         break;
3844 +       case 'R':
3845 +         USED_REX (REX_MODE64);
3846 +         if (intel_syntax)
3847 +           {
3848 +             if (rex & REX_MODE64)
3849 +               {
3850 +                 *obufp++ = 'q';
3851 +                 *obufp++ = 't';
3852 +               }
3853 +             else if (sizeflag & DFLAG)
3854 +               {
3855 +                 *obufp++ = 'd';
3856 +                 *obufp++ = 'q';
3857 +               }
3858 +             else
3859 +               {
3860 +                 *obufp++ = 'w';
3861 +                 *obufp++ = 'd';
3862 +               }
3863 +           }
3864 +         else
3865 +           {
3866 +             if (rex & REX_MODE64)
3867 +               *obufp++ = 'q';
3868 +             else if (sizeflag & DFLAG)
3869 +               *obufp++ = 'l';
3870 +             else
3871 +               *obufp++ = 'w';
3872 +           }
3873 +         if (!(rex & REX_MODE64))
3874 +           used_prefixes |= (prefixes & PREFIX_DATA);
3875 +         break;
3876 +       case 'S':
3877 +         if (intel_syntax)
3878 +           break;
3879 +         if (sizeflag & SUFFIX_ALWAYS)
3880 +           {
3881 +             if (rex & REX_MODE64)
3882 +               *obufp++ = 'q';
3883 +             else
3884 +               {
3885 +                 if (sizeflag & DFLAG)
3886 +                   *obufp++ = 'l';
3887 +                 else
3888 +                   *obufp++ = 'w';
3889 +                 used_prefixes |= (prefixes & PREFIX_DATA);
3890 +               }
3891 +           }
3892 +         break;
3893 +       case 'X':
3894 +         if (prefixes & PREFIX_DATA)
3895 +           *obufp++ = 'd';
3896 +         else
3897 +           *obufp++ = 's';
3898 +         used_prefixes |= (prefixes & PREFIX_DATA);
3899 +         break;
3900 +       case 'Y':
3901 +         if (intel_syntax)
3902 +           break;
3903 +         if (rex & REX_MODE64)
3904 +           {
3905 +             USED_REX (REX_MODE64);
3906 +             *obufp++ = 'q';
3907 +           }
3908 +         break;
3909 +         /* implicit operand size 'l' for i386 or 'q' for x86-64 */
3910 +       case 'W':
3911 +         /* operand size flag for cwtl, cbtw */
3912 +         USED_REX (0);
3913 +         if (rex)
3914 +           *obufp++ = 'l';
3915 +         else if (sizeflag & DFLAG)
3916 +           *obufp++ = 'w';
3917 +         else
3918 +           *obufp++ = 'b';
3919 +         if (intel_syntax)
3920 +           {
3921 +             if (rex)
3922 +               {
3923 +                 *obufp++ = 'q';
3924 +                 *obufp++ = 'e';
3925 +               }
3926 +             if (sizeflag & DFLAG)
3927 +               {
3928 +                 *obufp++ = 'd';
3929 +                 *obufp++ = 'e';
3930 +               }
3931 +             else
3932 +               {
3933 +                 *obufp++ = 'w';
3934 +               }
3935 +           }
3936 +         if (!rex)
3937 +           used_prefixes |= (prefixes & PREFIX_DATA);
3938 +         break;
3939 +       }
3940 +      alt = 0;
3941 +    }
3942 +  *obufp = 0;
3943 +  return 0;
3944 +}
3945 +
3946 +static void
3947 +oappend (const char *s)
3948 +{
3949 +  strcpy (obufp, s);
3950 +  obufp += strlen (s);
3951 +}
3952 +
3953 +static void
3954 +append_seg (void)
3955 +{
3956 +  if (prefixes & PREFIX_CS)
3957 +    {
3958 +      used_prefixes |= PREFIX_CS;
3959 +      oappend ("%cs:" + intel_syntax);
3960 +    }
3961 +  if (prefixes & PREFIX_DS)
3962 +    {
3963 +      used_prefixes |= PREFIX_DS;
3964 +      oappend ("%ds:" + intel_syntax);
3965 +    }
3966 +  if (prefixes & PREFIX_SS)
3967 +    {
3968 +      used_prefixes |= PREFIX_SS;
3969 +      oappend ("%ss:" + intel_syntax);
3970 +    }
3971 +  if (prefixes & PREFIX_ES)
3972 +    {
3973 +      used_prefixes |= PREFIX_ES;
3974 +      oappend ("%es:" + intel_syntax);
3975 +    }
3976 +  if (prefixes & PREFIX_FS)
3977 +    {
3978 +      used_prefixes |= PREFIX_FS;
3979 +      oappend ("%fs:" + intel_syntax);
3980 +    }
3981 +  if (prefixes & PREFIX_GS)
3982 +    {
3983 +      used_prefixes |= PREFIX_GS;
3984 +      oappend ("%gs:" + intel_syntax);
3985 +    }
3986 +}
3987 +
3988 +static void
3989 +OP_indirE (int bytemode, int sizeflag)
3990 +{
3991 +  if (!intel_syntax)
3992 +    oappend ("*");
3993 +  OP_E (bytemode, sizeflag);
3994 +}
3995 +
3996 +static void
3997 +print_operand_value (char *buf, int hex, bfd_vma disp)
3998 +{
3999 +  if (mode_64bit)
4000 +    {
4001 +      if (hex)
4002 +       {
4003 +         char tmp[30];
4004 +         int i;
4005 +         buf[0] = '0';
4006 +         buf[1] = 'x';
4007 +         sprintf_vma (tmp, disp);
4008 +         for (i = 0; tmp[i] == '0' && tmp[i + 1]; i++);
4009 +         strcpy (buf + 2, tmp + i);
4010 +       }
4011 +      else
4012 +       {
4013 +         bfd_signed_vma v = disp;
4014 +         char tmp[30];
4015 +         int i;
4016 +         if (v < 0)
4017 +           {
4018 +             *(buf++) = '-';
4019 +             v = -disp;
4020 +             /* Check for possible overflow on 0x8000000000000000.  */
4021 +             if (v < 0)
4022 +               {
4023 +                 strcpy (buf, "9223372036854775808");
4024 +                 return;
4025 +               }
4026 +           }
4027 +         if (!v)
4028 +           {
4029 +             strcpy (buf, "0");
4030 +             return;
4031 +           }
4032 +
4033 +         i = 0;
4034 +         tmp[29] = 0;
4035 +         while (v)
4036 +           {
4037 +             tmp[28 - i] = (v % 10) + '0';
4038 +             v /= 10;
4039 +             i++;
4040 +           }
4041 +         strcpy (buf, tmp + 29 - i);
4042 +       }
4043 +    }
4044 +  else
4045 +    {
4046 +      if (hex)
4047 +       sprintf (buf, "0x%x", (unsigned int) disp);
4048 +      else
4049 +       sprintf (buf, "%d", (int) disp);
4050 +    }
4051 +}
4052 +
4053 +static void
4054 +OP_E (int bytemode, int sizeflag)
4055 +{
4056 +  bfd_vma disp;
4057 +  int add = 0;
4058 +  int riprel = 0;
4059 +  USED_REX (REX_EXTZ);
4060 +  if (rex & REX_EXTZ)
4061 +    add += 8;
4062 +
4063 +  /* Skip mod/rm byte.  */
4064 +  MODRM_CHECK;
4065 +  codep++;
4066 +
4067 +  if (mod == 3)
4068 +    {
4069 +      switch (bytemode)
4070 +       {
4071 +       case b_mode:
4072 +         USED_REX (0);
4073 +         if (rex)
4074 +           oappend (names8rex[rm + add]);
4075 +         else
4076 +           oappend (names8[rm + add]);
4077 +         break;
4078 +       case w_mode:
4079 +         oappend (names16[rm + add]);
4080 +         break;
4081 +       case d_mode:
4082 +         oappend (names32[rm + add]);
4083 +         break;
4084 +       case q_mode:
4085 +         oappend (names64[rm + add]);
4086 +         break;
4087 +       case m_mode:
4088 +         if (mode_64bit)
4089 +           oappend (names64[rm + add]);
4090 +         else
4091 +           oappend (names32[rm + add]);
4092 +         break;
4093 +       case branch_v_mode:
4094 +         if (mode_64bit)
4095 +           oappend (names64[rm + add]);
4096 +         else
4097 +           {
4098 +             if ((sizeflag & DFLAG) || bytemode != branch_v_mode)
4099 +               oappend (names32[rm + add]);
4100 +             else
4101 +               oappend (names16[rm + add]);
4102 +             used_prefixes |= (prefixes & PREFIX_DATA);
4103 +           }
4104 +         break;
4105 +       case v_mode:
4106 +       case dq_mode:
4107 +       case dqw_mode:
4108 +         USED_REX (REX_MODE64);
4109 +         if (rex & REX_MODE64)
4110 +           oappend (names64[rm + add]);
4111 +         else if ((sizeflag & DFLAG) || bytemode != v_mode)
4112 +           oappend (names32[rm + add]);
4113 +         else
4114 +           oappend (names16[rm + add]);
4115 +         used_prefixes |= (prefixes & PREFIX_DATA);
4116 +         break;
4117 +       case 0:
4118 +         break;
4119 +       default:
4120 +         oappend (INTERNAL_DISASSEMBLER_ERROR);
4121 +         break;
4122 +       }
4123 +      return;
4124 +    }
4125 +
4126 +  disp = 0;
4127 +  append_seg ();
4128 +
4129 +  if ((sizeflag & AFLAG) || mode_64bit) /* 32 bit address mode */
4130 +    {
4131 +      int havesib;
4132 +      int havebase;
4133 +      int base;
4134 +      int index = 0;
4135 +      int scale = 0;
4136 +
4137 +      havesib = 0;
4138 +      havebase = 1;
4139 +      base = rm;
4140 +
4141 +      if (base == 4)
4142 +       {
4143 +         havesib = 1;
4144 +         FETCH_DATA (the_info, codep + 1);
4145 +         index = (*codep >> 3) & 7;
4146 +         if (mode_64bit || index != 0x4)
4147 +           /* When INDEX == 0x4 in 32 bit mode, SCALE is ignored.  */
4148 +           scale = (*codep >> 6) & 3;
4149 +         base = *codep & 7;
4150 +         USED_REX (REX_EXTY);
4151 +         if (rex & REX_EXTY)
4152 +           index += 8;
4153 +         codep++;
4154 +       }
4155 +      base += add;
4156 +
4157 +      switch (mod)
4158 +       {
4159 +       case 0:
4160 +         if ((base & 7) == 5)
4161 +           {
4162 +             havebase = 0;
4163 +             if (mode_64bit && !havesib)
4164 +               riprel = 1;
4165 +             disp = get32s ();
4166 +           }
4167 +         break;
4168 +       case 1:
4169 +         FETCH_DATA (the_info, codep + 1);
4170 +         disp = *codep++;
4171 +         if ((disp & 0x80) != 0)
4172 +           disp -= 0x100;
4173 +         break;
4174 +       case 2:
4175 +         disp = get32s ();
4176 +         break;
4177 +       }
4178 +
4179 +      if (!intel_syntax)
4180 +       if (mod != 0 || (base & 7) == 5)
4181 +         {
4182 +           print_operand_value (scratchbuf, !riprel, disp);
4183 +           oappend (scratchbuf);
4184 +           if (riprel)
4185 +             {
4186 +               set_op (disp, 1);
4187 +               oappend ("(%rip)");
4188 +             }
4189 +         }
4190 +
4191 +      if (havebase || (havesib && (index != 4 || scale != 0)))
4192 +       {
4193 +         if (intel_syntax)
4194 +           {
4195 +             switch (bytemode)
4196 +               {
4197 +               case b_mode:
4198 +                 oappend ("BYTE PTR ");
4199 +                 break;
4200 +               case w_mode:
4201 +               case dqw_mode:
4202 +                 oappend ("WORD PTR ");
4203 +                 break;
4204 +               case branch_v_mode:
4205 +               case v_mode:
4206 +               case dq_mode:
4207 +                 USED_REX (REX_MODE64);
4208 +                 if (rex & REX_MODE64)
4209 +                   oappend ("QWORD PTR ");
4210 +                 else if ((sizeflag & DFLAG) || bytemode == dq_mode)
4211 +                   oappend ("DWORD PTR ");
4212 +                 else
4213 +                   oappend ("WORD PTR ");
4214 +                 used_prefixes |= (prefixes & PREFIX_DATA);
4215 +                 break;
4216 +               case d_mode:
4217 +                 oappend ("DWORD PTR ");
4218 +                 break;
4219 +               case q_mode:
4220 +                 oappend ("QWORD PTR ");
4221 +                 break;
4222 +               case m_mode:
4223 +                 if (mode_64bit)
4224 +                   oappend ("QWORD PTR ");
4225 +                 else
4226 +                   oappend ("DWORD PTR ");
4227 +                 break;
4228 +               case f_mode:
4229 +                 if (sizeflag & DFLAG)
4230 +                   {
4231 +                     used_prefixes |= (prefixes & PREFIX_DATA);
4232 +                     oappend ("FWORD PTR ");
4233 +                   }
4234 +                 else
4235 +                   oappend ("DWORD PTR ");
4236 +                 break;
4237 +               case t_mode:
4238 +                 oappend ("TBYTE PTR ");
4239 +                 break;
4240 +               case x_mode:
4241 +                 oappend ("XMMWORD PTR ");
4242 +                 break;
4243 +               default:
4244 +                 break;
4245 +               }
4246 +           }
4247 +         *obufp++ = open_char;
4248 +         if (intel_syntax && riprel)
4249 +           oappend ("rip + ");
4250 +         *obufp = '\0';
4251 +         if (havebase)
4252 +           oappend (mode_64bit && (sizeflag & AFLAG)
4253 +                    ? names64[base] : names32[base]);
4254 +         if (havesib)
4255 +           {
4256 +             if (index != 4)
4257 +               {
4258 +                 if (!intel_syntax || havebase)
4259 +                   {
4260 +                     *obufp++ = separator_char;
4261 +                     *obufp = '\0';
4262 +                   }
4263 +                 oappend (mode_64bit && (sizeflag & AFLAG)
4264 +                          ? names64[index] : names32[index]);
4265 +               }
4266 +             if (scale != 0 || (!intel_syntax && index != 4))
4267 +               {
4268 +                 *obufp++ = scale_char;
4269 +                 *obufp = '\0';
4270 +                 sprintf (scratchbuf, "%d", 1 << scale);
4271 +                 oappend (scratchbuf);
4272 +               }
4273 +           }
4274 +         if (intel_syntax && disp)
4275 +           {
4276 +             if ((bfd_signed_vma) disp > 0)
4277 +               {
4278 +                 *obufp++ = '+';
4279 +                 *obufp = '\0';
4280 +               }
4281 +             else if (mod != 1)
4282 +               {
4283 +                 *obufp++ = '-';
4284 +                 *obufp = '\0';
4285 +                 disp = - (bfd_signed_vma) disp;
4286 +               }
4287 +
4288 +             print_operand_value (scratchbuf, mod != 1, disp);
4289 +             oappend (scratchbuf);
4290 +           }
4291 +
4292 +         *obufp++ = close_char;
4293 +         *obufp = '\0';
4294 +       }
4295 +      else if (intel_syntax)
4296 +       {
4297 +         if (mod != 0 || (base & 7) == 5)
4298 +           {
4299 +             if (prefixes & (PREFIX_CS | PREFIX_SS | PREFIX_DS
4300 +                             | PREFIX_ES | PREFIX_FS | PREFIX_GS))
4301 +               ;
4302 +             else
4303 +               {
4304 +                 oappend (names_seg[ds_reg - es_reg]);
4305 +                 oappend (":");
4306 +               }
4307 +             print_operand_value (scratchbuf, 1, disp);
4308 +             oappend (scratchbuf);
4309 +           }
4310 +       }
4311 +    }
4312 +  else
4313 +    { /* 16 bit address mode */
4314 +      switch (mod)
4315 +       {
4316 +       case 0:
4317 +         if (rm == 6)
4318 +           {
4319 +             disp = get16 ();
4320 +             if ((disp & 0x8000) != 0)
4321 +               disp -= 0x10000;
4322 +           }
4323 +         break;
4324 +       case 1:
4325 +         FETCH_DATA (the_info, codep + 1);
4326 +         disp = *codep++;
4327 +         if ((disp & 0x80) != 0)
4328 +           disp -= 0x100;
4329 +         break;
4330 +       case 2:
4331 +         disp = get16 ();
4332 +         if ((disp & 0x8000) != 0)
4333 +           disp -= 0x10000;
4334 +         break;
4335 +       }
4336 +
4337 +      if (!intel_syntax)
4338 +       if (mod != 0 || rm == 6)
4339 +         {
4340 +           print_operand_value (scratchbuf, 0, disp);
4341 +           oappend (scratchbuf);
4342 +         }
4343 +
4344 +      if (mod != 0 || rm != 6)
4345 +       {
4346 +         *obufp++ = open_char;
4347 +         *obufp = '\0';
4348 +         oappend (index16[rm]);
4349 +         if (intel_syntax && disp)
4350 +           {
4351 +             if ((bfd_signed_vma) disp > 0)
4352 +               {
4353 +                 *obufp++ = '+';
4354 +                 *obufp = '\0';
4355 +               }
4356 +             else if (mod != 1)
4357 +               {
4358 +                 *obufp++ = '-';
4359 +                 *obufp = '\0';
4360 +                 disp = - (bfd_signed_vma) disp;
4361 +               }
4362 +
4363 +             print_operand_value (scratchbuf, mod != 1, disp);
4364 +             oappend (scratchbuf);
4365 +           }
4366 +
4367 +         *obufp++ = close_char;
4368 +         *obufp = '\0';
4369 +       }
4370 +      else if (intel_syntax)
4371 +       {
4372 +         if (prefixes & (PREFIX_CS | PREFIX_SS | PREFIX_DS
4373 +                         | PREFIX_ES | PREFIX_FS | PREFIX_GS))
4374 +           ;
4375 +         else
4376 +           {
4377 +             oappend (names_seg[ds_reg - es_reg]);
4378 +             oappend (":");
4379 +           }
4380 +         print_operand_value (scratchbuf, 1, disp & 0xffff);
4381 +         oappend (scratchbuf);
4382 +       }
4383 +    }
4384 +}
4385 +
4386 +static void
4387 +OP_G (int bytemode, int sizeflag)
4388 +{
4389 +  int add = 0;
4390 +  USED_REX (REX_EXTX);
4391 +  if (rex & REX_EXTX)
4392 +    add += 8;
4393 +  switch (bytemode)
4394 +    {
4395 +    case b_mode:
4396 +      USED_REX (0);
4397 +      if (rex)
4398 +       oappend (names8rex[reg + add]);
4399 +      else
4400 +       oappend (names8[reg + add]);
4401 +      break;
4402 +    case w_mode:
4403 +      oappend (names16[reg + add]);
4404 +      break;
4405 +    case d_mode:
4406 +      oappend (names32[reg + add]);
4407 +      break;
4408 +    case q_mode:
4409 +      oappend (names64[reg + add]);
4410 +      break;
4411 +    case v_mode:
4412 +    case dq_mode:
4413 +    case dqw_mode:
4414 +      USED_REX (REX_MODE64);
4415 +      if (rex & REX_MODE64)
4416 +       oappend (names64[reg + add]);
4417 +      else if ((sizeflag & DFLAG) || bytemode != v_mode)
4418 +       oappend (names32[reg + add]);
4419 +      else
4420 +       oappend (names16[reg + add]);
4421 +      used_prefixes |= (prefixes & PREFIX_DATA);
4422 +      break;
4423 +    case m_mode:
4424 +      if (mode_64bit)
4425 +       oappend (names64[reg + add]);
4426 +      else
4427 +       oappend (names32[reg + add]);
4428 +      break;
4429 +    default:
4430 +      oappend (INTERNAL_DISASSEMBLER_ERROR);
4431 +      break;
4432 +    }
4433 +}
4434 +
4435 +static bfd_vma
4436 +get64 (void)
4437 +{
4438 +  bfd_vma x;
4439 +#ifdef BFD64
4440 +  unsigned int a;
4441 +  unsigned int b;
4442 +
4443 +  FETCH_DATA (the_info, codep + 8);
4444 +  a = *codep++ & 0xff;
4445 +  a |= (*codep++ & 0xff) << 8;
4446 +  a |= (*codep++ & 0xff) << 16;
4447 +  a |= (*codep++ & 0xff) << 24;
4448 +  b = *codep++ & 0xff;
4449 +  b |= (*codep++ & 0xff) << 8;
4450 +  b |= (*codep++ & 0xff) << 16;
4451 +  b |= (*codep++ & 0xff) << 24;
4452 +  x = a + ((bfd_vma) b << 32);
4453 +#else
4454 +  abort ();
4455 +  x = 0;
4456 +#endif
4457 +  return x;
4458 +}
4459 +
4460 +static bfd_signed_vma
4461 +get32 (void)
4462 +{
4463 +  bfd_signed_vma x = 0;
4464 +
4465 +  FETCH_DATA (the_info, codep + 4);
4466 +  x = *codep++ & (bfd_signed_vma) 0xff;
4467 +  x |= (*codep++ & (bfd_signed_vma) 0xff) << 8;
4468 +  x |= (*codep++ & (bfd_signed_vma) 0xff) << 16;
4469 +  x |= (*codep++ & (bfd_signed_vma) 0xff) << 24;
4470 +  return x;
4471 +}
4472 +
4473 +static bfd_signed_vma
4474 +get32s (void)
4475 +{
4476 +  bfd_signed_vma x = 0;
4477 +
4478 +  FETCH_DATA (the_info, codep + 4);
4479 +  x = *codep++ & (bfd_signed_vma) 0xff;
4480 +  x |= (*codep++ & (bfd_signed_vma) 0xff) << 8;
4481 +  x |= (*codep++ & (bfd_signed_vma) 0xff) << 16;
4482 +  x |= (*codep++ & (bfd_signed_vma) 0xff) << 24;
4483 +
4484 +  x = (x ^ ((bfd_signed_vma) 1 << 31)) - ((bfd_signed_vma) 1 << 31);
4485 +
4486 +  return x;
4487 +}
4488 +
4489 +static int
4490 +get16 (void)
4491 +{
4492 +  int x = 0;
4493 +
4494 +  FETCH_DATA (the_info, codep + 2);
4495 +  x = *codep++ & 0xff;
4496 +  x |= (*codep++ & 0xff) << 8;
4497 +  return x;
4498 +}
4499 +
4500 +static void
4501 +set_op (bfd_vma op, int riprel)
4502 +{
4503 +  op_index[op_ad] = op_ad;
4504 +  if (mode_64bit)
4505 +    {
4506 +      op_address[op_ad] = op;
4507 +      op_riprel[op_ad] = riprel;
4508 +    }
4509 +  else
4510 +    {
4511 +      /* Mask to get a 32-bit address.  */
4512 +      op_address[op_ad] = op & 0xffffffff;
4513 +      op_riprel[op_ad] = riprel & 0xffffffff;
4514 +    }
4515 +}
4516 +
4517 +static void
4518 +OP_REG (int code, int sizeflag)
4519 +{
4520 +  const char *s;
4521 +  int add = 0;
4522 +  USED_REX (REX_EXTZ);
4523 +  if (rex & REX_EXTZ)
4524 +    add = 8;
4525 +
4526 +  switch (code)
4527 +    {
4528 +    case indir_dx_reg:
4529 +      if (intel_syntax)
4530 +       s = "[dx]";
4531 +      else
4532 +       s = "(%dx)";
4533 +      break;
4534 +    case ax_reg: case cx_reg: case dx_reg: case bx_reg:
4535 +    case sp_reg: case bp_reg: case si_reg: case di_reg:
4536 +      s = names16[code - ax_reg + add];
4537 +      break;
4538 +    case es_reg: case ss_reg: case cs_reg:
4539 +    case ds_reg: case fs_reg: case gs_reg:
4540 +      s = names_seg[code - es_reg + add];
4541 +      break;
4542 +    case al_reg: case ah_reg: case cl_reg: case ch_reg:
4543 +    case dl_reg: case dh_reg: case bl_reg: case bh_reg:
4544 +      USED_REX (0);
4545 +      if (rex)
4546 +       s = names8rex[code - al_reg + add];
4547 +      else
4548 +       s = names8[code - al_reg];
4549 +      break;
4550 +    case rAX_reg: case rCX_reg: case rDX_reg: case rBX_reg:
4551 +    case rSP_reg: case rBP_reg: case rSI_reg: case rDI_reg:
4552 +      if (mode_64bit)
4553 +       {
4554 +         s = names64[code - rAX_reg + add];
4555 +         break;
4556 +       }
4557 +      code += eAX_reg - rAX_reg;
4558 +      /* Fall through.  */
4559 +    case eAX_reg: case eCX_reg: case eDX_reg: case eBX_reg:
4560 +    case eSP_reg: case eBP_reg: case eSI_reg: case eDI_reg:
4561 +      USED_REX (REX_MODE64);
4562 +      if (rex & REX_MODE64)
4563 +       s = names64[code - eAX_reg + add];
4564 +      else if (sizeflag & DFLAG)
4565 +       s = names32[code - eAX_reg + add];
4566 +      else
4567 +       s = names16[code - eAX_reg + add];
4568 +      used_prefixes |= (prefixes & PREFIX_DATA);
4569 +      break;
4570 +    default:
4571 +      s = INTERNAL_DISASSEMBLER_ERROR;
4572 +      break;
4573 +    }
4574 +  oappend (s);
4575 +}
4576 +
4577 +static void
4578 +OP_IMREG (int code, int sizeflag)
4579 +{
4580 +  const char *s;
4581 +
4582 +  switch (code)
4583 +    {
4584 +    case indir_dx_reg:
4585 +      if (intel_syntax)
4586 +       s = "[dx]";
4587 +      else
4588 +       s = "(%dx)";
4589 +      break;
4590 +    case ax_reg: case cx_reg: case dx_reg: case bx_reg:
4591 +    case sp_reg: case bp_reg: case si_reg: case di_reg:
4592 +      s = names16[code - ax_reg];
4593 +      break;
4594 +    case es_reg: case ss_reg: case cs_reg:
4595 +    case ds_reg: case fs_reg: case gs_reg:
4596 +      s = names_seg[code - es_reg];
4597 +      break;
4598 +    case al_reg: case ah_reg: case cl_reg: case ch_reg:
4599 +    case dl_reg: case dh_reg: case bl_reg: case bh_reg:
4600 +      USED_REX (0);
4601 +      if (rex)
4602 +       s = names8rex[code - al_reg];
4603 +      else
4604 +       s = names8[code - al_reg];
4605 +      break;
4606 +    case eAX_reg: case eCX_reg: case eDX_reg: case eBX_reg:
4607 +    case eSP_reg: case eBP_reg: case eSI_reg: case eDI_reg:
4608 +      USED_REX (REX_MODE64);
4609 +      if (rex & REX_MODE64)
4610 +       s = names64[code - eAX_reg];
4611 +      else if (sizeflag & DFLAG)
4612 +       s = names32[code - eAX_reg];
4613 +      else
4614 +       s = names16[code - eAX_reg];
4615 +      used_prefixes |= (prefixes & PREFIX_DATA);
4616 +      break;
4617 +    default:
4618 +      s = INTERNAL_DISASSEMBLER_ERROR;
4619 +      break;
4620 +    }
4621 +  oappend (s);
4622 +}
4623 +
4624 +static void
4625 +OP_I (int bytemode, int sizeflag)
4626 +{
4627 +  bfd_signed_vma op;
4628 +  bfd_signed_vma mask = -1;
4629 +
4630 +  switch (bytemode)
4631 +    {
4632 +    case b_mode:
4633 +      FETCH_DATA (the_info, codep + 1);
4634 +      op = *codep++;
4635 +      mask = 0xff;
4636 +      break;
4637 +    case q_mode:
4638 +      if (mode_64bit)
4639 +       {
4640 +         op = get32s ();
4641 +         break;
4642 +       }
4643 +      /* Fall through.  */
4644 +    case v_mode:
4645 +      USED_REX (REX_MODE64);
4646 +      if (rex & REX_MODE64)
4647 +       op = get32s ();
4648 +      else if (sizeflag & DFLAG)
4649 +       {
4650 +         op = get32 ();
4651 +         mask = 0xffffffff;
4652 +       }
4653 +      else
4654 +       {
4655 +         op = get16 ();
4656 +         mask = 0xfffff;
4657 +       }
4658 +      used_prefixes |= (prefixes & PREFIX_DATA);
4659 +      break;
4660 +    case w_mode:
4661 +      mask = 0xfffff;
4662 +      op = get16 ();
4663 +      break;
4664 +    case const_1_mode:
4665 +      if (intel_syntax)
4666 +        oappend ("1");
4667 +      return;
4668 +    default:
4669 +      oappend (INTERNAL_DISASSEMBLER_ERROR);
4670 +      return;
4671 +    }
4672 +
4673 +  op &= mask;
4674 +  scratchbuf[0] = '$';
4675 +  print_operand_value (scratchbuf + 1, 1, op);
4676 +  oappend (scratchbuf + intel_syntax);
4677 +  scratchbuf[0] = '\0';
4678 +}
4679 +
4680 +static void
4681 +OP_I64 (int bytemode, int sizeflag)
4682 +{
4683 +  bfd_signed_vma op;
4684 +  bfd_signed_vma mask = -1;
4685 +
4686 +  if (!mode_64bit)
4687 +    {
4688 +      OP_I (bytemode, sizeflag);
4689 +      return;
4690 +    }
4691 +
4692 +  switch (bytemode)
4693 +    {
4694 +    case b_mode:
4695 +      FETCH_DATA (the_info, codep + 1);
4696 +      op = *codep++;
4697 +      mask = 0xff;
4698 +      break;
4699 +    case v_mode:
4700 +      USED_REX (REX_MODE64);
4701 +      if (rex & REX_MODE64)
4702 +       op = get64 ();
4703 +      else if (sizeflag & DFLAG)
4704 +       {
4705 +         op = get32 ();
4706 +         mask = 0xffffffff;
4707 +       }
4708 +      else
4709 +       {
4710 +         op = get16 ();
4711 +         mask = 0xfffff;
4712 +       }
4713 +      used_prefixes |= (prefixes & PREFIX_DATA);
4714 +      break;
4715 +    case w_mode:
4716 +      mask = 0xfffff;
4717 +      op = get16 ();
4718 +      break;
4719 +    default:
4720 +      oappend (INTERNAL_DISASSEMBLER_ERROR);
4721 +      return;
4722 +    }
4723 +
4724 +  op &= mask;
4725 +  scratchbuf[0] = '$';
4726 +  print_operand_value (scratchbuf + 1, 1, op);
4727 +  oappend (scratchbuf + intel_syntax);
4728 +  scratchbuf[0] = '\0';
4729 +}
4730 +
4731 +static void
4732 +OP_sI (int bytemode, int sizeflag)
4733 +{
4734 +  bfd_signed_vma op;
4735 +  bfd_signed_vma mask = -1;
4736 +
4737 +  switch (bytemode)
4738 +    {
4739 +    case b_mode:
4740 +      FETCH_DATA (the_info, codep + 1);
4741 +      op = *codep++;
4742 +      if ((op & 0x80) != 0)
4743 +       op -= 0x100;
4744 +      mask = 0xffffffff;
4745 +      break;
4746 +    case v_mode:
4747 +      USED_REX (REX_MODE64);
4748 +      if (rex & REX_MODE64)
4749 +       op = get32s ();
4750 +      else if (sizeflag & DFLAG)
4751 +       {
4752 +         op = get32s ();
4753 +         mask = 0xffffffff;
4754 +       }
4755 +      else
4756 +       {
4757 +         mask = 0xffffffff;
4758 +         op = get16 ();
4759 +         if ((op & 0x8000) != 0)
4760 +           op -= 0x10000;
4761 +       }
4762 +      used_prefixes |= (prefixes & PREFIX_DATA);
4763 +      break;
4764 +    case w_mode:
4765 +      op = get16 ();
4766 +      mask = 0xffffffff;
4767 +      if ((op & 0x8000) != 0)
4768 +       op -= 0x10000;
4769 +      break;
4770 +    default:
4771 +      oappend (INTERNAL_DISASSEMBLER_ERROR);
4772 +      return;
4773 +    }
4774 +
4775 +  scratchbuf[0] = '$';
4776 +  print_operand_value (scratchbuf + 1, 1, op);
4777 +  oappend (scratchbuf + intel_syntax);
4778 +}
4779 +
4780 +static void
4781 +OP_J (int bytemode, int sizeflag)
4782 +{
4783 +  bfd_vma disp;
4784 +  bfd_vma mask = -1;
4785 +
4786 +  switch (bytemode)
4787 +    {
4788 +    case b_mode:
4789 +      FETCH_DATA (the_info, codep + 1);
4790 +      disp = *codep++;
4791 +      if ((disp & 0x80) != 0)
4792 +       disp -= 0x100;
4793 +      break;
4794 +    case v_mode:
4795 +      if (sizeflag & DFLAG)
4796 +       disp = get32s ();
4797 +      else
4798 +       {
4799 +         disp = get16 ();
4800 +         /* For some reason, a data16 prefix on a jump instruction
4801 +            means that the pc is masked to 16 bits after the
4802 +            displacement is added!  */
4803 +         mask = 0xffff;
4804 +       }
4805 +      break;
4806 +    default:
4807 +      oappend (INTERNAL_DISASSEMBLER_ERROR);
4808 +      return;
4809 +    }
4810 +  disp = (start_pc + codep - start_codep + disp) & mask;
4811 +  set_op (disp, 0);
4812 +  print_operand_value (scratchbuf, 1, disp);
4813 +  oappend (scratchbuf);
4814 +}
4815 +
4816 +static void
4817 +OP_SEG (int dummy ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
4818 +{
4819 +  oappend (names_seg[reg]);
4820 +}
4821 +
4822 +static void
4823 +OP_DIR (int dummy ATTRIBUTE_UNUSED, int sizeflag)
4824 +{
4825 +  int seg, offset;
4826 +
4827 +  if (sizeflag & DFLAG)
4828 +    {
4829 +      offset = get32 ();
4830 +      seg = get16 ();
4831 +    }
4832 +  else
4833 +    {
4834 +      offset = get16 ();
4835 +      seg = get16 ();
4836 +    }
4837 +  used_prefixes |= (prefixes & PREFIX_DATA);
4838 +  if (intel_syntax)
4839 +    sprintf (scratchbuf, "0x%x,0x%x", seg, offset);
4840 +  else
4841 +    sprintf (scratchbuf, "$0x%x,$0x%x", seg, offset);
4842 +  oappend (scratchbuf);
4843 +}
4844 +
4845 +static void
4846 +OP_OFF (int bytemode ATTRIBUTE_UNUSED, int sizeflag)
4847 +{
4848 +  bfd_vma off;
4849 +
4850 +  append_seg ();
4851 +
4852 +  if ((sizeflag & AFLAG) || mode_64bit)
4853 +    off = get32 ();
4854 +  else
4855 +    off = get16 ();
4856 +
4857 +  if (intel_syntax)
4858 +    {
4859 +      if (!(prefixes & (PREFIX_CS | PREFIX_SS | PREFIX_DS
4860 +                       | PREFIX_ES | PREFIX_FS | PREFIX_GS)))
4861 +       {
4862 +         oappend (names_seg[ds_reg - es_reg]);
4863 +         oappend (":");
4864 +       }
4865 +    }
4866 +  print_operand_value (scratchbuf, 1, off);
4867 +  oappend (scratchbuf);
4868 +}
4869 +
4870 +static void
4871 +OP_OFF64 (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
4872 +{
4873 +  bfd_vma off;
4874 +
4875 +  if (!mode_64bit)
4876 +    {
4877 +      OP_OFF (bytemode, sizeflag);
4878 +      return;
4879 +    }
4880 +
4881 +  append_seg ();
4882 +
4883 +  off = get64 ();
4884 +
4885 +  if (intel_syntax)
4886 +    {
4887 +      if (!(prefixes & (PREFIX_CS | PREFIX_SS | PREFIX_DS
4888 +                       | PREFIX_ES | PREFIX_FS | PREFIX_GS)))
4889 +       {
4890 +         oappend (names_seg[ds_reg - es_reg]);
4891 +         oappend (":");
4892 +       }
4893 +    }
4894 +  print_operand_value (scratchbuf, 1, off);
4895 +  oappend (scratchbuf);
4896 +}
4897 +
4898 +static void
4899 +ptr_reg (int code, int sizeflag)
4900 +{
4901 +  const char *s;
4902 +
4903 +  *obufp++ = open_char;
4904 +  used_prefixes |= (prefixes & PREFIX_ADDR);
4905 +  if (mode_64bit)
4906 +    {
4907 +      if (!(sizeflag & AFLAG))
4908 +       s = names32[code - eAX_reg];
4909 +      else
4910 +       s = names64[code - eAX_reg];
4911 +    }
4912 +  else if (sizeflag & AFLAG)
4913 +    s = names32[code - eAX_reg];
4914 +  else
4915 +    s = names16[code - eAX_reg];
4916 +  oappend (s);
4917 +  *obufp++ = close_char;
4918 +  *obufp = 0;
4919 +}
4920 +
4921 +static void
4922 +OP_ESreg (int code, int sizeflag)
4923 +{
4924 +  if (intel_syntax)
4925 +    {
4926 +      if (codep[-1] & 1)
4927 +       {
4928 +         USED_REX (REX_MODE64);
4929 +         used_prefixes |= (prefixes & PREFIX_DATA);
4930 +         if (rex & REX_MODE64)
4931 +           oappend ("QWORD PTR ");
4932 +         else if ((sizeflag & DFLAG))
4933 +           oappend ("DWORD PTR ");
4934 +         else
4935 +           oappend ("WORD PTR ");
4936 +       }
4937 +      else
4938 +       oappend ("BYTE PTR ");
4939 +    }
4940 +
4941 +  oappend ("%es:" + intel_syntax);
4942 +  ptr_reg (code, sizeflag);
4943 +}
4944 +
4945 +static void
4946 +OP_DSreg (int code, int sizeflag)
4947 +{
4948 +  if (intel_syntax)
4949 +    {
4950 +      if (codep[-1] != 0xd7 && (codep[-1] & 1))
4951 +       {
4952 +         USED_REX (REX_MODE64);
4953 +         used_prefixes |= (prefixes & PREFIX_DATA);
4954 +         if (rex & REX_MODE64)
4955 +           oappend ("QWORD PTR ");
4956 +         else if ((sizeflag & DFLAG))
4957 +           oappend ("DWORD PTR ");
4958 +         else
4959 +           oappend ("WORD PTR ");
4960 +       }
4961 +      else
4962 +       oappend ("BYTE PTR ");
4963 +    }
4964 +
4965 +  if ((prefixes
4966 +       & (PREFIX_CS
4967 +         | PREFIX_DS
4968 +         | PREFIX_SS
4969 +         | PREFIX_ES
4970 +         | PREFIX_FS
4971 +         | PREFIX_GS)) == 0)
4972 +    prefixes |= PREFIX_DS;
4973 +  append_seg ();
4974 +  ptr_reg (code, sizeflag);
4975 +}
4976 +
4977 +static void
4978 +OP_C (int dummy ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
4979 +{
4980 +  int add = 0;
4981 +  if (rex & REX_EXTX)
4982 +    {
4983 +      USED_REX (REX_EXTX);
4984 +      add = 8;
4985 +    }
4986 +  else if (!mode_64bit && (prefixes & PREFIX_LOCK))
4987 +    {
4988 +      used_prefixes |= PREFIX_LOCK;
4989 +      add = 8;
4990 +    }
4991 +  sprintf (scratchbuf, "%%cr%d", reg + add);
4992 +  oappend (scratchbuf + intel_syntax);
4993 +}
4994 +
4995 +static void
4996 +OP_D (int dummy ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
4997 +{
4998 +  int add = 0;
4999 +  USED_REX (REX_EXTX);
5000 +  if (rex & REX_EXTX)
5001 +    add = 8;
5002 +  if (intel_syntax)
5003 +    sprintf (scratchbuf, "db%d", reg + add);
5004 +  else
5005 +    sprintf (scratchbuf, "%%db%d", reg + add);
5006 +  oappend (scratchbuf);
5007 +}
5008 +
5009 +static void
5010 +OP_T (int dummy ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
5011 +{
5012 +  sprintf (scratchbuf, "%%tr%d", reg);
5013 +  oappend (scratchbuf + intel_syntax);
5014 +}
5015 +
5016 +static void
5017 +OP_Rd (int bytemode, int sizeflag)
5018 +{
5019 +  if (mod == 3)
5020 +    OP_E (bytemode, sizeflag);
5021 +  else
5022 +    BadOp ();
5023 +}
5024 +
5025 +static void
5026 +OP_MMX (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
5027 +{
5028 +  used_prefixes |= (prefixes & PREFIX_DATA);
5029 +  if (prefixes & PREFIX_DATA)
5030 +    {
5031 +      int add = 0;
5032 +      USED_REX (REX_EXTX);
5033 +      if (rex & REX_EXTX)
5034 +       add = 8;
5035 +      sprintf (scratchbuf, "%%xmm%d", reg + add);
5036 +    }
5037 +  else
5038 +    sprintf (scratchbuf, "%%mm%d", reg);
5039 +  oappend (scratchbuf + intel_syntax);
5040 +}
5041 +
5042 +static void
5043 +OP_XMM (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
5044 +{
5045 +  int add = 0;
5046 +  USED_REX (REX_EXTX);
5047 +  if (rex & REX_EXTX)
5048 +    add = 8;
5049 +  sprintf (scratchbuf, "%%xmm%d", reg + add);
5050 +  oappend (scratchbuf + intel_syntax);
5051 +}
5052 +
5053 +static void
5054 +OP_EM (int bytemode, int sizeflag)
5055 +{
5056 +  if (mod != 3)
5057 +    {
5058 +      if (intel_syntax && bytemode == v_mode)
5059 +       {
5060 +         bytemode = (prefixes & PREFIX_DATA) ? x_mode : q_mode;
5061 +         used_prefixes |= (prefixes & PREFIX_DATA);
5062 +       }
5063 +      OP_E (bytemode, sizeflag);
5064 +      return;
5065 +    }
5066 +
5067 +  /* Skip mod/rm byte.  */
5068 +  MODRM_CHECK;
5069 +  codep++;
5070 +  used_prefixes |= (prefixes & PREFIX_DATA);
5071 +  if (prefixes & PREFIX_DATA)
5072 +    {
5073 +      int add = 0;
5074 +
5075 +      USED_REX (REX_EXTZ);
5076 +      if (rex & REX_EXTZ)
5077 +       add = 8;
5078 +      sprintf (scratchbuf, "%%xmm%d", rm + add);
5079 +    }
5080 +  else
5081 +    sprintf (scratchbuf, "%%mm%d", rm);
5082 +  oappend (scratchbuf + intel_syntax);
5083 +}
5084 +
5085 +static void
5086 +OP_EX (int bytemode, int sizeflag)
5087 +{
5088 +  int add = 0;
5089 +  if (mod != 3)
5090 +    {
5091 +      if (intel_syntax && bytemode == v_mode)
5092 +       {
5093 +         switch (prefixes & (PREFIX_DATA|PREFIX_REPZ|PREFIX_REPNZ))
5094 +           {
5095 +           case 0:            bytemode = x_mode; break;
5096 +           case PREFIX_REPZ:  bytemode = d_mode; used_prefixes |= PREFIX_REPZ;  break;
5097 +           case PREFIX_DATA:  bytemode = x_mode; used_prefixes |= PREFIX_DATA;  break;
5098 +           case PREFIX_REPNZ: bytemode = q_mode; used_prefixes |= PREFIX_REPNZ; break;
5099 +           default:           bytemode = 0; break;
5100 +           }
5101 +       }
5102 +      OP_E (bytemode, sizeflag);
5103 +      return;
5104 +    }
5105 +  USED_REX (REX_EXTZ);
5106 +  if (rex & REX_EXTZ)
5107 +    add = 8;
5108 +
5109 +  /* Skip mod/rm byte.  */
5110 +  MODRM_CHECK;
5111 +  codep++;
5112 +  sprintf (scratchbuf, "%%xmm%d", rm + add);
5113 +  oappend (scratchbuf + intel_syntax);
5114 +}
5115 +
5116 +static void
5117 +OP_MS (int bytemode, int sizeflag)
5118 +{
5119 +  if (mod == 3)
5120 +    OP_EM (bytemode, sizeflag);
5121 +  else
5122 +    BadOp ();
5123 +}
5124 +
5125 +static void
5126 +OP_XS (int bytemode, int sizeflag)
5127 +{
5128 +  if (mod == 3)
5129 +    OP_EX (bytemode, sizeflag);
5130 +  else
5131 +    BadOp ();
5132 +}
5133 +
5134 +static void
5135 +OP_M (int bytemode, int sizeflag)
5136 +{
5137 +  if (mod == 3)
5138 +    BadOp ();  /* bad lea,lds,les,lfs,lgs,lss modrm */
5139 +  else
5140 +    OP_E (bytemode, sizeflag);
5141 +}
5142 +
5143 +static void
5144 +OP_0f07 (int bytemode, int sizeflag)
5145 +{
5146 +  if (mod != 3 || rm != 0)
5147 +    BadOp ();
5148 +  else
5149 +    OP_E (bytemode, sizeflag);
5150 +}
5151 +
5152 +static void
5153 +OP_0fae (int bytemode, int sizeflag)
5154 +{
5155 +  if (mod == 3)
5156 +    {
5157 +      if (reg == 7)
5158 +       strcpy (obuf + strlen (obuf) - sizeof ("clflush") + 1, "sfence");
5159 +
5160 +      if (reg < 5 || rm != 0)
5161 +       {
5162 +         BadOp ();     /* bad sfence, mfence, or lfence */
5163 +         return;
5164 +       }
5165 +    }
5166 +  else if (reg != 7)
5167 +    {
5168 +      BadOp ();                /* bad clflush */
5169 +      return;
5170 +    }
5171 +
5172 +  OP_E (bytemode, sizeflag);
5173 +}
5174 +
5175 +static void
5176 +NOP_Fixup (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
5177 +{
5178 +  /* NOP with REPZ prefix is called PAUSE.  */
5179 +  if (prefixes == PREFIX_REPZ)
5180 +    strcpy (obuf, "pause");
5181 +}
5182 +
5183 +static const char *const Suffix3DNow[] = {
5184 +/* 00 */       NULL,           NULL,           NULL,           NULL,
5185 +/* 04 */       NULL,           NULL,           NULL,           NULL,
5186 +/* 08 */       NULL,           NULL,           NULL,           NULL,
5187 +/* 0C */       "pi2fw",        "pi2fd",        NULL,           NULL,
5188 +/* 10 */       NULL,           NULL,           NULL,           NULL,
5189 +/* 14 */       NULL,           NULL,           NULL,           NULL,
5190 +/* 18 */       NULL,           NULL,           NULL,           NULL,
5191 +/* 1C */       "pf2iw",        "pf2id",        NULL,           NULL,
5192 +/* 20 */       NULL,           NULL,           NULL,           NULL,
5193 +/* 24 */       NULL,           NULL,           NULL,           NULL,
5194 +/* 28 */       NULL,           NULL,           NULL,           NULL,
5195 +/* 2C */       NULL,           NULL,           NULL,           NULL,
5196 +/* 30 */       NULL,           NULL,           NULL,           NULL,
5197 +/* 34 */       NULL,           NULL,           NULL,           NULL,
5198 +/* 38 */       NULL,           NULL,           NULL,           NULL,
5199 +/* 3C */       NULL,           NULL,           NULL,           NULL,
5200 +/* 40 */       NULL,           NULL,           NULL,           NULL,
5201 +/* 44 */       NULL,           NULL,           NULL,           NULL,
5202 +/* 48 */       NULL,           NULL,           NULL,           NULL,
5203 +/* 4C */       NULL,           NULL,           NULL,           NULL,
5204 +/* 50 */       NULL,           NULL,           NULL,           NULL,
5205 +/* 54 */       NULL,           NULL,           NULL,           NULL,
5206 +/* 58 */       NULL,           NULL,           NULL,           NULL,
5207 +/* 5C */       NULL,           NULL,           NULL,           NULL,
5208 +/* 60 */       NULL,           NULL,           NULL,           NULL,
5209 +/* 64 */       NULL,           NULL,           NULL,           NULL,
5210 +/* 68 */       NULL,           NULL,           NULL,           NULL,
5211 +/* 6C */       NULL,           NULL,           NULL,           NULL,
5212 +/* 70 */       NULL,           NULL,           NULL,           NULL,
5213 +/* 74 */       NULL,           NULL,           NULL,           NULL,
5214 +/* 78 */       NULL,           NULL,           NULL,           NULL,
5215 +/* 7C */       NULL,           NULL,           NULL,           NULL,
5216 +/* 80 */       NULL,           NULL,           NULL,           NULL,
5217 +/* 84 */       NULL,           NULL,           NULL,           NULL,
5218 +/* 88 */       NULL,           NULL,           "pfnacc",       NULL,
5219 +/* 8C */       NULL,           NULL,           "pfpnacc",      NULL,
5220 +/* 90 */       "pfcmpge",      NULL,           NULL,           NULL,
5221 +/* 94 */       "pfmin",        NULL,           "pfrcp",        "pfrsqrt",
5222 +/* 98 */       NULL,           NULL,           "pfsub",        NULL,
5223 +/* 9C */       NULL,           NULL,           "pfadd",        NULL,
5224 +/* A0 */       "pfcmpgt",      NULL,           NULL,           NULL,
5225 +/* A4 */       "pfmax",        NULL,           "pfrcpit1",     "pfrsqit1",
5226 +/* A8 */       NULL,           NULL,           "pfsubr",       NULL,
5227 +/* AC */       NULL,           NULL,           "pfacc",        NULL,
5228 +/* B0 */       "pfcmpeq",      NULL,           NULL,           NULL,
5229 +/* B4 */       "pfmul",        NULL,           "pfrcpit2",     "pfmulhrw",
5230 +/* B8 */       NULL,           NULL,           NULL,           "pswapd",
5231 +/* BC */       NULL,           NULL,           NULL,           "pavgusb",
5232 +/* C0 */       NULL,           NULL,           NULL,           NULL,
5233 +/* C4 */       NULL,           NULL,           NULL,           NULL,
5234 +/* C8 */       NULL,           NULL,           NULL,           NULL,
5235 +/* CC */       NULL,           NULL,           NULL,           NULL,
5236 +/* D0 */       NULL,           NULL,           NULL,           NULL,
5237 +/* D4 */       NULL,           NULL,           NULL,           NULL,
5238 +/* D8 */       NULL,           NULL,           NULL,           NULL,
5239 +/* DC */       NULL,           NULL,           NULL,           NULL,
5240 +/* E0 */       NULL,           NULL,           NULL,           NULL,
5241 +/* E4 */       NULL,           NULL,           NULL,           NULL,
5242 +/* E8 */       NULL,           NULL,           NULL,           NULL,
5243 +/* EC */       NULL,           NULL,           NULL,           NULL,
5244 +/* F0 */       NULL,           NULL,           NULL,           NULL,
5245 +/* F4 */       NULL,           NULL,           NULL,           NULL,
5246 +/* F8 */       NULL,           NULL,           NULL,           NULL,
5247 +/* FC */       NULL,           NULL,           NULL,           NULL,
5248 +};
5249 +
5250 +static void
5251 +OP_3DNowSuffix (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
5252 +{
5253 +  const char *mnemonic;
5254 +
5255 +  FETCH_DATA (the_info, codep + 1);
5256 +  /* AMD 3DNow! instructions are specified by an opcode suffix in the
5257 +     place where an 8-bit immediate would normally go.  ie. the last
5258 +     byte of the instruction.  */
5259 +  obufp = obuf + strlen (obuf);
5260 +  mnemonic = Suffix3DNow[*codep++ & 0xff];
5261 +  if (mnemonic)
5262 +    oappend (mnemonic);
5263 +  else
5264 +    {
5265 +      /* Since a variable sized modrm/sib chunk is between the start
5266 +        of the opcode (0x0f0f) and the opcode suffix, we need to do
5267 +        all the modrm processing first, and don't know until now that
5268 +        we have a bad opcode.  This necessitates some cleaning up.  */
5269 +      op1out[0] = '\0';
5270 +      op2out[0] = '\0';
5271 +      BadOp ();
5272 +    }
5273 +}
5274 +
5275 +static const char *simd_cmp_op[] = {
5276 +  "eq",
5277 +  "lt",
5278 +  "le",
5279 +  "unord",
5280 +  "neq",
5281 +  "nlt",
5282 +  "nle",
5283 +  "ord"
5284 +};
5285 +
5286 +static void
5287 +OP_SIMD_Suffix (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
5288 +{
5289 +  unsigned int cmp_type;
5290 +
5291 +  FETCH_DATA (the_info, codep + 1);
5292 +  obufp = obuf + strlen (obuf);
5293 +  cmp_type = *codep++ & 0xff;
5294 +  if (cmp_type < 8)
5295 +    {
5296 +      char suffix1 = 'p', suffix2 = 's';
5297 +      used_prefixes |= (prefixes & PREFIX_REPZ);
5298 +      if (prefixes & PREFIX_REPZ)
5299 +       suffix1 = 's';
5300 +      else
5301 +       {
5302 +         used_prefixes |= (prefixes & PREFIX_DATA);
5303 +         if (prefixes & PREFIX_DATA)
5304 +           suffix2 = 'd';
5305 +         else
5306 +           {
5307 +             used_prefixes |= (prefixes & PREFIX_REPNZ);
5308 +             if (prefixes & PREFIX_REPNZ)
5309 +               suffix1 = 's', suffix2 = 'd';
5310 +           }
5311 +       }
5312 +      sprintf (scratchbuf, "cmp%s%c%c",
5313 +              simd_cmp_op[cmp_type], suffix1, suffix2);
5314 +      used_prefixes |= (prefixes & PREFIX_REPZ);
5315 +      oappend (scratchbuf);
5316 +    }
5317 +  else
5318 +    {
5319 +      /* We have a bad extension byte.  Clean up.  */
5320 +      op1out[0] = '\0';
5321 +      op2out[0] = '\0';
5322 +      BadOp ();
5323 +    }
5324 +}
5325 +
5326 +static void
5327 +SIMD_Fixup (int extrachar, int sizeflag ATTRIBUTE_UNUSED)
5328 +{
5329 +  /* Change movlps/movhps to movhlps/movlhps for 2 register operand
5330 +     forms of these instructions.  */
5331 +  if (mod == 3)
5332 +    {
5333 +      char *p = obuf + strlen (obuf);
5334 +      *(p + 1) = '\0';
5335 +      *p       = *(p - 1);
5336 +      *(p - 1) = *(p - 2);
5337 +      *(p - 2) = *(p - 3);
5338 +      *(p - 3) = extrachar;
5339 +    }
5340 +}
5341 +
5342 +static void
5343 +PNI_Fixup (int extrachar ATTRIBUTE_UNUSED, int sizeflag)
5344 +{
5345 +  if (mod == 3 && reg == 1 && rm <= 1)
5346 +    {
5347 +      /* Override "sidt".  */
5348 +      char *p = obuf + strlen (obuf) - 4;
5349 +
5350 +      /* We might have a suffix when disassembling with -Msuffix.  */
5351 +      if (*p == 'i')
5352 +       --p;
5353 +
5354 +      if (rm)
5355 +       {
5356 +         /* mwait %eax,%ecx  */
5357 +         strcpy (p, "mwait");
5358 +         if (!intel_syntax)
5359 +           strcpy (op1out, names32[0]);
5360 +       }
5361 +      else
5362 +       {
5363 +         /* monitor %eax,%ecx,%edx"  */
5364 +         strcpy (p, "monitor");
5365 +         if (!intel_syntax)
5366 +           {
5367 +             if (!mode_64bit)
5368 +               strcpy (op1out, names32[0]);
5369 +             else if (!(prefixes & PREFIX_ADDR))
5370 +               strcpy (op1out, names64[0]);
5371 +             else
5372 +               {
5373 +                 strcpy (op1out, names32[0]);
5374 +                 used_prefixes |= PREFIX_ADDR;
5375 +               }
5376 +             strcpy (op3out, names32[2]);
5377 +           }
5378 +       }
5379 +      if (!intel_syntax)
5380 +       {
5381 +         strcpy (op2out, names32[1]);
5382 +         two_source_ops = 1;
5383 +       }
5384 +
5385 +      codep++;
5386 +    }
5387 +  else
5388 +    OP_M (0, sizeflag);
5389 +}
5390 +
5391 +static void
5392 +SVME_Fixup (int bytemode, int sizeflag)
5393 +{
5394 +  const char *alt;
5395 +  char *p;
5396 +
5397 +  switch (*codep)
5398 +    {
5399 +    case 0xd8:
5400 +      alt = "vmrun";
5401 +      break;
5402 +    case 0xd9:
5403 +      alt = "vmmcall";
5404 +      break;
5405 +    case 0xda:
5406 +      alt = "vmload";
5407 +      break;
5408 +    case 0xdb:
5409 +      alt = "vmsave";
5410 +      break;
5411 +    case 0xdc:
5412 +      alt = "stgi";
5413 +      break;
5414 +    case 0xdd:
5415 +      alt = "clgi";
5416 +      break;
5417 +    case 0xde:
5418 +      alt = "skinit";
5419 +      break;
5420 +    case 0xdf:
5421 +      alt = "invlpga";
5422 +      break;
5423 +    default:
5424 +      OP_M (bytemode, sizeflag);
5425 +      return;
5426 +    }
5427 +  /* Override "lidt".  */
5428 +  p = obuf + strlen (obuf) - 4;
5429 +  /* We might have a suffix.  */
5430 +  if (*p == 'i')
5431 +    --p;
5432 +  strcpy (p, alt);
5433 +  if (!(prefixes & PREFIX_ADDR))
5434 +    {
5435 +      ++codep;
5436 +      return;
5437 +    }
5438 +  used_prefixes |= PREFIX_ADDR;
5439 +  switch (*codep++)
5440 +    {
5441 +    case 0xdf:
5442 +      strcpy (op2out, names32[1]);
5443 +      two_source_ops = 1;
5444 +         /* Fall through.  */
5445 +    case 0xd8:
5446 +    case 0xda:
5447 +    case 0xdb:
5448 +      *obufp++ = open_char;
5449 +      if (mode_64bit || (sizeflag & AFLAG))
5450 +        alt = names32[0];
5451 +      else
5452 +        alt = names16[0];
5453 +      strcpy (obufp, alt);
5454 +      obufp += strlen (alt);
5455 +      *obufp++ = close_char;
5456 +      *obufp = '\0';
5457 +      break;
5458 +    }
5459 +}
5460 +
5461 +static void
5462 +INVLPG_Fixup (int bytemode, int sizeflag)
5463 +{
5464 +  const char *alt;
5465 +
5466 +  switch (*codep)
5467 +    {
5468 +    case 0xf8:
5469 +      alt = "swapgs";
5470 +      break;
5471 +    case 0xf9:
5472 +      alt = "rdtscp";
5473 +      break;
5474 +    default:
5475 +      OP_M (bytemode, sizeflag);
5476 +      return;
5477 +    }
5478 +  /* Override "invlpg".  */
5479 +  strcpy (obuf + strlen (obuf) - 6, alt);
5480 +  codep++;
5481 +}
5482 +
5483 +static void
5484 +BadOp (void)
5485 +{
5486 +  /* Throw away prefixes and 1st. opcode byte.  */
5487 +  codep = insn_codep + 1;
5488 +  oappend ("(bad)");
5489 +}
5490 +
5491 +static void
5492 +SEG_Fixup (int extrachar, int sizeflag)
5493 +{
5494 +  if (mod == 3)
5495 +    {
5496 +      /* We need to add a proper suffix with
5497 +
5498 +               movw %ds,%ax
5499 +               movl %ds,%eax
5500 +               movq %ds,%rax
5501 +               movw %ax,%ds
5502 +               movl %eax,%ds
5503 +               movq %rax,%ds
5504 +       */
5505 +      const char *suffix;
5506 +
5507 +      if (prefixes & PREFIX_DATA)
5508 +       suffix = "w";
5509 +      else
5510 +       {
5511 +         USED_REX (REX_MODE64);
5512 +         if (rex & REX_MODE64)
5513 +           suffix = "q";
5514 +         else
5515 +           suffix = "l";
5516 +       }
5517 +      strcat (obuf, suffix);
5518 +    }
5519 +  else
5520 +    {
5521 +      /* We need to fix the suffix for
5522 +
5523 +               movw %ds,(%eax)
5524 +               movw %ds,(%rax)
5525 +               movw (%eax),%ds
5526 +               movw (%rax),%ds
5527 +
5528 +        Override "mov[l|q]".  */
5529 +      char *p = obuf + strlen (obuf) - 1;
5530 +
5531 +      /* We might not have a suffix.  */
5532 +      if (*p == 'v')
5533 +       ++p;
5534 +      *p = 'w';
5535 +    }
5536 +
5537 +  OP_E (extrachar, sizeflag);
5538 +}
5539 +
5540 +static void
5541 +VMX_Fixup (int extrachar ATTRIBUTE_UNUSED, int sizeflag)
5542 +{
5543 +  if (mod == 3 && reg == 0 && rm >=1 && rm <= 4)
5544 +    {
5545 +      /* Override "sgdt".  */
5546 +      char *p = obuf + strlen (obuf) - 4;
5547 +
5548 +      /* We might have a suffix when disassembling with -Msuffix.  */
5549 +      if (*p == 'g')
5550 +       --p;
5551 +
5552 +      switch (rm)
5553 +       {
5554 +       case 1:
5555 +         strcpy (p, "vmcall");
5556 +         break;
5557 +       case 2:
5558 +         strcpy (p, "vmlaunch");
5559 +         break;
5560 +       case 3:
5561 +         strcpy (p, "vmresume");
5562 +         break;
5563 +       case 4:
5564 +         strcpy (p, "vmxoff");
5565 +         break;
5566 +       }
5567 +
5568 +      codep++;
5569 +    }
5570 +  else
5571 +    OP_E (0, sizeflag);
5572 +}
5573 +
5574 +static void
5575 +OP_VMX (int bytemode, int sizeflag)
5576 +{
5577 +  used_prefixes |= (prefixes & (PREFIX_DATA | PREFIX_REPZ));
5578 +  if (prefixes & PREFIX_DATA)
5579 +    strcpy (obuf, "vmclear");
5580 +  else if (prefixes & PREFIX_REPZ)
5581 +    strcpy (obuf, "vmxon");
5582 +  else
5583 +    strcpy (obuf, "vmptrld");
5584 +  OP_E (bytemode, sizeflag);
5585 +}
5586 diff -Nurp linux-2.6.22-590/arch/i386/kdb/kdba_bp.c linux-2.6.22-600/arch/i386/kdb/kdba_bp.c
5587 --- linux-2.6.22-590/arch/i386/kdb/kdba_bp.c    1970-01-01 01:00:00.000000000 +0100
5588 +++ linux-2.6.22-600/arch/i386/kdb/kdba_bp.c    2008-04-09 18:16:14.000000000 +0200
5589 @@ -0,0 +1,780 @@
5590 +/*
5591 + * Kernel Debugger Architecture Dependent Breakpoint Handling
5592 + *
5593 + * This file is subject to the terms and conditions of the GNU General Public
5594 + * License.  See the file "COPYING" in the main directory of this archive
5595 + * for more details.
5596 + *
5597 + * Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
5598 + */
5599 +
5600 +#include <linux/string.h>
5601 +#include <linux/kernel.h>
5602 +#include <linux/sched.h>
5603 +#include <linux/smp.h>
5604 +#include <linux/ptrace.h>
5605 +#include <linux/kdb.h>
5606 +#include <linux/kdbprivate.h>
5607 +
5608 +
5609 +static char *kdba_rwtypes[] = { "Instruction(Register)", "Data Write",
5610 +                       "I/O", "Data Access"};
5611 +
5612 +/*
5613 + * Table describing processor architecture hardware
5614 + * breakpoint registers.
5615 + */
5616 +
5617 +static kdbhard_bp_t kdb_hardbreaks[KDB_MAXHARDBPT];
5618 +
5619 +/*
5620 + * kdba_db_trap
5621 + *
5622 + *     Perform breakpoint processing upon entry to the
5623 + *     processor debugger fault.   Determine and print
5624 + *     the active breakpoint.
5625 + *
5626 + * Parameters:
5627 + *     regs    Exception frame containing machine register state
5628 + *     error   Error number passed to kdb.
5629 + * Outputs:
5630 + *     None.
5631 + * Returns:
5632 + *     KDB_DB_BPT      Standard instruction or data breakpoint encountered
5633 + *     KDB_DB_SS       Single Step fault ('ss' command or end of 'ssb' command)
5634 + *     KDB_DB_SSB      Single Step fault, caller should continue ('ssb' command)
5635 + *     KDB_DB_SSBPT    Single step over breakpoint
5636 + *     KDB_DB_NOBPT    No existing kdb breakpoint matches this debug exception
5637 + * Locking:
5638 + *     None.
5639 + * Remarks:
5640 + *     Yup, there be goto's here.
5641 + *
5642 + *     If multiple processors receive debug exceptions simultaneously,
5643 + *     one may be waiting at the kdb fence in kdb() while the user
5644 + *     issues a 'bc' command to clear the breakpoint the processor
5645 + *     which is waiting has already encountered.  If this is the case,
5646 + *     the debug registers will no longer match any entry in the
5647 + *     breakpoint table, and we'll return the value KDB_DB_NOBPT.
5648 + *     This can cause a panic in die_if_kernel().  It is safer to
5649 + *     disable the breakpoint (bd), go until all processors are past
5650 + *     the breakpoint then clear the breakpoint (bc).  This code
5651 + *     recognises a breakpoint even when disabled but not when it has
5652 + *     been cleared.
5653 + *
5654 + *     WARNING: This routine clears the debug state.  It should be called
5655 + *              once per debug and the result cached.
5656 + */
5657 +
5658 +kdb_dbtrap_t
5659 +kdba_db_trap(struct pt_regs *regs, int error_unused)
5660 +{
5661 +       kdb_machreg_t dr6;
5662 +       kdb_machreg_t dr7;
5663 +       int rw, reg;
5664 +       int i;
5665 +       kdb_dbtrap_t rv = KDB_DB_BPT;
5666 +       kdb_bp_t *bp;
5667 +
5668 +       if (KDB_NULL_REGS(regs))
5669 +               return KDB_DB_NOBPT;
5670 +
5671 +       dr6 = kdba_getdr6();
5672 +       dr7 = kdba_getdr7();
5673 +
5674 +       if (KDB_DEBUG(BP))
5675 +               kdb_printf("kdb: dr6 0x%lx dr7 0x%lx\n", dr6, dr7);
5676 +       if (dr6 & DR6_BS) {
5677 +               if (KDB_STATE(SSBPT)) {
5678 +                       if (KDB_DEBUG(BP))
5679 +                               kdb_printf("ssbpt\n");
5680 +                       KDB_STATE_CLEAR(SSBPT);
5681 +                       for(i=0,bp=kdb_breakpoints;
5682 +                           i < KDB_MAXBPT;
5683 +                           i++, bp++) {
5684 +                               if (KDB_DEBUG(BP))
5685 +                                       kdb_printf("bp 0x%p enabled %d delayed %d global %d cpu %d\n",
5686 +                                                  bp, bp->bp_enabled, bp->bp_delayed, bp->bp_global, bp->bp_cpu);
5687 +                               if (!bp->bp_enabled)
5688 +                                       continue;
5689 +                               if (!bp->bp_global && bp->bp_cpu != smp_processor_id())
5690 +                                       continue;
5691 +                               if (KDB_DEBUG(BP))
5692 +                                       kdb_printf("bp for this cpu\n");
5693 +                               if (bp->bp_delayed) {
5694 +                                       bp->bp_delayed = 0;
5695 +                                       if (KDB_DEBUG(BP))
5696 +                                               kdb_printf("kdba_installbp\n");
5697 +                                       kdba_installbp(regs, bp);
5698 +                                       if (!KDB_STATE(DOING_SS)) {
5699 +                                               regs->eflags &= ~EF_TF;
5700 +                                               return(KDB_DB_SSBPT);
5701 +                                       }
5702 +                                       break;
5703 +                               }
5704 +                       }
5705 +                       if (i == KDB_MAXBPT) {
5706 +                               kdb_printf("kdb: Unable to find delayed breakpoint\n");
5707 +                       }
5708 +                       if (!KDB_STATE(DOING_SS)) {
5709 +                               regs->eflags &= ~EF_TF;
5710 +                               return(KDB_DB_NOBPT);
5711 +                       }
5712 +                       /* FALLTHROUGH */
5713 +               }
5714 +
5715 +               /*
5716 +                * KDB_STATE_DOING_SS is set when the kernel debugger is using
5717 +                * the processor trap flag to single-step a processor.  If a
5718 +                * single step trap occurs and this flag is clear, the SS trap
5719 +                * will be ignored by KDB and the kernel will be allowed to deal
5720 +                * with it as necessary (e.g. for ptrace).
5721 +                */
5722 +               if (!KDB_STATE(DOING_SS))
5723 +                       goto unknown;
5724 +
5725 +               /* single step */
5726 +               rv = KDB_DB_SS;         /* Indicate single step */
5727 +               if (KDB_STATE(DOING_SSB)) {
5728 +                       unsigned char instruction[2];
5729 +
5730 +                       kdb_id1(regs->eip);
5731 +                       if (kdb_getarea(instruction, regs->eip) ||
5732 +                           (instruction[0]&0xf0) == 0xe0 ||    /* short disp jumps */
5733 +                           (instruction[0]&0xf0) == 0x70 ||    /* Misc. jumps */
5734 +                           instruction[0]        == 0xc2 ||    /* ret */
5735 +                           instruction[0]        == 0x9a ||    /* call */
5736 +                           (instruction[0]&0xf8) == 0xc8 ||    /* enter, leave, iret, int, */
5737 +                           ((instruction[0]      == 0x0f) &&
5738 +                            ((instruction[1]&0xf0)== 0x80))
5739 +                          ) {
5740 +                               /*
5741 +                                * End the ssb command here.
5742 +                                */
5743 +                               KDB_STATE_CLEAR(DOING_SSB);
5744 +                               KDB_STATE_CLEAR(DOING_SS);
5745 +                       } else {
5746 +                               rv = KDB_DB_SSB; /* Indicate ssb - dismiss immediately */
5747 +                       }
5748 +               } else {
5749 +                       /*
5750 +                        * Print current insn
5751 +                        */
5752 +                       kdb_printf("SS trap at ");
5753 +                       kdb_symbol_print(regs->eip, NULL, KDB_SP_DEFAULT|KDB_SP_NEWLINE);
5754 +                       kdb_id1(regs->eip);
5755 +                       KDB_STATE_CLEAR(DOING_SS);
5756 +               }
5757 +
5758 +               if (rv != KDB_DB_SSB)
5759 +                       regs->eflags &= ~EF_TF;
5760 +       }
5761 +
5762 +       if (dr6 & DR6_B0) {
5763 +               rw = DR7_RW0(dr7);
5764 +               reg = 0;
5765 +               goto handle;
5766 +       }
5767 +
5768 +       if (dr6 & DR6_B1) {
5769 +               rw = DR7_RW1(dr7);
5770 +               reg = 1;
5771 +               goto handle;
5772 +       }
5773 +
5774 +       if (dr6 & DR6_B2) {
5775 +               rw = DR7_RW2(dr7);
5776 +               reg = 2;
5777 +               goto handle;
5778 +       }
5779 +
5780 +       if (dr6 & DR6_B3) {
5781 +               rw = DR7_RW3(dr7);
5782 +               reg = 3;
5783 +               goto handle;
5784 +       }
5785 +
5786 +       if (rv > 0)
5787 +               goto handled;
5788 +
5789 +       goto unknown;   /* dismiss */
5790 +
5791 +handle:
5792 +       /*
5793 +        * Set Resume Flag
5794 +        */
5795 +       regs->eflags |= EF_RF;
5796 +
5797 +       /*
5798 +        * Determine which breakpoint was encountered.
5799 +        */
5800 +       for(i=0, bp=kdb_breakpoints; i<KDB_MAXBPT; i++, bp++) {
5801 +               if (!(bp->bp_free)
5802 +                && (bp->bp_global || bp->bp_cpu == smp_processor_id())
5803 +                && (bp->bp_hard)
5804 +                && (bp->bp_hard->bph_reg == reg)) {
5805 +                       /*
5806 +                        * Hit this breakpoint.
5807 +                        */
5808 +                       kdb_printf("%s breakpoint #%d at " kdb_bfd_vma_fmt "\n",
5809 +                                 kdba_rwtypes[rw],
5810 +                                 i, bp->bp_addr);
5811 +
5812 +                       /*
5813 +                        * For an instruction breakpoint, disassemble
5814 +                        * the current instruction.
5815 +                        */
5816 +                       if (rw == 0) {
5817 +                               kdb_id1(regs->eip);
5818 +                       }
5819 +
5820 +                       goto handled;
5821 +               }
5822 +       }
5823 +
5824 +unknown:
5825 +       regs->eflags |= EF_RF;  /* Supress further faults */
5826 +       rv = KDB_DB_NOBPT;      /* Cause kdb() to return */
5827 +
5828 +handled:
5829 +
5830 +       /*
5831 +        * Clear the pending exceptions.
5832 +        */
5833 +       kdba_putdr6(0);
5834 +
5835 +       return rv;
5836 +}
5837 +
5838 +/*
5839 + * kdba_bp_trap
5840 + *
5841 + *     Perform breakpoint processing upon entry to the
5842 + *     processor breakpoint instruction fault.   Determine and print
5843 + *     the active breakpoint.
5844 + *
5845 + * Parameters:
5846 + *     regs    Exception frame containing machine register state
5847 + *     error   Error number passed to kdb.
5848 + * Outputs:
5849 + *     None.
5850 + * Returns:
5851 + *     0       Standard instruction or data breakpoint encountered
5852 + *     1       Single Step fault ('ss' command)
5853 + *     2       Single Step fault, caller should continue ('ssb' command)
5854 + *     3       No existing kdb breakpoint matches this debug exception
5855 + * Locking:
5856 + *     None.
5857 + * Remarks:
5858 + *
5859 + *     If multiple processors receive debug exceptions simultaneously,
5860 + *     one may be waiting at the kdb fence in kdb() while the user
5861 + *     issues a 'bc' command to clear the breakpoint the processor which
5862 + *     is waiting has already encountered.   If this is the case, the
5863 + *     debug registers will no longer match any entry in the breakpoint
5864 + *     table, and we'll return the value '3'.  This can cause a panic
5865 + *     in die_if_kernel().  It is safer to disable the breakpoint (bd),
5866 + *     'go' until all processors are past the breakpoint then clear the
5867 + *     breakpoint (bc).  This code recognises a breakpoint even when
5868 + *     disabled but not when it has been cleared.
5869 + *
5870 + *     WARNING: This routine resets the eip.  It should be called
5871 + *              once per breakpoint and the result cached.
5872 + */
5873 +
5874 +kdb_dbtrap_t
5875 +kdba_bp_trap(struct pt_regs *regs, int error_unused)
5876 +{
5877 +       int i;
5878 +       kdb_dbtrap_t rv;
5879 +       kdb_bp_t *bp;
5880 +
5881 +       if (KDB_NULL_REGS(regs))
5882 +               return KDB_DB_NOBPT;
5883 +
5884 +       /*
5885 +        * Determine which breakpoint was encountered.
5886 +        */
5887 +       if (KDB_DEBUG(BP))
5888 +               kdb_printf("kdba_bp_trap: eip=0x%lx (not adjusted) "
5889 +                          "eflags=0x%lx regs=0x%p esp=0x%lx\n",
5890 +                          regs->eip, regs->eflags, regs, regs->esp);
5891 +
5892 +       rv = KDB_DB_NOBPT;      /* Cause kdb() to return */
5893 +
5894 +       for(i=0, bp=kdb_breakpoints; i<KDB_MAXBPT; i++, bp++) {
5895 +               if (bp->bp_free)
5896 +                       continue;
5897 +               if (!bp->bp_global && bp->bp_cpu != smp_processor_id())
5898 +                       continue;
5899 +                if ((void *)bp->bp_addr == (void *)(regs->eip - bp->bp_adjust)) {
5900 +                       /* Hit this breakpoint.  */
5901 +                       regs->eip -= bp->bp_adjust;
5902 +                       kdb_printf("Instruction(i) breakpoint #%d at 0x%lx (adjusted)\n",
5903 +                                 i, regs->eip);
5904 +                       kdb_id1(regs->eip);
5905 +                       rv = KDB_DB_BPT;
5906 +                       bp->bp_delay = 1;
5907 +                       /* SSBPT is set when the kernel debugger must single
5908 +                        * step a task in order to re-establish an instruction
5909 +                        * breakpoint which uses the instruction replacement
5910 +                        * mechanism.  It is cleared by any action that removes
5911 +                        * the need to single-step the breakpoint.
5912 +                        */
5913 +                       KDB_STATE_SET(SSBPT);
5914 +                       break;
5915 +               }
5916 +       }
5917 +
5918 +       return rv;
5919 +}
5920 +
5921 +/*
5922 + * kdba_handle_bp
5923 + *
5924 + *     Handle an instruction-breakpoint trap.  Called when re-installing
5925 + *     an enabled breakpoint which has has the bp_delay bit set.
5926 + *
5927 + * Parameters:
5928 + * Returns:
5929 + * Locking:
5930 + * Remarks:
5931 + *
5932 + * Ok, we really need to:
5933 + *     1) Restore the original instruction byte
5934 + *     2) Single Step
5935 + *     3) Restore breakpoint instruction
5936 + *     4) Continue.
5937 + *
5938 + *
5939 + */
5940 +
5941 +static void
5942 +kdba_handle_bp(struct pt_regs *regs, kdb_bp_t *bp)
5943 +{
5944 +       if (KDB_NULL_REGS(regs))
5945 +               return;
5946 +
5947 +       if (KDB_DEBUG(BP))
5948 +               kdb_printf("regs->eip = 0x%lx\n", regs->eip);
5949 +
5950 +       /*
5951 +        * Setup single step
5952 +        */
5953 +       kdba_setsinglestep(regs);
5954 +
5955 +       /*
5956 +        * Reset delay attribute
5957 +        */
5958 +       bp->bp_delay = 0;
5959 +       bp->bp_delayed = 1;
5960 +}
5961 +
5962 +
5963 +/*
5964 + * kdba_bptype
5965 + *
5966 + *     Return a string describing type of breakpoint.
5967 + *
5968 + * Parameters:
5969 + *     bph     Pointer to hardware breakpoint description
5970 + * Outputs:
5971 + *     None.
5972 + * Returns:
5973 + *     Character string.
5974 + * Locking:
5975 + *     None.
5976 + * Remarks:
5977 + */
5978 +
5979 +char *
5980 +kdba_bptype(kdbhard_bp_t *bph)
5981 +{
5982 +       char *mode;
5983 +
5984 +       mode = kdba_rwtypes[bph->bph_mode];
5985 +
5986 +       return mode;
5987 +}
5988 +
5989 +/*
5990 + * kdba_printbpreg
5991 + *
5992 + *     Print register name assigned to breakpoint
5993 + *
5994 + * Parameters:
5995 + *     bph     Pointer hardware breakpoint structure
5996 + * Outputs:
5997 + *     None.
5998 + * Returns:
5999 + *     None.
6000 + * Locking:
6001 + *     None.
6002 + * Remarks:
6003 + */
6004 +
6005 +static void
6006 +kdba_printbpreg(kdbhard_bp_t *bph)
6007 +{
6008 +       kdb_printf(" in dr%ld", bph->bph_reg);
6009 +}
6010 +
6011 +/*
6012 + * kdba_printbp
6013 + *
6014 + *     Print string describing hardware breakpoint.
6015 + *
6016 + * Parameters:
6017 + *     bph     Pointer to hardware breakpoint description
6018 + * Outputs:
6019 + *     None.
6020 + * Returns:
6021 + *     None.
6022 + * Locking:
6023 + *     None.
6024 + * Remarks:
6025 + */
6026 +
6027 +void
6028 +kdba_printbp(kdb_bp_t *bp)
6029 +{
6030 +       kdb_printf("\n    is enabled");
6031 +       if (bp->bp_hardtype) {
6032 +               kdba_printbpreg(bp->bp_hard);
6033 +               if (bp->bp_hard->bph_mode != 0) {
6034 +                       kdb_printf(" for %d bytes",
6035 +                                  bp->bp_hard->bph_length+1);
6036 +               }
6037 +       }
6038 +}
6039 +
6040 +/*
6041 + * kdba_parsebp
6042 + *
6043 + *     Parse architecture dependent portion of the
6044 + *     breakpoint command.
6045 + *
6046 + * Parameters:
6047 + *     None.
6048 + * Outputs:
6049 + *     None.
6050 + * Returns:
6051 + *     Zero for success, a kdb diagnostic for failure
6052 + * Locking:
6053 + *     None.
6054 + * Remarks:
6055 + *     for Ia32 architure, data access, data write and
6056 + *     I/O breakpoints are supported in addition to instruction
6057 + *     breakpoints.
6058 + *
6059 + *     {datar|dataw|io|inst} [length]
6060 + */
6061 +
6062 +int
6063 +kdba_parsebp(int argc, const char **argv, int *nextargp, kdb_bp_t *bp)
6064 +{
6065 +       int nextarg = *nextargp;
6066 +       int diag;
6067 +       kdbhard_bp_t *bph = &bp->bp_template;
6068 +
6069 +       bph->bph_mode = 0;              /* Default to instruction breakpoint */
6070 +       bph->bph_length = 0;            /* Length must be zero for insn bp */
6071 +       if ((argc + 1) != nextarg) {
6072 +               if (strnicmp(argv[nextarg], "datar", sizeof("datar")) == 0) {
6073 +                       bph->bph_mode = 3;
6074 +               } else if (strnicmp(argv[nextarg], "dataw", sizeof("dataw")) == 0) {
6075 +                       bph->bph_mode = 1;
6076 +               } else if (strnicmp(argv[nextarg], "io", sizeof("io")) == 0) {
6077 +                       bph->bph_mode = 2;
6078 +               } else if (strnicmp(argv[nextarg], "inst", sizeof("inst")) == 0) {
6079 +                       bph->bph_mode = 0;
6080 +               } else {
6081 +                       return KDB_ARGCOUNT;
6082 +               }
6083 +
6084 +               bph->bph_length = 3;    /* Default to 4 byte */
6085 +
6086 +               nextarg++;
6087 +
6088 +               if ((argc + 1) != nextarg) {
6089 +                       unsigned long len;
6090 +
6091 +                       diag = kdbgetularg((char *)argv[nextarg],
6092 +                                          &len);
6093 +                       if (diag)
6094 +                               return diag;
6095 +
6096 +
6097 +                       if ((len > 4) || (len == 3))
6098 +                               return KDB_BADLENGTH;
6099 +
6100 +                       bph->bph_length = len;
6101 +                       bph->bph_length--; /* Normalize for debug register */
6102 +                       nextarg++;
6103 +               }
6104 +
6105 +               if ((argc + 1) != nextarg)
6106 +                       return KDB_ARGCOUNT;
6107 +
6108 +               /*
6109 +                * Indicate to architecture independent level that
6110 +                * a hardware register assignment is required to enable
6111 +                * this breakpoint.
6112 +                */
6113 +
6114 +               bph->bph_free = 0;
6115 +       } else {
6116 +               if (KDB_DEBUG(BP))
6117 +                       kdb_printf("kdba_bp: no args, forcehw is %d\n", bp->bp_forcehw);
6118 +               if (bp->bp_forcehw) {
6119 +                       /*
6120 +                        * We are forced to use a hardware register for this
6121 +                        * breakpoint because either the bph or bpha
6122 +                        * commands were used to establish this breakpoint.
6123 +                        */
6124 +                       bph->bph_free = 0;
6125 +               } else {
6126 +                       /*
6127 +                        * Indicate to architecture dependent level that
6128 +                        * the instruction replacement breakpoint technique
6129 +                        * should be used for this breakpoint.
6130 +                        */
6131 +                       bph->bph_free = 1;
6132 +                       bp->bp_adjust = 1;      /* software, int 3 is one byte */
6133 +               }
6134 +       }
6135 +
6136 +       if (bph->bph_mode != 2 && kdba_verify_rw(bp->bp_addr, bph->bph_length+1)) {
6137 +               kdb_printf("Invalid address for breakpoint, ignoring bp command\n");
6138 +               return KDB_BADADDR;
6139 +       }
6140 +
6141 +       *nextargp = nextarg;
6142 +       return 0;
6143 +}
6144 +
6145 +/*
6146 + * kdba_allocbp
6147 + *
6148 + *     Associate a hardware register with a breakpoint.
6149 + *
6150 + * Parameters:
6151 + *     None.
6152 + * Outputs:
6153 + *     None.
6154 + * Returns:
6155 + *     A pointer to the allocated register kdbhard_bp_t structure for
6156 + *     success, Null and a non-zero diagnostic for failure.
6157 + * Locking:
6158 + *     None.
6159 + * Remarks:
6160 + */
6161 +
6162 +kdbhard_bp_t *
6163 +kdba_allocbp(kdbhard_bp_t *bph, int *diagp)
6164 +{
6165 +       int i;
6166 +       kdbhard_bp_t *newbph;
6167 +
6168 +       for(i=0,newbph=kdb_hardbreaks; i < KDB_MAXHARDBPT; i++, newbph++) {
6169 +               if (newbph->bph_free) {
6170 +                       break;
6171 +               }
6172 +       }
6173 +
6174 +       if (i == KDB_MAXHARDBPT) {
6175 +               *diagp = KDB_TOOMANYDBREGS;
6176 +               return NULL;
6177 +       }
6178 +
6179 +       *diagp = 0;
6180 +
6181 +       /*
6182 +        * Copy data from template.  Can't just copy the entire template
6183 +        * here because the register number in kdb_hardbreaks must be
6184 +        * preserved.
6185 +        */
6186 +       newbph->bph_data = bph->bph_data;
6187 +       newbph->bph_write = bph->bph_write;
6188 +       newbph->bph_mode = bph->bph_mode;
6189 +       newbph->bph_length = bph->bph_length;
6190 +
6191 +       /*
6192 +        * Mark entry allocated.
6193 +        */
6194 +       newbph->bph_free = 0;
6195 +
6196 +       return newbph;
6197 +}
6198 +
6199 +/*
6200 + * kdba_freebp
6201 + *
6202 + *     Deallocate a hardware breakpoint
6203 + *
6204 + * Parameters:
6205 + *     None.
6206 + * Outputs:
6207 + *     None.
6208 + * Returns:
6209 + *     Zero for success, a kdb diagnostic for failure
6210 + * Locking:
6211 + *     None.
6212 + * Remarks:
6213 + */
6214 +
6215 +void
6216 +kdba_freebp(kdbhard_bp_t *bph)
6217 +{
6218 +       bph->bph_free = 1;
6219 +}
6220 +
6221 +/*
6222 + * kdba_initbp
6223 + *
6224 + *     Initialize the breakpoint table for the hardware breakpoint
6225 + *     register.
6226 + *
6227 + * Parameters:
6228 + *     None.
6229 + * Outputs:
6230 + *     None.
6231 + * Returns:
6232 + *     Zero for success, a kdb diagnostic for failure
6233 + * Locking:
6234 + *     None.
6235 + * Remarks:
6236 + *
6237 + *     There is one entry per register.  On the ia32 architecture
6238 + *     all the registers are interchangeable, so no special allocation
6239 + *     criteria are required.
6240 + */
6241 +
6242 +void
6243 +kdba_initbp(void)
6244 +{
6245 +       int i;
6246 +       kdbhard_bp_t *bph;
6247 +
6248 +       /*
6249 +        * Clear the hardware breakpoint table
6250 +        */
6251 +
6252 +       memset(kdb_hardbreaks, '\0', sizeof(kdb_hardbreaks));
6253 +
6254 +       for(i=0,bph=kdb_hardbreaks; i<KDB_MAXHARDBPT; i++, bph++) {
6255 +               bph->bph_reg = i;
6256 +               bph->bph_free = 1;
6257 +       }
6258 +}
6259 +
6260 +/*
6261 + * kdba_installbp
6262 + *
6263 + *     Install a breakpoint
6264 + *
6265 + * Parameters:
6266 + *     regs    Exception frame
6267 + *     bp      Breakpoint structure for the breakpoint to be installed
6268 + * Outputs:
6269 + *     None.
6270 + * Returns:
6271 + *     0 if breakpoint installed.
6272 + * Locking:
6273 + *     None.
6274 + * Remarks:
6275 + *     For hardware breakpoints, a debug register is allocated
6276 + *     and assigned to the breakpoint.  If no debug register is
6277 + *     available, a warning message is printed and the breakpoint
6278 + *     is disabled.
6279 + *
6280 + *     For instruction replacement breakpoints, we must single-step
6281 + *     over the replaced instruction at this point so we can re-install
6282 + *     the breakpoint instruction after the single-step.  SSBPT is set
6283 + *     when the breakpoint is initially hit and is cleared by any action
6284 + *     that removes the need for single-step over the breakpoint.
6285 + */
6286 +
6287 +int
6288 +kdba_installbp(struct pt_regs *regs, kdb_bp_t *bp)
6289 +{
6290 +       /*
6291 +        * Install the breakpoint, if it is not already installed.
6292 +        */
6293 +
6294 +       if (KDB_DEBUG(BP)) {
6295 +               kdb_printf("kdba_installbp bp_installed %d\n", bp->bp_installed);
6296 +       }
6297 +       if (!KDB_STATE(SSBPT))
6298 +               bp->bp_delay = 0;
6299 +       if (!bp->bp_installed) {
6300 +               if (bp->bp_hardtype) {
6301 +                       kdba_installdbreg(bp);
6302 +                       bp->bp_installed = 1;
6303 +                       if (KDB_DEBUG(BP)) {
6304 +                               kdb_printf("kdba_installbp hardware reg %ld at " kdb_bfd_vma_fmt "\n",
6305 +                                          bp->bp_hard->bph_reg, bp->bp_addr);
6306 +                       }
6307 +               } else if (bp->bp_delay) {
6308 +                       if (KDB_DEBUG(BP))
6309 +                               kdb_printf("kdba_installbp delayed bp\n");
6310 +                       kdba_handle_bp(regs, bp);
6311 +               } else {
6312 +                       if (kdb_getarea_size(&(bp->bp_inst), bp->bp_addr, 1) ||
6313 +                           kdb_putword(bp->bp_addr, IA32_BREAKPOINT_INSTRUCTION, 1)) {
6314 +                               kdb_printf("kdba_installbp failed to set software breakpoint at 0x%lx\n", bp->bp_addr);
6315 +                               return(1);
6316 +                       }
6317 +                       bp->bp_installed = 1;
6318 +                       if (KDB_DEBUG(BP))
6319 +                               kdb_printf("kdba_installbp instruction 0x%x at " kdb_bfd_vma_fmt "\n",
6320 +                                          IA32_BREAKPOINT_INSTRUCTION, bp->bp_addr);
6321 +               }
6322 +       }
6323 +       return(0);
6324 +}
6325 +
6326 +/*
6327 + * kdba_removebp
6328 + *
6329 + *     Make a breakpoint ineffective.
6330 + *
6331 + * Parameters:
6332 + *     None.
6333 + * Outputs:
6334 + *     None.
6335 + * Returns:
6336 + *     None.
6337 + * Locking:
6338 + *     None.
6339 + * Remarks:
6340 + */
6341 +
6342 +int
6343 +kdba_removebp(kdb_bp_t *bp)
6344 +{
6345 +       /*
6346 +        * For hardware breakpoints, remove it from the active register,
6347 +        * for software breakpoints, restore the instruction stream.
6348 +        */
6349 +       if (KDB_DEBUG(BP)) {
6350 +               kdb_printf("kdba_removebp bp_installed %d\n", bp->bp_installed);
6351 +       }
6352 +       if (bp->bp_installed) {
6353 +               if (bp->bp_hardtype) {
6354 +                       if (KDB_DEBUG(BP)) {
6355 +                               kdb_printf("kdb: removing hardware reg %ld at " kdb_bfd_vma_fmt "\n",
6356 +                                          bp->bp_hard->bph_reg, bp->bp_addr);
6357 +                       }
6358 +                       kdba_removedbreg(bp);
6359 +               } else {
6360 +                       if (KDB_DEBUG(BP))
6361 +                               kdb_printf("kdb: restoring instruction 0x%x at " kdb_bfd_vma_fmt "\n",
6362 +                                          bp->bp_inst, bp->bp_addr);
6363 +                       if (kdb_putword(bp->bp_addr, bp->bp_inst, 1))
6364 +                               return(1);
6365 +               }
6366 +               bp->bp_installed = 0;
6367 +       }
6368 +       return(0);
6369 +}
6370 diff -Nurp linux-2.6.22-590/arch/i386/kdb/kdba_bt.c linux-2.6.22-600/arch/i386/kdb/kdba_bt.c
6371 --- linux-2.6.22-590/arch/i386/kdb/kdba_bt.c    1970-01-01 01:00:00.000000000 +0100
6372 +++ linux-2.6.22-600/arch/i386/kdb/kdba_bt.c    2008-04-09 18:16:14.000000000 +0200
6373 @@ -0,0 +1,473 @@
6374 +/*
6375 + * Kernel Debugger Architecture Dependent Stack Traceback
6376 + *
6377 + * This file is subject to the terms and conditions of the GNU General Public
6378 + * License.  See the file "COPYING" in the main directory of this archive
6379 + * for more details.
6380 + *
6381 + * Copyright (c) 1999-2006 Silicon Graphics, Inc.  All Rights Reserved.
6382 + */
6383 +
6384 +#include <linux/ctype.h>
6385 +#include <linux/string.h>
6386 +#include <linux/kernel.h>
6387 +#include <linux/sched.h>
6388 +#include <linux/kallsyms.h>
6389 +#include <linux/irq.h>
6390 +#include <linux/kdb.h>
6391 +#include <linux/kdbprivate.h>
6392 +#include <asm/system.h>
6393 +
6394 +/* On a 4K stack kernel, hardirq_ctx and softirq_ctx are [NR_CPUS] arrays.  The
6395 + * first element of each per-cpu stack is a struct thread_info.
6396 + */
6397 +void
6398 +kdba_get_stack_info_alternate(kdb_machreg_t addr, int cpu,
6399 +                             struct kdb_activation_record *ar)
6400 +{
6401 +#ifdef CONFIG_4KSTACKS
6402 +       struct thread_info *tinfo;
6403 +       static int first_time = 1;
6404 +       static struct thread_info **kdba_hardirq_ctx, **kdba_softirq_ctx;
6405 +       if (first_time) {
6406 +               kdb_symtab_t symtab;
6407 +               kdbgetsymval("hardirq_ctx", &symtab);
6408 +               kdba_hardirq_ctx = (struct thread_info **)symtab.sym_start;
6409 +               kdbgetsymval("softirq_ctx", &symtab);
6410 +               kdba_softirq_ctx = (struct thread_info **)symtab.sym_start;
6411 +               first_time = 0;
6412 +       }
6413 +       tinfo = (struct thread_info *)(addr & -THREAD_SIZE);
6414 +       if (cpu < 0) {
6415 +               /* Arbitrary address, see if it falls within any of the irq
6416 +                * stacks
6417 +                */
6418 +               int found = 0;
6419 +               for_each_online_cpu(cpu) {
6420 +                       if (tinfo == kdba_hardirq_ctx[cpu] ||
6421 +                           tinfo == kdba_softirq_ctx[cpu]) {
6422 +                               found = 1;
6423 +                               break;
6424 +                       }
6425 +               }
6426 +               if (!found)
6427 +                       return;
6428 +       }
6429 +       if (tinfo == kdba_hardirq_ctx[cpu] ||
6430 +           tinfo == kdba_softirq_ctx[cpu]) {
6431 +               ar->stack.physical_start = (kdb_machreg_t)tinfo;
6432 +               ar->stack.physical_end = ar->stack.physical_start + THREAD_SIZE;
6433 +               ar->stack.logical_start = ar->stack.physical_start +
6434 +                                         sizeof(struct thread_info);
6435 +               ar->stack.logical_end = ar->stack.physical_end;
6436 +               ar->stack.next = tinfo->previous_esp;
6437 +               if (tinfo == kdba_hardirq_ctx[cpu])
6438 +                       ar->stack.id = "hardirq_ctx";
6439 +               else
6440 +                       ar->stack.id = "softirq_ctx";
6441 +       }
6442 +#endif /* CONFIG_4KSTACKS */
6443 +}
6444 +
6445 +/* Given an address which claims to be on a stack, an optional cpu number and
6446 + * an optional task address, get information about the stack.
6447 + *
6448 + * t == NULL, cpu < 0 indicates an arbitrary stack address with no associated
6449 + * struct task, the address can be in an alternate stack or any task's normal
6450 + * stack.
6451 + *
6452 + * t != NULL, cpu >= 0 indicates a running task, the address can be in an
6453 + * alternate stack or that task's normal stack.
6454 + *
6455 + * t != NULL, cpu < 0 indicates a blocked task, the address can only be in that
6456 + * task's normal stack.
6457 + *
6458 + * t == NULL, cpu >= 0 is not a valid combination.
6459 + */
6460 +
6461 +static void
6462 +kdba_get_stack_info(kdb_machreg_t esp, int cpu,
6463 +                   struct kdb_activation_record *ar,
6464 +                   const struct task_struct *t)
6465 +{
6466 +       struct thread_info *tinfo;
6467 +       struct task_struct *g, *p;
6468 +       memset(&ar->stack, 0, sizeof(ar->stack));
6469 +       if (KDB_DEBUG(ARA))
6470 +               kdb_printf("%s: esp=0x%lx cpu=%d task=%p\n",
6471 +                          __FUNCTION__, esp, cpu, t);
6472 +       if (t == NULL || cpu >= 0) {
6473 +               kdba_get_stack_info_alternate(esp, cpu, ar);
6474 +               if (ar->stack.logical_start)
6475 +                       goto out;
6476 +       }
6477 +       esp &= -THREAD_SIZE;
6478 +       tinfo = (struct thread_info *)esp;
6479 +       if (t == NULL) {
6480 +               /* Arbitrary stack address without an associated task, see if
6481 +                * it falls within any normal process stack, including the idle
6482 +                * tasks.
6483 +                */
6484 +               kdb_do_each_thread(g, p) {
6485 +                       if (tinfo == task_thread_info(p)) {
6486 +                               t = p;
6487 +                               goto found;
6488 +                       }
6489 +               } kdb_while_each_thread(g, p);
6490 +               for_each_online_cpu(cpu) {
6491 +                       p = idle_task(cpu);
6492 +                       if (tinfo == task_thread_info(p)) {
6493 +                               t = p;
6494 +                               goto found;
6495 +                       }
6496 +               }
6497 +       found:
6498 +               if (KDB_DEBUG(ARA))
6499 +                       kdb_printf("%s: found task %p\n", __FUNCTION__, t);
6500 +       } else if (cpu >= 0) {
6501 +               /* running task */
6502 +               struct kdb_running_process *krp = kdb_running_process + cpu;
6503 +               if (krp->p != t || tinfo != task_thread_info(t))
6504 +                       t = NULL;
6505 +               if (KDB_DEBUG(ARA))
6506 +                       kdb_printf("%s: running task %p\n", __FUNCTION__, t);
6507 +       } else {
6508 +               /* blocked task */
6509 +               if (tinfo != task_thread_info(t))
6510 +                       t = NULL;
6511 +               if (KDB_DEBUG(ARA))
6512 +                       kdb_printf("%s: blocked task %p\n", __FUNCTION__, t);
6513 +       }
6514 +       if (t) {
6515 +               ar->stack.physical_start = esp;
6516 +               ar->stack.physical_end = esp + THREAD_SIZE;
6517 +               ar->stack.logical_start = esp + sizeof(struct thread_info);
6518 +               ar->stack.logical_end = ar->stack.physical_end;
6519 +               ar->stack.next = 0;
6520 +               ar->stack.id = "normal";
6521 +       }
6522 +out:
6523 +       if (ar->stack.physical_start && KDB_DEBUG(ARA)) {
6524 +               kdb_printf("%s: ar->stack\n", __FUNCTION__);
6525 +               kdb_printf("    physical_start=0x%lx\n", ar->stack.physical_start);
6526 +               kdb_printf("    physical_end=0x%lx\n", ar->stack.physical_end);
6527 +               kdb_printf("    logical_start=0x%lx\n", ar->stack.logical_start);
6528 +               kdb_printf("    logical_end=0x%lx\n", ar->stack.logical_end);
6529 +               kdb_printf("    next=0x%lx\n", ar->stack.next);
6530 +               kdb_printf("    id=%s\n", ar->stack.id);
6531 +       }
6532 +}
6533 +
6534 +/*
6535 + * bt_print_one
6536 + *
6537 + *     Print one back trace entry.
6538 + *
6539 + * Inputs:
6540 + *     eip     Current program counter, or return address.
6541 + *     esp     Stack pointer esp when at eip.
6542 + *     ar      Activation record for this frame.
6543 + *     symtab  Information about symbol that eip falls within.
6544 + *     argcount Maximum number of arguments to print.
6545 + * Outputs:
6546 + *     None.
6547 + * Returns:
6548 + *     None.
6549 + * Locking:
6550 + *     None.
6551 + * Remarks:
6552 + *     None.
6553 + */
6554 +
6555 +static void
6556 +bt_print_one(kdb_machreg_t eip, kdb_machreg_t esp,
6557 +            const struct kdb_activation_record *ar,
6558 +            const kdb_symtab_t *symtab, int argcount)
6559 +{
6560 +       int btsymarg = 0;
6561 +       int nosect = 0;
6562 +       kdb_machreg_t word;
6563 +
6564 +       kdbgetintenv("BTSYMARG", &btsymarg);
6565 +       kdbgetintenv("NOSECT", &nosect);
6566 +
6567 +       kdb_printf(kdb_machreg_fmt0, esp);
6568 +       kdb_symbol_print(eip, symtab, KDB_SP_SPACEB|KDB_SP_VALUE);
6569 +       if (argcount && ar->args) {
6570 +               int i, argc = ar->args;
6571 +               kdb_printf(" (");
6572 +               if (argc > argcount)
6573 +                       argc = argcount;
6574 +               for (i = 0; i < argc; i++) {
6575 +                       kdb_machreg_t argp = ar->arg[i];
6576 +                       if (i)
6577 +                               kdb_printf(", ");
6578 +                       kdb_getword(&word, argp, sizeof(word));
6579 +                       kdb_printf("0x%lx", word);
6580 +               }
6581 +               kdb_printf(")");
6582 +       }
6583 +       if (symtab->sym_name) {
6584 +               if (!nosect) {
6585 +                       kdb_printf("\n");
6586 +                       kdb_printf("                               %s",
6587 +                                  symtab->mod_name);
6588 +                       if (symtab->sec_name && symtab->sec_start)
6589 +                               kdb_printf(" 0x%lx 0x%lx",
6590 +                                          symtab->sec_start, symtab->sec_end);
6591 +                       kdb_printf(" 0x%lx 0x%lx",
6592 +                                  symtab->sym_start, symtab->sym_end);
6593 +               }
6594 +       }
6595 +       kdb_printf("\n");
6596 +       if (argcount && ar->args && btsymarg) {
6597 +               int i, argc = ar->args;
6598 +               kdb_symtab_t arg_symtab;
6599 +               for (i = 0; i < argc; i++) {
6600 +                       kdb_machreg_t argp = ar->arg[i];
6601 +                       kdb_getword(&word, argp, sizeof(word));
6602 +                       if (kdbnearsym(word, &arg_symtab)) {
6603 +                               kdb_printf("                               ");
6604 +                               kdb_symbol_print(word, &arg_symtab,
6605 +                                                KDB_SP_DEFAULT|KDB_SP_NEWLINE);
6606 +                       }
6607 +               }
6608 +       }
6609 +}
6610 +
6611 +/* Getting the starting point for a backtrace on a running process is
6612 + * moderately tricky.  kdba_save_running() saved the esp in krp->arch.esp, but
6613 + * that esp is not 100% accurate, it can be offset by a frame pointer or by the
6614 + * size of local variables in kdba_main_loop() and kdb_save_running().
6615 + *
6616 + * The calling sequence is kdb() -> kdba_main_loop() -> kdb_save_running() ->
6617 + * kdba_save_running().  Walk up the stack until we find a return address
6618 + * inside the main kdb() function and start the backtrace from there.
6619 + */
6620 +
6621 +static int
6622 +kdba_bt_stack_running(const struct task_struct *p,
6623 +                     const struct kdb_activation_record *ar,
6624 +                     kdb_machreg_t *eip, kdb_machreg_t *esp,
6625 +                     kdb_machreg_t *ebp)
6626 +{
6627 +       kdb_machreg_t addr, sp;
6628 +       kdb_symtab_t symtab;
6629 +       struct kdb_running_process *krp = kdb_running_process + task_cpu(p);
6630 +       int found = 0;
6631 +
6632 +       if (kdbgetsymval("kdb", &symtab) == 0)
6633 +               return 0;
6634 +       if (kdbnearsym(symtab.sym_start, &symtab) == 0)
6635 +               return 0;
6636 +       sp = krp->arch.esp;
6637 +       if (sp < ar->stack.logical_start || sp >= ar->stack.logical_end)
6638 +               return 0;
6639 +       while (sp < ar->stack.logical_end) {
6640 +               addr = *(kdb_machreg_t *)sp;
6641 +               if (addr >= symtab.sym_start && addr < symtab.sym_end) {
6642 +                       found = 1;
6643 +                       break;
6644 +               }
6645 +               sp += sizeof(kdb_machreg_t);
6646 +       }
6647 +       if (!found)
6648 +               return 0;
6649 +       *ebp = *esp = sp;
6650 +       *eip = addr;
6651 +       return 1;
6652 +}
6653 +
6654 +/*
6655 + * kdba_bt_stack
6656 + *
6657 + * Inputs:
6658 + *     addr    Pointer to Address provided to 'bt' command, if any.
6659 + *     argcount
6660 + *     p       Pointer to task for 'btp' command.
6661 + * Outputs:
6662 + *     None.
6663 + * Returns:
6664 + *     zero for success, a kdb diagnostic if error
6665 + * Locking:
6666 + *     none.
6667 + * Remarks:
6668 + *     mds comes in handy when examining the stack to do a manual
6669 + *     traceback.
6670 + */
6671 +
6672 +static int
6673 +kdba_bt_stack(kdb_machreg_t addr, int argcount, const struct task_struct *p)
6674 +{
6675 +       struct kdb_activation_record ar;
6676 +       kdb_machreg_t eip, esp, ebp, cs;
6677 +       kdb_symtab_t symtab;
6678 +       int first_time = 1, count = 0, btsp = 0, suppress;
6679 +       struct pt_regs *regs = NULL;
6680 +
6681 +       kdbgetintenv("BTSP", &btsp);
6682 +       suppress = !btsp;
6683 +       memset(&ar, 0, sizeof(ar));
6684 +
6685 +       /*
6686 +        * The caller may have supplied an address at which the
6687 +        * stack traceback operation should begin.  This address
6688 +        * is assumed by this code to point to a return-address
6689 +        * on the stack to be traced back.
6690 +        *
6691 +        * The end result of this will make it appear as if a function
6692 +        * entitled '<unknown>' was called from the function which
6693 +        * contains return-address.
6694 +        */
6695 +       if (addr) {
6696 +               eip = 0;
6697 +               ebp = 0;
6698 +               esp = addr;
6699 +               cs = __KERNEL_CS;       /* have to assume kernel space */
6700 +               suppress = 0;
6701 +               kdba_get_stack_info(esp, -1, &ar, NULL);
6702 +       } else {
6703 +               if (task_curr(p)) {
6704 +                       struct kdb_running_process *krp =
6705 +                           kdb_running_process + task_cpu(p);
6706 +
6707 +                       if (krp->seqno && krp->p == p
6708 +                           && krp->seqno >= kdb_seqno - 1) {
6709 +                               /* valid saved state, continue processing */
6710 +                       } else {
6711 +                               kdb_printf
6712 +                                   ("Process did not save state, cannot backtrace\n");
6713 +                               kdb_ps1(p);
6714 +                               return 0;
6715 +                       }
6716 +                       regs = krp->regs;
6717 +                       if (KDB_NULL_REGS(regs))
6718 +                               return KDB_BADREG;
6719 +                       kdba_getregcontents("xcs", regs, &cs);
6720 +                       if ((cs & 0xffff) != __KERNEL_CS) {
6721 +                               kdb_printf("Stack is not in kernel space, backtrace not available\n");
6722 +                               return 0;
6723 +                       }
6724 +                       kdba_getregcontents("eip", regs, &eip);
6725 +                       kdba_getregcontents("ebp", regs, &ebp);
6726 +                       esp = krp->arch.esp;
6727 +                       kdba_get_stack_info(esp, kdb_process_cpu(p), &ar, p);
6728 +                       if (kdba_bt_stack_running(p, &ar, &eip, &esp, &ebp) == 0) {
6729 +                               kdb_printf("%s: cannot adjust esp=0x%lx for a running task\n",
6730 +                                          __FUNCTION__, esp);
6731 +                       }
6732 +               } else {
6733 +                       /* Not on cpu, assume blocked.  Blocked tasks do not
6734 +                        * have pt_regs.  p->thread.{esp,eip} are set, esp
6735 +                        * points to the ebp value, assume kernel space.
6736 +                        */
6737 +                       eip = p->thread.eip;
6738 +                       esp = p->thread.esp;
6739 +                       ebp = *(unsigned long *)esp;
6740 +                       cs = __KERNEL_CS;
6741 +                       suppress = 0;
6742 +                       kdba_get_stack_info(esp, -1, &ar, p);
6743 +               }
6744 +       }
6745 +       if (!ar.stack.physical_start) {
6746 +               kdb_printf("esp=0x%lx is not in a valid kernel stack, backtrace not available\n",
6747 +                          esp);
6748 +               return 0;
6749 +       }
6750 +
6751 +       kdb_printf("esp        eip        Function (args)\n");
6752 +       if (ar.stack.next && !suppress)
6753 +               kdb_printf(" ======================= <%s>\n",
6754 +                          ar.stack.id);
6755 +
6756 +       /* Run through all the stacks */
6757 +       while (ar.stack.physical_start) {
6758 +               if (!first_time)
6759 +                       eip = *(kdb_machreg_t *)esp;
6760 +               first_time = 0;
6761 +               if (!suppress && __kernel_text_address(eip)) {
6762 +                       kdbnearsym(eip, &symtab);
6763 +                       bt_print_one(eip, esp, &ar, &symtab, argcount);
6764 +                       ++count;
6765 +               }
6766 +               if ((struct pt_regs *)esp == regs) {
6767 +                       if (ar.stack.next && suppress)
6768 +                               kdb_printf(" ======================= <%s>\n",
6769 +                                          ar.stack.id);
6770 +                       ++count;
6771 +                       suppress = 0;
6772 +               }
6773 +               esp += sizeof(eip);
6774 +               if (count > 200)
6775 +                       break;
6776 +               if (esp < ar.stack.logical_end)
6777 +                       continue;
6778 +               if (!ar.stack.next)
6779 +                       break;
6780 +               esp = ar.stack.next;
6781 +               if (KDB_DEBUG(ARA))
6782 +                       kdb_printf("new esp=0x%lx\n", esp);
6783 +               kdba_get_stack_info(esp, -1, &ar, NULL);
6784 +               if (!ar.stack.physical_start) {
6785 +                       kdb_printf("+++ Cannot resolve next stack\n");
6786 +               } else if (!suppress) {
6787 +                       kdb_printf(" ======================= <%s>\n",
6788 +                                  ar.stack.id);
6789 +                       ++count;
6790 +               }
6791 +       }
6792 +
6793 +       if (count > 200)
6794 +               kdb_printf("bt truncated, count limit reached\n");
6795 +       else if (suppress)
6796 +               kdb_printf
6797 +                   ("bt did not find pt_regs - no trace produced.  Suggest 'set BTSP 1'\n");
6798 +
6799 +       return 0;
6800 +}
6801 +
6802 +/*
6803 + * kdba_bt_address
6804 + *
6805 + *     Do a backtrace starting at a specified stack address.  Use this if the
6806 + *     heuristics get the stack decode wrong.
6807 + *
6808 + * Inputs:
6809 + *     addr    Address provided to 'bt' command.
6810 + *     argcount
6811 + * Outputs:
6812 + *     None.
6813 + * Returns:
6814 + *     zero for success, a kdb diagnostic if error
6815 + * Locking:
6816 + *     none.
6817 + * Remarks:
6818 + *     mds %esp comes in handy when examining the stack to do a manual
6819 + *     traceback.
6820 + */
6821 +
6822 +int kdba_bt_address(kdb_machreg_t addr, int argcount)
6823 +{
6824 +       return kdba_bt_stack(addr, argcount, NULL);
6825 +}
6826 +
6827 +/*
6828 + * kdba_bt_process
6829 + *
6830 + *     Do a backtrace for a specified process.
6831 + *
6832 + * Inputs:
6833 + *     p       Struct task pointer extracted by 'bt' command.
6834 + *     argcount
6835 + * Outputs:
6836 + *     None.
6837 + * Returns:
6838 + *     zero for success, a kdb diagnostic if error
6839 + * Locking:
6840 + *     none.
6841 + */
6842 +
6843 +int kdba_bt_process(const struct task_struct *p, int argcount)
6844 +{
6845 +       return kdba_bt_stack(0, argcount, p);
6846 +}
6847 diff -Nurp linux-2.6.22-590/arch/i386/kdb/kdba_id.c linux-2.6.22-600/arch/i386/kdb/kdba_id.c
6848 --- linux-2.6.22-590/arch/i386/kdb/kdba_id.c    1970-01-01 01:00:00.000000000 +0100
6849 +++ linux-2.6.22-600/arch/i386/kdb/kdba_id.c    2008-04-09 18:16:14.000000000 +0200
6850 @@ -0,0 +1,255 @@
6851 +/*
6852 + * Kernel Debugger Architecture Dependent Instruction Disassembly
6853 + *
6854 + * This file is subject to the terms and conditions of the GNU General Public
6855 + * License.  See the file "COPYING" in the main directory of this archive
6856 + * for more details.
6857 + *
6858 + * Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
6859 + */
6860 +
6861 +#include <stdarg.h>
6862 +#include <linux/kernel.h>
6863 +#include <linux/init.h>
6864 +#include <linux/ctype.h>
6865 +#include <linux/string.h>
6866 +#include <linux/kdb.h>
6867 +#include <linux/kdbprivate.h>
6868 +
6869 +/*
6870 + * kdba_dis_getsym
6871 + *
6872 + *     Get a symbol for the disassembler.
6873 + *
6874 + * Parameters:
6875 + *     addr    Address for which to get symbol
6876 + *     dip     Pointer to disassemble_info
6877 + * Returns:
6878 + *     0
6879 + * Locking:
6880 + * Remarks:
6881 + *     Not used for kdb.
6882 + */
6883 +
6884 +/* ARGSUSED */
6885 +static int
6886 +kdba_dis_getsym(bfd_vma addr, disassemble_info *dip)
6887 +{
6888 +
6889 +       return 0;
6890 +}
6891 +
6892 +/*
6893 + * kdba_printaddress
6894 + *
6895 + *     Print (symbolically) an address.
6896 + *
6897 + * Parameters:
6898 + *     addr    Address for which to get symbol
6899 + *     dip     Pointer to disassemble_info
6900 + *     flag    True if a ":<tab>" sequence should follow the address
6901 + * Returns:
6902 + *     0
6903 + * Locking:
6904 + * Remarks:
6905 + *
6906 + */
6907 +
6908 +/* ARGSUSED */
6909 +static void
6910 +kdba_printaddress(kdb_machreg_t addr, disassemble_info *dip, int flag)
6911 +{
6912 +       kdb_symtab_t symtab;
6913 +       int spaces = 5;
6914 +       unsigned int offset;
6915 +
6916 +       /*
6917 +        * Print a symbol name or address as necessary.
6918 +        */
6919 +       kdbnearsym(addr, &symtab);
6920 +       if (symtab.sym_name) {
6921 +               /* Do not use kdb_symbol_print here, it always does
6922 +                * kdb_printf but we want dip->fprintf_func.
6923 +                */
6924 +               dip->fprintf_func(dip->stream,
6925 +                       "0x%0*lx %s",
6926 +                       (int)(2*sizeof(addr)), addr, symtab.sym_name);
6927 +               if ((offset = addr - symtab.sym_start) == 0) {
6928 +                       spaces += 4;
6929 +               }
6930 +               else {
6931 +                       unsigned int o = offset;
6932 +                       while (o >>= 4)
6933 +                               --spaces;
6934 +                       dip->fprintf_func(dip->stream, "+0x%x", offset);
6935 +               }
6936 +
6937 +       } else {
6938 +               dip->fprintf_func(dip->stream, "0x%lx", addr);
6939 +       }
6940 +
6941 +       if (flag) {
6942 +               if (spaces < 1) {
6943 +                       spaces = 1;
6944 +               }
6945 +               dip->fprintf_func(dip->stream, ":%*s", spaces, " ");
6946 +       }
6947 +}
6948 +
6949 +/*
6950 + * kdba_dis_printaddr
6951 + *
6952 + *     Print (symbolically) an address.  Called by GNU disassembly
6953 + *     code via disassemble_info structure.
6954 + *
6955 + * Parameters:
6956 + *     addr    Address for which to get symbol
6957 + *     dip     Pointer to disassemble_info
6958 + * Returns:
6959 + *     0
6960 + * Locking:
6961 + * Remarks:
6962 + *     This function will never append ":<tab>" to the printed
6963 + *     symbolic address.
6964 + */
6965 +
6966 +static void
6967 +kdba_dis_printaddr(bfd_vma addr, disassemble_info *dip)
6968 +{
6969 +       kdba_printaddress(addr, dip, 0);
6970 +}
6971 +
6972 +/*
6973 + * kdba_dis_getmem
6974 + *
6975 + *     Fetch 'length' bytes from 'addr' into 'buf'.
6976 + *
6977 + * Parameters:
6978 + *     addr    Address for which to get symbol
6979 + *     buf     Address of buffer to fill with bytes from 'addr'
6980 + *     length  Number of bytes to fetch
6981 + *     dip     Pointer to disassemble_info
6982 + * Returns:
6983 + *     0 if data is available, otherwise error.
6984 + * Locking:
6985 + * Remarks:
6986 + *
6987 + */
6988 +
6989 +/* ARGSUSED */
6990 +static int
6991 +kdba_dis_getmem(bfd_vma addr, bfd_byte *buf, unsigned int length, disassemble_info *dip)
6992 +{
6993 +       return kdb_getarea_size(buf, addr, length);
6994 +}
6995 +
6996 +/*
6997 + * kdba_id_parsemode
6998 + *
6999 + *     Parse IDMODE environment variable string and
7000 + *     set appropriate value into "disassemble_info" structure.
7001 + *
7002 + * Parameters:
7003 + *     mode    Mode string
7004 + *     dip     Disassemble_info structure pointer
7005 + * Returns:
7006 + * Locking:
7007 + * Remarks:
7008 + *     We handle the values 'x86' and '8086' to enable either
7009 + *     32-bit instruction set or 16-bit legacy instruction set.
7010 + */
7011 +
7012 +int
7013 +kdba_id_parsemode(const char *mode, disassemble_info *dip)
7014 +{
7015 +
7016 +       if (mode) {
7017 +               if (strcmp(mode, "x86") == 0) {
7018 +                       dip->mach = bfd_mach_i386_i386;
7019 +               } else if (strcmp(mode, "8086") == 0) {
7020 +                       dip->mach = bfd_mach_i386_i8086;
7021 +               } else {
7022 +                       return KDB_BADMODE;
7023 +               }
7024 +       }
7025 +
7026 +       return 0;
7027 +}
7028 +
7029 +/*
7030 + * kdba_check_pc
7031 + *
7032 + *     Check that the pc is satisfactory.
7033 + *
7034 + * Parameters:
7035 + *     pc      Program Counter Value.
7036 + * Returns:
7037 + *     None
7038 + * Locking:
7039 + *     None.
7040 + * Remarks:
7041 + *     Can change pc.
7042 + */
7043 +
7044 +void
7045 +kdba_check_pc(kdb_machreg_t *pc)
7046 +{
7047 +       /* No action */
7048 +}
7049 +
7050 +/*
7051 + * kdba_id_printinsn
7052 + *
7053 + *     Format and print a single instruction at 'pc'. Return the
7054 + *     length of the instruction.
7055 + *
7056 + * Parameters:
7057 + *     pc      Program Counter Value.
7058 + *     dip     Disassemble_info structure pointer
7059 + * Returns:
7060 + *     Length of instruction, -1 for error.
7061 + * Locking:
7062 + *     None.
7063 + * Remarks:
7064 + *     Depends on 'IDMODE' environment variable.
7065 + */
7066 +
7067 +int
7068 +kdba_id_printinsn(kdb_machreg_t pc, disassemble_info *dip)
7069 +{
7070 +       kdba_printaddress(pc, dip, 1);
7071 +       return print_insn_i386_att(pc, dip);
7072 +}
7073 +
7074 +/*
7075 + * kdba_id_init
7076 + *
7077 + *     Initialize the architecture dependent elements of
7078 + *     the disassembly information structure
7079 + *     for the GNU disassembler.
7080 + *
7081 + * Parameters:
7082 + *     None.
7083 + * Outputs:
7084 + *     None.
7085 + * Returns:
7086 + *     None.
7087 + * Locking:
7088 + *     None.
7089 + * Remarks:
7090 + */
7091 +
7092 +void
7093 +kdba_id_init(disassemble_info *dip)
7094 +{
7095 +       dip->read_memory_func       = kdba_dis_getmem;
7096 +       dip->print_address_func     = kdba_dis_printaddr;
7097 +       dip->symbol_at_address_func = kdba_dis_getsym;
7098 +
7099 +       dip->flavour                = bfd_target_elf_flavour;
7100 +       dip->arch                   = bfd_arch_i386;
7101 +       dip->mach                   = bfd_mach_i386_i386;
7102 +       dip->endian                 = BFD_ENDIAN_LITTLE;
7103 +
7104 +       dip->display_endian         = BFD_ENDIAN_LITTLE;
7105 +}
7106 diff -Nurp linux-2.6.22-590/arch/i386/kdb/kdba_io.c linux-2.6.22-600/arch/i386/kdb/kdba_io.c
7107 --- linux-2.6.22-590/arch/i386/kdb/kdba_io.c    1970-01-01 01:00:00.000000000 +0100
7108 +++ linux-2.6.22-600/arch/i386/kdb/kdba_io.c    2008-04-09 18:16:14.000000000 +0200
7109 @@ -0,0 +1,503 @@
7110 +/*
7111 + * Kernel Debugger Architecture Dependent Console I/O handler
7112 + *
7113 + * This file is subject to the terms and conditions of the GNU General Public
7114 + * License.  See the file "COPYING" in the main directory of this archive
7115 + * for more details.
7116 + *
7117 + * Copyright (c) 1999-2006 Silicon Graphics, Inc.  All Rights Reserved.
7118 + */
7119 +
7120 +#include <linux/sched.h>
7121 +#include <linux/kernel.h>
7122 +#include <asm/io.h>
7123 +#include <linux/delay.h>
7124 +#include <linux/console.h>
7125 +#include <linux/ctype.h>
7126 +#include <linux/keyboard.h>
7127 +#include <linux/serial.h>
7128 +#include <linux/serial_reg.h>
7129 +
7130 +#include <linux/kdb.h>
7131 +#include <linux/kdbprivate.h>
7132 +#include <pc_keyb.h>
7133 +
7134 +#ifdef CONFIG_VT_CONSOLE
7135 +#define KDB_BLINK_LED 1
7136 +#else
7137 +#undef KDB_BLINK_LED
7138 +#endif
7139 +
7140 +#ifdef CONFIG_KDB_USB
7141 +struct kdb_usb_exchange kdb_usb_infos;
7142 +
7143 +EXPORT_SYMBOL(kdb_usb_infos);
7144 +
7145 +static unsigned char kdb_usb_keycode[256] = {
7146 +         0,  0,  0,  0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38,
7147 +        50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44,  2,  3,
7148 +         4,  5,  6,  7,  8,  9, 10, 11, 28,  1, 14, 15, 57, 12, 13, 26,
7149 +        27, 43, 84, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64,
7150 +        65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106,
7151 +       105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71,
7152 +        72, 73, 82, 83, 86,127,116,117, 85, 89, 90, 91, 92, 93, 94, 95,
7153 +       120,121,122,123,134,138,130,132,128,129,131,137,133,135,136,113,
7154 +       115,114,  0,  0,  0,124,  0,181,182,183,184,185,186,187,188,189,
7155 +       190,191,192,193,194,195,196,197,198,  0,  0,  0,  0,  0,  0,  0,
7156 +         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
7157 +         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
7158 +         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
7159 +         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
7160 +        29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113,
7161 +       150,158,159,128,136,177,178,176,142,152,173,140
7162 +};
7163 +
7164 +/* get_usb_char
7165 + * This function drives the UHCI controller,
7166 + * fetch the USB scancode and decode it
7167 + */
7168 +static int get_usb_char(void)
7169 +{
7170 +       static int usb_lock;
7171 +       unsigned char keycode, spec;
7172 +       extern u_short plain_map[], shift_map[], ctrl_map[];
7173 +
7174 +       /* Is USB initialized ? */
7175 +       if(!kdb_usb_infos.poll_func || !kdb_usb_infos.urb)
7176 +               return -1;
7177 +
7178 +       /* Transfer char if they are present */
7179 +       (*kdb_usb_infos.poll_func)(kdb_usb_infos.uhci, (struct urb *)kdb_usb_infos.urb);
7180 +
7181 +       spec = kdb_usb_infos.buffer[0];
7182 +       keycode = kdb_usb_infos.buffer[2];
7183 +       kdb_usb_infos.buffer[0] = (char)0;
7184 +       kdb_usb_infos.buffer[2] = (char)0;
7185 +
7186 +       if(kdb_usb_infos.buffer[3])
7187 +               return -1;
7188 +
7189 +       /* A normal key is pressed, decode it */
7190 +       if(keycode)
7191 +               keycode = kdb_usb_keycode[keycode];
7192 +
7193 +       /* 2 Keys pressed at one time ? */
7194 +       if (spec && keycode) {
7195 +               switch(spec)
7196 +               {
7197 +                       case 0x2:
7198 +                       case 0x20: /* Shift */
7199 +                               return shift_map[keycode];
7200 +                       case 0x1:
7201 +                       case 0x10: /* Ctrl */
7202 +                               return ctrl_map[keycode];
7203 +                       case 0x4:
7204 +                       case 0x40: /* Alt */
7205 +                               break;
7206 +               }
7207 +       }
7208 +       else {
7209 +               if(keycode) { /* If only one key pressed */
7210 +                       switch(keycode)
7211 +                       {
7212 +                               case 0x1C: /* Enter */
7213 +                                       return 13;
7214 +
7215 +                               case 0x3A: /* Capslock */
7216 +                                       usb_lock ? (usb_lock = 0) : (usb_lock = 1);
7217 +                                       break;
7218 +                               case 0x0E: /* Backspace */
7219 +                                       return 8;
7220 +                               case 0x0F: /* TAB */
7221 +                                       return 9;
7222 +                               case 0x77: /* Pause */
7223 +                                       break ;
7224 +                               default:
7225 +                                       if(!usb_lock) {
7226 +                                               return plain_map[keycode];
7227 +                                       }
7228 +                                       else {
7229 +                                               return shift_map[keycode];
7230 +                                       }
7231 +                       }
7232 +               }
7233 +       }
7234 +       return -1;
7235 +}
7236 +#endif /* CONFIG_KDB_USB */
7237 +
7238 +/*
7239 + * This module contains code to read characters from the keyboard or a serial
7240 + * port.
7241 + *
7242 + * It is used by the kernel debugger, and is polled, not interrupt driven.
7243 + *
7244 + */
7245 +
7246 +#ifdef KDB_BLINK_LED
7247 +/*
7248 + * send:  Send a byte to the keyboard controller.  Used primarily to
7249 + *       alter LED settings.
7250 + */
7251 +
7252 +static void
7253 +kdb_kbdsend(unsigned char byte)
7254 +{
7255 +       int timeout;
7256 +       for (timeout = 200 * 1000; timeout && (inb(KBD_STATUS_REG) & KBD_STAT_IBF); timeout--);
7257 +       outb(byte, KBD_DATA_REG);
7258 +       udelay(40);
7259 +       for (timeout = 200 * 1000; timeout && (~inb(KBD_STATUS_REG) & KBD_STAT_OBF); timeout--);
7260 +       inb(KBD_DATA_REG);
7261 +       udelay(40);
7262 +}
7263 +
7264 +static void
7265 +kdb_toggleled(int led)
7266 +{
7267 +       static int leds;
7268 +
7269 +       leds ^= led;
7270 +
7271 +       kdb_kbdsend(KBD_CMD_SET_LEDS);
7272 +       kdb_kbdsend((unsigned char)leds);
7273 +}
7274 +#endif /* KDB_BLINK_LED */
7275 +
7276 +#if defined(CONFIG_SERIAL_8250_CONSOLE) || defined(CONFIG_SERIAL_CORE_CONSOLE)
7277 +#define CONFIG_SERIAL_CONSOLE
7278 +#endif
7279 +
7280 +#if defined(CONFIG_SERIAL_CONSOLE)
7281 +
7282 +struct kdb_serial kdb_serial;
7283 +
7284 +static unsigned int
7285 +serial_inp(struct kdb_serial *kdb_serial, unsigned long offset)
7286 +{
7287 +       offset <<= kdb_serial->ioreg_shift;
7288 +
7289 +       switch (kdb_serial->io_type) {
7290 +       case SERIAL_IO_MEM:
7291 +               return readb((void __iomem *)(kdb_serial->iobase + offset));
7292 +               break;
7293 +       default:
7294 +               return inb(kdb_serial->iobase + offset);
7295 +               break;
7296 +       }
7297 +}
7298 +
7299 +/* Check if there is a byte ready at the serial port */
7300 +static int get_serial_char(void)
7301 +{
7302 +       unsigned char ch;
7303 +
7304 +       if (kdb_serial.iobase == 0)
7305 +               return -1;
7306 +
7307 +       if (serial_inp(&kdb_serial, UART_LSR) & UART_LSR_DR) {
7308 +               ch = serial_inp(&kdb_serial, UART_RX);
7309 +               if (ch == 0x7f)
7310 +                       ch = 8;
7311 +               return ch;
7312 +       }
7313 +       return -1;
7314 +}
7315 +#endif /* CONFIG_SERIAL_CONSOLE */
7316 +
7317 +#ifdef CONFIG_VT_CONSOLE
7318 +
7319 +static int kbd_exists;
7320 +
7321 +/*
7322 + * Check if the keyboard controller has a keypress for us.
7323 + * Some parts (Enter Release, LED change) are still blocking polled here,
7324 + * but hopefully they are all short.
7325 + */
7326 +static int get_kbd_char(void)
7327 +{
7328 +       int scancode, scanstatus;
7329 +       static int shift_lock;  /* CAPS LOCK state (0-off, 1-on) */
7330 +       static int shift_key;   /* Shift next keypress */
7331 +       static int ctrl_key;
7332 +       u_short keychar;
7333 +       extern u_short plain_map[], shift_map[], ctrl_map[];
7334 +
7335 +       if (KDB_FLAG(NO_I8042) || KDB_FLAG(NO_VT_CONSOLE) ||
7336 +           (inb(KBD_STATUS_REG) == 0xff && inb(KBD_DATA_REG) == 0xff)) {
7337 +               kbd_exists = 0;
7338 +               return -1;
7339 +       }
7340 +       kbd_exists = 1;
7341 +
7342 +       if ((inb(KBD_STATUS_REG) & KBD_STAT_OBF) == 0)
7343 +               return -1;
7344 +
7345 +       /*
7346 +        * Fetch the scancode
7347 +        */
7348 +       scancode = inb(KBD_DATA_REG);
7349 +       scanstatus = inb(KBD_STATUS_REG);
7350 +
7351 +       /*
7352 +        * Ignore mouse events.
7353 +        */
7354 +       if (scanstatus & KBD_STAT_MOUSE_OBF)
7355 +               return -1;
7356 +
7357 +       /*
7358 +        * Ignore release, trigger on make
7359 +        * (except for shift keys, where we want to
7360 +        *  keep the shift state so long as the key is
7361 +        *  held down).
7362 +        */
7363 +
7364 +       if (((scancode&0x7f) == 0x2a) || ((scancode&0x7f) == 0x36)) {
7365 +               /*
7366 +                * Next key may use shift table
7367 +                */
7368 +               if ((scancode & 0x80) == 0) {
7369 +                       shift_key=1;
7370 +               } else {
7371 +                       shift_key=0;
7372 +               }
7373 +               return -1;
7374 +       }
7375 +
7376 +       if ((scancode&0x7f) == 0x1d) {
7377 +               /*
7378 +                * Left ctrl key
7379 +                */
7380 +               if ((scancode & 0x80) == 0) {
7381 +                       ctrl_key = 1;
7382 +               } else {
7383 +                       ctrl_key = 0;
7384 +               }
7385 +               return -1;
7386 +       }
7387 +
7388 +       if ((scancode & 0x80) != 0)
7389 +               return -1;
7390 +
7391 +       scancode &= 0x7f;
7392 +
7393 +       /*
7394 +        * Translate scancode
7395 +        */
7396 +
7397 +       if (scancode == 0x3a) {
7398 +               /*
7399 +                * Toggle caps lock
7400 +                */
7401 +               shift_lock ^= 1;
7402 +
7403 +#ifdef KDB_BLINK_LED
7404 +               kdb_toggleled(0x4);
7405 +#endif
7406 +               return -1;
7407 +       }
7408 +
7409 +       if (scancode == 0x0e) {
7410 +               /*
7411 +                * Backspace
7412 +                */
7413 +               return 8;
7414 +       }
7415 +
7416 +       /* Special Key */
7417 +       switch (scancode) {
7418 +       case 0xF: /* Tab */
7419 +               return 9;
7420 +       case 0x53: /* Del */
7421 +               return 4;
7422 +       case 0x47: /* Home */
7423 +               return 1;
7424 +       case 0x4F: /* End */
7425 +               return 5;
7426 +       case 0x4B: /* Left */
7427 +               return 2;
7428 +       case 0x48: /* Up */
7429 +               return 16;
7430 +       case 0x50: /* Down */
7431 +               return 14;
7432 +       case 0x4D: /* Right */
7433 +               return 6;
7434 +       }
7435 +
7436 +       if (scancode == 0xe0) {
7437 +               return -1;
7438 +       }
7439 +
7440 +       /*
7441 +        * For Japanese 86/106 keyboards
7442 +        *      See comment in drivers/char/pc_keyb.c.
7443 +        *      - Masahiro Adegawa
7444 +        */
7445 +       if (scancode == 0x73) {
7446 +               scancode = 0x59;
7447 +       } else if (scancode == 0x7d) {
7448 +               scancode = 0x7c;
7449 +       }
7450 +
7451 +       if (!shift_lock && !shift_key && !ctrl_key) {
7452 +               keychar = plain_map[scancode];
7453 +       } else if (shift_lock || shift_key) {
7454 +               keychar = shift_map[scancode];
7455 +       } else if (ctrl_key) {
7456 +               keychar = ctrl_map[scancode];
7457 +       } else {
7458 +               keychar = 0x0020;
7459 +               kdb_printf("Unknown state/scancode (%d)\n", scancode);
7460 +       }
7461 +       keychar &= 0x0fff;
7462 +       if (keychar == '\t')
7463 +               keychar = ' ';
7464 +       switch (KTYP(keychar)) {
7465 +       case KT_LETTER:
7466 +       case KT_LATIN:
7467 +               if (isprint(keychar))
7468 +                       break;          /* printable characters */
7469 +               /* drop through */
7470 +       case KT_SPEC:
7471 +               if (keychar == K_ENTER)
7472 +                       break;
7473 +               /* drop through */
7474 +       default:
7475 +               return(-1);     /* ignore unprintables */
7476 +       }
7477 +
7478 +       if ((scancode & 0x7f) == 0x1c) {
7479 +               /*
7480 +                * enter key.  All done.  Absorb the release scancode.
7481 +                */
7482 +               while ((inb(KBD_STATUS_REG) & KBD_STAT_OBF) == 0)
7483 +                       ;
7484 +
7485 +               /*
7486 +                * Fetch the scancode
7487 +                */
7488 +               scancode = inb(KBD_DATA_REG);
7489 +               scanstatus = inb(KBD_STATUS_REG);
7490 +
7491 +               while (scanstatus & KBD_STAT_MOUSE_OBF) {
7492 +                       scancode = inb(KBD_DATA_REG);
7493 +                       scanstatus = inb(KBD_STATUS_REG);
7494 +               }
7495 +
7496 +               if (scancode != 0x9c) {
7497 +                       /*
7498 +                        * Wasn't an enter-release,  why not?
7499 +                        */
7500 +                       kdb_printf("kdb: expected enter got 0x%x status 0x%x\n",
7501 +                              scancode, scanstatus);
7502 +               }
7503 +
7504 +               kdb_printf("\n");
7505 +               return 13;
7506 +       }
7507 +
7508 +       return keychar & 0xff;
7509 +}
7510 +#endif /* CONFIG_VT_CONSOLE */
7511 +
7512 +#ifdef KDB_BLINK_LED
7513 +
7514 +/* Leave numlock alone, setting it messes up laptop keyboards with the keypad
7515 + * mapped over normal keys.
7516 + */
7517 +static int kdba_blink_mask = 0x1 | 0x4;
7518 +
7519 +#define BOGOMIPS (boot_cpu_data.loops_per_jiffy/(500000/HZ))
7520 +static int blink_led(void)
7521 +{
7522 +       static long delay;
7523 +
7524 +       if (kbd_exists == 0)
7525 +               return -1;
7526 +
7527 +       if (--delay < 0) {
7528 +               if (BOGOMIPS == 0)      /* early kdb */
7529 +                       delay = 150000000/1000;     /* arbitrary bogomips */
7530 +               else
7531 +                       delay = 150000000/BOGOMIPS; /* Roughly 1 second when polling */
7532 +               kdb_toggleled(kdba_blink_mask);
7533 +       }
7534 +       return -1;
7535 +}
7536 +#endif
7537 +
7538 +get_char_func poll_funcs[] = {
7539 +#if defined(CONFIG_VT_CONSOLE)
7540 +       get_kbd_char,
7541 +#endif
7542 +#if defined(CONFIG_SERIAL_CONSOLE)
7543 +       get_serial_char,
7544 +#endif
7545 +#ifdef KDB_BLINK_LED
7546 +       blink_led,
7547 +#endif
7548 +#ifdef CONFIG_KDB_USB
7549 +       get_usb_char,
7550 +#endif
7551 +       NULL
7552 +};
7553 +
7554 +/*
7555 + * On some Compaq Deskpro's, there is a keyboard freeze many times after
7556 + * exiting from the kdb. As kdb's keyboard handler is not interrupt-driven and
7557 + * uses a polled interface, it makes more sense to disable motherboard keyboard
7558 + * controller's OBF interrupts during kdb's polling.In case, of interrupts
7559 + * remaining enabled during kdb's polling, it may cause un-necessary
7560 + * interrupts being signalled during keypresses, which are also sometimes seen
7561 + * as spurious interrupts after exiting from kdb. This hack to disable OBF
7562 + * interrupts before entry to kdb and re-enabling them at kdb exit point also
7563 + * solves the keyboard freeze issue. These functions are called from
7564 + * kdb_local(), hence these are arch. specific setup and cleanup functions
7565 + * executing only on the local processor - ashishk@sco.com
7566 + */
7567 +
7568 +void kdba_local_arch_setup(void)
7569 +{
7570 +#ifdef CONFIG_VT_CONSOLE
7571 +       unsigned char c;
7572 +
7573 +       while (kbd_read_status() & KBD_STAT_IBF);
7574 +       kbd_write_command(KBD_CCMD_READ_MODE);
7575 +       mdelay(1);
7576 +       while (kbd_read_status() & KBD_STAT_IBF);
7577 +       while ( !(kbd_read_status() & KBD_STAT_OBF) );
7578 +       c = kbd_read_input();
7579 +       c &= ~KBD_MODE_KBD_INT;
7580 +       while (kbd_read_status() & KBD_STAT_IBF);
7581 +       kbd_write_command(KBD_CCMD_WRITE_MODE);
7582 +       mdelay(1);
7583 +       while (kbd_read_status() & KBD_STAT_IBF);
7584 +       kbd_write_output(c);
7585 +       mdelay(1);
7586 +       while (kbd_read_status() & KBD_STAT_IBF);
7587 +       mdelay(1);
7588 +#endif /* CONFIG_VT_CONSOLE */
7589 +}
7590 +
7591 +void kdba_local_arch_cleanup(void)
7592 +{
7593 +#ifdef CONFIG_VT_CONSOLE
7594 +       unsigned char c;
7595 +
7596 +       while (kbd_read_status() & KBD_STAT_IBF);
7597 +       kbd_write_command(KBD_CCMD_READ_MODE);
7598 +       mdelay(1);
7599 +       while (kbd_read_status() & KBD_STAT_IBF);
7600 +       while ( !(kbd_read_status() & KBD_STAT_OBF) );
7601 +       c = kbd_read_input();
7602 +       c |= KBD_MODE_KBD_INT;
7603 +       while (kbd_read_status() & KBD_STAT_IBF);
7604 +       kbd_write_command(KBD_CCMD_WRITE_MODE);
7605 +       mdelay(1);
7606 +       while (kbd_read_status() & KBD_STAT_IBF);
7607 +       kbd_write_output(c);
7608 +       mdelay(1);
7609 +       while (kbd_read_status() & KBD_STAT_IBF);
7610 +       mdelay(1);
7611 +#endif /* CONFIG_VT_CONSOLE */
7612 +}
7613 diff -Nurp linux-2.6.22-590/arch/i386/kdb/kdbasupport.c linux-2.6.22-600/arch/i386/kdb/kdbasupport.c
7614 --- linux-2.6.22-590/arch/i386/kdb/kdbasupport.c        1970-01-01 01:00:00.000000000 +0100
7615 +++ linux-2.6.22-600/arch/i386/kdb/kdbasupport.c        2008-04-09 18:16:14.000000000 +0200
7616 @@ -0,0 +1,1066 @@
7617 +/*
7618 + * Kernel Debugger Architecture Independent Support Functions
7619 + *
7620 + * This file is subject to the terms and conditions of the GNU General Public
7621 + * License.  See the file "COPYING" in the main directory of this archive
7622 + * for more details.
7623 + *
7624 + * Copyright (c) 1999-2006 Silicon Graphics, Inc.  All Rights Reserved.
7625 + */
7626 +
7627 +#include <linux/string.h>
7628 +#include <linux/stddef.h>
7629 +#include <linux/kernel.h>
7630 +#include <linux/module.h>
7631 +#include <linux/init.h>
7632 +#include <linux/irq.h>
7633 +#include <linux/ptrace.h>
7634 +#include <linux/mm.h>
7635 +#include <linux/sched.h>
7636 +#include <linux/hardirq.h>
7637 +#include <linux/kdb.h>
7638 +#include <linux/kdbprivate.h>
7639 +
7640 +#include <asm/processor.h>
7641 +#include <asm/msr.h>
7642 +#include <asm/uaccess.h>
7643 +#include <asm/desc.h>
7644 +
7645 +static kdb_machreg_t
7646 +kdba_getcr(int regnum)
7647 +{
7648 +       kdb_machreg_t contents = 0;
7649 +       switch(regnum) {
7650 +       case 0:
7651 +               __asm__ ("movl %%cr0,%0\n\t":"=r"(contents));
7652 +               break;
7653 +       case 1:
7654 +               break;
7655 +       case 2:
7656 +               __asm__ ("movl %%cr2,%0\n\t":"=r"(contents));
7657 +               break;
7658 +       case 3:
7659 +               __asm__ ("movl %%cr3,%0\n\t":"=r"(contents));
7660 +               break;
7661 +       case 4:
7662 +               __asm__ ("movl %%cr4,%0\n\t":"=r"(contents));
7663 +               break;
7664 +       default:
7665 +               break;
7666 +       }
7667 +
7668 +       return contents;
7669 +}
7670 +
7671 +static void
7672 +kdba_putdr(int regnum, kdb_machreg_t contents)
7673 +{
7674 +       switch(regnum) {
7675 +       case 0:
7676 +               __asm__ ("movl %0,%%db0\n\t"::"r"(contents));
7677 +               break;
7678 +       case 1:
7679 +               __asm__ ("movl %0,%%db1\n\t"::"r"(contents));
7680 +               break;
7681 +       case 2:
7682 +               __asm__ ("movl %0,%%db2\n\t"::"r"(contents));
7683 +               break;
7684 +       case 3:
7685 +               __asm__ ("movl %0,%%db3\n\t"::"r"(contents));
7686 +               break;
7687 +       case 4:
7688 +       case 5:
7689 +               break;
7690 +       case 6:
7691 +               __asm__ ("movl %0,%%db6\n\t"::"r"(contents));
7692 +               break;
7693 +       case 7:
7694 +               __asm__ ("movl %0,%%db7\n\t"::"r"(contents));
7695 +               break;
7696 +       default:
7697 +               break;
7698 +       }
7699 +}
7700 +
7701 +static kdb_machreg_t
7702 +kdba_getdr(int regnum)
7703 +{
7704 +       kdb_machreg_t contents = 0;
7705 +       switch(regnum) {
7706 +       case 0:
7707 +               __asm__ ("movl %%db0,%0\n\t":"=r"(contents));
7708 +               break;
7709 +       case 1:
7710 +               __asm__ ("movl %%db1,%0\n\t":"=r"(contents));
7711 +               break;
7712 +       case 2:
7713 +               __asm__ ("movl %%db2,%0\n\t":"=r"(contents));
7714 +               break;
7715 +       case 3:
7716 +               __asm__ ("movl %%db3,%0\n\t":"=r"(contents));
7717 +               break;
7718 +       case 4:
7719 +       case 5:
7720 +               break;
7721 +       case 6:
7722 +               __asm__ ("movl %%db6,%0\n\t":"=r"(contents));
7723 +               break;
7724 +       case 7:
7725 +               __asm__ ("movl %%db7,%0\n\t":"=r"(contents));
7726 +               break;
7727 +       default:
7728 +               break;
7729 +       }
7730 +
7731 +       return contents;
7732 +}
7733 +
7734 +kdb_machreg_t
7735 +kdba_getdr6(void)
7736 +{
7737 +       return kdba_getdr(6);
7738 +}
7739 +
7740 +kdb_machreg_t
7741 +kdba_getdr7(void)
7742 +{
7743 +       return kdba_getdr(7);
7744 +}
7745 +
7746 +void
7747 +kdba_putdr6(kdb_machreg_t contents)
7748 +{
7749 +       kdba_putdr(6, contents);
7750 +}
7751 +
7752 +static void
7753 +kdba_putdr7(kdb_machreg_t contents)
7754 +{
7755 +       kdba_putdr(7, contents);
7756 +}
7757 +
7758 +void
7759 +kdba_installdbreg(kdb_bp_t *bp)
7760 +{
7761 +       kdb_machreg_t dr7;
7762 +
7763 +       dr7 = kdba_getdr7();
7764 +
7765 +       kdba_putdr(bp->bp_hard->bph_reg, bp->bp_addr);
7766 +
7767 +       dr7 |= DR7_GE;
7768 +       if (cpu_has_de)
7769 +               set_in_cr4(X86_CR4_DE);
7770 +
7771 +       switch (bp->bp_hard->bph_reg){
7772 +       case 0:
7773 +               DR7_RW0SET(dr7,bp->bp_hard->bph_mode);
7774 +               DR7_LEN0SET(dr7,bp->bp_hard->bph_length);
7775 +               DR7_G0SET(dr7);
7776 +               break;
7777 +       case 1:
7778 +               DR7_RW1SET(dr7,bp->bp_hard->bph_mode);
7779 +               DR7_LEN1SET(dr7,bp->bp_hard->bph_length);
7780 +               DR7_G1SET(dr7);
7781 +               break;
7782 +       case 2:
7783 +               DR7_RW2SET(dr7,bp->bp_hard->bph_mode);
7784 +               DR7_LEN2SET(dr7,bp->bp_hard->bph_length);
7785 +               DR7_G2SET(dr7);
7786 +               break;
7787 +       case 3:
7788 +               DR7_RW3SET(dr7,bp->bp_hard->bph_mode);
7789 +               DR7_LEN3SET(dr7,bp->bp_hard->bph_length);
7790 +               DR7_G3SET(dr7);
7791 +               break;
7792 +       default:
7793 +               kdb_printf("kdb: Bad debug register!! %ld\n",
7794 +                          bp->bp_hard->bph_reg);
7795 +               break;
7796 +       }
7797 +
7798 +       kdba_putdr7(dr7);
7799 +       return;
7800 +}
7801 +
7802 +void
7803 +kdba_removedbreg(kdb_bp_t *bp)
7804 +{
7805 +       int regnum;
7806 +       kdb_machreg_t dr7;
7807 +
7808 +       if (!bp->bp_hard)
7809 +               return;
7810 +
7811 +       regnum = bp->bp_hard->bph_reg;
7812 +
7813 +       dr7 = kdba_getdr7();
7814 +
7815 +       kdba_putdr(regnum, 0);
7816 +
7817 +       switch (regnum) {
7818 +       case 0:
7819 +               DR7_G0CLR(dr7);
7820 +               DR7_L0CLR(dr7);
7821 +               break;
7822 +       case 1:
7823 +               DR7_G1CLR(dr7);
7824 +               DR7_L1CLR(dr7);
7825 +               break;
7826 +       case 2:
7827 +               DR7_G2CLR(dr7);
7828 +               DR7_L2CLR(dr7);
7829 +               break;
7830 +       case 3:
7831 +               DR7_G3CLR(dr7);
7832 +               DR7_L3CLR(dr7);
7833 +               break;
7834 +       default:
7835 +               kdb_printf("kdb: Bad debug register!! %d\n", regnum);
7836 +               break;
7837 +       }
7838 +
7839 +       kdba_putdr7(dr7);
7840 +}
7841 +
7842 +
7843 +/*
7844 + * kdba_getregcontents
7845 + *
7846 + *     Return the contents of the register specified by the
7847 + *     input string argument.   Return an error if the string
7848 + *     does not match a machine register.
7849 + *
7850 + *     The following pseudo register names are supported:
7851 + *        &regs         - Prints address of exception frame
7852 + *        kesp          - Prints kernel stack pointer at time of fault
7853 + *        cesp          - Prints current kernel stack pointer, inside kdb
7854 + *        ceflags       - Prints current flags, inside kdb
7855 + *        %<regname>    - Uses the value of the registers at the
7856 + *                        last time the user process entered kernel
7857 + *                        mode, instead of the registers at the time
7858 + *                        kdb was entered.
7859 + *
7860 + * Parameters:
7861 + *     regname         Pointer to string naming register
7862 + *     regs            Pointer to structure containing registers.
7863 + * Outputs:
7864 + *     *contents       Pointer to unsigned long to recieve register contents
7865 + * Returns:
7866 + *     0               Success
7867 + *     KDB_BADREG      Invalid register name
7868 + * Locking:
7869 + *     None.
7870 + * Remarks:
7871 + *     If kdb was entered via an interrupt from the kernel itself then
7872 + *     ss and esp are *not* on the stack.
7873 + */
7874 +
7875 +static struct kdbregs {
7876 +       char   *reg_name;
7877 +       size_t  reg_offset;
7878 +} kdbreglist[] = {
7879 +       { "eax",        offsetof(struct pt_regs, eax) },
7880 +       { "ebx",        offsetof(struct pt_regs, ebx) },
7881 +       { "ecx",        offsetof(struct pt_regs, ecx) },
7882 +       { "edx",        offsetof(struct pt_regs, edx) },
7883 +
7884 +       { "esi",        offsetof(struct pt_regs, esi) },
7885 +       { "edi",        offsetof(struct pt_regs, edi) },
7886 +       { "esp",        offsetof(struct pt_regs, esp) },
7887 +       { "eip",        offsetof(struct pt_regs, eip) },
7888 +
7889 +       { "ebp",        offsetof(struct pt_regs, ebp) },
7890 +       { "xss",        offsetof(struct pt_regs, xss) },
7891 +       { "xcs",        offsetof(struct pt_regs, xcs) },
7892 +       { "eflags",     offsetof(struct pt_regs, eflags) },
7893 +
7894 +       { "xds",        offsetof(struct pt_regs, xds) },
7895 +       { "xes",        offsetof(struct pt_regs, xes) },
7896 +       { "origeax",    offsetof(struct pt_regs, orig_eax) },
7897 +
7898 +};
7899 +
7900 +static const int nkdbreglist = sizeof(kdbreglist) / sizeof(struct kdbregs);
7901 +
7902 +static struct kdbregs dbreglist[] = {
7903 +       { "dr0",        0 },
7904 +       { "dr1",        1 },
7905 +       { "dr2",        2 },
7906 +       { "dr3",        3 },
7907 +       { "dr6",        6 },
7908 +       { "dr7",        7 },
7909 +};
7910 +
7911 +static const int ndbreglist = sizeof(dbreglist) / sizeof(struct kdbregs);
7912 +
7913 +int
7914 +kdba_getregcontents(const char *regname,
7915 +                   struct pt_regs *regs,
7916 +                   kdb_machreg_t *contents)
7917 +{
7918 +       int i;
7919 +
7920 +       if (strcmp(regname, "cesp") == 0) {
7921 +               asm volatile("movl %%esp,%0":"=m" (*contents));
7922 +               return 0;
7923 +       }
7924 +
7925 +       if (strcmp(regname, "ceflags") == 0) {
7926 +               unsigned long flags;
7927 +               local_save_flags(flags);
7928 +               *contents = flags;
7929 +               return 0;
7930 +       }
7931 +
7932 +       if (regname[0] == '%') {
7933 +               /* User registers:  %%e[a-c]x, etc */
7934 +               regname++;
7935 +               regs = (struct pt_regs *)
7936 +                       (kdb_current_task->thread.esp0 - sizeof(struct pt_regs));
7937 +       }
7938 +
7939 +       for (i=0; i<ndbreglist; i++) {
7940 +               if (strnicmp(dbreglist[i].reg_name,
7941 +                            regname,
7942 +                            strlen(regname)) == 0)
7943 +                       break;
7944 +       }
7945 +
7946 +       if ((i < ndbreglist)
7947 +        && (strlen(dbreglist[i].reg_name) == strlen(regname))) {
7948 +               *contents = kdba_getdr(dbreglist[i].reg_offset);
7949 +               return 0;
7950 +       }
7951 +
7952 +       if (!regs) {
7953 +               kdb_printf("%s: pt_regs not available, use bt* or pid to select a different task\n", __FUNCTION__);
7954 +               return KDB_BADREG;
7955 +       }
7956 +
7957 +       if (strcmp(regname, "&regs") == 0) {
7958 +               *contents = (unsigned long)regs;
7959 +               return 0;
7960 +       }
7961 +
7962 +       if (strcmp(regname, "kesp") == 0) {
7963 +               *contents = (unsigned long)regs + sizeof(struct pt_regs);
7964 +               if ((regs->xcs & 0xffff) == __KERNEL_CS) {
7965 +                       /* esp and ss are not on stack */
7966 +                       *contents -= 2*4;
7967 +               }
7968 +               return 0;
7969 +       }
7970 +
7971 +       for (i=0; i<nkdbreglist; i++) {
7972 +               if (strnicmp(kdbreglist[i].reg_name,
7973 +                            regname,
7974 +                            strlen(regname)) == 0)
7975 +                       break;
7976 +       }
7977 +
7978 +       if ((i < nkdbreglist)
7979 +        && (strlen(kdbreglist[i].reg_name) == strlen(regname))) {
7980 +               if ((regs->xcs & 0xffff) == __KERNEL_CS) {
7981 +                       /* No cpl switch, esp and ss are not on stack */
7982 +                       if (strcmp(kdbreglist[i].reg_name, "esp") == 0) {
7983 +                               *contents = (kdb_machreg_t)regs +
7984 +                                       sizeof(struct pt_regs) - 2*4;
7985 +                               return(0);
7986 +                       }
7987 +                       if (strcmp(kdbreglist[i].reg_name, "xss") == 0) {
7988 +                               asm volatile(
7989 +                                       "pushl %%ss\n"
7990 +                                       "popl %0\n"
7991 +                                       :"=m" (*contents));
7992 +                               return(0);
7993 +                       }
7994 +               }
7995 +               *contents = *(unsigned long *)((unsigned long)regs +
7996 +                               kdbreglist[i].reg_offset);
7997 +               return(0);
7998 +       }
7999 +
8000 +       return KDB_BADREG;
8001 +}
8002 +
8003 +/*
8004 + * kdba_setregcontents
8005 + *
8006 + *     Set the contents of the register specified by the
8007 + *     input string argument.   Return an error if the string
8008 + *     does not match a machine register.
8009 + *
8010 + *     Supports modification of user-mode registers via
8011 + *     %<register-name>
8012 + *
8013 + * Parameters:
8014 + *     regname         Pointer to string naming register
8015 + *     regs            Pointer to structure containing registers.
8016 + *     contents        Unsigned long containing new register contents
8017 + * Outputs:
8018 + * Returns:
8019 + *     0               Success
8020 + *     KDB_BADREG      Invalid register name
8021 + * Locking:
8022 + *     None.
8023 + * Remarks:
8024 + */
8025 +
8026 +int
8027 +kdba_setregcontents(const char *regname,
8028 +                 struct pt_regs *regs,
8029 +                 unsigned long contents)
8030 +{
8031 +       int i;
8032 +
8033 +       if (regname[0] == '%') {
8034 +               regname++;
8035 +               regs = (struct pt_regs *)
8036 +                       (kdb_current_task->thread.esp0 - sizeof(struct pt_regs));
8037 +       }
8038 +
8039 +       for (i=0; i<ndbreglist; i++) {
8040 +               if (strnicmp(dbreglist[i].reg_name,
8041 +                            regname,
8042 +                            strlen(regname)) == 0)
8043 +                       break;
8044 +       }
8045 +
8046 +       if ((i < ndbreglist)
8047 +        && (strlen(dbreglist[i].reg_name) == strlen(regname))) {
8048 +               kdba_putdr(dbreglist[i].reg_offset, contents);
8049 +               return 0;
8050 +       }
8051 +
8052 +       if (!regs) {
8053 +               kdb_printf("%s: pt_regs not available, use bt* or pid to select a different task\n", __FUNCTION__);
8054 +               return KDB_BADREG;
8055 +       }
8056 +
8057 +       for (i=0; i<nkdbreglist; i++) {
8058 +               if (strnicmp(kdbreglist[i].reg_name,
8059 +                            regname,
8060 +                            strlen(regname)) == 0)
8061 +                       break;
8062 +       }
8063 +
8064 +       if ((i < nkdbreglist)
8065 +        && (strlen(kdbreglist[i].reg_name) == strlen(regname))) {
8066 +               *(unsigned long *)((unsigned long)regs
8067 +                                  + kdbreglist[i].reg_offset) = contents;
8068 +               return 0;
8069 +       }
8070 +
8071 +       return KDB_BADREG;
8072 +}
8073 +
8074 +/*
8075 + * kdba_dumpregs
8076 + *
8077 + *     Dump the specified register set to the display.
8078 + *
8079 + * Parameters:
8080 + *     regs            Pointer to structure containing registers.
8081 + *     type            Character string identifying register set to dump
8082 + *     extra           string further identifying register (optional)
8083 + * Outputs:
8084 + * Returns:
8085 + *     0               Success
8086 + * Locking:
8087 + *     None.
8088 + * Remarks:
8089 + *     This function will dump the general register set if the type
8090 + *     argument is NULL (struct pt_regs).   The alternate register
8091 + *     set types supported by this function:
8092 + *
8093 + *     d               Debug registers
8094 + *     c               Control registers
8095 + *     u               User registers at most recent entry to kernel
8096 + *                     for the process currently selected with "pid" command.
8097 + * Following not yet implemented:
8098 + *     r               Memory Type Range Registers (extra defines register)
8099 + *
8100 + * MSR on i386/x86_64 are handled by rdmsr/wrmsr commands.
8101 + */
8102 +
8103 +int
8104 +kdba_dumpregs(struct pt_regs *regs,
8105 +           const char *type,
8106 +           const char *extra)
8107 +{
8108 +       int i;
8109 +       int count = 0;
8110 +
8111 +       if (type
8112 +        && (type[0] == 'u')) {
8113 +               type = NULL;
8114 +               regs = (struct pt_regs *)
8115 +                       (kdb_current_task->thread.esp0 - sizeof(struct pt_regs));
8116 +       }
8117 +
8118 +       if (type == NULL) {
8119 +               struct kdbregs *rlp;
8120 +               kdb_machreg_t contents;
8121 +
8122 +               if (!regs) {
8123 +                       kdb_printf("%s: pt_regs not available, use bt* or pid to select a different task\n", __FUNCTION__);
8124 +                       return KDB_BADREG;
8125 +               }
8126 +
8127 +               for (i=0, rlp=kdbreglist; i<nkdbreglist; i++,rlp++) {
8128 +                       kdb_printf("%s = ", rlp->reg_name);
8129 +                       kdba_getregcontents(rlp->reg_name, regs, &contents);
8130 +                       kdb_printf("0x%08lx ", contents);
8131 +                       if ((++count % 4) == 0)
8132 +                               kdb_printf("\n");
8133 +               }
8134 +
8135 +               kdb_printf("&regs = 0x%p\n", regs);
8136 +
8137 +               return 0;
8138 +       }
8139 +
8140 +       switch (type[0]) {
8141 +       case 'd':
8142 +       {
8143 +               unsigned long dr[8];
8144 +
8145 +               for(i=0; i<8; i++) {
8146 +                       if ((i == 4) || (i == 5)) continue;
8147 +                       dr[i] = kdba_getdr(i);
8148 +               }
8149 +               kdb_printf("dr0 = 0x%08lx  dr1 = 0x%08lx  dr2 = 0x%08lx  dr3 = 0x%08lx\n",
8150 +                          dr[0], dr[1], dr[2], dr[3]);
8151 +               kdb_printf("dr6 = 0x%08lx  dr7 = 0x%08lx\n",
8152 +                          dr[6], dr[7]);
8153 +               return 0;
8154 +       }
8155 +       case 'c':
8156 +       {
8157 +               unsigned long cr[5];
8158 +
8159 +               for (i=0; i<5; i++) {
8160 +                       cr[i] = kdba_getcr(i);
8161 +               }
8162 +               kdb_printf("cr0 = 0x%08lx  cr1 = 0x%08lx  cr2 = 0x%08lx  cr3 = 0x%08lx\ncr4 = 0x%08lx\n",
8163 +                          cr[0], cr[1], cr[2], cr[3], cr[4]);
8164 +               return 0;
8165 +       }
8166 +       case 'r':
8167 +               break;
8168 +       default:
8169 +               return KDB_BADREG;
8170 +       }
8171 +
8172 +       /* NOTREACHED */
8173 +       return 0;
8174 +}
8175 +EXPORT_SYMBOL(kdba_dumpregs);
8176 +
8177 +kdb_machreg_t
8178 +kdba_getpc(struct pt_regs *regs)
8179 +{
8180 +       return regs ? regs->eip : 0;
8181 +}
8182 +
8183 +int
8184 +kdba_setpc(struct pt_regs *regs, kdb_machreg_t newpc)
8185 +{
8186 +       if (KDB_NULL_REGS(regs))
8187 +               return KDB_BADREG;
8188 +       regs->eip = newpc;
8189 +       KDB_STATE_SET(IP_ADJUSTED);
8190 +       return 0;
8191 +}
8192 +
8193 +/*
8194 + * kdba_main_loop
8195 + *
8196 + *     Do any architecture specific set up before entering the main kdb loop.
8197 + *     The primary function of this routine is to make all processes look the
8198 + *     same to kdb, kdb must be able to list a process without worrying if the
8199 + *     process is running or blocked, so make all process look as though they
8200 + *     are blocked.
8201 + *
8202 + * Inputs:
8203 + *     reason          The reason KDB was invoked
8204 + *     error           The hardware-defined error code
8205 + *     error2          kdb's current reason code.  Initially error but can change
8206 + *                     acording to kdb state.
8207 + *     db_result       Result from break or debug point.
8208 + *     regs            The exception frame at time of fault/breakpoint.  If reason
8209 + *                     is SILENT or CPU_UP then regs is NULL, otherwise it should
8210 + *                     always be valid.
8211 + * Returns:
8212 + *     0       KDB was invoked for an event which it wasn't responsible
8213 + *     1       KDB handled the event for which it was invoked.
8214 + * Outputs:
8215 + *     Sets eip and esp in current->thread.
8216 + * Locking:
8217 + *     None.
8218 + * Remarks:
8219 + *     none.
8220 + */
8221 +
8222 +int
8223 +kdba_main_loop(kdb_reason_t reason, kdb_reason_t reason2, int error,
8224 +              kdb_dbtrap_t db_result, struct pt_regs *regs)
8225 +{
8226 +       int ret;
8227 +       kdb_save_running(regs);
8228 +       ret = kdb_main_loop(reason, reason2, error, db_result, regs);
8229 +       kdb_unsave_running(regs);
8230 +       return ret;
8231 +}
8232 +
8233 +void
8234 +kdba_disableint(kdb_intstate_t *state)
8235 +{
8236 +       unsigned long *fp = (unsigned long *)state;
8237 +       unsigned long flags;
8238 +
8239 +       local_irq_save(flags);
8240 +
8241 +       *fp = flags;
8242 +}
8243 +
8244 +void
8245 +kdba_restoreint(kdb_intstate_t *state)
8246 +{
8247 +       unsigned long flags = *(int *)state;
8248 +       local_irq_restore(flags);
8249 +}
8250 +
8251 +void
8252 +kdba_setsinglestep(struct pt_regs *regs)
8253 +{
8254 +       if (KDB_NULL_REGS(regs))
8255 +               return;
8256 +       if (regs->eflags & EF_IE)
8257 +               KDB_STATE_SET(A_IF);
8258 +       else
8259 +               KDB_STATE_CLEAR(A_IF);
8260 +       regs->eflags = (regs->eflags | EF_TF) & ~EF_IE;
8261 +}
8262 +
8263 +void
8264 +kdba_clearsinglestep(struct pt_regs *regs)
8265 +{
8266 +       if (KDB_NULL_REGS(regs))
8267 +               return;
8268 +       if (KDB_STATE(A_IF))
8269 +               regs->eflags |= EF_IE;
8270 +       else
8271 +               regs->eflags &= ~EF_IE;
8272 +}
8273 +
8274 +int asmlinkage
8275 +kdba_setjmp(kdb_jmp_buf *jb)
8276 +{
8277 +#if defined(CONFIG_FRAME_POINTER)
8278 +       __asm__ ("movl 8(%esp), %eax\n\t"
8279 +                "movl %ebx, 0(%eax)\n\t"
8280 +                "movl %esi, 4(%eax)\n\t"
8281 +                "movl %edi, 8(%eax)\n\t"
8282 +                "movl (%esp), %ecx\n\t"
8283 +                "movl %ecx, 12(%eax)\n\t"
8284 +                "leal 8(%esp), %ecx\n\t"
8285 +                "movl %ecx, 16(%eax)\n\t"
8286 +                "movl 4(%esp), %ecx\n\t"
8287 +                "movl %ecx, 20(%eax)\n\t");
8288 +#else   /* CONFIG_FRAME_POINTER */
8289 +       __asm__ ("movl 4(%esp), %eax\n\t"
8290 +                "movl %ebx, 0(%eax)\n\t"
8291 +                "movl %esi, 4(%eax)\n\t"
8292 +                "movl %edi, 8(%eax)\n\t"
8293 +                "movl %ebp, 12(%eax)\n\t"
8294 +                "leal 4(%esp), %ecx\n\t"
8295 +                "movl %ecx, 16(%eax)\n\t"
8296 +                "movl 0(%esp), %ecx\n\t"
8297 +                "movl %ecx, 20(%eax)\n\t");
8298 +#endif   /* CONFIG_FRAME_POINTER */
8299 +       return 0;
8300 +}
8301 +
8302 +void asmlinkage
8303 +kdba_longjmp(kdb_jmp_buf *jb, int reason)
8304 +{
8305 +#if defined(CONFIG_FRAME_POINTER)
8306 +       __asm__("movl 8(%esp), %ecx\n\t"
8307 +               "movl 12(%esp), %eax\n\t"
8308 +               "movl 20(%ecx), %edx\n\t"
8309 +               "movl 0(%ecx), %ebx\n\t"
8310 +               "movl 4(%ecx), %esi\n\t"
8311 +               "movl 8(%ecx), %edi\n\t"
8312 +               "movl 12(%ecx), %ebp\n\t"
8313 +               "movl 16(%ecx), %esp\n\t"
8314 +               "jmp *%edx\n");
8315 +#else    /* CONFIG_FRAME_POINTER */
8316 +       __asm__("movl 4(%esp), %ecx\n\t"
8317 +               "movl 8(%esp), %eax\n\t"
8318 +               "movl 20(%ecx), %edx\n\t"
8319 +               "movl 0(%ecx), %ebx\n\t"
8320 +               "movl 4(%ecx), %esi\n\t"
8321 +               "movl 8(%ecx), %edi\n\t"
8322 +               "movl 12(%ecx), %ebp\n\t"
8323 +               "movl 16(%ecx), %esp\n\t"
8324 +               "jmp *%edx\n");
8325 +#endif  /* CONFIG_FRAME_POINTER */
8326 +}
8327 +
8328 +/*
8329 + * kdba_pt_regs
8330 + *
8331 + *     Format a struct pt_regs
8332 + *
8333 + * Inputs:
8334 + *     argc    argument count
8335 + *     argv    argument vector
8336 + * Outputs:
8337 + *     None.
8338 + * Returns:
8339 + *     zero for success, a kdb diagnostic if error
8340 + * Locking:
8341 + *     none.
8342 + * Remarks:
8343 + *     If no address is supplied, it uses the last irq pt_regs.
8344 + */
8345 +
8346 +static int
8347 +kdba_pt_regs(int argc, const char **argv)
8348 +{
8349 +       int diag;
8350 +       kdb_machreg_t addr;
8351 +       long offset = 0;
8352 +       int nextarg;
8353 +       struct pt_regs *p;
8354 +       static const char *fmt = "  %-11.11s 0x%lx\n";
8355 +
8356 +       if (argc == 0) {
8357 +               addr = (kdb_machreg_t) get_irq_regs();
8358 +       } else if (argc == 1) {
8359 +               nextarg = 1;
8360 +               diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL);
8361 +               if (diag)
8362 +                       return diag;
8363 +       } else {
8364 +               return KDB_ARGCOUNT;
8365 +       }
8366 +
8367 +       p = (struct pt_regs *) addr;
8368 +       kdb_printf("struct pt_regs 0x%p-0x%p\n", p, (unsigned char *)p + sizeof(*p) - 1);
8369 +       kdb_print_nameval("ebx", p->ebx);
8370 +       kdb_print_nameval("ecx", p->ecx);
8371 +       kdb_print_nameval("edx", p->edx);
8372 +       kdb_print_nameval("esi", p->esi);
8373 +       kdb_print_nameval("edi", p->edi);
8374 +       kdb_print_nameval("ebp", p->ebp);
8375 +       kdb_print_nameval("eax", p->eax);
8376 +       kdb_printf(fmt, "xds", p->xds);
8377 +       kdb_printf(fmt, "xes", p->xes);
8378 +       kdb_print_nameval("orig_eax", p->orig_eax);
8379 +       kdb_print_nameval("eip", p->eip);
8380 +       kdb_printf(fmt, "xcs", p->xcs);
8381 +       kdb_printf(fmt, "eflags", p->eflags);
8382 +       kdb_printf(fmt, "esp", p->esp);
8383 +       kdb_printf(fmt, "xss", p->xss);
8384 +       return 0;
8385 +}
8386 +
8387 +/*
8388 + * kdba_stackdepth
8389 + *
8390 + *     Print processes that are using more than a specific percentage of their
8391 + *     stack.
8392 + *
8393 + * Inputs:
8394 + *     argc    argument count
8395 + *     argv    argument vector
8396 + * Outputs:
8397 + *     None.
8398 + * Returns:
8399 + *     zero for success, a kdb diagnostic if error
8400 + * Locking:
8401 + *     none.
8402 + * Remarks:
8403 + *     If no percentage is supplied, it uses 60.
8404 + */
8405 +
8406 +static void
8407 +kdba_stackdepth1(struct task_struct *p, unsigned long esp)
8408 +{
8409 +       struct thread_info *tinfo;
8410 +       int used;
8411 +       const char *type;
8412 +       kdb_ps1(p);
8413 +       do {
8414 +               tinfo = (struct thread_info *)(esp & -THREAD_SIZE);
8415 +               used = sizeof(*tinfo) + THREAD_SIZE - (esp & (THREAD_SIZE-1));
8416 +               type = NULL;
8417 +               if (kdb_task_has_cpu(p)) {
8418 +                       struct kdb_activation_record ar;
8419 +                       memset(&ar, 0, sizeof(ar));
8420 +                       kdba_get_stack_info_alternate(esp, -1, &ar);
8421 +                       type = ar.stack.id;
8422 +               }
8423 +               if (!type)
8424 +                       type = "process";
8425 +               kdb_printf("  %s stack %p esp %lx used %d\n", type, tinfo, esp, used);
8426 +               esp = tinfo->previous_esp;
8427 +       } while (esp);
8428 +}
8429 +
8430 +static int
8431 +kdba_stackdepth(int argc, const char **argv)
8432 +{
8433 +       int diag, cpu, threshold, used, over;
8434 +       unsigned long percentage;
8435 +       unsigned long esp;
8436 +       long offset = 0;
8437 +       int nextarg;
8438 +       struct task_struct *p, *g;
8439 +       struct kdb_running_process *krp;
8440 +       struct thread_info *tinfo;
8441 +
8442 +       if (argc == 0) {
8443 +               percentage = 60;
8444 +       } else if (argc == 1) {
8445 +               nextarg = 1;
8446 +               diag = kdbgetaddrarg(argc, argv, &nextarg, &percentage, &offset, NULL);
8447 +               if (diag)
8448 +                       return diag;
8449 +       } else {
8450 +               return KDB_ARGCOUNT;
8451 +       }
8452 +       percentage = max_t(int, percentage, 1);
8453 +       percentage = min_t(int, percentage, 100);
8454 +       threshold = ((2 * THREAD_SIZE * percentage) / 100 + 1) >> 1;
8455 +       kdb_printf("stackdepth: processes using more than %ld%% (%d bytes) of stack\n",
8456 +               percentage, threshold);
8457 +
8458 +       /* Run the active tasks first, they can have multiple stacks */
8459 +       for (cpu = 0, krp = kdb_running_process; cpu < NR_CPUS; ++cpu, ++krp) {
8460 +               if (!cpu_online(cpu))
8461 +                       continue;
8462 +               p = krp->p;
8463 +               esp = krp->arch.esp;
8464 +               over = 0;
8465 +               do {
8466 +                       tinfo = (struct thread_info *)(esp & -THREAD_SIZE);
8467 +                       used = sizeof(*tinfo) + THREAD_SIZE - (esp & (THREAD_SIZE-1));
8468 +                       if (used >= threshold)
8469 +                               over = 1;
8470 +                       esp = tinfo->previous_esp;
8471 +               } while (esp);
8472 +               if (over)
8473 +                       kdba_stackdepth1(p, krp->arch.esp);
8474 +       }
8475 +       /* Now the tasks that are not on cpus */
8476 +       kdb_do_each_thread(g, p) {
8477 +               if (kdb_task_has_cpu(p))
8478 +                       continue;
8479 +               esp = p->thread.esp;
8480 +               used = sizeof(*tinfo) + THREAD_SIZE - (esp & (THREAD_SIZE-1));
8481 +               over = used >= threshold;
8482 +               if (over)
8483 +                       kdba_stackdepth1(p, esp);
8484 +       } kdb_while_each_thread(g, p);
8485 +
8486 +       return 0;
8487 +}
8488 +
8489 +asmlinkage int kdb_call(void);
8490 +
8491 +/* Executed once on each cpu at startup. */
8492 +void
8493 +kdba_cpu_up(void)
8494 +{
8495 +}
8496 +
8497 +static int __init
8498 +kdba_arch_init(void)
8499 +{
8500 +#ifdef CONFIG_SMP
8501 +       set_intr_gate(KDB_VECTOR, kdb_interrupt);
8502 +#endif
8503 +       set_intr_gate(KDBENTER_VECTOR, kdb_call);
8504 +       return 0;
8505 +}
8506 +
8507 +arch_initcall(kdba_arch_init);
8508 +
8509 +/*
8510 + * kdba_init
8511 + *
8512 + *     Architecture specific initialization.
8513 + *
8514 + * Parameters:
8515 + *     None.
8516 + * Returns:
8517 + *     None.
8518 + * Locking:
8519 + *     None.
8520 + * Remarks:
8521 + *     None.
8522 + */
8523 +
8524 +void __init
8525 +kdba_init(void)
8526 +{
8527 +       kdba_arch_init();       /* Need to register KDBENTER_VECTOR early */
8528 +       kdb_register("pt_regs", kdba_pt_regs, "address", "Format struct pt_regs", 0);
8529 +       kdb_register("stackdepth", kdba_stackdepth, "[percentage]", "Print processes using >= stack percentage", 0);
8530 +
8531 +       return;
8532 +}
8533 +
8534 +/*
8535 + * kdba_adjust_ip
8536 + *
8537 + *     Architecture specific adjustment of instruction pointer before leaving
8538 + *     kdb.
8539 + *
8540 + * Parameters:
8541 + *     reason          The reason KDB was invoked
8542 + *     error           The hardware-defined error code
8543 + *     regs            The exception frame at time of fault/breakpoint.  If reason
8544 + *                     is SILENT or CPU_UP then regs is NULL, otherwise it should
8545 + *                     always be valid.
8546 + * Returns:
8547 + *     None.
8548 + * Locking:
8549 + *     None.
8550 + * Remarks:
8551 + *     noop on ix86.
8552 + */
8553 +
8554 +void
8555 +kdba_adjust_ip(kdb_reason_t reason, int error, struct pt_regs *regs)
8556 +{
8557 +       return;
8558 +}
8559 +
8560 +void
8561 +kdba_set_current_task(const struct task_struct *p)
8562 +{
8563 +       kdb_current_task = p;
8564 +       if (kdb_task_has_cpu(p)) {
8565 +               struct kdb_running_process *krp = kdb_running_process + kdb_process_cpu(p);
8566 +               kdb_current_regs = krp->regs;
8567 +               return;
8568 +       }
8569 +       kdb_current_regs = NULL;
8570 +}
8571 +
8572 +/*
8573 + * asm-i386 uaccess.h supplies __copy_to_user which relies on MMU to
8574 + * trap invalid addresses in the _xxx fields.  Verify the other address
8575 + * of the pair is valid by accessing the first and last byte ourselves,
8576 + * then any access violations should only be caused by the _xxx
8577 + * addresses,
8578 + */
8579 +
8580 +int
8581 +kdba_putarea_size(unsigned long to_xxx, void *from, size_t size)
8582 +{
8583 +       mm_segment_t oldfs = get_fs();
8584 +       int r;
8585 +       char c;
8586 +       c = *((volatile char *)from);
8587 +       c = *((volatile char *)from + size - 1);
8588 +
8589 +       if (to_xxx < PAGE_OFFSET) {
8590 +               return kdb_putuserarea_size(to_xxx, from, size);
8591 +       }
8592 +
8593 +       set_fs(KERNEL_DS);
8594 +       r = __copy_to_user_inatomic((void __user *)to_xxx, from, size);
8595 +       set_fs(oldfs);
8596 +       return r;
8597 +}
8598 +
8599 +int
8600 +kdba_getarea_size(void *to, unsigned long from_xxx, size_t size)
8601 +{
8602 +       mm_segment_t oldfs = get_fs();
8603 +       int r;
8604 +       *((volatile char *)to) = '\0';
8605 +       *((volatile char *)to + size - 1) = '\0';
8606 +
8607 +       if (from_xxx < PAGE_OFFSET) {
8608 +               return kdb_getuserarea_size(to, from_xxx, size);
8609 +       }
8610 +
8611 +       set_fs(KERNEL_DS);
8612 +       switch (size) {
8613 +       case 1:
8614 +               r = __copy_to_user_inatomic((void __user *)to, (void *)from_xxx, 1);
8615 +               break;
8616 +       case 2:
8617 +               r = __copy_to_user_inatomic((void __user *)to, (void *)from_xxx, 2);
8618 +               break;
8619 +       case 4:
8620 +               r = __copy_to_user_inatomic((void __user *)to, (void *)from_xxx, 4);
8621 +               break;
8622 +       case 8:
8623 +               r = __copy_to_user_inatomic((void __user *)to, (void *)from_xxx, 8);
8624 +               break;
8625 +       default:
8626 +               r = __copy_to_user_inatomic((void __user *)to, (void *)from_xxx, size);
8627 +               break;
8628 +       }
8629 +       set_fs(oldfs);
8630 +       return r;
8631 +}
8632 +
8633 +int
8634 +kdba_verify_rw(unsigned long addr, size_t size)
8635 +{
8636 +       unsigned char data[size];
8637 +       return(kdba_getarea_size(data, addr, size) || kdba_putarea_size(addr, data, size));
8638 +}
8639 +
8640 +#ifdef CONFIG_SMP
8641 +
8642 +#include <mach_ipi.h>
8643 +
8644 +/* When first entering KDB, try a normal IPI.  That reduces backtrace problems
8645 + * on the other cpus.
8646 + */
8647 +void
8648 +smp_kdb_stop(void)
8649 +{
8650 +       if (!KDB_FLAG(NOIPI))
8651 +               send_IPI_allbutself(KDB_VECTOR);
8652 +}
8653 +
8654 +/* The normal KDB IPI handler */
8655 +void
8656 +smp_kdb_interrupt(struct pt_regs *regs)
8657 +{
8658 +       struct pt_regs *old_regs = set_irq_regs(regs);
8659 +       ack_APIC_irq();
8660 +       irq_enter();
8661 +       kdb_ipi(regs, NULL);
8662 +       irq_exit();
8663 +       set_irq_regs(old_regs);
8664 +}
8665 +
8666 +/* Invoked once from kdb_wait_for_cpus when waiting for cpus.  For those cpus
8667 + * that have not responded to the normal KDB interrupt yet, hit them with an
8668 + * NMI event.
8669 + */
8670 +void
8671 +kdba_wait_for_cpus(void)
8672 +{
8673 +       int c;
8674 +       if (KDB_FLAG(CATASTROPHIC))
8675 +               return;
8676 +       kdb_printf("  Sending NMI to cpus that have not responded yet\n");
8677 +       for_each_online_cpu(c)
8678 +               if (kdb_running_process[c].seqno < kdb_seqno - 1)
8679 +                       send_IPI_mask(cpumask_of_cpu(c), NMI_VECTOR);
8680 +}
8681 +
8682 +#endif /* CONFIG_SMP */
8683 diff -Nurp linux-2.6.22-590/arch/i386/kdb/kdb_cmds linux-2.6.22-600/arch/i386/kdb/kdb_cmds
8684 --- linux-2.6.22-590/arch/i386/kdb/kdb_cmds     1970-01-01 01:00:00.000000000 +0100
8685 +++ linux-2.6.22-600/arch/i386/kdb/kdb_cmds     2008-04-09 18:16:14.000000000 +0200
8686 @@ -0,0 +1,17 @@
8687 +# Standard architecture specific commands for kdb.
8688 +# These commands are appended to those in kdb/kdb_cmds, see that file for
8689 +# restrictions.
8690 +
8691 +# Standard debugging information for first level support, invoked from archkdb*
8692 +# commands that are defined in kdb/kdb_cmds.
8693 +
8694 +defcmd archkdbcommon "" "Common arch debugging"
8695 +  set LINES 2000000
8696 +  set BTAPROMPT 0
8697 +  -summary
8698 +  -id %eip-24
8699 +  -cpu
8700 +  -ps
8701 +  -dmesg 600
8702 +  -bt
8703 +endefcmd
8704 diff -Nurp linux-2.6.22-590/arch/i386/kdb/Makefile linux-2.6.22-600/arch/i386/kdb/Makefile
8705 --- linux-2.6.22-590/arch/i386/kdb/Makefile     1970-01-01 01:00:00.000000000 +0100
8706 +++ linux-2.6.22-600/arch/i386/kdb/Makefile     2008-04-09 18:16:14.000000000 +0200
8707 @@ -0,0 +1,13 @@
8708 +#
8709 +# This file is subject to the terms and conditions of the GNU General Public
8710 +# License.  See the file "COPYING" in the main directory of this archive
8711 +# for more details.
8712 +#
8713 +# Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
8714 +#
8715 +
8716 +obj-$(CONFIG_KDB)      := kdba_bp.o kdba_id.o kdba_io.o kdbasupport.o i386-dis.o
8717 +
8718 +override CFLAGS := $(CFLAGS:%-pg=% )
8719 +
8720 +CFLAGS_kdba_io.o += -I $(TOPDIR)/arch/$(ARCH)/kdb
8721 diff -Nurp linux-2.6.22-590/arch/i386/kdb/pc_keyb.h linux-2.6.22-600/arch/i386/kdb/pc_keyb.h
8722 --- linux-2.6.22-590/arch/i386/kdb/pc_keyb.h    1970-01-01 01:00:00.000000000 +0100
8723 +++ linux-2.6.22-600/arch/i386/kdb/pc_keyb.h    2008-04-09 18:16:14.000000000 +0200
8724 @@ -0,0 +1,137 @@
8725 +/*
8726 + *     include/linux/pc_keyb.h
8727 + *
8728 + *     PC Keyboard And Keyboard Controller
8729 + *
8730 + *     (c) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
8731 + */
8732 +
8733 +/*
8734 + *     Configuration Switches
8735 + */
8736 +
8737 +#undef KBD_REPORT_ERR                  /* Report keyboard errors */
8738 +#define        KBD_REPORT_UNKN                 /* Report unknown scan codes */
8739 +#define        KBD_REPORT_TIMEOUTS             /* Report keyboard timeouts */
8740 +#undef KBD_IS_FOCUS_9000               /* We have the brain-damaged FOCUS-9000 keyboard */
8741 +#undef INITIALIZE_MOUSE                /* Define if your PS/2 mouse needs initialization. */
8742 +
8743 +
8744 +
8745 +#define KBD_INIT_TIMEOUT 1000          /* Timeout in ms for initializing the keyboard */
8746 +#define KBC_TIMEOUT 250                        /* Timeout in ms for sending to keyboard controller */
8747 +#define KBD_TIMEOUT 1000               /* Timeout in ms for keyboard command acknowledge */
8748 +
8749 +/*
8750 + *     Internal variables of the driver
8751 + */
8752 +
8753 +extern unsigned char pckbd_read_mask;
8754 +extern unsigned char aux_device_present;
8755 +
8756 +/*
8757 + *     Keyboard Controller Registers on normal PCs.
8758 + */
8759 +
8760 +#define KBD_STATUS_REG         0x64    /* Status register (R) */
8761 +#define KBD_CNTL_REG           0x64    /* Controller command register (W) */
8762 +#define KBD_DATA_REG           0x60    /* Keyboard data register (R/W) */
8763 +
8764 +/*
8765 + *     Keyboard Controller Commands
8766 + */
8767 +
8768 +#define KBD_CCMD_READ_MODE     0x20    /* Read mode bits */
8769 +#define KBD_CCMD_WRITE_MODE    0x60    /* Write mode bits */
8770 +#define KBD_CCMD_GET_VERSION   0xA1    /* Get controller version */
8771 +#define KBD_CCMD_MOUSE_DISABLE 0xA7    /* Disable mouse interface */
8772 +#define KBD_CCMD_MOUSE_ENABLE  0xA8    /* Enable mouse interface */
8773 +#define KBD_CCMD_TEST_MOUSE    0xA9    /* Mouse interface test */
8774 +#define KBD_CCMD_SELF_TEST     0xAA    /* Controller self test */
8775 +#define KBD_CCMD_KBD_TEST      0xAB    /* Keyboard interface test */
8776 +#define KBD_CCMD_KBD_DISABLE   0xAD    /* Keyboard interface disable */
8777 +#define KBD_CCMD_KBD_ENABLE    0xAE    /* Keyboard interface enable */
8778 +#define KBD_CCMD_WRITE_AUX_OBUF        0xD3    /* Write to output buffer as if
8779 +                                          initiated by the auxiliary device */
8780 +#define KBD_CCMD_WRITE_MOUSE   0xD4    /* Write the following byte to the mouse */
8781 +
8782 +/*
8783 + *     Keyboard Commands
8784 + */
8785 +
8786 +#define KBD_CMD_SET_LEDS       0xED    /* Set keyboard leds */
8787 +#define KBD_CMD_SET_RATE       0xF3    /* Set typematic rate */
8788 +#define KBD_CMD_ENABLE         0xF4    /* Enable scanning */
8789 +#define KBD_CMD_DISABLE                0xF5    /* Disable scanning */
8790 +#define KBD_CMD_RESET          0xFF    /* Reset */
8791 +
8792 +/*
8793 + *     Keyboard Replies
8794 + */
8795 +
8796 +#define KBD_REPLY_POR          0xAA    /* Power on reset */
8797 +#define KBD_REPLY_ACK          0xFA    /* Command ACK */
8798 +#define KBD_REPLY_RESEND       0xFE    /* Command NACK, send the cmd again */
8799 +
8800 +/*
8801 + *     Status Register Bits
8802 + */
8803 +
8804 +#define KBD_STAT_OBF           0x01    /* Keyboard output buffer full */
8805 +#define KBD_STAT_IBF           0x02    /* Keyboard input buffer full */
8806 +#define KBD_STAT_SELFTEST      0x04    /* Self test successful */
8807 +#define KBD_STAT_CMD           0x08    /* Last write was a command write (0=data) */
8808 +#define KBD_STAT_UNLOCKED      0x10    /* Zero if keyboard locked */
8809 +#define KBD_STAT_MOUSE_OBF     0x20    /* Mouse output buffer full */
8810 +#define KBD_STAT_GTO           0x40    /* General receive/xmit timeout */
8811 +#define KBD_STAT_PERR          0x80    /* Parity error */
8812 +
8813 +#define AUX_STAT_OBF (KBD_STAT_OBF | KBD_STAT_MOUSE_OBF)
8814 +
8815 +/*
8816 + *     Controller Mode Register Bits
8817 + */
8818 +
8819 +#define KBD_MODE_KBD_INT       0x01    /* Keyboard data generate IRQ1 */
8820 +#define KBD_MODE_MOUSE_INT     0x02    /* Mouse data generate IRQ12 */
8821 +#define KBD_MODE_SYS           0x04    /* The system flag (?) */
8822 +#define KBD_MODE_NO_KEYLOCK    0x08    /* The keylock doesn't affect the keyboard if set */
8823 +#define KBD_MODE_DISABLE_KBD   0x10    /* Disable keyboard interface */
8824 +#define KBD_MODE_DISABLE_MOUSE 0x20    /* Disable mouse interface */
8825 +#define KBD_MODE_KCC           0x40    /* Scan code conversion to PC format */
8826 +#define KBD_MODE_RFU           0x80
8827 +
8828 +/*
8829 + *     Mouse Commands
8830 + */
8831 +
8832 +#define AUX_SET_RES            0xE8    /* Set resolution */
8833 +#define AUX_SET_SCALE11                0xE6    /* Set 1:1 scaling */
8834 +#define AUX_SET_SCALE21                0xE7    /* Set 2:1 scaling */
8835 +#define AUX_GET_SCALE          0xE9    /* Get scaling factor */
8836 +#define AUX_SET_STREAM         0xEA    /* Set stream mode */
8837 +#define AUX_SET_SAMPLE         0xF3    /* Set sample rate */
8838 +#define AUX_ENABLE_DEV         0xF4    /* Enable aux device */
8839 +#define AUX_DISABLE_DEV                0xF5    /* Disable aux device */
8840 +#define AUX_RESET              0xFF    /* Reset aux device */
8841 +#define AUX_ACK                        0xFA    /* Command byte ACK. */
8842 +
8843 +#define AUX_BUF_SIZE           2048    /* This might be better divisible by
8844 +                                          three to make overruns stay in sync
8845 +                                          but then the read function would need
8846 +                                          a lock etc - ick */
8847 +
8848 +struct aux_queue {
8849 +       unsigned long head;
8850 +       unsigned long tail;
8851 +       wait_queue_head_t proc_list;
8852 +       struct fasync_struct *fasync;
8853 +       unsigned char buf[AUX_BUF_SIZE];
8854 +};
8855 +
8856 +
8857 +/* How to access the keyboard macros on this platform.  */
8858 +#define kbd_read_input() inb(KBD_DATA_REG)
8859 +#define kbd_read_status() inb(KBD_STATUS_REG)
8860 +#define kbd_write_output(val) outb(val, KBD_DATA_REG)
8861 +#define kbd_write_command(val) outb(val, KBD_CNTL_REG)
8862 diff -Nurp linux-2.6.22-590/arch/i386/kernel/entry.S linux-2.6.22-600/arch/i386/kernel/entry.S
8863 --- linux-2.6.22-590/arch/i386/kernel/entry.S   2008-04-09 18:10:46.000000000 +0200
8864 +++ linux-2.6.22-600/arch/i386/kernel/entry.S   2008-04-09 18:16:14.000000000 +0200
8865 @@ -976,6 +976,26 @@ ENTRY(alignment_check)
8866         CFI_ENDPROC
8867  END(alignment_check)
8868  
8869 +#ifdef CONFIG_KDB
8870 +
8871 +ENTRY(kdb_call)
8872 +       RING0_INT_FRAME
8873 +       pushl %eax              # save orig EAX
8874 +       CFI_ADJUST_CFA_OFFSET 4
8875 +       SAVE_ALL
8876 +       movl %esp,%ecx          # struct pt_regs
8877 +       movl $0,%edx            # error_code
8878 +       movl $1,%eax            # KDB_REASON_ENTER
8879 +       call  kdb
8880 +       jmp restore_all
8881 +       CFI_ENDPROC
8882 +
8883 +#ifdef CONFIG_SMP
8884 +BUILD_INTERRUPT(kdb_interrupt,KDB_VECTOR)
8885 +#endif /* CONFIG_SMP */
8886 +
8887 +#endif /* CONFIG_KDB */
8888 +
8889  ENTRY(divide_error)
8890         RING0_INT_FRAME
8891         pushl $0                        # no error code
8892 diff -Nurp linux-2.6.22-590/arch/i386/kernel/io_apic.c linux-2.6.22-600/arch/i386/kernel/io_apic.c
8893 --- linux-2.6.22-590/arch/i386/kernel/io_apic.c 2008-04-09 18:10:46.000000000 +0200
8894 +++ linux-2.6.22-600/arch/i386/kernel/io_apic.c 2008-04-09 18:16:14.000000000 +0200
8895 @@ -32,6 +32,10 @@
8896  #include <linux/sysdev.h>
8897  #include <linux/pci.h>
8898  #include <linux/msi.h>
8899 +
8900 +#ifdef CONFIG_KDB
8901 +#include <linux/kdb.h>
8902 +#endif /* CONFIG_KDB */
8903  #include <linux/htirq.h>
8904  #include <linux/freezer.h>
8905  #include <linux/kthread.h>
8906 @@ -1244,6 +1248,10 @@ next:
8907                 return -ENOSPC;
8908         if (vector == SYSCALL_VECTOR)
8909                 goto next;
8910 +#ifdef CONFIG_KDB
8911 +       if (vector == KDBENTER_VECTOR)
8912 +               goto next;
8913 +#endif /* CONFIG_KDB */
8914         for (i = 0; i < NR_IRQ_VECTORS; i++)
8915                 if (irq_vector[i] == vector)
8916                         goto next;
8917 diff -Nurp linux-2.6.22-590/arch/i386/kernel/reboot.c linux-2.6.22-600/arch/i386/kernel/reboot.c
8918 --- linux-2.6.22-590/arch/i386/kernel/reboot.c  2007-07-09 01:32:17.000000000 +0200
8919 +++ linux-2.6.22-600/arch/i386/kernel/reboot.c  2008-04-09 18:16:14.000000000 +0200
8920 @@ -3,6 +3,9 @@
8921   */
8922  
8923  #include <linux/mm.h>
8924 +#ifdef CONFIG_KDB
8925 +#include <linux/kdb.h>
8926 +#endif /* CONFIG_KDB */
8927  #include <linux/module.h>
8928  #include <linux/delay.h>
8929  #include <linux/init.h>
8930 @@ -313,6 +316,14 @@ static void native_machine_shutdown(void
8931          * all of the others, and disable their local APICs.
8932          */
8933  
8934 +#ifdef CONFIG_KDB
8935 +       /*
8936 +        * If this restart is occuring while kdb is running (e.g. reboot
8937 +        * command), the other CPU's are already stopped.  Don't try to
8938 +        * stop them yet again.
8939 +        */
8940 +       if (!KDB_IS_RUNNING())
8941 +#endif /* CONFIG_KDB */
8942         smp_send_stop();
8943  #endif /* CONFIG_SMP */
8944  
8945 diff -Nurp linux-2.6.22-590/arch/i386/kernel/traps.c linux-2.6.22-600/arch/i386/kernel/traps.c
8946 --- linux-2.6.22-590/arch/i386/kernel/traps.c   2008-04-09 18:10:52.000000000 +0200
8947 +++ linux-2.6.22-600/arch/i386/kernel/traps.c   2008-04-09 18:16:14.000000000 +0200
8948 @@ -41,6 +41,10 @@
8949  #include <linux/mca.h>
8950  #endif
8951  
8952 +#ifdef CONFIG_KDB
8953 +#include <linux/kdb.h>
8954 +#endif /* CONFIG_KDB */
8955 +
8956  #include <asm/processor.h>
8957  #include <asm/system.h>
8958  #include <asm/io.h>
8959 @@ -438,6 +442,10 @@ void die(const char * str, struct pt_reg
8960         bust_spinlocks(0);
8961         die.lock_owner = -1;
8962         spin_unlock_irqrestore(&die.lock, flags);
8963 +#ifdef CONFIG_KDB
8964 +       kdb_diemsg = str;
8965 +       kdb(KDB_REASON_OOPS, err, regs);
8966 +#endif /* CONFIG_KDB */
8967  
8968         if (!regs)
8969                 return;
8970 @@ -561,7 +569,7 @@ fastcall void do_##name(struct pt_regs *
8971  }
8972  
8973  DO_VM86_ERROR_INFO( 0, SIGFPE,  "divide error", divide_error, FPE_INTDIV, regs->eip)
8974 -#ifndef CONFIG_KPROBES
8975 +#if    !defined(CONFIG_KPROBES) && !defined(CONFIG_KDB)
8976  DO_VM86_ERROR( 3, SIGTRAP, "int3", int3)
8977  #endif
8978  DO_VM86_ERROR( 4, SIGSEGV, "overflow", overflow)
8979 @@ -670,6 +678,9 @@ io_check_error(unsigned char reason, str
8980  static __kprobes void
8981  unknown_nmi_error(unsigned char reason, struct pt_regs * regs)
8982  {
8983 +#ifdef CONFIG_KDB
8984 +       (void)kdb(KDB_REASON_NMI, reason, regs);
8985 +#endif /* CONFIG_KDB */
8986  #ifdef CONFIG_MCA
8987         /* Might actually be able to figure out what the guilty party
8988         * is. */
8989 @@ -705,6 +716,9 @@ void __kprobes die_nmi(struct pt_regs *r
8990         printk(" on CPU%d, eip %08lx, registers:\n",
8991                 smp_processor_id(), regs->eip);
8992         show_registers(regs);
8993 +#ifdef CONFIG_KDB
8994 +       kdb(KDB_REASON_NMI, 0, regs);
8995 +#endif /* CONFIG_KDB */
8996         console_silent();
8997         spin_unlock(&nmi_print_lock);
8998         bust_spinlocks(0);
8999 @@ -727,7 +741,17 @@ static __kprobes void default_do_nmi(str
9000         /* Only the BSP gets external NMIs from the system.  */
9001         if (!smp_processor_id())
9002                 reason = get_nmi_reason();
9003
9004 +
9005 +#if defined(CONFIG_SMP) && defined(CONFIG_KDB)
9006 +       /*
9007 +        * Call the kernel debugger to see if this NMI is due
9008 +        * to an KDB requested IPI.  If so, kdb will handle it.
9009 +        */
9010 +       if (kdb_ipi(regs, NULL)) {
9011 +               return;
9012 +       }
9013 +#endif /* defined(CONFIG_SMP) && defined(CONFIG_KDB) */
9014 +
9015         if (!(reason & 0xc0)) {
9016                 if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT)
9017                                                         == NOTIFY_STOP)
9018 @@ -776,6 +800,10 @@ fastcall __kprobes void do_nmi(struct pt
9019  #ifdef CONFIG_KPROBES
9020  fastcall void __kprobes do_int3(struct pt_regs *regs, long error_code)
9021  {
9022 +#ifdef CONFIG_KDB
9023 +       if (kdb(KDB_REASON_BREAK, error_code, regs))
9024 +               return;
9025 +#endif
9026         if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP)
9027                         == NOTIFY_STOP)
9028                 return;
9029 @@ -815,6 +843,11 @@ fastcall void __kprobes do_debug(struct 
9030  
9031         get_debugreg(condition, 6);
9032  
9033 +#ifdef CONFIG_KDB
9034 +       if (kdb(KDB_REASON_DEBUG, error_code, regs))
9035 +               return;
9036 +#endif /* CONFIG_KDB */
9037 +
9038         if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
9039                                         SIGTRAP) == NOTIFY_STOP)
9040                 return;
9041 @@ -868,6 +901,16 @@ clear_TF_reenable:
9042         return;
9043  }
9044  
9045 +#if    defined(CONFIG_KDB) && !defined(CONFIG_KPROBES)
9046 +fastcall void do_int3(struct pt_regs * regs, long error_code)
9047 +{
9048 +       if (kdb(KDB_REASON_BREAK, error_code, regs))
9049 +               return;
9050 +       do_trap(3, SIGTRAP, "int3", 1, regs, error_code, NULL);
9051 +}
9052 +#endif /* CONFIG_KDB && !CONFIG_KPROBES */
9053 +
9054 +
9055  /*
9056   * Note that we play around with the 'TS' bit in an attempt to get
9057   * the correct behaviour even in the presence of the asynchronous
9058 diff -Nurp linux-2.6.22-590/arch/i386/Makefile linux-2.6.22-600/arch/i386/Makefile
9059 --- linux-2.6.22-590/arch/i386/Makefile 2008-04-09 18:10:46.000000000 +0200
9060 +++ linux-2.6.22-600/arch/i386/Makefile 2008-04-09 18:16:14.000000000 +0200
9061 @@ -108,6 +108,7 @@ drivers-$(CONFIG_PCI)                       += arch/i386/pci
9062  # must be linked after kernel/
9063  drivers-$(CONFIG_OPROFILE)             += arch/i386/oprofile/
9064  drivers-$(CONFIG_PM)                   += arch/i386/power/
9065 +drivers-$(CONFIG_KDB)                  += arch/i386/kdb/
9066  
9067  CFLAGS += $(mflags-y)
9068  AFLAGS += $(mflags-y)
9069 diff -Nurp linux-2.6.22-590/arch/x86_64/Kconfig.debug linux-2.6.22-600/arch/x86_64/Kconfig.debug
9070 --- linux-2.6.22-590/arch/x86_64/Kconfig.debug  2007-07-09 01:32:17.000000000 +0200
9071 +++ linux-2.6.22-600/arch/x86_64/Kconfig.debug  2008-04-09 18:16:24.000000000 +0200
9072 @@ -16,6 +16,76 @@ config DEBUG_RODATA
9073          of the kernel code won't be covered by a 2MB TLB anymore.
9074          If in doubt, say "N".
9075  
9076 +config KDB
9077 +       bool "Built-in Kernel Debugger support"
9078 +       depends on DEBUG_KERNEL
9079 +       select KALLSYMS
9080 +       select KALLSYMS_ALL
9081 +       help
9082 +         This option provides a built-in kernel debugger.  The built-in
9083 +         kernel debugger contains commands which allow memory to be examined,
9084 +         instructions to be disassembled and breakpoints to be set.  For details,
9085 +         see Documentation/kdb/kdb.mm and the manual pages kdb_bt, kdb_ss, etc.
9086 +         Kdb can also be used via the serial port.  Set up the system to
9087 +         have a serial console (see Documentation/serial-console.txt).
9088 +         The key sequence <escape>KDB on the serial port will cause the
9089 +         kernel debugger to be entered with input from the serial port and
9090 +         output to the serial console.  If unsure, say N.
9091 +
9092 +config KDB_MODULES
9093 +       tristate "KDB modules"
9094 +       depends on KDB
9095 +       help
9096 +         KDB can be extended by adding your own modules, in directory
9097 +         kdb/modules.  This option selects the way that these modules should
9098 +         be compiled, as free standing modules (select M) or built into the
9099 +         kernel (select Y).  If unsure say M.
9100 +
9101 +config KDB_OFF
9102 +       bool "KDB off by default"
9103 +       depends on KDB
9104 +       help
9105 +         Normally kdb is activated by default, as long as CONFIG_KDB is set.
9106 +         If you want to ship a kernel with kdb support but only have kdb
9107 +         turned on when the user requests it then select this option.  When
9108 +         compiled with CONFIG_KDB_OFF, kdb ignores all events unless you boot
9109 +         with kdb=on or you echo "1" > /proc/sys/kernel/kdb.  This option also
9110 +         works in reverse, if kdb is normally activated, you can boot with
9111 +         kdb=off or echo "0" > /proc/sys/kernel/kdb to deactivate kdb. If
9112 +         unsure, say N.
9113 +
9114 +config KDB_CONTINUE_CATASTROPHIC
9115 +       int "KDB continues after catastrophic errors"
9116 +       depends on KDB
9117 +       default "0"
9118 +       help
9119 +         This integer controls the behaviour of kdb when the kernel gets a
9120 +         catastrophic error, i.e. for a panic, oops, NMI or other watchdog
9121 +         tripping.  CONFIG_KDB_CONTINUE_CATASTROPHIC interacts with
9122 +         /proc/sys/kernel/kdb and CONFIG_DUMP (if your kernel has the LKCD
9123 +         patch).
9124 +         When KDB is active (/proc/sys/kernel/kdb == 1) and a catastrophic
9125 +         error occurs, nothing extra happens until you type 'go'.
9126 +         CONFIG_KDB_CONTINUE_CATASTROPHIC == 0 (default).  The first time
9127 +         you type 'go', kdb warns you.  The second time you type 'go', KDB
9128 +         tries to continue - no guarantees that the kernel is still usable.
9129 +         CONFIG_KDB_CONTINUE_CATASTROPHIC == 1.  KDB tries to continue - no
9130 +         guarantees that the kernel is still usable.
9131 +         CONFIG_KDB_CONTINUE_CATASTROPHIC == 2.  If your kernel has the LKCD
9132 +         patch and LKCD is configured to take a dump then KDB forces a dump.
9133 +         Whether or not a dump is taken, KDB forces a reboot.
9134 +         When KDB is not active (/proc/sys/kernel/kdb == 0) and a catastrophic
9135 +         error occurs, the following steps are automatic, no human
9136 +         intervention is required.
9137 +         CONFIG_KDB_CONTINUE_CATASTROPHIC == 0 (default) or 1.  KDB attempts
9138 +         to continue - no guarantees that the kernel is still usable.
9139 +         CONFIG_KDB_CONTINUE_CATASTROPHIC == 2.  If your kernel has the LKCD
9140 +         patch and LKCD is configured to take a dump then KDB automatically
9141 +         forces a dump.  Whether or not a dump is taken, KDB forces a
9142 +         reboot.
9143 +         If you are not sure, say 0.  Read Documentation/kdb/dump.txt before
9144 +         setting to 2.
9145 +
9146  config IOMMU_DEBUG
9147         depends on IOMMU && DEBUG_KERNEL
9148         bool "Enable IOMMU debugging"
9149 diff -Nurp linux-2.6.22-590/arch/x86_64/kdb/ChangeLog linux-2.6.22-600/arch/x86_64/kdb/ChangeLog
9150 --- linux-2.6.22-590/arch/x86_64/kdb/ChangeLog  1970-01-01 01:00:00.000000000 +0100
9151 +++ linux-2.6.22-600/arch/x86_64/kdb/ChangeLog  2008-04-09 18:16:24.000000000 +0200
9152 @@ -0,0 +1,387 @@
9153 +2007-07-26 Keith Owens  <kaos@sgi.com>
9154 +
9155 +       * New x86 backtrace code.
9156 +       * kdb v4.4-2.6.22-x86_64-2.
9157 +
9158 +2007-07-09 Keith Owens  <kaos@sgi.com>
9159 +
9160 +       * kdb v4.4-2.6.22-x86_64-1.
9161 +
9162 +2007-07-02 Keith Owens  <kaos@sgi.com>
9163 +
9164 +       * kdb v4.4-2.6.22-rc7-x86_64-1.
9165 +
9166 +2007-06-25 Keith Owens  <kaos@sgi.com>
9167 +
9168 +       * Hook into DIE_NMIWATCHDOG.
9169 +       * kdb v4.4-2.6.22-rc5-x86_64-2.
9170 +
9171 +2007-06-20 Keith Owens  <kaos@sgi.com>
9172 +
9173 +       * kdb v4.4-2.6.22-rc5-x86_64-1.
9174 +
9175 +2007-06-08 Keith Owens  <kaos@sgi.com>
9176 +
9177 +       * kdb v4.4-2.6.22-rc4-x86_64-1.
9178 +
9179 +2007-05-28 Keith Owens  <kaos@sgi.com>
9180 +
9181 +       * kdb v4.4-2.6.22-rc3-x86_64-1.
9182 +
9183 +2007-05-22 Keith Owens  <kaos@sgi.com>
9184 +
9185 +       * Register KDBENTER_VECTOR early on the boot cpu.
9186 +       * kdb v4.4-2.6.22-rc2-x86_64-2.
9187 +
9188 +2007-05-22 Keith Owens  <kaos@sgi.com>
9189 +
9190 +       * kdb v4.4-2.6.22-rc2-x86_64-1.
9191 +
9192 +2007-05-22 Keith Owens  <kaos@sgi.com>
9193 +
9194 +       * kdb v4.4-2.6.22-rc1-x86_64-1.
9195 +
9196 +2007-05-17 Keith Owens  <kaos@sgi.com>
9197 +
9198 +       * Update dumpregs comments for rdmsr and wrmsr commands.
9199 +         Bernardo Innocenti.
9200 +       * kdb v4.4-2.6.21-x86_64-3.
9201 +
9202 +2007-05-15 Keith Owens  <kaos@sgi.com>
9203 +
9204 +       * Change kdba_late_init to kdba_arch_init so KDB_ENTER() can be used
9205 +         earlier.
9206 +       * kdb v4.4-2.6.21-x86_64-2.
9207 +
9208 +2007-04-29 Keith Owens  <kaos@sgi.com>
9209 +
9210 +       * kdb v4.4-2.6.21-x86_64-1.
9211 +
9212 +2007-04-16 Keith Owens  <kaos@sgi.com>
9213 +
9214 +       * Select KALLSYMS and KALLSYMS_ALL when KDB is selected.
9215 +       * kdb v4.4-2.6.21-rc7-x86_64-2.
9216 +
9217 +2007-04-16 Keith Owens  <kaos@sgi.com>
9218 +
9219 +       * kdb v4.4-2.6.21-rc7-x86_64-1.
9220 +
9221 +2007-04-10 Keith Owens  <kaos@sgi.com>
9222 +
9223 +       * kdb v4.4-2.6.21-rc6-x86_64-1.
9224 +
9225 +2007-04-02 Keith Owens  <kaos@sgi.com>
9226 +
9227 +       * kdb v4.4-2.6.21-rc5-x86_64-1.
9228 +
9229 +2007-03-19 Keith Owens  <kaos@sgi.com>
9230 +
9231 +       * kdb v4.4-2.6.21-rc4-x86_64-1.
9232 +
9233 +2007-03-14 Keith Owens  <kaos@sgi.com>
9234 +
9235 +       * kdb v4.4-2.6.21-rc3-x86_64-1.
9236 +
9237 +2007-03-14 Keith Owens  <kaos@sgi.com>
9238 +
9239 +       * kdb v4.4-2.6.21-rc2-x86_64-1.
9240 +
9241 +2007-03-01 Keith Owens  <kaos@sgi.com>
9242 +
9243 +       * kdb v4.4-2.6.21-rc1-x86_64-1.
9244 +
9245 +2007-03-01 Keith Owens  <kaos@sgi.com>
9246 +
9247 +       * Remove sparse warnings.
9248 +       * kdb v4.4-2.6.20-x86_64-3.
9249 +
9250 +2007-02-16 Keith Owens  <kaos@sgi.com>
9251 +
9252 +       * Initialise variable bits of struct disassemble_info each time.
9253 +       * kdb v4.4-2.6.20-x86_64-2.
9254 +
9255 +2007-02-06 Keith Owens  <kaos@sgi.com>
9256 +
9257 +       * kdb v4.4-2.6.20-x86_64-1.
9258 +
9259 +2007-02-01 Keith Owens  <kaos@sgi.com>
9260 +
9261 +       * kdb v4.4-2.6.20-rc7-x86_64-1.
9262 +
9263 +2007-01-10 Keith Owens  <kaos@sgi.com>
9264 +
9265 +       * Correct setjmp for the FRAME_POINTER=y case.
9266 +       * Remove duplicate longjmp code for FRAME_POINTER=n/y.
9267 +       * kdb v4.4-2.6.20-rc4-x86_64-2.
9268 +
9269 +2007-01-08 Keith Owens  <kaos@sgi.com>
9270 +
9271 +       * kdb v4.4-2.6.20-rc4-x86_64-1.
9272 +
9273 +2007-01-02 Keith Owens  <kaos@sgi.com>
9274 +
9275 +       * kdb v4.4-2.6.20-rc3-x86_64-1.
9276 +
9277 +2006-12-20 Keith Owens  <kaos@sgi.com>
9278 +
9279 +       * kdb v4.4-2.6.20-rc1-x86_64-1.
9280 +
9281 +2006-12-07 Keith Owens  <kaos@sgi.com>
9282 +
9283 +       * Export kdba_dumpregs.
9284 +       * kdb v4.4-2.6.19-x86_64-2.
9285 +
9286 +2006-11-30 Keith Owens  <kaos@sgi.com>
9287 +
9288 +       * kdb v4.4-2.6.19-x86_64-1.
9289 +
9290 +2006-11-27 Keith Owens  <kaos@sgi.com>
9291 +
9292 +       * Only use VT keyboard if the command line allows it and ACPI indicates
9293 +         that there is an i8042.
9294 +       * kdb v4.4-2.6.19-rc6-x86_64-2.
9295 +
9296 +2006-11-20 Keith Owens  <kaos@sgi.com>
9297 +
9298 +       * kdb v4.4-2.6.19-rc6-x86_64-1.
9299 +
9300 +2006-11-09 Keith Owens  <kaos@sgi.com>
9301 +
9302 +       * Only use VT console if the command line allows it.
9303 +       * kdb v4.4-2.6.19-rc5-x86_64-2.
9304 +
9305 +2006-11-08 Keith Owens  <kaos@sgi.com>
9306 +
9307 +       * kdb v4.4-2.6.19-rc5-x86_64-1.
9308 +
9309 +2006-11-01 Keith Owens  <kaos@sgi.com>
9310 +
9311 +       * kdb v4.4-2.6.19-rc4-x86_64-1.
9312 +
9313 +2006-10-24 Keith Owens  <kaos@sgi.com>
9314 +
9315 +       * kdb v4.4-2.6.19-rc3-x86_64-1.
9316 +
9317 +2006-10-24 Keith Owens  <kaos@sgi.com>
9318 +
9319 +       * Remove redundant regs and envp parameters.
9320 +       * kdb v4.4-2.6.19-rc2-x86_64-2.
9321 +
9322 +2006-10-18 Keith Owens  <kaos@sgi.com>
9323 +
9324 +       * kdb v4.4-2.6.19-rc2-x86_64-1.
9325 +
9326 +2006-10-11 Keith Owens  <kaos@sgi.com>
9327 +
9328 +       * Make the KDBENTER_VECTOR an interrupt gate instead of a trap gate, it
9329 +         simplifies the code and disables interrupts on KDB_ENTER().
9330 +       * Exclude the KDBENTER_VECTOR from irq assignment.
9331 +       * Enable KDB_ENTER() again.
9332 +       * kdb v4.4-2.6.19-rc1-x86_64-2.
9333 +
9334 +2006-10-09 Keith Owens  <kaos@sgi.com>
9335 +
9336 +       * KDB_ENTER() is getting spurious activations on some x86_64 hardware.
9337 +         Deactivate KDB_ENTER() until it is fixed.
9338 +       * kdb v4.4-2.6.19-rc1-x86_64-1.
9339 +
9340 +2006-10-06 Keith Owens  <kaos@sgi.com>
9341 +
9342 +       * Remove #include <linux/config.h>
9343 +       * kdb v4.4-2.6.18-x86_64-2.
9344 +
9345 +2006-09-20 Keith Owens  <kaos@sgi.com>
9346 +
9347 +       * kdb v4.4-2.6.18-x86_64-1.
9348 +
9349 +2006-09-15 Keith Owens  <kaos@sgi.com>
9350 +
9351 +       * kdb v4.4-2.6.18-rc7-x86_64-1.
9352 +
9353 +2006-08-30 Keith Owens  <kaos@sgi.com>
9354 +
9355 +       * Do not print debugstackptr in cpu_pda, it will be deleted soon.
9356 +       * Add KDB_ENTER().
9357 +       * Add warning for problems when following alternate stacks.
9358 +       * kdb v4.4-2.6.18-rc5-x86_64-3.
9359 +
9360 +2006-08-29 Keith Owens  <kaos@sgi.com>
9361 +
9362 +       * Rewrite all backtrace code.
9363 +       * Add pt_regs and cpu_pda commands.
9364 +       * Include patch to define orig_ist, to be removed once that patch is in
9365 +         the community tree.
9366 +       * kdb v4.4-2.6.18-rc5-x86_64-2.
9367 +
9368 +2006-08-28 Keith Owens  <kaos@sgi.com>
9369 +
9370 +       * kdb v4.4-2.6.18-rc5-x86_64-1.
9371 +
9372 +2006-08-08 Keith Owens  <kaos@sgi.com>
9373 +
9374 +       * kdb v4.4-2.6.18-rc4-x86_64-1.
9375 +
9376 +2006-08-04 Keith Owens  <kaos@sgi.com>
9377 +
9378 +       * kdb v4.4-2.6.18-rc3-x86_64-1.
9379 +
9380 +2006-07-18 Keith Owens  <kaos@sgi.com>
9381 +
9382 +       * kdb v4.4-2.6.18-rc2-x86_64-1.
9383 +
9384 +2006-07-12 Keith Owens  <kaos@sgi.com>
9385 +
9386 +       * sparse cleanups
9387 +       * kdb v4.4-2.6.18-rc1-x86_64-2.
9388 +
9389 +2006-07-07 Keith Owens  <kaos@sgi.com>
9390 +
9391 +       * kdb v4.4-2.6.18-rc1-x86_64-1.
9392 +
9393 +2006-07-04 Keith Owens  <kaos@sgi.com>
9394 +
9395 +       * Make KDB rendezvous on x86_64 a two stage approach.
9396 +       * Move smp_kdb_stop() and smp_kdb_interrupt() to kdbasupport.c.
9397 +       * Move setting of interrupt traps to kdbasupport.c.
9398 +       * Add KDB_REASON_CPU_UP support.
9399 +       * Move per cpu setup to kdba_cpu_up().
9400 +       * Delete kdba_enable_mce, architectures now do their own setup.
9401 +       * Delete kdba_enable_lbr, kdba_disable_lbr, kdba_print_lbr,
9402 +         page_fault_mca.  Only ever implemented on x86, difficult to maintain
9403 +         and rarely used in the field.
9404 +       * Replace #ifdef KDB_HAVE_LONGJMP with #ifdef kdba_setjmp.
9405 +       * kdb v4.4-2.6.17-x86_64-2.
9406 +
9407 +2006-06-19 Keith Owens  <kaos@sgi.com>
9408 +
9409 +       * kdb v4.4-2.6.17-x86_64-1.
9410 +
9411 +2006-05-31 Keith Owens  <kaos@sgi.com>
9412 +
9413 +       * Define arch/x86_64/kdb/kdb_cmds.
9414 +       * kdb v4.4-2.6.17-rc5-x86_64-2.
9415 +
9416 +2006-05-25 Keith Owens  <kaos@sgi.com>
9417 +
9418 +       * kdb v4.4-2.6.17-rc5-x86_64-1.
9419 +
9420 +2006-05-15 Keith Owens  <kaos@sgi.com>
9421 +
9422 +       * Refresh bfd related files from binutils 2.16.91.0.2.
9423 +       * kdb v4.4-2.6.17-rc4-x86_64-2.
9424 +
9425 +2006-05-12 Keith Owens <kaos@sgi.com>
9426 +
9427 +       * kdb v4.4-2.6-17-rc4-x86_64-1.
9428 +
9429 +2006-04-22 Keith Owens <kaos@sgi.com>
9430 +
9431 +       * kdb v4.4-2.6-17-rc2-x86_64-1.
9432 +
9433 +2006-04-13 Keith Owens <kaos@sgi.com>
9434 +
9435 +       * Remove trailing white space.
9436 +       * kdb v4.4-2.6-17-rc1-x86_64-1.
9437 +
9438 +2006-03-25 Jack F. Vogel <jfv@bluesong.net>
9439 +       * Sync with Keith's changes for 2.6.16
9440 +       * code from Andi Kleen to support above
9441 +
9442 +2005-09-30 Jack F. Vogel <jfv@bluesong.net>
9443 +       * Port to 2.6.14-rc2
9444 +       * sync with a couple changes from Keith
9445 +       * Add backtrace code from Jim Houston
9446 +         (thanks Jim)
9447 +
9448 +2005-08-31 Jack F. Vogel <jfv@bluesong.net>
9449 +       * Change to linker script for kexec
9450 +         thanks to Steven Dake <sdake@mvista.com>
9451 +
9452 +2005-08-30 Jack F. Vogel <jfv@bluesong.net>
9453 +       * Notify struct should not be devinit
9454 +         thanks IWAMOTO Toshihiro <iwamoto@valinux.co.jp>
9455 +
9456 +2005-08-25 Jack F. Vogel <jfv@bluesong.net>
9457 +       * Update to 2.6.11
9458 +       * Fix to synchronize with the notify changes
9459 +         thanks to Jim Houston.
9460 +
9461 +2004-09-30 Keith Owens <kaos@sgi.com>
9462 +       * Port to 2.6.9-rc2
9463 +       * Fix line editting characters.  Jim Houston, Comcast.
9464 +       * kdb v4.4-2.6.9-rc2-x86-64-1.
9465 +
9466 +2004-08-15 Jack F. Vogel <jfv@bluesong.net>
9467 +       * Port to 2.6.8
9468 +       * tighten up the code, using the built-in
9469 +         die_chain notify interface, thanks to
9470 +         Andi Kleen for pointing this out.
9471 +
9472 +2004-05-15 Jack F. Vogel <jfv@bluesong.net>
9473 +       * port to 2.6.6 for x86_64
9474 +
9475 +2003-12-15 Cliff Neighbors <cliff@fabric7.com>
9476 +       * initial port from i386 to x86_64
9477 +
9478 +2002-08-10 Keith Owens  <kaos@sgi.com>
9479 +
9480 +       * Replace kdb_port with kdb_serial to support memory mapped I/O.
9481 +         Note: This needs kdb v2.3-2.4.19-common-2 or later.
9482 +       * kdb v2.3-2.4.19-i386-3.
9483 +
9484 +2002-08-09 Keith Owens  <kaos@sgi.com>
9485 +
9486 +       * Use -fno-optimize-sibling-calls for kdb if gcc supports it.
9487 +       * .text.lock does not consume an activation frame.
9488 +       * kdb v2.3-2.4.19-i386-2.
9489 +
9490 +2002-08-07 Keith Owens  <kaos@sgi.com>
9491 +
9492 +       * Upgrade to 2.4.19.
9493 +       * Remove individual SGI copyrights, the general SGI copyright applies.
9494 +       * New .text.lock name.  Hugh Dickins.
9495 +       * Set KERNEL_CS in kdba_getcurrentframe.  Hugh Dickins.
9496 +       * Clean up disassembly layout.  Hugh Dickins, Keith Owens.
9497 +       * Replace hard coded stack size with THREAD_SIZE.  Hugh Dickins.
9498 +       * Better stack layout on bt with no frame pointers.  Hugh Dickins.
9499 +       * Make i386 IO breakpoints (bpha <address> IO) work again.
9500 +         Martin Wilck, Keith Owens.
9501 +       * Remove fixed KDB_MAX_COMMANDS size.
9502 +       * Add set_fs() around __copy_to_user on kernel addresses.
9503 +         Randolph Chung.
9504 +       * Position i386 for CONFIG_NUMA_REPLICATE.
9505 +       * kdb v2.3-2.4.19-i386-1.
9506 +
9507 +2002-07-09 Keith Owens  <kaos@sgi.com>
9508 +
9509 +       * Upgrade to 2.4.19-rc1.
9510 +
9511 +2002-06-14 Keith Owens  <kaos@sgi.com>
9512 +
9513 +       * Upgrade to 2.4.19-pre10.
9514 +       * kdb v2.1-2.4.19-pre10-i386-1.
9515 +
9516 +2002-04-09 Keith Owens  <kaos@sgi.com>
9517 +
9518 +       * Upgrade to 2.4.19-pre6.
9519 +       * kdb v2.1-2.4.19-pre6-i386-1.
9520 +
9521 +2002-02-26 Keith Owens  <kaos@sgi.com>
9522 +
9523 +       * Upgrade to 2.4.18.
9524 +       * kdb v2.1-2.4.18-i386-1.
9525 +
9526 +2002-01-18 Keith Owens  <kaos@sgi.com>
9527 +
9528 +       * Use new kdb_get/put functions.
9529 +       * Define kdba_{get,put}area_size functions for i386.
9530 +       * Remove over-engineered dblist callback functions.
9531 +       * Correctly handle failing call disp32 in backtrace.
9532 +       * Remove bp_instvalid flag, redundant code.
9533 +       * Remove dead code.
9534 +       * kdb v2.1-2.4.17-i386-1.
9535 +
9536 +2002-01-04 Keith Owens  <kaos@sgi.com>
9537 +
9538 +       * Sync xfs <-> kdb i386 code.
9539 +
9540 diff -Nurp linux-2.6.22-590/arch/x86_64/kdb/kdba_bp.c linux-2.6.22-600/arch/x86_64/kdb/kdba_bp.c
9541 --- linux-2.6.22-590/arch/x86_64/kdb/kdba_bp.c  1970-01-01 01:00:00.000000000 +0100
9542 +++ linux-2.6.22-600/arch/x86_64/kdb/kdba_bp.c  2008-04-09 18:16:24.000000000 +0200
9543 @@ -0,0 +1,777 @@
9544 +/*
9545 + * Kernel Debugger Architecture Dependent Breakpoint Handling
9546 + *
9547 + * This file is subject to the terms and conditions of the GNU General Public
9548 + * License.  See the file "COPYING" in the main directory of this archive
9549 + * for more details.
9550 + *
9551 + * Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
9552 + */
9553 +
9554 +#include <linux/string.h>
9555 +#include <linux/kernel.h>
9556 +#include <linux/sched.h>
9557 +#include <linux/smp.h>
9558 +#include <linux/ptrace.h>
9559 +#include <linux/kdb.h>
9560 +#include <linux/kdbprivate.h>
9561 +
9562 +
9563 +static char *kdba_rwtypes[] = { "Instruction(Register)", "Data Write",
9564 +                       "I/O", "Data Access"};
9565 +
9566 +/*
9567 + * Table describing processor architecture hardware
9568 + * breakpoint registers.
9569 + */
9570 +
9571 +kdbhard_bp_t   kdb_hardbreaks[KDB_MAXHARDBPT];
9572 +
9573 +/*
9574 + * kdba_db_trap
9575 + *
9576 + *     Perform breakpoint processing upon entry to the
9577 + *     processor debugger fault.   Determine and print
9578 + *     the active breakpoint.
9579 + *
9580 + * Parameters:
9581 + *     regs    Exception frame containing machine register state
9582 + *     error   Error number passed to kdb.
9583 + * Outputs:
9584 + *     None.
9585 + * Returns:
9586 + *     KDB_DB_BPT      Standard instruction or data breakpoint encountered
9587 + *     KDB_DB_SS       Single Step fault ('ss' command or end of 'ssb' command)
9588 + *     KDB_DB_SSB      Single Step fault, caller should continue ('ssb' command)
9589 + *     KDB_DB_SSBPT    Single step over breakpoint
9590 + *     KDB_DB_NOBPT    No existing kdb breakpoint matches this debug exception
9591 + * Locking:
9592 + *     None.
9593 + * Remarks:
9594 + *     Yup, there be goto's here.
9595 + *
9596 + *     If multiple processors receive debug exceptions simultaneously,
9597 + *     one may be waiting at the kdb fence in kdb() while the user
9598 + *     issues a 'bc' command to clear the breakpoint the processor
9599 + *     which is waiting has already encountered.  If this is the case,
9600 + *     the debug registers will no longer match any entry in the
9601 + *     breakpoint table, and we'll return the value KDB_DB_NOBPT.
9602 + *     This can cause a panic in die_if_kernel().  It is safer to
9603 + *     disable the breakpoint (bd), go until all processors are past
9604 + *     the breakpoint then clear the breakpoint (bc).  This code
9605 + *     recognises a breakpoint even when disabled but not when it has
9606 + *     been cleared.
9607 + *
9608 + *     WARNING: This routine clears the debug state.  It should be called
9609 + *              once per debug and the result cached.
9610 + */
9611 +
9612 +kdb_dbtrap_t
9613 +kdba_db_trap(struct pt_regs *regs, int error_unused)
9614 +{
9615 +       kdb_machreg_t  dr6;
9616 +       kdb_machreg_t  dr7;
9617 +       int rw, reg;
9618 +       int i;
9619 +       kdb_dbtrap_t rv = KDB_DB_BPT;
9620 +       kdb_bp_t *bp;
9621 +
9622 +       if (KDB_NULL_REGS(regs))
9623 +               return KDB_DB_NOBPT;
9624 +
9625 +       dr6 = kdba_getdr6();
9626 +       dr7 = kdba_getdr7();
9627 +
9628 +       if (KDB_DEBUG(BP))
9629 +               kdb_printf("kdb: dr6 0x%lx dr7 0x%lx\n", dr6, dr7);
9630 +       if (dr6 & DR6_BS) {
9631 +               if (KDB_STATE(SSBPT)) {
9632 +                       if (KDB_DEBUG(BP))
9633 +                               kdb_printf("ssbpt\n");
9634 +                       KDB_STATE_CLEAR(SSBPT);
9635 +                       for(i=0,bp=kdb_breakpoints;
9636 +                           i < KDB_MAXBPT;
9637 +                           i++, bp++) {
9638 +                               if (KDB_DEBUG(BP))
9639 +                                       kdb_printf("bp 0x%p enabled %d delayed %d global %d cpu %d\n",
9640 +                                                  bp, bp->bp_enabled, bp->bp_delayed, bp->bp_global, bp->bp_cpu);
9641 +                               if (!bp->bp_enabled)
9642 +                                       continue;
9643 +                               if (!bp->bp_global && bp->bp_cpu != smp_processor_id())
9644 +                                       continue;
9645 +                               if (KDB_DEBUG(BP))
9646 +                                       kdb_printf("bp for this cpu\n");
9647 +                               if (bp->bp_delayed) {
9648 +                                       bp->bp_delayed = 0;
9649 +                                       if (KDB_DEBUG(BP))
9650 +                                               kdb_printf("kdba_installbp\n");
9651 +                                       kdba_installbp(regs, bp);
9652 +                                       if (!KDB_STATE(DOING_SS)) {
9653 +                                               regs->eflags &= ~EF_TF;
9654 +                                               return(KDB_DB_SSBPT);
9655 +                                       }
9656 +                                       break;
9657 +                               }
9658 +                       }
9659 +                       if (i == KDB_MAXBPT) {
9660 +                               kdb_printf("kdb: Unable to find delayed breakpoint\n");
9661 +                       }
9662 +                       if (!KDB_STATE(DOING_SS)) {
9663 +                               regs->eflags &= ~EF_TF;
9664 +                               return(KDB_DB_NOBPT);
9665 +                       }
9666 +                       /* FALLTHROUGH */
9667 +               }
9668 +
9669 +               /*
9670 +                * KDB_STATE_DOING_SS is set when the kernel debugger is using
9671 +                * the processor trap flag to single-step a processor.  If a
9672 +                * single step trap occurs and this flag is clear, the SS trap
9673 +                * will be ignored by KDB and the kernel will be allowed to deal
9674 +                * with it as necessary (e.g. for ptrace).
9675 +                */
9676 +               if (!KDB_STATE(DOING_SS))
9677 +                       goto unknown;
9678 +
9679 +               /* single step */
9680 +               rv = KDB_DB_SS;         /* Indicate single step */
9681 +               if (KDB_STATE(DOING_SSB)) {
9682 +                       unsigned char instruction[2];
9683 +
9684 +                       kdb_id1(regs->rip);
9685 +                       if (kdb_getarea(instruction, regs->rip) ||
9686 +                           (instruction[0]&0xf0) == 0xe0 ||    /* short disp jumps */
9687 +                           (instruction[0]&0xf0) == 0x70 ||    /* Misc. jumps */
9688 +                           instruction[0]        == 0xc2 ||    /* ret */
9689 +                           instruction[0]        == 0x9a ||    /* call */
9690 +                           (instruction[0]&0xf8) == 0xc8 ||    /* enter, leave, iret, int, */
9691 +                           ((instruction[0]      == 0x0f) &&
9692 +                            ((instruction[1]&0xf0)== 0x80))
9693 +                          ) {
9694 +                               /*
9695 +                                * End the ssb command here.
9696 +                                */
9697 +                               KDB_STATE_CLEAR(DOING_SSB);
9698 +                               KDB_STATE_CLEAR(DOING_SS);
9699 +                       } else {
9700 +                               rv = KDB_DB_SSB; /* Indicate ssb - dismiss immediately */
9701 +                       }
9702 +               } else {
9703 +                       /*
9704 +                        * Print current insn
9705 +                        */
9706 +                       kdb_printf("SS trap at ");
9707 +                       kdb_symbol_print(regs->rip, NULL, KDB_SP_DEFAULT|KDB_SP_NEWLINE);
9708 +                       kdb_id1(regs->rip);
9709 +                       KDB_STATE_CLEAR(DOING_SS);
9710 +               }
9711 +
9712 +               if (rv != KDB_DB_SSB)
9713 +                       regs->eflags &= ~EF_TF;
9714 +       }
9715 +
9716 +       if (dr6 & DR6_B0) {
9717 +               rw = DR7_RW0(dr7);
9718 +               reg = 0;
9719 +               goto handle;
9720 +       }
9721 +
9722 +       if (dr6 & DR6_B1) {
9723 +               rw = DR7_RW1(dr7);
9724 +               reg = 1;
9725 +               goto handle;
9726 +       }
9727 +
9728 +       if (dr6 & DR6_B2) {
9729 +               rw = DR7_RW2(dr7);
9730 +               reg = 2;
9731 +               goto handle;
9732 +       }
9733 +
9734 +       if (dr6 & DR6_B3) {
9735 +               rw = DR7_RW3(dr7);
9736 +               reg = 3;
9737 +               goto handle;
9738 +       }
9739 +
9740 +       if (rv > 0)
9741 +               goto handled;
9742 +
9743 +       goto unknown;   /* dismiss */
9744 +
9745 +handle:
9746 +       /*
9747 +        * Set Resume Flag
9748 +        */
9749 +       regs->eflags |= EF_RF;
9750 +
9751 +       /*
9752 +        * Determine which breakpoint was encountered.
9753 +        */
9754 +       for(i=0, bp=kdb_breakpoints; i<KDB_MAXBPT; i++, bp++) {
9755 +               if (!(bp->bp_free)
9756 +                && (bp->bp_global || bp->bp_cpu == smp_processor_id())
9757 +                && (bp->bp_hard)
9758 +                && (bp->bp_hard->bph_reg == reg)) {
9759 +                       /*
9760 +                        * Hit this breakpoint.
9761 +                        */
9762 +                       kdb_printf("%s breakpoint #%d at " kdb_bfd_vma_fmt "\n",
9763 +                                 kdba_rwtypes[rw],
9764 +                                 i, bp->bp_addr);
9765 +                       /*
9766 +                        * For an instruction breakpoint, disassemble
9767 +                        * the current instruction.
9768 +                        */
9769 +                       if (rw == 0) {
9770 +                               kdb_id1(regs->rip);
9771 +                       }
9772 +
9773 +                       goto handled;
9774 +               }
9775 +       }
9776 +
9777 +unknown:
9778 +       regs->eflags |= EF_RF;  /* Supress further faults */
9779 +       rv = KDB_DB_NOBPT;      /* Cause kdb() to return */
9780 +
9781 +handled:
9782 +
9783 +       /*
9784 +        * Clear the pending exceptions.
9785 +        */
9786 +       kdba_putdr6(0);
9787 +
9788 +       return rv;
9789 +}
9790 +
9791 +/*
9792 + * kdba_bp_trap
9793 + *
9794 + *     Perform breakpoint processing upon entry to the
9795 + *     processor breakpoint instruction fault.   Determine and print
9796 + *     the active breakpoint.
9797 + *
9798 + * Parameters:
9799 + *     regs    Exception frame containing machine register state
9800 + *     error   Error number passed to kdb.
9801 + * Outputs:
9802 + *     None.
9803 + * Returns:
9804 + *     0       Standard instruction or data breakpoint encountered
9805 + *     1       Single Step fault ('ss' command)
9806 + *     2       Single Step fault, caller should continue ('ssb' command)
9807 + *     3       No existing kdb breakpoint matches this debug exception
9808 + * Locking:
9809 + *     None.
9810 + * Remarks:
9811 + *
9812 + *     If multiple processors receive debug exceptions simultaneously,
9813 + *     one may be waiting at the kdb fence in kdb() while the user
9814 + *     issues a 'bc' command to clear the breakpoint the processor which
9815 + *     is waiting has already encountered.   If this is the case, the
9816 + *     debug registers will no longer match any entry in the breakpoint
9817 + *     table, and we'll return the value '3'.  This can cause a panic
9818 + *     in die_if_kernel().  It is safer to disable the breakpoint (bd),
9819 + *     'go' until all processors are past the breakpoint then clear the
9820 + *     breakpoint (bc).  This code recognises a breakpoint even when
9821 + *     disabled but not when it has been cleared.
9822 + *
9823 + *     WARNING: This routine resets the rip.  It should be called
9824 + *              once per breakpoint and the result cached.
9825 + */
9826 +
9827 +kdb_dbtrap_t
9828 +kdba_bp_trap(struct pt_regs *regs, int error_unused)
9829 +{
9830 +       int i;
9831 +       kdb_dbtrap_t rv;
9832 +       kdb_bp_t *bp;
9833 +
9834 +       if (KDB_NULL_REGS(regs))
9835 +               return KDB_DB_NOBPT;
9836 +       /*
9837 +        * Determine which breakpoint was encountered.
9838 +        */
9839 +       if (KDB_DEBUG(BP))
9840 +               kdb_printf("kdba_bp_trap: rip=0x%lx (not adjusted) "
9841 +                          "eflags=0x%lx ef=0x%p rsp=0x%lx\n",
9842 +                          regs->rip, regs->eflags, regs, regs->rsp);
9843 +
9844 +       rv = KDB_DB_NOBPT;      /* Cause kdb() to return */
9845 +
9846 +       for(i=0, bp=kdb_breakpoints; i<KDB_MAXBPT; i++, bp++) {
9847 +               if (bp->bp_free)
9848 +                       continue;
9849 +               if (!bp->bp_global && bp->bp_cpu != smp_processor_id())
9850 +                       continue;
9851 +                if ((void *)bp->bp_addr == (void *)(regs->rip - bp->bp_adjust)) {
9852 +                       /* Hit this breakpoint.  */
9853 +                       regs->rip -= bp->bp_adjust;
9854 +                       kdb_printf("Instruction(i) breakpoint #%d at 0x%lx (adjusted)\n",
9855 +                                 i, regs->rip);
9856 +                       kdb_id1(regs->rip);
9857 +                       rv = KDB_DB_BPT;
9858 +                       bp->bp_delay = 1;
9859 +                       /* SSBPT is set when the kernel debugger must single
9860 +                        * step a task in order to re-establish an instruction
9861 +                        * breakpoint which uses the instruction replacement
9862 +                        * mechanism.  It is cleared by any action that removes
9863 +                        * the need to single-step the breakpoint.
9864 +                        */
9865 +                       KDB_STATE_SET(SSBPT);
9866 +                       break;
9867 +               }
9868 +       }
9869 +
9870 +       return rv;
9871 +}
9872 +
9873 +/*
9874 + * kdba_handle_bp
9875 + *
9876 + *     Handle an instruction-breakpoint trap.  Called when re-installing
9877 + *     an enabled breakpoint which has has the bp_delay bit set.
9878 + *
9879 + * Parameters:
9880 + * Returns:
9881 + * Locking:
9882 + * Remarks:
9883 + *
9884 + * Ok, we really need to:
9885 + *     1) Restore the original instruction byte
9886 + *     2) Single Step
9887 + *     3) Restore breakpoint instruction
9888 + *     4) Continue.
9889 + *
9890 + *
9891 + */
9892 +
9893 +static void
9894 +kdba_handle_bp(struct pt_regs *regs, kdb_bp_t *bp)
9895 +{
9896 +
9897 +       if (KDB_NULL_REGS(regs))
9898 +               return;
9899 +
9900 +       if (KDB_DEBUG(BP))
9901 +               kdb_printf("regs->rip = 0x%lx\n", regs->rip);
9902 +
9903 +       /*
9904 +        * Setup single step
9905 +        */
9906 +       kdba_setsinglestep(regs);
9907 +
9908 +       /*
9909 +        * Reset delay attribute
9910 +        */
9911 +       bp->bp_delay = 0;
9912 +       bp->bp_delayed = 1;
9913 +}
9914 +
9915 +
9916 +/*
9917 + * kdba_bptype
9918 + *
9919 + *     Return a string describing type of breakpoint.
9920 + *
9921 + * Parameters:
9922 + *     bph     Pointer to hardware breakpoint description
9923 + * Outputs:
9924 + *     None.
9925 + * Returns:
9926 + *     Character string.
9927 + * Locking:
9928 + *     None.
9929 + * Remarks:
9930 + */
9931 +
9932 +char *
9933 +kdba_bptype(kdbhard_bp_t *bph)
9934 +{
9935 +       char *mode;
9936 +
9937 +       mode = kdba_rwtypes[bph->bph_mode];
9938 +
9939 +       return mode;
9940 +}
9941 +
9942 +/*
9943 + * kdba_printbpreg
9944 + *
9945 + *     Print register name assigned to breakpoint
9946 + *
9947 + * Parameters:
9948 + *     bph     Pointer hardware breakpoint structure
9949 + * Outputs:
9950 + *     None.
9951 + * Returns:
9952 + *     None.
9953 + * Locking:
9954 + *     None.
9955 + * Remarks:
9956 + */
9957 +
9958 +static void
9959 +kdba_printbpreg(kdbhard_bp_t *bph)
9960 +{
9961 +       kdb_printf(" in dr%ld", bph->bph_reg);
9962 +}
9963 +
9964 +/*
9965 + * kdba_printbp
9966 + *
9967 + *     Print string describing hardware breakpoint.
9968 + *
9969 + * Parameters:
9970 + *     bph     Pointer to hardware breakpoint description
9971 + * Outputs:
9972 + *     None.
9973 + * Returns:
9974 + *     None.
9975 + * Locking:
9976 + *     None.
9977 + * Remarks:
9978 + */
9979 +
9980 +void
9981 +kdba_printbp(kdb_bp_t *bp)
9982 +{
9983 +       kdb_printf("\n    is enabled");
9984 +       if (bp->bp_hardtype) {
9985 +               kdba_printbpreg(bp->bp_hard);
9986 +               if (bp->bp_hard->bph_mode != 0) {
9987 +                       kdb_printf(" for %d bytes",
9988 +                                  bp->bp_hard->bph_length+1);
9989 +               }
9990 +       }
9991 +}
9992 +
9993 +/*
9994 + * kdba_parsebp
9995 + *
9996 + *     Parse architecture dependent portion of the
9997 + *     breakpoint command.
9998 + *
9999 + * Parameters:
10000 + *     None.
10001 + * Outputs:
10002 + *     None.
10003 + * Returns:
10004 + *     Zero for success, a kdb diagnostic for failure
10005 + * Locking:
10006 + *     None.
10007 + * Remarks:
10008 + *     for Ia32 architure, data access, data write and
10009 + *     I/O breakpoints are supported in addition to instruction
10010 + *     breakpoints.
10011 + *
10012 + *     {datar|dataw|io|inst} [length]
10013 + */
10014 +
10015 +int
10016 +kdba_parsebp(int argc, const char **argv, int *nextargp, kdb_bp_t *bp)
10017 +{
10018 +       int             nextarg = *nextargp;
10019 +       int             diag;
10020 +       kdbhard_bp_t    *bph = &bp->bp_template;
10021 +
10022 +       bph->bph_mode = 0;              /* Default to instruction breakpoint */
10023 +       bph->bph_length = 0;            /* Length must be zero for insn bp */
10024 +       if ((argc + 1) != nextarg) {
10025 +               if (strnicmp(argv[nextarg], "datar", sizeof("datar")) == 0) {
10026 +                       bph->bph_mode = 3;
10027 +               } else if (strnicmp(argv[nextarg], "dataw", sizeof("dataw")) == 0) {
10028 +                       bph->bph_mode = 1;
10029 +               } else if (strnicmp(argv[nextarg], "io", sizeof("io")) == 0) {
10030 +                       bph->bph_mode = 2;
10031 +               } else if (strnicmp(argv[nextarg], "inst", sizeof("inst")) == 0) {
10032 +                       bph->bph_mode = 0;
10033 +               } else {
10034 +                       return KDB_ARGCOUNT;
10035 +               }
10036 +
10037 +               bph->bph_length = 3;    /* Default to 4 byte */
10038 +
10039 +               nextarg++;
10040 +
10041 +               if ((argc + 1) != nextarg) {
10042 +                       unsigned long len;
10043 +
10044 +                       diag = kdbgetularg((char *)argv[nextarg],
10045 +                                          &len);
10046 +                       if (diag)
10047 +                               return diag;
10048 +
10049 +
10050 +                       if ((len > 4) || (len == 3))
10051 +                               return KDB_BADLENGTH;
10052 +
10053 +                       bph->bph_length = len;
10054 +                       bph->bph_length--; /* Normalize for debug register */
10055 +                       nextarg++;
10056 +               }
10057 +
10058 +               if ((argc + 1) != nextarg)
10059 +                       return KDB_ARGCOUNT;
10060 +
10061 +               /*
10062 +                * Indicate to architecture independent level that
10063 +                * a hardware register assignment is required to enable
10064 +                * this breakpoint.
10065 +                */
10066 +
10067 +               bph->bph_free = 0;
10068 +       } else {
10069 +               if (KDB_DEBUG(BP))
10070 +                       kdb_printf("kdba_bp: no args, forcehw is %d\n", bp->bp_forcehw);
10071 +               if (bp->bp_forcehw) {
10072 +                       /*
10073 +                        * We are forced to use a hardware register for this
10074 +                        * breakpoint because either the bph or bpha
10075 +                        * commands were used to establish this breakpoint.
10076 +                        */
10077 +                       bph->bph_free = 0;
10078 +               } else {
10079 +                       /*
10080 +                        * Indicate to architecture dependent level that
10081 +                        * the instruction replacement breakpoint technique
10082 +                        * should be used for this breakpoint.
10083 +                        */
10084 +                       bph->bph_free = 1;
10085 +                       bp->bp_adjust = 1;      /* software, int 3 is one byte */
10086 +               }
10087 +       }
10088 +
10089 +       if (bph->bph_mode != 2 && kdba_verify_rw(bp->bp_addr, bph->bph_length+1)) {
10090 +               kdb_printf("Invalid address for breakpoint, ignoring bp command\n");
10091 +               return KDB_BADADDR;
10092 +       }
10093 +
10094 +       *nextargp = nextarg;
10095 +       return 0;
10096 +}
10097 +
10098 +/*
10099 + * kdba_allocbp
10100 + *
10101 + *     Associate a hardware register with a breakpoint.
10102 + *
10103 + * Parameters:
10104 + *     None.
10105 + * Outputs:
10106 + *     None.
10107 + * Returns:
10108 + *     A pointer to the allocated register kdbhard_bp_t structure for
10109 + *     success, Null and a non-zero diagnostic for failure.
10110 + * Locking:
10111 + *     None.
10112 + * Remarks:
10113 + */
10114 +
10115 +kdbhard_bp_t *
10116 +kdba_allocbp(kdbhard_bp_t *bph, int *diagp)
10117 +{
10118 +       int i;
10119 +       kdbhard_bp_t *newbph;
10120 +
10121 +       for(i=0,newbph=kdb_hardbreaks; i < KDB_MAXHARDBPT; i++, newbph++) {
10122 +               if (newbph->bph_free) {
10123 +                       break;
10124 +               }
10125 +       }
10126 +
10127 +       if (i == KDB_MAXHARDBPT) {
10128 +               *diagp = KDB_TOOMANYDBREGS;
10129 +               return NULL;
10130 +       }
10131 +
10132 +       *diagp = 0;
10133 +
10134 +       /*
10135 +        * Copy data from template.  Can't just copy the entire template
10136 +        * here because the register number in kdb_hardbreaks must be
10137 +        * preserved.
10138 +        */
10139 +       newbph->bph_data = bph->bph_data;
10140 +       newbph->bph_write = bph->bph_write;
10141 +       newbph->bph_mode = bph->bph_mode;
10142 +       newbph->bph_length = bph->bph_length;
10143 +
10144 +       /*
10145 +        * Mark entry allocated.
10146 +        */
10147 +       newbph->bph_free = 0;
10148 +
10149 +       return newbph;
10150 +}
10151 +
10152 +/*
10153 + * kdba_freebp
10154 + *
10155 + *     Deallocate a hardware breakpoint
10156 + *
10157 + * Parameters:
10158 + *     None.
10159 + * Outputs:
10160 + *     None.
10161 + * Returns:
10162 + *     Zero for success, a kdb diagnostic for failure
10163 + * Locking:
10164 + *     None.
10165 + * Remarks:
10166 + */
10167 +
10168 +void
10169 +kdba_freebp(kdbhard_bp_t *bph)
10170 +{
10171 +       bph->bph_free = 1;
10172 +}
10173 +
10174 +/*
10175 + * kdba_initbp
10176 + *
10177 + *     Initialize the breakpoint table for the hardware breakpoint
10178 + *     register.
10179 + *
10180 + * Parameters:
10181 + *     None.
10182 + * Outputs:
10183 + *     None.
10184 + * Returns:
10185 + *     Zero for success, a kdb diagnostic for failure
10186 + * Locking:
10187 + *     None.
10188 + * Remarks:
10189 + *
10190 + *     There is one entry per register.  On the ia32 architecture
10191 + *     all the registers are interchangeable, so no special allocation
10192 + *     criteria are required.
10193 + */
10194 +
10195 +void
10196 +kdba_initbp(void)
10197 +{
10198 +       int i;
10199 +       kdbhard_bp_t *bph;
10200 +
10201 +       /*
10202 +        * Clear the hardware breakpoint table
10203 +        */
10204 +
10205 +       memset(kdb_hardbreaks, '\0', sizeof(kdb_hardbreaks));
10206 +
10207 +       for(i=0,bph=kdb_hardbreaks; i<KDB_MAXHARDBPT; i++, bph++) {
10208 +               bph->bph_reg = i;
10209 +               bph->bph_free = 1;
10210 +       }
10211 +}
10212 +
10213 +/*
10214 + * kdba_installbp
10215 + *
10216 + *     Install a breakpoint
10217 + *
10218 + * Parameters:
10219 + *     regs    Exception frame
10220 + *     bp      Breakpoint structure for the breakpoint to be installed
10221 + * Outputs:
10222 + *     None.
10223 + * Returns:
10224 + *     0 if breakpoint installed.
10225 + * Locking:
10226 + *     None.
10227 + * Remarks:
10228 + *     For hardware breakpoints, a debug register is allocated
10229 + *     and assigned to the breakpoint.  If no debug register is
10230 + *     available, a warning message is printed and the breakpoint
10231 + *     is disabled.
10232 + *
10233 + *     For instruction replacement breakpoints, we must single-step
10234 + *     over the replaced instruction at this point so we can re-install
10235 + *     the breakpoint instruction after the single-step.
10236 + */
10237 +
10238 +int
10239 +kdba_installbp(struct pt_regs *regs, kdb_bp_t *bp)
10240 +{
10241 +       /*
10242 +        * Install the breakpoint, if it is not already installed.
10243 +        */
10244 +
10245 +       if (KDB_DEBUG(BP)) {
10246 +               kdb_printf("kdba_installbp bp_installed %d\n", bp->bp_installed);
10247 +       }
10248 +       if (!KDB_STATE(SSBPT))
10249 +               bp->bp_delay = 0;
10250 +       if (!bp->bp_installed) {
10251 +               if (bp->bp_hardtype) {
10252 +                       kdba_installdbreg(bp);
10253 +                       bp->bp_installed = 1;
10254 +                       if (KDB_DEBUG(BP)) {
10255 +                               kdb_printf("kdba_installbp hardware reg %ld at " kdb_bfd_vma_fmt "\n",
10256 +                                          bp->bp_hard->bph_reg, bp->bp_addr);
10257 +                       }
10258 +               } else if (bp->bp_delay) {
10259 +                       if (KDB_DEBUG(BP))
10260 +                               kdb_printf("kdba_installbp delayed bp\n");
10261 +                       kdba_handle_bp(regs, bp);
10262 +               } else {
10263 +                       if (kdb_getarea_size(&(bp->bp_inst), bp->bp_addr, 1) ||
10264 +                           kdb_putword(bp->bp_addr, IA32_BREAKPOINT_INSTRUCTION, 1)) {
10265 +                               kdb_printf("kdba_installbp failed to set software breakpoint at " kdb_bfd_vma_fmt "\n", bp->bp_addr);
10266 +                               return(1);
10267 +                       }
10268 +                       bp->bp_installed = 1;
10269 +                       if (KDB_DEBUG(BP))
10270 +                               kdb_printf("kdba_installbp instruction 0x%x at " kdb_bfd_vma_fmt "\n",
10271 +                                          IA32_BREAKPOINT_INSTRUCTION, bp->bp_addr);
10272 +               }
10273 +       }
10274 +       return(0);
10275 +}
10276 +
10277 +/*
10278 + * kdba_removebp
10279 + *
10280 + *     Make a breakpoint ineffective.
10281 + *
10282 + * Parameters:
10283 + *     None.
10284 + * Outputs:
10285 + *     None.
10286 + * Returns:
10287 + *     None.
10288 + * Locking:
10289 + *     None.
10290 + * Remarks:
10291 + */
10292 +
10293 +int
10294 +kdba_removebp(kdb_bp_t *bp)
10295 +{
10296 +       /*
10297 +        * For hardware breakpoints, remove it from the active register,
10298 +        * for software breakpoints, restore the instruction stream.
10299 +        */
10300 +       if (KDB_DEBUG(BP)) {
10301 +               kdb_printf("kdba_removebp bp_installed %d\n", bp->bp_installed);
10302 +       }
10303 +       if (bp->bp_installed) {
10304 +               if (bp->bp_hardtype) {
10305 +                       if (KDB_DEBUG(BP)) {
10306 +                               kdb_printf("kdb: removing hardware reg %ld at " kdb_bfd_vma_fmt "\n",
10307 +                                          bp->bp_hard->bph_reg, bp->bp_addr);
10308 +                       }
10309 +                       kdba_removedbreg(bp);
10310 +               } else {
10311 +                       if (KDB_DEBUG(BP))
10312 +                               kdb_printf("kdb: restoring instruction 0x%x at " kdb_bfd_vma_fmt "\n",
10313 +                                          bp->bp_inst, bp->bp_addr);
10314 +                       if (kdb_putword(bp->bp_addr, bp->bp_inst, 1))
10315 +                               return(1);
10316 +               }
10317 +               bp->bp_installed = 0;
10318 +       }
10319 +       return(0);
10320 +}
10321 diff -Nurp linux-2.6.22-590/arch/x86_64/kdb/kdba_bt.c linux-2.6.22-600/arch/x86_64/kdb/kdba_bt.c
10322 --- linux-2.6.22-590/arch/x86_64/kdb/kdba_bt.c  1970-01-01 01:00:00.000000000 +0100
10323 +++ linux-2.6.22-600/arch/x86_64/kdb/kdba_bt.c  2008-04-09 18:16:24.000000000 +0200
10324 @@ -0,0 +1,535 @@
10325 +/*
10326 + * Kernel Debugger Architecture Dependent Stack Traceback
10327 + *
10328 + * This file is subject to the terms and conditions of the GNU General Public
10329 + * License.  See the file "COPYING" in the main directory of this archive
10330 + * for more details.
10331 + *
10332 + * Copyright (c) 1999-2006 Silicon Graphics, Inc.  All Rights Reserved.
10333 + */
10334 +
10335 +#include <linux/ctype.h>
10336 +#include <linux/string.h>
10337 +#include <linux/kernel.h>
10338 +#include <linux/sched.h>
10339 +#include <linux/kallsyms.h>
10340 +#include <linux/irq.h>
10341 +#include <linux/kdb.h>
10342 +#include <linux/kdbprivate.h>
10343 +#include <asm/system.h>
10344 +
10345 +/* x86_64 has multiple alternate stacks, with different sizes and different
10346 + * offsets to get the link from one stack to the next.  Some of the stacks are
10347 + * referenced via cpu_pda, some via per_cpu orig_ist.  Debug events can even
10348 + * have multiple nested stacks within the single physical stack, each nested
10349 + * stack has its own link and some of those links are wrong.
10350 + *
10351 + * Consistent it's not!
10352 + *
10353 + * Do not assume that these stacks are aligned on their size.
10354 + */
10355 +#define INTERRUPT_STACK (N_EXCEPTION_STACKS + 1)
10356 +void
10357 +kdba_get_stack_info_alternate(kdb_machreg_t addr, int cpu,
10358 +                             struct kdb_activation_record *ar)
10359 +{
10360 +       static struct {
10361 +               const char *id;
10362 +               unsigned int total_size;
10363 +               unsigned int nested_size;
10364 +               unsigned int next;
10365 +       } *sdp, stack_data[] = {
10366 +               [STACKFAULT_STACK - 1] =  { "stackfault",    EXCEPTION_STKSZ, EXCEPTION_STKSZ, EXCEPTION_STKSZ - 2*sizeof(void *) },
10367 +               [DOUBLEFAULT_STACK - 1] = { "doublefault",   EXCEPTION_STKSZ, EXCEPTION_STKSZ, EXCEPTION_STKSZ - 2*sizeof(void *) },
10368 +               [NMI_STACK - 1] =         { "nmi",           EXCEPTION_STKSZ, EXCEPTION_STKSZ, EXCEPTION_STKSZ - 2*sizeof(void *) },
10369 +               [DEBUG_STACK - 1] =       { "debug",         DEBUG_STKSZ,     EXCEPTION_STKSZ, EXCEPTION_STKSZ - 2*sizeof(void *) },
10370 +               [MCE_STACK - 1] =         { "machine check", EXCEPTION_STKSZ, EXCEPTION_STKSZ, EXCEPTION_STKSZ - 2*sizeof(void *) },
10371 +               [INTERRUPT_STACK - 1] =   { "interrupt",     IRQSTACKSIZE,    IRQSTACKSIZE,    IRQSTACKSIZE    -   sizeof(void *) },
10372 +       };
10373 +       unsigned long total_start = 0, total_size, total_end;
10374 +       int sd, found = 0;
10375 +
10376 +       for (sd = 0, sdp = stack_data;
10377 +            sd < ARRAY_SIZE(stack_data);
10378 +            ++sd, ++sdp) {
10379 +               total_size = sdp->total_size;
10380 +               if (!total_size)
10381 +                       continue;       /* in case stack_data[] has any holes */
10382 +               if (cpu < 0) {
10383 +                       /* Arbitrary address which can be on any cpu, see if it
10384 +                        * falls within any of the alternate stacks
10385 +                        */
10386 +                       int c;
10387 +                       for_each_online_cpu(c) {
10388 +                               if (sd == INTERRUPT_STACK - 1)
10389 +                                       total_end = (unsigned long)cpu_pda(c)->irqstackptr;
10390 +                               else
10391 +                                       total_end = per_cpu(orig_ist, c).ist[sd];
10392 +                               total_start = total_end - total_size;
10393 +                               if (addr >= total_start && addr < total_end) {
10394 +                                       found = 1;
10395 +                                       cpu = c;
10396 +                                       break;
10397 +                               }
10398 +                       }
10399 +                       if (!found)
10400 +                               continue;
10401 +               }
10402 +               /* Only check the supplied or found cpu */
10403 +               if (sd == INTERRUPT_STACK - 1)
10404 +                       total_end = (unsigned long)cpu_pda(cpu)->irqstackptr;
10405 +               else
10406 +                       total_end = per_cpu(orig_ist, cpu).ist[sd];
10407 +               total_start = total_end - total_size;
10408 +               if (addr >= total_start && addr < total_end) {
10409 +                       found = 1;
10410 +                       break;
10411 +               }
10412 +       }
10413 +       if (!found)
10414 +               return;
10415 +       /* find which nested stack the address is in */
10416 +       while (addr > total_start + sdp->nested_size)
10417 +               total_start += sdp->nested_size;
10418 +       ar->stack.physical_start = total_start;
10419 +       ar->stack.physical_end = total_start + sdp->nested_size;
10420 +       ar->stack.logical_start = total_start;
10421 +       ar->stack.logical_end = total_start + sdp->next;
10422 +       ar->stack.next = *(unsigned long *)ar->stack.logical_end;
10423 +       ar->stack.id = sdp->id;
10424 +
10425 +       /* Nasty: common_interrupt builds a partial pt_regs, with r15 through
10426 +        * rbx not being filled in.  It passes struct pt_regs* to do_IRQ (in
10427 +        * rdi) but the stack pointer is not adjusted to account for r15
10428 +        * through rbx.  This has two effects :-
10429 +        *
10430 +        * (1) struct pt_regs on an external interrupt actually overlaps with
10431 +        *     the local stack area used by do_IRQ.  Not only are r15-rbx
10432 +        *     undefined, the area that claims to hold their values can even
10433 +        *     change as the irq is processed..
10434 +        *
10435 +        * (2) The back stack pointer saved for the new frame is not pointing
10436 +        *     at pt_regs, it is pointing at rbx within the pt_regs passed to
10437 +        *     do_IRQ.
10438 +        *
10439 +        * There is nothing that I can do about (1) but I have to fix (2)
10440 +        * because kdb backtrace looks for pt_regs.
10441 +        */
10442 +
10443 +       if (sd == INTERRUPT_STACK - 1)
10444 +               ar->stack.next -= offsetof(struct pt_regs, rbx);
10445 +}
10446 +
10447 +/* Given an address which claims to be on a stack, an optional cpu number and
10448 + * an optional task address, get information about the stack.
10449 + *
10450 + * t == NULL, cpu < 0 indicates an arbitrary stack address with no associated
10451 + * struct task, the address can be in an alternate stack or any task's normal
10452 + * stack.
10453 + *
10454 + * t != NULL, cpu >= 0 indicates a running task, the address can be in an
10455 + * alternate stack or that task's normal stack.
10456 + *
10457 + * t != NULL, cpu < 0 indicates a blocked task, the address can only be in that
10458 + * task's normal stack.
10459 + *
10460 + * t == NULL, cpu >= 0 is not a valid combination.
10461 + */
10462 +
10463 +static void
10464 +kdba_get_stack_info(kdb_machreg_t rsp, int cpu,
10465 +                   struct kdb_activation_record *ar,
10466 +                   const struct task_struct *t)
10467 +{
10468 +       struct thread_info *tinfo;
10469 +       struct task_struct *g, *p;
10470 +       memset(&ar->stack, 0, sizeof(ar->stack));
10471 +       if (KDB_DEBUG(ARA))
10472 +               kdb_printf("%s: rsp=0x%lx cpu=%d task=%p\n",
10473 +                          __FUNCTION__, rsp, cpu, t);
10474 +       if (t == NULL || cpu >= 0) {
10475 +               kdba_get_stack_info_alternate(rsp, cpu, ar);
10476 +               if (ar->stack.logical_start)
10477 +                       goto out;
10478 +       }
10479 +       rsp &= -THREAD_SIZE;
10480 +       tinfo = (struct thread_info *)rsp;
10481 +       if (t == NULL) {
10482 +               /* Arbitrary stack address without an associated task, see if
10483 +                * it falls within any normal process stack, including the idle
10484 +                * tasks.
10485 +                */
10486 +               kdb_do_each_thread(g, p) {
10487 +                       if (tinfo == task_thread_info(p)) {
10488 +                               t = p;
10489 +                               goto found;
10490 +                       }
10491 +               } kdb_while_each_thread(g, p);
10492 +               for_each_online_cpu(cpu) {
10493 +                       p = idle_task(cpu);
10494 +                       if (tinfo == task_thread_info(p)) {
10495 +                               t = p;
10496 +                               goto found;
10497 +                       }
10498 +               }
10499 +       found:
10500 +               if (KDB_DEBUG(ARA))
10501 +                       kdb_printf("%s: found task %p\n", __FUNCTION__, t);
10502 +       } else if (cpu >= 0) {
10503 +               /* running task */
10504 +               struct kdb_running_process *krp = kdb_running_process + cpu;
10505 +               if (krp->p != t || tinfo != task_thread_info(t))
10506 +                       t = NULL;
10507 +               if (KDB_DEBUG(ARA))
10508 +                       kdb_printf("%s: running task %p\n", __FUNCTION__, t);
10509 +       } else {
10510 +               /* blocked task */
10511 +               if (tinfo != task_thread_info(t))
10512 +                       t = NULL;
10513 +               if (KDB_DEBUG(ARA))
10514 +                       kdb_printf("%s: blocked task %p\n", __FUNCTION__, t);
10515 +       }
10516 +       if (t) {
10517 +               ar->stack.physical_start = rsp;
10518 +               ar->stack.physical_end = rsp + THREAD_SIZE;
10519 +               ar->stack.logical_start = rsp + sizeof(struct thread_info);
10520 +               ar->stack.logical_end = ar->stack.physical_end;
10521 +               ar->stack.next = 0;
10522 +               ar->stack.id = "normal";
10523 +       }
10524 +out:
10525 +       if (ar->stack.physical_start && KDB_DEBUG(ARA)) {
10526 +               kdb_printf("%s: ar->stack\n", __FUNCTION__);
10527 +               kdb_printf("    physical_start=0x%lx\n", ar->stack.physical_start);
10528 +               kdb_printf("    physical_end=0x%lx\n", ar->stack.physical_end);
10529 +               kdb_printf("    logical_start=0x%lx\n", ar->stack.logical_start);
10530 +               kdb_printf("    logical_end=0x%lx\n", ar->stack.logical_end);
10531 +               kdb_printf("    next=0x%lx\n", ar->stack.next);
10532 +               kdb_printf("    id=%s\n", ar->stack.id);
10533 +       }
10534 +}
10535 +
10536 +/*
10537 + * bt_print_one
10538 + *
10539 + *     Print one back trace entry.
10540 + *
10541 + * Inputs:
10542 + *     rip     Current program counter, or return address.
10543 + *     rsp     Stack pointer rsp when at rip.
10544 + *     ar      Activation record for this frame.
10545 + *     symtab  Information about symbol that rip falls within.
10546 + *     argcount Maximum number of arguments to print.
10547 + * Outputs:
10548 + *     None.
10549 + * Returns:
10550 + *     None.
10551 + * Locking:
10552 + *     None.
10553 + * Remarks:
10554 + *     None.
10555 + */
10556 +
10557 +static void
10558 +bt_print_one(kdb_machreg_t rip, kdb_machreg_t rsp,
10559 +            const struct kdb_activation_record *ar,
10560 +            const kdb_symtab_t *symtab, int argcount)
10561 +{
10562 +       int btsymarg = 0;
10563 +       int nosect = 0;
10564 +       kdb_machreg_t word;
10565 +
10566 +       kdbgetintenv("BTSYMARG", &btsymarg);
10567 +       kdbgetintenv("NOSECT", &nosect);
10568 +
10569 +       kdb_printf(kdb_machreg_fmt0, rsp);
10570 +       kdb_symbol_print(rip, symtab, KDB_SP_SPACEB|KDB_SP_VALUE);
10571 +       if (argcount && ar->args) {
10572 +               int i, argc = ar->args;
10573 +               kdb_printf(" (");
10574 +               if (argc > argcount)
10575 +                       argc = argcount;
10576 +               for (i = 0; i < argc; i++) {
10577 +                       kdb_machreg_t argp = ar->arg[i];
10578 +                       if (i)
10579 +                               kdb_printf(", ");
10580 +                       kdb_getword(&word, argp, sizeof(word));
10581 +                       kdb_printf("0x%lx", word);
10582 +               }
10583 +               kdb_printf(")");
10584 +       }
10585 +       if (symtab->sym_name) {
10586 +               if (!nosect) {
10587 +                       kdb_printf("\n");
10588 +                       kdb_printf("                               %s",
10589 +                                  symtab->mod_name);
10590 +                       if (symtab->sec_name && symtab->sec_start)
10591 +                               kdb_printf(" 0x%lx 0x%lx",
10592 +                                          symtab->sec_start, symtab->sec_end);
10593 +                       kdb_printf(" 0x%lx 0x%lx",
10594 +                                  symtab->sym_start, symtab->sym_end);
10595 +               }
10596 +       }
10597 +       kdb_printf("\n");
10598 +       if (argcount && ar->args && btsymarg) {
10599 +               int i, argc = ar->args;
10600 +               kdb_symtab_t arg_symtab;
10601 +               for (i = 0; i < argc; i++) {
10602 +                       kdb_machreg_t argp = ar->arg[i];
10603 +                       kdb_getword(&word, argp, sizeof(word));
10604 +                       if (kdbnearsym(word, &arg_symtab)) {
10605 +                               kdb_printf("                               ");
10606 +                               kdb_symbol_print(word, &arg_symtab,
10607 +                                                KDB_SP_DEFAULT|KDB_SP_NEWLINE);
10608 +                       }
10609 +               }
10610 +       }
10611 +}
10612 +
10613 +/* Getting the starting point for a backtrace on a running process is
10614 + * moderately tricky.  kdba_save_running() saved the rsp in krp->arch.rsp, but
10615 + * that rsp is not 100% accurate, it can be offset by a frame pointer or by the
10616 + * size of local variables in kdba_main_loop() and kdb_save_running().
10617 + *
10618 + * The calling sequence is kdb() -> kdba_main_loop() -> kdb_save_running() ->
10619 + * kdba_save_running().  Walk up the stack until we find a return address
10620 + * inside the main kdb() function and start the backtrace from there.
10621 + */
10622 +
10623 +static int
10624 +kdba_bt_stack_running(const struct task_struct *p,
10625 +                     const struct kdb_activation_record *ar,
10626 +                     kdb_machreg_t *rip, kdb_machreg_t *rsp,
10627 +                     kdb_machreg_t *rbp)
10628 +{
10629 +       kdb_machreg_t addr, sp;
10630 +       kdb_symtab_t symtab;
10631 +       struct kdb_running_process *krp = kdb_running_process + task_cpu(p);
10632 +       int found = 0;
10633 +
10634 +       if (kdbgetsymval("kdb", &symtab) == 0)
10635 +               return 0;
10636 +       if (kdbnearsym(symtab.sym_start, &symtab) == 0)
10637 +               return 0;
10638 +       sp = krp->arch.rsp;
10639 +       if (sp < ar->stack.logical_start || sp >= ar->stack.logical_end)
10640 +               return 0;
10641 +       while (sp < ar->stack.logical_end) {
10642 +               addr = *(kdb_machreg_t *)sp;
10643 +               if (addr >= symtab.sym_start && addr < symtab.sym_end) {
10644 +                       found = 1;
10645 +                       break;
10646 +               }
10647 +               sp += sizeof(kdb_machreg_t);
10648 +       }
10649 +       if (!found)
10650 +               return 0;
10651 +       *rbp = *rsp = sp;
10652 +       *rip = addr;
10653 +       return 1;
10654 +}
10655 +
10656 +/*
10657 + * kdba_bt_stack
10658 + *
10659 + * Inputs:
10660 + *     addr    Pointer to Address provided to 'bt' command, if any.
10661 + *     argcount
10662 + *     p       Pointer to task for 'btp' command.
10663 + * Outputs:
10664 + *     None.
10665 + * Returns:
10666 + *     zero for success, a kdb diagnostic if error
10667 + * Locking:
10668 + *     none.
10669 + * Remarks:
10670 + *     mds comes in handy when examining the stack to do a manual
10671 + *     traceback.
10672 + */
10673 +
10674 +static int
10675 +kdba_bt_stack(kdb_machreg_t addr, int argcount, const struct task_struct *p)
10676 +{
10677 +       struct kdb_activation_record ar;
10678 +       kdb_machreg_t rip, rsp, rbp, cs;
10679 +       kdb_symtab_t symtab;
10680 +       int first_time = 1, count = 0, btsp = 0, suppress;
10681 +       struct pt_regs *regs = NULL;
10682 +
10683 +       kdbgetintenv("BTSP", &btsp);
10684 +       suppress = !btsp;
10685 +       memset(&ar, 0, sizeof(ar));
10686 +
10687 +       /*
10688 +        * The caller may have supplied an address at which the
10689 +        * stack traceback operation should begin.  This address
10690 +        * is assumed by this code to point to a return-address
10691 +        * on the stack to be traced back.
10692 +        *
10693 +        * The end result of this will make it appear as if a function
10694 +        * entitled '<unknown>' was called from the function which
10695 +        * contains return-address.
10696 +        */
10697 +       if (addr) {
10698 +               rip = 0;
10699 +               rbp = 0;
10700 +               rsp = addr;
10701 +               cs = __KERNEL_CS;       /* have to assume kernel space */
10702 +               suppress = 0;
10703 +               kdba_get_stack_info(rsp, -1, &ar, NULL);
10704 +       } else {
10705 +               if (task_curr(p)) {
10706 +                       struct kdb_running_process *krp =
10707 +                           kdb_running_process + task_cpu(p);
10708 +
10709 +                       if (krp->seqno && krp->p == p
10710 +                           && krp->seqno >= kdb_seqno - 1) {
10711 +                               /* valid saved state, continue processing */
10712 +                       } else {
10713 +                               kdb_printf
10714 +                                   ("Process did not save state, cannot backtrace\n");
10715 +                               kdb_ps1(p);
10716 +                               return 0;
10717 +                       }
10718 +                       regs = krp->regs;
10719 +                       if (KDB_NULL_REGS(regs))
10720 +                               return KDB_BADREG;
10721 +                       kdba_getregcontents("cs", regs, &cs);
10722 +                       if ((cs & 0xffff) != __KERNEL_CS) {
10723 +                               kdb_printf("Stack is not in kernel space, backtrace not available\n");
10724 +                               return 0;
10725 +                       }
10726 +                       kdba_getregcontents("rip", regs, &rip);
10727 +                       kdba_getregcontents("rbp", regs, &rbp);
10728 +                       rsp = krp->arch.rsp;
10729 +                       kdba_get_stack_info(rsp, kdb_process_cpu(p), &ar, p);
10730 +                       if (kdba_bt_stack_running(p, &ar, &rip, &rsp, &rbp) == 0) {
10731 +                               kdb_printf("%s: cannot adjust rsp=0x%lx for a running task\n",
10732 +                                          __FUNCTION__, rsp);
10733 +                       }
10734 +               } else {
10735 +                       /* Not on cpu, assume blocked.  Blocked tasks do
10736 +                        * not have pt_regs.  p->thread.rsp is set, rsp
10737 +                        * points to the rbp value, assume kernel space.
10738 +                        *
10739 +                        * The rip is no longer in the thread struct.  We know
10740 +                        * that the stack value was saved in schedule near the
10741 +                        * label thread_return.  Setting rip to thread_return-1
10742 +                        * lets the stack trace find that we are in schedule
10743 +                        * and correctly decode its prologue.  We extract the
10744 +                        * saved rbp and adjust the stack to undo the effects
10745 +                        * of the inline assembly code which switches the
10746 +                        * stack.
10747 +                        */
10748 +                       extern void thread_return(void);
10749 +                       rip = (kdb_machreg_t)&thread_return-1;
10750 +                       rsp = p->thread.rsp;
10751 +                       rbp = *(unsigned long *)rsp;
10752 +                       rsp += 16;
10753 +                       cs = __KERNEL_CS;
10754 +                       suppress = 0;
10755 +                       kdba_get_stack_info(rsp, -1, &ar, p);
10756 +               }
10757 +       }
10758 +       if (!ar.stack.physical_start) {
10759 +               kdb_printf("rsp=0x%lx is not in a valid kernel stack, backtrace not available\n",
10760 +                          rsp);
10761 +               return 0;
10762 +       }
10763 +
10764 +       kdb_printf("rsp                rip                Function (args)\n");
10765 +       if (ar.stack.next && !suppress)
10766 +               kdb_printf(" ======================= <%s>\n",
10767 +                          ar.stack.id);
10768 +
10769 +       /* Run through all the stacks */
10770 +       while (ar.stack.physical_start) {
10771 +               if (!first_time)
10772 +                       rip = *(kdb_machreg_t *)rsp;
10773 +               first_time = 0;
10774 +               if (!suppress && __kernel_text_address(rip)) {
10775 +                       kdbnearsym(rip, &symtab);
10776 +                       bt_print_one(rip, rsp, &ar, &symtab, argcount);
10777 +                       ++count;
10778 +               }
10779 +               if ((struct pt_regs *)rsp == regs) {
10780 +                       if (ar.stack.next && suppress)
10781 +                               kdb_printf(" ======================= <%s>\n",
10782 +                                          ar.stack.id);
10783 +                       ++count;
10784 +                       suppress = 0;
10785 +               }
10786 +               rsp += sizeof(rip);
10787 +               if (count > 200)
10788 +                       break;
10789 +               if (rsp < ar.stack.logical_end)
10790 +                       continue;
10791 +               if (!ar.stack.next)
10792 +                       break;
10793 +               rsp = ar.stack.next;
10794 +               if (KDB_DEBUG(ARA))
10795 +                       kdb_printf("new rsp=0x%lx\n", rsp);
10796 +               kdba_get_stack_info(rsp, -1, &ar, NULL);
10797 +               if (!ar.stack.physical_start) {
10798 +                       kdb_printf("+++ Cannot resolve next stack\n");
10799 +               } else if (!suppress) {
10800 +                       kdb_printf(" ======================= <%s>\n",
10801 +                                  ar.stack.id);
10802 +                       ++count;
10803 +               }
10804 +       }
10805 +
10806 +       if (count > 200)
10807 +               kdb_printf("bt truncated, count limit reached\n");
10808 +       else if (suppress)
10809 +               kdb_printf
10810 +                   ("bt did not find pt_regs - no trace produced.  Suggest 'set BTSP 1'\n");
10811 +
10812 +       return 0;
10813 +}
10814 +
10815 +/*
10816 + * kdba_bt_address
10817 + *
10818 + *     Do a backtrace starting at a specified stack address.  Use this if the
10819 + *     heuristics get the stack decode wrong.
10820 + *
10821 + * Inputs:
10822 + *     addr    Address provided to 'bt' command.
10823 + *     argcount
10824 + * Outputs:
10825 + *     None.
10826 + * Returns:
10827 + *     zero for success, a kdb diagnostic if error
10828 + * Locking:
10829 + *     none.
10830 + * Remarks:
10831 + *     mds %rsp comes in handy when examining the stack to do a manual
10832 + *     traceback.
10833 + */
10834 +
10835 +int kdba_bt_address(kdb_machreg_t addr, int argcount)
10836 +{
10837 +       return kdba_bt_stack(addr, argcount, NULL);
10838 +}
10839 +
10840 +/*
10841 + * kdba_bt_process
10842 + *
10843 + *     Do a backtrace for a specified process.
10844 + *
10845 + * Inputs:
10846 + *     p       Struct task pointer extracted by 'bt' command.
10847 + *     argcount
10848 + * Outputs:
10849 + *     None.
10850 + * Returns:
10851 + *     zero for success, a kdb diagnostic if error
10852 + * Locking:
10853 + *     none.
10854 + */
10855 +
10856 +int kdba_bt_process(const struct task_struct *p, int argcount)
10857 +{
10858 +       return kdba_bt_stack(0, argcount, p);
10859 +}
10860 diff -Nurp linux-2.6.22-590/arch/x86_64/kdb/kdba_id.c linux-2.6.22-600/arch/x86_64/kdb/kdba_id.c
10861 --- linux-2.6.22-590/arch/x86_64/kdb/kdba_id.c  1970-01-01 01:00:00.000000000 +0100
10862 +++ linux-2.6.22-600/arch/x86_64/kdb/kdba_id.c  2008-04-09 18:16:24.000000000 +0200
10863 @@ -0,0 +1,256 @@
10864 +/*
10865 + * Kernel Debugger Architecture Dependent Instruction Disassembly
10866 + *
10867 + * This file is subject to the terms and conditions of the GNU General Public
10868 + * License.  See the file "COPYING" in the main directory of this archive
10869 + * for more details.
10870 + *
10871 + * Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
10872 + */
10873 +
10874 +#include <stdarg.h>
10875 +#include <linux/kernel.h>
10876 +#include <linux/init.h>
10877 +#include <linux/ctype.h>
10878 +#include <linux/string.h>
10879 +#include <linux/kdb.h>
10880 +#include <linux/kdbprivate.h>
10881 +
10882 +/*
10883 + * kdba_dis_getsym
10884 + *
10885 + *     Get a symbol for the disassembler.
10886 + *
10887 + * Parameters:
10888 + *     addr    Address for which to get symbol
10889 + *     dip     Pointer to disassemble_info
10890 + * Returns:
10891 + *     0
10892 + * Locking:
10893 + * Remarks:
10894 + *     Not used for kdb.
10895 + */
10896 +
10897 +/* ARGSUSED */
10898 +static int
10899 +kdba_dis_getsym(bfd_vma addr, disassemble_info *dip)
10900 +{
10901 +
10902 +       return 0;
10903 +}
10904 +
10905 +/*
10906 + * kdba_printaddress
10907 + *
10908 + *     Print (symbolically) an address.
10909 + *
10910 + * Parameters:
10911 + *     addr    Address for which to get symbol
10912 + *     dip     Pointer to disassemble_info
10913 + *     flag    True if a ":<tab>" sequence should follow the address
10914 + * Returns:
10915 + *     0
10916 + * Locking:
10917 + * Remarks:
10918 + *
10919 + */
10920 +
10921 +/* ARGSUSED */
10922 +static void
10923 +kdba_printaddress(kdb_machreg_t addr, disassemble_info *dip, int flag)
10924 +{
10925 +       kdb_symtab_t symtab;
10926 +       int spaces = 5;
10927 +       unsigned int offset;
10928 +
10929 +       /*
10930 +        * Print a symbol name or address as necessary.
10931 +        */
10932 +       kdbnearsym(addr, &symtab);
10933 +       if (symtab.sym_name) {
10934 +               /* Do not use kdb_symbol_print here, it always does
10935 +                * kdb_printf but we want dip->fprintf_func.
10936 +                */
10937 +               dip->fprintf_func(dip->stream,
10938 +                       "0x%0*lx %s",
10939 +                       (int)(2*sizeof(addr)), addr, symtab.sym_name);
10940 +               if ((offset = addr - symtab.sym_start) == 0) {
10941 +                       spaces += 4;
10942 +               }
10943 +               else {
10944 +                       unsigned int o = offset;
10945 +                       while (o >>= 4)
10946 +                               --spaces;
10947 +                       dip->fprintf_func(dip->stream, "+0x%x", offset);
10948 +               }
10949 +
10950 +       } else {
10951 +               dip->fprintf_func(dip->stream, "0x%lx", addr);
10952 +       }
10953 +
10954 +       if (flag) {
10955 +               if (spaces < 1) {
10956 +                       spaces = 1;
10957 +               }
10958 +               dip->fprintf_func(dip->stream, ":%*s", spaces, " ");
10959 +       }
10960 +}
10961 +
10962 +/*
10963 + * kdba_dis_printaddr
10964 + *
10965 + *     Print (symbolically) an address.  Called by GNU disassembly
10966 + *     code via disassemble_info structure.
10967 + *
10968 + * Parameters:
10969 + *     addr    Address for which to get symbol
10970 + *     dip     Pointer to disassemble_info
10971 + * Returns:
10972 + *     0
10973 + * Locking:
10974 + * Remarks:
10975 + *     This function will never append ":<tab>" to the printed
10976 + *     symbolic address.
10977 + */
10978 +
10979 +static void
10980 +kdba_dis_printaddr(bfd_vma addr, disassemble_info *dip)
10981 +{
10982 +       kdba_printaddress(addr, dip, 0);
10983 +}
10984 +
10985 +/*
10986 + * kdba_dis_getmem
10987 + *
10988 + *     Fetch 'length' bytes from 'addr' into 'buf'.
10989 + *
10990 + * Parameters:
10991 + *     addr    Address for which to get symbol
10992 + *     buf     Address of buffer to fill with bytes from 'addr'
10993 + *     length  Number of bytes to fetch
10994 + *     dip     Pointer to disassemble_info
10995 + * Returns:
10996 + *     0 if data is available, otherwise error.
10997 + * Locking:
10998 + * Remarks:
10999 + *
11000 + */
11001 +
11002 +/* ARGSUSED */
11003 +static int
11004 +kdba_dis_getmem(bfd_vma addr, bfd_byte *buf, unsigned int length, disassemble_info *dip)
11005 +{
11006 +       return kdb_getarea_size(buf, addr, length);
11007 +}
11008 +
11009 +/*
11010 + * kdba_id_parsemode
11011 + *
11012 + *     Parse IDMODE environment variable string and
11013 + *     set appropriate value into "disassemble_info" structure.
11014 + *
11015 + * Parameters:
11016 + *     mode    Mode string
11017 + *     dip     Disassemble_info structure pointer
11018 + * Returns:
11019 + * Locking:
11020 + * Remarks:
11021 + *     We handle the values 'x86' and '8086' to enable either
11022 + *     32-bit instruction set or 16-bit legacy instruction set.
11023 + */
11024 +
11025 +int
11026 +kdba_id_parsemode(const char *mode, disassemble_info *dip)
11027 +{
11028 +       if (mode) {
11029 +               if (strcmp(mode, "x86_64") == 0) {
11030 +                       dip->mach = bfd_mach_x86_64;
11031 +               } else if (strcmp(mode, "x86") == 0) {
11032 +                       dip->mach = bfd_mach_i386_i386;
11033 +               } else if (strcmp(mode, "8086") == 0) {
11034 +                       dip->mach = bfd_mach_i386_i8086;
11035 +               } else {
11036 +                       return KDB_BADMODE;
11037 +               }
11038 +       }
11039 +
11040 +       return 0;
11041 +}
11042 +
11043 +/*
11044 + * kdba_check_pc
11045 + *
11046 + *     Check that the pc is satisfactory.
11047 + *
11048 + * Parameters:
11049 + *     pc      Program Counter Value.
11050 + * Returns:
11051 + *     None
11052 + * Locking:
11053 + *     None.
11054 + * Remarks:
11055 + *     Can change pc.
11056 + */
11057 +
11058 +void
11059 +kdba_check_pc(kdb_machreg_t *pc)
11060 +{
11061 +       /* No action */
11062 +}
11063 +
11064 +/*
11065 + * kdba_id_printinsn
11066 + *
11067 + *     Format and print a single instruction at 'pc'. Return the
11068 + *     length of the instruction.
11069 + *
11070 + * Parameters:
11071 + *     pc      Program Counter Value.
11072 + *     dip     Disassemble_info structure pointer
11073 + * Returns:
11074 + *     Length of instruction, -1 for error.
11075 + * Locking:
11076 + *     None.
11077 + * Remarks:
11078 + *     Depends on 'IDMODE' environment variable.
11079 + */
11080 +
11081 +int
11082 +kdba_id_printinsn(kdb_machreg_t pc, disassemble_info *dip)
11083 +{
11084 +       kdba_printaddress(pc, dip, 1);
11085 +       return print_insn_i386_att(pc, dip);
11086 +}
11087 +
11088 +/*
11089 + * kdba_id_init
11090 + *
11091 + *     Initialize the architecture dependent elements of
11092 + *     the disassembly information structure
11093 + *     for the GNU disassembler.
11094 + *
11095 + * Parameters:
11096 + *     None.
11097 + * Outputs:
11098 + *     None.
11099 + * Returns:
11100 + *     None.
11101 + * Locking:
11102 + *     None.
11103 + * Remarks:
11104 + */
11105 +
11106 +void
11107 +kdba_id_init(disassemble_info *dip)
11108 +{
11109 +       dip->read_memory_func       = kdba_dis_getmem;
11110 +       dip->print_address_func     = kdba_dis_printaddr;
11111 +       dip->symbol_at_address_func = kdba_dis_getsym;
11112 +
11113 +       dip->flavour                = bfd_target_elf_flavour;
11114 +       dip->arch                   = bfd_arch_i386;
11115 +       dip->mach                   = bfd_mach_x86_64;
11116 +       dip->endian                 = BFD_ENDIAN_LITTLE;
11117 +
11118 +       dip->display_endian         = BFD_ENDIAN_LITTLE;
11119 +}
11120 diff -Nurp linux-2.6.22-590/arch/x86_64/kdb/kdba_io.c linux-2.6.22-600/arch/x86_64/kdb/kdba_io.c
11121 --- linux-2.6.22-590/arch/x86_64/kdb/kdba_io.c  1970-01-01 01:00:00.000000000 +0100
11122 +++ linux-2.6.22-600/arch/x86_64/kdb/kdba_io.c  2008-04-09 18:16:24.000000000 +0200
11123 @@ -0,0 +1,503 @@
11124 +/*
11125 + * Kernel Debugger Architecture Dependent Console I/O handler
11126 + *
11127 + * This file is subject to the terms and conditions of the GNU General Public
11128 + * License.  See the file "COPYING" in the main directory of this archive
11129 + * for more details.
11130 + *
11131 + * Copyright (c) 1999-2006 Silicon Graphics, Inc.  All Rights Reserved.
11132 + */
11133 +
11134 +#include <linux/sched.h>
11135 +#include <linux/kernel.h>
11136 +#include <asm/io.h>
11137 +#include <linux/delay.h>
11138 +#include <linux/console.h>
11139 +#include <linux/ctype.h>
11140 +#include <linux/keyboard.h>
11141 +#include <linux/serial.h>
11142 +#include <linux/serial_reg.h>
11143 +
11144 +#include <linux/kdb.h>
11145 +#include <linux/kdbprivate.h>
11146 +#include <pc_keyb.h>
11147 +
11148 +#ifdef CONFIG_VT_CONSOLE
11149 +#define KDB_BLINK_LED 1
11150 +#else
11151 +#undef KDB_BLINK_LED
11152 +#endif
11153 +
11154 +#ifdef CONFIG_KDB_USB
11155 +struct kdb_usb_exchange kdb_usb_infos;
11156 +
11157 +EXPORT_SYMBOL(kdb_usb_infos);
11158 +
11159 +static unsigned char kdb_usb_keycode[256] = {
11160 +         0,  0,  0,  0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38,
11161 +        50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44,  2,  3,
11162 +         4,  5,  6,  7,  8,  9, 10, 11, 28,  1, 14, 15, 57, 12, 13, 26,
11163 +        27, 43, 84, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64,
11164 +        65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106,
11165 +       105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71,
11166 +        72, 73, 82, 83, 86,127,116,117, 85, 89, 90, 91, 92, 93, 94, 95,
11167 +       120,121,122,123,134,138,130,132,128,129,131,137,133,135,136,113,
11168 +       115,114,  0,  0,  0,124,  0,181,182,183,184,185,186,187,188,189,
11169 +       190,191,192,193,194,195,196,197,198,  0,  0,  0,  0,  0,  0,  0,
11170 +         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
11171 +         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
11172 +         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
11173 +         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
11174 +        29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113,
11175 +       150,158,159,128,136,177,178,176,142,152,173,140
11176 +};
11177 +
11178 +/* get_usb_char
11179 + * This function drives the UHCI controller,
11180 + * fetch the USB scancode and decode it
11181 + */
11182 +static int get_usb_char(void)
11183 +{
11184 +       static int usb_lock;
11185 +       unsigned char keycode, spec;
11186 +       extern u_short plain_map[], shift_map[], ctrl_map[];
11187 +
11188 +       /* Is USB initialized ? */
11189 +       if(!kdb_usb_infos.poll_func || !kdb_usb_infos.urb)
11190 +               return -1;
11191 +
11192 +       /* Transfer char if they are present */
11193 +       (*kdb_usb_infos.poll_func)(kdb_usb_infos.uhci, (struct urb *)kdb_usb_infos.urb);
11194 +
11195 +       spec = kdb_usb_infos.buffer[0];
11196 +       keycode = kdb_usb_infos.buffer[2];
11197 +       kdb_usb_infos.buffer[0] = (char)0;
11198 +       kdb_usb_infos.buffer[2] = (char)0;
11199 +
11200 +       if(kdb_usb_infos.buffer[3])
11201 +               return -1;
11202 +
11203 +       /* A normal key is pressed, decode it */
11204 +       if(keycode)
11205 +               keycode = kdb_usb_keycode[keycode];
11206 +
11207 +       /* 2 Keys pressed at one time ? */
11208 +       if (spec && keycode) {
11209 +               switch(spec)
11210 +               {
11211 +                       case 0x2:
11212 +                       case 0x20: /* Shift */
11213 +                               return shift_map[keycode];
11214 +                       case 0x1:
11215 +                       case 0x10: /* Ctrl */
11216 +                               return ctrl_map[keycode];
11217 +                       case 0x4:
11218 +                       case 0x40: /* Alt */
11219 +                               break;
11220 +               }
11221 +       }
11222 +       else {
11223 +               if(keycode) { /* If only one key pressed */
11224 +                       switch(keycode)
11225 +                       {
11226 +                               case 0x1C: /* Enter */
11227 +                                       return 13;
11228 +
11229 +                               case 0x3A: /* Capslock */
11230 +                                       usb_lock ? (usb_lock = 0) : (usb_lock = 1);
11231 +                                       break;
11232 +                               case 0x0E: /* Backspace */
11233 +                                       return 8;
11234 +                               case 0x0F: /* TAB */
11235 +                                       return 9;
11236 +                               case 0x77: /* Pause */
11237 +                                       break ;
11238 +                               default:
11239 +                                       if(!usb_lock) {
11240 +                                               return plain_map[keycode];
11241 +                                       }
11242 +                                       else {
11243 +                                               return shift_map[keycode];
11244 +                                       }
11245 +                       }
11246 +               }
11247 +       }
11248 +       return -1;
11249 +}
11250 +#endif /* CONFIG_KDB_USB */
11251 +
11252 +/*
11253 + * This module contains code to read characters from the keyboard or a serial
11254 + * port.
11255 + *
11256 + * It is used by the kernel debugger, and is polled, not interrupt driven.
11257 + *
11258 + */
11259 +
11260 +#ifdef KDB_BLINK_LED
11261 +/*
11262 + * send:  Send a byte to the keyboard controller.  Used primarily to
11263 + *       alter LED settings.
11264 + */
11265 +
11266 +static void
11267 +kdb_kbdsend(unsigned char byte)
11268 +{
11269 +       int timeout;
11270 +       for (timeout = 200 * 1000; timeout && (inb(KBD_STATUS_REG) & KBD_STAT_IBF); timeout--);
11271 +       outb(byte, KBD_DATA_REG);
11272 +       udelay(40);
11273 +       for (timeout = 200 * 1000; timeout && (~inb(KBD_STATUS_REG) & KBD_STAT_OBF); timeout--);
11274 +       inb(KBD_DATA_REG);
11275 +       udelay(40);
11276 +}
11277 +
11278 +static void
11279 +kdb_toggleled(int led)
11280 +{
11281 +       static int leds;
11282 +
11283 +       leds ^= led;
11284 +
11285 +       kdb_kbdsend(KBD_CMD_SET_LEDS);
11286 +       kdb_kbdsend((unsigned char)leds);
11287 +}
11288 +#endif /* KDB_BLINK_LED */
11289 +
11290 +#if defined(CONFIG_SERIAL_8250_CONSOLE) || defined(CONFIG_SERIAL_CORE_CONSOLE)
11291 +#define CONFIG_SERIAL_CONSOLE
11292 +#endif
11293 +
11294 +#if defined(CONFIG_SERIAL_CONSOLE)
11295 +
11296 +struct kdb_serial kdb_serial;
11297 +
11298 +static unsigned int
11299 +serial_inp(struct kdb_serial *kdb_serial, unsigned long offset)
11300 +{
11301 +       offset <<= kdb_serial->ioreg_shift;
11302 +
11303 +       switch (kdb_serial->io_type) {
11304 +       case SERIAL_IO_MEM:
11305 +               return readb((void __iomem *)(kdb_serial->iobase + offset));
11306 +               break;
11307 +       default:
11308 +               return inb(kdb_serial->iobase + offset);
11309 +               break;
11310 +       }
11311 +}
11312 +
11313 +/* Check if there is a byte ready at the serial port */
11314 +static int get_serial_char(void)
11315 +{
11316 +       unsigned char ch;
11317 +
11318 +       if (kdb_serial.iobase == 0)
11319 +               return -1;
11320 +
11321 +       if (serial_inp(&kdb_serial, UART_LSR) & UART_LSR_DR) {
11322 +               ch = serial_inp(&kdb_serial, UART_RX);
11323 +               if (ch == 0x7f)
11324 +                       ch = 8;
11325 +               return ch;
11326 +       }
11327 +       return -1;
11328 +}
11329 +#endif /* CONFIG_SERIAL_CONSOLE */
11330 +
11331 +#ifdef CONFIG_VT_CONSOLE
11332 +
11333 +static int kbd_exists;
11334 +
11335 +/*
11336 + * Check if the keyboard controller has a keypress for us.
11337 + * Some parts (Enter Release, LED change) are still blocking polled here,
11338 + * but hopefully they are all short.
11339 + */
11340 +static int get_kbd_char(void)
11341 +{
11342 +       int scancode, scanstatus;
11343 +       static int shift_lock;  /* CAPS LOCK state (0-off, 1-on) */
11344 +       static int shift_key;   /* Shift next keypress */
11345 +       static int ctrl_key;
11346 +       u_short keychar;
11347 +       extern u_short plain_map[], shift_map[], ctrl_map[];
11348 +
11349 +       if (KDB_FLAG(NO_I8042) || KDB_FLAG(NO_VT_CONSOLE) ||
11350 +           (inb(KBD_STATUS_REG) == 0xff && inb(KBD_DATA_REG) == 0xff)) {
11351 +               kbd_exists = 0;
11352 +               return -1;
11353 +       }
11354 +       kbd_exists = 1;
11355 +
11356 +       if ((inb(KBD_STATUS_REG) & KBD_STAT_OBF) == 0)
11357 +               return -1;
11358 +
11359 +       /*
11360 +        * Fetch the scancode
11361 +        */
11362 +       scancode = inb(KBD_DATA_REG);
11363 +       scanstatus = inb(KBD_STATUS_REG);
11364 +
11365 +       /*
11366 +        * Ignore mouse events.
11367 +        */
11368 +       if (scanstatus & KBD_STAT_MOUSE_OBF)
11369 +               return -1;
11370 +
11371 +       /*
11372 +        * Ignore release, trigger on make
11373 +        * (except for shift keys, where we want to
11374 +        *  keep the shift state so long as the key is
11375 +        *  held down).
11376 +        */
11377 +
11378 +       if (((scancode&0x7f) == 0x2a) || ((scancode&0x7f) == 0x36)) {
11379 +               /*
11380 +                * Next key may use shift table
11381 +                */
11382 +               if ((scancode & 0x80) == 0) {
11383 +                       shift_key=1;
11384 +               } else {
11385 +                       shift_key=0;
11386 +               }
11387 +               return -1;
11388 +       }
11389 +
11390 +       if ((scancode&0x7f) == 0x1d) {
11391 +               /*
11392 +                * Left ctrl key
11393 +                */
11394 +               if ((scancode & 0x80) == 0) {
11395 +                       ctrl_key = 1;
11396 +               } else {
11397 +                       ctrl_key = 0;
11398 +               }
11399 +               return -1;
11400 +       }
11401 +
11402 +       if ((scancode & 0x80) != 0)
11403 +               return -1;
11404 +
11405 +       scancode &= 0x7f;
11406 +
11407 +       /*
11408 +        * Translate scancode
11409 +        */
11410 +
11411 +       if (scancode == 0x3a) {
11412 +               /*
11413 +                * Toggle caps lock
11414 +                */
11415 +               shift_lock ^= 1;
11416 +
11417 +#ifdef KDB_BLINK_LED
11418 +               kdb_toggleled(0x4);
11419 +#endif
11420 +               return -1;
11421 +       }
11422 +
11423 +       if (scancode == 0x0e) {
11424 +               /*
11425 +                * Backspace
11426 +                */
11427 +               return 8;
11428 +       }
11429 +
11430 +       /* Special Key */
11431 +       switch (scancode) {
11432 +       case 0xF: /* Tab */
11433 +               return 9;
11434 +       case 0x53: /* Del */
11435 +               return 4;
11436 +       case 0x47: /* Home */
11437 +               return 1;
11438 +       case 0x4F: /* End */
11439 +               return 5;
11440 +       case 0x4B: /* Left */
11441 +               return 2;
11442 +       case 0x48: /* Up */
11443 +               return 16;
11444 +       case 0x50: /* Down */
11445 +               return 14;
11446 +       case 0x4D: /* Right */
11447 +               return 6;
11448 +       }
11449 +
11450 +       if (scancode == 0xe0) {
11451 +               return -1;
11452 +       }
11453 +
11454 +       /*
11455 +        * For Japanese 86/106 keyboards
11456 +        *      See comment in drivers/char/pc_keyb.c.
11457 +        *      - Masahiro Adegawa
11458 +        */
11459 +       if (scancode == 0x73) {
11460 +               scancode = 0x59;
11461 +       } else if (scancode == 0x7d) {
11462 +               scancode = 0x7c;
11463 +       }
11464 +
11465 +       if (!shift_lock && !shift_key && !ctrl_key) {
11466 +               keychar = plain_map[scancode];
11467 +       } else if (shift_lock || shift_key) {
11468 +               keychar = shift_map[scancode];
11469 +       } else if (ctrl_key) {
11470 +               keychar = ctrl_map[scancode];
11471 +       } else {
11472 +               keychar = 0x0020;
11473 +               kdb_printf("Unknown state/scancode (%d)\n", scancode);
11474 +       }
11475 +       keychar &= 0x0fff;
11476 +       if (keychar == '\t')
11477 +               keychar = ' ';
11478 +       switch (KTYP(keychar)) {
11479 +       case KT_LETTER:
11480 +       case KT_LATIN:
11481 +               if (isprint(keychar))
11482 +                       break;          /* printable characters */
11483 +               /* drop through */
11484 +       case KT_SPEC:
11485 +               if (keychar == K_ENTER)
11486 +                       break;
11487 +               /* drop through */
11488 +       default:
11489 +               return(-1);     /* ignore unprintables */
11490 +       }
11491 +
11492 +       if ((scancode & 0x7f) == 0x1c) {
11493 +               /*
11494 +                * enter key.  All done.  Absorb the release scancode.
11495 +                */
11496 +               while ((inb(KBD_STATUS_REG) & KBD_STAT_OBF) == 0)
11497 +                       ;
11498 +
11499 +               /*
11500 +                * Fetch the scancode
11501 +                */
11502 +               scancode = inb(KBD_DATA_REG);
11503 +               scanstatus = inb(KBD_STATUS_REG);
11504 +
11505 +               while (scanstatus & KBD_STAT_MOUSE_OBF) {
11506 +                       scancode = inb(KBD_DATA_REG);
11507 +                       scanstatus = inb(KBD_STATUS_REG);
11508 +               }
11509 +
11510 +               if (scancode != 0x9c) {
11511 +                       /*
11512 +                        * Wasn't an enter-release,  why not?
11513 +                        */
11514 +                       kdb_printf("kdb: expected enter got 0x%x status 0x%x\n",
11515 +                              scancode, scanstatus);
11516 +               }
11517 +
11518 +               kdb_printf("\n");
11519 +               return 13;
11520 +       }
11521 +
11522 +       return keychar & 0xff;
11523 +}
11524 +#endif /* CONFIG_VT_CONSOLE */
11525 +
11526 +#ifdef KDB_BLINK_LED
11527 +
11528 +/* Leave numlock alone, setting it messes up laptop keyboards with the keypad
11529 + * mapped over normal keys.
11530 + */
11531 +static int kdba_blink_mask = 0x1 | 0x4;
11532 +
11533 +#define BOGOMIPS (boot_cpu_data.loops_per_jiffy/(500000/HZ))
11534 +static int blink_led(void)
11535 +{
11536 +       static long delay;
11537 +
11538 +       if (kbd_exists == 0)
11539 +               return -1;
11540 +
11541 +       if (--delay < 0) {
11542 +               if (BOGOMIPS == 0)      /* early kdb */
11543 +                       delay = 150000000/1000;     /* arbitrary bogomips */
11544 +               else
11545 +                       delay = 150000000/BOGOMIPS; /* Roughly 1 second when polling */
11546 +               kdb_toggleled(kdba_blink_mask);
11547 +       }
11548 +       return -1;
11549 +}
11550 +#endif
11551 +
11552 +get_char_func poll_funcs[] = {
11553 +#if defined(CONFIG_VT_CONSOLE)
11554 +       get_kbd_char,
11555 +#endif
11556 +#if defined(CONFIG_SERIAL_CONSOLE)
11557 +       get_serial_char,
11558 +#endif
11559 +#ifdef KDB_BLINK_LED
11560 +       blink_led,
11561 +#endif
11562 +#ifdef CONFIG_KDB_USB
11563 +       get_usb_char,
11564 +#endif
11565 +       NULL
11566 +};
11567 +
11568 +/*
11569 + * On some Compaq Deskpro's, there is a keyboard freeze many times after
11570 + * exiting from the kdb. As kdb's keyboard handler is not interrupt-driven and
11571 + * uses a polled interface, it makes more sense to disable motherboard keyboard
11572 + * controller's OBF interrupts during kdb's polling.In case, of interrupts
11573 + * remaining enabled during kdb's polling, it may cause un-necessary
11574 + * interrupts being signalled during keypresses, which are also sometimes seen
11575 + * as spurious interrupts after exiting from kdb. This hack to disable OBF
11576 + * interrupts before entry to kdb and re-enabling them at kdb exit point also
11577 + * solves the keyboard freeze issue. These functions are called from
11578 + * kdb_local(), hence these are arch. specific setup and cleanup functions
11579 + * executing only on the local processor - ashishk@sco.com
11580 + */
11581 +
11582 +void kdba_local_arch_setup(void)
11583 +{
11584 +#ifdef CONFIG_VT_CONSOLE
11585 +       unsigned char c;
11586 +
11587 +       while (kbd_read_status() & KBD_STAT_IBF);
11588 +       kbd_write_command(KBD_CCMD_READ_MODE);
11589 +       mdelay(1);
11590 +       while (kbd_read_status() & KBD_STAT_IBF);
11591 +       while ( !(kbd_read_status() & KBD_STAT_OBF) );
11592 +       c = kbd_read_input();
11593 +       c &= ~KBD_MODE_KBD_INT;
11594 +       while (kbd_read_status() & KBD_STAT_IBF);
11595 +       kbd_write_command(KBD_CCMD_WRITE_MODE);
11596 +       mdelay(1);
11597 +       while (kbd_read_status() & KBD_STAT_IBF);
11598 +       kbd_write_output(c);
11599 +       mdelay(1);
11600 +       while (kbd_read_status() & KBD_STAT_IBF);
11601 +       mdelay(1);
11602 +#endif /* CONFIG_VT_CONSOLE */
11603 +}
11604 +
11605 +void kdba_local_arch_cleanup(void)
11606 +{
11607 +#ifdef CONFIG_VT_CONSOLE
11608 +       unsigned char c;
11609 +
11610 +       while (kbd_read_status() & KBD_STAT_IBF);
11611 +       kbd_write_command(KBD_CCMD_READ_MODE);
11612 +       mdelay(1);
11613 +       while (kbd_read_status() & KBD_STAT_IBF);
11614 +       while ( !(kbd_read_status() & KBD_STAT_OBF) );
11615 +       c = kbd_read_input();
11616 +       c |= KBD_MODE_KBD_INT;
11617 +       while (kbd_read_status() & KBD_STAT_IBF);
11618 +       kbd_write_command(KBD_CCMD_WRITE_MODE);
11619 +       mdelay(1);
11620 +       while (kbd_read_status() & KBD_STAT_IBF);
11621 +       kbd_write_output(c);
11622 +       mdelay(1);
11623 +       while (kbd_read_status() & KBD_STAT_IBF);
11624 +       mdelay(1);
11625 +#endif /* CONFIG_VT_CONSOLE */
11626 +}
11627 diff -Nurp linux-2.6.22-590/arch/x86_64/kdb/kdbasupport.c linux-2.6.22-600/arch/x86_64/kdb/kdbasupport.c
11628 --- linux-2.6.22-590/arch/x86_64/kdb/kdbasupport.c      1970-01-01 01:00:00.000000000 +0100
11629 +++ linux-2.6.22-600/arch/x86_64/kdb/kdbasupport.c      2008-04-09 18:16:24.000000000 +0200
11630 @@ -0,0 +1,1015 @@
11631 +/*
11632 + * Kernel Debugger Architecture Independent Support Functions
11633 + *
11634 + * This file is subject to the terms and conditions of the GNU General Public
11635 + * License.  See the file "COPYING" in the main directory of this archive
11636 + * for more details.
11637 + *
11638 + * Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
11639 + */
11640 +
11641 +#include <linux/string.h>
11642 +#include <linux/stddef.h>
11643 +#include <linux/kernel.h>
11644 +#include <linux/init.h>
11645 +#include <linux/ptrace.h>
11646 +#include <linux/mm.h>
11647 +#include <linux/sched.h>
11648 +#include <linux/hardirq.h>
11649 +#include <linux/kdb.h>
11650 +#include <linux/kdbprivate.h>
11651 +#include <linux/interrupt.h>
11652 +#include <linux/module.h>
11653 +#include <linux/kdebug.h>
11654 +#include <asm/processor.h>
11655 +#include <asm/msr.h>
11656 +#include <asm/uaccess.h>
11657 +#include <asm/mach_apic.h>
11658 +#include <asm/hw_irq.h>
11659 +#include <asm/desc.h>
11660 +
11661 +kdb_machreg_t
11662 +kdba_getdr6(void)
11663 +{
11664 +       return kdba_getdr(6);
11665 +}
11666 +
11667 +kdb_machreg_t
11668 +kdba_getdr7(void)
11669 +{
11670 +       return kdba_getdr(7);
11671 +}
11672 +
11673 +void
11674 +kdba_putdr6(kdb_machreg_t contents)
11675 +{
11676 +       kdba_putdr(6, contents);
11677 +}
11678 +
11679 +static void
11680 +kdba_putdr7(kdb_machreg_t contents)
11681 +{
11682 +       kdba_putdr(7, contents);
11683 +}
11684 +
11685 +void
11686 +kdba_installdbreg(kdb_bp_t *bp)
11687 +{
11688 +       kdb_machreg_t   dr7;
11689 +
11690 +       dr7 = kdba_getdr7();
11691 +
11692 +       kdba_putdr(bp->bp_hard->bph_reg, bp->bp_addr);
11693 +
11694 +       dr7 |= DR7_GE;
11695 +       if (cpu_has_de)
11696 +               set_in_cr4(X86_CR4_DE);
11697 +
11698 +       switch (bp->bp_hard->bph_reg){
11699 +       case 0:
11700 +               DR7_RW0SET(dr7,bp->bp_hard->bph_mode);
11701 +               DR7_LEN0SET(dr7,bp->bp_hard->bph_length);
11702 +               DR7_G0SET(dr7);
11703 +               break;
11704 +       case 1:
11705 +               DR7_RW1SET(dr7,bp->bp_hard->bph_mode);
11706 +               DR7_LEN1SET(dr7,bp->bp_hard->bph_length);
11707 +               DR7_G1SET(dr7);
11708 +               break;
11709 +       case 2:
11710 +               DR7_RW2SET(dr7,bp->bp_hard->bph_mode);
11711 +               DR7_LEN2SET(dr7,bp->bp_hard->bph_length);
11712 +               DR7_G2SET(dr7);
11713 +               break;
11714 +       case 3:
11715 +               DR7_RW3SET(dr7,bp->bp_hard->bph_mode);
11716 +               DR7_LEN3SET(dr7,bp->bp_hard->bph_length);
11717 +               DR7_G3SET(dr7);
11718 +               break;
11719 +       default:
11720 +               kdb_printf("kdb: Bad debug register!! %ld\n",
11721 +                          bp->bp_hard->bph_reg);
11722 +               break;
11723 +       }
11724 +
11725 +       kdba_putdr7(dr7);
11726 +       return;
11727 +}
11728 +
11729 +void
11730 +kdba_removedbreg(kdb_bp_t *bp)
11731 +{
11732 +       int             regnum;
11733 +       kdb_machreg_t   dr7;
11734 +
11735 +       if (!bp->bp_hard)
11736 +               return;
11737 +
11738 +       regnum = bp->bp_hard->bph_reg;
11739 +
11740 +       dr7 = kdba_getdr7();
11741 +
11742 +       kdba_putdr(regnum, 0);
11743 +
11744 +       switch (regnum) {
11745 +       case 0:
11746 +               DR7_G0CLR(dr7);
11747 +               DR7_L0CLR(dr7);
11748 +               break;
11749 +       case 1:
11750 +               DR7_G1CLR(dr7);
11751 +               DR7_L1CLR(dr7);
11752 +               break;
11753 +       case 2:
11754 +               DR7_G2CLR(dr7);
11755 +               DR7_L2CLR(dr7);
11756 +               break;
11757 +       case 3:
11758 +               DR7_G3CLR(dr7);
11759 +               DR7_L3CLR(dr7);
11760 +               break;
11761 +       default:
11762 +               kdb_printf("kdb: Bad debug register!! %d\n", regnum);
11763 +               break;
11764 +       }
11765 +
11766 +       kdba_putdr7(dr7);
11767 +}
11768 +
11769 +kdb_machreg_t
11770 +kdba_getdr(int regnum)
11771 +{
11772 +       kdb_machreg_t contents = 0;
11773 +       switch(regnum) {
11774 +       case 0:
11775 +               __asm__ ("movq %%db0,%0\n\t":"=r"(contents));
11776 +               break;
11777 +       case 1:
11778 +               __asm__ ("movq %%db1,%0\n\t":"=r"(contents));
11779 +               break;
11780 +       case 2:
11781 +               __asm__ ("movq %%db2,%0\n\t":"=r"(contents));
11782 +               break;
11783 +       case 3:
11784 +               __asm__ ("movq %%db3,%0\n\t":"=r"(contents));
11785 +               break;
11786 +       case 4:
11787 +       case 5:
11788 +               break;
11789 +       case 6:
11790 +               __asm__ ("movq %%db6,%0\n\t":"=r"(contents));
11791 +               break;
11792 +       case 7:
11793 +               __asm__ ("movq %%db7,%0\n\t":"=r"(contents));
11794 +               break;
11795 +       default:
11796 +               break;
11797 +       }
11798 +
11799 +       return contents;
11800 +}
11801 +
11802 +
11803 +kdb_machreg_t
11804 +kdb_getcr(int regnum)
11805 +{
11806 +       kdb_machreg_t contents = 0;
11807 +       switch(regnum) {
11808 +       case 0:
11809 +               __asm__ ("movq %%cr0,%0\n\t":"=r"(contents));
11810 +               break;
11811 +       case 1:
11812 +               break;
11813 +       case 2:
11814 +               __asm__ ("movq %%cr2,%0\n\t":"=r"(contents));
11815 +               break;
11816 +       case 3:
11817 +               __asm__ ("movq %%cr3,%0\n\t":"=r"(contents));
11818 +               break;
11819 +       case 4:
11820 +               __asm__ ("movq %%cr4,%0\n\t":"=r"(contents));
11821 +               break;
11822 +       default:
11823 +               break;
11824 +       }
11825 +
11826 +       return contents;
11827 +}
11828 +
11829 +void
11830 +kdba_putdr(int regnum, kdb_machreg_t contents)
11831 +{
11832 +       switch(regnum) {
11833 +       case 0:
11834 +               __asm__ ("movq %0,%%db0\n\t"::"r"(contents));
11835 +               break;
11836 +       case 1:
11837 +               __asm__ ("movq %0,%%db1\n\t"::"r"(contents));
11838 +               break;
11839 +       case 2:
11840 +               __asm__ ("movq %0,%%db2\n\t"::"r"(contents));
11841 +               break;
11842 +       case 3:
11843 +               __asm__ ("movq %0,%%db3\n\t"::"r"(contents));
11844 +               break;
11845 +       case 4:
11846 +       case 5:
11847 +               break;
11848 +       case 6:
11849 +               __asm__ ("movq %0,%%db6\n\t"::"r"(contents));
11850 +               break;
11851 +       case 7:
11852 +               __asm__ ("movq %0,%%db7\n\t"::"r"(contents));
11853 +               break;
11854 +       default:
11855 +               break;
11856 +       }
11857 +}
11858 +
11859 +/*
11860 + * kdba_getregcontents
11861 + *
11862 + *     Return the contents of the register specified by the
11863 + *     input string argument.   Return an error if the string
11864 + *     does not match a machine register.
11865 + *
11866 + *     The following pseudo register names are supported:
11867 + *        &regs         - Prints address of exception frame
11868 + *        krsp          - Prints kernel stack pointer at time of fault
11869 + *        crsp          - Prints current kernel stack pointer, inside kdb
11870 + *        ceflags       - Prints current flags, inside kdb
11871 + *        %<regname>    - Uses the value of the registers at the
11872 + *                        last time the user process entered kernel
11873 + *                        mode, instead of the registers at the time
11874 + *                        kdb was entered.
11875 + *
11876 + * Parameters:
11877 + *     regname         Pointer to string naming register
11878 + *     regs            Pointer to structure containing registers.
11879 + * Outputs:
11880 + *     *contents       Pointer to unsigned long to recieve register contents
11881 + * Returns:
11882 + *     0               Success
11883 + *     KDB_BADREG      Invalid register name
11884 + * Locking:
11885 + *     None.
11886 + * Remarks:
11887 + *     If kdb was entered via an interrupt from the kernel itself then
11888 + *     ss and rsp are *not* on the stack.
11889 + */
11890 +
11891 +static struct kdbregs {
11892 +       char   *reg_name;
11893 +       size_t  reg_offset;
11894 +} kdbreglist[] = {
11895 +       { "r15",        offsetof(struct pt_regs, r15) },
11896 +       { "r14",        offsetof(struct pt_regs, r14) },
11897 +       { "r13",        offsetof(struct pt_regs, r13) },
11898 +       { "r12",        offsetof(struct pt_regs, r12) },
11899 +       { "rbp",        offsetof(struct pt_regs, rbp) },
11900 +       { "rbx",        offsetof(struct pt_regs, rbx) },
11901 +       { "r11",        offsetof(struct pt_regs, r11) },
11902 +       { "r10",        offsetof(struct pt_regs, r10) },
11903 +       { "r9",         offsetof(struct pt_regs, r9) },
11904 +       { "r8",         offsetof(struct pt_regs, r8) },
11905 +       { "rax",        offsetof(struct pt_regs, rax) },
11906 +       { "rcx",        offsetof(struct pt_regs, rcx) },
11907 +       { "rdx",        offsetof(struct pt_regs, rdx) },
11908 +       { "rsi",        offsetof(struct pt_regs, rsi) },
11909 +       { "rdi",        offsetof(struct pt_regs, rdi) },
11910 +       { "orig_rax",   offsetof(struct pt_regs, orig_rax) },
11911 +       { "rip",        offsetof(struct pt_regs, rip) },
11912 +       { "cs",         offsetof(struct pt_regs, cs) },
11913 +       { "eflags",     offsetof(struct pt_regs, eflags) },
11914 +       { "rsp",        offsetof(struct pt_regs, rsp) },
11915 +       { "ss",         offsetof(struct pt_regs, ss) },
11916 +};
11917 +
11918 +static const int nkdbreglist = sizeof(kdbreglist) / sizeof(struct kdbregs);
11919 +
11920 +static struct kdbregs dbreglist[] = {
11921 +       { "dr0",        0 },
11922 +       { "dr1",        1 },
11923 +       { "dr2",        2 },
11924 +       { "dr3",        3 },
11925 +       { "dr6",        6 },
11926 +       { "dr7",        7 },
11927 +};
11928 +
11929 +static const int ndbreglist = sizeof(dbreglist) / sizeof(struct kdbregs);
11930 +
11931 +int
11932 +kdba_getregcontents(const char *regname,
11933 +                   struct pt_regs *regs,
11934 +                   kdb_machreg_t *contents)
11935 +{
11936 +       int i;
11937 +
11938 +       if (strcmp(regname, "&regs") == 0) {
11939 +               *contents = (unsigned long)regs;
11940 +               return 0;
11941 +       }
11942 +
11943 +       if (strcmp(regname, "krsp") == 0) {
11944 +               *contents = (unsigned long)regs + sizeof(struct pt_regs);
11945 +               if ((regs->cs & 0xffff) == __KERNEL_CS) {
11946 +                       /* rsp and ss are not on stack */
11947 +                       *contents -= 2*4;
11948 +               }
11949 +               return 0;
11950 +       }
11951 +
11952 +       if (strcmp(regname, "crsp") == 0) {
11953 +               asm volatile("movq %%rsp,%0":"=m" (*contents));
11954 +               return 0;
11955 +       }
11956 +
11957 +       if (strcmp(regname, "ceflags") == 0) {
11958 +               unsigned long flags;
11959 +               local_save_flags(flags);
11960 +               *contents = flags;
11961 +               return 0;
11962 +       }
11963 +
11964 +       if (regname[0] == '%') {
11965 +               /* User registers:  %%r[a-c]x, etc */
11966 +               regname++;
11967 +               regs = (struct pt_regs *)
11968 +                       (current->thread.rsp0 - sizeof(struct pt_regs));
11969 +       }
11970 +
11971 +       for (i=0; i<nkdbreglist; i++) {
11972 +               if (strnicmp(kdbreglist[i].reg_name,
11973 +                            regname,
11974 +                            strlen(regname)) == 0)
11975 +                       break;
11976 +       }
11977 +
11978 +       if ((i < nkdbreglist)
11979 +        && (strlen(kdbreglist[i].reg_name) == strlen(regname))) {
11980 +               if ((regs->cs & 0xffff) == __KERNEL_CS) {
11981 +                       /* No cpl switch, rsp is not on stack */
11982 +                       if (strcmp(kdbreglist[i].reg_name, "rsp") == 0) {
11983 +                               *contents = (kdb_machreg_t)regs +
11984 +                                       sizeof(struct pt_regs) - 2*8;
11985 +                               return(0);
11986 +                       }
11987 +#if 0  /* FIXME */
11988 +                       if (strcmp(kdbreglist[i].reg_name, "ss") == 0) {
11989 +                               kdb_machreg_t r;
11990 +
11991 +                               r = (kdb_machreg_t)regs +
11992 +                                       sizeof(struct pt_regs) - 2*8;
11993 +                               *contents = (kdb_machreg_t)SS(r);       /* XXX */
11994 +                               return(0);
11995 +                       }
11996 +#endif
11997 +               }
11998 +               *contents = *(unsigned long *)((unsigned long)regs +
11999 +                               kdbreglist[i].reg_offset);
12000 +               return(0);
12001 +       }
12002 +
12003 +       for (i=0; i<ndbreglist; i++) {
12004 +               if (strnicmp(dbreglist[i].reg_name,
12005 +                            regname,
12006 +                            strlen(regname)) == 0)
12007 +                       break;
12008 +       }
12009 +
12010 +       if ((i < ndbreglist)
12011 +        && (strlen(dbreglist[i].reg_name) == strlen(regname))) {
12012 +               *contents = kdba_getdr(dbreglist[i].reg_offset);
12013 +               return 0;
12014 +       }
12015 +       return KDB_BADREG;
12016 +}
12017 +
12018 +/*
12019 + * kdba_setregcontents
12020 + *
12021 + *     Set the contents of the register specified by the
12022 + *     input string argument.   Return an error if the string
12023 + *     does not match a machine register.
12024 + *
12025 + *     Supports modification of user-mode registers via
12026 + *     %<register-name>
12027 + *
12028 + * Parameters:
12029 + *     regname         Pointer to string naming register
12030 + *     regs            Pointer to structure containing registers.
12031 + *     contents        Unsigned long containing new register contents
12032 + * Outputs:
12033 + * Returns:
12034 + *     0               Success
12035 + *     KDB_BADREG      Invalid register name
12036 + * Locking:
12037 + *     None.
12038 + * Remarks:
12039 + */
12040 +
12041 +int
12042 +kdba_setregcontents(const char *regname,
12043 +                 struct pt_regs *regs,
12044 +                 unsigned long contents)
12045 +{
12046 +       int i;
12047 +
12048 +       if (regname[0] == '%') {
12049 +               regname++;
12050 +               regs = (struct pt_regs *)
12051 +                       (current->thread.rsp0 - sizeof(struct pt_regs));
12052 +       }
12053 +
12054 +       for (i=0; i<nkdbreglist; i++) {
12055 +               if (strnicmp(kdbreglist[i].reg_name,
12056 +                            regname,
12057 +                            strlen(regname)) == 0)
12058 +                       break;
12059 +       }
12060 +
12061 +       if ((i < nkdbreglist)
12062 +        && (strlen(kdbreglist[i].reg_name) == strlen(regname))) {
12063 +               *(unsigned long *)((unsigned long)regs
12064 +                                  + kdbreglist[i].reg_offset) = contents;
12065 +               return 0;
12066 +       }
12067 +
12068 +       for (i=0; i<ndbreglist; i++) {
12069 +               if (strnicmp(dbreglist[i].reg_name,
12070 +                            regname,
12071 +                            strlen(regname)) == 0)
12072 +                       break;
12073 +       }
12074 +
12075 +       if ((i < ndbreglist)
12076 +        && (strlen(dbreglist[i].reg_name) == strlen(regname))) {
12077 +               kdba_putdr(dbreglist[i].reg_offset, contents);
12078 +               return 0;
12079 +       }
12080 +
12081 +       return KDB_BADREG;
12082 +}
12083 +
12084 +/*
12085 + * kdba_dumpregs
12086 + *
12087 + *     Dump the specified register set to the display.
12088 + *
12089 + * Parameters:
12090 + *     regs            Pointer to structure containing registers.
12091 + *     type            Character string identifying register set to dump
12092 + *     extra           string further identifying register (optional)
12093 + * Outputs:
12094 + * Returns:
12095 + *     0               Success
12096 + * Locking:
12097 + *     None.
12098 + * Remarks:
12099 + *     This function will dump the general register set if the type
12100 + *     argument is NULL (struct pt_regs).   The alternate register
12101 + *     set types supported by this function:
12102 + *
12103 + *     d               Debug registers
12104 + *     c               Control registers
12105 + *     u               User registers at most recent entry to kernel
12106 + * Following not yet implemented:
12107 + *     r               Memory Type Range Registers (extra defines register)
12108 + *
12109 + * MSR on i386/x86_64 are handled by rdmsr/wrmsr commands.
12110 + */
12111 +
12112 +int
12113 +kdba_dumpregs(struct pt_regs *regs,
12114 +           const char *type,
12115 +           const char *extra)
12116 +{
12117 +       int i;
12118 +       int count = 0;
12119 +
12120 +       if (type
12121 +        && (type[0] == 'u')) {
12122 +               type = NULL;
12123 +               regs = (struct pt_regs *)
12124 +                       (current->thread.rsp0 - sizeof(struct pt_regs));
12125 +       }
12126 +
12127 +       if (type == NULL) {
12128 +               struct kdbregs *rlp;
12129 +               kdb_machreg_t contents;
12130 +
12131 +               for (i=0, rlp=kdbreglist; i<nkdbreglist; i++,rlp++) {
12132 +                       kdb_printf("%8s = ", rlp->reg_name);
12133 +                       kdba_getregcontents(rlp->reg_name, regs, &contents);
12134 +                       kdb_printf("0x%016lx ", contents);
12135 +                       if ((++count % 2) == 0)
12136 +                               kdb_printf("\n");
12137 +               }
12138 +
12139 +               kdb_printf("&regs = 0x%p\n", regs);
12140 +
12141 +               return 0;
12142 +       }
12143 +
12144 +       switch (type[0]) {
12145 +       case 'd':
12146 +       {
12147 +               unsigned long dr[8];
12148 +
12149 +               for(i=0; i<8; i++) {
12150 +                       if ((i == 4) || (i == 5)) continue;
12151 +                       dr[i] = kdba_getdr(i);
12152 +               }
12153 +               kdb_printf("dr0 = 0x%08lx  dr1 = 0x%08lx  dr2 = 0x%08lx  dr3 = 0x%08lx\n",
12154 +                          dr[0], dr[1], dr[2], dr[3]);
12155 +               kdb_printf("dr6 = 0x%08lx  dr7 = 0x%08lx\n",
12156 +                          dr[6], dr[7]);
12157 +               return 0;
12158 +       }
12159 +       case 'c':
12160 +       {
12161 +               unsigned long cr[5];
12162 +
12163 +               for (i=0; i<5; i++) {
12164 +                       cr[i] = kdb_getcr(i);
12165 +               }
12166 +               kdb_printf("cr0 = 0x%08lx  cr1 = 0x%08lx  cr2 = 0x%08lx  cr3 = 0x%08lx\ncr4 = 0x%08lx\n",
12167 +                          cr[0], cr[1], cr[2], cr[3], cr[4]);
12168 +               return 0;
12169 +       }
12170 +       case 'r':
12171 +               break;
12172 +       default:
12173 +               return KDB_BADREG;
12174 +       }
12175 +
12176 +       /* NOTREACHED */
12177 +       return 0;
12178 +}
12179 +EXPORT_SYMBOL(kdba_dumpregs);
12180 +
12181 +kdb_machreg_t
12182 +kdba_getpc(struct pt_regs *regs)
12183 +{
12184 +       return regs->rip;
12185 +}
12186 +
12187 +int
12188 +kdba_setpc(struct pt_regs *regs, kdb_machreg_t newpc)
12189 +{
12190 +       if (KDB_NULL_REGS(regs))
12191 +               return KDB_BADREG;
12192 +       regs->rip = newpc;
12193 +       KDB_STATE_SET(IP_ADJUSTED);
12194 +       return 0;
12195 +}
12196 +
12197 +/*
12198 + * kdba_main_loop
12199 + *
12200 + *     Do any architecture specific set up before entering the main kdb loop.
12201 + *     The primary function of this routine is to make all processes look the
12202 + *     same to kdb, kdb must be able to list a process without worrying if the
12203 + *     process is running or blocked, so make all process look as though they
12204 + *     are blocked.
12205 + *
12206 + * Inputs:
12207 + *     reason          The reason KDB was invoked
12208 + *     error           The hardware-defined error code
12209 + *     error2          kdb's current reason code.  Initially error but can change
12210 + *                     acording to kdb state.
12211 + *     db_result       Result from break or debug point.
12212 + *     ef              The exception frame at time of fault/breakpoint.  If reason
12213 + *                     is SILENT or CPU_UP then regs is NULL, otherwise it should
12214 + *                     always be valid.
12215 + * Returns:
12216 + *     0       KDB was invoked for an event which it wasn't responsible
12217 + *     1       KDB handled the event for which it was invoked.
12218 + * Outputs:
12219 + *     Sets rip and rsp in current->thread.
12220 + * Locking:
12221 + *     None.
12222 + * Remarks:
12223 + *     none.
12224 + */
12225 +
12226 +int
12227 +kdba_main_loop(kdb_reason_t reason, kdb_reason_t reason2, int error,
12228 +              kdb_dbtrap_t db_result, struct pt_regs *regs)
12229 +{
12230 +       int ret;
12231 +
12232 +       if (regs)
12233 +               kdba_getregcontents("rsp", regs, &(current->thread.rsp));
12234 +       kdb_save_running(regs);
12235 +       ret = kdb_main_loop(reason, reason2, error, db_result, regs);
12236 +       kdb_unsave_running(regs);
12237 +       return ret;
12238 +}
12239 +
12240 +void
12241 +kdba_disableint(kdb_intstate_t *state)
12242 +{
12243 +       unsigned long *fp = (unsigned long *)state;
12244 +       unsigned long flags;
12245 +
12246 +       local_irq_save(flags);
12247 +       *fp = flags;
12248 +}
12249 +
12250 +void
12251 +kdba_restoreint(kdb_intstate_t *state)
12252 +{
12253 +       unsigned long flags = *(unsigned long *)state;
12254 +       local_irq_restore(flags);
12255 +}
12256 +
12257 +void
12258 +kdba_setsinglestep(struct pt_regs *regs)
12259 +{
12260 +       if (KDB_NULL_REGS(regs))
12261 +               return;
12262 +       if (regs->eflags & EF_IE)
12263 +               KDB_STATE_SET(A_IF);
12264 +       else
12265 +               KDB_STATE_CLEAR(A_IF);
12266 +       regs->eflags = (regs->eflags | EF_TF) & ~EF_IE;
12267 +}
12268 +
12269 +void
12270 +kdba_clearsinglestep(struct pt_regs *regs)
12271 +{
12272 +       if (KDB_NULL_REGS(regs))
12273 +               return;
12274 +       if (KDB_STATE(A_IF))
12275 +               regs->eflags |= EF_IE;
12276 +       else
12277 +               regs->eflags &= ~EF_IE;
12278 +}
12279 +
12280 +int asmlinkage
12281 +kdba_setjmp(kdb_jmp_buf *jb)
12282 +{
12283 +#ifdef CONFIG_FRAME_POINTER
12284 +       __asm__ __volatile__
12285 +               ("movq %%rbx, (0*8)(%%rdi);"
12286 +               "movq %%rcx, (1*8)(%%rdi);"
12287 +               "movq %%r12, (2*8)(%%rdi);"
12288 +               "movq %%r13, (3*8)(%%rdi);"
12289 +               "movq %%r14, (4*8)(%%rdi);"
12290 +               "movq %%r15, (5*8)(%%rdi);"
12291 +               "leaq 16(%%rsp), %%rdx;"
12292 +               "movq %%rdx, (6*8)(%%rdi);"
12293 +               "movq %%rax, (7*8)(%%rdi)"
12294 +               :
12295 +               : "a" (__builtin_return_address(0)),
12296 +                 "c" (__builtin_frame_address(1))
12297 +               );
12298 +#else   /* !CONFIG_FRAME_POINTER */
12299 +       __asm__ __volatile__
12300 +               ("movq %%rbx, (0*8)(%%rdi);"
12301 +               "movq %%rbp, (1*8)(%%rdi);"
12302 +               "movq %%r12, (2*8)(%%rdi);"
12303 +               "movq %%r13, (3*8)(%%rdi);"
12304 +               "movq %%r14, (4*8)(%%rdi);"
12305 +               "movq %%r15, (5*8)(%%rdi);"
12306 +               "leaq 8(%%rsp), %%rdx;"
12307 +               "movq %%rdx, (6*8)(%%rdi);"
12308 +               "movq %%rax, (7*8)(%%rdi)"
12309 +               :
12310 +               : "a" (__builtin_return_address(0))
12311 +               );
12312 +#endif   /* CONFIG_FRAME_POINTER */
12313 +       return 0;
12314 +}
12315 +
12316 +void asmlinkage
12317 +kdba_longjmp(kdb_jmp_buf *jb, int reason)
12318 +{
12319 +       __asm__("movq (0*8)(%rdi),%rbx;"
12320 +               "movq (1*8)(%rdi),%rbp;"
12321 +               "movq (2*8)(%rdi),%r12;"
12322 +               "movq (3*8)(%rdi),%r13;"
12323 +               "movq (4*8)(%rdi),%r14;"
12324 +               "movq (5*8)(%rdi),%r15;"
12325 +               "movq (7*8)(%rdi),%rdx;"
12326 +               "movq (6*8)(%rdi),%rsp;"
12327 +               "mov %rsi, %rax;"
12328 +               "jmpq *%rdx");
12329 +}
12330 +
12331 +/*
12332 + * kdba_pt_regs
12333 + *
12334 + *     Format a struct pt_regs
12335 + *
12336 + * Inputs:
12337 + *     argc    argument count
12338 + *     argv    argument vector
12339 + * Outputs:
12340 + *     None.
12341 + * Returns:
12342 + *     zero for success, a kdb diagnostic if error
12343 + * Locking:
12344 + *     none.
12345 + * Remarks:
12346 + *     If no address is supplied, it uses the current irq pt_regs.
12347 + */
12348 +
12349 +static int
12350 +kdba_pt_regs(int argc, const char **argv)
12351 +{
12352 +       int diag;
12353 +       kdb_machreg_t addr;
12354 +       long offset = 0;
12355 +       int nextarg;
12356 +       struct pt_regs *p;
12357 +       static const char *fmt = "  %-11.11s 0x%lx\n";
12358 +       static int first_time = 1;
12359 +
12360 +       if (argc == 0) {
12361 +               addr = (kdb_machreg_t) get_irq_regs();
12362 +       } else if (argc == 1) {
12363 +               nextarg = 1;
12364 +               diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL);
12365 +               if (diag)
12366 +                       return diag;
12367 +       } else {
12368 +               return KDB_ARGCOUNT;
12369 +       }
12370 +
12371 +       p = (struct pt_regs *) addr;
12372 +       if (first_time) {
12373 +               first_time = 0;
12374 +               kdb_printf("\n+++ Warning: x86_64 pt_regs are not always "
12375 +                          "completely defined, r15-rbx may be invalid\n\n");
12376 +       }
12377 +       kdb_printf("struct pt_regs 0x%p-0x%p\n", p, (unsigned char *)p + sizeof(*p) - 1);
12378 +       kdb_print_nameval("r15", p->r15);
12379 +       kdb_print_nameval("r14", p->r14);
12380 +       kdb_print_nameval("r13", p->r13);
12381 +       kdb_print_nameval("r12", p->r12);
12382 +       kdb_print_nameval("rbp", p->rbp);
12383 +       kdb_print_nameval("rbx", p->rbx);
12384 +       kdb_print_nameval("r11", p->r11);
12385 +       kdb_print_nameval("r10", p->r10);
12386 +       kdb_print_nameval("r9", p->r9);
12387 +       kdb_print_nameval("r8", p->r8);
12388 +       kdb_print_nameval("rax", p->rax);
12389 +       kdb_print_nameval("rcx", p->rcx);
12390 +       kdb_print_nameval("rdx", p->rdx);
12391 +       kdb_print_nameval("rsi", p->rsi);
12392 +       kdb_print_nameval("rdi", p->rdi);
12393 +       kdb_print_nameval("orig_rax", p->orig_rax);
12394 +       kdb_print_nameval("rip", p->rip);
12395 +       kdb_printf(fmt, "cs", p->cs);
12396 +       kdb_printf(fmt, "eflags", p->eflags);
12397 +       kdb_printf(fmt, "rsp", p->rsp);
12398 +       kdb_printf(fmt, "ss", p->ss);
12399 +       return 0;
12400 +}
12401 +
12402 +/*
12403 + * kdba_cpu_pda
12404 + *
12405 + *     Format a struct cpu_pda
12406 + *
12407 + * Inputs:
12408 + *     argc    argument count
12409 + *     argv    argument vector
12410 + * Outputs:
12411 + *     None.
12412 + * Returns:
12413 + *     zero for success, a kdb diagnostic if error
12414 + * Locking:
12415 + *     none.
12416 + * Remarks:
12417 + *     If no cpu is supplied, it prints the current cpu.  If the cpu is '*'
12418 + *     then it prints all cpus.
12419 + */
12420 +
12421 +static int
12422 +kdba_cpu_pda(int argc, const char **argv)
12423 +{
12424 +       int diag, nextarg, all_cpus = 0;
12425 +       long offset = 0;
12426 +       unsigned long cpu;
12427 +       struct x8664_pda *c;
12428 +       static const char *fmtl = "  %-17.17s 0x%lx\n";
12429 +       static const char *fmtd = "  %-17.17s %d\n";
12430 +       static const char *fmtp = "  %-17.17s 0x%p\n";
12431 +
12432 +       if (argc == 0) {
12433 +               cpu = smp_processor_id();
12434 +       } else if (argc == 1) {
12435 +               if (strcmp(argv[1], "*") == 0) {
12436 +                       all_cpus = 1;
12437 +                       cpu = 0;
12438 +               } else {
12439 +                       nextarg = 1;
12440 +                       diag = kdbgetaddrarg(argc, argv, &nextarg, &cpu, &offset, NULL);
12441 +                       if (diag)
12442 +                               return diag;
12443 +               }
12444 +       } else {
12445 +               return KDB_ARGCOUNT;
12446 +       }
12447 +
12448 +       for (; cpu < NR_CPUS; ++cpu) {
12449 +               if (cpu_online(cpu)) {
12450 +                       c = cpu_pda(cpu);
12451 +                       kdb_printf("struct cpu_pda 0x%p-0x%p\n", c, (unsigned char *)c + sizeof(*c) - 1);
12452 +                       kdb_printf(fmtp, "pcurrent", c->pcurrent);
12453 +                       kdb_printf(fmtl, "data_offset", c->data_offset);
12454 +                       kdb_printf(fmtl, "kernelstack", c->kernelstack);
12455 +                       kdb_printf(fmtl, "oldrsp", c->oldrsp);
12456 +                       kdb_printf(fmtd, "irqcount", c->irqcount);
12457 +                       kdb_printf(fmtd, "cpunumber", c->cpunumber);
12458 +                       kdb_printf(fmtp, "irqstackptr", c->irqstackptr);
12459 +                       kdb_printf(fmtd, "nodenumber", c->nodenumber);
12460 +                       kdb_printf(fmtd, "__softirq_pending", c->__softirq_pending);
12461 +                       kdb_printf(fmtd, "__nmi_count", c->__nmi_count);
12462 +                       kdb_printf(fmtd, "mmu_state", c->mmu_state);
12463 +                       kdb_printf(fmtp, "active_mm", c->active_mm);
12464 +                       kdb_printf(fmtd, "apic_timer_irqs", c->apic_timer_irqs);
12465 +               }
12466 +               if (!all_cpus)
12467 +                       break;
12468 +       }
12469 +       return 0;
12470 +}
12471 +
12472 +/*
12473 + * kdba_entry
12474 + *
12475 + *     This is the interface routine between
12476 + *     the notifier die_chain and kdb
12477 + */
12478 +static int kdba_entry( struct notifier_block *b, unsigned long val, void *v)
12479 +{
12480 +       struct die_args *args = v;
12481 +       int err, trap, ret = 0;
12482 +       struct pt_regs *regs;
12483 +
12484 +       regs = args->regs;
12485 +       err  = args->err;
12486 +       trap  = args->trapnr;
12487 +       switch (val){
12488 +#ifdef CONFIG_SMP
12489 +               case DIE_NMI_IPI:
12490 +                       ret = kdb_ipi(regs, NULL);
12491 +                       break;
12492 +#endif /* CONFIG_SMP */
12493 +               case DIE_OOPS:
12494 +                       ret = kdb(KDB_REASON_OOPS, err, regs);
12495 +                       break;
12496 +               case DIE_CALL:
12497 +                       ret = kdb(KDB_REASON_ENTER, err, regs);
12498 +                       break;
12499 +               case DIE_DEBUG:
12500 +                       ret = kdb(KDB_REASON_DEBUG, err, regs);
12501 +                       break;
12502 +               case DIE_NMIWATCHDOG:
12503 +                       ret = kdb(KDB_REASON_NMI, err, regs);
12504 +                       break;
12505 +               case DIE_INT3:
12506 +                        ret = kdb(KDB_REASON_BREAK, err, regs);
12507 +                       // falls thru
12508 +               default:
12509 +                       break;
12510 +       }
12511 +       return (ret ? NOTIFY_STOP : NOTIFY_DONE);
12512 +}
12513 +
12514 +/*
12515 + * notifier block for kdb entry
12516 + */
12517 +static struct notifier_block kdba_notifier = {
12518 +       .notifier_call = kdba_entry
12519 +};
12520 +
12521 +asmlinkage int kdb_call(void);
12522 +
12523 +/* Executed once on each cpu at startup. */
12524 +void
12525 +kdba_cpu_up(void)
12526 +{
12527 +}
12528 +
12529 +static int __init
12530 +kdba_arch_init(void)
12531 +{
12532 +#ifdef CONFIG_SMP
12533 +       set_intr_gate(KDB_VECTOR, kdb_interrupt);
12534 +#endif
12535 +       set_intr_gate(KDBENTER_VECTOR, kdb_call);
12536 +       return 0;
12537 +}
12538 +
12539 +arch_initcall(kdba_arch_init);
12540 +
12541 +/*
12542 + * kdba_init
12543 + *
12544 + *     Architecture specific initialization.
12545 + *
12546 + * Parameters:
12547 + *     None.
12548 + * Returns:
12549 + *     None.
12550 + * Locking:
12551 + *     None.
12552 + * Remarks:
12553 + *     None.
12554 + */
12555 +
12556 +void __init
12557 +kdba_init(void)
12558 +{
12559 +       kdba_arch_init();       /* Need to register KDBENTER_VECTOR early */
12560 +       kdb_register("pt_regs", kdba_pt_regs, "address", "Format struct pt_regs", 0);
12561 +       kdb_register("cpu_pda", kdba_cpu_pda, "<cpu>", "Format struct cpu_pda", 0);
12562 +       register_die_notifier(&kdba_notifier);
12563 +       return;
12564 +}
12565 +
12566 +/*
12567 + * kdba_adjust_ip
12568 + *
12569 + *     Architecture specific adjustment of instruction pointer before leaving
12570 + *     kdb.
12571 + *
12572 + * Parameters:
12573 + *     reason          The reason KDB was invoked
12574 + *     error           The hardware-defined error code
12575 + *     ef              The exception frame at time of fault/breakpoint.  If reason
12576 + *                     is SILENT or CPU_UP then regs is NULL, otherwise it should
12577 + *                     always be valid.
12578 + * Returns:
12579 + *     None.
12580 + * Locking:
12581 + *     None.
12582 + * Remarks:
12583 + *     noop on ix86.
12584 + */
12585 +
12586 +void
12587 +kdba_adjust_ip(kdb_reason_t reason, int error, struct pt_regs *ef)
12588 +{
12589 +       return;
12590 +}
12591 +
12592 +void
12593 +kdba_set_current_task(const struct task_struct *p)
12594 +{
12595 +       kdb_current_task = p;
12596 +       if (kdb_task_has_cpu(p)) {
12597 +               struct kdb_running_process *krp = kdb_running_process + kdb_process_cpu(p);
12598 +               kdb_current_regs = krp->regs;
12599 +               return;
12600 +       }
12601 +       kdb_current_regs = NULL;
12602 +}
12603 +
12604 +#ifdef CONFIG_SMP
12605 +
12606 +/* When first entering KDB, try a normal IPI.  That reduces backtrace problems
12607 + * on the other cpus.
12608 + */
12609 +void
12610 +smp_kdb_stop(void)
12611 +{
12612 +       if (!KDB_FLAG(NOIPI))
12613 +               send_IPI_allbutself(KDB_VECTOR);
12614 +}
12615 +
12616 +/* The normal KDB IPI handler */
12617 +extern asmlinkage void smp_kdb_interrupt(struct pt_regs *regs);        /* for sparse */
12618 +asmlinkage void
12619 +smp_kdb_interrupt(struct pt_regs *regs)
12620 +{
12621 +       struct pt_regs *old_regs = set_irq_regs(regs);
12622 +       ack_APIC_irq();
12623 +       irq_enter();
12624 +       kdb_ipi(regs, NULL);
12625 +       irq_exit();
12626 +       set_irq_regs(old_regs);
12627 +}
12628 +
12629 +/* Invoked once from kdb_wait_for_cpus when waiting for cpus.  For those cpus
12630 + * that have not responded to the normal KDB interrupt yet, hit them with an
12631 + * NMI event.
12632 + */
12633 +void
12634 +kdba_wait_for_cpus(void)
12635 +{
12636 +       int c;
12637 +       if (KDB_FLAG(CATASTROPHIC))
12638 +               return;
12639 +       kdb_printf("  Sending NMI to cpus that have not responded yet\n");
12640 +       for_each_online_cpu(c)
12641 +               if (kdb_running_process[c].seqno < kdb_seqno - 1)
12642 +                       send_IPI_mask(cpumask_of_cpu(c), NMI_VECTOR);
12643 +}
12644 +
12645 +#endif /* CONFIG_SMP */
12646 diff -Nurp linux-2.6.22-590/arch/x86_64/kdb/kdb_cmds linux-2.6.22-600/arch/x86_64/kdb/kdb_cmds
12647 --- linux-2.6.22-590/arch/x86_64/kdb/kdb_cmds   1970-01-01 01:00:00.000000000 +0100
12648 +++ linux-2.6.22-600/arch/x86_64/kdb/kdb_cmds   2008-04-09 18:16:24.000000000 +0200
12649 @@ -0,0 +1,18 @@
12650 +# Standard architecture specific commands for kdb.
12651 +# These commands are appended to those in kdb/kdb_cmds, see that file for
12652 +# restrictions.
12653 +
12654 +# Standard debugging information for first level support, invoked from archkdb*
12655 +# commands that are defined in kdb/kdb_cmds.
12656 +
12657 +defcmd archkdbcommon "" "Common arch debugging"
12658 +  set LINES 2000000
12659 +  set BTAPROMPT 0
12660 +  -summary
12661 +  -id %rip-24
12662 +  -cpu
12663 +  -ps
12664 +  -dmesg 600
12665 +  -bt
12666 +  -cpu_pda *
12667 +endefcmd
12668 diff -Nurp linux-2.6.22-590/arch/x86_64/kdb/Makefile linux-2.6.22-600/arch/x86_64/kdb/Makefile
12669 --- linux-2.6.22-590/arch/x86_64/kdb/Makefile   1970-01-01 01:00:00.000000000 +0100
12670 +++ linux-2.6.22-600/arch/x86_64/kdb/Makefile   2008-04-09 18:16:24.000000000 +0200
12671 @@ -0,0 +1,13 @@
12672 +#
12673 +# This file is subject to the terms and conditions of the GNU General Public
12674 +# License.  See the file "COPYING" in the main directory of this archive
12675 +# for more details.
12676 +#
12677 +# Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
12678 +#
12679 +
12680 +obj-$(CONFIG_KDB)      := kdba_bp.o kdba_id.o kdba_io.o kdbasupport.o x86_64-dis.o
12681 +
12682 +override CFLAGS := $(CFLAGS:%-pg=% )
12683 +
12684 +CFLAGS_kdba_io.o += -I $(TOPDIR)/arch/$(ARCH)/kdb
12685 diff -Nurp linux-2.6.22-590/arch/x86_64/kdb/pc_keyb.h linux-2.6.22-600/arch/x86_64/kdb/pc_keyb.h
12686 --- linux-2.6.22-590/arch/x86_64/kdb/pc_keyb.h  1970-01-01 01:00:00.000000000 +0100
12687 +++ linux-2.6.22-600/arch/x86_64/kdb/pc_keyb.h  2008-04-09 18:16:24.000000000 +0200
12688 @@ -0,0 +1,137 @@
12689 +/*
12690 + *     include/linux/pc_keyb.h
12691 + *
12692 + *     PC Keyboard And Keyboard Controller
12693 + *
12694 + *     (c) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
12695 + */
12696 +
12697 +/*
12698 + *     Configuration Switches
12699 + */
12700 +
12701 +#undef KBD_REPORT_ERR                  /* Report keyboard errors */
12702 +#define        KBD_REPORT_UNKN                 /* Report unknown scan codes */
12703 +#define        KBD_REPORT_TIMEOUTS             /* Report keyboard timeouts */
12704 +#undef KBD_IS_FOCUS_9000               /* We have the brain-damaged FOCUS-9000 keyboard */
12705 +#undef INITIALIZE_MOUSE                /* Define if your PS/2 mouse needs initialization. */
12706 +
12707 +
12708 +
12709 +#define KBD_INIT_TIMEOUT 1000          /* Timeout in ms for initializing the keyboard */
12710 +#define KBC_TIMEOUT 250                        /* Timeout in ms for sending to keyboard controller */
12711 +#define KBD_TIMEOUT 1000               /* Timeout in ms for keyboard command acknowledge */
12712 +
12713 +/*
12714 + *     Internal variables of the driver
12715 + */
12716 +
12717 +extern unsigned char pckbd_read_mask;
12718 +extern unsigned char aux_device_present;
12719 +
12720 +/*
12721 + *     Keyboard Controller Registers on normal PCs.
12722 + */
12723 +
12724 +#define KBD_STATUS_REG         0x64    /* Status register (R) */
12725 +#define KBD_CNTL_REG           0x64    /* Controller command register (W) */
12726 +#define KBD_DATA_REG           0x60    /* Keyboard data register (R/W) */
12727 +
12728 +/*
12729 + *     Keyboard Controller Commands
12730 + */
12731 +
12732 +#define KBD_CCMD_READ_MODE     0x20    /* Read mode bits */
12733 +#define KBD_CCMD_WRITE_MODE    0x60    /* Write mode bits */
12734 +#define KBD_CCMD_GET_VERSION   0xA1    /* Get controller version */
12735 +#define KBD_CCMD_MOUSE_DISABLE 0xA7    /* Disable mouse interface */
12736 +#define KBD_CCMD_MOUSE_ENABLE  0xA8    /* Enable mouse interface */
12737 +#define KBD_CCMD_TEST_MOUSE    0xA9    /* Mouse interface test */
12738 +#define KBD_CCMD_SELF_TEST     0xAA    /* Controller self test */
12739 +#define KBD_CCMD_KBD_TEST      0xAB    /* Keyboard interface test */
12740 +#define KBD_CCMD_KBD_DISABLE   0xAD    /* Keyboard interface disable */
12741 +#define KBD_CCMD_KBD_ENABLE    0xAE    /* Keyboard interface enable */
12742 +#define KBD_CCMD_WRITE_AUX_OBUF        0xD3    /* Write to output buffer as if
12743 +                                          initiated by the auxiliary device */
12744 +#define KBD_CCMD_WRITE_MOUSE   0xD4    /* Write the following byte to the mouse */
12745 +
12746 +/*
12747 + *     Keyboard Commands
12748 + */
12749 +
12750 +#define KBD_CMD_SET_LEDS       0xED    /* Set keyboard leds */
12751 +#define KBD_CMD_SET_RATE       0xF3    /* Set typematic rate */
12752 +#define KBD_CMD_ENABLE         0xF4    /* Enable scanning */
12753 +#define KBD_CMD_DISABLE                0xF5    /* Disable scanning */
12754 +#define KBD_CMD_RESET          0xFF    /* Reset */
12755 +
12756 +/*
12757 + *     Keyboard Replies
12758 + */
12759 +
12760 +#define KBD_REPLY_POR          0xAA    /* Power on reset */
12761 +#define KBD_REPLY_ACK          0xFA    /* Command ACK */
12762 +#define KBD_REPLY_RESEND       0xFE    /* Command NACK, send the cmd again */
12763 +
12764 +/*
12765 + *     Status Register Bits
12766 + */
12767 +
12768 +#define KBD_STAT_OBF           0x01    /* Keyboard output buffer full */
12769 +#define KBD_STAT_IBF           0x02    /* Keyboard input buffer full */
12770 +#define KBD_STAT_SELFTEST      0x04    /* Self test successful */
12771 +#define KBD_STAT_CMD           0x08    /* Last write was a command write (0=data) */
12772 +#define KBD_STAT_UNLOCKED      0x10    /* Zero if keyboard locked */
12773 +#define KBD_STAT_MOUSE_OBF     0x20    /* Mouse output buffer full */
12774 +#define KBD_STAT_GTO           0x40    /* General receive/xmit timeout */
12775 +#define KBD_STAT_PERR          0x80    /* Parity error */
12776 +
12777 +#define AUX_STAT_OBF (KBD_STAT_OBF | KBD_STAT_MOUSE_OBF)
12778 +
12779 +/*
12780 + *     Controller Mode Register Bits
12781 + */
12782 +
12783 +#define KBD_MODE_KBD_INT       0x01    /* Keyboard data generate IRQ1 */
12784 +#define KBD_MODE_MOUSE_INT     0x02    /* Mouse data generate IRQ12 */
12785 +#define KBD_MODE_SYS           0x04    /* The system flag (?) */
12786 +#define KBD_MODE_NO_KEYLOCK    0x08    /* The keylock doesn't affect the keyboard if set */
12787 +#define KBD_MODE_DISABLE_KBD   0x10    /* Disable keyboard interface */
12788 +#define KBD_MODE_DISABLE_MOUSE 0x20    /* Disable mouse interface */
12789 +#define KBD_MODE_KCC           0x40    /* Scan code conversion to PC format */
12790 +#define KBD_MODE_RFU           0x80
12791 +
12792 +/*
12793 + *     Mouse Commands
12794 + */
12795 +
12796 +#define AUX_SET_RES            0xE8    /* Set resolution */
12797 +#define AUX_SET_SCALE11                0xE6    /* Set 1:1 scaling */
12798 +#define AUX_SET_SCALE21                0xE7    /* Set 2:1 scaling */
12799 +#define AUX_GET_SCALE          0xE9    /* Get scaling factor */
12800 +#define AUX_SET_STREAM         0xEA    /* Set stream mode */
12801 +#define AUX_SET_SAMPLE         0xF3    /* Set sample rate */
12802 +#define AUX_ENABLE_DEV         0xF4    /* Enable aux device */
12803 +#define AUX_DISABLE_DEV                0xF5    /* Disable aux device */
12804 +#define AUX_RESET              0xFF    /* Reset aux device */
12805 +#define AUX_ACK                        0xFA    /* Command byte ACK. */
12806 +
12807 +#define AUX_BUF_SIZE           2048    /* This might be better divisible by
12808 +                                          three to make overruns stay in sync
12809 +                                          but then the read function would need
12810 +                                          a lock etc - ick */
12811 +
12812 +struct aux_queue {
12813 +       unsigned long head;
12814 +       unsigned long tail;
12815 +       wait_queue_head_t proc_list;
12816 +       struct fasync_struct *fasync;
12817 +       unsigned char buf[AUX_BUF_SIZE];
12818 +};
12819 +
12820 +
12821 +/* How to access the keyboard macros on this platform.  */
12822 +#define kbd_read_input() inb(KBD_DATA_REG)
12823 +#define kbd_read_status() inb(KBD_STATUS_REG)
12824 +#define kbd_write_output(val) outb(val, KBD_DATA_REG)
12825 +#define kbd_write_command(val) outb(val, KBD_CNTL_REG)
12826 diff -Nurp linux-2.6.22-590/arch/x86_64/kdb/x86_64-dis.c linux-2.6.22-600/arch/x86_64/kdb/x86_64-dis.c
12827 --- linux-2.6.22-590/arch/x86_64/kdb/x86_64-dis.c       1970-01-01 01:00:00.000000000 +0100
12828 +++ linux-2.6.22-600/arch/x86_64/kdb/x86_64-dis.c       2008-04-09 18:16:24.000000000 +0200
12829 @@ -0,0 +1,4686 @@
12830 +/* Print i386 instructions for GDB, the GNU debugger.
12831 +   Copyright 1988, 1989, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
12832 +   2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
12833 +
12834 +   This file is part of GDB.
12835 +
12836 +   This program is free software; you can redistribute it and/or modify
12837 +   it under the terms of the GNU General Public License as published by
12838 +   the Free Software Foundation; either version 2 of the License, or
12839 +   (at your option) any later version.
12840 +
12841 +   This program is distributed in the hope that it will be useful,
12842 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
12843 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the
12844 +   GNU General Public License for more details.
12845 +
12846 +   You should have received a copy of the GNU General Public License
12847 +   along with this program; if not, write to the Free Software
12848 +   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
12849 +
12850 +/* Extracted from binutils 2.16.91.0.2 (OpenSUSE 10.0) and modified for kdb use.
12851 + * Run through col -b to remove trailing whitespace and various #ifdef/ifndef
12852 + * __KERNEL__ added.
12853 + * Keith Owens <kaos@sgi.com> 15 May 2006
12854 + */
12855 +
12856 +/* 80386 instruction printer by Pace Willisson (pace@prep.ai.mit.edu)
12857 +   July 1988
12858 +    modified by John Hassey (hassey@dg-rtp.dg.com)
12859 +    x86-64 support added by Jan Hubicka (jh@suse.cz)
12860 +    VIA PadLock support by Michal Ludvig (mludvig@suse.cz).  */
12861 +
12862 +/* The main tables describing the instructions is essentially a copy
12863 +   of the "Opcode Map" chapter (Appendix A) of the Intel 80386
12864 +   Programmers Manual. Usually, there is a capital letter, followed
12865 +   by a small letter.  The capital letter tell the addressing mode,
12866 +   and the small letter tells about the operand size.  Refer to
12867 +   the Intel manual for details.  */
12868 +
12869 +#ifdef __KERNEL__
12870 +#include <linux/kernel.h>
12871 +#include <linux/string.h>
12872 +#include <linux/dis-asm.h>
12873 +#include <linux/kdb.h>
12874 +#define abort() BUG()
12875 +#else  /* __KERNEL__ */
12876 +#include "dis-asm.h"
12877 +#include "sysdep.h"
12878 +#include "opintl.h"
12879 +#endif /* __KERNEL__ */
12880 +
12881 +#define MAXLEN 20
12882 +
12883 +#ifndef __KERNEL__
12884 +#include <setjmp.h>
12885 +#endif /* __KERNEL__ */
12886 +
12887 +#ifndef UNIXWARE_COMPAT
12888 +/* Set non-zero for broken, compatible instructions.  Set to zero for
12889 +   non-broken opcodes. */
12890 +#define UNIXWARE_COMPAT 1
12891 +#endif
12892 +
12893 +static int fetch_data (struct disassemble_info *, bfd_byte *);
12894 +static void ckprefix (void);
12895 +static const char *prefix_name (int, int);
12896 +static int print_insn (bfd_vma, disassemble_info *);
12897 +static void dofloat (int);
12898 +static void OP_ST (int, int);
12899 +static void OP_STi (int, int);
12900 +static int putop (const char *, int);
12901 +static void oappend (const char *);
12902 +static void append_seg (void);
12903 +static void OP_indirE (int, int);
12904 +static void print_operand_value (char *, int, bfd_vma);
12905 +static void OP_E (int, int);
12906 +static void OP_G (int, int);
12907 +static bfd_vma get64 (void);
12908 +static bfd_signed_vma get32 (void);
12909 +static bfd_signed_vma get32s (void);
12910 +static int get16 (void);
12911 +static void set_op (bfd_vma, int);
12912 +static void OP_REG (int, int);
12913 +static void OP_IMREG (int, int);
12914 +static void OP_I (int, int);
12915 +static void OP_I64 (int, int);
12916 +static void OP_sI (int, int);
12917 +static void OP_J (int, int);
12918 +static void OP_SEG (int, int);
12919 +static void OP_DIR (int, int);
12920 +static void OP_OFF (int, int);
12921 +static void OP_OFF64 (int, int);
12922 +static void ptr_reg (int, int);
12923 +static void OP_ESreg (int, int);
12924 +static void OP_DSreg (int, int);
12925 +static void OP_C (int, int);
12926 +static void OP_D (int, int);
12927 +static void OP_T (int, int);
12928 +static void OP_Rd (int, int);
12929 +static void OP_MMX (int, int);
12930 +static void OP_XMM (int, int);
12931 +static void OP_EM (int, int);
12932 +static void OP_EX (int, int);
12933 +static void OP_MS (int, int);
12934 +static void OP_XS (int, int);
12935 +static void OP_M (int, int);
12936 +static void OP_VMX (int, int);
12937 +static void OP_0fae (int, int);
12938 +static void OP_0f07 (int, int);
12939 +static void NOP_Fixup (int, int);
12940 +static void OP_3DNowSuffix (int, int);
12941 +static void OP_SIMD_Suffix (int, int);
12942 +static void SIMD_Fixup (int, int);
12943 +static void PNI_Fixup (int, int);
12944 +static void SVME_Fixup (int, int);
12945 +static void INVLPG_Fixup (int, int);
12946 +static void BadOp (void);
12947 +static void SEG_Fixup (int, int);
12948 +static void VMX_Fixup (int, int);
12949 +
12950 +struct dis_private {
12951 +  /* Points to first byte not fetched. */
12952 +  bfd_byte *max_fetched;
12953 +  bfd_byte the_buffer[MAXLEN];
12954 +  bfd_vma insn_start;
12955 +  int orig_sizeflag;
12956 +#ifndef __KERNEL__
12957 +  jmp_buf bailout;
12958 +#endif /* __KERNEL__ */
12959 +};
12960 +
12961 +/* The opcode for the fwait instruction, which we treat as a prefix
12962 +   when we can.         */
12963 +#define FWAIT_OPCODE (0x9b)
12964 +
12965 +/* Set to 1 for 64bit mode disassembly.         */
12966 +static int mode_64bit;
12967 +
12968 +/* Flags for the prefixes for the current instruction. See below.  */
12969 +static int prefixes;
12970 +
12971 +/* REX prefix the current instruction. See below.  */
12972 +static int rex;
12973 +/* Bits of REX we've already used.  */
12974 +static int rex_used;
12975 +#define REX_MODE64     8
12976 +#define REX_EXTX       4
12977 +#define REX_EXTY       2
12978 +#define REX_EXTZ       1
12979 +/* Mark parts used in the REX prefix.  When we are testing for
12980 +   empty prefix (for 8bit register REX extension), just mask it
12981 +   out.         Otherwise test for REX bit is excuse for existence of REX
12982 +   only in case value is nonzero.  */
12983 +#define USED_REX(value)                                        \
12984 +  {                                                    \
12985 +    if (value)                                         \
12986 +      rex_used |= (rex & value) ? (value) | 0x40 : 0;  \
12987 +    else                                               \
12988 +      rex_used |= 0x40;                                        \
12989 +  }
12990 +
12991 +/* Flags for prefixes which we somehow handled when printing the
12992 +   current instruction.         */
12993 +static int used_prefixes;
12994 +
12995 +/* Flags stored in PREFIXES.  */
12996 +#define PREFIX_REPZ 1
12997 +#define PREFIX_REPNZ 2
12998 +#define PREFIX_LOCK 4
12999 +#define PREFIX_CS 8
13000 +#define PREFIX_SS 0x10
13001 +#define PREFIX_DS 0x20
13002 +#define PREFIX_ES 0x40
13003 +#define PREFIX_FS 0x80
13004 +#define PREFIX_GS 0x100
13005 +#define PREFIX_DATA 0x200
13006 +#define PREFIX_ADDR 0x400
13007 +#define PREFIX_FWAIT 0x800
13008 +
13009 +/* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
13010 +   to ADDR (exclusive) are valid.  Returns 1 for success, longjmps
13011 +   on error.  */
13012 +#define FETCH_DATA(info, addr) \
13013 +  ((addr) <= ((struct dis_private *) (info->private_data))->max_fetched \
13014 +   ? 1 : fetch_data ((info), (addr)))
13015 +
13016 +static int
13017 +fetch_data (struct disassemble_info *info, bfd_byte *addr)
13018 +{
13019 +  int status;
13020 +  struct dis_private *priv = (struct dis_private *) info->private_data;
13021 +  bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
13022 +
13023 +  status = (*info->read_memory_func) (start,
13024 +                                     priv->max_fetched,
13025 +                                     addr - priv->max_fetched,
13026 +                                     info);
13027 +  if (status != 0)
13028 +    {
13029 +      /* If we did manage to read at least one byte, then
13030 +        print_insn_i386 will do something sensible.  Otherwise, print
13031 +        an error.  We do that here because this is where we know
13032 +        STATUS.  */
13033 +      if (priv->max_fetched == priv->the_buffer)
13034 +       (*info->memory_error_func) (status, start, info);
13035 +#ifndef __KERNEL__
13036 +      longjmp (priv->bailout, 1);
13037 +#else  /* __KERNEL__ */
13038 +       /* XXX - what to do? */
13039 +       kdb_printf("Hmm. longjmp.\n");
13040 +#endif /* __KERNEL__ */
13041 +    }
13042 +  else
13043 +    priv->max_fetched = addr;
13044 +  return 1;
13045 +}
13046 +
13047 +#define XX NULL, 0
13048 +
13049 +#define Eb OP_E, b_mode
13050 +#define Ev OP_E, v_mode
13051 +#define Ed OP_E, d_mode
13052 +#define Eq OP_E, q_mode
13053 +#define Edq OP_E, dq_mode
13054 +#define Edqw OP_E, dqw_mode
13055 +#define indirEv OP_indirE, branch_v_mode
13056 +#define indirEp OP_indirE, f_mode
13057 +#define Em OP_E, m_mode
13058 +#define Ew OP_E, w_mode
13059 +#define Ma OP_E, v_mode
13060 +#define M OP_M, 0              /* lea, lgdt, etc. */
13061 +#define Mp OP_M, f_mode                /* 32 or 48 bit memory operand for LDS, LES etc */
13062 +#define Gb OP_G, b_mode
13063 +#define Gv OP_G, v_mode
13064 +#define Gd OP_G, d_mode
13065 +#define Gdq OP_G, dq_mode
13066 +#define Gm OP_G, m_mode
13067 +#define Gw OP_G, w_mode
13068 +#define Rd OP_Rd, d_mode
13069 +#define Rm OP_Rd, m_mode
13070 +#define Ib OP_I, b_mode
13071 +#define sIb OP_sI, b_mode      /* sign extened byte */
13072 +#define Iv OP_I, v_mode
13073 +#define Iq OP_I, q_mode
13074 +#define Iv64 OP_I64, v_mode
13075 +#define Iw OP_I, w_mode
13076 +#define I1 OP_I, const_1_mode
13077 +#define Jb OP_J, b_mode
13078 +#define Jv OP_J, v_mode
13079 +#define Cm OP_C, m_mode
13080 +#define Dm OP_D, m_mode
13081 +#define Td OP_T, d_mode
13082 +#define Sv SEG_Fixup, v_mode
13083 +
13084 +#define RMeAX OP_REG, eAX_reg
13085 +#define RMeBX OP_REG, eBX_reg
13086 +#define RMeCX OP_REG, eCX_reg
13087 +#define RMeDX OP_REG, eDX_reg
13088 +#define RMeSP OP_REG, eSP_reg
13089 +#define RMeBP OP_REG, eBP_reg
13090 +#define RMeSI OP_REG, eSI_reg
13091 +#define RMeDI OP_REG, eDI_reg
13092 +#define RMrAX OP_REG, rAX_reg
13093 +#define RMrBX OP_REG, rBX_reg
13094 +#define RMrCX OP_REG, rCX_reg
13095 +#define RMrDX OP_REG, rDX_reg
13096 +#define RMrSP OP_REG, rSP_reg
13097 +#define RMrBP OP_REG, rBP_reg
13098 +#define RMrSI OP_REG, rSI_reg
13099 +#define RMrDI OP_REG, rDI_reg
13100 +#define RMAL OP_REG, al_reg
13101 +#define RMAL OP_REG, al_reg
13102 +#define RMCL OP_REG, cl_reg
13103 +#define RMDL OP_REG, dl_reg
13104 +#define RMBL OP_REG, bl_reg
13105 +#define RMAH OP_REG, ah_reg
13106 +#define RMCH OP_REG, ch_reg
13107 +#define RMDH OP_REG, dh_reg
13108 +#define RMBH OP_REG, bh_reg
13109 +#define RMAX OP_REG, ax_reg
13110 +#define RMDX OP_REG, dx_reg
13111 +
13112 +#define eAX OP_IMREG, eAX_reg
13113 +#define eBX OP_IMREG, eBX_reg
13114 +#define eCX OP_IMREG, eCX_reg
13115 +#define eDX OP_IMREG, eDX_reg
13116 +#define eSP OP_IMREG, eSP_reg
13117 +#define eBP OP_IMREG, eBP_reg
13118 +#define eSI OP_IMREG, eSI_reg
13119 +#define eDI OP_IMREG, eDI_reg
13120 +#define AL OP_IMREG, al_reg
13121 +#define AL OP_IMREG, al_reg
13122 +#define CL OP_IMREG, cl_reg
13123 +#define DL OP_IMREG, dl_reg
13124 +#define BL OP_IMREG, bl_reg
13125 +#define AH OP_IMREG, ah_reg
13126 +#define CH OP_IMREG, ch_reg
13127 +#define DH OP_IMREG, dh_reg
13128 +#define BH OP_IMREG, bh_reg
13129 +#define AX OP_IMREG, ax_reg
13130 +#define DX OP_IMREG, dx_reg
13131 +#define indirDX OP_IMREG, indir_dx_reg
13132 +
13133 +#define Sw OP_SEG, w_mode
13134 +#define Ap OP_DIR, 0
13135 +#define Ob OP_OFF, b_mode
13136 +#define Ob64 OP_OFF64, b_mode
13137 +#define Ov OP_OFF, v_mode
13138 +#define Ov64 OP_OFF64, v_mode
13139 +#define Xb OP_DSreg, eSI_reg
13140 +#define Xv OP_DSreg, eSI_reg
13141 +#define Yb OP_ESreg, eDI_reg
13142 +#define Yv OP_ESreg, eDI_reg
13143 +#define DSBX OP_DSreg, eBX_reg
13144 +
13145 +#define es OP_REG, es_reg
13146 +#define ss OP_REG, ss_reg
13147 +#define cs OP_REG, cs_reg
13148 +#define ds OP_REG, ds_reg
13149 +#define fs OP_REG, fs_reg
13150 +#define gs OP_REG, gs_reg
13151 +
13152 +#define MX OP_MMX, 0
13153 +#define XM OP_XMM, 0
13154 +#define EM OP_EM, v_mode
13155 +#define EX OP_EX, v_mode
13156 +#define MS OP_MS, v_mode
13157 +#define XS OP_XS, v_mode
13158 +#define VM OP_VMX, q_mode
13159 +#define OPSUF OP_3DNowSuffix, 0
13160 +#define OPSIMD OP_SIMD_Suffix, 0
13161 +
13162 +#define cond_jump_flag NULL, cond_jump_mode
13163 +#define loop_jcxz_flag NULL, loop_jcxz_mode
13164 +
13165 +/* bits in sizeflag */
13166 +#define SUFFIX_ALWAYS 4
13167 +#define AFLAG 2
13168 +#define DFLAG 1
13169 +
13170 +#define b_mode 1  /* byte operand */
13171 +#define v_mode 2  /* operand size depends on prefixes */
13172 +#define w_mode 3  /* word operand */
13173 +#define d_mode 4  /* double word operand  */
13174 +#define q_mode 5  /* quad word operand */
13175 +#define t_mode 6  /* ten-byte operand */
13176 +#define x_mode 7  /* 16-byte XMM operand */
13177 +#define m_mode 8  /* d_mode in 32bit, q_mode in 64bit mode.  */
13178 +#define cond_jump_mode 9
13179 +#define loop_jcxz_mode 10
13180 +#define dq_mode 11 /* operand size depends on REX prefixes.  */
13181 +#define dqw_mode 12 /* registers like dq_mode, memory like w_mode.  */
13182 +#define f_mode 13 /* 4- or 6-byte pointer operand */
13183 +#define const_1_mode 14
13184 +#define branch_v_mode 15 /* v_mode for branch. */
13185 +
13186 +#define es_reg 100
13187 +#define cs_reg 101
13188 +#define ss_reg 102
13189 +#define ds_reg 103
13190 +#define fs_reg 104
13191 +#define gs_reg 105
13192 +
13193 +#define eAX_reg 108
13194 +#define eCX_reg 109
13195 +#define eDX_reg 110
13196 +#define eBX_reg 111
13197 +#define eSP_reg 112
13198 +#define eBP_reg 113
13199 +#define eSI_reg 114
13200 +#define eDI_reg 115
13201 +
13202 +#define al_reg 116
13203 +#define cl_reg 117
13204 +#define dl_reg 118
13205 +#define bl_reg 119
13206 +#define ah_reg 120
13207 +#define ch_reg 121
13208 +#define dh_reg 122
13209 +#define bh_reg 123
13210 +
13211 +#define ax_reg 124
13212 +#define cx_reg 125
13213 +#define dx_reg 126
13214 +#define bx_reg 127
13215 +#define sp_reg 128
13216 +#define bp_reg 129
13217 +#define si_reg 130
13218 +#define di_reg 131
13219 +
13220 +#define rAX_reg 132
13221 +#define rCX_reg 133
13222 +#define rDX_reg 134
13223 +#define rBX_reg 135
13224 +#define rSP_reg 136
13225 +#define rBP_reg 137
13226 +#define rSI_reg 138
13227 +#define rDI_reg 139
13228 +
13229 +#define indir_dx_reg 150
13230 +
13231 +#define FLOATCODE 1
13232 +#define USE_GROUPS 2
13233 +#define USE_PREFIX_USER_TABLE 3
13234 +#define X86_64_SPECIAL 4
13235 +
13236 +#define FLOAT    NULL, NULL, FLOATCODE, NULL, 0, NULL, 0
13237 +
13238 +#define GRP1b    NULL, NULL, USE_GROUPS, NULL,  0, NULL, 0
13239 +#define GRP1S    NULL, NULL, USE_GROUPS, NULL,  1, NULL, 0
13240 +#define GRP1Ss   NULL, NULL, USE_GROUPS, NULL,  2, NULL, 0
13241 +#define GRP2b    NULL, NULL, USE_GROUPS, NULL,  3, NULL, 0
13242 +#define GRP2S    NULL, NULL, USE_GROUPS, NULL,  4, NULL, 0
13243 +#define GRP2b_one NULL, NULL, USE_GROUPS, NULL,         5, NULL, 0
13244 +#define GRP2S_one NULL, NULL, USE_GROUPS, NULL,         6, NULL, 0
13245 +#define GRP2b_cl  NULL, NULL, USE_GROUPS, NULL,         7, NULL, 0
13246 +#define GRP2S_cl  NULL, NULL, USE_GROUPS, NULL,         8, NULL, 0
13247 +#define GRP3b    NULL, NULL, USE_GROUPS, NULL,  9, NULL, 0
13248 +#define GRP3S    NULL, NULL, USE_GROUPS, NULL, 10, NULL, 0
13249 +#define GRP4     NULL, NULL, USE_GROUPS, NULL, 11, NULL, 0
13250 +#define GRP5     NULL, NULL, USE_GROUPS, NULL, 12, NULL, 0
13251 +#define GRP6     NULL, NULL, USE_GROUPS, NULL, 13, NULL, 0
13252 +#define GRP7     NULL, NULL, USE_GROUPS, NULL, 14, NULL, 0
13253 +#define GRP8     NULL, NULL, USE_GROUPS, NULL, 15, NULL, 0
13254 +#define GRP9     NULL, NULL, USE_GROUPS, NULL, 16, NULL, 0
13255 +#define GRP10    NULL, NULL, USE_GROUPS, NULL, 17, NULL, 0
13256 +#define GRP11    NULL, NULL, USE_GROUPS, NULL, 18, NULL, 0
13257 +#define GRP12    NULL, NULL, USE_GROUPS, NULL, 19, NULL, 0
13258 +#define GRP13    NULL, NULL, USE_GROUPS, NULL, 20, NULL, 0
13259 +#define GRP14    NULL, NULL, USE_GROUPS, NULL, 21, NULL, 0
13260 +#define GRPAMD   NULL, NULL, USE_GROUPS, NULL, 22, NULL, 0
13261 +#define GRPPADLCK1 NULL, NULL, USE_GROUPS, NULL, 23, NULL, 0
13262 +#define GRPPADLCK2 NULL, NULL, USE_GROUPS, NULL, 24, NULL, 0
13263 +
13264 +#define PREGRP0          NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  0, NULL, 0
13265 +#define PREGRP1          NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  1, NULL, 0
13266 +#define PREGRP2          NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  2, NULL, 0
13267 +#define PREGRP3          NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  3, NULL, 0
13268 +#define PREGRP4          NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  4, NULL, 0
13269 +#define PREGRP5          NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  5, NULL, 0
13270 +#define PREGRP6          NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  6, NULL, 0
13271 +#define PREGRP7          NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  7, NULL, 0
13272 +#define PREGRP8          NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  8, NULL, 0
13273 +#define PREGRP9          NULL, NULL, USE_PREFIX_USER_TABLE, NULL,  9, NULL, 0
13274 +#define PREGRP10  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 10, NULL, 0
13275 +#define PREGRP11  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 11, NULL, 0
13276 +#define PREGRP12  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 12, NULL, 0
13277 +#define PREGRP13  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 13, NULL, 0
13278 +#define PREGRP14  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 14, NULL, 0
13279 +#define PREGRP15  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 15, NULL, 0
13280 +#define PREGRP16  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 16, NULL, 0
13281 +#define PREGRP17  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 17, NULL, 0
13282 +#define PREGRP18  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 18, NULL, 0
13283 +#define PREGRP19  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 19, NULL, 0
13284 +#define PREGRP20  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 20, NULL, 0
13285 +#define PREGRP21  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 21, NULL, 0
13286 +#define PREGRP22  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 22, NULL, 0
13287 +#define PREGRP23  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 23, NULL, 0
13288 +#define PREGRP24  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 24, NULL, 0
13289 +#define PREGRP25  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 25, NULL, 0
13290 +#define PREGRP26  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 26, NULL, 0
13291 +#define PREGRP27  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 27, NULL, 0
13292 +#define PREGRP28  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 28, NULL, 0
13293 +#define PREGRP29  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 29, NULL, 0
13294 +#define PREGRP30  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 30, NULL, 0
13295 +#define PREGRP31  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 31, NULL, 0
13296 +#define PREGRP32  NULL, NULL, USE_PREFIX_USER_TABLE, NULL, 32, NULL, 0
13297 +
13298 +#define X86_64_0  NULL, NULL, X86_64_SPECIAL, NULL,  0, NULL, 0
13299 +
13300 +typedef void (*op_rtn) (int bytemode, int sizeflag);
13301 +
13302 +struct dis386 {
13303 +  const char *name;
13304 +  op_rtn op1;
13305 +  int bytemode1;
13306 +  op_rtn op2;
13307 +  int bytemode2;
13308 +  op_rtn op3;
13309 +  int bytemode3;
13310 +};
13311 +
13312 +/* Upper case letters in the instruction names here are macros.
13313 +   'A' => print 'b' if no register operands or suffix_always is true
13314 +   'B' => print 'b' if suffix_always is true
13315 +   'C' => print 's' or 'l' ('w' or 'd' in Intel mode) depending on operand
13316 +   .     size prefix
13317 +   'E' => print 'e' if 32-bit form of jcxz
13318 +   'F' => print 'w' or 'l' depending on address size prefix (loop insns)
13319 +   'H' => print ",pt" or ",pn" branch hint
13320 +   'I' => honor following macro letter even in Intel mode (implemented only
13321 +   .     for some of the macro letters)
13322 +   'J' => print 'l'
13323 +   'L' => print 'l' if suffix_always is true
13324 +   'N' => print 'n' if instruction has no wait "prefix"
13325 +   'O' => print 'd', or 'o'
13326 +   'P' => print 'w', 'l' or 'q' if instruction has an operand size prefix,
13327 +   .     or suffix_always is true.  print 'q' if rex prefix is present.
13328 +   'Q' => print 'w', 'l' or 'q' if no register operands or suffix_always
13329 +   .     is true
13330 +   'R' => print 'w', 'l' or 'q' ("wd" or "dq" in intel mode)
13331 +   'S' => print 'w', 'l' or 'q' if suffix_always is true
13332 +   'T' => print 'q' in 64bit mode and behave as 'P' otherwise
13333 +   'U' => print 'q' in 64bit mode and behave as 'Q' otherwise
13334 +   'W' => print 'b' or 'w' ("w" or "de" in intel mode)
13335 +   'X' => print 's', 'd' depending on data16 prefix (for XMM)
13336 +   'Y' => 'q' if instruction has an REX 64bit overwrite prefix
13337 +
13338 +   Many of the above letters print nothing in Intel mode.  See "putop"
13339 +   for the details.
13340 +
13341 +   Braces '{' and '}', and vertical bars '|', indicate alternative
13342 +   mnemonic strings for AT&T, Intel, X86_64 AT&T, and X86_64 Intel
13343 +   modes.  In cases where there are only two alternatives, the X86_64
13344 +   instruction is reserved, and "(bad)" is printed.
13345 +*/
13346 +
13347 +static const struct dis386 dis386[] = {
13348 +  /* 00 */
13349 +  { "addB",            Eb, Gb, XX },
13350 +  { "addS",            Ev, Gv, XX },
13351 +  { "addB",            Gb, Eb, XX },
13352 +  { "addS",            Gv, Ev, XX },
13353 +  { "addB",            AL, Ib, XX },
13354 +  { "addS",            eAX, Iv, XX },
13355 +  { "push{T|}",                es, XX, XX },
13356 +  { "pop{T|}",         es, XX, XX },
13357 +  /* 08 */
13358 +  { "orB",             Eb, Gb, XX },
13359 +  { "orS",             Ev, Gv, XX },
13360 +  { "orB",             Gb, Eb, XX },
13361 +  { "orS",             Gv, Ev, XX },
13362 +  { "orB",             AL, Ib, XX },
13363 +  { "orS",             eAX, Iv, XX },
13364 +  { "push{T|}",                cs, XX, XX },
13365 +  { "(bad)",           XX, XX, XX },   /* 0x0f extended opcode escape */
13366 +  /* 10 */
13367 +  { "adcB",            Eb, Gb, XX },
13368 +  { "adcS",            Ev, Gv, XX },
13369 +  { "adcB",            Gb, Eb, XX },
13370 +  { "adcS",            Gv, Ev, XX },
13371 +  { "adcB",            AL, Ib, XX },
13372 +  { "adcS",            eAX, Iv, XX },
13373 +  { "push{T|}",                ss, XX, XX },
13374 +  { "popT|}",          ss, XX, XX },
13375 +  /* 18 */
13376 +  { "sbbB",            Eb, Gb, XX },
13377 +  { "sbbS",            Ev, Gv, XX },
13378 +  { "sbbB",            Gb, Eb, XX },
13379 +  { "sbbS",            Gv, Ev, XX },
13380 +  { "sbbB",            AL, Ib, XX },
13381 +  { "sbbS",            eAX, Iv, XX },
13382 +  { "push{T|}",                ds, XX, XX },
13383 +  { "pop{T|}",         ds, XX, XX },
13384 +  /* 20 */
13385 +  { "andB",            Eb, Gb, XX },
13386 +  { "andS",            Ev, Gv, XX },
13387 +  { "andB",            Gb, Eb, XX },
13388 +  { "andS",            Gv, Ev, XX },
13389 +  { "andB",            AL, Ib, XX },
13390 +  { "andS",            eAX, Iv, XX },
13391 +  { "(bad)",           XX, XX, XX },   /* SEG ES prefix */
13392 +  { "daa{|}",          XX, XX, XX },
13393 +  /* 28 */
13394 +  { "subB",            Eb, Gb, XX },
13395 +  { "subS",            Ev, Gv, XX },
13396 +  { "subB",            Gb, Eb, XX },
13397 +  { "subS",            Gv, Ev, XX },
13398 +  { "subB",            AL, Ib, XX },
13399 +  { "subS",            eAX, Iv, XX },
13400 +  { "(bad)",           XX, XX, XX },   /* SEG CS prefix */
13401 +  { "das{|}",          XX, XX, XX },
13402 +  /* 30 */
13403 +  { "xorB",            Eb, Gb, XX },
13404 +  { "xorS",            Ev, Gv, XX },
13405 +  { "xorB",            Gb, Eb, XX },
13406 +  { "xorS",            Gv, Ev, XX },
13407 +  { "xorB",            AL, Ib, XX },
13408 +  { "xorS",            eAX, Iv, XX },
13409 +  { "(bad)",           XX, XX, XX },   /* SEG SS prefix */
13410 +  { "aaa{|}",          XX, XX, XX },
13411 +  /* 38 */
13412 +  { "cmpB",            Eb, Gb, XX },
13413 +  { "cmpS",            Ev, Gv, XX },
13414 +  { "cmpB",            Gb, Eb, XX },
13415 +  { "cmpS",            Gv, Ev, XX },
13416 +  { "cmpB",            AL, Ib, XX },
13417 +  { "cmpS",            eAX, Iv, XX },
13418 +  { "(bad)",           XX, XX, XX },   /* SEG DS prefix */
13419 +  { "aas{|}",          XX, XX, XX },
13420 +  /* 40 */
13421 +  { "inc{S|}",         RMeAX, XX, XX },
13422 +  { "inc{S|}",         RMeCX, XX, XX },
13423 +  { "inc{S|}",         RMeDX, XX, XX },
13424 +  { "inc{S|}",         RMeBX, XX, XX },
13425 +  { "inc{S|}",         RMeSP, XX, XX },
13426 +  { "inc{S|}",         RMeBP, XX, XX },
13427 +  { "inc{S|}",         RMeSI, XX, XX },
13428 +  { "inc{S|}",         RMeDI, XX, XX },
13429 +  /* 48 */
13430 +  { "dec{S|}",         RMeAX, XX, XX },
13431 +  { "dec{S|}",         RMeCX, XX, XX },
13432 +  { "dec{S|}",         RMeDX, XX, XX },
13433 +  { "dec{S|}",         RMeBX, XX, XX },
13434 +  { "dec{S|}",         RMeSP, XX, XX },
13435 +  { "dec{S|}",         RMeBP, XX, XX },
13436 +  { "dec{S|}",         RMeSI, XX, XX },
13437 +  { "dec{S|}",         RMeDI, XX, XX },
13438 +  /* 50 */
13439 +  { "pushS",           RMrAX, XX, XX },
13440 +  { "pushS",           RMrCX, XX, XX },
13441 +  { "pushS",           RMrDX, XX, XX },
13442 +  { "pushS",           RMrBX, XX, XX },
13443 +  { "pushS",           RMrSP, XX, XX },
13444 +  { "pushS",           RMrBP, XX, XX },
13445 +  { "pushS",           RMrSI, XX, XX },
13446 +  { "pushS",           RMrDI, XX, XX },
13447 +  /* 58 */
13448 +  { "popS",            RMrAX, XX, XX },
13449 +  { "popS",            RMrCX, XX, XX },
13450 +  { "popS",            RMrDX, XX, XX },
13451 +  { "popS",            RMrBX, XX, XX },
13452 +  { "popS",            RMrSP, XX, XX },
13453 +  { "popS",            RMrBP, XX, XX },
13454 +  { "popS",            RMrSI, XX, XX },
13455 +  { "popS",            RMrDI, XX, XX },
13456 +  /* 60 */
13457 +  { "pusha{P|}",       XX, XX, XX },
13458 +  { "popa{P|}",                XX, XX, XX },
13459 +  { "bound{S|}",       Gv, Ma, XX },
13460 +  { X86_64_0 },
13461 +  { "(bad)",           XX, XX, XX },   /* seg fs */
13462 +  { "(bad)",           XX, XX, XX },   /* seg gs */
13463 +  { "(bad)",           XX, XX, XX },   /* op size prefix */
13464 +  { "(bad)",           XX, XX, XX },   /* adr size prefix */
13465 +  /* 68 */
13466 +  { "pushT",           Iq, XX, XX },
13467 +  { "imulS",           Gv, Ev, Iv },
13468 +  { "pushT",           sIb, XX, XX },
13469 +  { "imulS",           Gv, Ev, sIb },
13470 +  { "ins{b||b|}",      Yb, indirDX, XX },
13471 +  { "ins{R||R|}",      Yv, indirDX, XX },
13472 +  { "outs{b||b|}",     indirDX, Xb, XX },
13473 +  { "outs{R||R|}",     indirDX, Xv, XX },
13474 +  /* 70 */
13475 +  { "joH",             Jb, XX, cond_jump_flag },
13476 +  { "jnoH",            Jb, XX, cond_jump_flag },
13477 +  { "jbH",             Jb, XX, cond_jump_flag },
13478 +  { "jaeH",            Jb, XX, cond_jump_flag },
13479 +  { "jeH",             Jb, XX, cond_jump_flag },
13480 +  { "jneH",            Jb, XX, cond_jump_flag },
13481 +  { "jbeH",            Jb, XX, cond_jump_flag },
13482 +  { "jaH",             Jb, XX, cond_jump_flag },
13483 +  /* 78 */
13484 +  { "jsH",             Jb, XX, cond_jump_flag },
13485 +  { "jnsH",            Jb, XX, cond_jump_flag },
13486 +  { "jpH",             Jb, XX, cond_jump_flag },
13487 +  { "jnpH",            Jb, XX, cond_jump_flag },
13488 +  { "jlH",             Jb, XX, cond_jump_flag },
13489 +  { "jgeH",            Jb, XX, cond_jump_flag },
13490 +  { "jleH",            Jb, XX, cond_jump_flag },
13491 +  { "jgH",             Jb, XX, cond_jump_flag },
13492 +  /* 80 */
13493 +  { GRP1b },
13494 +  { GRP1S },
13495 +  { "(bad)",           XX, XX, XX },
13496 +  { GRP1Ss },
13497 +  { "testB",           Eb, Gb, XX },
13498 +  { "testS",           Ev, Gv, XX },
13499 +  { "xchgB",           Eb, Gb, XX },
13500 +  { "xchgS",           Ev, Gv, XX },
13501 +  /* 88 */
13502 +  { "movB",            Eb, Gb, XX },
13503 +  { "movS",            Ev, Gv, XX },
13504 +  { "movB",            Gb, Eb, XX },
13505 +  { "movS",            Gv, Ev, XX },
13506 +  { "movQ",            Sv, Sw, XX },
13507 +  { "leaS",            Gv, M, XX },
13508 +  { "movQ",            Sw, Sv, XX },
13509 +  { "popU",            Ev, XX, XX },
13510 +  /* 90 */
13511 +  { "nop",             NOP_Fixup, 0, XX, XX },
13512 +  { "xchgS",           RMeCX, eAX, XX },
13513 +  { "xchgS",           RMeDX, eAX, XX },
13514 +  { "xchgS",           RMeBX, eAX, XX },
13515 +  { "xchgS",           RMeSP, eAX, XX },
13516 +  { "xchgS",           RMeBP, eAX, XX },
13517 +  { "xchgS",           RMeSI, eAX, XX },
13518 +  { "xchgS",           RMeDI, eAX, XX },
13519 +  /* 98 */
13520 +  { "cW{tR||tR|}",     XX, XX, XX },
13521 +  { "cR{tO||tO|}",     XX, XX, XX },
13522 +  { "Jcall{T|}",       Ap, XX, XX },
13523 +  { "(bad)",           XX, XX, XX },   /* fwait */
13524 +  { "pushfT",          XX, XX, XX },
13525 +  { "popfT",           XX, XX, XX },
13526 +  { "sahf{|}",         XX, XX, XX },
13527 +  { "lahf{|}",         XX, XX, XX },
13528 +  /* a0 */
13529 +  { "movB",            AL, Ob64, XX },
13530 +  { "movS",            eAX, Ov64, XX },
13531 +  { "movB",            Ob64, AL, XX },
13532 +  { "movS",            Ov64, eAX, XX },
13533 +  { "movs{b||b|}",     Yb, Xb, XX },
13534 +  { "movs{R||R|}",     Yv, Xv, XX },
13535 +  { "cmps{b||b|}",     Xb, Yb, XX },
13536 +  { "cmps{R||R|}",     Xv, Yv, XX },
13537 +  /* a8 */
13538 +  { "testB",           AL, Ib, XX },
13539 +  { "testS",           eAX, Iv, XX },
13540 +  { "stosB",           Yb, AL, XX },
13541 +  { "stosS",           Yv, eAX, XX },
13542 +  { "lodsB",           AL, Xb, XX },
13543 +  { "lodsS",           eAX, Xv, XX },
13544 +  { "scasB",           AL, Yb, XX },
13545 +  { "scasS",           eAX, Yv, XX },
13546 +  /* b0 */
13547 +  { "movB",            RMAL, Ib, XX },
13548 +  { "movB",            RMCL, Ib, XX },
13549 +  { "movB",            RMDL, Ib, XX },
13550 +  { "movB",            RMBL, Ib, XX },
13551 +  { "movB",            RMAH, Ib, XX },
13552 +  { "movB",            RMCH, Ib, XX },
13553 +  { "movB",            RMDH, Ib, XX },
13554 +  { "movB",            RMBH, Ib, XX },
13555 +  /* b8 */
13556 +  { "movS",            RMeAX, Iv64, XX },
13557 +  { "movS",            RMeCX, Iv64, XX },
13558 +  { "movS",            RMeDX, Iv64, XX },
13559 +  { "movS",            RMeBX, Iv64, XX },
13560 +  { "movS",            RMeSP, Iv64, XX },
13561 +  { "movS",            RMeBP, Iv64, XX },
13562 +  { "movS",            RMeSI, Iv64, XX },
13563 +  { "movS",            RMeDI, Iv64, XX },
13564 +  /* c0 */
13565 +  { GRP2b },
13566 +  { GRP2S },
13567 +  { "retT",            Iw, XX, XX },
13568 +  { "retT",            XX, XX, XX },
13569 +  { "les{S|}",         Gv, Mp, XX },
13570 +  { "ldsS",            Gv, Mp, XX },
13571 +  { "movA",            Eb, Ib, XX },
13572 +  { "movQ",            Ev, Iv, XX },
13573 +  /* c8 */
13574 +  { "enterT",          Iw, Ib, XX },
13575 +  { "leaveT",          XX, XX, XX },
13576 +  { "lretP",           Iw, XX, XX },
13577 +  { "lretP",           XX, XX, XX },
13578 +  { "int3",            XX, XX, XX },
13579 +  { "int",             Ib, XX, XX },
13580 +  { "into{|}",         XX, XX, XX },
13581 +  { "iretP",           XX, XX, XX },
13582 +  /* d0 */
13583 +  { GRP2b_one },
13584 +  { GRP2S_one },
13585 +  { GRP2b_cl },
13586 +  { GRP2S_cl },
13587 +  { "aam{|}",          sIb, XX, XX },
13588 +  { "aad{|}",          sIb, XX, XX },
13589 +  { "(bad)",           XX, XX, XX },
13590 +  { "xlat",            DSBX, XX, XX },
13591 +  /* d8 */
13592 +  { FLOAT },
13593 +  { FLOAT },
13594 +  { FLOAT },
13595 +  { FLOAT },
13596 +  { FLOAT },
13597 +  { FLOAT },
13598 +  { FLOAT },
13599 +  { FLOAT },
13600 +  /* e0 */
13601 +  { "loopneFH",                Jb, XX, loop_jcxz_flag },
13602 +  { "loopeFH",         Jb, XX, loop_jcxz_flag },
13603 +  { "loopFH",          Jb, XX, loop_jcxz_flag },
13604 +  { "jEcxzH",          Jb, XX, loop_jcxz_flag },
13605 +  { "inB",             AL, Ib, XX },
13606 +  { "inS",             eAX, Ib, XX },
13607 +  { "outB",            Ib, AL, XX },
13608 +  { "outS",            Ib, eAX, XX },
13609 +  /* e8 */
13610 +  { "callT",           Jv, XX, XX },
13611 +  { "jmpT",            Jv, XX, XX },
13612 +  { "Jjmp{T|}",                Ap, XX, XX },
13613 +  { "jmp",             Jb, XX, XX },
13614 +  { "inB",             AL, indirDX, XX },
13615 +  { "inS",             eAX, indirDX, XX },
13616 +  { "outB",            indirDX, AL, XX },
13617 +  { "outS",            indirDX, eAX, XX },
13618 +  /* f0 */
13619 +  { "(bad)",           XX, XX, XX },   /* lock prefix */
13620 +  { "icebp",           XX, XX, XX },
13621 +  { "(bad)",           XX, XX, XX },   /* repne */
13622 +  { "(bad)",           XX, XX, XX },   /* repz */
13623 +  { "hlt",             XX, XX, XX },
13624 +  { "cmc",             XX, XX, XX },
13625 +  { GRP3b },
13626 +  { GRP3S },
13627 +  /* f8 */
13628 +  { "clc",             XX, XX, XX },
13629 +  { "stc",             XX, XX, XX },
13630 +  { "cli",             XX, XX, XX },
13631 +  { "sti",             XX, XX, XX },
13632 +  { "cld",             XX, XX, XX },
13633 +  { "std",             XX, XX, XX },
13634 +  { GRP4 },
13635 +  { GRP5 },
13636 +};
13637 +
13638 +static const struct dis386 dis386_twobyte[] = {
13639 +  /* 00 */
13640 +  { GRP6 },
13641 +  { GRP7 },
13642 +  { "larS",            Gv, Ew, XX },
13643 +  { "lslS",            Gv, Ew, XX },
13644 +  { "(bad)",           XX, XX, XX },
13645 +  { "syscall",         XX, XX, XX },
13646 +  { "clts",            XX, XX, XX },
13647 +  { "sysretP",         XX, XX, XX },
13648 +  /* 08 */
13649 +  { "invd",            XX, XX, XX },
13650 +  { "wbinvd",          XX, XX, XX },
13651 +  { "(bad)",           XX, XX, XX },
13652 +  { "ud2a",            XX, XX, XX },
13653 +  { "(bad)",           XX, XX, XX },
13654 +  { GRPAMD },
13655 +  { "femms",           XX, XX, XX },
13656 +  { "",                        MX, EM, OPSUF }, /* See OP_3DNowSuffix.  */
13657 +  /* 10 */
13658 +  { PREGRP8 },
13659 +  { PREGRP9 },
13660 +  { PREGRP30 },
13661 +  { "movlpX",          EX, XM, SIMD_Fixup, 'h' },
13662 +  { "unpcklpX",                XM, EX, XX },
13663 +  { "unpckhpX",                XM, EX, XX },
13664 +  { PREGRP31 },
13665 +  { "movhpX",          EX, XM, SIMD_Fixup, 'l' },
13666 +  /* 18 */
13667 +  { GRP14 },
13668 +  { "(bad)",           XX, XX, XX },
13669 +  { "(bad)",           XX, XX, XX },
13670 +  { "(bad)",           XX, XX, XX },
13671 +  { "(bad)",           XX, XX, XX },
13672 +  { "(bad)",           XX, XX, XX },
13673 +  { "(bad)",           XX, XX, XX },
13674 +  { "(bad)",           XX, XX, XX },
13675 +  /* 20 */
13676 +  { "movL",            Rm, Cm, XX },
13677 +  { "movL",            Rm, Dm, XX },
13678 +  { "movL",            Cm, Rm, XX },
13679 +  { "movL",            Dm, Rm, XX },
13680 +  { "movL",            Rd, Td, XX },
13681 +  { "(bad)",           XX, XX, XX },
13682 +  { "movL",            Td, Rd, XX },
13683 +  { "(bad)",           XX, XX, XX },
13684 +  /* 28 */
13685 +  { "movapX",          XM, EX, XX },
13686 +  { "movapX",          EX, XM, XX },
13687 +  { PREGRP2 },
13688 +  { "movntpX",         Ev, XM, XX },
13689 +  { PREGRP4 },
13690 +  { PREGRP3 },
13691 +  { "ucomisX",         XM,EX, XX },
13692 +  { "comisX",          XM,EX, XX },
13693 +  /* 30 */
13694 +  { "wrmsr",           XX, XX, XX },
13695 +  { "rdtsc",           XX, XX, XX },
13696 +  { "rdmsr",           XX, XX, XX },
13697 +  { "rdpmc",           XX, XX, XX },
13698 +  { "sysenter",                XX, XX, XX },
13699 +  { "sysexit",         XX, XX, XX },
13700 +  { "(bad)",           XX, XX, XX },
13701 +  { "(bad)",           XX, XX, XX },
13702 +  /* 38 */
13703 +  { "(bad)",           XX, XX, XX },
13704 +  { "(bad)",           XX, XX, XX },
13705 +  { "(bad)",           XX, XX, XX },
13706 +  { "(bad)",           XX, XX, XX },
13707 +  { "(bad)",           XX, XX, XX },
13708 +  { "(bad)",           XX, XX, XX },
13709 +  { "(bad)",           XX, XX, XX },
13710 +  { "(bad)",           XX, XX, XX },
13711 +  /* 40 */
13712 +  { "cmovo",           Gv, Ev, XX },
13713 +  { "cmovno",          Gv, Ev, XX },
13714 +  { "cmovb",           Gv, Ev, XX },
13715 +  { "cmovae",          Gv, Ev, XX },
13716 +  { "cmove",           Gv, Ev, XX },
13717 +  { "cmovne",          Gv, Ev, XX },
13718 +  { "cmovbe",          Gv, Ev, XX },
13719 +  { "cmova",           Gv, Ev, XX },
13720 +  /* 48 */
13721 +  { "cmovs",           Gv, Ev, XX },
13722 +  { "cmovns",          Gv, Ev, XX },
13723 +  { "cmovp",           Gv, Ev, XX },
13724 +  { "cmovnp",          Gv, Ev, XX },
13725 +  { "cmovl",           Gv, Ev, XX },
13726 +  { "cmovge",          Gv, Ev, XX },
13727 +  { "cmovle",          Gv, Ev, XX },
13728 +  { "cmovg",           Gv, Ev, XX },
13729 +  /* 50 */
13730 +  { "movmskpX",                Gdq, XS, XX },
13731 +  { PREGRP13 },
13732 +  { PREGRP12 },
13733 +  { PREGRP11 },
13734 +  { "andpX",           XM, EX, XX },
13735 +  { "andnpX",          XM, EX, XX },
13736 +  { "orpX",            XM, EX, XX },
13737 +  { "xorpX",           XM, EX, XX },
13738 +  /* 58 */
13739 +  { PREGRP0 },
13740 +  { PREGRP10 },
13741 +  { PREGRP17 },
13742 +  { PREGRP16 },
13743 +  { PREGRP14 },
13744 +  { PREGRP7 },
13745 +  { PREGRP5 },
13746 +  { PREGRP6 },
13747 +  /* 60 */
13748 +  { "punpcklbw",       MX, EM, XX },
13749 +  { "punpcklwd",       MX, EM, XX },
13750 +  { "punpckldq",       MX, EM, XX },
13751 +  { "packsswb",                MX, EM, XX },
13752 +  { "pcmpgtb",         MX, EM, XX },
13753 +  { "pcmpgtw",         MX, EM, XX },
13754 +  { "pcmpgtd",         MX, EM, XX },
13755 +  { "packuswb",                MX, EM, XX },
13756 +  /* 68 */
13757 +  { "punpckhbw",       MX, EM, XX },
13758 +  { "punpckhwd",       MX, EM, XX },
13759 +  { "punpckhdq",       MX, EM, XX },
13760 +  { "packssdw",                MX, EM, XX },
13761 +  { PREGRP26 },
13762 +  { PREGRP24 },
13763 +  { "movd",            MX, Edq, XX },
13764 +  { PREGRP19 },
13765 +  /* 70 */
13766 +  { PREGRP22 },
13767 +  { GRP10 },
13768 +  { GRP11 },
13769 +  { GRP12 },
13770 +  { "pcmpeqb",         MX, EM, XX },
13771 +  { "pcmpeqw",         MX, EM, XX },
13772 +  { "pcmpeqd",         MX, EM, XX },
13773 +  { "emms",            XX, XX, XX },
13774 +  /* 78 */
13775 +  { "vmread",          Em, Gm, XX },
13776 +  { "vmwrite",         Gm, Em, XX },
13777 +  { "(bad)",           XX, XX, XX },
13778 +  { "(bad)",           XX, XX, XX },
13779 +  { PREGRP28 },
13780 +  { PREGRP29 },
13781 +  { PREGRP23 },
13782 +  { PREGRP20 },
13783 +  /* 80 */
13784 +  { "joH",             Jv, XX, cond_jump_flag },
13785 +  { "jnoH",            Jv, XX, cond_jump_flag },
13786 +  { "jbH",             Jv, XX, cond_jump_flag },
13787 +  { "jaeH",            Jv, XX, cond_jump_flag },
13788 +  { "jeH",             Jv, XX, cond_jump_flag },
13789 +  { "jneH",            Jv, XX, cond_jump_flag },
13790 +  { "jbeH",            Jv, XX, cond_jump_flag },
13791 +  { "jaH",             Jv, XX, cond_jump_flag },
13792 +  /* 88 */
13793 +  { "jsH",             Jv, XX, cond_jump_flag },
13794 +  { "jnsH",            Jv, XX, cond_jump_flag },
13795 +  { "jpH",             Jv, XX, cond_jump_flag },
13796 +  { "jnpH",            Jv, XX, cond_jump_flag },
13797 +  { "jlH",             Jv, XX, cond_jump_flag },
13798 +  { "jgeH",            Jv, XX, cond_jump_flag },
13799 +  { "jleH",            Jv, XX, cond_jump_flag },
13800 +  { "jgH",             Jv, XX, cond_jump_flag },
13801 +  /* 90 */
13802 +  { "seto",            Eb, XX, XX },
13803 +  { "setno",           Eb, XX, XX },
13804 +  { "setb",            Eb, XX, XX },
13805 +  { "setae",           Eb, XX, XX },
13806 +  { "sete",            Eb, XX, XX },
13807 +  { "setne",           Eb, XX, XX },
13808 +  { "setbe",           Eb, XX, XX },
13809 +  { "seta",            Eb, XX, XX },
13810 +  /* 98 */
13811 +  { "sets",            Eb, XX, XX },
13812 +  { "setns",           Eb, XX, XX },
13813 +  { "setp",            Eb, XX, XX },
13814 +  { "setnp",           Eb, XX, XX },
13815 +  { "setl",            Eb, XX, XX },
13816 +  { "setge",           Eb, XX, XX },
13817 +  { "setle",           Eb, XX, XX },
13818 +  { "setg",            Eb, XX, XX },
13819 +  /* a0 */
13820 +  { "pushT",           fs, XX, XX },
13821 +  { "popT",            fs, XX, XX },
13822 +  { "cpuid",           XX, XX, XX },
13823 +  { "btS",             Ev, Gv, XX },
13824 +  { "shldS",           Ev, Gv, Ib },
13825 +  { "shldS",           Ev, Gv, CL },
13826 +  { GRPPADLCK2 },
13827 +  { GRPPADLCK1 },
13828 +  /* a8 */
13829 +  { "pushT",           gs, XX, XX },
13830 +  { "popT",            gs, XX, XX },
13831 +  { "rsm",             XX, XX, XX },
13832 +  { "btsS",            Ev, Gv, XX },
13833 +  { "shrdS",           Ev, Gv, Ib },
13834 +  { "shrdS",           Ev, Gv, CL },
13835 +  { GRP13 },
13836 +  { "imulS",           Gv, Ev, XX },
13837 +  /* b0 */
13838 +  { "cmpxchgB",                Eb, Gb, XX },
13839 +  { "cmpxchgS",                Ev, Gv, XX },
13840 +  { "lssS",            Gv, Mp, XX },
13841 +  { "btrS",            Ev, Gv, XX },
13842 +  { "lfsS",            Gv, Mp, XX },
13843 +  { "lgsS",            Gv, Mp, XX },
13844 +  { "movz{bR|x|bR|x}", Gv, Eb, XX },
13845 +  { "movz{wR|x|wR|x}", Gv, Ew, XX }, /* yes, there really is movzww ! */
13846 +  /* b8 */
13847 +  { "(bad)",           XX, XX, XX },
13848 +  { "ud2b",            XX, XX, XX },
13849 +  { GRP8 },
13850 +  { "btcS",            Ev, Gv, XX },
13851 +  { "bsfS",            Gv, Ev, XX },
13852 +  { "bsrS",            Gv, Ev, XX },
13853 +  { "movs{bR|x|bR|x}", Gv, Eb, XX },
13854 +  { "movs{wR|x|wR|x}", Gv, Ew, XX }, /* yes, there really is movsww ! */
13855 +  /* c0 */
13856 +  { "xaddB",           Eb, Gb, XX },
13857 +  { "xaddS",           Ev, Gv, XX },
13858 +  { PREGRP1 },
13859 +  { "movntiS",         Ev, Gv, XX },
13860 +  { "pinsrw",          MX, Edqw, Ib },
13861 +  { "pextrw",          Gdq, MS, Ib },
13862 +  { "shufpX",          XM, EX, Ib },
13863 +  { GRP9 },
13864 +  /* c8 */
13865 +  { "bswap",           RMeAX, XX, XX },
13866 +  { "bswap",           RMeCX, XX, XX },
13867 +  { "bswap",           RMeDX, XX, XX },
13868 +  { "bswap",           RMeBX, XX, XX },
13869 +  { "bswap",           RMeSP, XX, XX },
13870 +  { "bswap",           RMeBP, XX, XX },
13871 +  { "bswap",           RMeSI, XX, XX },
13872 +  { "bswap",           RMeDI, XX, XX },
13873 +  /* d0 */
13874 +  { PREGRP27 },
13875 +  { "psrlw",           MX, EM, XX },
13876 +  { "psrld",           MX, EM, XX },
13877 +  { "psrlq",           MX, EM, XX },
13878 +  { "paddq",           MX, EM, XX },
13879 +  { "pmullw",          MX, EM, XX },
13880 +  { PREGRP21 },
13881 +  { "pmovmskb",                Gdq, MS, XX },
13882 +  /* d8 */
13883 +  { "psubusb",         MX, EM, XX },
13884 +  { "psubusw",         MX, EM, XX },
13885 +  { "pminub",          MX, EM, XX },
13886 +  { "pand",            MX, EM, XX },
13887 +  { "paddusb",         MX, EM, XX },
13888 +  { "paddusw",         MX, EM, XX },
13889 +  { "pmaxub",          MX, EM, XX },
13890 +  { "pandn",           MX, EM, XX },
13891 +  /* e0 */
13892 +  { "pavgb",           MX, EM, XX },
13893 +  { "psraw",           MX, EM, XX },
13894 +  { "psrad",           MX, EM, XX },
13895 +  { "pavgw",           MX, EM, XX },
13896 +  { "pmulhuw",         MX, EM, XX },
13897 +  { "pmulhw",          MX, EM, XX },
13898 +  { PREGRP15 },
13899 +  { PREGRP25 },
13900 +  /* e8 */
13901 +  { "psubsb",          MX, EM, XX },
13902 +  { "psubsw",          MX, EM, XX },
13903 +  { "pminsw",          MX, EM, XX },
13904 +  { "por",             MX, EM, XX },
13905 +  { "paddsb",          MX, EM, XX },
13906 +  { "paddsw",          MX, EM, XX },
13907 +  { "pmaxsw",          MX, EM, XX },
13908 +  { "pxor",            MX, EM, XX },
13909 +  /* f0 */
13910 +  { PREGRP32 },
13911 +  { "psllw",           MX, EM, XX },
13912 +  { "pslld",           MX, EM, XX },
13913 +  { "psllq",           MX, EM, XX },
13914 +  { "pmuludq",         MX, EM, XX },
13915 +  { "pmaddwd",         MX, EM, XX },
13916 +  { "psadbw",          MX, EM, XX },
13917 +  { PREGRP18 },
13918 +  /* f8 */
13919 +  { "psubb",           MX, EM, XX },
13920 +  { "psubw",           MX, EM, XX },
13921 +  { "psubd",           MX, EM, XX },
13922 +  { "psubq",           MX, EM, XX },
13923 +  { "paddb",           MX, EM, XX },
13924 +  { "paddw",           MX, EM, XX },
13925 +  { "paddd",           MX, EM, XX },
13926 +  { "(bad)",           XX, XX, XX }
13927 +};
13928 +
13929 +static const unsigned char onebyte_has_modrm[256] = {
13930 +  /*      0 1 2 3 4 5 6 7 8 9 a b c d e f        */
13931 +  /*      -------------------------------        */
13932 +  /* 00 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0, /* 00 */
13933 +  /* 10 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0, /* 10 */
13934 +  /* 20 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0, /* 20 */
13935 +  /* 30 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0, /* 30 */
13936 +  /* 40 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 40 */
13937 +  /* 50 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 50 */
13938 +  /* 60 */ 0,0,1,1,0,0,0,0,0,1,0,1,0,0,0,0, /* 60 */
13939 +  /* 70 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 70 */
13940 +  /* 80 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 80 */
13941 +  /* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 90 */
13942 +  /* a0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* a0 */
13943 +  /* b0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* b0 */
13944 +  /* c0 */ 1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0, /* c0 */
13945 +  /* d0 */ 1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1, /* d0 */
13946 +  /* e0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* e0 */
13947 +  /* f0 */ 0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1  /* f0 */
13948 +  /*      -------------------------------        */
13949 +  /*      0 1 2 3 4 5 6 7 8 9 a b c d e f        */
13950 +};
13951 +
13952 +static const unsigned char twobyte_has_modrm[256] = {
13953 +  /*      0 1 2 3 4 5 6 7 8 9 a b c d e f        */
13954 +  /*      -------------------------------        */
13955 +  /* 00 */ 1,1,1,1,0,0,0,0,0,0,0,0,0,1,0,1, /* 0f */
13956 +  /* 10 */ 1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0, /* 1f */
13957 +  /* 20 */ 1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1, /* 2f */
13958 +  /* 30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 3f */
13959 +  /* 40 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 4f */
13960 +  /* 50 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 5f */
13961 +  /* 60 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 6f */
13962 +  /* 70 */ 1,1,1,1,1,1,1,0,1,1,0,0,1,1,1,1, /* 7f */
13963 +  /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */
13964 +  /* 90 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 9f */
13965 +  /* a0 */ 0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1, /* af */
13966 +  /* b0 */ 1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1, /* bf */
13967 +  /* c0 */ 1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, /* cf */
13968 +  /* d0 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* df */
13969 +  /* e0 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* ef */
13970 +  /* f0 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0  /* ff */
13971 +  /*      -------------------------------        */
13972 +  /*      0 1 2 3 4 5 6 7 8 9 a b c d e f        */
13973 +};
13974 +
13975 +static const unsigned char twobyte_uses_SSE_prefix[256] = {
13976 +  /*      0 1 2 3 4 5 6 7 8 9 a b c d e f        */
13977 +  /*      -------------------------------        */
13978 +  /* 00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0f */
13979 +  /* 10 */ 1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0, /* 1f */
13980 +  /* 20 */ 0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,0, /* 2f */
13981 +  /* 30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 3f */
13982 +  /* 40 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 4f */
13983 +  /* 50 */ 0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1, /* 5f */
13984 +  /* 60 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1, /* 6f */
13985 +  /* 70 */ 1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1, /* 7f */
13986 +  /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */
13987 +  /* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 9f */
13988 +  /* a0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* af */
13989 +  /* b0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* bf */
13990 +  /* c0 */ 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, /* cf */
13991 +  /* d0 */ 1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0, /* df */
13992 +  /* e0 */ 0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0, /* ef */
13993 +  /* f0 */ 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0  /* ff */
13994 +  /*      -------------------------------        */
13995 +  /*      0 1 2 3 4 5 6 7 8 9 a b c d e f        */
13996 +};
13997 +
13998 +static char obuf[100];
13999 +static char *obufp;
14000 +static char scratchbuf[100];
14001 +static unsigned char *start_codep;
14002 +static unsigned char *insn_codep;
14003 +static unsigned char *codep;
14004 +static disassemble_info *the_info;
14005 +static int mod;
14006 +static int rm;
14007 +static int reg;
14008 +static unsigned char need_modrm;
14009 +
14010 +/* If we are accessing mod/rm/reg without need_modrm set, then the
14011 +   values are stale.  Hitting this abort likely indicates that you
14012 +   need to update onebyte_has_modrm or twobyte_has_modrm.  */
14013 +#define MODRM_CHECK  if (!need_modrm) abort ()
14014 +
14015 +static const char **names64;
14016 +static const char **names32;
14017 +static const char **names16;
14018 +static const char **names8;
14019 +static const char **names8rex;
14020 +static const char **names_seg;
14021 +static const char **index16;
14022 +
14023 +static const char *intel_names64[] = {
14024 +  "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
14025 +  "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
14026 +};
14027 +static const char *intel_names32[] = {
14028 +  "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
14029 +  "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d"
14030 +};
14031 +static const char *intel_names16[] = {
14032 +  "ax", "cx", "dx", "bx", "sp", "bp", "si", "di",
14033 +  "r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w"
14034 +};
14035 +static const char *intel_names8[] = {
14036 +  "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh",
14037 +};
14038 +static const char *intel_names8rex[] = {
14039 +  "al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil",
14040 +  "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b"
14041 +};
14042 +static const char *intel_names_seg[] = {
14043 +  "es", "cs", "ss", "ds", "fs", "gs", "?", "?",
14044 +};
14045 +static const char *intel_index16[] = {
14046 +  "bx+si", "bx+di", "bp+si", "bp+di", "si", "di", "bp", "bx"
14047 +};
14048 +
14049 +static const char *att_names64[] = {
14050 +  "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
14051 +  "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15"
14052 +};
14053 +static const char *att_names32[] = {
14054 +  "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
14055 +  "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d"
14056 +};
14057 +static const char *att_names16[] = {
14058 +  "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di",
14059 +  "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w"
14060 +};
14061 +static const char *att_names8[] = {
14062 +  "%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh",
14063 +};
14064 +static const char *att_names8rex[] = {
14065 +  "%al", "%cl", "%dl", "%bl", "%spl", "%bpl", "%sil", "%dil",
14066 +  "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b"
14067 +};
14068 +static const char *att_names_seg[] = {
14069 +  "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "%?", "%?",
14070 +};
14071 +static const char *att_index16[] = {
14072 +  "%bx,%si", "%bx,%di", "%bp,%si", "%bp,%di", "%si", "%di", "%bp", "%bx"
14073 +};
14074 +
14075 +static const struct dis386 grps[][8] = {
14076 +  /* GRP1b */
14077 +  {
14078 +    { "addA",  Eb, Ib, XX },
14079 +    { "orA",   Eb, Ib, XX },
14080 +    { "adcA",  Eb, Ib, XX },
14081 +    { "sbbA",  Eb, Ib, XX },
14082 +    { "andA",  Eb, Ib, XX },
14083 +    { "subA",  Eb, Ib, XX },
14084 +    { "xorA",  Eb, Ib, XX },
14085 +    { "cmpA",  Eb, Ib, XX }
14086 +  },
14087 +  /* GRP1S */
14088 +  {
14089 +    { "addQ",  Ev, Iv, XX },
14090 +    { "orQ",   Ev, Iv, XX },
14091 +    { "adcQ",  Ev, Iv, XX },
14092 +    { "sbbQ",  Ev, Iv, XX },
14093 +    { "andQ",  Ev, Iv, XX },
14094 +    { "subQ",  Ev, Iv, XX },
14095 +    { "xorQ",  Ev, Iv, XX },
14096 +    { "cmpQ",  Ev, Iv, XX }
14097 +  },
14098 +  /* GRP1Ss */
14099 +  {
14100 +    { "addQ",  Ev, sIb, XX },
14101 +    { "orQ",   Ev, sIb, XX },
14102 +    { "adcQ",  Ev, sIb, XX },
14103 +    { "sbbQ",  Ev, sIb, XX },
14104 +    { "andQ",  Ev, sIb, XX },
14105 +    { "subQ",  Ev, sIb, XX },
14106 +    { "xorQ",  Ev, sIb, XX },
14107 +    { "cmpQ",  Ev, sIb, XX }
14108 +  },
14109 +  /* GRP2b */
14110 +  {
14111 +    { "rolA",  Eb, Ib, XX },
14112 +    { "rorA",  Eb, Ib, XX },
14113 +    { "rclA",  Eb, Ib, XX },
14114 +    { "rcrA",  Eb, Ib, XX },
14115 +    { "shlA",  Eb, Ib, XX },
14116 +    { "shrA",  Eb, Ib, XX },
14117 +    { "(bad)", XX, XX, XX },
14118 +    { "sarA",  Eb, Ib, XX },
14119 +  },
14120 +  /* GRP2S */
14121 +  {
14122 +    { "rolQ",  Ev, Ib, XX },
14123 +    { "rorQ",  Ev, Ib, XX },
14124 +    { "rclQ",  Ev, Ib, XX },
14125 +    { "rcrQ",  Ev, Ib, XX },
14126 +    { "shlQ",  Ev, Ib, XX },
14127 +    { "shrQ",  Ev, Ib, XX },
14128 +    { "(bad)", XX, XX, XX },
14129 +    { "sarQ",  Ev, Ib, XX },
14130 +  },
14131 +  /* GRP2b_one */
14132 +  {
14133 +    { "rolA",  Eb, I1, XX },
14134 +    { "rorA",  Eb, I1, XX },
14135 +    { "rclA",  Eb, I1, XX },
14136 +    { "rcrA",  Eb, I1, XX },
14137 +    { "shlA",  Eb, I1, XX },
14138 +    { "shrA",  Eb, I1, XX },
14139 +    { "(bad)", XX, XX, XX },
14140 +    { "sarA",  Eb, I1, XX },
14141 +  },
14142 +  /* GRP2S_one */
14143 +  {
14144 +    { "rolQ",  Ev, I1, XX },
14145 +    { "rorQ",  Ev, I1, XX },
14146 +    { "rclQ",  Ev, I1, XX },
14147 +    { "rcrQ",  Ev, I1, XX },
14148 +    { "shlQ",  Ev, I1, XX },
14149 +    { "shrQ",  Ev, I1, XX },
14150 +    { "(bad)", XX, XX, XX},
14151 +    { "sarQ",  Ev, I1, XX },
14152 +  },
14153 +  /* GRP2b_cl */
14154 +  {
14155 +    { "rolA",  Eb, CL, XX },
14156 +    { "rorA",  Eb, CL, XX },
14157 +    { "rclA",  Eb, CL, XX },
14158 +    { "rcrA",  Eb, CL, XX },
14159 +    { "shlA",  Eb, CL, XX },
14160 +    { "shrA",  Eb, CL, XX },
14161 +    { "(bad)", XX, XX, XX },
14162 +    { "sarA",  Eb, CL, XX },
14163 +  },
14164 +  /* GRP2S_cl */
14165 +  {
14166 +    { "rolQ",  Ev, CL, XX },
14167 +    { "rorQ",  Ev, CL, XX },
14168 +    { "rclQ",  Ev, CL, XX },
14169 +    { "rcrQ",  Ev, CL, XX },
14170 +    { "shlQ",  Ev, CL, XX },
14171 +    { "shrQ",  Ev, CL, XX },
14172 +    { "(bad)", XX, XX, XX },
14173 +    { "sarQ",  Ev, CL, XX }
14174 +  },
14175 +  /* GRP3b */
14176 +  {
14177 +    { "testA", Eb, Ib, XX },
14178 +    { "(bad)", Eb, XX, XX },
14179 +    { "notA",  Eb, XX, XX },
14180 +    { "negA",  Eb, XX, XX },
14181 +    { "mulA",  Eb, XX, XX },   /* Don't print the implicit %al register,  */
14182 +    { "imulA", Eb, XX, XX },   /* to distinguish these opcodes from other */
14183 +    { "divA",  Eb, XX, XX },   /* mul/imul opcodes.  Do the same for div  */
14184 +    { "idivA", Eb, XX, XX }    /* and idiv for consistency.               */
14185 +  },
14186 +  /* GRP3S */
14187 +  {
14188 +    { "testQ", Ev, Iv, XX },
14189 +    { "(bad)", XX, XX, XX },
14190 +    { "notQ",  Ev, XX, XX },
14191 +    { "negQ",  Ev, XX, XX },
14192 +    { "mulQ",  Ev, XX, XX },   /* Don't print the implicit register.  */
14193 +    { "imulQ", Ev, XX, XX },
14194 +    { "divQ",  Ev, XX, XX },
14195 +    { "idivQ", Ev, XX, XX },
14196 +  },
14197 +  /* GRP4 */
14198 +  {
14199 +    { "incA",  Eb, XX, XX },
14200 +    { "decA",  Eb, XX, XX },
14201 +    { "(bad)", XX, XX, XX },
14202 +    { "(bad)", XX, XX, XX },
14203 +    { "(bad)", XX, XX, XX },
14204 +    { "(bad)", XX, XX, XX },
14205 +    { "(bad)", XX, XX, XX },
14206 +    { "(bad)", XX, XX, XX },
14207 +  },
14208 +  /* GRP5 */
14209 +  {
14210 +    { "incQ",  Ev, XX, XX },
14211 +    { "decQ",  Ev, XX, XX },
14212 +    { "callT", indirEv, XX, XX },
14213 +    { "JcallT", indirEp, XX, XX },
14214 +    { "jmpT",  indirEv, XX, XX },
14215 +    { "JjmpT", indirEp, XX, XX },
14216 +    { "pushU", Ev, XX, XX },
14217 +    { "(bad)", XX, XX, XX },
14218 +  },
14219 +  /* GRP6 */
14220 +  {
14221 +    { "sldtQ", Ev, XX, XX },
14222 +    { "strQ",  Ev, XX, XX },
14223 +    { "lldt",  Ew, XX, XX },
14224 +    { "ltr",   Ew, XX, XX },
14225 +    { "verr",  Ew, XX, XX },
14226 +    { "verw",  Ew, XX, XX },
14227 +    { "(bad)", XX, XX, XX },
14228 +    { "(bad)", XX, XX, XX }
14229 +  },
14230 +  /* GRP7 */
14231 +  {
14232 +    { "sgdtIQ", VMX_Fixup, 0, XX, XX },
14233 +    { "sidtIQ", PNI_Fixup, 0, XX, XX },
14234 +    { "lgdt{Q|Q||}",    M, XX, XX },
14235 +    { "lidt{Q|Q||}",    SVME_Fixup, 0, XX, XX },
14236 +    { "smswQ", Ev, XX, XX },
14237 +    { "(bad)", XX, XX, XX },
14238 +    { "lmsw",  Ew, XX, XX },
14239 +    { "invlpg", INVLPG_Fixup, w_mode, XX, XX },
14240 +  },
14241 +  /* GRP8 */
14242 +  {
14243 +    { "(bad)", XX, XX, XX },
14244 +    { "(bad)", XX, XX, XX },
14245 +    { "(bad)", XX, XX, XX },
14246 +    { "(bad)", XX, XX, XX },
14247 +    { "btQ",   Ev, Ib, XX },
14248 +    { "btsQ",  Ev, Ib, XX },
14249 +    { "btrQ",  Ev, Ib, XX },
14250 +    { "btcQ",  Ev, Ib, XX },
14251 +  },
14252 +  /* GRP9 */
14253 +  {
14254 +    { "(bad)", XX, XX, XX },
14255 +    { "cmpxchg8b", Eq, XX, XX },
14256 +    { "(bad)", XX, XX, XX },
14257 +    { "(bad)", XX, XX, XX },
14258 +    { "(bad)", XX, XX, XX },
14259 +    { "(bad)", XX, XX, XX },
14260 +    { "",      VM, XX, XX },           /* See OP_VMX.  */
14261 +    { "vmptrst", Eq, XX, XX },
14262 +  },
14263 +  /* GRP10 */
14264 +  {
14265 +    { "(bad)", XX, XX, XX },
14266 +    { "(bad)", XX, XX, XX },
14267 +    { "psrlw", MS, Ib, XX },
14268 +    { "(bad)", XX, XX, XX },
14269 +    { "psraw", MS, Ib, XX },
14270 +    { "(bad)", XX, XX, XX },
14271 +    { "psllw", MS, Ib, XX },
14272 +    { "(bad)", XX, XX, XX },
14273 +  },
14274 +  /* GRP11 */
14275 +  {
14276 +    { "(bad)", XX, XX, XX },
14277 +    { "(bad)", XX, XX, XX },
14278 +    { "psrld", MS, Ib, XX },
14279 +    { "(bad)", XX, XX, XX },
14280 +    { "psrad", MS, Ib, XX },
14281 +    { "(bad)", XX, XX, XX },
14282 +    { "pslld", MS, Ib, XX },
14283 +    { "(bad)", XX, XX, XX },
14284 +  },
14285 +  /* GRP12 */
14286 +  {
14287 +    { "(bad)", XX, XX, XX },
14288 +    { "(bad)", XX, XX, XX },
14289 +    { "psrlq", MS, Ib, XX },
14290 +    { "psrldq", MS, Ib, XX },
14291 +    { "(bad)", XX, XX, XX },
14292 +    { "(bad)", XX, XX, XX },
14293 +    { "psllq", MS, Ib, XX },
14294 +    { "pslldq", MS, Ib, XX },
14295 +  },
14296 +  /* GRP13 */
14297 +  {
14298 +    { "fxsave", Ev, XX, XX },
14299 +    { "fxrstor", Ev, XX, XX },
14300 +    { "ldmxcsr", Ev, XX, XX },
14301 +    { "stmxcsr", Ev, XX, XX },
14302 +    { "(bad)", XX, XX, XX },
14303 +    { "lfence", OP_0fae, 0, XX, XX },
14304 +    { "mfence", OP_0fae, 0, XX, XX },
14305 +    { "clflush", OP_0fae, 0, XX, XX },
14306 +  },
14307 +  /* GRP14 */
14308 +  {
14309 +    { "prefetchnta", Ev, XX, XX },
14310 +    { "prefetcht0", Ev, XX, XX },
14311 +    { "prefetcht1", Ev, XX, XX },
14312 +    { "prefetcht2", Ev, XX, XX },
14313 +    { "(bad)", XX, XX, XX },
14314 +    { "(bad)", XX, XX, XX },
14315 +    { "(bad)", XX, XX, XX },
14316 +    { "(bad)", XX, XX, XX },
14317 +  },
14318 +  /* GRPAMD */
14319 +  {
14320 +    { "prefetch", Eb, XX, XX },
14321 +    { "prefetchw", Eb, XX, XX },
14322 +    { "(bad)", XX, XX, XX },
14323 +    { "(bad)", XX, XX, XX },
14324 +    { "(bad)", XX, XX, XX },
14325 +    { "(bad)", XX, XX, XX },
14326 +    { "(bad)", XX, XX, XX },
14327 +    { "(bad)", XX, XX, XX },
14328 +  },
14329 +  /* GRPPADLCK1 */
14330 +  {
14331 +    { "xstore-rng", OP_0f07, 0, XX, XX },
14332 +    { "xcrypt-ecb", OP_0f07, 0, XX, XX },
14333 +    { "xcrypt-cbc", OP_0f07, 0, XX, XX },
14334 +    { "xcrypt-ctr", OP_0f07, 0, XX, XX },
14335 +    { "xcrypt-cfb", OP_0f07, 0, XX, XX },
14336 +    { "xcrypt-ofb", OP_0f07, 0, XX, XX },
14337 +    { "(bad)", OP_0f07, 0, XX, XX },
14338 +    { "(bad)", OP_0f07, 0, XX, XX },
14339 +  },
14340 +  /* GRPPADLCK2 */
14341 +  {
14342 +    { "montmul", OP_0f07, 0, XX, XX },
14343 +    { "xsha1",  OP_0f07, 0, XX, XX },
14344 +    { "xsha256", OP_0f07, 0, XX, XX },
14345 +    { "(bad)",  OP_0f07, 0, XX, XX },
14346 +    { "(bad)",  OP_0f07, 0, XX, XX },
14347 +    { "(bad)",  OP_0f07, 0, XX, XX },
14348 +    { "(bad)",  OP_0f07, 0, XX, XX },
14349 +    { "(bad)",  OP_0f07, 0, XX, XX },
14350 +  }
14351 +};
14352 +
14353 +static const struct dis386 prefix_user_table[][4] = {
14354 +  /* PREGRP0 */
14355 +  {
14356 +    { "addps", XM, EX, XX },
14357 +    { "addss", XM, EX, XX },
14358 +    { "addpd", XM, EX, XX },
14359 +    { "addsd", XM, EX, XX },
14360 +  },
14361 +  /* PREGRP1 */
14362 +  {
14363 +    { "", XM, EX, OPSIMD },    /* See OP_SIMD_SUFFIX.  */
14364 +    { "", XM, EX, OPSIMD },
14365 +    { "", XM, EX, OPSIMD },
14366 +    { "", XM, EX, OPSIMD },
14367 +  },
14368 +  /* PREGRP2 */
14369 +  {
14370 +    { "cvtpi2ps", XM, EM, XX },
14371 +    { "cvtsi2ssY", XM, Ev, XX },
14372 +    { "cvtpi2pd", XM, EM, XX },
14373 +    { "cvtsi2sdY", XM, Ev, XX },
14374 +  },
14375 +  /* PREGRP3 */
14376 +  {
14377 +    { "cvtps2pi", MX, EX, XX },
14378 +    { "cvtss2siY", Gv, EX, XX },
14379 +    { "cvtpd2pi", MX, EX, XX },
14380 +    { "cvtsd2siY", Gv, EX, XX },
14381 +  },
14382 +  /* PREGRP4 */
14383 +  {
14384 +    { "cvttps2pi", MX, EX, XX },
14385 +    { "cvttss2siY", Gv, EX, XX },
14386 +    { "cvttpd2pi", MX, EX, XX },
14387 +    { "cvttsd2siY", Gv, EX, XX },
14388 +  },
14389 +  /* PREGRP5 */
14390 +  {
14391 +    { "divps", XM, EX, XX },
14392 +    { "divss", XM, EX, XX },
14393 +    { "divpd", XM, EX, XX },
14394 +    { "divsd", XM, EX, XX },
14395 +  },
14396 +  /* PREGRP6 */
14397 +  {
14398 +    { "maxps", XM, EX, XX },
14399 +    { "maxss", XM, EX, XX },
14400 +    { "maxpd", XM, EX, XX },
14401 +    { "maxsd", XM, EX, XX },
14402 +  },
14403 +  /* PREGRP7 */
14404 +  {
14405 +    { "minps", XM, EX, XX },
14406 +    { "minss", XM, EX, XX },
14407 +    { "minpd", XM, EX, XX },
14408 +    { "minsd", XM, EX, XX },
14409 +  },
14410 +  /* PREGRP8 */
14411 +  {
14412 +    { "movups", XM, EX, XX },
14413 +    { "movss", XM, EX, XX },
14414 +    { "movupd", XM, EX, XX },
14415 +    { "movsd", XM, EX, XX },
14416 +  },
14417 +  /* PREGRP9 */
14418 +  {
14419 +    { "movups", EX, XM, XX },
14420 +    { "movss", EX, XM, XX },
14421 +    { "movupd", EX, XM, XX },
14422 +    { "movsd", EX, XM, XX },
14423 +  },
14424 +  /* PREGRP10 */
14425 +  {
14426 +    { "mulps", XM, EX, XX },
14427 +    { "mulss", XM, EX, XX },
14428 +    { "mulpd", XM, EX, XX },
14429 +    { "mulsd", XM, EX, XX },
14430 +  },
14431 +  /* PREGRP11 */
14432 +  {
14433 +    { "rcpps", XM, EX, XX },
14434 +    { "rcpss", XM, EX, XX },
14435 +    { "(bad)", XM, EX, XX },
14436 +    { "(bad)", XM, EX, XX },
14437 +  },
14438 +  /* PREGRP12 */
14439 +  {
14440 +    { "rsqrtps", XM, EX, XX },
14441 +    { "rsqrtss", XM, EX, XX },
14442 +    { "(bad)", XM, EX, XX },
14443 +    { "(bad)", XM, EX, XX },
14444 +  },
14445 +  /* PREGRP13 */
14446 +  {
14447 +    { "sqrtps", XM, EX, XX },
14448 +    { "sqrtss", XM, EX, XX },
14449 +    { "sqrtpd", XM, EX, XX },
14450 +    { "sqrtsd", XM, EX, XX },
14451 +  },
14452 +  /* PREGRP14 */
14453 +  {
14454 +    { "subps", XM, EX, XX },
14455 +    { "subss", XM, EX, XX },
14456 +    { "subpd", XM, EX, XX },
14457 +    { "subsd", XM, EX, XX },
14458 +  },
14459 +  /* PREGRP15 */
14460 +  {
14461 +    { "(bad)", XM, EX, XX },
14462 +    { "cvtdq2pd", XM, EX, XX },
14463 +    { "cvttpd2dq", XM, EX, XX },
14464 +    { "cvtpd2dq", XM, EX, XX },
14465 +  },
14466 +  /* PREGRP16 */
14467 +  {
14468 +    { "cvtdq2ps", XM, EX, XX },
14469 +    { "cvttps2dq",XM, EX, XX },
14470 +    { "cvtps2dq",XM, EX, XX },
14471 +    { "(bad)", XM, EX, XX },
14472 +  },
14473 +  /* PREGRP17 */
14474 +  {
14475 +    { "cvtps2pd", XM, EX, XX },
14476 +    { "cvtss2sd", XM, EX, XX },
14477 +    { "cvtpd2ps", XM, EX, XX },
14478 +    { "cvtsd2ss", XM, EX, XX },
14479 +  },
14480 +  /* PREGRP18 */
14481 +  {
14482 +    { "maskmovq", MX, MS, XX },
14483 +    { "(bad)", XM, EX, XX },
14484 +    { "maskmovdqu", XM, EX, XX },
14485 +    { "(bad)", XM, EX, XX },
14486 +  },
14487 +  /* PREGRP19 */
14488 +  {
14489 +    { "movq", MX, EM, XX },
14490 +    { "movdqu", XM, EX, XX },
14491 +    { "movdqa", XM, EX, XX },
14492 +    { "(bad)", XM, EX, XX },
14493 +  },
14494 +  /* PREGRP20 */
14495 +  {
14496 +    { "movq", EM, MX, XX },
14497 +    { "movdqu", EX, XM, XX },
14498 +    { "movdqa", EX, XM, XX },
14499 +    { "(bad)", EX, XM, XX },
14500 +  },
14501 +  /* PREGRP21 */
14502 +  {
14503 +    { "(bad)", EX, XM, XX },
14504 +    { "movq2dq", XM, MS, XX },
14505 +    { "movq", EX, XM, XX },
14506 +    { "movdq2q", MX, XS, XX },
14507 +  },
14508 +  /* PREGRP22 */
14509 +  {
14510 +    { "pshufw", MX, EM, Ib },
14511 +    { "pshufhw", XM, EX, Ib },
14512 +    { "pshufd", XM, EX, Ib },
14513 +    { "pshuflw", XM, EX, Ib },
14514 +  },
14515 +  /* PREGRP23 */
14516 +  {
14517 +    { "movd", Edq, MX, XX },
14518 +    { "movq", XM, EX, XX },
14519 +    { "movd", Edq, XM, XX },
14520 +    { "(bad)", Ed, XM, XX },
14521 +  },
14522 +  /* PREGRP24 */
14523 +  {
14524 +    { "(bad)", MX, EX, XX },
14525 +    { "(bad)", XM, EX, XX },
14526 +    { "punpckhqdq", XM, EX, XX },
14527 +    { "(bad)", XM, EX, XX },
14528 +  },
14529 +  /* PREGRP25 */
14530 +  {
14531 +    { "movntq", EM, MX, XX },
14532 +    { "(bad)", EM, XM, XX },
14533 +    { "movntdq", EM, XM, XX },
14534 +    { "(bad)", EM, XM, XX },
14535 +  },
14536 +  /* PREGRP26 */
14537 +  {
14538 +    { "(bad)", MX, EX, XX },
14539 +    { "(bad)", XM, EX, XX },
14540 +    { "punpcklqdq", XM, EX, XX },
14541 +    { "(bad)", XM, EX, XX },
14542 +  },
14543 +  /* PREGRP27 */
14544 +  {
14545 +    { "(bad)", MX, EX, XX },
14546 +    { "(bad)", XM, EX, XX },
14547 +    { "addsubpd", XM, EX, XX },
14548 +    { "addsubps", XM, EX, XX },
14549 +  },
14550 +  /* PREGRP28 */
14551 +  {
14552 +    { "(bad)", MX, EX, XX },
14553 +    { "(bad)", XM, EX, XX },
14554 +    { "haddpd", XM, EX, XX },
14555 +    { "haddps", XM, EX, XX },
14556 +  },
14557 +  /* PREGRP29 */
14558 +  {
14559 +    { "(bad)", MX, EX, XX },
14560 +    { "(bad)", XM, EX, XX },
14561 +    { "hsubpd", XM, EX, XX },
14562 +    { "hsubps", XM, EX, XX },
14563 +  },
14564 +  /* PREGRP30 */
14565 +  {
14566 +    { "movlpX", XM, EX, SIMD_Fixup, 'h' }, /* really only 2 operands */
14567 +    { "movsldup", XM, EX, XX },
14568 +    { "movlpd", XM, EX, XX },
14569 +    { "movddup", XM, EX, XX },
14570 +  },
14571 +  /* PREGRP31 */
14572 +  {
14573 +    { "movhpX", XM, EX, SIMD_Fixup, 'l' },
14574 +    { "movshdup", XM, EX, XX },
14575 +    { "movhpd", XM, EX, XX },
14576 +    { "(bad)", XM, EX, XX },
14577 +  },
14578 +  /* PREGRP32 */
14579 +  {
14580 +    { "(bad)", XM, EX, XX },
14581 +    { "(bad)", XM, EX, XX },
14582 +    { "(bad)", XM, EX, XX },
14583 +    { "lddqu", XM, M, XX },
14584 +  },
14585 +};
14586 +
14587 +static const struct dis386 x86_64_table[][2] = {
14588 +  {
14589 +    { "arpl", Ew, Gw, XX },
14590 +    { "movs{||lq|xd}", Gv, Ed, XX },
14591 +  },
14592 +};
14593 +
14594 +#ifdef __KERNEL__
14595 +#define INTERNAL_DISASSEMBLER_ERROR "<internal disassembler error>"
14596 +#else  /* __KERNEL__ */
14597 +#define INTERNAL_DISASSEMBLER_ERROR _("<internal disassembler error>")
14598 +#endif /* __KERNEL__ */
14599 +
14600 +static void
14601 +ckprefix (void)
14602 +{
14603 +  int newrex;
14604 +  rex = 0;
14605 +  prefixes = 0;
14606 +  used_prefixes = 0;
14607 +  rex_used = 0;
14608 +  while (1)
14609 +    {
14610 +      FETCH_DATA (the_info, codep + 1);
14611 +      newrex = 0;
14612 +      switch (*codep)
14613 +       {
14614 +       /* REX prefixes family.  */
14615 +       case 0x40:
14616 +       case 0x41:
14617 +       case 0x42:
14618 +       case 0x43:
14619 +       case 0x44:
14620 +       case 0x45:
14621 +       case 0x46:
14622 +       case 0x47:
14623 +       case 0x48:
14624 +       case 0x49:
14625 +       case 0x4a:
14626 +       case 0x4b:
14627 +       case 0x4c:
14628 +       case 0x4d:
14629 +       case 0x4e:
14630 +       case 0x4f:
14631 +           if (mode_64bit)
14632 +             newrex = *codep;
14633 +           else
14634 +             return;
14635 +         break;
14636 +       case 0xf3:
14637 +         prefixes |= PREFIX_REPZ;
14638 +         break;
14639 +       case 0xf2:
14640 +         prefixes |= PREFIX_REPNZ;
14641 +         break;
14642 +       case 0xf0:
14643 +         prefixes |= PREFIX_LOCK;
14644 +         break;
14645 +       case 0x2e:
14646 +         prefixes |= PREFIX_CS;
14647 +         break;
14648 +       case 0x36:
14649 +         prefixes |= PREFIX_SS;
14650 +         break;
14651 +       case 0x3e:
14652 +         prefixes |= PREFIX_DS;
14653 +         break;
14654 +       case 0x26:
14655 +         prefixes |= PREFIX_ES;
14656 +         break;
14657 +       case 0x64:
14658 +         prefixes |= PREFIX_FS;
14659 +         break;
14660 +       case 0x65:
14661 +         prefixes |= PREFIX_GS;
14662 +         break;
14663 +       case 0x66:
14664 +         prefixes |= PREFIX_DATA;
14665 +         break;
14666 +       case 0x67:
14667 +         prefixes |= PREFIX_ADDR;
14668 +         break;
14669 +       case FWAIT_OPCODE:
14670 +         /* fwait is really an instruction.  If there are prefixes
14671 +            before the fwait, they belong to the fwait, *not* to the
14672 +            following instruction.  */
14673 +         if (prefixes)
14674 +           {
14675 +             prefixes |= PREFIX_FWAIT;
14676 +             codep++;
14677 +             return;
14678 +           }
14679 +         prefixes = PREFIX_FWAIT;
14680 +         break;
14681 +       default:
14682 +         return;
14683 +       }
14684 +      /* Rex is ignored when followed by another prefix.  */
14685 +      if (rex)
14686 +       {
14687 +         oappend (prefix_name (rex, 0));
14688 +         oappend (" ");
14689 +       }
14690 +      rex = newrex;
14691 +      codep++;
14692 +    }
14693 +}
14694 +
14695 +/* Return the name of the prefix byte PREF, or NULL if PREF is not a
14696 +   prefix byte.         */
14697 +
14698 +static const char *
14699 +prefix_name (int pref, int sizeflag)
14700 +{
14701 +  switch (pref)
14702 +    {
14703 +    /* REX prefixes family.  */
14704 +    case 0x40:
14705 +      return "rex";
14706 +    case 0x41:
14707 +      return "rexZ";
14708 +    case 0x42:
14709 +      return "rexY";
14710 +    case 0x43:
14711 +      return "rexYZ";
14712 +    case 0x44:
14713 +      return "rexX";
14714 +    case 0x45:
14715 +      return "rexXZ";
14716 +    case 0x46:
14717 +      return "rexXY";
14718 +    case 0x47:
14719 +      return "rexXYZ";
14720 +    case 0x48:
14721 +      return "rex64";
14722 +    case 0x49:
14723 +      return "rex64Z";
14724 +    case 0x4a:
14725 +      return "rex64Y";
14726 +    case 0x4b:
14727 +      return "rex64YZ";
14728 +    case 0x4c:
14729 +      return "rex64X";
14730 +    case 0x4d:
14731 +      return "rex64XZ";
14732 +    case 0x4e:
14733 +      return "rex64XY";
14734 +    case 0x4f:
14735 +      return "rex64XYZ";
14736 +    case 0xf3:
14737 +      return "repz";
14738 +    case 0xf2:
14739 +      return "repnz";
14740 +    case 0xf0:
14741 +      return "lock";
14742 +    case 0x2e:
14743 +      return "cs";
14744 +    case 0x36:
14745 +      return "ss";
14746 +    case 0x3e:
14747 +      return "ds";
14748 +    case 0x26:
14749 +      return "es";
14750 +    case 0x64:
14751 +      return "fs";
14752 +    case 0x65:
14753 +      return "gs";
14754 +    case 0x66:
14755 +      return (sizeflag & DFLAG) ? "data16" : "data32";
14756 +    case 0x67:
14757 +      if (mode_64bit)
14758 +       return (sizeflag & AFLAG) ? "addr32" : "addr64";
14759 +      else
14760 +       return (sizeflag & AFLAG) ? "addr16" : "addr32";
14761 +    case FWAIT_OPCODE:
14762 +      return "fwait";
14763 +    default:
14764 +      return NULL;
14765 +    }
14766 +}
14767 +
14768 +static char op1out[100], op2out[100], op3out[100];
14769 +static int op_ad, op_index[3];
14770 +static int two_source_ops;
14771 +static bfd_vma op_address[3];
14772 +static bfd_vma op_riprel[3];
14773 +static bfd_vma start_pc;
14774 +
14775 +/*
14776 + *   On the 386's of 1988, the maximum length of an instruction is 15 bytes.
14777 + *   (see topic "Redundant prefixes" in the "Differences from 8086"
14778 + *   section of the "Virtual 8086 Mode" chapter.)
14779 + * 'pc' should be the address of this instruction, it will
14780 + *   be used to print the target address if this is a relative jump or call
14781 + * The function returns the length of this instruction in bytes.
14782 + */
14783 +
14784 +static char intel_syntax;
14785 +static char open_char;
14786 +static char close_char;
14787 +static char separator_char;
14788 +static char scale_char;
14789 +
14790 +/* Here for backwards compatibility.  When gdb stops using
14791 +   print_insn_i386_att and print_insn_i386_intel these functions can
14792 +   disappear, and print_insn_i386 be merged into print_insn.  */
14793 +int
14794 +print_insn_i386_att (bfd_vma pc, disassemble_info *info)
14795 +{
14796 +  intel_syntax = 0;
14797 +
14798 +  return print_insn (pc, info);
14799 +}
14800 +
14801 +int
14802 +print_insn_i386_intel (bfd_vma pc, disassemble_info *info)
14803 +{
14804 +  intel_syntax = 1;
14805 +
14806 +  return print_insn (pc, info);
14807 +}
14808 +
14809 +int
14810 +print_insn_i386 (bfd_vma pc, disassemble_info *info)
14811 +{
14812 +  intel_syntax = -1;
14813 +
14814 +  return print_insn (pc, info);
14815 +}
14816 +
14817 +static int
14818 +print_insn (bfd_vma pc, disassemble_info *info)
14819 +{
14820 +  const struct dis386 *dp;
14821 +  int i;
14822 +  char *first, *second, *third;
14823 +  int needcomma;
14824 +  unsigned char uses_SSE_prefix, uses_LOCK_prefix;
14825 +  int sizeflag;
14826 +  const char *p;
14827 +  struct dis_private priv;
14828 +
14829 +  mode_64bit = (info->mach == bfd_mach_x86_64_intel_syntax
14830 +               || info->mach == bfd_mach_x86_64);
14831 +
14832 +  if (intel_syntax == (char) -1)
14833 +    intel_syntax = (info->mach == bfd_mach_i386_i386_intel_syntax
14834 +                   || info->mach == bfd_mach_x86_64_intel_syntax);
14835 +
14836 +  if (info->mach == bfd_mach_i386_i386
14837 +      || info->mach == bfd_mach_x86_64
14838 +      || info->mach == bfd_mach_i386_i386_intel_syntax
14839 +      || info->mach == bfd_mach_x86_64_intel_syntax)
14840 +    priv.orig_sizeflag = AFLAG | DFLAG;
14841 +  else if (info->mach == bfd_mach_i386_i8086)
14842 +    priv.orig_sizeflag = 0;
14843 +  else
14844 +    abort ();
14845 +
14846 +  for (p = info->disassembler_options; p != NULL; )
14847 +    {
14848 +      if (strncmp (p, "x86-64", 6) == 0)
14849 +       {
14850 +         mode_64bit = 1;
14851 +         priv.orig_sizeflag = AFLAG | DFLAG;
14852 +       }
14853 +      else if (strncmp (p, "i386", 4) == 0)
14854 +       {
14855 +         mode_64bit = 0;
14856 +         priv.orig_sizeflag = AFLAG | DFLAG;
14857 +       }
14858 +      else if (strncmp (p, "i8086", 5) == 0)
14859 +       {
14860 +         mode_64bit = 0;
14861 +         priv.orig_sizeflag = 0;
14862 +       }
14863 +      else if (strncmp (p, "intel", 5) == 0)
14864 +       {
14865 +         intel_syntax = 1;
14866 +       }
14867 +      else if (strncmp (p, "att", 3) == 0)
14868 +       {
14869 +         intel_syntax = 0;
14870 +       }
14871 +      else if (strncmp (p, "addr", 4) == 0)
14872 +       {
14873 +         if (p[4] == '1' && p[5] == '6')
14874 +           priv.orig_sizeflag &= ~AFLAG;
14875 +         else if (p[4] == '3' && p[5] == '2')
14876 +           priv.orig_sizeflag |= AFLAG;
14877 +       }
14878 +      else if (strncmp (p, "data", 4) == 0)
14879 +       {
14880 +         if (p[4] == '1' && p[5] == '6')
14881 +           priv.orig_sizeflag &= ~DFLAG;
14882 +         else if (p[4] == '3' && p[5] == '2')
14883 +           priv.orig_sizeflag |= DFLAG;
14884 +       }
14885 +      else if (strncmp (p, "suffix", 6) == 0)
14886 +       priv.orig_sizeflag |= SUFFIX_ALWAYS;
14887 +
14888 +      p = strchr (p, ',');
14889 +      if (p != NULL)
14890 +       p++;
14891 +    }
14892 +
14893 +  if (intel_syntax)
14894 +    {
14895 +      names64 = intel_names64;
14896 +      names32 = intel_names32;
14897 +      names16 = intel_names16;
14898 +      names8 = intel_names8;
14899 +      names8rex = intel_names8rex;
14900 +      names_seg = intel_names_seg;
14901 +      index16 = intel_index16;
14902 +      open_char = '[';
14903 +      close_char = ']';
14904 +      separator_char = '+';
14905 +      scale_char = '*';
14906 +    }
14907 +  else
14908 +    {
14909 +      names64 = att_names64;
14910 +      names32 = att_names32;
14911 +      names16 = att_names16;
14912 +      names8 = att_names8;
14913 +      names8rex = att_names8rex;
14914 +      names_seg = att_names_seg;
14915 +      index16 = att_index16;
14916 +      open_char = '(';
14917 +      close_char =  ')';
14918 +      separator_char = ',';
14919 +      scale_char = ',';
14920 +    }
14921 +
14922 +  /* The output looks better if we put 7 bytes on a line, since that
14923 +     puts most long word instructions on a single line.         */
14924 +  info->bytes_per_line = 7;
14925 +
14926 +  info->private_data = &priv;
14927 +  priv.max_fetched = priv.the_buffer;
14928 +  priv.insn_start = pc;
14929 +
14930 +  obuf[0] = 0;
14931 +  op1out[0] = 0;
14932 +  op2out[0] = 0;
14933 +  op3out[0] = 0;
14934 +
14935 +  op_index[0] = op_index[1] = op_index[2] = -1;
14936 +
14937 +  the_info = info;
14938 +  start_pc = pc;
14939 +  start_codep = priv.the_buffer;
14940 +  codep = priv.the_buffer;
14941 +
14942 +#ifndef __KERNEL__
14943 +  if (setjmp (priv.bailout) != 0)
14944 +    {
14945 +      const char *name;
14946 +
14947 +      /* Getting here means we tried for data but didn't get it.  That
14948 +        means we have an incomplete instruction of some sort.  Just
14949 +        print the first byte as a prefix or a .byte pseudo-op.  */
14950 +      if (codep > priv.the_buffer)
14951 +       {
14952 +         name = prefix_name (priv.the_buffer[0], priv.orig_sizeflag);
14953 +         if (name != NULL)
14954 +           (*info->fprintf_func) (info->stream, "%s", name);
14955 +         else
14956 +           {
14957 +             /* Just print the first byte as a .byte instruction.  */
14958 +             (*info->fprintf_func) (info->stream, ".byte 0x%x",
14959 +                                    (unsigned int) priv.the_buffer[0]);
14960 +           }
14961 +
14962 +         return 1;
14963 +       }
14964 +
14965 +      return -1;
14966 +    }
14967 +#endif /* __KERNEL__ */
14968 +
14969 +  obufp = obuf;
14970 +  ckprefix ();
14971 +
14972 +  insn_codep = codep;
14973 +  sizeflag = priv.orig_sizeflag;
14974 +
14975 +  FETCH_DATA (info, codep + 1);
14976 +  two_source_ops = (*codep == 0x62) || (*codep == 0xc8);
14977 +
14978 +  if ((prefixes & PREFIX_FWAIT)
14979 +      && ((*codep < 0xd8) || (*codep > 0xdf)))
14980 +    {
14981 +      const char *name;
14982 +
14983 +      /* fwait not followed by floating point instruction.  Print the
14984 +        first prefix, which is probably fwait itself.  */
14985 +      name = prefix_name (priv.the_buffer[0], priv.orig_sizeflag);
14986 +      if (name == NULL)
14987 +       name = INTERNAL_DISASSEMBLER_ERROR;
14988 +      (*info->fprintf_func) (info->stream, "%s", name);
14989 +      return 1;
14990 +    }
14991 +
14992 +  if (*codep == 0x0f)
14993 +    {
14994 +      FETCH_DATA (info, codep + 2);
14995 +      dp = &dis386_twobyte[*++codep];
14996 +      need_modrm = twobyte_has_modrm[*codep];
14997 +      uses_SSE_prefix = twobyte_uses_SSE_prefix[*codep];
14998 +      uses_LOCK_prefix = (*codep & ~0x02) == 0x20;
14999 +    }
15000 +  else
15001 +    {
15002 +      dp = &dis386[*codep];
15003 +      need_modrm = onebyte_has_modrm[*codep];
15004 +      uses_SSE_prefix = 0;
15005 +      uses_LOCK_prefix = 0;
15006 +    }
15007 +  codep++;
15008 +
15009 +  if (!uses_SSE_prefix && (prefixes & PREFIX_REPZ))
15010 +    {
15011 +      oappend ("repz ");
15012 +      used_prefixes |= PREFIX_REPZ;
15013 +    }
15014 +  if (!uses_SSE_prefix && (prefixes & PREFIX_REPNZ))
15015 +    {
15016 +      oappend ("repnz ");
15017 +      used_prefixes |= PREFIX_REPNZ;
15018 +    }
15019 +  if (!uses_LOCK_prefix && (prefixes & PREFIX_LOCK))
15020 +    {
15021 +      oappend ("lock ");
15022 +      used_prefixes |= PREFIX_LOCK;
15023 +    }
15024 +
15025 +  if (prefixes & PREFIX_ADDR)
15026 +    {
15027 +      sizeflag ^= AFLAG;
15028 +      if (dp->bytemode3 != loop_jcxz_mode || intel_syntax)
15029 +       {
15030 +         if ((sizeflag & AFLAG) || mode_64bit)
15031 +           oappend ("addr32 ");
15032 +         else
15033 +           oappend ("addr16 ");
15034 +         used_prefixes |= PREFIX_ADDR;
15035 +       }
15036 +    }
15037 +
15038 +  if (!uses_SSE_prefix && (prefixes & PREFIX_DATA))
15039 +    {
15040 +      sizeflag ^= DFLAG;
15041 +      if (dp->bytemode3 == cond_jump_mode
15042 +         && dp->bytemode1 == v_mode
15043 +         && !intel_syntax)
15044 +       {
15045 +         if (sizeflag & DFLAG)
15046 +           oappend ("data32 ");
15047 +         else
15048 +           oappend ("data16 ");
15049 +         used_prefixes |= PREFIX_DATA;
15050 +       }
15051 +    }
15052 +
15053 +  if (need_modrm)
15054 +    {
15055 +      FETCH_DATA (info, codep + 1);
15056 +      mod = (*codep >> 6) & 3;
15057 +      reg = (*codep >> 3) & 7;
15058 +      rm = *codep & 7;
15059 +    }
15060 +
15061 +  if (dp->name == NULL && dp->bytemode1 == FLOATCODE)
15062 +    {
15063 +      dofloat (sizeflag);
15064 +    }
15065 +  else
15066 +    {
15067 +      int index;
15068 +      if (dp->name == NULL)
15069 +       {
15070 +         switch (dp->bytemode1)
15071 +           {
15072 +           case USE_GROUPS:
15073 +             dp = &grps[dp->bytemode2][reg];
15074 +             break;
15075 +
15076 +           case USE_PREFIX_USER_TABLE:
15077 +             index = 0;
15078 +             used_prefixes |= (prefixes & PREFIX_REPZ);
15079 +             if (prefixes & PREFIX_REPZ)
15080 +               index = 1;
15081 +             else
15082 +               {
15083 +                 used_prefixes |= (prefixes & PREFIX_DATA);
15084 +                 if (prefixes & PREFIX_DATA)
15085 +                   index = 2;
15086 +                 else
15087 +                   {
15088 +                     used_prefixes |= (prefixes & PREFIX_REPNZ);
15089 +                     if (prefixes & PREFIX_REPNZ)
15090 +                       index = 3;
15091 +                   }
15092 +               }
15093 +             dp = &prefix_user_table[dp->bytemode2][index];
15094 +             break;
15095 +
15096 +           case X86_64_SPECIAL:
15097 +             dp = &x86_64_table[dp->bytemode2][mode_64bit];
15098 +             break;
15099 +
15100 +           default:
15101 +             oappend (INTERNAL_DISASSEMBLER_ERROR);
15102 +             break;
15103 +           }
15104 +       }
15105 +
15106 +      if (putop (dp->name, sizeflag) == 0)
15107 +       {
15108 +         obufp = op1out;
15109 +         op_ad = 2;
15110 +         if (dp->op1)
15111 +           (*dp->op1) (dp->bytemode1, sizeflag);
15112 +
15113 +         obufp = op2out;
15114 +         op_ad = 1;
15115 +         if (dp->op2)
15116 +           (*dp->op2) (dp->bytemode2, sizeflag);
15117 +
15118 +         obufp = op3out;
15119 +         op_ad = 0;
15120 +         if (dp->op3)
15121 +           (*dp->op3) (dp->bytemode3, sizeflag);
15122 +       }
15123 +    }
15124 +
15125 +  /* See if any prefixes were not used.         If so, print the first one
15126 +     separately.  If we don't do this, we'll wind up printing an
15127 +     instruction stream which does not precisely correspond to the
15128 +     bytes we are disassembling.  */
15129 +  if ((prefixes & ~used_prefixes) != 0)
15130 +    {
15131 +      const char *name;
15132 +
15133 +      name = prefix_name (priv.the_buffer[0], priv.orig_sizeflag);
15134 +      if (name == NULL)
15135 +       name = INTERNAL_DISASSEMBLER_ERROR;
15136 +      (*info->fprintf_func) (info->stream, "%s", name);
15137 +      return 1;
15138 +    }
15139 +  if (rex & ~rex_used)
15140 +    {
15141 +      const char *name;
15142 +      name = prefix_name (rex | 0x40, priv.orig_sizeflag);
15143 +      if (name == NULL)
15144 +       name = INTERNAL_DISASSEMBLER_ERROR;
15145 +      (*info->fprintf_func) (info->stream, "%s ", name);
15146 +    }
15147 +
15148 +  obufp = obuf + strlen (obuf);
15149 +  for (i = strlen (obuf); i < 6; i++)
15150 +    oappend (" ");
15151 +  oappend (" ");
15152 +  (*info->fprintf_func) (info->stream, "%s", obuf);
15153 +
15154 +  /* The enter and bound instructions are printed with operands in the same
15155 +     order as the intel book; everything else is printed in reverse order.  */
15156 +  if (intel_syntax || two_source_ops)
15157 +    {
15158 +      first = op1out;
15159 +      second = op2out;
15160 +      third = op3out;
15161 +      op_ad = op_index[0];
15162 +      op_index[0] = op_index[2];
15163 +      op_index[2] = op_ad;
15164 +    }
15165 +  else
15166 +    {
15167 +      first = op3out;
15168 +      second = op2out;
15169 +      third = op1out;
15170 +    }
15171 +  needcomma = 0;
15172 +  if (*first)
15173 +    {
15174 +      if (op_index[0] != -1 && !op_riprel[0])
15175 +       (*info->print_address_func) ((bfd_vma) op_address[op_index[0]], info);
15176 +      else
15177 +       (*info->fprintf_func) (info->stream, "%s", first);
15178 +      needcomma = 1;
15179 +    }
15180 +  if (*second)
15181 +    {
15182 +      if (needcomma)
15183 +       (*info->fprintf_func) (info->stream, ",");
15184 +      if (op_index[1] != -1 && !op_riprel[1])
15185 +       (*info->print_address_func) ((bfd_vma) op_address[op_index[1]], info);
15186 +      else
15187 +       (*info->fprintf_func) (info->stream, "%s", second);
15188 +      needcomma = 1;
15189 +    }
15190 +  if (*third)
15191 +    {
15192 +      if (needcomma)
15193 +       (*info->fprintf_func) (info->stream, ",");
15194 +      if (op_index[2] != -1 && !op_riprel[2])
15195 +       (*info->print_address_func) ((bfd_vma) op_address[op_index[2]], info);
15196 +      else
15197 +       (*info->fprintf_func) (info->stream, "%s", third);
15198 +    }
15199 +  for (i = 0; i < 3; i++)
15200 +    if (op_index[i] != -1 && op_riprel[i])
15201 +      {
15202 +       (*info->fprintf_func) (info->stream, "        # ");
15203 +       (*info->print_address_func) ((bfd_vma) (start_pc + codep - start_codep
15204 +                                               + op_address[op_index[i]]), info);
15205 +      }
15206 +  return codep - priv.the_buffer;
15207 +}
15208 +
15209 +static const char *float_mem[] = {
15210 +  /* d8 */
15211 +  "fadd{s||s|}",
15212 +  "fmul{s||s|}",
15213 +  "fcom{s||s|}",
15214 +  "fcomp{s||s|}",
15215 +  "fsub{s||s|}",
15216 +  "fsubr{s||s|}",
15217 +  "fdiv{s||s|}",
15218 +  "fdivr{s||s|}",
15219 +  /* d9 */
15220 +  "fld{s||s|}",
15221 +  "(bad)",
15222 +  "fst{s||s|}",
15223 +  "fstp{s||s|}",
15224 +  "fldenvIC",
15225 +  "fldcw",
15226 +  "fNstenvIC",
15227 +  "fNstcw",
15228 +  /* da */
15229 +  "fiadd{l||l|}",
15230 +  "fimul{l||l|}",
15231 +  "ficom{l||l|}",
15232 +  "ficomp{l||l|}",
15233 +  "fisub{l||l|}",
15234 +  "fisubr{l||l|}",
15235 +  "fidiv{l||l|}",
15236 +  "fidivr{l||l|}",
15237 +  /* db */
15238 +  "fild{l||l|}",
15239 +  "fisttp{l||l|}",
15240 +  "fist{l||l|}",
15241 +  "fistp{l||l|}",
15242 +  "(bad)",
15243 +  "fld{t||t|}",
15244 +  "(bad)",
15245 +  "fstp{t||t|}",
15246 +  /* dc */
15247 +  "fadd{l||l|}",
15248 +  "fmul{l||l|}",
15249 +  "fcom{l||l|}",
15250 +  "fcomp{l||l|}",
15251 +  "fsub{l||l|}",
15252 +  "fsubr{l||l|}",
15253 +  "fdiv{l||l|}",
15254 +  "fdivr{l||l|}",
15255 +  /* dd */
15256 +  "fld{l||l|}",
15257 +  "fisttp{ll||ll|}",
15258 +  "fst{l||l|}",
15259 +  "fstp{l||l|}",
15260 +  "frstorIC",
15261 +  "(bad)",
15262 +  "fNsaveIC",
15263 +  "fNstsw",
15264 +  /* de */
15265 +  "fiadd",
15266 +  "fimul",
15267 +  "ficom",
15268 +  "ficomp",
15269 +  "fisub",
15270 +  "fisubr",
15271 +  "fidiv",
15272 +  "fidivr",
15273 +  /* df */
15274 +  "fild",
15275 +  "fisttp",
15276 +  "fist",
15277 +  "fistp",
15278 +  "fbld",
15279 +  "fild{ll||ll|}",
15280 +  "fbstp",
15281 +  "fistp{ll||ll|}",
15282 +};
15283 +
15284 +static const unsigned char float_mem_mode[] = {
15285 +  /* d8 */
15286 +  d_mode,
15287 +  d_mode,
15288 +  d_mode,
15289 +  d_mode,
15290 +  d_mode,
15291 +  d_mode,
15292 +  d_mode,
15293 +  d_mode,
15294 +  /* d9 */
15295 +  d_mode,
15296 +  0,
15297 +  d_mode,
15298 +  d_mode,
15299 +  0,
15300 +  w_mode,
15301 +  0,
15302 +  w_mode,
15303 +  /* da */
15304 +  d_mode,
15305 +  d_mode,
15306 +  d_mode,
15307 +  d_mode,
15308 +  d_mode,
15309 +  d_mode,
15310 +  d_mode,
15311 +  d_mode,
15312 +  /* db */
15313 +  d_mode,
15314 +  d_mode,
15315 +  d_mode,
15316 +  d_mode,
15317 +  0,
15318 +  t_mode,
15319 +  0,
15320 +  t_mode,
15321 +  /* dc */
15322 +  q_mode,
15323 +  q_mode,
15324 +  q_mode,
15325 +  q_mode,
15326 +  q_mode,
15327 +  q_mode,
15328 +  q_mode,
15329 +  q_mode,
15330 +  /* dd */
15331 +  q_mode,
15332 +  q_mode,
15333 +  q_mode,
15334 +  q_mode,
15335 +  0,
15336 +  0,
15337 +  0,
15338 +  w_mode,
15339 +  /* de */
15340 +  w_mode,
15341 +  w_mode,
15342 +  w_mode,
15343 +  w_mode,
15344 +  w_mode,
15345 +  w_mode,
15346 +  w_mode,
15347 +  w_mode,
15348 +  /* df */
15349 +  w_mode,
15350 +  w_mode,
15351 +  w_mode,
15352 +  w_mode,
15353 +  t_mode,
15354 +  q_mode,
15355 +  t_mode,
15356 +  q_mode
15357 +};
15358 +
15359 +#define ST OP_ST, 0
15360 +#define STi OP_STi, 0
15361 +
15362 +#define FGRPd9_2 NULL, NULL, 0, NULL, 0, NULL, 0
15363 +#define FGRPd9_4 NULL, NULL, 1, NULL, 0, NULL, 0
15364 +#define FGRPd9_5 NULL, NULL, 2, NULL, 0, NULL, 0
15365 +#define FGRPd9_6 NULL, NULL, 3, NULL, 0, NULL, 0
15366 +#define FGRPd9_7 NULL, NULL, 4, NULL, 0, NULL, 0
15367 +#define FGRPda_5 NULL, NULL, 5, NULL, 0, NULL, 0
15368 +#define FGRPdb_4 NULL, NULL, 6, NULL, 0, NULL, 0
15369 +#define FGRPde_3 NULL, NULL, 7, NULL, 0, NULL, 0
15370 +#define FGRPdf_4 NULL, NULL, 8, NULL, 0, NULL, 0
15371 +
15372 +static const struct dis386 float_reg[][8] = {
15373 +  /* d8 */
15374 +  {
15375 +    { "fadd",  ST, STi, XX },
15376 +    { "fmul",  ST, STi, XX },
15377 +    { "fcom",  STi, XX, XX },
15378 +    { "fcomp", STi, XX, XX },
15379 +    { "fsub",  ST, STi, XX },
15380 +    { "fsubr", ST, STi, XX },
15381 +    { "fdiv",  ST, STi, XX },
15382 +    { "fdivr", ST, STi, XX },
15383 +  },
15384 +  /* d9 */
15385 +  {
15386 +    { "fld",   STi, XX, XX },
15387 +    { "fxch",  STi, XX, XX },
15388 +    { FGRPd9_2 },
15389 +    { "(bad)", XX, XX, XX },
15390 +    { FGRPd9_4 },
15391 +    { FGRPd9_5 },
15392 +    { FGRPd9_6 },
15393 +    { FGRPd9_7 },
15394 +  },
15395 +  /* da */
15396 +  {
15397 +    { "fcmovb", ST, STi, XX },
15398 +    { "fcmove", ST, STi, XX },
15399 +    { "fcmovbe",ST, STi, XX },
15400 +    { "fcmovu", ST, STi, XX },
15401 +    { "(bad)", XX, XX, XX },
15402 +    { FGRPda_5 },
15403 +    { "(bad)", XX, XX, XX },
15404 +    { "(bad)", XX, XX, XX },
15405 +  },
15406 +  /* db */
15407 +  {
15408 +    { "fcmovnb",ST, STi, XX },
15409 +    { "fcmovne",ST, STi, XX },
15410 +    { "fcmovnbe",ST, STi, XX },
15411 +    { "fcmovnu",ST, STi, XX },
15412 +    { FGRPdb_4 },
15413 +    { "fucomi", ST, STi, XX },
15414 +    { "fcomi", ST, STi, XX },
15415 +    { "(bad)", XX, XX, XX },
15416 +  },
15417 +  /* dc */
15418 +  {
15419 +    { "fadd",  STi, ST, XX },
15420 +    { "fmul",  STi, ST, XX },
15421 +    { "(bad)", XX, XX, XX },
15422 +    { "(bad)", XX, XX, XX },
15423 +#if UNIXWARE_COMPAT
15424 +    { "fsub",  STi, ST, XX },
15425 +    { "fsubr", STi, ST, XX },
15426 +    { "fdiv",  STi, ST, XX },
15427 +    { "fdivr", STi, ST, XX },
15428 +#else
15429 +    { "fsubr", STi, ST, XX },
15430 +    { "fsub",  STi, ST, XX },
15431 +    { "fdivr", STi, ST, XX },
15432 +    { "fdiv",  STi, ST, XX },
15433 +#endif
15434 +  },
15435 +  /* dd */
15436 +  {
15437 +    { "ffree", STi, XX, XX },
15438 +    { "(bad)", XX, XX, XX },
15439 +    { "fst",   STi, XX, XX },
15440 +    { "fstp",  STi, XX, XX },
15441 +    { "fucom", STi, XX, XX },
15442 +    { "fucomp", STi, XX, XX },
15443 +    { "(bad)", XX, XX, XX },
15444 +    { "(bad)", XX, XX, XX },
15445 +  },
15446 +  /* de */
15447 +  {
15448 +    { "faddp", STi, ST, XX },
15449 +    { "fmulp", STi, ST, XX },
15450 +    { "(bad)", XX, XX, XX },
15451 +    { FGRPde_3 },
15452 +#if UNIXWARE_COMPAT
15453 +    { "fsubp", STi, ST, XX },
15454 +    { "fsubrp", STi, ST, XX },
15455 +    { "fdivp", STi, ST, XX },
15456 +    { "fdivrp", STi, ST, XX },
15457 +#else
15458 +    { "fsubrp", STi, ST, XX },
15459 +    { "fsubp", STi, ST, XX },
15460 +    { "fdivrp", STi, ST, XX },
15461 +    { "fdivp", STi, ST, XX },
15462 +#endif
15463 +  },
15464 +  /* df */
15465 +  {
15466 +    { "ffreep", STi, XX, XX },
15467 +    { "(bad)", XX, XX, XX },
15468 +    { "(bad)", XX, XX, XX },
15469 +    { "(bad)", XX, XX, XX },
15470 +    { FGRPdf_4 },
15471 +    { "fucomip",ST, STi, XX },
15472 +    { "fcomip", ST, STi, XX },
15473 +    { "(bad)", XX, XX, XX },
15474 +  },
15475 +};
15476 +
15477 +static char *fgrps[][8] = {
15478 +  /* d9_2  0 */
15479 +  {
15480 +    "fnop","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
15481 +  },
15482 +
15483 +  /* d9_4  1 */
15484 +  {
15485 +    "fchs","fabs","(bad)","(bad)","ftst","fxam","(bad)","(bad)",
15486 +  },
15487 +
15488 +  /* d9_5  2 */
15489 +  {
15490 +    "fld1","fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz","(bad)",
15491 +  },
15492 +
15493 +  /* d9_6  3 */
15494 +  {
15495 +    "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp","fincstp",
15496 +  },
15497 +
15498 +  /* d9_7  4 */
15499 +  {
15500 +    "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos",
15501 +  },
15502 +
15503 +  /* da_5  5 */
15504 +  {
15505 +    "(bad)","fucompp","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
15506 +  },
15507 +
15508 +  /* db_4  6 */
15509 +  {
15510 +    "feni(287 only)","fdisi(287 only)","fNclex","fNinit",
15511 +    "fNsetpm(287 only)","(bad)","(bad)","(bad)",
15512 +  },
15513 +
15514 +  /* de_3  7 */
15515 +  {
15516 +    "(bad)","fcompp","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
15517 +  },
15518 +
15519 +  /* df_4  8 */
15520 +  {
15521 +    "fNstsw","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
15522 +  },
15523 +};
15524 +
15525 +static void
15526 +dofloat (int sizeflag)
15527 +{
15528 +  const struct dis386 *dp;
15529 +  unsigned char floatop;
15530 +
15531 +  floatop = codep[-1];
15532 +
15533 +  if (mod != 3)
15534 +    {
15535 +      int fp_indx = (floatop - 0xd8) * 8 + reg;
15536 +
15537 +      putop (float_mem[fp_indx], sizeflag);
15538 +      obufp = op1out;
15539 +      OP_E (float_mem_mode[fp_indx], sizeflag);
15540 +      return;
15541 +    }
15542 +  /* Skip mod/rm byte. */
15543 +  MODRM_CHECK;
15544 +  codep++;
15545 +
15546 +  dp = &float_reg[floatop - 0xd8][reg];
15547 +  if (dp->name == NULL)
15548 +    {
15549 +      putop (fgrps[dp->bytemode1][rm], sizeflag);
15550 +
15551 +      /* Instruction fnstsw is only one with strange arg.  */
15552 +      if (floatop == 0xdf && codep[-1] == 0xe0)
15553 +       strcpy (op1out, names16[0]);
15554 +    }
15555 +  else
15556 +    {
15557 +      putop (dp->name, sizeflag);
15558 +
15559 +      obufp = op1out;
15560 +      if (dp->op1)
15561 +       (*dp->op1) (dp->bytemode1, sizeflag);
15562 +      obufp = op2out;
15563 +      if (dp->op2)
15564 +       (*dp->op2) (dp->bytemode2, sizeflag);
15565 +    }
15566 +}
15567 +
15568 +static void
15569 +OP_ST (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
15570 +{
15571 +  oappend ("%st");
15572 +}
15573 +
15574 +static void
15575 +OP_STi (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
15576 +{
15577 +  sprintf (scratchbuf, "%%st(%d)", rm);
15578 +  oappend (scratchbuf + intel_syntax);
15579 +}
15580 +
15581 +/* Capital letters in template are macros.  */
15582 +static int
15583 +putop (const char *template, int sizeflag)
15584 +{
15585 +  const char *p;
15586 +  int alt = 0;
15587 +
15588 +  for (p = template; *p; p++)
15589 +    {
15590 +      switch (*p)
15591 +       {
15592 +       default:
15593 +         *obufp++ = *p;
15594 +         break;
15595 +       case '{':
15596 +         alt = 0;
15597 +         if (intel_syntax)
15598 +           alt += 1;
15599 +         if (mode_64bit)
15600 +           alt += 2;
15601 +         while (alt != 0)
15602 +           {
15603 +             while (*++p != '|')
15604 +               {
15605 +                 if (*p == '}')
15606 +                   {
15607 +                     /* Alternative not valid.  */
15608 +                     strcpy (obuf, "(bad)");
15609 +                     obufp = obuf + 5;
15610 +                     return 1;
15611 +                   }
15612 +                 else if (*p == '\0')
15613 +                   abort ();
15614 +               }
15615 +             alt--;
15616 +           }
15617 +         /* Fall through.  */
15618 +       case 'I':
15619 +         alt = 1;
15620 +         continue;
15621 +       case '|':
15622 +         while (*++p != '}')
15623 +           {
15624 +             if (*p == '\0')
15625 +               abort ();
15626 +           }
15627 +         break;
15628 +       case '}':
15629 +         break;
15630 +       case 'A':
15631 +         if (intel_syntax)
15632 +           break;
15633 +         if (mod != 3 || (sizeflag & SUFFIX_ALWAYS))
15634 +           *obufp++ = 'b';
15635 +         break;
15636 +       case 'B':
15637 +         if (intel_syntax)
15638 +           break;
15639 +         if (sizeflag & SUFFIX_ALWAYS)
15640 +           *obufp++ = 'b';
15641 +         break;
15642 +       case 'C':
15643 +         if (intel_syntax && !alt)
15644 +           break;
15645 +         if ((prefixes & PREFIX_DATA) || (sizeflag & SUFFIX_ALWAYS))
15646 +           {
15647 +             if (sizeflag & DFLAG)
15648 +               *obufp++ = intel_syntax ? 'd' : 'l';
15649 +             else
15650 +               *obufp++ = intel_syntax ? 'w' : 's';
15651 +             used_prefixes |= (prefixes & PREFIX_DATA);
15652 +           }
15653 +         break;
15654 +       case 'E':               /* For jcxz/jecxz */
15655 +         if (mode_64bit)
15656 +           {
15657 +             if (sizeflag & AFLAG)
15658 +               *obufp++ = 'r';
15659 +             else
15660 +               *obufp++ = 'e';
15661 +           }
15662 +         else
15663 +           if (sizeflag & AFLAG)
15664 +             *obufp++ = 'e';
15665 +         used_prefixes |= (prefixes & PREFIX_ADDR);
15666 +         break;
15667 +       case 'F':
15668 +         if (intel_syntax)
15669 +           break;
15670 +         if ((prefixes & PREFIX_ADDR) || (sizeflag & SUFFIX_ALWAYS))
15671 +           {
15672 +             if (sizeflag & AFLAG)
15673 +               *obufp++ = mode_64bit ? 'q' : 'l';
15674 +             else
15675 +               *obufp++ = mode_64bit ? 'l' : 'w';
15676 +             used_prefixes |= (prefixes & PREFIX_ADDR);
15677 +           }
15678 +         break;
15679 +       case 'H':
15680 +         if (intel_syntax)
15681 +           break;
15682 +         if ((prefixes & (PREFIX_CS | PREFIX_DS)) == PREFIX_CS
15683 +             || (prefixes & (PREFIX_CS | PREFIX_DS)) == PREFIX_DS)
15684 +           {
15685 +             used_prefixes |= prefixes & (PREFIX_CS | PREFIX_DS);
15686 +             *obufp++ = ',';
15687 +             *obufp++ = 'p';
15688 +             if (prefixes & PREFIX_DS)
15689 +               *obufp++ = 't';
15690 +             else
15691 +               *obufp++ = 'n';
15692 +           }
15693 +         break;
15694 +       case 'J':
15695 +         if (intel_syntax)
15696 +           break;
15697 +         *obufp++ = 'l';
15698 +         break;
15699 +       case 'L':
15700 +         if (intel_syntax)
15701 +           break;
15702 +         if (sizeflag & SUFFIX_ALWAYS)
15703 +           *obufp++ = 'l';
15704 +         break;
15705 +       case 'N':
15706 +         if ((prefixes & PREFIX_FWAIT) == 0)
15707 +           *obufp++ = 'n';
15708 +         else
15709 +           used_prefixes |= PREFIX_FWAIT;
15710 +         break;
15711 +       case 'O':
15712 +         USED_REX (REX_MODE64);
15713 +         if (rex & REX_MODE64)
15714 +           *obufp++ = 'o';
15715 +         else
15716 +           *obufp++ = 'd';
15717 +         break;
15718 +       case 'T':
15719 +         if (intel_syntax)
15720 +           break;
15721 +         if (mode_64bit)
15722 +           {
15723 +             *obufp++ = 'q';
15724 +             break;
15725 +           }
15726 +         /* Fall through.  */
15727 +       case 'P':
15728 +         if (intel_syntax)
15729 +           break;
15730 +         if ((prefixes & PREFIX_DATA)
15731 +             || (rex & REX_MODE64)
15732 +             || (sizeflag & SUFFIX_ALWAYS))
15733 +           {
15734 +             USED_REX (REX_MODE64);
15735 +             if (rex & REX_MODE64)
15736 +               *obufp++ = 'q';
15737 +             else
15738 +               {
15739 +                  if (sizeflag & DFLAG)
15740 +                     *obufp++ = 'l';
15741 +                  else
15742 +                    *obufp++ = 'w';
15743 +                  used_prefixes |= (prefixes & PREFIX_DATA);
15744 +               }
15745 +           }
15746 +         break;
15747 +       case 'U':
15748 +         if (intel_syntax)
15749 +           break;
15750 +         if (mode_64bit)
15751 +           {
15752 +             *obufp++ = 'q';
15753 +             break;
15754 +           }
15755 +         /* Fall through.  */
15756 +       case 'Q':
15757 +         if (intel_syntax && !alt)
15758 +           break;
15759 +         USED_REX (REX_MODE64);
15760 +         if (mod != 3 || (sizeflag & SUFFIX_ALWAYS))
15761 +           {
15762 +             if (rex & REX_MODE64)
15763 +               *obufp++ = 'q';
15764 +             else
15765 +               {
15766 +                 if (sizeflag & DFLAG)
15767 +                   *obufp++ = intel_syntax ? 'd' : 'l';
15768 +                 else
15769 +                   *obufp++ = 'w';
15770 +                 used_prefixes |= (prefixes & PREFIX_DATA);
15771 +               }
15772 +           }
15773 +         break;
15774 +       case 'R':
15775 +         USED_REX (REX_MODE64);
15776 +         if (intel_syntax)
15777 +           {
15778 +             if (rex & REX_MODE64)
15779 +               {
15780 +                 *obufp++ = 'q';
15781 +                 *obufp++ = 't';
15782 +               }
15783 +             else if (sizeflag & DFLAG)
15784 +               {
15785 +                 *obufp++ = 'd';
15786 +                 *obufp++ = 'q';
15787 +               }
15788 +             else
15789 +               {
15790 +                 *obufp++ = 'w';
15791 +                 *obufp++ = 'd';
15792 +               }
15793 +           }
15794 +         else
15795 +           {
15796 +             if (rex & REX_MODE64)
15797 +               *obufp++ = 'q';
15798 +             else if (sizeflag & DFLAG)
15799 +               *obufp++ = 'l';
15800 +             else
15801 +               *obufp++ = 'w';
15802 +           }
15803 +         if (!(rex & REX_MODE64))
15804 +           used_prefixes |= (prefixes & PREFIX_DATA);
15805 +         break;
15806 +       case 'S':
15807 +         if (intel_syntax)
15808 +           break;
15809 +         if (sizeflag & SUFFIX_ALWAYS)
15810 +           {
15811 +             if (rex & REX_MODE64)
15812 +               *obufp++ = 'q';
15813 +             else
15814 +               {
15815 +                 if (sizeflag & DFLAG)
15816 +                   *obufp++ = 'l';
15817 +                 else
15818 +                   *obufp++ = 'w';
15819 +                 used_prefixes |= (prefixes & PREFIX_DATA);
15820 +               }
15821 +           }
15822 +         break;
15823 +       case 'X':
15824 +         if (prefixes & PREFIX_DATA)
15825 +           *obufp++ = 'd';
15826 +         else
15827 +           *obufp++ = 's';
15828 +         used_prefixes |= (prefixes & PREFIX_DATA);
15829 +         break;
15830 +       case 'Y':
15831 +         if (intel_syntax)
15832 +           break;
15833 +         if (rex & REX_MODE64)
15834 +           {
15835 +             USED_REX (REX_MODE64);
15836 +             *obufp++ = 'q';
15837 +           }
15838 +         break;
15839 +         /* implicit operand size 'l' for i386 or 'q' for x86-64 */
15840 +       case 'W':
15841 +         /* operand size flag for cwtl, cbtw */
15842 +         USED_REX (0);
15843 +         if (rex)
15844 +           *obufp++ = 'l';
15845 +         else if (sizeflag & DFLAG)
15846 +           *obufp++ = 'w';
15847 +         else
15848 +           *obufp++ = 'b';
15849 +         if (intel_syntax)
15850 +           {
15851 +             if (rex)
15852 +               {
15853 +                 *obufp++ = 'q';
15854 +                 *obufp++ = 'e';
15855 +               }
15856 +             if (sizeflag & DFLAG)
15857 +               {
15858 +                 *obufp++ = 'd';
15859 +                 *obufp++ = 'e';
15860 +               }
15861 +             else
15862 +               {
15863 +                 *obufp++ = 'w';
15864 +               }
15865 +           }
15866 +         if (!rex)
15867 +           used_prefixes |= (prefixes & PREFIX_DATA);
15868 +         break;
15869 +       }
15870 +      alt = 0;
15871 +    }
15872 +  *obufp = 0;
15873 +  return 0;
15874 +}
15875 +
15876 +static void
15877 +oappend (const char *s)
15878 +{
15879 +  strcpy (obufp, s);
15880 +  obufp += strlen (s);
15881 +}
15882 +
15883 +static void
15884 +append_seg (void)
15885 +{
15886 +  if (prefixes & PREFIX_CS)
15887 +    {
15888 +      used_prefixes |= PREFIX_CS;
15889 +      oappend ("%cs:" + intel_syntax);
15890 +    }
15891 +  if (prefixes & PREFIX_DS)
15892 +    {
15893 +      used_prefixes |= PREFIX_DS;
15894 +      oappend ("%ds:" + intel_syntax);
15895 +    }
15896 +  if (prefixes & PREFIX_SS)
15897 +    {
15898 +      used_prefixes |= PREFIX_SS;
15899 +      oappend ("%ss:" + intel_syntax);
15900 +    }
15901 +  if (prefixes & PREFIX_ES)
15902 +    {
15903 +      used_prefixes |= PREFIX_ES;
15904 +      oappend ("%es:" + intel_syntax);
15905 +    }
15906 +  if (prefixes & PREFIX_FS)
15907 +    {
15908 +      used_prefixes |= PREFIX_FS;
15909 +      oappend ("%fs:" + intel_syntax);
15910 +    }
15911 +  if (prefixes & PREFIX_GS)
15912 +    {
15913 +      used_prefixes |= PREFIX_GS;
15914 +      oappend ("%gs:" + intel_syntax);
15915 +    }
15916 +}
15917 +
15918 +static void
15919 +OP_indirE (int bytemode, int sizeflag)
15920 +{
15921 +  if (!intel_syntax)
15922 +    oappend ("*");
15923 +  OP_E (bytemode, sizeflag);
15924 +}
15925 +
15926 +static void
15927 +print_operand_value (char *buf, int hex, bfd_vma disp)
15928 +{
15929 +  if (mode_64bit)
15930 +    {
15931 +      if (hex)
15932 +       {
15933 +         char tmp[30];
15934 +         int i;
15935 +         buf[0] = '0';
15936 +         buf[1] = 'x';
15937 +         sprintf_vma (tmp, disp);
15938 +         for (i = 0; tmp[i] == '0' && tmp[i + 1]; i++);
15939 +         strcpy (buf + 2, tmp + i);
15940 +       }
15941 +      else
15942 +       {
15943 +         bfd_signed_vma v = disp;
15944 +         char tmp[30];
15945 +         int i;
15946 +         if (v < 0)
15947 +           {
15948 +             *(buf++) = '-';
15949 +             v = -disp;
15950 +             /* Check for possible overflow on 0x8000000000000000.  */
15951 +             if (v < 0)
15952 +               {
15953 +                 strcpy (buf, "9223372036854775808");
15954 +                 return;
15955 +               }
15956 +           }
15957 +         if (!v)
15958 +           {
15959 +             strcpy (buf, "0");
15960 +             return;
15961 +           }
15962 +
15963 +         i = 0;
15964 +         tmp[29] = 0;
15965 +         while (v)
15966 +           {
15967 +             tmp[28 - i] = (v % 10) + '0';
15968 +             v /= 10;
15969 +             i++;
15970 +           }
15971 +         strcpy (buf, tmp + 29 - i);
15972 +       }
15973 +    }
15974 +  else
15975 +    {
15976 +      if (hex)
15977 +       sprintf (buf, "0x%x", (unsigned int) disp);
15978 +      else
15979 +       sprintf (buf, "%d", (int) disp);
15980 +    }
15981 +}
15982 +
15983 +static void
15984 +OP_E (int bytemode, int sizeflag)
15985 +{
15986 +  bfd_vma disp;
15987 +  int add = 0;
15988 +  int riprel = 0;
15989 +  USED_REX (REX_EXTZ);
15990 +  if (rex & REX_EXTZ)
15991 +    add += 8;
15992 +
15993 +  /* Skip mod/rm byte. */
15994 +  MODRM_CHECK;
15995 +  codep++;
15996 +
15997 +  if (mod == 3)
15998 +    {
15999 +      switch (bytemode)
16000 +       {
16001 +       case b_mode:
16002 +         USED_REX (0);
16003 +         if (rex)
16004 +           oappend (names8rex[rm + add]);
16005 +         else
16006 +           oappend (names8[rm + add]);
16007 +         break;
16008 +       case w_mode:
16009 +         oappend (names16[rm + add]);
16010 +         break;
16011 +       case d_mode:
16012 +         oappend (names32[rm + add]);
16013 +         break;
16014 +       case q_mode:
16015 +         oappend (names64[rm + add]);
16016 +         break;
16017 +       case m_mode:
16018 +         if (mode_64bit)
16019 +           oappend (names64[rm + add]);
16020 +         else
16021 +           oappend (names32[rm + add]);
16022 +         break;
16023 +       case branch_v_mode:
16024 +         if (mode_64bit)
16025 +           oappend (names64[rm + add]);
16026 +         else
16027 +           {
16028 +             if ((sizeflag & DFLAG) || bytemode != branch_v_mode)
16029 +               oappend (names32[rm + add]);
16030 +             else
16031 +               oappend (names16[rm + add]);
16032 +             used_prefixes |= (prefixes & PREFIX_DATA);
16033 +           }
16034 +         break;
16035 +       case v_mode:
16036 +       case dq_mode:
16037 +       case dqw_mode:
16038 +         USED_REX (REX_MODE64);
16039 +         if (rex & REX_MODE64)
16040 +           oappend (names64[rm + add]);
16041 +         else if ((sizeflag & DFLAG) || bytemode != v_mode)
16042 +           oappend (names32[rm + add]);
16043 +         else
16044 +           oappend (names16[rm + add]);
16045 +         used_prefixes |= (prefixes & PREFIX_DATA);
16046 +         break;
16047 +       case 0:
16048 +         break;
16049 +       default:
16050 +         oappend (INTERNAL_DISASSEMBLER_ERROR);
16051 +         break;
16052 +       }
16053 +      return;
16054 +    }
16055 +
16056 +  disp = 0;
16057 +  append_seg ();
16058 +
16059 +  if ((sizeflag & AFLAG) || mode_64bit) /* 32 bit address mode */
16060 +    {
16061 +      int havesib;
16062 +      int havebase;
16063 +      int base;
16064 +      int index = 0;
16065 +      int scale = 0;
16066 +
16067 +      havesib = 0;
16068 +      havebase = 1;
16069 +      base = rm;
16070 +
16071 +      if (base == 4)
16072 +       {
16073 +         havesib = 1;
16074 +         FETCH_DATA (the_info, codep + 1);
16075 +         index = (*codep >> 3) & 7;
16076 +         if (mode_64bit || index != 0x4)
16077 +           /* When INDEX == 0x4 in 32 bit mode, SCALE is ignored.  */
16078 +           scale = (*codep >> 6) & 3;
16079 +         base = *codep & 7;
16080 +         USED_REX (REX_EXTY);
16081 +         if (rex & REX_EXTY)
16082 +           index += 8;
16083 +         codep++;
16084 +       }
16085 +      base += add;
16086 +
16087 +      switch (mod)
16088 +       {
16089 +       case 0:
16090 +         if ((base & 7) == 5)
16091 +           {
16092 +             havebase = 0;
16093 +             if (mode_64bit && !havesib)
16094 +               riprel = 1;
16095 +             disp = get32s ();
16096 +           }
16097 +         break;
16098 +       case 1:
16099 +         FETCH_DATA (the_info, codep + 1);
16100 +         disp = *codep++;
16101 +         if ((disp & 0x80) != 0)
16102 +           disp -= 0x100;
16103 +         break;
16104 +       case 2:
16105 +         disp = get32s ();
16106 +         break;
16107 +       }
16108 +
16109 +      if (!intel_syntax)
16110 +       if (mod != 0 || (base & 7) == 5)
16111 +         {
16112 +           print_operand_value (scratchbuf, !riprel, disp);
16113 +           oappend (scratchbuf);
16114 +           if (riprel)
16115 +             {
16116 +               set_op (disp, 1);
16117 +               oappend ("(%rip)");
16118 +             }
16119 +         }
16120 +
16121 +      if (havebase || (havesib && (index != 4 || scale != 0)))
16122 +       {
16123 +         if (intel_syntax)
16124 +           {
16125 +             switch (bytemode)
16126 +               {
16127 +               case b_mode:
16128 +                 oappend ("BYTE PTR ");
16129 +                 break;
16130 +               case w_mode:
16131 +               case dqw_mode:
16132 +                 oappend ("WORD PTR ");
16133 +                 break;
16134 +               case branch_v_mode:
16135 +               case v_mode:
16136 +               case dq_mode:
16137 +                 USED_REX (REX_MODE64);
16138 +                 if (rex & REX_MODE64)
16139 +                   oappend ("QWORD PTR ");
16140 +                 else if ((sizeflag & DFLAG) || bytemode == dq_mode)
16141 +                   oappend ("DWORD PTR ");
16142 +                 else
16143 +                   oappend ("WORD PTR ");
16144 +                 used_prefixes |= (prefixes & PREFIX_DATA);
16145 +                 break;
16146 +               case d_mode:
16147 +                 oappend ("DWORD PTR ");
16148 +                 break;
16149 +               case q_mode:
16150 +                 oappend ("QWORD PTR ");
16151 +                 break;
16152 +               case m_mode:
16153 +                 if (mode_64bit)
16154 +                   oappend ("QWORD PTR ");
16155 +                 else
16156 +                   oappend ("DWORD PTR ");
16157 +                 break;
16158 +               case f_mode:
16159 +                 if (sizeflag & DFLAG)
16160 +                   {
16161 +                     used_prefixes |= (prefixes & PREFIX_DATA);
16162 +                     oappend ("FWORD PTR ");
16163 +                   }
16164 +                 else
16165 +                   oappend ("DWORD PTR ");
16166 +                 break;
16167 +               case t_mode:
16168 +                 oappend ("TBYTE PTR ");
16169 +                 break;
16170 +               case x_mode:
16171 +                 oappend ("XMMWORD PTR ");
16172 +                 break;
16173 +               default:
16174 +                 break;
16175 +               }
16176 +           }
16177 +         *obufp++ = open_char;
16178 +         if (intel_syntax && riprel)
16179 +           oappend ("rip + ");
16180 +         *obufp = '\0';
16181 +         if (havebase)
16182 +           oappend (mode_64bit && (sizeflag & AFLAG)
16183 +                    ? names64[base] : names32[base]);
16184 +         if (havesib)
16185 +           {
16186 +             if (index != 4)
16187 +               {
16188 +                 if (!intel_syntax || havebase)
16189 +                   {
16190 +                     *obufp++ = separator_char;
16191 +                     *obufp = '\0';
16192 +                   }
16193 +                 oappend (mode_64bit && (sizeflag & AFLAG)
16194 +                          ? names64[index] : names32[index]);
16195 +               }
16196 +             if (scale != 0 || (!intel_syntax && index != 4))
16197 +               {
16198 +                 *obufp++ = scale_char;
16199 +                 *obufp = '\0';
16200 +                 sprintf (scratchbuf, "%d", 1 << scale);
16201 +                 oappend (scratchbuf);
16202 +               }
16203 +           }
16204 +         if (intel_syntax && disp)
16205 +           {
16206 +             if ((bfd_signed_vma) disp > 0)
16207 +               {
16208 +                 *obufp++ = '+';
16209 +                 *obufp = '\0';
16210 +               }
16211 +             else if (mod != 1)
16212 +               {
16213 +                 *obufp++ = '-';
16214 +                 *obufp = '\0';
16215 +                 disp = - (bfd_signed_vma) disp;
16216 +               }
16217 +
16218 +             print_operand_value (scratchbuf, mod != 1, disp);
16219 +             oappend (scratchbuf);
16220 +           }
16221 +
16222 +         *obufp++ = close_char;
16223 +         *obufp = '\0';
16224 +       }
16225 +      else if (intel_syntax)
16226 +       {
16227 +         if (mod != 0 || (base & 7) == 5)
16228 +           {
16229 +             if (prefixes & (PREFIX_CS | PREFIX_SS | PREFIX_DS
16230 +                             | PREFIX_ES | PREFIX_FS | PREFIX_GS))
16231 +               ;
16232 +             else
16233 +               {
16234 +                 oappend (names_seg[ds_reg - es_reg]);
16235 +                 oappend (":");
16236 +               }
16237 +             print_operand_value (scratchbuf, 1, disp);
16238 +             oappend (scratchbuf);
16239 +           }
16240 +       }
16241 +    }
16242 +  else
16243 +    { /* 16 bit address mode */
16244 +      switch (mod)
16245 +       {
16246 +       case 0:
16247 +         if (rm == 6)
16248 +           {
16249 +             disp = get16 ();
16250 +             if ((disp & 0x8000) != 0)
16251 +               disp -= 0x10000;
16252 +           }
16253 +         break;
16254 +       case 1:
16255 +         FETCH_DATA (the_info, codep + 1);
16256 +         disp = *codep++;
16257 +         if ((disp & 0x80) != 0)
16258 +           disp -= 0x100;
16259 +         break;
16260 +       case 2:
16261 +         disp = get16 ();
16262 +         if ((disp & 0x8000) != 0)
16263 +           disp -= 0x10000;
16264 +         break;
16265 +       }
16266 +
16267 +      if (!intel_syntax)
16268 +       if (mod != 0 || rm == 6)
16269 +         {
16270 +           print_operand_value (scratchbuf, 0, disp);
16271 +           oappend (scratchbuf);
16272 +         }
16273 +
16274 +      if (mod != 0 || rm != 6)
16275 +       {
16276 +         *obufp++ = open_char;
16277 +         *obufp = '\0';
16278 +         oappend (index16[rm]);
16279 +         if (intel_syntax && disp)
16280 +           {
16281 +             if ((bfd_signed_vma) disp > 0)
16282 +               {
16283 +                 *obufp++ = '+';
16284 +                 *obufp = '\0';
16285 +               }
16286 +             else if (mod != 1)
16287 +               {
16288 +                 *obufp++ = '-';
16289 +                 *obufp = '\0';
16290 +                 disp = - (bfd_signed_vma) disp;
16291 +               }
16292 +
16293 +             print_operand_value (scratchbuf, mod != 1, disp);
16294 +             oappend (scratchbuf);
16295 +           }
16296 +
16297 +         *obufp++ = close_char;
16298 +         *obufp = '\0';
16299 +       }
16300 +      else if (intel_syntax)
16301 +       {
16302 +         if (prefixes & (PREFIX_CS | PREFIX_SS | PREFIX_DS
16303 +                         | PREFIX_ES | PREFIX_FS | PREFIX_GS))
16304 +           ;
16305 +         else
16306 +           {
16307 +             oappend (names_seg[ds_reg - es_reg]);
16308 +             oappend (":");
16309 +           }
16310 +         print_operand_value (scratchbuf, 1, disp & 0xffff);
16311 +         oappend (scratchbuf);
16312 +       }
16313 +    }
16314 +}
16315 +
16316 +static void
16317 +OP_G (int bytemode, int sizeflag)
16318 +{
16319 +  int add = 0;
16320 +  USED_REX (REX_EXTX);
16321 +  if (rex & REX_EXTX)
16322 +    add += 8;
16323 +  switch (bytemode)
16324 +    {
16325 +    case b_mode:
16326 +      USED_REX (0);
16327 +      if (rex)
16328 +       oappend (names8rex[reg + add]);
16329 +      else
16330 +       oappend (names8[reg + add]);
16331 +      break;
16332 +    case w_mode:
16333 +      oappend (names16[reg + add]);
16334 +      break;
16335 +    case d_mode:
16336 +      oappend (names32[reg + add]);
16337 +      break;
16338 +    case q_mode:
16339 +      oappend (names64[reg + add]);
16340 +      break;
16341 +    case v_mode:
16342 +    case dq_mode:
16343 +    case dqw_mode:
16344 +      USED_REX (REX_MODE64);
16345 +      if (rex & REX_MODE64)
16346 +       oappend (names64[reg + add]);
16347 +      else if ((sizeflag & DFLAG) || bytemode != v_mode)
16348 +       oappend (names32[reg + add]);
16349 +      else
16350 +       oappend (names16[reg + add]);
16351 +      used_prefixes |= (prefixes & PREFIX_DATA);
16352 +      break;
16353 +    case m_mode:
16354 +      if (mode_64bit)
16355 +       oappend (names64[reg + add]);
16356 +      else
16357 +       oappend (names32[reg + add]);
16358 +      break;
16359 +    default:
16360 +      oappend (INTERNAL_DISASSEMBLER_ERROR);
16361 +      break;
16362 +    }
16363 +}
16364 +
16365 +static bfd_vma
16366 +get64 (void)
16367 +{
16368 +  bfd_vma x;
16369 +#ifdef BFD64
16370 +  unsigned int a;
16371 +  unsigned int b;
16372 +
16373 +  FETCH_DATA (the_info, codep + 8);
16374 +  a = *codep++ & 0xff;
16375 +  a |= (*codep++ & 0xff) << 8;
16376 +  a |= (*codep++ & 0xff) << 16;
16377 +  a |= (*codep++ & 0xff) << 24;
16378 +  b = *codep++ & 0xff;
16379 +  b |= (*codep++ & 0xff) << 8;
16380 +  b |= (*codep++ & 0xff) << 16;
16381 +  b |= (*codep++ & 0xff) << 24;
16382 +  x = a + ((bfd_vma) b << 32);
16383 +#else
16384 +  abort ();
16385 +  x = 0;
16386 +#endif
16387 +  return x;
16388 +}
16389 +
16390 +static bfd_signed_vma
16391 +get32 (void)
16392 +{
16393 +  bfd_signed_vma x = 0;
16394 +
16395 +  FETCH_DATA (the_info, codep + 4);
16396 +  x = *codep++ & (bfd_signed_vma) 0xff;
16397 +  x |= (*codep++ & (bfd_signed_vma) 0xff) << 8;
16398 +  x |= (*codep++ & (bfd_signed_vma) 0xff) << 16;
16399 +  x |= (*codep++ & (bfd_signed_vma) 0xff) << 24;
16400 +  return x;
16401 +}
16402 +
16403 +static bfd_signed_vma
16404 +get32s (void)
16405 +{
16406 +  bfd_signed_vma x = 0;
16407 +
16408 +  FETCH_DATA (the_info, codep + 4);
16409 +  x = *codep++ & (bfd_signed_vma) 0xff;
16410 +  x |= (*codep++ & (bfd_signed_vma) 0xff) << 8;
16411 +  x |= (*codep++ & (bfd_signed_vma) 0xff) << 16;
16412 +  x |= (*codep++ & (bfd_signed_vma) 0xff) << 24;
16413 +
16414 +  x = (x ^ ((bfd_signed_vma) 1 << 31)) - ((bfd_signed_vma) 1 << 31);
16415 +
16416 +  return x;
16417 +}
16418 +
16419 +static int
16420 +get16 (void)
16421 +{
16422 +  int x = 0;
16423 +
16424 +  FETCH_DATA (the_info, codep + 2);
16425 +  x = *codep++ & 0xff;
16426 +  x |= (*codep++ & 0xff) << 8;
16427 +  return x;
16428 +}
16429 +
16430 +static void
16431 +set_op (bfd_vma op, int riprel)
16432 +{
16433 +  op_index[op_ad] = op_ad;
16434 +  if (mode_64bit)
16435 +    {
16436 +      op_address[op_ad] = op;
16437 +      op_riprel[op_ad] = riprel;
16438 +    }
16439 +  else
16440 +    {
16441 +      /* Mask to get a 32-bit address. */
16442 +      op_address[op_ad] = op & 0xffffffff;
16443 +      op_riprel[op_ad] = riprel & 0xffffffff;
16444 +    }
16445 +}
16446 +
16447 +static void
16448 +OP_REG (int code, int sizeflag)
16449 +{
16450 +  const char *s;
16451 +  int add = 0;
16452 +  USED_REX (REX_EXTZ);
16453 +  if (rex & REX_EXTZ)
16454 +    add = 8;
16455 +
16456 +  switch (code)
16457 +    {
16458 +    case indir_dx_reg:
16459 +      if (intel_syntax)
16460 +       s = "[dx]";
16461 +      else
16462 +       s = "(%dx)";
16463 +      break;
16464 +    case ax_reg: case cx_reg: case dx_reg: case bx_reg:
16465 +    case sp_reg: case bp_reg: case si_reg: case di_reg:
16466 +      s = names16[code - ax_reg + add];
16467 +      break;
16468 +    case es_reg: case ss_reg: case cs_reg:
16469 +    case ds_reg: case fs_reg: case gs_reg:
16470 +      s = names_seg[code - es_reg + add];
16471 +      break;
16472 +    case al_reg: case ah_reg: case cl_reg: case ch_reg:
16473 +    case dl_reg: case dh_reg: case bl_reg: case bh_reg:
16474 +      USED_REX (0);
16475 +      if (rex)
16476 +       s = names8rex[code - al_reg + add];
16477 +      else
16478 +       s = names8[code - al_reg];
16479 +      break;
16480 +    case rAX_reg: case rCX_reg: case rDX_reg: case rBX_reg:
16481 +    case rSP_reg: case rBP_reg: case rSI_reg: case rDI_reg:
16482 +      if (mode_64bit)
16483 +       {
16484 +         s = names64[code - rAX_reg + add];
16485 +         break;
16486 +       }
16487 +      code += eAX_reg - rAX_reg;
16488 +      /* Fall through. */
16489 +    case eAX_reg: case eCX_reg: case eDX_reg: case eBX_reg:
16490 +    case eSP_reg: case eBP_reg: case eSI_reg: case eDI_reg:
16491 +      USED_REX (REX_MODE64);
16492 +      if (rex & REX_MODE64)
16493 +       s = names64[code - eAX_reg + add];
16494 +      else if (sizeflag & DFLAG)
16495 +       s = names32[code - eAX_reg + add];
16496 +      else
16497 +       s = names16[code - eAX_reg + add];
16498 +      used_prefixes |= (prefixes & PREFIX_DATA);
16499 +      break;
16500 +    default:
16501 +      s = INTERNAL_DISASSEMBLER_ERROR;
16502 +      break;
16503 +    }
16504 +  oappend (s);
16505 +}
16506 +
16507 +static void
16508 +OP_IMREG (int code, int sizeflag)
16509 +{
16510 +  const char *s;
16511 +
16512 +  switch (code)
16513 +    {
16514 +    case indir_dx_reg:
16515 +      if (intel_syntax)
16516 +       s = "[dx]";
16517 +      else
16518 +       s = "(%dx)";
16519 +      break;
16520 +    case ax_reg: case cx_reg: case dx_reg: case bx_reg:
16521 +    case sp_reg: case bp_reg: case si_reg: case di_reg:
16522 +      s = names16[code - ax_reg];
16523 +      break;
16524 +    case es_reg: case ss_reg: case cs_reg:
16525 +    case ds_reg: case fs_reg: case gs_reg:
16526 +      s = names_seg[code - es_reg];
16527 +      break;
16528 +    case al_reg: case ah_reg: case cl_reg: case ch_reg:
16529 +    case dl_reg: case dh_reg: case bl_reg: case bh_reg:
16530 +      USED_REX (0);
16531 +      if (rex)
16532 +       s = names8rex[code - al_reg];
16533 +      else
16534 +       s = names8[code - al_reg];
16535 +      break;
16536 +    case eAX_reg: case eCX_reg: case eDX_reg: case eBX_reg:
16537 +    case eSP_reg: case eBP_reg: case eSI_reg: case eDI_reg:
16538 +      USED_REX (REX_MODE64);
16539 +      if (rex & REX_MODE64)
16540 +       s = names64[code - eAX_reg];
16541 +      else if (sizeflag & DFLAG)
16542 +       s = names32[code - eAX_reg];
16543 +      else
16544 +       s = names16[code - eAX_reg];
16545 +      used_prefixes |= (prefixes & PREFIX_DATA);
16546 +      break;
16547 +    default:
16548 +      s = INTERNAL_DISASSEMBLER_ERROR;
16549 +      break;
16550 +    }
16551 +  oappend (s);
16552 +}
16553 +
16554 +static void
16555 +OP_I (int bytemode, int sizeflag)
16556 +{
16557 +  bfd_signed_vma op;
16558 +  bfd_signed_vma mask = -1;
16559 +
16560 +  switch (bytemode)
16561 +    {
16562 +    case b_mode:
16563 +      FETCH_DATA (the_info, codep + 1);
16564 +      op = *codep++;
16565 +      mask = 0xff;
16566 +      break;
16567 +    case q_mode:
16568 +      if (mode_64bit)
16569 +       {
16570 +         op = get32s ();
16571 +         break;
16572 +       }
16573 +      /* Fall through. */
16574 +    case v_mode:
16575 +      USED_REX (REX_MODE64);
16576 +      if (rex & REX_MODE64)
16577 +       op = get32s ();
16578 +      else if (sizeflag & DFLAG)
16579 +       {
16580 +         op = get32 ();
16581 +         mask = 0xffffffff;
16582 +       }
16583 +      else
16584 +       {
16585 +         op = get16 ();
16586 +         mask = 0xfffff;
16587 +       }
16588 +      used_prefixes |= (prefixes & PREFIX_DATA);
16589 +      break;
16590 +    case w_mode:
16591 +      mask = 0xfffff;
16592 +      op = get16 ();
16593 +      break;
16594 +    case const_1_mode:
16595 +      if (intel_syntax)
16596 +       oappend ("1");
16597 +      return;
16598 +    default:
16599 +      oappend (INTERNAL_DISASSEMBLER_ERROR);
16600 +      return;
16601 +    }
16602 +
16603 +  op &= mask;
16604 +  scratchbuf[0] = '$';
16605 +  print_operand_value (scratchbuf + 1, 1, op);
16606 +  oappend (scratchbuf + intel_syntax);
16607 +  scratchbuf[0] = '\0';
16608 +}
16609 +
16610 +static void
16611 +OP_I64 (int bytemode, int sizeflag)
16612 +{
16613 +  bfd_signed_vma op;
16614 +  bfd_signed_vma mask = -1;
16615 +
16616 +  if (!mode_64bit)
16617 +    {
16618 +      OP_I (bytemode, sizeflag);
16619 +      return;
16620 +    }
16621 +
16622 +  switch (bytemode)
16623 +    {
16624 +    case b_mode:
16625 +      FETCH_DATA (the_info, codep + 1);
16626 +      op = *codep++;
16627 +      mask = 0xff;
16628 +      break;
16629 +    case v_mode:
16630 +      USED_REX (REX_MODE64);
16631 +      if (rex & REX_MODE64)
16632 +       op = get64 ();
16633 +      else if (sizeflag & DFLAG)
16634 +       {
16635 +         op = get32 ();
16636 +         mask = 0xffffffff;
16637 +       }
16638 +      else
16639 +       {
16640 +         op = get16 ();
16641 +         mask = 0xfffff;
16642 +       }
16643 +      used_prefixes |= (prefixes & PREFIX_DATA);
16644 +      break;
16645 +    case w_mode:
16646 +      mask = 0xfffff;
16647 +      op = get16 ();
16648 +      break;
16649 +    default:
16650 +      oappend (INTERNAL_DISASSEMBLER_ERROR);
16651 +      return;
16652 +    }
16653 +
16654 +  op &= mask;
16655 +  scratchbuf[0] = '$';
16656 +  print_operand_value (scratchbuf + 1, 1, op);
16657 +  oappend (scratchbuf + intel_syntax);
16658 +  scratchbuf[0] = '\0';
16659 +}
16660 +
16661 +static void
16662 +OP_sI (int bytemode, int sizeflag)
16663 +{
16664 +  bfd_signed_vma op;
16665 +  bfd_signed_vma mask = -1;
16666 +
16667 +  switch (bytemode)
16668 +    {
16669 +    case b_mode:
16670 +      FETCH_DATA (the_info, codep + 1);
16671 +      op = *codep++;
16672 +      if ((op & 0x80) != 0)
16673 +       op -= 0x100;
16674 +      mask = 0xffffffff;
16675 +      break;
16676 +    case v_mode:
16677 +      USED_REX (REX_MODE64);
16678 +      if (rex & REX_MODE64)
16679 +       op = get32s ();
16680 +      else if (sizeflag & DFLAG)
16681 +       {
16682 +         op = get32s ();
16683 +         mask = 0xffffffff;
16684 +       }
16685 +      else
16686 +       {
16687 +         mask = 0xffffffff;
16688 +         op = get16 ();
16689 +         if ((op & 0x8000) != 0)
16690 +           op -= 0x10000;
16691 +       }
16692 +      used_prefixes |= (prefixes & PREFIX_DATA);
16693 +      break;
16694 +    case w_mode:
16695 +      op = get16 ();
16696 +      mask = 0xffffffff;
16697 +      if ((op & 0x8000) != 0)
16698 +       op -= 0x10000;
16699 +      break;
16700 +    default:
16701 +      oappend (INTERNAL_DISASSEMBLER_ERROR);
16702 +      return;
16703 +    }
16704 +
16705 +  scratchbuf[0] = '$';
16706 +  print_operand_value (scratchbuf + 1, 1, op);
16707 +  oappend (scratchbuf + intel_syntax);
16708 +}
16709 +
16710 +static void
16711 +OP_J (int bytemode, int sizeflag)
16712 +{
16713 +  bfd_vma disp;
16714 +  bfd_vma mask = -1;
16715 +
16716 +  switch (bytemode)
16717 +    {
16718 +    case b_mode:
16719 +      FETCH_DATA (the_info, codep + 1);
16720 +      disp = *codep++;
16721 +      if ((disp & 0x80) != 0)
16722 +       disp -= 0x100;
16723 +      break;
16724 +    case v_mode:
16725 +      if (sizeflag & DFLAG)
16726 +       disp = get32s ();
16727 +      else
16728 +       {
16729 +         disp = get16 ();
16730 +         /* For some reason, a data16 prefix on a jump instruction
16731 +            means that the pc is masked to 16 bits after the
16732 +            displacement is added!  */
16733 +         mask = 0xffff;
16734 +       }
16735 +      break;
16736 +    default:
16737 +      oappend (INTERNAL_DISASSEMBLER_ERROR);
16738 +      return;
16739 +    }
16740 +  disp = (start_pc + codep - start_codep + disp) & mask;
16741 +  set_op (disp, 0);
16742 +  print_operand_value (scratchbuf, 1, disp);
16743 +  oappend (scratchbuf);
16744 +}
16745 +
16746 +static void
16747 +OP_SEG (int dummy ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
16748 +{
16749 +  oappend (names_seg[reg]);
16750 +}
16751 +
16752 +static void
16753 +OP_DIR (int dummy ATTRIBUTE_UNUSED, int sizeflag)
16754 +{
16755 +  int seg, offset;
16756 +
16757 +  if (sizeflag & DFLAG)
16758 +    {
16759 +      offset = get32 ();
16760 +      seg = get16 ();
16761 +    }
16762 +  else
16763 +    {
16764 +      offset = get16 ();
16765 +      seg = get16 ();
16766 +    }
16767 +  used_prefixes |= (prefixes & PREFIX_DATA);
16768 +  if (intel_syntax)
16769 +    sprintf (scratchbuf, "0x%x,0x%x", seg, offset);
16770 +  else
16771 +    sprintf (scratchbuf, "$0x%x,$0x%x", seg, offset);
16772 +  oappend (scratchbuf);
16773 +}
16774 +
16775 +static void
16776 +OP_OFF (int bytemode ATTRIBUTE_UNUSED, int sizeflag)
16777 +{
16778 +  bfd_vma off;
16779 +
16780 +  append_seg ();
16781 +
16782 +  if ((sizeflag & AFLAG) || mode_64bit)
16783 +    off = get32 ();
16784 +  else
16785 +    off = get16 ();
16786 +
16787 +  if (intel_syntax)
16788 +    {
16789 +      if (!(prefixes & (PREFIX_CS | PREFIX_SS | PREFIX_DS
16790 +                       | PREFIX_ES | PREFIX_FS | PREFIX_GS)))
16791 +       {
16792 +         oappend (names_seg[ds_reg - es_reg]);
16793 +         oappend (":");
16794 +       }
16795 +    }
16796 +  print_operand_value (scratchbuf, 1, off);
16797 +  oappend (scratchbuf);
16798 +}
16799 +
16800 +static void
16801 +OP_OFF64 (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
16802 +{
16803 +  bfd_vma off;
16804 +
16805 +  if (!mode_64bit)
16806 +    {
16807 +      OP_OFF (bytemode, sizeflag);
16808 +      return;
16809 +    }
16810 +
16811 +  append_seg ();
16812 +
16813 +  off = get64 ();
16814 +
16815 +  if (intel_syntax)
16816 +    {
16817 +      if (!(prefixes & (PREFIX_CS | PREFIX_SS | PREFIX_DS
16818 +                       | PREFIX_ES | PREFIX_FS | PREFIX_GS)))
16819 +       {
16820 +         oappend (names_seg[ds_reg - es_reg]);
16821 +         oappend (":");
16822 +       }
16823 +    }
16824 +  print_operand_value (scratchbuf, 1, off);
16825 +  oappend (scratchbuf);
16826 +}
16827 +
16828 +static void
16829 +ptr_reg (int code, int sizeflag)
16830 +{
16831 +  const char *s;
16832 +
16833 +  *obufp++ = open_char;
16834 +  used_prefixes |= (prefixes & PREFIX_ADDR);
16835 +  if (mode_64bit)
16836 +    {
16837 +      if (!(sizeflag & AFLAG))
16838 +       s = names32[code - eAX_reg];
16839 +      else
16840 +       s = names64[code - eAX_reg];
16841 +    }
16842 +  else if (sizeflag & AFLAG)
16843 +    s = names32[code - eAX_reg];
16844 +  else
16845 +    s = names16[code - eAX_reg];
16846 +  oappend (s);
16847 +  *obufp++ = close_char;
16848 +  *obufp = 0;
16849 +}
16850 +
16851 +static void
16852 +OP_ESreg (int code, int sizeflag)
16853 +{
16854 +  if (intel_syntax)
16855 +    {
16856 +      if (codep[-1] & 1)
16857 +       {
16858 +         USED_REX (REX_MODE64);
16859 +         used_prefixes |= (prefixes & PREFIX_DATA);
16860 +         if (rex & REX_MODE64)
16861 +           oappend ("QWORD PTR ");
16862 +         else if ((sizeflag & DFLAG))
16863 +           oappend ("DWORD PTR ");
16864 +         else
16865 +           oappend ("WORD PTR ");
16866 +       }
16867 +      else
16868 +       oappend ("BYTE PTR ");
16869 +    }
16870 +
16871 +  oappend ("%es:" + intel_syntax);
16872 +  ptr_reg (code, sizeflag);
16873 +}
16874 +
16875 +static void
16876 +OP_DSreg (int code, int sizeflag)
16877 +{
16878 +  if (intel_syntax)
16879 +    {
16880 +      if (codep[-1] != 0xd7 && (codep[-1] & 1))
16881 +       {
16882 +         USED_REX (REX_MODE64);
16883 +         used_prefixes |= (prefixes & PREFIX_DATA);
16884 +         if (rex & REX_MODE64)
16885 +           oappend ("QWORD PTR ");
16886 +         else if ((sizeflag & DFLAG))
16887 +           oappend ("DWORD PTR ");
16888 +         else
16889 +           oappend ("WORD PTR ");
16890 +       }
16891 +      else
16892 +       oappend ("BYTE PTR ");
16893 +    }
16894 +
16895 +  if ((prefixes
16896 +       & (PREFIX_CS
16897 +         | PREFIX_DS
16898 +         | PREFIX_SS
16899 +         | PREFIX_ES
16900 +         | PREFIX_FS
16901 +         | PREFIX_GS)) == 0)
16902 +    prefixes |= PREFIX_DS;
16903 +  append_seg ();
16904 +  ptr_reg (code, sizeflag);
16905 +}
16906 +
16907 +static void
16908 +OP_C (int dummy ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
16909 +{
16910 +  int add = 0;
16911 +  if (rex & REX_EXTX)
16912 +    {
16913 +      USED_REX (REX_EXTX);
16914 +      add = 8;
16915 +    }
16916 +  else if (!mode_64bit && (prefixes & PREFIX_LOCK))
16917 +    {
16918 +      used_prefixes |= PREFIX_LOCK;
16919 +      add = 8;
16920 +    }
16921 +  sprintf (scratchbuf, "%%cr%d", reg + add);
16922 +  oappend (scratchbuf + intel_syntax);
16923 +}
16924 +
16925 +static void
16926 +OP_D (int dummy ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
16927 +{
16928 +  int add = 0;
16929 +  USED_REX (REX_EXTX);
16930 +  if (rex & REX_EXTX)
16931 +    add = 8;
16932 +  if (intel_syntax)
16933 +    sprintf (scratchbuf, "db%d", reg + add);
16934 +  else
16935 +    sprintf (scratchbuf, "%%db%d", reg + add);
16936 +  oappend (scratchbuf);
16937 +}
16938 +
16939 +static void
16940 +OP_T (int dummy ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
16941 +{
16942 +  sprintf (scratchbuf, "%%tr%d", reg);
16943 +  oappend (scratchbuf + intel_syntax);
16944 +}
16945 +
16946 +static void
16947 +OP_Rd (int bytemode, int sizeflag)
16948 +{
16949 +  if (mod == 3)
16950 +    OP_E (bytemode, sizeflag);
16951 +  else
16952 +    BadOp ();
16953 +}
16954 +
16955 +static void
16956 +OP_MMX (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
16957 +{
16958 +  used_prefixes |= (prefixes & PREFIX_DATA);
16959 +  if (prefixes & PREFIX_DATA)
16960 +    {
16961 +      int add = 0;
16962 +      USED_REX (REX_EXTX);
16963 +      if (rex & REX_EXTX)
16964 +       add = 8;
16965 +      sprintf (scratchbuf, "%%xmm%d", reg + add);
16966 +    }
16967 +  else
16968 +    sprintf (scratchbuf, "%%mm%d", reg);
16969 +  oappend (scratchbuf + intel_syntax);
16970 +}
16971 +
16972 +static void
16973 +OP_XMM (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
16974 +{
16975 +  int add = 0;
16976 +  USED_REX (REX_EXTX);
16977 +  if (rex & REX_EXTX)
16978 +    add = 8;
16979 +  sprintf (scratchbuf, "%%xmm%d", reg + add);
16980 +  oappend (scratchbuf + intel_syntax);
16981 +}
16982 +
16983 +static void
16984 +OP_EM (int bytemode, int sizeflag)
16985 +{
16986 +  if (mod != 3)
16987 +    {
16988 +      if (intel_syntax && bytemode == v_mode)
16989 +       {
16990 +         bytemode = (prefixes & PREFIX_DATA) ? x_mode : q_mode;
16991 +         used_prefixes |= (prefixes & PREFIX_DATA);
16992 +       }
16993 +      OP_E (bytemode, sizeflag);
16994 +      return;
16995 +    }
16996 +
16997 +  /* Skip mod/rm byte. */
16998 +  MODRM_CHECK;
16999 +  codep++;
17000 +  used_prefixes |= (prefixes & PREFIX_DATA);
17001 +  if (prefixes & PREFIX_DATA)
17002 +    {
17003 +      int add = 0;
17004 +
17005 +      USED_REX (REX_EXTZ);
17006 +      if (rex & REX_EXTZ)
17007 +       add = 8;
17008 +      sprintf (scratchbuf, "%%xmm%d", rm + add);
17009 +    }
17010 +  else
17011 +    sprintf (scratchbuf, "%%mm%d", rm);
17012 +  oappend (scratchbuf + intel_syntax);
17013 +}
17014 +
17015 +static void
17016 +OP_EX (int bytemode, int sizeflag)
17017 +{
17018 +  int add = 0;
17019 +  if (mod != 3)
17020 +    {
17021 +      if (intel_syntax && bytemode == v_mode)
17022 +       {
17023 +         switch (prefixes & (PREFIX_DATA|PREFIX_REPZ|PREFIX_REPNZ))
17024 +           {
17025 +           case 0:            bytemode = x_mode; break;
17026 +           case PREFIX_REPZ:  bytemode = d_mode; used_prefixes |= PREFIX_REPZ;  break;
17027 +           case PREFIX_DATA:  bytemode = x_mode; used_prefixes |= PREFIX_DATA;  break;
17028 +           case PREFIX_REPNZ: bytemode = q_mode; used_prefixes |= PREFIX_REPNZ; break;
17029 +           default:           bytemode = 0; break;
17030 +           }
17031 +       }
17032 +      OP_E (bytemode, sizeflag);
17033 +      return;
17034 +    }
17035 +  USED_REX (REX_EXTZ);
17036 +  if (rex & REX_EXTZ)
17037 +    add = 8;
17038 +
17039 +  /* Skip mod/rm byte. */
17040 +  MODRM_CHECK;
17041 +  codep++;
17042 +  sprintf (scratchbuf, "%%xmm%d", rm + add);
17043 +  oappend (scratchbuf + intel_syntax);
17044 +}
17045 +
17046 +static void
17047 +OP_MS (int bytemode, int sizeflag)
17048 +{
17049 +  if (mod == 3)
17050 +    OP_EM (bytemode, sizeflag);
17051 +  else
17052 +    BadOp ();
17053 +}
17054 +
17055 +static void
17056 +OP_XS (int bytemode, int sizeflag)
17057 +{
17058 +  if (mod == 3)
17059 +    OP_EX (bytemode, sizeflag);
17060 +  else
17061 +    BadOp ();
17062 +}
17063 +
17064 +static void
17065 +OP_M (int bytemode, int sizeflag)
17066 +{
17067 +  if (mod == 3)
17068 +    BadOp ();  /* bad lea,lds,les,lfs,lgs,lss modrm */
17069 +  else
17070 +    OP_E (bytemode, sizeflag);
17071 +}
17072 +
17073 +static void
17074 +OP_0f07 (int bytemode, int sizeflag)
17075 +{
17076 +  if (mod != 3 || rm != 0)
17077 +    BadOp ();
17078 +  else
17079 +    OP_E (bytemode, sizeflag);
17080 +}
17081 +
17082 +static void
17083 +OP_0fae (int bytemode, int sizeflag)
17084 +{
17085 +  if (mod == 3)
17086 +    {
17087 +      if (reg == 7)
17088 +       strcpy (obuf + strlen (obuf) - sizeof ("clflush") + 1, "sfence");
17089 +
17090 +      if (reg < 5 || rm != 0)
17091 +       {
17092 +         BadOp ();     /* bad sfence, mfence, or lfence */
17093 +         return;
17094 +       }
17095 +    }
17096 +  else if (reg != 7)
17097 +    {
17098 +      BadOp ();                /* bad clflush */
17099 +      return;
17100 +    }
17101 +
17102 +  OP_E (bytemode, sizeflag);
17103 +}
17104 +
17105 +static void
17106 +NOP_Fixup (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
17107 +{
17108 +  /* NOP with REPZ prefix is called PAUSE.  */
17109 +  if (prefixes == PREFIX_REPZ)
17110 +    strcpy (obuf, "pause");
17111 +}
17112 +
17113 +static const char *const Suffix3DNow[] = {
17114 +/* 00 */       NULL,           NULL,           NULL,           NULL,
17115 +/* 04 */       NULL,           NULL,           NULL,           NULL,
17116 +/* 08 */       NULL,           NULL,           NULL,           NULL,
17117 +/* 0C */       "pi2fw",        "pi2fd",        NULL,           NULL,
17118 +/* 10 */       NULL,           NULL,           NULL,           NULL,
17119 +/* 14 */       NULL,           NULL,           NULL,           NULL,
17120 +/* 18 */       NULL,           NULL,           NULL,           NULL,
17121 +/* 1C */       "pf2iw",        "pf2id",        NULL,           NULL,
17122 +/* 20 */       NULL,           NULL,           NULL,           NULL,
17123 +/* 24 */       NULL,           NULL,           NULL,           NULL,
17124 +/* 28 */       NULL,           NULL,           NULL,           NULL,
17125 +/* 2C */       NULL,           NULL,           NULL,           NULL,
17126 +/* 30 */       NULL,           NULL,           NULL,           NULL,
17127 +/* 34 */       NULL,           NULL,           NULL,           NULL,
17128 +/* 38 */       NULL,           NULL,           NULL,           NULL,
17129 +/* 3C */       NULL,           NULL,           NULL,           NULL,
17130 +/* 40 */       NULL,           NULL,           NULL,           NULL,
17131 +/* 44 */       NULL,           NULL,           NULL,           NULL,
17132 +/* 48 */       NULL,           NULL,           NULL,           NULL,
17133 +/* 4C */       NULL,           NULL,           NULL,           NULL,
17134 +/* 50 */       NULL,           NULL,           NULL,           NULL,
17135 +/* 54 */       NULL,           NULL,           NULL,           NULL,
17136 +/* 58 */       NULL,           NULL,           NULL,           NULL,
17137 +/* 5C */       NULL,           NULL,           NULL,           NULL,
17138 +/* 60 */       NULL,           NULL,           NULL,           NULL,
17139 +/* 64 */       NULL,           NULL,           NULL,           NULL,
17140 +/* 68 */       NULL,           NULL,           NULL,           NULL,
17141 +/* 6C */       NULL,           NULL,           NULL,           NULL,
17142 +/* 70 */       NULL,           NULL,           NULL,           NULL,
17143 +/* 74 */       NULL,           NULL,           NULL,           NULL,
17144 +/* 78 */       NULL,           NULL,           NULL,           NULL,
17145 +/* 7C */       NULL,           NULL,           NULL,           NULL,
17146 +/* 80 */       NULL,           NULL,           NULL,           NULL,
17147 +/* 84 */       NULL,           NULL,           NULL,           NULL,
17148 +/* 88 */       NULL,           NULL,           "pfnacc",       NULL,
17149 +/* 8C */       NULL,           NULL,           "pfpnacc",      NULL,
17150 +/* 90 */       "pfcmpge",      NULL,           NULL,           NULL,
17151 +/* 94 */       "pfmin",        NULL,           "pfrcp",        "pfrsqrt",
17152 +/* 98 */       NULL,           NULL,           "pfsub",        NULL,
17153 +/* 9C */       NULL,           NULL,           "pfadd",        NULL,
17154 +/* A0 */       "pfcmpgt",      NULL,           NULL,           NULL,
17155 +/* A4 */       "pfmax",        NULL,           "pfrcpit1",     "pfrsqit1",
17156 +/* A8 */       NULL,           NULL,           "pfsubr",       NULL,
17157 +/* AC */       NULL,           NULL,           "pfacc",        NULL,
17158 +/* B0 */       "pfcmpeq",      NULL,           NULL,           NULL,
17159 +/* B4 */       "pfmul",        NULL,           "pfrcpit2",     "pfmulhrw",
17160 +/* B8 */       NULL,           NULL,           NULL,           "pswapd",
17161 +/* BC */       NULL,           NULL,           NULL,           "pavgusb",
17162 +/* C0 */       NULL,           NULL,           NULL,           NULL,
17163 +/* C4 */       NULL,           NULL,           NULL,           NULL,
17164 +/* C8 */       NULL,           NULL,           NULL,           NULL,
17165 +/* CC */       NULL,           NULL,           NULL,           NULL,
17166 +/* D0 */       NULL,           NULL,           NULL,           NULL,
17167 +/* D4 */       NULL,           NULL,           NULL,           NULL,
17168 +/* D8 */       NULL,           NULL,           NULL,           NULL,
17169 +/* DC */       NULL,           NULL,           NULL,           NULL,
17170 +/* E0 */       NULL,           NULL,           NULL,           NULL,
17171 +/* E4 */       NULL,           NULL,           NULL,           NULL,
17172 +/* E8 */       NULL,           NULL,           NULL,           NULL,
17173 +/* EC */       NULL,           NULL,           NULL,           NULL,
17174 +/* F0 */       NULL,           NULL,           NULL,           NULL,
17175 +/* F4 */       NULL,           NULL,           NULL,           NULL,
17176 +/* F8 */       NULL,           NULL,           NULL,           NULL,
17177 +/* FC */       NULL,           NULL,           NULL,           NULL,
17178 +};
17179 +
17180 +static void
17181 +OP_3DNowSuffix (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
17182 +{
17183 +  const char *mnemonic;
17184 +
17185 +  FETCH_DATA (the_info, codep + 1);
17186 +  /* AMD 3DNow! instructions are specified by an opcode suffix in the
17187 +     place where an 8-bit immediate would normally go. ie. the last
17188 +     byte of the instruction.  */
17189 +  obufp = obuf + strlen (obuf);
17190 +  mnemonic = Suffix3DNow[*codep++ & 0xff];
17191 +  if (mnemonic)
17192 +    oappend (mnemonic);
17193 +  else
17194 +    {
17195 +      /* Since a variable sized modrm/sib chunk is between the start
17196 +        of the opcode (0x0f0f) and the opcode suffix, we need to do
17197 +        all the modrm processing first, and don't know until now that
17198 +        we have a bad opcode.  This necessitates some cleaning up.  */
17199 +      op1out[0] = '\0';
17200 +      op2out[0] = '\0';
17201 +      BadOp ();
17202 +    }
17203 +}
17204 +
17205 +static const char *simd_cmp_op[] = {
17206 +  "eq",
17207 +  "lt",
17208 +  "le",
17209 +  "unord",
17210 +  "neq",
17211 +  "nlt",
17212 +  "nle",
17213 +  "ord"
17214 +};
17215 +
17216 +static void
17217 +OP_SIMD_Suffix (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
17218 +{
17219 +  unsigned int cmp_type;
17220 +
17221 +  FETCH_DATA (the_info, codep + 1);
17222 +  obufp = obuf + strlen (obuf);
17223 +  cmp_type = *codep++ & 0xff;
17224 +  if (cmp_type < 8)
17225 +    {
17226 +      char suffix1 = 'p', suffix2 = 's';
17227 +      used_prefixes |= (prefixes & PREFIX_REPZ);
17228 +      if (prefixes & PREFIX_REPZ)
17229 +       suffix1 = 's';
17230 +      else
17231 +       {
17232 +         used_prefixes |= (prefixes & PREFIX_DATA);
17233 +         if (prefixes & PREFIX_DATA)
17234 +           suffix2 = 'd';
17235 +         else
17236 +           {
17237 +             used_prefixes |= (prefixes & PREFIX_REPNZ);
17238 +             if (prefixes & PREFIX_REPNZ)
17239 +               suffix1 = 's', suffix2 = 'd';
17240 +           }
17241 +       }
17242 +      sprintf (scratchbuf, "cmp%s%c%c",
17243 +              simd_cmp_op[cmp_type], suffix1, suffix2);
17244 +      used_prefixes |= (prefixes & PREFIX_REPZ);
17245 +      oappend (scratchbuf);
17246 +    }
17247 +  else
17248 +    {
17249 +      /* We have a bad extension byte. Clean up.  */
17250 +      op1out[0] = '\0';
17251 +      op2out[0] = '\0';
17252 +      BadOp ();
17253 +    }
17254 +}
17255 +
17256 +static void
17257 +SIMD_Fixup (int extrachar, int sizeflag ATTRIBUTE_UNUSED)
17258 +{
17259 +  /* Change movlps/movhps to movhlps/movlhps for 2 register operand
17260 +     forms of these instructions.  */
17261 +  if (mod == 3)
17262 +    {
17263 +      char *p = obuf + strlen (obuf);
17264 +      *(p + 1) = '\0';
17265 +      *p       = *(p - 1);
17266 +      *(p - 1) = *(p - 2);
17267 +      *(p - 2) = *(p - 3);
17268 +      *(p - 3) = extrachar;
17269 +    }
17270 +}
17271 +
17272 +static void
17273 +PNI_Fixup (int extrachar ATTRIBUTE_UNUSED, int sizeflag)
17274 +{
17275 +  if (mod == 3 && reg == 1 && rm <= 1)
17276 +    {
17277 +      /* Override "sidt".  */
17278 +      char *p = obuf + strlen (obuf) - 4;
17279 +
17280 +      /* We might have a suffix when disassembling with -Msuffix.  */
17281 +      if (*p == 'i')
17282 +       --p;
17283 +
17284 +      if (rm)
17285 +       {
17286 +         /* mwait %eax,%ecx  */
17287 +         strcpy (p, "mwait");
17288 +         if (!intel_syntax)
17289 +           strcpy (op1out, names32[0]);
17290 +       }
17291 +      else
17292 +       {
17293 +         /* monitor %eax,%ecx,%edx"  */
17294 +         strcpy (p, "monitor");
17295 +         if (!intel_syntax)
17296 +           {
17297 +             if (!mode_64bit)
17298 +               strcpy (op1out, names32[0]);
17299 +             else if (!(prefixes & PREFIX_ADDR))
17300 +               strcpy (op1out, names64[0]);
17301 +             else
17302 +               {
17303 +                 strcpy (op1out, names32[0]);
17304 +                 used_prefixes |= PREFIX_ADDR;
17305 +               }
17306 +             strcpy (op3out, names32[2]);
17307 +           }
17308 +       }
17309 +      if (!intel_syntax)
17310 +       {
17311 +         strcpy (op2out, names32[1]);
17312 +         two_source_ops = 1;
17313 +       }
17314 +
17315 +      codep++;
17316 +    }
17317 +  else
17318 +    OP_M (0, sizeflag);
17319 +}
17320 +
17321 +static void
17322 +SVME_Fixup (int bytemode, int sizeflag)
17323 +{
17324 +  const char *alt;
17325 +  char *p;
17326 +
17327 +  switch (*codep)
17328 +    {
17329 +    case 0xd8:
17330 +      alt = "vmrun";
17331 +      break;
17332 +    case 0xd9:
17333 +      alt = "vmmcall";
17334 +      break;
17335 +    case 0xda:
17336 +      alt = "vmload";
17337 +      break;
17338 +    case 0xdb:
17339 +      alt = "vmsave";
17340 +      break;
17341 +    case 0xdc:
17342 +      alt = "stgi";
17343 +      break;
17344 +    case 0xdd:
17345 +      alt = "clgi";
17346 +      break;
17347 +    case 0xde:
17348 +      alt = "skinit";
17349 +      break;
17350 +    case 0xdf:
17351 +      alt = "invlpga";
17352 +      break;
17353 +    default:
17354 +      OP_M (bytemode, sizeflag);
17355 +      return;
17356 +    }
17357 +  /* Override "lidt".  */
17358 +  p = obuf + strlen (obuf) - 4;
17359 +  /* We might have a suffix.  */
17360 +  if (*p == 'i')
17361 +    --p;
17362 +  strcpy (p, alt);
17363 +  if (!(prefixes & PREFIX_ADDR))
17364 +    {
17365 +      ++codep;
17366 +      return;
17367 +    }
17368 +  used_prefixes |= PREFIX_ADDR;
17369 +  switch (*codep++)
17370 +    {
17371 +    case 0xdf:
17372 +      strcpy (op2out, names32[1]);
17373 +      two_source_ops = 1;
17374 +         /* Fall through.  */
17375 +    case 0xd8:
17376 +    case 0xda:
17377 +    case 0xdb:
17378 +      *obufp++ = open_char;
17379 +      if (mode_64bit || (sizeflag & AFLAG))
17380 +       alt = names32[0];
17381 +      else
17382 +       alt = names16[0];
17383 +      strcpy (obufp, alt);
17384 +      obufp += strlen (alt);
17385 +      *obufp++ = close_char;
17386 +      *obufp = '\0';
17387 +      break;
17388 +    }
17389 +}
17390 +
17391 +static void
17392 +INVLPG_Fixup (int bytemode, int sizeflag)
17393 +{
17394 +  const char *alt;
17395 +
17396 +  switch (*codep)
17397 +    {
17398 +    case 0xf8:
17399 +      alt = "swapgs";
17400 +      break;
17401 +    case 0xf9:
17402 +      alt = "rdtscp";
17403 +      break;
17404 +    default:
17405 +      OP_M (bytemode, sizeflag);
17406 +      return;
17407 +    }
17408 +  /* Override "invlpg".         */
17409 +  strcpy (obuf + strlen (obuf) - 6, alt);
17410 +  codep++;
17411 +}
17412 +
17413 +static void
17414 +BadOp (void)
17415 +{
17416 +  /* Throw away prefixes and 1st. opcode byte. */
17417 +  codep = insn_codep + 1;
17418 +  oappend ("(bad)");
17419 +}
17420 +
17421 +static void
17422 +SEG_Fixup (int extrachar, int sizeflag)
17423 +{
17424 +  if (mod == 3)
17425 +    {
17426 +      /* We need to add a proper suffix with
17427 +
17428 +               movw %ds,%ax
17429 +               movl %ds,%eax
17430 +               movq %ds,%rax
17431 +               movw %ax,%ds
17432 +               movl %eax,%ds
17433 +               movq %rax,%ds
17434 +       */
17435 +      const char *suffix;
17436 +
17437 +      if (prefixes & PREFIX_DATA)
17438 +       suffix = "w";
17439 +      else
17440 +       {
17441 +         USED_REX (REX_MODE64);
17442 +         if (rex & REX_MODE64)
17443 +           suffix = "q";
17444 +         else
17445 +           suffix = "l";
17446 +       }
17447 +      strcat (obuf, suffix);
17448 +    }
17449 +  else
17450 +    {
17451 +      /* We need to fix the suffix for
17452 +
17453 +               movw %ds,(%eax)
17454 +               movw %ds,(%rax)
17455 +               movw (%eax),%ds
17456 +               movw (%rax),%ds
17457 +
17458 +        Override "mov[l|q]".  */
17459 +      char *p = obuf + strlen (obuf) - 1;
17460 +
17461 +      /* We might not have a suffix.  */
17462 +      if (*p == 'v')
17463 +       ++p;
17464 +      *p = 'w';
17465 +    }
17466 +
17467 +  OP_E (extrachar, sizeflag);
17468 +}
17469 +
17470 +static void
17471 +VMX_Fixup (int extrachar ATTRIBUTE_UNUSED, int sizeflag)
17472 +{
17473 +  if (mod == 3 && reg == 0 && rm >=1 && rm <= 4)
17474 +    {
17475 +      /* Override "sgdt".  */
17476 +      char *p = obuf + strlen (obuf) - 4;
17477 +
17478 +      /* We might have a suffix when disassembling with -Msuffix.  */
17479 +      if (*p == 'g')
17480 +       --p;
17481 +
17482 +      switch (rm)
17483 +       {
17484 +       case 1:
17485 +         strcpy (p, "vmcall");
17486 +         break;
17487 +       case 2:
17488 +         strcpy (p, "vmlaunch");
17489 +         break;
17490 +       case 3:
17491 +         strcpy (p, "vmresume");
17492 +         break;
17493 +       case 4:
17494 +         strcpy (p, "vmxoff");
17495 +         break;
17496 +       }
17497 +
17498 +      codep++;
17499 +    }
17500 +  else
17501 +    OP_E (0, sizeflag);
17502 +}
17503 +
17504 +static void
17505 +OP_VMX (int bytemode, int sizeflag)
17506 +{
17507 +  used_prefixes |= (prefixes & (PREFIX_DATA | PREFIX_REPZ));
17508 +  if (prefixes & PREFIX_DATA)
17509 +    strcpy (obuf, "vmclear");
17510 +  else if (prefixes & PREFIX_REPZ)
17511 +    strcpy (obuf, "vmxon");
17512 +  else
17513 +    strcpy (obuf, "vmptrld");
17514 +  OP_E (bytemode, sizeflag);
17515 +}
17516 diff -Nurp linux-2.6.22-590/arch/x86_64/kernel/entry.S linux-2.6.22-600/arch/x86_64/kernel/entry.S
17517 --- linux-2.6.22-590/arch/x86_64/kernel/entry.S 2007-07-09 01:32:17.000000000 +0200
17518 +++ linux-2.6.22-600/arch/x86_64/kernel/entry.S 2008-04-09 18:16:24.000000000 +0200
17519 @@ -1170,3 +1170,30 @@ KPROBE_ENTRY(ignore_sysret)
17520         sysret
17521         CFI_ENDPROC
17522  ENDPROC(ignore_sysret)
17523 +
17524 +#ifdef CONFIG_KDB
17525 +
17526 +#ifdef CONFIG_SMP
17527 +ENTRY(kdb_interrupt)
17528 +       apicinterrupt KDB_VECTOR,smp_kdb_interrupt
17529 +END(kdb_interrupt)
17530 +#endif /* CONFIG_SMP */
17531 +
17532 +ENTRY(kdb_call)
17533 +       INTR_FRAME
17534 +       cld
17535 +       pushq $-1                       # orig_eax
17536 +       CFI_ADJUST_CFA_OFFSET 8
17537 +       SAVE_ALL
17538 +       movq $1,%rdi                    # KDB_REASON_ENTER
17539 +       movq $0,%rsi                    # error_code
17540 +       movq %rsp,%rdx                  # struct pt_regs
17541 +       call kdb
17542 +       RESTORE_ALL
17543 +       addq $8,%rsp                    # forget orig_eax
17544 +       CFI_ADJUST_CFA_OFFSET -8
17545 +       iretq
17546 +       CFI_ENDPROC
17547 +END(kdb_call)
17548 +
17549 +#endif /* CONFIG_KDB */
17550 diff -Nurp linux-2.6.22-590/arch/x86_64/kernel/io_apic.c linux-2.6.22-600/arch/x86_64/kernel/io_apic.c
17551 --- linux-2.6.22-590/arch/x86_64/kernel/io_apic.c       2008-04-09 18:10:46.000000000 +0200
17552 +++ linux-2.6.22-600/arch/x86_64/kernel/io_apic.c       2008-04-09 18:16:24.000000000 +0200
17553 @@ -35,6 +35,10 @@
17554  #include <acpi/acpi_bus.h>
17555  #endif
17556  
17557 +#ifdef CONFIG_KDB
17558 +#include <linux/kdb.h>
17559 +#endif /* CONFIG_KDB */
17560 +
17561  #include <asm/idle.h>
17562  #include <asm/io.h>
17563  #include <asm/smp.h>
17564 @@ -697,6 +701,10 @@ next:
17565                         continue;
17566                 if (vector == IA32_SYSCALL_VECTOR)
17567                         goto next;
17568 +#ifdef CONFIG_KDB
17569 +               if (vector == KDBENTER_VECTOR)
17570 +                       goto next;
17571 +#endif /* CONFIG_KDB */
17572                 for_each_cpu_mask(new_cpu, new_mask)
17573                         if (per_cpu(vector_irq, new_cpu)[vector] != -1)
17574                                 goto next;
17575 diff -Nurp linux-2.6.22-590/arch/x86_64/kernel/traps.c linux-2.6.22-600/arch/x86_64/kernel/traps.c
17576 --- linux-2.6.22-590/arch/x86_64/kernel/traps.c 2008-04-09 18:10:53.000000000 +0200
17577 +++ linux-2.6.22-600/arch/x86_64/kernel/traps.c 2008-04-09 18:17:59.000000000 +0200
17578 @@ -555,6 +555,8 @@ void __kprobes die_nmi(char *str, struct
17579         printk(str, smp_processor_id());
17580         show_registers(regs);
17581         vxh_dump_history();
17582 +       if (strncmp(str, "NMI Watchdog", 12) == 0)
17583 +               notify_die(DIE_NMIWATCHDOG, "nmi_watchdog", regs, 0, 2, SIGINT);
17584         if (kexec_should_crash(current))
17585                 crash_kexec(regs);
17586         if (do_panic || panic_on_oops)
17587 diff -Nurp linux-2.6.22-590/arch/x86_64/Makefile linux-2.6.22-600/arch/x86_64/Makefile
17588 --- linux-2.6.22-590/arch/x86_64/Makefile       2008-04-09 18:10:46.000000000 +0200
17589 +++ linux-2.6.22-600/arch/x86_64/Makefile       2008-04-09 18:16:24.000000000 +0200
17590 @@ -80,6 +80,7 @@ core-y                                        += arch/x86_64/kernel/ \
17591  core-$(CONFIG_IA32_EMULATION)          += arch/x86_64/ia32/
17592  drivers-$(CONFIG_PCI)                  += arch/x86_64/pci/
17593  drivers-$(CONFIG_OPROFILE)             += arch/x86_64/oprofile/
17594 +drivers-$(CONFIG_KDB)                  += arch/x86_64/kdb/
17595  
17596  boot := arch/x86_64/boot
17597  
17598 diff -Nurp linux-2.6.22-590/Documentation/kdb/bt_x86 linux-2.6.22-600/Documentation/kdb/bt_x86
17599 --- linux-2.6.22-590/Documentation/kdb/bt_x86   1970-01-01 01:00:00.000000000 +0100
17600 +++ linux-2.6.22-600/Documentation/kdb/bt_x86   2008-04-09 18:14:28.000000000 +0200
17601 @@ -0,0 +1,1837 @@
17602 +Copyright Keith Owens, 2007.
17603 +
17604 +How the KDB backtrace for x86 works, how to diagnose problems and submit a bug
17605 +==============================================================================
17606 +
17607 +Unlike ia64, x86 architectures do not mandate unwind information in the kernel.
17608 +gcc will include some unwind information for C functions, but not for assembler
17609 +code.  Attempts have been made to add unwind information to the assembler code
17610 +by hand, with little success.  Eventually Linus rejected the x86 unwind code
17611 +because it was breaking too often and destroying useful debugging data.
17612 +
17613 +Even if the x86 unwinder worked correctly, it would only give an accurate
17614 +backtrace, it would not give function arguments. Needless to say, function
17615 +arguments are what people really want.  To get function arguments requires much
17616 +more support from the compiler than simple unwind data, the compiler has to
17617 +track line by line where each argument is held and make that data available to
17618 +the debugger.  Compiling with gcc -g will provide that information, but the
17619 +resulting kernel is several times larger than normal.
17620 +
17621 +Although the gcc -g data can be stored on another machine, there are constructs
17622 +in the kernel that cannot be tracked by this method.  i386 builds with 4K stacks
17623 +and all x86_64 builds have multiple kernel stacks.  The compiler knows nothing
17624 +about these extra stacks and cannot backtrace through them correctly.  The
17625 +assembler code in arch/{i386,x86_64}/kernel/entry.S is a maze of twisty logic
17626 +paths, some of which eventually jump to common labels.  Describing this twisty
17627 +logic to an unwinder is very difficult, expecially when you try to describe
17628 +where arguments and/or registers are held).
17629 +
17630 +KDB gets an accurate x86 backtrace and extracts the arguments by performing code
17631 +decomposition and analysis at run time.  This avoids the need to bloat the
17632 +running kernel to several times its normal size with gcc -g data.  KDB (unlike
17633 +gdb) also knows about the additional kernel stacks and twisty assembler code
17634 +paths.
17635 +
17636 +The x86 backtrace code for i386 is very similar to the x86_64 code, with 80%
17637 +common code and data.  Most of the differences between the backtrace for the two
17638 +architectures is due to the assembler code and stack handling.  To avoid code
17639 +duplication between KDB patches, the x86 backtrace code is actually stored in
17640 +the kdb common patch, in source kdb/kdba_bt_x86.c.  kdb/Makefile only builds
17641 +kdba_bt_x86.o for i386 or x86_64.  Most of the code reads as if the architecture
17642 +is x86_64, using register names like rsp and rip.  i386 is treated as a subset
17643 +of x86_64, with fewer registers and printing the names as esp and eip.  When
17644 +this documentation refers to rsp and rip, read it as esp and eip for i386.  The
17645 +20% of code and data that is different in held in two large #ifdef sections,
17646 +scan kdba_bt_x86.c for CONFIG_X86_64.  Be careful when changing anything in the
17647 +architecture specific sections, you will need to review the other architecture
17648 +to see if it needs changes as well.
17649 +
17650 +The idea behind the x86 backtrace is to trace one function at a time, which
17651 +gives us the calling function.  Then apply the same algorithm to the calling
17652 +function until you unwind to the first function in the process.  The starting
17653 +point for tracing any process is to extract the current stack pointer and
17654 +current instruction pointer (rsp and rip).  The way that these values are
17655 +extracted varies between running tasks and blocked tasks, the method is
17656 +described later (Process Starting Point) but ignore it for now, just assume that
17657 +we have a starting rsp and rip.
17658 +
17659 +Given the instruction pointer (rip), we identify the start and end of the kernel
17660 +or module function it is in, using the kernel symbol table.  This is easy for C
17661 +code, it is significantly harder for assembler code because of the twisty code
17662 +paths that branch to common labels.  The method of identifying the current
17663 +function is described later (Identifying The Current Function) but ignore it for
17664 +now, just assumes that we have the start and end address of the function plus
17665 +its name.
17666 +
17667 +After the rip has been mapped to a function name with sensible start and end
17668 +addresses, the next step is to analyse the code paths in that function.  KDB
17669 +already has a built in disassembler (copied with slight modifications from
17670 +binutils) which knows how to decode each x86 instruction.  Instead of
17671 +duplicating that logic in kdba_bt_x86, it takes advantage of the fact that you
17672 +can override the disassembler's print function, sending the output line to a
17673 +buffer instead of printing it.  kdba_bt_x86 stills has to decode the buffer but
17674 +that is a lot easier than decoding the x86 instruction set.
17675 +
17676 +The code analysis consists of two main passes.  There are example below of the
17677 +analysis with basic block (bb) debugging activated (Examples of Basic Block
17678 +Debugging Output).
17679 +
17680 +The first pass (bb_pass1) identifies all the basic blocks in the function.  For
17681 +our purposes, a basic block has a single entry point and one or more exit
17682 +points.  The start of the function is the start of basic block 0, all other
17683 +blocks are the target of jump instructions (conditional or unconditional) from
17684 +within the rest of the code.  A block ends with an unconditional jump or with a
17685 +terminating instruction such as ret, iret, sysexit, sysret or ud2a (BUG).  A
17686 +block can also end because the next instruction is the start of a new block
17687 +(target of jmp or jcc), in this case there is an implied drop through from one
17688 +block to the next.
17689 +
17690 +Although a call instruction also transfers control, it returns to the next
17691 +instruction so call is not treated as a transfer.  Instead call is treated as a
17692 +normal instruction with side effects, the scratch registers are cleared after a
17693 +call.
17694 +
17695 +At the end of the first pass over the function we have a directed graph that
17696 +starts at bb[0].  The nodes of the graph (bb_list[]) are the basic blocks with
17697 +their start and end address.  The vertices are the jmp or jcc instructions
17698 +(bb_jmp_list[]) that transfer control between blocks, plus any implied drop
17699 +through transfers between consecutive blocks.  This graph can have cycles, many
17700 +functions have loops in them which transfer control back to earlier in the code
17701 +body.
17702 +
17703 +The second pass (bb_pass2) runs over the directed graph analysing the effect of
17704 +each instruction on the register and memory state.  It is important to
17705 +understand that the analysis in this pass is an abstract one, it does not use
17706 +actual hex values for the register contents, instead it uses symbolic values.
17707 +When the basic block code says that "register rsi contains value rax" it means
17708 +that whatever value was in rax on entry to the function has also been copied to
17709 +register rsi at this point in the logic flow.
17710 +
17711 +At an abstract level, all C functions start with exactly the same state, each
17712 +register contains its own symbolic value (except for the stack pointer, see
17713 +later) with no local stack variables defined yet.  Assembler functions tend to
17714 +have unusual starting points, with some registers and/or memory contents defined
17715 +differently on entry.  For example, ret_from_intr on i386 already has a struct
17716 +pt_regs on its stack, ret_from_intr on x86_64 already has a partial struct
17717 +pt_regs plus another two words stacked on top of it.  The special starting cases
17718 +are listed in the arch specific bb_special_cases[].
17719 +
17720 +Once the input state of bb[0] has been defined (including any special cases),
17721 +bb_pass2_do_changed_blocks() runs over all the nodes in bb_list[].  Each
17722 +instruction in each block is analysed (Tracking the Effects of Instructions) to
17723 +see what effect it has on the abstract register state, the analysis of each
17724 +instruction is done in bb_usage().  An instruction can copy one register to
17725 +another, it can copy a register to stack, move from stack to a register or it
17726 +can invalidate the contents of a register or memory location.  A general rule in
17727 +bb_usage() is that any operation whose results cannot be calculated in terms of
17728 +an original input value gives an undefined result.  Remember that it is the
17729 +abstract value that becomes undefined, moving a constant to a register gives a
17730 +defined value for the view of the program but it is undefined as far as the
17731 +abstract state is concerned.
17732 +
17733 +References to data on the stack are a little awkward because the stack pointer
17734 +frequently changes.  To overcome this, kdba_bt_x86 defines a pseudo register
17735 +called the 'original stack pointer' (osp).  This always represents the stack
17736 +pointer on entry to the function, so on entry rsp contains osp+0x0.  As rsp is
17737 +modified, it still points at osp, but its offset from osp changes.  Copying rsp
17738 +to another register (e.g. mov %rsp,%rbp) copies the osp offset as well.  At the
17739 +point that this function calls the next function down the stack, kdba_bt_x86
17740 +knows the delta from osp to rsp.  Applying that delta to the actual value of the
17741 +stack pointer gives the stack pointer value on input to the current function,
17742 +that location contains the return address so we can go up one stack frame and
17743 +repeat the process.
17744 +
17745 +After doing basic block analysis on the current function, kdba_bt_x86 knows what
17746 +the abstract register and memory state is at the point this function was
17747 +interrupted or it called the next function down the stack, this is the exit
17748 +state.  For an interrupt the actual register values are saved in a struct
17749 +pt_regs, for a call we have unwound from the KDB interrupt back to the called
17750 +function so we have some idea of what the register values are in the called
17751 +function.  The abstract exit state is merged with the known actual register
17752 +values to derive the original stack pointer.  That in turn gives us any
17753 +registers that were saved on stack.  The original stack pointer gives the return
17754 +address from the calling function, go up one stack frame and repeat the
17755 +analysis.
17756 +
17757 +
17758 +Process Starting Point
17759 +======================
17760 +
17761 +All backtrace code needs a starting point which defines at least the stack
17762 +pointer and instruction pointer, it may define other registers as well.  The
17763 +first part of kdba_bt_stack() extracts the starting point.  Processes can be in
17764 +one of three states, running (currently on a cpu), blocked (sleeping or ready to
17765 +run but not currently on a cpu) or unknown.
17766 +
17767 +For running processes, the current rsp and rip are dynamic.  Because KDB stops
17768 +the entire machine by sending an interrupt to the other cpus, KDB can save the
17769 +rsp and rip for each cpu at the point where KDB is entered.  This data is held
17770 +in array kdb_running_process and is stored by kdb_save_running() and the arch
17771 +specific kdba_save_running() functions.  When backtracing a running process, KDB
17772 +uses the data in kdb_running_process as its starting point.
17773 +
17774 +For blocked processes we always have the saved rsp, it is held in the process's
17775 +thread_info.  For i386 blocked processes, thread_info also contains the saved
17776 +rip.  For x86_64 blocked processes, rip is no longer saved in thread_info, it is
17777 +assumed that all blocked processes will resume at assembler label thread_return,
17778 +so that rip is used on x86_64.  See arch specific kdba_bt_stack_rip().
17779 +
17780 +Unknown process state only occurs when the user does 'bt <stack_address>'.
17781 +Unlike other bt commands, 'bt <stack_address>' does not identify any specific
17782 +process, instead it identifies a kernel stack.  <stack_address> must be inside a
17783 +valid kernel stack and must point to a saved rip from a call instruction.
17784 +kdba_bt_x86.c uses the common kdba_get_stack_info() and arch specific
17785 +kdba_get_stack_info_alternate() functions to check that the address falls within
17786 +a valid kernel stack.  If the user gives a stack address that does not point to
17787 +a saved rip from a call instruction then the backtrace will be garbage.
17788 +
17789 +
17790 +Identifying The Current Function
17791 +================================
17792 +
17793 +Given a rip value, KDB uses the kallsyms data to find the start of the function
17794 +(first address <= rip) and the end of the function (next symbol in kallsyms).
17795 +This works for plain C code because gcc only generates one label per function.
17796 +It does not work for assembler code or for assembler code embedded in C
17797 +functions, because the assembler labels appear as global entries in kallsyms.
17798 +For example, arch/i386/kernel/entry.S has function ret_from_exception which
17799 +contains three global labels ret_from_intr, check_userspace and
17800 +resume_userspace.  If rip points to any of those global labels, KDB wants the
17801 +start of the real function, i.e. ret_from_exception.  In addition, if rip points
17802 +to ret_from_exception, KDB wants the end of the function to be after the last
17803 +global label in that function, i.e. after resume_userspace.
17804 +
17805 +The simplest way to handle these unwanted global labels is to list the spurious
17806 +assembler labels, which is done in the arch specific array bb_spurious.  After
17807 +mapping rip to the nearest start and end labels from kallsyms, kdb_bb() works
17808 +backwards until it finds a non-spurious label then works forwards to the next
17809 +non-spurious label.  That gives a real start and end address and a real name for
17810 +the current function.
17811 +
17812 +Note that this algorithm only applies in kdb_bb() when it maps rip to a suitable
17813 +start and end address.  When disassembling the code, you will still see the
17814 +spurious label names, users need to see the extra labels.  ret_from_exception on
17815 +i386 disassembles like this (2.6.22) :-
17816 +
17817 +[0]kdb> id ret_from_exception
17818 +0xc0102554 ret_from_exception:         cli
17819 +0xc0102555 ret_from_intr:         mov    $0xfffff000,%ebp
17820 +0xc010255a ret_from_intr+0x5:     and    %esp,%ebp
17821 +0xc010255c check_userspace:         mov    0x34(%esp),%eax
17822 +0xc0102560 check_userspace+0x4:     mov    0x30(%esp),%al
17823 +0xc0102564 check_userspace+0x8:     and    $0x20003,%eax
17824 +0xc0102569 check_userspace+0xd:     cmp    $0x3,%eax
17825 +0xc010256c check_userspace+0x10:    jb     0xc010258c resume_kernel
17826 +0xc0102572 check_userspace+0x16:    mov    %esi,%esi
17827 +0xc0102574 resume_userspace:         cli
17828 +0xc0102575 resume_userspace+0x1:     mov    0x8(%ebp),%ecx
17829 +0xc0102578 resume_userspace+0x4:     and    $0xfe3e,%ecx
17830 +0xc010257e resume_userspace+0xa:     jne    0xc01026f4 work_pending
17831 +0xc0102584 resume_userspace+0x10:    jmp    0xc01026a7 restore_all
17832 +0xc0102589 resume_userspace+0x15:    lea    0x0(%esi),%esi
17833 +0xc010258c resume_kernel:         cli
17834 +
17835 +For the purposes of kdba_bt_x86.c, any rip from 0xc0102554 to 0xc0102589 needs
17836 +to map to the range 0xc0102554 (start) to 0xc010258c (end) with function name
17837 +ret_from_exception.  Therefore ret_from_intr, check_userspace and
17838 +resume_userspace are listed in bb_spurious[] for i386 so those symbols are
17839 +ignored.  The comments in bb_spurious[] list the function that encloses each
17840 +spurious label, those comments are only for humans, they do not affect the code.
17841 +
17842 +Once rip has been mapped to non-spurious labels, the module name, function name,
17843 +start and end address are stored in variables bb_mod_name, bb_func_name,
17844 +bb_func_start, bb_func_end.  These variables are used throughout kdba_bt_x86.c
17845 +for processing each function in turn.
17846 +
17847 +Watch for changes to assembler code, especially in arch/i386/kernel/entry.S,
17848 +arch/x86_64/kernel/entry.S and arch/x86_64/ia32/ia32entry.S.  When new labels
17849 +are added you may need to adjust bb_spurious[] for that architecture.  Running
17850 +bb_all can help identify assembler labels that have been added or deleted.
17851 +
17852 +
17853 +Tracking the Effects of Instructions
17854 +====================================
17855 +
17856 +bb_pass2_do_changed_blocks() uses the KDB disassembler to decode the x86
17857 +instructions to something a human can read.  bb_dis_pass2() is used as a print
17858 +routine to store data for a single instruction in a buffer then
17859 +bb_parse_buffer() starts the analysis.  Any instruction prefixes like lock or
17860 +rep are stripped out.  The opcode string is isolated then up to 3 operands are
17861 +extracted (imul can have 3 operands), these are src, dst and dst2.  The operand
17862 +is matched against table bb_opcode_usage_all[] which lists all the instructions
17863 +that actually appear in i386 and x86_64 kernels.  A lot of the x86 instrcution
17864 +set is not used by the kernel so instructions such as SSE do not appear in
17865 +bb_opcode_usage_all[].
17866 +
17867 +Each operand is decoded by bb_parse_operand() to see whether it has a segment
17868 +prefix, displacement, base, index or scale.  An indirect call or jmp is
17869 +identified.  Operands consisting only of a register are classified as 'reg'
17870 +type, displacements starting with '$' are immediate values otherwise the operand
17871 +refers to a memory location.  Any base or index register name is mapped to the
17872 +abstract register name that contains it, this takes care of mapping (say) %ah to
17873 +rax.
17874 +
17875 +After decoding the opcode and all its operands, bb_usage() decides what effect
17876 +the instruction will have on the abstract state machine.  Some x86 instructions
17877 +list all the affected registers in their operands and these can be handled as
17878 +generic cases.  Alas many x86 instructions have side effects and change
17879 +registers that are not listed in the operands, these have to be handled as
17880 +special cases.  enum bb_operand_usage lists the generic and special cases.
17881 +
17882 +bb_usage() is basically one huge switch statement over the special values in
17883 +enum bb_operand_usage.  For each special case it tracks the side effects of the
17884 +instruction.  Once all the special cases have been handled and converted to
17885 +generic cases then bb_usage() handles the generic cases.
17886 +
17887 +bb_usage() detects when a register is copied to another register, a register is
17888 +copied to stack or a known stack value is copied to a register and updates the
17889 +state data accordingly.  It is particularly important that all stack pointer
17890 +updates and copies of the stack pointer are tracked, much of the saved state is
17891 +on stack and can be accessed via any register that points to the stack, not just
17892 +via rsp.
17893 +
17894 +i386 built with 4K stacks and all x86_64 builds have multiple kernel stacks.
17895 +bb_usage() knows which instructions or locations are used to switch stacks and
17896 +pretends that these instructions have no effect on the contents of rsp.  The
17897 +higher level backtrace code knows how to handle stack switching, it is too
17898 +complicated for basic block analysis.
17899 +
17900 +
17901 +Transfer of Control Outside the Current Function
17902 +================================================
17903 +
17904 +Ignoring call instructions, most C code does not transfer control outside the
17905 +current function, IOW there are no jump instructions to instructions outside the
17906 +function.  There are a few cases that this can occur for C code, inline
17907 +assembler and tail recursion.
17908 +
17909 +Tail recursion occurs when a function ends by returning the value from a second
17910 +function and that second function has exactly the same arguments and return
17911 +value as the current function.  For example,
17912 +
17913 +    int bar(int i, char *p)
17914 +    {
17915 +        ... do some work and return an int ...
17916 +    }
17917 +
17918 +    int foo(int i, char *p)
17919 +    {
17920 +        return bar(i, p);
17921 +    }
17922 +
17923 +If tail recursion is active (gcc -foptimize-sibling-calls) then instead of foo
17924 +calling bar, bar returning to foo then foo returning to its caller, gcc will end
17925 +foo with a direct jmp to bar.  The source code says that something called foo
17926 +but the stack trace will show bar is active, with no sign of foo on stack.  When
17927 +bar returns it will use the return address from the code that called foo.
17928 +
17929 +bb_transfer() detects an unconditional jmp to code outside the function body and
17930 +assumes that this represents tail recursion.  For tail recursion to work
17931 +correctly, all the preserved registers must contain their original values,
17932 +bb_sanity_check() validates this.  Any deviation from the expected state will
17933 +stop basic block analysis and fall back on the old unreliable backtrace code.
17934 +
17935 +Besides tail recursion in C code, assembler code can jump to labels outside the
17936 +current function.  Unfortunately this occurs all the time in the twisty
17937 +assembler code and, to make things worse, many of these transfers are done with
17938 +non-standard register or memory state.  bb_special_case() and the arch specific
17939 +bb_special_cases[] handle all the known special cases, including what the
17940 +register and/or memory state should be.  Any deviation from the expected state
17941 +will stop basic block analysis and fall back on the old unreliable backtrace
17942 +code.
17943 +
17944 +
17945 +Locating Arguments
17946 +==================
17947 +
17948 +Function arguments can be passed in registers or on stack.  The full ABI for
17949 +passing arguments is described in
17950 +
17951 +  http://www.caldera.com/developers/devspecs/abi386-4.pdf
17952 +  http://www.x86-64.org/documentation/abi.pdf
17953 +
17954 +The short description, ignoring special cases like passing structures by name
17955 +and floating point arguments which tend not to apply to the kernel, is :-
17956 +
17957 +i386.   With -mpregparm=0, all arguments are passed on stack, except for
17958 +        functions defined as FASTCALL, where the first 3 arguments are passed in
17959 +        registers.
17960 +
17961 +        With -mregparm=3, the first 3 arguments are passed in registers except
17962 +        for functions defined as asmlinkage or with variable number of
17963 +        arguments, when arguments are still passed on stack.  -mpregparm=3 used
17964 +        to be a config option, in recent kernels it is the default.
17965 +
17966 +        Arguments defined as long long (64 bit) are passed in two registers or
17967 +        in two locations on stack.  Being passed in two pieces makes a 64 bit
17968 +        argument look like two 32 bit arguments to KDB, it will be printed as
17969 +        two separate arguments.
17970 +
17971 +        When compiled with -mregparm=3, if a 64 bit argument is argument number
17972 +        2 then it will not be split between register and stack, instead it will
17973 +        all be on stack and the third argument register will not be used.  This
17974 +        makes it look like there is an extra argument in the list.  There is
17975 +        nothing that KDB can do to detect these corner cases with 64 bit
17976 +        arguments on i386, which is a pity because they can confuse users.
17977 +
17978 +        The preserved registers are ebx, ebp, esp, esi, edi.  Arguments are
17979 +        passed in eax, edx, ecx.  The return value is in eax.
17980 +
17981 +x86_64. The first 6 arguments are passed in registers, the 7th and later
17982 +        arguments are passed on stack.  Except for functions with a variable
17983 +        number of arguments (e.g. printk) where all arguments are on stack
17984 +        except for rax which contains the number of SSE arguments (always 0 for
17985 +        the kernel).
17986 +
17987 +        The preserved registers are rbx, rbp, rsp, r12, r13, r14, r15.
17988 +        Arguments are passed in rdi, rsi, rdx, rcx, r8, r9.  The return value is
17989 +        in rax.
17990 +
17991 +For both architectures, kdba_bt detects an argument that is passed in a register
17992 +by the fact that the function code reads from that argument type register while
17993 +it contains its original value.  IOW, testing the value of rax, copying rax to
17994 +another register or storing it on stack without first overwriting rax means that
17995 +rax contains a useful input value.  Reading from memory which is above the
17996 +original stack pointer means that there is a argument at that location on
17997 +stack.
17998 +
17999 +There are some functions in the kernel whose definition contains arguments that
18000 +are not actually used.  Typically these functions are instantiations of generic
18001 +function definitions where some, but not all, instantiations use all the
18002 +arguments.  For example, a filesystem function may take flags that are not used
18003 +by this particular filesystem, but the function definition has to match the
18004 +generic filesystem declarations.  If the unused arguments are at the end of the
18005 +list then there is no way of telling from the object code that they exist, the
18006 +function that does not use the trailing aguments will have no code that refers
18007 +to them.  KDB will print a truncated argument list for this case.
18008 +
18009 +If the unused arguments are not at the end of the list then KDB can detect the
18010 +presence of the unused arguments, because there is code that refers to later
18011 +arguments.  KDB will print the unused argument, although gcc may have
18012 +overwritten the register it is in, in which case KDB prints "invalid".
18013 +
18014 +Originally kdba_bt_x86 would detect that there was no reference to arguments in
18015 +registers but there were still references to arguments on stack and assume that
18016 +the function had all its arguments on stack.  Unfortunately this did not work
18017 +with the large number of 'pass through' functions in the kernel.  A 'pass
18018 +through' function is one which calls another function with roughly the same
18019 +argument list and makes no other reference to the register arguments.  For
18020 +example, ipv4_doint_and_flush_strategy() takes 7 arguments, calls
18021 +devinet_conf_sysctl() with those 7 arguments in the same order and has no other
18022 +reference to any of its arguments.
18023 +
18024 +Pass through functions do not touch the arguments that are passed in registers
18025 +because they are already in the right location for the routine about to be
18026 +called, so the pass through function has no code that references the argument
18027 +registers.  No code means that kdba_bt_x86 cannot tell if the function has
18028 +register arguments or not.  The arguments passed on stack must always be copied
18029 +to the new stack frame, even for pass through functions, so the arguments on
18030 +stack can always be detected.
18031 +
18032 +kdba_bt_x86 was changed to assume that if there are any arguments on stack then
18033 +there are always arguments in registers, except for a list of functions that are
18034 +known to be asmlinkage or to have a variable number of arguments.
18035 +bb_assume_pass_through() ignores the known special cases, for other functions
18036 +which have stack arguments but no register arguments it assumes the function is
18037 +pass through and prints a warning about that assumption.
18038 +
18039 +The above heuristics mean that there is one case that kdba_bt_x86 cannot detect:
18040 +pass through functions where all the arguments are in registers.  These have no
18041 +argument references at all in their code, so they are printed with no arguments.
18042 +All they do is call another function so this class of functions never fails, or
18043 +if it does fail then it is due to something that is not argument related.  If
18044 +the failure is further down the call stack then the arguments are printed at the
18045 +next function down the stack, so the user still has the arguments.
18046 +
18047 +This list of limitations on getting the x86 arguments may seem to be a long one,
18048 +but kdba_bt_x86 gives sensible results for most functions.  For kernel
18049 +debugging, any arguments are far better than none at all.
18050 +
18051 +
18052 +Kernel Stack Switching
18053 +======================
18054 +
18055 +Understanding the unusual way that x86 kernel stacks are used is very important
18056 +when diagnosing backtrace problems.  Every process has its own normal kernel
18057 +stack, even processes that run entirely within the kernel such as kthread or the
18058 +per cpu migration processes.  The normal stacks are 4K or 8K on i386 (depending
18059 +on CONFIG_4KSTACKS) and 8K on x86_64.  The normal stacks are global, they are
18060 +not tied to any cpu.
18061 +
18062 +For i386 with 8K stacks there are no other kernel stacks so there is no stack
18063 +switching to worry about.
18064 +
18065 +For i386 with 4K process stacks, each cpu also has a 4K soft irq stack and a 4K
18066 +hard irq stack.  It is possible for a process to be running on its own process
18067 +stack, for the process to be interrupted by a soft irq which is then interrupted
18068 +by a hard irq.  At that point the backtrace is split between the hard irq, the
18069 +soft irq and the normal normal stacks.
18070 +
18071 +On x86_64, each cpu always has stacks for stackfault, doublefault, nmi, debug,
18072 +mce and interrupts.  See Documentation/x86_64/kernel-stacks.
18073 +
18074 +The arch specific kdba_get_stack_info_alternate() function works out which stack
18075 +the backtrace starts on, how big the stack is and how to switch to the next
18076 +stack.  This information is stored in the kdb_activation_record and used by the
18077 +higher level backtrace code to detect a stack switch.
18078 +
18079 +The normal stack has some padding at the end, this reflects the stack pointer
18080 +when the process was created in the kernel.  kdba_bt_x86 cannot backtrace
18081 +through this padding data, mainly because the code that set the nitial stack
18082 +pointer no longer exists after boot.  ARCH_NORMAL_PADDING defines how many words
18083 +to ignore at the end of the normal stack.
18084 +
18085 +
18086 +Debugging KDB
18087 +=============
18088 +
18089 +KDB has conditional debugging print statements scattered throughout the code.
18090 +If KDB is not behaving as expected, you can turn on debugging and rerun the
18091 +command.  Before debugging KDB, set LINES 10000 and capture the output via a
18092 +serial console.  If using minicom, turn on word wrap (control-A W) and capture
18093 +mode (control-A L).  If you are using a serial console via a serial to Ethernet
18094 +interface using ssh or telnet, use the 'script' command to start the session.
18095 +
18096 +The various KDB_DEBUG_FLAG_* flags are listed in include/linux/kdbprivate.h.
18097 +You set debug with 'set KDBDEBUG 0xnn' where nn is the or'd value of the desired
18098 +flags.  'set KDBDEBUG 0' turns off KDB debugging.  When diagnosing x86 backtrace
18099 +problems, the most useful debug flags are
18100 +
18101 +  KDB_DEBUG_FLAG_ARA            0x10    Activation record, arch specific
18102 +  KDB_DEBUG_FLAG_BB_SUMM        0x04    Basic block analysis, summary only
18103 +  KDB_DEBUG_FLAG_BB             0x20    All basic block analysis
18104 +
18105 +ARA prints information about the different kernel stacks as kdba_bt_x86 unwinds
18106 +through the switched kernel stacks.  BB_SUMM prints a summary of the basic block
18107 +analysis for each function, including the abstract exit state and the rollback
18108 +calculations.  BB prints a huge amount of basic block debugging, you probably
18109 +only want to turn this for the full backtrace on as a last resort.
18110 +
18111 +I find 'set KDBDEBUG 0x14' to be best to get an overview of a problem.  It gives
18112 +both the kernel stack information plus the abstract state and actual location of
18113 +data for each function.
18114 +
18115 +Command 'bb1' does a detailed debug session for a single function, bb1 takes a
18116 +single parameter, the address of the exit point from the function, by number,
18117 +not by name.  bb1 turns on KDB_DEBUG_FLAG_BB, does basic block analysis for the
18118 +function that contains the exit point then resets the debug flags to their
18119 +previous value.
18120 +
18121 +Command 'bb_all' runs through every function in the base kernel (not module
18122 +functions) and does a basic block analysis of every function.  It also validates
18123 +the various tables in kdba_bt_x86 where possible.  bb_all is meant for the KDB
18124 +maintainer to check that all the base kernel function pass the sanity checks, it
18125 +can also be used by end users when reporting a bug.  bb_all takes no parameters.
18126 +It prints a '.' for every 100 functions it has analysed and allows for up to 20
18127 +errors before giving up.  The output from bb_all also includes the config
18128 +variables that affect basic block analysis plus any assumptions about 'pass
18129 +through' functions.
18130 +
18131 +
18132 +Submitting a Bug Report Against kdba_bt_x86
18133 +===========================================
18134 +
18135 +Capture the KDB output via a serial console.
18136 +
18137 +set LINES 10000
18138 +set BTSP 1
18139 +set KDBDEBUG 0x14
18140 +Reproduce the problem.
18141 +set KDBDEBUG 0
18142 +bb_all
18143 +
18144 +If you can identify the rip/eip where kdba_bt_x86 gets confused, run bb1 with
18145 +that address.
18146 +
18147 +Find each set of output from kdba_get_stack_info in the trace, extract the last
18148 +two lines and type those lines into KDB.  That will give a hex and symbolic dump
18149 +of the raw kernel stacks.  For example, if the trace data is
18150 +
18151 +kdba_get_stack_info: esp=0xc04fbef8 cpu=0 task=c047b3e0
18152 +kdba_get_stack_info: ar->stack
18153 +    physical_start=0xc04fb000
18154 +    physical_end=0xc04fc000
18155 +    logical_start=0xc04fb038
18156 +    logical_end=0xc04fc000
18157 +    next=0xc04b4f44
18158 +    id=hardirq_ctx
18159 +    set MDCOUNT 1024
18160 +    mds 0xc04fb000
18161 +
18162 +then type the last two lines into KDB.  Repeat this for each stack listed by
18163 +kdba_get_stack_info on the failing backtrace.
18164 +
18165 +Send all the console output to the KDB maintainer.
18166 +
18167 +
18168 +Examples of Basic Block Debugging Output
18169 +========================================
18170 +
18171 +Example of the basic block analysis of fs/namei::getname() on i386.  Kernel
18172 +2.6.22, i386, compiled with frame pointers, gcc 4.1.0.
18173 +
18174 +Basic block debugging is very verbose, so set a high number of output lines.
18175 +You really need a reliable serial console to capture this amount of output.
18176 +
18177 +    [0]kdb> set LINES 10000
18178 +
18179 +A simple disassemble of getname().  This is not required for debugging purposes
18180 +since each instruction is printed as part of basic block debugging, but this can
18181 +be easier to read.
18182 +
18183 +    [0]kdb> id getname
18184 +    0xc015cce8 getname:         push   %ebp
18185 +    0xc015cce9 getname+0x1:     mov    %esp,%ebp
18186 +    0xc015cceb getname+0x3:     push   %edi
18187 +    0xc015ccec getname+0x4:     push   %esi
18188 +    0xc015cced getname+0x5:     push   %ebx
18189 +    0xc015ccee getname+0x6:     sub    $0x4,%esp
18190 +    0xc015ccf1 getname+0x9:     mov    %eax,%edi
18191 +    0xc015ccf3 getname+0xb:     mov    $0xd0,%edx
18192 +    0xc015ccf8 getname+0x10:    mov    0xc04b2120,%eax
18193 +    0xc015ccfd getname+0x15:    call   0xc0153009 kmem_cache_alloc
18194 +    0xc015cd02 getname+0x1a:    mov    %eax,0xfffffff0(%ebp)
18195 +    0xc015cd05 getname+0x1d:    mov    $0xfffffff4,%eax
18196 +    0xc015cd0a getname+0x22:    cmpl   $0x0,0xfffffff0(%ebp)
18197 +    0xc015cd0e getname+0x26:    je     0xc015cd7d getname+0x95
18198 +    0xc015cd10 getname+0x28:    mov    %esp,%eax
18199 +    0xc015cd12 getname+0x2a:    and    $0xfffff000,%eax
18200 +    0xc015cd17 getname+0x2f:    cmpl   $0xffffffff,0x18(%eax)
18201 +    0xc015cd1b getname+0x33:    je     0xc015cd39 getname+0x51
18202 +    0xc015cd1d getname+0x35:    mov    $0xfffffff2,%esi
18203 +    0xc015cd22 getname+0x3a:    cmp    $0xbfffffff,%edi
18204 +    0xc015cd28 getname+0x40:    ja     0xc015cd60 getname+0x78
18205 +    0xc015cd2a getname+0x42:    mov    $0xc0000000,%ebx
18206 +    0xc015cd2f getname+0x47:    sub    %edi,%ebx
18207 +    0xc015cd31 getname+0x49:    cmp    $0xfff,%ebx
18208 +    0xc015cd37 getname+0x4f:    jbe    0xc015cd3e getname+0x56
18209 +    0xc015cd39 getname+0x51:    mov    $0x1000,%ebx
18210 +    0xc015cd3e getname+0x56:    mov    %ebx,%ecx
18211 +    0xc015cd40 getname+0x58:    mov    %edi,%edx
18212 +    0xc015cd42 getname+0x5a:    mov    0xfffffff0(%ebp),%eax
18213 +    0xc015cd45 getname+0x5d:    call   0xc023dbb4 strncpy_from_user
18214 +    0xc015cd4a getname+0x62:    cmp    $0x0,%eax
18215 +    0xc015cd4d getname+0x65:    jle    0xc015cd5a getname+0x72
18216 +    0xc015cd4f getname+0x67:    mov    $0xffffffdc,%esi
18217 +    0xc015cd54 getname+0x6c:    cmp    %ebx,%eax
18218 +    0xc015cd56 getname+0x6e:    jae    0xc015cd60 getname+0x78
18219 +    0xc015cd58 getname+0x70:    jmp    0xc015cd71 getname+0x89
18220 +    0xc015cd5a getname+0x72:    je     0xc015cd76 getname+0x8e
18221 +    0xc015cd5c getname+0x74:    jge    0xc015cd71 getname+0x89
18222 +    0xc015cd5e getname+0x76:    mov    %eax,%esi
18223 +    0xc015cd60 getname+0x78:    mov    0xfffffff0(%ebp),%edx
18224 +    0xc015cd63 getname+0x7b:    mov    0xc04b2120,%eax
18225 +    0xc015cd68 getname+0x80:    call   0xc01521f1 kmem_cache_free
18226 +    0xc015cd6d getname+0x85:    mov    %esi,%eax
18227 +    0xc015cd6f getname+0x87:    jmp    0xc015cd7d getname+0x95
18228 +    0xc015cd71 getname+0x89:    mov    0xfffffff0(%ebp),%eax
18229 +    0xc015cd74 getname+0x8c:    jmp    0xc015cd7d getname+0x95
18230 +    0xc015cd76 getname+0x8e:    mov    $0xfffffffe,%esi
18231 +    0xc015cd7b getname+0x93:    jmp    0xc015cd60 getname+0x78
18232 +    0xc015cd7d getname+0x95:    pop    %edx
18233 +    0xc015cd7e getname+0x96:    pop    %ebx
18234 +    0xc015cd7f getname+0x97:    pop    %esi
18235 +    0xc015cd80 getname+0x98:    pop    %edi
18236 +    0xc015cd81 getname+0x99:    pop    %ebp
18237 +    0xc015cd82 getname+0x9a:    ret
18238 +
18239 +The bb1 command only one argument which must be an address, not a name.  bb1
18240 +turns on full basic block debugging and analyses the function containing the
18241 +supplied address.  Give bb1 the address of the exit point from this function,
18242 +IOW the return address that is stored on stack due to a call from this function
18243 +to the next function down the call stack.  Assume that getname() has called
18244 +kmem_cache_free() and something went wrong in kmem_cache_free() or one of the
18245 +functions that it calls.  The call to kmem_cache_free is at 0xc015cd68 and the
18246 +return address on stack is the instruction after the call, i.e. 0xc015cd6d, so
18247 +
18248 +    [0]kdb> bb1 0xc015cd6d
18249 +    bb_pass1: func_name getname func_start 0xc015cce8 func_end 0xc015cd83
18250 +
18251 +bb_pass1 has identified the function name and its start and end address.  For C
18252 +functions these are just the function start address and the next symbol in
18253 +kallsyms.  For Assembler code there may be spurious labels so the function name
18254 +may not match the label prior to the address given to bb1.  For an example of
18255 +that on i386, find the address of resume_userspace then pass that address to the
18256 +bb1 KDB command.
18257 +
18258 +    bb_pass1: end
18259 +      bb[0] start 0xc015cce8 end 0xc015cd38 drop_through 1
18260 +      bb[1] start 0xc015cd39 end 0xc015cd3d drop_through 1
18261 +      bb[2] start 0xc015cd3e end 0xc015cd58 drop_through 0
18262 +      bb[3] start 0xc015cd5a end 0xc015cd5f drop_through 1
18263 +      bb[4] start 0xc015cd60 end 0xc015cd6f drop_through 0
18264 +      bb[5] start 0xc015cd71 end 0xc015cd74 drop_through 0
18265 +      bb[6] start 0xc015cd76 end 0xc015cd7b drop_through 0
18266 +      bb[7] start 0xc015cd7d end 0xc015cd82 drop_through 0
18267 +      bb_jmp[0] from 0xc015cd0e to 0xc015cd7d drop_through 0
18268 +      bb_jmp[1] from 0xc015cd1b to 0xc015cd39 drop_through 0
18269 +      bb_jmp[2] from 0xc015cd28 to 0xc015cd60 drop_through 0
18270 +      bb_jmp[3] from 0xc015cd37 to 0xc015cd3e drop_through 0
18271 +      bb_jmp[4] from 0xc015cd4d to 0xc015cd5a drop_through 0
18272 +      bb_jmp[5] from 0xc015cd56 to 0xc015cd60 drop_through 0
18273 +      bb_jmp[6] from 0xc015cd58 to 0xc015cd71 drop_through 0
18274 +      bb_jmp[7] from 0xc015cd5a to 0xc015cd76 drop_through 0
18275 +      bb_jmp[8] from 0xc015cd5c to 0xc015cd71 drop_through 0
18276 +      bb_jmp[9] from 0xc015cd6f to 0xc015cd7d drop_through 0
18277 +      bb_jmp[10] from 0xc015cd74 to 0xc015cd7d drop_through 0
18278 +      bb_jmp[11] from 0xc015cd7b to 0xc015cd60 drop_through 0
18279 +      bb_jmp[12] from 0xc015cd38 to 0xc015cd39 drop_through 1
18280 +      bb_jmp[13] from 0xc015cd3d to 0xc015cd3e drop_through 1
18281 +      bb_jmp[14] from 0xc015cd5f to 0xc015cd60 drop_through 1
18282 +
18283 +After analysing the logic flow, we can see that getname() consists of 8 basic
18284 +blocks (nodes in bb_list[]).  5 of these blocks end in unconditional jumps, the
18285 +other 3 drop through to the next block.  There are 15 transfers of control
18286 +(vertices in bb_jmp_list[]).  12 of these transfers are explicit jmp or jcc
18287 +instructions, the other 3 are implicit transfers when dropping through from one
18288 +block to the next.  The node list is sorted by start address, the vertex list is
18289 +not sorted.
18290 +
18291 +Basic block 0 starts at the function start (0xc015cce8) and ends at 0xc015cd38.
18292 +0xc015cd39 is the target of a jump instruction (0xc015cd1b: je 0xc015cd39) so
18293 +0xc015cd39 starts a new block, which means that 0xc015cd38 becomes the end of
18294 +the previous block.  Because bb[0] does not end in an explicit jmp instruction,
18295 +there is a drop through from the end of bb[0] to the start of bb[1], see
18296 +bb_jmp[12].
18297 +
18298 +    bb_pass2: start
18299 +
18300 +To get the most accurate results from pass2, try to scan the directed graph by
18301 +only looking at nodes whose inputs are all defined.  Initially only process
18302 +nodes with no missing inputs.
18303 +
18304 +      bb_pass2_do_changed_blocks: allow_missing 0
18305 +
18306 +      bb[0]
18307 +      bb_reg_state c07282e0
18308 +        rax = rax
18309 +        rbx = rbx
18310 +        rcx = rcx
18311 +        rdx = rdx
18312 +        rdi = rdi
18313 +        rsi = rsi
18314 +        rbp = rbp
18315 +        rsp = osp+0x0
18316 +
18317 +The initial state for bb[0] is the same for all C functions.  Each register
18318 +contains its own abstract value, except for rsp which is defined in terms of the
18319 +original stack pointer (osp).
18320 +
18321 +     '0xc015cce8 getname:         push   %ebp'
18322 +
18323 +The first instruction of getname() saves the frame pointer.
18324 +
18325 +      opcode 'push' matched by 'push', usage 44
18326 +      src  R: %ebp base_rc 8 (rbp)
18327 +
18328 +bb_usage() reports how the instruction was recognised and how its operands were
18329 +decoded.  Although this is i386 (ebp), it is reported as rbp.  Using the x86_64
18330 +names for registers throughout makes it easier to create common code for the two
18331 +architecures.
18332 +
18333 +      rsp osp offset +0x0 -> -0x4
18334 +
18335 +A push instruction decrements rsp by 4 (i386) or 8 (x86_64) bytes.  rsp
18336 +originally contained the original stack pointer (osp), now it contains the
18337 +original stack pointer - 4.
18338 +
18339 +      *(rsp+0x0 osp-0x4) = rbp slot 0
18340 +
18341 +The stack location pointed to by *rsp now contains the original value of rbp.
18342 +Since rsp contains (osp-0x4), *(osp-0x4) contains rbp.  It is slot 0 in the
18343 +memory array associated with the register state.
18344 +
18345 +     '0xc015cce9 getname+0x1:     mov    %esp,%ebp'
18346 +      opcode 'mov' matched by 'mov', usage 36
18347 +      src  R: %esp base_rc 9 (rsp)
18348 +      dst  R: %ebp base_rc 8 (rbp)
18349 +      rbp = rsp (osp-0x4)
18350 +
18351 +Copy esp (rsp) to ebp (rbp).  rsp contained (osp-0x4) so rbp also contains
18352 +(osp-0x4).  Any reference to data via either rbp or rsp will now be tracked as a
18353 +stack location.
18354 +
18355 +     '0xc015cceb getname+0x3:     push   %edi'
18356 +      opcode 'push' matched by 'push', usage 44
18357 +      src  R: %edi base_rc 6 (rdi)
18358 +      rsp osp offset -0x4 -> -0x8
18359 +      *(rsp+0x0 osp-0x8) = rdi slot 1
18360 +     '0xc015ccec getname+0x4:     push   %esi'
18361 +      opcode 'push' matched by 'push', usage 44
18362 +      src  R: %esi base_rc 7 (rsi)
18363 +      rsp osp offset -0x8 -> -0xc
18364 +      *(rsp+0x0 osp-0xc) = rsi slot 2
18365 +     '0xc015cced getname+0x5:     push   %ebx'
18366 +      opcode 'push' matched by 'push', usage 44
18367 +      src  R: %ebx base_rc 3 (rbx)
18368 +      rsp osp offset -0xc -> -0x10
18369 +      *(rsp+0x0 osp-0x10) = rbx slot 3
18370 +
18371 +Push 3 registers to stack.  rsp is adjusted for each push and stack locations
18372 +are assigned to contain the values of edi, esi and ebx.  This sequence is very
18373 +common in i386 C functions.  edi, esi and ebx are preserved registers on i386,
18374 +but gcc wants to use them for scratch space.  The original contents iof these
18375 +registers must be saved on stack and restored before returning to our caller.
18376 +
18377 +     '0xc015ccee getname+0x6:     sub    $0x4,%esp'
18378 +      opcode 'sub' matched by 'sub', usage 51
18379 +      src  I: $0x4
18380 +      dst  R: %esp base_rc 9 (rsp)
18381 +      rsp osp offset -0x10 -> -0x14
18382 +
18383 +Subtract 4 bytes from esp.  This defines the local stack variables.  Sorry,
18384 +names for local stack variables are not available to KDB.
18385 +
18386 +     '0xc015ccf1 getname+0x9:     mov    %eax,%edi'
18387 +      opcode 'mov' matched by 'mov', usage 36
18388 +      src  R: %eax base_rc 2 (rax)
18389 +      dst  R: %edi base_rc 6 (rdi)
18390 +      rdi = rax (rax)
18391 +
18392 +Having saved edi on stack, gcc now overwrites edi with eax.  At this point rax
18393 +still contains its original value, so rdi now contains a copy of rax, as well as
18394 +the original value which is still in rax.  This is a common sequence in C code.
18395 +rax contains argument 0 but it is also a scratch register.  If the code needs to
18396 +use argument 0 later then its value must be saved somewhere before executing any
18397 +instruction that changes rax.  edi is a preserved register so its contents will
18398 +not be changed by any function that we call, or if it is changed then it will be
18399 +restored before returning to this function.
18400 +
18401 +rax is listed in the arch specific bb_param_reg[] list and the code is reading
18402 +from rax while it still contains its original value.  The only way that makes
18403 +any sense is when rax is an input argument to getname().  We note that fact in
18404 +bb_reg_read().
18405 +
18406 +     '0xc015ccf3 getname+0xb:     mov    $0xd0,%edx'
18407 +      opcode 'mov' matched by 'mov', usage 36
18408 +      src  I: $0xd0
18409 +      dst  R: %edx base_rc 5 (rdx)
18410 +      rdx = undefined
18411 +
18412 +Moving an constant value to edx.  Although this is a constant, it does not refer
18413 +to any of the original values that were supplied to this function.  Therefore
18414 +rdx becomes undefined for the purposes of the code analysis.
18415 +
18416 +     '0xc015ccf8 getname+0x10:    mov    0xc04b2120,%eax'
18417 +      opcode 'mov' matched by 'mov', usage 36
18418 +      src  M: 0xc04b2120
18419 +      dst  R: %eax base_rc 2 (rax)
18420 +      rax = undefined
18421 +
18422 +Moving a constant value to eax makes rax undefined.
18423 +
18424 +     '0xc015ccfd getname+0x15:    call   0xc0153009 <kmem_cache_alloc>'
18425 +      opcode 'call' matched by 'call', usage 17
18426 +      src  M: 0xc0153009
18427 +      bb_reg_state c0728658
18428 +        rax = undefined
18429 +        rbx = rbx
18430 +        rcx = rcx
18431 +        rdx = undefined
18432 +        rdi = rax
18433 +        rsi = rsi
18434 +        rbp = osp-0x4
18435 +        rsp = osp-0x14
18436 +        slot 0 offset_address -0x4 rbp
18437 +        slot 1 offset_address -0x8 rdi
18438 +        slot 2 offset_address -0xc rsi
18439 +        slot 3 offset_address -0x10 rbx
18440 +
18441 +Basic block debugging prints the register and memory state when transfering
18442 +control between blocks and when issuing call instructions.  The call state is
18443 +mainly useful when C code calls assembler routines, especially if you are not
18444 +sure what state the assembler code expects.  Not all of our assembler is as well
18445 +documented as it could be :(
18446 +
18447 +      rax = undefined
18448 +      rcx = undefined
18449 +      rdx = undefined
18450 +
18451 +The i386 ABI says that some registers are preserved across calls, see the arch
18452 +specific bb_preserved_reg[] list.  Any registers not in that list automatically
18453 +become undefined after a call instruction.
18454 +
18455 +     '0xc015cd02 getname+0x1a:    mov    %eax,0xfffffff0(%ebp)'
18456 +      opcode 'mov' matched by 'mov', usage 36
18457 +      src  R: %eax base_rc 2 (rax)
18458 +      dst  M: 0xfffffff0(%ebp) base_rc 8 (rbp)
18459 +
18460 +eax is the return value from the call, it is being saved at offset 0xfffffff0
18461 +(-0x10) from ebp.  Since rbp contains (osp-0x4) the return value is being stored
18462 +at (osp-0x14).  This is a stack location but we have no record of any data being
18463 +held at that location, it is part of the local stack variables.
18464 +
18465 +     '0xc015cd05 getname+0x1d:    mov    $0xfffffff4,%eax'
18466 +      opcode 'mov' matched by 'mov', usage 36
18467 +      src  I: $0xfffffff4
18468 +      dst  R: %eax base_rc 2 (rax)
18469 +      rax = undefined
18470 +     '0xc015cd0a getname+0x22:    cmpl   $0x0,0xfffffff0(%ebp)'
18471 +      opcode 'cmpl' matched by 'cmp', usage 3
18472 +      src  I: $0x0
18473 +      dst  M: 0xfffffff0(%ebp) base_rc 8 (rbp)
18474 +     '0xc015cd0e getname+0x26:    je     0xc015cd7d <getname+0x95>'
18475 +      opcode 'je' matched by 'j', usage 28
18476 +      src  M: 0xc015cd7d
18477 +      bb_reg_state c0728658
18478 +        rax = undefined
18479 +        rbx = rbx
18480 +        rcx = undefined
18481 +        rdx = undefined
18482 +        rdi = rax
18483 +        rsi = rsi
18484 +        rbp = osp-0x4
18485 +        rsp = osp-0x14
18486 +        slot 0 offset_address -0x4 rbp
18487 +        slot 1 offset_address -0x8 rdi
18488 +        slot 2 offset_address -0xc rsi
18489 +        slot 3 offset_address -0x10 rbx
18490 +
18491 +Transfer of control, print the register and memory state.
18492 +
18493 +      matched: from 0xc015cd0e to 0xc015cd7d drop_through 0 bb_jmp[0]
18494 +
18495 +Which bb_jmp_list[] entry matches this transfer.
18496 +
18497 +      new state c07286b8
18498 +
18499 +The current abstract register and memory state is cloned at address c07286b8.
18500 +This state becomes one of the inputs to the basic block whose start address is
18501 +0xc015cd7d.
18502 +
18503 +     '0xc015cd10 getname+0x28:    mov    %esp,%eax'
18504 +      opcode 'mov' matched by 'mov', usage 36
18505 +      src  R: %esp base_rc 9 (rsp)
18506 +      dst  R: %eax base_rc 2 (rax)
18507 +      rax = rsp (osp-0x14)
18508 +
18509 +Copy rsp which contains (osp-0x14) to rax.  rax contains a valid stack pointer.
18510 +
18511 +     '0xc015cd12 getname+0x2a:    and    $0xfffff000,%eax'
18512 +      opcode 'and' matched by 'and', usage 11
18513 +      src  I: $0xfffff000
18514 +      dst  R: %eax base_rc 2 (rax)
18515 +      rax = undefined
18516 +
18517 +But not for long.
18518 +
18519 +     '0xc015cd17 getname+0x2f:    cmpl   $0xffffffff,0x18(%eax)'
18520 +      opcode 'cmpl' matched by 'cmp', usage 3
18521 +      src  I: $0xffffffff
18522 +      dst  M: 0x18(%eax) base_rc 2 (rax)
18523 +     '0xc015cd1b getname+0x33:    je     0xc015cd39 <getname+0x51>'
18524 +      opcode 'je' matched by 'j', usage 28
18525 +      src  M: 0xc015cd39
18526 +      bb_reg_state c0728658
18527 +        rax = undefined
18528 +        rbx = rbx
18529 +        rcx = undefined
18530 +        rdx = undefined
18531 +        rdi = rax
18532 +        rsi = rsi
18533 +        rbp = osp-0x4
18534 +        rsp = osp-0x14
18535 +        slot 0 offset_address -0x4 rbp
18536 +        slot 1 offset_address -0x8 rdi
18537 +        slot 2 offset_address -0xc rsi
18538 +        slot 3 offset_address -0x10 rbx
18539 +
18540 +Another transfer of control, print the state.
18541 +
18542 +      matched: from 0xc015cd1b to 0xc015cd39 drop_through 0 bb_jmp[1]
18543 +
18544 +Which bb_jmp_list[] entry was used.
18545 +
18546 +      reuse bb_jmp[0]
18547 +
18548 +To save space, we only clone the state if it is different.  Otherwise we reuse
18549 +the state from another vertex and bump the reference count.
18550 +
18551 +     '0xc015cd1d getname+0x35:    mov    $0xfffffff2,%esi'
18552 +      opcode 'mov' matched by 'mov', usage 36
18553 +      src  I: $0xfffffff2
18554 +      dst  R: %esi base_rc 7 (rsi)
18555 +      rsi = undefined
18556 +
18557 +Using esi as a scratch register, even though the i386 ABi says that esi is a
18558 +preserved register.  Not to worry, the original value of rsi was saved on stack
18559 +on entry and it will be restored before exit.
18560 +
18561 +     '0xc015cd22 getname+0x3a:    cmp    $0xbfffffff,%edi'
18562 +      opcode 'cmp' matched by 'cmp', usage 3
18563 +      src  I: $0xbfffffff
18564 +      dst  R: %edi base_rc 6 (rdi)
18565 +     '0xc015cd28 getname+0x40:    ja     0xc015cd60 <getname+0x78>'
18566 +      opcode 'ja' matched by 'j', usage 28
18567 +      src  M: 0xc015cd60
18568 +      bb_reg_state c0728658
18569 +        rax = undefined
18570 +        rbx = rbx
18571 +        rcx = undefined
18572 +        rdx = undefined
18573 +        rdi = rax
18574 +        rsi = undefined
18575 +        rbp = osp-0x4
18576 +        rsp = osp-0x14
18577 +        slot 0 offset_address -0x4 rbp
18578 +        slot 1 offset_address -0x8 rdi
18579 +        slot 2 offset_address -0xc rsi
18580 +        slot 3 offset_address -0x10 rbx
18581 +      matched: from 0xc015cd28 to 0xc015cd60 drop_through 0 bb_jmp[2]
18582 +      new state c0728710
18583 +
18584 +This state is different from any states already saved, clone to a new entry.
18585 +
18586 +     '0xc015cd2a getname+0x42:    mov    $0xc0000000,%ebx'
18587 +      opcode 'mov' matched by 'mov', usage 36
18588 +      src  I: $0xc0000000
18589 +      dst  R: %ebx base_rc 3 (rbx)
18590 +      rbx = undefined
18591 +     '0xc015cd2f getname+0x47:    sub    %edi,%ebx'
18592 +      opcode 'sub' matched by 'sub', usage 51
18593 +      src  R: %edi base_rc 6 (rdi)
18594 +      dst  R: %ebx base_rc 3 (rbx)
18595 +      rbx = undefined
18596 +     '0xc015cd31 getname+0x49:    cmp    $0xfff,%ebx'
18597 +      opcode 'cmp' matched by 'cmp', usage 3
18598 +      src  I: $0xfff
18599 +      dst  R: %ebx base_rc 3 (rbx)
18600 +     '0xc015cd37 getname+0x4f:    jbe    0xc015cd3e <getname+0x56>'
18601 +      opcode 'jbe' matched by 'j', usage 28
18602 +      src  M: 0xc015cd3e
18603 +      bb_reg_state c0728658
18604 +        rax = undefined
18605 +        rbx = undefined
18606 +        rcx = undefined
18607 +        rdx = undefined
18608 +        rdi = rax
18609 +        rsi = undefined
18610 +        rbp = osp-0x4
18611 +        rsp = osp-0x14
18612 +        slot 0 offset_address -0x4 rbp
18613 +        slot 1 offset_address -0x8 rdi
18614 +        slot 2 offset_address -0xc rsi
18615 +        slot 3 offset_address -0x10 rbx
18616 +      matched: from 0xc015cd37 to 0xc015cd3e drop_through 0 bb_jmp[3]
18617 +      new state c0728768
18618 +
18619 +This state is different from any states already saved, clone to a new entry.
18620 +
18621 +      bb_reg_state c0728658
18622 +        rax = undefined
18623 +        rbx = undefined
18624 +        rcx = undefined
18625 +        rdx = undefined
18626 +        rdi = rax
18627 +        rsi = undefined
18628 +        rbp = osp-0x4
18629 +        rsp = osp-0x14
18630 +        slot 0 offset_address -0x4 rbp
18631 +        slot 1 offset_address -0x8 rdi
18632 +        slot 2 offset_address -0xc rsi
18633 +        slot 3 offset_address -0x10 rbx
18634 +      matched: from 0xc015cd38 to 0xc015cd39 drop_through 1 bb_jmp[12]
18635 +      reuse bb_jmp[3]
18636 +
18637 +Basic block 0 drops through to basic block 1, treat it as an implicit transfer
18638 +of control.  The state is the same as the previous jump instruction so reuse it
18639 +and bump the reference count.
18640 +
18641 +That ends basic block 0, now pick the next block in the list that (a) needs to
18642 +be scanned and (b) has all its input states defined.  In this case bb[1].
18643 +
18644 +      bb[1]
18645 +
18646 +bb[1] starts at 0xc015cd39 and has two paths that transfer control to it.
18647 +bb_jmp[1] from an explicit jump at 0xc015cd1b and a drop through at bb_jmp[12].
18648 +Where there is more than one input state we have to merge them and reconcile the
18649 +final value.
18650 +
18651 +      first state c07286b8
18652 +
18653 +The first input state is stored at c07286b8.  Looking back through the trace we
18654 +find that entry associated with bb_jmp[0], not bb_jmp[1] as expected.  However
18655 +bb_jmp[1] reused the state that was stored for bb_jmp[0] so all is well.
18656 +
18657 +      bb_reg_state c0728658
18658 +        rax = undefined
18659 +        rbx = rbx
18660 +        rcx = undefined
18661 +        rdx = undefined
18662 +        rdi = rax
18663 +        rsi = rsi
18664 +        rbp = osp-0x4
18665 +        rsp = osp-0x14
18666 +        slot 0 offset_address -0x4 rbp
18667 +        slot 1 offset_address -0x8 rdi
18668 +        slot 2 offset_address -0xc rsi
18669 +        slot 3 offset_address -0x10 rbx
18670 +
18671 +The first state for bb[1].
18672 +
18673 +      merging state c0728768
18674 +
18675 +Now merge the second state, which is held at c0728768.
18676 +
18677 +      rbx = undefined
18678 +      rsi = undefined
18679 +
18680 +The two states disagree on the values being tracked in rbx and rsi.  Compiler
18681 +theory 101 says that if two or more paths to a basic block have different values
18682 +for a register then that register cannot be relied on at the start of the block,
18683 +so make it undefined.  The same logic applies to memory locations.
18684 +
18685 +      final state
18686 +      bb_reg_state c0728658
18687 +        rax = undefined
18688 +        rbx = undefined
18689 +        rcx = undefined
18690 +        rdx = undefined
18691 +        rdi = rax
18692 +        rsi = undefined
18693 +        rbp = osp-0x4
18694 +        rsp = osp-0x14
18695 +        slot 0 offset_address -0x4 rbp
18696 +        slot 1 offset_address -0x8 rdi
18697 +        slot 2 offset_address -0xc rsi
18698 +        slot 3 offset_address -0x10 rbx
18699 +
18700 +After merging all the input states, this is the final starting state for bb[1].
18701 +Now track what bb[1] does to the state.
18702 +
18703 +     '0xc015cd39 getname+0x51:    mov    $0x1000,%ebx'
18704 +      opcode 'mov' matched by 'mov', usage 36
18705 +      src  I: $0x1000
18706 +      dst  R: %ebx base_rc 3 (rbx)
18707 +      rbx = undefined
18708 +      bb_reg_state c0728658
18709 +        rax = undefined
18710 +        rbx = undefined
18711 +        rcx = undefined
18712 +        rdx = undefined
18713 +        rdi = rax
18714 +        rsi = undefined
18715 +        rbp = osp-0x4
18716 +        rsp = osp-0x14
18717 +        slot 0 offset_address -0x4 rbp
18718 +        slot 1 offset_address -0x8 rdi
18719 +        slot 2 offset_address -0xc rsi
18720 +        slot 3 offset_address -0x10 rbx
18721 +      matched: from 0xc015cd3d to 0xc015cd3e drop_through 1 bb_jmp[13]
18722 +      reuse bb_jmp[3]
18723 +
18724 +bb[1] is a single instruction which drops through to bb[2].
18725 +
18726 +      bb[2]
18727 +      first state c0728768
18728 +      bb_reg_state c0728658
18729 +        rax = undefined
18730 +        rbx = undefined
18731 +        rcx = undefined
18732 +        rdx = undefined
18733 +        rdi = rax
18734 +        rsi = undefined
18735 +        rbp = osp-0x4
18736 +        rsp = osp-0x14
18737 +        slot 0 offset_address -0x4 rbp
18738 +        slot 1 offset_address -0x8 rdi
18739 +        slot 2 offset_address -0xc rsi
18740 +        slot 3 offset_address -0x10 rbx
18741 +      merging state c0728768
18742 +
18743 +bb[2] has two inputs, both vertices are pointing to input state c0728768.
18744 +Merging an entry with itself has no effect.
18745 +
18746 +     '0xc015cd3e getname+0x56:    mov    %ebx,%ecx'
18747 +      opcode 'mov' matched by 'mov', usage 36
18748 +      src  R: %ebx base_rc 3 (rbx)
18749 +      dst  R: %ecx base_rc 4 (rcx)
18750 +      rcx = rbx (undefined)
18751 +     '0xc015cd40 getname+0x58:    mov    %edi,%edx'
18752 +      opcode 'mov' matched by 'mov', usage 36
18753 +      src  R: %edi base_rc 6 (rdi)
18754 +      dst  R: %edx base_rc 5 (rdx)
18755 +      rdx = rdi (rax)
18756 +     '0xc015cd42 getname+0x5a:    mov    0xfffffff0(%ebp),%eax'
18757 +      opcode 'mov' matched by 'mov', usage 36
18758 +      src  M: 0xfffffff0(%ebp) base_rc 8 (rbp)
18759 +      dst  R: %eax base_rc 2 (rax)
18760 +      rax = *(rbp-0x10) (osp-0x14)  rax = undefined
18761 +     '0xc015cd45 getname+0x5d:    call   0xc023dbb4 <strncpy_from_user>'
18762 +      opcode 'call' matched by 'call', usage 17
18763 +      src  M: 0xc023dbb4
18764 +      bb_reg_state c0728658
18765 +        rax = undefined
18766 +        rbx = undefined
18767 +        rcx = undefined
18768 +        rdx = rax
18769 +        rdi = rax
18770 +        rsi = undefined
18771 +        rbp = osp-0x4
18772 +        rsp = osp-0x14
18773 +        slot 0 offset_address -0x4 rbp
18774 +        slot 1 offset_address -0x8 rdi
18775 +        slot 2 offset_address -0xc rsi
18776 +        slot 3 offset_address -0x10 rbx
18777 +      rax = undefined
18778 +      rcx = undefined
18779 +      rdx = undefined
18780 +     '0xc015cd4a getname+0x62:    cmp    $0x0,%eax'
18781 +      opcode 'cmp' matched by 'cmp', usage 3
18782 +      src  I: $0x0
18783 +      dst  R: %eax base_rc 2 (rax)
18784 +     '0xc015cd4d getname+0x65:    jle    0xc015cd5a <getname+0x72>'
18785 +      opcode 'jle' matched by 'j', usage 28
18786 +      src  M: 0xc015cd5a
18787 +      bb_reg_state c0728658
18788 +        rax = undefined
18789 +        rbx = undefined
18790 +        rcx = undefined
18791 +        rdx = undefined
18792 +        rdi = rax
18793 +        rsi = undefined
18794 +        rbp = osp-0x4
18795 +        rsp = osp-0x14
18796 +        slot 0 offset_address -0x4 rbp
18797 +        slot 1 offset_address -0x8 rdi
18798 +        slot 2 offset_address -0xc rsi
18799 +        slot 3 offset_address -0x10 rbx
18800 +      matched: from 0xc015cd4d to 0xc015cd5a drop_through 0 bb_jmp[4]
18801 +      reuse bb_jmp[3]
18802 +     '0xc015cd4f getname+0x67:    mov    $0xffffffdc,%esi'
18803 +      opcode 'mov' matched by 'mov', usage 36
18804 +      src  I: $0xffffffdc
18805 +      dst  R: %esi base_rc 7 (rsi)
18806 +      rsi = undefined
18807 +     '0xc015cd54 getname+0x6c:    cmp    %ebx,%eax'
18808 +      opcode 'cmp' matched by 'cmp', usage 3
18809 +      src  R: %ebx base_rc 3 (rbx)
18810 +      dst  R: %eax base_rc 2 (rax)
18811 +     '0xc015cd56 getname+0x6e:    jae    0xc015cd60 <getname+0x78>'
18812 +      opcode 'jae' matched by 'j', usage 28
18813 +      src  M: 0xc015cd60
18814 +      bb_reg_state c0728658
18815 +        rax = undefined
18816 +        rbx = undefined
18817 +        rcx = undefined
18818 +        rdx = undefined
18819 +        rdi = rax
18820 +        rsi = undefined
18821 +        rbp = osp-0x4
18822 +        rsp = osp-0x14
18823 +        slot 0 offset_address -0x4 rbp
18824 +        slot 1 offset_address -0x8 rdi
18825 +        slot 2 offset_address -0xc rsi
18826 +        slot 3 offset_address -0x10 rbx
18827 +      matched: from 0xc015cd56 to 0xc015cd60 drop_through 0 bb_jmp[5]
18828 +      reuse bb_jmp[3]
18829 +     '0xc015cd58 getname+0x70:    jmp    0xc015cd71 <getname+0x89>'
18830 +      opcode 'jmp' matched by 'j', usage 28
18831 +      src  M: 0xc015cd71
18832 +      bb_reg_state c0728658
18833 +        rax = undefined
18834 +        rbx = undefined
18835 +        rcx = undefined
18836 +        rdx = undefined
18837 +        rdi = rax
18838 +        rsi = undefined
18839 +        rbp = osp-0x4
18840 +        rsp = osp-0x14
18841 +        slot 0 offset_address -0x4 rbp
18842 +        slot 1 offset_address -0x8 rdi
18843 +        slot 2 offset_address -0xc rsi
18844 +        slot 3 offset_address -0x10 rbx
18845 +      matched: from 0xc015cd58 to 0xc015cd71 drop_through 0 bb_jmp[6]
18846 +      reuse bb_jmp[3]
18847 +
18848 +      bb[3]
18849 +      first state c0728768
18850 +      bb_reg_state c0728658
18851 +        rax = undefined
18852 +        rbx = undefined
18853 +        rcx = undefined
18854 +        rdx = undefined
18855 +        rdi = rax
18856 +        rsi = undefined
18857 +        rbp = osp-0x4
18858 +        rsp = osp-0x14
18859 +        slot 0 offset_address -0x4 rbp
18860 +        slot 1 offset_address -0x8 rdi
18861 +        slot 2 offset_address -0xc rsi
18862 +        slot 3 offset_address -0x10 rbx
18863 +
18864 +bb[3] only has one input, nothing to merge.
18865 +
18866 +     '0xc015cd5a getname+0x72:    je     0xc015cd76 <getname+0x8e>'
18867 +      opcode 'je' matched by 'j', usage 28
18868 +      src  M: 0xc015cd76
18869 +      bb_reg_state c0728658
18870 +        rax = undefined
18871 +        rbx = undefined
18872 +        rcx = undefined
18873 +        rdx = undefined
18874 +        rdi = rax
18875 +        rsi = undefined
18876 +        rbp = osp-0x4
18877 +        rsp = osp-0x14
18878 +        slot 0 offset_address -0x4 rbp
18879 +        slot 1 offset_address -0x8 rdi
18880 +        slot 2 offset_address -0xc rsi
18881 +        slot 3 offset_address -0x10 rbx
18882 +      matched: from 0xc015cd5a to 0xc015cd76 drop_through 0 bb_jmp[7]
18883 +      reuse bb_jmp[3]
18884 +     '0xc015cd5c getname+0x74:    jge    0xc015cd71 <getname+0x89>'
18885 +      opcode 'jge' matched by 'j', usage 28
18886 +      src  M: 0xc015cd71
18887 +      bb_reg_state c0728658
18888 +        rax = undefined
18889 +        rbx = undefined
18890 +        rcx = undefined
18891 +        rdx = undefined
18892 +        rdi = rax
18893 +        rsi = undefined
18894 +        rbp = osp-0x4
18895 +        rsp = osp-0x14
18896 +        slot 0 offset_address -0x4 rbp
18897 +        slot 1 offset_address -0x8 rdi
18898 +        slot 2 offset_address -0xc rsi
18899 +        slot 3 offset_address -0x10 rbx
18900 +      matched: from 0xc015cd5c to 0xc015cd71 drop_through 0 bb_jmp[8]
18901 +      reuse bb_jmp[3]
18902 +     '0xc015cd5e getname+0x76:    mov    %eax,%esi'
18903 +      opcode 'mov' matched by 'mov', usage 36
18904 +      src  R: %eax base_rc 2 (rax)
18905 +      dst  R: %esi base_rc 7 (rsi)
18906 +      rsi = rax (undefined)
18907 +      bb_reg_state c0728658
18908 +        rax = undefined
18909 +        rbx = undefined
18910 +        rcx = undefined
18911 +        rdx = undefined
18912 +        rdi = rax
18913 +        rsi = undefined
18914 +        rbp = osp-0x4
18915 +        rsp = osp-0x14
18916 +        slot 0 offset_address -0x4 rbp
18917 +        slot 1 offset_address -0x8 rdi
18918 +        slot 2 offset_address -0xc rsi
18919 +        slot 3 offset_address -0x10 rbx
18920 +      matched: from 0xc015cd5f to 0xc015cd60 drop_through 1 bb_jmp[14]
18921 +      reuse bb_jmp[3]
18922 +
18923 +      bb[5]
18924 +      first state c0728768
18925 +      bb_reg_state c0728658
18926 +        rax = undefined
18927 +        rbx = undefined
18928 +        rcx = undefined
18929 +        rdx = undefined
18930 +        rdi = rax
18931 +        rsi = undefined
18932 +        rbp = osp-0x4
18933 +        rsp = osp-0x14
18934 +        slot 0 offset_address -0x4 rbp
18935 +        slot 1 offset_address -0x8 rdi
18936 +        slot 2 offset_address -0xc rsi
18937 +        slot 3 offset_address -0x10 rbx
18938 +      merging state c0728768
18939 +     '0xc015cd71 getname+0x89:    mov    0xfffffff0(%ebp),%eax'
18940 +      opcode 'mov' matched by 'mov', usage 36
18941 +      src  M: 0xfffffff0(%ebp) base_rc 8 (rbp)
18942 +      dst  R: %eax base_rc 2 (rax)
18943 +      rax = *(rbp-0x10) (osp-0x14)  rax = undefined
18944 +     '0xc015cd74 getname+0x8c:    jmp    0xc015cd7d <getname+0x95>'
18945 +      opcode 'jmp' matched by 'j', usage 28
18946 +      src  M: 0xc015cd7d
18947 +      bb_reg_state c0728658
18948 +        rax = undefined
18949 +        rbx = undefined
18950 +        rcx = undefined
18951 +        rdx = undefined
18952 +        rdi = rax
18953 +        rsi = undefined
18954 +        rbp = osp-0x4
18955 +        rsp = osp-0x14
18956 +        slot 0 offset_address -0x4 rbp
18957 +        slot 1 offset_address -0x8 rdi
18958 +        slot 2 offset_address -0xc rsi
18959 +        slot 3 offset_address -0x10 rbx
18960 +      matched: from 0xc015cd74 to 0xc015cd7d drop_through 0 bb_jmp[10]
18961 +      reuse bb_jmp[3]
18962 +
18963 +      bb[6]
18964 +      first state c0728768
18965 +      bb_reg_state c0728658
18966 +        rax = undefined
18967 +        rbx = undefined
18968 +        rcx = undefined
18969 +        rdx = undefined
18970 +        rdi = rax
18971 +        rsi = undefined
18972 +        rbp = osp-0x4
18973 +        rsp = osp-0x14
18974 +        slot 0 offset_address -0x4 rbp
18975 +        slot 1 offset_address -0x8 rdi
18976 +        slot 2 offset_address -0xc rsi
18977 +        slot 3 offset_address -0x10 rbx
18978 +     '0xc015cd76 getname+0x8e:    mov    $0xfffffffe,%esi'
18979 +      opcode 'mov' matched by 'mov', usage 36
18980 +      src  I: $0xfffffffe
18981 +      dst  R: %esi base_rc 7 (rsi)
18982 +      rsi = undefined
18983 +     '0xc015cd7b getname+0x93:    jmp    0xc015cd60 <getname+0x78>'
18984 +      opcode 'jmp' matched by 'j', usage 28
18985 +      src  M: 0xc015cd60
18986 +      bb_reg_state c0728658
18987 +        rax = undefined
18988 +        rbx = undefined
18989 +        rcx = undefined
18990 +        rdx = undefined
18991 +        rdi = rax
18992 +        rsi = undefined
18993 +        rbp = osp-0x4
18994 +        rsp = osp-0x14
18995 +        slot 0 offset_address -0x4 rbp
18996 +        slot 1 offset_address -0x8 rdi
18997 +        slot 2 offset_address -0xc rsi
18998 +        slot 3 offset_address -0x10 rbx
18999 +      matched: from 0xc015cd7b to 0xc015cd60 drop_through 0 bb_jmp[11]
19000 +      reuse bb_jmp[3]
19001 +
19002 +      bb[4]
19003 +      first state c0728710
19004 +      bb_reg_state c0728658
19005 +        rax = undefined
19006 +        rbx = rbx
19007 +        rcx = undefined
19008 +        rdx = undefined
19009 +        rdi = rax
19010 +        rsi = undefined
19011 +        rbp = osp-0x4
19012 +        rsp = osp-0x14
19013 +        slot 0 offset_address -0x4 rbp
19014 +        slot 1 offset_address -0x8 rdi
19015 +        slot 2 offset_address -0xc rsi
19016 +        slot 3 offset_address -0x10 rbx
19017 +      merging state c0728768
19018 +      rbx = undefined
19019 +      merging state c0728768
19020 +      merging state c0728768
19021 +
19022 +bb[4] has 4 inputs, 3 of which have the same state.  One one path (state
19023 +c0728710) rbx is defined, on the others (c0728768) rbx is undefined so the final
19024 +state has rbx as undefined.
19025 +
19026 +      final state
19027 +      bb_reg_state c0728658
19028 +        rax = undefined
19029 +        rbx = undefined
19030 +        rcx = undefined
19031 +        rdx = undefined
19032 +        rdi = rax
19033 +        rsi = undefined
19034 +        rbp = osp-0x4
19035 +        rsp = osp-0x14
19036 +        slot 0 offset_address -0x4 rbp
19037 +        slot 1 offset_address -0x8 rdi
19038 +        slot 2 offset_address -0xc rsi
19039 +        slot 3 offset_address -0x10 rbx
19040 +     '0xc015cd60 getname+0x78:    mov    0xfffffff0(%ebp),%edx'
19041 +      opcode 'mov' matched by 'mov', usage 36
19042 +      src  M: 0xfffffff0(%ebp) base_rc 8 (rbp)
19043 +      dst  R: %edx base_rc 5 (rdx)
19044 +      rdx = *(rbp-0x10) (osp-0x14)  rdx = undefined
19045 +     '0xc015cd63 getname+0x7b:    mov    0xc04b2120,%eax'
19046 +      opcode 'mov' matched by 'mov', usage 36
19047 +      src  M: 0xc04b2120
19048 +      dst  R: %eax base_rc 2 (rax)
19049 +      rax = undefined
19050 +     '0xc015cd68 getname+0x80:    call   0xc01521f1 <kmem_cache_free>'
19051 +      opcode 'call' matched by 'call', usage 17
19052 +      src  M: 0xc01521f1
19053 +      bb_reg_state c0728658
19054 +        rax = undefined
19055 +        rbx = undefined
19056 +        rcx = undefined
19057 +        rdx = undefined
19058 +        rdi = rax
19059 +        rsi = undefined
19060 +        rbp = osp-0x4
19061 +        rsp = osp-0x14
19062 +        slot 0 offset_address -0x4 rbp
19063 +        slot 1 offset_address -0x8 rdi
19064 +        slot 2 offset_address -0xc rsi
19065 +        slot 3 offset_address -0x10 rbx
19066 +      rax = undefined
19067 +      rcx = undefined
19068 +      rdx = undefined
19069 +      bb_reg_state c0728658
19070 +        rax = undefined
19071 +        rbx = undefined
19072 +        rcx = undefined
19073 +        rdx = undefined
19074 +        rdi = rax
19075 +        rsi = undefined
19076 +        rbp = osp-0x4
19077 +        rsp = osp-0x14
19078 +        slot 0 offset_address -0x4 rbp
19079 +        slot 1 offset_address -0x8 rdi
19080 +        slot 2 offset_address -0xc rsi
19081 +        slot 3 offset_address -0x10 rbx
19082 +     '0xc015cd6d getname+0x85:    mov    %esi,%eax'
19083 +      opcode 'mov' matched by 'mov', usage 36
19084 +      src  R: %esi base_rc 7 (rsi)
19085 +      dst  R: %eax base_rc 2 (rax)
19086 +      rax = rsi (undefined)
19087 +     '0xc015cd6f getname+0x87:    jmp    0xc015cd7d <getname+0x95>'
19088 +      opcode 'jmp' matched by 'j', usage 28
19089 +      src  M: 0xc015cd7d
19090 +      bb_reg_state c0728658
19091 +        rax = undefined
19092 +        rbx = undefined
19093 +        rcx = undefined
19094 +        rdx = undefined
19095 +        rdi = rax
19096 +        rsi = undefined
19097 +        rbp = osp-0x4
19098 +        rsp = osp-0x14
19099 +        slot 0 offset_address -0x4 rbp
19100 +        slot 1 offset_address -0x8 rdi
19101 +        slot 2 offset_address -0xc rsi
19102 +        slot 3 offset_address -0x10 rbx
19103 +      matched: from 0xc015cd6f to 0xc015cd7d drop_through 0 bb_jmp[9]
19104 +      reuse bb_jmp[3]
19105 +
19106 +      bb[7]
19107 +      first state c07286b8
19108 +      bb_reg_state c0728658
19109 +        rax = undefined
19110 +        rbx = rbx
19111 +        rcx = undefined
19112 +        rdx = undefined
19113 +        rdi = rax
19114 +        rsi = rsi
19115 +        rbp = osp-0x4
19116 +        rsp = osp-0x14
19117 +        slot 0 offset_address -0x4 rbp
19118 +        slot 1 offset_address -0x8 rdi
19119 +        slot 2 offset_address -0xc rsi
19120 +        slot 3 offset_address -0x10 rbx
19121 +      merging state c0728768
19122 +      rbx = undefined
19123 +      rsi = undefined
19124 +      merging state c0728768
19125 +      final state
19126 +      bb_reg_state c0728658
19127 +        rax = undefined
19128 +        rbx = undefined
19129 +        rcx = undefined
19130 +        rdx = undefined
19131 +        rdi = rax
19132 +        rsi = undefined
19133 +        rbp = osp-0x4
19134 +        rsp = osp-0x14
19135 +        slot 0 offset_address -0x4 rbp
19136 +        slot 1 offset_address -0x8 rdi
19137 +        slot 2 offset_address -0xc rsi
19138 +        slot 3 offset_address -0x10 rbx
19139 +     '0xc015cd7d getname+0x95:    pop    %edx'
19140 +      opcode 'pop' matched by 'pop', usage 42
19141 +      src  R: %edx base_rc 5 (rdx)
19142 +      rdx = *(rsp+0x0) (osp-0x14)  rdx = undefined
19143 +      rsp osp offset -0x14 -> -0x10
19144 +
19145 +This instruction is a bit misleading.  It looks like gcc is restoring a value
19146 +from the stack *(osp-0x14) to edx, but we have no record of any useful data
19147 +being stored at osp-0x14.  In fact gcc is just reducing the stack pointer by 4
19148 +bytes to reverse the effect of 0xc015ccee: sub $0x4,%esp, the value popped into
19149 +edx contains nothing useful.  Why gcc does pop instead of add $0x4,%esp is a
19150 +puzzle, probably some micro optimization.
19151 +
19152 +     '0xc015cd7e getname+0x96:    pop    %ebx'
19153 +      opcode 'pop' matched by 'pop', usage 42
19154 +      src  R: %ebx base_rc 3 (rbx)
19155 +      rbx = *(rsp+0x0) (osp-0x10) value rbx
19156 +      rsp osp offset -0x10 -> -0xc
19157 +      delete rbx from osp-0x10 slot 3
19158 +
19159 +This pop is doing something useful.  It is restoring the original value of the
19160 +preserved register ebx from stack, reversing 0xc015cced: push %ebx.  Note that
19161 +incrementing rsp from osp-0x10 to osp-0xc invalidates the data held in memory at
19162 +osp-0x10, so we delete our record of it.
19163 +
19164 +     '0xc015cd7f getname+0x97:    pop    %esi'
19165 +      opcode 'pop' matched by 'pop', usage 42
19166 +      src  R: %esi base_rc 7 (rsi)
19167 +      rsi = *(rsp+0x0) (osp-0xc) value rsi
19168 +      rsp osp offset -0xc -> -0x8
19169 +      delete rsi from osp-0xc slot 2
19170 +     '0xc015cd80 getname+0x98:    pop    %edi'
19171 +      opcode 'pop' matched by 'pop', usage 42
19172 +      src  R: %edi base_rc 6 (rdi)
19173 +      rdi = *(rsp+0x0) (osp-0x8) value rdi
19174 +      rsp osp offset -0x8 -> -0x4
19175 +      delete rdi from osp-0x8 slot 1
19176 +
19177 +Pop the other preserved registers, in reverse order to the push sequence at the
19178 +start.
19179 +
19180 +     '0xc015cd81 getname+0x99:    pop    %ebp'
19181 +      opcode 'pop' matched by 'pop', usage 42
19182 +      src  R: %ebp base_rc 8 (rbp)
19183 +      rbp = *(rsp+0x0) (osp-0x4) value rbp
19184 +      rsp osp offset -0x4 -> +0x0
19185 +      delete rbp from osp-0x4 slot 0
19186 +
19187 +Pop the previous frame pointer.
19188 +
19189 +     '0xc015cd82 getname+0x9a:    ret    '
19190 +      opcode 'ret' matched by 'ret', usage 48
19191 +
19192 +When a ret instruction is executed, all the preserved registers must be back to
19193 +their original value and the stack pointer must contain osp+0.
19194 +bb_sanity_check() will complain and abort the backtrace if this is not true.  No
19195 +complaints here.
19196 +
19197 +    bb_pass2: end bb_reg_params 1 bb_memory_params 0
19198 +
19199 +We identified one argument passed in a register (the read of rax at 0xc015ccf1)
19200 +and no reference to memory locations above the stack frame.  So we have one
19201 +argument being passed in a register and no arguments being passed on stack.
19202 +This matches
19203 +
19204 +  char * getname(const char __user * filename)
19205 +
19206 +    bb_pass2: bb_exit_state at 0xc015cd6d
19207 +      bb_reg_state c07287c0
19208 +        rax = undefined
19209 +        rbx = undefined
19210 +        rcx = undefined
19211 +        rdx = undefined
19212 +        rdi = rax
19213 +        rsi = undefined
19214 +        rbp = osp-0x4
19215 +        rsp = osp-0x14
19216 +        slot 0 offset_address -0x4 rbp
19217 +        slot 1 offset_address -0x8 rdi
19218 +        slot 2 offset_address -0xc rsi
19219 +        slot 3 offset_address -0x10 rbx
19220 +
19221 +We told bb1 that the exit address from this function is 0xc015cd6d.  The
19222 +abstract state at this exit point was saved, it defines how we rollback the
19223 +actual register values from the next function down the stack (kmem_cache_free)
19224 +to get the actual register values on entry to this function (getname).  See
19225 +bb_actual_rollback() which updates bb_actual[].
19226 +
19227 +Looking at the exit state above, we see that rsp contains the abstracte value
19228 +osp-0x14.  It is a given that we have the actual value of rsp after the call
19229 +from getname() to kmem_cache_free(), otherwise we would not have found the
19230 +return address on stack and we would not be analysing getname().  Adding 0x14
19231 +(the delta from osp to rsp) to our current actual rsp gives us the actual value
19232 +of osp on entry to getname().
19233 +
19234 +The main aim of doing all this work is to track the function arguments so we can
19235 +print them if possible.  getname() only has one argument which was passed in
19236 +eax.  According to the abstract exit state, the original value of rax is
19237 +currently in rdi, so by looking at the actual value of rdi from the next stack
19238 +frame down we are able to get the argument to getname().
19239 +
19240 +It is not always possible to get register arguments, gcc will only preserve
19241 +input arguments as long as it needs them so there may be no saved copy of
19242 +arguments that are passed in register.  In this case, bt_print_one() prints
19243 +"invalid".
19244 +
19245 +If basic block analysis detected any arguments were passed on stack, their
19246 +contents can now be extracted based on the known value of the stack pointer.
19247 +bt_print_one() prints the arguments, if BT_ARGS is non-zero then any argument
19248 +that might be a kernel address is printed as a symbol.
19249 +
19250 +Once rsp has been rolled back to osp, we can calculate that actual address of
19251 +the stack locations that contain useful data.  The previous values of rbp, rdi,
19252 +rsi and rbx are then copied from those locations into bb_actual[].  That gives
19253 +the values for those registers at the exit point from the function that called
19254 +getname().  Go up one level and repeat the analysis.
19255 +
19256 +There are two references to rdi in the exit state, which can be confusing.
19257 +
19258 +        rdi = rax
19259 +        slot 1 offset_address -0x8 rdi
19260 +
19261 +The first reference says that "register rdi contains the original value of rax",
19262 +the second reference says that "*(osp-0x8) contains the original value of rdi".
19263 +Do not confuse the two, one is by name, the other is by value.
19264 +
19265 +getname() is a fairly simple function, it has no loops.  __follow_mount is more
19266 +complicated, it has loops as well as BUG() statements.
19267 +
19268 +    [0]kdb> id __follow_mount
19269 +    0xc015be76 __follow_mount:         push   %ebp
19270 +    0xc015be77 __follow_mount+0x1:     mov    %esp,%ebp
19271 +    0xc015be79 __follow_mount+0x3:     push   %edi
19272 +    0xc015be7a __follow_mount+0x4:     push   %esi
19273 +    0xc015be7b __follow_mount+0x5:     push   %ebx
19274 +    0xc015be7c __follow_mount+0x6:     mov    %eax,%esi
19275 +    0xc015be7e __follow_mount+0x8:     xor    %edi,%edi
19276 +    0xc015be80 __follow_mount+0xa:     jmp    0xc015beca __follow_mount+0x54
19277 +    0xc015be82 __follow_mount+0xc:     mov    (%esi),%eax
19278 +    0xc015be84 __follow_mount+0xe:     call   0xc0169664 lookup_mnt
19279 +    0xc015be89 __follow_mount+0x13:    mov    %eax,%ebx
19280 +    0xc015be8b __follow_mount+0x15:    test   %eax,%eax
19281 +    0xc015be8d __follow_mount+0x17:    je     0xc015bed3 __follow_mount+0x5d
19282 +    0xc015be8f __follow_mount+0x19:    mov    0x4(%esi),%eax
19283 +    0xc015be92 __follow_mount+0x1c:    call   0xc0163de2 dput
19284 +    0xc015be97 __follow_mount+0x21:    test   %edi,%edi
19285 +    0xc015be99 __follow_mount+0x23:    je     0xc015bead __follow_mount+0x37
19286 +    0xc015be9b __follow_mount+0x25:    mov    (%esi),%eax
19287 +    0xc015be9d __follow_mount+0x27:    test   %eax,%eax
19288 +    0xc015be9f __follow_mount+0x29:    je     0xc015bead __follow_mount+0x37
19289 +    0xc015bea1 __follow_mount+0x2b:    movl   $0x0,0x64(%eax)
19290 +    0xc015bea8 __follow_mount+0x32:    call   0xc016835b mntput_no_expire
19291 +    0xc015bead __follow_mount+0x37:    mov    %ebx,(%esi)
19292 +    0xc015beaf __follow_mount+0x39:    mov    0x10(%ebx),%eax
19293 +    0xc015beb2 __follow_mount+0x3c:    test   %eax,%eax
19294 +    0xc015beb4 __follow_mount+0x3e:    je     0xc015bec2 __follow_mount+0x4c
19295 +    0xc015beb6 __follow_mount+0x40:    cmpl   $0x0,(%eax)
19296 +    0xc015beb9 __follow_mount+0x43:    jne    0xc015bebf __follow_mount+0x49
19297 +    0xc015bebb __follow_mount+0x45:    ud2a
19298 +    0xc015bebd __follow_mount+0x47:    jmp    0xc015bebd __follow_mount+0x47
19299 +    0xc015bebf __follow_mount+0x49:    lock incl (%eax)
19300 +    0xc015bec2 __follow_mount+0x4c:    mov    %eax,0x4(%esi)
19301 +    0xc015bec5 __follow_mount+0x4f:    mov    $0x1,%edi
19302 +    0xc015beca __follow_mount+0x54:    mov    0x4(%esi),%edx
19303 +    0xc015becd __follow_mount+0x57:    cmpl   $0x0,0x74(%edx)
19304 +    0xc015bed1 __follow_mount+0x5b:    jne    0xc015be82 __follow_mount+0xc
19305 +    0xc015bed3 __follow_mount+0x5d:    mov    %edi,%eax
19306 +    0xc015bed5 __follow_mount+0x5f:    pop    %ebx
19307 +    0xc015bed6 __follow_mount+0x60:    pop    %esi
19308 +    0xc015bed7 __follow_mount+0x61:    pop    %edi
19309 +    0xc015bed8 __follow_mount+0x62:    pop    %ebp
19310 +    0xc015bed9 __follow_mount+0x63:    ret
19311 +
19312 +    [0]kdb> bb1 0xc015bed9
19313 +    bb_pass1: func_name __follow_mount func_start 0xc015be76 func_end 0xc015beda
19314 +    bb_pass1: end
19315 +      bb[0] start 0xc015be76 end 0xc015be80 drop_through 0
19316 +      bb[1] start 0xc015be82 end 0xc015beac drop_through 1
19317 +      bb[2] start 0xc015bead end 0xc015bebb drop_through 0
19318 +
19319 +Note that the ud2a (BUG) instruction at 0xc015bebb ends bb[2].
19320 +
19321 +      bb[3] start 0xc015bebd end 0xc015bebd drop_through 0
19322 +
19323 +bb[3] is peculiar, it is a jmp to itself, nothing else refers to 0xc015bebd and
19324 +you cannot drop through from the previous instruction because ud2a kills the
19325 +kernel.  The i386 and x86_64 BUG() macros contain for(;;) after ud2a, for no
19326 +good reason that I can see (is there old hardware that does not abort on ud2a?).
19327 +ia64 and the generic versions of BUG() do not contain for(;;).  for(;;) after
19328 +ud2a generates a branch to itself than can never be executed.
19329 +
19330 +      bb[4] start 0xc015bebf end 0xc015bec1 drop_through 1
19331 +      bb[5] start 0xc015bec2 end 0xc015bec9 drop_through 1
19332 +      bb[6] start 0xc015beca end 0xc015bed2 drop_through 1
19333 +      bb[7] start 0xc015bed3 end 0xc015bed9 drop_through 0
19334 +      bb_jmp[0] from 0xc015be80 to 0xc015beca drop_through 0
19335 +      bb_jmp[1] from 0xc015be8d to 0xc015bed3 drop_through 0
19336 +      bb_jmp[2] from 0xc015be99 to 0xc015bead drop_through 0
19337 +      bb_jmp[3] from 0xc015be9f to 0xc015bead drop_through 0
19338 +      bb_jmp[4] from 0xc015beb4 to 0xc015bec2 drop_through 0
19339 +      bb_jmp[5] from 0xc015beb9 to 0xc015bebf drop_through 0
19340 +      bb_jmp[6] from 0xc015bebd to 0xc015bebd drop_through 0
19341 +      bb_jmp[7] from 0xc015bed1 to 0xc015be82 drop_through 0
19342 +      bb_jmp[8] from 0xc015beac to 0xc015bead drop_through 1
19343 +      bb_jmp[9] from 0xc015bec1 to 0xc015bec2 drop_through 1
19344 +      bb_jmp[10] from 0xc015bec9 to 0xc015beca drop_through 1
19345 +      bb_jmp[11] from 0xc015bed2 to 0xc015bed3 drop_through 1
19346 +
19347 +Apart from bb[0] and the special case bb[3], all the other blocks are part of a
19348 +cycle.  That cycle goes bb[0] -> bb[6].  bb[6] -> {bb[1], bb[7]}.  bb[1] ->
19349 +{bb[2], bb[7]}.  bb[2] -> {bb[4], bb[5]}.  bb[4] -> bb[5].  bb[5] -> bb[6] and
19350 +back to the start.  bb[7] ends with 'ret', it does not feed into other blocks.
19351 +
19352 +    bb_pass2: start
19353 +
19354 +      bb_pass2_do_changed_blocks: allow_missing 0
19355 +
19356 +      bb[0]
19357 +      [ ... detail snipped ... ]
19358 +      matched: from 0xc015be80 to 0xc015beca drop_through 0 bb_jmp[0]
19359 +      new state c07286d8
19360 +
19361 +      bb_pass2_do_changed_blocks: allow_missing 1
19362 +
19363 +Because of the cycle, only bb[0] can be processed with 0 missing inputs, all the
19364 +other blocks have at least one missing input.  Call bb_pass2_do_changed_blocks()
19365 +again, this time allowing one missing input per blocks.
19366 +
19367 +      bb[6]
19368 +      first state c07286d8
19369 +      [ ... detail snipped ... ]
19370 +      matched: from 0xc015bed2 to 0xc015bed3 drop_through 1 bb_jmp[11]
19371 +      reuse bb_jmp[7]
19372 +
19373 +      bb[7]
19374 +      first state c0728730
19375 +      [ ... detail snipped ... ]
19376 +
19377 +      bb[1]
19378 +      first state c0728730
19379 +      [ ... detail snipped ... ]
19380 +      matched: from 0xc015beac to 0xc015bead drop_through 1 bb_jmp[8]
19381 +      reuse bb_jmp[1]
19382 +
19383 +      bb[2]
19384 +      first state c0728788
19385 +      [ ... detail snipped ... ]
19386 +      merging state c0728788
19387 +      merging state c0728788
19388 +      [ ... detail snipped ... ]
19389 +      matched: from 0xc015beb9 to 0xc015bebf drop_through 0 bb_jmp[5]
19390 +      reuse bb_jmp[1]
19391 +
19392 +      bb[4]
19393 +      first state c0728788
19394 +      [ ... detail snipped ... ]
19395 +      matched: from 0xc015bec1 to 0xc015bec2 drop_through 1 bb_jmp[9]
19396 +      reuse bb_jmp[1]
19397 +
19398 +      bb[5]
19399 +      first state c0728788
19400 +      [ ... detail snipped ... ]
19401 +      merging state c0728788
19402 +      [ ... detail snipped ... ]
19403 +      matched: from 0xc015bec9 to 0xc015beca drop_through 1 bb_jmp[10]
19404 +      reuse bb_jmp[1]
19405 +
19406 +      bb[6]
19407 +      first state c07286d8
19408 +      [ ... detail snipped ... ]
19409 +      merging state c0728788
19410 +      matched: from 0xc015bed2 to 0xc015bed3 drop_through 1 bb_jmp[11]
19411 +      reuse bb_jmp[1]
19412 +
19413 +Note the rescan of bb[6].  The first scan only had one input from bb[0].  After
19414 +traversing the cycle and getting back from bb[5] to bb[6], bb[6] now has more
19415 +inputs so we need to rescan it.  With the additional input, the output state
19416 +from bb[6] has changed since the first scan, which means that every block it
19417 +feeds has to be rescanned.  bb[6] feeds bb[1] and bb[7].
19418 +
19419 +      bb[7]
19420 +      first state c0728788
19421 +      [ ... detail snipped ... ]
19422 +      merging state c0728788
19423 +      [ ... detail snipped ... ]
19424 +
19425 +bb[7] being rescanned, this time it has data for both its inputs.
19426 +
19427 +      bb[1]
19428 +      first state c0728788
19429 +      [ ... detail snipped ... ]
19430 +      matched: from 0xc015beac to 0xc015bead drop_through 1 bb_jmp[8]
19431 +      no state change
19432 +
19433 +bb[1] is being rescanned because the input from bb[6] has changed, however the
19434 +rescan of bb[1] reports 'no state change', the changed input from bb[6] did not
19435 +affect the final output state from bb[1].  Because the output state from bb[1]
19436 +has not changed since the previous scan, there is no need to rescan bb[2], bb[7]
19437 +or bb[4].  Since bb[4] is not being rescanned, there is no need to rescan bb[5]
19438 +or bb[6] and the cycle is closed.
19439 diff -Nurp linux-2.6.22-590/Documentation/kdb/kdb_bp.man linux-2.6.22-600/Documentation/kdb/kdb_bp.man
19440 --- linux-2.6.22-590/Documentation/kdb/kdb_bp.man       1970-01-01 01:00:00.000000000 +0100
19441 +++ linux-2.6.22-600/Documentation/kdb/kdb_bp.man       2008-04-09 18:14:28.000000000 +0200
19442 @@ -0,0 +1,197 @@
19443 +.TH BD 1 "July 12, 2004"
19444 +.SH NAME
19445 +bp, bpa, bph, bpha, bd, bc, be, bl \- breakpoint commands
19446 +.SH SYNOPSIS
19447 +bp \fIaddress-expression\fP
19448 +.LP
19449 +bpa \fIaddress-expression\fP
19450 +.LP
19451 +bph \fIaddress-expression\fP [\f(CWDATAR|DATAW|DATAA|IO\fP [\fIlength\fP]]
19452 +.LP
19453 +bpha \fIaddress-expression\fP [\f(CWDATAR|DATAW|DATAA|IO\fP [\fIlength\fP]]
19454 +.LP
19455 +bd \fIbreakpoint-number\fP
19456 +.LP
19457 +bc \fIbreakpoint-number\fP
19458 +.LP
19459 +be \fIbreakpoint-number\fP
19460 +.LP
19461 +bl
19462 +.SH DESCRIPTION
19463 +.hy 0
19464 +The
19465 +.B bp
19466 +family of commands are used to establish a breakpoint.
19467 +The \fIaddress-expression\fP may be a numeric value (decimal or
19468 +hexidecimal), a symbol name, a register name preceeded by a
19469 +percent symbol '%', or a simple expression consisting of a
19470 +symbol name, an addition or subtraction character and a numeric
19471 +value (decimal or hexidecimal).
19472 +.P
19473 +\fBbph\fP and \fBbpha\fP will force the use of a hardware register, provided
19474 +the processor architecture supports them.
19475 +.P
19476 +The \fIaddress-expression\fP may also consist of a single
19477 +asterisk '*' symbol which indicates that the command should
19478 +operate on all existing breakpoints (valid only for \fBbc\fP,
19479 +\fBbd\fP and \fBbe\fP).
19480 +.P
19481 +Four different types of
19482 +breakpoints may be set:
19483 +
19484 +.TP 8
19485 +Instruction
19486 +Causes the kernel debugger to be invoked from the debug exception
19487 +path when an instruction is fetched from the specified address.  This
19488 +is the default if no other type of breakpoint is requested or when
19489 +the \fBbp\fP command is used.
19490 +
19491 +.TP 8
19492 +DATAR
19493 +Causes the kernel debugger to be entered when data of length
19494 +\fIlength\fP is read from or written to the specified address.
19495 +This type of breakpoint must use a processor debug register which
19496 +places an architecture dependent limit on the number of data and I/O
19497 +breakpoints that may be established. On arm mode XScale platform
19498 +(thumb mode is not supported yet),
19499 +debugger is triggered by reading from the specified address.
19500 +The \fBbph\fP or \fBbpha\fP commands must be used.
19501 +
19502 +.TP 8
19503 +DATAW
19504 +Enters the kernel debugger when data of length \fIlength\fP
19505 +is written to the specified address.  \fIlength\fP defaults
19506 +to four bytes if it is not explicitly specified.
19507 +Note that the processor may have already overwritten the prior data at
19508 +the breakpoint location before the kernel debugger is invoked.
19509 +The prior data should be saved before establishing the breakpoint, if
19510 +required. On arm mode XScale platform, the debugger is triggered
19511 +after having overwritten the specified address.
19512 +The \fBbph\fP or \fBbpha\fP commands must be used.
19513 +
19514 +.TP 8
19515 +IO
19516 +Enters the kernel debugger when an \fBin\fP or \fBout\fP instruction
19517 +targets the specified I/O address.  The \fBbph\fP or \fBbpha\fP
19518 +commands must be used. This type of breakpoint is not valid in
19519 +arm mode XScale platform. This option is not valid in arm
19520 +mode XScale platform.
19521 +
19522 +.TP 8
19523 +DATAA
19524 +Enters the kernel debugger after the data in specified address has
19525 +been accessed (read or write), this option is only used in arm
19526 +mode XScale platform.
19527 +
19528 +.P
19529 +The
19530 +.B bpha
19531 +command will establish a breakpoint on all processors in an
19532 +SMP system.   This command is not available in an uniprocessor
19533 +kernel.
19534 +.P
19535 +The
19536 +.B bd
19537 +command will disable a breakpoint without removing it from the kernel
19538 +debugger's breakpoint table.
19539 +This can be used to keep breakpoints in the table without exceeding the
19540 +architecture limit on breakpoint registers.
19541 +A breakpoint-number of \fI*\fR will disable all break points.
19542 +.P
19543 +The
19544 +.B be
19545 +command will re-enable a disabled breakpoint.
19546 +A breakpoint-number of \fI*\fR will enable all break points.
19547 +.P
19548 +The
19549 +.B bc
19550 +command will clear a breakpoint from the breakpoint table.
19551 +A breakpoint-number of \fI*\fR will clear all break points.
19552 +.P
19553 +The
19554 +.B bl
19555 +command will list the existing set of breakpoints.
19556 +.SH LIMITATIONS
19557 +There is a compile time limit of sixteen entries in the
19558 +breakpoint table at any one time.
19559 +.P
19560 +There are architecture dependent limits on the number of hardware
19561 +breakpoints that can be set.
19562 +.IP ix86 8
19563 +Four.
19564 +.PD 0
19565 +.IP xscale 8
19566 +Two for insruction breakpoints and another two for data breakpoint.
19567 +.PD 0
19568 +.IP ia64 8
19569 +?
19570 +.PD 0
19571 +.IP sparc64 8
19572 +None.
19573 +.PD 1
19574 +When issuing the "go" command after entering the debugger due to
19575 +a breakpoint, kdb will silently perform a single step in order to
19576 +reapply the breakpoint. The sparc64 port has some limitations on
19577 +single stepping, which may limit where a breakpoint may be safely
19578 +set. Please read the man page for \fBss\fP for more information.
19579 +.SH ENVIRONMENT
19580 +The breakpoint subsystem does not currently use any environment
19581 +variables.
19582 +.SH SMP CONSIDERATIONS
19583 +Using
19584 +.B bc
19585 +is risky on SMP systems.
19586 +If you clear a breakpoint when another cpu has hit that breakpoint but
19587 +has not been processed then it may not be recognised as a kdb
19588 +breakpoint, usually resulting in incorrect program counters and kernel
19589 +panics.
19590 +It is safer to disable the breakpoint with
19591 +.BR bd ,
19592 +then
19593 +.B go
19594 +to let any other processors that are waiting on the breakpoint to
19595 +clear.
19596 +After all processors are clear of the disabled breakpoint then it is
19597 +safe to clear it using
19598 +.BR bc .
19599 +.P
19600 +Breakpoints which use the processor breakpoint registers
19601 +are only established on the processor which is
19602 +currently active.  If you wish breakpoints to be universal
19603 +use the
19604 +.B bpa
19605 +or
19606 +.B bpha
19607 +commands.
19608 +.SH EXAMPLES
19609 +.TP 8
19610 +bp schedule
19611 +Sets an instruction breakpoint at the begining of the
19612 +function \fBschedule\fP.
19613 +
19614 +.TP 8
19615 +bp schedule+0x12e
19616 +Sets an instruction breakpoint at the instruction located
19617 +at \fBschedule\fP+\fI0x12e\fP.
19618 +
19619 +.TP 8
19620 +bph ttybuffer+0x24 dataw
19621 +Sets a data write breakpoint at the location referenced by
19622 +\fBttybuffer\fP+\fI0x24\fP for a length of four bytes.
19623 +
19624 +.TP 8
19625 +bph 0xc0254010 datar 1
19626 +Establishes a data reference breakpoint at address \fB0xc0254010\fP
19627 +for a length of one byte.
19628 +
19629 +.TP 8
19630 +bp
19631 +List current breakpoint table.
19632 +
19633 +.TP 8
19634 +bd 0
19635 +Disable breakpoint #0.
19636 +
19637 +.TP 8
19638 +bc *
19639 +Clear all breakpoints
19640 diff -Nurp linux-2.6.22-590/Documentation/kdb/kdb_bt.man linux-2.6.22-600/Documentation/kdb/kdb_bt.man
19641 --- linux-2.6.22-590/Documentation/kdb/kdb_bt.man       1970-01-01 01:00:00.000000000 +0100
19642 +++ linux-2.6.22-600/Documentation/kdb/kdb_bt.man       2008-04-09 18:14:28.000000000 +0200
19643 @@ -0,0 +1,315 @@
19644 +.TH BT 1 "July 20, 2007"
19645 +.SH NAME
19646 +bt \- Stack Traceback command
19647 +.SH SYNOPSIS
19648 +bt [ <stack-frame-address> ]
19649 +.LP
19650 +btp <pid>
19651 +.LP
19652 +btt <struct-task-address>
19653 +.LP
19654 +bta [ DRSTZUIMA ]
19655 +.LP
19656 +btc [<cpu>]
19657 +.SH DESCRIPTION
19658 +.hy 0
19659 +The
19660 +.B bt
19661 +command is used to print a stack traceback.  It uses the
19662 +current registers (see \fBrd\fP command) to determine
19663 +the starting context and attempts to provide a complete
19664 +stack traceback for the active thread.   If \fIstack-frame-address\fP
19665 +is supplied, it is assumed to point to the start of a valid
19666 +stack frame and the stack will be traced back from that
19667 +point.
19668 +On x86 architecture, \fIstack-frame-address\fP must be the stack address of a
19669 +saved \fB%eip\fP (\fB%rip\fP for x86_64) value from a \fBcall\fP instruction.
19670 +.P
19671 +The \fBbtp\fP command will analyze the stack for the given
19672 +process identification (see the \fBps\fP command).
19673 +\fBbtp\fP sets the current process for any following register display or update
19674 +commands.
19675 +.P
19676 +The \fBbtt\fP command will analyze the stack for the given task
19677 +structure.
19678 +It is exactly equivalent to \fBbtp\fR on the pid extracted from the
19679 +task structure.
19680 +\fBbtt\fP sets the current process for any following register display or update
19681 +commands.
19682 +.P
19683 +The \fBbta\fP command lists the stack for all processes in the desired
19684 +state.
19685 +Without any parameters, \fBbta\fP gives a backtrace for all useful processes.
19686 +If a parameter is specified, it is a single string consisting of the
19687 +letters D, R, S, T, Z, U, I, M and A in any order.
19688 +See the kdb \fBps\fR man page for more details.
19689 +\fBbta\fP does not change the current process.
19690 +.P
19691 +The \fBbtc\fP command will analyze the stack for the current process on
19692 +a specified cpu or, if no cpu number is supplied, for the current
19693 +process on all cpus.
19694 +It does not switch to the other cpus, instead it uses the task
19695 +structures to identify and issue \fBbtt\fR against the current task on
19696 +the desired cpus.
19697 +\fBbtc\fP with no arguments does not change the current process.
19698 +\fBbtc\fP with a cpu number sets the current process for any following register
19699 +display or update commands.
19700 +.P
19701 +For each function, the stack trace prints at least two lines.
19702 +The first line contains four or five fields\ :-
19703 +.IP * 3
19704 +The pointer to the stack frame.
19705 +.PD 0
19706 +.IP * 3
19707 +The current address within this frame.
19708 +.IP * 3
19709 +The address converted to a function name (actually the first non-local
19710 +label which is <= the address).
19711 +.IP * 3
19712 +The offset of the address within the function.
19713 +.IP * 3
19714 +Any parameters to the function.
19715 +.PD 1
19716 +.PP
19717 +If environment variable NOSECT is set to 0 then the next line contains
19718 +five fields which are designed to make it easier to match the trace
19719 +against the kernel code\ :-
19720 +.IP * 3
19721 +The module name that contains the address, "kernel" if it is in the
19722 +base kernel.
19723 +.PD 0
19724 +.IP * 3
19725 +The section name that contains the address (not available on 2.6 kernels).
19726 +.IP * 3
19727 +The start address of the section (not available on 2.6 kernels).
19728 +.IP * 3
19729 +The start address of the function.
19730 +.IP * 3
19731 +The end address of the function (the first non-local label which is >
19732 +the address).
19733 +.PD 1
19734 +.PP
19735 +If arguments are being converted to symbols, any argument which
19736 +converts to a kernel or module address is printed as\ :-
19737 +.IP * 3
19738 +Argument address.
19739 +.PD 0
19740 +.IP * 3
19741 +The module name that contains the address, "kernel" if it is in the
19742 +base kernel.
19743 +.IP * 3
19744 +The symbol name the argument maps to.
19745 +.IP * 3
19746 +The offset of the argument from the symbol, suppressed if 0.
19747 +.PD 1
19748 +.P
19749 +On architectures that use nested stacks, the backtrace will indicate a
19750 +switch to a new stack by printing a line of equal signs and the type of
19751 +stack.
19752 +.SH MATCHING TRACE TO KERNEL CODE
19753 +The command "objdump\ -S" will disassemble an object and, if the code
19754 +was compiled with debugging (gcc flag -g), objdump will interleave the
19755 +C source lines with the generated object.
19756 +.PP
19757 +A complete objdump of the kernel or a module is too big, normally you
19758 +only want specific functions.
19759 +By default objdump will only print the .text section but Linux uses
19760 +other section names for executable code.
19761 +When objdump prints relocatable objects (modules) it uses an offset of
19762 +0 which is awkward to relate to the stack trace.
19763 +The five fields which are printed for each function are designed to
19764 +make it easier to match the stack trace against the kernel code using
19765 +"objdump\ -S".
19766 +.PP
19767 +If the function is in the kernel then you need the section name, the
19768 +start and end address of the function.  The command is
19769 +.PP
19770 +.nf
19771 +  objdump -S -j <section_name> \\
19772 +          --start-address=<start-address> \\
19773 +          --stop-address=<end-address> \\
19774 +          /usr/src/linux/vmlinux
19775 +.fi
19776 +.PP
19777 +If the function is in a module then you need the section name, the
19778 +start address of the section, the start and end address of the
19779 +function, the module name.  The command is
19780 +.PP
19781 +.nf
19782 +  objdump -S -j <section_name> \\
19783 +          --adjust-vma=<section-start> \\
19784 +          --start-address=<start-address> \\
19785 +          --stop-address=<end-address> \\
19786 +          /path/to/module/<module-name>.o
19787 +.fi
19788 +.PP
19789 +Unfortunately the 2.6 kernel does not provide the information required
19790 +to locate the start of the section, which makes it very difficult to
19791 +perform a reliable objdump on a module.
19792 +.PP
19793 +All addresses to objdump must be preceded by '0x' if they are in hex,
19794 +objdump does not assume hex.
19795 +The stack trace values are printed with leading '0x' to make it easy to
19796 +run objdump.
19797 +.SH LIMITATIONS
19798 +Some architectures pass parameters in registers; ia64, x86_64 and i386 (with
19799 +gcc flag -mregparm) fall into this category.
19800 +On these architectures, the compiler may reuse input parameter registers as
19801 +scratch space.
19802 +For example, if a function takes a pointer to a structure and only accesses one
19803 +field in that structure, the compiler may calculate the address of the field by
19804 +adding a value to the input register.
19805 +Once the input register has been updated, it no longer points to the
19806 +start of the structure, but to some field within it.
19807 +This also occurs with array pointers, the compiler may update the input pointer
19808 +directly, leaving it pointing to some element of the array instead of the start
19809 +of the array.
19810 +Always treat parameter values that have been passed in registers with extreme
19811 +suspicion, the compiler may have changed the value.
19812 +The x86 backtrace can generally identify register parameters that are no longer
19813 +valid, it prints them as 'invalid' instead of as a misleading number.
19814 +The ia64 backtrace cannot identify parameter registers that have been
19815 +overwritten.
19816 +.P
19817 +x86 architectures do not have full unwind information in the kernel.
19818 +The KDB backtrace on x86 performs code decomposition and analysis to track the
19819 +frames on the call stack (including stack switches) and to locate parameters.
19820 +if this code analysis does not yield a valid result, KDB falls back on the old
19821 +method of scanning the process stack and printing anything that looks like a
19822 +kernel address.
19823 +This old method is unreliable (it produces lots of false positives in the
19824 +trace) and cannot track parameters at all, so no parameters are printed.
19825 +If you get an x86 backtrace that falls back to the old method, read
19826 +Documentation/kdb/bt_x86 and follow the steps listed to get diagnostics and to
19827 +submit a bug report.
19828 +.P
19829 +There are a lot of functions in the kernel which take some arguments then do
19830 +nothing except call another function with the same initial arguments, sometimes
19831 +adding parameters at the end.  For example\ :-
19832 +.nf
19833 +.na
19834 +.ft CW
19835 +
19836 +int ipv4_doint_and_flush_strategy(ctl_table *table, int __user *name, int nlen,
19837 +                                 void __user *oldval, size_t __user *oldlenp,
19838 +                                 void __user *newval, size_t newlen)
19839 +{
19840 +       int ret = devinet_conf_sysctl(table, name, nlen, oldval, oldlenp,
19841 +                                     newval, newlen);
19842 +
19843 +       if (ret == 1)
19844 +               rt_cache_flush(0);
19845 +
19846 +       return ret;
19847 +}
19848 +.ad b
19849 +.fi
19850 +.P
19851 +ipv4_doint_and_flush_strategy() passes all its parameters directly to
19852 +devinet_conf_sysctl() and makes no other use of those parameters,
19853 +so ipv4_doint_and_flush_strategy is a 'pass through' function.
19854 +The x86_64 calling sequence mandates that the first 6 parameters are passed in
19855 +registers, with other parameters being passed on stack.
19856 +The i386 calling sequence with -mregparm=3 (which is the default since about
19857 +2.6.18) passes the first 3 parameters in registers, with other parameters being
19858 +passed on stack.
19859 +The only exceptions to the above calling sequence are for functions declared as
19860 +asmlinkage or functions with a variable number of parameters (e.g. printk).
19861 +.P
19862 +When a pass through function calls another function, the first 3 (i386) or 6
19863 +(x86) parameters are already in their correct registers so the pass through
19864 +function does not need to access the registers, which means that there are no
19865 +references to these registers in the assembler code for the function.
19866 +Users still want to see those arguments so the x86 backtrace has to assume that
19867 +if\ :-
19868 +.IP * 2
19869 +There are parameters passed on the stack and
19870 +.IP *
19871 +There are no code references to parameters passed in registers and
19872 +.IP *
19873 +The function is not a known asmlinkage or variadic function, then
19874 +there are pass through register arguments.
19875 +.P
19876 +The x86 backtrace will warn you when it makes this assumption, like this\ :-
19877 +.nf
19878 +.na
19879 +.ft CW
19880 +
19881 +  <function_name> has memory parameters but no register parameters.
19882 +  Assuming it is a 'pass through' function that does not refer to its register
19883 +  parameters and setting <n> register parameters
19884 +.ad b
19885 +.fi
19886 +.P
19887 +The above 3 line message is only printed once, any future assumptions will
19888 +print a shorter message.
19889 +.P
19890 +The \fBbt\fP command may print more or less arguments for a function
19891 +than that function accepts.
19892 +For x86, trailing arguments that are passed in but not used by the function
19893 +will not be printed, resulting in fewer arguments than expected.
19894 +For ia64, the hardware does not distinguish between input and local registers,
19895 +some local registers may be printed as function arguments, resulting in more
19896 +arguments than expected.
19897 +.P
19898 +On i386, 64 bit arguments (long long) occupy two adjacent 32 bit fields.
19899 +There is no way for KDB to tell that this has occurred, so 64 bit arguments
19900 +will be printed as two separate 32 bit arguments.
19901 +.SH ENVIRONMENT
19902 +The \fBBTARGS\fP environment variable governs the maximum number
19903 +of arguments that are printed for any single function.
19904 +On IA64 hardware, there is no difference between input and local registers, the
19905 +first \fBBTARGS\fP registers are printed, up to the total limit of input plus
19906 +local registers.
19907 +Use a large value for \fBBTARGS\fP if you want to see the local registers on
19908 +IA64.
19909 +.PP
19910 +If the \fBBTSP\fP environment variable is non-zero then the entire backtrace is
19911 +printed, otherwise only the backtrace to the point of the last interrupt is
19912 +printed.
19913 +Printing the entire backtrace with 'set\ BTSP\ 1' is useful for diagnosing
19914 +problems with the backtrace algorithms.
19915 +In addition, when BTSP is non-zero, each backtrace frame may print extra lines
19916 +giving information about the stack pointers, this is architecture specific.
19917 +.PP
19918 +If the \fBBTSYMARG\fP environment variable is non-zero then any
19919 +arguments that fall within the kernel or modules are converted to symbols.
19920 +.PP
19921 +If the \fBNOSECT\fP environment variable is non-zero then the
19922 +section information is suppressed.
19923 +The default is NOSECT=1 so section data is suppressed; use set\ NOSECT=0
19924 +to see section information.
19925 +.PP
19926 +The \fBBTAPROMPT\fP environment variable controls the prompt after each
19927 +process is listed by the \fBbta\fP command.  If \fBBTAPROMPT\fP is not
19928 +set or is non-zero then \fBbta\fP issues a prompt after each process is
19929 +listed.  If \fBBTAPROMPT\fP is set to zero then no prompt is issued and
19930 +all processes are listed without human intervention.
19931 +.PP
19932 +\fBbt\fR with no parameters uses the \fBPS\fR environment variable, see
19933 +the kdb \fBps\fR man page.
19934 +.SH SMP CONSIDERATIONS
19935 +None.
19936 +.SH EXAMPLES
19937 +.nf
19938 +.na
19939 +.ft CW
19940 +[0]kdb> bt
19941 +Stack traceback for pid 2873
19942 +0xc2efc0f0     2873     2836  1    0   R  0xc2efc2a0 *mount
19943 +esp        eip        Function (args)
19944 +0xf65a3c88 0xc0201f9f xfs_mount_validate_sb (0xf68bcb08, 0xf68bcb48, 0x0)
19945 +0xf65a3c94 0xc0202f17 xfs_readsb+0x9d (0xf68bcb08, 0x0)
19946 +0xf65a3cc0 0xc020a72e xfs_mount+0x21d (invalid, 0xf68bc2f0, 0x0)
19947 +0xf65a3cf4 0xc021a84a vfs_mount+0x1a (invalid)
19948 +0xf65a3d04 0xc021a721 xfs_fs_fill_super+0x76 (0xf76b6200, invalid, invalid)
19949 +0xf65a3d78 0xc015ad81 get_sb_bdev+0xd4 (invalid, invalid, invalid, 0xf7257000, 0xc021a6ab, 0xf7594b38)
19950 +  xfs_fs_get_sb has memory parameters but no register parameters.
19951 +  Assuming it is a 'pass through' function that does not refer to its register
19952 +  parameters and setting 3 register parameters
19953 +0xf65a3db4 0xc0219a3a xfs_fs_get_sb+0x21 (invalid, invalid, invalid, 0xf7257000, 0xf7594b38)
19954 +0xf65a3dcc 0xc015a992 vfs_kern_mount+0x41 (0xc04847e0, 0x0, 0xf68e9000, 0xf7257000)
19955 +0xf65a3df0 0xc015aa11 do_kern_mount+0x38 (0xf6818000, 0x0, 0xf68e9000, 0xf7257000)
19956 +0xf65a3e10 0xc016c8b0 do_mount+0x5df (0xf68e9000, 0xf65d6000, 0xf6818000, 0xc0ed0000, 0xf7257000)
19957 +0xf65a3f90 0xc016c996 sys_mount+0x6f (0x8069b50, 0x8069b60, 0x8069b70, 0xc0ed0000, 0x8069ba0)
19958 +0xf65a3fb4 0xc0102646 sysenter_past_esp+0x5f (invalid, invalid, invalid, 0x73, 0x246, 0xbfe52f50)
19959 diff -Nurp linux-2.6.22-590/Documentation/kdb/kdb_env.man linux-2.6.22-600/Documentation/kdb/kdb_env.man
19960 --- linux-2.6.22-590/Documentation/kdb/kdb_env.man      1970-01-01 01:00:00.000000000 +0100
19961 +++ linux-2.6.22-600/Documentation/kdb/kdb_env.man      2008-04-09 18:14:28.000000000 +0200
19962 @@ -0,0 +1,46 @@
19963 +.TH ENV 1 "24 September 2000"
19964 +.SH NAME
19965 +env, set \- Environment manipulation commands
19966 +.SH SYNOPSIS
19967 +env
19968 +.LP
19969 +set \fIenvironment-variable\fP=\fIvalue\fP
19970 +.SH DESCRIPTION
19971 +The kernel debugger contains an environment which contains a series
19972 +of name-value pairs.  Some environment variables are known to the
19973 +various kernel debugger commands and have specific meaning to the
19974 +command; such are enumerated on the respective reference material.
19975 +.P
19976 +Arbitrary environment variables may be created and used with
19977 +many commands (those which require an \fIaddress-expression\fP).
19978 +.P
19979 +The
19980 +.B env
19981 +command is used to display the current environment.
19982 +.P
19983 +The
19984 +.B set
19985 +command is used to alter an existing environment variable or
19986 +establish a new environment variable.
19987 +.SH LIMITATIONS
19988 +There is a compile-time limit of 33 environment variables.
19989 +.P
19990 +There is a compile-time limit of 512 bytes (\fBKDB_ENVBUFSIZE\fP)
19991 +of heap space available for new environment variables and for
19992 +environment variables changed from their compile-time values.
19993 +.SH ENVIRONMENT
19994 +These commands explicitly manipulate the environment.
19995 +.SH SMP CONSIDERATIONS
19996 +None.
19997 +.SH USER SETTINGS
19998 +You can include "set" commands in kdb/kdb_cmds (see kdb.mm) to define
19999 +your environment variables at kernel startup.
20000 +.SH EXAMPLES
20001 +.TP 8
20002 +env
20003 +Display current environment settings.
20004 +
20005 +.TP 8
20006 +set IDCOUNT=100
20007 +Set the number of lines to display for the \fBid\fP command
20008 +to the value \fI100\fP.
20009 diff -Nurp linux-2.6.22-590/Documentation/kdb/kdb_ll.man linux-2.6.22-600/Documentation/kdb/kdb_ll.man
20010 --- linux-2.6.22-590/Documentation/kdb/kdb_ll.man       1970-01-01 01:00:00.000000000 +0100
20011 +++ linux-2.6.22-600/Documentation/kdb/kdb_ll.man       2008-04-09 18:14:28.000000000 +0200
20012 @@ -0,0 +1,134 @@
20013 +.TH LL 1 "19 April 1999"
20014 +.SH NAME
20015 +ll \- Linked List examination
20016 +.SH SYNOPSIS
20017 +ll <addr> <link-offset> <cmd>
20018 +.SH DESCRIPTION
20019 +The
20020 +.B ll
20021 +command is used to execute a single command repetitively for
20022 +each element of a linked list.
20023 +.P
20024 +The command specified by <cmd> will be executed with a single
20025 +argument, the address of the current element.
20026 +.SH LIMITATIONS
20027 +Be careful if using this command recursively.
20028 +.SH ENVIRONMENT
20029 +None.
20030 +.SH SMP CONSIDERATIONS
20031 +None.
20032 +.SH EXAMPLES
20033 +.nf
20034 +.na
20035 +.ft CW
20036 +# cd modules
20037 +# insmod kdbm_vm.o
20038 +# Entering kdb on processor 0 due to PAUSE
20039 +kdb> ps
20040 +Task Addr     Pid       Parent   cpu  lcpu    Tss     Command
20041 +0xc03de000 0000000001 0000000000 0000 0000 0xc03de2d4 init
20042 +0xc0090000 0000000002 0000000001 0000 0000 0xc00902d4 kflushd
20043 +0xc000e000 0000000003 0000000001 0000 0000 0xc000e2d4 kpiod
20044 +0xc000c000 0000000004 0000000001 0000 0000 0xc000c2d4 kswapd
20045 +0xc7de2000 0000000056 0000000001 0000 0000 0xc7de22d4 kerneld
20046 +0xc7d3a000 0000000179 0000000001 0000 0000 0xc7d3a2d4 syslogd
20047 +0xc7a7e000 0000000188 0000000001 0000 0000 0xc7a7e2d4 klogd
20048 +0xc7a04000 0000000199 0000000001 0000 0000 0xc7a042d4 atd
20049 +0xc7b84000 0000000210 0000000001 0000 0000 0xc7b842d4 crond
20050 +0xc79d6000 0000000221 0000000001 0000 0000 0xc79d62d4 portmap
20051 +0xc798e000 0000000232 0000000001 0000 0000 0xc798e2d4 snmpd
20052 +0xc7904000 0000000244 0000000001 0000 0000 0xc79042d4 inetd
20053 +0xc78fc000 0000000255 0000000001 0000 0000 0xc78fc2d4 lpd
20054 +0xc77ec000 0000000270 0000000001 0000 0000 0xc77ec2d4 sendmail
20055 +0xc77b8000 0000000282 0000000001 0000 0000 0xc77b82d4 gpm
20056 +0xc7716000 0000000300 0000000001 0000 0000 0xc77162d4 smbd
20057 +0xc7ee2000 0000000322 0000000001 0000 0000 0xc7ee22d4 mingetty
20058 +0xc7d6e000 0000000323 0000000001 0000 0000 0xc7d6e2d4 login
20059 +0xc778c000 0000000324 0000000001 0000 0000 0xc778c2d4 mingetty
20060 +0xc78b6000 0000000325 0000000001 0000 0000 0xc78b62d4 mingetty
20061 +0xc77e8000 0000000326 0000000001 0000 0000 0xc77e82d4 mingetty
20062 +0xc7708000 0000000327 0000000001 0000 0000 0xc77082d4 mingetty
20063 +0xc770e000 0000000328 0000000001 0000 0000 0xc770e2d4 mingetty
20064 +0xc76b0000 0000000330 0000000001 0000 0000 0xc76b02d4 update
20065 +0xc7592000 0000000331 0000000323 0000 0000 0xc75922d4 ksh
20066 +0xc7546000 0000000338 0000000331 0000 0000 0xc75462d4 su
20067 +0xc74dc000 0000000339 0000000338 0000 0000 0xc74dc2d4 ksh
20068 +kdb> md 0xc74dc2d4
20069 +c74dc2d4: 00000000 c74de000 00000018 00000000  .....`MG........
20070 +c74dc2e4: 00000000 00000000 00000000 074de000  .............`M.
20071 +c74dc2f4: c01123ff 00000000 00000000 00000000  #.@............
20072 +c74dc304: 00000000 00000000 c74dded0 00000000  ........P^MG....
20073 +[omitted]
20074 +c74dc474: 00000000 00000000 00000000 00000000  ................
20075 +c74dc484: 00000000 c7c15d00 c77b0900 c026fbe0  .....]AG..{G`{&@
20076 +c74dc494: 00000000 c76c2000 00000000 00000000  ..... lG........
20077 +c74dc4a4: 00000000 00000000 00000000 c74dc4ac  ............,DMG
20078 +kdb> md 0xc026fbe0
20079 +c026fbe0: c0262b60 00000000 c7594940 c74de000  @HYG....@IYG.`MG
20080 +[omitted]
20081 +kdb> md 0xc0262b60
20082 +c0262b60: c0266660 08048000 0804c000 c7bec360  `f&@.....@..`C>G
20083 +kdb> ll c0262b60 12 md
20084 +c0262b60: c0266660 08048000 0804c000 c7bec360  `f&@.....@..`C>G
20085 +c7bec360: c0266660 0804c000 0804d000 c7becb20  `f&@.@...P.. K>G
20086 +c7becb20: c0266660 0804d000 08050000 c7bec3a0  `f&@.P...... C>G
20087 +c7bec3a0: c0266660 40000000 40009000 c7bec420  `f&@...@...@ D>G
20088 +c7bec420: c0266660 40009000 4000b000 c7bec4a0  `f&@...@.0.@ D>G
20089 +c7bec4a0: c0266660 4000b000 40010000 c7bec8e0  `f&@.0.@...@`H>G
20090 +c7bec8e0: c0266660 40010000 400a1000 c7becbe0  `f&@...@...@`K>G
20091 +c7becbe0: c0266660 400a1000 400a8000 c7becc60  `f&@...@...@`L>G
20092 +c7becc60: c0266660 400a8000 400b4000 c7952300  `f&@...@.@.@.#.G
20093 +c7952300: c0266660 400b5000 400bc000 c79521c0  `f&@.P.@.@.@@!.G
20094 +c79521c0: c0266660 400bc000 400bd000 c7bec6e0  `f&@.@.@.P.@`F>G
20095 +c7bec6e0: c0266660 bffff000 c0000000 00000000  `f&@.p?...@....
20096 +kdb>
20097 +kdb> ll c0262b60 12 vm
20098 +struct vm_area_struct at 0xc0262b60 for 56 bytes
20099 +vm_start = 0x8048000   vm_end = 0x804c000
20100 +page_prot = 0x25   avl_height = 2244    vm_offset = 0x0
20101 +flags:  READ EXEC MAYREAD MAYWRITE MAYEXEC DENYWRITE EXECUTABLE
20102 +struct vm_area_struct at 0xc7bec360 for 56 bytes
20103 +vm_start = 0x804c000   vm_end = 0x804d000
20104 +page_prot = 0x25   avl_height = -31808    vm_offset = 0x3000
20105 +flags:  READ WRITE MAYREAD MAYWRITE MAYEXEC DENYWRITE EXECUTABLE
20106 +struct vm_area_struct at 0xc7becb20 for 56 bytes
20107 +vm_start = 0x804d000   vm_end = 0x8050000
20108 +page_prot = 0x25   avl_height = -28664    vm_offset = 0x0
20109 +flags:  READ WRITE EXEC MAYREAD MAYWRITE MAYEXEC
20110 +struct vm_area_struct at 0xc7bec3a0 for 56 bytes
20111 +vm_start = 0x40000000   vm_end = 0x40009000
20112 +page_prot = 0x25   avl_height = 30126    vm_offset = 0x0
20113 +flags:  READ EXEC MAYREAD MAYWRITE MAYEXEC DENYWRITE
20114 +struct vm_area_struct at 0xc7bec420 for 56 bytes
20115 +vm_start = 0x40009000   vm_end = 0x4000b000
20116 +page_prot = 0x25   avl_height = 30126    vm_offset = 0x8000
20117 +flags:  READ WRITE MAYREAD MAYWRITE MAYEXEC DENYWRITE
20118 +struct vm_area_struct at 0xc7bec4a0 for 56 bytes
20119 +vm_start = 0x4000b000   vm_end = 0x40010000
20120 +page_prot = 0x25   avl_height = 26853    vm_offset = 0x0
20121 +flags:  READ MAYREAD MAYWRITE MAYEXEC
20122 +struct vm_area_struct at 0xc7bec8e0 for 56 bytes
20123 +vm_start = 0x40010000   vm_end = 0x400a1000
20124 +page_prot = 0x25   avl_height = 2244    vm_offset = 0x0
20125 +flags:  READ EXEC MAYREAD MAYWRITE MAYEXEC
20126 +struct vm_area_struct at 0xc7becbe0 for 56 bytes
20127 +vm_start = 0x400a1000   vm_end = 0x400a8000
20128 +page_prot = 0x25   avl_height = 30126    vm_offset = 0x90000
20129 +flags:  READ WRITE MAYREAD MAYWRITE MAYEXEC
20130 +struct vm_area_struct at 0xc7becc60 for 56 bytes
20131 +vm_start = 0x400a8000   vm_end = 0x400b4000
20132 +page_prot = 0x25   avl_height = 2244    vm_offset = 0x0
20133 +flags:  READ WRITE MAYREAD MAYWRITE MAYEXEC
20134 +struct vm_area_struct at 0xc7952300 for 56 bytes
20135 +vm_start = 0x400b5000   vm_end = 0x400bc000
20136 +page_prot = 0x25   avl_height = 30126    vm_offset = 0x0
20137 +flags:  READ EXEC MAYREAD MAYWRITE MAYEXEC
20138 +struct vm_area_struct at 0xc79521c0 for 56 bytes
20139 +vm_start = 0x400bc000   vm_end = 0x400bd000
20140 +page_prot = 0x25   avl_height = -16344    vm_offset = 0x6000
20141 +flags:  READ WRITE MAYREAD MAYWRITE MAYEXEC
20142 +struct vm_area_struct at 0xc7bec6e0 for 56 bytes
20143 +vm_start = 0xbffff000   vm_end = 0xc0000000
20144 +page_prot = 0x25   avl_height = 2244    vm_offset = 0x0
20145 +flags:  READ WRITE EXEC MAYREAD MAYWRITE MAYEXEC GROWSDOWN
20146 +kdb>
20147 diff -Nurp linux-2.6.22-590/Documentation/kdb/kdb_md.man linux-2.6.22-600/Documentation/kdb/kdb_md.man
20148 --- linux-2.6.22-590/Documentation/kdb/kdb_md.man       1970-01-01 01:00:00.000000000 +0100
20149 +++ linux-2.6.22-600/Documentation/kdb/kdb_md.man       2008-04-09 18:14:28.000000000 +0200
20150 @@ -0,0 +1,136 @@
20151 +.TH MD 1 "August 4, 2004"
20152 +.SH NAME
20153 +md, mdWcN, mdr, mds, mm, mmW\- Memory manipulation commands
20154 +.SH SYNOPSIS
20155 +md [ \fIaddress-expression\fP [ \fIline-count\fP [\fIoutput-radix\fP ] ] ]
20156 +.LP
20157 +md\fIW\fRc\fIn\fR [ \fIaddress-expression\fP [ \fIline-count\fP [\fIoutput-radix\fP ] ] ]
20158 +.LP
20159 +mdp \fIphysical-address-expression\fP,\fIbytes\fP
20160 +.LP
20161 +mdr \fIaddress-expression\fP,\fIbytes\fP
20162 +.LP
20163 +mds [ \fIaddress-expression\fP [ \fIline-count\fP [\fIoutput-radix\fP ] ] ]
20164 +.LP
20165 +mm \fIaddress-expression\fP \fInew-contents\fP
20166 +.LP
20167 +mm\fIW\fR \fIaddress-expression\fP \fInew-contents\fP
20168 +.SH DESCRIPTION
20169 +The
20170 +.B md
20171 +command is used to display the contents of memory.
20172 +The \fIaddress-expression\fP may be a numeric value (decimal or
20173 +hexidecimal), a symbol name, a register name preceeded by one or more
20174 +percent symbols '%', an environment variable name preceeded by
20175 +a currency symbol '$',  or a simple expression consisting of a
20176 +symbol name, an addition or subtraction character and a numeric
20177 +value (decimal or hexidecimal).
20178 +.P
20179 +If an address is specified and the \fIline-count\fP or \fIradix\fP arguments
20180 +are omitted, they default to the values of the \fBMDCOUNT\fP and \fBRADIX\fP
20181 +environment variables respectively.  If the \fBMDCOUNT\fP or \fBRADIX\fP
20182 +environment variables are unset, the appropriate defaults will be used [see
20183 +\fBENVIRONMENT\fP below].  If no address is specified then md resumes
20184 +after the last address printed, using the previous values of count and
20185 +radix.  The start address is rounded down to a multiple of the
20186 +BYTESPERWORD (md) or width (md\fIW\fR).
20187 +.P
20188 +md uses the current value of environment variable \fBBYTESPERWORD\fP to
20189 +read the data.  When reading hardware registers that require special
20190 +widths, it is more convenient to use md\fIW\fRc\fIn\fR where \fIW\fR is
20191 +the width for this command and \fRc\fIn\fR is the number of entries to
20192 +read.  For example, md1c20 reads 20 bytes, 1 at a time.  To continue
20193 +printing just type md, the width and count apply to following md
20194 +commands with no parameters.  \fBNote:\fR The count is the number of
20195 +repeats of the width, unlike MDCOUNT which gives the number of md lines
20196 +to print.
20197 +.P
20198 +The
20199 +.B mdp
20200 +command displays the contents of physical memory, starting at the
20201 +specified physical address for the specified number of bytes.
20202 +The address is preceded by 'phys'.
20203 +.P
20204 +The
20205 +.B mdr
20206 +command displays the raw contents of memory, starting at the specified
20207 +address for the specified number of bytes.
20208 +The data is printed in one line without a leading address and no
20209 +trailing character conversion.
20210 +.B mdr
20211 +is intended for interfacing with external debuggers, it is of little
20212 +use to humans.
20213 +.P
20214 +The
20215 +.B mds
20216 +command displays the contents of memory one word per line and
20217 +attempts to correlate the contents of each word with a symbol
20218 +in the symbol table.   If no symbol is found, the ascii representation
20219 +of the word is printed, otherwise the symbol name and offset from
20220 +symbol value are printed.
20221 +By default the section data is printed for kernel symbols.
20222 +.P
20223 +The
20224 +.B mm
20225 +and
20226 +\fBmm\fIW\fR
20227 +commands allow modification of memory.   The bytes at the address
20228 +represented by \fIaddress-expression\fP are changed to
20229 +\fInew-contents\fP.  \fInew-contents\fP is allowed to be an
20230 +\fIaddress-expression\fP.
20231 +.B mm
20232 +changes a machine word, \fBmm\fIW\fR changes \fIW\fR bytes at that
20233 +address.
20234 +.SH LIMITATIONS
20235 +None.
20236 +.SH ENVIRONMENT
20237 +.TP 8
20238 +MDCOUNT
20239 +This environment variable (default=8) defines the number of lines
20240 +that will be displayed by each invocation of the \fBmd\fP command.
20241 +
20242 +.TP 8
20243 +RADIX
20244 +This environment variable (default=16) defines the radix used to
20245 +print the memory contents.
20246 +
20247 +.TP 8
20248 +BYTESPERWORD
20249 +This environment variable (default=4) selects the width of output
20250 +data when printing memory contents.  Select the value two to get
20251 +16-bit word output, select the value one to get byte output.
20252 +
20253 +.TP 8
20254 +LINES
20255 +This environment variable governs the number of lines of output
20256 +that will be presented before the kernel debugger built-in pager
20257 +pauses the output.   This variable only affects the functioning
20258 +of the \fBmd\fP and \fBmds\fP if the \fBMDCOUNT\fP variable
20259 +is set to a value greater than the \fBLINES\fP variable.
20260 +
20261 +.TP 8
20262 +NOSECT
20263 +If the \fBNOSECT\fP environment variable is non-zero then the
20264 +section information is suppressed.
20265 +The default is NOSECT=1 so section data is suppressed; use set\ NOSECT=0
20266 +to see section information.
20267 +.SH SMP CONSIDERATIONS
20268 +None.
20269 +.SH EXAMPLES
20270 +.TP 8
20271 +md %edx
20272 +Display memory starting at the address contained in register \fB%edx\fP.
20273 +
20274 +.TP 8
20275 +mds %esp
20276 +Display stack contents symbolically.   This command is quite useful
20277 +in manual stack traceback.
20278 +
20279 +.TP 8
20280 +mm 0xc0252110 0x25
20281 +Change the memory location at 0xc0252110 to the value 0x25.
20282 +
20283 +.TP 8
20284 +md chrdev_table 15
20285 +Display 15 lines (at 16 bytes per line) starting at address
20286 +represented by the symbol \fIchrdev_table\fP.
20287 diff -Nurp linux-2.6.22-590/Documentation/kdb/kdb.mm linux-2.6.22-600/Documentation/kdb/kdb.mm
20288 --- linux-2.6.22-590/Documentation/kdb/kdb.mm   1970-01-01 01:00:00.000000000 +0100
20289 +++ linux-2.6.22-600/Documentation/kdb/kdb.mm   2008-04-09 18:14:28.000000000 +0200
20290 @@ -0,0 +1,492 @@
20291 +.TH KDB 8 "September 21, 2005"
20292 +.hy 0
20293 +.SH NAME
20294 +Built-in Kernel Debugger for Linux - v4.4
20295 +.SH "Overview"
20296 +This document describes the built-in kernel debugger available
20297 +for linux.   This debugger allows the programmer to interactively
20298 +examine kernel memory, disassemble kernel functions, set breakpoints
20299 +in the kernel code and display and modify register contents.
20300 +.P
20301 +A symbol table is included in the kernel image and in modules which
20302 +enables all non-stack symbols (including static symbols) to be used as
20303 +arguments to the kernel debugger commands.
20304 +.SH "Getting Started"
20305 +To include the kernel debugger in a linux kernel, use a
20306 +configuration mechanism (e.g. xconfig, menuconfig, et. al.)
20307 +to enable the \fBCONFIG_KDB\fP option.   Additionally, for accurate
20308 +stack tracebacks, it is recommended that the \fBCONFIG_FRAME_POINTER\fP
20309 +option be enabled (if present).   \fBCONFIG_FRAME_POINTER\fP changes the compiler
20310 +flags so that the frame pointer register will be used as a frame
20311 +pointer rather than a general purpose register.
20312 +.P
20313 +After linux has been configured to include the kernel debugger,
20314 +make a new kernel with the new configuration file (a make clean
20315 +is recommended before making the kernel), and install the kernel
20316 +as normal.
20317 +.P
20318 +You can compile a kernel with kdb support but have kdb off by default,
20319 +select \fBCONFIG_KDB_OFF\fR.  Then the user has to explicitly activate
20320 +kdb by booting with the 'kdb=on' flag or, after /proc is mounted, by
20321 +.nf
20322 +  echo "1" > /proc/sys/kernel/kdb
20323 +.fi
20324 +You can also do the reverse, compile a kernel with kdb on and
20325 +deactivate kdb with the boot flag 'kdb=off' or, after /proc is mounted,
20326 +by
20327 +.nf
20328 +  echo "0" > /proc/sys/kernel/kdb
20329 +.fi
20330 +.P
20331 +When booting the new kernel, the 'kdb=early' flag
20332 +may be added after the image name on the boot line to
20333 +force the kernel to stop in the kernel debugger early in the
20334 +kernel initialization process.  'kdb=early' implies 'kdb=on'.
20335 +If the 'kdb=early' flag isn't provided, then kdb will automatically be
20336 +invoked upon system panic or when the \fBPAUSE\fP key is used from the
20337 +keyboard, assuming that kdb is on.  Older versions of kdb used just a
20338 +boot flag of 'kdb' to activate kdb early, this is no longer supported.
20339 +.P
20340 +KDB can also be used via the serial port.  Set up the system to
20341 +have a serial console (see \fIDocumentation/serial-console.txt\fP), you
20342 +must also have a user space program such as agetty set up to read from
20343 +the serial console.
20344 +The control sequence \fB<esc>KDB\fP on the serial port will cause the
20345 +kernel debugger to be entered, assuming that kdb is on, that some
20346 +program is reading from the serial console, at least one cpu is
20347 +accepting interrupts and the serial console driver is still usable.
20348 +.P
20349 +\fBNote:\fR\ When the serial console sequence consists of multiple
20350 +characters such as <esc>KDB then all but the last character are passed
20351 +through to the application that is reading from the serial console.
20352 +After exiting from kdb, you should use backspace to delete the rest of
20353 +the control sequence.
20354 +.P
20355 +You can boot with kdb activated but without the ability to enter kdb
20356 +via any keyboard sequence.
20357 +In this mode, kdb will only be entered after a system failure.
20358 +Booting with kdb=on-nokey will activate kdb but ignore keyboard
20359 +sequences that would normally drop you into kdb.
20360 +kdb=on-nokey is mainly useful when you are using a PC keyboard and your
20361 +application needs to use the Pause key.
20362 +You can also activate this mode by
20363 +.nf
20364 +  echo "2" > /proc/sys/kernel/kdb
20365 +.fi
20366 +.P
20367 +If the console is sitting on the login prompt when you enter kdb, then
20368 +the login command may switch into upper case mode.
20369 +This is not a kdb bug, it is a "feature" of login - if the userid is
20370 +all upper case then login assumes that you using a TeleType (circa
20371 +1960) which does not have lower case characters.
20372 +Wait 60 seconds for login to timeout and it will switch back to lower
20373 +case mode.
20374 +.P
20375 +\fBNote:\fR\ Your distributor may have chosen a different kdb
20376 +activation sequence for the serial console.
20377 +Consult your distribution documentation.
20378 +.P
20379 +If you have both a keyboard+video and a serial console, you can use
20380 +either for kdb.
20381 +Define both video and serial consoles with boot parameters
20382 +.P
20383 +.nf
20384 +  console=tty0 console=ttyS0,38400
20385 +.fi
20386 +.P
20387 +Any kdb data entered on the keyboard or the serial console will be echoed
20388 +to both.
20389 +.P
20390 +If you are using a USB keyboard then kdb commands cannot be entered
20391 +until the kernel has initialised the USB subsystem and recognised the
20392 +keyboard.
20393 +Using kdb=early with a USB keyboard will not work, the USB subsystem is
20394 +initialised too late.
20395 +.P
20396 +While kdb is active, the keyboard (not serial console) indicators may strobe.
20397 +The caps lock and scroll lock lights will turn on and off, num lock is not used
20398 +because it can confuse laptop keyboards where the numeric keypad is mapped over
20399 +the normal keys.
20400 +On exit from kdb the keyboard indicators will probably be wrong, they will not match the kernel state.
20401 +Pressing caps lock twice should get the indicators back in sync with
20402 +the kernel.
20403 +.SH "Basic Commands"
20404 +There are several categories of commands available to the
20405 +kernel debugger user including commands providing memory
20406 +display and modification, register display and modification,
20407 +instruction disassemble, breakpoints and stack tracebacks.
20408 +Any command can be prefixed with '-' which will cause kdb to ignore any
20409 +errors on that command, this is useful when packaging commands using
20410 +defcmd.
20411 +A line whose first non-space character is '#' is printed and ignored.
20412 +.P
20413 +The following table shows the currently implemented standard commands,
20414 +these are always available.  Other commands can be added by extra
20415 +debugging modules, type '?' at the kdb prompt to get a list of all
20416 +available commands.
20417 +.DS
20418 +.TS
20419 +box, center;
20420 +l | l
20421 +l | l.
20422 +Command        Description
20423 +_
20424 +bc     Clear Breakpoint
20425 +bd     Disable Breakpoint
20426 +be     Enable Breakpoint
20427 +bl     Display breakpoints
20428 +bp     Set or Display breakpoint
20429 +bph    Set or Display hardware breakpoint
20430 +bpa    Set or Display breakpoint globally
20431 +bpha   Set or Display hardware breakpoint globally
20432 +bt     Stack backtrace for current process
20433 +btp    Stack backtrace for specific process
20434 +bta    Stack backtrace for all processes
20435 +btc    Cycle over all live cpus and backtrace each one
20436 +cpu    Display or switch cpus
20437 +dmesg  Display system messages
20438 +defcmd Define a command as a set of other commands
20439 +ef     Print exception frame
20440 +env    Show environment
20441 +go     Restart execution
20442 +handlers       Control the display of IA64 MCA/INIT handlers
20443 +help   Display help message
20444 +id     Disassemble Instructions
20445 +kill   Send a signal to a process
20446 +ll     Follow Linked Lists
20447 +lsmod  List loaded modules
20448 +md     Display memory contents
20449 +mdWcN  Display memory contents with width W and count N.
20450 +mdp    Display memory based on a physical address
20451 +mdr    Display raw memory contents
20452 +mds    Display memory contents symbolically
20453 +mm     Modify memory contents, words
20454 +mmW    Modify memory contents, bytes
20455 +per_cpu        Display per_cpu variables
20456 +pid    Change the default process context
20457 +ps     Display process status
20458 +reboot Reboot the machine
20459 +rd     Display register contents
20460 +rm     Modify register contents
20461 +rq     Display runqueue for one cpu
20462 +rqa    Display runqueue for all cpus
20463 +set    Add/change environment variable
20464 +sr     Invoke SysReq commands
20465 +ss     Single step a cpu
20466 +ssb    Single step a cpu until a branch instruction
20467 +stackdepth     Print the stack depth for selected processes
20468 +summary        Summarize the system
20469 +.TE
20470 +.DE
20471 +.P
20472 +Some commands can be abbreviated, such commands are indicated by a
20473 +non-zero \fIminlen\fP parameter to \fBkdb_register\fP; the value of
20474 +\fIminlen\fP being the minimum length to which the command can be
20475 +abbreviated (for example, the \fBgo\fP command can be abbreviated
20476 +legally to \fBg\fP).
20477 +.P
20478 +If an input string does not match a command in the command table,
20479 +it is treated as an address expression and the corresponding address
20480 +value and nearest symbol are shown.
20481 +.P
20482 +Some of the commands are described here.
20483 +Information on the more complicated commands can be found in the
20484 +appropriate manual pages.
20485 +.TP 8
20486 +cpu
20487 +With no parameters, it lists the available cpus.
20488 +\&'*' after a cpu number indicates a cpu that did not respond to the kdb
20489 +stop signal.
20490 +\&'+' after a cpu number indicates a cpu for which kdb has some data, but
20491 +that cpu is no longer responding to kdb, so you cannot switch to it.
20492 +This could be a cpu that has failed after entering kdb, or the cpu may
20493 +have saved its state for debugging then entered the prom, this is
20494 +normal for an IA64 MCA event.
20495 +\&'I' after a cpu number means that the cpu was idle before it entered
20496 +kdb, it is unlikely to contain any useful data.
20497 +\&'F' after a cpu number means that the cpu is offline.
20498 +There is currenly no way to distinguish between cpus that used to be
20499 +online but are now offline and cpus that were never online, the kernel
20500 +does not maintain the information required to separate those two cases.
20501 +.I cpu
20502 +followed by a number will switch to that cpu, you cannot switch to
20503 +a cpu marked '*', '+' or 'F'.
20504 +This command is only available if the kernel was configured for SMP.
20505 +.TP 8
20506 +dmesg [lines] [adjust]
20507 +Displays the system messages from the kernel buffer.
20508 +If kdb logging is on, it is disabled by dmesg and is left as disabled.
20509 +With no parameters or a zero value for 'lines', dmesg dumps the entire
20510 +kernel buffer.
20511 +If lines is specified and is positive, dmesg dumps the last 'lines'
20512 +from the buffer.
20513 +If lines is specified and is negative, dmesg dumps the first 'lines'
20514 +from the buffer.
20515 +If adjust is specified, adjust the starting point for the lines that
20516 +are printed.
20517 +When 'lines' is positive, move the starting point back by 'adjust'
20518 +lines, when 'lines' is negative, move the starting point forward by
20519 +\&'adjust' lines.
20520 +.I dmesg -100
20521 +will dump 100 lines, from the start of the buffer.
20522 +.I dmesg 100
20523 +will dump 100 lines, starting 100 lines from the end of the buffer,
20524 +.I dmesg 100 100
20525 +will dump 100 lines, starting 200 lines from the end of the buffer.
20526 +.I dmesg -100 100
20527 +will dump 100 lines, starting 100 lines from the start of the buffer.
20528 +.TP 8
20529 +defcmd
20530 +Defines a new command as a set of other commands, all input until
20531 +.I endefcmd
20532 +is saved and executed as a package.
20533 +.I defcmd
20534 +takes three parameters, the command name to be defined and used to
20535 +invoke the package, a quoted string containing the usage text and a
20536 +quoted string containing the help text for the command.
20537 +When using defcmd, it is a good idea to prefix commands that might fail
20538 +with '-', this ignores errors so the following commands are still
20539 +executed.
20540 +For example,
20541 +.P
20542 +.nf
20543 +        defcmd diag "" "Standard diagnostics"
20544 +          set LINES 2000
20545 +          set BTAPROMPT 0
20546 +          -id %eip-0x40
20547 +          -cpu
20548 +          -ps
20549 +          -dmesg 80
20550 +          -bt
20551 +          -bta
20552 +        endefcmd
20553 +.fi
20554 +.P
20555 +When used with no parameters, defcmd prints all the defined commands.
20556 +.TP 8
20557 +go
20558 +Continue normal execution.
20559 +Active breakpoints are reestablished and the processor(s) allowed to
20560 +run normally.
20561 +To continue at a specific address, use
20562 +.I rm
20563 +to change the instruction pointer then go.
20564 +.TP 8
20565 +handlers
20566 +Control the display of IA64 MCA/INIT handlers.
20567 +The IA64 MCA/INIT handlers run on separate tasks.
20568 +During an MCA/INIT event, the active tasks are typically the handlers,
20569 +rather than the original tasks, which is not very useful for debugging.
20570 +By default, KDB hides the MCA/INIT handlers so commands such as ps and
20571 +btc will display the original task.
20572 +You can change this behaviour by using
20573 +.I handlers show
20574 +to display the MCA/INIT handlers instead of the original tasks or use
20575 +.I handlers hide
20576 +(the default) to hide the MCA/INIT handlers and display the original
20577 +tasks.
20578 +.I handlers status
20579 +will list the address of the handler task and the original task for
20580 +each cpu.
20581 +\fBNote:\fR\ If the original task was running in user space or it
20582 +failed any of the MCA/INIT verification tests then there is no original
20583 +task to display.
20584 +In this case, the handler will be displayed even if
20585 +.I handlers hide
20586 +is set and
20587 +.I handlers status
20588 +will not show an original task.
20589 +.TP 8
20590 +id
20591 +Disassemble instructions starting at an address.
20592 +Environment variable IDCOUNT controls how many lines of disassembly
20593 +output the command produces.
20594 +.TP 8
20595 +kill
20596 +Internal command to send a signal (like kill(1)) to a process.
20597 +kill -signal pid.
20598 +.TP 8
20599 +lsmod
20600 +Internal command to list modules.
20601 +This does not use any kernel nor user space services so can be used at any time.
20602 +.TP 8
20603 +per_cpu <variable_name> [<length>] [<cpu>]
20604 +Display the values of a per_cpu variable, the variable_name is
20605 +specified without the \fIper_cpu__\fR prefix.
20606 +Length is the length of the variable, 1-8, if omitted or 0 it defaults
20607 +to the size of the machine's register.
20608 +To display the variable on a specific cpu, the third parameter is the
20609 +cpu number.
20610 +When the third parameter is omitted, the variable's value is printed
20611 +from all cpus, except that zero values are suppressed.
20612 +For each cpu, per_cpu prints the cpu number, the address of the
20613 +variable and its value.
20614 +.TP 8
20615 +pid <number>
20616 +Change the current process context, with no parameters it displays the
20617 +current process.
20618 +The current process is used to display registers, both kernel and user
20619 +space.
20620 +It is also used when dumping user pages.
20621 +.I pid R
20622 +resets to the original process that was running when kdb was entered.
20623 +This command is useful if you have been looking at other processes and/or
20624 +cpus and you want to get back to the original process.
20625 +It does not switch cpus, it only resets the context to the original process.
20626 +.TP 8
20627 +reboot
20628 +Reboot the system, with no attempt to do a clean close down.
20629 +.TP 8
20630 +rq <cpu>
20631 +Display the runqueues for the specified cpu.
20632 +.TP 8
20633 +rqa
20634 +Display the runqueues for all cpus.
20635 +.TP 8
20636 +stackdepth <percentage>
20637 +Print the stack usage for processes using more than the specified
20638 +percentage of their stack.
20639 +If percentage is not supplied, it defaults to 60.
20640 +This command is only implemented on i386 and ia64 architectures,
20641 +patches for other architectures will be gratefully accepted.
20642 +.TP 8
20643 +summary
20644 +Print a summary of the system, including the time (no timezone is
20645 +applied), uname information and various critical system counters.
20646 +.SH INITIAL KDB COMMANDS
20647 +kdb/kdb_cmds is a plain text file where you can define kdb commands
20648 +which are to be issued during kdb_init().  One command per line, blank
20649 +lines are ignored, lines starting with '#' are ignored.  kdb_cmds is
20650 +intended for per user customization of kdb, you can use it to set
20651 +environment variables to suit your hardware or to set standard
20652 +breakpoints for the problem you are debugging.  This file is converted
20653 +to a small C object, compiled and linked into the kernel.  You must
20654 +rebuild and reinstall the kernel after changing kdb_cmds.  This file
20655 +will never be shipped with any useful data so you can always override
20656 +it with your local copy.  Sample kdb_cmds:
20657 +.P
20658 +.nf
20659 +# Initial commands for kdb, alter to suit your needs.
20660 +# These commands are executed in kdb_init() context, no SMP, no
20661 +# processes.  Commands that require process data (including stack or
20662 +# registers) are not reliable this early.  set and bp commands should
20663 +# be safe.  Global breakpoint commands affect each cpu as it is booted.
20664 +
20665 +set LINES=50
20666 +set MDCOUNT=25
20667 +set RECURSE=1
20668 +bp sys_init_module
20669 +.fi
20670 +.SH INTERRUPTS AND KDB
20671 +When a kdb event occurs, one cpu (the initial cpu) enters kdb state.
20672 +It uses a cross system interrupt to interrupt the
20673 +other cpus and bring them all into kdb state.  All cpus run with
20674 +interrupts disabled while they are inside kdb, this prevents most
20675 +external events from disturbing the kernel while kdb is running.
20676 +.B Note:
20677 +Disabled interrupts means that any I/O that relies on interrupts cannot
20678 +proceed while kdb is in control, devices can time out.  The clock tick
20679 +is also disabled, machines will lose track of time while they are
20680 +inside kdb.
20681 +.P
20682 +Even with interrupts disabled, some non-maskable interrupt events will
20683 +still occur, these can disturb the kernel while you are debugging it.
20684 +The initial cpu will still accept NMI events, assuming that kdb was not
20685 +entered for an NMI event.  Any cpu where you use the SS or SSB commands
20686 +will accept NMI events, even after the instruction has finished and the
20687 +cpu is back in kdb.  This is an unavoidable side effect of the fact that
20688 +doing SS[B] requires the cpu to drop all the way out of kdb, including
20689 +exiting from the event that brought the cpu into kdb.  Under normal
20690 +circumstances the only NMI event is for the NMI oopser and that is kdb
20691 +aware so it does not disturb the kernel while kdb is running.
20692 +.P
20693 +Sometimes doing SS or SSB on ix86 will allow one interrupt to proceed,
20694 +even though the cpu is disabled for interrupts.  I have not been able
20695 +to track this one down but I suspect that the interrupt was pending
20696 +when kdb was entered and it runs when kdb exits through IRET even
20697 +though the popped flags are marked as cli().  If any ix86 hardware
20698 +expert can shed some light on this problem, please notify the kdb
20699 +maintainer.
20700 +.SH RECOVERING FROM KDB ERRORS
20701 +If a kdb command breaks and kdb has enough of a recovery environment
20702 +then kdb will abort the command and drop back into mainline kdb code.
20703 +This means that user written kdb commands can follow bad pointers
20704 +without killing kdb.  Ideally all code should verify that data areas
20705 +are valid (using kdb_getarea) before accessing it but lots of calls to
20706 +kdb_getarea can be clumsy.
20707 +.P
20708 +The sparc64 port does not currently provide this error recovery.
20709 +If someone would volunteer to write the necessary longjmp/setjmp
20710 +code, their efforts would be greatly appreciated. In the
20711 +meantime, it is possible for kdb to trigger a panic by accessing
20712 +a bad address.
20713 +.SH DEBUGGING THE DEBUGGER
20714 +kdb has limited support for debugging problems within kdb.  If you
20715 +suspect that kdb is failing, you can set environment variable KDBDEBUG
20716 +to a bit pattern which will activate kdb_printf statements within kdb.
20717 +See include/linux/kdb.h, KDB_DEBUG_FLAG_xxx defines.  For example
20718 +.nf
20719 +  set KDBDEBUG=0x60
20720 +.fi
20721 +activates the event callbacks into kdb plus state tracing in sections
20722 +of kdb.
20723 +.nf
20724 +  set KDBDEBUG=0x18
20725 +.fi
20726 +gives lots of tracing as kdb tries to decode the process stack.
20727 +.P
20728 +You can also perform one level of recursion in kdb.  If environment
20729 +variable RECURSE is not set or is 0 then kdb will either recover from
20730 +an error (if the recovery environment is satisfactory) or kdb will
20731 +allow the error to percolate, usually resulting in a dead system.  When
20732 +RECURSE is 1 then kdb will recover from an error or, if there is no
20733 +satisfactory recovery environment, it will drop into kdb state to let
20734 +you diagnose the problem.  When RECURSE is 2 then all errors drop into
20735 +kdb state, kdb does not attempt recovery first.  Errors while in
20736 +recursive state all drop through, kdb does not even attempt to recover
20737 +from recursive errors.
20738 +.SH KEYBOARD EDITING
20739 +kdb supports a command history, which can be accessed via keyboard
20740 +sequences.
20741 +It supports the special keys on PC keyboards, control characters and
20742 +vt100 sequences on a serial console or a PC keyboard.
20743 +.P
20744 +.DS
20745 +.TS
20746 +box, center;
20747 +l | l | l l | l
20748 +l | l | l l | l.
20749 +PC Special keys        Control VT100 key       Codes   Action
20750 +_
20751 +Backspace      ctrl-H  Backspace       0x7f    Delete character to the left of the cursor
20752 +Delete ctrl-D  Delete  \\e[3~  Delete character to the right of the cursor
20753 +Home   ctrl-A  Home    \\e[1~  Go to start of line
20754 +End    ctrl-E  End     \\e[4~  Go to end of line
20755 +Up arrow       ctrl-P  Up arrow        \\e[A   Up one command in history
20756 +Down arrow     ctrl-N  Down arrow      \\e[B   Down one command in history
20757 +Left arrow     ctrl-B  Left arrow      \\e[D   Left one character in current command
20758 +Right arrow    ctrl-F  Right arrow     \\e[C   Right one character in current command
20759 +.TE
20760 +.DE
20761 +.P
20762 +There is no toggle for insert/replace mode, kdb editing is always in
20763 +insert mode.
20764 +Use delete and backspace to delete characters.
20765 +.P
20766 +kdb also supports tab completion for kernel symbols
20767 +Type the start of a kernel symbol and press tab (ctrl-I) to complete
20768 +the name
20769 +If there is more than one possible match, kdb will append any common
20770 +characters and wait for more input, pressing tab a second time will
20771 +display the possible matches
20772 +The number of matches is limited by environment variable DTABCOUNT,
20773 +with a default of 30 if that variable is not set.
20774 +.SH AUTHORS
20775 +Scott Lurndal, Richard Bass, Scott Foehner, Srinivasa Thirumalachar,
20776 +Masahiro Adegawa, Marc Esipovich, Ted Kline, Steve Lord, Andi Kleen,
20777 +Sonic Zhang.
20778 +.br
20779 +Keith Owens <kaos@sgi.com> - kdb maintainer.
20780 +.SH SEE ALSO
20781 +.P
20782 +linux/Documentation/kdb/kdb_{bp,bt,env,ll,md,ps,rd,sr,ss}.man
20783 diff -Nurp linux-2.6.22-590/Documentation/kdb/kdb_ps.man linux-2.6.22-600/Documentation/kdb/kdb_ps.man
20784 --- linux-2.6.22-590/Documentation/kdb/kdb_ps.man       1970-01-01 01:00:00.000000000 +0100
20785 +++ linux-2.6.22-600/Documentation/kdb/kdb_ps.man       2008-04-09 18:14:28.000000000 +0200
20786 @@ -0,0 +1,96 @@
20787 +.TH PS 1 "September 14, 2004"
20788 +.SH NAME
20789 +ps \- Display processes
20790 +.SH SYNOPSIS
20791 +ps [ DRSTCZEUIMA ]
20792 +.SH DESCRIPTION
20793 +The
20794 +.B ps
20795 +command displays the status of all processes in the desired state.
20796 +This command does not take any locks (all cpus should be frozen while
20797 +kdb is running) so it can safely be used to debug lock problems with
20798 +the process table.
20799 +.P
20800 +Without any parameters, \fBps\fP displays all the interesting
20801 +processes, excluding idle tasks and sleeping system daemons.
20802 +If a parameter is specified, it is a single string consisting of the
20803 +letters D, R, S, T, C, Z, E, U, I and M, in any order.
20804 +Each letter selects processes in a specific state, when multiple
20805 +letters are specified, a process will be displayed if it is in any of
20806 +the specified states.
20807 +The states are\ :-
20808 +.P
20809 +.DS
20810 +.TS
20811 +box, center;
20812 +l | l
20813 +l | l.
20814 +D      Uninterruptible sleep
20815 +R      Running
20816 +S      Interruptible sleep
20817 +T      Stopped
20818 +C      Traced
20819 +Z      Zombie
20820 +E      Dead
20821 +U      Unrunnable
20822 +I      Idle task
20823 +M      Sleeping system daemon
20824 +A      All
20825 +.TE
20826 +.DE
20827 +.P
20828 +For state R (running), the process may not be on a cpu at the moment,
20829 +but it is ready to run.
20830 +The header line above the backtrace contains '1' in the fourth field if
20831 +the process is actually on a cpu.
20832 +.P
20833 +The idle task is run on each cpu when there is no work for that cpu to do.
20834 +Unless the idle task is servicing an interrupt, there is no point in
20835 +printing the idle task.
20836 +An idle task that is not servicing a interrupt is marked as state I,
20837 +while servicing an interrupt it is in state R.
20838 +By default, idle tasks are not printed, use \fBps\ I\fR to print them.
20839 +If the idle tasks are not being printed, the start of the \fBps\R
20840 +output contains a list of which cpus are idle.
20841 +.P
20842 +Each cpu has one or more system daemons to handle per cpu work such as
20843 +soft irqs.
20844 +A system daemon (idenified by a NULL mm pointer) that is sleeping is
20845 +marked as state M.
20846 +These processes rarely have any useful data and generate a lot of
20847 +output on large machines, so sleeping system daemons are not printed by
20848 +default.
20849 +Use \fBps\ M\fR to print them.
20850 +.P
20851 +At the start of the \fBps\fR output is a line giving the cpu status,
20852 +see the kdb \fBcpu\fR command.
20853 +.SH LIMITATIONS
20854 +None.
20855 +.SH ENVIRONMENT
20856 +.TP 8
20857 +PS
20858 +This environment variable (default=DRSTCZEU) is used when \fBps\fR
20859 +is issued with no parameters.
20860 +
20861 +.SH SMP CONSIDERATIONS
20862 +None.
20863 +.SH EXAMPLES
20864 +.TP 8
20865 +\fBps\fR
20866 +displays the useful tasks, suppressing idle tasks and sleeping
20867 +system daemons.
20868 +
20869 +.TP 8
20870 +\fBps\ RD\fR
20871 +displays only tasks that are running or are in an uninterruptible
20872 +sleep.
20873 +
20874 +.TP 8
20875 +\fBps\ DRSTCZEUIM\fR
20876 +displays all tasks.
20877 +
20878 +.TP 8
20879 +\fBps\ A\fR
20880 +displays all tasks.
20881 +This is easier than remembering DRSTCZEUIM.
20882 +
20883 diff -Nurp linux-2.6.22-590/Documentation/kdb/kdb_rd.man linux-2.6.22-600/Documentation/kdb/kdb_rd.man
20884 --- linux-2.6.22-590/Documentation/kdb/kdb_rd.man       1970-01-01 01:00:00.000000000 +0100
20885 +++ linux-2.6.22-600/Documentation/kdb/kdb_rd.man       2008-04-09 18:14:28.000000000 +0200
20886 @@ -0,0 +1,170 @@
20887 +.TH RD 1 "September 20, 2005"
20888 +.SH NAME
20889 +rd, rm\- Register manipulation commands
20890 +.SH SYNOPSIS
20891 +rd [[c [n]]|d|u]
20892 +.LP
20893 +rm \fIregister-name\fP \fInew-contents\fP
20894 +.LP
20895 +ef <address>
20896 +.SH DESCRIPTION
20897 +The
20898 +.B rd
20899 +command is used to display the contents of processor and coprocessor registers.
20900 +Without any arguments, the rd command displays the contents of the general
20901 +register set at the point at which the kernel debugger was entered.
20902 +If the bt* or pid commands have been used to change the current process then
20903 +.B rd
20904 +and
20905 +.B rm
20906 +may not be able to display any registers.
20907 +'n' argument is only used for XScale platform to identify the desired
20908 +coprocessor number, while 'd' option is not valid for XScale platform.
20909 +.P
20910 +On IA32 and IA64, with the 'c' argument, the processor control registers
20911 +%cr0, %cr1, %cr2 and %cr4 are displayed, while with the 'd' argument
20912 +the processor debug registers are displayed.  If the 'u' argument
20913 +is supplied, the registers for the current task as of the last
20914 +time the current task entered the kernel are displayed.
20915 +.P
20916 +On XScale, 'c' argument is used to display the
20917 +all coprocessor control registers or specified coprocessor registers by
20918 +argumnet 'n'. Argument 'u' is used to display the
20919 +registers for the current task as of the last time the current task
20920 +entered the kernel. Argument 'd' is not supported.
20921 +.P
20922 +On ix86, the
20923 +.B rm
20924 +command allows modification of a register.  The following
20925 +register names are valid:  \fB%eax\fP, \fB%ebx\fP, \fB%ecx\fP,
20926 +\fB%edx\fP, \fB%esi\fP, \fB%edi\fP, \fB%esp\fP, \fB%eip\fP,
20927 +and \fB%ebp\fP.   Note that if two '%' symbols are used
20928 +consecutively, the register set displayed by the 'u' argument
20929 +to the \fBrd\fP command is modified.
20930 +.P
20931 +The debug registers, \fBdr0\fP through \fBdr3\fP and both
20932 +\fBdr6\fP and \fBdr7\fP can also be modified with the \fBrm\fP
20933 +command.
20934 +.P
20935 +On sparc64, the valid registers are named \fB%g0\fP through
20936 +\fB%g7\fP, \fB%l0\fP through \fB%l7\fP, \fB%o0\fP through
20937 +\fB%o7\fP, and \fB%i0\fP through \fB%i7\fP, with the exceptions
20938 +that \fB%o6\fP is called \fB%sp\fP and that \fB%i6\fP is called
20939 +\fB%fp\fP. The registers \fB%tstate\fP, \fB%tpc\fP, \fB%tnpc\fP,
20940 +\fB%y\fP, and \fB%fprs\fP provide state information at the time
20941 +the system entered kdb. Additionally, when viewing registers, two
20942 +convenience names are provided: \fB%&regs\fP shows the
20943 +address on the stack of the current registers, and \fB%csp\fP
20944 +shows the current stack pointer within kdb itself.
20945 +.P
20946 +While on XScale, both the cpu registers and most coprocessor
20947 +registers can be be modified. \fIregister-name\fP can be followings like
20948 +r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14,
20949 +r15, cpsr to address  cpu registers. For the coprocessor registers in XSacle,
20950 +either alias name or \fICpcc[CRndd[CRmbb[Opaa]]]\fP can be used to address
20951 +the register in coprocessor cc with CRn=dd, CRm=bb and opcode2=aa. All aa, bb, cc, dd can be
20952 +1 or 2 decimal digitals, the default value is 0 when any of them is omitted. Name
20953 +acc0_h and acc0_l are used to identify the high byte and
20954 +low word of accumulator in coprocessor 0.
20955 +.P
20956 +On IA64, the parameter to
20957 +.B rd
20958 +can be d (debug registers), u (user registers at most recent entry to kernel),
20959 +i (interrupt registers), %isr (current interrupt status), s (stacked
20960 +registers), k (kernel registers).  You can also specify these individual
20961 +registers -
20962 +psr,
20963 +ifs,
20964 +ip,
20965 +unat,
20966 +pfs,
20967 +rsc,
20968 +rnat,
20969 +bsps,
20970 +pr,
20971 +ldrs,
20972 +ccv,
20973 +fpsr,
20974 +b0,
20975 +b6,
20976 +b7,
20977 +r1,
20978 +r2,
20979 +r3,
20980 +r8,
20981 +r9,
20982 +r10,
20983 +r11,
20984 +r12,
20985 +r13,
20986 +r14,
20987 +r15,
20988 +r16,
20989 +r17,
20990 +r18,
20991 +r19,
20992 +r20,
20993 +r21,
20994 +r22,
20995 +r23,
20996 +r24,
20997 +r25,
20998 +r26,
20999 +r27,
21000 +r28,
21001 +r29,
21002 +r30,
21003 +r31.
21004 +.B rm
21005 +can change any of the individual registers or the stacked registers.
21006 +.P
21007 +The
21008 +.B ef
21009 +command displays an exception frame at the specified address.
21010 +.SH LIMITATIONS
21011 +Currently the \fBrm\fP command will not allow modification of the
21012 +control registers.
21013 +.P
21014 +Currently neither the \fBrd\fP command nor the \fBrm\fP command will
21015 +display or modify the model specific registers on the Pentium
21016 +and Pentium Pro families.
21017 +.SH ENVIRONMENT
21018 +None.
21019 +.SH SMP CONSIDERATIONS
21020 +None.
21021 +.SH EXAMPLES
21022 +.TP 8
21023 +rd
21024 +Display general register set from kdb's current task.
21025 +
21026 +.TP 8
21027 +rd c 0
21028 +Display coprocessor 0 registers.
21029 +
21030 +.TP 8
21031 +rm %eax 0
21032 +Set the contents of \fB%eax\fP to zero.  This will be the
21033 +value of %eax when kdb returns from the condition which
21034 +invoked it.
21035 +
21036 +.TP 8
21037 +rm %%eax 0
21038 +Set the value of the \fB%eax\fP register to zero.  This will
21039 +be the value the user-mode application will see upon returning
21040 +from the kernel.
21041 +
21042 +.TP 8
21043 +rm %acc0_h 0
21044 +Set the contents of high byte of accumulator to zero.
21045 +
21046 +.TP 8
21047 +rm dr0 0xc1287220
21048 +Set the value of the \fBdr0\fB register to \f(CW0xc1287220\fP.
21049 +
21050 +.TP 8
21051 +rm %InVLD_BTB 0
21052 +Write 0 to coprocessor 15 register with CRn=7, CRm=5, opcode2=6.
21053 +
21054 +.TP 8
21055 +rm %CP15CRn7CRm5Op6 0
21056 +Same with above.
21057 diff -Nurp linux-2.6.22-590/Documentation/kdb/kdb_sr.man linux-2.6.22-600/Documentation/kdb/kdb_sr.man
21058 --- linux-2.6.22-590/Documentation/kdb/kdb_sr.man       1970-01-01 01:00:00.000000000 +0100
21059 +++ linux-2.6.22-600/Documentation/kdb/kdb_sr.man       2008-04-09 18:14:28.000000000 +0200
21060 @@ -0,0 +1,68 @@
21061 +.TH SR 1 "7 October 2002"
21062 +.SH NAME
21063 +sr \- invoke sysrq commands from kdb
21064 +.SH SYNOPSIS
21065 +sr \fIx\fP
21066 +.SH DESCRIPTION
21067 +.hy 0
21068 +The
21069 +.B sr
21070 +command invokes the existing sysrq handler code in the kernel.
21071 +This command takes a single character which is passed to sysrq
21072 +processing, as if you had entered the sysrq key sequence followed by
21073 +that character.
21074 +.P
21075 +.B Caveats:
21076 +.P
21077 +kdb will always call the sysrq code but sysrq may be disabled.
21078 +If you expect to use sysrq functions during debugging then
21079 +.IP ""
21080 +echo "1" > /proc/sys/kernel/sysrq
21081 +.P
21082 +before starting the debug session.
21083 +Alternatively issue
21084 +.IP ""
21085 +mm4 sysrq_enabled 1
21086 +.P
21087 +during debugging.
21088 +.P
21089 +The sysrq code prints a heading using console loglevel 7 then reverts
21090 +to the original loglevel for the rest of the sysrq processing.
21091 +If the rest of the sysrq output is printed at a level below your
21092 +current loglevel then you will not see the output on the kdb console,
21093 +the output will only appear in the printk buffer.
21094 +It is the user's responsibility to set the loglevel correctly if they
21095 +want to see the sysrq output on the console.
21096 +Issue
21097 +.IP ""
21098 +sr 7
21099 +.P
21100 +before any other
21101 +.B sr
21102 +commands if you want to see the output on the console.
21103 +You may even have to adjust the default message loglevel in order to
21104 +see any output from
21105 +.BR sr .
21106 +See Documentation/sysctl/kernel.txt for details on setting console
21107 +loglevels via /proc.
21108 +You can also adjust the loglevel variables via kdb
21109 +.BR mm ;
21110 +on older kernels there are variables such as default_message_level, on
21111 +newer kernels all the loglevel variables are in array console_printk,
21112 +see kernel/printk.c for your kernel.
21113 +.P
21114 +Operations that require interrupt driven I/O can be invoked from kdb
21115 +.BR sr ,
21116 +but they will not do anything until you type 'go' to exit from kdb
21117 +(interrupts are disabled while in kdb).
21118 +There is no guarantee that these operations will work, if the machine
21119 +entered kdb because of an error then interrupt driven I/O may already
21120 +be dead.
21121 +Do not assume that
21122 +.B sr\ s
21123 +does anything useful.
21124 +.P
21125 +The sysrq handler uses locks and calls printk which also uses locks.
21126 +If the sysrq handler or any of the sysrq functions have to wait for a
21127 +lock then they will never return and kdb will appear to hang.
21128 +Invoking sysrq code from kdb is inherently unsafe.
21129 diff -Nurp linux-2.6.22-590/Documentation/kdb/kdb_ss.man linux-2.6.22-600/Documentation/kdb/kdb_ss.man
21130 --- linux-2.6.22-590/Documentation/kdb/kdb_ss.man       1970-01-01 01:00:00.000000000 +0100
21131 +++ linux-2.6.22-600/Documentation/kdb/kdb_ss.man       2008-04-09 18:14:28.000000000 +0200
21132 @@ -0,0 +1,109 @@
21133 +.TH SS 1 "17 January 2002"
21134 +.SH NAME
21135 +ss, ssb \- Single Step
21136 +.SH SYNOPSIS
21137 +ss
21138 +.LP
21139 +ssb
21140 +.SH DESCRIPTION
21141 +The
21142 +.B ss
21143 +command is used to execute a single instruction and return
21144 +to the kernel debugger.
21145 +.P
21146 +Both the instruction that was single-stepped and the next
21147 +instruction to execute are printed.
21148 +.P
21149 +The \fBssb\fP command will execute instructions from the
21150 +current value of the instruction pointer.  Each instruction
21151 +may be printed as it is executed, depending upon architecture;
21152 +execution will stop at any instruction which would cause the flow
21153 +of control to change (e.g. branch, call, interrupt instruction,
21154 +return, etc.)
21155 +.SH LIMITATIONS
21156 +On sparc64, there are some circumstances where single-stepping
21157 +can be dangerous. Do not single-step across an instruction which
21158 +changes the interrupt-enable bit in %tstate. Do not single step
21159 +through code which is invoked when entering or leaving the
21160 +kernel, particularly any kernel entry code before %tl is set to
21161 +0, or any kernel exit code after %tl is set to 1.
21162 +.SH ENVIRONMENT
21163 +None.
21164 +.SH SMP CONSIDERATIONS
21165 +Other processors are held in the kernel debugger when the instruction
21166 +is traced.  Single stepping though code that requires a lock which is
21167 +in use by another processor is an exercise in futility, it will never
21168 +succeed.
21169 +.SH INTERRUPT CONSIDERATIONS
21170 +When a kdb event occurs, one cpu (the initial cpu) enters kdb state.
21171 +It uses a cross system interrupt to interrupt the
21172 +other cpus and bring them all into kdb state.  All cpus run with
21173 +interrupts disabled while they are inside kdb, this prevents most
21174 +external events from disturbing the kernel while kdb is running.
21175 +.B Note:
21176 +Disabled interrupts means that any I/O that relies on interrupts cannot
21177 +proceed while kdb is in control, devices can time out.  The clock tick
21178 +is also disabled, machines will lose track of time while they are
21179 +inside kdb.
21180 +.P
21181 +Even with interrupts disabled, some non-maskable interrupt events
21182 +will still occur, these can disturb the kernel while you are
21183 +debugging it.  The initial cpu will still accept NMI events,
21184 +assuming that kdb was not entered for an NMI event.  Any cpu
21185 +where you use the SS or SSB commands will accept NMI events, even
21186 +after the instruction has finished and the cpu is back in kdb.
21187 +This is an unavoidable side effect of the fact that doing SS[B]
21188 +requires the cpu to drop all the way out of kdb, including
21189 +exiting from the NMI event that brought the cpu into kdb.  Under
21190 +normal circumstances the only NMI event is for the NMI oopser and
21191 +that is kdb aware so it does not disturb the kernel while kdb is
21192 +running.
21193 +.P
21194 +Sometimes doing SS or SSB on ix86 will allow one interrupt to proceed,
21195 +even though the cpu is disabled for interrupts.  I have not been able
21196 +to track this one down but I suspect that the interrupt was pending
21197 +when kdb was entered and it runs when kdb exits through IRET even
21198 +though the popped flags are marked as cli().  If any ix86 hardware
21199 +expert can shed some light on this problem, please notify the kdb
21200 +maintainer.
21201 +.SH EXAMPLES
21202 +.nf
21203 +.na
21204 +.ft CW
21205 +kdb> bp gendisk_head datar 4
21206 +Data Access Breakpoint #0 at 0xc024ddf4 (gendisk_head) in dr0 is enabled on cpu 0
21207 +for 4 bytes
21208 +kdb> go
21209 +...
21210 +[root@host /root]# cat /proc/partitions
21211 +Entering kdb on processor 0 due to Debug Exception @ 0xc01845e3
21212 +Read/Write breakpoint #0 at 0xc024ddf4
21213 +[0]kdb> ssb
21214 +sd_finish+0x7b:  movzbl 0xc02565d4,%edx
21215 +sd_finish+0x82:  leal   0xf(%edx),%eax
21216 +sd_finish+0x85:  sarl   $0x4,%eax
21217 +sd_finish+0x88:  movl   0xc0256654,%ecx
21218 +sd_finish+0x8e:  leal   (%eax,%eax,4),%edx
21219 +sd_finish+0x91:  leal   (%eax,%edx,2),%edx
21220 +sd_finish+0x94:  movl   0xc0251108,%eax
21221 +sd_finish+0x99:  movl   %eax,0xffffffc(%ecx,%edx,4)
21222 +sd_finish+0x9d:  movl   %ecx,0xc0251108
21223 +sd_finish+0xa3:  xorl   %ebx,%ebx
21224 +sd_finish+0xa5:  cmpb   $0x0,0xc02565d4
21225 +[0]kdb> go
21226 +[root@host /root]#
21227 +
21228 +[0]kdb> ss
21229 +sys_read:   pushl  %ebp
21230 +SS trap at 0xc01274c1
21231 +sys_read+0x1:   movl   %esp,%ebp
21232 +[0]kdb> ss
21233 +sys_read+0x1:   movl   %esp,%ebp
21234 +SS trap at 0xc01274c3
21235 +sys_read+0x3:   subl   $0xc,%esp
21236 +[0]kdb> ss
21237 +sys_read+0x3:   subl   $0xc,%esp
21238 +SS trap at 0xc01274c6
21239 +sys_read+0x6:   pushl  %edi
21240 +[0]kdb>
21241 +
21242 diff -Nurp linux-2.6.22-590/Documentation/kdb/slides linux-2.6.22-600/Documentation/kdb/slides
21243 --- linux-2.6.22-590/Documentation/kdb/slides   1970-01-01 01:00:00.000000000 +0100
21244 +++ linux-2.6.22-600/Documentation/kdb/slides   2008-04-09 18:14:28.000000000 +0200
21245 @@ -0,0 +1,1382 @@
21246 +#! /opt/cpg/bin/do-mgp
21247 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21248 +%%
21249 +%deffont "standard" tfont "comic.ttf"
21250 +%deffont "thick" tfont "arialb.ttf"
21251 +%deffont "typewriter" xfont "courier new-bold-r"
21252 +%deffont "type2writer" xfont "arial narrow-bold-r"
21253 +%%
21254 +%% Default settings per each line numbers.
21255 +%%
21256 +#%default 1 leftfill, size 2, fore "black", back "LemonChiffon2", font "thick"
21257 +%default 1 leftfill, size 2, fore "black", back "white", font "thick"
21258 +%default 2 size 10, vgap 10, prefix " ", center
21259 +%default 3 size 2, bar "gray70", vgap 10
21260 +%default 4 size 6, fore "black", vgap 30, prefix " ", font "standard", left
21261 +%%
21262 +%% Default settings that are applied to TAB-indented lines.
21263 +%%
21264 +%tab 1 size 4, vgap 35, prefix "  ", icon arc "red" 40
21265 +%tab 2 size 4, vgap 20, prefix "      ", icon delta3 "blue" 40
21266 +%tab 3 size 4, vgap 20, prefix "            ", icon delta3 "green" 40
21267 +%%
21268 +%%
21269 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21270 +%page
21271 +
21272 +KDB - Kernel Debugger
21273 +
21274 +
21275 +
21276 +%size 7,center, font "thick"
21277 +Introduction
21278 +
21279 +And
21280 +
21281 +Demonstration
21282 +
21283 +
21284 +%size 3
21285 +
21286 +February 5, 2002                                   IBM Linux Technology Center                                   Paul Dorwin
21287 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21288 +%page
21289 +
21290 +IBM Legal
21291 +
21292 +
21293 +       IBM Legal requires this information:
21294 +
21295 +%size 3
21296 +
21297 +        THE INFORMATION IN THE FOLLOWING PRESENTATION IS PREPARED
21298 +        SOLELY FOR THE INFORMATION OF THE READER, AND COMES "AS IS"
21299 +        AND WITHOUT WARRANTY OR REPRESENATION OF ANY KIND.
21300 +
21301 +        ANY PARTY USING THE MATERIALS IN THIS PRESENTATION DOES SO
21302 +        AT ITS OWN RISK LIABILITY AND THE PROVIDER OF THE MATERIALS
21303 +        ACCEPTS NO RISK OR LIABILITY FOR SUCH USE OR RESULTING FROM
21304 +        DISSEMINATION TO OR USE BY ANY OTHER PARTY
21305 +
21306 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21307 +%page
21308 +
21309 +Agenda
21310 +
21311 +%size 5
21312 +
21313 +        Installing and Configuring KDB
21314 +
21315 +        KDB Commands
21316 +
21317 +        Scull Demo
21318 +
21319 +                Setting Breakpoints
21320 +
21321 +                Displaying Data Structures
21322 +
21323 +        Kernel Data structures
21324 +
21325 +                Take a walk through an IO operation
21326 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21327 +%page
21328 +
21329 +Installing Configuring KDB
21330 +
21331 +
21332 +       Install KDB patch.
21333 +               Start with a clean source tree
21334 +               Apply architecture specific patches
21335 +               Obtain patch for your kernel version
21336 +                       see http://oss.sgi.com/projects/kdb/
21337 +               Apply the kdb patch
21338 +                       patch -p 1 -N -u -i /path/to/patch
21339 +               Apply any other patches
21340 +               Build and reboot on your kdb enabled kernel
21341 +               Man pages can be found at Documentation/kdb
21342 +
21343 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21344 +%page
21345 +
21346 +Configuring KDB
21347 +
21348 +
21349 +       Config kernel with the following options:
21350 +               These are documented in Documentation/Configure.help
21351 +
21352 +               CONFIG_KDB=y
21353 +                       Enable compilation of KDB in the kernel..
21354 +                       Setting this also sets CONFIG_KALLSYMS=y.
21355 +               CONFIG_KDB_MODULES=n
21356 +                       KDB may be extended, compiling kdb/modules.
21357 +               CONFIG_KDB_OFF=n
21358 +                       y = KDB is disabled  by default.
21359 +                       boot with kdb=on to enable at boot.
21360 +                       /proc/sys/kernel/kdb to enable/disable when system is up.
21361 +               CONFIG_KALLSYMS=y
21362 +                       This causes all symbols to be exported.
21363 +               CONFIG_FRAME_POINTER=y
21364 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21365 +%page
21366 +
21367 +Invoking KDB
21368 +
21369 +
21370 +       KDB can be invoked in the following ways:
21371 +
21372 +               Early init with "kdb=early" lilo flag
21373 +                       Hits breakpoint prior to fork_init() (init/main.c)
21374 +
21375 +               Serial console with CNTRL-A
21376 +
21377 +               Console with PAUSE key
21378 +
21379 +               When a pre-set breakpoint is hit
21380 +
21381 +               On panic
21382 +
21383 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21384 +%page
21385 +
21386 +KDB Commands
21387 +
21388 +
21389 +       KDB environment
21390 +               env                             Show environment variables
21391 +               set                             Set environment variables
21392 +               help                    Display Help Message
21393 +               ?                               Display Help Message
21394 +
21395 +       System related
21396 +               sections                        List kernel and module sections
21397 +               lsmod                   List loaded kernel modules
21398 +               reboot                  Reboot the machine immediately
21399 +               cpu             <cpunum>        Switch to new cpu
21400 +
21401 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21402 +%page
21403 +
21404 +KDB Commands
21405 +
21406 +
21407 +       Memory Manipulation
21408 +               md              <vaddr>         Display Memory Contents
21409 +               mdr     <vaddr> <bytes> Display Raw Memory
21410 +               mds     <vaddr>         Display Symbolically
21411 +               mm      <vaddr> <value> Modify Memory Contents
21412 +               id              <vaddr>         Display Instructions
21413 +
21414 +       Register Manipulation
21415 +               rd                              Display Registers
21416 +               rm              <reg> <value>   Modify Registers
21417 +               ef               <vaddr>                Display exception frame
21418 +
21419 +       Stack
21420 +               bt              [<vaddr>]       Stack traceback
21421 +               btp              <pid>          Display stack for <pid>
21422 +               bta                             Display all stacks
21423 +
21424 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21425 +%page
21426 +
21427 +KDB Commands
21428 +
21429 +
21430 +       Breakpoint
21431 +               bc               <bpnum>        Clear Breakpoint
21432 +               bd               <bpnum>        Disable Breakpoint
21433 +               be               <bpnum>        Enable Breakpoint
21434 +               bl              [<vaddr>]       Display breakpoints
21435 +               bp              [<vaddr>]       Set/Display breakpoints
21436 +               bpa             [<vaddr>]       Set/Display global breakpoints
21437 +               bph     [<vaddr>]       Set hardware breakpoint
21438 +               bpha    [<vaddr>]       Set global hardware breakpoint
21439 +               bp* modifiers:
21440 +                       instruction - break on instruction fetch (default)
21441 +                       datar - break on read  at vaddr
21442 +                       dataw - break on write at vaddr
21443 +                       IO - break on in or out op at vaddress
21444 +
21445 +       Execution control
21446 +               go                [<vaddr>]     Continue Execution
21447 +               ss                [<#steps>]    Single Step
21448 +               ssb                             Single step to branch/call
21449 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21450 +%page
21451 +
21452 +KDB Commands
21453 +
21454 +
21455 +       Kernel structures
21456 +               ll <vaddr> <offset> <command>   Traverse list and execute command
21457 +               ps                              Display active task list
21458 +               vm              <vaddr>         Display vm_area_struct
21459 +               dentry  <dentry>                Display interesting dentry stuff
21460 +               filp            <filp>          Display interesting filp stuff
21461 +               sh              <vaddr>         Show scsi_host
21462 +               sd              <vaddr>         Show scsi_device
21463 +               sc              <vaddr>         Show scsi_cmnd
21464 +               kiobuf  <vaddr>         Display kiobuf
21465 +               page    <vaddr>         Display page
21466 +               inode   <vaddr>         Display inode
21467 +               bh              <vaddr>         Display buffer head
21468 +               inode_pages     <inode *>       Display pages in an inode
21469 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21470 +%page
21471 +
21472 +Scull Demo
21473 +
21474 +
21475 +       Objective
21476 +               Find and display the data associated with a scull device
21477 +
21478 +       The sequence of events
21479 +               Populate the scull device with data
21480 +               Identify the breakpoints
21481 +               Set breakpoint in the device read function
21482 +               Identify the data structure elements
21483 +               Identify device structures used to track data
21484 +               Display data structures containing the data
21485 +               Show the usage of the filp command
21486 +
21487 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21488 +%page
21489 +
21490 +Scull Demo: Populate Device
21491 +
21492 +
21493 +       Obtain the code
21494 +               Surf to http://examples.oreilly.com/linuxdrive2/
21495 +               Download the tarball
21496 +               Untar it to /usr/src
21497 +
21498 +       Build and install the module
21499 +               cd /usr/src/ldd2-samples-1.0.1/scull
21500 +               make
21501 +               ./scull.init start
21502 +
21503 +       Populate the scull device
21504 +               cat main.c > /dev/scull0
21505 +               cat /dev/scull0
21506 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21507 +%page
21508 +
21509 +Scull Demo: Driver Details
21510 +
21511 +
21512 +       cat /dev/scull0
21513 +               fd =
21514 +%fore "blue", cont
21515 +open
21516 +%fore "black", cont
21517 +("/dev/scull0", O_RDONLY);
21518 +                       Kernel finds the file_operations structure
21519 +                       Kernel then invokes the open function
21520 +%fore "blue"
21521 +               read
21522 +%fore "black", cont
21523 +(fd, buf, size);
21524 +                       Kernel finds the file_operations structure
21525 +                       Kernel then invokes the read function
21526 +
21527 +       Scull device file operations structure
21528 +
21529 +%font "typewriter", size 3
21530 +    struct file_operations scull_fops = {
21531 +        llseek:     scull_llseek,
21532 +%fore "blue"
21533 +        read:       scull_read,
21534 +%fore "black"
21535 +        write:      scull_write,
21536 +        ioctl:      scull_ioctl,
21537 +%fore "blue"
21538 +        open:       scull_open,
21539 +%fore "black"
21540 +        release:    scull_release,
21541 +    };
21542 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21543 +%page
21544 +
21545 +Scull Demo: Driver Details
21546 +
21547 +%font "typewriter", size 3
21548 +       scull_open code
21549 +%font "typewriter", size 3
21550 +    int
21551 +%fore "blue", cont
21552 +scull_open
21553 +%fore "black", cont
21554 +(struct inode *inode, struct file *filp)
21555 +    {
21556 +        Scull_Dev *dev; /* device information */
21557 +        int num = NUM(inode->i_rdev);
21558 +
21559 +        <snip>
21560 +
21561 +        dev = (Scull_Dev *)filp->private_data;
21562 +        if (!dev) {
21563 +            if (num >= scull_nr_devs) return -ENODEV;
21564 +%fore "blue"
21565 +            dev = &scull_devices[num];
21566 +            filp->private_data = dev;
21567 +%fore "black"
21568 +        }
21569 +
21570 +        <snip>
21571 +
21572 +    }
21573 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21574 +%page
21575 +
21576 +Scull Demo: Driver Details
21577 +
21578 +%font "typewriter", size 3
21579 +       scull_read code
21580 +%font "typewriter", size 3
21581 +    ssize_t
21582 +%fore "blue", cont
21583 +scull_read
21584 +%fore "black", cont
21585 +(struct file *filp, char *buf, size_t count,
21586 +            loff_t *f_pos)
21587 +    {
21588 +
21589 +%fore "blue", cont
21590 +        Scull_Dev *dev = filp->private_data;
21591 +%fore "black", cont
21592 + /* the first listitem */
21593 +%fore "blue"
21594 +        Scull_Dev *dptr;
21595 +%fore "black"
21596 +        int quantum = dev->quantum;
21597 +        int qset = dev->qset;
21598 +        int itemsize = quantum * qset;
21599 +        if (down_interruptible(&dev->sem))
21600 +                return -ERESTARTSYS;
21601 +        if (*f_pos + count > dev->size)
21602 +            count = dev->size - *f_pos;
21603 +
21604 +        /* find listitem, qset index, and offset in the quantum */
21605 +        item = (long)*f_pos / itemsize;
21606 +        rest = (long)*f_pos % itemsize;
21607 +        s_pos = rest / quantum; q_pos = rest % quantum;
21608 +
21609 +        /* follow the list up to the right position */
21610 +%fore "blue"
21611 +        dptr = scull_follow(dev, item);
21612 +%fore "black"
21613 +
21614 +        <snip>
21615 +
21616 +    }
21617 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21618 +%page
21619 +
21620 +Scull Demo: Breakpoints
21621 +
21622 +
21623 +%font "typewriter", size 3
21624 +       Determine where to set breakpoint
21625 +%font "typewriter", size 3
21626 +%fore "blue"
21627 +        dptr = scull_follow(dev, item);
21628 +%fore "black"
21629 +
21630 +%font "typewriter", size 3
21631 +       Disassemble scull_read
21632 +%font "typewriter", size 3
21633 +    [0]kdb>
21634 +%fore "blue", cont
21635 +id scull_read
21636 +%fore "black"
21637 +    0xf8c083b4 scull_read:  push   %ebp
21638 +    0xf8c083b5 scull_read+0x1:mov    %esp,%ebp
21639 +    0xf8c083b7 scull_read+0x3:push   %edi
21640 +            <snip>
21641 +    0xf8c08465 scull_read+0xb1:sub    $0x8,%esp
21642 +%fore "blue"
21643 +    0xf8c08468 scull_read+0xb4:push   %ecx
21644 +    0xf8c08469 scull_read+0xb5:push   %esi
21645 +    0xf8c0846a scull_read+0xb6:call   0xf8c08364 scull_follow:
21646 +%fore "black"
21647 +    0xf8c0846f scull_read+0xbb:mov    %eax,
21648 +%fore "blue", cont
21649 + %edx
21650 +%fore "black"
21651 +    0xf8c08471
21652 +%fore "blue", cont
21653 +scull_read+0xbd
21654 +%fore "black", cont
21655 +:add    $0x10,%esp
21656 +            <snip>
21657 +
21658 +       Set breakpoint in driver read
21659 +%font "typewriter", size 3
21660 +    [0]kdb>
21661 +%fore "blue",cont
21662 +bp scull_read+0xbd
21663 +%fore "black"
21664 +    Instruction(i) BP #0 at 0xf8c08471 ([scull]scull_read+0xbd)
21665 +        is enabled globally adjust 1
21666 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21667 +%page
21668 +
21669 +Scull Demo: Breakpoints
21670 +
21671 +
21672 +%font "typewriter", size 3
21673 +       Restart the system
21674 +%font "typewriter", size 3
21675 +    [0]kdb>
21676 +%fore "blue", cont
21677 +go
21678 +%fore "black"
21679 +
21680 +       Hit the Breakpoint
21681 +%font "typewriter", size 3
21682 +    [root@elm3b77 root]#
21683 +%fore "blue", cont
21684 +cat /dev/scull0
21685 +%fore "black"
21686 +    Instruction(i) breakpoint #0 at 0xf8c08471 (adjusted)
21687 +    0xf8c08471 scull_read+0xbd:int3
21688 +    Entering kdb (current=0xf73ec000, pid 1249) on processor 2
21689 +                  due to Breakpoint @ 0xf8c08471
21690 +
21691 +       Display the registers
21692 +%font "typewriter", size 3
21693 +    [2]kdb>
21694 +%fore "blue", cont
21695 +rd
21696 +%fore "black"
21697 +    eax = 0xf77d7b60 ebx = 0x00000000 ecx = 0x00000000 edx =
21698 +%fore "blue", cont
21699 +0xf77d7b60
21700 +%fore "black"
21701 +    esi =
21702 +%fore "blue", cont
21703 +0xf77d7b60
21704 +%fore "black", cont
21705 + edi = 0x00001000 esp = 0xf7415f40 eip = 0xf8c08471
21706 +    ebp = 0xf7415f78 xss = 0x00000018 xcs = 0x00000010 eflags = 0x00000246
21707 +    xds = 0xf7590018 xes = 0x00000018 origeax = 0xffffffff &regs = 0xf7415f0c
21708 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21709 +%page
21710 +
21711 +Scull Demo: Data Structures
21712 +
21713 +%font "typewriter", size 3
21714 +       Display the Scull_Dev structure
21715 +%font "typewriter", size 3
21716 +    [2]kdb>
21717 +%fore "blue", cont
21718 +md 0xf77d7b60 2
21719 +%fore "black"
21720 +    0xf77d7b60
21721 +%fore "blue", cont
21722 +f7400000
21723 +%fore "black", cont
21724 + 00000000 00000fa0 000003e8   ..@w.... ...h...
21725 +    0xf77d7b70 0000534e 00000000 00000000 00000000   NS..............
21726 +
21727 +       Scull Device Structure
21728 +%font "typewriter", size 3
21729 +    typedef struct Scull_Dev {
21730 +%fore "blue"
21731 +       void **data;
21732 +%fore "black"
21733 +       struct Scull_Dev *next;   /* next listitem */
21734 +       int quantum;              /* the current quantum size */
21735 +       int qset;                 /* the current array size */
21736 +       unsigned long size;
21737 +       devfs_handle_t handle;    /* only used if devfs is there */
21738 +       unsigned int access_key;  /* used by sculluid and scullpriv */
21739 +       struct semaphore sem;     /* mutual exclusion semaphore     */
21740 +    } Scull_Dev;
21741 +%size 6
21742 +
21743 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21744 +%page
21745 +
21746 +Scull Demo: Data Structures
21747 +
21748 +
21749 +%font "typewriter", size 3
21750 +       Display the quantum set (dev->data)
21751 +%font "typewriter", size 3
21752 +    [2]kdb>
21753 +%fore "blue", cont
21754 +md f7400000 2
21755 +%fore "black"
21756 +    0xf7400000
21757 +%fore "blue", cont
21758 +f73ea000
21759 +%fore "black", cont
21760 + f73f1000 f740c000 f7ab4000   . >w..?w.@@w.@+w
21761 +    0xf7400010 f73ef000 f755b000 00000000 00000000   .p>w.0Uw........
21762 +
21763 +       Display the first quantum (dev->data[0])
21764 +%font "typewriter", size 3
21765 +    [2]kdb>
21766 +%fore "blue", cont
21767 +md f73ea000
21768 +%fore "black"
21769 +    0xf73ea000 200a2a2f 616d202a 632e6e69 202d2d20   /*. * main.c --
21770 +    0xf73ea010 20656874 65726162 75637320 63206c6c   the bare scull c
21771 +    0xf73ea020 20726168 75646f6d 200a656c 2a200a2a   har module. *. *
21772 +    0xf73ea030 706f4320 67697279 28207468 32202943    Copyright (C) 2
21773 +    0xf73ea040 20313030 73656c41 646e6173 52206f72   001 Alessandro R
21774 +    0xf73ea050 6e696275 6e612069 6f4a2064 6874616e   ubini and Jonath
21775 +    0xf73ea060 43206e61 6562726f 2a200a74 706f4320   an Corbet. * Cop
21776 +    0xf73ea070 67697279 28207468 32202943 20313030   yright (C) 2001
21777 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21778 +%page
21779 +
21780 +Scull Demo: filp command
21781 +
21782 +
21783 +%font "typewriter", size 3
21784 +       Show filp usage - here is the scull_read prototype
21785 +%font "typewriter", size 3
21786 +    ssize_t scull_read(
21787 +%fore "blue", cont
21788 +struct file *filp
21789 +%fore "black", cont
21790 +, char *buf,
21791 +                       size_t count, loff_t *f_pos);
21792 +       Show the stack trace:
21793 +%font "typewriter", size 3
21794 +[2]kdb>
21795 +%fore "blue", cont
21796 +bt
21797 +%fore "black"
21798 +    EBP       EIP         Function(args)
21799 +    0xee9dbf78 0xf8c08471 [scull]scull_read+0xbd (
21800 +%fore "blue", cont
21801 +0xeaf6c0c0
21802 +%fore "black", cont
21803 +, 0x804e128,
21804 +                                          0x1000, 0xeaf6c0e0, 0x804f000)
21805 +                     scull .text 0xf8c08060 0xf8c083b4 0xf8c084dc
21806 +    0xee9dbfbc 0xc0136278 sys_read+0x98 (0x3, 0x804e128, 0x1000, ...
21807 +                     kernel .text 0xc0100000 0xc01361e0 0xc01362b0
21808 +               0xc010702b system_call+0x33
21809 +                     kernel .text 0xc0100000 0xc0106ff8 0xc0107030
21810 +       And show the filp output
21811 +%font "typewriter", size 3
21812 +    [2]kdb>
21813 +%fore "blue", cont
21814 +filp 0xeaf6c0c0
21815 +%fore "black"
21816 +    name.name 0xe93889fc  name.len  6
21817 +    File Pointer at 0xeaf6c0c0
21818 +     f_list.nxt = 0xe42deca0 f_list.prv = 0xf7e69070
21819 +%fore "blue"
21820 +     f_dentry = 0xe93889a0
21821 +%fore "black", cont
21822 + f_op = 0xf8c0a200
21823 +     f_count = 2 f_flags = 0x8000 f_mode = 0x1
21824 +     f_pos = 0 f_reada = 0 f_ramax = 0
21825 +     f_raend = 0 f_ralen = 0 f_rawin = 0
21826 +
21827 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21828 +%page
21829 +
21830 +Scull Demo: filp command
21831 +
21832 +
21833 +%font "typewriter", size 3
21834 +       filp output - continued
21835 +%font "typewriter", size 3
21836 +%fore "blue"
21837 +    Directory Entry at 0xe93889a0
21838 +%fore "black"
21839 +     d_name.len = 6
21840 +%fore "orange", cont
21841 +d_name.name = 0xe93889fc
21842 +%fore "black", cont
21843 +>
21844 +     d_count = 1 d_flags = 0x0
21845 +%fore "blue", cont
21846 +d_inode = 0xe827b680
21847 +%fore "black"
21848 +     d_hash.nxt = 0xc215aec8 d_hash.prv = 0xc215aec8
21849 +     d_lru.nxt = 0xe93889b8 d_lru.prv = 0xe93889b8
21850 +     d_child.nxt = 0xe89e1e80 d_child.prv = 0xe9388940
21851 +     d_subdirs.nxt = 0xe93889c8 d_subdirs.prv = 0xe93889c8
21852 +     d_alias.nxt = 0xe827b690 d_alias.prv = 0xe827b690
21853 +     d_op = 0x00000000 d_sb = 0xf7e69000
21854 +
21855 +%fore "blue"
21856 +    Inode Entry at 0xe827b680
21857 +%fore "black"
21858 +     i_mode = 0x21a4  i_nlink = 1  i_rdev = 0xfe00
21859 +     i_ino = 37182 i_count = 1 i_dev = 0x821
21860 +     i_hash.nxt = 0xc20e6be8 i_hash.prv = 0xc20e6be8
21861 +     i_list.nxt = 0xe827b2c8 i_list.prv = 0xe827b868
21862 +     i_dentry.nxt = 0xe93889d0 i_dentry.prv = 0xe93889d0
21863 +
21864 +       Check the filename (display d_name.name)
21865 +%font "typewriter", size 3
21866 +    [2]kdb>
21867 +%fore "orange", cont
21868 +md 0xe93889fc 1
21869 +%fore "black"
21870 +    0xe93889fc 6c756373 0000306c 00000000 00000000   scull0..........
21871 +
21872 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21873 +%page
21874 +
21875 +Kernel Structures
21876 +
21877 +
21878 +       Objective
21879 +               Show output from various kernel related kdb commands
21880 +
21881 +       Sequence of events
21882 +               Simple Program
21883 +                       Write a simple program which allocates memory and hangs
21884 +                       Show usage of the ps, vm, and ll commands
21885 +               Walk an IO operation
21886 +                       Hit a breakpoint in qlogic driver (isp1020_queuecommand)
21887 +                       Show usage of scsi related commands (sc, sh, and sd)
21888 +                       Show usage of vm related commands (bh, page, inode, inode_pages)
21889 +
21890 +
21891 +
21892 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21893 +%page
21894 +
21895 +Simple program
21896 +
21897 +%font "typewriter", size 3
21898 +       simple.c - simple program which allocates memory
21899 +%font "typewriter", size 3
21900 +%fore "blue"
21901 +    int foo_global[8192];
21902 +%fore "black"
21903 +    main()
21904 +    {
21905 +        int *
21906 +%fore "blue", cont
21907 +foo_malloc;
21908 +%fore "black"
21909 +        int i;
21910 +        foo_malloc = (int *)malloc(0x8192);
21911 +        for(i = 0; i < 0x100; i++) {
21912 +            foo_global[i] = 0xdead0000 | i;
21913 +            foo_malloc[i] = 0xbeef0000 | i;
21914 +        }
21915 +        printf("foo_global at %x\n", (int)foo_global);
21916 +        printf("foo_malloc at %x\n", (int)foo_malloc);
21917 +        printf("sleep forever\n");
21918 +        sleep(2000000);
21919 +    }
21920 +
21921 +       simple output
21922 +%font "typewriter", size 3
21923 +    [root@elm3b77 scull]# cc -o simple simple.c
21924 +    [root@elm3b77 scull]# ./simple
21925 +    foo_global at
21926 +%fore "blue", cont
21927 +8049780
21928 +%fore "black"
21929 +    foo_malloc at
21930 +%fore "blue", cont
21931 +8051788
21932 +%fore "black"
21933 +    sleep forever
21934 +
21935 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21936 +%page
21937 +
21938 +Simple Program
21939 +
21940 +%font "typewriter", size 3
21941 +       Show the output of the ps command
21942 +%font "typewriter", size 3
21943 +    Entering kdb (current=0xc2010000, pid 0) on processor 3 due to
21944 +                                             Keyboard Entry
21945 +    [3]kdb>
21946 +%fore "blue", cont
21947 +ps
21948 +%fore "black"
21949 +    Task Addr  Pid      Parent   [*] cpu  State Thread     Command
21950 +    0xf7efe000 00000001 00000000  0  003  stop  0xf7efe370 init
21951 +    0xf7ef0000 00000002 00000001  0  001  stop  0xf7ef0370 keventd
21952 +    0xf7eec000 00000003 00000000  0  000  stop  0xf7eec370 ksoftirqd_CPU0
21953 +    0xf7eea000 00000004 00000000  0  001  stop  0xf7eea370 ksoftirqd_CPU1
21954 +    0xf7ee8000 00000005 00000000  0  002  stop  0xf7ee8370 ksoftirqd_CPU2
21955 +    0xf7ee6000 00000006 00000000  0  003  stop  0xf7ee6370 ksoftirqd_CPU3
21956 +
21957 +                         <snip>
21958 +
21959 +    0xf7b46000 00001006 00000737  0  003  stop  0xf7b46370 sshd
21960 +    0xf7ace000 00001007 00001006  0  000  stop  0xf7ace370 bash
21961 +    0xef06a000 00001066 00001007  0  003  stop  0xef06a370 su
21962 +    0xeef88000 00001067 00001066  0  000  stop  0xeef88370 bash
21963 +    0xeef64000 00001119 00000770  0  001  stop  0xeef64370 in.ftpd
21964 +%fore "blue"
21965 +    0xeeeac000
21966 +%fore "black", cont
21967 + 00001138 00001067  0  001  stop  0xeeeac370
21968 +%fore "blue", cont
21969 +simple
21970 +%fore "black"
21971 +    [3]kdb>
21972 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21973 +%page
21974 +
21975 +Simple Program
21976 +
21977 +%font "typewriter", size 3
21978 +       Display the task struct
21979 +%font "typewriter", size 3
21980 +    [3]kdb>
21981 +%fore "blue", cont
21982 +md 0xeeeac000
21983 +%fore "black"
21984 +    0xeeeac000 00000001 00000000 00000000 c0000000   ................
21985 +    0xeeeac010 c0339880 00000000 00000000 ffffffff   ................
21986 +    0xeeeac020 0000000a 00000000 00000000
21987 +%fore "blue", cont
21988 +f7e10f00
21989 +%fore "black", cont
21990 +   ..............aw
21991 +    0xeeeac030 00000001 ffffffff ffffffff 00000000   ................
21992 +
21993 +%font "typewriter", size 3
21994 +       Determine offset of mm_struct ptr in task_struct
21995 +%font "typewriter", size 3
21996 +    struct task_struct {
21997 +      [0]   volatile long state;
21998 +      [4]   unsigned long flags;
21999 +      [8]   int sigpending;
22000 +      [c]   mm_segment_t addr_limit;
22001 +      [10]  struct exec_domain *exec_domain;
22002 +      [14]  volatile long need_resched;
22003 +      [18]  unsigned long ptrace;
22004 +      [1c]  int lock_depth;
22005 +      [20]  long counter;
22006 +      [24]  long nice;
22007 +      [28]  unsigned long policy;
22008 +%fore "blue"
22009 +      [2c]  struct mm_struct *mm;
22010 +%fore "black"
22011 +      [30]  int processor;
22012 +      [34]  unsigned long cpus_runnable, cpus_allowed;
22013 +       <snip>
22014 +    };
22015 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22016 +%page
22017 +
22018 +Simple Program
22019 +
22020 +
22021 +%font "typewriter", size 3
22022 +       Display the mm_struct associated with simple process
22023 +%font "typewriter", size 3
22024 +    [3]kdb>
22025 +%fore "blue", cont
22026 +md f7e10f00
22027 +%fore "black"
22028 +    0xf7e10f00
22029 +%fore "blue", cont
22030 +e8357a80
22031 +%fore "black", cont
22032 + e8357978 f7ac77e0 eb15eac0   .z5hxy5h`w,w@j.k
22033 +    0xf7e10f10 00000001 00000002 0000000b 00000000   ................
22034 +    0xf7e10f20 00000001 f7e10f24 f7e10f24 00000001   ................
22035 +    0xf7e10f30 f7e35e70 eea7e8f0 08048000 0804862b   ................
22036 +    0xf7e10f40 0804962c 08049744 08051780 0805a000   ................
22037 +    0xf7e10f50 bffffd10 bffffe00 bffffe09 bffffe09   ................
22038 +    0xf7e10f60 bffffff3 0000005a 00000168 00000000   ................
22039 +    0xf7e10f70 00000000 00000002 00000000 00000001   ................
22040 +
22041 +%font "typewriter", size 3
22042 +       Determine offset of the first vma in the process
22043 +%font "typewriter", size 3
22044 +    struct mm_struct {
22045 +%fore "blue"
22046 +            struct vm_area_struct * mmap;
22047 +%fore "black"
22048 +            rb_root_t mm_rb;
22049 +            struct vm_area_struct * mmap_cache;
22050 +            <snip>
22051 +    };
22052 +
22053 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22054 +%page
22055 +
22056 +Simple Program
22057 +
22058 +%font "typewriter", size 3
22059 +       Display the first vma using md
22060 +%font "typewriter", size 3
22061 +    [3]kdb>
22062 +%fore "blue", cont
22063 +md  e8357a80
22064 +%fore "black"
22065 +    0xe8357a80 f7e10f00 08048000 08049000
22066 +%fore "blue", cont
22067 +e8727e00
22068 +%fore "black",cont
22069 +   ..aw.........~rh
22070 +    0xe8357a90 00000025 00001875 e8727e18 00000001   %...u....~rh....
22071 +
22072 +       Display the first vma using vma
22073 +%font "typewriter", size 3
22074 +    [3]kdb>
22075 +%fore "blue", cont
22076 +vma e8357a80
22077 +%fore "black"
22078 +    struct vm_area_struct at 0xe8357a80 for 68 bytes
22079 +    vm_start = 0x8048000   vm_end = 0x8049000
22080 +    page_prot = 0x25
22081 +    flags:  READ EXEC MAYREAD MAYWRITE MAYEXEC DENYWRITE EXECUTABLE
22082 +%font "typewriter", size 3
22083 +
22084 +       Determine the offset to the vma list
22085 +%font "typewriter", size 3
22086 +    struct vm_area_struct {
22087 +      [0]   struct mm_struct * vm_mm;
22088 +      [4]   unsigned long vm_start;
22089 +      [8]   unsigned long vm_end;
22090 +%fore "blue"
22091 +      [c]   struct vm_area_struct *vm_next;
22092 +%fore "black"
22093 +            <snip>
22094 +    };
22095 +       Display the next vma
22096 +%font "typewriter", size 3
22097 +    [3]kdb> vma e8727e00
22098 +    struct vm_area_struct at 0xe8727e00 for 68 bytes
22099 +    vm_start = 0x8049000   vm_end = 0x804a000
22100 +    page_prot = 0x25
22101 +    flags:  READ WRITE MAYREAD MAYWRITE MAYEXEC DENYWRITE EXECUTABLE
22102 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22103 +%page
22104 +
22105 +Simple Program
22106 +
22107 +%font "typewriter", size 3
22108 +       Use the ll command to display the list of vma's
22109 +%font "typewriter", size 3
22110 +        [3]kdb> ll e8357a80 0xc vma
22111 +.
22112 +        struct vm_area_struct at 0xe8357a80 for 68 bytes
22113 +        vm_start = 0x8048000   vm_end = 0x8049000
22114 +        page_prot = 0x25
22115 +        flags:  READ EXEC MAYREAD MAYWRITE MAYEXEC DENYWRITE EXECUTABLE
22116 +.
22117 +        struct vm_area_struct at 0xe8727e00 for 68 bytes
22118 +        vm_start =
22119 +%fore "orange", cont
22120 +0x8049000
22121 +%fore "black", cont
22122 +   vm_end =
22123 +%fore "orange", cont
22124 +0x804a000
22125 +%fore "black"
22126 +        page_prot = 0x25
22127 +        flags:  READ WRITE MAYREAD MAYWRITE MAYEXEC DENYWRITE EXECUTABLE
22128 +.
22129 +        struct vm_area_struct at 0xe8727c80 for 68 bytes
22130 +        vm_start =
22131 +%fore "blue", cont
22132 +0x804a000
22133 +%fore "black", cont
22134 +   vm_end =
22135 +%fore "blue", cont
22136 +0x805a000
22137 +%fore "black"
22138 +        page_prot = 0x25
22139 +        flags:  READ WRITE EXEC MAYREAD MAYWRITE MAYEXEC
22140 +        <snip>
22141 +        struct vm_area_struct at 0xe8357900 for 68 bytes
22142 +        vm_start = 0xbfffe000   vm_end = 0xc0000000
22143 +        page_prot = 0x25
22144 +        flags:  READ WRITE EXEC MAYREAD MAYWRITE MAYEXEC GROWSDOWN
22145 +
22146 +       Match the vma to the displayed addresses
22147 +%font "typewriter", size 3
22148 +        foo_global  at
22149 +%fore "orange", cont
22150 +8049780
22151 +%fore "black"
22152 +        foo_malloc at
22153 +%fore "blue", cont
22154 +8051788
22155 +%fore "black"
22156 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22157 +%page
22158 +
22159 +Walking IO structures
22160 +
22161 +
22162 +       Objective
22163 +               Show usage of various scsi and vm related kdb commands
22164 +
22165 +       Sequence:
22166 +               Set a breakpoint in the scsi driver
22167 +                       Stops when queueing a command to the controller
22168 +               Cause IO on an idle disk
22169 +               Show various IO stack traces
22170 +               Display the IO data structures
22171 +               Display vm information about the data
22172 +
22173 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22174 +%page
22175 +
22176 +Walking IO structures
22177 +
22178 +
22179 +%font "typewriter", size 3
22180 +       Set the breakpoint
22181 +
22182 +%font "typewriter", size 3
22183 +    [3]kdb>
22184 +%fore "blue", cont
22185 +bp isp1020_queuecommand
22186 +%fore "black"
22187 +    Instruction(i) BP #0 at 0xc01ecfe0 (isp1020_queuecommand)
22188 +        is enabled globally adjust 1
22189 +
22190 +%font "typewriter", size 3
22191 +       Create some activity on a previously unused disk
22192 +
22193 +%font "typewriter", size 3
22194 +    [3]kdb>
22195 +%fore "blue", cont
22196 +go
22197 +%fore "black"
22198 +    [root@elm3b77 root]#
22199 +%fore "blue", cont
22200 +ls /rh62
22201 +%fore "black"
22202 +
22203 +    Instruction(i) breakpoint #0 at 0xc01ecfe0 (adjusted)
22204 +    0xc01ecfe0 isp1020_queuecommand:int3
22205 +
22206 +    Entering kdb (current=0xf75ba000, pid 1181) on processor 3 due to
22207 +                                                Breakpoint @ 0xc01ecfe0
22208 +
22209 +
22210 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22211 +%page
22212 +
22213 +Walking IO structures
22214 +
22215 +
22216 +%font "typewriter", size 3
22217 +       Show the stack.
22218 +       This is a read of the /rh62 directory
22219 +
22220 +%font "typewriter", size 3
22221 +    [1]kdb>
22222 +%fore "blue", cont
22223 +bt
22224 +%fore "black"
22225 +        EBP       EIP         Function(args)
22226 +    0xf75bbdf4 0xc01ecfe0 isp1020_queuecommand
22227 +               0xc01e2c77 scsi_dispatch_cmd+0x1f7
22228 +    0xf75bbe24 0xc01e99b1 scsi_request_fn+0x2f1
22229 +    0xf75bbe34 0xc01c84fd generic_unplug_device+0x2d
22230 +    0xf75bbe50 0xc011b3af __run_task_queue+0x5f
22231 +    0xf75bbe6c 0xc013a63c block_sync_page+0x1c
22232 +    0xf75bbe98 0xc0128127 __lock_page+0x77
22233 +    0xf75bbea4 0xc0128178 lock_page+0x18
22234 +    0xf75bbec8 0xc012a4b3 read_cache_page+0xc3
22235 +    0xf75bbef4 0xc0168e23 ext2_get_page+0x23
22236 +    0xf75bbf48 0xc0168fdd ext2_readdir+0xfd
22237 +    0xf75bbf68 0xc0143d2e vfs_readdir+0x7e
22238 +    0xf75bbfbc 0xc01442ed
22239 +%fore "blue", cont
22240 +sys_getdents64+0x4d
22241 +%fore "black"
22242 +               0xc010702b system_call+0x33
22243 +
22244 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22245 +%page
22246 +
22247 +Walking IO structures
22248 +
22249 +
22250 +%font "typewriter", size 3
22251 +       Allow the operation to complete
22252 +
22253 +%font "typewriter", size 3
22254 +    [3]kdb>
22255 +%fore "blue", cont
22256 +go
22257 +%fore "black"
22258 +    bench  build  etc   lib         mnt   oldsys  rh72  spv   usr
22259 +    bin    data   h     linux       mnt1  opt     root  test  var
22260 +    boot   dev    home  lost+found  mnt2  proc    sbin  tmp
22261 +
22262 +%font "typewriter", size 3
22263 +       Force some more activity
22264 +
22265 +%font "typewriter", size 3
22266 +    [root@elm3b77 root]#
22267 +%fore "blue", cont
22268 +cd /rh62/tmp
22269 +%fore "black"
22270 +    Instruction(i) breakpoint #0 at 0xc01ecfe0 (adjusted)
22271 +    0xc01ecfe0 isp1020_queuecommand:int3
22272 +
22273 +    Entering kdb (current=0xf768a000, pid 981) on processor 3 due to
22274 +                                               Breakpoint @ 0xc01ecfe0
22275 +
22276 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22277 +%page
22278 +
22279 +Walking IO structures
22280 +
22281 +
22282 +%font "typewriter", size 3
22283 +       Show the stack.
22284 +       This is an inode read for /rh62/tmp
22285 +
22286 +%font "typewriter", size 3
22287 +    [3]kdb>
22288 +%fore "blue", cont
22289 +bt
22290 +%fore "black"
22291 +        EBP       EIP         Function(args)
22292 +    0xf768bd68 0xc01ecfe0 isp1020_queuecommand
22293 +               0xc01e2c77 scsi_dispatch_cmd+0x1f7
22294 +    0xf768bd98 0xc01e99b1 scsi_request_fn+0x2f1
22295 +    0xf768bda8 0xc01c84fd generic_unplug_device+0x2d
22296 +    0xf768bdc4 0xc011b3af __run_task_queue+0x5f
22297 +    0xf768bdfc 0xc0137216 __wait_on_buffer+0x56
22298 +    0xf768be1c 0xc0138600 bread+0x50
22299 +    0xf768be5c 0xc016b684 ext2_read_inode+0x114
22300 +    0xf768bf0c 0xc013fbec real_lookup+0x7c
22301 +    0xf768bf78 0xc014035d link_path_walk+0x5ad
22302 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22303 +%page
22304 +
22305 +Walking IO structures
22306 +
22307 +
22308 +%font "typewriter", size 3
22309 +       Create a new file, causing yet more disk activity
22310 +
22311 +%font "typewriter", size 3
22312 +    [3]kdb>
22313 +%fore "blue", cont
22314 +go
22315 +%fore "black"
22316 +
22317 +    [root@elm3b77 tmp]#
22318 +%fore "blue", cont
22319 +echo "Hello linux reading group" > j1;sync
22320 +%fore "black"
22321 +
22322 +    Instruction(i) breakpoint #0 at 0xc01ecfe0 (adjusted)
22323 +    0xc01ecfe0 isp1020_queuecommand:int3
22324 +
22325 +    Entering kdb (current=0xf768a000, pid 981) on processor 3 due to
22326 +                                               Breakpoint @ 0xc01ecfe0
22327 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22328 +%page
22329 +
22330 +Walking IO structures
22331 +
22332 +
22333 +%font "typewriter", size 3
22334 +       Show the stack
22335 +       This is an inode read in response to the open
22336 +%font "typewriter", size 3
22337 +    [3]kdb>
22338 +%fore "blue", cont
22339 +bt
22340 +%fore "black"
22341 +        EBP       EIP         Function(args)
22342 +    0xf768bd78 0xc01ecfe0 isp1020_queuecommand
22343 +               0xc01e2c77 scsi_dispatch_cmd+0x1f7
22344 +    0xf768bda8 0xc01e99b1 scsi_request_fn+0x2f1
22345 +    0xf768bdb8 0xc01c84fd generic_unplug_device+0x2d
22346 +    0xf768bdd4 0xc011b3af __run_task_queue+0x5f
22347 +    0xf768bdf0 0xc013a63c block_sync_page+0x1c
22348 +    0xf768be1c 0xc0128127 __lock_page+0x77
22349 +    0xf768be28 0xc0128178 lock_page+0x18
22350 +    0xf768be4c 0xc012a4b3 read_cache_page+0xc3
22351 +    0xf768be78 0xc0168e23 ext2_get_page+0x23
22352 +    0xf768beb8 0xc01691ed ext2_find_entry+0x8d
22353 +    0xf768bed4 0xc016933a ext2_inode_by_name+0x1a
22354 +    0xf768befc 0xc016c077 ext2_lookup+0x27
22355 +    0xf768bf1c 0xc014094a lookup_hash+0x9a
22356 +    0xf768bf64 0xc0140c4d open_namei+0xfd
22357 +    0xf768bfa0 0xc0135907 filp_open+0x37
22358 +    0xf768bfbc 0xc0135c64 sys_open+0x34
22359 +               0xc010702b system_call+0x33
22360 +
22361 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22362 +%page
22363 +
22364 +Walking IO structures
22365 +
22366 +
22367 +%font "typewriter", size 3
22368 +       Let the operation continue
22369 +%font "typewriter", size 3
22370 +    [3]kdb>
22371 +%fore "blue", cont
22372 +go
22373 +%fore "black"
22374 +    Instruction(i) breakpoint #0 at 0xc01ecfe0 (adjusted)
22375 +    0xc01ecfe0 isp1020_queuecommand: int3
22376 +    Entering kdb (current=0xc0352000, pid 0) on processor 0 due to
22377 +                                               Breakpoint @ 0xc01ecfe0
22378 +       Show the stack
22379 +       This is an io completion queuing the next request
22380 +%font "typewriter", size 3
22381 +    [0]kdb>
22382 +%fore "blue", cont
22383 +bt
22384 +%fore "black"
22385 +        EBP       EIP         Function(args)
22386 +    0xc0353df4 0xc01ecfe0 isp1020_queuecommand(
22387 +%fore "blue", cont
22388 +0xf7e63a00
22389 +%fore "black", cont
22390 +,0xc01e7fc0...
22391 +               0xc01e2c77 scsi_dispatch_cmd+0x1f7
22392 +    0xc0353e24 0xc01e99b1 scsi_request_fn+0x2f1
22393 +    0xc0353e40 0xc01e8f6a
22394 +%fore "blue", cont
22395 +scsi_queue_next_request+0x4a
22396 +%fore "black"
22397 +    0xc0353e5c 0xc01e9166 __scsi_end_request+0x116
22398 +    0xc0353ea8 0xc01e93e0
22399 +%fore "blue", cont
22400 +scsi_io_completion+0x170
22401 +%fore "black"
22402 +    0xc0353ecc 0xc01f658e rw_intr+0x14e
22403 +    0xc0353ef8 0xc01e8668 scsi_old_done+0x6a8
22404 +    0xc0353fd4 0xc01052c2 cpu_idle+0x52
22405 +       Function prototype
22406 +%font "typewriter", size 3
22407 +        int isp1020_queuecommand(
22408 +%fore "blue", cont
22409 +Scsi_Cmnd *Cmnd,
22410 +%fore "black"
22411 +                                 void (*done)(Scsi_Cmnd *))
22412 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22413 +%page
22414 +
22415 +Walking IO structures
22416 +
22417 +
22418 +%font "typewriter", size 3
22419 +       Show the command being queued
22420 +%font "typewriter", size 3
22421 +    [0]kdb>
22422 +%fore "blue", cont
22423 +sc 0xf7e63a00
22424 +%fore "black"
22425 +    scsi_cmnd at 0xf7e63a00
22426 +%fore "blue"
22427 +    host = 0xf7e91400
22428 +%fore "black", cont
22429 +  state = 4099  owner = 258
22430 +%fore "blue", cont
22431 +device = 0xf7ed5d80
22432 +%fore "black"
22433 +    bnext = 0x00000000  reset_chain = 0x00000000  eh_state = 0
22434 +                                                  done = 0xc01f6440
22435 +    serial_number = 3402  serial_num_at_to = 0 retries = 0 timeout = 0
22436 +    id/lun/cmnd = [0/0/0]  cmd_len = 10  old_cmd_len = 10
22437 +    cmnd = [2a/00/00/28/00/3f/00/00/10/00/ef/f7]
22438 +    data_cmnd = [2a/00/00/28/00/3f/00/00/10/00/ef/f7]
22439 +    request_buffer = 0xc03fd000  bh_next = 0x00000000
22440 +                                 request_bufflen = 8192
22441 +    use_sg = 2  old_use_sg = 2 sglist_len = 512 abore_reason = 0
22442 +    bufflen = 8192  buffer = 0xc03fd000  underflow = 8192
22443 +                                         transfersize = 512
22444 +    tag = 0 pid = 3401
22445 +    request struct
22446 +    rq_status = RQ_ACTIVE  rq_dev = [8/1]  errors = 1  cmd = 0
22447 +    sector = 2621440  nr_sectors = 16  current_nr_sectors = 8
22448 +    buffer = 0xf7599000
22449 +%fore "blue", cont
22450 +bh = 0xf75ca300
22451 +%fore "black", cont
22452 + bhtail = 0xf75ca3c0
22453 +
22454 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22455 +%page
22456 +
22457 +Walking IO structures
22458 +
22459 +
22460 +%font "typewriter", size 3
22461 +       Display the host adapter
22462 +%font "typewriter", size 3
22463 +    [0]kdb>
22464 +%fore "blue", cont
22465 +sh 0xf7e91400
22466 +%fore "black"
22467 +    Scsi_Host at 0xf7e91400
22468 +    next = 0x00000000
22469 +%fore "blue", cont
22470 +host_queue = 0xf7ed5d80
22471 +%fore "black"
22472 +    ehandler = 0x00000000 eh_wait = 0x00000000  en_notify = 0x00000000
22473 +                                                eh_action = 0x00000000
22474 +    h_active = 0x0 host_wait = 0xc0353ac4 hostt = 0xc034bce0
22475 +                                          host_busy = 1
22476 +    host_failed = 0  extra_bytes = 524  host_no = 0 resetting = 0
22477 +    max id/lun/channel = [16/8/0]  this_id = 7
22478 +    can_queue = 64 cmd_per_lun = 1  sg_tablesize = 427 u_isa_dma = 0
22479 +    host_blocked = 0  reverse_ordering = 0
22480 +
22481 +%font "typewriter", size 3
22482 +       Display the scsi device
22483 +%font "typewriter", size 3
22484 +    [0]kdb>
22485 +%fore "blue", cont
22486 +sd 0xf7ed5d80
22487 +%fore "black"
22488 +    scsi_device at 0xf7ed5d80
22489 +    next = 0xf7ed5c80   prev = 0x00000000  host = 0xf7e91400
22490 +    device_busy = 1
22491 +%fore "blue", cont
22492 +device_queue 0xf7e63a00
22493 +%fore "black"
22494 +    id/lun/chan = [0/0/0]  single_lun = 0  device_blocked = 0
22495 +    queue_depth = 1 current_tag = 0  scsi_level = 4
22496 +    IBM      DGHS18X          0360
22497 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22498 +%page
22499 +
22500 +Walking IO structures
22501 +
22502 +
22503 +%font "typewriter", size 3
22504 +       Display the Buffer header associated with the command
22505 +%font "typewriter", size 3
22506 +    [0]kdb>
22507 +%fore "blue", cont
22508 +bh 0xf75ca300
22509 +%fore "black"
22510 +    buffer_head at 0xf75ca300
22511 +      next 0x00000000 bno 327680 rsec 2621440 size 4096
22512 +                                      dev 0x801 rdev 0x801
22513 +      count 2 state 0x1d [Uptodate Lock Req Mapped] ftime 0x7695e
22514 +                    b_list 1 b_reqnext 0xf75ca3c0 b_data 0xf7599000
22515 +%fore "blue"
22516 +      b_page 0xc1dd6640
22517 +%fore "black", cont
22518 + b_this_page 0xf75ca300 b_private 0x00000000
22519 +
22520 +       Display the associated page structure
22521 +%font "typewriter", size 3
22522 +    [0]kdb>
22523 +%fore "blue", cont
22524 +page 0xc1dd6640
22525 +%fore "black"
22526 +    struct page at 0xc1dd6640
22527 +      next 0xc1dd7300 prev 0xc1dd6240
22528 +%fore "blue", cont
22529 +addr space 0xf7af04d0
22530 +%fore "black"
22531 +                                      index 327680 (offset 0x50000000)
22532 +      count 2 flags PG_referenced PG_lru virtual 0xf7599000
22533 +      buffers 0xf75ca300
22534 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22535 +%page
22536 +
22537 +Walking IO structures
22538 +
22539 +
22540 +%font "typewriter", size 3
22541 +       Display the Address space associated with the page
22542 +%font "typewriter", size 3
22543 +    [0]kdb>
22544 +%fore "blue", cont
22545 +md 0xf7af04d0
22546 +%fore "black"
22547 +    0xf7af04d0 c1dd6240 c1dea740 f7af04d8 f7af04d8   @b]A@'^AX./wX./w
22548 +    0xf7af04e0 f7af04e0 f7af04e0 00000007 c033b700   `./w`./w.....73@
22549 +    0xf7af04f0
22550 +%fore "blue", cont
22551 +f7af0420
22552 +%fore "black", cont
22553 + 00000000 00000000 00000001    ./w............
22554 +    0xf7af0500 000001d0 00000000 00000000 f7af050c   P............./w
22555 +    0xf7af0510 f7af050c 00000000 f7a8afa0 00000000   ../w.... /(w....
22556 +
22557 +       The structure looks like:
22558 +%size 3
22559 +    struct address_space {
22560 +        struct list_head    clean_pages; /* list of clean pages */
22561 +        struct list_head    dirty_pages; /* list of dirty pages */
22562 +        struct list_head    locked_pages;/* list of locked pages */
22563 +        unsigned long       nrpages;     /* number of total pages */
22564 +        spinlock_t          page_lock;   /* spinlock protecting them*/
22565 +        struct address_space_operations *a_ops;    /* methods */
22566 +%fore "blue"
22567 +        struct inode        *host;       /* owner: inode, block_dev */
22568 +%fore "black"
22569 +    <snip>
22570 +    };
22571 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22572 +%page
22573 +
22574 +Walking IO structures
22575 +
22576 +
22577 +%font "typewriter", size 3
22578 +       Display the inode associated with the address space
22579 +       I think htis is the inode for the block device.
22580 +
22581 +%font "typewriter", size 3
22582 +    [1]kdb>
22583 +%fore "blue", cont
22584 +inode f7af0420
22585 +%fore "black"
22586 +    struct inode at  0xf7af0420
22587 +     i_ino = 289 i_count = 1 i_dev = 0x801 i_size 4301789184
22588 +     i_mode = 0x8000  i_nlink = 1  i_rdev = 0x801
22589 +     i_hash.nxt = 0xf7af0420 i_hash.prv = 0xf7af0420
22590 +     i_list.nxt = 0xf7af0608 i_list.prv = 0xf7af0068
22591 +     i_dentry.nxt = 0xf7af0430 i_dentry.prv = 0xf7af0430
22592 +     i_dirty_buffers.nxt = 0xf7af0438 i_dirty_buffers.prv = 0xf7af0438
22593 +     i_sb = 0xc201f200 i_op = 0xc03cfdc0 i_data = 0xf7af04d0 nrpages = 6
22594 +     i_mapping = 0xf7af04d0
22595 +     i_flags 0x0 i_state 0x0 []  fs specific info @ 0xf7af0540
22596 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22597 +%page
22598 +
22599 +Walking IO structures
22600 +
22601 +
22602 +%font "typewriter", size 3
22603 +       Display the page list associated with the inode
22604 +%font "typewriter", size 3
22605 +    [0]kdb>
22606 +%fore "blue", cont
22607 +inode_pages f7af0420
22608 +%fore "black"
22609 +CLEAN  page_struct   index  cnt  flags
22610 +   0xc1dd6240    327735        2    0x44 bh 0xf75caae0 bno   327735
22611 +                                            [Lock Req Mapped]
22612 +%fore "blue"
22613 +   0xc1dd6640    327680        2    0x44 bh 0xf75ca300 bno   327680
22614 +                                            [Uptodate Lock Req Mapped]
22615 +%fore "black"
22616 +   0xc1dd7300    327681        2    0x44 bh 0xf75ca3c0 bno   327681
22617 +                                            [Uptodate Lock Req Mapped]
22618 +   0xc1dd6e00    327684        2    0x44 bh 0xf75ca420 bno   327684
22619 +                                            [Uptodate Req Mapped]
22620 +   0xc1de8fc0         4        2    0xc0 bh 0xf7b5ade0 bno        4
22621 +                                            [Uptodate Req Mapped]
22622 +   0xc1dea700         1        2    0x44 bh 0xf7e02740 bno        1
22623 +                                            [Uptodate Req Mapped]
22624 +   0xc1dea740         0        2    0x44 bh 0xf7e028c0 bno        0
22625 +                                            [Uptodate Req Mapped]
22626 +DIRTY  page_struct   index  cnt  flags
22627 +LOCKED page_struct   index  cnt  flags
22628 diff -Nurp linux-2.6.22-590/drivers/char/keyboard.c linux-2.6.22-600/drivers/char/keyboard.c
22629 --- linux-2.6.22-590/drivers/char/keyboard.c    2007-07-09 01:32:17.000000000 +0200
22630 +++ linux-2.6.22-600/drivers/char/keyboard.c    2008-04-09 18:14:28.000000000 +0200
22631 @@ -40,6 +40,9 @@
22632  #include <linux/sysrq.h>
22633  #include <linux/input.h>
22634  #include <linux/reboot.h>
22635 +#ifdef CONFIG_KDB
22636 +#include <linux/kdb.h>
22637 +#endif /* CONFIG_KDB */
22638  
22639  extern void ctrl_alt_del(void);
22640  
22641 @@ -1138,6 +1141,13 @@ static void kbd_keycode(unsigned int key
22642                         if (keycode < BTN_MISC && printk_ratelimit())
22643                                 printk(KERN_WARNING "keyboard.c: can't emulate rawmode for keycode %d\n", keycode);
22644  
22645 +#ifdef CONFIG_KDB
22646 +       if (down && !rep && keycode == KEY_PAUSE && kdb_on == 1) {
22647 +               kdb(KDB_REASON_KEYBOARD, 0, get_irq_regs());
22648 +               return;
22649 +       }
22650 +#endif /* CONFIG_KDB */
22651 +
22652  #ifdef CONFIG_MAGIC_SYSRQ             /* Handle the SysRq Hack */
22653         if (keycode == KEY_SYSRQ && (sysrq_down || (down == 1 && sysrq_alt))) {
22654                 if (!sysrq_down) {
22655 diff -Nurp linux-2.6.22-590/drivers/hid/usbhid/hid-core.c linux-2.6.22-600/drivers/hid/usbhid/hid-core.c
22656 --- linux-2.6.22-590/drivers/hid/usbhid/hid-core.c      2007-07-09 01:32:17.000000000 +0200
22657 +++ linux-2.6.22-600/drivers/hid/usbhid/hid-core.c      2008-04-09 18:14:28.000000000 +0200
22658 @@ -43,6 +43,10 @@
22659  #define DRIVER_DESC "USB HID core driver"
22660  #define DRIVER_LICENSE "GPL"
22661  
22662 +#ifdef CONFIG_KDB_USB
22663 +#include <linux/kdb.h>
22664 +#endif
22665 +
22666  static char *hid_types[] = {"Device", "Pointer", "Mouse", "Device", "Joystick",
22667                                 "Gamepad", "Keyboard", "Keypad", "Multi-Axis Controller"};
22668  /*
22669 @@ -948,6 +952,12 @@ static void hid_disconnect(struct usb_in
22670  
22671         usbhid = hid->driver_data;
22672  
22673 +#ifdef CONFIG_KDB_USB
22674 +       /* Unlink the KDB USB struct */
22675 +       if (usbhid->urbin == kdb_usb_infos.urb)
22676 +               memset(&kdb_usb_infos, 0, sizeof(kdb_usb_infos));
22677 +#endif
22678 +
22679         spin_lock_irq(&usbhid->inlock); /* Sync with error handler */
22680         usb_set_intfdata(intf, NULL);
22681         spin_unlock_irq(&usbhid->inlock);
22682 @@ -1033,6 +1043,16 @@ static int hid_probe(struct usb_interfac
22683         printk(": USB HID v%x.%02x %s [%s] on %s\n",
22684                 hid->version >> 8, hid->version & 0xff, c, hid->name, path);
22685  
22686 +#ifdef CONFIG_KDB_USB
22687 +       /* Initialization of the KDB structure */
22688 +       if (!strcmp(c, "Keyboard")) {
22689 +               struct usbhid_device *usbhid = hid->driver_data;
22690 +               kdb_usb_infos.urb = usbhid->urbin;
22691 +               kdb_usb_infos.buffer = usbhid->inbuf;
22692 +               kdb_usb_infos.reset_timer = NULL;
22693 +       }
22694 +#endif
22695 +
22696         return 0;
22697  }
22698  
22699 diff -Nurp linux-2.6.22-590/drivers/hid/usbhid/usbkbd.c linux-2.6.22-600/drivers/hid/usbhid/usbkbd.c
22700 --- linux-2.6.22-590/drivers/hid/usbhid/usbkbd.c        2007-07-09 01:32:17.000000000 +0200
22701 +++ linux-2.6.22-600/drivers/hid/usbhid/usbkbd.c        2008-04-09 18:14:28.000000000 +0200
22702 @@ -32,6 +32,9 @@
22703  #include <linux/init.h>
22704  #include <linux/usb/input.h>
22705  #include <linux/hid.h>
22706 +#ifdef CONFIG_KDB_USB
22707 +#include <linux/kdb.h>
22708 +#endif
22709  
22710  /*
22711   * Version Information
22712 @@ -288,6 +291,13 @@ static int usb_kbd_probe(struct usb_inte
22713         usb_fill_int_urb(kbd->irq, dev, pipe,
22714                          kbd->new, (maxp > 8 ? 8 : maxp),
22715                          usb_kbd_irq, kbd, endpoint->bInterval);
22716 +
22717 +#ifdef CONFIG_KDB_USB
22718 +       /* Init the KDB structure */
22719 +       kdb_usb_infos.urb = kbd->irq;
22720 +       kdb_usb_infos.buffer = kbd->new;
22721 +       kdb_usb_infos.reset_timer = NULL;
22722 +#endif
22723         kbd->irq->transfer_dma = kbd->new_dma;
22724         kbd->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
22725  
22726 @@ -324,6 +334,11 @@ static void usb_kbd_disconnect(struct us
22727         struct usb_kbd *kbd = usb_get_intfdata (intf);
22728  
22729         usb_set_intfdata(intf, NULL);
22730 +#ifdef CONFIG_KDB_USB
22731 +       /* Unlink the KDB USB struct */
22732 +       if (kbd && kbd->irq == kdb_usb_infos.urb)
22733 +               memset(&kdb_usb_infos, 0, sizeof(kdb_usb_infos));
22734 +#endif /* CONFIG_KDB_USB */
22735         if (kbd) {
22736                 usb_kill_urb(kbd->irq);
22737                 input_unregister_device(kbd->dev);
22738 diff -Nurp linux-2.6.22-590/drivers/serial/8250.c linux-2.6.22-600/drivers/serial/8250.c
22739 --- linux-2.6.22-590/drivers/serial/8250.c      2007-07-09 01:32:17.000000000 +0200
22740 +++ linux-2.6.22-600/drivers/serial/8250.c      2008-04-09 18:14:28.000000000 +0200
22741 @@ -45,6 +45,19 @@
22742  #include <asm/irq.h>
22743  
22744  #include "8250.h"
22745 +#include <linux/kdb.h>
22746 +#ifdef CONFIG_KDB
22747 +/*
22748 + * kdb_serial_line records the serial line number of the first serial console.
22749 + * NOTE: The kernel ignores characters on the serial line unless a user space
22750 + * program has opened the line first.  To enter kdb before user space has opened
22751 + * the serial line, you can use the 'kdb=early' flag to lilo and set the
22752 + * appropriate breakpoints.
22753 + */
22754 +
22755 +static int  kdb_serial_line = -1;
22756 +static const char *kdb_serial_ptr = kdb_serial_str;
22757 +#endif /* CONFIG_KDB */
22758  
22759  /*
22760   * Configuration:
22761 @@ -1287,6 +1300,20 @@ receive_chars(struct uart_8250_port *up,
22762  
22763         do {
22764                 ch = serial_inp(up, UART_RX);
22765 +#ifdef CONFIG_KDB
22766 +               if ((up->port.line == kdb_serial_line) && kdb_on == 1) {
22767 +                   if (ch == *kdb_serial_ptr) {
22768 +                       if (!(*++kdb_serial_ptr)) {
22769 +                           atomic_inc(&kdb_8250);
22770 +                           kdb(KDB_REASON_KEYBOARD, 0, get_irq_regs());
22771 +                           atomic_dec(&kdb_8250);
22772 +                           kdb_serial_ptr = kdb_serial_str;
22773 +                           break;
22774 +                       }
22775 +                   } else
22776 +                       kdb_serial_ptr = kdb_serial_str;
22777 +               }
22778 +#endif /* CONFIG_KDB */
22779                 flag = TTY_NORMAL;
22780                 up->port.icount.rx++;
22781  
22782 @@ -2460,7 +2487,7 @@ serial8250_console_write(struct console 
22783         if (up->port.sysrq) {
22784                 /* serial8250_handle_port() already took the lock */
22785                 locked = 0;
22786 -       } else if (oops_in_progress) {
22787 +       } else if (oops_in_progress || KDB_8250()) {
22788                 locked = spin_trylock(&up->port.lock);
22789         } else
22790                 spin_lock(&up->port.lock);
22791 @@ -2508,6 +2535,30 @@ static int __init serial8250_console_set
22792         if (!port->iobase && !port->membase)
22793                 return -ENODEV;
22794  
22795 +#ifdef CONFIG_KDB
22796 +       /*
22797 +        * Remember the line number of the first serial
22798 +        * console.  We'll make this the kdb serial console too.
22799 +        */
22800 +       if (co && kdb_serial_line == -1) {
22801 +               kdb_serial_line = co->index;
22802 +               kdb_serial.io_type = port->iotype;
22803 +               switch (port->iotype) {
22804 +               case SERIAL_IO_MEM:
22805 +#ifdef  SERIAL_IO_MEM32
22806 +               case SERIAL_IO_MEM32:
22807 +#endif
22808 +                       kdb_serial.iobase = (unsigned long)(port->membase);
22809 +                       kdb_serial.ioreg_shift = port->regshift;
22810 +                       break;
22811 +               default:
22812 +                       kdb_serial.iobase = port->iobase;
22813 +                       kdb_serial.ioreg_shift = 0;
22814 +                       break;
22815 +               }
22816 +       }
22817 +#endif /* CONFIG_KDB */
22818 +
22819         if (options)
22820                 uart_parse_options(options, &baud, &parity, &bits, &flow);
22821  
22822 diff -Nurp linux-2.6.22-590/drivers/serial/8250_early.c linux-2.6.22-600/drivers/serial/8250_early.c
22823 --- linux-2.6.22-590/drivers/serial/8250_early.c        2007-07-09 01:32:17.000000000 +0200
22824 +++ linux-2.6.22-600/drivers/serial/8250_early.c        2008-04-09 18:14:28.000000000 +0200
22825 @@ -35,6 +35,13 @@
22826  #include <asm/io.h>
22827  #include <asm/serial.h>
22828  
22829 +
22830 +#ifdef CONFIG_KDB
22831 +#include <linux/kdb.h>
22832 +
22833 +static int  kdb_serial_line = -1;
22834 +#endif /* CONFIG_KDB */
22835 +
22836  struct early_uart_device {
22837         struct uart_port port;
22838         char options[16];               /* e.g., 115200n8 */
22839 @@ -186,6 +193,31 @@ static int __init early_uart_setup(struc
22840         if ((err = parse_options(device, options)) < 0)
22841                 return err;
22842  
22843 +
22844 +#ifdef CONFIG_KDB
22845 +       /*
22846 +        * Remember the line number of the first serial
22847 +        * console.  We'll make this the kdb serial console too.
22848 +        */
22849 +       if (console && kdb_serial_line == -1) {
22850 +               kdb_serial_line = console->index;
22851 +               kdb_serial.io_type = device->port.iotype;
22852 +               switch (device->port.iotype) {
22853 +               case SERIAL_IO_MEM:
22854 +#ifdef  SERIAL_IO_MEM32
22855 +               case SERIAL_IO_MEM32:
22856 +#endif
22857 +                       kdb_serial.iobase = (unsigned long)(device->port.membase);
22858 +                       kdb_serial.ioreg_shift = device->port.regshift;
22859 +                       break;
22860 +               default:
22861 +                       kdb_serial.iobase = device->port.iobase;
22862 +                       kdb_serial.ioreg_shift = 0;
22863 +                       break;
22864 +               }
22865 +       }
22866 +#endif /* CONFIG_KDB */
22867 +
22868         init_port(device);
22869         return 0;
22870  }
22871 @@ -218,7 +250,7 @@ int __init early_serial_console_init(cha
22872                 return -ENODEV;
22873  
22874         options = strchr(cmdline, ',') + 1;
22875 -       if ((err = early_uart_setup(NULL, options)) < 0)
22876 +       if ((err = early_uart_setup(&early_uart_console, options)) < 0)
22877                 return err;
22878         return early_uart_console_init();
22879  }
22880 diff -Nurp linux-2.6.22-590/drivers/serial/sn_console.c linux-2.6.22-600/drivers/serial/sn_console.c
22881 --- linux-2.6.22-590/drivers/serial/sn_console.c        2007-07-09 01:32:17.000000000 +0200
22882 +++ linux-2.6.22-600/drivers/serial/sn_console.c        2008-04-09 18:14:28.000000000 +0200
22883 @@ -48,6 +48,22 @@
22884  #include <linux/delay.h> /* for mdelay */
22885  #include <linux/miscdevice.h>
22886  #include <linux/serial_core.h>
22887 +#ifdef CONFIG_KDB
22888 +#include <linux/kdb.h>
22889 +#include <linux/kdbprivate.h>
22890 +#include <linux/serial_reg.h>
22891 +/*
22892 + * kdb_serial_line records the serial line number of the first serial console.
22893 + * NOTE: The kernel ignores characters on the serial line unless a user space
22894 + * program has opened the line first.  To enter kdb before user space has opened
22895 + * the serial line, you can use the 'kdb=early' flag to lilo and set the
22896 + * appropriate breakpoints.
22897 + */
22898 +
22899 +static int  kdb_serial_line = -1;
22900 +static char *kdb_serial_ptr = (char *)kdb_serial_str;
22901 +#endif /* CONFIG_KDB */
22902 +
22903  
22904  #include <asm/io.h>
22905  #include <asm/sn/simulator.h>
22906 @@ -485,6 +501,26 @@ sn_receive_chars(struct sn_cons_port *po
22907                                "obtaining data from the console (0x%0x)\n", ch);
22908                         break;
22909                 }
22910 +#ifdef CONFIG_KDB
22911 +       if (kdb_on == 1) {
22912 +               if (ch == *kdb_serial_ptr) {
22913 +                       if (!(*++kdb_serial_ptr)) {
22914 +                               spin_unlock_irqrestore(&port->sc_port.lock, flags);
22915 +                               if (!get_irq_regs()) {
22916 +                                       KDB_STATE_SET(KEYBOARD);
22917 +                                       KDB_ENTER();   /* to get some registers */
22918 +                               } else
22919 +                                       kdb(KDB_REASON_KEYBOARD, 0, get_irq_regs());
22920 +                               kdb_serial_ptr = (char *)kdb_serial_str;
22921 +                               spin_lock_irqsave(&port->sc_port.lock, flags);
22922 +                               break;
22923 +                       }
22924 +               }
22925 +               else
22926 +                       kdb_serial_ptr = (char *)kdb_serial_str;
22927 +       }
22928 +#endif /* CONFIG_KDB */
22929 +
22930  #ifdef CONFIG_MAGIC_SYSRQ
22931                  if (sysrq_requested) {
22932                          unsigned long sysrq_timeout = sysrq_requested + HZ*5;
22933 @@ -1008,6 +1044,15 @@ sn_sal_console_write(struct console *co,
22934   */
22935  static int __init sn_sal_console_setup(struct console *co, char *options)
22936  {
22937 +#ifdef CONFIG_KDB
22938 +       /*
22939 +       * Remember the line number of the first serial
22940 +       * console.  We'll make this the kdb serial console too.
22941 +       */
22942 +       if (kdb_serial_line == -1) {
22943 +               kdb_serial_line = co->index;
22944 +       }
22945 +#endif /* CONFIG_KDB */
22946         return 0;
22947  }
22948  
22949 @@ -1083,3 +1128,31 @@ static int __init sn_sal_serial_console_
22950  }
22951  
22952  console_initcall(sn_sal_serial_console_init);
22953 +
22954 +#ifdef CONFIG_KDB
22955 +int
22956 +l1_control_in_polled(int offset)
22957 +{
22958 +       int sal_call_status = 0, input;
22959 +       int ret = 0;
22960 +       if (offset == UART_LSR) {
22961 +               ret = (UART_LSR_THRE | UART_LSR_TEMT);  /* can send anytime */
22962 +               sal_call_status = ia64_sn_console_check(&input);
22963 +               if (!sal_call_status && input) {
22964 +                       /* input pending */
22965 +                       ret |= UART_LSR_DR;
22966 +               }
22967 +       }
22968 +       return ret;
22969 +}
22970 +
22971 +int
22972 +l1_serial_in_polled(void)
22973 +{
22974 +       int ch;
22975 +       if (!ia64_sn_console_getc(&ch))
22976 +               return ch;
22977 +       else
22978 +               return 0;
22979 +}
22980 +#endif /* CONFIG_KDB */
22981 diff -Nurp linux-2.6.22-590/drivers/usb/host/ohci-hcd.c linux-2.6.22-600/drivers/usb/host/ohci-hcd.c
22982 --- linux-2.6.22-590/drivers/usb/host/ohci-hcd.c        2007-07-09 01:32:17.000000000 +0200
22983 +++ linux-2.6.22-600/drivers/usb/host/ohci-hcd.c        2008-04-09 18:14:28.000000000 +0200
22984 @@ -843,6 +843,53 @@ static int ohci_restart (struct ohci_hcd
22985  
22986  /*-------------------------------------------------------------------------*/
22987  
22988 +#ifdef CONFIG_KDB_USB
22989 +
22990 +static void
22991 +ohci_kdb_poll (void * __ohci, struct urb *urb)
22992 +{
22993 +       struct ohci_hcd *ohci;
22994 +       struct ohci_regs * regs;
22995 +
22996 +       /*
22997 +        * NOTE - we use the ohci_hcd from the urb rather than the
22998 +        * __ohci parameter (which is NULL anyway). This ensures
22999 +        * that we will process the proper controller for the urb.
23000 +        */
23001 +
23002 +       if (!urb) /* can happen if no keyboard attached */
23003 +               return;
23004 +
23005 +       ohci = (struct ohci_hcd *) hcd_to_ohci(bus_to_hcd(urb->dev->bus));
23006 +       regs = ohci->regs;
23007 +
23008 +       /* if the urb is not currently in progress resubmit it */
23009 +       if (urb->status != -EINPROGRESS) {
23010 +
23011 +               if (usb_submit_urb (urb, GFP_ATOMIC))
23012 +                       return;
23013 +
23014 +               /* make sure the HC registers are set correctly */
23015 +               writel (OHCI_INTR_WDH, &regs->intrenable);
23016 +               writel (OHCI_INTR_WDH, &regs->intrstatus);
23017 +               writel (OHCI_INTR_MIE, &regs->intrenable);
23018 +
23019 +               // flush those pci writes
23020 +               (void) readl (&ohci->regs->control);
23021 +       }
23022 +
23023 +       if (ohci->hcca->done_head) {
23024 +               dl_done_list_kdb (ohci, urb);
23025 +               writel (OHCI_INTR_WDH, &regs->intrstatus);
23026 +               // flush the pci write
23027 +               (void) readl (&ohci->regs->control);
23028 +       }
23029 +}
23030 +
23031 +#endif /* CONFIG_KDB_USB */
23032 +
23033 +/*-------------------------------------------------------------------------*/
23034 +
23035  #define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC
23036  
23037  MODULE_AUTHOR (DRIVER_AUTHOR);
23038 diff -Nurp linux-2.6.22-590/drivers/usb/host/ohci-pci.c linux-2.6.22-600/drivers/usb/host/ohci-pci.c
23039 --- linux-2.6.22-590/drivers/usb/host/ohci-pci.c        2007-07-09 01:32:17.000000000 +0200
23040 +++ linux-2.6.22-600/drivers/usb/host/ohci-pci.c        2008-04-09 18:14:28.000000000 +0200
23041 @@ -18,6 +18,10 @@
23042  #error "This file is PCI bus glue.  CONFIG_PCI must be defined."
23043  #endif
23044  
23045 +#ifdef CONFIG_KDB_USB
23046 +#include <linux/kdb.h>
23047 +#endif
23048 +
23049  /*-------------------------------------------------------------------------*/
23050  
23051  static int broken_suspend(struct usb_hcd *hcd)
23052 @@ -199,6 +203,12 @@ static int __devinit ohci_pci_start (str
23053                 ohci_err (ohci, "can't start\n");
23054                 ohci_stop (hcd);
23055         }
23056 +#ifdef CONFIG_KDB_USB
23057 +       if (ret >= 0) {
23058 +               kdb_usb_infos.poll_func = ohci_kdb_poll;
23059 +               kdb_usb_infos.uhci = NULL; /* not used */
23060 +       }
23061 +#endif
23062         return ret;
23063  }
23064  
23065 diff -Nurp linux-2.6.22-590/drivers/usb/host/ohci-q.c linux-2.6.22-600/drivers/usb/host/ohci-q.c
23066 --- linux-2.6.22-590/drivers/usb/host/ohci-q.c  2007-07-09 01:32:17.000000000 +0200
23067 +++ linux-2.6.22-600/drivers/usb/host/ohci-q.c  2008-04-09 18:14:28.000000000 +0200
23068 @@ -1115,3 +1115,65 @@ dl_done_list (struct ohci_hcd *ohci)
23069                 td = td_next;
23070         }
23071  }
23072 +
23073 +
23074 +/*-------------------------------------------------------------------------*/
23075 +
23076 +#ifdef CONFIG_KDB_USB
23077 +static void
23078 +dl_done_list_kdb (struct ohci_hcd *ohci, struct urb *kdburb)
23079 +{
23080 +       struct td       *td = dl_reverse_done_list (ohci);
23081 +
23082 +       while (td) {
23083 +               struct td       *td_next = td->next_dl_td;
23084 +               struct urb      *urb = td->urb;
23085 +               urb_priv_t      *urb_priv = urb->hcpriv;
23086 +               struct ed       *ed = td->ed;
23087 +
23088 +               if (urb != kdburb) {
23089 +                       td = td_next;
23090 +                       continue;
23091 +               }
23092 +
23093 +               /* update URB's length and status from TD */
23094 +               td_done (ohci, urb, td);
23095 +               urb_priv->td_cnt++;
23096 +
23097 +               /* If all this urb's TDs are done, just resubmit it */
23098 +               if (urb_priv->td_cnt == urb_priv->length) {
23099 +                       urb->actual_length = 0;
23100 +                       urb->status = -EINPROGRESS;
23101 +                       td_submit_urb (ohci, urb);
23102 +               }
23103 +
23104 +               /* clean schedule:  unlink EDs that are no longer busy */
23105 +               if (list_empty (&ed->td_list)) {
23106 +                       if (ed->state == ED_OPER)
23107 +                               start_ed_unlink (ohci, ed);
23108 +
23109 +               /* ... reenabling halted EDs only after fault cleanup */
23110 +               } else if ((ed->hwINFO & cpu_to_hc32 (ohci, ED_SKIP | ED_DEQUEUE))
23111 +                                       == cpu_to_hc32 (ohci, ED_SKIP)) {
23112 +                       td = list_entry (ed->td_list.next, struct td, td_list);
23113 +                       if (!(td->hwINFO & cpu_to_hc32 (ohci, TD_DONE))) {
23114 +                               ed->hwINFO &= ~cpu_to_hc32 (ohci, ED_SKIP);
23115 +                               /* ... hc may need waking-up */
23116 +                               switch (ed->type) {
23117 +                               case PIPE_CONTROL:
23118 +                                       ohci_writel (ohci, OHCI_CLF,
23119 +                                               &ohci->regs->cmdstatus);
23120 +                                       break;
23121 +                               case PIPE_BULK:
23122 +                                       ohci_writel (ohci, OHCI_BLF,
23123 +                                               &ohci->regs->cmdstatus);
23124 +                                       break;
23125 +                               }
23126 +                       }
23127 +               }
23128 +
23129 +               td = td_next;
23130 +       }
23131 +}
23132 +
23133 +#endif /* CONFIG_KDB_USB */
23134 diff -Nurp linux-2.6.22-590/fs/proc/mmu.c linux-2.6.22-600/fs/proc/mmu.c
23135 --- linux-2.6.22-590/fs/proc/mmu.c      2007-07-09 01:32:17.000000000 +0200
23136 +++ linux-2.6.22-600/fs/proc/mmu.c      2008-04-09 18:14:28.000000000 +0200
23137 @@ -31,11 +31,21 @@
23138  #include <asm/div64.h>
23139  #include "internal.h"
23140  
23141 +#ifdef CONFIG_KDB
23142 +#include <linux/kdb.h>
23143 +#endif
23144 +
23145  void get_vmalloc_info(struct vmalloc_info *vmi)
23146  {
23147         struct vm_struct *vma;
23148         unsigned long free_area_size;
23149         unsigned long prev_end;
23150 +#ifdef CONFIG_KDB
23151 +       int get_lock = !KDB_IS_RUNNING();
23152 +#else
23153 +#define        get_lock 1
23154 +#endif
23155 +
23156  
23157         vmi->used = 0;
23158  
23159 @@ -47,7 +57,8 @@ void get_vmalloc_info(struct vmalloc_inf
23160  
23161                 prev_end = VMALLOC_START;
23162  
23163 -               read_lock(&vmlist_lock);
23164 +               if (get_lock)
23165 +                       read_lock(&vmlist_lock);
23166  
23167                 for (vma = vmlist; vma; vma = vma->next) {
23168                         unsigned long addr = (unsigned long) vma->addr;
23169 @@ -72,6 +83,7 @@ void get_vmalloc_info(struct vmalloc_inf
23170                 if (VMALLOC_END - prev_end > vmi->largest_chunk)
23171                         vmi->largest_chunk = VMALLOC_END - prev_end;
23172  
23173 -               read_unlock(&vmlist_lock);
23174 +               if (get_lock)
23175 +                       read_unlock(&vmlist_lock);
23176         }
23177  }
23178 diff -Nurp linux-2.6.22-590/fs/proc/proc_misc.c linux-2.6.22-600/fs/proc/proc_misc.c
23179 --- linux-2.6.22-590/fs/proc/proc_misc.c        2008-04-09 18:10:53.000000000 +0200
23180 +++ linux-2.6.22-600/fs/proc/proc_misc.c        2008-04-09 18:14:28.000000000 +0200
23181 @@ -235,6 +235,120 @@ static int meminfo_read_proc(char *page,
23182  #undef K
23183  }
23184  
23185 +#ifdef CONFIG_KDB
23186 +#include <linux/kdb.h>
23187 +#include <linux/kdbprivate.h>
23188 +/* Like meminfo_read_proc() but without the locks and using kdb_printf() */
23189 +void
23190 +kdb_meminfo_read_proc(void)
23191 +{
23192 +       struct sysinfo i;
23193 +       unsigned long committed;
23194 +       unsigned long allowed;
23195 +       struct vmalloc_info vmi;
23196 +       long cached;
23197 +
23198 +/*
23199 + * display in kilobytes.
23200 + */
23201 +#define K(x) ((x) << (PAGE_SHIFT - 10))
23202 +       si_meminfo(&i);
23203 +       kdb_si_swapinfo(&i);
23204 +       committed = atomic_read(&vm_committed_space);
23205 +       allowed = ((totalram_pages - hugetlb_total_pages())
23206 +               * sysctl_overcommit_ratio / 100) + total_swap_pages;
23207 +
23208 +       cached = global_page_state(NR_FILE_PAGES) -
23209 +                       total_swapcache_pages - i.bufferram;
23210 +       if (cached < 0)
23211 +               cached = 0;
23212 +
23213 +       get_vmalloc_info(&vmi);
23214 +
23215 +       kdb_printf(
23216 +               "MemTotal:     %8lu kB\n"
23217 +               "MemFree:      %8lu kB\n"
23218 +               "Buffers:      %8lu kB\n",
23219 +               K(i.totalram),
23220 +               K(i.freeram),
23221 +               K(i.bufferram)
23222 +               );
23223 +       kdb_printf(
23224 +               "Cached:       %8lu kB\n"
23225 +               "SwapCached:   %8lu kB\n"
23226 +               "Active:       %8lu kB\n"
23227 +               "Inactive:     %8lu kB\n",
23228 +               K(cached),
23229 +               K(total_swapcache_pages),
23230 +               K(global_page_state(NR_ACTIVE)),
23231 +               K(global_page_state(NR_INACTIVE))
23232 +               );
23233 +#ifdef CONFIG_HIGHMEM
23234 +       kdb_printf(
23235 +               "HighTotal:    %8lu kB\n"
23236 +               "HighFree:     %8lu kB\n"
23237 +               "LowTotal:     %8lu kB\n"
23238 +               "LowFree:      %8lu kB\n",
23239 +               K(i.totalhigh),
23240 +               K(i.freehigh),
23241 +               K(i.totalram-i.totalhigh),
23242 +               K(i.freeram-i.freehigh)
23243 +               );
23244 +#endif
23245 +       kdb_printf(
23246 +               "SwapTotal:    %8lu kB\n"
23247 +               "SwapFree:     %8lu kB\n"
23248 +               "Dirty:        %8lu kB\n",
23249 +               K(i.totalswap),
23250 +               K(i.freeswap),
23251 +               K(global_page_state(NR_FILE_DIRTY))
23252 +               );
23253 +       kdb_printf(
23254 +               "Writeback:    %8lu kB\n"
23255 +               "AnonPages:    %8lu kB\n"
23256 +               "Mapped:       %8lu kB\n",
23257 +               K(global_page_state(NR_WRITEBACK)),
23258 +               K(global_page_state(NR_ANON_PAGES)),
23259 +               K(global_page_state(NR_FILE_MAPPED))
23260 +               );
23261 +       kdb_printf(
23262 +               "Slab:         %8lu kB\n"
23263 +               "SReclaimable: %8lu kB\n"
23264 +               "SUnreclaim:   %8lu kB\n",
23265 +               K(global_page_state(NR_SLAB_RECLAIMABLE) +
23266 +                               global_page_state(NR_SLAB_UNRECLAIMABLE)),
23267 +               K(global_page_state(NR_SLAB_RECLAIMABLE)),
23268 +               K(global_page_state(NR_SLAB_UNRECLAIMABLE))
23269 +               );
23270 +       kdb_printf(
23271 +               "PageTables:   %8lu kB\n"
23272 +               "NFS_Unstable: %8lu kB\n"
23273 +               "Bounce:       %8lu kB\n",
23274 +               K(global_page_state(NR_PAGETABLE)),
23275 +               K(global_page_state(NR_UNSTABLE_NFS)),
23276 +               K(global_page_state(NR_BOUNCE))
23277 +               );
23278 +       kdb_printf(
23279 +               "CommitLimit:  %8lu kB\n"
23280 +               "Committed_AS: %8lu kB\n"
23281 +               "VmallocTotal: %8lu kB\n",
23282 +               K(allowed),
23283 +               K(committed),
23284 +               (unsigned long)VMALLOC_TOTAL >> 10
23285 +               );
23286 +       kdb_printf(
23287 +               "VmallocUsed:  %8lu kB\n"
23288 +               "VmallocChunk: %8lu kB\n",
23289 +               vmi.used >> 10,
23290 +               vmi.largest_chunk >> 10
23291 +               );
23292 +
23293 +#ifdef CONFIG_HUGETLBFS
23294 +       kdb_hugetlb_report_meminfo();
23295 +#endif
23296 +}
23297 +#endif /* CONFIG_KDB */
23298 +
23299  extern struct seq_operations fragmentation_op;
23300  static int fragmentation_open(struct inode *inode, struct file *file)
23301  {
23302 diff -Nurp linux-2.6.22-590/include/asm-i386/ansidecl.h linux-2.6.22-600/include/asm-i386/ansidecl.h
23303 --- linux-2.6.22-590/include/asm-i386/ansidecl.h        1970-01-01 01:00:00.000000000 +0100
23304 +++ linux-2.6.22-600/include/asm-i386/ansidecl.h        2008-04-09 18:16:14.000000000 +0200
23305 @@ -0,0 +1,383 @@
23306 +/* ANSI and traditional C compatability macros
23307 +   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001
23308 +   Free Software Foundation, Inc.
23309 +   This file is part of the GNU C Library.
23310 +
23311 +This program is free software; you can redistribute it and/or modify
23312 +it under the terms of the GNU General Public License as published by
23313 +the Free Software Foundation; either version 2 of the License, or
23314 +(at your option) any later version.
23315 +
23316 +This program is distributed in the hope that it will be useful,
23317 +but WITHOUT ANY WARRANTY; without even the implied warranty of
23318 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23319 +GNU General Public License for more details.
23320 +
23321 +You should have received a copy of the GNU General Public License
23322 +along with this program; if not, write to the Free Software
23323 +Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
23324 +
23325 +/* Extracted from binutils 2.16.91.0.2 (OpenSUSE 10.0) and modified for kdb use.
23326 + * Any trailing whitespace was removed and #ifdef/ifndef __KERNEL__ added as
23327 + * required.
23328 + * Keith Owens <kaos@sgi.com> 15 May 2006
23329 + */
23330 +
23331 +/* ANSI and traditional C compatibility macros
23332 +
23333 +   ANSI C is assumed if __STDC__ is #defined.
23334 +
23335 +   Macro               ANSI C definition       Traditional C definition
23336 +   -----               ---- - ----------       ----------- - ----------
23337 +   ANSI_PROTOTYPES     1                       not defined
23338 +   PTR                 `void *'                `char *'
23339 +   PTRCONST            `void *const'           `char *'
23340 +   LONG_DOUBLE         `long double'           `double'
23341 +   const               not defined             `'
23342 +   volatile            not defined             `'
23343 +   signed              not defined             `'
23344 +   VA_START(ap, var)   va_start(ap, var)       va_start(ap)
23345 +
23346 +   Note that it is safe to write "void foo();" indicating a function
23347 +   with no return value, in all K+R compilers we have been able to test.
23348 +
23349 +   For declaring functions with prototypes, we also provide these:
23350 +
23351 +   PARAMS ((prototype))
23352 +   -- for functions which take a fixed number of arguments.  Use this
23353 +   when declaring the function.  When defining the function, write a
23354 +   K+R style argument list.  For example:
23355 +
23356 +       char *strcpy PARAMS ((char *dest, char *source));
23357 +       ...
23358 +       char *
23359 +       strcpy (dest, source)
23360 +            char *dest;
23361 +            char *source;
23362 +       { ... }
23363 +
23364 +
23365 +   VPARAMS ((prototype, ...))
23366 +   -- for functions which take a variable number of arguments.  Use
23367 +   PARAMS to declare the function, VPARAMS to define it.  For example:
23368 +
23369 +       int printf PARAMS ((const char *format, ...));
23370 +       ...
23371 +       int
23372 +       printf VPARAMS ((const char *format, ...))
23373 +       {
23374 +          ...
23375 +       }
23376 +
23377 +   For writing functions which take variable numbers of arguments, we
23378 +   also provide the VA_OPEN, VA_CLOSE, and VA_FIXEDARG macros.  These
23379 +   hide the differences between K+R <varargs.h> and C89 <stdarg.h> more
23380 +   thoroughly than the simple VA_START() macro mentioned above.
23381 +
23382 +   VA_OPEN and VA_CLOSE are used *instead of* va_start and va_end.
23383 +   Immediately after VA_OPEN, put a sequence of VA_FIXEDARG calls
23384 +   corresponding to the list of fixed arguments.  Then use va_arg
23385 +   normally to get the variable arguments, or pass your va_list object
23386 +   around.  You do not declare the va_list yourself; VA_OPEN does it
23387 +   for you.
23388 +
23389 +   Here is a complete example:
23390 +
23391 +       int
23392 +       printf VPARAMS ((const char *format, ...))
23393 +       {
23394 +          int result;
23395 +
23396 +          VA_OPEN (ap, format);
23397 +          VA_FIXEDARG (ap, const char *, format);
23398 +
23399 +          result = vfprintf (stdout, format, ap);
23400 +          VA_CLOSE (ap);
23401 +
23402 +          return result;
23403 +       }
23404 +
23405 +
23406 +   You can declare variables either before or after the VA_OPEN,
23407 +   VA_FIXEDARG sequence.  Also, VA_OPEN and VA_CLOSE are the beginning
23408 +   and end of a block.  They must appear at the same nesting level,
23409 +   and any variables declared after VA_OPEN go out of scope at
23410 +   VA_CLOSE.  Unfortunately, with a K+R compiler, that includes the
23411 +   argument list.  You can have multiple instances of VA_OPEN/VA_CLOSE
23412 +   pairs in a single function in case you need to traverse the
23413 +   argument list more than once.
23414 +
23415 +   For ease of writing code which uses GCC extensions but needs to be
23416 +   portable to other compilers, we provide the GCC_VERSION macro that
23417 +   simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
23418 +   wrappers around __attribute__.  Also, __extension__ will be #defined
23419 +   to nothing if it doesn't work.  See below.
23420 +
23421 +   This header also defines a lot of obsolete macros:
23422 +   CONST, VOLATILE, SIGNED, PROTO, EXFUN, DEFUN, DEFUN_VOID,
23423 +   AND, DOTS, NOARGS.  Don't use them.  */
23424 +
23425 +#ifndef        _ANSIDECL_H
23426 +#define _ANSIDECL_H    1
23427 +
23428 +/* Every source file includes this file,
23429 +   so they will all get the switch for lint.  */
23430 +/* LINTLIBRARY */
23431 +
23432 +/* Using MACRO(x,y) in cpp #if conditionals does not work with some
23433 +   older preprocessors.  Thus we can't define something like this:
23434 +
23435 +#define HAVE_GCC_VERSION(MAJOR, MINOR) \
23436 +  (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR)))
23437 +
23438 +and then test "#if HAVE_GCC_VERSION(2,7)".
23439 +
23440 +So instead we use the macro below and test it against specific values.  */
23441 +
23442 +/* This macro simplifies testing whether we are using gcc, and if it
23443 +   is of a particular minimum version. (Both major & minor numbers are
23444 +   significant.)  This macro will evaluate to 0 if we are not using
23445 +   gcc at all.  */
23446 +#ifndef GCC_VERSION
23447 +#define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
23448 +#endif /* GCC_VERSION */
23449 +
23450 +#if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32) || (defined(__alpha) && defined(__cplusplus))
23451 +/* All known AIX compilers implement these things (but don't always
23452 +   define __STDC__).  The RISC/OS MIPS compiler defines these things
23453 +   in SVR4 mode, but does not define __STDC__.  */
23454 +/* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other
23455 +   C++ compilers, does not define __STDC__, though it acts as if this
23456 +   was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */
23457 +
23458 +#define ANSI_PROTOTYPES        1
23459 +#define PTR            void *
23460 +#define PTRCONST       void *const
23461 +#define LONG_DOUBLE    long double
23462 +
23463 +/* PARAMS is often defined elsewhere (e.g. by libintl.h), so wrap it in
23464 +   a #ifndef.  */
23465 +#ifndef PARAMS
23466 +#define PARAMS(ARGS)           ARGS
23467 +#endif
23468 +
23469 +#define VPARAMS(ARGS)          ARGS
23470 +#define VA_START(VA_LIST, VAR) va_start(VA_LIST, VAR)
23471 +
23472 +/* variadic function helper macros */
23473 +/* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's
23474 +   use without inhibiting further decls and without declaring an
23475 +   actual variable.  */
23476 +#define VA_OPEN(AP, VAR)       { va_list AP; va_start(AP, VAR); { struct Qdmy
23477 +#define VA_CLOSE(AP)           } va_end(AP); }
23478 +#define VA_FIXEDARG(AP, T, N)  struct Qdmy
23479 +
23480 +#undef const
23481 +#undef volatile
23482 +#undef signed
23483 +
23484 +#ifdef __KERNEL__
23485 +#ifndef        __STDC_VERSION__
23486 +#define        __STDC_VERSION__ 0
23487 +#endif
23488 +#endif /* __KERNEL__ */
23489 +
23490 +/* inline requires special treatment; it's in C99, and GCC >=2.7 supports
23491 +   it too, but it's not in C89.  */
23492 +#undef inline
23493 +#if __STDC_VERSION__ > 199901L
23494 +/* it's a keyword */
23495 +#else
23496 +# if GCC_VERSION >= 2007
23497 +#  define inline __inline__   /* __inline__ prevents -pedantic warnings */
23498 +# else
23499 +#  define inline  /* nothing */
23500 +# endif
23501 +#endif
23502 +
23503 +/* These are obsolete.  Do not use.  */
23504 +#ifndef IN_GCC
23505 +#define CONST          const
23506 +#define VOLATILE       volatile
23507 +#define SIGNED         signed
23508 +
23509 +#define PROTO(type, name, arglist)     type name arglist
23510 +#define EXFUN(name, proto)             name proto
23511 +#define DEFUN(name, arglist, args)     name(args)
23512 +#define DEFUN_VOID(name)               name(void)
23513 +#define AND            ,
23514 +#define DOTS           , ...
23515 +#define NOARGS         void
23516 +#endif /* ! IN_GCC */
23517 +
23518 +#else  /* Not ANSI C.  */
23519 +
23520 +#undef  ANSI_PROTOTYPES
23521 +#define PTR            char *
23522 +#define PTRCONST       PTR
23523 +#define LONG_DOUBLE    double
23524 +
23525 +#define PARAMS(args)           ()
23526 +#define VPARAMS(args)          (va_alist) va_dcl
23527 +#define VA_START(va_list, var) va_start(va_list)
23528 +
23529 +#define VA_OPEN(AP, VAR)               { va_list AP; va_start(AP); { struct Qdmy
23530 +#define VA_CLOSE(AP)                   } va_end(AP); }
23531 +#define VA_FIXEDARG(AP, TYPE, NAME)    TYPE NAME = va_arg(AP, TYPE)
23532 +
23533 +/* some systems define these in header files for non-ansi mode */
23534 +#undef const
23535 +#undef volatile
23536 +#undef signed
23537 +#undef inline
23538 +#define const
23539 +#define volatile
23540 +#define signed
23541 +#define inline
23542 +
23543 +#ifndef IN_GCC
23544 +#define CONST
23545 +#define VOLATILE
23546 +#define SIGNED
23547 +
23548 +#define PROTO(type, name, arglist)     type name ()
23549 +#define EXFUN(name, proto)             name()
23550 +#define DEFUN(name, arglist, args)     name arglist args;
23551 +#define DEFUN_VOID(name)               name()
23552 +#define AND            ;
23553 +#define DOTS
23554 +#define NOARGS
23555 +#endif /* ! IN_GCC */
23556 +
23557 +#endif /* ANSI C.  */
23558 +
23559 +/* Define macros for some gcc attributes.  This permits us to use the
23560 +   macros freely, and know that they will come into play for the
23561 +   version of gcc in which they are supported.  */
23562 +
23563 +#if (GCC_VERSION < 2007)
23564 +# define __attribute__(x)
23565 +#endif
23566 +
23567 +/* Attribute __malloc__ on functions was valid as of gcc 2.96. */
23568 +#ifndef ATTRIBUTE_MALLOC
23569 +# if (GCC_VERSION >= 2096)
23570 +#  define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
23571 +# else
23572 +#  define ATTRIBUTE_MALLOC
23573 +# endif /* GNUC >= 2.96 */
23574 +#endif /* ATTRIBUTE_MALLOC */
23575 +
23576 +/* Attributes on labels were valid as of gcc 2.93. */
23577 +#ifndef ATTRIBUTE_UNUSED_LABEL
23578 +# if (!defined (__cplusplus) && GCC_VERSION >= 2093)
23579 +#  define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
23580 +# else
23581 +#  define ATTRIBUTE_UNUSED_LABEL
23582 +# endif /* !__cplusplus && GNUC >= 2.93 */
23583 +#endif /* ATTRIBUTE_UNUSED_LABEL */
23584 +
23585 +#ifndef ATTRIBUTE_UNUSED
23586 +#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
23587 +#endif /* ATTRIBUTE_UNUSED */
23588 +
23589 +/* Before GCC 3.4, the C++ frontend couldn't parse attributes placed after the
23590 +   identifier name.  */
23591 +#if ! defined(__cplusplus) || (GCC_VERSION >= 3004)
23592 +# define ARG_UNUSED(NAME) NAME ATTRIBUTE_UNUSED
23593 +#else /* !__cplusplus || GNUC >= 3.4 */
23594 +# define ARG_UNUSED(NAME) NAME
23595 +#endif /* !__cplusplus || GNUC >= 3.4 */
23596 +
23597 +#ifndef ATTRIBUTE_NORETURN
23598 +#define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
23599 +#endif /* ATTRIBUTE_NORETURN */
23600 +
23601 +/* Attribute `nonnull' was valid as of gcc 3.3.  */
23602 +#ifndef ATTRIBUTE_NONNULL
23603 +# if (GCC_VERSION >= 3003)
23604 +#  define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
23605 +# else
23606 +#  define ATTRIBUTE_NONNULL(m)
23607 +# endif /* GNUC >= 3.3 */
23608 +#endif /* ATTRIBUTE_NONNULL */
23609 +
23610 +/* Attribute `pure' was valid as of gcc 3.0.  */
23611 +#ifndef ATTRIBUTE_PURE
23612 +# if (GCC_VERSION >= 3000)
23613 +#  define ATTRIBUTE_PURE __attribute__ ((__pure__))
23614 +# else
23615 +#  define ATTRIBUTE_PURE
23616 +# endif /* GNUC >= 3.0 */
23617 +#endif /* ATTRIBUTE_PURE */
23618 +
23619 +/* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL.
23620 +   This was the case for the `printf' format attribute by itself
23621 +   before GCC 3.3, but as of 3.3 we need to add the `nonnull'
23622 +   attribute to retain this behavior.  */
23623 +#ifndef ATTRIBUTE_PRINTF
23624 +#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m)
23625 +#define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
23626 +#define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
23627 +#define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
23628 +#define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5)
23629 +#define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
23630 +#endif /* ATTRIBUTE_PRINTF */
23631 +
23632 +/* Use ATTRIBUTE_FPTR_PRINTF when the format attribute is to be set on
23633 +   a function pointer.  Format attributes were allowed on function
23634 +   pointers as of gcc 3.1.  */
23635 +#ifndef ATTRIBUTE_FPTR_PRINTF
23636 +# if (GCC_VERSION >= 3001)
23637 +#  define ATTRIBUTE_FPTR_PRINTF(m, n) ATTRIBUTE_PRINTF(m, n)
23638 +# else
23639 +#  define ATTRIBUTE_FPTR_PRINTF(m, n)
23640 +# endif /* GNUC >= 3.1 */
23641 +# define ATTRIBUTE_FPTR_PRINTF_1 ATTRIBUTE_FPTR_PRINTF(1, 2)
23642 +# define ATTRIBUTE_FPTR_PRINTF_2 ATTRIBUTE_FPTR_PRINTF(2, 3)
23643 +# define ATTRIBUTE_FPTR_PRINTF_3 ATTRIBUTE_FPTR_PRINTF(3, 4)
23644 +# define ATTRIBUTE_FPTR_PRINTF_4 ATTRIBUTE_FPTR_PRINTF(4, 5)
23645 +# define ATTRIBUTE_FPTR_PRINTF_5 ATTRIBUTE_FPTR_PRINTF(5, 6)
23646 +#endif /* ATTRIBUTE_FPTR_PRINTF */
23647 +
23648 +/* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL.  A
23649 +   NULL format specifier was allowed as of gcc 3.3.  */
23650 +#ifndef ATTRIBUTE_NULL_PRINTF
23651 +# if (GCC_VERSION >= 3003)
23652 +#  define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
23653 +# else
23654 +#  define ATTRIBUTE_NULL_PRINTF(m, n)
23655 +# endif /* GNUC >= 3.3 */
23656 +# define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2)
23657 +# define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3)
23658 +# define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4)
23659 +# define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5)
23660 +# define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6)
23661 +#endif /* ATTRIBUTE_NULL_PRINTF */
23662 +
23663 +/* Attribute `sentinel' was valid as of gcc 3.5.  */
23664 +#ifndef ATTRIBUTE_SENTINEL
23665 +# if (GCC_VERSION >= 3005)
23666 +#  define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
23667 +# else
23668 +#  define ATTRIBUTE_SENTINEL
23669 +# endif /* GNUC >= 3.5 */
23670 +#endif /* ATTRIBUTE_SENTINEL */
23671 +
23672 +
23673 +#ifndef ATTRIBUTE_ALIGNED_ALIGNOF
23674 +# if (GCC_VERSION >= 3000)
23675 +#  define ATTRIBUTE_ALIGNED_ALIGNOF(m) __attribute__ ((__aligned__ (__alignof__ (m))))
23676 +# else
23677 +#  define ATTRIBUTE_ALIGNED_ALIGNOF(m)
23678 +# endif /* GNUC >= 3.0 */
23679 +#endif /* ATTRIBUTE_ALIGNED_ALIGNOF */
23680 +
23681 +/* We use __extension__ in some places to suppress -pedantic warnings
23682 +   about GCC extensions.  This feature didn't work properly before
23683 +   gcc 2.8.  */
23684 +#if GCC_VERSION < 2008
23685 +#define __extension__
23686 +#endif
23687 +
23688 +#endif /* ansidecl.h   */
23689 diff -Nurp linux-2.6.22-590/include/asm-i386/bfd.h linux-2.6.22-600/include/asm-i386/bfd.h
23690 --- linux-2.6.22-590/include/asm-i386/bfd.h     1970-01-01 01:00:00.000000000 +0100
23691 +++ linux-2.6.22-600/include/asm-i386/bfd.h     2008-04-09 18:16:14.000000000 +0200
23692 @@ -0,0 +1,4921 @@
23693 +/* DO NOT EDIT!  -*- buffer-read-only: t -*-  This file is automatically
23694 +   generated from "bfd-in.h", "init.c", "opncls.c", "libbfd.c",
23695 +   "bfdio.c", "bfdwin.c", "section.c", "archures.c", "reloc.c",
23696 +   "syms.c", "bfd.c", "archive.c", "corefile.c", "targets.c", "format.c",
23697 +   "linker.c" and "simple.c".
23698 +   Run "make headers" in your build bfd/ to regenerate.  */
23699 +
23700 +/* Main header file for the bfd library -- portable access to object files.
23701 +
23702 +   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
23703 +   1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
23704 +
23705 +   Contributed by Cygnus Support.
23706 +
23707 +   This file is part of BFD, the Binary File Descriptor library.
23708 +
23709 +   This program is free software; you can redistribute it and/or modify
23710 +   it under the terms of the GNU General Public License as published by
23711 +   the Free Software Foundation; either version 2 of the License, or
23712 +   (at your option) any later version.
23713 +
23714 +   This program is distributed in the hope that it will be useful,
23715 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
23716 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23717 +   GNU General Public License for more details.
23718 +
23719 +   You should have received a copy of the GNU General Public License
23720 +   along with this program; if not, write to the Free Software
23721 +   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
23722 +
23723 +/* Extracted from binutils 2.16.91.0.2 (OpenSUSE 10.0) and modified for kdb use.
23724 + * Any trailing whitespace was removed and #ifdef/ifndef __KERNEL__ added as
23725 + * required.
23726 + * Keith Owens <kaos@sgi.com> 15 May 2006
23727 + */
23728 +
23729 +#ifndef __BFD_H_SEEN__
23730 +#define __BFD_H_SEEN__
23731 +
23732 +#ifdef __cplusplus
23733 +extern "C" {
23734 +#endif
23735 +
23736 +#ifdef __KERNEL__
23737 +#include <asm/ansidecl.h>
23738 +#else  /* __KERNEL__ */
23739 +#include "ansidecl.h"
23740 +#include "symcat.h"
23741 +#endif /* __KERNEL__ */
23742 +#if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
23743 +#ifndef SABER
23744 +/* This hack is to avoid a problem with some strict ANSI C preprocessors.
23745 +   The problem is, "32_" is not a valid preprocessing token, and we don't
23746 +   want extra underscores (e.g., "nlm_32_").  The XCONCAT2 macro will
23747 +   cause the inner CONCAT2 macros to be evaluated first, producing
23748 +   still-valid pp-tokens.  Then the final concatenation can be done.  */
23749 +#undef CONCAT4
23750 +#define CONCAT4(a,b,c,d) XCONCAT2(CONCAT2(a,b),CONCAT2(c,d))
23751 +#endif
23752 +#endif
23753 +
23754 +/* The word size used by BFD on the host.  This may be 64 with a 32
23755 +   bit target if the host is 64 bit, or if other 64 bit targets have
23756 +   been selected with --enable-targets, or if --enable-64-bit-bfd.  */
23757 +#ifdef __KERNEL__
23758 +#define BFD_ARCH_SIZE 32
23759 +#else  /* __KERNEL__ */
23760 +#define BFD_ARCH_SIZE 64
23761 +#endif /* __KERNEL__ */
23762 +
23763 +/* The word size of the default bfd target.  */
23764 +#define BFD_DEFAULT_TARGET_SIZE 32
23765 +
23766 +#define BFD_HOST_64BIT_LONG 0
23767 +#define BFD_HOST_LONG_LONG 1
23768 +#if 1
23769 +#define BFD_HOST_64_BIT long long
23770 +#define BFD_HOST_U_64_BIT unsigned long long
23771 +typedef BFD_HOST_64_BIT bfd_int64_t;
23772 +typedef BFD_HOST_U_64_BIT bfd_uint64_t;
23773 +#endif
23774 +
23775 +#if BFD_ARCH_SIZE >= 64
23776 +#define BFD64
23777 +#endif
23778 +
23779 +#ifndef INLINE
23780 +#if __GNUC__ >= 2
23781 +#define INLINE __inline__
23782 +#else
23783 +#define INLINE
23784 +#endif
23785 +#endif
23786 +
23787 +/* Forward declaration.  */
23788 +typedef struct bfd bfd;
23789 +
23790 +/* Boolean type used in bfd.  Too many systems define their own
23791 +   versions of "boolean" for us to safely typedef a "boolean" of
23792 +   our own.  Using an enum for "bfd_boolean" has its own set of
23793 +   problems, with strange looking casts required to avoid warnings
23794 +   on some older compilers.  Thus we just use an int.
23795 +
23796 +   General rule: Functions which are bfd_boolean return TRUE on
23797 +   success and FALSE on failure (unless they're a predicate).  */
23798 +
23799 +typedef int bfd_boolean;
23800 +#undef FALSE
23801 +#undef TRUE
23802 +#define FALSE 0
23803 +#define TRUE 1
23804 +
23805 +#ifdef BFD64
23806 +
23807 +#ifndef BFD_HOST_64_BIT
23808 + #error No 64 bit integer type available
23809 +#endif /* ! defined (BFD_HOST_64_BIT) */
23810 +
23811 +typedef BFD_HOST_U_64_BIT bfd_vma;
23812 +typedef BFD_HOST_64_BIT bfd_signed_vma;
23813 +typedef BFD_HOST_U_64_BIT bfd_size_type;
23814 +typedef BFD_HOST_U_64_BIT symvalue;
23815 +
23816 +#ifndef fprintf_vma
23817 +#if BFD_HOST_64BIT_LONG
23818 +#define sprintf_vma(s,x) sprintf (s, "%016lx", x)
23819 +#define fprintf_vma(f,x) fprintf (f, "%016lx", x)
23820 +#else
23821 +#define _bfd_int64_low(x) ((unsigned long) (((x) & 0xffffffff)))
23822 +#define _bfd_int64_high(x) ((unsigned long) (((x) >> 32) & 0xffffffff))
23823 +#define fprintf_vma(s,x) \
23824 +  fprintf ((s), "%08lx%08lx", _bfd_int64_high (x), _bfd_int64_low (x))
23825 +#define sprintf_vma(s,x) \
23826 +  sprintf ((s), "%08lx%08lx", _bfd_int64_high (x), _bfd_int64_low (x))
23827 +#endif
23828 +#endif
23829 +
23830 +#else /* not BFD64  */
23831 +
23832 +/* Represent a target address.  Also used as a generic unsigned type
23833 +   which is guaranteed to be big enough to hold any arithmetic types
23834 +   we need to deal with.  */
23835 +typedef unsigned long bfd_vma;
23836 +
23837 +/* A generic signed type which is guaranteed to be big enough to hold any
23838 +   arithmetic types we need to deal with.  Can be assumed to be compatible
23839 +   with bfd_vma in the same way that signed and unsigned ints are compatible
23840 +   (as parameters, in assignment, etc).  */
23841 +typedef long bfd_signed_vma;
23842 +
23843 +typedef unsigned long symvalue;
23844 +typedef unsigned long bfd_size_type;
23845 +
23846 +/* Print a bfd_vma x on stream s.  */
23847 +#define fprintf_vma(s,x) fprintf (s, "%08lx", x)
23848 +#define sprintf_vma(s,x) sprintf (s, "%08lx", x)
23849 +
23850 +#endif /* not BFD64  */
23851 +
23852 +#define HALF_BFD_SIZE_TYPE \
23853 +  (((bfd_size_type) 1) << (8 * sizeof (bfd_size_type) / 2))
23854 +
23855 +#ifndef BFD_HOST_64_BIT
23856 +/* Fall back on a 32 bit type.  The idea is to make these types always
23857 +   available for function return types, but in the case that
23858 +   BFD_HOST_64_BIT is undefined such a function should abort or
23859 +   otherwise signal an error.  */
23860 +typedef bfd_signed_vma bfd_int64_t;
23861 +typedef bfd_vma bfd_uint64_t;
23862 +#endif
23863 +
23864 +/* An offset into a file.  BFD always uses the largest possible offset
23865 +   based on the build time availability of fseek, fseeko, or fseeko64.  */
23866 +typedef BFD_HOST_64_BIT file_ptr;
23867 +typedef unsigned BFD_HOST_64_BIT ufile_ptr;
23868 +
23869 +extern void bfd_sprintf_vma (bfd *, char *, bfd_vma);
23870 +extern void bfd_fprintf_vma (bfd *, void *, bfd_vma);
23871 +
23872 +#define printf_vma(x) fprintf_vma(stdout,x)
23873 +#define bfd_printf_vma(abfd,x) bfd_fprintf_vma (abfd,stdout,x)
23874 +
23875 +typedef unsigned int flagword; /* 32 bits of flags */
23876 +typedef unsigned char bfd_byte;
23877 +\f
23878 +/* File formats.  */
23879 +
23880 +typedef enum bfd_format
23881 +{
23882 +  bfd_unknown = 0,     /* File format is unknown.  */
23883 +  bfd_object,          /* Linker/assembler/compiler output.  */
23884 +  bfd_archive,         /* Object archive file.  */
23885 +  bfd_core,            /* Core dump.  */
23886 +  bfd_type_end         /* Marks the end; don't use it!  */
23887 +}
23888 +bfd_format;
23889 +
23890 +/* Values that may appear in the flags field of a BFD.  These also
23891 +   appear in the object_flags field of the bfd_target structure, where
23892 +   they indicate the set of flags used by that backend (not all flags
23893 +   are meaningful for all object file formats) (FIXME: at the moment,
23894 +   the object_flags values have mostly just been copied from backend
23895 +   to another, and are not necessarily correct).  */
23896 +
23897 +/* No flags.  */
23898 +#define BFD_NO_FLAGS           0x00
23899 +
23900 +/* BFD contains relocation entries.  */
23901 +#define HAS_RELOC      0x01
23902 +
23903 +/* BFD is directly executable.  */
23904 +#define EXEC_P         0x02
23905 +
23906 +/* BFD has line number information (basically used for F_LNNO in a
23907 +   COFF header).  */
23908 +#define HAS_LINENO     0x04
23909 +
23910 +/* BFD has debugging information.  */
23911 +#define HAS_DEBUG      0x08
23912 +
23913 +/* BFD has symbols.  */
23914 +#define HAS_SYMS       0x10
23915 +
23916 +/* BFD has local symbols (basically used for F_LSYMS in a COFF
23917 +   header).  */
23918 +#define HAS_LOCALS     0x20
23919 +
23920 +/* BFD is a dynamic object.  */
23921 +#define DYNAMIC        0x40
23922 +
23923 +/* Text section is write protected (if D_PAGED is not set, this is
23924 +   like an a.out NMAGIC file) (the linker sets this by default, but
23925 +   clears it for -r or -N).  */
23926 +#define WP_TEXT        0x80
23927 +
23928 +/* BFD is dynamically paged (this is like an a.out ZMAGIC file) (the
23929 +   linker sets this by default, but clears it for -r or -n or -N).  */
23930 +#define D_PAGED        0x100
23931 +
23932 +/* BFD is relaxable (this means that bfd_relax_section may be able to
23933 +   do something) (sometimes bfd_relax_section can do something even if
23934 +   this is not set).  */
23935 +#define BFD_IS_RELAXABLE 0x200
23936 +
23937 +/* This may be set before writing out a BFD to request using a
23938 +   traditional format.  For example, this is used to request that when
23939 +   writing out an a.out object the symbols not be hashed to eliminate
23940 +   duplicates.  */
23941 +#define BFD_TRADITIONAL_FORMAT 0x400
23942 +
23943 +/* This flag indicates that the BFD contents are actually cached in
23944 +   memory.  If this is set, iostream points to a bfd_in_memory struct.  */
23945 +#define BFD_IN_MEMORY 0x800
23946 +
23947 +/* The sections in this BFD specify a memory page.  */
23948 +#define HAS_LOAD_PAGE 0x1000
23949 +
23950 +/* This BFD has been created by the linker and doesn't correspond
23951 +   to any input file.  */
23952 +#define BFD_LINKER_CREATED 0x2000
23953 +\f
23954 +/* Symbols and relocation.  */
23955 +
23956 +/* A count of carsyms (canonical archive symbols).  */
23957 +typedef unsigned long symindex;
23958 +
23959 +/* How to perform a relocation.  */
23960 +typedef const struct reloc_howto_struct reloc_howto_type;
23961 +
23962 +#define BFD_NO_MORE_SYMBOLS ((symindex) ~0)
23963 +
23964 +/* General purpose part of a symbol X;
23965 +   target specific parts are in libcoff.h, libaout.h, etc.  */
23966 +
23967 +#define bfd_get_section(x) ((x)->section)
23968 +#define bfd_get_output_section(x) ((x)->section->output_section)
23969 +#define bfd_set_section(x,y) ((x)->section) = (y)
23970 +#define bfd_asymbol_base(x) ((x)->section->vma)
23971 +#define bfd_asymbol_value(x) (bfd_asymbol_base(x) + (x)->value)
23972 +#define bfd_asymbol_name(x) ((x)->name)
23973 +/*Perhaps future: #define bfd_asymbol_bfd(x) ((x)->section->owner)*/
23974 +#define bfd_asymbol_bfd(x) ((x)->the_bfd)
23975 +#define bfd_asymbol_flavour(x) (bfd_asymbol_bfd(x)->xvec->flavour)
23976 +
23977 +/* A canonical archive symbol.  */
23978 +/* This is a type pun with struct ranlib on purpose!  */
23979 +typedef struct carsym
23980 +{
23981 +  char *name;
23982 +  file_ptr file_offset;        /* Look here to find the file.  */
23983 +}
23984 +carsym;                        /* To make these you call a carsymogen.  */
23985 +
23986 +/* Used in generating armaps (archive tables of contents).
23987 +   Perhaps just a forward definition would do?  */
23988 +struct orl                     /* Output ranlib.  */
23989 +{
23990 +  char **name;         /* Symbol name.  */
23991 +  union
23992 +  {
23993 +    file_ptr pos;
23994 +    bfd *abfd;
23995 +  } u;                 /* bfd* or file position.  */
23996 +  int namidx;          /* Index into string table.  */
23997 +};
23998 +\f
23999 +/* Linenumber stuff.  */
24000 +typedef struct lineno_cache_entry
24001 +{
24002 +  unsigned int line_number;    /* Linenumber from start of function.  */
24003 +  union
24004 +  {
24005 +    struct bfd_symbol *sym;    /* Function name.  */
24006 +    bfd_vma offset;                    /* Offset into section.  */
24007 +  } u;
24008 +}
24009 +alent;
24010 +\f
24011 +/* Object and core file sections.  */
24012 +
24013 +#define        align_power(addr, align)        \
24014 +  (((addr) + ((bfd_vma) 1 << (align)) - 1) & ((bfd_vma) -1 << (align)))
24015 +
24016 +typedef struct bfd_section *sec_ptr;
24017 +
24018 +#define bfd_get_section_name(bfd, ptr) ((ptr)->name + 0)
24019 +#define bfd_get_section_vma(bfd, ptr) ((ptr)->vma + 0)
24020 +#define bfd_get_section_lma(bfd, ptr) ((ptr)->lma + 0)
24021 +#define bfd_get_section_alignment(bfd, ptr) ((ptr)->alignment_power + 0)
24022 +#define bfd_section_name(bfd, ptr) ((ptr)->name)
24023 +#define bfd_section_size(bfd, ptr) ((ptr)->size)
24024 +#define bfd_get_section_size(ptr) ((ptr)->size)
24025 +#define bfd_section_vma(bfd, ptr) ((ptr)->vma)
24026 +#define bfd_section_lma(bfd, ptr) ((ptr)->lma)
24027 +#define bfd_section_alignment(bfd, ptr) ((ptr)->alignment_power)
24028 +#define bfd_get_section_flags(bfd, ptr) ((ptr)->flags + 0)
24029 +#define bfd_get_section_userdata(bfd, ptr) ((ptr)->userdata)
24030 +
24031 +#define bfd_is_com_section(ptr) (((ptr)->flags & SEC_IS_COMMON) != 0)
24032 +
24033 +#define bfd_set_section_vma(bfd, ptr, val) (((ptr)->vma = (ptr)->lma = (val)), ((ptr)->user_set_vma = TRUE), TRUE)
24034 +#define bfd_set_section_alignment(bfd, ptr, val) (((ptr)->alignment_power = (val)),TRUE)
24035 +#define bfd_set_section_userdata(bfd, ptr, val) (((ptr)->userdata = (val)),TRUE)
24036 +/* Find the address one past the end of SEC.  */
24037 +#define bfd_get_section_limit(bfd, sec) \
24038 +  (((sec)->rawsize ? (sec)->rawsize : (sec)->size) \
24039 +   / bfd_octets_per_byte (bfd))
24040 +
24041 +typedef struct stat stat_type;
24042 +\f
24043 +typedef enum bfd_print_symbol
24044 +{
24045 +  bfd_print_symbol_name,
24046 +  bfd_print_symbol_more,
24047 +  bfd_print_symbol_all
24048 +} bfd_print_symbol_type;
24049 +
24050 +/* Information about a symbol that nm needs.  */
24051 +
24052 +typedef struct _symbol_info
24053 +{
24054 +  symvalue value;
24055 +  char type;
24056 +  const char *name;            /* Symbol name.  */
24057 +  unsigned char stab_type;     /* Stab type.  */
24058 +  char stab_other;             /* Stab other.  */
24059 +  short stab_desc;             /* Stab desc.  */
24060 +  const char *stab_name;       /* String for stab type.  */
24061 +} symbol_info;
24062 +
24063 +/* Get the name of a stabs type code.  */
24064 +
24065 +extern const char *bfd_get_stab_name (int);
24066 +\f
24067 +/* Hash table routines.  There is no way to free up a hash table.  */
24068 +
24069 +/* An element in the hash table.  Most uses will actually use a larger
24070 +   structure, and an instance of this will be the first field.  */
24071 +
24072 +struct bfd_hash_entry
24073 +{
24074 +  /* Next entry for this hash code.  */
24075 +  struct bfd_hash_entry *next;
24076 +  /* String being hashed.  */
24077 +  const char *string;
24078 +  /* Hash code.  This is the full hash code, not the index into the
24079 +     table.  */
24080 +  unsigned long hash;
24081 +};
24082 +
24083 +/* A hash table.  */
24084 +
24085 +struct bfd_hash_table
24086 +{
24087 +  /* The hash array.  */
24088 +  struct bfd_hash_entry **table;
24089 +  /* The number of slots in the hash table.  */
24090 +  unsigned int size;
24091 +  /* A function used to create new elements in the hash table.  The
24092 +     first entry is itself a pointer to an element.  When this
24093 +     function is first invoked, this pointer will be NULL.  However,
24094 +     having the pointer permits a hierarchy of method functions to be
24095 +     built each of which calls the function in the superclass.  Thus
24096 +     each function should be written to allocate a new block of memory
24097 +     only if the argument is NULL.  */
24098 +  struct bfd_hash_entry *(*newfunc)
24099 +    (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
24100 +   /* An objalloc for this hash table.  This is a struct objalloc *,
24101 +     but we use void * to avoid requiring the inclusion of objalloc.h.  */
24102 +  void *memory;
24103 +};
24104 +
24105 +/* Initialize a hash table.  */
24106 +extern bfd_boolean bfd_hash_table_init
24107 +  (struct bfd_hash_table *,
24108 +   struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
24109 +                              struct bfd_hash_table *,
24110 +                              const char *));
24111 +
24112 +/* Initialize a hash table specifying a size.  */
24113 +extern bfd_boolean bfd_hash_table_init_n
24114 +  (struct bfd_hash_table *,
24115 +   struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
24116 +                              struct bfd_hash_table *,
24117 +                              const char *),
24118 +   unsigned int size);
24119 +
24120 +/* Free up a hash table.  */
24121 +extern void bfd_hash_table_free
24122 +  (struct bfd_hash_table *);
24123 +
24124 +/* Look up a string in a hash table.  If CREATE is TRUE, a new entry
24125 +   will be created for this string if one does not already exist.  The
24126 +   COPY argument must be TRUE if this routine should copy the string
24127 +   into newly allocated memory when adding an entry.  */
24128 +extern struct bfd_hash_entry *bfd_hash_lookup
24129 +  (struct bfd_hash_table *, const char *, bfd_boolean create,
24130 +   bfd_boolean copy);
24131 +
24132 +/* Replace an entry in a hash table.  */
24133 +extern void bfd_hash_replace
24134 +  (struct bfd_hash_table *, struct bfd_hash_entry *old,
24135 +   struct bfd_hash_entry *nw);
24136 +
24137 +/* Base method for creating a hash table entry.  */
24138 +extern struct bfd_hash_entry *bfd_hash_newfunc
24139 +  (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
24140 +
24141 +/* Grab some space for a hash table entry.  */
24142 +extern void *bfd_hash_allocate
24143 +  (struct bfd_hash_table *, unsigned int);
24144 +
24145 +/* Traverse a hash table in a random order, calling a function on each
24146 +   element.  If the function returns FALSE, the traversal stops.  The
24147 +   INFO argument is passed to the function.  */
24148 +extern void bfd_hash_traverse
24149 +  (struct bfd_hash_table *,
24150 +   bfd_boolean (*) (struct bfd_hash_entry *, void *),
24151 +   void *info);
24152 +
24153 +/* Allows the default size of a hash table to be configured. New hash
24154 +   tables allocated using bfd_hash_table_init will be created with
24155 +   this size.  */
24156 +extern void bfd_hash_set_default_size (bfd_size_type);
24157 +
24158 +/* This structure is used to keep track of stabs in sections
24159 +   information while linking.  */
24160 +
24161 +struct stab_info
24162 +{
24163 +  /* A hash table used to hold stabs strings.  */
24164 +  struct bfd_strtab_hash *strings;
24165 +  /* The header file hash table.  */
24166 +  struct bfd_hash_table includes;
24167 +  /* The first .stabstr section.  */
24168 +  struct bfd_section *stabstr;
24169 +};
24170 +
24171 +#define COFF_SWAP_TABLE (void *) &bfd_coff_std_swap_table
24172 +
24173 +/* User program access to BFD facilities.  */
24174 +
24175 +/* Direct I/O routines, for programs which know more about the object
24176 +   file than BFD does.  Use higher level routines if possible.  */
24177 +
24178 +extern bfd_size_type bfd_bread (void *, bfd_size_type, bfd *);
24179 +extern bfd_size_type bfd_bwrite (const void *, bfd_size_type, bfd *);
24180 +extern int bfd_seek (bfd *, file_ptr, int);
24181 +extern file_ptr bfd_tell (bfd *);
24182 +extern int bfd_flush (bfd *);
24183 +extern int bfd_stat (bfd *, struct stat *);
24184 +
24185 +/* Deprecated old routines.  */
24186 +#if __GNUC__
24187 +#define bfd_read(BUF, ELTSIZE, NITEMS, ABFD)                           \
24188 +  (warn_deprecated ("bfd_read", __FILE__, __LINE__, __FUNCTION__),     \
24189 +   bfd_bread ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
24190 +#define bfd_write(BUF, ELTSIZE, NITEMS, ABFD)                          \
24191 +  (warn_deprecated ("bfd_write", __FILE__, __LINE__, __FUNCTION__),    \
24192 +   bfd_bwrite ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
24193 +#else
24194 +#define bfd_read(BUF, ELTSIZE, NITEMS, ABFD)                           \
24195 +  (warn_deprecated ("bfd_read", (const char *) 0, 0, (const char *) 0), \
24196 +   bfd_bread ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
24197 +#define bfd_write(BUF, ELTSIZE, NITEMS, ABFD)                          \
24198 +  (warn_deprecated ("bfd_write", (const char *) 0, 0, (const char *) 0),\
24199 +   bfd_bwrite ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
24200 +#endif
24201 +extern void warn_deprecated (const char *, const char *, int, const char *);
24202 +
24203 +/* Cast from const char * to char * so that caller can assign to
24204 +   a char * without a warning.  */
24205 +#define bfd_get_filename(abfd) ((char *) (abfd)->filename)
24206 +#define bfd_get_cacheable(abfd) ((abfd)->cacheable)
24207 +#define bfd_get_format(abfd) ((abfd)->format)
24208 +#define bfd_get_target(abfd) ((abfd)->xvec->name)
24209 +#define bfd_get_flavour(abfd) ((abfd)->xvec->flavour)
24210 +#define bfd_family_coff(abfd) \
24211 +  (bfd_get_flavour (abfd) == bfd_target_coff_flavour || \
24212 +   bfd_get_flavour (abfd) == bfd_target_xcoff_flavour)
24213 +#define bfd_big_endian(abfd) ((abfd)->xvec->byteorder == BFD_ENDIAN_BIG)
24214 +#define bfd_little_endian(abfd) ((abfd)->xvec->byteorder == BFD_ENDIAN_LITTLE)
24215 +#define bfd_header_big_endian(abfd) \
24216 +  ((abfd)->xvec->header_byteorder == BFD_ENDIAN_BIG)
24217 +#define bfd_header_little_endian(abfd) \
24218 +  ((abfd)->xvec->header_byteorder == BFD_ENDIAN_LITTLE)
24219 +#define bfd_get_file_flags(abfd) ((abfd)->flags)
24220 +#define bfd_applicable_file_flags(abfd) ((abfd)->xvec->object_flags)
24221 +#define bfd_applicable_section_flags(abfd) ((abfd)->xvec->section_flags)
24222 +#define bfd_my_archive(abfd) ((abfd)->my_archive)
24223 +#define bfd_has_map(abfd) ((abfd)->has_armap)
24224 +
24225 +#define bfd_valid_reloc_types(abfd) ((abfd)->xvec->valid_reloc_types)
24226 +#define bfd_usrdata(abfd) ((abfd)->usrdata)
24227 +
24228 +#define bfd_get_start_address(abfd) ((abfd)->start_address)
24229 +#define bfd_get_symcount(abfd) ((abfd)->symcount)
24230 +#define bfd_get_outsymbols(abfd) ((abfd)->outsymbols)
24231 +#define bfd_count_sections(abfd) ((abfd)->section_count)
24232 +
24233 +#define bfd_get_dynamic_symcount(abfd) ((abfd)->dynsymcount)
24234 +
24235 +#define bfd_get_symbol_leading_char(abfd) ((abfd)->xvec->symbol_leading_char)
24236 +
24237 +#define bfd_set_cacheable(abfd,bool) (((abfd)->cacheable = bool), TRUE)
24238 +
24239 +extern bfd_boolean bfd_cache_close
24240 +  (bfd *abfd);
24241 +/* NB: This declaration should match the autogenerated one in libbfd.h.  */
24242 +
24243 +extern bfd_boolean bfd_cache_close_all (void);
24244 +
24245 +extern bfd_boolean bfd_record_phdr
24246 +  (bfd *, unsigned long, bfd_boolean, flagword, bfd_boolean, bfd_vma,
24247 +   bfd_boolean, bfd_boolean, unsigned int, struct bfd_section **);
24248 +
24249 +/* Byte swapping routines.  */
24250 +
24251 +bfd_uint64_t bfd_getb64 (const void *);
24252 +bfd_uint64_t bfd_getl64 (const void *);
24253 +bfd_int64_t bfd_getb_signed_64 (const void *);
24254 +bfd_int64_t bfd_getl_signed_64 (const void *);
24255 +bfd_vma bfd_getb32 (const void *);
24256 +bfd_vma bfd_getl32 (const void *);
24257 +bfd_signed_vma bfd_getb_signed_32 (const void *);
24258 +bfd_signed_vma bfd_getl_signed_32 (const void *);
24259 +bfd_vma bfd_getb16 (const void *);
24260 +bfd_vma bfd_getl16 (const void *);
24261 +bfd_signed_vma bfd_getb_signed_16 (const void *);
24262 +bfd_signed_vma bfd_getl_signed_16 (const void *);
24263 +void bfd_putb64 (bfd_uint64_t, void *);
24264 +void bfd_putl64 (bfd_uint64_t, void *);
24265 +void bfd_putb32 (bfd_vma, void *);
24266 +void bfd_putl32 (bfd_vma, void *);
24267 +void bfd_putb16 (bfd_vma, void *);
24268 +void bfd_putl16 (bfd_vma, void *);
24269 +
24270 +/* Byte swapping routines which take size and endiannes as arguments.  */
24271 +
24272 +bfd_uint64_t bfd_get_bits (const void *, int, bfd_boolean);
24273 +void bfd_put_bits (bfd_uint64_t, void *, int, bfd_boolean);
24274 +
24275 +extern bfd_boolean bfd_section_already_linked_table_init (void);
24276 +extern void bfd_section_already_linked_table_free (void);
24277 +\f
24278 +/* Externally visible ECOFF routines.  */
24279 +
24280 +#if defined(__STDC__) || defined(ALMOST_STDC)
24281 +struct ecoff_debug_info;
24282 +struct ecoff_debug_swap;
24283 +struct ecoff_extr;
24284 +struct bfd_symbol;
24285 +struct bfd_link_info;
24286 +struct bfd_link_hash_entry;
24287 +struct bfd_elf_version_tree;
24288 +#endif
24289 +extern bfd_vma bfd_ecoff_get_gp_value
24290 +  (bfd * abfd);
24291 +extern bfd_boolean bfd_ecoff_set_gp_value
24292 +  (bfd *abfd, bfd_vma gp_value);
24293 +extern bfd_boolean bfd_ecoff_set_regmasks
24294 +  (bfd *abfd, unsigned long gprmask, unsigned long fprmask,
24295 +   unsigned long *cprmask);
24296 +extern void *bfd_ecoff_debug_init
24297 +  (bfd *output_bfd, struct ecoff_debug_info *output_debug,
24298 +   const struct ecoff_debug_swap *output_swap, struct bfd_link_info *);
24299 +extern void bfd_ecoff_debug_free
24300 +  (void *handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
24301 +   const struct ecoff_debug_swap *output_swap, struct bfd_link_info *);
24302 +extern bfd_boolean bfd_ecoff_debug_accumulate
24303 +  (void *handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
24304 +   const struct ecoff_debug_swap *output_swap, bfd *input_bfd,
24305 +   struct ecoff_debug_info *input_debug,
24306 +   const struct ecoff_debug_swap *input_swap, struct bfd_link_info *);
24307 +extern bfd_boolean bfd_ecoff_debug_accumulate_other
24308 +  (void *handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
24309 +   const struct ecoff_debug_swap *output_swap, bfd *input_bfd,
24310 +   struct bfd_link_info *);
24311 +extern bfd_boolean bfd_ecoff_debug_externals
24312 +  (bfd *abfd, struct ecoff_debug_info *debug,
24313 +   const struct ecoff_debug_swap *swap, bfd_boolean relocatable,
24314 +   bfd_boolean (*get_extr) (struct bfd_symbol *, struct ecoff_extr *),
24315 +   void (*set_index) (struct bfd_symbol *, bfd_size_type));
24316 +extern bfd_boolean bfd_ecoff_debug_one_external
24317 +  (bfd *abfd, struct ecoff_debug_info *debug,
24318 +   const struct ecoff_debug_swap *swap, const char *name,
24319 +   struct ecoff_extr *esym);
24320 +extern bfd_size_type bfd_ecoff_debug_size
24321 +  (bfd *abfd, struct ecoff_debug_info *debug,
24322 +   const struct ecoff_debug_swap *swap);
24323 +extern bfd_boolean bfd_ecoff_write_debug
24324 +  (bfd *abfd, struct ecoff_debug_info *debug,
24325 +   const struct ecoff_debug_swap *swap, file_ptr where);
24326 +extern bfd_boolean bfd_ecoff_write_accumulated_debug
24327 +  (void *handle, bfd *abfd, struct ecoff_debug_info *debug,
24328 +   const struct ecoff_debug_swap *swap,
24329 +   struct bfd_link_info *info, file_ptr where);
24330 +
24331 +/* Externally visible ELF routines.  */
24332 +
24333 +struct bfd_link_needed_list
24334 +{
24335 +  struct bfd_link_needed_list *next;
24336 +  bfd *by;
24337 +  const char *name;
24338 +};
24339 +
24340 +enum dynamic_lib_link_class {
24341 +  DYN_NORMAL = 0,
24342 +  DYN_AS_NEEDED = 1,
24343 +  DYN_DT_NEEDED = 2,
24344 +  DYN_NO_ADD_NEEDED = 4,
24345 +  DYN_NO_NEEDED = 8
24346 +};
24347 +
24348 +extern bfd_boolean bfd_elf_record_link_assignment
24349 +  (struct bfd_link_info *, const char *, bfd_boolean);
24350 +extern struct bfd_link_needed_list *bfd_elf_get_needed_list
24351 +  (bfd *, struct bfd_link_info *);
24352 +extern bfd_boolean bfd_elf_get_bfd_needed_list
24353 +  (bfd *, struct bfd_link_needed_list **);
24354 +extern bfd_boolean bfd_elf_size_dynamic_sections
24355 +  (bfd *, const char *, const char *, const char *, const char * const *,
24356 +   struct bfd_link_info *, struct bfd_section **,
24357 +   struct bfd_elf_version_tree *);
24358 +extern bfd_boolean bfd_elf_size_dynsym_hash_dynstr
24359 +  (bfd *, struct bfd_link_info *);
24360 +extern void bfd_elf_set_dt_needed_name
24361 +  (bfd *, const char *);
24362 +extern const char *bfd_elf_get_dt_soname
24363 +  (bfd *);
24364 +extern void bfd_elf_set_dyn_lib_class
24365 +  (bfd *, int);
24366 +extern int bfd_elf_get_dyn_lib_class
24367 +  (bfd *);
24368 +extern struct bfd_link_needed_list *bfd_elf_get_runpath_list
24369 +  (bfd *, struct bfd_link_info *);
24370 +extern bfd_boolean bfd_elf_discard_info
24371 +  (bfd *, struct bfd_link_info *);
24372 +extern unsigned int _bfd_elf_default_action_discarded
24373 +  (struct bfd_section *);
24374 +
24375 +/* Return an upper bound on the number of bytes required to store a
24376 +   copy of ABFD's program header table entries.  Return -1 if an error
24377 +   occurs; bfd_get_error will return an appropriate code.  */
24378 +extern long bfd_get_elf_phdr_upper_bound
24379 +  (bfd *abfd);
24380 +
24381 +/* Copy ABFD's program header table entries to *PHDRS.  The entries
24382 +   will be stored as an array of Elf_Internal_Phdr structures, as
24383 +   defined in include/elf/internal.h.  To find out how large the
24384 +   buffer needs to be, call bfd_get_elf_phdr_upper_bound.
24385 +
24386 +   Return the number of program header table entries read, or -1 if an
24387 +   error occurs; bfd_get_error will return an appropriate code.  */
24388 +extern int bfd_get_elf_phdrs
24389 +  (bfd *abfd, void *phdrs);
24390 +
24391 +/* Create a new BFD as if by bfd_openr.  Rather than opening a file,
24392 +   reconstruct an ELF file by reading the segments out of remote memory
24393 +   based on the ELF file header at EHDR_VMA and the ELF program headers it
24394 +   points to.  If not null, *LOADBASEP is filled in with the difference
24395 +   between the VMAs from which the segments were read, and the VMAs the
24396 +   file headers (and hence BFD's idea of each section's VMA) put them at.
24397 +
24398 +   The function TARGET_READ_MEMORY is called to copy LEN bytes from the
24399 +   remote memory at target address VMA into the local buffer at MYADDR; it
24400 +   should return zero on success or an `errno' code on failure.  TEMPL must
24401 +   be a BFD for an ELF target with the word size and byte order found in
24402 +   the remote memory.  */
24403 +extern bfd *bfd_elf_bfd_from_remote_memory
24404 +  (bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep,
24405 +   int (*target_read_memory) (bfd_vma vma, bfd_byte *myaddr, int len));
24406 +
24407 +/* Return the arch_size field of an elf bfd, or -1 if not elf.  */
24408 +extern int bfd_get_arch_size
24409 +  (bfd *);
24410 +
24411 +/* Return TRUE if address "naturally" sign extends, or -1 if not elf.  */
24412 +extern int bfd_get_sign_extend_vma
24413 +  (bfd *);
24414 +
24415 +extern struct bfd_section *_bfd_elf_tls_setup
24416 +  (bfd *, struct bfd_link_info *);
24417 +
24418 +extern void _bfd_elf_provide_symbol
24419 +  (struct bfd_link_info *, const char *, bfd_vma, struct bfd_section *);
24420 +
24421 +extern void _bfd_elf_provide_section_bound_symbols
24422 +  (struct bfd_link_info *, struct bfd_section *, const char *, const char *);
24423 +
24424 +extern void _bfd_elf_fix_excluded_sec_syms
24425 +  (bfd *, struct bfd_link_info *);
24426 +
24427 +extern bfd_boolean bfd_m68k_elf32_create_embedded_relocs
24428 +  (bfd *, struct bfd_link_info *, struct bfd_section *, struct bfd_section *,
24429 +   char **);
24430 +
24431 +/* SunOS shared library support routines for the linker.  */
24432 +
24433 +extern struct bfd_link_needed_list *bfd_sunos_get_needed_list
24434 +  (bfd *, struct bfd_link_info *);
24435 +extern bfd_boolean bfd_sunos_record_link_assignment
24436 +  (bfd *, struct bfd_link_info *, const char *);
24437 +extern bfd_boolean bfd_sunos_size_dynamic_sections
24438 +  (bfd *, struct bfd_link_info *, struct bfd_section **,
24439 +   struct bfd_section **, struct bfd_section **);
24440 +
24441 +/* Linux shared library support routines for the linker.  */
24442 +
24443 +extern bfd_boolean bfd_i386linux_size_dynamic_sections
24444 +  (bfd *, struct bfd_link_info *);
24445 +extern bfd_boolean bfd_m68klinux_size_dynamic_sections
24446 +  (bfd *, struct bfd_link_info *);
24447 +extern bfd_boolean bfd_sparclinux_size_dynamic_sections
24448 +  (bfd *, struct bfd_link_info *);
24449 +
24450 +/* mmap hacks */
24451 +
24452 +struct _bfd_window_internal;
24453 +typedef struct _bfd_window_internal bfd_window_internal;
24454 +
24455 +typedef struct _bfd_window
24456 +{
24457 +  /* What the user asked for.  */
24458 +  void *data;
24459 +  bfd_size_type size;
24460 +  /* The actual window used by BFD.  Small user-requested read-only
24461 +     regions sharing a page may share a single window into the object
24462 +     file.  Read-write versions shouldn't until I've fixed things to
24463 +     keep track of which portions have been claimed by the
24464 +     application; don't want to give the same region back when the
24465 +     application wants two writable copies!  */
24466 +  struct _bfd_window_internal *i;
24467 +}
24468 +bfd_window;
24469 +
24470 +extern void bfd_init_window
24471 +  (bfd_window *);
24472 +extern void bfd_free_window
24473 +  (bfd_window *);
24474 +extern bfd_boolean bfd_get_file_window
24475 +  (bfd *, file_ptr, bfd_size_type, bfd_window *, bfd_boolean);
24476 +
24477 +/* XCOFF support routines for the linker.  */
24478 +
24479 +extern bfd_boolean bfd_xcoff_link_record_set
24480 +  (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *, bfd_size_type);
24481 +extern bfd_boolean bfd_xcoff_import_symbol
24482 +  (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *, bfd_vma,
24483 +   const char *, const char *, const char *, unsigned int);
24484 +extern bfd_boolean bfd_xcoff_export_symbol
24485 +  (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *);
24486 +extern bfd_boolean bfd_xcoff_link_count_reloc
24487 +  (bfd *, struct bfd_link_info *, const char *);
24488 +extern bfd_boolean bfd_xcoff_record_link_assignment
24489 +  (bfd *, struct bfd_link_info *, const char *);
24490 +extern bfd_boolean bfd_xcoff_size_dynamic_sections
24491 +  (bfd *, struct bfd_link_info *, const char *, const char *,
24492 +   unsigned long, unsigned long, unsigned long, bfd_boolean,
24493 +   int, bfd_boolean, bfd_boolean, struct bfd_section **, bfd_boolean);
24494 +extern bfd_boolean bfd_xcoff_link_generate_rtinit
24495 +  (bfd *, const char *, const char *, bfd_boolean);
24496 +
24497 +/* XCOFF support routines for ar.  */
24498 +extern bfd_boolean bfd_xcoff_ar_archive_set_magic
24499 +  (bfd *, char *);
24500 +
24501 +/* Externally visible COFF routines.  */
24502 +
24503 +#if defined(__STDC__) || defined(ALMOST_STDC)
24504 +struct internal_syment;
24505 +union internal_auxent;
24506 +#endif
24507 +
24508 +extern bfd_boolean bfd_coff_get_syment
24509 +  (bfd *, struct bfd_symbol *, struct internal_syment *);
24510 +
24511 +extern bfd_boolean bfd_coff_get_auxent
24512 +  (bfd *, struct bfd_symbol *, int, union internal_auxent *);
24513 +
24514 +extern bfd_boolean bfd_coff_set_symbol_class
24515 +  (bfd *, struct bfd_symbol *, unsigned int);
24516 +
24517 +extern bfd_boolean bfd_m68k_coff_create_embedded_relocs
24518 +  (bfd *, struct bfd_link_info *, struct bfd_section *, struct bfd_section *, char **);
24519 +
24520 +/* ARM Interworking support.  Called from linker.  */
24521 +extern bfd_boolean bfd_arm_allocate_interworking_sections
24522 +  (struct bfd_link_info *);
24523 +
24524 +extern bfd_boolean bfd_arm_process_before_allocation
24525 +  (bfd *, struct bfd_link_info *, int);
24526 +
24527 +extern bfd_boolean bfd_arm_get_bfd_for_interworking
24528 +  (bfd *, struct bfd_link_info *);
24529 +
24530 +/* PE ARM Interworking support.  Called from linker.  */
24531 +extern bfd_boolean bfd_arm_pe_allocate_interworking_sections
24532 +  (struct bfd_link_info *);
24533 +
24534 +extern bfd_boolean bfd_arm_pe_process_before_allocation
24535 +  (bfd *, struct bfd_link_info *, int);
24536 +
24537 +extern bfd_boolean bfd_arm_pe_get_bfd_for_interworking
24538 +  (bfd *, struct bfd_link_info *);
24539 +
24540 +/* ELF ARM Interworking support.  Called from linker.  */
24541 +extern bfd_boolean bfd_elf32_arm_allocate_interworking_sections
24542 +  (struct bfd_link_info *);
24543 +
24544 +extern bfd_boolean bfd_elf32_arm_process_before_allocation
24545 +  (bfd *, struct bfd_link_info *, int);
24546 +
24547 +void bfd_elf32_arm_set_target_relocs
24548 +  (struct bfd_link_info *, int, char *, int, int);
24549 +
24550 +extern bfd_boolean bfd_elf32_arm_get_bfd_for_interworking
24551 +  (bfd *, struct bfd_link_info *);
24552 +
24553 +extern bfd_boolean bfd_elf32_arm_add_glue_sections_to_bfd
24554 +  (bfd *, struct bfd_link_info *);
24555 +
24556 +/* ELF ARM mapping symbol support */
24557 +extern bfd_boolean bfd_is_arm_mapping_symbol_name
24558 +  (const char * name);
24559 +
24560 +/* ARM Note section processing.  */
24561 +extern bfd_boolean bfd_arm_merge_machines
24562 +  (bfd *, bfd *);
24563 +
24564 +extern bfd_boolean bfd_arm_update_notes
24565 +  (bfd *, const char *);
24566 +
24567 +extern unsigned int bfd_arm_get_mach_from_notes
24568 +  (bfd *, const char *);
24569 +
24570 +/* TI COFF load page support.  */
24571 +extern void bfd_ticoff_set_section_load_page
24572 +  (struct bfd_section *, int);
24573 +
24574 +extern int bfd_ticoff_get_section_load_page
24575 +  (struct bfd_section *);
24576 +
24577 +/* H8/300 functions.  */
24578 +extern bfd_vma bfd_h8300_pad_address
24579 +  (bfd *, bfd_vma);
24580 +
24581 +/* IA64 Itanium code generation.  Called from linker.  */
24582 +extern void bfd_elf32_ia64_after_parse
24583 +  (int);
24584 +
24585 +extern void bfd_elf64_ia64_after_parse
24586 +  (int);
24587 +
24588 +/* This structure is used for a comdat section, as in PE.  A comdat
24589 +   section is associated with a particular symbol.  When the linker
24590 +   sees a comdat section, it keeps only one of the sections with a
24591 +   given name and associated with a given symbol.  */
24592 +
24593 +struct coff_comdat_info
24594 +{
24595 +  /* The name of the symbol associated with a comdat section.  */
24596 +  const char *name;
24597 +
24598 +  /* The local symbol table index of the symbol associated with a
24599 +     comdat section.  This is only meaningful to the object file format
24600 +     specific code; it is not an index into the list returned by
24601 +     bfd_canonicalize_symtab.  */
24602 +  long symbol;
24603 +};
24604 +
24605 +extern struct coff_comdat_info *bfd_coff_get_comdat_section
24606 +  (bfd *, struct bfd_section *);
24607 +
24608 +/* Extracted from init.c.  */
24609 +void bfd_init (void);
24610 +
24611 +/* Extracted from opncls.c.  */
24612 +bfd *bfd_fopen (const char *filename, const char *target,
24613 +    const char *mode, int fd);
24614 +
24615 +bfd *bfd_openr (const char *filename, const char *target);
24616 +
24617 +bfd *bfd_fdopenr (const char *filename, const char *target, int fd);
24618 +
24619 +bfd *bfd_openstreamr (const char *, const char *, void *);
24620 +
24621 +bfd *bfd_openr_iovec (const char *filename, const char *target,
24622 +    void *(*open) (struct bfd *nbfd,
24623 +    void *open_closure),
24624 +    void *open_closure,
24625 +    file_ptr (*pread) (struct bfd *nbfd,
24626 +    void *stream,
24627 +    void *buf,
24628 +    file_ptr nbytes,
24629 +    file_ptr offset),
24630 +    int (*close) (struct bfd *nbfd,
24631 +    void *stream));
24632 +
24633 +bfd *bfd_openw (const char *filename, const char *target);
24634 +
24635 +bfd_boolean bfd_close (bfd *abfd);
24636 +
24637 +bfd_boolean bfd_close_all_done (bfd *);
24638 +
24639 +bfd *bfd_create (const char *filename, bfd *templ);
24640 +
24641 +bfd_boolean bfd_make_writable (bfd *abfd);
24642 +
24643 +bfd_boolean bfd_make_readable (bfd *abfd);
24644 +
24645 +unsigned long bfd_calc_gnu_debuglink_crc32
24646 +   (unsigned long crc, const unsigned char *buf, bfd_size_type len);
24647 +
24648 +char *bfd_follow_gnu_debuglink (bfd *abfd, const char *dir);
24649 +
24650 +struct bfd_section *bfd_create_gnu_debuglink_section
24651 +   (bfd *abfd, const char *filename);
24652 +
24653 +bfd_boolean bfd_fill_in_gnu_debuglink_section
24654 +   (bfd *abfd, struct bfd_section *sect, const char *filename);
24655 +
24656 +/* Extracted from libbfd.c.  */
24657 +
24658 +/* Byte swapping macros for user section data.  */
24659 +
24660 +#define bfd_put_8(abfd, val, ptr) \
24661 +  ((void) (*((unsigned char *) (ptr)) = (val) & 0xff))
24662 +#define bfd_put_signed_8 \
24663 +  bfd_put_8
24664 +#define bfd_get_8(abfd, ptr) \
24665 +  (*(unsigned char *) (ptr) & 0xff)
24666 +#define bfd_get_signed_8(abfd, ptr) \
24667 +  (((*(unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80)
24668 +
24669 +#define bfd_put_16(abfd, val, ptr) \
24670 +  BFD_SEND (abfd, bfd_putx16, ((val),(ptr)))
24671 +#define bfd_put_signed_16 \
24672 +  bfd_put_16
24673 +#define bfd_get_16(abfd, ptr) \
24674 +  BFD_SEND (abfd, bfd_getx16, (ptr))
24675 +#define bfd_get_signed_16(abfd, ptr) \
24676 +  BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
24677 +
24678 +#define bfd_put_32(abfd, val, ptr) \
24679 +  BFD_SEND (abfd, bfd_putx32, ((val),(ptr)))
24680 +#define bfd_put_signed_32 \
24681 +  bfd_put_32
24682 +#define bfd_get_32(abfd, ptr) \
24683 +  BFD_SEND (abfd, bfd_getx32, (ptr))
24684 +#define bfd_get_signed_32(abfd, ptr) \
24685 +  BFD_SEND (abfd, bfd_getx_signed_32, (ptr))
24686 +
24687 +#define bfd_put_64(abfd, val, ptr) \
24688 +  BFD_SEND (abfd, bfd_putx64, ((val), (ptr)))
24689 +#define bfd_put_signed_64 \
24690 +  bfd_put_64
24691 +#define bfd_get_64(abfd, ptr) \
24692 +  BFD_SEND (abfd, bfd_getx64, (ptr))
24693 +#define bfd_get_signed_64(abfd, ptr) \
24694 +  BFD_SEND (abfd, bfd_getx_signed_64, (ptr))
24695 +
24696 +#define bfd_get(bits, abfd, ptr)                       \
24697 +  ((bits) == 8 ? (bfd_vma) bfd_get_8 (abfd, ptr)       \
24698 +   : (bits) == 16 ? bfd_get_16 (abfd, ptr)             \
24699 +   : (bits) == 32 ? bfd_get_32 (abfd, ptr)             \
24700 +   : (bits) == 64 ? bfd_get_64 (abfd, ptr)             \
24701 +   : (abort (), (bfd_vma) - 1))
24702 +
24703 +#define bfd_put(bits, abfd, val, ptr)                  \
24704 +  ((bits) == 8 ? bfd_put_8  (abfd, val, ptr)           \
24705 +   : (bits) == 16 ? bfd_put_16 (abfd, val, ptr)                \
24706 +   : (bits) == 32 ? bfd_put_32 (abfd, val, ptr)                \
24707 +   : (bits) == 64 ? bfd_put_64 (abfd, val, ptr)                \
24708 +   : (abort (), (void) 0))
24709 +
24710 +
24711 +/* Byte swapping macros for file header data.  */
24712 +
24713 +#define bfd_h_put_8(abfd, val, ptr) \
24714 +  bfd_put_8 (abfd, val, ptr)
24715 +#define bfd_h_put_signed_8(abfd, val, ptr) \
24716 +  bfd_put_8 (abfd, val, ptr)
24717 +#define bfd_h_get_8(abfd, ptr) \
24718 +  bfd_get_8 (abfd, ptr)
24719 +#define bfd_h_get_signed_8(abfd, ptr) \
24720 +  bfd_get_signed_8 (abfd, ptr)
24721 +
24722 +#define bfd_h_put_16(abfd, val, ptr) \
24723 +  BFD_SEND (abfd, bfd_h_putx16, (val, ptr))
24724 +#define bfd_h_put_signed_16 \
24725 +  bfd_h_put_16
24726 +#define bfd_h_get_16(abfd, ptr) \
24727 +  BFD_SEND (abfd, bfd_h_getx16, (ptr))
24728 +#define bfd_h_get_signed_16(abfd, ptr) \
24729 +  BFD_SEND (abfd, bfd_h_getx_signed_16, (ptr))
24730 +
24731 +#define bfd_h_put_32(abfd, val, ptr) \
24732 +  BFD_SEND (abfd, bfd_h_putx32, (val, ptr))
24733 +#define bfd_h_put_signed_32 \
24734 +  bfd_h_put_32
24735 +#define bfd_h_get_32(abfd, ptr) \
24736 +  BFD_SEND (abfd, bfd_h_getx32, (ptr))
24737 +#define bfd_h_get_signed_32(abfd, ptr) \
24738 +  BFD_SEND (abfd, bfd_h_getx_signed_32, (ptr))
24739 +
24740 +#define bfd_h_put_64(abfd, val, ptr) \
24741 +  BFD_SEND (abfd, bfd_h_putx64, (val, ptr))
24742 +#define bfd_h_put_signed_64 \
24743 +  bfd_h_put_64
24744 +#define bfd_h_get_64(abfd, ptr) \
24745 +  BFD_SEND (abfd, bfd_h_getx64, (ptr))
24746 +#define bfd_h_get_signed_64(abfd, ptr) \
24747 +  BFD_SEND (abfd, bfd_h_getx_signed_64, (ptr))
24748 +
24749 +/* Aliases for the above, which should eventually go away.  */
24750 +
24751 +#define H_PUT_64  bfd_h_put_64
24752 +#define H_PUT_32  bfd_h_put_32
24753 +#define H_PUT_16  bfd_h_put_16
24754 +#define H_PUT_8   bfd_h_put_8
24755 +#define H_PUT_S64 bfd_h_put_signed_64
24756 +#define H_PUT_S32 bfd_h_put_signed_32
24757 +#define H_PUT_S16 bfd_h_put_signed_16
24758 +#define H_PUT_S8  bfd_h_put_signed_8
24759 +#define H_GET_64  bfd_h_get_64
24760 +#define H_GET_32  bfd_h_get_32
24761 +#define H_GET_16  bfd_h_get_16
24762 +#define H_GET_8   bfd_h_get_8
24763 +#define H_GET_S64 bfd_h_get_signed_64
24764 +#define H_GET_S32 bfd_h_get_signed_32
24765 +#define H_GET_S16 bfd_h_get_signed_16
24766 +#define H_GET_S8  bfd_h_get_signed_8
24767 +
24768 +
24769 +/* Extracted from bfdio.c.  */
24770 +long bfd_get_mtime (bfd *abfd);
24771 +
24772 +long bfd_get_size (bfd *abfd);
24773 +
24774 +/* Extracted from bfdwin.c.  */
24775 +/* Extracted from section.c.  */
24776 +typedef struct bfd_section
24777 +{
24778 +  /* The name of the section; the name isn't a copy, the pointer is
24779 +     the same as that passed to bfd_make_section.  */
24780 +  const char *name;
24781 +
24782 +  /* A unique sequence number.  */
24783 +  int id;
24784 +
24785 +  /* Which section in the bfd; 0..n-1 as sections are created in a bfd.  */
24786 +  int index;
24787 +
24788 +  /* The next section in the list belonging to the BFD, or NULL.  */
24789 +  struct bfd_section *next;
24790 +
24791 +  /* The previous section in the list belonging to the BFD, or NULL.  */
24792 +  struct bfd_section *prev;
24793 +
24794 +  /* The field flags contains attributes of the section. Some
24795 +     flags are read in from the object file, and some are
24796 +     synthesized from other information.  */
24797 +  flagword flags;
24798 +
24799 +#define SEC_NO_FLAGS   0x000
24800 +
24801 +  /* Tells the OS to allocate space for this section when loading.
24802 +     This is clear for a section containing debug information only.  */
24803 +#define SEC_ALLOC      0x001
24804 +
24805 +  /* Tells the OS to load the section from the file when loading.
24806 +     This is clear for a .bss section.  */
24807 +#define SEC_LOAD       0x002
24808 +
24809 +  /* The section contains data still to be relocated, so there is
24810 +     some relocation information too.  */
24811 +#define SEC_RELOC      0x004
24812 +
24813 +  /* A signal to the OS that the section contains read only data.  */
24814 +#define SEC_READONLY   0x008
24815 +
24816 +  /* The section contains code only.  */
24817 +#define SEC_CODE       0x010
24818 +
24819 +  /* The section contains data only.  */
24820 +#define SEC_DATA       0x020
24821 +
24822 +  /* The section will reside in ROM.  */
24823 +#define SEC_ROM        0x040
24824 +
24825 +  /* The section contains constructor information. This section
24826 +     type is used by the linker to create lists of constructors and
24827 +     destructors used by <<g++>>. When a back end sees a symbol
24828 +     which should be used in a constructor list, it creates a new
24829 +     section for the type of name (e.g., <<__CTOR_LIST__>>), attaches
24830 +     the symbol to it, and builds a relocation. To build the lists
24831 +     of constructors, all the linker has to do is catenate all the
24832 +     sections called <<__CTOR_LIST__>> and relocate the data
24833 +     contained within - exactly the operations it would peform on
24834 +     standard data.  */
24835 +#define SEC_CONSTRUCTOR 0x080
24836 +
24837 +  /* The section has contents - a data section could be
24838 +     <<SEC_ALLOC>> | <<SEC_HAS_CONTENTS>>; a debug section could be
24839 +     <<SEC_HAS_CONTENTS>>  */
24840 +#define SEC_HAS_CONTENTS 0x100
24841 +
24842 +  /* An instruction to the linker to not output the section
24843 +     even if it has information which would normally be written.  */
24844 +#define SEC_NEVER_LOAD 0x200
24845 +
24846 +  /* The section contains thread local data.  */
24847 +#define SEC_THREAD_LOCAL 0x400
24848 +
24849 +  /* The section has GOT references.  This flag is only for the
24850 +     linker, and is currently only used by the elf32-hppa back end.
24851 +     It will be set if global offset table references were detected
24852 +     in this section, which indicate to the linker that the section
24853 +     contains PIC code, and must be handled specially when doing a
24854 +     static link.  */
24855 +#define SEC_HAS_GOT_REF 0x800
24856 +
24857 +  /* The section contains common symbols (symbols may be defined
24858 +     multiple times, the value of a symbol is the amount of
24859 +     space it requires, and the largest symbol value is the one
24860 +     used).  Most targets have exactly one of these (which we
24861 +     translate to bfd_com_section_ptr), but ECOFF has two.  */
24862 +#define SEC_IS_COMMON 0x1000
24863 +
24864 +  /* The section contains only debugging information.  For
24865 +     example, this is set for ELF .debug and .stab sections.
24866 +     strip tests this flag to see if a section can be
24867 +     discarded.  */
24868 +#define SEC_DEBUGGING 0x2000
24869 +
24870 +  /* The contents of this section are held in memory pointed to
24871 +     by the contents field.  This is checked by bfd_get_section_contents,
24872 +     and the data is retrieved from memory if appropriate.  */
24873 +#define SEC_IN_MEMORY 0x4000
24874 +
24875 +  /* The contents of this section are to be excluded by the
24876 +     linker for executable and shared objects unless those
24877 +     objects are to be further relocated.  */
24878 +#define SEC_EXCLUDE 0x8000
24879 +
24880 +  /* The contents of this section are to be sorted based on the sum of
24881 +     the symbol and addend values specified by the associated relocation
24882 +     entries.  Entries without associated relocation entries will be
24883 +     appended to the end of the section in an unspecified order.  */
24884 +#define SEC_SORT_ENTRIES 0x10000
24885 +
24886 +  /* When linking, duplicate sections of the same name should be
24887 +     discarded, rather than being combined into a single section as
24888 +     is usually done.  This is similar to how common symbols are
24889 +     handled.  See SEC_LINK_DUPLICATES below.  */
24890 +#define SEC_LINK_ONCE 0x20000
24891 +
24892 +  /* If SEC_LINK_ONCE is set, this bitfield describes how the linker
24893 +     should handle duplicate sections.  */
24894 +#define SEC_LINK_DUPLICATES 0x40000
24895 +
24896 +  /* This value for SEC_LINK_DUPLICATES means that duplicate
24897 +     sections with the same name should simply be discarded.  */
24898 +#define SEC_LINK_DUPLICATES_DISCARD 0x0
24899 +
24900 +  /* This value for SEC_LINK_DUPLICATES means that the linker
24901 +     should warn if there are any duplicate sections, although
24902 +     it should still only link one copy.  */
24903 +#define SEC_LINK_DUPLICATES_ONE_ONLY 0x80000
24904 +
24905 +  /* This value for SEC_LINK_DUPLICATES means that the linker
24906 +     should warn if any duplicate sections are a different size.  */
24907 +#define SEC_LINK_DUPLICATES_SAME_SIZE 0x100000
24908 +
24909 +  /* This value for SEC_LINK_DUPLICATES means that the linker
24910 +     should warn if any duplicate sections contain different
24911 +     contents.  */
24912 +#define SEC_LINK_DUPLICATES_SAME_CONTENTS \
24913 +  (SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE)
24914 +
24915 +  /* This section was created by the linker as part of dynamic
24916 +     relocation or other arcane processing.  It is skipped when
24917 +     going through the first-pass output, trusting that someone
24918 +     else up the line will take care of it later.  */
24919 +#define SEC_LINKER_CREATED 0x200000
24920 +
24921 +  /* This section should not be subject to garbage collection.  */
24922 +#define SEC_KEEP 0x400000
24923 +
24924 +  /* This section contains "short" data, and should be placed
24925 +     "near" the GP.  */
24926 +#define SEC_SMALL_DATA 0x800000
24927 +
24928 +  /* Attempt to merge identical entities in the section.
24929 +     Entity size is given in the entsize field.  */
24930 +#define SEC_MERGE 0x1000000
24931 +
24932 +  /* If given with SEC_MERGE, entities to merge are zero terminated
24933 +     strings where entsize specifies character size instead of fixed
24934 +     size entries.  */
24935 +#define SEC_STRINGS 0x2000000
24936 +
24937 +  /* This section contains data about section groups.  */
24938 +#define SEC_GROUP 0x4000000
24939 +
24940 +  /* The section is a COFF shared library section.  This flag is
24941 +     only for the linker.  If this type of section appears in
24942 +     the input file, the linker must copy it to the output file
24943 +     without changing the vma or size.  FIXME: Although this
24944 +     was originally intended to be general, it really is COFF
24945 +     specific (and the flag was renamed to indicate this).  It
24946 +     might be cleaner to have some more general mechanism to
24947 +     allow the back end to control what the linker does with
24948 +     sections.  */
24949 +#define SEC_COFF_SHARED_LIBRARY 0x10000000
24950 +
24951 +  /* This section contains data which may be shared with other
24952 +     executables or shared objects. This is for COFF only.  */
24953 +#define SEC_COFF_SHARED 0x20000000
24954 +
24955 +  /* When a section with this flag is being linked, then if the size of
24956 +     the input section is less than a page, it should not cross a page
24957 +     boundary.  If the size of the input section is one page or more,
24958 +     it should be aligned on a page boundary.  This is for TI
24959 +     TMS320C54X only.  */
24960 +#define SEC_TIC54X_BLOCK 0x40000000
24961 +
24962 +  /* Conditionally link this section; do not link if there are no
24963 +     references found to any symbol in the section.  This is for TI
24964 +     TMS320C54X only.  */
24965 +#define SEC_TIC54X_CLINK 0x80000000
24966 +
24967 +  /*  End of section flags.  */
24968 +
24969 +  /* Some internal packed boolean fields.  */
24970 +
24971 +  /* See the vma field.  */
24972 +  unsigned int user_set_vma : 1;
24973 +
24974 +  /* A mark flag used by some of the linker backends.  */
24975 +  unsigned int linker_mark : 1;
24976 +
24977 +  /* Another mark flag used by some of the linker backends.  Set for
24978 +     output sections that have an input section.  */
24979 +  unsigned int linker_has_input : 1;
24980 +
24981 +  /* Mark flags used by some linker backends for garbage collection.  */
24982 +  unsigned int gc_mark : 1;
24983 +  unsigned int gc_mark_from_eh : 1;
24984 +
24985 +  /* The following flags are used by the ELF linker. */
24986 +
24987 +  /* Mark sections which have been allocated to segments.  */
24988 +  unsigned int segment_mark : 1;
24989 +
24990 +  /* Type of sec_info information.  */
24991 +  unsigned int sec_info_type:3;
24992 +#define ELF_INFO_TYPE_NONE      0
24993 +#define ELF_INFO_TYPE_STABS     1
24994 +#define ELF_INFO_TYPE_MERGE     2
24995 +#define ELF_INFO_TYPE_EH_FRAME  3
24996 +#define ELF_INFO_TYPE_JUST_SYMS 4
24997 +
24998 +  /* Nonzero if this section uses RELA relocations, rather than REL.  */
24999 +  unsigned int use_rela_p:1;
25000 +
25001 +  /* Bits used by various backends.  The generic code doesn't touch
25002 +     these fields.  */
25003 +
25004 +  /* Nonzero if this section has TLS related relocations.  */
25005 +  unsigned int has_tls_reloc:1;
25006 +
25007 +  /* Nonzero if this section has a gp reloc.  */
25008 +  unsigned int has_gp_reloc:1;
25009 +
25010 +  /* Nonzero if this section needs the relax finalize pass.  */
25011 +  unsigned int need_finalize_relax:1;
25012 +
25013 +  /* Whether relocations have been processed.  */
25014 +  unsigned int reloc_done : 1;
25015 +
25016 +  /* End of internal packed boolean fields.  */
25017 +
25018 +  /*  The virtual memory address of the section - where it will be
25019 +      at run time.  The symbols are relocated against this.  The
25020 +      user_set_vma flag is maintained by bfd; if it's not set, the
25021 +      backend can assign addresses (for example, in <<a.out>>, where
25022 +      the default address for <<.data>> is dependent on the specific
25023 +      target and various flags).  */
25024 +  bfd_vma vma;
25025 +
25026 +  /*  The load address of the section - where it would be in a
25027 +      rom image; really only used for writing section header
25028 +      information.  */
25029 +  bfd_vma lma;
25030 +
25031 +  /* The size of the section in octets, as it will be output.
25032 +     Contains a value even if the section has no contents (e.g., the
25033 +     size of <<.bss>>).  */
25034 +  bfd_size_type size;
25035 +
25036 +  /* For input sections, the original size on disk of the section, in
25037 +     octets.  This field is used by the linker relaxation code.  It is
25038 +     currently only set for sections where the linker relaxation scheme
25039 +     doesn't cache altered section and reloc contents (stabs, eh_frame,
25040 +     SEC_MERGE, some coff relaxing targets), and thus the original size
25041 +     needs to be kept to read the section multiple times.
25042 +     For output sections, rawsize holds the section size calculated on
25043 +     a previous linker relaxation pass.  */
25044 +  bfd_size_type rawsize;
25045 +
25046 +  /* If this section is going to be output, then this value is the
25047 +     offset in *bytes* into the output section of the first byte in the
25048 +     input section (byte ==> smallest addressable unit on the
25049 +     target).  In most cases, if this was going to start at the
25050 +     100th octet (8-bit quantity) in the output section, this value
25051 +     would be 100.  However, if the target byte size is 16 bits
25052 +     (bfd_octets_per_byte is "2"), this value would be 50.  */
25053 +  bfd_vma output_offset;
25054 +
25055 +  /* The output section through which to map on output.  */
25056 +  struct bfd_section *output_section;
25057 +
25058 +  /* The alignment requirement of the section, as an exponent of 2 -
25059 +     e.g., 3 aligns to 2^3 (or 8).  */
25060 +  unsigned int alignment_power;
25061 +
25062 +  /* If an input section, a pointer to a vector of relocation
25063 +     records for the data in this section.  */
25064 +  struct reloc_cache_entry *relocation;
25065 +
25066 +  /* If an output section, a pointer to a vector of pointers to
25067 +     relocation records for the data in this section.  */
25068 +  struct reloc_cache_entry **orelocation;
25069 +
25070 +  /* The number of relocation records in one of the above.  */
25071 +  unsigned reloc_count;
25072 +
25073 +  /* Information below is back end specific - and not always used
25074 +     or updated.  */
25075 +
25076 +  /* File position of section data.  */
25077 +  file_ptr filepos;
25078 +
25079 +  /* File position of relocation info.  */
25080 +  file_ptr rel_filepos;
25081 +
25082 +  /* File position of line data.  */
25083 +  file_ptr line_filepos;
25084 +
25085 +  /* Pointer to data for applications.  */
25086 +  void *userdata;
25087 +
25088 +  /* If the SEC_IN_MEMORY flag is set, this points to the actual
25089 +     contents.  */
25090 +  unsigned char *contents;
25091 +
25092 +  /* Attached line number information.  */
25093 +  alent *lineno;
25094 +
25095 +  /* Number of line number records.  */
25096 +  unsigned int lineno_count;
25097 +
25098 +  /* Entity size for merging purposes.  */
25099 +  unsigned int entsize;
25100 +
25101 +  /* Points to the kept section if this section is a link-once section,
25102 +     and is discarded.  */
25103 +  struct bfd_section *kept_section;
25104 +
25105 +  /* When a section is being output, this value changes as more
25106 +     linenumbers are written out.  */
25107 +  file_ptr moving_line_filepos;
25108 +
25109 +  /* What the section number is in the target world.  */
25110 +  int target_index;
25111 +
25112 +  void *used_by_bfd;
25113 +
25114 +  /* If this is a constructor section then here is a list of the
25115 +     relocations created to relocate items within it.  */
25116 +  struct relent_chain *constructor_chain;
25117 +
25118 +  /* The BFD which owns the section.  */
25119 +  bfd *owner;
25120 +
25121 +  /* A symbol which points at this section only.  */
25122 +  struct bfd_symbol *symbol;
25123 +  struct bfd_symbol **symbol_ptr_ptr;
25124 +
25125 +  /* Early in the link process, map_head and map_tail are used to build
25126 +     a list of input sections attached to an output section.  Later,
25127 +     output sections use these fields for a list of bfd_link_order
25128 +     structs.  */
25129 +  union {
25130 +    struct bfd_link_order *link_order;
25131 +    struct bfd_section *s;
25132 +  } map_head, map_tail;
25133 +} asection;
25134 +
25135 +/* These sections are global, and are managed by BFD.  The application
25136 +   and target back end are not permitted to change the values in
25137 +   these sections.  New code should use the section_ptr macros rather
25138 +   than referring directly to the const sections.  The const sections
25139 +   may eventually vanish.  */
25140 +#define BFD_ABS_SECTION_NAME "*ABS*"
25141 +#define BFD_UND_SECTION_NAME "*UND*"
25142 +#define BFD_COM_SECTION_NAME "*COM*"
25143 +#define BFD_IND_SECTION_NAME "*IND*"
25144 +
25145 +/* The absolute section.  */
25146 +extern asection bfd_abs_section;
25147 +#define bfd_abs_section_ptr ((asection *) &bfd_abs_section)
25148 +#define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr)
25149 +/* Pointer to the undefined section.  */
25150 +extern asection bfd_und_section;
25151 +#define bfd_und_section_ptr ((asection *) &bfd_und_section)
25152 +#define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr)
25153 +/* Pointer to the common section.  */
25154 +extern asection bfd_com_section;
25155 +#define bfd_com_section_ptr ((asection *) &bfd_com_section)
25156 +/* Pointer to the indirect section.  */
25157 +extern asection bfd_ind_section;
25158 +#define bfd_ind_section_ptr ((asection *) &bfd_ind_section)
25159 +#define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr)
25160 +
25161 +#define bfd_is_const_section(SEC)              \
25162 + (   ((SEC) == bfd_abs_section_ptr)            \
25163 +  || ((SEC) == bfd_und_section_ptr)            \
25164 +  || ((SEC) == bfd_com_section_ptr)            \
25165 +  || ((SEC) == bfd_ind_section_ptr))
25166 +
25167 +extern const struct bfd_symbol * const bfd_abs_symbol;
25168 +extern const struct bfd_symbol * const bfd_com_symbol;
25169 +extern const struct bfd_symbol * const bfd_und_symbol;
25170 +extern const struct bfd_symbol * const bfd_ind_symbol;
25171 +
25172 +/* Macros to handle insertion and deletion of a bfd's sections.  These
25173 +   only handle the list pointers, ie. do not adjust section_count,
25174 +   target_index etc.  */
25175 +#define bfd_section_list_remove(ABFD, S) \
25176 +  do                                                   \
25177 +    {                                                  \
25178 +      asection *_s = S;                                \
25179 +      asection *_next = _s->next;                      \
25180 +      asection *_prev = _s->prev;                      \
25181 +      if (_prev)                                       \
25182 +        _prev->next = _next;                           \
25183 +      else                                             \
25184 +        (ABFD)->sections = _next;                      \
25185 +      if (_next)                                       \
25186 +        _next->prev = _prev;                           \
25187 +      else                                             \
25188 +        (ABFD)->section_last = _prev;                  \
25189 +    }                                                  \
25190 +  while (0)
25191 +#define bfd_section_list_append(ABFD, S) \
25192 +  do                                                   \
25193 +    {                                                  \
25194 +      asection *_s = S;                                \
25195 +      bfd *_abfd = ABFD;                               \
25196 +      _s->next = NULL;                                 \
25197 +      if (_abfd->section_last)                         \
25198 +        {                                              \
25199 +          _s->prev = _abfd->section_last;              \
25200 +          _abfd->section_last->next = _s;              \
25201 +        }                                              \
25202 +      else                                             \
25203 +        {                                              \
25204 +          _s->prev = NULL;                             \
25205 +          _abfd->sections = _s;                        \
25206 +        }                                              \
25207 +      _abfd->section_last = _s;                        \
25208 +    }                                                  \
25209 +  while (0)
25210 +#define bfd_section_list_prepend(ABFD, S) \
25211 +  do                                                   \
25212 +    {                                                  \
25213 +      asection *_s = S;                                \
25214 +      bfd *_abfd = ABFD;                               \
25215 +      _s->prev = NULL;                                 \
25216 +      if (_abfd->sections)                             \
25217 +        {                                              \
25218 +          _s->next = _abfd->sections;                  \
25219 +          _abfd->sections->prev = _s;                  \
25220 +        }                                              \
25221 +      else                                             \
25222 +        {                                              \
25223 +          _s->next = NULL;                             \
25224 +          _abfd->section_last = _s;                    \
25225 +        }                                              \
25226 +      _abfd->sections = _s;                            \
25227 +    }                                                  \
25228 +  while (0)
25229 +#define bfd_section_list_insert_after(ABFD, A, S) \
25230 +  do                                                   \
25231 +    {                                                  \
25232 +      asection *_a = A;                                \
25233 +      asection *_s = S;                                \
25234 +      asection *_next = _a->next;                      \
25235 +      _s->next = _next;                                \
25236 +      _s->prev = _a;                                   \
25237 +      _a->next = _s;                                   \
25238 +      if (_next)                                       \
25239 +        _next->prev = _s;                              \
25240 +      else                                             \
25241 +        (ABFD)->section_last = _s;                     \
25242 +    }                                                  \
25243 +  while (0)
25244 +#define bfd_section_list_insert_before(ABFD, B, S) \
25245 +  do                                                   \
25246 +    {                                                  \
25247 +      asection *_b = B;                                \
25248 +      asection *_s = S;                                \
25249 +      asection *_prev = _b->prev;                      \
25250 +      _s->prev = _prev;                                \
25251 +      _s->next = _b;                                   \
25252 +      _b->prev = _s;                                   \
25253 +      if (_prev)                                       \
25254 +        _prev->next = _s;                              \
25255 +      else                                             \
25256 +        (ABFD)->sections = _s;                         \
25257 +    }                                                  \
25258 +  while (0)
25259 +#define bfd_section_removed_from_list(ABFD, S) \
25260 +  ((S)->next == NULL ? (ABFD)->section_last != (S) : (S)->next->prev != (S))
25261 +
25262 +void bfd_section_list_clear (bfd *);
25263 +
25264 +asection *bfd_get_section_by_name (bfd *abfd, const char *name);
25265 +
25266 +asection *bfd_get_section_by_name_if
25267 +   (bfd *abfd,
25268 +    const char *name,
25269 +    bfd_boolean (*func) (bfd *abfd, asection *sect, void *obj),
25270 +    void *obj);
25271 +
25272 +char *bfd_get_unique_section_name
25273 +   (bfd *abfd, const char *templat, int *count);
25274 +
25275 +asection *bfd_make_section_old_way (bfd *abfd, const char *name);
25276 +
25277 +asection *bfd_make_section_anyway_with_flags
25278 +   (bfd *abfd, const char *name, flagword flags);
25279 +
25280 +asection *bfd_make_section_anyway (bfd *abfd, const char *name);
25281 +
25282 +asection *bfd_make_section_with_flags
25283 +   (bfd *, const char *name, flagword flags);
25284 +
25285 +asection *bfd_make_section (bfd *, const char *name);
25286 +
25287 +bfd_boolean bfd_set_section_flags
25288 +   (bfd *abfd, asection *sec, flagword flags);
25289 +
25290 +void bfd_map_over_sections
25291 +   (bfd *abfd,
25292 +    void (*func) (bfd *abfd, asection *sect, void *obj),
25293 +    void *obj);
25294 +
25295 +asection *bfd_sections_find_if
25296 +   (bfd *abfd,
25297 +    bfd_boolean (*operation) (bfd *abfd, asection *sect, void *obj),
25298 +    void *obj);
25299 +
25300 +bfd_boolean bfd_set_section_size
25301 +   (bfd *abfd, asection *sec, bfd_size_type val);
25302 +
25303 +bfd_boolean bfd_set_section_contents
25304 +   (bfd *abfd, asection *section, const void *data,
25305 +    file_ptr offset, bfd_size_type count);
25306 +
25307 +bfd_boolean bfd_get_section_contents
25308 +   (bfd *abfd, asection *section, void *location, file_ptr offset,
25309 +    bfd_size_type count);
25310 +
25311 +bfd_boolean bfd_malloc_and_get_section
25312 +   (bfd *abfd, asection *section, bfd_byte **buf);
25313 +
25314 +bfd_boolean bfd_copy_private_section_data
25315 +   (bfd *ibfd, asection *isec, bfd *obfd, asection *osec);
25316 +
25317 +#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \
25318 +     BFD_SEND (obfd, _bfd_copy_private_section_data, \
25319 +               (ibfd, isection, obfd, osection))
25320 +bfd_boolean bfd_generic_is_group_section (bfd *, const asection *sec);
25321 +
25322 +bfd_boolean bfd_generic_discard_group (bfd *abfd, asection *group);
25323 +
25324 +/* Extracted from archures.c.  */
25325 +enum bfd_architecture
25326 +{
25327 +  bfd_arch_unknown,   /* File arch not known.  */
25328 +  bfd_arch_obscure,   /* Arch known, not one of these.  */
25329 +  bfd_arch_m68k,      /* Motorola 68xxx */
25330 +#define bfd_mach_m68000 1
25331 +#define bfd_mach_m68008 2
25332 +#define bfd_mach_m68010 3
25333 +#define bfd_mach_m68020 4
25334 +#define bfd_mach_m68030 5
25335 +#define bfd_mach_m68040 6
25336 +#define bfd_mach_m68060 7
25337 +#define bfd_mach_cpu32  8
25338 +#define bfd_mach_mcf5200  9
25339 +#define bfd_mach_mcf5206e 10
25340 +#define bfd_mach_mcf5307  11
25341 +#define bfd_mach_mcf5407  12
25342 +#define bfd_mach_mcf528x  13
25343 +#define bfd_mach_mcfv4e   14
25344 +#define bfd_mach_mcf521x   15
25345 +#define bfd_mach_mcf5249   16
25346 +#define bfd_mach_mcf547x   17
25347 +#define bfd_mach_mcf548x   18
25348 +  bfd_arch_vax,       /* DEC Vax */
25349 +  bfd_arch_i960,      /* Intel 960 */
25350 +    /* The order of the following is important.
25351 +       lower number indicates a machine type that
25352 +       only accepts a subset of the instructions
25353 +       available to machines with higher numbers.
25354 +       The exception is the "ca", which is
25355 +       incompatible with all other machines except
25356 +       "core".  */
25357 +
25358 +#define bfd_mach_i960_core      1
25359 +#define bfd_mach_i960_ka_sa     2
25360 +#define bfd_mach_i960_kb_sb     3
25361 +#define bfd_mach_i960_mc        4
25362 +#define bfd_mach_i960_xa        5
25363 +#define bfd_mach_i960_ca        6
25364 +#define bfd_mach_i960_jx        7
25365 +#define bfd_mach_i960_hx        8
25366 +
25367 +  bfd_arch_or32,      /* OpenRISC 32 */
25368 +
25369 +  bfd_arch_a29k,      /* AMD 29000 */
25370 +  bfd_arch_sparc,     /* SPARC */
25371 +#define bfd_mach_sparc                 1
25372 +/* The difference between v8plus and v9 is that v9 is a true 64 bit env.  */
25373 +#define bfd_mach_sparc_sparclet        2
25374 +#define bfd_mach_sparc_sparclite       3
25375 +#define bfd_mach_sparc_v8plus          4
25376 +#define bfd_mach_sparc_v8plusa         5 /* with ultrasparc add'ns.  */
25377 +#define bfd_mach_sparc_sparclite_le    6
25378 +#define bfd_mach_sparc_v9              7
25379 +#define bfd_mach_sparc_v9a             8 /* with ultrasparc add'ns.  */
25380 +#define bfd_mach_sparc_v8plusb         9 /* with cheetah add'ns.  */
25381 +#define bfd_mach_sparc_v9b             10 /* with cheetah add'ns.  */
25382 +/* Nonzero if MACH has the v9 instruction set.  */
25383 +#define bfd_mach_sparc_v9_p(mach) \
25384 +  ((mach) >= bfd_mach_sparc_v8plus && (mach) <= bfd_mach_sparc_v9b \
25385 +   && (mach) != bfd_mach_sparc_sparclite_le)
25386 +/* Nonzero if MACH is a 64 bit sparc architecture.  */
25387 +#define bfd_mach_sparc_64bit_p(mach) \
25388 +  ((mach) >= bfd_mach_sparc_v9 && (mach) != bfd_mach_sparc_v8plusb)
25389 +  bfd_arch_mips,      /* MIPS Rxxxx */
25390 +#define bfd_mach_mips3000              3000
25391 +#define bfd_mach_mips3900              3900
25392 +#define bfd_mach_mips4000              4000
25393 +#define bfd_mach_mips4010              4010
25394 +#define bfd_mach_mips4100              4100
25395 +#define bfd_mach_mips4111              4111
25396 +#define bfd_mach_mips4120              4120
25397 +#define bfd_mach_mips4300              4300
25398 +#define bfd_mach_mips4400              4400
25399 +#define bfd_mach_mips4600              4600
25400 +#define bfd_mach_mips4650              4650
25401 +#define bfd_mach_mips5000              5000
25402 +#define bfd_mach_mips5400              5400
25403 +#define bfd_mach_mips5500              5500
25404 +#define bfd_mach_mips6000              6000
25405 +#define bfd_mach_mips7000              7000
25406 +#define bfd_mach_mips8000              8000
25407 +#define bfd_mach_mips9000              9000
25408 +#define bfd_mach_mips10000             10000
25409 +#define bfd_mach_mips12000             12000
25410 +#define bfd_mach_mips16                16
25411 +#define bfd_mach_mips5                 5
25412 +#define bfd_mach_mips_sb1              12310201 /* octal 'SB', 01 */
25413 +#define bfd_mach_mipsisa32             32
25414 +#define bfd_mach_mipsisa32r2           33
25415 +#define bfd_mach_mipsisa64             64
25416 +#define bfd_mach_mipsisa64r2           65
25417 +  bfd_arch_i386,      /* Intel 386 */
25418 +#define bfd_mach_i386_i386 1
25419 +#define bfd_mach_i386_i8086 2
25420 +#define bfd_mach_i386_i386_intel_syntax 3
25421 +#define bfd_mach_x86_64 64
25422 +#define bfd_mach_x86_64_intel_syntax 65
25423 +  bfd_arch_we32k,     /* AT&T WE32xxx */
25424 +  bfd_arch_tahoe,     /* CCI/Harris Tahoe */
25425 +  bfd_arch_i860,      /* Intel 860 */
25426 +  bfd_arch_i370,      /* IBM 360/370 Mainframes */
25427 +  bfd_arch_romp,      /* IBM ROMP PC/RT */
25428 +  bfd_arch_alliant,   /* Alliant */
25429 +  bfd_arch_convex,    /* Convex */
25430 +  bfd_arch_m88k,      /* Motorola 88xxx */
25431 +  bfd_arch_m98k,      /* Motorola 98xxx */
25432 +  bfd_arch_pyramid,   /* Pyramid Technology */
25433 +  bfd_arch_h8300,     /* Renesas H8/300 (formerly Hitachi H8/300) */
25434 +#define bfd_mach_h8300    1
25435 +#define bfd_mach_h8300h   2
25436 +#define bfd_mach_h8300s   3
25437 +#define bfd_mach_h8300hn  4
25438 +#define bfd_mach_h8300sn  5
25439 +#define bfd_mach_h8300sx  6
25440 +#define bfd_mach_h8300sxn 7
25441 +  bfd_arch_pdp11,     /* DEC PDP-11 */
25442 +  bfd_arch_powerpc,   /* PowerPC */
25443 +#define bfd_mach_ppc           32
25444 +#define bfd_mach_ppc64         64
25445 +#define bfd_mach_ppc_403       403
25446 +#define bfd_mach_ppc_403gc     4030
25447 +#define bfd_mach_ppc_505       505
25448 +#define bfd_mach_ppc_601       601
25449 +#define bfd_mach_ppc_602       602
25450 +#define bfd_mach_ppc_603       603
25451 +#define bfd_mach_ppc_ec603e    6031
25452 +#define bfd_mach_ppc_604       604
25453 +#define bfd_mach_ppc_620       620
25454 +#define bfd_mach_ppc_630       630
25455 +#define bfd_mach_ppc_750       750
25456 +#define bfd_mach_ppc_860       860
25457 +#define bfd_mach_ppc_a35       35
25458 +#define bfd_mach_ppc_rs64ii    642
25459 +#define bfd_mach_ppc_rs64iii   643
25460 +#define bfd_mach_ppc_7400      7400
25461 +#define bfd_mach_ppc_e500      500
25462 +  bfd_arch_rs6000,    /* IBM RS/6000 */
25463 +#define bfd_mach_rs6k          6000
25464 +#define bfd_mach_rs6k_rs1      6001
25465 +#define bfd_mach_rs6k_rsc      6003
25466 +#define bfd_mach_rs6k_rs2      6002
25467 +  bfd_arch_hppa,      /* HP PA RISC */
25468 +#define bfd_mach_hppa10        10
25469 +#define bfd_mach_hppa11        11
25470 +#define bfd_mach_hppa20        20
25471 +#define bfd_mach_hppa20w       25
25472 +  bfd_arch_d10v,      /* Mitsubishi D10V */
25473 +#define bfd_mach_d10v          1
25474 +#define bfd_mach_d10v_ts2      2
25475 +#define bfd_mach_d10v_ts3      3
25476 +  bfd_arch_d30v,      /* Mitsubishi D30V */
25477 +  bfd_arch_dlx,       /* DLX */
25478 +  bfd_arch_m68hc11,   /* Motorola 68HC11 */
25479 +  bfd_arch_m68hc12,   /* Motorola 68HC12 */
25480 +#define bfd_mach_m6812_default 0
25481 +#define bfd_mach_m6812         1
25482 +#define bfd_mach_m6812s        2
25483 +  bfd_arch_z8k,       /* Zilog Z8000 */
25484 +#define bfd_mach_z8001         1
25485 +#define bfd_mach_z8002         2
25486 +  bfd_arch_h8500,     /* Renesas H8/500 (formerly Hitachi H8/500) */
25487 +  bfd_arch_sh,        /* Renesas / SuperH SH (formerly Hitachi SH) */
25488 +#define bfd_mach_sh            1
25489 +#define bfd_mach_sh2        0x20
25490 +#define bfd_mach_sh_dsp     0x2d
25491 +#define bfd_mach_sh2a       0x2a
25492 +#define bfd_mach_sh2a_nofpu 0x2b
25493 +#define bfd_mach_sh2a_nofpu_or_sh4_nommu_nofpu 0x2a1
25494 +#define bfd_mach_sh2a_nofpu_or_sh3_nommu 0x2a2
25495 +#define bfd_mach_sh2a_or_sh4  0x2a3
25496 +#define bfd_mach_sh2a_or_sh3e 0x2a4
25497 +#define bfd_mach_sh2e       0x2e
25498 +#define bfd_mach_sh3        0x30
25499 +#define bfd_mach_sh3_nommu  0x31
25500 +#define bfd_mach_sh3_dsp    0x3d
25501 +#define bfd_mach_sh3e       0x3e
25502 +#define bfd_mach_sh4        0x40
25503 +#define bfd_mach_sh4_nofpu  0x41
25504 +#define bfd_mach_sh4_nommu_nofpu  0x42
25505 +#define bfd_mach_sh4a       0x4a
25506 +#define bfd_mach_sh4a_nofpu 0x4b
25507 +#define bfd_mach_sh4al_dsp  0x4d
25508 +#define bfd_mach_sh5        0x50
25509 +  bfd_arch_alpha,     /* Dec Alpha */
25510 +#define bfd_mach_alpha_ev4  0x10
25511 +#define bfd_mach_alpha_ev5  0x20
25512 +#define bfd_mach_alpha_ev6  0x30
25513 +  bfd_arch_arm,       /* Advanced Risc Machines ARM.  */
25514 +#define bfd_mach_arm_unknown   0
25515 +#define bfd_mach_arm_2         1
25516 +#define bfd_mach_arm_2a        2
25517 +#define bfd_mach_arm_3         3
25518 +#define bfd_mach_arm_3M        4
25519 +#define bfd_mach_arm_4         5
25520 +#define bfd_mach_arm_4T        6
25521 +#define bfd_mach_arm_5         7
25522 +#define bfd_mach_arm_5T        8
25523 +#define bfd_mach_arm_5TE       9
25524 +#define bfd_mach_arm_XScale    10
25525 +#define bfd_mach_arm_ep9312    11
25526 +#define bfd_mach_arm_iWMMXt    12
25527 +  bfd_arch_ns32k,     /* National Semiconductors ns32000 */
25528 +  bfd_arch_w65,       /* WDC 65816 */
25529 +  bfd_arch_tic30,     /* Texas Instruments TMS320C30 */
25530 +  bfd_arch_tic4x,     /* Texas Instruments TMS320C3X/4X */
25531 +#define bfd_mach_tic3x         30
25532 +#define bfd_mach_tic4x         40
25533 +  bfd_arch_tic54x,    /* Texas Instruments TMS320C54X */
25534 +  bfd_arch_tic80,     /* TI TMS320c80 (MVP) */
25535 +  bfd_arch_v850,      /* NEC V850 */
25536 +#define bfd_mach_v850          1
25537 +#define bfd_mach_v850e         'E'
25538 +#define bfd_mach_v850e1        '1'
25539 +  bfd_arch_arc,       /* ARC Cores */
25540 +#define bfd_mach_arc_5         5
25541 +#define bfd_mach_arc_6         6
25542 +#define bfd_mach_arc_7         7
25543 +#define bfd_mach_arc_8         8
25544 + bfd_arch_m32c,     /* Renesas M16C/M32C.  */
25545 +#define bfd_mach_m16c        0x75
25546 +#define bfd_mach_m32c        0x78
25547 +  bfd_arch_m32r,      /* Renesas M32R (formerly Mitsubishi M32R/D) */
25548 +#define bfd_mach_m32r          1 /* For backwards compatibility.  */
25549 +#define bfd_mach_m32rx         'x'
25550 +#define bfd_mach_m32r2         '2'
25551 +  bfd_arch_mn10200,   /* Matsushita MN10200 */
25552 +  bfd_arch_mn10300,   /* Matsushita MN10300 */
25553 +#define bfd_mach_mn10300               300
25554 +#define bfd_mach_am33          330
25555 +#define bfd_mach_am33_2        332
25556 +  bfd_arch_fr30,
25557 +#define bfd_mach_fr30          0x46523330
25558 +  bfd_arch_frv,
25559 +#define bfd_mach_frv           1
25560 +#define bfd_mach_frvsimple     2
25561 +#define bfd_mach_fr300         300
25562 +#define bfd_mach_fr400         400
25563 +#define bfd_mach_fr450         450
25564 +#define bfd_mach_frvtomcat     499     /* fr500 prototype */
25565 +#define bfd_mach_fr500         500
25566 +#define bfd_mach_fr550         550
25567 +  bfd_arch_mcore,
25568 +  bfd_arch_ia64,      /* HP/Intel ia64 */
25569 +#define bfd_mach_ia64_elf64    64
25570 +#define bfd_mach_ia64_elf32    32
25571 +  bfd_arch_ip2k,      /* Ubicom IP2K microcontrollers. */
25572 +#define bfd_mach_ip2022        1
25573 +#define bfd_mach_ip2022ext     2
25574 + bfd_arch_iq2000,     /* Vitesse IQ2000.  */
25575 +#define bfd_mach_iq2000        1
25576 +#define bfd_mach_iq10          2
25577 +  bfd_arch_ms1,
25578 +#define bfd_mach_ms1           1
25579 +#define bfd_mach_mrisc2        2
25580 +  bfd_arch_pj,
25581 +  bfd_arch_avr,       /* Atmel AVR microcontrollers.  */
25582 +#define bfd_mach_avr1          1
25583 +#define bfd_mach_avr2          2
25584 +#define bfd_mach_avr3          3
25585 +#define bfd_mach_avr4          4
25586 +#define bfd_mach_avr5          5
25587 +  bfd_arch_cr16c,       /* National Semiconductor CompactRISC. */
25588 +#define bfd_mach_cr16c         1
25589 +  bfd_arch_crx,       /*  National Semiconductor CRX.  */
25590 +#define bfd_mach_crx           1
25591 +  bfd_arch_cris,      /* Axis CRIS */
25592 +#define bfd_mach_cris_v0_v10   255
25593 +#define bfd_mach_cris_v32      32
25594 +#define bfd_mach_cris_v10_v32  1032
25595 +  bfd_arch_s390,      /* IBM s390 */
25596 +#define bfd_mach_s390_31       31
25597 +#define bfd_mach_s390_64       64
25598 +  bfd_arch_openrisc,  /* OpenRISC */
25599 +  bfd_arch_mmix,      /* Donald Knuth's educational processor.  */
25600 +  bfd_arch_xstormy16,
25601 +#define bfd_mach_xstormy16     1
25602 +  bfd_arch_msp430,    /* Texas Instruments MSP430 architecture.  */
25603 +#define bfd_mach_msp11          11
25604 +#define bfd_mach_msp110         110
25605 +#define bfd_mach_msp12          12
25606 +#define bfd_mach_msp13          13
25607 +#define bfd_mach_msp14          14
25608 +#define bfd_mach_msp15          15
25609 +#define bfd_mach_msp16          16
25610 +#define bfd_mach_msp31          31
25611 +#define bfd_mach_msp32          32
25612 +#define bfd_mach_msp33          33
25613 +#define bfd_mach_msp41          41
25614 +#define bfd_mach_msp42          42
25615 +#define bfd_mach_msp43          43
25616 +#define bfd_mach_msp44          44
25617 +  bfd_arch_xtensa,    /* Tensilica's Xtensa cores.  */
25618 +#define bfd_mach_xtensa        1
25619 +   bfd_arch_maxq,     /* Dallas MAXQ 10/20 */
25620 +#define bfd_mach_maxq10    10
25621 +#define bfd_mach_maxq20    20
25622 +  bfd_arch_last
25623 +  };
25624 +
25625 +typedef struct bfd_arch_info
25626 +{
25627 +  int bits_per_word;
25628 +  int bits_per_address;
25629 +  int bits_per_byte;
25630 +  enum bfd_architecture arch;
25631 +  unsigned long mach;
25632 +  const char *arch_name;
25633 +  const char *printable_name;
25634 +  unsigned int section_align_power;
25635 +  /* TRUE if this is the default machine for the architecture.
25636 +     The default arch should be the first entry for an arch so that
25637 +     all the entries for that arch can be accessed via <<next>>.  */
25638 +  bfd_boolean the_default;
25639 +  const struct bfd_arch_info * (*compatible)
25640 +    (const struct bfd_arch_info *a, const struct bfd_arch_info *b);
25641 +
25642 +  bfd_boolean (*scan) (const struct bfd_arch_info *, const char *);
25643 +
25644 +  const struct bfd_arch_info *next;
25645 +}
25646 +bfd_arch_info_type;
25647 +
25648 +const char *bfd_printable_name (bfd *abfd);
25649 +
25650 +const bfd_arch_info_type *bfd_scan_arch (const char *string);
25651 +
25652 +const char **bfd_arch_list (void);
25653 +
25654 +const bfd_arch_info_type *bfd_arch_get_compatible
25655 +   (const bfd *abfd, const bfd *bbfd, bfd_boolean accept_unknowns);
25656 +
25657 +void bfd_set_arch_info (bfd *abfd, const bfd_arch_info_type *arg);
25658 +
25659 +enum bfd_architecture bfd_get_arch (bfd *abfd);
25660 +
25661 +unsigned long bfd_get_mach (bfd *abfd);
25662 +
25663 +unsigned int bfd_arch_bits_per_byte (bfd *abfd);
25664 +
25665 +unsigned int bfd_arch_bits_per_address (bfd *abfd);
25666 +
25667 +const bfd_arch_info_type *bfd_get_arch_info (bfd *abfd);
25668 +
25669 +const bfd_arch_info_type *bfd_lookup_arch
25670 +   (enum bfd_architecture arch, unsigned long machine);
25671 +
25672 +const char *bfd_printable_arch_mach
25673 +   (enum bfd_architecture arch, unsigned long machine);
25674 +
25675 +unsigned int bfd_octets_per_byte (bfd *abfd);
25676 +
25677 +unsigned int bfd_arch_mach_octets_per_byte
25678 +   (enum bfd_architecture arch, unsigned long machine);
25679 +
25680 +/* Extracted from reloc.c.  */
25681 +typedef enum bfd_reloc_status
25682 +{
25683 +  /* No errors detected.  */
25684 +  bfd_reloc_ok,
25685 +
25686 +  /* The relocation was performed, but there was an overflow.  */
25687 +  bfd_reloc_overflow,
25688 +
25689 +  /* The address to relocate was not within the section supplied.  */
25690 +  bfd_reloc_outofrange,
25691 +
25692 +  /* Used by special functions.  */
25693 +  bfd_reloc_continue,
25694 +
25695 +  /* Unsupported relocation size requested.  */
25696 +  bfd_reloc_notsupported,
25697 +
25698 +  /* Unused.  */
25699 +  bfd_reloc_other,
25700 +
25701 +  /* The symbol to relocate against was undefined.  */
25702 +  bfd_reloc_undefined,
25703 +
25704 +  /* The relocation was performed, but may not be ok - presently
25705 +     generated only when linking i960 coff files with i960 b.out
25706 +     symbols.  If this type is returned, the error_message argument
25707 +     to bfd_perform_relocation will be set.  */
25708 +  bfd_reloc_dangerous
25709 + }
25710 + bfd_reloc_status_type;
25711 +
25712 +
25713 +typedef struct reloc_cache_entry
25714 +{
25715 +  /* A pointer into the canonical table of pointers.  */
25716 +  struct bfd_symbol **sym_ptr_ptr;
25717 +
25718 +  /* offset in section.  */
25719 +  bfd_size_type address;
25720 +
25721 +  /* addend for relocation value.  */
25722 +  bfd_vma addend;
25723 +
25724 +  /* Pointer to how to perform the required relocation.  */
25725 +  reloc_howto_type *howto;
25726 +
25727 +}
25728 +arelent;
25729 +
25730 +enum complain_overflow
25731 +{
25732 +  /* Do not complain on overflow.  */
25733 +  complain_overflow_dont,
25734 +
25735 +  /* Complain if the bitfield overflows, whether it is considered
25736 +     as signed or unsigned.  */
25737 +  complain_overflow_bitfield,
25738 +
25739 +  /* Complain if the value overflows when considered as signed
25740 +     number.  */
25741 +  complain_overflow_signed,
25742 +
25743 +  /* Complain if the value overflows when considered as an
25744 +     unsigned number.  */
25745 +  complain_overflow_unsigned
25746 +};
25747 +
25748 +struct reloc_howto_struct
25749 +{
25750 +  /*  The type field has mainly a documentary use - the back end can
25751 +      do what it wants with it, though normally the back end's
25752 +      external idea of what a reloc number is stored
25753 +      in this field.  For example, a PC relative word relocation
25754 +      in a coff environment has the type 023 - because that's
25755 +      what the outside world calls a R_PCRWORD reloc.  */
25756 +  unsigned int type;
25757 +
25758 +  /*  The value the final relocation is shifted right by.  This drops
25759 +      unwanted data from the relocation.  */
25760 +  unsigned int rightshift;
25761 +
25762 +  /*  The size of the item to be relocated.  This is *not* a
25763 +      power-of-two measure.  To get the number of bytes operated
25764 +      on by a type of relocation, use bfd_get_reloc_size.  */
25765 +  int size;
25766 +
25767 +  /*  The number of bits in the item to be relocated.  This is used
25768 +      when doing overflow checking.  */
25769 +  unsigned int bitsize;
25770 +
25771 +  /*  Notes that the relocation is relative to the location in the
25772 +      data section of the addend.  The relocation function will
25773 +      subtract from the relocation value the address of the location
25774 +      being relocated.  */
25775 +  bfd_boolean pc_relative;
25776 +
25777 +  /*  The bit position of the reloc value in the destination.
25778 +      The relocated value is left shifted by this amount.  */
25779 +  unsigned int bitpos;
25780 +
25781 +  /* What type of overflow error should be checked for when
25782 +     relocating.  */
25783 +  enum complain_overflow complain_on_overflow;
25784 +
25785 +  /* If this field is non null, then the supplied function is
25786 +     called rather than the normal function.  This allows really
25787 +     strange relocation methods to be accommodated (e.g., i960 callj
25788 +     instructions).  */
25789 +  bfd_reloc_status_type (*special_function)
25790 +    (bfd *, arelent *, struct bfd_symbol *, void *, asection *,
25791 +     bfd *, char **);
25792 +
25793 +  /* The textual name of the relocation type.  */
25794 +  char *name;
25795 +
25796 +  /* Some formats record a relocation addend in the section contents
25797 +     rather than with the relocation.  For ELF formats this is the
25798 +     distinction between USE_REL and USE_RELA (though the code checks
25799 +     for USE_REL == 1/0).  The value of this field is TRUE if the
25800 +     addend is recorded with the section contents; when performing a
25801 +     partial link (ld -r) the section contents (the data) will be
25802 +     modified.  The value of this field is FALSE if addends are
25803 +     recorded with the relocation (in arelent.addend); when performing
25804 +     a partial link the relocation will be modified.
25805 +     All relocations for all ELF USE_RELA targets should set this field
25806 +     to FALSE (values of TRUE should be looked on with suspicion).
25807 +     However, the converse is not true: not all relocations of all ELF
25808 +     USE_REL targets set this field to TRUE.  Why this is so is peculiar
25809 +     to each particular target.  For relocs that aren't used in partial
25810 +     links (e.g. GOT stuff) it doesn't matter what this is set to.  */
25811 +  bfd_boolean partial_inplace;
25812 +
25813 +  /* src_mask selects the part of the instruction (or data) to be used
25814 +     in the relocation sum.  If the target relocations don't have an
25815 +     addend in the reloc, eg. ELF USE_REL, src_mask will normally equal
25816 +     dst_mask to extract the addend from the section contents.  If
25817 +     relocations do have an addend in the reloc, eg. ELF USE_RELA, this
25818 +     field should be zero.  Non-zero values for ELF USE_RELA targets are
25819 +     bogus as in those cases the value in the dst_mask part of the
25820 +     section contents should be treated as garbage.  */
25821 +  bfd_vma src_mask;
25822 +
25823 +  /* dst_mask selects which parts of the instruction (or data) are
25824 +     replaced with a relocated value.  */
25825 +  bfd_vma dst_mask;
25826 +
25827 +  /* When some formats create PC relative instructions, they leave
25828 +     the value of the pc of the place being relocated in the offset
25829 +     slot of the instruction, so that a PC relative relocation can
25830 +     be made just by adding in an ordinary offset (e.g., sun3 a.out).
25831 +     Some formats leave the displacement part of an instruction
25832 +     empty (e.g., m88k bcs); this flag signals the fact.  */
25833 +  bfd_boolean pcrel_offset;
25834 +};
25835 +
25836 +#define HOWTO(C, R, S, B, P, BI, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC) \
25837 +  { (unsigned) C, R, S, B, P, BI, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC }
25838 +#define NEWHOWTO(FUNCTION, NAME, SIZE, REL, IN) \
25839 +  HOWTO (0, 0, SIZE, 0, REL, 0, complain_overflow_dont, FUNCTION, \
25840 +         NAME, FALSE, 0, 0, IN)
25841 +
25842 +#define EMPTY_HOWTO(C) \
25843 +  HOWTO ((C), 0, 0, 0, FALSE, 0, complain_overflow_dont, NULL, \
25844 +         NULL, FALSE, 0, 0, FALSE)
25845 +
25846 +#define HOWTO_PREPARE(relocation, symbol)               \
25847 +  {                                                     \
25848 +    if (symbol != NULL)                                 \
25849 +      {                                                 \
25850 +        if (bfd_is_com_section (symbol->section))       \
25851 +          {                                             \
25852 +            relocation = 0;                             \
25853 +          }                                             \
25854 +        else                                            \
25855 +          {                                             \
25856 +            relocation = symbol->value;                 \
25857 +          }                                             \
25858 +      }                                                 \
25859 +  }
25860 +
25861 +unsigned int bfd_get_reloc_size (reloc_howto_type *);
25862 +
25863 +typedef struct relent_chain
25864 +{
25865 +  arelent relent;
25866 +  struct relent_chain *next;
25867 +}
25868 +arelent_chain;
25869 +
25870 +bfd_reloc_status_type bfd_check_overflow
25871 +   (enum complain_overflow how,
25872 +    unsigned int bitsize,
25873 +    unsigned int rightshift,
25874 +    unsigned int addrsize,
25875 +    bfd_vma relocation);
25876 +
25877 +bfd_reloc_status_type bfd_perform_relocation
25878 +   (bfd *abfd,
25879 +    arelent *reloc_entry,
25880 +    void *data,
25881 +    asection *input_section,
25882 +    bfd *output_bfd,
25883 +    char **error_message);
25884 +
25885 +bfd_reloc_status_type bfd_install_relocation
25886 +   (bfd *abfd,
25887 +    arelent *reloc_entry,
25888 +    void *data, bfd_vma data_start,
25889 +    asection *input_section,
25890 +    char **error_message);
25891 +
25892 +enum bfd_reloc_code_real {
25893 +  _dummy_first_bfd_reloc_code_real,
25894 +
25895 +
25896 +/* Basic absolute relocations of N bits.  */
25897 +  BFD_RELOC_64,
25898 +  BFD_RELOC_32,
25899 +  BFD_RELOC_26,
25900 +  BFD_RELOC_24,
25901 +  BFD_RELOC_16,
25902 +  BFD_RELOC_14,
25903 +  BFD_RELOC_8,
25904 +
25905 +/* PC-relative relocations.  Sometimes these are relative to the address
25906 +of the relocation itself; sometimes they are relative to the start of
25907 +the section containing the relocation.  It depends on the specific target.
25908 +
25909 +The 24-bit relocation is used in some Intel 960 configurations.  */
25910 +  BFD_RELOC_64_PCREL,
25911 +  BFD_RELOC_32_PCREL,
25912 +  BFD_RELOC_24_PCREL,
25913 +  BFD_RELOC_16_PCREL,
25914 +  BFD_RELOC_12_PCREL,
25915 +  BFD_RELOC_8_PCREL,
25916 +
25917 +/* Section relative relocations.  Some targets need this for DWARF2.  */
25918 +  BFD_RELOC_32_SECREL,
25919 +
25920 +/* For ELF.  */
25921 +  BFD_RELOC_32_GOT_PCREL,
25922 +  BFD_RELOC_16_GOT_PCREL,
25923 +  BFD_RELOC_8_GOT_PCREL,
25924 +  BFD_RELOC_32_GOTOFF,
25925 +  BFD_RELOC_16_GOTOFF,
25926 +  BFD_RELOC_LO16_GOTOFF,
25927 +  BFD_RELOC_HI16_GOTOFF,
25928 +  BFD_RELOC_HI16_S_GOTOFF,
25929 +  BFD_RELOC_8_GOTOFF,
25930 +  BFD_RELOC_64_PLT_PCREL,
25931 +  BFD_RELOC_32_PLT_PCREL,
25932 +  BFD_RELOC_24_PLT_PCREL,
25933 +  BFD_RELOC_16_PLT_PCREL,
25934 +  BFD_RELOC_8_PLT_PCREL,
25935 +  BFD_RELOC_64_PLTOFF,
25936 +  BFD_RELOC_32_PLTOFF,
25937 +  BFD_RELOC_16_PLTOFF,
25938 +  BFD_RELOC_LO16_PLTOFF,
25939 +  BFD_RELOC_HI16_PLTOFF,
25940 +  BFD_RELOC_HI16_S_PLTOFF,
25941 +  BFD_RELOC_8_PLTOFF,
25942 +
25943 +/* Relocations used by 68K ELF.  */
25944 +  BFD_RELOC_68K_GLOB_DAT,
25945 +  BFD_RELOC_68K_JMP_SLOT,
25946 +  BFD_RELOC_68K_RELATIVE,
25947 +
25948 +/* Linkage-table relative.  */
25949 +  BFD_RELOC_32_BASEREL,
25950 +  BFD_RELOC_16_BASEREL,
25951 +  BFD_RELOC_LO16_BASEREL,
25952 +  BFD_RELOC_HI16_BASEREL,
25953 +  BFD_RELOC_HI16_S_BASEREL,
25954 +  BFD_RELOC_8_BASEREL,
25955 +  BFD_RELOC_RVA,
25956 +
25957 +/* Absolute 8-bit relocation, but used to form an address like 0xFFnn.  */
25958 +  BFD_RELOC_8_FFnn,
25959 +
25960 +/* These PC-relative relocations are stored as word displacements --
25961 +i.e., byte displacements shifted right two bits.  The 30-bit word
25962 +displacement (<<32_PCREL_S2>> -- 32 bits, shifted 2) is used on the
25963 +SPARC.  (SPARC tools generally refer to this as <<WDISP30>>.)  The
25964 +signed 16-bit displacement is used on the MIPS, and the 23-bit
25965 +displacement is used on the Alpha.  */
25966 +  BFD_RELOC_32_PCREL_S2,
25967 +  BFD_RELOC_16_PCREL_S2,
25968 +  BFD_RELOC_23_PCREL_S2,
25969 +
25970 +/* High 22 bits and low 10 bits of 32-bit value, placed into lower bits of
25971 +the target word.  These are used on the SPARC.  */
25972 +  BFD_RELOC_HI22,
25973 +  BFD_RELOC_LO10,
25974 +
25975 +/* For systems that allocate a Global Pointer register, these are
25976 +displacements off that register.  These relocation types are
25977 +handled specially, because the value the register will have is
25978 +decided relatively late.  */
25979 +  BFD_RELOC_GPREL16,
25980 +  BFD_RELOC_GPREL32,
25981 +
25982 +/* Reloc types used for i960/b.out.  */
25983 +  BFD_RELOC_I960_CALLJ,
25984 +
25985 +/* SPARC ELF relocations.  There is probably some overlap with other
25986 +relocation types already defined.  */
25987 +  BFD_RELOC_NONE,
25988 +  BFD_RELOC_SPARC_WDISP22,
25989 +  BFD_RELOC_SPARC22,
25990 +  BFD_RELOC_SPARC13,
25991 +  BFD_RELOC_SPARC_GOT10,
25992 +  BFD_RELOC_SPARC_GOT13,
25993 +  BFD_RELOC_SPARC_GOT22,
25994 +  BFD_RELOC_SPARC_PC10,
25995 +  BFD_RELOC_SPARC_PC22,
25996 +  BFD_RELOC_SPARC_WPLT30,
25997 +  BFD_RELOC_SPARC_COPY,
25998 +  BFD_RELOC_SPARC_GLOB_DAT,
25999 +  BFD_RELOC_SPARC_JMP_SLOT,
26000 +  BFD_RELOC_SPARC_RELATIVE,
26001 +  BFD_RELOC_SPARC_UA16,
26002 +  BFD_RELOC_SPARC_UA32,
26003 +  BFD_RELOC_SPARC_UA64,
26004 +
26005 +/* I think these are specific to SPARC a.out (e.g., Sun 4).  */
26006 +  BFD_RELOC_SPARC_BASE13,
26007 +  BFD_RELOC_SPARC_BASE22,
26008 +
26009 +/* SPARC64 relocations  */
26010 +#define BFD_RELOC_SPARC_64 BFD_RELOC_64
26011 +  BFD_RELOC_SPARC_10,
26012 +  BFD_RELOC_SPARC_11,
26013 +  BFD_RELOC_SPARC_OLO10,
26014 +  BFD_RELOC_SPARC_HH22,
26015 +  BFD_RELOC_SPARC_HM10,
26016 +  BFD_RELOC_SPARC_LM22,
26017 +  BFD_RELOC_SPARC_PC_HH22,
26018 +  BFD_RELOC_SPARC_PC_HM10,
26019 +  BFD_RELOC_SPARC_PC_LM22,
26020 +  BFD_RELOC_SPARC_WDISP16,
26021 +  BFD_RELOC_SPARC_WDISP19,
26022 +  BFD_RELOC_SPARC_7,
26023 +  BFD_RELOC_SPARC_6,
26024 +  BFD_RELOC_SPARC_5,
26025 +#define BFD_RELOC_SPARC_DISP64 BFD_RELOC_64_PCREL
26026 +  BFD_RELOC_SPARC_PLT32,
26027 +  BFD_RELOC_SPARC_PLT64,
26028 +  BFD_RELOC_SPARC_HIX22,
26029 +  BFD_RELOC_SPARC_LOX10,
26030 +  BFD_RELOC_SPARC_H44,
26031 +  BFD_RELOC_SPARC_M44,
26032 +  BFD_RELOC_SPARC_L44,
26033 +  BFD_RELOC_SPARC_REGISTER,
26034 +
26035 +/* SPARC little endian relocation  */
26036 +  BFD_RELOC_SPARC_REV32,
26037 +
26038 +/* SPARC TLS relocations  */
26039 +  BFD_RELOC_SPARC_TLS_GD_HI22,
26040 +  BFD_RELOC_SPARC_TLS_GD_LO10,
26041 +  BFD_RELOC_SPARC_TLS_GD_ADD,
26042 +  BFD_RELOC_SPARC_TLS_GD_CALL,
26043 +  BFD_RELOC_SPARC_TLS_LDM_HI22,
26044 +  BFD_RELOC_SPARC_TLS_LDM_LO10,
26045 +  BFD_RELOC_SPARC_TLS_LDM_ADD,
26046 +  BFD_RELOC_SPARC_TLS_LDM_CALL,
26047 +  BFD_RELOC_SPARC_TLS_LDO_HIX22,
26048 +  BFD_RELOC_SPARC_TLS_LDO_LOX10,
26049 +  BFD_RELOC_SPARC_TLS_LDO_ADD,
26050 +  BFD_RELOC_SPARC_TLS_IE_HI22,
26051 +  BFD_RELOC_SPARC_TLS_IE_LO10,
26052 +  BFD_RELOC_SPARC_TLS_IE_LD,
26053 +  BFD_RELOC_SPARC_TLS_IE_LDX,
26054 +  BFD_RELOC_SPARC_TLS_IE_ADD,
26055 +  BFD_RELOC_SPARC_TLS_LE_HIX22,
26056 +  BFD_RELOC_SPARC_TLS_LE_LOX10,
26057 +  BFD_RELOC_SPARC_TLS_DTPMOD32,
26058 +  BFD_RELOC_SPARC_TLS_DTPMOD64,
26059 +  BFD_RELOC_SPARC_TLS_DTPOFF32,
26060 +  BFD_RELOC_SPARC_TLS_DTPOFF64,
26061 +  BFD_RELOC_SPARC_TLS_TPOFF32,
26062 +  BFD_RELOC_SPARC_TLS_TPOFF64,
26063 +
26064 +/* Alpha ECOFF and ELF relocations.  Some of these treat the symbol or
26065 +"addend" in some special way.
26066 +For GPDISP_HI16 ("gpdisp") relocations, the symbol is ignored when
26067 +writing; when reading, it will be the absolute section symbol.  The
26068 +addend is the displacement in bytes of the "lda" instruction from
26069 +the "ldah" instruction (which is at the address of this reloc).  */
26070 +  BFD_RELOC_ALPHA_GPDISP_HI16,
26071 +
26072 +/* For GPDISP_LO16 ("ignore") relocations, the symbol is handled as
26073 +with GPDISP_HI16 relocs.  The addend is ignored when writing the
26074 +relocations out, and is filled in with the file's GP value on
26075 +reading, for convenience.  */
26076 +  BFD_RELOC_ALPHA_GPDISP_LO16,
26077 +
26078 +/* The ELF GPDISP relocation is exactly the same as the GPDISP_HI16
26079 +relocation except that there is no accompanying GPDISP_LO16
26080 +relocation.  */
26081 +  BFD_RELOC_ALPHA_GPDISP,
26082 +
26083 +/* The Alpha LITERAL/LITUSE relocs are produced by a symbol reference;
26084 +the assembler turns it into a LDQ instruction to load the address of
26085 +the symbol, and then fills in a register in the real instruction.
26086 +
26087 +The LITERAL reloc, at the LDQ instruction, refers to the .lita
26088 +section symbol.  The addend is ignored when writing, but is filled
26089 +in with the file's GP value on reading, for convenience, as with the
26090 +GPDISP_LO16 reloc.
26091 +
26092 +The ELF_LITERAL reloc is somewhere between 16_GOTOFF and GPDISP_LO16.
26093 +It should refer to the symbol to be referenced, as with 16_GOTOFF,
26094 +but it generates output not based on the position within the .got
26095 +section, but relative to the GP value chosen for the file during the
26096 +final link stage.
26097 +
26098 +The LITUSE reloc, on the instruction using the loaded address, gives
26099 +information to the linker that it might be able to use to optimize
26100 +away some literal section references.  The symbol is ignored (read
26101 +as the absolute section symbol), and the "addend" indicates the type
26102 +of instruction using the register:
26103 +1 - "memory" fmt insn
26104 +2 - byte-manipulation (byte offset reg)
26105 +3 - jsr (target of branch)  */
26106 +  BFD_RELOC_ALPHA_LITERAL,
26107 +  BFD_RELOC_ALPHA_ELF_LITERAL,
26108 +  BFD_RELOC_ALPHA_LITUSE,
26109 +
26110 +/* The HINT relocation indicates a value that should be filled into the
26111 +"hint" field of a jmp/jsr/ret instruction, for possible branch-
26112 +prediction logic which may be provided on some processors.  */
26113 +  BFD_RELOC_ALPHA_HINT,
26114 +
26115 +/* The LINKAGE relocation outputs a linkage pair in the object file,
26116 +which is filled by the linker.  */
26117 +  BFD_RELOC_ALPHA_LINKAGE,
26118 +
26119 +/* The CODEADDR relocation outputs a STO_CA in the object file,
26120 +which is filled by the linker.  */
26121 +  BFD_RELOC_ALPHA_CODEADDR,
26122 +
26123 +/* The GPREL_HI/LO relocations together form a 32-bit offset from the
26124 +GP register.  */
26125 +  BFD_RELOC_ALPHA_GPREL_HI16,
26126 +  BFD_RELOC_ALPHA_GPREL_LO16,
26127 +
26128 +/* Like BFD_RELOC_23_PCREL_S2, except that the source and target must
26129 +share a common GP, and the target address is adjusted for
26130 +STO_ALPHA_STD_GPLOAD.  */
26131 +  BFD_RELOC_ALPHA_BRSGP,
26132 +
26133 +/* Alpha thread-local storage relocations.  */
26134 +  BFD_RELOC_ALPHA_TLSGD,
26135 +  BFD_RELOC_ALPHA_TLSLDM,
26136 +  BFD_RELOC_ALPHA_DTPMOD64,
26137 +  BFD_RELOC_ALPHA_GOTDTPREL16,
26138 +  BFD_RELOC_ALPHA_DTPREL64,
26139 +  BFD_RELOC_ALPHA_DTPREL_HI16,
26140 +  BFD_RELOC_ALPHA_DTPREL_LO16,
26141 +  BFD_RELOC_ALPHA_DTPREL16,
26142 +  BFD_RELOC_ALPHA_GOTTPREL16,
26143 +  BFD_RELOC_ALPHA_TPREL64,
26144 +  BFD_RELOC_ALPHA_TPREL_HI16,
26145 +  BFD_RELOC_ALPHA_TPREL_LO16,
26146 +  BFD_RELOC_ALPHA_TPREL16,
26147 +
26148 +/* Bits 27..2 of the relocation address shifted right 2 bits;
26149 +simple reloc otherwise.  */
26150 +  BFD_RELOC_MIPS_JMP,
26151 +
26152 +/* The MIPS16 jump instruction.  */
26153 +  BFD_RELOC_MIPS16_JMP,
26154 +
26155 +/* MIPS16 GP relative reloc.  */
26156 +  BFD_RELOC_MIPS16_GPREL,
26157 +
26158 +/* High 16 bits of 32-bit value; simple reloc.  */
26159 +  BFD_RELOC_HI16,
26160 +
26161 +/* High 16 bits of 32-bit value but the low 16 bits will be sign
26162 +extended and added to form the final result.  If the low 16
26163 +bits form a negative number, we need to add one to the high value
26164 +to compensate for the borrow when the low bits are added.  */
26165 +  BFD_RELOC_HI16_S,
26166 +
26167 +/* Low 16 bits.  */
26168 +  BFD_RELOC_LO16,
26169 +
26170 +/* High 16 bits of 32-bit pc-relative value  */
26171 +  BFD_RELOC_HI16_PCREL,
26172 +
26173 +/* High 16 bits of 32-bit pc-relative value, adjusted  */
26174 +  BFD_RELOC_HI16_S_PCREL,
26175 +
26176 +/* Low 16 bits of pc-relative value  */
26177 +  BFD_RELOC_LO16_PCREL,
26178 +
26179 +/* MIPS16 high 16 bits of 32-bit value.  */
26180 +  BFD_RELOC_MIPS16_HI16,
26181 +
26182 +/* MIPS16 high 16 bits of 32-bit value but the low 16 bits will be sign
26183 +extended and added to form the final result.  If the low 16
26184 +bits form a negative number, we need to add one to the high value
26185 +to compensate for the borrow when the low bits are added.  */
26186 +  BFD_RELOC_MIPS16_HI16_S,
26187 +
26188 +/* MIPS16 low 16 bits.  */
26189 +  BFD_RELOC_MIPS16_LO16,
26190 +
26191 +/* Relocation against a MIPS literal section.  */
26192 +  BFD_RELOC_MIPS_LITERAL,
26193 +
26194 +/* MIPS ELF relocations.  */
26195 +  BFD_RELOC_MIPS_GOT16,
26196 +  BFD_RELOC_MIPS_CALL16,
26197 +  BFD_RELOC_MIPS_GOT_HI16,
26198 +  BFD_RELOC_MIPS_GOT_LO16,
26199 +  BFD_RELOC_MIPS_CALL_HI16,
26200 +  BFD_RELOC_MIPS_CALL_LO16,
26201 +  BFD_RELOC_MIPS_SUB,
26202 +  BFD_RELOC_MIPS_GOT_PAGE,
26203 +  BFD_RELOC_MIPS_GOT_OFST,
26204 +  BFD_RELOC_MIPS_GOT_DISP,
26205 +  BFD_RELOC_MIPS_SHIFT5,
26206 +  BFD_RELOC_MIPS_SHIFT6,
26207 +  BFD_RELOC_MIPS_INSERT_A,
26208 +  BFD_RELOC_MIPS_INSERT_B,
26209 +  BFD_RELOC_MIPS_DELETE,
26210 +  BFD_RELOC_MIPS_HIGHEST,
26211 +  BFD_RELOC_MIPS_HIGHER,
26212 +  BFD_RELOC_MIPS_SCN_DISP,
26213 +  BFD_RELOC_MIPS_REL16,
26214 +  BFD_RELOC_MIPS_RELGOT,
26215 +  BFD_RELOC_MIPS_JALR,
26216 +  BFD_RELOC_MIPS_TLS_DTPMOD32,
26217 +  BFD_RELOC_MIPS_TLS_DTPREL32,
26218 +  BFD_RELOC_MIPS_TLS_DTPMOD64,
26219 +  BFD_RELOC_MIPS_TLS_DTPREL64,
26220 +  BFD_RELOC_MIPS_TLS_GD,
26221 +  BFD_RELOC_MIPS_TLS_LDM,
26222 +  BFD_RELOC_MIPS_TLS_DTPREL_HI16,
26223 +  BFD_RELOC_MIPS_TLS_DTPREL_LO16,
26224 +  BFD_RELOC_MIPS_TLS_GOTTPREL,
26225 +  BFD_RELOC_MIPS_TLS_TPREL32,
26226 +  BFD_RELOC_MIPS_TLS_TPREL64,
26227 +  BFD_RELOC_MIPS_TLS_TPREL_HI16,
26228 +  BFD_RELOC_MIPS_TLS_TPREL_LO16,
26229 +
26230 +
26231 +/* Fujitsu Frv Relocations.  */
26232 +  BFD_RELOC_FRV_LABEL16,
26233 +  BFD_RELOC_FRV_LABEL24,
26234 +  BFD_RELOC_FRV_LO16,
26235 +  BFD_RELOC_FRV_HI16,
26236 +  BFD_RELOC_FRV_GPREL12,
26237 +  BFD_RELOC_FRV_GPRELU12,
26238 +  BFD_RELOC_FRV_GPREL32,
26239 +  BFD_RELOC_FRV_GPRELHI,
26240 +  BFD_RELOC_FRV_GPRELLO,
26241 +  BFD_RELOC_FRV_GOT12,
26242 +  BFD_RELOC_FRV_GOTHI,
26243 +  BFD_RELOC_FRV_GOTLO,
26244 +  BFD_RELOC_FRV_FUNCDESC,
26245 +  BFD_RELOC_FRV_FUNCDESC_GOT12,
26246 +  BFD_RELOC_FRV_FUNCDESC_GOTHI,
26247 +  BFD_RELOC_FRV_FUNCDESC_GOTLO,
26248 +  BFD_RELOC_FRV_FUNCDESC_VALUE,
26249 +  BFD_RELOC_FRV_FUNCDESC_GOTOFF12,
26250 +  BFD_RELOC_FRV_FUNCDESC_GOTOFFHI,
26251 +  BFD_RELOC_FRV_FUNCDESC_GOTOFFLO,
26252 +  BFD_RELOC_FRV_GOTOFF12,
26253 +  BFD_RELOC_FRV_GOTOFFHI,
26254 +  BFD_RELOC_FRV_GOTOFFLO,
26255 +  BFD_RELOC_FRV_GETTLSOFF,
26256 +  BFD_RELOC_FRV_TLSDESC_VALUE,
26257 +  BFD_RELOC_FRV_GOTTLSDESC12,
26258 +  BFD_RELOC_FRV_GOTTLSDESCHI,
26259 +  BFD_RELOC_FRV_GOTTLSDESCLO,
26260 +  BFD_RELOC_FRV_TLSMOFF12,
26261 +  BFD_RELOC_FRV_TLSMOFFHI,
26262 +  BFD_RELOC_FRV_TLSMOFFLO,
26263 +  BFD_RELOC_FRV_GOTTLSOFF12,
26264 +  BFD_RELOC_FRV_GOTTLSOFFHI,
26265 +  BFD_RELOC_FRV_GOTTLSOFFLO,
26266 +  BFD_RELOC_FRV_TLSOFF,
26267 +  BFD_RELOC_FRV_TLSDESC_RELAX,
26268 +  BFD_RELOC_FRV_GETTLSOFF_RELAX,
26269 +  BFD_RELOC_FRV_TLSOFF_RELAX,
26270 +  BFD_RELOC_FRV_TLSMOFF,
26271 +
26272 +
26273 +/* This is a 24bit GOT-relative reloc for the mn10300.  */
26274 +  BFD_RELOC_MN10300_GOTOFF24,
26275 +
26276 +/* This is a 32bit GOT-relative reloc for the mn10300, offset by two bytes
26277 +in the instruction.  */
26278 +  BFD_RELOC_MN10300_GOT32,
26279 +
26280 +/* This is a 24bit GOT-relative reloc for the mn10300, offset by two bytes
26281 +in the instruction.  */
26282 +  BFD_RELOC_MN10300_GOT24,
26283 +
26284 +/* This is a 16bit GOT-relative reloc for the mn10300, offset by two bytes
26285 +in the instruction.  */
26286 +  BFD_RELOC_MN10300_GOT16,
26287 +
26288 +/* Copy symbol at runtime.  */
26289 +  BFD_RELOC_MN10300_COPY,
26290 +
26291 +/* Create GOT entry.  */
26292 +  BFD_RELOC_MN10300_GLOB_DAT,
26293 +
26294 +/* Create PLT entry.  */
26295 +  BFD_RELOC_MN10300_JMP_SLOT,
26296 +
26297 +/* Adjust by program base.  */
26298 +  BFD_RELOC_MN10300_RELATIVE,
26299 +
26300 +
26301 +/* i386/elf relocations  */
26302 +  BFD_RELOC_386_GOT32,
26303 +  BFD_RELOC_386_PLT32,
26304 +  BFD_RELOC_386_COPY,
26305 +  BFD_RELOC_386_GLOB_DAT,
26306 +  BFD_RELOC_386_JUMP_SLOT,
26307 +  BFD_RELOC_386_RELATIVE,
26308 +  BFD_RELOC_386_GOTOFF,
26309 +  BFD_RELOC_386_GOTPC,
26310 +  BFD_RELOC_386_TLS_TPOFF,
26311 +  BFD_RELOC_386_TLS_IE,
26312 +  BFD_RELOC_386_TLS_GOTIE,
26313 +  BFD_RELOC_386_TLS_LE,
26314 +  BFD_RELOC_386_TLS_GD,
26315 +  BFD_RELOC_386_TLS_LDM,
26316 +  BFD_RELOC_386_TLS_LDO_32,
26317 +  BFD_RELOC_386_TLS_IE_32,
26318 +  BFD_RELOC_386_TLS_LE_32,
26319 +  BFD_RELOC_386_TLS_DTPMOD32,
26320 +  BFD_RELOC_386_TLS_DTPOFF32,
26321 +  BFD_RELOC_386_TLS_TPOFF32,
26322 +
26323 +/* x86-64/elf relocations  */
26324 +  BFD_RELOC_X86_64_GOT32,
26325 +  BFD_RELOC_X86_64_PLT32,
26326 +  BFD_RELOC_X86_64_COPY,
26327 +  BFD_RELOC_X86_64_GLOB_DAT,
26328 +  BFD_RELOC_X86_64_JUMP_SLOT,
26329 +  BFD_RELOC_X86_64_RELATIVE,
26330 +  BFD_RELOC_X86_64_GOTPCREL,
26331 +  BFD_RELOC_X86_64_32S,
26332 +  BFD_RELOC_X86_64_DTPMOD64,
26333 +  BFD_RELOC_X86_64_DTPOFF64,
26334 +  BFD_RELOC_X86_64_TPOFF64,
26335 +  BFD_RELOC_X86_64_TLSGD,
26336 +  BFD_RELOC_X86_64_TLSLD,
26337 +  BFD_RELOC_X86_64_DTPOFF32,
26338 +  BFD_RELOC_X86_64_GOTTPOFF,
26339 +  BFD_RELOC_X86_64_TPOFF32,
26340 +  BFD_RELOC_X86_64_GOTOFF64,
26341 +  BFD_RELOC_X86_64_GOTPC32,
26342 +
26343 +/* ns32k relocations  */
26344 +  BFD_RELOC_NS32K_IMM_8,
26345 +  BFD_RELOC_NS32K_IMM_16,
26346 +  BFD_RELOC_NS32K_IMM_32,
26347 +  BFD_RELOC_NS32K_IMM_8_PCREL,
26348 +  BFD_RELOC_NS32K_IMM_16_PCREL,
26349 +  BFD_RELOC_NS32K_IMM_32_PCREL,
26350 +  BFD_RELOC_NS32K_DISP_8,
26351 +  BFD_RELOC_NS32K_DISP_16,
26352 +  BFD_RELOC_NS32K_DISP_32,
26353 +  BFD_RELOC_NS32K_DISP_8_PCREL,
26354 +  BFD_RELOC_NS32K_DISP_16_PCREL,
26355 +  BFD_RELOC_NS32K_DISP_32_PCREL,
26356 +
26357 +/* PDP11 relocations  */
26358 +  BFD_RELOC_PDP11_DISP_8_PCREL,
26359 +  BFD_RELOC_PDP11_DISP_6_PCREL,
26360 +
26361 +/* Picojava relocs.  Not all of these appear in object files.  */
26362 +  BFD_RELOC_PJ_CODE_HI16,
26363 +  BFD_RELOC_PJ_CODE_LO16,
26364 +  BFD_RELOC_PJ_CODE_DIR16,
26365 +  BFD_RELOC_PJ_CODE_DIR32,
26366 +  BFD_RELOC_PJ_CODE_REL16,
26367 +  BFD_RELOC_PJ_CODE_REL32,
26368 +
26369 +/* Power(rs6000) and PowerPC relocations.  */
26370 +  BFD_RELOC_PPC_B26,
26371 +  BFD_RELOC_PPC_BA26,
26372 +  BFD_RELOC_PPC_TOC16,
26373 +  BFD_RELOC_PPC_B16,
26374 +  BFD_RELOC_PPC_B16_BRTAKEN,
26375 +  BFD_RELOC_PPC_B16_BRNTAKEN,
26376 +  BFD_RELOC_PPC_BA16,
26377 +  BFD_RELOC_PPC_BA16_BRTAKEN,
26378 +  BFD_RELOC_PPC_BA16_BRNTAKEN,
26379 +  BFD_RELOC_PPC_COPY,
26380 +  BFD_RELOC_PPC_GLOB_DAT,
26381 +  BFD_RELOC_PPC_JMP_SLOT,
26382 +  BFD_RELOC_PPC_RELATIVE,
26383 +  BFD_RELOC_PPC_LOCAL24PC,
26384 +  BFD_RELOC_PPC_EMB_NADDR32,
26385 +  BFD_RELOC_PPC_EMB_NADDR16,
26386 +  BFD_RELOC_PPC_EMB_NADDR16_LO,
26387 +  BFD_RELOC_PPC_EMB_NADDR16_HI,
26388 +  BFD_RELOC_PPC_EMB_NADDR16_HA,
26389 +  BFD_RELOC_PPC_EMB_SDAI16,
26390 +  BFD_RELOC_PPC_EMB_SDA2I16,
26391 +  BFD_RELOC_PPC_EMB_SDA2REL,
26392 +  BFD_RELOC_PPC_EMB_SDA21,
26393 +  BFD_RELOC_PPC_EMB_MRKREF,
26394 +  BFD_RELOC_PPC_EMB_RELSEC16,
26395 +  BFD_RELOC_PPC_EMB_RELST_LO,
26396 +  BFD_RELOC_PPC_EMB_RELST_HI,
26397 +  BFD_RELOC_PPC_EMB_RELST_HA,
26398 +  BFD_RELOC_PPC_EMB_BIT_FLD,
26399 +  BFD_RELOC_PPC_EMB_RELSDA,
26400 +  BFD_RELOC_PPC64_HIGHER,
26401 +  BFD_RELOC_PPC64_HIGHER_S,
26402 +  BFD_RELOC_PPC64_HIGHEST,
26403 +  BFD_RELOC_PPC64_HIGHEST_S,
26404 +  BFD_RELOC_PPC64_TOC16_LO,
26405 +  BFD_RELOC_PPC64_TOC16_HI,
26406 +  BFD_RELOC_PPC64_TOC16_HA,
26407 +  BFD_RELOC_PPC64_TOC,
26408 +  BFD_RELOC_PPC64_PLTGOT16,
26409 +  BFD_RELOC_PPC64_PLTGOT16_LO,
26410 +  BFD_RELOC_PPC64_PLTGOT16_HI,
26411 +  BFD_RELOC_PPC64_PLTGOT16_HA,
26412 +  BFD_RELOC_PPC64_ADDR16_DS,
26413 +  BFD_RELOC_PPC64_ADDR16_LO_DS,
26414 +  BFD_RELOC_PPC64_GOT16_DS,
26415 +  BFD_RELOC_PPC64_GOT16_LO_DS,
26416 +  BFD_RELOC_PPC64_PLT16_LO_DS,
26417 +  BFD_RELOC_PPC64_SECTOFF_DS,
26418 +  BFD_RELOC_PPC64_SECTOFF_LO_DS,
26419 +  BFD_RELOC_PPC64_TOC16_DS,
26420 +  BFD_RELOC_PPC64_TOC16_LO_DS,
26421 +  BFD_RELOC_PPC64_PLTGOT16_DS,
26422 +  BFD_RELOC_PPC64_PLTGOT16_LO_DS,
26423 +
26424 +/* PowerPC and PowerPC64 thread-local storage relocations.  */
26425 +  BFD_RELOC_PPC_TLS,
26426 +  BFD_RELOC_PPC_DTPMOD,
26427 +  BFD_RELOC_PPC_TPREL16,
26428 +  BFD_RELOC_PPC_TPREL16_LO,
26429 +  BFD_RELOC_PPC_TPREL16_HI,
26430 +  BFD_RELOC_PPC_TPREL16_HA,
26431 +  BFD_RELOC_PPC_TPREL,
26432 +  BFD_RELOC_PPC_DTPREL16,
26433 +  BFD_RELOC_PPC_DTPREL16_LO,
26434 +  BFD_RELOC_PPC_DTPREL16_HI,
26435 +  BFD_RELOC_PPC_DTPREL16_HA,
26436 +  BFD_RELOC_PPC_DTPREL,
26437 +  BFD_RELOC_PPC_GOT_TLSGD16,
26438 +  BFD_RELOC_PPC_GOT_TLSGD16_LO,
26439 +  BFD_RELOC_PPC_GOT_TLSGD16_HI,
26440 +  BFD_RELOC_PPC_GOT_TLSGD16_HA,
26441 +  BFD_RELOC_PPC_GOT_TLSLD16,
26442 +  BFD_RELOC_PPC_GOT_TLSLD16_LO,
26443 +  BFD_RELOC_PPC_GOT_TLSLD16_HI,
26444 +  BFD_RELOC_PPC_GOT_TLSLD16_HA,
26445 +  BFD_RELOC_PPC_GOT_TPREL16,
26446 +  BFD_RELOC_PPC_GOT_TPREL16_LO,
26447 +  BFD_RELOC_PPC_GOT_TPREL16_HI,
26448 +  BFD_RELOC_PPC_GOT_TPREL16_HA,
26449 +  BFD_RELOC_PPC_GOT_DTPREL16,
26450 +  BFD_RELOC_PPC_GOT_DTPREL16_LO,
26451 +  BFD_RELOC_PPC_GOT_DTPREL16_HI,
26452 +  BFD_RELOC_PPC_GOT_DTPREL16_HA,
26453 +  BFD_RELOC_PPC64_TPREL16_DS,
26454 +  BFD_RELOC_PPC64_TPREL16_LO_DS,
26455 +  BFD_RELOC_PPC64_TPREL16_HIGHER,
26456 +  BFD_RELOC_PPC64_TPREL16_HIGHERA,
26457 +  BFD_RELOC_PPC64_TPREL16_HIGHEST,
26458 +  BFD_RELOC_PPC64_TPREL16_HIGHESTA,
26459 +  BFD_RELOC_PPC64_DTPREL16_DS,
26460 +  BFD_RELOC_PPC64_DTPREL16_LO_DS,
26461 +  BFD_RELOC_PPC64_DTPREL16_HIGHER,
26462 +  BFD_RELOC_PPC64_DTPREL16_HIGHERA,
26463 +  BFD_RELOC_PPC64_DTPREL16_HIGHEST,
26464 +  BFD_RELOC_PPC64_DTPREL16_HIGHESTA,
26465 +
26466 +/* IBM 370/390 relocations  */
26467 +  BFD_RELOC_I370_D12,
26468 +
26469 +/* The type of reloc used to build a constructor table - at the moment
26470 +probably a 32 bit wide absolute relocation, but the target can choose.
26471 +It generally does map to one of the other relocation types.  */
26472 +  BFD_RELOC_CTOR,
26473 +
26474 +/* ARM 26 bit pc-relative branch.  The lowest two bits must be zero and are
26475 +not stored in the instruction.  */
26476 +  BFD_RELOC_ARM_PCREL_BRANCH,
26477 +
26478 +/* ARM 26 bit pc-relative branch.  The lowest bit must be zero and is
26479 +not stored in the instruction.  The 2nd lowest bit comes from a 1 bit
26480 +field in the instruction.  */
26481 +  BFD_RELOC_ARM_PCREL_BLX,
26482 +
26483 +/* Thumb 22 bit pc-relative branch.  The lowest bit must be zero and is
26484 +not stored in the instruction.  The 2nd lowest bit comes from a 1 bit
26485 +field in the instruction.  */
26486 +  BFD_RELOC_THUMB_PCREL_BLX,
26487 +
26488 +/* Thumb 7-, 9-, 12-, 20-, 23-, and 25-bit pc-relative branches.
26489 +The lowest bit must be zero and is not stored in the instruction.
26490 +Note that the corresponding ELF R_ARM_THM_JUMPnn constant has an
26491 +"nn" one smaller in all cases.  Note further that BRANCH23
26492 +corresponds to R_ARM_THM_CALL.  */
26493 +  BFD_RELOC_THUMB_PCREL_BRANCH7,
26494 +  BFD_RELOC_THUMB_PCREL_BRANCH9,
26495 +  BFD_RELOC_THUMB_PCREL_BRANCH12,
26496 +  BFD_RELOC_THUMB_PCREL_BRANCH20,
26497 +  BFD_RELOC_THUMB_PCREL_BRANCH23,
26498 +  BFD_RELOC_THUMB_PCREL_BRANCH25,
26499 +
26500 +/* 12-bit immediate offset, used in ARM-format ldr and str instructions.  */
26501 +  BFD_RELOC_ARM_OFFSET_IMM,
26502 +
26503 +/* 5-bit immediate offset, used in Thumb-format ldr and str instructions.  */
26504 +  BFD_RELOC_ARM_THUMB_OFFSET,
26505 +
26506 +/* Pc-relative or absolute relocation depending on target.  Used for
26507 +entries in .init_array sections.  */
26508 +  BFD_RELOC_ARM_TARGET1,
26509 +
26510 +/* Read-only segment base relative address.  */
26511 +  BFD_RELOC_ARM_ROSEGREL32,
26512 +
26513 +/* Data segment base relative address.  */
26514 +  BFD_RELOC_ARM_SBREL32,
26515 +
26516 +/* This reloc is used for references to RTTI data from exception handling
26517 +tables.  The actual definition depends on the target.  It may be a
26518 +pc-relative or some form of GOT-indirect relocation.  */
26519 +  BFD_RELOC_ARM_TARGET2,
26520 +
26521 +/* 31-bit PC relative address.  */
26522 +  BFD_RELOC_ARM_PREL31,
26523 +
26524 +/* Relocations for setting up GOTs and PLTs for shared libraries.  */
26525 +  BFD_RELOC_ARM_JUMP_SLOT,
26526 +  BFD_RELOC_ARM_GLOB_DAT,
26527 +  BFD_RELOC_ARM_GOT32,
26528 +  BFD_RELOC_ARM_PLT32,
26529 +  BFD_RELOC_ARM_RELATIVE,
26530 +  BFD_RELOC_ARM_GOTOFF,
26531 +  BFD_RELOC_ARM_GOTPC,
26532 +
26533 +/* ARM thread-local storage relocations.  */
26534 +  BFD_RELOC_ARM_TLS_GD32,
26535 +  BFD_RELOC_ARM_TLS_LDO32,
26536 +  BFD_RELOC_ARM_TLS_LDM32,
26537 +  BFD_RELOC_ARM_TLS_DTPOFF32,
26538 +  BFD_RELOC_ARM_TLS_DTPMOD32,
26539 +  BFD_RELOC_ARM_TLS_TPOFF32,
26540 +  BFD_RELOC_ARM_TLS_IE32,
26541 +  BFD_RELOC_ARM_TLS_LE32,
26542 +
26543 +/* These relocs are only used within the ARM assembler.  They are not
26544 +(at present) written to any object files.  */
26545 +  BFD_RELOC_ARM_IMMEDIATE,
26546 +  BFD_RELOC_ARM_ADRL_IMMEDIATE,
26547 +  BFD_RELOC_ARM_T32_IMMEDIATE,
26548 +  BFD_RELOC_ARM_SHIFT_IMM,
26549 +  BFD_RELOC_ARM_SMI,
26550 +  BFD_RELOC_ARM_SWI,
26551 +  BFD_RELOC_ARM_MULTI,
26552 +  BFD_RELOC_ARM_CP_OFF_IMM,
26553 +  BFD_RELOC_ARM_CP_OFF_IMM_S2,
26554 +  BFD_RELOC_ARM_ADR_IMM,
26555 +  BFD_RELOC_ARM_LDR_IMM,
26556 +  BFD_RELOC_ARM_LITERAL,
26557 +  BFD_RELOC_ARM_IN_POOL,
26558 +  BFD_RELOC_ARM_OFFSET_IMM8,
26559 +  BFD_RELOC_ARM_T32_OFFSET_U8,
26560 +  BFD_RELOC_ARM_T32_OFFSET_IMM,
26561 +  BFD_RELOC_ARM_HWLITERAL,
26562 +  BFD_RELOC_ARM_THUMB_ADD,
26563 +  BFD_RELOC_ARM_THUMB_IMM,
26564 +  BFD_RELOC_ARM_THUMB_SHIFT,
26565 +
26566 +/* Renesas / SuperH SH relocs.  Not all of these appear in object files.  */
26567 +  BFD_RELOC_SH_PCDISP8BY2,
26568 +  BFD_RELOC_SH_PCDISP12BY2,
26569 +  BFD_RELOC_SH_IMM3,
26570 +  BFD_RELOC_SH_IMM3U,
26571 +  BFD_RELOC_SH_DISP12,
26572 +  BFD_RELOC_SH_DISP12BY2,
26573 +  BFD_RELOC_SH_DISP12BY4,
26574 +  BFD_RELOC_SH_DISP12BY8,
26575 +  BFD_RELOC_SH_DISP20,
26576 +  BFD_RELOC_SH_DISP20BY8,
26577 +  BFD_RELOC_SH_IMM4,
26578 +  BFD_RELOC_SH_IMM4BY2,
26579 +  BFD_RELOC_SH_IMM4BY4,
26580 +  BFD_RELOC_SH_IMM8,
26581 +  BFD_RELOC_SH_IMM8BY2,
26582 +  BFD_RELOC_SH_IMM8BY4,
26583 +  BFD_RELOC_SH_PCRELIMM8BY2,
26584 +  BFD_RELOC_SH_PCRELIMM8BY4,
26585 +  BFD_RELOC_SH_SWITCH16,
26586 +  BFD_RELOC_SH_SWITCH32,
26587 +  BFD_RELOC_SH_USES,
26588 +  BFD_RELOC_SH_COUNT,
26589 +  BFD_RELOC_SH_ALIGN,
26590 +  BFD_RELOC_SH_CODE,
26591 +  BFD_RELOC_SH_DATA,
26592 +  BFD_RELOC_SH_LABEL,
26593 +  BFD_RELOC_SH_LOOP_START,
26594 +  BFD_RELOC_SH_LOOP_END,
26595 +  BFD_RELOC_SH_COPY,
26596 +  BFD_RELOC_SH_GLOB_DAT,
26597 +  BFD_RELOC_SH_JMP_SLOT,
26598 +  BFD_RELOC_SH_RELATIVE,
26599 +  BFD_RELOC_SH_GOTPC,
26600 +  BFD_RELOC_SH_GOT_LOW16,
26601 +  BFD_RELOC_SH_GOT_MEDLOW16,
26602 +  BFD_RELOC_SH_GOT_MEDHI16,
26603 +  BFD_RELOC_SH_GOT_HI16,
26604 +  BFD_RELOC_SH_GOTPLT_LOW16,
26605 +  BFD_RELOC_SH_GOTPLT_MEDLOW16,
26606 +  BFD_RELOC_SH_GOTPLT_MEDHI16,
26607 +  BFD_RELOC_SH_GOTPLT_HI16,
26608 +  BFD_RELOC_SH_PLT_LOW16,
26609 +  BFD_RELOC_SH_PLT_MEDLOW16,
26610 +  BFD_RELOC_SH_PLT_MEDHI16,
26611 +  BFD_RELOC_SH_PLT_HI16,
26612 +  BFD_RELOC_SH_GOTOFF_LOW16,
26613 +  BFD_RELOC_SH_GOTOFF_MEDLOW16,
26614 +  BFD_RELOC_SH_GOTOFF_MEDHI16,
26615 +  BFD_RELOC_SH_GOTOFF_HI16,
26616 +  BFD_RELOC_SH_GOTPC_LOW16,
26617 +  BFD_RELOC_SH_GOTPC_MEDLOW16,
26618 +  BFD_RELOC_SH_GOTPC_MEDHI16,
26619 +  BFD_RELOC_SH_GOTPC_HI16,
26620 +  BFD_RELOC_SH_COPY64,
26621 +  BFD_RELOC_SH_GLOB_DAT64,
26622 +  BFD_RELOC_SH_JMP_SLOT64,
26623 +  BFD_RELOC_SH_RELATIVE64,
26624 +  BFD_RELOC_SH_GOT10BY4,
26625 +  BFD_RELOC_SH_GOT10BY8,
26626 +  BFD_RELOC_SH_GOTPLT10BY4,
26627 +  BFD_RELOC_SH_GOTPLT10BY8,
26628 +  BFD_RELOC_SH_GOTPLT32,
26629 +  BFD_RELOC_SH_SHMEDIA_CODE,
26630 +  BFD_RELOC_SH_IMMU5,
26631 +  BFD_RELOC_SH_IMMS6,
26632 +  BFD_RELOC_SH_IMMS6BY32,
26633 +  BFD_RELOC_SH_IMMU6,
26634 +  BFD_RELOC_SH_IMMS10,
26635 +  BFD_RELOC_SH_IMMS10BY2,
26636 +  BFD_RELOC_SH_IMMS10BY4,
26637 +  BFD_RELOC_SH_IMMS10BY8,
26638 +  BFD_RELOC_SH_IMMS16,
26639 +  BFD_RELOC_SH_IMMU16,
26640 +  BFD_RELOC_SH_IMM_LOW16,
26641 +  BFD_RELOC_SH_IMM_LOW16_PCREL,
26642 +  BFD_RELOC_SH_IMM_MEDLOW16,
26643 +  BFD_RELOC_SH_IMM_MEDLOW16_PCREL,
26644 +  BFD_RELOC_SH_IMM_MEDHI16,
26645 +  BFD_RELOC_SH_IMM_MEDHI16_PCREL,
26646 +  BFD_RELOC_SH_IMM_HI16,
26647 +  BFD_RELOC_SH_IMM_HI16_PCREL,
26648 +  BFD_RELOC_SH_PT_16,
26649 +  BFD_RELOC_SH_TLS_GD_32,
26650 +  BFD_RELOC_SH_TLS_LD_32,
26651 +  BFD_RELOC_SH_TLS_LDO_32,
26652 +  BFD_RELOC_SH_TLS_IE_32,
26653 +  BFD_RELOC_SH_TLS_LE_32,
26654 +  BFD_RELOC_SH_TLS_DTPMOD32,
26655 +  BFD_RELOC_SH_TLS_DTPOFF32,
26656 +  BFD_RELOC_SH_TLS_TPOFF32,
26657 +
26658 +/* ARC Cores relocs.
26659 +ARC 22 bit pc-relative branch.  The lowest two bits must be zero and are
26660 +not stored in the instruction.  The high 20 bits are installed in bits 26
26661 +through 7 of the instruction.  */
26662 +  BFD_RELOC_ARC_B22_PCREL,
26663 +
26664 +/* ARC 26 bit absolute branch.  The lowest two bits must be zero and are not
26665 +stored in the instruction.  The high 24 bits are installed in bits 23
26666 +through 0.  */
26667 +  BFD_RELOC_ARC_B26,
26668 +
26669 +/* Mitsubishi D10V relocs.
26670 +This is a 10-bit reloc with the right 2 bits
26671 +assumed to be 0.  */
26672 +  BFD_RELOC_D10V_10_PCREL_R,
26673 +
26674 +/* Mitsubishi D10V relocs.
26675 +This is a 10-bit reloc with the right 2 bits
26676 +assumed to be 0.  This is the same as the previous reloc
26677 +except it is in the left container, i.e.,
26678 +shifted left 15 bits.  */
26679 +  BFD_RELOC_D10V_10_PCREL_L,
26680 +
26681 +/* This is an 18-bit reloc with the right 2 bits
26682 +assumed to be 0.  */
26683 +  BFD_RELOC_D10V_18,
26684 +
26685 +/* This is an 18-bit reloc with the right 2 bits
26686 +assumed to be 0.  */
26687 +  BFD_RELOC_D10V_18_PCREL,
26688 +
26689 +/* Mitsubishi D30V relocs.
26690 +This is a 6-bit absolute reloc.  */
26691 +  BFD_RELOC_D30V_6,
26692 +
26693 +/* This is a 6-bit pc-relative reloc with
26694 +the right 3 bits assumed to be 0.  */
26695 +  BFD_RELOC_D30V_9_PCREL,
26696 +
26697 +/* This is a 6-bit pc-relative reloc with
26698 +the right 3 bits assumed to be 0. Same
26699 +as the previous reloc but on the right side
26700 +of the container.  */
26701 +  BFD_RELOC_D30V_9_PCREL_R,
26702 +
26703 +/* This is a 12-bit absolute reloc with the
26704 +right 3 bitsassumed to be 0.  */
26705 +  BFD_RELOC_D30V_15,
26706 +
26707 +/* This is a 12-bit pc-relative reloc with
26708 +the right 3 bits assumed to be 0.  */
26709 +  BFD_RELOC_D30V_15_PCREL,
26710 +
26711 +/* This is a 12-bit pc-relative reloc with
26712 +the right 3 bits assumed to be 0. Same
26713 +as the previous reloc but on the right side
26714 +of the container.  */
26715 +  BFD_RELOC_D30V_15_PCREL_R,
26716 +
26717 +/* This is an 18-bit absolute reloc with
26718 +the right 3 bits assumed to be 0.  */
26719 +  BFD_RELOC_D30V_21,
26720 +
26721 +/* This is an 18-bit pc-relative reloc with
26722 +the right 3 bits assumed to be 0.  */
26723 +  BFD_RELOC_D30V_21_PCREL,
26724 +
26725 +/* This is an 18-bit pc-relative reloc with
26726 +the right 3 bits assumed to be 0. Same
26727 +as the previous reloc but on the right side
26728 +of the container.  */
26729 +  BFD_RELOC_D30V_21_PCREL_R,
26730 +
26731 +/* This is a 32-bit absolute reloc.  */
26732 +  BFD_RELOC_D30V_32,
26733 +
26734 +/* This is a 32-bit pc-relative reloc.  */
26735 +  BFD_RELOC_D30V_32_PCREL,
26736 +
26737 +/* DLX relocs  */
26738 +  BFD_RELOC_DLX_HI16_S,
26739 +
26740 +/* DLX relocs  */
26741 +  BFD_RELOC_DLX_LO16,
26742 +
26743 +/* DLX relocs  */
26744 +  BFD_RELOC_DLX_JMP26,
26745 +
26746 +/* Renesas M16C/M32C Relocations.  */
26747 +  BFD_RELOC_M16C_8_PCREL8,
26748 +  BFD_RELOC_M16C_16_PCREL8,
26749 +  BFD_RELOC_M16C_8_PCREL16,
26750 +  BFD_RELOC_M16C_8_ELABEL24,
26751 +  BFD_RELOC_M16C_8_ABS16,
26752 +  BFD_RELOC_M16C_16_ABS16,
26753 +  BFD_RELOC_M16C_16_ABS24,
26754 +  BFD_RELOC_M16C_16_ABS32,
26755 +  BFD_RELOC_M16C_24_ABS16,
26756 +  BFD_RELOC_M16C_24_ABS24,
26757 +  BFD_RELOC_M16C_24_ABS32,
26758 +  BFD_RELOC_M16C_32_ABS16,
26759 +  BFD_RELOC_M16C_32_ABS24,
26760 +  BFD_RELOC_M16C_32_ABS32,
26761 +  BFD_RELOC_M16C_40_ABS16,
26762 +  BFD_RELOC_M16C_40_ABS24,
26763 +  BFD_RELOC_M16C_40_ABS32,
26764 +
26765 +/* Renesas M32R (formerly Mitsubishi M32R) relocs.
26766 +This is a 24 bit absolute address.  */
26767 +  BFD_RELOC_M32R_24,
26768 +
26769 +/* This is a 10-bit pc-relative reloc with the right 2 bits assumed to be 0.  */
26770 +  BFD_RELOC_M32R_10_PCREL,
26771 +
26772 +/* This is an 18-bit reloc with the right 2 bits assumed to be 0.  */
26773 +  BFD_RELOC_M32R_18_PCREL,
26774 +
26775 +/* This is a 26-bit reloc with the right 2 bits assumed to be 0.  */
26776 +  BFD_RELOC_M32R_26_PCREL,
26777 +
26778 +/* This is a 16-bit reloc containing the high 16 bits of an address
26779 +used when the lower 16 bits are treated as unsigned.  */
26780 +  BFD_RELOC_M32R_HI16_ULO,
26781 +
26782 +/* This is a 16-bit reloc containing the high 16 bits of an address
26783 +used when the lower 16 bits are treated as signed.  */
26784 +  BFD_RELOC_M32R_HI16_SLO,
26785 +
26786 +/* This is a 16-bit reloc containing the lower 16 bits of an address.  */
26787 +  BFD_RELOC_M32R_LO16,
26788 +
26789 +/* This is a 16-bit reloc containing the small data area offset for use in
26790 +add3, load, and store instructions.  */
26791 +  BFD_RELOC_M32R_SDA16,
26792 +
26793 +/* For PIC.  */
26794 +  BFD_RELOC_M32R_GOT24,
26795 +  BFD_RELOC_M32R_26_PLTREL,
26796 +  BFD_RELOC_M32R_COPY,
26797 +  BFD_RELOC_M32R_GLOB_DAT,
26798 +  BFD_RELOC_M32R_JMP_SLOT,
26799 +  BFD_RELOC_M32R_RELATIVE,
26800 +  BFD_RELOC_M32R_GOTOFF,
26801 +  BFD_RELOC_M32R_GOTOFF_HI_ULO,
26802 +  BFD_RELOC_M32R_GOTOFF_HI_SLO,
26803 +  BFD_RELOC_M32R_GOTOFF_LO,
26804 +  BFD_RELOC_M32R_GOTPC24,
26805 +  BFD_RELOC_M32R_GOT16_HI_ULO,
26806 +  BFD_RELOC_M32R_GOT16_HI_SLO,
26807 +  BFD_RELOC_M32R_GOT16_LO,
26808 +  BFD_RELOC_M32R_GOTPC_HI_ULO,
26809 +  BFD_RELOC_M32R_GOTPC_HI_SLO,
26810 +  BFD_RELOC_M32R_GOTPC_LO,
26811 +
26812 +/* This is a 9-bit reloc  */
26813 +  BFD_RELOC_V850_9_PCREL,
26814 +
26815 +/* This is a 22-bit reloc  */
26816 +  BFD_RELOC_V850_22_PCREL,
26817 +
26818 +/* This is a 16 bit offset from the short data area pointer.  */
26819 +  BFD_RELOC_V850_SDA_16_16_OFFSET,
26820 +
26821 +/* This is a 16 bit offset (of which only 15 bits are used) from the
26822 +short data area pointer.  */
26823 +  BFD_RELOC_V850_SDA_15_16_OFFSET,
26824 +
26825 +/* This is a 16 bit offset from the zero data area pointer.  */
26826 +  BFD_RELOC_V850_ZDA_16_16_OFFSET,
26827 +
26828 +/* This is a 16 bit offset (of which only 15 bits are used) from the
26829 +zero data area pointer.  */
26830 +  BFD_RELOC_V850_ZDA_15_16_OFFSET,
26831 +
26832 +/* This is an 8 bit offset (of which only 6 bits are used) from the
26833 +tiny data area pointer.  */
26834 +  BFD_RELOC_V850_TDA_6_8_OFFSET,
26835 +
26836 +/* This is an 8bit offset (of which only 7 bits are used) from the tiny
26837 +data area pointer.  */
26838 +  BFD_RELOC_V850_TDA_7_8_OFFSET,
26839 +
26840 +/* This is a 7 bit offset from the tiny data area pointer.  */
26841 +  BFD_RELOC_V850_TDA_7_7_OFFSET,
26842 +
26843 +/* This is a 16 bit offset from the tiny data area pointer.  */
26844 +  BFD_RELOC_V850_TDA_16_16_OFFSET,
26845 +
26846 +/* This is a 5 bit offset (of which only 4 bits are used) from the tiny
26847 +data area pointer.  */
26848 +  BFD_RELOC_V850_TDA_4_5_OFFSET,
26849 +
26850 +/* This is a 4 bit offset from the tiny data area pointer.  */
26851 +  BFD_RELOC_V850_TDA_4_4_OFFSET,
26852 +
26853 +/* This is a 16 bit offset from the short data area pointer, with the
26854 +bits placed non-contiguously in the instruction.  */
26855 +  BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET,
26856 +
26857 +/* This is a 16 bit offset from the zero data area pointer, with the
26858 +bits placed non-contiguously in the instruction.  */
26859 +  BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET,
26860 +
26861 +/* This is a 6 bit offset from the call table base pointer.  */
26862 +  BFD_RELOC_V850_CALLT_6_7_OFFSET,
26863 +
26864 +/* This is a 16 bit offset from the call table base pointer.  */
26865 +  BFD_RELOC_V850_CALLT_16_16_OFFSET,
26866 +
26867 +/* Used for relaxing indirect function calls.  */
26868 +  BFD_RELOC_V850_LONGCALL,
26869 +
26870 +/* Used for relaxing indirect jumps.  */
26871 +  BFD_RELOC_V850_LONGJUMP,
26872 +
26873 +/* Used to maintain alignment whilst relaxing.  */
26874 +  BFD_RELOC_V850_ALIGN,
26875 +
26876 +/* This is a variation of BFD_RELOC_LO16 that can be used in v850e ld.bu
26877 +instructions.  */
26878 +  BFD_RELOC_V850_LO16_SPLIT_OFFSET,
26879 +
26880 +/* This is a 32bit pcrel reloc for the mn10300, offset by two bytes in the
26881 +instruction.  */
26882 +  BFD_RELOC_MN10300_32_PCREL,
26883 +
26884 +/* This is a 16bit pcrel reloc for the mn10300, offset by two bytes in the
26885 +instruction.  */
26886 +  BFD_RELOC_MN10300_16_PCREL,
26887 +
26888 +/* This is a 8bit DP reloc for the tms320c30, where the most
26889 +significant 8 bits of a 24 bit word are placed into the least
26890 +significant 8 bits of the opcode.  */
26891 +  BFD_RELOC_TIC30_LDP,
26892 +
26893 +/* This is a 7bit reloc for the tms320c54x, where the least
26894 +significant 7 bits of a 16 bit word are placed into the least
26895 +significant 7 bits of the opcode.  */
26896 +  BFD_RELOC_TIC54X_PARTLS7,
26897 +
26898 +/* This is a 9bit DP reloc for the tms320c54x, where the most
26899 +significant 9 bits of a 16 bit word are placed into the least
26900 +significant 9 bits of the opcode.  */
26901 +  BFD_RELOC_TIC54X_PARTMS9,
26902 +
26903 +/* This is an extended address 23-bit reloc for the tms320c54x.  */
26904 +  BFD_RELOC_TIC54X_23,
26905 +
26906 +/* This is a 16-bit reloc for the tms320c54x, where the least
26907 +significant 16 bits of a 23-bit extended address are placed into
26908 +the opcode.  */
26909 +  BFD_RELOC_TIC54X_16_OF_23,
26910 +
26911 +/* This is a reloc for the tms320c54x, where the most
26912 +significant 7 bits of a 23-bit extended address are placed into
26913 +the opcode.  */
26914 +  BFD_RELOC_TIC54X_MS7_OF_23,
26915 +
26916 +/* This is a 48 bit reloc for the FR30 that stores 32 bits.  */
26917 +  BFD_RELOC_FR30_48,
26918 +
26919 +/* This is a 32 bit reloc for the FR30 that stores 20 bits split up into
26920 +two sections.  */
26921 +  BFD_RELOC_FR30_20,
26922 +
26923 +/* This is a 16 bit reloc for the FR30 that stores a 6 bit word offset in
26924 +4 bits.  */
26925 +  BFD_RELOC_FR30_6_IN_4,
26926 +
26927 +/* This is a 16 bit reloc for the FR30 that stores an 8 bit byte offset
26928 +into 8 bits.  */
26929 +  BFD_RELOC_FR30_8_IN_8,
26930 +
26931 +/* This is a 16 bit reloc for the FR30 that stores a 9 bit short offset
26932 +into 8 bits.  */
26933 +  BFD_RELOC_FR30_9_IN_8,
26934 +
26935 +/* This is a 16 bit reloc for the FR30 that stores a 10 bit word offset
26936 +into 8 bits.  */
26937 +  BFD_RELOC_FR30_10_IN_8,
26938 +
26939 +/* This is a 16 bit reloc for the FR30 that stores a 9 bit pc relative
26940 +short offset into 8 bits.  */
26941 +  BFD_RELOC_FR30_9_PCREL,
26942 +
26943 +/* This is a 16 bit reloc for the FR30 that stores a 12 bit pc relative
26944 +short offset into 11 bits.  */
26945 +  BFD_RELOC_FR30_12_PCREL,
26946 +
26947 +/* Motorola Mcore relocations.  */
26948 +  BFD_RELOC_MCORE_PCREL_IMM8BY4,
26949 +  BFD_RELOC_MCORE_PCREL_IMM11BY2,
26950 +  BFD_RELOC_MCORE_PCREL_IMM4BY2,
26951 +  BFD_RELOC_MCORE_PCREL_32,
26952 +  BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2,
26953 +  BFD_RELOC_MCORE_RVA,
26954 +
26955 +/* These are relocations for the GETA instruction.  */
26956 +  BFD_RELOC_MMIX_GETA,
26957 +  BFD_RELOC_MMIX_GETA_1,
26958 +  BFD_RELOC_MMIX_GETA_2,
26959 +  BFD_RELOC_MMIX_GETA_3,
26960 +
26961 +/* These are relocations for a conditional branch instruction.  */
26962 +  BFD_RELOC_MMIX_CBRANCH,
26963 +  BFD_RELOC_MMIX_CBRANCH_J,
26964 +  BFD_RELOC_MMIX_CBRANCH_1,
26965 +  BFD_RELOC_MMIX_CBRANCH_2,
26966 +  BFD_RELOC_MMIX_CBRANCH_3,
26967 +
26968 +/* These are relocations for the PUSHJ instruction.  */
26969 +  BFD_RELOC_MMIX_PUSHJ,
26970 +  BFD_RELOC_MMIX_PUSHJ_1,
26971 +  BFD_RELOC_MMIX_PUSHJ_2,
26972 +  BFD_RELOC_MMIX_PUSHJ_3,
26973 +  BFD_RELOC_MMIX_PUSHJ_STUBBABLE,
26974 +
26975 +/* These are relocations for the JMP instruction.  */
26976 +  BFD_RELOC_MMIX_JMP,
26977 +  BFD_RELOC_MMIX_JMP_1,
26978 +  BFD_RELOC_MMIX_JMP_2,
26979 +  BFD_RELOC_MMIX_JMP_3,
26980 +
26981 +/* This is a relocation for a relative address as in a GETA instruction or
26982 +a branch.  */
26983 +  BFD_RELOC_MMIX_ADDR19,
26984 +
26985 +/* This is a relocation for a relative address as in a JMP instruction.  */
26986 +  BFD_RELOC_MMIX_ADDR27,
26987 +
26988 +/* This is a relocation for an instruction field that may be a general
26989 +register or a value 0..255.  */
26990 +  BFD_RELOC_MMIX_REG_OR_BYTE,
26991 +
26992 +/* This is a relocation for an instruction field that may be a general
26993 +register.  */
26994 +  BFD_RELOC_MMIX_REG,
26995 +
26996 +/* This is a relocation for two instruction fields holding a register and
26997 +an offset, the equivalent of the relocation.  */
26998 +  BFD_RELOC_MMIX_BASE_PLUS_OFFSET,
26999 +
27000 +/* This relocation is an assertion that the expression is not allocated as
27001 +a global register.  It does not modify contents.  */
27002 +  BFD_RELOC_MMIX_LOCAL,
27003 +
27004 +/* This is a 16 bit reloc for the AVR that stores 8 bit pc relative
27005 +short offset into 7 bits.  */
27006 +  BFD_RELOC_AVR_7_PCREL,
27007 +
27008 +/* This is a 16 bit reloc for the AVR that stores 13 bit pc relative
27009 +short offset into 12 bits.  */
27010 +  BFD_RELOC_AVR_13_PCREL,
27011 +
27012 +/* This is a 16 bit reloc for the AVR that stores 17 bit value (usually
27013 +program memory address) into 16 bits.  */
27014 +  BFD_RELOC_AVR_16_PM,
27015 +
27016 +/* This is a 16 bit reloc for the AVR that stores 8 bit value (usually
27017 +data memory address) into 8 bit immediate value of LDI insn.  */
27018 +  BFD_RELOC_AVR_LO8_LDI,
27019 +
27020 +/* This is a 16 bit reloc for the AVR that stores 8 bit value (high 8 bit
27021 +of data memory address) into 8 bit immediate value of LDI insn.  */
27022 +  BFD_RELOC_AVR_HI8_LDI,
27023 +
27024 +/* This is a 16 bit reloc for the AVR that stores 8 bit value (most high 8 bit
27025 +of program memory address) into 8 bit immediate value of LDI insn.  */
27026 +  BFD_RELOC_AVR_HH8_LDI,
27027 +
27028 +/* This is a 16 bit reloc for the AVR that stores negated 8 bit value
27029 +(usually data memory address) into 8 bit immediate value of SUBI insn.  */
27030 +  BFD_RELOC_AVR_LO8_LDI_NEG,
27031 +
27032 +/* This is a 16 bit reloc for the AVR that stores negated 8 bit value
27033 +(high 8 bit of data memory address) into 8 bit immediate value of
27034 +SUBI insn.  */
27035 +  BFD_RELOC_AVR_HI8_LDI_NEG,
27036 +
27037 +/* This is a 16 bit reloc for the AVR that stores negated 8 bit value
27038 +(most high 8 bit of program memory address) into 8 bit immediate value
27039 +of LDI or SUBI insn.  */
27040 +  BFD_RELOC_AVR_HH8_LDI_NEG,
27041 +
27042 +/* This is a 16 bit reloc for the AVR that stores 8 bit value (usually
27043 +command address) into 8 bit immediate value of LDI insn.  */
27044 +  BFD_RELOC_AVR_LO8_LDI_PM,
27045 +
27046 +/* This is a 16 bit reloc for the AVR that stores 8 bit value (high 8 bit
27047 +of command address) into 8 bit immediate value of LDI insn.  */
27048 +  BFD_RELOC_AVR_HI8_LDI_PM,
27049 +
27050 +/* This is a 16 bit reloc for the AVR that stores 8 bit value (most high 8 bit
27051 +of command address) into 8 bit immediate value of LDI insn.  */
27052 +  BFD_RELOC_AVR_HH8_LDI_PM,
27053 +
27054 +/* This is a 16 bit reloc for the AVR that stores negated 8 bit value
27055 +(usually command address) into 8 bit immediate value of SUBI insn.  */
27056 +  BFD_RELOC_AVR_LO8_LDI_PM_NEG,
27057 +
27058 +/* This is a 16 bit reloc for the AVR that stores negated 8 bit value
27059 +(high 8 bit of 16 bit command address) into 8 bit immediate value
27060 +of SUBI insn.  */
27061 +  BFD_RELOC_AVR_HI8_LDI_PM_NEG,
27062 +
27063 +/* This is a 16 bit reloc for the AVR that stores negated 8 bit value
27064 +(high 6 bit of 22 bit command address) into 8 bit immediate
27065 +value of SUBI insn.  */
27066 +  BFD_RELOC_AVR_HH8_LDI_PM_NEG,
27067 +
27068 +/* This is a 32 bit reloc for the AVR that stores 23 bit value
27069 +into 22 bits.  */
27070 +  BFD_RELOC_AVR_CALL,
27071 +
27072 +/* This is a 16 bit reloc for the AVR that stores all needed bits
27073 +for absolute addressing with ldi with overflow check to linktime  */
27074 +  BFD_RELOC_AVR_LDI,
27075 +
27076 +/* This is a 6 bit reloc for the AVR that stores offset for ldd/std
27077 +instructions  */
27078 +  BFD_RELOC_AVR_6,
27079 +
27080 +/* This is a 6 bit reloc for the AVR that stores offset for adiw/sbiw
27081 +instructions  */
27082 +  BFD_RELOC_AVR_6_ADIW,
27083 +
27084 +/* Direct 12 bit.  */
27085 +  BFD_RELOC_390_12,
27086 +
27087 +/* 12 bit GOT offset.  */
27088 +  BFD_RELOC_390_GOT12,
27089 +
27090 +/* 32 bit PC relative PLT address.  */
27091 +  BFD_RELOC_390_PLT32,
27092 +
27093 +/* Copy symbol at runtime.  */
27094 +  BFD_RELOC_390_COPY,
27095 +
27096 +/* Create GOT entry.  */
27097 +  BFD_RELOC_390_GLOB_DAT,
27098 +
27099 +/* Create PLT entry.  */
27100 +  BFD_RELOC_390_JMP_SLOT,
27101 +
27102 +/* Adjust by program base.  */
27103 +  BFD_RELOC_390_RELATIVE,
27104 +
27105 +/* 32 bit PC relative offset to GOT.  */
27106 +  BFD_RELOC_390_GOTPC,
27107 +
27108 +/* 16 bit GOT offset.  */
27109 +  BFD_RELOC_390_GOT16,
27110 +
27111 +/* PC relative 16 bit shifted by 1.  */
27112 +  BFD_RELOC_390_PC16DBL,
27113 +
27114 +/* 16 bit PC rel. PLT shifted by 1.  */
27115 +  BFD_RELOC_390_PLT16DBL,
27116 +
27117 +/* PC relative 32 bit shifted by 1.  */
27118 +  BFD_RELOC_390_PC32DBL,
27119 +
27120 +/* 32 bit PC rel. PLT shifted by 1.  */
27121 +  BFD_RELOC_390_PLT32DBL,
27122 +
27123 +/* 32 bit PC rel. GOT shifted by 1.  */
27124 +  BFD_RELOC_390_GOTPCDBL,
27125 +
27126 +/* 64 bit GOT offset.  */
27127 +  BFD_RELOC_390_GOT64,
27128 +
27129 +/* 64 bit PC relative PLT address.  */
27130 +  BFD_RELOC_390_PLT64,
27131 +
27132 +/* 32 bit rel. offset to GOT entry.  */
27133 +  BFD_RELOC_390_GOTENT,
27134 +
27135 +/* 64 bit offset to GOT.  */
27136 +  BFD_RELOC_390_GOTOFF64,
27137 +
27138 +/* 12-bit offset to symbol-entry within GOT, with PLT handling.  */
27139 +  BFD_RELOC_390_GOTPLT12,
27140 +
27141 +/* 16-bit offset to symbol-entry within GOT, with PLT handling.  */
27142 +  BFD_RELOC_390_GOTPLT16,
27143 +
27144 +/* 32-bit offset to symbol-entry within GOT, with PLT handling.  */
27145 +  BFD_RELOC_390_GOTPLT32,
27146 +
27147 +/* 64-bit offset to symbol-entry within GOT, with PLT handling.  */
27148 +  BFD_RELOC_390_GOTPLT64,
27149 +
27150 +/* 32-bit rel. offset to symbol-entry within GOT, with PLT handling.  */
27151 +  BFD_RELOC_390_GOTPLTENT,
27152 +
27153 +/* 16-bit rel. offset from the GOT to a PLT entry.  */
27154 +  BFD_RELOC_390_PLTOFF16,
27155 +
27156 +/* 32-bit rel. offset from the GOT to a PLT entry.  */
27157 +  BFD_RELOC_390_PLTOFF32,
27158 +
27159 +/* 64-bit rel. offset from the GOT to a PLT entry.  */
27160 +  BFD_RELOC_390_PLTOFF64,
27161 +
27162 +/* s390 tls relocations.  */
27163 +  BFD_RELOC_390_TLS_LOAD,
27164 +  BFD_RELOC_390_TLS_GDCALL,
27165 +  BFD_RELOC_390_TLS_LDCALL,
27166 +  BFD_RELOC_390_TLS_GD32,
27167 +  BFD_RELOC_390_TLS_GD64,
27168 +  BFD_RELOC_390_TLS_GOTIE12,
27169 +  BFD_RELOC_390_TLS_GOTIE32,
27170 +  BFD_RELOC_390_TLS_GOTIE64,
27171 +  BFD_RELOC_390_TLS_LDM32,
27172 +  BFD_RELOC_390_TLS_LDM64,
27173 +  BFD_RELOC_390_TLS_IE32,
27174 +  BFD_RELOC_390_TLS_IE64,
27175 +  BFD_RELOC_390_TLS_IEENT,
27176 +  BFD_RELOC_390_TLS_LE32,
27177 +  BFD_RELOC_390_TLS_LE64,
27178 +  BFD_RELOC_390_TLS_LDO32,
27179 +  BFD_RELOC_390_TLS_LDO64,
27180 +  BFD_RELOC_390_TLS_DTPMOD,
27181 +  BFD_RELOC_390_TLS_DTPOFF,
27182 +  BFD_RELOC_390_TLS_TPOFF,
27183 +
27184 +/* Long displacement extension.  */
27185 +  BFD_RELOC_390_20,
27186 +  BFD_RELOC_390_GOT20,
27187 +  BFD_RELOC_390_GOTPLT20,
27188 +  BFD_RELOC_390_TLS_GOTIE20,
27189 +
27190 +/* Scenix IP2K - 9-bit register number / data address  */
27191 +  BFD_RELOC_IP2K_FR9,
27192 +
27193 +/* Scenix IP2K - 4-bit register/data bank number  */
27194 +  BFD_RELOC_IP2K_BANK,
27195 +
27196 +/* Scenix IP2K - low 13 bits of instruction word address  */
27197 +  BFD_RELOC_IP2K_ADDR16CJP,
27198 +
27199 +/* Scenix IP2K - high 3 bits of instruction word address  */
27200 +  BFD_RELOC_IP2K_PAGE3,
27201 +
27202 +/* Scenix IP2K - ext/low/high 8 bits of data address  */
27203 +  BFD_RELOC_IP2K_LO8DATA,
27204 +  BFD_RELOC_IP2K_HI8DATA,
27205 +  BFD_RELOC_IP2K_EX8DATA,
27206 +
27207 +/* Scenix IP2K - low/high 8 bits of instruction word address  */
27208 +  BFD_RELOC_IP2K_LO8INSN,
27209 +  BFD_RELOC_IP2K_HI8INSN,
27210 +
27211 +/* Scenix IP2K - even/odd PC modifier to modify snb pcl.0  */
27212 +  BFD_RELOC_IP2K_PC_SKIP,
27213 +
27214 +/* Scenix IP2K - 16 bit word address in text section.  */
27215 +  BFD_RELOC_IP2K_TEXT,
27216 +
27217 +/* Scenix IP2K - 7-bit sp or dp offset  */
27218 +  BFD_RELOC_IP2K_FR_OFFSET,
27219 +
27220 +/* Scenix VPE4K coprocessor - data/insn-space addressing  */
27221 +  BFD_RELOC_VPE4KMATH_DATA,
27222 +  BFD_RELOC_VPE4KMATH_INSN,
27223 +
27224 +/* These two relocations are used by the linker to determine which of
27225 +the entries in a C++ virtual function table are actually used.  When
27226 +the --gc-sections option is given, the linker will zero out the entries
27227 +that are not used, so that the code for those functions need not be
27228 +included in the output.
27229 +
27230 +VTABLE_INHERIT is a zero-space relocation used to describe to the
27231 +linker the inheritance tree of a C++ virtual function table.  The
27232 +relocation's symbol should be the parent class' vtable, and the
27233 +relocation should be located at the child vtable.
27234 +
27235 +VTABLE_ENTRY is a zero-space relocation that describes the use of a
27236 +virtual function table entry.  The reloc's symbol should refer to the
27237 +table of the class mentioned in the code.  Off of that base, an offset
27238 +describes the entry that is being used.  For Rela hosts, this offset
27239 +is stored in the reloc's addend.  For Rel hosts, we are forced to put
27240 +this offset in the reloc's section offset.  */
27241 +  BFD_RELOC_VTABLE_INHERIT,
27242 +  BFD_RELOC_VTABLE_ENTRY,
27243 +
27244 +/* Intel IA64 Relocations.  */
27245 +  BFD_RELOC_IA64_IMM14,
27246 +  BFD_RELOC_IA64_IMM22,
27247 +  BFD_RELOC_IA64_IMM64,
27248 +  BFD_RELOC_IA64_DIR32MSB,
27249 +  BFD_RELOC_IA64_DIR32LSB,
27250 +  BFD_RELOC_IA64_DIR64MSB,
27251 +  BFD_RELOC_IA64_DIR64LSB,
27252 +  BFD_RELOC_IA64_GPREL22,
27253 +  BFD_RELOC_IA64_GPREL64I,
27254 +  BFD_RELOC_IA64_GPREL32MSB,
27255 +  BFD_RELOC_IA64_GPREL32LSB,
27256 +  BFD_RELOC_IA64_GPREL64MSB,
27257 +  BFD_RELOC_IA64_GPREL64LSB,
27258 +  BFD_RELOC_IA64_LTOFF22,
27259 +  BFD_RELOC_IA64_LTOFF64I,
27260 +  BFD_RELOC_IA64_PLTOFF22,
27261 +  BFD_RELOC_IA64_PLTOFF64I,
27262 +  BFD_RELOC_IA64_PLTOFF64MSB,
27263 +  BFD_RELOC_IA64_PLTOFF64LSB,
27264 +  BFD_RELOC_IA64_FPTR64I,
27265 +  BFD_RELOC_IA64_FPTR32MSB,
27266 +  BFD_RELOC_IA64_FPTR32LSB,
27267 +  BFD_RELOC_IA64_FPTR64MSB,
27268 +  BFD_RELOC_IA64_FPTR64LSB,
27269 +  BFD_RELOC_IA64_PCREL21B,
27270 +  BFD_RELOC_IA64_PCREL21BI,
27271 +  BFD_RELOC_IA64_PCREL21M,
27272 +  BFD_RELOC_IA64_PCREL21F,
27273 +  BFD_RELOC_IA64_PCREL22,
27274 +  BFD_RELOC_IA64_PCREL60B,
27275 +  BFD_RELOC_IA64_PCREL64I,
27276 +  BFD_RELOC_IA64_PCREL32MSB,
27277 +  BFD_RELOC_IA64_PCREL32LSB,
27278 +  BFD_RELOC_IA64_PCREL64MSB,
27279 +  BFD_RELOC_IA64_PCREL64LSB,
27280 +  BFD_RELOC_IA64_LTOFF_FPTR22,
27281 +  BFD_RELOC_IA64_LTOFF_FPTR64I,
27282 +  BFD_RELOC_IA64_LTOFF_FPTR32MSB,
27283 +  BFD_RELOC_IA64_LTOFF_FPTR32LSB,
27284 +  BFD_RELOC_IA64_LTOFF_FPTR64MSB,
27285 +  BFD_RELOC_IA64_LTOFF_FPTR64LSB,
27286 +  BFD_RELOC_IA64_SEGREL32MSB,
27287 +  BFD_RELOC_IA64_SEGREL32LSB,
27288 +  BFD_RELOC_IA64_SEGREL64MSB,
27289 +  BFD_RELOC_IA64_SEGREL64LSB,
27290 +  BFD_RELOC_IA64_SECREL32MSB,
27291 +  BFD_RELOC_IA64_SECREL32LSB,
27292 +  BFD_RELOC_IA64_SECREL64MSB,
27293 +  BFD_RELOC_IA64_SECREL64LSB,
27294 +  BFD_RELOC_IA64_REL32MSB,
27295 +  BFD_RELOC_IA64_REL32LSB,
27296 +  BFD_RELOC_IA64_REL64MSB,
27297 +  BFD_RELOC_IA64_REL64LSB,
27298 +  BFD_RELOC_IA64_LTV32MSB,
27299 +  BFD_RELOC_IA64_LTV32LSB,
27300 +  BFD_RELOC_IA64_LTV64MSB,
27301 +  BFD_RELOC_IA64_LTV64LSB,
27302 +  BFD_RELOC_IA64_IPLTMSB,
27303 +  BFD_RELOC_IA64_IPLTLSB,
27304 +  BFD_RELOC_IA64_COPY,
27305 +  BFD_RELOC_IA64_LTOFF22X,
27306 +  BFD_RELOC_IA64_LDXMOV,
27307 +  BFD_RELOC_IA64_TPREL14,
27308 +  BFD_RELOC_IA64_TPREL22,
27309 +  BFD_RELOC_IA64_TPREL64I,
27310 +  BFD_RELOC_IA64_TPREL64MSB,
27311 +  BFD_RELOC_IA64_TPREL64LSB,
27312 +  BFD_RELOC_IA64_LTOFF_TPREL22,
27313 +  BFD_RELOC_IA64_DTPMOD64MSB,
27314 +  BFD_RELOC_IA64_DTPMOD64LSB,
27315 +  BFD_RELOC_IA64_LTOFF_DTPMOD22,
27316 +  BFD_RELOC_IA64_DTPREL14,
27317 +  BFD_RELOC_IA64_DTPREL22,
27318 +  BFD_RELOC_IA64_DTPREL64I,
27319 +  BFD_RELOC_IA64_DTPREL32MSB,
27320 +  BFD_RELOC_IA64_DTPREL32LSB,
27321 +  BFD_RELOC_IA64_DTPREL64MSB,
27322 +  BFD_RELOC_IA64_DTPREL64LSB,
27323 +  BFD_RELOC_IA64_LTOFF_DTPREL22,
27324 +
27325 +/* Motorola 68HC11 reloc.
27326 +This is the 8 bit high part of an absolute address.  */
27327 +  BFD_RELOC_M68HC11_HI8,
27328 +
27329 +/* Motorola 68HC11 reloc.
27330 +This is the 8 bit low part of an absolute address.  */
27331 +  BFD_RELOC_M68HC11_LO8,
27332 +
27333 +/* Motorola 68HC11 reloc.
27334 +This is the 3 bit of a value.  */
27335 +  BFD_RELOC_M68HC11_3B,
27336 +
27337 +/* Motorola 68HC11 reloc.
27338 +This reloc marks the beginning of a jump/call instruction.
27339 +It is used for linker relaxation to correctly identify beginning
27340 +of instruction and change some branches to use PC-relative
27341 +addressing mode.  */
27342 +  BFD_RELOC_M68HC11_RL_JUMP,
27343 +
27344 +/* Motorola 68HC11 reloc.
27345 +This reloc marks a group of several instructions that gcc generates
27346 +and for which the linker relaxation pass can modify and/or remove
27347 +some of them.  */
27348 +  BFD_RELOC_M68HC11_RL_GROUP,
27349 +
27350 +/* Motorola 68HC11 reloc.
27351 +This is the 16-bit lower part of an address.  It is used for 'call'
27352 +instruction to specify the symbol address without any special
27353 +transformation (due to memory bank window).  */
27354 +  BFD_RELOC_M68HC11_LO16,
27355 +
27356 +/* Motorola 68HC11 reloc.
27357 +This is a 8-bit reloc that specifies the page number of an address.
27358 +It is used by 'call' instruction to specify the page number of
27359 +the symbol.  */
27360 +  BFD_RELOC_M68HC11_PAGE,
27361 +
27362 +/* Motorola 68HC11 reloc.
27363 +This is a 24-bit reloc that represents the address with a 16-bit
27364 +value and a 8-bit page number.  The symbol address is transformed
27365 +to follow the 16K memory bank of 68HC12 (seen as mapped in the window).  */
27366 +  BFD_RELOC_M68HC11_24,
27367 +
27368 +/* Motorola 68HC12 reloc.
27369 +This is the 5 bits of a value.  */
27370 +  BFD_RELOC_M68HC12_5B,
27371 +
27372 +/* NS CR16C Relocations.  */
27373 +  BFD_RELOC_16C_NUM08,
27374 +  BFD_RELOC_16C_NUM08_C,
27375 +  BFD_RELOC_16C_NUM16,
27376 +  BFD_RELOC_16C_NUM16_C,
27377 +  BFD_RELOC_16C_NUM32,
27378 +  BFD_RELOC_16C_NUM32_C,
27379 +  BFD_RELOC_16C_DISP04,
27380 +  BFD_RELOC_16C_DISP04_C,
27381 +  BFD_RELOC_16C_DISP08,
27382 +  BFD_RELOC_16C_DISP08_C,
27383 +  BFD_RELOC_16C_DISP16,
27384 +  BFD_RELOC_16C_DISP16_C,
27385 +  BFD_RELOC_16C_DISP24,
27386 +  BFD_RELOC_16C_DISP24_C,
27387 +  BFD_RELOC_16C_DISP24a,
27388 +  BFD_RELOC_16C_DISP24a_C,
27389 +  BFD_RELOC_16C_REG04,
27390 +  BFD_RELOC_16C_REG04_C,
27391 +  BFD_RELOC_16C_REG04a,
27392 +  BFD_RELOC_16C_REG04a_C,
27393 +  BFD_RELOC_16C_REG14,
27394 +  BFD_RELOC_16C_REG14_C,
27395 +  BFD_RELOC_16C_REG16,
27396 +  BFD_RELOC_16C_REG16_C,
27397 +  BFD_RELOC_16C_REG20,
27398 +  BFD_RELOC_16C_REG20_C,
27399 +  BFD_RELOC_16C_ABS20,
27400 +  BFD_RELOC_16C_ABS20_C,
27401 +  BFD_RELOC_16C_ABS24,
27402 +  BFD_RELOC_16C_ABS24_C,
27403 +  BFD_RELOC_16C_IMM04,
27404 +  BFD_RELOC_16C_IMM04_C,
27405 +  BFD_RELOC_16C_IMM16,
27406 +  BFD_RELOC_16C_IMM16_C,
27407 +  BFD_RELOC_16C_IMM20,
27408 +  BFD_RELOC_16C_IMM20_C,
27409 +  BFD_RELOC_16C_IMM24,
27410 +  BFD_RELOC_16C_IMM24_C,
27411 +  BFD_RELOC_16C_IMM32,
27412 +  BFD_RELOC_16C_IMM32_C,
27413 +
27414 +/* NS CRX Relocations.  */
27415 +  BFD_RELOC_CRX_REL4,
27416 +  BFD_RELOC_CRX_REL8,
27417 +  BFD_RELOC_CRX_REL8_CMP,
27418 +  BFD_RELOC_CRX_REL16,
27419 +  BFD_RELOC_CRX_REL24,
27420 +  BFD_RELOC_CRX_REL32,
27421 +  BFD_RELOC_CRX_REGREL12,
27422 +  BFD_RELOC_CRX_REGREL22,
27423 +  BFD_RELOC_CRX_REGREL28,
27424 +  BFD_RELOC_CRX_REGREL32,
27425 +  BFD_RELOC_CRX_ABS16,
27426 +  BFD_RELOC_CRX_ABS32,
27427 +  BFD_RELOC_CRX_NUM8,
27428 +  BFD_RELOC_CRX_NUM16,
27429 +  BFD_RELOC_CRX_NUM32,
27430 +  BFD_RELOC_CRX_IMM16,
27431 +  BFD_RELOC_CRX_IMM32,
27432 +  BFD_RELOC_CRX_SWITCH8,
27433 +  BFD_RELOC_CRX_SWITCH16,
27434 +  BFD_RELOC_CRX_SWITCH32,
27435 +
27436 +/* These relocs are only used within the CRIS assembler.  They are not
27437 +(at present) written to any object files.  */
27438 +  BFD_RELOC_CRIS_BDISP8,
27439 +  BFD_RELOC_CRIS_UNSIGNED_5,
27440 +  BFD_RELOC_CRIS_SIGNED_6,
27441 +  BFD_RELOC_CRIS_UNSIGNED_6,
27442 +  BFD_RELOC_CRIS_SIGNED_8,
27443 +  BFD_RELOC_CRIS_UNSIGNED_8,
27444 +  BFD_RELOC_CRIS_SIGNED_16,
27445 +  BFD_RELOC_CRIS_UNSIGNED_16,
27446 +  BFD_RELOC_CRIS_LAPCQ_OFFSET,
27447 +  BFD_RELOC_CRIS_UNSIGNED_4,
27448 +
27449 +/* Relocs used in ELF shared libraries for CRIS.  */
27450 +  BFD_RELOC_CRIS_COPY,
27451 +  BFD_RELOC_CRIS_GLOB_DAT,
27452 +  BFD_RELOC_CRIS_JUMP_SLOT,
27453 +  BFD_RELOC_CRIS_RELATIVE,
27454 +
27455 +/* 32-bit offset to symbol-entry within GOT.  */
27456 +  BFD_RELOC_CRIS_32_GOT,
27457 +
27458 +/* 16-bit offset to symbol-entry within GOT.  */
27459 +  BFD_RELOC_CRIS_16_GOT,
27460 +
27461 +/* 32-bit offset to symbol-entry within GOT, with PLT handling.  */
27462 +  BFD_RELOC_CRIS_32_GOTPLT,
27463 +
27464 +/* 16-bit offset to symbol-entry within GOT, with PLT handling.  */
27465 +  BFD_RELOC_CRIS_16_GOTPLT,
27466 +
27467 +/* 32-bit offset to symbol, relative to GOT.  */
27468 +  BFD_RELOC_CRIS_32_GOTREL,
27469 +
27470 +/* 32-bit offset to symbol with PLT entry, relative to GOT.  */
27471 +  BFD_RELOC_CRIS_32_PLT_GOTREL,
27472 +
27473 +/* 32-bit offset to symbol with PLT entry, relative to this relocation.  */
27474 +  BFD_RELOC_CRIS_32_PLT_PCREL,
27475 +
27476 +/* Intel i860 Relocations.  */
27477 +  BFD_RELOC_860_COPY,
27478 +  BFD_RELOC_860_GLOB_DAT,
27479 +  BFD_RELOC_860_JUMP_SLOT,
27480 +  BFD_RELOC_860_RELATIVE,
27481 +  BFD_RELOC_860_PC26,
27482 +  BFD_RELOC_860_PLT26,
27483 +  BFD_RELOC_860_PC16,
27484 +  BFD_RELOC_860_LOW0,
27485 +  BFD_RELOC_860_SPLIT0,
27486 +  BFD_RELOC_860_LOW1,
27487 +  BFD_RELOC_860_SPLIT1,
27488 +  BFD_RELOC_860_LOW2,
27489 +  BFD_RELOC_860_SPLIT2,
27490 +  BFD_RELOC_860_LOW3,
27491 +  BFD_RELOC_860_LOGOT0,
27492 +  BFD_RELOC_860_SPGOT0,
27493 +  BFD_RELOC_860_LOGOT1,
27494 +  BFD_RELOC_860_SPGOT1,
27495 +  BFD_RELOC_860_LOGOTOFF0,
27496 +  BFD_RELOC_860_SPGOTOFF0,
27497 +  BFD_RELOC_860_LOGOTOFF1,
27498 +  BFD_RELOC_860_SPGOTOFF1,
27499 +  BFD_RELOC_860_LOGOTOFF2,
27500 +  BFD_RELOC_860_LOGOTOFF3,
27501 +  BFD_RELOC_860_LOPC,
27502 +  BFD_RELOC_860_HIGHADJ,
27503 +  BFD_RELOC_860_HAGOT,
27504 +  BFD_RELOC_860_HAGOTOFF,
27505 +  BFD_RELOC_860_HAPC,
27506 +  BFD_RELOC_860_HIGH,
27507 +  BFD_RELOC_860_HIGOT,
27508 +  BFD_RELOC_860_HIGOTOFF,
27509 +
27510 +/* OpenRISC Relocations.  */
27511 +  BFD_RELOC_OPENRISC_ABS_26,
27512 +  BFD_RELOC_OPENRISC_REL_26,
27513 +
27514 +/* H8 elf Relocations.  */
27515 +  BFD_RELOC_H8_DIR16A8,
27516 +  BFD_RELOC_H8_DIR16R8,
27517 +  BFD_RELOC_H8_DIR24A8,
27518 +  BFD_RELOC_H8_DIR24R8,
27519 +  BFD_RELOC_H8_DIR32A16,
27520 +
27521 +/* Sony Xstormy16 Relocations.  */
27522 +  BFD_RELOC_XSTORMY16_REL_12,
27523 +  BFD_RELOC_XSTORMY16_12,
27524 +  BFD_RELOC_XSTORMY16_24,
27525 +  BFD_RELOC_XSTORMY16_FPTR16,
27526 +
27527 +/* Relocations used by VAX ELF.  */
27528 +  BFD_RELOC_VAX_GLOB_DAT,
27529 +  BFD_RELOC_VAX_JMP_SLOT,
27530 +  BFD_RELOC_VAX_RELATIVE,
27531 +
27532 +/* Morpho MS1 - 16 bit immediate relocation.  */
27533 +  BFD_RELOC_MS1_PC16,
27534 +
27535 +/* Morpho MS1 - Hi 16 bits of an address.  */
27536 +  BFD_RELOC_MS1_HI16,
27537 +
27538 +/* Morpho MS1 - Low 16 bits of an address.  */
27539 +  BFD_RELOC_MS1_LO16,
27540 +
27541 +/* Morpho MS1 - Used to tell the linker which vtable entries are used.  */
27542 +  BFD_RELOC_MS1_GNU_VTINHERIT,
27543 +
27544 +/* Morpho MS1 - Used to tell the linker which vtable entries are used.  */
27545 +  BFD_RELOC_MS1_GNU_VTENTRY,
27546 +
27547 +/* msp430 specific relocation codes  */
27548 +  BFD_RELOC_MSP430_10_PCREL,
27549 +  BFD_RELOC_MSP430_16_PCREL,
27550 +  BFD_RELOC_MSP430_16,
27551 +  BFD_RELOC_MSP430_16_PCREL_BYTE,
27552 +  BFD_RELOC_MSP430_16_BYTE,
27553 +  BFD_RELOC_MSP430_2X_PCREL,
27554 +  BFD_RELOC_MSP430_RL_PCREL,
27555 +
27556 +/* IQ2000 Relocations.  */
27557 +  BFD_RELOC_IQ2000_OFFSET_16,
27558 +  BFD_RELOC_IQ2000_OFFSET_21,
27559 +  BFD_RELOC_IQ2000_UHI16,
27560 +
27561 +/* Special Xtensa relocation used only by PLT entries in ELF shared
27562 +objects to indicate that the runtime linker should set the value
27563 +to one of its own internal functions or data structures.  */
27564 +  BFD_RELOC_XTENSA_RTLD,
27565 +
27566 +/* Xtensa relocations for ELF shared objects.  */
27567 +  BFD_RELOC_XTENSA_GLOB_DAT,
27568 +  BFD_RELOC_XTENSA_JMP_SLOT,
27569 +  BFD_RELOC_XTENSA_RELATIVE,
27570 +
27571 +/* Xtensa relocation used in ELF object files for symbols that may require
27572 +PLT entries.  Otherwise, this is just a generic 32-bit relocation.  */
27573 +  BFD_RELOC_XTENSA_PLT,
27574 +
27575 +/* Xtensa relocations to mark the difference of two local symbols.
27576 +These are only needed to support linker relaxation and can be ignored
27577 +when not relaxing.  The field is set to the value of the difference
27578 +assuming no relaxation.  The relocation encodes the position of the
27579 +first symbol so the linker can determine whether to adjust the field
27580 +value.  */
27581 +  BFD_RELOC_XTENSA_DIFF8,
27582 +  BFD_RELOC_XTENSA_DIFF16,
27583 +  BFD_RELOC_XTENSA_DIFF32,
27584 +
27585 +/* Generic Xtensa relocations for instruction operands.  Only the slot
27586 +number is encoded in the relocation.  The relocation applies to the
27587 +last PC-relative immediate operand, or if there are no PC-relative
27588 +immediates, to the last immediate operand.  */
27589 +  BFD_RELOC_XTENSA_SLOT0_OP,
27590 +  BFD_RELOC_XTENSA_SLOT1_OP,
27591 +  BFD_RELOC_XTENSA_SLOT2_OP,
27592 +  BFD_RELOC_XTENSA_SLOT3_OP,
27593 +  BFD_RELOC_XTENSA_SLOT4_OP,
27594 +  BFD_RELOC_XTENSA_SLOT5_OP,
27595 +  BFD_RELOC_XTENSA_SLOT6_OP,
27596 +  BFD_RELOC_XTENSA_SLOT7_OP,
27597 +  BFD_RELOC_XTENSA_SLOT8_OP,
27598 +  BFD_RELOC_XTENSA_SLOT9_OP,
27599 +  BFD_RELOC_XTENSA_SLOT10_OP,
27600 +  BFD_RELOC_XTENSA_SLOT11_OP,
27601 +  BFD_RELOC_XTENSA_SLOT12_OP,
27602 +  BFD_RELOC_XTENSA_SLOT13_OP,
27603 +  BFD_RELOC_XTENSA_SLOT14_OP,
27604 +
27605 +/* Alternate Xtensa relocations.  Only the slot is encoded in the
27606 +relocation.  The meaning of these relocations is opcode-specific.  */
27607 +  BFD_RELOC_XTENSA_SLOT0_ALT,
27608 +  BFD_RELOC_XTENSA_SLOT1_ALT,
27609 +  BFD_RELOC_XTENSA_SLOT2_ALT,
27610 +  BFD_RELOC_XTENSA_SLOT3_ALT,
27611 +  BFD_RELOC_XTENSA_SLOT4_ALT,
27612 +  BFD_RELOC_XTENSA_SLOT5_ALT,
27613 +  BFD_RELOC_XTENSA_SLOT6_ALT,
27614 +  BFD_RELOC_XTENSA_SLOT7_ALT,
27615 +  BFD_RELOC_XTENSA_SLOT8_ALT,
27616 +  BFD_RELOC_XTENSA_SLOT9_ALT,
27617 +  BFD_RELOC_XTENSA_SLOT10_ALT,
27618 +  BFD_RELOC_XTENSA_SLOT11_ALT,
27619 +  BFD_RELOC_XTENSA_SLOT12_ALT,
27620 +  BFD_RELOC_XTENSA_SLOT13_ALT,
27621 +  BFD_RELOC_XTENSA_SLOT14_ALT,
27622 +
27623 +/* Xtensa relocations for backward compatibility.  These have all been
27624 +replaced by BFD_RELOC_XTENSA_SLOT0_OP.  */
27625 +  BFD_RELOC_XTENSA_OP0,
27626 +  BFD_RELOC_XTENSA_OP1,
27627 +  BFD_RELOC_XTENSA_OP2,
27628 +
27629 +/* Xtensa relocation to mark that the assembler expanded the
27630 +instructions from an original target.  The expansion size is
27631 +encoded in the reloc size.  */
27632 +  BFD_RELOC_XTENSA_ASM_EXPAND,
27633 +
27634 +/* Xtensa relocation to mark that the linker should simplify
27635 +assembler-expanded instructions.  This is commonly used
27636 +internally by the linker after analysis of a
27637 +BFD_RELOC_XTENSA_ASM_EXPAND.  */
27638 +  BFD_RELOC_XTENSA_ASM_SIMPLIFY,
27639 +  BFD_RELOC_UNUSED };
27640 +typedef enum bfd_reloc_code_real bfd_reloc_code_real_type;
27641 +reloc_howto_type *bfd_reloc_type_lookup
27642 +   (bfd *abfd, bfd_reloc_code_real_type code);
27643 +
27644 +const char *bfd_get_reloc_code_name (bfd_reloc_code_real_type code);
27645 +
27646 +/* Extracted from syms.c.  */
27647 +
27648 +typedef struct bfd_symbol
27649 +{
27650 +  /* A pointer to the BFD which owns the symbol. This information
27651 +     is necessary so that a back end can work out what additional
27652 +     information (invisible to the application writer) is carried
27653 +     with the symbol.
27654 +
27655 +     This field is *almost* redundant, since you can use section->owner
27656 +     instead, except that some symbols point to the global sections
27657 +     bfd_{abs,com,und}_section.  This could be fixed by making
27658 +     these globals be per-bfd (or per-target-flavor).  FIXME.  */
27659 +  struct bfd *the_bfd; /* Use bfd_asymbol_bfd(sym) to access this field.  */
27660 +
27661 +  /* The text of the symbol. The name is left alone, and not copied; the
27662 +     application may not alter it.  */
27663 +  const char *name;
27664 +
27665 +  /* The value of the symbol.  This really should be a union of a
27666 +     numeric value with a pointer, since some flags indicate that
27667 +     a pointer to another symbol is stored here.  */
27668 +  symvalue value;
27669 +
27670 +  /* Attributes of a symbol.  */
27671 +#define BSF_NO_FLAGS    0x00
27672 +
27673 +  /* The symbol has local scope; <<static>> in <<C>>. The value
27674 +     is the offset into the section of the data.  */
27675 +#define BSF_LOCAL      0x01
27676 +
27677 +  /* The symbol has global scope; initialized data in <<C>>. The
27678 +     value is the offset into the section of the data.  */
27679 +#define BSF_GLOBAL     0x02
27680 +
27681 +  /* The symbol has global scope and is exported. The value is
27682 +     the offset into the section of the data.  */
27683 +#define BSF_EXPORT     BSF_GLOBAL /* No real difference.  */
27684 +
27685 +  /* A normal C symbol would be one of:
27686 +     <<BSF_LOCAL>>, <<BSF_FORT_COMM>>,  <<BSF_UNDEFINED>> or
27687 +     <<BSF_GLOBAL>>.  */
27688 +
27689 +  /* The symbol is a debugging record. The value has an arbitrary
27690 +     meaning, unless BSF_DEBUGGING_RELOC is also set.  */
27691 +#define BSF_DEBUGGING  0x08
27692 +
27693 +  /* The symbol denotes a function entry point.  Used in ELF,
27694 +     perhaps others someday.  */
27695 +#define BSF_FUNCTION    0x10
27696 +
27697 +  /* Used by the linker.  */
27698 +#define BSF_KEEP        0x20
27699 +#define BSF_KEEP_G      0x40
27700 +
27701 +  /* A weak global symbol, overridable without warnings by
27702 +     a regular global symbol of the same name.  */
27703 +#define BSF_WEAK        0x80
27704 +
27705 +  /* This symbol was created to point to a section, e.g. ELF's
27706 +     STT_SECTION symbols.  */
27707 +#define BSF_SECTION_SYM 0x100
27708 +
27709 +  /* The symbol used to be a common symbol, but now it is
27710 +     allocated.  */
27711 +#define BSF_OLD_COMMON  0x200
27712 +
27713 +  /* The default value for common data.  */
27714 +#define BFD_FORT_COMM_DEFAULT_VALUE 0
27715 +
27716 +  /* In some files the type of a symbol sometimes alters its
27717 +     location in an output file - ie in coff a <<ISFCN>> symbol
27718 +     which is also <<C_EXT>> symbol appears where it was
27719 +     declared and not at the end of a section.  This bit is set
27720 +     by the target BFD part to convey this information.  */
27721 +#define BSF_NOT_AT_END    0x400
27722 +
27723 +  /* Signal that the symbol is the label of constructor section.  */
27724 +#define BSF_CONSTRUCTOR   0x800
27725 +
27726 +  /* Signal that the symbol is a warning symbol.  The name is a
27727 +     warning.  The name of the next symbol is the one to warn about;
27728 +     if a reference is made to a symbol with the same name as the next
27729 +     symbol, a warning is issued by the linker.  */
27730 +#define BSF_WARNING       0x1000
27731 +
27732 +  /* Signal that the symbol is indirect.  This symbol is an indirect
27733 +     pointer to the symbol with the same name as the next symbol.  */
27734 +#define BSF_INDIRECT      0x2000
27735 +
27736 +  /* BSF_FILE marks symbols that contain a file name.  This is used
27737 +     for ELF STT_FILE symbols.  */
27738 +#define BSF_FILE          0x4000
27739 +
27740 +  /* Symbol is from dynamic linking information.  */
27741 +#define BSF_DYNAMIC       0x8000
27742 +
27743 +  /* The symbol denotes a data object.  Used in ELF, and perhaps
27744 +     others someday.  */
27745 +#define BSF_OBJECT        0x10000
27746 +
27747 +  /* This symbol is a debugging symbol.  The value is the offset
27748 +     into the section of the data.  BSF_DEBUGGING should be set
27749 +     as well.  */
27750 +#define BSF_DEBUGGING_RELOC 0x20000
27751 +
27752 +  /* This symbol is thread local.  Used in ELF.  */
27753 +#define BSF_THREAD_LOCAL  0x40000
27754 +
27755 +  flagword flags;
27756 +
27757 +  /* A pointer to the section to which this symbol is
27758 +     relative.  This will always be non NULL, there are special
27759 +     sections for undefined and absolute symbols.  */
27760 +  struct bfd_section *section;
27761 +
27762 +  /* Back end special data.  */
27763 +  union
27764 +    {
27765 +      void *p;
27766 +      bfd_vma i;
27767 +    }
27768 +  udata;
27769 +}
27770 +asymbol;
27771 +
27772 +#define bfd_get_symtab_upper_bound(abfd) \
27773 +     BFD_SEND (abfd, _bfd_get_symtab_upper_bound, (abfd))
27774 +
27775 +bfd_boolean bfd_is_local_label (bfd *abfd, asymbol *sym);
27776 +
27777 +bfd_boolean bfd_is_local_label_name (bfd *abfd, const char *name);
27778 +
27779 +#define bfd_is_local_label_name(abfd, name) \
27780 +  BFD_SEND (abfd, _bfd_is_local_label_name, (abfd, name))
27781 +
27782 +bfd_boolean bfd_is_target_special_symbol (bfd *abfd, asymbol *sym);
27783 +
27784 +#define bfd_is_target_special_symbol(abfd, sym) \
27785 +  BFD_SEND (abfd, _bfd_is_target_special_symbol, (abfd, sym))
27786 +
27787 +#define bfd_canonicalize_symtab(abfd, location) \
27788 +  BFD_SEND (abfd, _bfd_canonicalize_symtab, (abfd, location))
27789 +
27790 +bfd_boolean bfd_set_symtab
27791 +   (bfd *abfd, asymbol **location, unsigned int count);
27792 +
27793 +void bfd_print_symbol_vandf (bfd *abfd, void *file, asymbol *symbol);
27794 +
27795 +#define bfd_make_empty_symbol(abfd) \
27796 +  BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd))
27797 +
27798 +asymbol *_bfd_generic_make_empty_symbol (bfd *);
27799 +
27800 +#define bfd_make_debug_symbol(abfd,ptr,size) \
27801 +  BFD_SEND (abfd, _bfd_make_debug_symbol, (abfd, ptr, size))
27802 +
27803 +int bfd_decode_symclass (asymbol *symbol);
27804 +
27805 +bfd_boolean bfd_is_undefined_symclass (int symclass);
27806 +
27807 +void bfd_symbol_info (asymbol *symbol, symbol_info *ret);
27808 +
27809 +bfd_boolean bfd_copy_private_symbol_data
27810 +   (bfd *ibfd, asymbol *isym, bfd *obfd, asymbol *osym);
27811 +
27812 +#define bfd_copy_private_symbol_data(ibfd, isymbol, obfd, osymbol) \
27813 +  BFD_SEND (obfd, _bfd_copy_private_symbol_data, \
27814 +            (ibfd, isymbol, obfd, osymbol))
27815 +
27816 +/* Extracted from bfd.c.  */
27817 +struct bfd
27818 +{
27819 +  /* A unique identifier of the BFD  */
27820 +  unsigned int id;
27821 +
27822 +  /* The filename the application opened the BFD with.  */
27823 +  const char *filename;
27824 +
27825 +  /* A pointer to the target jump table.  */
27826 +  const struct bfd_target *xvec;
27827 +
27828 +  /* The IOSTREAM, and corresponding IO vector that provide access
27829 +     to the file backing the BFD.  */
27830 +  void *iostream;
27831 +  const struct bfd_iovec *iovec;
27832 +
27833 +  /* Is the file descriptor being cached?  That is, can it be closed as
27834 +     needed, and re-opened when accessed later?  */
27835 +  bfd_boolean cacheable;
27836 +
27837 +  /* Marks whether there was a default target specified when the
27838 +     BFD was opened. This is used to select which matching algorithm
27839 +     to use to choose the back end.  */
27840 +  bfd_boolean target_defaulted;
27841 +
27842 +  /* The caching routines use these to maintain a
27843 +     least-recently-used list of BFDs.  */
27844 +  struct bfd *lru_prev, *lru_next;
27845 +
27846 +  /* When a file is closed by the caching routines, BFD retains
27847 +     state information on the file here...  */
27848 +  ufile_ptr where;
27849 +
27850 +  /* ... and here: (``once'' means at least once).  */
27851 +  bfd_boolean opened_once;
27852 +
27853 +  /* Set if we have a locally maintained mtime value, rather than
27854 +     getting it from the file each time.  */
27855 +  bfd_boolean mtime_set;
27856 +
27857 +  /* File modified time, if mtime_set is TRUE.  */
27858 +  long mtime;
27859 +
27860 +  /* Reserved for an unimplemented file locking extension.  */
27861 +  int ifd;
27862 +
27863 +  /* The format which belongs to the BFD. (object, core, etc.)  */
27864 +  bfd_format format;
27865 +
27866 +  /* The direction with which the BFD was opened.  */
27867 +  enum bfd_direction
27868 +    {
27869 +      no_direction = 0,
27870 +      read_direction = 1,
27871 +      write_direction = 2,
27872 +      both_direction = 3
27873 +    }
27874 +  direction;
27875 +
27876 +  /* Format_specific flags.  */
27877 +  flagword flags;
27878 +
27879 +  /* Currently my_archive is tested before adding origin to
27880 +     anything. I believe that this can become always an add of
27881 +     origin, with origin set to 0 for non archive files.  */
27882 +  ufile_ptr origin;
27883 +
27884 +  /* Remember when output has begun, to stop strange things
27885 +     from happening.  */
27886 +  bfd_boolean output_has_begun;
27887 +
27888 +  /* A hash table for section names.  */
27889 +  struct bfd_hash_table section_htab;
27890 +
27891 +  /* Pointer to linked list of sections.  */
27892 +  struct bfd_section *sections;
27893 +
27894 +  /* The last section on the section list.  */
27895 +  struct bfd_section *section_last;
27896 +
27897 +  /* The number of sections.  */
27898 +  unsigned int section_count;
27899 +
27900 +  /* Stuff only useful for object files:
27901 +     The start address.  */
27902 +  bfd_vma start_address;
27903 +
27904 +  /* Used for input and output.  */
27905 +  unsigned int symcount;
27906 +
27907 +  /* Symbol table for output BFD (with symcount entries).  */
27908 +  struct bfd_symbol  **outsymbols;
27909 +
27910 +  /* Used for slurped dynamic symbol tables.  */
27911 +  unsigned int dynsymcount;
27912 +
27913 +  /* Pointer to structure which contains architecture information.  */
27914 +  const struct bfd_arch_info *arch_info;
27915 +
27916 +  /* Flag set if symbols from this BFD should not be exported.  */
27917 +  bfd_boolean no_export;
27918 +
27919 +  /* Stuff only useful for archives.  */
27920 +  void *arelt_data;
27921 +  struct bfd *my_archive;      /* The containing archive BFD.  */
27922 +  struct bfd *next;            /* The next BFD in the archive.  */
27923 +  struct bfd *archive_head;    /* The first BFD in the archive.  */
27924 +  bfd_boolean has_armap;
27925 +
27926 +  /* A chain of BFD structures involved in a link.  */
27927 +  struct bfd *link_next;
27928 +
27929 +  /* A field used by _bfd_generic_link_add_archive_symbols.  This will
27930 +     be used only for archive elements.  */
27931 +  int archive_pass;
27932 +
27933 +  /* Used by the back end to hold private data.  */
27934 +  union
27935 +    {
27936 +      struct aout_data_struct *aout_data;
27937 +      struct artdata *aout_ar_data;
27938 +      struct _oasys_data *oasys_obj_data;
27939 +      struct _oasys_ar_data *oasys_ar_data;
27940 +      struct coff_tdata *coff_obj_data;
27941 +      struct pe_tdata *pe_obj_data;
27942 +      struct xcoff_tdata *xcoff_obj_data;
27943 +      struct ecoff_tdata *ecoff_obj_data;
27944 +      struct ieee_data_struct *ieee_data;
27945 +      struct ieee_ar_data_struct *ieee_ar_data;
27946 +      struct srec_data_struct *srec_data;
27947 +      struct ihex_data_struct *ihex_data;
27948 +      struct tekhex_data_struct *tekhex_data;
27949 +      struct elf_obj_tdata *elf_obj_data;
27950 +      struct nlm_obj_tdata *nlm_obj_data;
27951 +      struct bout_data_struct *bout_data;
27952 +      struct mmo_data_struct *mmo_data;
27953 +      struct sun_core_struct *sun_core_data;
27954 +      struct sco5_core_struct *sco5_core_data;
27955 +      struct trad_core_struct *trad_core_data;
27956 +      struct som_data_struct *som_data;
27957 +      struct hpux_core_struct *hpux_core_data;
27958 +      struct hppabsd_core_struct *hppabsd_core_data;
27959 +      struct sgi_core_struct *sgi_core_data;
27960 +      struct lynx_core_struct *lynx_core_data;
27961 +      struct osf_core_struct *osf_core_data;
27962 +      struct cisco_core_struct *cisco_core_data;
27963 +      struct versados_data_struct *versados_data;
27964 +      struct netbsd_core_struct *netbsd_core_data;
27965 +      struct mach_o_data_struct *mach_o_data;
27966 +      struct mach_o_fat_data_struct *mach_o_fat_data;
27967 +      struct bfd_pef_data_struct *pef_data;
27968 +      struct bfd_pef_xlib_data_struct *pef_xlib_data;
27969 +      struct bfd_sym_data_struct *sym_data;
27970 +      void *any;
27971 +    }
27972 +  tdata;
27973 +
27974 +  /* Used by the application to hold private data.  */
27975 +  void *usrdata;
27976 +
27977 +  /* Where all the allocated stuff under this BFD goes.  This is a
27978 +     struct objalloc *, but we use void * to avoid requiring the inclusion
27979 +     of objalloc.h.  */
27980 +  void *memory;
27981 +};
27982 +
27983 +typedef enum bfd_error
27984 +{
27985 +  bfd_error_no_error = 0,
27986 +  bfd_error_system_call,
27987 +  bfd_error_invalid_target,
27988 +  bfd_error_wrong_format,
27989 +  bfd_error_wrong_object_format,
27990 +  bfd_error_invalid_operation,
27991 +  bfd_error_no_memory,
27992 +  bfd_error_no_symbols,
27993 +  bfd_error_no_armap,
27994 +  bfd_error_no_more_archived_files,
27995 +  bfd_error_malformed_archive,
27996 +  bfd_error_file_not_recognized,
27997 +  bfd_error_file_ambiguously_recognized,
27998 +  bfd_error_no_contents,
27999 +  bfd_error_nonrepresentable_section,
28000 +  bfd_error_no_debug_section,
28001 +  bfd_error_bad_value,
28002 +  bfd_error_file_truncated,
28003 +  bfd_error_file_too_big,
28004 +  bfd_error_invalid_error_code
28005 +}
28006 +bfd_error_type;
28007 +
28008 +bfd_error_type bfd_get_error (void);
28009 +
28010 +void bfd_set_error (bfd_error_type error_tag);
28011 +
28012 +const char *bfd_errmsg (bfd_error_type error_tag);
28013 +
28014 +void bfd_perror (const char *message);
28015 +
28016 +typedef void (*bfd_error_handler_type) (const char *, ...);
28017 +
28018 +bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
28019 +
28020 +void bfd_set_error_program_name (const char *);
28021 +
28022 +bfd_error_handler_type bfd_get_error_handler (void);
28023 +
28024 +long bfd_get_reloc_upper_bound (bfd *abfd, asection *sect);
28025 +
28026 +long bfd_canonicalize_reloc
28027 +   (bfd *abfd, asection *sec, arelent **loc, asymbol **syms);
28028 +
28029 +void bfd_set_reloc
28030 +   (bfd *abfd, asection *sec, arelent **rel, unsigned int count);
28031 +
28032 +bfd_boolean bfd_set_file_flags (bfd *abfd, flagword flags);
28033 +
28034 +int bfd_get_arch_size (bfd *abfd);
28035 +
28036 +int bfd_get_sign_extend_vma (bfd *abfd);
28037 +
28038 +bfd_boolean bfd_set_start_address (bfd *abfd, bfd_vma vma);
28039 +
28040 +unsigned int bfd_get_gp_size (bfd *abfd);
28041 +
28042 +void bfd_set_gp_size (bfd *abfd, unsigned int i);
28043 +
28044 +bfd_vma bfd_scan_vma (const char *string, const char **end, int base);
28045 +
28046 +bfd_boolean bfd_copy_private_header_data (bfd *ibfd, bfd *obfd);
28047 +
28048 +#define bfd_copy_private_header_data(ibfd, obfd) \
28049 +     BFD_SEND (obfd, _bfd_copy_private_header_data, \
28050 +               (ibfd, obfd))
28051 +bfd_boolean bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd);
28052 +
28053 +#define bfd_copy_private_bfd_data(ibfd, obfd) \
28054 +     BFD_SEND (obfd, _bfd_copy_private_bfd_data, \
28055 +               (ibfd, obfd))
28056 +bfd_boolean bfd_merge_private_bfd_data (bfd *ibfd, bfd *obfd);
28057 +
28058 +#define bfd_merge_private_bfd_data(ibfd, obfd) \
28059 +     BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
28060 +               (ibfd, obfd))
28061 +bfd_boolean bfd_set_private_flags (bfd *abfd, flagword flags);
28062 +
28063 +#define bfd_set_private_flags(abfd, flags) \
28064 +     BFD_SEND (abfd, _bfd_set_private_flags, (abfd, flags))
28065 +#define bfd_sizeof_headers(abfd, reloc) \
28066 +       BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
28067 +
28068 +#define bfd_find_nearest_line(abfd, sec, syms, off, file, func, line) \
28069 +       BFD_SEND (abfd, _bfd_find_nearest_line, \
28070 +                 (abfd, sec, syms, off, file, func, line))
28071 +
28072 +#define bfd_find_line(abfd, syms, sym, file, line) \
28073 +       BFD_SEND (abfd, _bfd_find_line, \
28074 +                 (abfd, syms, sym, file, line))
28075 +
28076 +#define bfd_find_inliner_info(abfd, file, func, line) \
28077 +       BFD_SEND (abfd, _bfd_find_inliner_info, \
28078 +                 (abfd, file, func, line))
28079 +
28080 +#define bfd_debug_info_start(abfd) \
28081 +       BFD_SEND (abfd, _bfd_debug_info_start, (abfd))
28082 +
28083 +#define bfd_debug_info_end(abfd) \
28084 +       BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
28085 +
28086 +#define bfd_debug_info_accumulate(abfd, section) \
28087 +       BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
28088 +
28089 +#define bfd_stat_arch_elt(abfd, stat) \
28090 +       BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
28091 +
28092 +#define bfd_update_armap_timestamp(abfd) \
28093 +       BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
28094 +
28095 +#define bfd_set_arch_mach(abfd, arch, mach)\
28096 +       BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
28097 +
28098 +#define bfd_relax_section(abfd, section, link_info, again) \
28099 +       BFD_SEND (abfd, _bfd_relax_section, (abfd, section, link_info, again))
28100 +
28101 +#define bfd_gc_sections(abfd, link_info) \
28102 +       BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
28103 +
28104 +#define bfd_merge_sections(abfd, link_info) \
28105 +       BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
28106 +
28107 +#define bfd_is_group_section(abfd, sec) \
28108 +       BFD_SEND (abfd, _bfd_is_group_section, (abfd, sec))
28109 +
28110 +#define bfd_discard_group(abfd, sec) \
28111 +       BFD_SEND (abfd, _bfd_discard_group, (abfd, sec))
28112 +
28113 +#define bfd_link_hash_table_create(abfd) \
28114 +       BFD_SEND (abfd, _bfd_link_hash_table_create, (abfd))
28115 +
28116 +#define bfd_link_hash_table_free(abfd, hash) \
28117 +       BFD_SEND (abfd, _bfd_link_hash_table_free, (hash))
28118 +
28119 +#define bfd_link_add_symbols(abfd, info) \
28120 +       BFD_SEND (abfd, _bfd_link_add_symbols, (abfd, info))
28121 +
28122 +#define bfd_link_just_syms(abfd, sec, info) \
28123 +       BFD_SEND (abfd, _bfd_link_just_syms, (sec, info))
28124 +
28125 +#define bfd_final_link(abfd, info) \
28126 +       BFD_SEND (abfd, _bfd_final_link, (abfd, info))
28127 +
28128 +#define bfd_free_cached_info(abfd) \
28129 +       BFD_SEND (abfd, _bfd_free_cached_info, (abfd))
28130 +
28131 +#define bfd_get_dynamic_symtab_upper_bound(abfd) \
28132 +       BFD_SEND (abfd, _bfd_get_dynamic_symtab_upper_bound, (abfd))
28133 +
28134 +#define bfd_print_private_bfd_data(abfd, file)\
28135 +       BFD_SEND (abfd, _bfd_print_private_bfd_data, (abfd, file))
28136 +
28137 +#define bfd_canonicalize_dynamic_symtab(abfd, asymbols) \
28138 +       BFD_SEND (abfd, _bfd_canonicalize_dynamic_symtab, (abfd, asymbols))
28139 +
28140 +#define bfd_get_synthetic_symtab(abfd, count, syms, dyncount, dynsyms, ret) \
28141 +       BFD_SEND (abfd, _bfd_get_synthetic_symtab, (abfd, count, syms, \
28142 +                                                   dyncount, dynsyms, ret))
28143 +
28144 +#define bfd_get_dynamic_reloc_upper_bound(abfd) \
28145 +       BFD_SEND (abfd, _bfd_get_dynamic_reloc_upper_bound, (abfd))
28146 +
28147 +#define bfd_canonicalize_dynamic_reloc(abfd, arels, asyms) \
28148 +       BFD_SEND (abfd, _bfd_canonicalize_dynamic_reloc, (abfd, arels, asyms))
28149 +
28150 +extern bfd_byte *bfd_get_relocated_section_contents
28151 +  (bfd *, struct bfd_link_info *, struct bfd_link_order *, bfd_byte *,
28152 +   bfd_boolean, asymbol **);
28153 +
28154 +bfd_boolean bfd_alt_mach_code (bfd *abfd, int alternative);
28155 +
28156 +struct bfd_preserve
28157 +{
28158 +  void *marker;
28159 +  void *tdata;
28160 +  flagword flags;
28161 +  const struct bfd_arch_info *arch_info;
28162 +  struct bfd_section *sections;
28163 +  struct bfd_section *section_last;
28164 +  unsigned int section_count;
28165 +  struct bfd_hash_table section_htab;
28166 +};
28167 +
28168 +bfd_boolean bfd_preserve_save (bfd *, struct bfd_preserve *);
28169 +
28170 +void bfd_preserve_restore (bfd *, struct bfd_preserve *);
28171 +
28172 +void bfd_preserve_finish (bfd *, struct bfd_preserve *);
28173 +
28174 +/* Extracted from archive.c.  */
28175 +symindex bfd_get_next_mapent
28176 +   (bfd *abfd, symindex previous, carsym **sym);
28177 +
28178 +bfd_boolean bfd_set_archive_head (bfd *output, bfd *new_head);
28179 +
28180 +bfd *bfd_openr_next_archived_file (bfd *archive, bfd *previous);
28181 +
28182 +/* Extracted from corefile.c.  */
28183 +const char *bfd_core_file_failing_command (bfd *abfd);
28184 +
28185 +int bfd_core_file_failing_signal (bfd *abfd);
28186 +
28187 +bfd_boolean core_file_matches_executable_p
28188 +   (bfd *core_bfd, bfd *exec_bfd);
28189 +
28190 +/* Extracted from targets.c.  */
28191 +#define BFD_SEND(bfd, message, arglist) \
28192 +  ((*((bfd)->xvec->message)) arglist)
28193 +
28194 +#ifdef DEBUG_BFD_SEND
28195 +#undef BFD_SEND
28196 +#define BFD_SEND(bfd, message, arglist) \
28197 +  (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
28198 +    ((*((bfd)->xvec->message)) arglist) : \
28199 +    (bfd_assert (__FILE__,__LINE__), NULL))
28200 +#endif
28201 +#define BFD_SEND_FMT(bfd, message, arglist) \
28202 +  (((bfd)->xvec->message[(int) ((bfd)->format)]) arglist)
28203 +
28204 +#ifdef DEBUG_BFD_SEND
28205 +#undef BFD_SEND_FMT
28206 +#define BFD_SEND_FMT(bfd, message, arglist) \
28207 +  (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
28208 +   (((bfd)->xvec->message[(int) ((bfd)->format)]) arglist) : \
28209 +   (bfd_assert (__FILE__,__LINE__), NULL))
28210 +#endif
28211 +
28212 +enum bfd_flavour
28213 +{
28214 +  bfd_target_unknown_flavour,
28215 +  bfd_target_aout_flavour,
28216 +  bfd_target_coff_flavour,
28217 +  bfd_target_ecoff_flavour,
28218 +  bfd_target_xcoff_flavour,
28219 +  bfd_target_elf_flavour,
28220 +  bfd_target_ieee_flavour,
28221 +  bfd_target_nlm_flavour,
28222 +  bfd_target_oasys_flavour,
28223 +  bfd_target_tekhex_flavour,
28224 +  bfd_target_srec_flavour,
28225 +  bfd_target_ihex_flavour,
28226 +  bfd_target_som_flavour,
28227 +  bfd_target_os9k_flavour,
28228 +  bfd_target_versados_flavour,
28229 +  bfd_target_msdos_flavour,
28230 +  bfd_target_ovax_flavour,
28231 +  bfd_target_evax_flavour,
28232 +  bfd_target_mmo_flavour,
28233 +  bfd_target_mach_o_flavour,
28234 +  bfd_target_pef_flavour,
28235 +  bfd_target_pef_xlib_flavour,
28236 +  bfd_target_sym_flavour
28237 +};
28238 +
28239 +enum bfd_endian { BFD_ENDIAN_BIG, BFD_ENDIAN_LITTLE, BFD_ENDIAN_UNKNOWN };
28240 +
28241 +/* Forward declaration.  */
28242 +typedef struct bfd_link_info _bfd_link_info;
28243 +
28244 +typedef struct bfd_target
28245 +{
28246 +  /* Identifies the kind of target, e.g., SunOS4, Ultrix, etc.  */
28247 +  char *name;
28248 +
28249 + /* The "flavour" of a back end is a general indication about
28250 +    the contents of a file.  */
28251 +  enum bfd_flavour flavour;
28252 +
28253 +  /* The order of bytes within the data area of a file.  */
28254 +  enum bfd_endian byteorder;
28255 +
28256 + /* The order of bytes within the header parts of a file.  */
28257 +  enum bfd_endian header_byteorder;
28258 +
28259 +  /* A mask of all the flags which an executable may have set -
28260 +     from the set <<BFD_NO_FLAGS>>, <<HAS_RELOC>>, ...<<D_PAGED>>.  */
28261 +  flagword object_flags;
28262 +
28263 + /* A mask of all the flags which a section may have set - from
28264 +    the set <<SEC_NO_FLAGS>>, <<SEC_ALLOC>>, ...<<SET_NEVER_LOAD>>.  */
28265 +  flagword section_flags;
28266 +
28267 + /* The character normally found at the front of a symbol.
28268 +    (if any), perhaps `_'.  */
28269 +  char symbol_leading_char;
28270 +
28271 + /* The pad character for file names within an archive header.  */
28272 +  char ar_pad_char;
28273 +
28274 +  /* The maximum number of characters in an archive header.  */
28275 +  unsigned short ar_max_namelen;
28276 +
28277 +  /* Entries for byte swapping for data. These are different from the
28278 +     other entry points, since they don't take a BFD as the first argument.
28279 +     Certain other handlers could do the same.  */
28280 +  bfd_uint64_t   (*bfd_getx64) (const void *);
28281 +  bfd_int64_t    (*bfd_getx_signed_64) (const void *);
28282 +  void           (*bfd_putx64) (bfd_uint64_t, void *);
28283 +  bfd_vma        (*bfd_getx32) (const void *);
28284 +  bfd_signed_vma (*bfd_getx_signed_32) (const void *);
28285 +  void           (*bfd_putx32) (bfd_vma, void *);
28286 +  bfd_vma        (*bfd_getx16) (const void *);
28287 +  bfd_signed_vma (*bfd_getx_signed_16) (const void *);
28288 +  void           (*bfd_putx16) (bfd_vma, void *);
28289 +
28290 +  /* Byte swapping for the headers.  */
28291 +  bfd_uint64_t   (*bfd_h_getx64) (const void *);
28292 +  bfd_int64_t    (*bfd_h_getx_signed_64) (const void *);
28293 +  void           (*bfd_h_putx64) (bfd_uint64_t, void *);
28294 +  bfd_vma        (*bfd_h_getx32) (const void *);
28295 +  bfd_signed_vma (*bfd_h_getx_signed_32) (const void *);
28296 +  void           (*bfd_h_putx32) (bfd_vma, void *);
28297 +  bfd_vma        (*bfd_h_getx16) (const void *);
28298 +  bfd_signed_vma (*bfd_h_getx_signed_16) (const void *);
28299 +  void           (*bfd_h_putx16) (bfd_vma, void *);
28300 +
28301 +  /* Format dependent routines: these are vectors of entry points
28302 +     within the target vector structure, one for each format to check.  */
28303 +
28304 +  /* Check the format of a file being read.  Return a <<bfd_target *>> or zero.  */
28305 +  const struct bfd_target *(*_bfd_check_format[bfd_type_end]) (bfd *);
28306 +
28307 +  /* Set the format of a file being written.  */
28308 +  bfd_boolean (*_bfd_set_format[bfd_type_end]) (bfd *);
28309 +
28310 +  /* Write cached information into a file being written, at <<bfd_close>>.  */
28311 +  bfd_boolean (*_bfd_write_contents[bfd_type_end]) (bfd *);
28312 +
28313 +
28314 +  /* Generic entry points.  */
28315 +#define BFD_JUMP_TABLE_GENERIC(NAME) \
28316 +  NAME##_close_and_cleanup, \
28317 +  NAME##_bfd_free_cached_info, \
28318 +  NAME##_new_section_hook, \
28319 +  NAME##_get_section_contents, \
28320 +  NAME##_get_section_contents_in_window
28321 +
28322 +  /* Called when the BFD is being closed to do any necessary cleanup.  */
28323 +  bfd_boolean (*_close_and_cleanup) (bfd *);
28324 +  /* Ask the BFD to free all cached information.  */
28325 +  bfd_boolean (*_bfd_free_cached_info) (bfd *);
28326 +  /* Called when a new section is created.  */
28327 +  bfd_boolean (*_new_section_hook) (bfd *, sec_ptr);
28328 +  /* Read the contents of a section.  */
28329 +  bfd_boolean (*_bfd_get_section_contents)
28330 +    (bfd *, sec_ptr, void *, file_ptr, bfd_size_type);
28331 +  bfd_boolean (*_bfd_get_section_contents_in_window)
28332 +    (bfd *, sec_ptr, bfd_window *, file_ptr, bfd_size_type);
28333 +
28334 +  /* Entry points to copy private data.  */
28335 +#define BFD_JUMP_TABLE_COPY(NAME) \
28336 +  NAME##_bfd_copy_private_bfd_data, \
28337 +  NAME##_bfd_merge_private_bfd_data, \
28338 +  NAME##_bfd_copy_private_section_data, \
28339 +  NAME##_bfd_copy_private_symbol_data, \
28340 +  NAME##_bfd_copy_private_header_data, \
28341 +  NAME##_bfd_set_private_flags, \
28342 +  NAME##_bfd_print_private_bfd_data
28343 +
28344 +  /* Called to copy BFD general private data from one object file
28345 +     to another.  */
28346 +  bfd_boolean (*_bfd_copy_private_bfd_data) (bfd *, bfd *);
28347 +  /* Called to merge BFD general private data from one object file
28348 +     to a common output file when linking.  */
28349 +  bfd_boolean (*_bfd_merge_private_bfd_data) (bfd *, bfd *);
28350 +  /* Called to copy BFD private section data from one object file
28351 +     to another.  */
28352 +  bfd_boolean (*_bfd_copy_private_section_data)
28353 +    (bfd *, sec_ptr, bfd *, sec_ptr);
28354 +  /* Called to copy BFD private symbol data from one symbol
28355 +     to another.  */
28356 +  bfd_boolean (*_bfd_copy_private_symbol_data)
28357 +    (bfd *, asymbol *, bfd *, asymbol *);
28358 +  /* Called to copy BFD private header data from one object file
28359 +     to another.  */
28360 +  bfd_boolean (*_bfd_copy_private_header_data)
28361 +    (bfd *, bfd *);
28362 +  /* Called to set private backend flags.  */
28363 +  bfd_boolean (*_bfd_set_private_flags) (bfd *, flagword);
28364 +
28365 +  /* Called to print private BFD data.  */
28366 +  bfd_boolean (*_bfd_print_private_bfd_data) (bfd *, void *);
28367 +
28368 +  /* Core file entry points.  */
28369 +#define BFD_JUMP_TABLE_CORE(NAME) \
28370 +  NAME##_core_file_failing_command, \
28371 +  NAME##_core_file_failing_signal, \
28372 +  NAME##_core_file_matches_executable_p
28373 +
28374 +  char *      (*_core_file_failing_command) (bfd *);
28375 +  int         (*_core_file_failing_signal) (bfd *);
28376 +  bfd_boolean (*_core_file_matches_executable_p) (bfd *, bfd *);
28377 +
28378 +  /* Archive entry points.  */
28379 +#define BFD_JUMP_TABLE_ARCHIVE(NAME) \
28380 +  NAME##_slurp_armap, \
28381 +  NAME##_slurp_extended_name_table, \
28382 +  NAME##_construct_extended_name_table, \
28383 +  NAME##_truncate_arname, \
28384 +  NAME##_write_armap, \
28385 +  NAME##_read_ar_hdr, \
28386 +  NAME##_openr_next_archived_file, \
28387 +  NAME##_get_elt_at_index, \
28388 +  NAME##_generic_stat_arch_elt, \
28389 +  NAME##_update_armap_timestamp
28390 +
28391 +  bfd_boolean (*_bfd_slurp_armap) (bfd *);
28392 +  bfd_boolean (*_bfd_slurp_extended_name_table) (bfd *);
28393 +  bfd_boolean (*_bfd_construct_extended_name_table)
28394 +    (bfd *, char **, bfd_size_type *, const char **);
28395 +  void        (*_bfd_truncate_arname) (bfd *, const char *, char *);
28396 +  bfd_boolean (*write_armap)
28397 +    (bfd *, unsigned int, struct orl *, unsigned int, int);
28398 +  void *      (*_bfd_read_ar_hdr_fn) (bfd *);
28399 +  bfd *       (*openr_next_archived_file) (bfd *, bfd *);
28400 +#define bfd_get_elt_at_index(b,i) BFD_SEND (b, _bfd_get_elt_at_index, (b,i))
28401 +  bfd *       (*_bfd_get_elt_at_index) (bfd *, symindex);
28402 +  int         (*_bfd_stat_arch_elt) (bfd *, struct stat *);
28403 +  bfd_boolean (*_bfd_update_armap_timestamp) (bfd *);
28404 +
28405 +  /* Entry points used for symbols.  */
28406 +#define BFD_JUMP_TABLE_SYMBOLS(NAME) \
28407 +  NAME##_get_symtab_upper_bound, \
28408 +  NAME##_canonicalize_symtab, \
28409 +  NAME##_make_empty_symbol, \
28410 +  NAME##_print_symbol, \
28411 +  NAME##_get_symbol_info, \
28412 +  NAME##_bfd_is_local_label_name, \
28413 +  NAME##_bfd_is_target_special_symbol, \
28414 +  NAME##_get_lineno, \
28415 +  NAME##_find_nearest_line, \
28416 +  _bfd_generic_find_line, \
28417 +  NAME##_find_inliner_info, \
28418 +  NAME##_bfd_make_debug_symbol, \
28419 +  NAME##_read_minisymbols, \
28420 +  NAME##_minisymbol_to_symbol
28421 +
28422 +  long        (*_bfd_get_symtab_upper_bound) (bfd *);
28423 +  long        (*_bfd_canonicalize_symtab)
28424 +    (bfd *, struct bfd_symbol **);
28425 +  struct bfd_symbol *
28426 +              (*_bfd_make_empty_symbol) (bfd *);
28427 +  void        (*_bfd_print_symbol)
28428 +    (bfd *, void *, struct bfd_symbol *, bfd_print_symbol_type);
28429 +#define bfd_print_symbol(b,p,s,e) BFD_SEND (b, _bfd_print_symbol, (b,p,s,e))
28430 +  void        (*_bfd_get_symbol_info)
28431 +    (bfd *, struct bfd_symbol *, symbol_info *);
28432 +#define bfd_get_symbol_info(b,p,e) BFD_SEND (b, _bfd_get_symbol_info, (b,p,e))
28433 +  bfd_boolean (*_bfd_is_local_label_name) (bfd *, const char *);
28434 +  bfd_boolean (*_bfd_is_target_special_symbol) (bfd *, asymbol *);
28435 +  alent *     (*_get_lineno) (bfd *, struct bfd_symbol *);
28436 +  bfd_boolean (*_bfd_find_nearest_line)
28437 +    (bfd *, struct bfd_section *, struct bfd_symbol **, bfd_vma,
28438 +     const char **, const char **, unsigned int *);
28439 +  bfd_boolean (*_bfd_find_line)
28440 +    (bfd *, struct bfd_symbol **, struct bfd_symbol *,
28441 +     const char **, unsigned int *);
28442 +  bfd_boolean (*_bfd_find_inliner_info)
28443 +    (bfd *, const char **, const char **, unsigned int *);
28444 + /* Back-door to allow format-aware applications to create debug symbols
28445 +    while using BFD for everything else.  Currently used by the assembler
28446 +    when creating COFF files.  */
28447 +  asymbol *   (*_bfd_make_debug_symbol)
28448 +    (bfd *, void *, unsigned long size);
28449 +#define bfd_read_minisymbols(b, d, m, s) \
28450 +  BFD_SEND (b, _read_minisymbols, (b, d, m, s))
28451 +  long        (*_read_minisymbols)
28452 +    (bfd *, bfd_boolean, void **, unsigned int *);
28453 +#define bfd_minisymbol_to_symbol(b, d, m, f) \
28454 +  BFD_SEND (b, _minisymbol_to_symbol, (b, d, m, f))
28455 +  asymbol *   (*_minisymbol_to_symbol)
28456 +    (bfd *, bfd_boolean, const void *, asymbol *);
28457 +
28458 +  /* Routines for relocs.  */
28459 +#define BFD_JUMP_TABLE_RELOCS(NAME) \
28460 +  NAME##_get_reloc_upper_bound, \
28461 +  NAME##_canonicalize_reloc, \
28462 +  NAME##_bfd_reloc_type_lookup
28463 +
28464 +  long        (*_get_reloc_upper_bound) (bfd *, sec_ptr);
28465 +  long        (*_bfd_canonicalize_reloc)
28466 +    (bfd *, sec_ptr, arelent **, struct bfd_symbol **);
28467 +  /* See documentation on reloc types.  */
28468 +  reloc_howto_type *
28469 +              (*reloc_type_lookup) (bfd *, bfd_reloc_code_real_type);
28470 +
28471 +  /* Routines used when writing an object file.  */
28472 +#define BFD_JUMP_TABLE_WRITE(NAME) \
28473 +  NAME##_set_arch_mach, \
28474 +  NAME##_set_section_contents
28475 +
28476 +  bfd_boolean (*_bfd_set_arch_mach)
28477 +    (bfd *, enum bfd_architecture, unsigned long);
28478 +  bfd_boolean (*_bfd_set_section_contents)
28479 +    (bfd *, sec_ptr, const void *, file_ptr, bfd_size_type);
28480 +
28481 +  /* Routines used by the linker.  */
28482 +#define BFD_JUMP_TABLE_LINK(NAME) \
28483 +  NAME##_sizeof_headers, \
28484 +  NAME##_bfd_get_relocated_section_contents, \
28485 +  NAME##_bfd_relax_section, \
28486 +  NAME##_bfd_link_hash_table_create, \
28487 +  NAME##_bfd_link_hash_table_free, \
28488 +  NAME##_bfd_link_add_symbols, \
28489 +  NAME##_bfd_link_just_syms, \
28490 +  NAME##_bfd_final_link, \
28491 +  NAME##_bfd_link_split_section, \
28492 +  NAME##_bfd_gc_sections, \
28493 +  NAME##_bfd_merge_sections, \
28494 +  NAME##_bfd_is_group_section, \
28495 +  NAME##_bfd_discard_group, \
28496 +  NAME##_section_already_linked \
28497 +
28498 +  int         (*_bfd_sizeof_headers) (bfd *, bfd_boolean);
28499 +  bfd_byte *  (*_bfd_get_relocated_section_contents)
28500 +    (bfd *, struct bfd_link_info *, struct bfd_link_order *,
28501 +     bfd_byte *, bfd_boolean, struct bfd_symbol **);
28502 +
28503 +  bfd_boolean (*_bfd_relax_section)
28504 +    (bfd *, struct bfd_section *, struct bfd_link_info *, bfd_boolean *);
28505 +
28506 +  /* Create a hash table for the linker.  Different backends store
28507 +     different information in this table.  */
28508 +  struct bfd_link_hash_table *
28509 +              (*_bfd_link_hash_table_create) (bfd *);
28510 +
28511 +  /* Release the memory associated with the linker hash table.  */
28512 +  void        (*_bfd_link_hash_table_free) (struct bfd_link_hash_table *);
28513 +
28514 +  /* Add symbols from this object file into the hash table.  */
28515 +  bfd_boolean (*_bfd_link_add_symbols) (bfd *, struct bfd_link_info *);
28516 +
28517 +  /* Indicate that we are only retrieving symbol values from this section.  */
28518 +  void        (*_bfd_link_just_syms) (asection *, struct bfd_link_info *);
28519 +
28520 +  /* Do a link based on the link_order structures attached to each
28521 +     section of the BFD.  */
28522 +  bfd_boolean (*_bfd_final_link) (bfd *, struct bfd_link_info *);
28523 +
28524 +  /* Should this section be split up into smaller pieces during linking.  */
28525 +  bfd_boolean (*_bfd_link_split_section) (bfd *, struct bfd_section *);
28526 +
28527 +  /* Remove sections that are not referenced from the output.  */
28528 +  bfd_boolean (*_bfd_gc_sections) (bfd *, struct bfd_link_info *);
28529 +
28530 +  /* Attempt to merge SEC_MERGE sections.  */
28531 +  bfd_boolean (*_bfd_merge_sections) (bfd *, struct bfd_link_info *);
28532 +
28533 +  /* Is this section a member of a group?  */
28534 +  bfd_boolean (*_bfd_is_group_section) (bfd *, const struct bfd_section *);
28535 +
28536 +  /* Discard members of a group.  */
28537 +  bfd_boolean (*_bfd_discard_group) (bfd *, struct bfd_section *);
28538 +
28539 +  /* Check if SEC has been already linked during a reloceatable or
28540 +     final link.  */
28541 +  void (*_section_already_linked) (bfd *, struct bfd_section *);
28542 +
28543 +  /* Routines to handle dynamic symbols and relocs.  */
28544 +#define BFD_JUMP_TABLE_DYNAMIC(NAME) \
28545 +  NAME##_get_dynamic_symtab_upper_bound, \
28546 +  NAME##_canonicalize_dynamic_symtab, \
28547 +  NAME##_get_synthetic_symtab, \
28548 +  NAME##_get_dynamic_reloc_upper_bound, \
28549 +  NAME##_canonicalize_dynamic_reloc
28550 +
28551 +  /* Get the amount of memory required to hold the dynamic symbols.  */
28552 +  long        (*_bfd_get_dynamic_symtab_upper_bound) (bfd *);
28553 +  /* Read in the dynamic symbols.  */
28554 +  long        (*_bfd_canonicalize_dynamic_symtab)
28555 +    (bfd *, struct bfd_symbol **);
28556 +  /* Create synthetized symbols.  */
28557 +  long        (*_bfd_get_synthetic_symtab)
28558 +    (bfd *, long, struct bfd_symbol **, long, struct bfd_symbol **,
28559 +     struct bfd_symbol **);
28560 +  /* Get the amount of memory required to hold the dynamic relocs.  */
28561 +  long        (*_bfd_get_dynamic_reloc_upper_bound) (bfd *);
28562 +  /* Read in the dynamic relocs.  */
28563 +  long        (*_bfd_canonicalize_dynamic_reloc)
28564 +    (bfd *, arelent **, struct bfd_symbol **);
28565 +
28566 +  /* Opposite endian version of this target.  */
28567 +  const struct bfd_target * alternative_target;
28568 +
28569 +  /* Data for use by back-end routines, which isn't
28570 +     generic enough to belong in this structure.  */
28571 +  const void *backend_data;
28572 +
28573 +} bfd_target;
28574 +
28575 +bfd_boolean bfd_set_default_target (const char *name);
28576 +
28577 +const bfd_target *bfd_find_target (const char *target_name, bfd *abfd);
28578 +
28579 +const char ** bfd_target_list (void);
28580 +
28581 +const bfd_target *bfd_search_for_target
28582 +   (int (*search_func) (const bfd_target *, void *),
28583 +    void *);
28584 +
28585 +/* Extracted from format.c.  */
28586 +bfd_boolean bfd_check_format (bfd *abfd, bfd_format format);
28587 +
28588 +bfd_boolean bfd_check_format_matches
28589 +   (bfd *abfd, bfd_format format, char ***matching);
28590 +
28591 +bfd_boolean bfd_set_format (bfd *abfd, bfd_format format);
28592 +
28593 +const char *bfd_format_string (bfd_format format);
28594 +
28595 +/* Extracted from linker.c.  */
28596 +bfd_boolean bfd_link_split_section (bfd *abfd, asection *sec);
28597 +
28598 +#define bfd_link_split_section(abfd, sec) \
28599 +       BFD_SEND (abfd, _bfd_link_split_section, (abfd, sec))
28600 +
28601 +void bfd_section_already_linked (bfd *abfd, asection *sec);
28602 +
28603 +#define bfd_section_already_linked(abfd, sec) \
28604 +       BFD_SEND (abfd, _section_already_linked, (abfd, sec))
28605 +
28606 +/* Extracted from simple.c.  */
28607 +bfd_byte *bfd_simple_get_relocated_section_contents
28608 +   (bfd *abfd, asection *sec, bfd_byte *outbuf, asymbol **symbol_table);
28609 +
28610 +#ifdef __cplusplus
28611 +}
28612 +#endif
28613 +#endif
28614 diff -Nurp linux-2.6.22-590/include/asm-i386/kdb.h linux-2.6.22-600/include/asm-i386/kdb.h
28615 --- linux-2.6.22-590/include/asm-i386/kdb.h     1970-01-01 01:00:00.000000000 +0100
28616 +++ linux-2.6.22-600/include/asm-i386/kdb.h     2008-04-09 18:16:14.000000000 +0200
28617 @@ -0,0 +1,45 @@
28618 +#ifndef        _ASM_KDB_H
28619 +#define _ASM_KDB_H
28620 +
28621 +/*
28622 + * Kernel Debugger Architecture Dependent Global Headers
28623 + *
28624 + * This file is subject to the terms and conditions of the GNU General Public
28625 + * License.  See the file "COPYING" in the main directory of this archive
28626 + * for more details.
28627 + *
28628 + * Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
28629 + */
28630 +
28631 +/*
28632 + * KDB_ENTER() is a macro which causes entry into the kernel
28633 + * debugger from any point in the kernel code stream.  If it
28634 + * is intended to be used from interrupt level, it must  use
28635 + * a non-maskable entry method.
28636 + */
28637 +#define KDB_ENTER()    do {if (kdb_on && !KDB_IS_RUNNING()) { asm("\tint $129\n"); }} while(0)
28638 +
28639 +/*
28640 + * Needed for exported symbols.
28641 + */
28642 +typedef unsigned long kdb_machreg_t;
28643 +
28644 +#define kdb_machreg_fmt                "0x%lx"
28645 +#define kdb_machreg_fmt0       "0x%08lx"
28646 +#define kdb_bfd_vma_fmt                "0x%lx"
28647 +#define kdb_bfd_vma_fmt0       "0x%08lx"
28648 +#define kdb_elfw_addr_fmt      "0x%x"
28649 +#define kdb_elfw_addr_fmt0     "0x%08x"
28650 +
28651 +/*
28652 + * Per cpu arch specific kdb state.  Must be in range 0xff000000.
28653 + */
28654 +#define KDB_STATE_A_IF         0x01000000      /* Saved IF flag */
28655 +
28656 +static inline unsigned long
28657 +kdba_funcptr_value(void *fp)
28658 +{
28659 +       return (unsigned long)fp;
28660 +}
28661 +
28662 +#endif /* !_ASM_KDB_H */
28663 diff -Nurp linux-2.6.22-590/include/asm-i386/kdbprivate.h linux-2.6.22-600/include/asm-i386/kdbprivate.h
28664 --- linux-2.6.22-590/include/asm-i386/kdbprivate.h      1970-01-01 01:00:00.000000000 +0100
28665 +++ linux-2.6.22-600/include/asm-i386/kdbprivate.h      2008-04-09 18:16:14.000000000 +0200
28666 @@ -0,0 +1,189 @@
28667 +#ifndef        _ASM_KDBPRIVATE_H
28668 +#define _ASM_KDBPRIVATE_H
28669 +
28670 +/*
28671 + * Kernel Debugger Architecture Dependent Private Headers
28672 + *
28673 + * This file is subject to the terms and conditions of the GNU General Public
28674 + * License.  See the file "COPYING" in the main directory of this archive
28675 + * for more details.
28676 + *
28677 + * Copyright (c) 1999-2006 Silicon Graphics, Inc.  All Rights Reserved.
28678 + */
28679 +
28680 +typedef unsigned char kdb_machinst_t;
28681 +
28682 +/*
28683 + * KDB_MAXBPT describes the total number of breakpoints
28684 + * supported by this architecure.
28685 + */
28686 +#define KDB_MAXBPT     16
28687 +
28688 +/*
28689 + * KDB_MAXHARDBPT describes the total number of hardware
28690 + * breakpoint registers that exist.
28691 + */
28692 +#define KDB_MAXHARDBPT  4
28693 +
28694 +/* Maximum number of arguments to a function  */
28695 +#define KDBA_MAXARGS   16
28696 +
28697 +/*
28698 + * Platform specific environment entries
28699 + */
28700 +#define KDB_PLATFORM_ENV       "IDMODE=x86", "BYTESPERWORD=4", "IDCOUNT=16"
28701 +
28702 +/*
28703 + * Support for ia32 debug registers
28704 + */
28705 +typedef struct _kdbhard_bp {
28706 +       kdb_machreg_t   bph_reg;        /* Register this breakpoint uses */
28707 +
28708 +       unsigned int    bph_free:1;     /* Register available for use */
28709 +       unsigned int    bph_data:1;     /* Data Access breakpoint */
28710 +
28711 +       unsigned int    bph_write:1;    /* Write Data breakpoint */
28712 +       unsigned int    bph_mode:2;     /* 0=inst, 1=write, 2=io, 3=read */
28713 +       unsigned int    bph_length:2;   /* 0=1, 1=2, 2=BAD, 3=4 (bytes) */
28714 +} kdbhard_bp_t;
28715 +
28716 +#define IA32_BREAKPOINT_INSTRUCTION    0xcc
28717 +
28718 +#define DR6_BT  0x00008000
28719 +#define DR6_BS  0x00004000
28720 +#define DR6_BD  0x00002000
28721 +
28722 +#define DR6_B3  0x00000008
28723 +#define DR6_B2  0x00000004
28724 +#define DR6_B1  0x00000002
28725 +#define DR6_B0  0x00000001
28726 +#define DR6_DR_MASK  0x0000000F
28727 +
28728 +#define DR7_RW_VAL(dr, drnum) \
28729 +       (((dr) >> (16 + (4 * (drnum)))) & 0x3)
28730 +
28731 +#define DR7_RW_SET(dr, drnum, rw)                              \
28732 +       do {                                                    \
28733 +              (dr) &= ~(0x3 << (16 + (4 * (drnum))));         \
28734 +              (dr) |= (((rw) & 0x3) << (16 + (4 * (drnum)))); \
28735 +       } while (0)
28736 +
28737 +#define DR7_RW0(dr)            DR7_RW_VAL(dr, 0)
28738 +#define DR7_RW0SET(dr,rw)      DR7_RW_SET(dr, 0, rw)
28739 +#define DR7_RW1(dr)            DR7_RW_VAL(dr, 1)
28740 +#define DR7_RW1SET(dr,rw)      DR7_RW_SET(dr, 1, rw)
28741 +#define DR7_RW2(dr)            DR7_RW_VAL(dr, 2)
28742 +#define DR7_RW2SET(dr,rw)      DR7_RW_SET(dr, 2, rw)
28743 +#define DR7_RW3(dr)            DR7_RW_VAL(dr, 3)
28744 +#define DR7_RW3SET(dr,rw)      DR7_RW_SET(dr, 3, rw)
28745 +
28746 +
28747 +#define DR7_LEN_VAL(dr, drnum) \
28748 +       (((dr) >> (18 + (4 * (drnum)))) & 0x3)
28749 +
28750 +#define DR7_LEN_SET(dr, drnum, rw)                             \
28751 +       do {                                                    \
28752 +              (dr) &= ~(0x3 << (18 + (4 * (drnum))));         \
28753 +              (dr) |= (((rw) & 0x3) << (18 + (4 * (drnum)))); \
28754 +       } while (0)
28755 +
28756 +#define DR7_LEN0(dr)           DR7_LEN_VAL(dr, 0)
28757 +#define DR7_LEN0SET(dr,len)    DR7_LEN_SET(dr, 0, len)
28758 +#define DR7_LEN1(dr)           DR7_LEN_VAL(dr, 1)
28759 +#define DR7_LEN1SET(dr,len)    DR7_LEN_SET(dr, 1, len)
28760 +#define DR7_LEN2(dr)           DR7_LEN_VAL(dr, 2)
28761 +#define DR7_LEN2SET(dr,len)    DR7_LEN_SET(dr, 2, len)
28762 +#define DR7_LEN3(dr)           DR7_LEN_VAL(dr, 3)
28763 +#define DR7_LEN3SET(dr,len)    DR7_LEN_SET(dr, 3, len)
28764 +
28765 +#define DR7_G0(dr)    (((dr)>>1)&0x1)
28766 +#define DR7_G0SET(dr) ((dr) |= 0x2)
28767 +#define DR7_G0CLR(dr) ((dr) &= ~0x2)
28768 +#define DR7_G1(dr)    (((dr)>>3)&0x1)
28769 +#define DR7_G1SET(dr) ((dr) |= 0x8)
28770 +#define DR7_G1CLR(dr) ((dr) &= ~0x8)
28771 +#define DR7_G2(dr)    (((dr)>>5)&0x1)
28772 +#define DR7_G2SET(dr) ((dr) |= 0x20)
28773 +#define DR7_G2CLR(dr) ((dr) &= ~0x20)
28774 +#define DR7_G3(dr)    (((dr)>>7)&0x1)
28775 +#define DR7_G3SET(dr) ((dr) |= 0x80)
28776 +#define DR7_G3CLR(dr) ((dr) &= ~0x80)
28777 +
28778 +#define DR7_L0(dr)    (((dr))&0x1)
28779 +#define DR7_L0SET(dr) ((dr) |= 0x1)
28780 +#define DR7_L0CLR(dr) ((dr) &= ~0x1)
28781 +#define DR7_L1(dr)    (((dr)>>2)&0x1)
28782 +#define DR7_L1SET(dr) ((dr) |= 0x4)
28783 +#define DR7_L1CLR(dr) ((dr) &= ~0x4)
28784 +#define DR7_L2(dr)    (((dr)>>4)&0x1)
28785 +#define DR7_L2SET(dr) ((dr) |= 0x10)
28786 +#define DR7_L2CLR(dr) ((dr) &= ~0x10)
28787 +#define DR7_L3(dr)    (((dr)>>6)&0x1)
28788 +#define DR7_L3SET(dr) ((dr) |= 0x40)
28789 +#define DR7_L3CLR(dr) ((dr) &= ~0x40)
28790 +
28791 +#define DR7_GD          0x00002000              /* General Detect Enable */
28792 +#define DR7_GE          0x00000200              /* Global exact */
28793 +#define DR7_LE          0x00000100              /* Local exact */
28794 +
28795 +#define DR_TYPE_EXECUTE        0x0
28796 +#define DR_TYPE_WRITE  0x1
28797 +#define DR_TYPE_IO     0x2
28798 +#define DR_TYPE_RW     0x3
28799 +
28800 +extern kdb_machreg_t kdba_getdr6(void);
28801 +extern void kdba_putdr6(kdb_machreg_t);
28802 +
28803 +extern kdb_machreg_t kdba_getdr7(void);
28804 +
28805 +/*
28806 + * Support for setjmp/longjmp
28807 + */
28808 +#define JB_BX   0
28809 +#define JB_SI   1
28810 +#define JB_DI   2
28811 +#define JB_BP   3
28812 +#define JB_SP   4
28813 +#define JB_PC   5
28814 +
28815 +typedef struct __kdb_jmp_buf {
28816 +       unsigned long   regs[6];        /* kdba_setjmp assumes fixed offsets here */
28817 +} kdb_jmp_buf;
28818 +
28819 +extern int asmlinkage kdba_setjmp(kdb_jmp_buf *);
28820 +extern void asmlinkage kdba_longjmp(kdb_jmp_buf *, int);
28821 +#define kdba_setjmp kdba_setjmp
28822 +
28823 +extern kdb_jmp_buf  *kdbjmpbuf;
28824 +
28825 +/* Arch specific data saved for running processes */
28826 +
28827 +struct kdba_running_process {
28828 +       long esp;       /* CONFIG_4KSTACKS may be on a different stack */
28829 +       long eip;       /* eip when esp was set */
28830 +};
28831 +
28832 +static inline
28833 +void kdba_save_running(struct kdba_running_process *k, struct pt_regs *regs)
28834 +{
28835 +       k->esp = current_stack_pointer;
28836 +       __asm__ __volatile__ ( " lea 1f,%%eax; movl %%eax,%0 ; 1: " : "=r"(k->eip) : : "eax" );
28837 +}
28838 +
28839 +static inline
28840 +void kdba_unsave_running(struct kdba_running_process *k, struct pt_regs *regs)
28841 +{
28842 +}
28843 +
28844 +struct kdb_activation_record;
28845 +extern void kdba_get_stack_info_alternate(kdb_machreg_t addr, int cpu,
28846 +                                         struct kdb_activation_record *ar);
28847 +
28848 +extern void kdba_wait_for_cpus(void);
28849 +
28850 +extern fastcall void kdb_interrupt(void);
28851 +
28852 +#define        KDB_INT_REGISTERS       8
28853 +
28854 +
28855 +#endif /* !_ASM_KDBPRIVATE_H */
28856 diff -Nurp linux-2.6.22-590/include/asm-i386/kdebug.h linux-2.6.22-600/include/asm-i386/kdebug.h
28857 --- linux-2.6.22-590/include/asm-i386/kdebug.h  2007-07-09 01:32:17.000000000 +0200
28858 +++ linux-2.6.22-600/include/asm-i386/kdebug.h  2008-04-09 18:16:14.000000000 +0200
28859 @@ -23,6 +23,8 @@ enum die_val {
28860         DIE_DIE,
28861         DIE_NMIWATCHDOG,
28862         DIE_KERNELDEBUG,
28863 +       DIE_KDEBUG_ENTER,
28864 +       DIE_KDEBUG_LEAVE,
28865         DIE_TRAP,
28866         DIE_GPF,
28867         DIE_CALL,
28868 diff -Nurp linux-2.6.22-590/include/asm-i386/kmap_types.h linux-2.6.22-600/include/asm-i386/kmap_types.h
28869 --- linux-2.6.22-590/include/asm-i386/kmap_types.h      2007-07-09 01:32:17.000000000 +0200
28870 +++ linux-2.6.22-600/include/asm-i386/kmap_types.h      2008-04-09 18:16:14.000000000 +0200
28871 @@ -22,7 +22,8 @@ D(9)  KM_IRQ0,
28872  D(10)  KM_IRQ1,
28873  D(11)  KM_SOFTIRQ0,
28874  D(12)  KM_SOFTIRQ1,
28875 -D(13)  KM_TYPE_NR
28876 +D(13)  KM_KDB,
28877 +D(14)  KM_TYPE_NR
28878  };
28879  
28880  #undef D
28881 diff -Nurp linux-2.6.22-590/include/asm-i386/mach-default/irq_vectors.h linux-2.6.22-600/include/asm-i386/mach-default/irq_vectors.h
28882 --- linux-2.6.22-590/include/asm-i386/mach-default/irq_vectors.h        2007-07-09 01:32:17.000000000 +0200
28883 +++ linux-2.6.22-600/include/asm-i386/mach-default/irq_vectors.h        2008-04-09 18:16:14.000000000 +0200
28884 @@ -29,6 +29,7 @@
28885  #define FIRST_EXTERNAL_VECTOR  0x20
28886  
28887  #define SYSCALL_VECTOR         0x80
28888 +#define KDBENTER_VECTOR                0x81
28889  
28890  /*
28891   * Vectors 0x20-0x2f are used for ISA interrupts.
28892 @@ -48,6 +49,7 @@
28893  #define INVALIDATE_TLB_VECTOR  0xfd
28894  #define RESCHEDULE_VECTOR      0xfc
28895  #define CALL_FUNCTION_VECTOR   0xfb
28896 +#define KDB_VECTOR             0xf9
28897  
28898  #define THERMAL_APIC_VECTOR    0xf0
28899  /*
28900 diff -Nurp linux-2.6.22-590/include/asm-i386/ptrace.h linux-2.6.22-600/include/asm-i386/ptrace.h
28901 --- linux-2.6.22-590/include/asm-i386/ptrace.h  2007-07-09 01:32:17.000000000 +0200
28902 +++ linux-2.6.22-600/include/asm-i386/ptrace.h  2008-04-09 18:16:14.000000000 +0200
28903 @@ -26,6 +26,29 @@ struct pt_regs {
28904         int  xss;
28905  };
28906  
28907 +enum EFLAGS {
28908 +        EF_CF   = 0x00000001,
28909 +        EF_PF   = 0x00000004,
28910 +        EF_AF   = 0x00000010,
28911 +        EF_ZF   = 0x00000040,
28912 +        EF_SF   = 0x00000080,
28913 +        EF_TF   = 0x00000100,
28914 +        EF_IE   = 0x00000200,
28915 +        EF_DF   = 0x00000400,
28916 +        EF_OF   = 0x00000800,
28917 +        EF_IOPL = 0x00003000,
28918 +        EF_IOPL_RING0 = 0x00000000,
28919 +        EF_IOPL_RING1 = 0x00001000,
28920 +        EF_IOPL_RING2 = 0x00002000,
28921 +        EF_NT   = 0x00004000,   /* nested task */
28922 +        EF_RF   = 0x00010000,   /* resume */
28923 +        EF_VM   = 0x00020000,   /* virtual mode */
28924 +        EF_AC   = 0x00040000,   /* alignment */
28925 +        EF_VIF  = 0x00080000,   /* virtual interrupt */
28926 +        EF_VIP  = 0x00100000,   /* virtual interrupt pending */
28927 +        EF_ID   = 0x00200000,   /* id */
28928 +};
28929 +
28930  #ifdef __KERNEL__
28931  
28932  #include <asm/vm86.h>
28933 diff -Nurp linux-2.6.22-590/include/asm-x86_64/ansidecl.h linux-2.6.22-600/include/asm-x86_64/ansidecl.h
28934 --- linux-2.6.22-590/include/asm-x86_64/ansidecl.h      1970-01-01 01:00:00.000000000 +0100
28935 +++ linux-2.6.22-600/include/asm-x86_64/ansidecl.h      2008-04-09 18:16:24.000000000 +0200
28936 @@ -0,0 +1,383 @@
28937 +/* ANSI and traditional C compatability macros
28938 +   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001
28939 +   Free Software Foundation, Inc.
28940 +   This file is part of the GNU C Library.
28941 +
28942 +This program is free software; you can redistribute it and/or modify
28943 +it under the terms of the GNU General Public License as published by
28944 +the Free Software Foundation; either version 2 of the License, or
28945 +(at your option) any later version.
28946 +
28947 +This program is distributed in the hope that it will be useful,
28948 +but WITHOUT ANY WARRANTY; without even the implied warranty of
28949 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28950 +GNU General Public License for more details.
28951 +
28952 +You should have received a copy of the GNU General Public License
28953 +along with this program; if not, write to the Free Software
28954 +Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
28955 +
28956 +/* Extracted from binutils 2.16.91.0.2 (OpenSUSE 10.0) and modified for kdb use.
28957 + * Any trailing whitespace was removed and #ifdef/ifndef __KERNEL__ added as
28958 + * required.
28959 + * Keith Owens <kaos@sgi.com> 15 May 2006
28960 + */
28961 +
28962 +/* ANSI and traditional C compatibility macros
28963 +
28964 +   ANSI C is assumed if __STDC__ is #defined.
28965 +
28966 +   Macro               ANSI C definition       Traditional C definition
28967 +   -----               ---- - ----------       ----------- - ----------
28968 +   ANSI_PROTOTYPES     1                       not defined
28969 +   PTR                 `void *'                `char *'
28970 +   PTRCONST            `void *const'           `char *'
28971 +   LONG_DOUBLE         `long double'           `double'
28972 +   const               not defined             `'
28973 +   volatile            not defined             `'
28974 +   signed              not defined             `'
28975 +   VA_START(ap, var)   va_start(ap, var)       va_start(ap)
28976 +
28977 +   Note that it is safe to write "void foo();" indicating a function
28978 +   with no return value, in all K+R compilers we have been able to test.
28979 +
28980 +   For declaring functions with prototypes, we also provide these:
28981 +
28982 +   PARAMS ((prototype))
28983 +   -- for functions which take a fixed number of arguments.  Use this
28984 +   when declaring the function.  When defining the function, write a
28985 +   K+R style argument list.  For example:
28986 +
28987 +       char *strcpy PARAMS ((char *dest, char *source));
28988 +       ...
28989 +       char *
28990 +       strcpy (dest, source)
28991 +            char *dest;
28992 +            char *source;
28993 +       { ... }
28994 +
28995 +
28996 +   VPARAMS ((prototype, ...))
28997 +   -- for functions which take a variable number of arguments.  Use
28998 +   PARAMS to declare the function, VPARAMS to define it.  For example:
28999 +
29000 +       int printf PARAMS ((const char *format, ...));
29001 +       ...
29002 +       int
29003 +       printf VPARAMS ((const char *format, ...))
29004 +       {
29005 +          ...
29006 +       }
29007 +
29008 +   For writing functions which take variable numbers of arguments, we
29009 +   also provide the VA_OPEN, VA_CLOSE, and VA_FIXEDARG macros.  These
29010 +   hide the differences between K+R <varargs.h> and C89 <stdarg.h> more
29011 +   thoroughly than the simple VA_START() macro mentioned above.
29012 +
29013 +   VA_OPEN and VA_CLOSE are used *instead of* va_start and va_end.
29014 +   Immediately after VA_OPEN, put a sequence of VA_FIXEDARG calls
29015 +   corresponding to the list of fixed arguments.  Then use va_arg
29016 +   normally to get the variable arguments, or pass your va_list object
29017 +   around.  You do not declare the va_list yourself; VA_OPEN does it
29018 +   for you.
29019 +
29020 +   Here is a complete example:
29021 +
29022 +       int
29023 +       printf VPARAMS ((const char *format, ...))
29024 +       {
29025 +          int result;
29026 +
29027 +          VA_OPEN (ap, format);
29028 +          VA_FIXEDARG (ap, const char *, format);
29029 +
29030 +          result = vfprintf (stdout, format, ap);
29031 +          VA_CLOSE (ap);
29032 +
29033 +          return result;
29034 +       }
29035 +
29036 +
29037 +   You can declare variables either before or after the VA_OPEN,
29038 +   VA_FIXEDARG sequence.  Also, VA_OPEN and VA_CLOSE are the beginning
29039 +   and end of a block.  They must appear at the same nesting level,
29040 +   and any variables declared after VA_OPEN go out of scope at
29041 +   VA_CLOSE.  Unfortunately, with a K+R compiler, that includes the
29042 +   argument list.  You can have multiple instances of VA_OPEN/VA_CLOSE
29043 +   pairs in a single function in case you need to traverse the
29044 +   argument list more than once.
29045 +
29046 +   For ease of writing code which uses GCC extensions but needs to be
29047 +   portable to other compilers, we provide the GCC_VERSION macro that
29048 +   simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
29049 +   wrappers around __attribute__.  Also, __extension__ will be #defined
29050 +   to nothing if it doesn't work.  See below.
29051 +
29052 +   This header also defines a lot of obsolete macros:
29053 +   CONST, VOLATILE, SIGNED, PROTO, EXFUN, DEFUN, DEFUN_VOID,
29054 +   AND, DOTS, NOARGS.  Don't use them.  */
29055 +
29056 +#ifndef        _ANSIDECL_H
29057 +#define _ANSIDECL_H    1
29058 +
29059 +/* Every source file includes this file,
29060 +   so they will all get the switch for lint.  */
29061 +/* LINTLIBRARY */
29062 +
29063 +/* Using MACRO(x,y) in cpp #if conditionals does not work with some
29064 +   older preprocessors.  Thus we can't define something like this:
29065 +
29066 +#define HAVE_GCC_VERSION(MAJOR, MINOR) \
29067 +  (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR)))
29068 +
29069 +and then test "#if HAVE_GCC_VERSION(2,7)".
29070 +
29071 +So instead we use the macro below and test it against specific values.  */
29072 +
29073 +/* This macro simplifies testing whether we are using gcc, and if it
29074 +   is of a particular minimum version. (Both major & minor numbers are
29075 +   significant.)  This macro will evaluate to 0 if we are not using
29076 +   gcc at all.  */
29077 +#ifndef GCC_VERSION
29078 +#define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
29079 +#endif /* GCC_VERSION */
29080 +
29081 +#if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32) || (defined(__alpha) && defined(__cplusplus))
29082 +/* All known AIX compilers implement these things (but don't always
29083 +   define __STDC__).  The RISC/OS MIPS compiler defines these things
29084 +   in SVR4 mode, but does not define __STDC__.  */
29085 +/* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other
29086 +   C++ compilers, does not define __STDC__, though it acts as if this
29087 +   was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */
29088 +
29089 +#define ANSI_PROTOTYPES        1
29090 +#define PTR            void *
29091 +#define PTRCONST       void *const
29092 +#define LONG_DOUBLE    long double
29093 +
29094 +/* PARAMS is often defined elsewhere (e.g. by libintl.h), so wrap it in
29095 +   a #ifndef.  */
29096 +#ifndef PARAMS
29097 +#define PARAMS(ARGS)           ARGS
29098 +#endif
29099 +
29100 +#define VPARAMS(ARGS)          ARGS
29101 +#define VA_START(VA_LIST, VAR) va_start(VA_LIST, VAR)
29102 +
29103 +/* variadic function helper macros */
29104 +/* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's
29105 +   use without inhibiting further decls and without declaring an
29106 +   actual variable.  */
29107 +#define VA_OPEN(AP, VAR)       { va_list AP; va_start(AP, VAR); { struct Qdmy
29108 +#define VA_CLOSE(AP)           } va_end(AP); }
29109 +#define VA_FIXEDARG(AP, T, N)  struct Qdmy
29110 +
29111 +#undef const
29112 +#undef volatile
29113 +#undef signed
29114 +
29115 +#ifdef __KERNEL__
29116 +#ifndef        __STDC_VERSION__
29117 +#define        __STDC_VERSION__ 0
29118 +#endif
29119 +#endif /* __KERNEL__ */
29120 +
29121 +/* inline requires special treatment; it's in C99, and GCC >=2.7 supports
29122 +   it too, but it's not in C89.  */
29123 +#undef inline
29124 +#if __STDC_VERSION__ > 199901L
29125 +/* it's a keyword */
29126 +#else
29127 +# if GCC_VERSION >= 2007
29128 +#  define inline __inline__   /* __inline__ prevents -pedantic warnings */
29129 +# else
29130 +#  define inline  /* nothing */
29131 +# endif
29132 +#endif
29133 +
29134 +/* These are obsolete.  Do not use.  */
29135 +#ifndef IN_GCC
29136 +#define CONST          const
29137 +#define VOLATILE       volatile
29138 +#define SIGNED         signed
29139 +
29140 +#define PROTO(type, name, arglist)     type name arglist
29141 +#define EXFUN(name, proto)             name proto
29142 +#define DEFUN(name, arglist, args)     name(args)
29143 +#define DEFUN_VOID(name)               name(void)
29144 +#define AND            ,
29145 +#define DOTS           , ...
29146 +#define NOARGS         void
29147 +#endif /* ! IN_GCC */
29148 +
29149 +#else  /* Not ANSI C.  */
29150 +
29151 +#undef  ANSI_PROTOTYPES
29152 +#define PTR            char *
29153 +#define PTRCONST       PTR
29154 +#define LONG_DOUBLE    double
29155 +
29156 +#define PARAMS(args)           ()
29157 +#define VPARAMS(args)          (va_alist) va_dcl
29158 +#define VA_START(va_list, var) va_start(va_list)
29159 +
29160 +#define VA_OPEN(AP, VAR)               { va_list AP; va_start(AP); { struct Qdmy
29161 +#define VA_CLOSE(AP)                   } va_end(AP); }
29162 +#define VA_FIXEDARG(AP, TYPE, NAME)    TYPE NAME = va_arg(AP, TYPE)
29163 +
29164 +/* some systems define these in header files for non-ansi mode */
29165 +#undef const
29166 +#undef volatile
29167 +#undef signed
29168 +#undef inline
29169 +#define const
29170 +#define volatile
29171 +#define signed
29172 +#define inline
29173 +
29174 +#ifndef IN_GCC
29175 +#define CONST
29176 +#define VOLATILE
29177 +#define SIGNED
29178 +
29179 +#define PROTO(type, name, arglist)     type name ()
29180 +#define EXFUN(name, proto)             name()
29181 +#define DEFUN(name, arglist, args)     name arglist args;
29182 +#define DEFUN_VOID(name)               name()
29183 +#define AND            ;
29184 +#define DOTS
29185 +#define NOARGS
29186 +#endif /* ! IN_GCC */
29187 +
29188 +#endif /* ANSI C.  */
29189 +
29190 +/* Define macros for some gcc attributes.  This permits us to use the
29191 +   macros freely, and know that they will come into play for the
29192 +   version of gcc in which they are supported.  */
29193 +
29194 +#if (GCC_VERSION < 2007)
29195 +# define __attribute__(x)
29196 +#endif
29197 +
29198 +/* Attribute __malloc__ on functions was valid as of gcc 2.96. */
29199 +#ifndef ATTRIBUTE_MALLOC
29200 +# if (GCC_VERSION >= 2096)
29201 +#  define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
29202 +# else
29203 +#  define ATTRIBUTE_MALLOC
29204 +# endif /* GNUC >= 2.96 */
29205 +#endif /* ATTRIBUTE_MALLOC */
29206 +
29207 +/* Attributes on labels were valid as of gcc 2.93. */
29208 +#ifndef ATTRIBUTE_UNUSED_LABEL
29209 +# if (!defined (__cplusplus) && GCC_VERSION >= 2093)
29210 +#  define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
29211 +# else
29212 +#  define ATTRIBUTE_UNUSED_LABEL
29213 +# endif /* !__cplusplus && GNUC >= 2.93 */
29214 +#endif /* ATTRIBUTE_UNUSED_LABEL */
29215 +
29216 +#ifndef ATTRIBUTE_UNUSED
29217 +#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
29218 +#endif /* ATTRIBUTE_UNUSED */
29219 +
29220 +/* Before GCC 3.4, the C++ frontend couldn't parse attributes placed after the
29221 +   identifier name.  */
29222 +#if ! defined(__cplusplus) || (GCC_VERSION >= 3004)
29223 +# define ARG_UNUSED(NAME) NAME ATTRIBUTE_UNUSED
29224 +#else /* !__cplusplus || GNUC >= 3.4 */
29225 +# define ARG_UNUSED(NAME) NAME
29226 +#endif /* !__cplusplus || GNUC >= 3.4 */
29227 +
29228 +#ifndef ATTRIBUTE_NORETURN
29229 +#define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
29230 +#endif /* ATTRIBUTE_NORETURN */
29231 +
29232 +/* Attribute `nonnull' was valid as of gcc 3.3.  */
29233 +#ifndef ATTRIBUTE_NONNULL
29234 +# if (GCC_VERSION >= 3003)
29235 +#  define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
29236 +# else
29237 +#  define ATTRIBUTE_NONNULL(m)
29238 +# endif /* GNUC >= 3.3 */
29239 +#endif /* ATTRIBUTE_NONNULL */
29240 +
29241 +/* Attribute `pure' was valid as of gcc 3.0.  */
29242 +#ifndef ATTRIBUTE_PURE
29243 +# if (GCC_VERSION >= 3000)
29244 +#  define ATTRIBUTE_PURE __attribute__ ((__pure__))
29245 +# else
29246 +#  define ATTRIBUTE_PURE
29247 +# endif /* GNUC >= 3.0 */
29248 +#endif /* ATTRIBUTE_PURE */
29249 +
29250 +/* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL.
29251 +   This was the case for the `printf' format attribute by itself
29252 +   before GCC 3.3, but as of 3.3 we need to add the `nonnull'
29253 +   attribute to retain this behavior.  */
29254 +#ifndef ATTRIBUTE_PRINTF
29255 +#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m)
29256 +#define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
29257 +#define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
29258 +#define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
29259 +#define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5)
29260 +#define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
29261 +#endif /* ATTRIBUTE_PRINTF */
29262 +
29263 +/* Use ATTRIBUTE_FPTR_PRINTF when the format attribute is to be set on
29264 +   a function pointer.  Format attributes were allowed on function
29265 +   pointers as of gcc 3.1.  */
29266 +#ifndef ATTRIBUTE_FPTR_PRINTF
29267 +# if (GCC_VERSION >= 3001)
29268 +#  define ATTRIBUTE_FPTR_PRINTF(m, n) ATTRIBUTE_PRINTF(m, n)
29269 +# else
29270 +#  define ATTRIBUTE_FPTR_PRINTF(m, n)
29271 +# endif /* GNUC >= 3.1 */
29272 +# define ATTRIBUTE_FPTR_PRINTF_1 ATTRIBUTE_FPTR_PRINTF(1, 2)
29273 +# define ATTRIBUTE_FPTR_PRINTF_2 ATTRIBUTE_FPTR_PRINTF(2, 3)
29274 +# define ATTRIBUTE_FPTR_PRINTF_3 ATTRIBUTE_FPTR_PRINTF(3, 4)
29275 +# define ATTRIBUTE_FPTR_PRINTF_4 ATTRIBUTE_FPTR_PRINTF(4, 5)
29276 +# define ATTRIBUTE_FPTR_PRINTF_5 ATTRIBUTE_FPTR_PRINTF(5, 6)
29277 +#endif /* ATTRIBUTE_FPTR_PRINTF */
29278 +
29279 +/* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL.  A
29280 +   NULL format specifier was allowed as of gcc 3.3.  */
29281 +#ifndef ATTRIBUTE_NULL_PRINTF
29282 +# if (GCC_VERSION >= 3003)
29283 +#  define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
29284 +# else
29285 +#  define ATTRIBUTE_NULL_PRINTF(m, n)
29286 +# endif /* GNUC >= 3.3 */
29287 +# define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2)
29288 +# define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3)
29289 +# define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4)
29290 +# define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5)
29291 +# define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6)
29292 +#endif /* ATTRIBUTE_NULL_PRINTF */
29293 +
29294 +/* Attribute `sentinel' was valid as of gcc 3.5.  */
29295 +#ifndef ATTRIBUTE_SENTINEL
29296 +# if (GCC_VERSION >= 3005)
29297 +#  define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
29298 +# else
29299 +#  define ATTRIBUTE_SENTINEL
29300 +# endif /* GNUC >= 3.5 */
29301 +#endif /* ATTRIBUTE_SENTINEL */
29302 +
29303 +
29304 +#ifndef ATTRIBUTE_ALIGNED_ALIGNOF
29305 +# if (GCC_VERSION >= 3000)
29306 +#  define ATTRIBUTE_ALIGNED_ALIGNOF(m) __attribute__ ((__aligned__ (__alignof__ (m))))
29307 +# else
29308 +#  define ATTRIBUTE_ALIGNED_ALIGNOF(m)
29309 +# endif /* GNUC >= 3.0 */
29310 +#endif /* ATTRIBUTE_ALIGNED_ALIGNOF */
29311 +
29312 +/* We use __extension__ in some places to suppress -pedantic warnings
29313 +   about GCC extensions.  This feature didn't work properly before
29314 +   gcc 2.8.  */
29315 +#if GCC_VERSION < 2008
29316 +#define __extension__
29317 +#endif
29318 +
29319 +#endif /* ansidecl.h   */
29320 diff -Nurp linux-2.6.22-590/include/asm-x86_64/bfd.h linux-2.6.22-600/include/asm-x86_64/bfd.h
29321 --- linux-2.6.22-590/include/asm-x86_64/bfd.h   1970-01-01 01:00:00.000000000 +0100
29322 +++ linux-2.6.22-600/include/asm-x86_64/bfd.h   2008-04-09 18:16:24.000000000 +0200
29323 @@ -0,0 +1,4917 @@
29324 +/* DO NOT EDIT!  -*- buffer-read-only: t -*-  This file is automatically
29325 +   generated from "bfd-in.h", "init.c", "opncls.c", "libbfd.c",
29326 +   "bfdio.c", "bfdwin.c", "section.c", "archures.c", "reloc.c",
29327 +   "syms.c", "bfd.c", "archive.c", "corefile.c", "targets.c", "format.c",
29328 +   "linker.c" and "simple.c".
29329 +   Run "make headers" in your build bfd/ to regenerate.  */
29330 +
29331 +/* Main header file for the bfd library -- portable access to object files.
29332 +
29333 +   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
29334 +   1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
29335 +
29336 +   Contributed by Cygnus Support.
29337 +
29338 +   This file is part of BFD, the Binary File Descriptor library.
29339 +
29340 +   This program is free software; you can redistribute it and/or modify
29341 +   it under the terms of the GNU General Public License as published by
29342 +   the Free Software Foundation; either version 2 of the License, or
29343 +   (at your option) any later version.
29344 +
29345 +   This program is distributed in the hope that it will be useful,
29346 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
29347 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29348 +   GNU General Public License for more details.
29349 +
29350 +   You should have received a copy of the GNU General Public License
29351 +   along with this program; if not, write to the Free Software
29352 +   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
29353 +
29354 +/* Extracted from binutils 2.16.91.0.2 (OpenSUSE 10.0) and modified for kdb use.
29355 + * Any trailing whitespace was removed and #ifdef/ifndef __KERNEL__ added as
29356 + * required.
29357 + * Keith Owens <kaos@sgi.com> 15 May 2006
29358 + */
29359 +
29360 +#ifndef __BFD_H_SEEN__
29361 +#define __BFD_H_SEEN__
29362 +
29363 +#ifdef __cplusplus
29364 +extern "C" {
29365 +#endif
29366 +
29367 +#ifdef __KERNEL__
29368 +#include <asm/ansidecl.h>
29369 +#else  /* __KERNEL__ */
29370 +#include "ansidecl.h"
29371 +#include "symcat.h"
29372 +#endif /* __KERNEL__ */
29373 +#if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
29374 +#ifndef SABER
29375 +/* This hack is to avoid a problem with some strict ANSI C preprocessors.
29376 +   The problem is, "32_" is not a valid preprocessing token, and we don't
29377 +   want extra underscores (e.g., "nlm_32_").  The XCONCAT2 macro will
29378 +   cause the inner CONCAT2 macros to be evaluated first, producing
29379 +   still-valid pp-tokens.  Then the final concatenation can be done.  */
29380 +#undef CONCAT4
29381 +#define CONCAT4(a,b,c,d) XCONCAT2(CONCAT2(a,b),CONCAT2(c,d))
29382 +#endif
29383 +#endif
29384 +
29385 +/* The word size used by BFD on the host.  This may be 64 with a 32
29386 +   bit target if the host is 64 bit, or if other 64 bit targets have
29387 +   been selected with --enable-targets, or if --enable-64-bit-bfd.  */
29388 +#define BFD_ARCH_SIZE 64
29389 +
29390 +/* The word size of the default bfd target.  */
29391 +#define BFD_DEFAULT_TARGET_SIZE 64
29392 +
29393 +#define BFD_HOST_64BIT_LONG 1
29394 +#define BFD_HOST_LONG_LONG 1
29395 +#if 1
29396 +#define BFD_HOST_64_BIT long
29397 +#define BFD_HOST_U_64_BIT unsigned long
29398 +typedef BFD_HOST_64_BIT bfd_int64_t;
29399 +typedef BFD_HOST_U_64_BIT bfd_uint64_t;
29400 +#endif
29401 +
29402 +#if BFD_ARCH_SIZE >= 64
29403 +#define BFD64
29404 +#endif
29405 +
29406 +#ifndef INLINE
29407 +#if __GNUC__ >= 2
29408 +#define INLINE __inline__
29409 +#else
29410 +#define INLINE
29411 +#endif
29412 +#endif
29413 +
29414 +/* Forward declaration.  */
29415 +typedef struct bfd bfd;
29416 +
29417 +/* Boolean type used in bfd.  Too many systems define their own
29418 +   versions of "boolean" for us to safely typedef a "boolean" of
29419 +   our own.  Using an enum for "bfd_boolean" has its own set of
29420 +   problems, with strange looking casts required to avoid warnings
29421 +   on some older compilers.  Thus we just use an int.
29422 +
29423 +   General rule: Functions which are bfd_boolean return TRUE on
29424 +   success and FALSE on failure (unless they're a predicate).  */
29425 +
29426 +typedef int bfd_boolean;
29427 +#undef FALSE
29428 +#undef TRUE
29429 +#define FALSE 0
29430 +#define TRUE 1
29431 +
29432 +#ifdef BFD64
29433 +
29434 +#ifndef BFD_HOST_64_BIT
29435 + #error No 64 bit integer type available
29436 +#endif /* ! defined (BFD_HOST_64_BIT) */
29437 +
29438 +typedef BFD_HOST_U_64_BIT bfd_vma;
29439 +typedef BFD_HOST_64_BIT bfd_signed_vma;
29440 +typedef BFD_HOST_U_64_BIT bfd_size_type;
29441 +typedef BFD_HOST_U_64_BIT symvalue;
29442 +
29443 +#ifndef fprintf_vma
29444 +#if BFD_HOST_64BIT_LONG
29445 +#define sprintf_vma(s,x) sprintf (s, "%016lx", x)
29446 +#define fprintf_vma(f,x) fprintf (f, "%016lx", x)
29447 +#else
29448 +#define _bfd_int64_low(x) ((unsigned long) (((x) & 0xffffffff)))
29449 +#define _bfd_int64_high(x) ((unsigned long) (((x) >> 32) & 0xffffffff))
29450 +#define fprintf_vma(s,x) \
29451 +  fprintf ((s), "%08lx%08lx", _bfd_int64_high (x), _bfd_int64_low (x))
29452 +#define sprintf_vma(s,x) \
29453 +  sprintf ((s), "%08lx%08lx", _bfd_int64_high (x), _bfd_int64_low (x))
29454 +#endif
29455 +#endif
29456 +
29457 +#else /* not BFD64  */
29458 +
29459 +/* Represent a target address.  Also used as a generic unsigned type
29460 +   which is guaranteed to be big enough to hold any arithmetic types
29461 +   we need to deal with.  */
29462 +typedef unsigned long bfd_vma;
29463 +
29464 +/* A generic signed type which is guaranteed to be big enough to hold any
29465 +   arithmetic types we need to deal with.  Can be assumed to be compatible
29466 +   with bfd_vma in the same way that signed and unsigned ints are compatible
29467 +   (as parameters, in assignment, etc).  */
29468 +typedef long bfd_signed_vma;
29469 +
29470 +typedef unsigned long symvalue;
29471 +typedef unsigned long bfd_size_type;
29472 +
29473 +/* Print a bfd_vma x on stream s.  */
29474 +#define fprintf_vma(s,x) fprintf (s, "%08lx", x)
29475 +#define sprintf_vma(s,x) sprintf (s, "%08lx", x)
29476 +
29477 +#endif /* not BFD64  */
29478 +
29479 +#define HALF_BFD_SIZE_TYPE \
29480 +  (((bfd_size_type) 1) << (8 * sizeof (bfd_size_type) / 2))
29481 +
29482 +#ifndef BFD_HOST_64_BIT
29483 +/* Fall back on a 32 bit type.  The idea is to make these types always
29484 +   available for function return types, but in the case that
29485 +   BFD_HOST_64_BIT is undefined such a function should abort or
29486 +   otherwise signal an error.  */
29487 +typedef bfd_signed_vma bfd_int64_t;
29488 +typedef bfd_vma bfd_uint64_t;
29489 +#endif
29490 +
29491 +/* An offset into a file.  BFD always uses the largest possible offset
29492 +   based on the build time availability of fseek, fseeko, or fseeko64.  */
29493 +typedef BFD_HOST_64_BIT file_ptr;
29494 +typedef unsigned BFD_HOST_64_BIT ufile_ptr;
29495 +
29496 +extern void bfd_sprintf_vma (bfd *, char *, bfd_vma);
29497 +extern void bfd_fprintf_vma (bfd *, void *, bfd_vma);
29498 +
29499 +#define printf_vma(x) fprintf_vma(stdout,x)
29500 +#define bfd_printf_vma(abfd,x) bfd_fprintf_vma (abfd,stdout,x)
29501 +
29502 +typedef unsigned int flagword; /* 32 bits of flags */
29503 +typedef unsigned char bfd_byte;
29504 +\f
29505 +/* File formats.  */
29506 +
29507 +typedef enum bfd_format
29508 +{
29509 +  bfd_unknown = 0,     /* File format is unknown.  */
29510 +  bfd_object,          /* Linker/assembler/compiler output.  */
29511 +  bfd_archive,         /* Object archive file.  */
29512 +  bfd_core,            /* Core dump.  */
29513 +  bfd_type_end         /* Marks the end; don't use it!  */
29514 +}
29515 +bfd_format;
29516 +
29517 +/* Values that may appear in the flags field of a BFD.  These also
29518 +   appear in the object_flags field of the bfd_target structure, where
29519 +   they indicate the set of flags used by that backend (not all flags
29520 +   are meaningful for all object file formats) (FIXME: at the moment,
29521 +   the object_flags values have mostly just been copied from backend
29522 +   to another, and are not necessarily correct).  */
29523 +
29524 +/* No flags.  */
29525 +#define BFD_NO_FLAGS           0x00
29526 +
29527 +/* BFD contains relocation entries.  */
29528 +#define HAS_RELOC      0x01
29529 +
29530 +/* BFD is directly executable.  */
29531 +#define EXEC_P         0x02
29532 +
29533 +/* BFD has line number information (basically used for F_LNNO in a
29534 +   COFF header).  */
29535 +#define HAS_LINENO     0x04
29536 +
29537 +/* BFD has debugging information.  */
29538 +#define HAS_DEBUG      0x08
29539 +
29540 +/* BFD has symbols.  */
29541 +#define HAS_SYMS       0x10
29542 +
29543 +/* BFD has local symbols (basically used for F_LSYMS in a COFF
29544 +   header).  */
29545 +#define HAS_LOCALS     0x20
29546 +
29547 +/* BFD is a dynamic object.  */
29548 +#define DYNAMIC        0x40
29549 +
29550 +/* Text section is write protected (if D_PAGED is not set, this is
29551 +   like an a.out NMAGIC file) (the linker sets this by default, but
29552 +   clears it for -r or -N).  */
29553 +#define WP_TEXT        0x80
29554 +
29555 +/* BFD is dynamically paged (this is like an a.out ZMAGIC file) (the
29556 +   linker sets this by default, but clears it for -r or -n or -N).  */
29557 +#define D_PAGED        0x100
29558 +
29559 +/* BFD is relaxable (this means that bfd_relax_section may be able to
29560 +   do something) (sometimes bfd_relax_section can do something even if
29561 +   this is not set).  */
29562 +#define BFD_IS_RELAXABLE 0x200
29563 +
29564 +/* This may be set before writing out a BFD to request using a
29565 +   traditional format.  For example, this is used to request that when
29566 +   writing out an a.out object the symbols not be hashed to eliminate
29567 +   duplicates.  */
29568 +#define BFD_TRADITIONAL_FORMAT 0x400
29569 +
29570 +/* This flag indicates that the BFD contents are actually cached in
29571 +   memory.  If this is set, iostream points to a bfd_in_memory struct.  */
29572 +#define BFD_IN_MEMORY 0x800
29573 +
29574 +/* The sections in this BFD specify a memory page.  */
29575 +#define HAS_LOAD_PAGE 0x1000
29576 +
29577 +/* This BFD has been created by the linker and doesn't correspond
29578 +   to any input file.  */
29579 +#define BFD_LINKER_CREATED 0x2000
29580 +\f
29581 +/* Symbols and relocation.  */
29582 +
29583 +/* A count of carsyms (canonical archive symbols).  */
29584 +typedef unsigned long symindex;
29585 +
29586 +/* How to perform a relocation.  */
29587 +typedef const struct reloc_howto_struct reloc_howto_type;
29588 +
29589 +#define BFD_NO_MORE_SYMBOLS ((symindex) ~0)
29590 +
29591 +/* General purpose part of a symbol X;
29592 +   target specific parts are in libcoff.h, libaout.h, etc.  */
29593 +
29594 +#define bfd_get_section(x) ((x)->section)
29595 +#define bfd_get_output_section(x) ((x)->section->output_section)
29596 +#define bfd_set_section(x,y) ((x)->section) = (y)
29597 +#define bfd_asymbol_base(x) ((x)->section->vma)
29598 +#define bfd_asymbol_value(x) (bfd_asymbol_base(x) + (x)->value)
29599 +#define bfd_asymbol_name(x) ((x)->name)
29600 +/*Perhaps future: #define bfd_asymbol_bfd(x) ((x)->section->owner)*/
29601 +#define bfd_asymbol_bfd(x) ((x)->the_bfd)
29602 +#define bfd_asymbol_flavour(x) (bfd_asymbol_bfd(x)->xvec->flavour)
29603 +
29604 +/* A canonical archive symbol.  */
29605 +/* This is a type pun with struct ranlib on purpose!  */
29606 +typedef struct carsym
29607 +{
29608 +  char *name;
29609 +  file_ptr file_offset;        /* Look here to find the file.  */
29610 +}
29611 +carsym;                        /* To make these you call a carsymogen.  */
29612 +
29613 +/* Used in generating armaps (archive tables of contents).
29614 +   Perhaps just a forward definition would do?  */
29615 +struct orl                     /* Output ranlib.  */
29616 +{
29617 +  char **name;         /* Symbol name.  */
29618 +  union
29619 +  {
29620 +    file_ptr pos;
29621 +    bfd *abfd;
29622 +  } u;                 /* bfd* or file position.  */
29623 +  int namidx;          /* Index into string table.  */
29624 +};
29625 +\f
29626 +/* Linenumber stuff.  */
29627 +typedef struct lineno_cache_entry
29628 +{
29629 +  unsigned int line_number;    /* Linenumber from start of function.  */
29630 +  union
29631 +  {
29632 +    struct bfd_symbol *sym;    /* Function name.  */
29633 +    bfd_vma offset;                    /* Offset into section.  */
29634 +  } u;
29635 +}
29636 +alent;
29637 +\f
29638 +/* Object and core file sections.  */
29639 +
29640 +#define        align_power(addr, align)        \
29641 +  (((addr) + ((bfd_vma) 1 << (align)) - 1) & ((bfd_vma) -1 << (align)))
29642 +
29643 +typedef struct bfd_section *sec_ptr;
29644 +
29645 +#define bfd_get_section_name(bfd, ptr) ((ptr)->name + 0)
29646 +#define bfd_get_section_vma(bfd, ptr) ((ptr)->vma + 0)
29647 +#define bfd_get_section_lma(bfd, ptr) ((ptr)->lma + 0)
29648 +#define bfd_get_section_alignment(bfd, ptr) ((ptr)->alignment_power + 0)
29649 +#define bfd_section_name(bfd, ptr) ((ptr)->name)
29650 +#define bfd_section_size(bfd, ptr) ((ptr)->size)
29651 +#define bfd_get_section_size(ptr) ((ptr)->size)
29652 +#define bfd_section_vma(bfd, ptr) ((ptr)->vma)
29653 +#define bfd_section_lma(bfd, ptr) ((ptr)->lma)
29654 +#define bfd_section_alignment(bfd, ptr) ((ptr)->alignment_power)
29655 +#define bfd_get_section_flags(bfd, ptr) ((ptr)->flags + 0)
29656 +#define bfd_get_section_userdata(bfd, ptr) ((ptr)->userdata)
29657 +
29658 +#define bfd_is_com_section(ptr) (((ptr)->flags & SEC_IS_COMMON) != 0)
29659 +
29660 +#define bfd_set_section_vma(bfd, ptr, val) (((ptr)->vma = (ptr)->lma = (val)), ((ptr)->user_set_vma = TRUE), TRUE)
29661 +#define bfd_set_section_alignment(bfd, ptr, val) (((ptr)->alignment_power = (val)),TRUE)
29662 +#define bfd_set_section_userdata(bfd, ptr, val) (((ptr)->userdata = (val)),TRUE)
29663 +/* Find the address one past the end of SEC.  */
29664 +#define bfd_get_section_limit(bfd, sec) \
29665 +  (((sec)->rawsize ? (sec)->rawsize : (sec)->size) \
29666 +   / bfd_octets_per_byte (bfd))
29667 +
29668 +typedef struct stat stat_type;
29669 +\f
29670 +typedef enum bfd_print_symbol
29671 +{
29672 +  bfd_print_symbol_name,
29673 +  bfd_print_symbol_more,
29674 +  bfd_print_symbol_all
29675 +} bfd_print_symbol_type;
29676 +
29677 +/* Information about a symbol that nm needs.  */
29678 +
29679 +typedef struct _symbol_info
29680 +{
29681 +  symvalue value;
29682 +  char type;
29683 +  const char *name;            /* Symbol name.  */
29684 +  unsigned char stab_type;     /* Stab type.  */
29685 +  char stab_other;             /* Stab other.  */
29686 +  short stab_desc;             /* Stab desc.  */
29687 +  const char *stab_name;       /* String for stab type.  */
29688 +} symbol_info;
29689 +
29690 +/* Get the name of a stabs type code.  */
29691 +
29692 +extern const char *bfd_get_stab_name (int);
29693 +\f
29694 +/* Hash table routines.  There is no way to free up a hash table.  */
29695 +
29696 +/* An element in the hash table.  Most uses will actually use a larger
29697 +   structure, and an instance of this will be the first field.  */
29698 +
29699 +struct bfd_hash_entry
29700 +{
29701 +  /* Next entry for this hash code.  */
29702 +  struct bfd_hash_entry *next;
29703 +  /* String being hashed.  */
29704 +  const char *string;
29705 +  /* Hash code.  This is the full hash code, not the index into the
29706 +     table.  */
29707 +  unsigned long hash;
29708 +};
29709 +
29710 +/* A hash table.  */
29711 +
29712 +struct bfd_hash_table
29713 +{
29714 +  /* The hash array.  */
29715 +  struct bfd_hash_entry **table;
29716 +  /* The number of slots in the hash table.  */
29717 +  unsigned int size;
29718 +  /* A function used to create new elements in the hash table.  The
29719 +     first entry is itself a pointer to an element.  When this
29720 +     function is first invoked, this pointer will be NULL.  However,
29721 +     having the pointer permits a hierarchy of method functions to be
29722 +     built each of which calls the function in the superclass.  Thus
29723 +     each function should be written to allocate a new block of memory
29724 +     only if the argument is NULL.  */
29725 +  struct bfd_hash_entry *(*newfunc)
29726 +    (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
29727 +   /* An objalloc for this hash table.  This is a struct objalloc *,
29728 +     but we use void * to avoid requiring the inclusion of objalloc.h.  */
29729 +  void *memory;
29730 +};
29731 +
29732 +/* Initialize a hash table.  */
29733 +extern bfd_boolean bfd_hash_table_init
29734 +  (struct bfd_hash_table *,
29735 +   struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
29736 +                              struct bfd_hash_table *,
29737 +                              const char *));
29738 +
29739 +/* Initialize a hash table specifying a size.  */
29740 +extern bfd_boolean bfd_hash_table_init_n
29741 +  (struct bfd_hash_table *,
29742 +   struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
29743 +                              struct bfd_hash_table *,
29744 +                              const char *),
29745 +   unsigned int size);
29746 +
29747 +/* Free up a hash table.  */
29748 +extern void bfd_hash_table_free
29749 +  (struct bfd_hash_table *);
29750 +
29751 +/* Look up a string in a hash table.  If CREATE is TRUE, a new entry
29752 +   will be created for this string if one does not already exist.  The
29753 +   COPY argument must be TRUE if this routine should copy the string
29754 +   into newly allocated memory when adding an entry.  */
29755 +extern struct bfd_hash_entry *bfd_hash_lookup
29756 +  (struct bfd_hash_table *, const char *, bfd_boolean create,
29757 +   bfd_boolean copy);
29758 +
29759 +/* Replace an entry in a hash table.  */
29760 +extern void bfd_hash_replace
29761 +  (struct bfd_hash_table *, struct bfd_hash_entry *old,
29762 +   struct bfd_hash_entry *nw);
29763 +
29764 +/* Base method for creating a hash table entry.  */
29765 +extern struct bfd_hash_entry *bfd_hash_newfunc
29766 +  (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
29767 +
29768 +/* Grab some space for a hash table entry.  */
29769 +extern void *bfd_hash_allocate
29770 +  (struct bfd_hash_table *, unsigned int);
29771 +
29772 +/* Traverse a hash table in a random order, calling a function on each
29773 +   element.  If the function returns FALSE, the traversal stops.  The
29774 +   INFO argument is passed to the function.  */
29775 +extern void bfd_hash_traverse
29776 +  (struct bfd_hash_table *,
29777 +   bfd_boolean (*) (struct bfd_hash_entry *, void *),
29778 +   void *info);
29779 +
29780 +/* Allows the default size of a hash table to be configured. New hash
29781 +   tables allocated using bfd_hash_table_init will be created with
29782 +   this size.  */
29783 +extern void bfd_hash_set_default_size (bfd_size_type);
29784 +
29785 +/* This structure is used to keep track of stabs in sections
29786 +   information while linking.  */
29787 +
29788 +struct stab_info
29789 +{
29790 +  /* A hash table used to hold stabs strings.  */
29791 +  struct bfd_strtab_hash *strings;
29792 +  /* The header file hash table.  */
29793 +  struct bfd_hash_table includes;
29794 +  /* The first .stabstr section.  */
29795 +  struct bfd_section *stabstr;
29796 +};
29797 +
29798 +#define COFF_SWAP_TABLE (void *) &bfd_coff_std_swap_table
29799 +
29800 +/* User program access to BFD facilities.  */
29801 +
29802 +/* Direct I/O routines, for programs which know more about the object
29803 +   file than BFD does.  Use higher level routines if possible.  */
29804 +
29805 +extern bfd_size_type bfd_bread (void *, bfd_size_type, bfd *);
29806 +extern bfd_size_type bfd_bwrite (const void *, bfd_size_type, bfd *);
29807 +extern int bfd_seek (bfd *, file_ptr, int);
29808 +extern file_ptr bfd_tell (bfd *);
29809 +extern int bfd_flush (bfd *);
29810 +extern int bfd_stat (bfd *, struct stat *);
29811 +
29812 +/* Deprecated old routines.  */
29813 +#if __GNUC__
29814 +#define bfd_read(BUF, ELTSIZE, NITEMS, ABFD)                           \
29815 +  (warn_deprecated ("bfd_read", __FILE__, __LINE__, __FUNCTION__),     \
29816 +   bfd_bread ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
29817 +#define bfd_write(BUF, ELTSIZE, NITEMS, ABFD)                          \
29818 +  (warn_deprecated ("bfd_write", __FILE__, __LINE__, __FUNCTION__),    \
29819 +   bfd_bwrite ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
29820 +#else
29821 +#define bfd_read(BUF, ELTSIZE, NITEMS, ABFD)                           \
29822 +  (warn_deprecated ("bfd_read", (const char *) 0, 0, (const char *) 0), \
29823 +   bfd_bread ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
29824 +#define bfd_write(BUF, ELTSIZE, NITEMS, ABFD)                          \
29825 +  (warn_deprecated ("bfd_write", (const char *) 0, 0, (const char *) 0),\
29826 +   bfd_bwrite ((BUF), (ELTSIZE) * (NITEMS), (ABFD)))
29827 +#endif
29828 +extern void warn_deprecated (const char *, const char *, int, const char *);
29829 +
29830 +/* Cast from const char * to char * so that caller can assign to
29831 +   a char * without a warning.  */
29832 +#define bfd_get_filename(abfd) ((char *) (abfd)->filename)
29833 +#define bfd_get_cacheable(abfd) ((abfd)->cacheable)
29834 +#define bfd_get_format(abfd) ((abfd)->format)
29835 +#define bfd_get_target(abfd) ((abfd)->xvec->name)
29836 +#define bfd_get_flavour(abfd) ((abfd)->xvec->flavour)
29837 +#define bfd_family_coff(abfd) \
29838 +  (bfd_get_flavour (abfd) == bfd_target_coff_flavour || \
29839 +   bfd_get_flavour (abfd) == bfd_target_xcoff_flavour)
29840 +#define bfd_big_endian(abfd) ((abfd)->xvec->byteorder == BFD_ENDIAN_BIG)
29841 +#define bfd_little_endian(abfd) ((abfd)->xvec->byteorder == BFD_ENDIAN_LITTLE)
29842 +#define bfd_header_big_endian(abfd) \
29843 +  ((abfd)->xvec->header_byteorder == BFD_ENDIAN_BIG)
29844 +#define bfd_header_little_endian(abfd) \
29845 +  ((abfd)->xvec->header_byteorder == BFD_ENDIAN_LITTLE)
29846 +#define bfd_get_file_flags(abfd) ((abfd)->flags)
29847 +#define bfd_applicable_file_flags(abfd) ((abfd)->xvec->object_flags)
29848 +#define bfd_applicable_section_flags(abfd) ((abfd)->xvec->section_flags)
29849 +#define bfd_my_archive(abfd) ((abfd)->my_archive)
29850 +#define bfd_has_map(abfd) ((abfd)->has_armap)
29851 +
29852 +#define bfd_valid_reloc_types(abfd) ((abfd)->xvec->valid_reloc_types)
29853 +#define bfd_usrdata(abfd) ((abfd)->usrdata)
29854 +
29855 +#define bfd_get_start_address(abfd) ((abfd)->start_address)
29856 +#define bfd_get_symcount(abfd) ((abfd)->symcount)
29857 +#define bfd_get_outsymbols(abfd) ((abfd)->outsymbols)
29858 +#define bfd_count_sections(abfd) ((abfd)->section_count)
29859 +
29860 +#define bfd_get_dynamic_symcount(abfd) ((abfd)->dynsymcount)
29861 +
29862 +#define bfd_get_symbol_leading_char(abfd) ((abfd)->xvec->symbol_leading_char)
29863 +
29864 +#define bfd_set_cacheable(abfd,bool) (((abfd)->cacheable = bool), TRUE)
29865 +
29866 +extern bfd_boolean bfd_cache_close
29867 +  (bfd *abfd);
29868 +/* NB: This declaration should match the autogenerated one in libbfd.h.  */
29869 +
29870 +extern bfd_boolean bfd_cache_close_all (void);
29871 +
29872 +extern bfd_boolean bfd_record_phdr
29873 +  (bfd *, unsigned long, bfd_boolean, flagword, bfd_boolean, bfd_vma,
29874 +   bfd_boolean, bfd_boolean, unsigned int, struct bfd_section **);
29875 +
29876 +/* Byte swapping routines.  */
29877 +
29878 +bfd_uint64_t bfd_getb64 (const void *);
29879 +bfd_uint64_t bfd_getl64 (const void *);
29880 +bfd_int64_t bfd_getb_signed_64 (const void *);
29881 +bfd_int64_t bfd_getl_signed_64 (const void *);
29882 +bfd_vma bfd_getb32 (const void *);
29883 +bfd_vma bfd_getl32 (const void *);
29884 +bfd_signed_vma bfd_getb_signed_32 (const void *);
29885 +bfd_signed_vma bfd_getl_signed_32 (const void *);
29886 +bfd_vma bfd_getb16 (const void *);
29887 +bfd_vma bfd_getl16 (const void *);
29888 +bfd_signed_vma bfd_getb_signed_16 (const void *);
29889 +bfd_signed_vma bfd_getl_signed_16 (const void *);
29890 +void bfd_putb64 (bfd_uint64_t, void *);
29891 +void bfd_putl64 (bfd_uint64_t, void *);
29892 +void bfd_putb32 (bfd_vma, void *);
29893 +void bfd_putl32 (bfd_vma, void *);
29894 +void bfd_putb16 (bfd_vma, void *);
29895 +void bfd_putl16 (bfd_vma, void *);
29896 +
29897 +/* Byte swapping routines which take size and endiannes as arguments.  */
29898 +
29899 +bfd_uint64_t bfd_get_bits (const void *, int, bfd_boolean);
29900 +void bfd_put_bits (bfd_uint64_t, void *, int, bfd_boolean);
29901 +
29902 +extern bfd_boolean bfd_section_already_linked_table_init (void);
29903 +extern void bfd_section_already_linked_table_free (void);
29904 +\f
29905 +/* Externally visible ECOFF routines.  */
29906 +
29907 +#if defined(__STDC__) || defined(ALMOST_STDC)
29908 +struct ecoff_debug_info;
29909 +struct ecoff_debug_swap;
29910 +struct ecoff_extr;
29911 +struct bfd_symbol;
29912 +struct bfd_link_info;
29913 +struct bfd_link_hash_entry;
29914 +struct bfd_elf_version_tree;
29915 +#endif
29916 +extern bfd_vma bfd_ecoff_get_gp_value
29917 +  (bfd * abfd);
29918 +extern bfd_boolean bfd_ecoff_set_gp_value
29919 +  (bfd *abfd, bfd_vma gp_value);
29920 +extern bfd_boolean bfd_ecoff_set_regmasks
29921 +  (bfd *abfd, unsigned long gprmask, unsigned long fprmask,
29922 +   unsigned long *cprmask);
29923 +extern void *bfd_ecoff_debug_init
29924 +  (bfd *output_bfd, struct ecoff_debug_info *output_debug,
29925 +   const struct ecoff_debug_swap *output_swap, struct bfd_link_info *);
29926 +extern void bfd_ecoff_debug_free
29927 +  (void *handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
29928 +   const struct ecoff_debug_swap *output_swap, struct bfd_link_info *);
29929 +extern bfd_boolean bfd_ecoff_debug_accumulate
29930 +  (void *handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
29931 +   const struct ecoff_debug_swap *output_swap, bfd *input_bfd,
29932 +   struct ecoff_debug_info *input_debug,
29933 +   const struct ecoff_debug_swap *input_swap, struct bfd_link_info *);
29934 +extern bfd_boolean bfd_ecoff_debug_accumulate_other
29935 +  (void *handle, bfd *output_bfd, struct ecoff_debug_info *output_debug,
29936 +   const struct ecoff_debug_swap *output_swap, bfd *input_bfd,
29937 +   struct bfd_link_info *);
29938 +extern bfd_boolean bfd_ecoff_debug_externals
29939 +  (bfd *abfd, struct ecoff_debug_info *debug,
29940 +   const struct ecoff_debug_swap *swap, bfd_boolean relocatable,
29941 +   bfd_boolean (*get_extr) (struct bfd_symbol *, struct ecoff_extr *),
29942 +   void (*set_index) (struct bfd_symbol *, bfd_size_type));
29943 +extern bfd_boolean bfd_ecoff_debug_one_external
29944 +  (bfd *abfd, struct ecoff_debug_info *debug,
29945 +   const struct ecoff_debug_swap *swap, const char *name,
29946 +   struct ecoff_extr *esym);
29947 +extern bfd_size_type bfd_ecoff_debug_size
29948 +  (bfd *abfd, struct ecoff_debug_info *debug,
29949 +   const struct ecoff_debug_swap *swap);
29950 +extern bfd_boolean bfd_ecoff_write_debug
29951 +  (bfd *abfd, struct ecoff_debug_info *debug,
29952 +   const struct ecoff_debug_swap *swap, file_ptr where);
29953 +extern bfd_boolean bfd_ecoff_write_accumulated_debug
29954 +  (void *handle, bfd *abfd, struct ecoff_debug_info *debug,
29955 +   const struct ecoff_debug_swap *swap,
29956 +   struct bfd_link_info *info, file_ptr where);
29957 +
29958 +/* Externally visible ELF routines.  */
29959 +
29960 +struct bfd_link_needed_list
29961 +{
29962 +  struct bfd_link_needed_list *next;
29963 +  bfd *by;
29964 +  const char *name;
29965 +};
29966 +
29967 +enum dynamic_lib_link_class {
29968 +  DYN_NORMAL = 0,
29969 +  DYN_AS_NEEDED = 1,
29970 +  DYN_DT_NEEDED = 2,
29971 +  DYN_NO_ADD_NEEDED = 4,
29972 +  DYN_NO_NEEDED = 8
29973 +};
29974 +
29975 +extern bfd_boolean bfd_elf_record_link_assignment
29976 +  (struct bfd_link_info *, const char *, bfd_boolean);
29977 +extern struct bfd_link_needed_list *bfd_elf_get_needed_list
29978 +  (bfd *, struct bfd_link_info *);
29979 +extern bfd_boolean bfd_elf_get_bfd_needed_list
29980 +  (bfd *, struct bfd_link_needed_list **);
29981 +extern bfd_boolean bfd_elf_size_dynamic_sections
29982 +  (bfd *, const char *, const char *, const char *, const char * const *,
29983 +   struct bfd_link_info *, struct bfd_section **,
29984 +   struct bfd_elf_version_tree *);
29985 +extern bfd_boolean bfd_elf_size_dynsym_hash_dynstr
29986 +  (bfd *, struct bfd_link_info *);
29987 +extern void bfd_elf_set_dt_needed_name
29988 +  (bfd *, const char *);
29989 +extern const char *bfd_elf_get_dt_soname
29990 +  (bfd *);
29991 +extern void bfd_elf_set_dyn_lib_class
29992 +  (bfd *, int);
29993 +extern int bfd_elf_get_dyn_lib_class
29994 +  (bfd *);
29995 +extern struct bfd_link_needed_list *bfd_elf_get_runpath_list
29996 +  (bfd *, struct bfd_link_info *);
29997 +extern bfd_boolean bfd_elf_discard_info
29998 +  (bfd *, struct bfd_link_info *);
29999 +extern unsigned int _bfd_elf_default_action_discarded
30000 +  (struct bfd_section *);
30001 +
30002 +/* Return an upper bound on the number of bytes required to store a
30003 +   copy of ABFD's program header table entries.  Return -1 if an error
30004 +   occurs; bfd_get_error will return an appropriate code.  */
30005 +extern long bfd_get_elf_phdr_upper_bound
30006 +  (bfd *abfd);
30007 +
30008 +/* Copy ABFD's program header table entries to *PHDRS.  The entries
30009 +   will be stored as an array of Elf_Internal_Phdr structures, as
30010 +   defined in include/elf/internal.h.  To find out how large the
30011 +   buffer needs to be, call bfd_get_elf_phdr_upper_bound.
30012 +
30013 +   Return the number of program header table entries read, or -1 if an
30014 +   error occurs; bfd_get_error will return an appropriate code.  */
30015 +extern int bfd_get_elf_phdrs
30016 +  (bfd *abfd, void *phdrs);
30017 +
30018 +/* Create a new BFD as if by bfd_openr.  Rather than opening a file,
30019 +   reconstruct an ELF file by reading the segments out of remote memory
30020 +   based on the ELF file header at EHDR_VMA and the ELF program headers it
30021 +   points to.  If not null, *LOADBASEP is filled in with the difference
30022 +   between the VMAs from which the segments were read, and the VMAs the
30023 +   file headers (and hence BFD's idea of each section's VMA) put them at.
30024 +
30025 +   The function TARGET_READ_MEMORY is called to copy LEN bytes from the
30026 +   remote memory at target address VMA into the local buffer at MYADDR; it
30027 +   should return zero on success or an `errno' code on failure.  TEMPL must
30028 +   be a BFD for an ELF target with the word size and byte order found in
30029 +   the remote memory.  */
30030 +extern bfd *bfd_elf_bfd_from_remote_memory
30031 +  (bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep,
30032 +   int (*target_read_memory) (bfd_vma vma, bfd_byte *myaddr, int len));
30033 +
30034 +/* Return the arch_size field of an elf bfd, or -1 if not elf.  */
30035 +extern int bfd_get_arch_size
30036 +  (bfd *);
30037 +
30038 +/* Return TRUE if address "naturally" sign extends, or -1 if not elf.  */
30039 +extern int bfd_get_sign_extend_vma
30040 +  (bfd *);
30041 +
30042 +extern struct bfd_section *_bfd_elf_tls_setup
30043 +  (bfd *, struct bfd_link_info *);
30044 +
30045 +extern void _bfd_elf_provide_symbol
30046 +  (struct bfd_link_info *, const char *, bfd_vma, struct bfd_section *);
30047 +
30048 +extern void _bfd_elf_provide_section_bound_symbols
30049 +  (struct bfd_link_info *, struct bfd_section *, const char *, const char *);
30050 +
30051 +extern void _bfd_elf_fix_excluded_sec_syms
30052 +  (bfd *, struct bfd_link_info *);
30053 +
30054 +extern bfd_boolean bfd_m68k_elf32_create_embedded_relocs
30055 +  (bfd *, struct bfd_link_info *, struct bfd_section *, struct bfd_section *,
30056 +   char **);
30057 +
30058 +/* SunOS shared library support routines for the linker.  */
30059 +
30060 +extern struct bfd_link_needed_list *bfd_sunos_get_needed_list
30061 +  (bfd *, struct bfd_link_info *);
30062 +extern bfd_boolean bfd_sunos_record_link_assignment
30063 +  (bfd *, struct bfd_link_info *, const char *);
30064 +extern bfd_boolean bfd_sunos_size_dynamic_sections
30065 +  (bfd *, struct bfd_link_info *, struct bfd_section **,
30066 +   struct bfd_section **, struct bfd_section **);
30067 +
30068 +/* Linux shared library support routines for the linker.  */
30069 +
30070 +extern bfd_boolean bfd_i386linux_size_dynamic_sections
30071 +  (bfd *, struct bfd_link_info *);
30072 +extern bfd_boolean bfd_m68klinux_size_dynamic_sections
30073 +  (bfd *, struct bfd_link_info *);
30074 +extern bfd_boolean bfd_sparclinux_size_dynamic_sections
30075 +  (bfd *, struct bfd_link_info *);
30076 +
30077 +/* mmap hacks */
30078 +
30079 +struct _bfd_window_internal;
30080 +typedef struct _bfd_window_internal bfd_window_internal;
30081 +
30082 +typedef struct _bfd_window
30083 +{
30084 +  /* What the user asked for.  */
30085 +  void *data;
30086 +  bfd_size_type size;
30087 +  /* The actual window used by BFD.  Small user-requested read-only
30088 +     regions sharing a page may share a single window into the object
30089 +     file.  Read-write versions shouldn't until I've fixed things to
30090 +     keep track of which portions have been claimed by the
30091 +     application; don't want to give the same region back when the
30092 +     application wants two writable copies!  */
30093 +  struct _bfd_window_internal *i;
30094 +}
30095 +bfd_window;
30096 +
30097 +extern void bfd_init_window
30098 +  (bfd_window *);
30099 +extern void bfd_free_window
30100 +  (bfd_window *);
30101 +extern bfd_boolean bfd_get_file_window
30102 +  (bfd *, file_ptr, bfd_size_type, bfd_window *, bfd_boolean);
30103 +
30104 +/* XCOFF support routines for the linker.  */
30105 +
30106 +extern bfd_boolean bfd_xcoff_link_record_set
30107 +  (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *, bfd_size_type);
30108 +extern bfd_boolean bfd_xcoff_import_symbol
30109 +  (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *, bfd_vma,
30110 +   const char *, const char *, const char *, unsigned int);
30111 +extern bfd_boolean bfd_xcoff_export_symbol
30112 +  (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *);
30113 +extern bfd_boolean bfd_xcoff_link_count_reloc
30114 +  (bfd *, struct bfd_link_info *, const char *);
30115 +extern bfd_boolean bfd_xcoff_record_link_assignment
30116 +  (bfd *, struct bfd_link_info *, const char *);
30117 +extern bfd_boolean bfd_xcoff_size_dynamic_sections
30118 +  (bfd *, struct bfd_link_info *, const char *, const char *,
30119 +   unsigned long, unsigned long, unsigned long, bfd_boolean,
30120 +   int, bfd_boolean, bfd_boolean, struct bfd_section **, bfd_boolean);
30121 +extern bfd_boolean bfd_xcoff_link_generate_rtinit
30122 +  (bfd *, const char *, const char *, bfd_boolean);
30123 +
30124 +/* XCOFF support routines for ar.  */
30125 +extern bfd_boolean bfd_xcoff_ar_archive_set_magic
30126 +  (bfd *, char *);
30127 +
30128 +/* Externally visible COFF routines.  */
30129 +
30130 +#if defined(__STDC__) || defined(ALMOST_STDC)
30131 +struct internal_syment;
30132 +union internal_auxent;
30133 +#endif
30134 +
30135 +extern bfd_boolean bfd_coff_get_syment
30136 +  (bfd *, struct bfd_symbol *, struct internal_syment *);
30137 +
30138 +extern bfd_boolean bfd_coff_get_auxent
30139 +  (bfd *, struct bfd_symbol *, int, union internal_auxent *);
30140 +
30141 +extern bfd_boolean bfd_coff_set_symbol_class
30142 +  (bfd *, struct bfd_symbol *, unsigned int);
30143 +
30144 +extern bfd_boolean bfd_m68k_coff_create_embedded_relocs
30145 +  (bfd *, struct bfd_link_info *, struct bfd_section *, struct bfd_section *, char **);
30146 +
30147 +/* ARM Interworking support.  Called from linker.  */
30148 +extern bfd_boolean bfd_arm_allocate_interworking_sections
30149 +  (struct bfd_link_info *);
30150 +
30151 +extern bfd_boolean bfd_arm_process_before_allocation
30152 +  (bfd *, struct bfd_link_info *, int);
30153 +
30154 +extern bfd_boolean bfd_arm_get_bfd_for_interworking
30155 +  (bfd *, struct bfd_link_info *);
30156 +
30157 +/* PE ARM Interworking support.  Called from linker.  */
30158 +extern bfd_boolean bfd_arm_pe_allocate_interworking_sections
30159 +  (struct bfd_link_info *);
30160 +
30161 +extern bfd_boolean bfd_arm_pe_process_before_allocation
30162 +  (bfd *, struct bfd_link_info *, int);
30163 +
30164 +extern bfd_boolean bfd_arm_pe_get_bfd_for_interworking
30165 +  (bfd *, struct bfd_link_info *);
30166 +
30167 +/* ELF ARM Interworking support.  Called from linker.  */
30168 +extern bfd_boolean bfd_elf32_arm_allocate_interworking_sections
30169 +  (struct bfd_link_info *);
30170 +
30171 +extern bfd_boolean bfd_elf32_arm_process_before_allocation
30172 +  (bfd *, struct bfd_link_info *, int);
30173 +
30174 +void bfd_elf32_arm_set_target_relocs
30175 +  (struct bfd_link_info *, int, char *, int, int);
30176 +
30177 +extern bfd_boolean bfd_elf32_arm_get_bfd_for_interworking
30178 +  (bfd *, struct bfd_link_info *);
30179 +
30180 +extern bfd_boolean bfd_elf32_arm_add_glue_sections_to_bfd
30181 +  (bfd *, struct bfd_link_info *);
30182 +
30183 +/* ELF ARM mapping symbol support */
30184 +extern bfd_boolean bfd_is_arm_mapping_symbol_name
30185 +  (const char * name);
30186 +
30187 +/* ARM Note section processing.  */
30188 +extern bfd_boolean bfd_arm_merge_machines
30189 +  (bfd *, bfd *);
30190 +
30191 +extern bfd_boolean bfd_arm_update_notes
30192 +  (bfd *, const char *);
30193 +
30194 +extern unsigned int bfd_arm_get_mach_from_notes
30195 +  (bfd *, const char *);
30196 +
30197 +/* TI COFF load page support.  */
30198 +extern void bfd_ticoff_set_section_load_page
30199 +  (struct bfd_section *, int);
30200 +
30201 +extern int bfd_ticoff_get_section_load_page
30202 +  (struct bfd_section *);
30203 +
30204 +/* H8/300 functions.  */
30205 +extern bfd_vma bfd_h8300_pad_address
30206 +  (bfd *, bfd_vma);
30207 +
30208 +/* IA64 Itanium code generation.  Called from linker.  */
30209 +extern void bfd_elf32_ia64_after_parse
30210 +  (int);
30211 +
30212 +extern void bfd_elf64_ia64_after_parse
30213 +  (int);
30214 +
30215 +/* This structure is used for a comdat section, as in PE.  A comdat
30216 +   section is associated with a particular symbol.  When the linker
30217 +   sees a comdat section, it keeps only one of the sections with a
30218 +   given name and associated with a given symbol.  */
30219 +
30220 +struct coff_comdat_info
30221 +{
30222 +  /* The name of the symbol associated with a comdat section.  */
30223 +  const char *name;
30224 +
30225 +  /* The local symbol table index of the symbol associated with a
30226 +     comdat section.  This is only meaningful to the object file format
30227 +     specific code; it is not an index into the list returned by
30228 +     bfd_canonicalize_symtab.  */
30229 +  long symbol;
30230 +};
30231 +
30232 +extern struct coff_comdat_info *bfd_coff_get_comdat_section
30233 +  (bfd *, struct bfd_section *);
30234 +
30235 +/* Extracted from init.c.  */
30236 +void bfd_init (void);
30237 +
30238 +/* Extracted from opncls.c.  */
30239 +bfd *bfd_fopen (const char *filename, const char *target,
30240 +    const char *mode, int fd);
30241 +
30242 +bfd *bfd_openr (const char *filename, const char *target);
30243 +
30244 +bfd *bfd_fdopenr (const char *filename, const char *target, int fd);
30245 +
30246 +bfd *bfd_openstreamr (const char *, const char *, void *);
30247 +
30248 +bfd *bfd_openr_iovec (const char *filename, const char *target,
30249 +    void *(*open) (struct bfd *nbfd,
30250 +    void *open_closure),
30251 +    void *open_closure,
30252 +    file_ptr (*pread) (struct bfd *nbfd,
30253 +    void *stream,
30254 +    void *buf,
30255 +    file_ptr nbytes,
30256 +    file_ptr offset),
30257 +    int (*close) (struct bfd *nbfd,
30258 +    void *stream));
30259 +
30260 +bfd *bfd_openw (const char *filename, const char *target);
30261 +
30262 +bfd_boolean bfd_close (bfd *abfd);
30263 +
30264 +bfd_boolean bfd_close_all_done (bfd *);
30265 +
30266 +bfd *bfd_create (const char *filename, bfd *templ);
30267 +
30268 +bfd_boolean bfd_make_writable (bfd *abfd);
30269 +
30270 +bfd_boolean bfd_make_readable (bfd *abfd);
30271 +
30272 +unsigned long bfd_calc_gnu_debuglink_crc32
30273 +   (unsigned long crc, const unsigned char *buf, bfd_size_type len);
30274 +
30275 +char *bfd_follow_gnu_debuglink (bfd *abfd, const char *dir);
30276 +
30277 +struct bfd_section *bfd_create_gnu_debuglink_section
30278 +   (bfd *abfd, const char *filename);
30279 +
30280 +bfd_boolean bfd_fill_in_gnu_debuglink_section
30281 +   (bfd *abfd, struct bfd_section *sect, const char *filename);
30282 +
30283 +/* Extracted from libbfd.c.  */
30284 +
30285 +/* Byte swapping macros for user section data.  */
30286 +
30287 +#define bfd_put_8(abfd, val, ptr) \
30288 +  ((void) (*((unsigned char *) (ptr)) = (val) & 0xff))
30289 +#define bfd_put_signed_8 \
30290 +  bfd_put_8
30291 +#define bfd_get_8(abfd, ptr) \
30292 +  (*(unsigned char *) (ptr) & 0xff)
30293 +#define bfd_get_signed_8(abfd, ptr) \
30294 +  (((*(unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80)
30295 +
30296 +#define bfd_put_16(abfd, val, ptr) \
30297 +  BFD_SEND (abfd, bfd_putx16, ((val),(ptr)))
30298 +#define bfd_put_signed_16 \
30299 +  bfd_put_16
30300 +#define bfd_get_16(abfd, ptr) \
30301 +  BFD_SEND (abfd, bfd_getx16, (ptr))
30302 +#define bfd_get_signed_16(abfd, ptr) \
30303 +  BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
30304 +
30305 +#define bfd_put_32(abfd, val, ptr) \
30306 +  BFD_SEND (abfd, bfd_putx32, ((val),(ptr)))
30307 +#define bfd_put_signed_32 \
30308 +  bfd_put_32
30309 +#define bfd_get_32(abfd, ptr) \
30310 +  BFD_SEND (abfd, bfd_getx32, (ptr))
30311 +#define bfd_get_signed_32(abfd, ptr) \
30312 +  BFD_SEND (abfd, bfd_getx_signed_32, (ptr))
30313 +
30314 +#define bfd_put_64(abfd, val, ptr) \
30315 +  BFD_SEND (abfd, bfd_putx64, ((val), (ptr)))
30316 +#define bfd_put_signed_64 \
30317 +  bfd_put_64
30318 +#define bfd_get_64(abfd, ptr) \
30319 +  BFD_SEND (abfd, bfd_getx64, (ptr))
30320 +#define bfd_get_signed_64(abfd, ptr) \
30321 +  BFD_SEND (abfd, bfd_getx_signed_64, (ptr))
30322 +
30323 +#define bfd_get(bits, abfd, ptr)                       \
30324 +  ((bits) == 8 ? (bfd_vma) bfd_get_8 (abfd, ptr)       \
30325 +   : (bits) == 16 ? bfd_get_16 (abfd, ptr)             \
30326 +   : (bits) == 32 ? bfd_get_32 (abfd, ptr)             \
30327 +   : (bits) == 64 ? bfd_get_64 (abfd, ptr)             \
30328 +   : (abort (), (bfd_vma) - 1))
30329 +
30330 +#define bfd_put(bits, abfd, val, ptr)                  \
30331 +  ((bits) == 8 ? bfd_put_8  (abfd, val, ptr)           \
30332 +   : (bits) == 16 ? bfd_put_16 (abfd, val, ptr)                \
30333 +   : (bits) == 32 ? bfd_put_32 (abfd, val, ptr)                \
30334 +   : (bits) == 64 ? bfd_put_64 (abfd, val, ptr)                \
30335 +   : (abort (), (void) 0))
30336 +
30337 +
30338 +/* Byte swapping macros for file header data.  */
30339 +
30340 +#define bfd_h_put_8(abfd, val, ptr) \
30341 +  bfd_put_8 (abfd, val, ptr)
30342 +#define bfd_h_put_signed_8(abfd, val, ptr) \
30343 +  bfd_put_8 (abfd, val, ptr)
30344 +#define bfd_h_get_8(abfd, ptr) \
30345 +  bfd_get_8 (abfd, ptr)
30346 +#define bfd_h_get_signed_8(abfd, ptr) \
30347 +  bfd_get_signed_8 (abfd, ptr)
30348 +
30349 +#define bfd_h_put_16(abfd, val, ptr) \
30350 +  BFD_SEND (abfd, bfd_h_putx16, (val, ptr))
30351 +#define bfd_h_put_signed_16 \
30352 +  bfd_h_put_16
30353 +#define bfd_h_get_16(abfd, ptr) \
30354 +  BFD_SEND (abfd, bfd_h_getx16, (ptr))
30355 +#define bfd_h_get_signed_16(abfd, ptr) \
30356 +  BFD_SEND (abfd, bfd_h_getx_signed_16, (ptr))
30357 +
30358 +#define bfd_h_put_32(abfd, val, ptr) \
30359 +  BFD_SEND (abfd, bfd_h_putx32, (val, ptr))
30360 +#define bfd_h_put_signed_32 \
30361 +  bfd_h_put_32
30362 +#define bfd_h_get_32(abfd, ptr) \
30363 +  BFD_SEND (abfd, bfd_h_getx32, (ptr))
30364 +#define bfd_h_get_signed_32(abfd, ptr) \
30365 +  BFD_SEND (abfd, bfd_h_getx_signed_32, (ptr))
30366 +
30367 +#define bfd_h_put_64(abfd, val, ptr) \
30368 +  BFD_SEND (abfd, bfd_h_putx64, (val, ptr))
30369 +#define bfd_h_put_signed_64 \
30370 +  bfd_h_put_64
30371 +#define bfd_h_get_64(abfd, ptr) \
30372 +  BFD_SEND (abfd, bfd_h_getx64, (ptr))
30373 +#define bfd_h_get_signed_64(abfd, ptr) \
30374 +  BFD_SEND (abfd, bfd_h_getx_signed_64, (ptr))
30375 +
30376 +/* Aliases for the above, which should eventually go away.  */
30377 +
30378 +#define H_PUT_64  bfd_h_put_64
30379 +#define H_PUT_32  bfd_h_put_32
30380 +#define H_PUT_16  bfd_h_put_16
30381 +#define H_PUT_8   bfd_h_put_8
30382 +#define H_PUT_S64 bfd_h_put_signed_64
30383 +#define H_PUT_S32 bfd_h_put_signed_32
30384 +#define H_PUT_S16 bfd_h_put_signed_16
30385 +#define H_PUT_S8  bfd_h_put_signed_8
30386 +#define H_GET_64  bfd_h_get_64
30387 +#define H_GET_32  bfd_h_get_32
30388 +#define H_GET_16  bfd_h_get_16
30389 +#define H_GET_8   bfd_h_get_8
30390 +#define H_GET_S64 bfd_h_get_signed_64
30391 +#define H_GET_S32 bfd_h_get_signed_32
30392 +#define H_GET_S16 bfd_h_get_signed_16
30393 +#define H_GET_S8  bfd_h_get_signed_8
30394 +
30395 +
30396 +/* Extracted from bfdio.c.  */
30397 +long bfd_get_mtime (bfd *abfd);
30398 +
30399 +long bfd_get_size (bfd *abfd);
30400 +
30401 +/* Extracted from bfdwin.c.  */
30402 +/* Extracted from section.c.  */
30403 +typedef struct bfd_section
30404 +{
30405 +  /* The name of the section; the name isn't a copy, the pointer is
30406 +     the same as that passed to bfd_make_section.  */
30407 +  const char *name;
30408 +
30409 +  /* A unique sequence number.  */
30410 +  int id;
30411 +
30412 +  /* Which section in the bfd; 0..n-1 as sections are created in a bfd.  */
30413 +  int index;
30414 +
30415 +  /* The next section in the list belonging to the BFD, or NULL.  */
30416 +  struct bfd_section *next;
30417 +
30418 +  /* The previous section in the list belonging to the BFD, or NULL.  */
30419 +  struct bfd_section *prev;
30420 +
30421 +  /* The field flags contains attributes of the section. Some
30422 +     flags are read in from the object file, and some are
30423 +     synthesized from other information.  */
30424 +  flagword flags;
30425 +
30426 +#define SEC_NO_FLAGS   0x000
30427 +
30428 +  /* Tells the OS to allocate space for this section when loading.
30429 +     This is clear for a section containing debug information only.  */
30430 +#define SEC_ALLOC      0x001
30431 +
30432 +  /* Tells the OS to load the section from the file when loading.
30433 +     This is clear for a .bss section.  */
30434 +#define SEC_LOAD       0x002
30435 +
30436 +  /* The section contains data still to be relocated, so there is
30437 +     some relocation information too.  */
30438 +#define SEC_RELOC      0x004
30439 +
30440 +  /* A signal to the OS that the section contains read only data.  */
30441 +#define SEC_READONLY   0x008
30442 +
30443 +  /* The section contains code only.  */
30444 +#define SEC_CODE       0x010
30445 +
30446 +  /* The section contains data only.  */
30447 +#define SEC_DATA       0x020
30448 +
30449 +  /* The section will reside in ROM.  */
30450 +#define SEC_ROM        0x040
30451 +
30452 +  /* The section contains constructor information. This section
30453 +     type is used by the linker to create lists of constructors and
30454 +     destructors used by <<g++>>. When a back end sees a symbol
30455 +     which should be used in a constructor list, it creates a new
30456 +     section for the type of name (e.g., <<__CTOR_LIST__>>), attaches
30457 +     the symbol to it, and builds a relocation. To build the lists
30458 +     of constructors, all the linker has to do is catenate all the
30459 +     sections called <<__CTOR_LIST__>> and relocate the data
30460 +     contained within - exactly the operations it would peform on
30461 +     standard data.  */
30462 +#define SEC_CONSTRUCTOR 0x080
30463 +
30464 +  /* The section has contents - a data section could be
30465 +     <<SEC_ALLOC>> | <<SEC_HAS_CONTENTS>>; a debug section could be
30466 +     <<SEC_HAS_CONTENTS>>  */
30467 +#define SEC_HAS_CONTENTS 0x100
30468 +
30469 +  /* An instruction to the linker to not output the section
30470 +     even if it has information which would normally be written.  */
30471 +#define SEC_NEVER_LOAD 0x200
30472 +
30473 +  /* The section contains thread local data.  */
30474 +#define SEC_THREAD_LOCAL 0x400
30475 +
30476 +  /* The section has GOT references.  This flag is only for the
30477 +     linker, and is currently only used by the elf32-hppa back end.
30478 +     It will be set if global offset table references were detected
30479 +     in this section, which indicate to the linker that the section
30480 +     contains PIC code, and must be handled specially when doing a
30481 +     static link.  */
30482 +#define SEC_HAS_GOT_REF 0x800
30483 +
30484 +  /* The section contains common symbols (symbols may be defined
30485 +     multiple times, the value of a symbol is the amount of
30486 +     space it requires, and the largest symbol value is the one
30487 +     used).  Most targets have exactly one of these (which we
30488 +     translate to bfd_com_section_ptr), but ECOFF has two.  */
30489 +#define SEC_IS_COMMON 0x1000
30490 +
30491 +  /* The section contains only debugging information.  For
30492 +     example, this is set for ELF .debug and .stab sections.
30493 +     strip tests this flag to see if a section can be
30494 +     discarded.  */
30495 +#define SEC_DEBUGGING 0x2000
30496 +
30497 +  /* The contents of this section are held in memory pointed to
30498 +     by the contents field.  This is checked by bfd_get_section_contents,
30499 +     and the data is retrieved from memory if appropriate.  */
30500 +#define SEC_IN_MEMORY 0x4000
30501 +
30502 +  /* The contents of this section are to be excluded by the
30503 +     linker for executable and shared objects unless those
30504 +     objects are to be further relocated.  */
30505 +#define SEC_EXCLUDE 0x8000
30506 +
30507 +  /* The contents of this section are to be sorted based on the sum of
30508 +     the symbol and addend values specified by the associated relocation
30509 +     entries.  Entries without associated relocation entries will be
30510 +     appended to the end of the section in an unspecified order.  */
30511 +#define SEC_SORT_ENTRIES 0x10000
30512 +
30513 +  /* When linking, duplicate sections of the same name should be
30514 +     discarded, rather than being combined into a single section as
30515 +     is usually done.  This is similar to how common symbols are
30516 +     handled.  See SEC_LINK_DUPLICATES below.  */
30517 +#define SEC_LINK_ONCE 0x20000
30518 +
30519 +  /* If SEC_LINK_ONCE is set, this bitfield describes how the linker
30520 +     should handle duplicate sections.  */
30521 +#define SEC_LINK_DUPLICATES 0x40000
30522 +
30523 +  /* This value for SEC_LINK_DUPLICATES means that duplicate
30524 +     sections with the same name should simply be discarded.  */
30525 +#define SEC_LINK_DUPLICATES_DISCARD 0x0
30526 +
30527 +  /* This value for SEC_LINK_DUPLICATES means that the linker
30528 +     should warn if there are any duplicate sections, although
30529 +     it should still only link one copy.  */
30530 +#define SEC_LINK_DUPLICATES_ONE_ONLY 0x80000
30531 +
30532 +  /* This value for SEC_LINK_DUPLICATES means that the linker
30533 +     should warn if any duplicate sections are a different size.  */
30534 +#define SEC_LINK_DUPLICATES_SAME_SIZE 0x100000
30535 +
30536 +  /* This value for SEC_LINK_DUPLICATES means that the linker
30537 +     should warn if any duplicate sections contain different
30538 +     contents.  */
30539 +#define SEC_LINK_DUPLICATES_SAME_CONTENTS \
30540 +  (SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE)
30541 +
30542 +  /* This section was created by the linker as part of dynamic
30543 +     relocation or other arcane processing.  It is skipped when
30544 +     going through the first-pass output, trusting that someone
30545 +     else up the line will take care of it later.  */
30546 +#define SEC_LINKER_CREATED 0x200000
30547 +
30548 +  /* This section should not be subject to garbage collection.  */
30549 +#define SEC_KEEP 0x400000
30550 +
30551 +  /* This section contains "short" data, and should be placed
30552 +     "near" the GP.  */
30553 +#define SEC_SMALL_DATA 0x800000
30554 +
30555 +  /* Attempt to merge identical entities in the section.
30556 +     Entity size is given in the entsize field.  */
30557 +#define SEC_MERGE 0x1000000
30558 +
30559 +  /* If given with SEC_MERGE, entities to merge are zero terminated
30560 +     strings where entsize specifies character size instead of fixed
30561 +     size entries.  */
30562 +#define SEC_STRINGS 0x2000000
30563 +
30564 +  /* This section contains data about section groups.  */
30565 +#define SEC_GROUP 0x4000000
30566 +
30567 +  /* The section is a COFF shared library section.  This flag is
30568 +     only for the linker.  If this type of section appears in
30569 +     the input file, the linker must copy it to the output file
30570 +     without changing the vma or size.  FIXME: Although this
30571 +     was originally intended to be general, it really is COFF
30572 +     specific (and the flag was renamed to indicate this).  It
30573 +     might be cleaner to have some more general mechanism to
30574 +     allow the back end to control what the linker does with
30575 +     sections.  */
30576 +#define SEC_COFF_SHARED_LIBRARY 0x10000000
30577 +
30578 +  /* This section contains data which may be shared with other
30579 +     executables or shared objects. This is for COFF only.  */
30580 +#define SEC_COFF_SHARED 0x20000000
30581 +
30582 +  /* When a section with this flag is being linked, then if the size of
30583 +     the input section is less than a page, it should not cross a page
30584 +     boundary.  If the size of the input section is one page or more,
30585 +     it should be aligned on a page boundary.  This is for TI
30586 +     TMS320C54X only.  */
30587 +#define SEC_TIC54X_BLOCK 0x40000000
30588 +
30589 +  /* Conditionally link this section; do not link if there are no
30590 +     references found to any symbol in the section.  This is for TI
30591 +     TMS320C54X only.  */
30592 +#define SEC_TIC54X_CLINK 0x80000000
30593 +
30594 +  /*  End of section flags.  */
30595 +
30596 +  /* Some internal packed boolean fields.  */
30597 +
30598 +  /* See the vma field.  */
30599 +  unsigned int user_set_vma : 1;
30600 +
30601 +  /* A mark flag used by some of the linker backends.  */
30602 +  unsigned int linker_mark : 1;
30603 +
30604 +  /* Another mark flag used by some of the linker backends.  Set for
30605 +     output sections that have an input section.  */
30606 +  unsigned int linker_has_input : 1;
30607 +
30608 +  /* Mark flags used by some linker backends for garbage collection.  */
30609 +  unsigned int gc_mark : 1;
30610 +  unsigned int gc_mark_from_eh : 1;
30611 +
30612 +  /* The following flags are used by the ELF linker. */
30613 +
30614 +  /* Mark sections which have been allocated to segments.  */
30615 +  unsigned int segment_mark : 1;
30616 +
30617 +  /* Type of sec_info information.  */
30618 +  unsigned int sec_info_type:3;
30619 +#define ELF_INFO_TYPE_NONE      0
30620 +#define ELF_INFO_TYPE_STABS     1
30621 +#define ELF_INFO_TYPE_MERGE     2
30622 +#define ELF_INFO_TYPE_EH_FRAME  3
30623 +#define ELF_INFO_TYPE_JUST_SYMS 4
30624 +
30625 +  /* Nonzero if this section uses RELA relocations, rather than REL.  */
30626 +  unsigned int use_rela_p:1;
30627 +
30628 +  /* Bits used by various backends.  The generic code doesn't touch
30629 +     these fields.  */
30630 +
30631 +  /* Nonzero if this section has TLS related relocations.  */
30632 +  unsigned int has_tls_reloc:1;
30633 +
30634 +  /* Nonzero if this section has a gp reloc.  */
30635 +  unsigned int has_gp_reloc:1;
30636 +
30637 +  /* Nonzero if this section needs the relax finalize pass.  */
30638 +  unsigned int need_finalize_relax:1;
30639 +
30640 +  /* Whether relocations have been processed.  */
30641 +  unsigned int reloc_done : 1;
30642 +
30643 +  /* End of internal packed boolean fields.  */
30644 +
30645 +  /*  The virtual memory address of the section - where it will be
30646 +      at run time.  The symbols are relocated against this.  The
30647 +      user_set_vma flag is maintained by bfd; if it's not set, the
30648 +      backend can assign addresses (for example, in <<a.out>>, where
30649 +      the default address for <<.data>> is dependent on the specific
30650 +      target and various flags).  */
30651 +  bfd_vma vma;
30652 +
30653 +  /*  The load address of the section - where it would be in a
30654 +      rom image; really only used for writing section header
30655 +      information.  */
30656 +  bfd_vma lma;
30657 +
30658 +  /* The size of the section in octets, as it will be output.
30659 +     Contains a value even if the section has no contents (e.g., the
30660 +     size of <<.bss>>).  */
30661 +  bfd_size_type size;
30662 +
30663 +  /* For input sections, the original size on disk of the section, in
30664 +     octets.  This field is used by the linker relaxation code.  It is
30665 +     currently only set for sections where the linker relaxation scheme
30666 +     doesn't cache altered section and reloc contents (stabs, eh_frame,
30667 +     SEC_MERGE, some coff relaxing targets), and thus the original size
30668 +     needs to be kept to read the section multiple times.
30669 +     For output sections, rawsize holds the section size calculated on
30670 +     a previous linker relaxation pass.  */
30671 +  bfd_size_type rawsize;
30672 +
30673 +  /* If this section is going to be output, then this value is the
30674 +     offset in *bytes* into the output section of the first byte in the
30675 +     input section (byte ==> smallest addressable unit on the
30676 +     target).  In most cases, if this was going to start at the
30677 +     100th octet (8-bit quantity) in the output section, this value
30678 +     would be 100.  However, if the target byte size is 16 bits
30679 +     (bfd_octets_per_byte is "2"), this value would be 50.  */
30680 +  bfd_vma output_offset;
30681 +
30682 +  /* The output section through which to map on output.  */
30683 +  struct bfd_section *output_section;
30684 +
30685 +  /* The alignment requirement of the section, as an exponent of 2 -
30686 +     e.g., 3 aligns to 2^3 (or 8).  */
30687 +  unsigned int alignment_power;
30688 +
30689 +  /* If an input section, a pointer to a vector of relocation
30690 +     records for the data in this section.  */
30691 +  struct reloc_cache_entry *relocation;
30692 +
30693 +  /* If an output section, a pointer to a vector of pointers to
30694 +     relocation records for the data in this section.  */
30695 +  struct reloc_cache_entry **orelocation;
30696 +
30697 +  /* The number of relocation records in one of the above.  */
30698 +  unsigned reloc_count;
30699 +
30700 +  /* Information below is back end specific - and not always used
30701 +     or updated.  */
30702 +
30703 +  /* File position of section data.  */
30704 +  file_ptr filepos;
30705 +
30706 +  /* File position of relocation info.  */
30707 +  file_ptr rel_filepos;
30708 +
30709 +  /* File position of line data.  */
30710 +  file_ptr line_filepos;
30711 +
30712 +  /* Pointer to data for applications.  */
30713 +  void *userdata;
30714 +
30715 +  /* If the SEC_IN_MEMORY flag is set, this points to the actual
30716 +     contents.  */
30717 +  unsigned char *contents;
30718 +
30719 +  /* Attached line number information.  */
30720 +  alent *lineno;
30721 +
30722 +  /* Number of line number records.  */
30723 +  unsigned int lineno_count;
30724 +
30725 +  /* Entity size for merging purposes.  */
30726 +  unsigned int entsize;
30727 +
30728 +  /* Points to the kept section if this section is a link-once section,
30729 +     and is discarded.  */
30730 +  struct bfd_section *kept_section;
30731 +
30732 +  /* When a section is being output, this value changes as more
30733 +     linenumbers are written out.  */
30734 +  file_ptr moving_line_filepos;
30735 +
30736 +  /* What the section number is in the target world.  */
30737 +  int target_index;
30738 +
30739 +  void *used_by_bfd;
30740 +
30741 +  /* If this is a constructor section then here is a list of the
30742 +     relocations created to relocate items within it.  */
30743 +  struct relent_chain *constructor_chain;
30744 +
30745 +  /* The BFD which owns the section.  */
30746 +  bfd *owner;
30747 +
30748 +  /* A symbol which points at this section only.  */
30749 +  struct bfd_symbol *symbol;
30750 +  struct bfd_symbol **symbol_ptr_ptr;
30751 +
30752 +  /* Early in the link process, map_head and map_tail are used to build
30753 +     a list of input sections attached to an output section.  Later,
30754 +     output sections use these fields for a list of bfd_link_order
30755 +     structs.  */
30756 +  union {
30757 +    struct bfd_link_order *link_order;
30758 +    struct bfd_section *s;
30759 +  } map_head, map_tail;
30760 +} asection;
30761 +
30762 +/* These sections are global, and are managed by BFD.  The application
30763 +   and target back end are not permitted to change the values in
30764 +   these sections.  New code should use the section_ptr macros rather
30765 +   than referring directly to the const sections.  The const sections
30766 +   may eventually vanish.  */
30767 +#define BFD_ABS_SECTION_NAME "*ABS*"
30768 +#define BFD_UND_SECTION_NAME "*UND*"
30769 +#define BFD_COM_SECTION_NAME "*COM*"
30770 +#define BFD_IND_SECTION_NAME "*IND*"
30771 +
30772 +/* The absolute section.  */
30773 +extern asection bfd_abs_section;
30774 +#define bfd_abs_section_ptr ((asection *) &bfd_abs_section)
30775 +#define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr)
30776 +/* Pointer to the undefined section.  */
30777 +extern asection bfd_und_section;
30778 +#define bfd_und_section_ptr ((asection *) &bfd_und_section)
30779 +#define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr)
30780 +/* Pointer to the common section.  */
30781 +extern asection bfd_com_section;
30782 +#define bfd_com_section_ptr ((asection *) &bfd_com_section)
30783 +/* Pointer to the indirect section.  */
30784 +extern asection bfd_ind_section;
30785 +#define bfd_ind_section_ptr ((asection *) &bfd_ind_section)
30786 +#define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr)
30787 +
30788 +#define bfd_is_const_section(SEC)              \
30789 + (   ((SEC) == bfd_abs_section_ptr)            \
30790 +  || ((SEC) == bfd_und_section_ptr)            \
30791 +  || ((SEC) == bfd_com_section_ptr)            \
30792 +  || ((SEC) == bfd_ind_section_ptr))
30793 +
30794 +extern const struct bfd_symbol * const bfd_abs_symbol;
30795 +extern const struct bfd_symbol * const bfd_com_symbol;
30796 +extern const struct bfd_symbol * const bfd_und_symbol;
30797 +extern const struct bfd_symbol * const bfd_ind_symbol;
30798 +
30799 +/* Macros to handle insertion and deletion of a bfd's sections.  These
30800 +   only handle the list pointers, ie. do not adjust section_count,
30801 +   target_index etc.  */
30802 +#define bfd_section_list_remove(ABFD, S) \
30803 +  do                                                   \
30804 +    {                                                  \
30805 +      asection *_s = S;                                \
30806 +      asection *_next = _s->next;                      \
30807 +      asection *_prev = _s->prev;                      \
30808 +      if (_prev)                                       \
30809 +        _prev->next = _next;                           \
30810 +      else                                             \
30811 +        (ABFD)->sections = _next;                      \
30812 +      if (_next)                                       \
30813 +        _next->prev = _prev;                           \
30814 +      else                                             \
30815 +        (ABFD)->section_last = _prev;                  \
30816 +    }                                                  \
30817 +  while (0)
30818 +#define bfd_section_list_append(ABFD, S) \
30819 +  do                                                   \
30820 +    {                                                  \
30821 +      asection *_s = S;                                \
30822 +      bfd *_abfd = ABFD;                               \
30823 +      _s->next = NULL;                                 \
30824 +      if (_abfd->section_last)                         \
30825 +        {                                              \
30826 +          _s->prev = _abfd->section_last;              \
30827 +          _abfd->section_last->next = _s;              \
30828 +        }                                              \
30829 +      else                                             \
30830 +        {                                              \
30831 +          _s->prev = NULL;                             \
30832 +          _abfd->sections = _s;                        \
30833 +        }                                              \
30834 +      _abfd->section_last = _s;                        \
30835 +    }                                                  \
30836 +  while (0)
30837 +#define bfd_section_list_prepend(ABFD, S) \
30838 +  do                                                   \
30839 +    {                                                  \
30840 +      asection *_s = S;                                \
30841 +      bfd *_abfd = ABFD;                               \
30842 +      _s->prev = NULL;                                 \
30843 +      if (_abfd->sections)                             \
30844 +        {                                              \
30845 +          _s->next = _abfd->sections;                  \
30846 +          _abfd->sections->prev = _s;                  \
30847 +        }                                              \
30848 +      else                                             \
30849 +        {                                              \
30850 +          _s->next = NULL;                             \
30851 +          _abfd->section_last = _s;                    \
30852 +        }                                              \
30853 +      _abfd->sections = _s;                            \
30854 +    }                                                  \
30855 +  while (0)
30856 +#define bfd_section_list_insert_after(ABFD, A, S) \
30857 +  do                                                   \
30858 +    {                                                  \
30859 +      asection *_a = A;                                \
30860 +      asection *_s = S;                                \
30861 +      asection *_next = _a->next;                      \
30862 +      _s->next = _next;                                \
30863 +      _s->prev = _a;                                   \
30864 +      _a->next = _s;                                   \
30865 +      if (_next)                                       \
30866 +        _next->prev = _s;                              \
30867 +      else                                             \
30868 +        (ABFD)->section_last = _s;                     \
30869 +    }                                                  \
30870 +  while (0)
30871 +#define bfd_section_list_insert_before(ABFD, B, S) \
30872 +  do                                                   \
30873 +    {                                                  \
30874 +      asection *_b = B;                                \
30875 +      asection *_s = S;                                \
30876 +      asection *_prev = _b->prev;                      \
30877 +      _s->prev = _prev;                                \
30878 +      _s->next = _b;                                   \
30879 +      _b->prev = _s;                                   \
30880 +      if (_prev)                                       \
30881 +        _prev->next = _s;                              \
30882 +      else                                             \
30883 +        (ABFD)->sections = _s;                         \
30884 +    }                                                  \
30885 +  while (0)
30886 +#define bfd_section_removed_from_list(ABFD, S) \
30887 +  ((S)->next == NULL ? (ABFD)->section_last != (S) : (S)->next->prev != (S))
30888 +
30889 +void bfd_section_list_clear (bfd *);
30890 +
30891 +asection *bfd_get_section_by_name (bfd *abfd, const char *name);
30892 +
30893 +asection *bfd_get_section_by_name_if
30894 +   (bfd *abfd,
30895 +    const char *name,
30896 +    bfd_boolean (*func) (bfd *abfd, asection *sect, void *obj),
30897 +    void *obj);
30898 +
30899 +char *bfd_get_unique_section_name
30900 +   (bfd *abfd, const char *templat, int *count);
30901 +
30902 +asection *bfd_make_section_old_way (bfd *abfd, const char *name);
30903 +
30904 +asection *bfd_make_section_anyway_with_flags
30905 +   (bfd *abfd, const char *name, flagword flags);
30906 +
30907 +asection *bfd_make_section_anyway (bfd *abfd, const char *name);
30908 +
30909 +asection *bfd_make_section_with_flags
30910 +   (bfd *, const char *name, flagword flags);
30911 +
30912 +asection *bfd_make_section (bfd *, const char *name);
30913 +
30914 +bfd_boolean bfd_set_section_flags
30915 +   (bfd *abfd, asection *sec, flagword flags);
30916 +
30917 +void bfd_map_over_sections
30918 +   (bfd *abfd,
30919 +    void (*func) (bfd *abfd, asection *sect, void *obj),
30920 +    void *obj);
30921 +
30922 +asection *bfd_sections_find_if
30923 +   (bfd *abfd,
30924 +    bfd_boolean (*operation) (bfd *abfd, asection *sect, void *obj),
30925 +    void *obj);
30926 +
30927 +bfd_boolean bfd_set_section_size
30928 +   (bfd *abfd, asection *sec, bfd_size_type val);
30929 +
30930 +bfd_boolean bfd_set_section_contents
30931 +   (bfd *abfd, asection *section, const void *data,
30932 +    file_ptr offset, bfd_size_type count);
30933 +
30934 +bfd_boolean bfd_get_section_contents
30935 +   (bfd *abfd, asection *section, void *location, file_ptr offset,
30936 +    bfd_size_type count);
30937 +
30938 +bfd_boolean bfd_malloc_and_get_section
30939 +   (bfd *abfd, asection *section, bfd_byte **buf);
30940 +
30941 +bfd_boolean bfd_copy_private_section_data
30942 +   (bfd *ibfd, asection *isec, bfd *obfd, asection *osec);
30943 +
30944 +#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \
30945 +     BFD_SEND (obfd, _bfd_copy_private_section_data, \
30946 +               (ibfd, isection, obfd, osection))
30947 +bfd_boolean bfd_generic_is_group_section (bfd *, const asection *sec);
30948 +
30949 +bfd_boolean bfd_generic_discard_group (bfd *abfd, asection *group);
30950 +
30951 +/* Extracted from archures.c.  */
30952 +enum bfd_architecture
30953 +{
30954 +  bfd_arch_unknown,   /* File arch not known.  */
30955 +  bfd_arch_obscure,   /* Arch known, not one of these.  */
30956 +  bfd_arch_m68k,      /* Motorola 68xxx */
30957 +#define bfd_mach_m68000 1
30958 +#define bfd_mach_m68008 2
30959 +#define bfd_mach_m68010 3
30960 +#define bfd_mach_m68020 4
30961 +#define bfd_mach_m68030 5
30962 +#define bfd_mach_m68040 6
30963 +#define bfd_mach_m68060 7
30964 +#define bfd_mach_cpu32  8
30965 +#define bfd_mach_mcf5200  9
30966 +#define bfd_mach_mcf5206e 10
30967 +#define bfd_mach_mcf5307  11
30968 +#define bfd_mach_mcf5407  12
30969 +#define bfd_mach_mcf528x  13
30970 +#define bfd_mach_mcfv4e   14
30971 +#define bfd_mach_mcf521x   15
30972 +#define bfd_mach_mcf5249   16
30973 +#define bfd_mach_mcf547x   17
30974 +#define bfd_mach_mcf548x   18
30975 +  bfd_arch_vax,       /* DEC Vax */
30976 +  bfd_arch_i960,      /* Intel 960 */
30977 +    /* The order of the following is important.
30978 +       lower number indicates a machine type that
30979 +       only accepts a subset of the instructions
30980 +       available to machines with higher numbers.
30981 +       The exception is the "ca", which is
30982 +       incompatible with all other machines except
30983 +       "core".  */
30984 +
30985 +#define bfd_mach_i960_core      1
30986 +#define bfd_mach_i960_ka_sa     2
30987 +#define bfd_mach_i960_kb_sb     3
30988 +#define bfd_mach_i960_mc        4
30989 +#define bfd_mach_i960_xa        5
30990 +#define bfd_mach_i960_ca        6
30991 +#define bfd_mach_i960_jx        7
30992 +#define bfd_mach_i960_hx        8
30993 +
30994 +  bfd_arch_or32,      /* OpenRISC 32 */
30995 +
30996 +  bfd_arch_a29k,      /* AMD 29000 */
30997 +  bfd_arch_sparc,     /* SPARC */
30998 +#define bfd_mach_sparc                 1
30999 +/* The difference between v8plus and v9 is that v9 is a true 64 bit env.  */
31000 +#define bfd_mach_sparc_sparclet        2
31001 +#define bfd_mach_sparc_sparclite       3
31002 +#define bfd_mach_sparc_v8plus          4
31003 +#define bfd_mach_sparc_v8plusa         5 /* with ultrasparc add'ns.  */
31004 +#define bfd_mach_sparc_sparclite_le    6
31005 +#define bfd_mach_sparc_v9              7
31006 +#define bfd_mach_sparc_v9a             8 /* with ultrasparc add'ns.  */
31007 +#define bfd_mach_sparc_v8plusb         9 /* with cheetah add'ns.  */
31008 +#define bfd_mach_sparc_v9b             10 /* with cheetah add'ns.  */
31009 +/* Nonzero if MACH has the v9 instruction set.  */
31010 +#define bfd_mach_sparc_v9_p(mach) \
31011 +  ((mach) >= bfd_mach_sparc_v8plus && (mach) <= bfd_mach_sparc_v9b \
31012 +   && (mach) != bfd_mach_sparc_sparclite_le)
31013 +/* Nonzero if MACH is a 64 bit sparc architecture.  */
31014 +#define bfd_mach_sparc_64bit_p(mach) \
31015 +  ((mach) >= bfd_mach_sparc_v9 && (mach) != bfd_mach_sparc_v8plusb)
31016 +  bfd_arch_mips,      /* MIPS Rxxxx */
31017 +#define bfd_mach_mips3000              3000
31018 +#define bfd_mach_mips3900              3900
31019 +#define bfd_mach_mips4000              4000
31020 +#define bfd_mach_mips4010              4010
31021 +#define bfd_mach_mips4100              4100
31022 +#define bfd_mach_mips4111              4111
31023 +#define bfd_mach_mips4120              4120
31024 +#define bfd_mach_mips4300              4300
31025 +#define bfd_mach_mips4400              4400
31026 +#define bfd_mach_mips4600              4600
31027 +#define bfd_mach_mips4650              4650
31028 +#define bfd_mach_mips5000              5000
31029 +#define bfd_mach_mips5400              5400
31030 +#define bfd_mach_mips5500              5500
31031 +#define bfd_mach_mips6000              6000
31032 +#define bfd_mach_mips7000              7000
31033 +#define bfd_mach_mips8000              8000
31034 +#define bfd_mach_mips9000              9000
31035 +#define bfd_mach_mips10000             10000
31036 +#define bfd_mach_mips12000             12000
31037 +#define bfd_mach_mips16                16
31038 +#define bfd_mach_mips5                 5
31039 +#define bfd_mach_mips_sb1              12310201 /* octal 'SB', 01 */
31040 +#define bfd_mach_mipsisa32             32
31041 +#define bfd_mach_mipsisa32r2           33
31042 +#define bfd_mach_mipsisa64             64
31043 +#define bfd_mach_mipsisa64r2           65
31044 +  bfd_arch_i386,      /* Intel 386 */
31045 +#define bfd_mach_i386_i386 1
31046 +#define bfd_mach_i386_i8086 2
31047 +#define bfd_mach_i386_i386_intel_syntax 3
31048 +#define bfd_mach_x86_64 64
31049 +#define bfd_mach_x86_64_intel_syntax 65
31050 +  bfd_arch_we32k,     /* AT&T WE32xxx */
31051 +  bfd_arch_tahoe,     /* CCI/Harris Tahoe */
31052 +  bfd_arch_i860,      /* Intel 860 */
31053 +  bfd_arch_i370,      /* IBM 360/370 Mainframes */
31054 +  bfd_arch_romp,      /* IBM ROMP PC/RT */
31055 +  bfd_arch_alliant,   /* Alliant */
31056 +  bfd_arch_convex,    /* Convex */
31057 +  bfd_arch_m88k,      /* Motorola 88xxx */
31058 +  bfd_arch_m98k,      /* Motorola 98xxx */
31059 +  bfd_arch_pyramid,   /* Pyramid Technology */
31060 +  bfd_arch_h8300,     /* Renesas H8/300 (formerly Hitachi H8/300) */
31061 +#define bfd_mach_h8300    1
31062 +#define bfd_mach_h8300h   2
31063 +#define bfd_mach_h8300s   3
31064 +#define bfd_mach_h8300hn  4
31065 +#define bfd_mach_h8300sn  5
31066 +#define bfd_mach_h8300sx  6
31067 +#define bfd_mach_h8300sxn 7
31068 +  bfd_arch_pdp11,     /* DEC PDP-11 */
31069 +  bfd_arch_powerpc,   /* PowerPC */
31070 +#define bfd_mach_ppc           32
31071 +#define bfd_mach_ppc64         64
31072 +#define bfd_mach_ppc_403       403
31073 +#define bfd_mach_ppc_403gc     4030
31074 +#define bfd_mach_ppc_505       505
31075 +#define bfd_mach_ppc_601       601
31076 +#define bfd_mach_ppc_602       602
31077 +#define bfd_mach_ppc_603       603
31078 +#define bfd_mach_ppc_ec603e    6031
31079 +#define bfd_mach_ppc_604       604
31080 +#define bfd_mach_ppc_620       620
31081 +#define bfd_mach_ppc_630       630
31082 +#define bfd_mach_ppc_750       750
31083 +#define bfd_mach_ppc_860       860
31084 +#define bfd_mach_ppc_a35       35
31085 +#define bfd_mach_ppc_rs64ii    642
31086 +#define bfd_mach_ppc_rs64iii   643
31087 +#define bfd_mach_ppc_7400      7400
31088 +#define bfd_mach_ppc_e500      500
31089 +  bfd_arch_rs6000,    /* IBM RS/6000 */
31090 +#define bfd_mach_rs6k          6000
31091 +#define bfd_mach_rs6k_rs1      6001
31092 +#define bfd_mach_rs6k_rsc      6003
31093 +#define bfd_mach_rs6k_rs2      6002
31094 +  bfd_arch_hppa,      /* HP PA RISC */
31095 +#define bfd_mach_hppa10        10
31096 +#define bfd_mach_hppa11        11
31097 +#define bfd_mach_hppa20        20
31098 +#define bfd_mach_hppa20w       25
31099 +  bfd_arch_d10v,      /* Mitsubishi D10V */
31100 +#define bfd_mach_d10v          1
31101 +#define bfd_mach_d10v_ts2      2
31102 +#define bfd_mach_d10v_ts3      3
31103 +  bfd_arch_d30v,      /* Mitsubishi D30V */
31104 +  bfd_arch_dlx,       /* DLX */
31105 +  bfd_arch_m68hc11,   /* Motorola 68HC11 */
31106 +  bfd_arch_m68hc12,   /* Motorola 68HC12 */
31107 +#define bfd_mach_m6812_default 0
31108 +#define bfd_mach_m6812         1
31109 +#define bfd_mach_m6812s        2
31110 +  bfd_arch_z8k,       /* Zilog Z8000 */
31111 +#define bfd_mach_z8001         1
31112 +#define bfd_mach_z8002         2
31113 +  bfd_arch_h8500,     /* Renesas H8/500 (formerly Hitachi H8/500) */
31114 +  bfd_arch_sh,        /* Renesas / SuperH SH (formerly Hitachi SH) */
31115 +#define bfd_mach_sh            1
31116 +#define bfd_mach_sh2        0x20
31117 +#define bfd_mach_sh_dsp     0x2d
31118 +#define bfd_mach_sh2a       0x2a
31119 +#define bfd_mach_sh2a_nofpu 0x2b
31120 +#define bfd_mach_sh2a_nofpu_or_sh4_nommu_nofpu 0x2a1
31121 +#define bfd_mach_sh2a_nofpu_or_sh3_nommu 0x2a2
31122 +#define bfd_mach_sh2a_or_sh4  0x2a3
31123 +#define bfd_mach_sh2a_or_sh3e 0x2a4
31124 +#define bfd_mach_sh2e       0x2e
31125 +#define bfd_mach_sh3        0x30
31126 +#define bfd_mach_sh3_nommu  0x31
31127 +#define bfd_mach_sh3_dsp    0x3d
31128 +#define bfd_mach_sh3e       0x3e
31129 +#define bfd_mach_sh4        0x40
31130 +#define bfd_mach_sh4_nofpu  0x41
31131 +#define bfd_mach_sh4_nommu_nofpu  0x42
31132 +#define bfd_mach_sh4a       0x4a
31133 +#define bfd_mach_sh4a_nofpu 0x4b
31134 +#define bfd_mach_sh4al_dsp  0x4d
31135 +#define bfd_mach_sh5        0x50
31136 +  bfd_arch_alpha,     /* Dec Alpha */
31137 +#define bfd_mach_alpha_ev4  0x10
31138 +#define bfd_mach_alpha_ev5  0x20
31139 +#define bfd_mach_alpha_ev6  0x30
31140 +  bfd_arch_arm,       /* Advanced Risc Machines ARM.  */
31141 +#define bfd_mach_arm_unknown   0
31142 +#define bfd_mach_arm_2         1
31143 +#define bfd_mach_arm_2a        2
31144 +#define bfd_mach_arm_3         3
31145 +#define bfd_mach_arm_3M        4
31146 +#define bfd_mach_arm_4         5
31147 +#define bfd_mach_arm_4T        6
31148 +#define bfd_mach_arm_5         7
31149 +#define bfd_mach_arm_5T        8
31150 +#define bfd_mach_arm_5TE       9
31151 +#define bfd_mach_arm_XScale    10
31152 +#define bfd_mach_arm_ep9312    11
31153 +#define bfd_mach_arm_iWMMXt    12
31154 +  bfd_arch_ns32k,     /* National Semiconductors ns32000 */
31155 +  bfd_arch_w65,       /* WDC 65816 */
31156 +  bfd_arch_tic30,     /* Texas Instruments TMS320C30 */
31157 +  bfd_arch_tic4x,     /* Texas Instruments TMS320C3X/4X */
31158 +#define bfd_mach_tic3x         30
31159 +#define bfd_mach_tic4x         40
31160 +  bfd_arch_tic54x,    /* Texas Instruments TMS320C54X */
31161 +  bfd_arch_tic80,     /* TI TMS320c80 (MVP) */
31162 +  bfd_arch_v850,      /* NEC V850 */
31163 +#define bfd_mach_v850          1
31164 +#define bfd_mach_v850e         'E'
31165 +#define bfd_mach_v850e1        '1'
31166 +  bfd_arch_arc,       /* ARC Cores */
31167 +#define bfd_mach_arc_5         5
31168 +#define bfd_mach_arc_6         6
31169 +#define bfd_mach_arc_7         7
31170 +#define bfd_mach_arc_8         8
31171 + bfd_arch_m32c,     /* Renesas M16C/M32C.  */
31172 +#define bfd_mach_m16c        0x75
31173 +#define bfd_mach_m32c        0x78
31174 +  bfd_arch_m32r,      /* Renesas M32R (formerly Mitsubishi M32R/D) */
31175 +#define bfd_mach_m32r          1 /* For backwards compatibility.  */
31176 +#define bfd_mach_m32rx         'x'
31177 +#define bfd_mach_m32r2         '2'
31178 +  bfd_arch_mn10200,   /* Matsushita MN10200 */
31179 +  bfd_arch_mn10300,   /* Matsushita MN10300 */
31180 +#define bfd_mach_mn10300               300
31181 +#define bfd_mach_am33          330
31182 +#define bfd_mach_am33_2        332
31183 +  bfd_arch_fr30,
31184 +#define bfd_mach_fr30          0x46523330
31185 +  bfd_arch_frv,
31186 +#define bfd_mach_frv           1
31187 +#define bfd_mach_frvsimple     2
31188 +#define bfd_mach_fr300         300
31189 +#define bfd_mach_fr400         400
31190 +#define bfd_mach_fr450         450
31191 +#define bfd_mach_frvtomcat     499     /* fr500 prototype */
31192 +#define bfd_mach_fr500         500
31193 +#define bfd_mach_fr550         550
31194 +  bfd_arch_mcore,
31195 +  bfd_arch_ia64,      /* HP/Intel ia64 */
31196 +#define bfd_mach_ia64_elf64    64
31197 +#define bfd_mach_ia64_elf32    32
31198 +  bfd_arch_ip2k,      /* Ubicom IP2K microcontrollers. */
31199 +#define bfd_mach_ip2022        1
31200 +#define bfd_mach_ip2022ext     2
31201 + bfd_arch_iq2000,     /* Vitesse IQ2000.  */
31202 +#define bfd_mach_iq2000        1
31203 +#define bfd_mach_iq10          2
31204 +  bfd_arch_ms1,
31205 +#define bfd_mach_ms1           1
31206 +#define bfd_mach_mrisc2        2
31207 +  bfd_arch_pj,
31208 +  bfd_arch_avr,       /* Atmel AVR microcontrollers.  */
31209 +#define bfd_mach_avr1          1
31210 +#define bfd_mach_avr2          2
31211 +#define bfd_mach_avr3          3
31212 +#define bfd_mach_avr4          4
31213 +#define bfd_mach_avr5          5
31214 +  bfd_arch_cr16c,       /* National Semiconductor CompactRISC. */
31215 +#define bfd_mach_cr16c         1
31216 +  bfd_arch_crx,       /*  National Semiconductor CRX.  */
31217 +#define bfd_mach_crx           1
31218 +  bfd_arch_cris,      /* Axis CRIS */
31219 +#define bfd_mach_cris_v0_v10   255
31220 +#define bfd_mach_cris_v32      32
31221 +#define bfd_mach_cris_v10_v32  1032
31222 +  bfd_arch_s390,      /* IBM s390 */
31223 +#define bfd_mach_s390_31       31
31224 +#define bfd_mach_s390_64       64
31225 +  bfd_arch_openrisc,  /* OpenRISC */
31226 +  bfd_arch_mmix,      /* Donald Knuth's educational processor.  */
31227 +  bfd_arch_xstormy16,
31228 +#define bfd_mach_xstormy16     1
31229 +  bfd_arch_msp430,    /* Texas Instruments MSP430 architecture.  */
31230 +#define bfd_mach_msp11          11
31231 +#define bfd_mach_msp110         110
31232 +#define bfd_mach_msp12          12
31233 +#define bfd_mach_msp13          13
31234 +#define bfd_mach_msp14          14
31235 +#define bfd_mach_msp15          15
31236 +#define bfd_mach_msp16          16
31237 +#define bfd_mach_msp31          31
31238 +#define bfd_mach_msp32          32
31239 +#define bfd_mach_msp33          33
31240 +#define bfd_mach_msp41          41
31241 +#define bfd_mach_msp42          42
31242 +#define bfd_mach_msp43          43
31243 +#define bfd_mach_msp44          44
31244 +  bfd_arch_xtensa,    /* Tensilica's Xtensa cores.  */
31245 +#define bfd_mach_xtensa        1
31246 +   bfd_arch_maxq,     /* Dallas MAXQ 10/20 */
31247 +#define bfd_mach_maxq10    10
31248 +#define bfd_mach_maxq20    20
31249 +  bfd_arch_last
31250 +  };
31251 +
31252 +typedef struct bfd_arch_info
31253 +{
31254 +  int bits_per_word;
31255 +  int bits_per_address;
31256 +  int bits_per_byte;
31257 +  enum bfd_architecture arch;
31258 +  unsigned long mach;
31259 +  const char *arch_name;
31260 +  const char *printable_name;
31261 +  unsigned int section_align_power;
31262 +  /* TRUE if this is the default machine for the architecture.
31263 +     The default arch should be the first entry for an arch so that
31264 +     all the entries for that arch can be accessed via <<next>>.  */
31265 +  bfd_boolean the_default;
31266 +  const struct bfd_arch_info * (*compatible)
31267 +    (const struct bfd_arch_info *a, const struct bfd_arch_info *b);
31268 +
31269 +  bfd_boolean (*scan) (const struct bfd_arch_info *, const char *);
31270 +
31271 +  const struct bfd_arch_info *next;
31272 +}
31273 +bfd_arch_info_type;
31274 +
31275 +const char *bfd_printable_name (bfd *abfd);
31276 +
31277 +const bfd_arch_info_type *bfd_scan_arch (const char *string);
31278 +
31279 +const char **bfd_arch_list (void);
31280 +
31281 +const bfd_arch_info_type *bfd_arch_get_compatible
31282 +   (const bfd *abfd, const bfd *bbfd, bfd_boolean accept_unknowns);
31283 +
31284 +void bfd_set_arch_info (bfd *abfd, const bfd_arch_info_type *arg);
31285 +
31286 +enum bfd_architecture bfd_get_arch (bfd *abfd);
31287 +
31288 +unsigned long bfd_get_mach (bfd *abfd);
31289 +
31290 +unsigned int bfd_arch_bits_per_byte (bfd *abfd);
31291 +
31292 +unsigned int bfd_arch_bits_per_address (bfd *abfd);
31293 +
31294 +const bfd_arch_info_type *bfd_get_arch_info (bfd *abfd);
31295 +
31296 +const bfd_arch_info_type *bfd_lookup_arch
31297 +   (enum bfd_architecture arch, unsigned long machine);
31298 +
31299 +const char *bfd_printable_arch_mach
31300 +   (enum bfd_architecture arch, unsigned long machine);
31301 +
31302 +unsigned int bfd_octets_per_byte (bfd *abfd);
31303 +
31304 +unsigned int bfd_arch_mach_octets_per_byte
31305 +   (enum bfd_architecture arch, unsigned long machine);
31306 +
31307 +/* Extracted from reloc.c.  */
31308 +typedef enum bfd_reloc_status
31309 +{
31310 +  /* No errors detected.  */
31311 +  bfd_reloc_ok,
31312 +
31313 +  /* The relocation was performed, but there was an overflow.  */
31314 +  bfd_reloc_overflow,
31315 +
31316 +  /* The address to relocate was not within the section supplied.  */
31317 +  bfd_reloc_outofrange,
31318 +
31319 +  /* Used by special functions.  */
31320 +  bfd_reloc_continue,
31321 +
31322 +  /* Unsupported relocation size requested.  */
31323 +  bfd_reloc_notsupported,
31324 +
31325 +  /* Unused.  */
31326 +  bfd_reloc_other,
31327 +
31328 +  /* The symbol to relocate against was undefined.  */
31329 +  bfd_reloc_undefined,
31330 +
31331 +  /* The relocation was performed, but may not be ok - presently
31332 +     generated only when linking i960 coff files with i960 b.out
31333 +     symbols.  If this type is returned, the error_message argument
31334 +     to bfd_perform_relocation will be set.  */
31335 +  bfd_reloc_dangerous
31336 + }
31337 + bfd_reloc_status_type;
31338 +
31339 +
31340 +typedef struct reloc_cache_entry
31341 +{
31342 +  /* A pointer into the canonical table of pointers.  */
31343 +  struct bfd_symbol **sym_ptr_ptr;
31344 +
31345 +  /* offset in section.  */
31346 +  bfd_size_type address;
31347 +
31348 +  /* addend for relocation value.  */
31349 +  bfd_vma addend;
31350 +
31351 +  /* Pointer to how to perform the required relocation.  */
31352 +  reloc_howto_type *howto;
31353 +
31354 +}
31355 +arelent;
31356 +
31357 +enum complain_overflow
31358 +{
31359 +  /* Do not complain on overflow.  */
31360 +  complain_overflow_dont,
31361 +
31362 +  /* Complain if the bitfield overflows, whether it is considered
31363 +     as signed or unsigned.  */
31364 +  complain_overflow_bitfield,
31365 +
31366 +  /* Complain if the value overflows when considered as signed
31367 +     number.  */
31368 +  complain_overflow_signed,
31369 +
31370 +  /* Complain if the value overflows when considered as an
31371 +     unsigned number.  */
31372 +  complain_overflow_unsigned
31373 +};
31374 +
31375 +struct reloc_howto_struct
31376 +{
31377 +  /*  The type field has mainly a documentary use - the back end can
31378 +      do what it wants with it, though normally the back end's
31379 +      external idea of what a reloc number is stored
31380 +      in this field.  For example, a PC relative word relocation
31381 +      in a coff environment has the type 023 - because that's
31382 +      what the outside world calls a R_PCRWORD reloc.  */
31383 +  unsigned int type;
31384 +
31385 +  /*  The value the final relocation is shifted right by.  This drops
31386 +      unwanted data from the relocation.  */
31387 +  unsigned int rightshift;
31388 +
31389 +  /*  The size of the item to be relocated.  This is *not* a
31390 +      power-of-two measure.  To get the number of bytes operated
31391 +      on by a type of relocation, use bfd_get_reloc_size.  */
31392 +  int size;
31393 +
31394 +  /*  The number of bits in the item to be relocated.  This is used
31395 +      when doing overflow checking.  */
31396 +  unsigned int bitsize;
31397 +
31398 +  /*  Notes that the relocation is relative to the location in the
31399 +      data section of the addend.  The relocation function will
31400 +      subtract from the relocation value the address of the location
31401 +      being relocated.  */
31402 +  bfd_boolean pc_relative;
31403 +
31404 +  /*  The bit position of the reloc value in the destination.
31405 +      The relocated value is left shifted by this amount.  */
31406 +  unsigned int bitpos;
31407 +
31408 +  /* What type of overflow error should be checked for when
31409 +     relocating.  */
31410 +  enum complain_overflow complain_on_overflow;
31411 +
31412 +  /* If this field is non null, then the supplied function is
31413 +     called rather than the normal function.  This allows really
31414 +     strange relocation methods to be accommodated (e.g., i960 callj
31415 +     instructions).  */
31416 +  bfd_reloc_status_type (*special_function)
31417 +    (bfd *, arelent *, struct bfd_symbol *, void *, asection *,
31418 +     bfd *, char **);
31419 +
31420 +  /* The textual name of the relocation type.  */
31421 +  char *name;
31422 +
31423 +  /* Some formats record a relocation addend in the section contents
31424 +     rather than with the relocation.  For ELF formats this is the
31425 +     distinction between USE_REL and USE_RELA (though the code checks
31426 +     for USE_REL == 1/0).  The value of this field is TRUE if the
31427 +     addend is recorded with the section contents; when performing a
31428 +     partial link (ld -r) the section contents (the data) will be
31429 +     modified.  The value of this field is FALSE if addends are
31430 +     recorded with the relocation (in arelent.addend); when performing
31431 +     a partial link the relocation will be modified.
31432 +     All relocations for all ELF USE_RELA targets should set this field
31433 +     to FALSE (values of TRUE should be looked on with suspicion).
31434 +     However, the converse is not true: not all relocations of all ELF
31435 +     USE_REL targets set this field to TRUE.  Why this is so is peculiar
31436 +     to each particular target.  For relocs that aren't used in partial
31437 +     links (e.g. GOT stuff) it doesn't matter what this is set to.  */
31438 +  bfd_boolean partial_inplace;
31439 +
31440 +  /* src_mask selects the part of the instruction (or data) to be used
31441 +     in the relocation sum.  If the target relocations don't have an
31442 +     addend in the reloc, eg. ELF USE_REL, src_mask will normally equal
31443 +     dst_mask to extract the addend from the section contents.  If
31444 +     relocations do have an addend in the reloc, eg. ELF USE_RELA, this
31445 +     field should be zero.  Non-zero values for ELF USE_RELA targets are
31446 +     bogus as in those cases the value in the dst_mask part of the
31447 +     section contents should be treated as garbage.  */
31448 +  bfd_vma src_mask;
31449 +
31450 +  /* dst_mask selects which parts of the instruction (or data) are
31451 +     replaced with a relocated value.  */
31452 +  bfd_vma dst_mask;
31453 +
31454 +  /* When some formats create PC relative instructions, they leave
31455 +     the value of the pc of the place being relocated in the offset
31456 +     slot of the instruction, so that a PC relative relocation can
31457 +     be made just by adding in an ordinary offset (e.g., sun3 a.out).
31458 +     Some formats leave the displacement part of an instruction
31459 +     empty (e.g., m88k bcs); this flag signals the fact.  */
31460 +  bfd_boolean pcrel_offset;
31461 +};
31462 +
31463 +#define HOWTO(C, R, S, B, P, BI, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC) \
31464 +  { (unsigned) C, R, S, B, P, BI, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC }
31465 +#define NEWHOWTO(FUNCTION, NAME, SIZE, REL, IN) \
31466 +  HOWTO (0, 0, SIZE, 0, REL, 0, complain_overflow_dont, FUNCTION, \
31467 +         NAME, FALSE, 0, 0, IN)
31468 +
31469 +#define EMPTY_HOWTO(C) \
31470 +  HOWTO ((C), 0, 0, 0, FALSE, 0, complain_overflow_dont, NULL, \
31471 +         NULL, FALSE, 0, 0, FALSE)
31472 +
31473 +#define HOWTO_PREPARE(relocation, symbol)               \
31474 +  {                                                     \
31475 +    if (symbol != NULL)                                 \
31476 +      {                                                 \
31477 +        if (bfd_is_com_section (symbol->section))       \
31478 +          {                                             \
31479 +            relocation = 0;                             \
31480 +          }                                             \
31481 +        else                                            \
31482 +          {                                             \
31483 +            relocation = symbol->value;                 \
31484 +          }                                             \
31485 +      }                                                 \
31486 +  }
31487 +
31488 +unsigned int bfd_get_reloc_size (reloc_howto_type *);
31489 +
31490 +typedef struct relent_chain
31491 +{
31492 +  arelent relent;
31493 +  struct relent_chain *next;
31494 +}
31495 +arelent_chain;
31496 +
31497 +bfd_reloc_status_type bfd_check_overflow
31498 +   (enum complain_overflow how,
31499 +    unsigned int bitsize,
31500 +    unsigned int rightshift,
31501 +    unsigned int addrsize,
31502 +    bfd_vma relocation);
31503 +
31504 +bfd_reloc_status_type bfd_perform_relocation
31505 +   (bfd *abfd,
31506 +    arelent *reloc_entry,
31507 +    void *data,
31508 +    asection *input_section,
31509 +    bfd *output_bfd,
31510 +    char **error_message);
31511 +
31512 +bfd_reloc_status_type bfd_install_relocation
31513 +   (bfd *abfd,
31514 +    arelent *reloc_entry,
31515 +    void *data, bfd_vma data_start,
31516 +    asection *input_section,
31517 +    char **error_message);
31518 +
31519 +enum bfd_reloc_code_real {
31520 +  _dummy_first_bfd_reloc_code_real,
31521 +
31522 +
31523 +/* Basic absolute relocations of N bits.  */
31524 +  BFD_RELOC_64,
31525 +  BFD_RELOC_32,
31526 +  BFD_RELOC_26,
31527 +  BFD_RELOC_24,
31528 +  BFD_RELOC_16,
31529 +  BFD_RELOC_14,
31530 +  BFD_RELOC_8,
31531 +
31532 +/* PC-relative relocations.  Sometimes these are relative to the address
31533 +of the relocation itself; sometimes they are relative to the start of
31534 +the section containing the relocation.  It depends on the specific target.
31535 +
31536 +The 24-bit relocation is used in some Intel 960 configurations.  */
31537 +  BFD_RELOC_64_PCREL,
31538 +  BFD_RELOC_32_PCREL,
31539 +  BFD_RELOC_24_PCREL,
31540 +  BFD_RELOC_16_PCREL,
31541 +  BFD_RELOC_12_PCREL,
31542 +  BFD_RELOC_8_PCREL,
31543 +
31544 +/* Section relative relocations.  Some targets need this for DWARF2.  */
31545 +  BFD_RELOC_32_SECREL,
31546 +
31547 +/* For ELF.  */
31548 +  BFD_RELOC_32_GOT_PCREL,
31549 +  BFD_RELOC_16_GOT_PCREL,
31550 +  BFD_RELOC_8_GOT_PCREL,
31551 +  BFD_RELOC_32_GOTOFF,
31552 +  BFD_RELOC_16_GOTOFF,
31553 +  BFD_RELOC_LO16_GOTOFF,
31554 +  BFD_RELOC_HI16_GOTOFF,
31555 +  BFD_RELOC_HI16_S_GOTOFF,
31556 +  BFD_RELOC_8_GOTOFF,
31557 +  BFD_RELOC_64_PLT_PCREL,
31558 +  BFD_RELOC_32_PLT_PCREL,
31559 +  BFD_RELOC_24_PLT_PCREL,
31560 +  BFD_RELOC_16_PLT_PCREL,
31561 +  BFD_RELOC_8_PLT_PCREL,
31562 +  BFD_RELOC_64_PLTOFF,
31563 +  BFD_RELOC_32_PLTOFF,
31564 +  BFD_RELOC_16_PLTOFF,
31565 +  BFD_RELOC_LO16_PLTOFF,
31566 +  BFD_RELOC_HI16_PLTOFF,
31567 +  BFD_RELOC_HI16_S_PLTOFF,
31568 +  BFD_RELOC_8_PLTOFF,
31569 +
31570 +/* Relocations used by 68K ELF.  */
31571 +  BFD_RELOC_68K_GLOB_DAT,
31572 +  BFD_RELOC_68K_JMP_SLOT,
31573 +  BFD_RELOC_68K_RELATIVE,
31574 +
31575 +/* Linkage-table relative.  */
31576 +  BFD_RELOC_32_BASEREL,
31577 +  BFD_RELOC_16_BASEREL,
31578 +  BFD_RELOC_LO16_BASEREL,
31579 +  BFD_RELOC_HI16_BASEREL,
31580 +  BFD_RELOC_HI16_S_BASEREL,
31581 +  BFD_RELOC_8_BASEREL,
31582 +  BFD_RELOC_RVA,
31583 +
31584 +/* Absolute 8-bit relocation, but used to form an address like 0xFFnn.  */
31585 +  BFD_RELOC_8_FFnn,
31586 +
31587 +/* These PC-relative relocations are stored as word displacements --
31588 +i.e., byte displacements shifted right two bits.  The 30-bit word
31589 +displacement (<<32_PCREL_S2>> -- 32 bits, shifted 2) is used on the
31590 +SPARC.  (SPARC tools generally refer to this as <<WDISP30>>.)  The
31591 +signed 16-bit displacement is used on the MIPS, and the 23-bit
31592 +displacement is used on the Alpha.  */
31593 +  BFD_RELOC_32_PCREL_S2,
31594 +  BFD_RELOC_16_PCREL_S2,
31595 +  BFD_RELOC_23_PCREL_S2,
31596 +
31597 +/* High 22 bits and low 10 bits of 32-bit value, placed into lower bits of
31598 +the target word.  These are used on the SPARC.  */
31599 +  BFD_RELOC_HI22,
31600 +  BFD_RELOC_LO10,
31601 +
31602 +/* For systems that allocate a Global Pointer register, these are
31603 +displacements off that register.  These relocation types are
31604 +handled specially, because the value the register will have is
31605 +decided relatively late.  */
31606 +  BFD_RELOC_GPREL16,
31607 +  BFD_RELOC_GPREL32,
31608 +
31609 +/* Reloc types used for i960/b.out.  */
31610 +  BFD_RELOC_I960_CALLJ,
31611 +
31612 +/* SPARC ELF relocations.  There is probably some overlap with other
31613 +relocation types already defined.  */
31614 +  BFD_RELOC_NONE,
31615 +  BFD_RELOC_SPARC_WDISP22,
31616 +  BFD_RELOC_SPARC22,
31617 +  BFD_RELOC_SPARC13,
31618 +  BFD_RELOC_SPARC_GOT10,
31619 +  BFD_RELOC_SPARC_GOT13,
31620 +  BFD_RELOC_SPARC_GOT22,
31621 +  BFD_RELOC_SPARC_PC10,
31622 +  BFD_RELOC_SPARC_PC22,
31623 +  BFD_RELOC_SPARC_WPLT30,
31624 +  BFD_RELOC_SPARC_COPY,
31625 +  BFD_RELOC_SPARC_GLOB_DAT,
31626 +  BFD_RELOC_SPARC_JMP_SLOT,
31627 +  BFD_RELOC_SPARC_RELATIVE,
31628 +  BFD_RELOC_SPARC_UA16,
31629 +  BFD_RELOC_SPARC_UA32,
31630 +  BFD_RELOC_SPARC_UA64,
31631 +
31632 +/* I think these are specific to SPARC a.out (e.g., Sun 4).  */
31633 +  BFD_RELOC_SPARC_BASE13,
31634 +  BFD_RELOC_SPARC_BASE22,
31635 +
31636 +/* SPARC64 relocations  */
31637 +#define BFD_RELOC_SPARC_64 BFD_RELOC_64
31638 +  BFD_RELOC_SPARC_10,
31639 +  BFD_RELOC_SPARC_11,
31640 +  BFD_RELOC_SPARC_OLO10,
31641 +  BFD_RELOC_SPARC_HH22,
31642 +  BFD_RELOC_SPARC_HM10,
31643 +  BFD_RELOC_SPARC_LM22,
31644 +  BFD_RELOC_SPARC_PC_HH22,
31645 +  BFD_RELOC_SPARC_PC_HM10,
31646 +  BFD_RELOC_SPARC_PC_LM22,
31647 +  BFD_RELOC_SPARC_WDISP16,
31648 +  BFD_RELOC_SPARC_WDISP19,
31649 +  BFD_RELOC_SPARC_7,
31650 +  BFD_RELOC_SPARC_6,
31651 +  BFD_RELOC_SPARC_5,
31652 +#define BFD_RELOC_SPARC_DISP64 BFD_RELOC_64_PCREL
31653 +  BFD_RELOC_SPARC_PLT32,
31654 +  BFD_RELOC_SPARC_PLT64,
31655 +  BFD_RELOC_SPARC_HIX22,
31656 +  BFD_RELOC_SPARC_LOX10,
31657 +  BFD_RELOC_SPARC_H44,
31658 +  BFD_RELOC_SPARC_M44,
31659 +  BFD_RELOC_SPARC_L44,
31660 +  BFD_RELOC_SPARC_REGISTER,
31661 +
31662 +/* SPARC little endian relocation  */
31663 +  BFD_RELOC_SPARC_REV32,
31664 +
31665 +/* SPARC TLS relocations  */
31666 +  BFD_RELOC_SPARC_TLS_GD_HI22,
31667 +  BFD_RELOC_SPARC_TLS_GD_LO10,
31668 +  BFD_RELOC_SPARC_TLS_GD_ADD,
31669 +  BFD_RELOC_SPARC_TLS_GD_CALL,
31670 +  BFD_RELOC_SPARC_TLS_LDM_HI22,
31671 +  BFD_RELOC_SPARC_TLS_LDM_LO10,
31672 +  BFD_RELOC_SPARC_TLS_LDM_ADD,
31673 +  BFD_RELOC_SPARC_TLS_LDM_CALL,
31674 +  BFD_RELOC_SPARC_TLS_LDO_HIX22,
31675 +  BFD_RELOC_SPARC_TLS_LDO_LOX10,
31676 +  BFD_RELOC_SPARC_TLS_LDO_ADD,
31677 +  BFD_RELOC_SPARC_TLS_IE_HI22,
31678 +  BFD_RELOC_SPARC_TLS_IE_LO10,
31679 +  BFD_RELOC_SPARC_TLS_IE_LD,
31680 +  BFD_RELOC_SPARC_TLS_IE_LDX,
31681 +  BFD_RELOC_SPARC_TLS_IE_ADD,
31682 +  BFD_RELOC_SPARC_TLS_LE_HIX22,
31683 +  BFD_RELOC_SPARC_TLS_LE_LOX10,
31684 +  BFD_RELOC_SPARC_TLS_DTPMOD32,
31685 +  BFD_RELOC_SPARC_TLS_DTPMOD64,
31686 +  BFD_RELOC_SPARC_TLS_DTPOFF32,
31687 +  BFD_RELOC_SPARC_TLS_DTPOFF64,
31688 +  BFD_RELOC_SPARC_TLS_TPOFF32,
31689 +  BFD_RELOC_SPARC_TLS_TPOFF64,
31690 +
31691 +/* Alpha ECOFF and ELF relocations.  Some of these treat the symbol or
31692 +"addend" in some special way.
31693 +For GPDISP_HI16 ("gpdisp") relocations, the symbol is ignored when
31694 +writing; when reading, it will be the absolute section symbol.  The
31695 +addend is the displacement in bytes of the "lda" instruction from
31696 +the "ldah" instruction (which is at the address of this reloc).  */
31697 +  BFD_RELOC_ALPHA_GPDISP_HI16,
31698 +
31699 +/* For GPDISP_LO16 ("ignore") relocations, the symbol is handled as
31700 +with GPDISP_HI16 relocs.  The addend is ignored when writing the
31701 +relocations out, and is filled in with the file's GP value on
31702 +reading, for convenience.  */
31703 +  BFD_RELOC_ALPHA_GPDISP_LO16,
31704 +
31705 +/* The ELF GPDISP relocation is exactly the same as the GPDISP_HI16
31706 +relocation except that there is no accompanying GPDISP_LO16
31707 +relocation.  */
31708 +  BFD_RELOC_ALPHA_GPDISP,
31709 +
31710 +/* The Alpha LITERAL/LITUSE relocs are produced by a symbol reference;
31711 +the assembler turns it into a LDQ instruction to load the address of
31712 +the symbol, and then fills in a register in the real instruction.
31713 +
31714 +The LITERAL reloc, at the LDQ instruction, refers to the .lita
31715 +section symbol.  The addend is ignored when writing, but is filled
31716 +in with the file's GP value on reading, for convenience, as with the
31717 +GPDISP_LO16 reloc.
31718 +
31719 +The ELF_LITERAL reloc is somewhere between 16_GOTOFF and GPDISP_LO16.
31720 +It should refer to the symbol to be referenced, as with 16_GOTOFF,
31721 +but it generates output not based on the position within the .got
31722 +section, but relative to the GP value chosen for the file during the
31723 +final link stage.
31724 +
31725 +The LITUSE reloc, on the instruction using the loaded address, gives
31726 +information to the linker that it might be able to use to optimize
31727 +away some literal section references.  The symbol is ignored (read
31728 +as the absolute section symbol), and the "addend" indicates the type
31729 +of instruction using the register:
31730 +1 - "memory" fmt insn
31731 +2 - byte-manipulation (byte offset reg)
31732 +3 - jsr (target of branch)  */
31733 +  BFD_RELOC_ALPHA_LITERAL,
31734 +  BFD_RELOC_ALPHA_ELF_LITERAL,
31735 +  BFD_RELOC_ALPHA_LITUSE,
31736 +
31737 +/* The HINT relocation indicates a value that should be filled into the
31738 +"hint" field of a jmp/jsr/ret instruction, for possible branch-
31739 +prediction logic which may be provided on some processors.  */
31740 +  BFD_RELOC_ALPHA_HINT,
31741 +
31742 +/* The LINKAGE relocation outputs a linkage pair in the object file,
31743 +which is filled by the linker.  */
31744 +  BFD_RELOC_ALPHA_LINKAGE,
31745 +
31746 +/* The CODEADDR relocation outputs a STO_CA in the object file,
31747 +which is filled by the linker.  */
31748 +  BFD_RELOC_ALPHA_CODEADDR,
31749 +
31750 +/* The GPREL_HI/LO relocations together form a 32-bit offset from the
31751 +GP register.  */
31752 +  BFD_RELOC_ALPHA_GPREL_HI16,
31753 +  BFD_RELOC_ALPHA_GPREL_LO16,
31754 +
31755 +/* Like BFD_RELOC_23_PCREL_S2, except that the source and target must
31756 +share a common GP, and the target address is adjusted for
31757 +STO_ALPHA_STD_GPLOAD.  */
31758 +  BFD_RELOC_ALPHA_BRSGP,
31759 +
31760 +/* Alpha thread-local storage relocations.  */
31761 +  BFD_RELOC_ALPHA_TLSGD,
31762 +  BFD_RELOC_ALPHA_TLSLDM,
31763 +  BFD_RELOC_ALPHA_DTPMOD64,
31764 +  BFD_RELOC_ALPHA_GOTDTPREL16,
31765 +  BFD_RELOC_ALPHA_DTPREL64,
31766 +  BFD_RELOC_ALPHA_DTPREL_HI16,
31767 +  BFD_RELOC_ALPHA_DTPREL_LO16,
31768 +  BFD_RELOC_ALPHA_DTPREL16,
31769 +  BFD_RELOC_ALPHA_GOTTPREL16,
31770 +  BFD_RELOC_ALPHA_TPREL64,
31771 +  BFD_RELOC_ALPHA_TPREL_HI16,
31772 +  BFD_RELOC_ALPHA_TPREL_LO16,
31773 +  BFD_RELOC_ALPHA_TPREL16,
31774 +
31775 +/* Bits 27..2 of the relocation address shifted right 2 bits;
31776 +simple reloc otherwise.  */
31777 +  BFD_RELOC_MIPS_JMP,
31778 +
31779 +/* The MIPS16 jump instruction.  */
31780 +  BFD_RELOC_MIPS16_JMP,
31781 +
31782 +/* MIPS16 GP relative reloc.  */
31783 +  BFD_RELOC_MIPS16_GPREL,
31784 +
31785 +/* High 16 bits of 32-bit value; simple reloc.  */
31786 +  BFD_RELOC_HI16,
31787 +
31788 +/* High 16 bits of 32-bit value but the low 16 bits will be sign
31789 +extended and added to form the final result.  If the low 16
31790 +bits form a negative number, we need to add one to the high value
31791 +to compensate for the borrow when the low bits are added.  */
31792 +  BFD_RELOC_HI16_S,
31793 +
31794 +/* Low 16 bits.  */
31795 +  BFD_RELOC_LO16,
31796 +
31797 +/* High 16 bits of 32-bit pc-relative value  */
31798 +  BFD_RELOC_HI16_PCREL,
31799 +
31800 +/* High 16 bits of 32-bit pc-relative value, adjusted  */
31801 +  BFD_RELOC_HI16_S_PCREL,
31802 +
31803 +/* Low 16 bits of pc-relative value  */
31804 +  BFD_RELOC_LO16_PCREL,
31805 +
31806 +/* MIPS16 high 16 bits of 32-bit value.  */
31807 +  BFD_RELOC_MIPS16_HI16,
31808 +
31809 +/* MIPS16 high 16 bits of 32-bit value but the low 16 bits will be sign
31810 +extended and added to form the final result.  If the low 16
31811 +bits form a negative number, we need to add one to the high value
31812 +to compensate for the borrow when the low bits are added.  */
31813 +  BFD_RELOC_MIPS16_HI16_S,
31814 +
31815 +/* MIPS16 low 16 bits.  */
31816 +  BFD_RELOC_MIPS16_LO16,
31817 +
31818 +/* Relocation against a MIPS literal section.  */
31819 +  BFD_RELOC_MIPS_LITERAL,
31820 +
31821 +/* MIPS ELF relocations.  */
31822 +  BFD_RELOC_MIPS_GOT16,
31823 +  BFD_RELOC_MIPS_CALL16,
31824 +  BFD_RELOC_MIPS_GOT_HI16,
31825 +  BFD_RELOC_MIPS_GOT_LO16,
31826 +  BFD_RELOC_MIPS_CALL_HI16,
31827 +  BFD_RELOC_MIPS_CALL_LO16,
31828 +  BFD_RELOC_MIPS_SUB,
31829 +  BFD_RELOC_MIPS_GOT_PAGE,
31830 +  BFD_RELOC_MIPS_GOT_OFST,
31831 +  BFD_RELOC_MIPS_GOT_DISP,
31832 +  BFD_RELOC_MIPS_SHIFT5,
31833 +  BFD_RELOC_MIPS_SHIFT6,
31834 +  BFD_RELOC_MIPS_INSERT_A,
31835 +  BFD_RELOC_MIPS_INSERT_B,
31836 +  BFD_RELOC_MIPS_DELETE,
31837 +  BFD_RELOC_MIPS_HIGHEST,
31838 +  BFD_RELOC_MIPS_HIGHER,
31839 +  BFD_RELOC_MIPS_SCN_DISP,
31840 +  BFD_RELOC_MIPS_REL16,
31841 +  BFD_RELOC_MIPS_RELGOT,
31842 +  BFD_RELOC_MIPS_JALR,
31843 +  BFD_RELOC_MIPS_TLS_DTPMOD32,
31844 +  BFD_RELOC_MIPS_TLS_DTPREL32,
31845 +  BFD_RELOC_MIPS_TLS_DTPMOD64,
31846 +  BFD_RELOC_MIPS_TLS_DTPREL64,
31847 +  BFD_RELOC_MIPS_TLS_GD,
31848 +  BFD_RELOC_MIPS_TLS_LDM,
31849 +  BFD_RELOC_MIPS_TLS_DTPREL_HI16,
31850 +  BFD_RELOC_MIPS_TLS_DTPREL_LO16,
31851 +  BFD_RELOC_MIPS_TLS_GOTTPREL,
31852 +  BFD_RELOC_MIPS_TLS_TPREL32,
31853 +  BFD_RELOC_MIPS_TLS_TPREL64,
31854 +  BFD_RELOC_MIPS_TLS_TPREL_HI16,
31855 +  BFD_RELOC_MIPS_TLS_TPREL_LO16,
31856 +
31857 +
31858 +/* Fujitsu Frv Relocations.  */
31859 +  BFD_RELOC_FRV_LABEL16,
31860 +  BFD_RELOC_FRV_LABEL24,
31861 +  BFD_RELOC_FRV_LO16,
31862 +  BFD_RELOC_FRV_HI16,
31863 +  BFD_RELOC_FRV_GPREL12,
31864 +  BFD_RELOC_FRV_GPRELU12,
31865 +  BFD_RELOC_FRV_GPREL32,
31866 +  BFD_RELOC_FRV_GPRELHI,
31867 +  BFD_RELOC_FRV_GPRELLO,
31868 +  BFD_RELOC_FRV_GOT12,
31869 +  BFD_RELOC_FRV_GOTHI,
31870 +  BFD_RELOC_FRV_GOTLO,
31871 +  BFD_RELOC_FRV_FUNCDESC,
31872 +  BFD_RELOC_FRV_FUNCDESC_GOT12,
31873 +  BFD_RELOC_FRV_FUNCDESC_GOTHI,
31874 +  BFD_RELOC_FRV_FUNCDESC_GOTLO,
31875 +  BFD_RELOC_FRV_FUNCDESC_VALUE,
31876 +  BFD_RELOC_FRV_FUNCDESC_GOTOFF12,
31877 +  BFD_RELOC_FRV_FUNCDESC_GOTOFFHI,
31878 +  BFD_RELOC_FRV_FUNCDESC_GOTOFFLO,
31879 +  BFD_RELOC_FRV_GOTOFF12,
31880 +  BFD_RELOC_FRV_GOTOFFHI,
31881 +  BFD_RELOC_FRV_GOTOFFLO,
31882 +  BFD_RELOC_FRV_GETTLSOFF,
31883 +  BFD_RELOC_FRV_TLSDESC_VALUE,
31884 +  BFD_RELOC_FRV_GOTTLSDESC12,
31885 +  BFD_RELOC_FRV_GOTTLSDESCHI,
31886 +  BFD_RELOC_FRV_GOTTLSDESCLO,
31887 +  BFD_RELOC_FRV_TLSMOFF12,
31888 +  BFD_RELOC_FRV_TLSMOFFHI,
31889 +  BFD_RELOC_FRV_TLSMOFFLO,
31890 +  BFD_RELOC_FRV_GOTTLSOFF12,
31891 +  BFD_RELOC_FRV_GOTTLSOFFHI,
31892 +  BFD_RELOC_FRV_GOTTLSOFFLO,
31893 +  BFD_RELOC_FRV_TLSOFF,
31894 +  BFD_RELOC_FRV_TLSDESC_RELAX,
31895 +  BFD_RELOC_FRV_GETTLSOFF_RELAX,
31896 +  BFD_RELOC_FRV_TLSOFF_RELAX,
31897 +  BFD_RELOC_FRV_TLSMOFF,
31898 +
31899 +
31900 +/* This is a 24bit GOT-relative reloc for the mn10300.  */
31901 +  BFD_RELOC_MN10300_GOTOFF24,
31902 +
31903 +/* This is a 32bit GOT-relative reloc for the mn10300, offset by two bytes
31904 +in the instruction.  */
31905 +  BFD_RELOC_MN10300_GOT32,
31906 +
31907 +/* This is a 24bit GOT-relative reloc for the mn10300, offset by two bytes
31908 +in the instruction.  */
31909 +  BFD_RELOC_MN10300_GOT24,
31910 +
31911 +/* This is a 16bit GOT-relative reloc for the mn10300, offset by two bytes
31912 +in the instruction.  */
31913 +  BFD_RELOC_MN10300_GOT16,
31914 +
31915 +/* Copy symbol at runtime.  */
31916 +  BFD_RELOC_MN10300_COPY,
31917 +
31918 +/* Create GOT entry.  */
31919 +  BFD_RELOC_MN10300_GLOB_DAT,
31920 +
31921 +/* Create PLT entry.  */
31922 +  BFD_RELOC_MN10300_JMP_SLOT,
31923 +
31924 +/* Adjust by program base.  */
31925 +  BFD_RELOC_MN10300_RELATIVE,
31926 +
31927 +
31928 +/* i386/elf relocations  */
31929 +  BFD_RELOC_386_GOT32,
31930 +  BFD_RELOC_386_PLT32,
31931 +  BFD_RELOC_386_COPY,
31932 +  BFD_RELOC_386_GLOB_DAT,
31933 +  BFD_RELOC_386_JUMP_SLOT,
31934 +  BFD_RELOC_386_RELATIVE,
31935 +  BFD_RELOC_386_GOTOFF,
31936 +  BFD_RELOC_386_GOTPC,
31937 +  BFD_RELOC_386_TLS_TPOFF,
31938 +  BFD_RELOC_386_TLS_IE,
31939 +  BFD_RELOC_386_TLS_GOTIE,
31940 +  BFD_RELOC_386_TLS_LE,
31941 +  BFD_RELOC_386_TLS_GD,
31942 +  BFD_RELOC_386_TLS_LDM,
31943 +  BFD_RELOC_386_TLS_LDO_32,
31944 +  BFD_RELOC_386_TLS_IE_32,
31945 +  BFD_RELOC_386_TLS_LE_32,
31946 +  BFD_RELOC_386_TLS_DTPMOD32,
31947 +  BFD_RELOC_386_TLS_DTPOFF32,
31948 +  BFD_RELOC_386_TLS_TPOFF32,
31949 +
31950 +/* x86-64/elf relocations  */
31951 +  BFD_RELOC_X86_64_GOT32,
31952 +  BFD_RELOC_X86_64_PLT32,
31953 +  BFD_RELOC_X86_64_COPY,
31954 +  BFD_RELOC_X86_64_GLOB_DAT,
31955 +  BFD_RELOC_X86_64_JUMP_SLOT,
31956 +  BFD_RELOC_X86_64_RELATIVE,
31957 +  BFD_RELOC_X86_64_GOTPCREL,
31958 +  BFD_RELOC_X86_64_32S,
31959 +  BFD_RELOC_X86_64_DTPMOD64,
31960 +  BFD_RELOC_X86_64_DTPOFF64,
31961 +  BFD_RELOC_X86_64_TPOFF64,
31962 +  BFD_RELOC_X86_64_TLSGD,
31963 +  BFD_RELOC_X86_64_TLSLD,
31964 +  BFD_RELOC_X86_64_DTPOFF32,
31965 +  BFD_RELOC_X86_64_GOTTPOFF,
31966 +  BFD_RELOC_X86_64_TPOFF32,
31967 +  BFD_RELOC_X86_64_GOTOFF64,
31968 +  BFD_RELOC_X86_64_GOTPC32,
31969 +
31970 +/* ns32k relocations  */
31971 +  BFD_RELOC_NS32K_IMM_8,
31972 +  BFD_RELOC_NS32K_IMM_16,
31973 +  BFD_RELOC_NS32K_IMM_32,
31974 +  BFD_RELOC_NS32K_IMM_8_PCREL,
31975 +  BFD_RELOC_NS32K_IMM_16_PCREL,
31976 +  BFD_RELOC_NS32K_IMM_32_PCREL,
31977 +  BFD_RELOC_NS32K_DISP_8,
31978 +  BFD_RELOC_NS32K_DISP_16,
31979 +  BFD_RELOC_NS32K_DISP_32,
31980 +  BFD_RELOC_NS32K_DISP_8_PCREL,
31981 +  BFD_RELOC_NS32K_DISP_16_PCREL,
31982 +  BFD_RELOC_NS32K_DISP_32_PCREL,
31983 +
31984 +/* PDP11 relocations  */
31985 +  BFD_RELOC_PDP11_DISP_8_PCREL,
31986 +  BFD_RELOC_PDP11_DISP_6_PCREL,
31987 +
31988 +/* Picojava relocs.  Not all of these appear in object files.  */
31989 +  BFD_RELOC_PJ_CODE_HI16,
31990 +  BFD_RELOC_PJ_CODE_LO16,
31991 +  BFD_RELOC_PJ_CODE_DIR16,
31992 +  BFD_RELOC_PJ_CODE_DIR32,
31993 +  BFD_RELOC_PJ_CODE_REL16,
31994 +  BFD_RELOC_PJ_CODE_REL32,
31995 +
31996 +/* Power(rs6000) and PowerPC relocations.  */
31997 +  BFD_RELOC_PPC_B26,
31998 +  BFD_RELOC_PPC_BA26,
31999 +  BFD_RELOC_PPC_TOC16,
32000 +  BFD_RELOC_PPC_B16,
32001 +  BFD_RELOC_PPC_B16_BRTAKEN,
32002 +  BFD_RELOC_PPC_B16_BRNTAKEN,
32003 +  BFD_RELOC_PPC_BA16,
32004 +  BFD_RELOC_PPC_BA16_BRTAKEN,
32005 +  BFD_RELOC_PPC_BA16_BRNTAKEN,
32006 +  BFD_RELOC_PPC_COPY,
32007 +  BFD_RELOC_PPC_GLOB_DAT,
32008 +  BFD_RELOC_PPC_JMP_SLOT,
32009 +  BFD_RELOC_PPC_RELATIVE,
32010 +  BFD_RELOC_PPC_LOCAL24PC,
32011 +  BFD_RELOC_PPC_EMB_NADDR32,
32012 +  BFD_RELOC_PPC_EMB_NADDR16,
32013 +  BFD_RELOC_PPC_EMB_NADDR16_LO,
32014 +  BFD_RELOC_PPC_EMB_NADDR16_HI,
32015 +  BFD_RELOC_PPC_EMB_NADDR16_HA,
32016 +  BFD_RELOC_PPC_EMB_SDAI16,
32017 +  BFD_RELOC_PPC_EMB_SDA2I16,
32018 +  BFD_RELOC_PPC_EMB_SDA2REL,
32019 +  BFD_RELOC_PPC_EMB_SDA21,
32020 +  BFD_RELOC_PPC_EMB_MRKREF,
32021 +  BFD_RELOC_PPC_EMB_RELSEC16,
32022 +  BFD_RELOC_PPC_EMB_RELST_LO,
32023 +  BFD_RELOC_PPC_EMB_RELST_HI,
32024 +  BFD_RELOC_PPC_EMB_RELST_HA,
32025 +  BFD_RELOC_PPC_EMB_BIT_FLD,
32026 +  BFD_RELOC_PPC_EMB_RELSDA,
32027 +  BFD_RELOC_PPC64_HIGHER,
32028 +  BFD_RELOC_PPC64_HIGHER_S,
32029 +  BFD_RELOC_PPC64_HIGHEST,
32030 +  BFD_RELOC_PPC64_HIGHEST_S,
32031 +  BFD_RELOC_PPC64_TOC16_LO,
32032 +  BFD_RELOC_PPC64_TOC16_HI,
32033 +  BFD_RELOC_PPC64_TOC16_HA,
32034 +  BFD_RELOC_PPC64_TOC,
32035 +  BFD_RELOC_PPC64_PLTGOT16,
32036 +  BFD_RELOC_PPC64_PLTGOT16_LO,
32037 +  BFD_RELOC_PPC64_PLTGOT16_HI,
32038 +  BFD_RELOC_PPC64_PLTGOT16_HA,
32039 +  BFD_RELOC_PPC64_ADDR16_DS,
32040 +  BFD_RELOC_PPC64_ADDR16_LO_DS,
32041 +  BFD_RELOC_PPC64_GOT16_DS,
32042 +  BFD_RELOC_PPC64_GOT16_LO_DS,
32043 +  BFD_RELOC_PPC64_PLT16_LO_DS,
32044 +  BFD_RELOC_PPC64_SECTOFF_DS,
32045 +  BFD_RELOC_PPC64_SECTOFF_LO_DS,
32046 +  BFD_RELOC_PPC64_TOC16_DS,
32047 +  BFD_RELOC_PPC64_TOC16_LO_DS,
32048 +  BFD_RELOC_PPC64_PLTGOT16_DS,
32049 +  BFD_RELOC_PPC64_PLTGOT16_LO_DS,
32050 +
32051 +/* PowerPC and PowerPC64 thread-local storage relocations.  */
32052 +  BFD_RELOC_PPC_TLS,
32053 +  BFD_RELOC_PPC_DTPMOD,
32054 +  BFD_RELOC_PPC_TPREL16,
32055 +  BFD_RELOC_PPC_TPREL16_LO,
32056 +  BFD_RELOC_PPC_TPREL16_HI,
32057 +  BFD_RELOC_PPC_TPREL16_HA,
32058 +  BFD_RELOC_PPC_TPREL,
32059 +  BFD_RELOC_PPC_DTPREL16,
32060 +  BFD_RELOC_PPC_DTPREL16_LO,
32061 +  BFD_RELOC_PPC_DTPREL16_HI,
32062 +  BFD_RELOC_PPC_DTPREL16_HA,
32063 +  BFD_RELOC_PPC_DTPREL,
32064 +  BFD_RELOC_PPC_GOT_TLSGD16,
32065 +  BFD_RELOC_PPC_GOT_TLSGD16_LO,
32066 +  BFD_RELOC_PPC_GOT_TLSGD16_HI,
32067 +  BFD_RELOC_PPC_GOT_TLSGD16_HA,
32068 +  BFD_RELOC_PPC_GOT_TLSLD16,
32069 +  BFD_RELOC_PPC_GOT_TLSLD16_LO,
32070 +  BFD_RELOC_PPC_GOT_TLSLD16_HI,
32071 +  BFD_RELOC_PPC_GOT_TLSLD16_HA,
32072 +  BFD_RELOC_PPC_GOT_TPREL16,
32073 +  BFD_RELOC_PPC_GOT_TPREL16_LO,
32074 +  BFD_RELOC_PPC_GOT_TPREL16_HI,
32075 +  BFD_RELOC_PPC_GOT_TPREL16_HA,
32076 +  BFD_RELOC_PPC_GOT_DTPREL16,
32077 +  BFD_RELOC_PPC_GOT_DTPREL16_LO,
32078 +  BFD_RELOC_PPC_GOT_DTPREL16_HI,
32079 +  BFD_RELOC_PPC_GOT_DTPREL16_HA,
32080 +  BFD_RELOC_PPC64_TPREL16_DS,
32081 +  BFD_RELOC_PPC64_TPREL16_LO_DS,
32082 +  BFD_RELOC_PPC64_TPREL16_HIGHER,
32083 +  BFD_RELOC_PPC64_TPREL16_HIGHERA,
32084 +  BFD_RELOC_PPC64_TPREL16_HIGHEST,
32085 +  BFD_RELOC_PPC64_TPREL16_HIGHESTA,
32086 +  BFD_RELOC_PPC64_DTPREL16_DS,
32087 +  BFD_RELOC_PPC64_DTPREL16_LO_DS,
32088 +  BFD_RELOC_PPC64_DTPREL16_HIGHER,
32089 +  BFD_RELOC_PPC64_DTPREL16_HIGHERA,
32090 +  BFD_RELOC_PPC64_DTPREL16_HIGHEST,
32091 +  BFD_RELOC_PPC64_DTPREL16_HIGHESTA,
32092 +
32093 +/* IBM 370/390 relocations  */
32094 +  BFD_RELOC_I370_D12,
32095 +
32096 +/* The type of reloc used to build a constructor table - at the moment
32097 +probably a 32 bit wide absolute relocation, but the target can choose.
32098 +It generally does map to one of the other relocation types.  */
32099 +  BFD_RELOC_CTOR,
32100 +
32101 +/* ARM 26 bit pc-relative branch.  The lowest two bits must be zero and are
32102 +not stored in the instruction.  */
32103 +  BFD_RELOC_ARM_PCREL_BRANCH,
32104 +
32105 +/* ARM 26 bit pc-relative branch.  The lowest bit must be zero and is
32106 +not stored in the instruction.  The 2nd lowest bit comes from a 1 bit
32107 +field in the instruction.  */
32108 +  BFD_RELOC_ARM_PCREL_BLX,
32109 +
32110 +/* Thumb 22 bit pc-relative branch.  The lowest bit must be zero and is
32111 +not stored in the instruction.  The 2nd lowest bit comes from a 1 bit
32112 +field in the instruction.  */
32113 +  BFD_RELOC_THUMB_PCREL_BLX,
32114 +
32115 +/* Thumb 7-, 9-, 12-, 20-, 23-, and 25-bit pc-relative branches.
32116 +The lowest bit must be zero and is not stored in the instruction.
32117 +Note that the corresponding ELF R_ARM_THM_JUMPnn constant has an
32118 +"nn" one smaller in all cases.  Note further that BRANCH23
32119 +corresponds to R_ARM_THM_CALL.  */
32120 +  BFD_RELOC_THUMB_PCREL_BRANCH7,
32121 +  BFD_RELOC_THUMB_PCREL_BRANCH9,
32122 +  BFD_RELOC_THUMB_PCREL_BRANCH12,
32123 +  BFD_RELOC_THUMB_PCREL_BRANCH20,
32124 +  BFD_RELOC_THUMB_PCREL_BRANCH23,
32125 +  BFD_RELOC_THUMB_PCREL_BRANCH25,
32126 +
32127 +/* 12-bit immediate offset, used in ARM-format ldr and str instructions.  */
32128 +  BFD_RELOC_ARM_OFFSET_IMM,
32129 +
32130 +/* 5-bit immediate offset, used in Thumb-format ldr and str instructions.  */
32131 +  BFD_RELOC_ARM_THUMB_OFFSET,
32132 +
32133 +/* Pc-relative or absolute relocation depending on target.  Used for
32134 +entries in .init_array sections.  */
32135 +  BFD_RELOC_ARM_TARGET1,
32136 +
32137 +/* Read-only segment base relative address.  */
32138 +  BFD_RELOC_ARM_ROSEGREL32,
32139 +
32140 +/* Data segment base relative address.  */
32141 +  BFD_RELOC_ARM_SBREL32,
32142 +
32143 +/* This reloc is used for references to RTTI data from exception handling
32144 +tables.  The actual definition depends on the target.  It may be a
32145 +pc-relative or some form of GOT-indirect relocation.  */
32146 +  BFD_RELOC_ARM_TARGET2,
32147 +
32148 +/* 31-bit PC relative address.  */
32149 +  BFD_RELOC_ARM_PREL31,
32150 +
32151 +/* Relocations for setting up GOTs and PLTs for shared libraries.  */
32152 +  BFD_RELOC_ARM_JUMP_SLOT,
32153 +  BFD_RELOC_ARM_GLOB_DAT,
32154 +  BFD_RELOC_ARM_GOT32,
32155 +  BFD_RELOC_ARM_PLT32,
32156 +  BFD_RELOC_ARM_RELATIVE,
32157 +  BFD_RELOC_ARM_GOTOFF,
32158 +  BFD_RELOC_ARM_GOTPC,
32159 +
32160 +/* ARM thread-local storage relocations.  */
32161 +  BFD_RELOC_ARM_TLS_GD32,
32162 +  BFD_RELOC_ARM_TLS_LDO32,
32163 +  BFD_RELOC_ARM_TLS_LDM32,
32164 +  BFD_RELOC_ARM_TLS_DTPOFF32,
32165 +  BFD_RELOC_ARM_TLS_DTPMOD32,
32166 +  BFD_RELOC_ARM_TLS_TPOFF32,
32167 +  BFD_RELOC_ARM_TLS_IE32,
32168 +  BFD_RELOC_ARM_TLS_LE32,
32169 +
32170 +/* These relocs are only used within the ARM assembler.  They are not
32171 +(at present) written to any object files.  */
32172 +  BFD_RELOC_ARM_IMMEDIATE,
32173 +  BFD_RELOC_ARM_ADRL_IMMEDIATE,
32174 +  BFD_RELOC_ARM_T32_IMMEDIATE,
32175 +  BFD_RELOC_ARM_SHIFT_IMM,
32176 +  BFD_RELOC_ARM_SMI,
32177 +  BFD_RELOC_ARM_SWI,
32178 +  BFD_RELOC_ARM_MULTI,
32179 +  BFD_RELOC_ARM_CP_OFF_IMM,
32180 +  BFD_RELOC_ARM_CP_OFF_IMM_S2,
32181 +  BFD_RELOC_ARM_ADR_IMM,
32182 +  BFD_RELOC_ARM_LDR_IMM,
32183 +  BFD_RELOC_ARM_LITERAL,
32184 +  BFD_RELOC_ARM_IN_POOL,
32185 +  BFD_RELOC_ARM_OFFSET_IMM8,
32186 +  BFD_RELOC_ARM_T32_OFFSET_U8,
32187 +  BFD_RELOC_ARM_T32_OFFSET_IMM,
32188 +  BFD_RELOC_ARM_HWLITERAL,
32189 +  BFD_RELOC_ARM_THUMB_ADD,
32190 +  BFD_RELOC_ARM_THUMB_IMM,
32191 +  BFD_RELOC_ARM_THUMB_SHIFT,
32192 +
32193 +/* Renesas / SuperH SH relocs.  Not all of these appear in object files.  */
32194 +  BFD_RELOC_SH_PCDISP8BY2,
32195 +  BFD_RELOC_SH_PCDISP12BY2,
32196 +  BFD_RELOC_SH_IMM3,
32197 +  BFD_RELOC_SH_IMM3U,
32198 +  BFD_RELOC_SH_DISP12,
32199 +  BFD_RELOC_SH_DISP12BY2,
32200 +  BFD_RELOC_SH_DISP12BY4,
32201 +  BFD_RELOC_SH_DISP12BY8,
32202 +  BFD_RELOC_SH_DISP20,
32203 +  BFD_RELOC_SH_DISP20BY8,
32204 +  BFD_RELOC_SH_IMM4,
32205 +  BFD_RELOC_SH_IMM4BY2,
32206 +  BFD_RELOC_SH_IMM4BY4,
32207 +  BFD_RELOC_SH_IMM8,
32208 +  BFD_RELOC_SH_IMM8BY2,
32209 +  BFD_RELOC_SH_IMM8BY4,
32210 +  BFD_RELOC_SH_PCRELIMM8BY2,
32211 +  BFD_RELOC_SH_PCRELIMM8BY4,
32212 +  BFD_RELOC_SH_SWITCH16,
32213 +  BFD_RELOC_SH_SWITCH32,
32214 +  BFD_RELOC_SH_USES,
32215 +  BFD_RELOC_SH_COUNT,
32216 +  BFD_RELOC_SH_ALIGN,
32217 +  BFD_RELOC_SH_CODE,
32218 +  BFD_RELOC_SH_DATA,
32219 +  BFD_RELOC_SH_LABEL,
32220 +  BFD_RELOC_SH_LOOP_START,
32221 +  BFD_RELOC_SH_LOOP_END,
32222 +  BFD_RELOC_SH_COPY,
32223 +  BFD_RELOC_SH_GLOB_DAT,
32224 +  BFD_RELOC_SH_JMP_SLOT,
32225 +  BFD_RELOC_SH_RELATIVE,
32226 +  BFD_RELOC_SH_GOTPC,
32227 +  BFD_RELOC_SH_GOT_LOW16,
32228 +  BFD_RELOC_SH_GOT_MEDLOW16,
32229 +  BFD_RELOC_SH_GOT_MEDHI16,
32230 +  BFD_RELOC_SH_GOT_HI16,
32231 +  BFD_RELOC_SH_GOTPLT_LOW16,
32232 +  BFD_RELOC_SH_GOTPLT_MEDLOW16,
32233 +  BFD_RELOC_SH_GOTPLT_MEDHI16,
32234 +  BFD_RELOC_SH_GOTPLT_HI16,
32235 +  BFD_RELOC_SH_PLT_LOW16,
32236 +  BFD_RELOC_SH_PLT_MEDLOW16,
32237 +  BFD_RELOC_SH_PLT_MEDHI16,
32238 +  BFD_RELOC_SH_PLT_HI16,
32239 +  BFD_RELOC_SH_GOTOFF_LOW16,
32240 +  BFD_RELOC_SH_GOTOFF_MEDLOW16,
32241 +  BFD_RELOC_SH_GOTOFF_MEDHI16,
32242 +  BFD_RELOC_SH_GOTOFF_HI16,
32243 +  BFD_RELOC_SH_GOTPC_LOW16,
32244 +  BFD_RELOC_SH_GOTPC_MEDLOW16,
32245 +  BFD_RELOC_SH_GOTPC_MEDHI16,
32246 +  BFD_RELOC_SH_GOTPC_HI16,
32247 +  BFD_RELOC_SH_COPY64,
32248 +  BFD_RELOC_SH_GLOB_DAT64,
32249 +  BFD_RELOC_SH_JMP_SLOT64,
32250 +  BFD_RELOC_SH_RELATIVE64,
32251 +  BFD_RELOC_SH_GOT10BY4,
32252 +  BFD_RELOC_SH_GOT10BY8,
32253 +  BFD_RELOC_SH_GOTPLT10BY4,
32254 +  BFD_RELOC_SH_GOTPLT10BY8,
32255 +  BFD_RELOC_SH_GOTPLT32,
32256 +  BFD_RELOC_SH_SHMEDIA_CODE,
32257 +  BFD_RELOC_SH_IMMU5,
32258 +  BFD_RELOC_SH_IMMS6,
32259 +  BFD_RELOC_SH_IMMS6BY32,
32260 +  BFD_RELOC_SH_IMMU6,
32261 +  BFD_RELOC_SH_IMMS10,
32262 +  BFD_RELOC_SH_IMMS10BY2,
32263 +  BFD_RELOC_SH_IMMS10BY4,
32264 +  BFD_RELOC_SH_IMMS10BY8,
32265 +  BFD_RELOC_SH_IMMS16,
32266 +  BFD_RELOC_SH_IMMU16,
32267 +  BFD_RELOC_SH_IMM_LOW16,
32268 +  BFD_RELOC_SH_IMM_LOW16_PCREL,
32269 +  BFD_RELOC_SH_IMM_MEDLOW16,
32270 +  BFD_RELOC_SH_IMM_MEDLOW16_PCREL,
32271 +  BFD_RELOC_SH_IMM_MEDHI16,
32272 +  BFD_RELOC_SH_IMM_MEDHI16_PCREL,
32273 +  BFD_RELOC_SH_IMM_HI16,
32274 +  BFD_RELOC_SH_IMM_HI16_PCREL,
32275 +  BFD_RELOC_SH_PT_16,
32276 +  BFD_RELOC_SH_TLS_GD_32,
32277 +  BFD_RELOC_SH_TLS_LD_32,
32278 +  BFD_RELOC_SH_TLS_LDO_32,
32279 +  BFD_RELOC_SH_TLS_IE_32,
32280 +  BFD_RELOC_SH_TLS_LE_32,
32281 +  BFD_RELOC_SH_TLS_DTPMOD32,
32282 +  BFD_RELOC_SH_TLS_DTPOFF32,
32283 +  BFD_RELOC_SH_TLS_TPOFF32,
32284 +
32285 +/* ARC Cores relocs.
32286 +ARC 22 bit pc-relative branch.  The lowest two bits must be zero and are
32287 +not stored in the instruction.  The high 20 bits are installed in bits 26
32288 +through 7 of the instruction.  */
32289 +  BFD_RELOC_ARC_B22_PCREL,
32290 +
32291 +/* ARC 26 bit absolute branch.  The lowest two bits must be zero and are not
32292 +stored in the instruction.  The high 24 bits are installed in bits 23
32293 +through 0.  */
32294 +  BFD_RELOC_ARC_B26,
32295 +
32296 +/* Mitsubishi D10V relocs.
32297 +This is a 10-bit reloc with the right 2 bits
32298 +assumed to be 0.  */
32299 +  BFD_RELOC_D10V_10_PCREL_R,
32300 +
32301 +/* Mitsubishi D10V relocs.
32302 +This is a 10-bit reloc with the right 2 bits
32303 +assumed to be 0.  This is the same as the previous reloc
32304 +except it is in the left container, i.e.,
32305 +shifted left 15 bits.  */
32306 +  BFD_RELOC_D10V_10_PCREL_L,
32307 +
32308 +/* This is an 18-bit reloc with the right 2 bits
32309 +assumed to be 0.  */
32310 +  BFD_RELOC_D10V_18,
32311 +
32312 +/* This is an 18-bit reloc with the right 2 bits
32313 +assumed to be 0.  */
32314 +  BFD_RELOC_D10V_18_PCREL,
32315 +
32316 +/* Mitsubishi D30V relocs.
32317 +This is a 6-bit absolute reloc.  */
32318 +  BFD_RELOC_D30V_6,
32319 +
32320 +/* This is a 6-bit pc-relative reloc with
32321 +the right 3 bits assumed to be 0.  */
32322 +  BFD_RELOC_D30V_9_PCREL,
32323 +
32324 +/* This is a 6-bit pc-relative reloc with
32325 +the right 3 bits assumed to be 0. Same
32326 +as the previous reloc but on the right side
32327 +of the container.  */
32328 +  BFD_RELOC_D30V_9_PCREL_R,
32329 +
32330 +/* This is a 12-bit absolute reloc with the
32331 +right 3 bitsassumed to be 0.  */
32332 +  BFD_RELOC_D30V_15,
32333 +
32334 +/* This is a 12-bit pc-relative reloc with
32335 +the right 3 bits assumed to be 0.  */
32336 +  BFD_RELOC_D30V_15_PCREL,
32337 +
32338 +/* This is a 12-bit pc-relative reloc with
32339 +the right 3 bits assumed to be 0. Same
32340 +as the previous reloc but on the right side
32341 +of the container.  */
32342 +  BFD_RELOC_D30V_15_PCREL_R,
32343 +
32344 +/* This is an 18-bit absolute reloc with
32345 +the right 3 bits assumed to be 0.  */
32346 +  BFD_RELOC_D30V_21,
32347 +
32348 +/* This is an 18-bit pc-relative reloc with
32349 +the right 3 bits assumed to be 0.  */
32350 +  BFD_RELOC_D30V_21_PCREL,
32351 +
32352 +/* This is an 18-bit pc-relative reloc with
32353 +the right 3 bits assumed to be 0. Same
32354 +as the previous reloc but on the right side
32355 +of the container.  */
32356 +  BFD_RELOC_D30V_21_PCREL_R,
32357 +
32358 +/* This is a 32-bit absolute reloc.  */
32359 +  BFD_RELOC_D30V_32,
32360 +
32361 +/* This is a 32-bit pc-relative reloc.  */
32362 +  BFD_RELOC_D30V_32_PCREL,
32363 +
32364 +/* DLX relocs  */
32365 +  BFD_RELOC_DLX_HI16_S,
32366 +
32367 +/* DLX relocs  */
32368 +  BFD_RELOC_DLX_LO16,
32369 +
32370 +/* DLX relocs  */
32371 +  BFD_RELOC_DLX_JMP26,
32372 +
32373 +/* Renesas M16C/M32C Relocations.  */
32374 +  BFD_RELOC_M16C_8_PCREL8,
32375 +  BFD_RELOC_M16C_16_PCREL8,
32376 +  BFD_RELOC_M16C_8_PCREL16,
32377 +  BFD_RELOC_M16C_8_ELABEL24,
32378 +  BFD_RELOC_M16C_8_ABS16,
32379 +  BFD_RELOC_M16C_16_ABS16,
32380 +  BFD_RELOC_M16C_16_ABS24,
32381 +  BFD_RELOC_M16C_16_ABS32,
32382 +  BFD_RELOC_M16C_24_ABS16,
32383 +  BFD_RELOC_M16C_24_ABS24,
32384 +  BFD_RELOC_M16C_24_ABS32,
32385 +  BFD_RELOC_M16C_32_ABS16,
32386 +  BFD_RELOC_M16C_32_ABS24,
32387 +  BFD_RELOC_M16C_32_ABS32,
32388 +  BFD_RELOC_M16C_40_ABS16,
32389 +  BFD_RELOC_M16C_40_ABS24,
32390 +  BFD_RELOC_M16C_40_ABS32,
32391 +
32392 +/* Renesas M32R (formerly Mitsubishi M32R) relocs.
32393 +This is a 24 bit absolute address.  */
32394 +  BFD_RELOC_M32R_24,
32395 +
32396 +/* This is a 10-bit pc-relative reloc with the right 2 bits assumed to be 0.  */
32397 +  BFD_RELOC_M32R_10_PCREL,
32398 +
32399 +/* This is an 18-bit reloc with the right 2 bits assumed to be 0.  */
32400 +  BFD_RELOC_M32R_18_PCREL,
32401 +
32402 +/* This is a 26-bit reloc with the right 2 bits assumed to be 0.  */
32403 +  BFD_RELOC_M32R_26_PCREL,
32404 +
32405 +/* This is a 16-bit reloc containing the high 16 bits of an address
32406 +used when the lower 16 bits are treated as unsigned.  */
32407 +  BFD_RELOC_M32R_HI16_ULO,
32408 +
32409 +/* This is a 16-bit reloc containing the high 16 bits of an address
32410 +used when the lower 16 bits are treated as signed.  */
32411 +  BFD_RELOC_M32R_HI16_SLO,
32412 +
32413 +/* This is a 16-bit reloc containing the lower 16 bits of an address.  */
32414 +  BFD_RELOC_M32R_LO16,
32415 +
32416 +/* This is a 16-bit reloc containing the small data area offset for use in
32417 +add3, load, and store instructions.  */
32418 +  BFD_RELOC_M32R_SDA16,
32419 +
32420 +/* For PIC.  */
32421 +  BFD_RELOC_M32R_GOT24,
32422 +  BFD_RELOC_M32R_26_PLTREL,
32423 +  BFD_RELOC_M32R_COPY,
32424 +  BFD_RELOC_M32R_GLOB_DAT,
32425 +  BFD_RELOC_M32R_JMP_SLOT,
32426 +  BFD_RELOC_M32R_RELATIVE,
32427 +  BFD_RELOC_M32R_GOTOFF,
32428 +  BFD_RELOC_M32R_GOTOFF_HI_ULO,
32429 +  BFD_RELOC_M32R_GOTOFF_HI_SLO,
32430 +  BFD_RELOC_M32R_GOTOFF_LO,
32431 +  BFD_RELOC_M32R_GOTPC24,
32432 +  BFD_RELOC_M32R_GOT16_HI_ULO,
32433 +  BFD_RELOC_M32R_GOT16_HI_SLO,
32434 +  BFD_RELOC_M32R_GOT16_LO,
32435 +  BFD_RELOC_M32R_GOTPC_HI_ULO,
32436 +  BFD_RELOC_M32R_GOTPC_HI_SLO,
32437 +  BFD_RELOC_M32R_GOTPC_LO,
32438 +
32439 +/* This is a 9-bit reloc  */
32440 +  BFD_RELOC_V850_9_PCREL,
32441 +
32442 +/* This is a 22-bit reloc  */
32443 +  BFD_RELOC_V850_22_PCREL,
32444 +
32445 +/* This is a 16 bit offset from the short data area pointer.  */
32446 +  BFD_RELOC_V850_SDA_16_16_OFFSET,
32447 +
32448 +/* This is a 16 bit offset (of which only 15 bits are used) from the
32449 +short data area pointer.  */
32450 +  BFD_RELOC_V850_SDA_15_16_OFFSET,
32451 +
32452 +/* This is a 16 bit offset from the zero data area pointer.  */
32453 +  BFD_RELOC_V850_ZDA_16_16_OFFSET,
32454 +
32455 +/* This is a 16 bit offset (of which only 15 bits are used) from the
32456 +zero data area pointer.  */
32457 +  BFD_RELOC_V850_ZDA_15_16_OFFSET,
32458 +
32459 +/* This is an 8 bit offset (of which only 6 bits are used) from the
32460 +tiny data area pointer.  */
32461 +  BFD_RELOC_V850_TDA_6_8_OFFSET,
32462 +
32463 +/* This is an 8bit offset (of which only 7 bits are used) from the tiny
32464 +data area pointer.  */
32465 +  BFD_RELOC_V850_TDA_7_8_OFFSET,
32466 +
32467 +/* This is a 7 bit offset from the tiny data area pointer.  */
32468 +  BFD_RELOC_V850_TDA_7_7_OFFSET,
32469 +
32470 +/* This is a 16 bit offset from the tiny data area pointer.  */
32471 +  BFD_RELOC_V850_TDA_16_16_OFFSET,
32472 +
32473 +/* This is a 5 bit offset (of which only 4 bits are used) from the tiny
32474 +data area pointer.  */
32475 +  BFD_RELOC_V850_TDA_4_5_OFFSET,
32476 +
32477 +/* This is a 4 bit offset from the tiny data area pointer.  */
32478 +  BFD_RELOC_V850_TDA_4_4_OFFSET,
32479 +
32480 +/* This is a 16 bit offset from the short data area pointer, with the
32481 +bits placed non-contiguously in the instruction.  */
32482 +  BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET,
32483 +
32484 +/* This is a 16 bit offset from the zero data area pointer, with the
32485 +bits placed non-contiguously in the instruction.  */
32486 +  BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET,
32487 +
32488 +/* This is a 6 bit offset from the call table base pointer.  */
32489 +  BFD_RELOC_V850_CALLT_6_7_OFFSET,
32490 +
32491 +/* This is a 16 bit offset from the call table base pointer.  */
32492 +  BFD_RELOC_V850_CALLT_16_16_OFFSET,
32493 +
32494 +/* Used for relaxing indirect function calls.  */
32495 +  BFD_RELOC_V850_LONGCALL,
32496 +
32497 +/* Used for relaxing indirect jumps.  */
32498 +  BFD_RELOC_V850_LONGJUMP,
32499 +
32500 +/* Used to maintain alignment whilst relaxing.  */
32501 +  BFD_RELOC_V850_ALIGN,
32502 +
32503 +/* This is a variation of BFD_RELOC_LO16 that can be used in v850e ld.bu
32504 +instructions.  */
32505 +  BFD_RELOC_V850_LO16_SPLIT_OFFSET,
32506 +
32507 +/* This is a 32bit pcrel reloc for the mn10300, offset by two bytes in the
32508 +instruction.  */
32509 +  BFD_RELOC_MN10300_32_PCREL,
32510 +
32511 +/* This is a 16bit pcrel reloc for the mn10300, offset by two bytes in the
32512 +instruction.  */
32513 +  BFD_RELOC_MN10300_16_PCREL,
32514 +
32515 +/* This is a 8bit DP reloc for the tms320c30, where the most
32516 +significant 8 bits of a 24 bit word are placed into the least
32517 +significant 8 bits of the opcode.  */
32518 +  BFD_RELOC_TIC30_LDP,
32519 +
32520 +/* This is a 7bit reloc for the tms320c54x, where the least
32521 +significant 7 bits of a 16 bit word are placed into the least
32522 +significant 7 bits of the opcode.  */
32523 +  BFD_RELOC_TIC54X_PARTLS7,
32524 +
32525 +/* This is a 9bit DP reloc for the tms320c54x, where the most
32526 +significant 9 bits of a 16 bit word are placed into the least
32527 +significant 9 bits of the opcode.  */
32528 +  BFD_RELOC_TIC54X_PARTMS9,
32529 +
32530 +/* This is an extended address 23-bit reloc for the tms320c54x.  */
32531 +  BFD_RELOC_TIC54X_23,
32532 +
32533 +/* This is a 16-bit reloc for the tms320c54x, where the least
32534 +significant 16 bits of a 23-bit extended address are placed into
32535 +the opcode.  */
32536 +  BFD_RELOC_TIC54X_16_OF_23,
32537 +
32538 +/* This is a reloc for the tms320c54x, where the most
32539 +significant 7 bits of a 23-bit extended address are placed into
32540 +the opcode.  */
32541 +  BFD_RELOC_TIC54X_MS7_OF_23,
32542 +
32543 +/* This is a 48 bit reloc for the FR30 that stores 32 bits.  */
32544 +  BFD_RELOC_FR30_48,
32545 +
32546 +/* This is a 32 bit reloc for the FR30 that stores 20 bits split up into
32547 +two sections.  */
32548 +  BFD_RELOC_FR30_20,
32549 +
32550 +/* This is a 16 bit reloc for the FR30 that stores a 6 bit word offset in
32551 +4 bits.  */
32552 +  BFD_RELOC_FR30_6_IN_4,
32553 +
32554 +/* This is a 16 bit reloc for the FR30 that stores an 8 bit byte offset
32555 +into 8 bits.  */
32556 +  BFD_RELOC_FR30_8_IN_8,
32557 +
32558 +/* This is a 16 bit reloc for the FR30 that stores a 9 bit short offset
32559 +into 8 bits.  */
32560 +  BFD_RELOC_FR30_9_IN_8,
32561 +
32562 +/* This is a 16 bit reloc for the FR30 that stores a 10 bit word offset
32563 +into 8 bits.  */
32564 +  BFD_RELOC_FR30_10_IN_8,
32565 +
32566 +/* This is a 16 bit reloc for the FR30 that stores a 9 bit pc relative
32567 +short offset into 8 bits.  */
32568 +  BFD_RELOC_FR30_9_PCREL,
32569 +
32570 +/* This is a 16 bit reloc for the FR30 that stores a 12 bit pc relative
32571 +short offset into 11 bits.  */
32572 +  BFD_RELOC_FR30_12_PCREL,
32573 +
32574 +/* Motorola Mcore relocations.  */
32575 +  BFD_RELOC_MCORE_PCREL_IMM8BY4,
32576 +  BFD_RELOC_MCORE_PCREL_IMM11BY2,
32577 +  BFD_RELOC_MCORE_PCREL_IMM4BY2,
32578 +  BFD_RELOC_MCORE_PCREL_32,
32579 +  BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2,
32580 +  BFD_RELOC_MCORE_RVA,
32581 +
32582 +/* These are relocations for the GETA instruction.  */
32583 +  BFD_RELOC_MMIX_GETA,
32584 +  BFD_RELOC_MMIX_GETA_1,
32585 +  BFD_RELOC_MMIX_GETA_2,
32586 +  BFD_RELOC_MMIX_GETA_3,
32587 +
32588 +/* These are relocations for a conditional branch instruction.  */
32589 +  BFD_RELOC_MMIX_CBRANCH,
32590 +  BFD_RELOC_MMIX_CBRANCH_J,
32591 +  BFD_RELOC_MMIX_CBRANCH_1,
32592 +  BFD_RELOC_MMIX_CBRANCH_2,
32593 +  BFD_RELOC_MMIX_CBRANCH_3,
32594 +
32595 +/* These are relocations for the PUSHJ instruction.  */
32596 +  BFD_RELOC_MMIX_PUSHJ,
32597 +  BFD_RELOC_MMIX_PUSHJ_1,
32598 +  BFD_RELOC_MMIX_PUSHJ_2,
32599 +  BFD_RELOC_MMIX_PUSHJ_3,
32600 +  BFD_RELOC_MMIX_PUSHJ_STUBBABLE,
32601 +
32602 +/* These are relocations for the JMP instruction.  */
32603 +  BFD_RELOC_MMIX_JMP,
32604 +  BFD_RELOC_MMIX_JMP_1,
32605 +  BFD_RELOC_MMIX_JMP_2,
32606 +  BFD_RELOC_MMIX_JMP_3,
32607 +
32608 +/* This is a relocation for a relative address as in a GETA instruction or
32609 +a branch.  */
32610 +  BFD_RELOC_MMIX_ADDR19,
32611 +
32612 +/* This is a relocation for a relative address as in a JMP instruction.  */
32613 +  BFD_RELOC_MMIX_ADDR27,
32614 +
32615 +/* This is a relocation for an instruction field that may be a general
32616 +register or a value 0..255.  */
32617 +  BFD_RELOC_MMIX_REG_OR_BYTE,
32618 +
32619 +/* This is a relocation for an instruction field that may be a general
32620 +register.  */
32621 +  BFD_RELOC_MMIX_REG,
32622 +
32623 +/* This is a relocation for two instruction fields holding a register and
32624 +an offset, the equivalent of the relocation.  */
32625 +  BFD_RELOC_MMIX_BASE_PLUS_OFFSET,
32626 +
32627 +/* This relocation is an assertion that the expression is not allocated as
32628 +a global register.  It does not modify contents.  */
32629 +  BFD_RELOC_MMIX_LOCAL,
32630 +
32631 +/* This is a 16 bit reloc for the AVR that stores 8 bit pc relative
32632 +short offset into 7 bits.  */
32633 +  BFD_RELOC_AVR_7_PCREL,
32634 +
32635 +/* This is a 16 bit reloc for the AVR that stores 13 bit pc relative
32636 +short offset into 12 bits.  */
32637 +  BFD_RELOC_AVR_13_PCREL,
32638 +
32639 +/* This is a 16 bit reloc for the AVR that stores 17 bit value (usually
32640 +program memory address) into 16 bits.  */
32641 +  BFD_RELOC_AVR_16_PM,
32642 +
32643 +/* This is a 16 bit reloc for the AVR that stores 8 bit value (usually
32644 +data memory address) into 8 bit immediate value of LDI insn.  */
32645 +  BFD_RELOC_AVR_LO8_LDI,
32646 +
32647 +/* This is a 16 bit reloc for the AVR that stores 8 bit value (high 8 bit
32648 +of data memory address) into 8 bit immediate value of LDI insn.  */
32649 +  BFD_RELOC_AVR_HI8_LDI,
32650 +
32651 +/* This is a 16 bit reloc for the AVR that stores 8 bit value (most high 8 bit
32652 +of program memory address) into 8 bit immediate value of LDI insn.  */
32653 +  BFD_RELOC_AVR_HH8_LDI,
32654 +
32655 +/* This is a 16 bit reloc for the AVR that stores negated 8 bit value
32656 +(usually data memory address) into 8 bit immediate value of SUBI insn.  */
32657 +  BFD_RELOC_AVR_LO8_LDI_NEG,
32658 +
32659 +/* This is a 16 bit reloc for the AVR that stores negated 8 bit value
32660 +(high 8 bit of data memory address) into 8 bit immediate value of
32661 +SUBI insn.  */
32662 +  BFD_RELOC_AVR_HI8_LDI_NEG,
32663 +
32664 +/* This is a 16 bit reloc for the AVR that stores negated 8 bit value
32665 +(most high 8 bit of program memory address) into 8 bit immediate value
32666 +of LDI or SUBI insn.  */
32667 +  BFD_RELOC_AVR_HH8_LDI_NEG,
32668 +
32669 +/* This is a 16 bit reloc for the AVR that stores 8 bit value (usually
32670 +command address) into 8 bit immediate value of LDI insn.  */
32671 +  BFD_RELOC_AVR_LO8_LDI_PM,
32672 +
32673 +/* This is a 16 bit reloc for the AVR that stores 8 bit value (high 8 bit
32674 +of command address) into 8 bit immediate value of LDI insn.  */
32675 +  BFD_RELOC_AVR_HI8_LDI_PM,
32676 +
32677 +/* This is a 16 bit reloc for the AVR that stores 8 bit value (most high 8 bit
32678 +of command address) into 8 bit immediate value of LDI insn.  */
32679 +  BFD_RELOC_AVR_HH8_LDI_PM,
32680 +
32681 +/* This is a 16 bit reloc for the AVR that stores negated 8 bit value
32682 +(usually command address) into 8 bit immediate value of SUBI insn.  */
32683 +  BFD_RELOC_AVR_LO8_LDI_PM_NEG,
32684 +
32685 +/* This is a 16 bit reloc for the AVR that stores negated 8 bit value
32686 +(high 8 bit of 16 bit command address) into 8 bit immediate value
32687 +of SUBI insn.  */
32688 +  BFD_RELOC_AVR_HI8_LDI_PM_NEG,
32689 +
32690 +/* This is a 16 bit reloc for the AVR that stores negated 8 bit value
32691 +(high 6 bit of 22 bit command address) into 8 bit immediate
32692 +value of SUBI insn.  */
32693 +  BFD_RELOC_AVR_HH8_LDI_PM_NEG,
32694 +
32695 +/* This is a 32 bit reloc for the AVR that stores 23 bit value
32696 +into 22 bits.  */
32697 +  BFD_RELOC_AVR_CALL,
32698 +
32699 +/* This is a 16 bit reloc for the AVR that stores all needed bits
32700 +for absolute addressing with ldi with overflow check to linktime  */
32701 +  BFD_RELOC_AVR_LDI,
32702 +
32703 +/* This is a 6 bit reloc for the AVR that stores offset for ldd/std
32704 +instructions  */
32705 +  BFD_RELOC_AVR_6,
32706 +
32707 +/* This is a 6 bit reloc for the AVR that stores offset for adiw/sbiw
32708 +instructions  */
32709 +  BFD_RELOC_AVR_6_ADIW,
32710 +
32711 +/* Direct 12 bit.  */
32712 +  BFD_RELOC_390_12,
32713 +
32714 +/* 12 bit GOT offset.  */
32715 +  BFD_RELOC_390_GOT12,
32716 +
32717 +/* 32 bit PC relative PLT address.  */
32718 +  BFD_RELOC_390_PLT32,
32719 +
32720 +/* Copy symbol at runtime.  */
32721 +  BFD_RELOC_390_COPY,
32722 +
32723 +/* Create GOT entry.  */
32724 +  BFD_RELOC_390_GLOB_DAT,
32725 +
32726 +/* Create PLT entry.  */
32727 +  BFD_RELOC_390_JMP_SLOT,
32728 +
32729 +/* Adjust by program base.  */
32730 +  BFD_RELOC_390_RELATIVE,
32731 +
32732 +/* 32 bit PC relative offset to GOT.  */
32733 +  BFD_RELOC_390_GOTPC,
32734 +
32735 +/* 16 bit GOT offset.  */
32736 +  BFD_RELOC_390_GOT16,
32737 +
32738 +/* PC relative 16 bit shifted by 1.  */
32739 +  BFD_RELOC_390_PC16DBL,
32740 +
32741 +/* 16 bit PC rel. PLT shifted by 1.  */
32742 +  BFD_RELOC_390_PLT16DBL,
32743 +
32744 +/* PC relative 32 bit shifted by 1.  */
32745 +  BFD_RELOC_390_PC32DBL,
32746 +
32747 +/* 32 bit PC rel. PLT shifted by 1.  */
32748 +  BFD_RELOC_390_PLT32DBL,
32749 +
32750 +/* 32 bit PC rel. GOT shifted by 1.  */
32751 +  BFD_RELOC_390_GOTPCDBL,
32752 +
32753 +/* 64 bit GOT offset.  */
32754 +  BFD_RELOC_390_GOT64,
32755 +
32756 +/* 64 bit PC relative PLT address.  */
32757 +  BFD_RELOC_390_PLT64,
32758 +
32759 +/* 32 bit rel. offset to GOT entry.  */
32760 +  BFD_RELOC_390_GOTENT,
32761 +
32762 +/* 64 bit offset to GOT.  */
32763 +  BFD_RELOC_390_GOTOFF64,
32764 +
32765 +/* 12-bit offset to symbol-entry within GOT, with PLT handling.  */
32766 +  BFD_RELOC_390_GOTPLT12,
32767 +
32768 +/* 16-bit offset to symbol-entry within GOT, with PLT handling.  */
32769 +  BFD_RELOC_390_GOTPLT16,
32770 +
32771 +/* 32-bit offset to symbol-entry within GOT, with PLT handling.  */
32772 +  BFD_RELOC_390_GOTPLT32,
32773 +
32774 +/* 64-bit offset to symbol-entry within GOT, with PLT handling.  */
32775 +  BFD_RELOC_390_GOTPLT64,
32776 +
32777 +/* 32-bit rel. offset to symbol-entry within GOT, with PLT handling.  */
32778 +  BFD_RELOC_390_GOTPLTENT,
32779 +
32780 +/* 16-bit rel. offset from the GOT to a PLT entry.  */
32781 +  BFD_RELOC_390_PLTOFF16,
32782 +
32783 +/* 32-bit rel. offset from the GOT to a PLT entry.  */
32784 +  BFD_RELOC_390_PLTOFF32,
32785 +
32786 +/* 64-bit rel. offset from the GOT to a PLT entry.  */
32787 +  BFD_RELOC_390_PLTOFF64,
32788 +
32789 +/* s390 tls relocations.  */
32790 +  BFD_RELOC_390_TLS_LOAD,
32791 +  BFD_RELOC_390_TLS_GDCALL,
32792 +  BFD_RELOC_390_TLS_LDCALL,
32793 +  BFD_RELOC_390_TLS_GD32,
32794 +  BFD_RELOC_390_TLS_GD64,
32795 +  BFD_RELOC_390_TLS_GOTIE12,
32796 +  BFD_RELOC_390_TLS_GOTIE32,
32797 +  BFD_RELOC_390_TLS_GOTIE64,
32798 +  BFD_RELOC_390_TLS_LDM32,
32799 +  BFD_RELOC_390_TLS_LDM64,
32800 +  BFD_RELOC_390_TLS_IE32,
32801 +  BFD_RELOC_390_TLS_IE64,
32802 +  BFD_RELOC_390_TLS_IEENT,
32803 +  BFD_RELOC_390_TLS_LE32,
32804 +  BFD_RELOC_390_TLS_LE64,
32805 +  BFD_RELOC_390_TLS_LDO32,
32806 +  BFD_RELOC_390_TLS_LDO64,
32807 +  BFD_RELOC_390_TLS_DTPMOD,
32808 +  BFD_RELOC_390_TLS_DTPOFF,
32809 +  BFD_RELOC_390_TLS_TPOFF,
32810 +
32811 +/* Long displacement extension.  */
32812 +  BFD_RELOC_390_20,
32813 +  BFD_RELOC_390_GOT20,
32814 +  BFD_RELOC_390_GOTPLT20,
32815 +  BFD_RELOC_390_TLS_GOTIE20,
32816 +
32817 +/* Scenix IP2K - 9-bit register number / data address  */
32818 +  BFD_RELOC_IP2K_FR9,
32819 +
32820 +/* Scenix IP2K - 4-bit register/data bank number  */
32821 +  BFD_RELOC_IP2K_BANK,
32822 +
32823 +/* Scenix IP2K - low 13 bits of instruction word address  */
32824 +  BFD_RELOC_IP2K_ADDR16CJP,
32825 +
32826 +/* Scenix IP2K - high 3 bits of instruction word address  */
32827 +  BFD_RELOC_IP2K_PAGE3,
32828 +
32829 +/* Scenix IP2K - ext/low/high 8 bits of data address  */
32830 +  BFD_RELOC_IP2K_LO8DATA,
32831 +  BFD_RELOC_IP2K_HI8DATA,
32832 +  BFD_RELOC_IP2K_EX8DATA,
32833 +
32834 +/* Scenix IP2K - low/high 8 bits of instruction word address  */
32835 +  BFD_RELOC_IP2K_LO8INSN,
32836 +  BFD_RELOC_IP2K_HI8INSN,
32837 +
32838 +/* Scenix IP2K - even/odd PC modifier to modify snb pcl.0  */
32839 +  BFD_RELOC_IP2K_PC_SKIP,
32840 +
32841 +/* Scenix IP2K - 16 bit word address in text section.  */
32842 +  BFD_RELOC_IP2K_TEXT,
32843 +
32844 +/* Scenix IP2K - 7-bit sp or dp offset  */
32845 +  BFD_RELOC_IP2K_FR_OFFSET,
32846 +
32847 +/* Scenix VPE4K coprocessor - data/insn-space addressing  */
32848 +  BFD_RELOC_VPE4KMATH_DATA,
32849 +  BFD_RELOC_VPE4KMATH_INSN,
32850 +
32851 +/* These two relocations are used by the linker to determine which of
32852 +the entries in a C++ virtual function table are actually used.  When
32853 +the --gc-sections option is given, the linker will zero out the entries
32854 +that are not used, so that the code for those functions need not be
32855 +included in the output.
32856 +
32857 +VTABLE_INHERIT is a zero-space relocation used to describe to the
32858 +linker the inheritance tree of a C++ virtual function table.  The
32859 +relocation's symbol should be the parent class' vtable, and the
32860 +relocation should be located at the child vtable.
32861 +
32862 +VTABLE_ENTRY is a zero-space relocation that describes the use of a
32863 +virtual function table entry.  The reloc's symbol should refer to the
32864 +table of the class mentioned in the code.  Off of that base, an offset
32865 +describes the entry that is being used.  For Rela hosts, this offset
32866 +is stored in the reloc's addend.  For Rel hosts, we are forced to put
32867 +this offset in the reloc's section offset.  */
32868 +  BFD_RELOC_VTABLE_INHERIT,
32869 +  BFD_RELOC_VTABLE_ENTRY,
32870 +
32871 +/* Intel IA64 Relocations.  */
32872 +  BFD_RELOC_IA64_IMM14,
32873 +  BFD_RELOC_IA64_IMM22,
32874 +  BFD_RELOC_IA64_IMM64,
32875 +  BFD_RELOC_IA64_DIR32MSB,
32876 +  BFD_RELOC_IA64_DIR32LSB,
32877 +  BFD_RELOC_IA64_DIR64MSB,
32878 +  BFD_RELOC_IA64_DIR64LSB,
32879 +  BFD_RELOC_IA64_GPREL22,
32880 +  BFD_RELOC_IA64_GPREL64I,
32881 +  BFD_RELOC_IA64_GPREL32MSB,
32882 +  BFD_RELOC_IA64_GPREL32LSB,
32883 +  BFD_RELOC_IA64_GPREL64MSB,
32884 +  BFD_RELOC_IA64_GPREL64LSB,
32885 +  BFD_RELOC_IA64_LTOFF22,
32886 +  BFD_RELOC_IA64_LTOFF64I,
32887 +  BFD_RELOC_IA64_PLTOFF22,
32888 +  BFD_RELOC_IA64_PLTOFF64I,
32889 +  BFD_RELOC_IA64_PLTOFF64MSB,
32890 +  BFD_RELOC_IA64_PLTOFF64LSB,
32891 +  BFD_RELOC_IA64_FPTR64I,
32892 +  BFD_RELOC_IA64_FPTR32MSB,
32893 +  BFD_RELOC_IA64_FPTR32LSB,
32894 +  BFD_RELOC_IA64_FPTR64MSB,
32895 +  BFD_RELOC_IA64_FPTR64LSB,
32896 +  BFD_RELOC_IA64_PCREL21B,
32897 +  BFD_RELOC_IA64_PCREL21BI,
32898 +  BFD_RELOC_IA64_PCREL21M,
32899 +  BFD_RELOC_IA64_PCREL21F,
32900 +  BFD_RELOC_IA64_PCREL22,
32901 +  BFD_RELOC_IA64_PCREL60B,
32902 +  BFD_RELOC_IA64_PCREL64I,
32903 +  BFD_RELOC_IA64_PCREL32MSB,
32904 +  BFD_RELOC_IA64_PCREL32LSB,
32905 +  BFD_RELOC_IA64_PCREL64MSB,
32906 +  BFD_RELOC_IA64_PCREL64LSB,
32907 +  BFD_RELOC_IA64_LTOFF_FPTR22,
32908 +  BFD_RELOC_IA64_LTOFF_FPTR64I,
32909 +  BFD_RELOC_IA64_LTOFF_FPTR32MSB,
32910 +  BFD_RELOC_IA64_LTOFF_FPTR32LSB,
32911 +  BFD_RELOC_IA64_LTOFF_FPTR64MSB,
32912 +  BFD_RELOC_IA64_LTOFF_FPTR64LSB,
32913 +  BFD_RELOC_IA64_SEGREL32MSB,
32914 +  BFD_RELOC_IA64_SEGREL32LSB,
32915 +  BFD_RELOC_IA64_SEGREL64MSB,
32916 +  BFD_RELOC_IA64_SEGREL64LSB,
32917 +  BFD_RELOC_IA64_SECREL32MSB,
32918 +  BFD_RELOC_IA64_SECREL32LSB,
32919 +  BFD_RELOC_IA64_SECREL64MSB,
32920 +  BFD_RELOC_IA64_SECREL64LSB,
32921 +  BFD_RELOC_IA64_REL32MSB,
32922 +  BFD_RELOC_IA64_REL32LSB,
32923 +  BFD_RELOC_IA64_REL64MSB,
32924 +  BFD_RELOC_IA64_REL64LSB,
32925 +  BFD_RELOC_IA64_LTV32MSB,
32926 +  BFD_RELOC_IA64_LTV32LSB,
32927 +  BFD_RELOC_IA64_LTV64MSB,
32928 +  BFD_RELOC_IA64_LTV64LSB,
32929 +  BFD_RELOC_IA64_IPLTMSB,
32930 +  BFD_RELOC_IA64_IPLTLSB,
32931 +  BFD_RELOC_IA64_COPY,
32932 +  BFD_RELOC_IA64_LTOFF22X,
32933 +  BFD_RELOC_IA64_LDXMOV,
32934 +  BFD_RELOC_IA64_TPREL14,
32935 +  BFD_RELOC_IA64_TPREL22,
32936 +  BFD_RELOC_IA64_TPREL64I,
32937 +  BFD_RELOC_IA64_TPREL64MSB,
32938 +  BFD_RELOC_IA64_TPREL64LSB,
32939 +  BFD_RELOC_IA64_LTOFF_TPREL22,
32940 +  BFD_RELOC_IA64_DTPMOD64MSB,
32941 +  BFD_RELOC_IA64_DTPMOD64LSB,
32942 +  BFD_RELOC_IA64_LTOFF_DTPMOD22,
32943 +  BFD_RELOC_IA64_DTPREL14,
32944 +  BFD_RELOC_IA64_DTPREL22,
32945 +  BFD_RELOC_IA64_DTPREL64I,
32946 +  BFD_RELOC_IA64_DTPREL32MSB,
32947 +  BFD_RELOC_IA64_DTPREL32LSB,
32948 +  BFD_RELOC_IA64_DTPREL64MSB,
32949 +  BFD_RELOC_IA64_DTPREL64LSB,
32950 +  BFD_RELOC_IA64_LTOFF_DTPREL22,
32951 +
32952 +/* Motorola 68HC11 reloc.
32953 +This is the 8 bit high part of an absolute address.  */
32954 +  BFD_RELOC_M68HC11_HI8,
32955 +
32956 +/* Motorola 68HC11 reloc.
32957 +This is the 8 bit low part of an absolute address.  */
32958 +  BFD_RELOC_M68HC11_LO8,
32959 +
32960 +/* Motorola 68HC11 reloc.
32961 +This is the 3 bit of a value.  */
32962 +  BFD_RELOC_M68HC11_3B,
32963 +
32964 +/* Motorola 68HC11 reloc.
32965 +This reloc marks the beginning of a jump/call instruction.
32966 +It is used for linker relaxation to correctly identify beginning
32967 +of instruction and change some branches to use PC-relative
32968 +addressing mode.  */
32969 +  BFD_RELOC_M68HC11_RL_JUMP,
32970 +
32971 +/* Motorola 68HC11 reloc.
32972 +This reloc marks a group of several instructions that gcc generates
32973 +and for which the linker relaxation pass can modify and/or remove
32974 +some of them.  */
32975 +  BFD_RELOC_M68HC11_RL_GROUP,
32976 +
32977 +/* Motorola 68HC11 reloc.
32978 +This is the 16-bit lower part of an address.  It is used for 'call'
32979 +instruction to specify the symbol address without any special
32980 +transformation (due to memory bank window).  */
32981 +  BFD_RELOC_M68HC11_LO16,
32982 +
32983 +/* Motorola 68HC11 reloc.
32984 +This is a 8-bit reloc that specifies the page number of an address.
32985 +It is used by 'call' instruction to specify the page number of
32986 +the symbol.  */
32987 +  BFD_RELOC_M68HC11_PAGE,
32988 +
32989 +/* Motorola 68HC11 reloc.
32990 +This is a 24-bit reloc that represents the address with a 16-bit
32991 +value and a 8-bit page number.  The symbol address is transformed
32992 +to follow the 16K memory bank of 68HC12 (seen as mapped in the window).  */
32993 +  BFD_RELOC_M68HC11_24,
32994 +
32995 +/* Motorola 68HC12 reloc.
32996 +This is the 5 bits of a value.  */
32997 +  BFD_RELOC_M68HC12_5B,
32998 +
32999 +/* NS CR16C Relocations.  */
33000 +  BFD_RELOC_16C_NUM08,
33001 +  BFD_RELOC_16C_NUM08_C,
33002 +  BFD_RELOC_16C_NUM16,
33003 +  BFD_RELOC_16C_NUM16_C,
33004 +  BFD_RELOC_16C_NUM32,
33005 +  BFD_RELOC_16C_NUM32_C,
33006 +  BFD_RELOC_16C_DISP04,
33007 +  BFD_RELOC_16C_DISP04_C,
33008 +  BFD_RELOC_16C_DISP08,
33009 +  BFD_RELOC_16C_DISP08_C,
33010 +  BFD_RELOC_16C_DISP16,
33011 +  BFD_RELOC_16C_DISP16_C,
33012 +  BFD_RELOC_16C_DISP24,
33013 +  BFD_RELOC_16C_DISP24_C,
33014 +  BFD_RELOC_16C_DISP24a,
33015 +  BFD_RELOC_16C_DISP24a_C,
33016 +  BFD_RELOC_16C_REG04,
33017 +  BFD_RELOC_16C_REG04_C,
33018 +  BFD_RELOC_16C_REG04a,
33019 +  BFD_RELOC_16C_REG04a_C,
33020 +  BFD_RELOC_16C_REG14,
33021 +  BFD_RELOC_16C_REG14_C,
33022 +  BFD_RELOC_16C_REG16,
33023 +  BFD_RELOC_16C_REG16_C,
33024 +  BFD_RELOC_16C_REG20,
33025 +  BFD_RELOC_16C_REG20_C,
33026 +  BFD_RELOC_16C_ABS20,
33027 +  BFD_RELOC_16C_ABS20_C,
33028 +  BFD_RELOC_16C_ABS24,
33029 +  BFD_RELOC_16C_ABS24_C,
33030 +  BFD_RELOC_16C_IMM04,
33031 +  BFD_RELOC_16C_IMM04_C,
33032 +  BFD_RELOC_16C_IMM16,
33033 +  BFD_RELOC_16C_IMM16_C,
33034 +  BFD_RELOC_16C_IMM20,
33035 +  BFD_RELOC_16C_IMM20_C,
33036 +  BFD_RELOC_16C_IMM24,
33037 +  BFD_RELOC_16C_IMM24_C,
33038 +  BFD_RELOC_16C_IMM32,
33039 +  BFD_RELOC_16C_IMM32_C,
33040 +
33041 +/* NS CRX Relocations.  */
33042 +  BFD_RELOC_CRX_REL4,
33043 +  BFD_RELOC_CRX_REL8,
33044 +  BFD_RELOC_CRX_REL8_CMP,
33045 +  BFD_RELOC_CRX_REL16,
33046 +  BFD_RELOC_CRX_REL24,
33047 +  BFD_RELOC_CRX_REL32,
33048 +  BFD_RELOC_CRX_REGREL12,
33049 +  BFD_RELOC_CRX_REGREL22,
33050 +  BFD_RELOC_CRX_REGREL28,
33051 +  BFD_RELOC_CRX_REGREL32,
33052 +  BFD_RELOC_CRX_ABS16,
33053 +  BFD_RELOC_CRX_ABS32,
33054 +  BFD_RELOC_CRX_NUM8,
33055 +  BFD_RELOC_CRX_NUM16,
33056 +  BFD_RELOC_CRX_NUM32,
33057 +  BFD_RELOC_CRX_IMM16,
33058 +  BFD_RELOC_CRX_IMM32,
33059 +  BFD_RELOC_CRX_SWITCH8,
33060 +  BFD_RELOC_CRX_SWITCH16,
33061 +  BFD_RELOC_CRX_SWITCH32,
33062 +
33063 +/* These relocs are only used within the CRIS assembler.  They are not
33064 +(at present) written to any object files.  */
33065 +  BFD_RELOC_CRIS_BDISP8,
33066 +  BFD_RELOC_CRIS_UNSIGNED_5,
33067 +  BFD_RELOC_CRIS_SIGNED_6,
33068 +  BFD_RELOC_CRIS_UNSIGNED_6,
33069 +  BFD_RELOC_CRIS_SIGNED_8,
33070 +  BFD_RELOC_CRIS_UNSIGNED_8,
33071 +  BFD_RELOC_CRIS_SIGNED_16,
33072 +  BFD_RELOC_CRIS_UNSIGNED_16,
33073 +  BFD_RELOC_CRIS_LAPCQ_OFFSET,
33074 +  BFD_RELOC_CRIS_UNSIGNED_4,
33075 +
33076 +/* Relocs used in ELF shared libraries for CRIS.  */
33077 +  BFD_RELOC_CRIS_COPY,
33078 +  BFD_RELOC_CRIS_GLOB_DAT,
33079 +  BFD_RELOC_CRIS_JUMP_SLOT,
33080 +  BFD_RELOC_CRIS_RELATIVE,
33081 +
33082 +/* 32-bit offset to symbol-entry within GOT.  */
33083 +  BFD_RELOC_CRIS_32_GOT,
33084 +
33085 +/* 16-bit offset to symbol-entry within GOT.  */
33086 +  BFD_RELOC_CRIS_16_GOT,
33087 +
33088 +/* 32-bit offset to symbol-entry within GOT, with PLT handling.  */
33089 +  BFD_RELOC_CRIS_32_GOTPLT,
33090 +
33091 +/* 16-bit offset to symbol-entry within GOT, with PLT handling.  */
33092 +  BFD_RELOC_CRIS_16_GOTPLT,
33093 +
33094 +/* 32-bit offset to symbol, relative to GOT.  */
33095 +  BFD_RELOC_CRIS_32_GOTREL,
33096 +
33097 +/* 32-bit offset to symbol with PLT entry, relative to GOT.  */
33098 +  BFD_RELOC_CRIS_32_PLT_GOTREL,
33099 +
33100 +/* 32-bit offset to symbol with PLT entry, relative to this relocation.  */
33101 +  BFD_RELOC_CRIS_32_PLT_PCREL,
33102 +
33103 +/* Intel i860 Relocations.  */
33104 +  BFD_RELOC_860_COPY,
33105 +  BFD_RELOC_860_GLOB_DAT,
33106 +  BFD_RELOC_860_JUMP_SLOT,
33107 +  BFD_RELOC_860_RELATIVE,
33108 +  BFD_RELOC_860_PC26,
33109 +  BFD_RELOC_860_PLT26,
33110 +  BFD_RELOC_860_PC16,
33111 +  BFD_RELOC_860_LOW0,
33112 +  BFD_RELOC_860_SPLIT0,
33113 +  BFD_RELOC_860_LOW1,
33114 +  BFD_RELOC_860_SPLIT1,
33115 +  BFD_RELOC_860_LOW2,
33116 +  BFD_RELOC_860_SPLIT2,
33117 +  BFD_RELOC_860_LOW3,
33118 +  BFD_RELOC_860_LOGOT0,
33119 +  BFD_RELOC_860_SPGOT0,
33120 +  BFD_RELOC_860_LOGOT1,
33121 +  BFD_RELOC_860_SPGOT1,
33122 +  BFD_RELOC_860_LOGOTOFF0,
33123 +  BFD_RELOC_860_SPGOTOFF0,
33124 +  BFD_RELOC_860_LOGOTOFF1,
33125 +  BFD_RELOC_860_SPGOTOFF1,
33126 +  BFD_RELOC_860_LOGOTOFF2,
33127 +  BFD_RELOC_860_LOGOTOFF3,
33128 +  BFD_RELOC_860_LOPC,
33129 +  BFD_RELOC_860_HIGHADJ,
33130 +  BFD_RELOC_860_HAGOT,
33131 +  BFD_RELOC_860_HAGOTOFF,
33132 +  BFD_RELOC_860_HAPC,
33133 +  BFD_RELOC_860_HIGH,
33134 +  BFD_RELOC_860_HIGOT,
33135 +  BFD_RELOC_860_HIGOTOFF,
33136 +
33137 +/* OpenRISC Relocations.  */
33138 +  BFD_RELOC_OPENRISC_ABS_26,
33139 +  BFD_RELOC_OPENRISC_REL_26,
33140 +
33141 +/* H8 elf Relocations.  */
33142 +  BFD_RELOC_H8_DIR16A8,
33143 +  BFD_RELOC_H8_DIR16R8,
33144 +  BFD_RELOC_H8_DIR24A8,
33145 +  BFD_RELOC_H8_DIR24R8,
33146 +  BFD_RELOC_H8_DIR32A16,
33147 +
33148 +/* Sony Xstormy16 Relocations.  */
33149 +  BFD_RELOC_XSTORMY16_REL_12,
33150 +  BFD_RELOC_XSTORMY16_12,
33151 +  BFD_RELOC_XSTORMY16_24,
33152 +  BFD_RELOC_XSTORMY16_FPTR16,
33153 +
33154 +/* Relocations used by VAX ELF.  */
33155 +  BFD_RELOC_VAX_GLOB_DAT,
33156 +  BFD_RELOC_VAX_JMP_SLOT,
33157 +  BFD_RELOC_VAX_RELATIVE,
33158 +
33159 +/* Morpho MS1 - 16 bit immediate relocation.  */
33160 +  BFD_RELOC_MS1_PC16,
33161 +
33162 +/* Morpho MS1 - Hi 16 bits of an address.  */
33163 +  BFD_RELOC_MS1_HI16,
33164 +
33165 +/* Morpho MS1 - Low 16 bits of an address.  */
33166 +  BFD_RELOC_MS1_LO16,
33167 +
33168 +/* Morpho MS1 - Used to tell the linker which vtable entries are used.  */
33169 +  BFD_RELOC_MS1_GNU_VTINHERIT,
33170 +
33171 +/* Morpho MS1 - Used to tell the linker which vtable entries are used.  */
33172 +  BFD_RELOC_MS1_GNU_VTENTRY,
33173 +
33174 +/* msp430 specific relocation codes  */
33175 +  BFD_RELOC_MSP430_10_PCREL,
33176 +  BFD_RELOC_MSP430_16_PCREL,
33177 +  BFD_RELOC_MSP430_16,
33178 +  BFD_RELOC_MSP430_16_PCREL_BYTE,
33179 +  BFD_RELOC_MSP430_16_BYTE,
33180 +  BFD_RELOC_MSP430_2X_PCREL,
33181 +  BFD_RELOC_MSP430_RL_PCREL,
33182 +
33183 +/* IQ2000 Relocations.  */
33184 +  BFD_RELOC_IQ2000_OFFSET_16,
33185 +  BFD_RELOC_IQ2000_OFFSET_21,
33186 +  BFD_RELOC_IQ2000_UHI16,
33187 +
33188 +/* Special Xtensa relocation used only by PLT entries in ELF shared
33189 +objects to indicate that the runtime linker should set the value
33190 +to one of its own internal functions or data structures.  */
33191 +  BFD_RELOC_XTENSA_RTLD,
33192 +
33193 +/* Xtensa relocations for ELF shared objects.  */
33194 +  BFD_RELOC_XTENSA_GLOB_DAT,
33195 +  BFD_RELOC_XTENSA_JMP_SLOT,
33196 +  BFD_RELOC_XTENSA_RELATIVE,
33197 +
33198 +/* Xtensa relocation used in ELF object files for symbols that may require
33199 +PLT entries.  Otherwise, this is just a generic 32-bit relocation.  */
33200 +  BFD_RELOC_XTENSA_PLT,
33201 +
33202 +/* Xtensa relocations to mark the difference of two local symbols.
33203 +These are only needed to support linker relaxation and can be ignored
33204 +when not relaxing.  The field is set to the value of the difference
33205 +assuming no relaxation.  The relocation encodes the position of the
33206 +first symbol so the linker can determine whether to adjust the field
33207 +value.  */
33208 +  BFD_RELOC_XTENSA_DIFF8,
33209 +  BFD_RELOC_XTENSA_DIFF16,
33210 +  BFD_RELOC_XTENSA_DIFF32,
33211 +
33212 +/* Generic Xtensa relocations for instruction operands.  Only the slot
33213 +number is encoded in the relocation.  The relocation applies to the
33214 +last PC-relative immediate operand, or if there are no PC-relative
33215 +immediates, to the last immediate operand.  */
33216 +  BFD_RELOC_XTENSA_SLOT0_OP,
33217 +  BFD_RELOC_XTENSA_SLOT1_OP,
33218 +  BFD_RELOC_XTENSA_SLOT2_OP,
33219 +  BFD_RELOC_XTENSA_SLOT3_OP,
33220 +  BFD_RELOC_XTENSA_SLOT4_OP,
33221 +  BFD_RELOC_XTENSA_SLOT5_OP,
33222 +  BFD_RELOC_XTENSA_SLOT6_OP,
33223 +  BFD_RELOC_XTENSA_SLOT7_OP,
33224 +  BFD_RELOC_XTENSA_SLOT8_OP,
33225 +  BFD_RELOC_XTENSA_SLOT9_OP,
33226 +  BFD_RELOC_XTENSA_SLOT10_OP,
33227 +  BFD_RELOC_XTENSA_SLOT11_OP,
33228 +  BFD_RELOC_XTENSA_SLOT12_OP,
33229 +  BFD_RELOC_XTENSA_SLOT13_OP,
33230 +  BFD_RELOC_XTENSA_SLOT14_OP,
33231 +
33232 +/* Alternate Xtensa relocations.  Only the slot is encoded in the
33233 +relocation.  The meaning of these relocations is opcode-specific.  */
33234 +  BFD_RELOC_XTENSA_SLOT0_ALT,
33235 +  BFD_RELOC_XTENSA_SLOT1_ALT,
33236 +  BFD_RELOC_XTENSA_SLOT2_ALT,
33237 +  BFD_RELOC_XTENSA_SLOT3_ALT,
33238 +  BFD_RELOC_XTENSA_SLOT4_ALT,
33239 +  BFD_RELOC_XTENSA_SLOT5_ALT,
33240 +  BFD_RELOC_XTENSA_SLOT6_ALT,
33241 +  BFD_RELOC_XTENSA_SLOT7_ALT,
33242 +  BFD_RELOC_XTENSA_SLOT8_ALT,
33243 +  BFD_RELOC_XTENSA_SLOT9_ALT,
33244 +  BFD_RELOC_XTENSA_SLOT10_ALT,
33245 +  BFD_RELOC_XTENSA_SLOT11_ALT,
33246 +  BFD_RELOC_XTENSA_SLOT12_ALT,
33247 +  BFD_RELOC_XTENSA_SLOT13_ALT,
33248 +  BFD_RELOC_XTENSA_SLOT14_ALT,
33249 +
33250 +/* Xtensa relocations for backward compatibility.  These have all been
33251 +replaced by BFD_RELOC_XTENSA_SLOT0_OP.  */
33252 +  BFD_RELOC_XTENSA_OP0,
33253 +  BFD_RELOC_XTENSA_OP1,
33254 +  BFD_RELOC_XTENSA_OP2,
33255 +
33256 +/* Xtensa relocation to mark that the assembler expanded the
33257 +instructions from an original target.  The expansion size is
33258 +encoded in the reloc size.  */
33259 +  BFD_RELOC_XTENSA_ASM_EXPAND,
33260 +
33261 +/* Xtensa relocation to mark that the linker should simplify
33262 +assembler-expanded instructions.  This is commonly used
33263 +internally by the linker after analysis of a
33264 +BFD_RELOC_XTENSA_ASM_EXPAND.  */
33265 +  BFD_RELOC_XTENSA_ASM_SIMPLIFY,
33266 +  BFD_RELOC_UNUSED };
33267 +typedef enum bfd_reloc_code_real bfd_reloc_code_real_type;
33268 +reloc_howto_type *bfd_reloc_type_lookup
33269 +   (bfd *abfd, bfd_reloc_code_real_type code);
33270 +
33271 +const char *bfd_get_reloc_code_name (bfd_reloc_code_real_type code);
33272 +
33273 +/* Extracted from syms.c.  */
33274 +
33275 +typedef struct bfd_symbol
33276 +{
33277 +  /* A pointer to the BFD which owns the symbol. This information
33278 +     is necessary so that a back end can work out what additional
33279 +     information (invisible to the application writer) is carried
33280 +     with the symbol.
33281 +
33282 +     This field is *almost* redundant, since you can use section->owner
33283 +     instead, except that some symbols point to the global sections
33284 +     bfd_{abs,com,und}_section.  This could be fixed by making
33285 +     these globals be per-bfd (or per-target-flavor).  FIXME.  */
33286 +  struct bfd *the_bfd; /* Use bfd_asymbol_bfd(sym) to access this field.  */
33287 +
33288 +  /* The text of the symbol. The name is left alone, and not copied; the
33289 +     application may not alter it.  */
33290 +  const char *name;
33291 +
33292 +  /* The value of the symbol.  This really should be a union of a
33293 +     numeric value with a pointer, since some flags indicate that
33294 +     a pointer to another symbol is stored here.  */
33295 +  symvalue value;
33296 +
33297 +  /* Attributes of a symbol.  */
33298 +#define BSF_NO_FLAGS    0x00
33299 +
33300 +  /* The symbol has local scope; <<static>> in <<C>>. The value
33301 +     is the offset into the section of the data.  */
33302 +#define BSF_LOCAL      0x01
33303 +
33304 +  /* The symbol has global scope; initialized data in <<C>>. The
33305 +     value is the offset into the section of the data.  */
33306 +#define BSF_GLOBAL     0x02
33307 +
33308 +  /* The symbol has global scope and is exported. The value is
33309 +     the offset into the section of the data.  */
33310 +#define BSF_EXPORT     BSF_GLOBAL /* No real difference.  */
33311 +
33312 +  /* A normal C symbol would be one of:
33313 +     <<BSF_LOCAL>>, <<BSF_FORT_COMM>>,  <<BSF_UNDEFINED>> or
33314 +     <<BSF_GLOBAL>>.  */
33315 +
33316 +  /* The symbol is a debugging record. The value has an arbitrary
33317 +     meaning, unless BSF_DEBUGGING_RELOC is also set.  */
33318 +#define BSF_DEBUGGING  0x08
33319 +
33320 +  /* The symbol denotes a function entry point.  Used in ELF,
33321 +     perhaps others someday.  */
33322 +#define BSF_FUNCTION    0x10
33323 +
33324 +  /* Used by the linker.  */
33325 +#define BSF_KEEP        0x20
33326 +#define BSF_KEEP_G      0x40
33327 +
33328 +  /* A weak global symbol, overridable without warnings by
33329 +     a regular global symbol of the same name.  */
33330 +#define BSF_WEAK        0x80
33331 +
33332 +  /* This symbol was created to point to a section, e.g. ELF's
33333 +     STT_SECTION symbols.  */
33334 +#define BSF_SECTION_SYM 0x100
33335 +
33336 +  /* The symbol used to be a common symbol, but now it is
33337 +     allocated.  */
33338 +#define BSF_OLD_COMMON  0x200
33339 +
33340 +  /* The default value for common data.  */
33341 +#define BFD_FORT_COMM_DEFAULT_VALUE 0
33342 +
33343 +  /* In some files the type of a symbol sometimes alters its
33344 +     location in an output file - ie in coff a <<ISFCN>> symbol
33345 +     which is also <<C_EXT>> symbol appears where it was
33346 +     declared and not at the end of a section.  This bit is set
33347 +     by the target BFD part to convey this information.  */
33348 +#define BSF_NOT_AT_END    0x400
33349 +
33350 +  /* Signal that the symbol is the label of constructor section.  */
33351 +#define BSF_CONSTRUCTOR   0x800
33352 +
33353 +  /* Signal that the symbol is a warning symbol.  The name is a
33354 +     warning.  The name of the next symbol is the one to warn about;
33355 +     if a reference is made to a symbol with the same name as the next
33356 +     symbol, a warning is issued by the linker.  */
33357 +#define BSF_WARNING       0x1000
33358 +
33359 +  /* Signal that the symbol is indirect.  This symbol is an indirect
33360 +     pointer to the symbol with the same name as the next symbol.  */
33361 +#define BSF_INDIRECT      0x2000
33362 +
33363 +  /* BSF_FILE marks symbols that contain a file name.  This is used
33364 +     for ELF STT_FILE symbols.  */
33365 +#define BSF_FILE          0x4000
33366 +
33367 +  /* Symbol is from dynamic linking information.  */
33368 +#define BSF_DYNAMIC       0x8000
33369 +
33370 +  /* The symbol denotes a data object.  Used in ELF, and perhaps
33371 +     others someday.  */
33372 +#define BSF_OBJECT        0x10000
33373 +
33374 +  /* This symbol is a debugging symbol.  The value is the offset
33375 +     into the section of the data.  BSF_DEBUGGING should be set
33376 +     as well.  */
33377 +#define BSF_DEBUGGING_RELOC 0x20000
33378 +
33379 +  /* This symbol is thread local.  Used in ELF.  */
33380 +#define BSF_THREAD_LOCAL  0x40000
33381 +
33382 +  flagword flags;
33383 +
33384 +  /* A pointer to the section to which this symbol is
33385 +     relative.  This will always be non NULL, there are special
33386 +     sections for undefined and absolute symbols.  */
33387 +  struct bfd_section *section;
33388 +
33389 +  /* Back end special data.  */
33390 +  union
33391 +    {
33392 +      void *p;
33393 +      bfd_vma i;
33394 +    }
33395 +  udata;
33396 +}
33397 +asymbol;
33398 +
33399 +#define bfd_get_symtab_upper_bound(abfd) \
33400 +     BFD_SEND (abfd, _bfd_get_symtab_upper_bound, (abfd))
33401 +
33402 +bfd_boolean bfd_is_local_label (bfd *abfd, asymbol *sym);
33403 +
33404 +bfd_boolean bfd_is_local_label_name (bfd *abfd, const char *name);
33405 +
33406 +#define bfd_is_local_label_name(abfd, name) \
33407 +  BFD_SEND (abfd, _bfd_is_local_label_name, (abfd, name))
33408 +
33409 +bfd_boolean bfd_is_target_special_symbol (bfd *abfd, asymbol *sym);
33410 +
33411 +#define bfd_is_target_special_symbol(abfd, sym) \
33412 +  BFD_SEND (abfd, _bfd_is_target_special_symbol, (abfd, sym))
33413 +
33414 +#define bfd_canonicalize_symtab(abfd, location) \
33415 +  BFD_SEND (abfd, _bfd_canonicalize_symtab, (abfd, location))
33416 +
33417 +bfd_boolean bfd_set_symtab
33418 +   (bfd *abfd, asymbol **location, unsigned int count);
33419 +
33420 +void bfd_print_symbol_vandf (bfd *abfd, void *file, asymbol *symbol);
33421 +
33422 +#define bfd_make_empty_symbol(abfd) \
33423 +  BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd))
33424 +
33425 +asymbol *_bfd_generic_make_empty_symbol (bfd *);
33426 +
33427 +#define bfd_make_debug_symbol(abfd,ptr,size) \
33428 +  BFD_SEND (abfd, _bfd_make_debug_symbol, (abfd, ptr, size))
33429 +
33430 +int bfd_decode_symclass (asymbol *symbol);
33431 +
33432 +bfd_boolean bfd_is_undefined_symclass (int symclass);
33433 +
33434 +void bfd_symbol_info (asymbol *symbol, symbol_info *ret);
33435 +
33436 +bfd_boolean bfd_copy_private_symbol_data
33437 +   (bfd *ibfd, asymbol *isym, bfd *obfd, asymbol *osym);
33438 +
33439 +#define bfd_copy_private_symbol_data(ibfd, isymbol, obfd, osymbol) \
33440 +  BFD_SEND (obfd, _bfd_copy_private_symbol_data, \
33441 +            (ibfd, isymbol, obfd, osymbol))
33442 +
33443 +/* Extracted from bfd.c.  */
33444 +struct bfd
33445 +{
33446 +  /* A unique identifier of the BFD  */
33447 +  unsigned int id;
33448 +
33449 +  /* The filename the application opened the BFD with.  */
33450 +  const char *filename;
33451 +
33452 +  /* A pointer to the target jump table.  */
33453 +  const struct bfd_target *xvec;
33454 +
33455 +  /* The IOSTREAM, and corresponding IO vector that provide access
33456 +     to the file backing the BFD.  */
33457 +  void *iostream;
33458 +  const struct bfd_iovec *iovec;
33459 +
33460 +  /* Is the file descriptor being cached?  That is, can it be closed as
33461 +     needed, and re-opened when accessed later?  */
33462 +  bfd_boolean cacheable;
33463 +
33464 +  /* Marks whether there was a default target specified when the
33465 +     BFD was opened. This is used to select which matching algorithm
33466 +     to use to choose the back end.  */
33467 +  bfd_boolean target_defaulted;
33468 +
33469 +  /* The caching routines use these to maintain a
33470 +     least-recently-used list of BFDs.  */
33471 +  struct bfd *lru_prev, *lru_next;
33472 +
33473 +  /* When a file is closed by the caching routines, BFD retains
33474 +     state information on the file here...  */
33475 +  ufile_ptr where;
33476 +
33477 +  /* ... and here: (``once'' means at least once).  */
33478 +  bfd_boolean opened_once;
33479 +
33480 +  /* Set if we have a locally maintained mtime value, rather than
33481 +     getting it from the file each time.  */
33482 +  bfd_boolean mtime_set;
33483 +
33484 +  /* File modified time, if mtime_set is TRUE.  */
33485 +  long mtime;
33486 +
33487 +  /* Reserved for an unimplemented file locking extension.  */
33488 +  int ifd;
33489 +
33490 +  /* The format which belongs to the BFD. (object, core, etc.)  */
33491 +  bfd_format format;
33492 +
33493 +  /* The direction with which the BFD was opened.  */
33494 +  enum bfd_direction
33495 +    {
33496 +      no_direction = 0,
33497 +      read_direction = 1,
33498 +      write_direction = 2,
33499 +      both_direction = 3
33500 +    }
33501 +  direction;
33502 +
33503 +  /* Format_specific flags.  */
33504 +  flagword flags;
33505 +
33506 +  /* Currently my_archive is tested before adding origin to
33507 +     anything. I believe that this can become always an add of
33508 +     origin, with origin set to 0 for non archive files.  */
33509 +  ufile_ptr origin;
33510 +
33511 +  /* Remember when output has begun, to stop strange things
33512 +     from happening.  */
33513 +  bfd_boolean output_has_begun;
33514 +
33515 +  /* A hash table for section names.  */
33516 +  struct bfd_hash_table section_htab;
33517 +
33518 +  /* Pointer to linked list of sections.  */
33519 +  struct bfd_section *sections;
33520 +
33521 +  /* The last section on the section list.  */
33522 +  struct bfd_section *section_last;
33523 +
33524 +  /* The number of sections.  */
33525 +  unsigned int section_count;
33526 +
33527 +  /* Stuff only useful for object files:
33528 +     The start address.  */
33529 +  bfd_vma start_address;
33530 +
33531 +  /* Used for input and output.  */
33532 +  unsigned int symcount;
33533 +
33534 +  /* Symbol table for output BFD (with symcount entries).  */
33535 +  struct bfd_symbol  **outsymbols;
33536 +
33537 +  /* Used for slurped dynamic symbol tables.  */
33538 +  unsigned int dynsymcount;
33539 +
33540 +  /* Pointer to structure which contains architecture information.  */
33541 +  const struct bfd_arch_info *arch_info;
33542 +
33543 +  /* Flag set if symbols from this BFD should not be exported.  */
33544 +  bfd_boolean no_export;
33545 +
33546 +  /* Stuff only useful for archives.  */
33547 +  void *arelt_data;
33548 +  struct bfd *my_archive;      /* The containing archive BFD.  */
33549 +  struct bfd *next;            /* The next BFD in the archive.  */
33550 +  struct bfd *archive_head;    /* The first BFD in the archive.  */
33551 +  bfd_boolean has_armap;
33552 +
33553 +  /* A chain of BFD structures involved in a link.  */
33554 +  struct bfd *link_next;
33555 +
33556 +  /* A field used by _bfd_generic_link_add_archive_symbols.  This will
33557 +     be used only for archive elements.  */
33558 +  int archive_pass;
33559 +
33560 +  /* Used by the back end to hold private data.  */
33561 +  union
33562 +    {
33563 +      struct aout_data_struct *aout_data;
33564 +      struct artdata *aout_ar_data;
33565 +      struct _oasys_data *oasys_obj_data;
33566 +      struct _oasys_ar_data *oasys_ar_data;
33567 +      struct coff_tdata *coff_obj_data;
33568 +      struct pe_tdata *pe_obj_data;
33569 +      struct xcoff_tdata *xcoff_obj_data;
33570 +      struct ecoff_tdata *ecoff_obj_data;
33571 +      struct ieee_data_struct *ieee_data;
33572 +      struct ieee_ar_data_struct *ieee_ar_data;
33573 +      struct srec_data_struct *srec_data;
33574 +      struct ihex_data_struct *ihex_data;
33575 +      struct tekhex_data_struct *tekhex_data;
33576 +      struct elf_obj_tdata *elf_obj_data;
33577 +      struct nlm_obj_tdata *nlm_obj_data;
33578 +      struct bout_data_struct *bout_data;
33579 +      struct mmo_data_struct *mmo_data;
33580 +      struct sun_core_struct *sun_core_data;
33581 +      struct sco5_core_struct *sco5_core_data;
33582 +      struct trad_core_struct *trad_core_data;
33583 +      struct som_data_struct *som_data;
33584 +      struct hpux_core_struct *hpux_core_data;
33585 +      struct hppabsd_core_struct *hppabsd_core_data;
33586 +      struct sgi_core_struct *sgi_core_data;
33587 +      struct lynx_core_struct *lynx_core_data;
33588 +      struct osf_core_struct *osf_core_data;
33589 +      struct cisco_core_struct *cisco_core_data;
33590 +      struct versados_data_struct *versados_data;
33591 +      struct netbsd_core_struct *netbsd_core_data;
33592 +      struct mach_o_data_struct *mach_o_data;
33593 +      struct mach_o_fat_data_struct *mach_o_fat_data;
33594 +      struct bfd_pef_data_struct *pef_data;
33595 +      struct bfd_pef_xlib_data_struct *pef_xlib_data;
33596 +      struct bfd_sym_data_struct *sym_data;
33597 +      void *any;
33598 +    }
33599 +  tdata;
33600 +
33601 +  /* Used by the application to hold private data.  */
33602 +  void *usrdata;
33603 +
33604 +  /* Where all the allocated stuff under this BFD goes.  This is a
33605 +     struct objalloc *, but we use void * to avoid requiring the inclusion
33606 +     of objalloc.h.  */
33607 +  void *memory;
33608 +};
33609 +
33610 +typedef enum bfd_error
33611 +{
33612 +  bfd_error_no_error = 0,
33613 +  bfd_error_system_call,
33614 +  bfd_error_invalid_target,
33615 +  bfd_error_wrong_format,
33616 +  bfd_error_wrong_object_format,
33617 +  bfd_error_invalid_operation,
33618 +  bfd_error_no_memory,
33619 +  bfd_error_no_symbols,
33620 +  bfd_error_no_armap,
33621 +  bfd_error_no_more_archived_files,
33622 +  bfd_error_malformed_archive,
33623 +  bfd_error_file_not_recognized,
33624 +  bfd_error_file_ambiguously_recognized,
33625 +  bfd_error_no_contents,
33626 +  bfd_error_nonrepresentable_section,
33627 +  bfd_error_no_debug_section,
33628 +  bfd_error_bad_value,
33629 +  bfd_error_file_truncated,
33630 +  bfd_error_file_too_big,
33631 +  bfd_error_invalid_error_code
33632 +}
33633 +bfd_error_type;
33634 +
33635 +bfd_error_type bfd_get_error (void);
33636 +
33637 +void bfd_set_error (bfd_error_type error_tag);
33638 +
33639 +const char *bfd_errmsg (bfd_error_type error_tag);
33640 +
33641 +void bfd_perror (const char *message);
33642 +
33643 +typedef void (*bfd_error_handler_type) (const char *, ...);
33644 +
33645 +bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
33646 +
33647 +void bfd_set_error_program_name (const char *);
33648 +
33649 +bfd_error_handler_type bfd_get_error_handler (void);
33650 +
33651 +long bfd_get_reloc_upper_bound (bfd *abfd, asection *sect);
33652 +
33653 +long bfd_canonicalize_reloc
33654 +   (bfd *abfd, asection *sec, arelent **loc, asymbol **syms);
33655 +
33656 +void bfd_set_reloc
33657 +   (bfd *abfd, asection *sec, arelent **rel, unsigned int count);
33658 +
33659 +bfd_boolean bfd_set_file_flags (bfd *abfd, flagword flags);
33660 +
33661 +int bfd_get_arch_size (bfd *abfd);
33662 +
33663 +int bfd_get_sign_extend_vma (bfd *abfd);
33664 +
33665 +bfd_boolean bfd_set_start_address (bfd *abfd, bfd_vma vma);
33666 +
33667 +unsigned int bfd_get_gp_size (bfd *abfd);
33668 +
33669 +void bfd_set_gp_size (bfd *abfd, unsigned int i);
33670 +
33671 +bfd_vma bfd_scan_vma (const char *string, const char **end, int base);
33672 +
33673 +bfd_boolean bfd_copy_private_header_data (bfd *ibfd, bfd *obfd);
33674 +
33675 +#define bfd_copy_private_header_data(ibfd, obfd) \
33676 +     BFD_SEND (obfd, _bfd_copy_private_header_data, \
33677 +               (ibfd, obfd))
33678 +bfd_boolean bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd);
33679 +
33680 +#define bfd_copy_private_bfd_data(ibfd, obfd) \
33681 +     BFD_SEND (obfd, _bfd_copy_private_bfd_data, \
33682 +               (ibfd, obfd))
33683 +bfd_boolean bfd_merge_private_bfd_data (bfd *ibfd, bfd *obfd);
33684 +
33685 +#define bfd_merge_private_bfd_data(ibfd, obfd) \
33686 +     BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
33687 +               (ibfd, obfd))
33688 +bfd_boolean bfd_set_private_flags (bfd *abfd, flagword flags);
33689 +
33690 +#define bfd_set_private_flags(abfd, flags) \
33691 +     BFD_SEND (abfd, _bfd_set_private_flags, (abfd, flags))
33692 +#define bfd_sizeof_headers(abfd, reloc) \
33693 +       BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
33694 +
33695 +#define bfd_find_nearest_line(abfd, sec, syms, off, file, func, line) \
33696 +       BFD_SEND (abfd, _bfd_find_nearest_line, \
33697 +                 (abfd, sec, syms, off, file, func, line))
33698 +
33699 +#define bfd_find_line(abfd, syms, sym, file, line) \
33700 +       BFD_SEND (abfd, _bfd_find_line, \
33701 +                 (abfd, syms, sym, file, line))
33702 +
33703 +#define bfd_find_inliner_info(abfd, file, func, line) \
33704 +       BFD_SEND (abfd, _bfd_find_inliner_info, \
33705 +                 (abfd, file, func, line))
33706 +
33707 +#define bfd_debug_info_start(abfd) \
33708 +       BFD_SEND (abfd, _bfd_debug_info_start, (abfd))
33709 +
33710 +#define bfd_debug_info_end(abfd) \
33711 +       BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
33712 +
33713 +#define bfd_debug_info_accumulate(abfd, section) \
33714 +       BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
33715 +
33716 +#define bfd_stat_arch_elt(abfd, stat) \
33717 +       BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
33718 +
33719 +#define bfd_update_armap_timestamp(abfd) \
33720 +       BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
33721 +
33722 +#define bfd_set_arch_mach(abfd, arch, mach)\
33723 +       BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
33724 +
33725 +#define bfd_relax_section(abfd, section, link_info, again) \
33726 +       BFD_SEND (abfd, _bfd_relax_section, (abfd, section, link_info, again))
33727 +
33728 +#define bfd_gc_sections(abfd, link_info) \
33729 +       BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
33730 +
33731 +#define bfd_merge_sections(abfd, link_info) \
33732 +       BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
33733 +
33734 +#define bfd_is_group_section(abfd, sec) \
33735 +       BFD_SEND (abfd, _bfd_is_group_section, (abfd, sec))
33736 +
33737 +#define bfd_discard_group(abfd, sec) \
33738 +       BFD_SEND (abfd, _bfd_discard_group, (abfd, sec))
33739 +
33740 +#define bfd_link_hash_table_create(abfd) \
33741 +       BFD_SEND (abfd, _bfd_link_hash_table_create, (abfd))
33742 +
33743 +#define bfd_link_hash_table_free(abfd, hash) \
33744 +       BFD_SEND (abfd, _bfd_link_hash_table_free, (hash))
33745 +
33746 +#define bfd_link_add_symbols(abfd, info) \
33747 +       BFD_SEND (abfd, _bfd_link_add_symbols, (abfd, info))
33748 +
33749 +#define bfd_link_just_syms(abfd, sec, info) \
33750 +       BFD_SEND (abfd, _bfd_link_just_syms, (sec, info))
33751 +
33752 +#define bfd_final_link(abfd, info) \
33753 +       BFD_SEND (abfd, _bfd_final_link, (abfd, info))
33754 +
33755 +#define bfd_free_cached_info(abfd) \
33756 +       BFD_SEND (abfd, _bfd_free_cached_info, (abfd))
33757 +
33758 +#define bfd_get_dynamic_symtab_upper_bound(abfd) \
33759 +       BFD_SEND (abfd, _bfd_get_dynamic_symtab_upper_bound, (abfd))
33760 +
33761 +#define bfd_print_private_bfd_data(abfd, file)\
33762 +       BFD_SEND (abfd, _bfd_print_private_bfd_data, (abfd, file))
33763 +
33764 +#define bfd_canonicalize_dynamic_symtab(abfd, asymbols) \
33765 +       BFD_SEND (abfd, _bfd_canonicalize_dynamic_symtab, (abfd, asymbols))
33766 +
33767 +#define bfd_get_synthetic_symtab(abfd, count, syms, dyncount, dynsyms, ret) \
33768 +       BFD_SEND (abfd, _bfd_get_synthetic_symtab, (abfd, count, syms, \
33769 +                                                   dyncount, dynsyms, ret))
33770 +
33771 +#define bfd_get_dynamic_reloc_upper_bound(abfd) \
33772 +       BFD_SEND (abfd, _bfd_get_dynamic_reloc_upper_bound, (abfd))
33773 +
33774 +#define bfd_canonicalize_dynamic_reloc(abfd, arels, asyms) \
33775 +       BFD_SEND (abfd, _bfd_canonicalize_dynamic_reloc, (abfd, arels, asyms))
33776 +
33777 +extern bfd_byte *bfd_get_relocated_section_contents
33778 +  (bfd *, struct bfd_link_info *, struct bfd_link_order *, bfd_byte *,
33779 +   bfd_boolean, asymbol **);
33780 +
33781 +bfd_boolean bfd_alt_mach_code (bfd *abfd, int alternative);
33782 +
33783 +struct bfd_preserve
33784 +{
33785 +  void *marker;
33786 +  void *tdata;
33787 +  flagword flags;
33788 +  const struct bfd_arch_info *arch_info;
33789 +  struct bfd_section *sections;
33790 +  struct bfd_section *section_last;
33791 +  unsigned int section_count;
33792 +  struct bfd_hash_table section_htab;
33793 +};
33794 +
33795 +bfd_boolean bfd_preserve_save (bfd *, struct bfd_preserve *);
33796 +
33797 +void bfd_preserve_restore (bfd *, struct bfd_preserve *);
33798 +
33799 +void bfd_preserve_finish (bfd *, struct bfd_preserve *);
33800 +
33801 +/* Extracted from archive.c.  */
33802 +symindex bfd_get_next_mapent
33803 +   (bfd *abfd, symindex previous, carsym **sym);
33804 +
33805 +bfd_boolean bfd_set_archive_head (bfd *output, bfd *new_head);
33806 +
33807 +bfd *bfd_openr_next_archived_file (bfd *archive, bfd *previous);
33808 +
33809 +/* Extracted from corefile.c.  */
33810 +const char *bfd_core_file_failing_command (bfd *abfd);
33811 +
33812 +int bfd_core_file_failing_signal (bfd *abfd);
33813 +
33814 +bfd_boolean core_file_matches_executable_p
33815 +   (bfd *core_bfd, bfd *exec_bfd);
33816 +
33817 +/* Extracted from targets.c.  */
33818 +#define BFD_SEND(bfd, message, arglist) \
33819 +  ((*((bfd)->xvec->message)) arglist)
33820 +
33821 +#ifdef DEBUG_BFD_SEND
33822 +#undef BFD_SEND
33823 +#define BFD_SEND(bfd, message, arglist) \
33824 +  (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
33825 +    ((*((bfd)->xvec->message)) arglist) : \
33826 +    (bfd_assert (__FILE__,__LINE__), NULL))
33827 +#endif
33828 +#define BFD_SEND_FMT(bfd, message, arglist) \
33829 +  (((bfd)->xvec->message[(int) ((bfd)->format)]) arglist)
33830 +
33831 +#ifdef DEBUG_BFD_SEND
33832 +#undef BFD_SEND_FMT
33833 +#define BFD_SEND_FMT(bfd, message, arglist) \
33834 +  (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
33835 +   (((bfd)->xvec->message[(int) ((bfd)->format)]) arglist) : \
33836 +   (bfd_assert (__FILE__,__LINE__), NULL))
33837 +#endif
33838 +
33839 +enum bfd_flavour
33840 +{
33841 +  bfd_target_unknown_flavour,
33842 +  bfd_target_aout_flavour,
33843 +  bfd_target_coff_flavour,
33844 +  bfd_target_ecoff_flavour,
33845 +  bfd_target_xcoff_flavour,
33846 +  bfd_target_elf_flavour,
33847 +  bfd_target_ieee_flavour,
33848 +  bfd_target_nlm_flavour,
33849 +  bfd_target_oasys_flavour,
33850 +  bfd_target_tekhex_flavour,
33851 +  bfd_target_srec_flavour,
33852 +  bfd_target_ihex_flavour,
33853 +  bfd_target_som_flavour,
33854 +  bfd_target_os9k_flavour,
33855 +  bfd_target_versados_flavour,
33856 +  bfd_target_msdos_flavour,
33857 +  bfd_target_ovax_flavour,
33858 +  bfd_target_evax_flavour,
33859 +  bfd_target_mmo_flavour,
33860 +  bfd_target_mach_o_flavour,
33861 +  bfd_target_pef_flavour,
33862 +  bfd_target_pef_xlib_flavour,
33863 +  bfd_target_sym_flavour
33864 +};
33865 +
33866 +enum bfd_endian { BFD_ENDIAN_BIG, BFD_ENDIAN_LITTLE, BFD_ENDIAN_UNKNOWN };
33867 +
33868 +/* Forward declaration.  */
33869 +typedef struct bfd_link_info _bfd_link_info;
33870 +
33871 +typedef struct bfd_target
33872 +{
33873 +  /* Identifies the kind of target, e.g., SunOS4, Ultrix, etc.  */
33874 +  char *name;
33875 +
33876 + /* The "flavour" of a back end is a general indication about
33877 +    the contents of a file.  */
33878 +  enum bfd_flavour flavour;
33879 +
33880 +  /* The order of bytes within the data area of a file.  */
33881 +  enum bfd_endian byteorder;
33882 +
33883 + /* The order of bytes within the header parts of a file.  */
33884 +  enum bfd_endian header_byteorder;
33885 +
33886 +  /* A mask of all the flags which an executable may have set -
33887 +     from the set <<BFD_NO_FLAGS>>, <<HAS_RELOC>>, ...<<D_PAGED>>.  */
33888 +  flagword object_flags;
33889 +
33890 + /* A mask of all the flags which a section may have set - from
33891 +    the set <<SEC_NO_FLAGS>>, <<SEC_ALLOC>>, ...<<SET_NEVER_LOAD>>.  */
33892 +  flagword section_flags;
33893 +
33894 + /* The character normally found at the front of a symbol.
33895 +    (if any), perhaps `_'.  */
33896 +  char symbol_leading_char;
33897 +
33898 + /* The pad character for file names within an archive header.  */
33899 +  char ar_pad_char;
33900 +
33901 +  /* The maximum number of characters in an archive header.  */
33902 +  unsigned short ar_max_namelen;
33903 +
33904 +  /* Entries for byte swapping for data. These are different from the
33905 +     other entry points, since they don't take a BFD as the first argument.
33906 +     Certain other handlers could do the same.  */
33907 +  bfd_uint64_t   (*bfd_getx64) (const void *);
33908 +  bfd_int64_t    (*bfd_getx_signed_64) (const void *);
33909 +  void           (*bfd_putx64) (bfd_uint64_t, void *);
33910 +  bfd_vma        (*bfd_getx32) (const void *);
33911 +  bfd_signed_vma (*bfd_getx_signed_32) (const void *);
33912 +  void           (*bfd_putx32) (bfd_vma, void *);
33913 +  bfd_vma        (*bfd_getx16) (const void *);
33914 +  bfd_signed_vma (*bfd_getx_signed_16) (const void *);
33915 +  void           (*bfd_putx16) (bfd_vma, void *);
33916 +
33917 +  /* Byte swapping for the headers.  */
33918 +  bfd_uint64_t   (*bfd_h_getx64) (const void *);
33919 +  bfd_int64_t    (*bfd_h_getx_signed_64) (const void *);
33920 +  void           (*bfd_h_putx64) (bfd_uint64_t, void *);
33921 +  bfd_vma        (*bfd_h_getx32) (const void *);
33922 +  bfd_signed_vma (*bfd_h_getx_signed_32) (const void *);
33923 +  void           (*bfd_h_putx32) (bfd_vma, void *);
33924 +  bfd_vma        (*bfd_h_getx16) (const void *);
33925 +  bfd_signed_vma (*bfd_h_getx_signed_16) (const void *);
33926 +  void           (*bfd_h_putx16) (bfd_vma, void *);
33927 +
33928 +  /* Format dependent routines: these are vectors of entry points
33929 +     within the target vector structure, one for each format to check.  */
33930 +
33931 +  /* Check the format of a file being read.  Return a <<bfd_target *>> or zero.  */
33932 +  const struct bfd_target *(*_bfd_check_format[bfd_type_end]) (bfd *);
33933 +
33934 +  /* Set the format of a file being written.  */
33935 +  bfd_boolean (*_bfd_set_format[bfd_type_end]) (bfd *);
33936 +
33937 +  /* Write cached information into a file being written, at <<bfd_close>>.  */
33938 +  bfd_boolean (*_bfd_write_contents[bfd_type_end]) (bfd *);
33939 +
33940 +
33941 +  /* Generic entry points.  */
33942 +#define BFD_JUMP_TABLE_GENERIC(NAME) \
33943 +  NAME##_close_and_cleanup, \
33944 +  NAME##_bfd_free_cached_info, \
33945 +  NAME##_new_section_hook, \
33946 +  NAME##_get_section_contents, \
33947 +  NAME##_get_section_contents_in_window
33948 +
33949 +  /* Called when the BFD is being closed to do any necessary cleanup.  */
33950 +  bfd_boolean (*_close_and_cleanup) (bfd *);
33951 +  /* Ask the BFD to free all cached information.  */
33952 +  bfd_boolean (*_bfd_free_cached_info) (bfd *);
33953 +  /* Called when a new section is created.  */
33954 +  bfd_boolean (*_new_section_hook) (bfd *, sec_ptr);
33955 +  /* Read the contents of a section.  */
33956 +  bfd_boolean (*_bfd_get_section_contents)
33957 +    (bfd *, sec_ptr, void *, file_ptr, bfd_size_type);
33958 +  bfd_boolean (*_bfd_get_section_contents_in_window)
33959 +    (bfd *, sec_ptr, bfd_window *, file_ptr, bfd_size_type);
33960 +
33961 +  /* Entry points to copy private data.  */
33962 +#define BFD_JUMP_TABLE_COPY(NAME) \
33963 +  NAME##_bfd_copy_private_bfd_data, \
33964 +  NAME##_bfd_merge_private_bfd_data, \
33965 +  NAME##_bfd_copy_private_section_data, \
33966 +  NAME##_bfd_copy_private_symbol_data, \
33967 +  NAME##_bfd_copy_private_header_data, \
33968 +  NAME##_bfd_set_private_flags, \
33969 +  NAME##_bfd_print_private_bfd_data
33970 +
33971 +  /* Called to copy BFD general private data from one object file
33972 +     to another.  */
33973 +  bfd_boolean (*_bfd_copy_private_bfd_data) (bfd *, bfd *);
33974 +  /* Called to merge BFD general private data from one object file
33975 +     to a common output file when linking.  */
33976 +  bfd_boolean (*_bfd_merge_private_bfd_data) (bfd *, bfd *);
33977 +  /* Called to copy BFD private section data from one object file
33978 +     to another.  */
33979 +  bfd_boolean (*_bfd_copy_private_section_data)
33980 +    (bfd *, sec_ptr, bfd *, sec_ptr);
33981 +  /* Called to copy BFD private symbol data from one symbol
33982 +     to another.  */
33983 +  bfd_boolean (*_bfd_copy_private_symbol_data)
33984 +    (bfd *, asymbol *, bfd *, asymbol *);
33985 +  /* Called to copy BFD private header data from one object file
33986 +     to another.  */
33987 +  bfd_boolean (*_bfd_copy_private_header_data)
33988 +    (bfd *, bfd *);
33989 +  /* Called to set private backend flags.  */
33990 +  bfd_boolean (*_bfd_set_private_flags) (bfd *, flagword);
33991 +
33992 +  /* Called to print private BFD data.  */
33993 +  bfd_boolean (*_bfd_print_private_bfd_data) (bfd *, void *);
33994 +
33995 +  /* Core file entry points.  */
33996 +#define BFD_JUMP_TABLE_CORE(NAME) \
33997 +  NAME##_core_file_failing_command, \
33998 +  NAME##_core_file_failing_signal, \
33999 +  NAME##_core_file_matches_executable_p
34000 +
34001 +  char *      (*_core_file_failing_command) (bfd *);
34002 +  int         (*_core_file_failing_signal) (bfd *);
34003 +  bfd_boolean (*_core_file_matches_executable_p) (bfd *, bfd *);
34004 +
34005 +  /* Archive entry points.  */
34006 +#define BFD_JUMP_TABLE_ARCHIVE(NAME) \
34007 +  NAME##_slurp_armap, \
34008 +  NAME##_slurp_extended_name_table, \
34009 +  NAME##_construct_extended_name_table, \
34010 +  NAME##_truncate_arname, \
34011 +  NAME##_write_armap, \
34012 +  NAME##_read_ar_hdr, \
34013 +  NAME##_openr_next_archived_file, \
34014 +  NAME##_get_elt_at_index, \
34015 +  NAME##_generic_stat_arch_elt, \
34016 +  NAME##_update_armap_timestamp
34017 +
34018 +  bfd_boolean (*_bfd_slurp_armap) (bfd *);
34019 +  bfd_boolean (*_bfd_slurp_extended_name_table) (bfd *);
34020 +  bfd_boolean (*_bfd_construct_extended_name_table)
34021 +    (bfd *, char **, bfd_size_type *, const char **);
34022 +  void        (*_bfd_truncate_arname) (bfd *, const char *, char *);
34023 +  bfd_boolean (*write_armap)
34024 +    (bfd *, unsigned int, struct orl *, unsigned int, int);
34025 +  void *      (*_bfd_read_ar_hdr_fn) (bfd *);
34026 +  bfd *       (*openr_next_archived_file) (bfd *, bfd *);
34027 +#define bfd_get_elt_at_index(b,i) BFD_SEND (b, _bfd_get_elt_at_index, (b,i))
34028 +  bfd *       (*_bfd_get_elt_at_index) (bfd *, symindex);
34029 +  int         (*_bfd_stat_arch_elt) (bfd *, struct stat *);
34030 +  bfd_boolean (*_bfd_update_armap_timestamp) (bfd *);
34031 +
34032 +  /* Entry points used for symbols.  */
34033 +#define BFD_JUMP_TABLE_SYMBOLS(NAME) \
34034 +  NAME##_get_symtab_upper_bound, \
34035 +  NAME##_canonicalize_symtab, \
34036 +  NAME##_make_empty_symbol, \
34037 +  NAME##_print_symbol, \
34038 +  NAME##_get_symbol_info, \
34039 +  NAME##_bfd_is_local_label_name, \
34040 +  NAME##_bfd_is_target_special_symbol, \
34041 +  NAME##_get_lineno, \
34042 +  NAME##_find_nearest_line, \
34043 +  _bfd_generic_find_line, \
34044 +  NAME##_find_inliner_info, \
34045 +  NAME##_bfd_make_debug_symbol, \
34046 +  NAME##_read_minisymbols, \
34047 +  NAME##_minisymbol_to_symbol
34048 +
34049 +  long        (*_bfd_get_symtab_upper_bound) (bfd *);
34050 +  long        (*_bfd_canonicalize_symtab)
34051 +    (bfd *, struct bfd_symbol **);
34052 +  struct bfd_symbol *
34053 +              (*_bfd_make_empty_symbol) (bfd *);
34054 +  void        (*_bfd_print_symbol)
34055 +    (bfd *, void *, struct bfd_symbol *, bfd_print_symbol_type);
34056 +#define bfd_print_symbol(b,p,s,e) BFD_SEND (b, _bfd_print_symbol, (b,p,s,e))
34057 +  void        (*_bfd_get_symbol_info)
34058 +    (bfd *, struct bfd_symbol *, symbol_info *);
34059 +#define bfd_get_symbol_info(b,p,e) BFD_SEND (b, _bfd_get_symbol_info, (b,p,e))
34060 +  bfd_boolean (*_bfd_is_local_label_name) (bfd *, const char *);
34061 +  bfd_boolean (*_bfd_is_target_special_symbol) (bfd *, asymbol *);
34062 +  alent *     (*_get_lineno) (bfd *, struct bfd_symbol *);
34063 +  bfd_boolean (*_bfd_find_nearest_line)
34064 +    (bfd *, struct bfd_section *, struct bfd_symbol **, bfd_vma,
34065 +     const char **, const char **, unsigned int *);
34066 +  bfd_boolean (*_bfd_find_line)
34067 +    (bfd *, struct bfd_symbol **, struct bfd_symbol *,
34068 +     const char **, unsigned int *);
34069 +  bfd_boolean (*_bfd_find_inliner_info)
34070 +    (bfd *, const char **, const char **, unsigned int *);
34071 + /* Back-door to allow format-aware applications to create debug symbols
34072 +    while using BFD for everything else.  Currently used by the assembler
34073 +    when creating COFF files.  */
34074 +  asymbol *   (*_bfd_make_debug_symbol)
34075 +    (bfd *, void *, unsigned long size);
34076 +#define bfd_read_minisymbols(b, d, m, s) \
34077 +  BFD_SEND (b, _read_minisymbols, (b, d, m, s))
34078 +  long        (*_read_minisymbols)
34079 +    (bfd *, bfd_boolean, void **, unsigned int *);
34080 +#define bfd_minisymbol_to_symbol(b, d, m, f) \
34081 +  BFD_SEND (b, _minisymbol_to_symbol, (b, d, m, f))
34082 +  asymbol *   (*_minisymbol_to_symbol)
34083 +    (bfd *, bfd_boolean, const void *, asymbol *);
34084 +
34085 +  /* Routines for relocs.  */
34086 +#define BFD_JUMP_TABLE_RELOCS(NAME) \
34087 +  NAME##_get_reloc_upper_bound, \
34088 +  NAME##_canonicalize_reloc, \
34089 +  NAME##_bfd_reloc_type_lookup
34090 +
34091 +  long        (*_get_reloc_upper_bound) (bfd *, sec_ptr);
34092 +  long        (*_bfd_canonicalize_reloc)
34093 +    (bfd *, sec_ptr, arelent **, struct bfd_symbol **);
34094 +  /* See documentation on reloc types.  */
34095 +  reloc_howto_type *
34096 +              (*reloc_type_lookup) (bfd *, bfd_reloc_code_real_type);
34097 +
34098 +  /* Routines used when writing an object file.  */
34099 +#define BFD_JUMP_TABLE_WRITE(NAME) \
34100 +  NAME##_set_arch_mach, \
34101 +  NAME##_set_section_contents
34102 +
34103 +  bfd_boolean (*_bfd_set_arch_mach)
34104 +    (bfd *, enum bfd_architecture, unsigned long);
34105 +  bfd_boolean (*_bfd_set_section_contents)
34106 +    (bfd *, sec_ptr, const void *, file_ptr, bfd_size_type);
34107 +
34108 +  /* Routines used by the linker.  */
34109 +#define BFD_JUMP_TABLE_LINK(NAME) \
34110 +  NAME##_sizeof_headers, \
34111 +  NAME##_bfd_get_relocated_section_contents, \
34112 +  NAME##_bfd_relax_section, \
34113 +  NAME##_bfd_link_hash_table_create, \
34114 +  NAME##_bfd_link_hash_table_free, \
34115 +  NAME##_bfd_link_add_symbols, \
34116 +  NAME##_bfd_link_just_syms, \
34117 +  NAME##_bfd_final_link, \
34118 +  NAME##_bfd_link_split_section, \
34119 +  NAME##_bfd_gc_sections, \
34120 +  NAME##_bfd_merge_sections, \
34121 +  NAME##_bfd_is_group_section, \
34122 +  NAME##_bfd_discard_group, \
34123 +  NAME##_section_already_linked \
34124 +
34125 +  int         (*_bfd_sizeof_headers) (bfd *, bfd_boolean);
34126 +  bfd_byte *  (*_bfd_get_relocated_section_contents)
34127 +    (bfd *, struct bfd_link_info *, struct bfd_link_order *,
34128 +     bfd_byte *, bfd_boolean, struct bfd_symbol **);
34129 +
34130 +  bfd_boolean (*_bfd_relax_section)
34131 +    (bfd *, struct bfd_section *, struct bfd_link_info *, bfd_boolean *);
34132 +
34133 +  /* Create a hash table for the linker.  Different backends store
34134 +     different information in this table.  */
34135 +  struct bfd_link_hash_table *
34136 +              (*_bfd_link_hash_table_create) (bfd *);
34137 +
34138 +  /* Release the memory associated with the linker hash table.  */
34139 +  void        (*_bfd_link_hash_table_free) (struct bfd_link_hash_table *);
34140 +
34141 +  /* Add symbols from this object file into the hash table.  */
34142 +  bfd_boolean (*_bfd_link_add_symbols) (bfd *, struct bfd_link_info *);
34143 +
34144 +  /* Indicate that we are only retrieving symbol values from this section.  */
34145 +  void        (*_bfd_link_just_syms) (asection *, struct bfd_link_info *);
34146 +
34147 +  /* Do a link based on the link_order structures attached to each
34148 +     section of the BFD.  */
34149 +  bfd_boolean (*_bfd_final_link) (bfd *, struct bfd_link_info *);
34150 +
34151 +  /* Should this section be split up into smaller pieces during linking.  */
34152 +  bfd_boolean (*_bfd_link_split_section) (bfd *, struct bfd_section *);
34153 +
34154 +  /* Remove sections that are not referenced from the output.  */
34155 +  bfd_boolean (*_bfd_gc_sections) (bfd *, struct bfd_link_info *);
34156 +
34157 +  /* Attempt to merge SEC_MERGE sections.  */
34158 +  bfd_boolean (*_bfd_merge_sections) (bfd *, struct bfd_link_info *);
34159 +
34160 +  /* Is this section a member of a group?  */
34161 +  bfd_boolean (*_bfd_is_group_section) (bfd *, const struct bfd_section *);
34162 +
34163 +  /* Discard members of a group.  */
34164 +  bfd_boolean (*_bfd_discard_group) (bfd *, struct bfd_section *);
34165 +
34166 +  /* Check if SEC has been already linked during a reloceatable or
34167 +     final link.  */
34168 +  void (*_section_already_linked) (bfd *, struct bfd_section *);
34169 +
34170 +  /* Routines to handle dynamic symbols and relocs.  */
34171 +#define BFD_JUMP_TABLE_DYNAMIC(NAME) \
34172 +  NAME##_get_dynamic_symtab_upper_bound, \
34173 +  NAME##_canonicalize_dynamic_symtab, \
34174 +  NAME##_get_synthetic_symtab, \
34175 +  NAME##_get_dynamic_reloc_upper_bound, \
34176 +  NAME##_canonicalize_dynamic_reloc
34177 +
34178 +  /* Get the amount of memory required to hold the dynamic symbols.  */
34179 +  long        (*_bfd_get_dynamic_symtab_upper_bound) (bfd *);
34180 +  /* Read in the dynamic symbols.  */
34181 +  long        (*_bfd_canonicalize_dynamic_symtab)
34182 +    (bfd *, struct bfd_symbol **);
34183 +  /* Create synthetized symbols.  */
34184 +  long        (*_bfd_get_synthetic_symtab)
34185 +    (bfd *, long, struct bfd_symbol **, long, struct bfd_symbol **,
34186 +     struct bfd_symbol **);
34187 +  /* Get the amount of memory required to hold the dynamic relocs.  */
34188 +  long        (*_bfd_get_dynamic_reloc_upper_bound) (bfd *);
34189 +  /* Read in the dynamic relocs.  */
34190 +  long        (*_bfd_canonicalize_dynamic_reloc)
34191 +    (bfd *, arelent **, struct bfd_symbol **);
34192 +
34193 +  /* Opposite endian version of this target.  */
34194 +  const struct bfd_target * alternative_target;
34195 +
34196 +  /* Data for use by back-end routines, which isn't
34197 +     generic enough to belong in this structure.  */
34198 +  const void *backend_data;
34199 +
34200 +} bfd_target;
34201 +
34202 +bfd_boolean bfd_set_default_target (const char *name);
34203 +
34204 +const bfd_target *bfd_find_target (const char *target_name, bfd *abfd);
34205 +
34206 +const char ** bfd_target_list (void);
34207 +
34208 +const bfd_target *bfd_search_for_target
34209 +   (int (*search_func) (const bfd_target *, void *),
34210 +    void *);
34211 +
34212 +/* Extracted from format.c.  */
34213 +bfd_boolean bfd_check_format (bfd *abfd, bfd_format format);
34214 +
34215 +bfd_boolean bfd_check_format_matches
34216 +   (bfd *abfd, bfd_format format, char ***matching);
34217 +
34218 +bfd_boolean bfd_set_format (bfd *abfd, bfd_format format);
34219 +
34220 +const char *bfd_format_string (bfd_format format);
34221 +
34222 +/* Extracted from linker.c.  */
34223 +bfd_boolean bfd_link_split_section (bfd *abfd, asection *sec);
34224 +
34225 +#define bfd_link_split_section(abfd, sec) \
34226 +       BFD_SEND (abfd, _bfd_link_split_section, (abfd, sec))
34227 +
34228 +void bfd_section_already_linked (bfd *abfd, asection *sec);
34229 +
34230 +#define bfd_section_already_linked(abfd, sec) \
34231 +       BFD_SEND (abfd, _section_already_linked, (abfd, sec))
34232 +
34233 +/* Extracted from simple.c.  */
34234 +bfd_byte *bfd_simple_get_relocated_section_contents
34235 +   (bfd *abfd, asection *sec, bfd_byte *outbuf, asymbol **symbol_table);
34236 +
34237 +#ifdef __cplusplus
34238 +}
34239 +#endif
34240 +#endif
34241 diff -Nurp linux-2.6.22-590/include/asm-x86_64/hw_irq.h linux-2.6.22-600/include/asm-x86_64/hw_irq.h
34242 --- linux-2.6.22-590/include/asm-x86_64/hw_irq.h        2007-07-09 01:32:17.000000000 +0200
34243 +++ linux-2.6.22-600/include/asm-x86_64/hw_irq.h        2008-04-09 18:16:24.000000000 +0200
34244 @@ -30,7 +30,7 @@
34245  #define FIRST_EXTERNAL_VECTOR  0x20
34246  
34247  #define IA32_SYSCALL_VECTOR    0x80
34248 -
34249 +#define KDBENTER_VECTOR         0x81
34250  
34251  /* Reserve the lowest usable priority level 0x20 - 0x2f for triggering
34252   * cleanup after irq migration.
34253 @@ -68,8 +68,7 @@
34254  #define ERROR_APIC_VECTOR      0xfe
34255  #define RESCHEDULE_VECTOR      0xfd
34256  #define CALL_FUNCTION_VECTOR   0xfc
34257 -/* fb free - please don't readd KDB here because it's useless
34258 -   (hint - think what a NMI bit does to a vector) */
34259 +#define KDB_VECTOR             0xfb
34260  #define THERMAL_APIC_VECTOR    0xfa
34261  #define THRESHOLD_APIC_VECTOR   0xf9
34262  /* f8 free */
34263 diff -Nurp linux-2.6.22-590/include/asm-x86_64/kdb.h linux-2.6.22-600/include/asm-x86_64/kdb.h
34264 --- linux-2.6.22-590/include/asm-x86_64/kdb.h   1970-01-01 01:00:00.000000000 +0100
34265 +++ linux-2.6.22-600/include/asm-x86_64/kdb.h   2008-04-09 18:16:24.000000000 +0200
34266 @@ -0,0 +1,120 @@
34267 +#ifndef        _ASM_KDB_H
34268 +#define _ASM_KDB_H
34269 +
34270 +/*
34271 + * Kernel Debugger Architecture Dependent Global Headers
34272 + *
34273 + * This file is subject to the terms and conditions of the GNU General Public
34274 + * License.  See the file "COPYING" in the main directory of this archive
34275 + * for more details.
34276 + *
34277 + * Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
34278 + */
34279 +
34280 +       /*
34281 +        * KDB_ENTER() is a macro which causes entry into the kernel
34282 +        * debugger from any point in the kernel code stream.  If it
34283 +        * is intended to be used from interrupt level, it must  use
34284 +        * a non-maskable entry method. The vector is KDB_VECTOR,
34285 +        * defined in hw_irq.h
34286 +        */
34287 +#define KDB_ENTER()    do {if (kdb_on && !KDB_IS_RUNNING()) { asm("\tint $129\n"); }} while(0)
34288 +
34289 +       /*
34290 +        * Needed for exported symbols.
34291 +        */
34292 +typedef unsigned long kdb_machreg_t;
34293 +
34294 +#define kdb_machreg_fmt                "0x%lx"
34295 +#define kdb_machreg_fmt0       "0x%016lx"
34296 +#define kdb_bfd_vma_fmt                "0x%lx"
34297 +#define kdb_bfd_vma_fmt0       "0x%016lx"
34298 +#define kdb_elfw_addr_fmt      "0x%x"
34299 +#define kdb_elfw_addr_fmt0     "0x%016x"
34300 +
34301 +       /*
34302 +        * Per cpu arch specific kdb state.  Must be in range 0xff000000.
34303 +        */
34304 +#define KDB_STATE_A_IF         0x01000000      /* Saved IF flag */
34305 +
34306 +       /*
34307 +        * Functions to safely read and write kernel areas.  The {to,from}_xxx
34308 +        * addresses are not necessarily valid, these functions must check for
34309 +        * validity.  If the arch already supports get and put routines with
34310 +        * suitable validation and/or recovery on invalid addresses then use
34311 +        * those routines, otherwise check it yourself.
34312 +        */
34313 +
34314 +       /*
34315 +        * asm-i386 uaccess.h supplies __copy_to_user which relies on MMU to
34316 +        * trap invalid addresses in the _xxx fields.  Verify the other address
34317 +        * of the pair is valid by accessing the first and last byte ourselves,
34318 +        * then any access violations should only be caused by the _xxx
34319 +        * addresses,
34320 +        */
34321 +
34322 +#include <asm/uaccess.h>
34323 +
34324 +static inline int
34325 +__kdba_putarea_size(unsigned long to_xxx, void *from, size_t size)
34326 +{
34327 +       mm_segment_t oldfs = get_fs();
34328 +       int r;
34329 +       char c;
34330 +       c = *((volatile char *)from);
34331 +       c = *((volatile char *)from + size - 1);
34332 +
34333 +       if (to_xxx < PAGE_OFFSET) {
34334 +               return kdb_putuserarea_size(to_xxx, from, size);
34335 +       }
34336 +
34337 +       set_fs(KERNEL_DS);
34338 +       r = __copy_to_user((void *)to_xxx, from, size);
34339 +       set_fs(oldfs);
34340 +       return r;
34341 +}
34342 +
34343 +static inline int
34344 +__kdba_getarea_size(void *to, unsigned long from_xxx, size_t size)
34345 +{
34346 +       mm_segment_t oldfs = get_fs();
34347 +       int r;
34348 +       *((volatile char *)to) = '\0';
34349 +       *((volatile char *)to + size - 1) = '\0';
34350 +
34351 +       if (from_xxx < PAGE_OFFSET) {
34352 +               return kdb_getuserarea_size(to, from_xxx, size);
34353 +       }
34354 +
34355 +       set_fs(KERNEL_DS);
34356 +       r = __copy_to_user(to, (void *)from_xxx, size);
34357 +       set_fs(oldfs);
34358 +       return r;
34359 +}
34360 +
34361 +/* For numa with replicated code/data, the platform must supply its own
34362 + * kdba_putarea_size and kdba_getarea_size routines.  Without replication kdb
34363 + * uses the standard architecture routines.
34364 + */
34365 +#ifdef CONFIG_NUMA_REPLICATE
34366 +extern int kdba_putarea_size(unsigned long to_xxx, void *from, size_t size);
34367 +extern int kdba_getarea_size(void *to, unsigned long from_xxx, size_t size);
34368 +#else
34369 +#define kdba_putarea_size __kdba_putarea_size
34370 +#define kdba_getarea_size __kdba_getarea_size
34371 +#endif
34372 +
34373 +static inline int
34374 +kdba_verify_rw(unsigned long addr, size_t size)
34375 +{
34376 +       unsigned char data[size];
34377 +       return(kdba_getarea_size(data, addr, size) || kdba_putarea_size(addr, data, size));
34378 +}
34379 +
34380 +static inline unsigned long
34381 +kdba_funcptr_value(void *fp)
34382 +{
34383 +       return (unsigned long)fp;
34384 +}
34385 +
34386 +#endif /* !_ASM_KDB_H */
34387 diff -Nurp linux-2.6.22-590/include/asm-x86_64/kdbprivate.h linux-2.6.22-600/include/asm-x86_64/kdbprivate.h
34388 --- linux-2.6.22-590/include/asm-x86_64/kdbprivate.h    1970-01-01 01:00:00.000000000 +0100
34389 +++ linux-2.6.22-600/include/asm-x86_64/kdbprivate.h    2008-04-09 18:16:24.000000000 +0200
34390 @@ -0,0 +1,193 @@
34391 +#ifndef        _ASM_KDBPRIVATE_H
34392 +#define _ASM_KDBPRIVATE_H
34393 +
34394 +/*
34395 + * Kernel Debugger Architecture Dependent Private Headers
34396 + *
34397 + * This file is subject to the terms and conditions of the GNU General Public
34398 + * License.  See the file "COPYING" in the main directory of this archive
34399 + * for more details.
34400 + *
34401 + * Copyright (c) 1999-2006 Silicon Graphics, Inc.  All Rights Reserved.
34402 + */
34403 +
34404 +typedef unsigned char kdb_machinst_t;
34405 +
34406 +       /*
34407 +        * KDB_MAXBPT describes the total number of breakpoints
34408 +        * supported by this architecure.
34409 +        */
34410 +#define KDB_MAXBPT     16
34411 +
34412 +       /*
34413 +        * KDB_MAXHARDBPT describes the total number of hardware
34414 +        * breakpoint registers that exist.
34415 +        */
34416 +#define KDB_MAXHARDBPT  4
34417 +
34418 +/* Maximum number of arguments to a function  */
34419 +#define KDBA_MAXARGS   16
34420 +
34421 +       /*
34422 +        * Platform specific environment entries
34423 +        */
34424 +#define KDB_PLATFORM_ENV       "IDMODE=x86_64", "BYTESPERWORD=8", "IDCOUNT=16"
34425 +
34426 +       /*
34427 +        * Support for ia32 debug registers
34428 +        */
34429 +typedef struct _kdbhard_bp {
34430 +       kdb_machreg_t   bph_reg;        /* Register this breakpoint uses */
34431 +
34432 +       unsigned int    bph_free:1;     /* Register available for use */
34433 +       unsigned int    bph_data:1;     /* Data Access breakpoint */
34434 +
34435 +       unsigned int    bph_write:1;    /* Write Data breakpoint */
34436 +       unsigned int    bph_mode:2;     /* 0=inst, 1=write, 2=io, 3=read */
34437 +       unsigned int    bph_length:2;   /* 0=1, 1=2, 2=BAD, 3=4 (bytes) */
34438 +} kdbhard_bp_t;
34439 +
34440 +extern kdbhard_bp_t    kdb_hardbreaks[/* KDB_MAXHARDBPT */];
34441 +
34442 +#define IA32_BREAKPOINT_INSTRUCTION    0xcc
34443 +
34444 +#define DR6_BT  0x00008000
34445 +#define DR6_BS  0x00004000
34446 +#define DR6_BD  0x00002000
34447 +
34448 +#define DR6_B3  0x00000008
34449 +#define DR6_B2  0x00000004
34450 +#define DR6_B1  0x00000002
34451 +#define DR6_B0  0x00000001
34452 +#define DR6_DR_MASK  0x0000000F
34453 +
34454 +#define DR7_RW_VAL(dr, drnum) \
34455 +       (((dr) >> (16 + (4 * (drnum)))) & 0x3)
34456 +
34457 +#define DR7_RW_SET(dr, drnum, rw)                              \
34458 +       do {                                                    \
34459 +               (dr) &= ~(0x3 << (16 + (4 * (drnum))));         \
34460 +               (dr) |= (((rw) & 0x3) << (16 + (4 * (drnum)))); \
34461 +       } while (0)
34462 +
34463 +#define DR7_RW0(dr)       DR7_RW_VAL(dr, 0)
34464 +#define DR7_RW0SET(dr,rw)  DR7_RW_SET(dr, 0, rw)
34465 +#define DR7_RW1(dr)       DR7_RW_VAL(dr, 1)
34466 +#define DR7_RW1SET(dr,rw)  DR7_RW_SET(dr, 1, rw)
34467 +#define DR7_RW2(dr)       DR7_RW_VAL(dr, 2)
34468 +#define DR7_RW2SET(dr,rw)  DR7_RW_SET(dr, 2, rw)
34469 +#define DR7_RW3(dr)       DR7_RW_VAL(dr, 3)
34470 +#define DR7_RW3SET(dr,rw)  DR7_RW_SET(dr, 3, rw)
34471 +
34472 +
34473 +#define DR7_LEN_VAL(dr, drnum) \
34474 +       (((dr) >> (18 + (4 * (drnum)))) & 0x3)
34475 +
34476 +#define DR7_LEN_SET(dr, drnum, rw)                             \
34477 +       do {                                                    \
34478 +               (dr) &= ~(0x3 << (18 + (4 * (drnum))));         \
34479 +               (dr) |= (((rw) & 0x3) << (18 + (4 * (drnum)))); \
34480 +       } while (0)
34481 +#define DR7_LEN0(dr)        DR7_LEN_VAL(dr, 0)
34482 +#define DR7_LEN0SET(dr,len)  DR7_LEN_SET(dr, 0, len)
34483 +#define DR7_LEN1(dr)        DR7_LEN_VAL(dr, 1)
34484 +#define DR7_LEN1SET(dr,len)  DR7_LEN_SET(dr, 1, len)
34485 +#define DR7_LEN2(dr)        DR7_LEN_VAL(dr, 2)
34486 +#define DR7_LEN2SET(dr,len)  DR7_LEN_SET(dr, 2, len)
34487 +#define DR7_LEN3(dr)        DR7_LEN_VAL(dr, 3)
34488 +#define DR7_LEN3SET(dr,len)  DR7_LEN_SET(dr, 3, len)
34489 +
34490 +#define DR7_G0(dr)    (((dr)>>1)&0x1)
34491 +#define DR7_G0SET(dr) ((dr) |= 0x2)
34492 +#define DR7_G0CLR(dr) ((dr) &= ~0x2)
34493 +#define DR7_G1(dr)    (((dr)>>3)&0x1)
34494 +#define DR7_G1SET(dr) ((dr) |= 0x8)
34495 +#define DR7_G1CLR(dr) ((dr) &= ~0x8)
34496 +#define DR7_G2(dr)    (((dr)>>5)&0x1)
34497 +#define DR7_G2SET(dr) ((dr) |= 0x20)
34498 +#define DR7_G2CLR(dr) ((dr) &= ~0x20)
34499 +#define DR7_G3(dr)    (((dr)>>7)&0x1)
34500 +#define DR7_G3SET(dr) ((dr) |= 0x80)
34501 +#define DR7_G3CLR(dr) ((dr) &= ~0x80)
34502 +
34503 +#define DR7_L0(dr)    (((dr))&0x1)
34504 +#define DR7_L0SET(dr) ((dr) |= 0x1)
34505 +#define DR7_L0CLR(dr) ((dr) &= ~0x1)
34506 +#define DR7_L1(dr)    (((dr)>>2)&0x1)
34507 +#define DR7_L1SET(dr) ((dr) |= 0x4)
34508 +#define DR7_L1CLR(dr) ((dr) &= ~0x4)
34509 +#define DR7_L2(dr)    (((dr)>>4)&0x1)
34510 +#define DR7_L2SET(dr) ((dr) |= 0x10)
34511 +#define DR7_L2CLR(dr) ((dr) &= ~0x10)
34512 +#define DR7_L3(dr)    (((dr)>>6)&0x1)
34513 +#define DR7_L3SET(dr) ((dr) |= 0x40)
34514 +#define DR7_L3CLR(dr) ((dr) &= ~0x40)
34515 +
34516 +#define DR7_GD          0x00002000              /* General Detect Enable */
34517 +#define DR7_GE          0x00000200              /* Global exact */
34518 +#define DR7_LE          0x00000100              /* Local exact */
34519 +
34520 +extern kdb_machreg_t kdba_getdr6(void);
34521 +extern void kdba_putdr6(kdb_machreg_t);
34522 +
34523 +extern kdb_machreg_t kdba_getdr7(void);
34524 +
34525 +extern kdb_machreg_t kdba_getdr(int);
34526 +extern void kdba_putdr(int, kdb_machreg_t);
34527 +
34528 +extern kdb_machreg_t kdb_getcr(int);
34529 +
34530 +/*
34531 + * reg indicies for x86_64 setjmp/longjmp
34532 + */
34533 +#define JB_RBX   0
34534 +#define JB_RBP   1
34535 +#define JB_R12   2
34536 +#define JB_R13   3
34537 +#define JB_R14   4
34538 +#define JB_R15   5
34539 +#define JB_RSP   6
34540 +#define JB_PC    7
34541 +
34542 +typedef struct __kdb_jmp_buf {
34543 +        unsigned long   regs[8];       /* kdba_setjmp assumes fixed offsets here */
34544 +} kdb_jmp_buf;
34545 +
34546 +extern int asmlinkage kdba_setjmp(kdb_jmp_buf *);
34547 +extern void asmlinkage kdba_longjmp(kdb_jmp_buf *, int);
34548 +#define kdba_setjmp kdba_setjmp
34549 +
34550 +extern kdb_jmp_buf  *kdbjmpbuf;
34551 +
34552 +/* Arch specific data saved for running processes */
34553 +
34554 +struct kdba_running_process {
34555 +       long rsp;       /* KDB may be on a different stack */
34556 +       long rip;       /* rip when rsp was set */
34557 +};
34558 +
34559 +register unsigned long current_stack_pointer asm("rsp") __attribute_used__;
34560 +
34561 +static inline
34562 +void kdba_save_running(struct kdba_running_process *k, struct pt_regs *regs)
34563 +{
34564 +       k->rsp = current_stack_pointer;
34565 +       __asm__ __volatile__ ( " lea 0(%%rip),%%rax; movq %%rax,%0 ; " : "=r"(k->rip) : : "rax" );
34566 +}
34567 +
34568 +static inline
34569 +void kdba_unsave_running(struct kdba_running_process *k, struct pt_regs *regs)
34570 +{
34571 +}
34572 +
34573 +struct kdb_activation_record;
34574 +extern void kdba_get_stack_info_alternate(kdb_machreg_t addr, int cpu,
34575 +                                         struct kdb_activation_record *ar);
34576 +
34577 +extern void kdba_wait_for_cpus(void);
34578 +
34579 +extern asmlinkage void kdb_interrupt(void);
34580 +
34581 +#define        KDB_INT_REGISTERS       16
34582 +
34583 +#endif /* !_ASM_KDBPRIVATE_H */
34584 diff -Nurp linux-2.6.22-590/include/asm-x86_64/kdebug.h linux-2.6.22-600/include/asm-x86_64/kdebug.h
34585 --- linux-2.6.22-590/include/asm-x86_64/kdebug.h        2007-07-09 01:32:17.000000000 +0200
34586 +++ linux-2.6.22-600/include/asm-x86_64/kdebug.h        2008-04-09 18:16:24.000000000 +0200
34587 @@ -23,6 +23,8 @@ enum die_val {
34588         DIE_CALL,
34589         DIE_NMI_IPI,
34590         DIE_PAGE_FAULT,
34591 +       DIE_KDEBUG_ENTER,
34592 +       DIE_KDEBUG_LEAVE,
34593  };
34594  
34595  extern void printk_address(unsigned long address);
34596 diff -Nurp linux-2.6.22-590/include/asm-x86_64/kmap_types.h linux-2.6.22-600/include/asm-x86_64/kmap_types.h
34597 --- linux-2.6.22-590/include/asm-x86_64/kmap_types.h    2007-07-09 01:32:17.000000000 +0200
34598 +++ linux-2.6.22-600/include/asm-x86_64/kmap_types.h    2008-04-09 18:16:24.000000000 +0200
34599 @@ -13,6 +13,7 @@ enum km_type {
34600         KM_IRQ1,
34601         KM_SOFTIRQ0,
34602         KM_SOFTIRQ1,
34603 +       KM_KDB,
34604         KM_TYPE_NR
34605  };
34606  
34607 diff -Nurp linux-2.6.22-590/include/linux/console.h linux-2.6.22-600/include/linux/console.h
34608 --- linux-2.6.22-590/include/linux/console.h    2007-07-09 01:32:17.000000000 +0200
34609 +++ linux-2.6.22-600/include/linux/console.h    2008-04-09 18:14:28.000000000 +0200
34610 @@ -137,7 +137,12 @@ void vcs_remove_sysfs(struct tty_struct 
34611  
34612  /* Some debug stub to catch some of the obvious races in the VT code */
34613  #if 1
34614 +#ifdef CONFIG_KDB
34615 +#include <linux/kdb.h>
34616 +#define WARN_CONSOLE_UNLOCKED()        WARN_ON(!is_console_locked() && !oops_in_progress && !atomic_read(&kdb_event))
34617 +#else  /* !CONFIG_KDB */
34618  #define WARN_CONSOLE_UNLOCKED()        WARN_ON(!is_console_locked() && !oops_in_progress)
34619 +#endif /* CONFIG_KDB */
34620  #else
34621  #define WARN_CONSOLE_UNLOCKED()
34622  #endif
34623 diff -Nurp linux-2.6.22-590/include/linux/dis-asm.h linux-2.6.22-600/include/linux/dis-asm.h
34624 --- linux-2.6.22-590/include/linux/dis-asm.h    1970-01-01 01:00:00.000000000 +0100
34625 +++ linux-2.6.22-600/include/linux/dis-asm.h    2008-04-09 18:14:28.000000000 +0200
34626 @@ -0,0 +1,347 @@
34627 +/* Interface between the opcode library and its callers.
34628 +
34629 +   Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005
34630 +   Free Software Foundation, Inc.
34631 +
34632 +   This program is free software; you can redistribute it and/or modify
34633 +   it under the terms of the GNU General Public License as published by
34634 +   the Free Software Foundation; either version 2, or (at your option)
34635 +   any later version.
34636 +
34637 +   This program is distributed in the hope that it will be useful,
34638 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
34639 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34640 +   GNU General Public License for more details.
34641 +
34642 +   You should have received a copy of the GNU General Public License
34643 +   along with this program; if not, write to the Free Software
34644 +   Foundation, Inc., 51 Franklin Street - Fifth Floor,
34645 +   Boston, MA 02110-1301, USA.
34646 +
34647 +   Written by Cygnus Support, 1993.
34648 +
34649 +   The opcode library (libopcodes.a) provides instruction decoders for
34650 +   a large variety of instruction sets, callable with an identical
34651 +   interface, for making instruction-processing programs more independent
34652 +   of the instruction set being processed.  */
34653 +
34654 +/* Extracted from binutils 2.16.91.0.2 (OpenSUSE 10.0) and modified for kdb use.
34655 + * Any trailing whitespace was removed and #ifdef/ifndef __KERNEL__ added as
34656 + * required.
34657 + * Keith Owens <kaos@sgi.com> 15 May 2006
34658 + */
34659 +
34660 +#ifndef DIS_ASM_H
34661 +#define DIS_ASM_H
34662 +
34663 +#ifdef __cplusplus
34664 +extern "C" {
34665 +#endif
34666 +
34667 +#ifdef __KERNEL__
34668 +#include <asm/ansidecl.h>
34669 +#include <asm/bfd.h>
34670 +typedef void FILE;
34671 +#else  /* __KERNEL__ */
34672 +#include <stdio.h>
34673 +#include "bfd.h"
34674 +#endif /* __KERNEL__ */
34675 +
34676 +typedef int (*fprintf_ftype) (void *, const char*, ...) ATTRIBUTE_FPTR_PRINTF_2;
34677 +
34678 +enum dis_insn_type {
34679 +  dis_noninsn,                 /* Not a valid instruction */
34680 +  dis_nonbranch,               /* Not a branch instruction */
34681 +  dis_branch,                  /* Unconditional branch */
34682 +  dis_condbranch,              /* Conditional branch */
34683 +  dis_jsr,                     /* Jump to subroutine */
34684 +  dis_condjsr,                 /* Conditional jump to subroutine */
34685 +  dis_dref,                    /* Data reference instruction */
34686 +  dis_dref2                    /* Two data references in instruction */
34687 +};
34688 +
34689 +/* This struct is passed into the instruction decoding routine,
34690 +   and is passed back out into each callback.  The various fields are used
34691 +   for conveying information from your main routine into your callbacks,
34692 +   for passing information into the instruction decoders (such as the
34693 +   addresses of the callback functions), or for passing information
34694 +   back from the instruction decoders to their callers.
34695 +
34696 +   It must be initialized before it is first passed; this can be done
34697 +   by hand, or using one of the initialization macros below.  */
34698 +
34699 +typedef struct disassemble_info {
34700 +  fprintf_ftype fprintf_func;
34701 +  void *stream;
34702 +  void *application_data;
34703 +
34704 +  /* Target description.  We could replace this with a pointer to the bfd,
34705 +     but that would require one.  There currently isn't any such requirement
34706 +     so to avoid introducing one we record these explicitly.  */
34707 +  /* The bfd_flavour.  This can be bfd_target_unknown_flavour.  */
34708 +  enum bfd_flavour flavour;
34709 +  /* The bfd_arch value.  */
34710 +  enum bfd_architecture arch;
34711 +  /* The bfd_mach value.  */
34712 +  unsigned long mach;
34713 +  /* Endianness (for bi-endian cpus).  Mono-endian cpus can ignore this.  */
34714 +  enum bfd_endian endian;
34715 +  /* An arch/mach-specific bitmask of selected instruction subsets, mainly
34716 +     for processors with run-time-switchable instruction sets.  The default,
34717 +     zero, means that there is no constraint.  CGEN-based opcodes ports
34718 +     may use ISA_foo masks.  */
34719 +  unsigned long insn_sets;
34720 +
34721 +  /* Some targets need information about the current section to accurately
34722 +     display insns.  If this is NULL, the target disassembler function
34723 +     will have to make its best guess.  */
34724 +  asection *section;
34725 +
34726 +  /* An array of pointers to symbols either at the location being disassembled
34727 +     or at the start of the function being disassembled.  The array is sorted
34728 +     so that the first symbol is intended to be the one used.  The others are
34729 +     present for any misc. purposes.  This is not set reliably, but if it is
34730 +     not NULL, it is correct.  */
34731 +  asymbol **symbols;
34732 +  /* Number of symbols in array.  */
34733 +  int num_symbols;
34734 +
34735 +  /* For use by the disassembler.
34736 +     The top 16 bits are reserved for public use (and are documented here).
34737 +     The bottom 16 bits are for the internal use of the disassembler.  */
34738 +  unsigned long flags;
34739 +#define INSN_HAS_RELOC 0x80000000
34740 +  void *private_data;
34741 +
34742 +  /* Function used to get bytes to disassemble.  MEMADDR is the
34743 +     address of the stuff to be disassembled, MYADDR is the address to
34744 +     put the bytes in, and LENGTH is the number of bytes to read.
34745 +     INFO is a pointer to this struct.
34746 +     Returns an errno value or 0 for success.  */
34747 +  int (*read_memory_func)
34748 +    (bfd_vma memaddr, bfd_byte *myaddr, unsigned int length,
34749 +     struct disassemble_info *info);
34750 +
34751 +  /* Function which should be called if we get an error that we can't
34752 +     recover from.  STATUS is the errno value from read_memory_func and
34753 +     MEMADDR is the address that we were trying to read.  INFO is a
34754 +     pointer to this struct.  */
34755 +  void (*memory_error_func)
34756 +    (int status, bfd_vma memaddr, struct disassemble_info *info);
34757 +
34758 +  /* Function called to print ADDR.  */
34759 +  void (*print_address_func)
34760 +    (bfd_vma addr, struct disassemble_info *info);
34761 +
34762 +  /* Function called to determine if there is a symbol at the given ADDR.
34763 +     If there is, the function returns 1, otherwise it returns 0.
34764 +     This is used by ports which support an overlay manager where
34765 +     the overlay number is held in the top part of an address.  In
34766 +     some circumstances we want to include the overlay number in the
34767 +     address, (normally because there is a symbol associated with
34768 +     that address), but sometimes we want to mask out the overlay bits.  */
34769 +  int (* symbol_at_address_func)
34770 +    (bfd_vma addr, struct disassemble_info * info);
34771 +
34772 +  /* Function called to check if a SYMBOL is can be displayed to the user.
34773 +     This is used by some ports that want to hide special symbols when
34774 +     displaying debugging outout.  */
34775 +  bfd_boolean (* symbol_is_valid)
34776 +    (asymbol *, struct disassemble_info * info);
34777 +
34778 +  /* These are for buffer_read_memory.  */
34779 +  bfd_byte *buffer;
34780 +  bfd_vma buffer_vma;
34781 +  unsigned int buffer_length;
34782 +
34783 +  /* This variable may be set by the instruction decoder.  It suggests
34784 +      the number of bytes objdump should display on a single line.  If
34785 +      the instruction decoder sets this, it should always set it to
34786 +      the same value in order to get reasonable looking output.  */
34787 +  int bytes_per_line;
34788 +
34789 +  /* The next two variables control the way objdump displays the raw data.  */
34790 +  /* For example, if bytes_per_line is 8 and bytes_per_chunk is 4, the */
34791 +  /* output will look like this:
34792 +     00:   00000000 00000000
34793 +     with the chunks displayed according to "display_endian". */
34794 +  int bytes_per_chunk;
34795 +  enum bfd_endian display_endian;
34796 +
34797 +  /* Number of octets per incremented target address
34798 +     Normally one, but some DSPs have byte sizes of 16 or 32 bits.  */
34799 +  unsigned int octets_per_byte;
34800 +
34801 +  /* The number of zeroes we want to see at the end of a section before we
34802 +     start skipping them.  */
34803 +  unsigned int skip_zeroes;
34804 +
34805 +  /* The number of zeroes to skip at the end of a section.  If the number
34806 +     of zeroes at the end is between SKIP_ZEROES_AT_END and SKIP_ZEROES,
34807 +     they will be disassembled.  If there are fewer than
34808 +     SKIP_ZEROES_AT_END, they will be skipped.  This is a heuristic
34809 +     attempt to avoid disassembling zeroes inserted by section
34810 +     alignment.  */
34811 +  unsigned int skip_zeroes_at_end;
34812 +
34813 +  /* Results from instruction decoders.  Not all decoders yet support
34814 +     this information.  This info is set each time an instruction is
34815 +     decoded, and is only valid for the last such instruction.
34816 +
34817 +     To determine whether this decoder supports this information, set
34818 +     insn_info_valid to 0, decode an instruction, then check it.  */
34819 +
34820 +  char insn_info_valid;                /* Branch info has been set. */
34821 +  char branch_delay_insns;     /* How many sequential insn's will run before
34822 +                                  a branch takes effect.  (0 = normal) */
34823 +  char data_size;              /* Size of data reference in insn, in bytes */
34824 +  enum dis_insn_type insn_type;        /* Type of instruction */
34825 +  bfd_vma target;              /* Target address of branch or dref, if known;
34826 +                                  zero if unknown.  */
34827 +  bfd_vma target2;             /* Second target address for dref2 */
34828 +
34829 +  /* Command line options specific to the target disassembler.  */
34830 +  char * disassembler_options;
34831 +
34832 +} disassemble_info;
34833 +
34834 +\f
34835 +/* Standard disassemblers.  Disassemble one instruction at the given
34836 +   target address.  Return number of octets processed.  */
34837 +typedef int (*disassembler_ftype) (bfd_vma, disassemble_info *);
34838 +
34839 +extern int print_insn_big_mips         (bfd_vma, disassemble_info *);
34840 +extern int print_insn_little_mips      (bfd_vma, disassemble_info *);
34841 +extern int print_insn_i386             (bfd_vma, disassemble_info *);
34842 +extern int print_insn_i386_att         (bfd_vma, disassemble_info *);
34843 +extern int print_insn_i386_intel       (bfd_vma, disassemble_info *);
34844 +extern int print_insn_ia64             (bfd_vma, disassemble_info *);
34845 +extern int print_insn_i370             (bfd_vma, disassemble_info *);
34846 +extern int print_insn_m68hc11          (bfd_vma, disassemble_info *);
34847 +extern int print_insn_m68hc12          (bfd_vma, disassemble_info *);
34848 +extern int print_insn_m68k             (bfd_vma, disassemble_info *);
34849 +extern int print_insn_z8001            (bfd_vma, disassemble_info *);
34850 +extern int print_insn_z8002            (bfd_vma, disassemble_info *);
34851 +extern int print_insn_h8300            (bfd_vma, disassemble_info *);
34852 +extern int print_insn_h8300h           (bfd_vma, disassemble_info *);
34853 +extern int print_insn_h8300s           (bfd_vma, disassemble_info *);
34854 +extern int print_insn_h8500            (bfd_vma, disassemble_info *);
34855 +extern int print_insn_alpha            (bfd_vma, disassemble_info *);
34856 +extern int print_insn_big_arm          (bfd_vma, disassemble_info *);
34857 +extern int print_insn_little_arm       (bfd_vma, disassemble_info *);
34858 +extern int print_insn_sparc            (bfd_vma, disassemble_info *);
34859 +extern int print_insn_big_a29k         (bfd_vma, disassemble_info *);
34860 +extern int print_insn_little_a29k      (bfd_vma, disassemble_info *);
34861 +extern int print_insn_avr              (bfd_vma, disassemble_info *);
34862 +extern int print_insn_d10v             (bfd_vma, disassemble_info *);
34863 +extern int print_insn_d30v             (bfd_vma, disassemble_info *);
34864 +extern int print_insn_dlx              (bfd_vma, disassemble_info *);
34865 +extern int print_insn_fr30             (bfd_vma, disassemble_info *);
34866 +extern int print_insn_hppa             (bfd_vma, disassemble_info *);
34867 +extern int print_insn_i860             (bfd_vma, disassemble_info *);
34868 +extern int print_insn_i960             (bfd_vma, disassemble_info *);
34869 +extern int print_insn_ip2k             (bfd_vma, disassemble_info *);
34870 +extern int print_insn_m32r             (bfd_vma, disassemble_info *);
34871 +extern int print_insn_m88k             (bfd_vma, disassemble_info *);
34872 +extern int print_insn_maxq_little      (bfd_vma, disassemble_info *);
34873 +extern int print_insn_maxq_big         (bfd_vma, disassemble_info *);
34874 +extern int print_insn_mcore            (bfd_vma, disassemble_info *);
34875 +extern int print_insn_mmix             (bfd_vma, disassemble_info *);
34876 +extern int print_insn_mn10200          (bfd_vma, disassemble_info *);
34877 +extern int print_insn_mn10300          (bfd_vma, disassemble_info *);
34878 +extern int print_insn_ms1               (bfd_vma, disassemble_info *);
34879 +extern int print_insn_msp430           (bfd_vma, disassemble_info *);
34880 +extern int print_insn_ns32k            (bfd_vma, disassemble_info *);
34881 +extern int print_insn_crx               (bfd_vma, disassemble_info *);
34882 +extern int print_insn_openrisc         (bfd_vma, disassemble_info *);
34883 +extern int print_insn_big_or32         (bfd_vma, disassemble_info *);
34884 +extern int print_insn_little_or32      (bfd_vma, disassemble_info *);
34885 +extern int print_insn_pdp11            (bfd_vma, disassemble_info *);
34886 +extern int print_insn_pj               (bfd_vma, disassemble_info *);
34887 +extern int print_insn_big_powerpc      (bfd_vma, disassemble_info *);
34888 +extern int print_insn_little_powerpc   (bfd_vma, disassemble_info *);
34889 +extern int print_insn_rs6000           (bfd_vma, disassemble_info *);
34890 +extern int print_insn_s390             (bfd_vma, disassemble_info *);
34891 +extern int print_insn_sh               (bfd_vma, disassemble_info *);
34892 +extern int print_insn_tic30            (bfd_vma, disassemble_info *);
34893 +extern int print_insn_tic4x            (bfd_vma, disassemble_info *);
34894 +extern int print_insn_tic54x           (bfd_vma, disassemble_info *);
34895 +extern int print_insn_tic80            (bfd_vma, disassemble_info *);
34896 +extern int print_insn_v850             (bfd_vma, disassemble_info *);
34897 +extern int print_insn_vax              (bfd_vma, disassemble_info *);
34898 +extern int print_insn_w65              (bfd_vma, disassemble_info *);
34899 +extern int print_insn_xstormy16                (bfd_vma, disassemble_info *);
34900 +extern int print_insn_xtensa           (bfd_vma, disassemble_info *);
34901 +extern int print_insn_sh64             (bfd_vma, disassemble_info *);
34902 +extern int print_insn_sh64x_media      (bfd_vma, disassemble_info *);
34903 +extern int print_insn_frv              (bfd_vma, disassemble_info *);
34904 +extern int print_insn_iq2000           (bfd_vma, disassemble_info *);
34905 +extern int print_insn_m32c     (bfd_vma, disassemble_info *);
34906 +
34907 +extern disassembler_ftype arc_get_disassembler (void *);
34908 +extern disassembler_ftype cris_get_disassembler (bfd *);
34909 +
34910 +extern void print_mips_disassembler_options (FILE *);
34911 +extern void print_ppc_disassembler_options (FILE *);
34912 +extern void print_arm_disassembler_options (FILE *);
34913 +extern void parse_arm_disassembler_option (char *);
34914 +extern int get_arm_regname_num_options (void);
34915 +extern int set_arm_regname_option (int);
34916 +extern int get_arm_regnames (int, const char **, const char **, const char *const **);
34917 +extern bfd_boolean arm_symbol_is_valid (asymbol *, struct disassemble_info *);
34918 +
34919 +/* Fetch the disassembler for a given BFD, if that support is available.  */
34920 +extern disassembler_ftype disassembler (bfd *);
34921 +
34922 +/* Amend the disassemble_info structure as necessary for the target architecture.
34923 +   Should only be called after initialising the info->arch field.  */
34924 +extern void disassemble_init_for_target (struct disassemble_info * info);
34925 +
34926 +/* Document any target specific options available from the disassembler.  */
34927 +extern void disassembler_usage (FILE *);
34928 +
34929 +\f
34930 +/* This block of definitions is for particular callers who read instructions
34931 +   into a buffer before calling the instruction decoder.  */
34932 +
34933 +/* Here is a function which callers may wish to use for read_memory_func.
34934 +   It gets bytes from a buffer.  */
34935 +extern int buffer_read_memory
34936 +  (bfd_vma, bfd_byte *, unsigned int, struct disassemble_info *);
34937 +
34938 +/* This function goes with buffer_read_memory.
34939 +   It prints a message using info->fprintf_func and info->stream.  */
34940 +extern void perror_memory (int, bfd_vma, struct disassemble_info *);
34941 +
34942 +
34943 +/* Just print the address in hex.  This is included for completeness even
34944 +   though both GDB and objdump provide their own (to print symbolic
34945 +   addresses).  */
34946 +extern void generic_print_address
34947 +  (bfd_vma, struct disassemble_info *);
34948 +
34949 +/* Always true.  */
34950 +extern int generic_symbol_at_address
34951 +  (bfd_vma, struct disassemble_info *);
34952 +
34953 +/* Also always true.  */
34954 +extern bfd_boolean generic_symbol_is_valid
34955 +  (asymbol *, struct disassemble_info *);
34956 +
34957 +/* Method to initialize a disassemble_info struct.  This should be
34958 +   called by all applications creating such a struct.  */
34959 +extern void init_disassemble_info (struct disassemble_info *info, void *stream,
34960 +                                  fprintf_ftype fprintf_func);
34961 +
34962 +/* For compatibility with existing code.  */
34963 +#define INIT_DISASSEMBLE_INFO(INFO, STREAM, FPRINTF_FUNC) \
34964 +  init_disassemble_info (&(INFO), (STREAM), (fprintf_ftype) (FPRINTF_FUNC))
34965 +#define INIT_DISASSEMBLE_INFO_NO_ARCH(INFO, STREAM, FPRINTF_FUNC) \
34966 +  init_disassemble_info (&(INFO), (STREAM), (fprintf_ftype) (FPRINTF_FUNC))
34967 +
34968 +
34969 +#ifdef __cplusplus
34970 +}
34971 +#endif
34972 +
34973 +#endif /* ! defined (DIS_ASM_H) */
34974 diff -Nurp linux-2.6.22-590/include/linux/kdb.h linux-2.6.22-600/include/linux/kdb.h
34975 --- linux-2.6.22-590/include/linux/kdb.h        1970-01-01 01:00:00.000000000 +0100
34976 +++ linux-2.6.22-600/include/linux/kdb.h        2008-04-09 18:14:28.000000000 +0200
34977 @@ -0,0 +1,166 @@
34978 +#ifndef _KDB_H
34979 +#define _KDB_H
34980 +
34981 +/*
34982 + * Kernel Debugger Architecture Independent Global Headers
34983 + *
34984 + * This file is subject to the terms and conditions of the GNU General Public
34985 + * License.  See the file "COPYING" in the main directory of this archive
34986 + * for more details.
34987 + *
34988 + * Copyright (c) 2000-2007 Silicon Graphics, Inc.  All Rights Reserved.
34989 + * Copyright (C) 2000 Stephane Eranian <eranian@hpl.hp.com>
34990 + */
34991 +
34992 +#include <linux/init.h>
34993 +#include <linux/sched.h>
34994 +#include <asm/atomic.h>
34995 +
34996 +#ifdef CONFIG_KDB
34997 +/* These are really private, but they must be defined before including
34998 + * asm-$(ARCH)/kdb.h, so make them public and put them here.
34999 + */
35000 +extern int kdb_getuserarea_size(void *, unsigned long, size_t);
35001 +extern int kdb_putuserarea_size(unsigned long, void *, size_t);
35002 +
35003 +#include <asm/kdb.h>
35004 +#endif
35005 +
35006 +#define KDB_MAJOR_VERSION      4
35007 +#define KDB_MINOR_VERSION      4
35008 +#define KDB_TEST_VERSION       ""
35009 +
35010 +/*
35011 + * kdb_initial_cpu is initialized to -1, and is set to the cpu
35012 + * number whenever the kernel debugger is entered.
35013 + */
35014 +extern volatile int kdb_initial_cpu;
35015 +extern atomic_t kdb_event;
35016 +extern atomic_t kdb_8250;
35017 +#ifdef CONFIG_KDB
35018 +#define KDB_IS_RUNNING() (kdb_initial_cpu != -1)
35019 +#define KDB_8250() (atomic_read(&kdb_8250) != 0)
35020 +#else
35021 +#define KDB_IS_RUNNING() (0)
35022 +#define KDB_8250() (0)
35023 +#endif /* CONFIG_KDB */
35024 +
35025 +/*
35026 + * kdb_on
35027 + *
35028 + *     Defines whether kdb is on or not.  Default value
35029 + *     is set by CONFIG_KDB_OFF.  Boot with kdb=on/off/on-nokey
35030 + *     or echo "[012]" > /proc/sys/kernel/kdb to change it.
35031 + */
35032 +extern int kdb_on;
35033 +
35034 +#if defined(CONFIG_SERIAL_8250_CONSOLE) || defined(CONFIG_SERIAL_SGI_L1_CONSOLE)
35035 +/*
35036 + * kdb_serial.iobase is initialized to zero, and is set to the I/O
35037 + * address of the serial port when the console is setup in
35038 + * serial_console_setup.
35039 + */
35040 +extern struct kdb_serial {
35041 +       int io_type;
35042 +       unsigned long iobase;
35043 +       unsigned long ioreg_shift;
35044 +} kdb_serial;
35045 +#endif
35046 +
35047 +/*
35048 + * kdb_diemsg
35049 + *
35050 + *     Contains a pointer to the last string supplied to the
35051 + *     kernel 'die' panic function.
35052 + */
35053 +extern const char *kdb_diemsg;
35054 +
35055 +#define KDB_FLAG_EARLYKDB      (1 << 0)        /* set from boot parameter kdb=early */
35056 +#define KDB_FLAG_CATASTROPHIC  (1 << 1)        /* A catastrophic event has occurred */
35057 +#define KDB_FLAG_CMD_INTERRUPT (1 << 2)        /* Previous command was interrupted */
35058 +#define KDB_FLAG_NOIPI         (1 << 3)        /* Do not send IPIs */
35059 +#define KDB_FLAG_ONLY_DO_DUMP  (1 << 4)        /* Only do a dump, used when kdb is off */
35060 +#define KDB_FLAG_NO_CONSOLE    (1 << 5)        /* No console is available, kdb is disabled */
35061 +#define KDB_FLAG_NO_VT_CONSOLE (1 << 6)        /* No VT console is available, do not use keyboard */
35062 +#define KDB_FLAG_NO_I8042      (1 << 7)        /* No i8042 chip is available, do not use keyboard */
35063 +#define KDB_FLAG_RECOVERY      (1 << 8)        /* kdb is being entered for an error which has been recovered */
35064 +
35065 +extern volatile int kdb_flags;                 /* Global flags, see kdb_state for per cpu state */
35066 +
35067 +extern void kdb_save_flags(void);
35068 +extern void kdb_restore_flags(void);
35069 +
35070 +#define KDB_FLAG(flag)         (kdb_flags & KDB_FLAG_##flag)
35071 +#define KDB_FLAG_SET(flag)     ((void)(kdb_flags |= KDB_FLAG_##flag))
35072 +#define KDB_FLAG_CLEAR(flag)   ((void)(kdb_flags &= ~KDB_FLAG_##flag))
35073 +
35074 +/*
35075 + * External entry point for the kernel debugger.  The pt_regs
35076 + * at the time of entry are supplied along with the reason for
35077 + * entry to the kernel debugger.
35078 + */
35079 +
35080 +typedef enum {
35081 +       KDB_REASON_ENTER=1,             /* KDB_ENTER() trap/fault - regs valid */
35082 +       KDB_REASON_ENTER_SLAVE,         /* KDB_ENTER_SLAVE() trap/fault - regs valid */
35083 +       KDB_REASON_BREAK,               /* Breakpoint inst. - regs valid */
35084 +       KDB_REASON_DEBUG,               /* Debug Fault - regs valid */
35085 +       KDB_REASON_OOPS,                /* Kernel Oops - regs valid */
35086 +       KDB_REASON_SWITCH,              /* CPU switch - regs valid*/
35087 +       KDB_REASON_KEYBOARD,            /* Keyboard entry - regs valid */
35088 +       KDB_REASON_NMI,                 /* Non-maskable interrupt; regs valid */
35089 +       KDB_REASON_RECURSE,             /* Recursive entry to kdb; regs probably valid */
35090 +       KDB_REASON_CPU_UP,              /* Add one cpu to kdb; regs invalid */
35091 +       KDB_REASON_SILENT,              /* Silent entry/exit to kdb; regs invalid - internal only */
35092 +} kdb_reason_t;
35093 +
35094 +#ifdef CONFIG_KDB
35095 +extern fastcall int kdb(kdb_reason_t, int, struct pt_regs *);
35096 +#else
35097 +#define kdb(reason,error_code,frame) (0)
35098 +#endif
35099 +
35100 +/* Mainly used by kdb code, but this function is sometimes used
35101 + * by hacked debug code so make it generally available, not private.
35102 + */
35103 +extern void kdb_printf(const char *,...)
35104 +           __attribute__ ((format (printf, 1, 2)));
35105 +typedef void (*kdb_printf_t)(const char *, ...)
35106 +            __attribute__ ((format (printf, 1, 2)));
35107 +extern void kdb_init(void);
35108 +
35109 +#if defined(CONFIG_SMP)
35110 +/*
35111 + * Kernel debugger non-maskable IPI handler.
35112 + */
35113 +extern int kdb_ipi(struct pt_regs *, void (*ack_interrupt)(void));
35114 +extern void smp_kdb_stop(void);
35115 +#else  /* CONFIG_SMP */
35116 +#define        smp_kdb_stop()
35117 +#endif /* CONFIG_SMP */
35118 +
35119 +#ifdef CONFIG_KDB_USB
35120 +#include <linux/usb.h>
35121 +
35122 +struct kdb_usb_exchange {
35123 +       void *uhci;                     /* pointer to the UHCI structure */
35124 +       struct urb *urb;                /* pointer to the URB */
35125 +       unsigned char *buffer;          /* pointer to buffer */
35126 +       void (*poll_func)(void *, struct urb *); /* pointer to the polling function */
35127 +       void (*reset_timer)(void);      /* pointer to the reset timer function */
35128 +};
35129 +extern struct kdb_usb_exchange kdb_usb_infos; /* KDB common structure */
35130 +#endif /* CONFIG_KDB_USB */
35131 +
35132 +static inline
35133 +int kdb_process_cpu(const struct task_struct *p)
35134 +{
35135 +       unsigned int cpu = task_thread_info(p)->cpu;
35136 +       if (cpu > NR_CPUS)
35137 +               cpu = 0;
35138 +       return cpu;
35139 +}
35140 +
35141 +extern const char kdb_serial_str[];
35142 +
35143 +#endif /* !_KDB_H */
35144 diff -Nurp linux-2.6.22-590/include/linux/kdbprivate.h linux-2.6.22-600/include/linux/kdbprivate.h
35145 --- linux-2.6.22-590/include/linux/kdbprivate.h 1970-01-01 01:00:00.000000000 +0100
35146 +++ linux-2.6.22-600/include/linux/kdbprivate.h 2008-04-09 18:14:28.000000000 +0200
35147 @@ -0,0 +1,485 @@
35148 +#ifndef _KDBPRIVATE_H
35149 +#define _KDBPRIVATE_H
35150 +
35151 +/*
35152 + * Kernel Debugger Architecture Independent Private Headers
35153 + *
35154 + * This file is subject to the terms and conditions of the GNU General Public
35155 + * License.  See the file "COPYING" in the main directory of this archive
35156 + * for more details.
35157 + *
35158 + * Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
35159 + */
35160 +
35161 +
35162 +#include <linux/dis-asm.h>
35163 +#include <asm/kdbprivate.h>
35164 +#include <asm/bfd.h>
35165 +
35166 +       /*
35167 +        * Kernel Debugger Error codes.  Must not overlap with command codes.
35168 +        */
35169 +
35170 +#define KDB_NOTFOUND   (-1)
35171 +#define KDB_ARGCOUNT   (-2)
35172 +#define KDB_BADWIDTH   (-3)
35173 +#define KDB_BADRADIX   (-4)
35174 +#define KDB_NOTENV     (-5)
35175 +#define KDB_NOENVVALUE (-6)
35176 +#define KDB_NOTIMP     (-7)
35177 +#define KDB_ENVFULL    (-8)
35178 +#define KDB_ENVBUFFULL (-9 )
35179 +#define KDB_TOOMANYBPT (-10)
35180 +#define KDB_TOOMANYDBREGS (-11)
35181 +#define KDB_DUPBPT     (-12)
35182 +#define KDB_BPTNOTFOUND        (-13)
35183 +#define KDB_BADMODE    (-14)
35184 +#define KDB_BADINT     (-15)
35185 +#define KDB_INVADDRFMT  (-16)
35186 +#define KDB_BADREG      (-17)
35187 +#define KDB_BADCPUNUM   (-18)
35188 +#define KDB_BADLENGTH  (-19)
35189 +#define KDB_NOBP       (-20)
35190 +#define KDB_BADADDR    (-21)
35191 +
35192 +       /*
35193 +        * Kernel Debugger Command codes.  Must not overlap with error codes.
35194 +        */
35195 +#define KDB_CMD_GO     (-1001)
35196 +#define KDB_CMD_CPU    (-1002)
35197 +#define KDB_CMD_SS     (-1003)
35198 +#define KDB_CMD_SSB    (-1004)
35199 +
35200 +       /*
35201 +        * Internal debug flags
35202 +        */
35203 +/*     KDB_DEBUG_FLAG_BT       0x0001          Was Stack traceback debug */
35204 +#define KDB_DEBUG_FLAG_BP      0x0002          /* Breakpoint subsystem debug */
35205 +#define KDB_DEBUG_FLAG_BB_SUMM 0x0004          /* Basic block analysis, summary only */
35206 +#define KDB_DEBUG_FLAG_AR      0x0008          /* Activation record, generic */
35207 +#define KDB_DEBUG_FLAG_ARA     0x0010          /* Activation record, arch specific */
35208 +#define KDB_DEBUG_FLAG_BB      0x0020          /* All basic block analysis */
35209 +#define KDB_DEBUG_FLAG_STATE   0x0040          /* State flags */
35210 +#define KDB_DEBUG_FLAG_MASK    0xffff          /* All debug flags */
35211 +#define KDB_DEBUG_FLAG_SHIFT   16              /* Shift factor for dbflags */
35212 +
35213 +#define KDB_DEBUG(flag)                (kdb_flags & (KDB_DEBUG_FLAG_##flag << KDB_DEBUG_FLAG_SHIFT))
35214 +#define KDB_DEBUG_STATE(text,value)    if (KDB_DEBUG(STATE)) kdb_print_state(text, value)
35215 +
35216 +typedef enum {
35217 +       KDB_REPEAT_NONE = 0,            /* Do not repeat this command */
35218 +       KDB_REPEAT_NO_ARGS,             /* Repeat the command without arguments */
35219 +       KDB_REPEAT_WITH_ARGS,           /* Repeat the command including its arguments */
35220 +} kdb_repeat_t;
35221 +
35222 +typedef int (*kdb_func_t)(int, const char **);
35223 +
35224 +       /*
35225 +        * Symbol table format returned by kallsyms.
35226 +        */
35227 +
35228 +typedef struct __ksymtab {
35229 +               unsigned long value;            /* Address of symbol */
35230 +               const char *mod_name;           /* Module containing symbol or "kernel" */
35231 +               unsigned long mod_start;
35232 +               unsigned long mod_end;
35233 +               const char *sec_name;           /* Section containing symbol */
35234 +               unsigned long sec_start;
35235 +               unsigned long sec_end;
35236 +               const char *sym_name;           /* Full symbol name, including any version */
35237 +               unsigned long sym_start;
35238 +               unsigned long sym_end;
35239 +               } kdb_symtab_t;
35240 +extern int kallsyms_symbol_next(char *prefix_name, int flag);
35241 +extern int kallsyms_symbol_complete(char *prefix_name, int max_len);
35242 +
35243 +       /*
35244 +        * Exported Symbols for kernel loadable modules to use.
35245 +        */
35246 +extern int kdb_register(char *, kdb_func_t, char *, char *, short);
35247 +extern int kdb_register_repeat(char *, kdb_func_t, char *, char *, short, kdb_repeat_t);
35248 +extern int kdb_unregister(char *);
35249 +
35250 +extern int kdb_getarea_size(void *, unsigned long, size_t);
35251 +extern int kdb_putarea_size(unsigned long, void *, size_t);
35252 +
35253 +/* Like get_user and put_user, kdb_getarea and kdb_putarea take variable
35254 + * names, not pointers.  The underlying *_size functions take pointers.
35255 + */
35256 +#define kdb_getarea(x,addr) kdb_getarea_size(&(x), addr, sizeof((x)))
35257 +#define kdb_putarea(addr,x) kdb_putarea_size(addr, &(x), sizeof((x)))
35258 +
35259 +extern int kdb_getphysword(unsigned long *word,
35260 +                       unsigned long addr, size_t size);
35261 +extern int kdb_getword(unsigned long *, unsigned long, size_t);
35262 +extern int kdb_putword(unsigned long, unsigned long, size_t);
35263 +
35264 +extern int kdbgetularg(const char *, unsigned long *);
35265 +extern char *kdbgetenv(const char *);
35266 +extern int kdbgetintenv(const char *, int *);
35267 +extern int kdbgetaddrarg(int, const char**, int*, unsigned long *,
35268 +                        long *, char **);
35269 +extern int kdbgetsymval(const char *, kdb_symtab_t *);
35270 +extern int kdbnearsym(unsigned long, kdb_symtab_t *);
35271 +extern void kdbnearsym_cleanup(void);
35272 +extern char *kdb_read(char *buffer, size_t bufsize);
35273 +extern char *kdb_strdup(const char *str, gfp_t type);
35274 +extern void kdb_symbol_print(kdb_machreg_t, const kdb_symtab_t *, unsigned int);
35275 +
35276 +        /*
35277 +         * Do we have a set of registers?
35278 +         */
35279 +
35280 +#define KDB_NULL_REGS(regs) \
35281 +       (regs == (struct pt_regs *)NULL ? kdb_printf("%s: null regs - should never happen\n", __FUNCTION__), 1 : 0)
35282 +
35283 +        /*
35284 +         * Routine for debugging the debugger state.
35285 +         */
35286 +
35287 +extern void kdb_print_state(const char *, int);
35288 +
35289 +       /*
35290 +        * Per cpu kdb state.  A cpu can be under kdb control but outside kdb,
35291 +        * for example when doing single step.
35292 +        */
35293 +volatile extern int kdb_state[ /*NR_CPUS*/ ];
35294 +#define KDB_STATE_KDB          0x00000001      /* Cpu is inside kdb */
35295 +#define KDB_STATE_LEAVING      0x00000002      /* Cpu is leaving kdb */
35296 +#define KDB_STATE_CMD          0x00000004      /* Running a kdb command */
35297 +#define KDB_STATE_KDB_CONTROL  0x00000008      /* This cpu is under kdb control */
35298 +#define KDB_STATE_HOLD_CPU     0x00000010      /* Hold this cpu inside kdb */
35299 +#define KDB_STATE_DOING_SS     0x00000020      /* Doing ss command */
35300 +#define KDB_STATE_DOING_SSB    0x00000040      /* Doing ssb command, DOING_SS is also set */
35301 +#define KDB_STATE_SSBPT                0x00000080      /* Install breakpoint after one ss, independent of DOING_SS */
35302 +#define KDB_STATE_REENTRY      0x00000100      /* Valid re-entry into kdb */
35303 +#define KDB_STATE_SUPPRESS     0x00000200      /* Suppress error messages */
35304 +#define KDB_STATE_LONGJMP      0x00000400      /* longjmp() data is available */
35305 +#define KDB_STATE_GO_SWITCH    0x00000800      /* go is switching back to initial cpu */
35306 +#define KDB_STATE_PRINTF_LOCK  0x00001000      /* Holds kdb_printf lock */
35307 +#define KDB_STATE_WAIT_IPI     0x00002000      /* Waiting for kdb_ipi() NMI */
35308 +#define KDB_STATE_RECURSE      0x00004000      /* Recursive entry to kdb */
35309 +#define KDB_STATE_IP_ADJUSTED  0x00008000      /* Restart IP has been adjusted */
35310 +#define KDB_STATE_GO1          0x00010000      /* go only releases one cpu */
35311 +#define KDB_STATE_KEYBOARD     0x00020000      /* kdb entered via keyboard on this cpu */
35312 +#define KDB_STATE_ARCH         0xff000000      /* Reserved for arch specific use */
35313 +
35314 +#define KDB_STATE_CPU(flag,cpu)                (kdb_state[cpu] & KDB_STATE_##flag)
35315 +#define KDB_STATE_SET_CPU(flag,cpu)    ((void)(kdb_state[cpu] |= KDB_STATE_##flag))
35316 +#define KDB_STATE_CLEAR_CPU(flag,cpu)  ((void)(kdb_state[cpu] &= ~KDB_STATE_##flag))
35317 +
35318 +#define KDB_STATE(flag)                KDB_STATE_CPU(flag,smp_processor_id())
35319 +#define KDB_STATE_SET(flag)    KDB_STATE_SET_CPU(flag,smp_processor_id())
35320 +#define KDB_STATE_CLEAR(flag)  KDB_STATE_CLEAR_CPU(flag,smp_processor_id())
35321 +
35322 +       /*
35323 +        * kdb_nextline
35324 +        *
35325 +        *      Contains the current line number on the screen.  Used
35326 +        *      to handle the built-in pager (LINES env variable)
35327 +        */
35328 +extern volatile int kdb_nextline;
35329 +
35330 +       /*
35331 +        * Breakpoint state
35332 +        *
35333 +        *      Each active and inactive breakpoint is represented by
35334 +        *      an instance of the following data structure.
35335 +        */
35336 +
35337 +typedef struct _kdb_bp {
35338 +       bfd_vma         bp_addr;        /* Address breakpoint is present at */
35339 +       kdb_machinst_t  bp_inst;        /* Replaced instruction */
35340 +
35341 +       unsigned int    bp_free:1;      /* This entry is available */
35342 +
35343 +       unsigned int    bp_enabled:1;   /* Breakpoint is active in register */
35344 +       unsigned int    bp_global:1;    /* Global to all processors */
35345 +
35346 +       unsigned int    bp_hardtype:1;  /* Uses hardware register */
35347 +       unsigned int    bp_forcehw:1;   /* Force hardware register */
35348 +       unsigned int    bp_installed:1; /* Breakpoint is installed */
35349 +       unsigned int    bp_delay:1;     /* Do delayed bp handling */
35350 +       unsigned int    bp_delayed:1;   /* Delayed breakpoint */
35351 +
35352 +       int             bp_cpu;         /* Cpu #  (if bp_global == 0) */
35353 +       kdbhard_bp_t    bp_template;    /* Hardware breakpoint template */
35354 +       kdbhard_bp_t    *bp_hard;       /* Hardware breakpoint structure */
35355 +       int             bp_adjust;      /* Adjustment to PC for real instruction */
35356 +} kdb_bp_t;
35357 +
35358 +       /*
35359 +        * Breakpoint handling subsystem global variables
35360 +        */
35361 +extern kdb_bp_t kdb_breakpoints[/* KDB_MAXBPT */];
35362 +
35363 +       /*
35364 +        * Breakpoint architecture dependent functions.  Must be provided
35365 +        * in some form for all architectures.
35366 +        */
35367 +extern void kdba_initbp(void);
35368 +extern void kdba_printbp(kdb_bp_t *);
35369 +extern kdbhard_bp_t *kdba_allocbp(kdbhard_bp_t *, int *);
35370 +extern void kdba_freebp(kdbhard_bp_t *);
35371 +extern int kdba_parsebp(int, const char**, int *, kdb_bp_t*);
35372 +extern char *kdba_bptype(kdbhard_bp_t *);
35373 +extern void kdba_setsinglestep(struct pt_regs *);
35374 +extern void kdba_clearsinglestep(struct pt_regs *);
35375 +
35376 +       /*
35377 +        * Adjust instruction pointer architecture dependent function.  Must be
35378 +        * provided in some form for all architectures.
35379 +        */
35380 +extern void kdba_adjust_ip(kdb_reason_t, int, struct pt_regs *);
35381 +
35382 +       /*
35383 +        * KDB-only global function prototypes.
35384 +        */
35385 +extern void kdb_id1(unsigned long);
35386 +extern void kdb_id_init(void);
35387 +
35388 +       /*
35389 +        * Initialization functions.
35390 +        */
35391 +extern void kdba_init(void);
35392 +extern void kdb_io_init(void);
35393 +
35394 +       /*
35395 +        * Architecture specific function to read a string.
35396 +        */
35397 +typedef int (*get_char_func)(void);
35398 +extern get_char_func poll_funcs[];
35399 +
35400 +#ifndef        CONFIG_IA64
35401 +       /*
35402 +        * Data for a single activation record on stack.
35403 +        */
35404 +
35405 +struct kdb_stack_info {
35406 +       kdb_machreg_t physical_start;
35407 +       kdb_machreg_t physical_end;
35408 +       kdb_machreg_t logical_start;
35409 +       kdb_machreg_t logical_end;
35410 +       kdb_machreg_t next;
35411 +       const char *  id;
35412 +};
35413 +
35414 +typedef struct { DECLARE_BITMAP(bits, KDBA_MAXARGS); } valid_t;
35415 +
35416 +struct kdb_activation_record {
35417 +       struct kdb_stack_info   stack;          /* information about current stack */
35418 +       int             args;                   /* number of arguments detected */
35419 +       kdb_machreg_t   arg[KDBA_MAXARGS];      /* -> arguments */
35420 +       valid_t         valid;                  /* is argument n valid? */
35421 +};
35422 +#endif
35423 +
35424 +       /*
35425 +        * Architecture specific Stack Traceback functions.
35426 +        */
35427 +
35428 +struct task_struct;
35429 +
35430 +extern int kdba_bt_address(kdb_machreg_t, int);
35431 +extern int kdba_bt_process(const struct task_struct *, int);
35432 +
35433 +       /*
35434 +        * KDB Command Table
35435 +        */
35436 +
35437 +typedef struct _kdbtab {
35438 +       char    *cmd_name;              /* Command name */
35439 +       kdb_func_t cmd_func;            /* Function to execute command */
35440 +       char    *cmd_usage;             /* Usage String for this command */
35441 +       char    *cmd_help;              /* Help message for this command */
35442 +       short    cmd_flags;             /* Parsing flags */
35443 +       short    cmd_minlen;            /* Minimum legal # command chars required */
35444 +       kdb_repeat_t cmd_repeat;        /* Does command auto repeat on enter? */
35445 +} kdbtab_t;
35446 +
35447 +       /*
35448 +        * External command function declarations
35449 +        */
35450 +
35451 +extern int kdb_id(int, const char **);
35452 +extern int kdb_bt(int, const char **);
35453 +
35454 +       /*
35455 +        * External utility function declarations
35456 +        */
35457 +extern char* kdb_getstr(char *, size_t, char *);
35458 +
35459 +       /*
35460 +        * Register contents manipulation
35461 +        */
35462 +extern int kdba_getregcontents(const char *, struct pt_regs *, kdb_machreg_t *);
35463 +extern int kdba_setregcontents(const char *, struct pt_regs *, kdb_machreg_t);
35464 +extern int kdba_dumpregs(struct pt_regs *, const char *, const char *);
35465 +extern int kdba_setpc(struct pt_regs *, kdb_machreg_t);
35466 +extern kdb_machreg_t kdba_getpc(struct pt_regs *);
35467 +
35468 +       /*
35469 +        * Debug register handling.
35470 +        */
35471 +extern void kdba_installdbreg(kdb_bp_t*);
35472 +extern void kdba_removedbreg(kdb_bp_t*);
35473 +
35474 +       /*
35475 +        * Breakpoint handling - External interfaces
35476 +        */
35477 +extern void kdb_initbptab(void);
35478 +extern void kdb_bp_install_global(struct pt_regs *);
35479 +extern void kdb_bp_install_local(struct pt_regs *);
35480 +extern void kdb_bp_remove_global(void);
35481 +extern void kdb_bp_remove_local(void);
35482 +
35483 +       /*
35484 +        * Breakpoint handling - Internal to kdb_bp.c/kdba_bp.c
35485 +        */
35486 +extern int kdba_installbp(struct pt_regs *regs, kdb_bp_t *);
35487 +extern int kdba_removebp(kdb_bp_t *);
35488 +
35489 +
35490 +typedef enum {
35491 +       KDB_DB_BPT,     /* Breakpoint */
35492 +       KDB_DB_SS,      /* Single-step trap */
35493 +       KDB_DB_SSB,     /* Single step to branch */
35494 +       KDB_DB_SSBPT,   /* Single step over breakpoint */
35495 +       KDB_DB_NOBPT    /* Spurious breakpoint */
35496 +} kdb_dbtrap_t;
35497 +
35498 +extern kdb_dbtrap_t kdba_db_trap(struct pt_regs *, int);       /* DEBUG trap/fault handler */
35499 +extern kdb_dbtrap_t kdba_bp_trap(struct pt_regs *, int);       /* Breakpoint trap/fault hdlr */
35500 +
35501 +       /*
35502 +        * Interrupt Handling
35503 +        */
35504 +typedef unsigned long kdb_intstate_t;
35505 +
35506 +extern void kdba_disableint(kdb_intstate_t *);
35507 +extern void kdba_restoreint(kdb_intstate_t *);
35508 +
35509 +       /*
35510 +        * SMP and process stack manipulation routines.
35511 +        */
35512 +extern int kdba_ipi(struct pt_regs *, void (*)(void));
35513 +extern int kdba_main_loop(kdb_reason_t, kdb_reason_t, int, kdb_dbtrap_t, struct pt_regs *);
35514 +extern int kdb_main_loop(kdb_reason_t, kdb_reason_t, int, kdb_dbtrap_t, struct pt_regs *);
35515 +
35516 +       /*
35517 +        * General Disassembler interfaces
35518 +        */
35519 +extern int kdb_dis_fprintf(PTR, const char *, ...) __attribute__ ((format (printf, 2, 3)));
35520 +extern int kdb_dis_fprintf_dummy(PTR, const char *, ...) __attribute__ ((format (printf, 2, 3)));
35521 +extern disassemble_info        kdb_di;
35522 +
35523 +       /*
35524 +        * Architecture Dependent Disassembler interfaces
35525 +        */
35526 +extern int  kdba_id_printinsn(kdb_machreg_t, disassemble_info *);
35527 +extern int  kdba_id_parsemode(const char *, disassemble_info*);
35528 +extern void kdba_id_init(disassemble_info *);
35529 +extern void kdba_check_pc(kdb_machreg_t *);
35530 +
35531 +       /*
35532 +        * Miscellaneous functions and data areas
35533 +        */
35534 +extern char *kdb_cmds[];
35535 +extern void kdb_syslog_data(char *syslog_data[]);
35536 +extern unsigned long kdb_task_state_string(const char *);
35537 +extern char kdb_task_state_char (const struct task_struct *);
35538 +extern unsigned long kdb_task_state(const struct task_struct *p, unsigned long mask);
35539 +extern void kdb_ps_suppressed(void);
35540 +extern void kdb_ps1(const struct task_struct *p);
35541 +extern int kdb_parse(const char *cmdstr);
35542 +extern void kdb_print_nameval(const char *name, unsigned long val);
35543 +extern void kdb_send_sig_info(struct task_struct *p, struct siginfo *info, int seqno);
35544 +#ifdef CONFIG_SWAP
35545 +extern void kdb_si_swapinfo(struct sysinfo *);
35546 +#else
35547 +#include <linux/swap.h>
35548 +#define kdb_si_swapinfo(x) si_swapinfo(x)
35549 +#endif
35550 +extern void kdb_meminfo_read_proc(void);
35551 +#ifdef CONFIG_HUGETLB_PAGE
35552 +extern void kdb_hugetlb_report_meminfo(void);
35553 +#endif /* CONFIG_HUGETLB_PAGE */
35554 +extern const char *kdb_walk_kallsyms(loff_t *pos);
35555 +
35556 +       /*
35557 +        * Architecture Dependant Local Processor setup & cleanup interfaces
35558 +        */
35559 +extern void kdba_local_arch_setup(void);
35560 +extern void kdba_local_arch_cleanup(void);
35561 +
35562 +       /*
35563 +        * Defines for kdb_symbol_print.
35564 +        */
35565 +#define KDB_SP_SPACEB  0x0001          /* Space before string */
35566 +#define KDB_SP_SPACEA  0x0002          /* Space after string */
35567 +#define KDB_SP_PAREN   0x0004          /* Parenthesis around string */
35568 +#define KDB_SP_VALUE   0x0008          /* Print the value of the address */
35569 +#define KDB_SP_SYMSIZE 0x0010          /* Print the size of the symbol */
35570 +#define KDB_SP_NEWLINE 0x0020          /* Newline after string */
35571 +#define KDB_SP_DEFAULT (KDB_SP_VALUE|KDB_SP_PAREN)
35572 +
35573 +/* Save data about running processes */
35574 +
35575 +struct kdb_running_process {
35576 +       struct task_struct *p;
35577 +       struct pt_regs *regs;
35578 +       int seqno;                              /* kdb sequence number */
35579 +       int irq_depth;                          /* irq count */
35580 +       struct kdba_running_process arch;       /* arch dependent save data */
35581 +};
35582 +
35583 +extern struct kdb_running_process kdb_running_process[/* NR_CPUS */];
35584 +
35585 +extern void kdb_save_running(struct pt_regs *);
35586 +extern void kdb_unsave_running(struct pt_regs *);
35587 +extern struct task_struct *kdb_curr_task(int);
35588 +
35589 +/*     Incremented each time the main kdb loop is entered on the initial cpu,
35590 + *     it gives some indication of how old the saved data is.
35591 + */
35592 +extern int kdb_seqno;
35593 +
35594 +#define kdb_task_has_cpu(p) (task_curr(p))
35595 +extern void kdb_runqueue(unsigned long cpu, kdb_printf_t xxx_printf);
35596 +
35597 +/* Simplify coexistence with NPTL */
35598 +#define        kdb_do_each_thread(g, p) do_each_thread(g, p)
35599 +#define        kdb_while_each_thread(g, p) while_each_thread(g, p)
35600 +
35601 +#define GFP_KDB (in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
35602 +
35603 +extern void *debug_kmalloc(size_t size, gfp_t flags);
35604 +extern void debug_kfree(void *);
35605 +extern void debug_kusage(void);
35606 +
35607 +extern void kdba_set_current_task(const struct task_struct *);
35608 +extern const struct task_struct *kdb_current_task;
35609 +extern struct pt_regs *kdb_current_regs;
35610 +
35611 +/* Functions to safely read and write kernel areas.  The {to,from}_xxx
35612 + * addresses are not necessarily valid, these functions must check for
35613 + * validity.  If the arch already supports get and put routines with suitable
35614 + * validation and/or recovery on invalid addresses then use those routines,
35615 + * otherwise check it yourself.
35616 + */
35617 +
35618 +extern int kdba_putarea_size(unsigned long to_xxx, void *from, size_t size);
35619 +extern int kdba_getarea_size(void *to, unsigned long from_xxx, size_t size);
35620 +extern int kdba_verify_rw(unsigned long addr, size_t size);
35621 +
35622 +#ifndef KDB_RUNNING_PROCESS_ORIGINAL
35623 +#define KDB_RUNNING_PROCESS_ORIGINAL kdb_running_process
35624 +#endif
35625 +
35626 +extern int kdb_wait_for_cpus_secs;
35627 +extern void kdba_cpu_up(void);
35628 +extern char kdb_prompt_str[];
35629 +
35630 +#define        KDB_WORD_SIZE   ((int)sizeof(kdb_machreg_t))
35631 +
35632 +#endif /* !_KDBPRIVATE_H */
35633 diff -Nurp linux-2.6.22-590/include/linux/sysctl.h linux-2.6.22-600/include/linux/sysctl.h
35634 --- linux-2.6.22-590/include/linux/sysctl.h     2008-04-09 18:10:57.000000000 +0200
35635 +++ linux-2.6.22-600/include/linux/sysctl.h     2008-04-09 18:14:28.000000000 +0200
35636 @@ -166,6 +166,7 @@ enum
35637         KERN_MAX_LOCK_DEPTH=74,
35638         KERN_NMI_WATCHDOG=75, /* int: enable/disable nmi watchdog */
35639         KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
35640 +       KERN_KDB=77,            /* int: kdb on/off */
35641  };
35642  
35643  
35644 diff -Nurp linux-2.6.22-590/init/main.c linux-2.6.22-600/init/main.c
35645 --- linux-2.6.22-590/init/main.c        2008-04-09 18:10:53.000000000 +0200
35646 +++ linux-2.6.22-600/init/main.c        2008-04-09 18:14:28.000000000 +0200
35647 @@ -67,6 +67,10 @@
35648  #include <asm/smp.h>
35649  #endif
35650  
35651 +#ifdef CONFIG_KDB
35652 +#include <linux/kdb.h>
35653 +#endif /* CONFIG_KDB */
35654 +
35655  /*
35656   * This is one of the first .c files built. Error out early if we have compiler
35657   * trouble.
35658 @@ -188,6 +192,26 @@ static const char *panic_later, *panic_p
35659  
35660  extern struct obs_kernel_param __setup_start[], __setup_end[];
35661  
35662 +#ifdef CONFIG_KDB
35663 +static int __init kdb_setup(char *str)
35664 +{
35665 +       if (strcmp(str, "on") == 0) {
35666 +               kdb_on = 1;
35667 +       } else if (strcmp(str, "on-nokey") == 0) {
35668 +               kdb_on = 2;
35669 +       } else if (strcmp(str, "off") == 0) {
35670 +               kdb_on = 0;
35671 +       } else if (strcmp(str, "early") == 0) {
35672 +               kdb_on = 1;
35673 +               kdb_flags |= KDB_FLAG_EARLYKDB;
35674 +       } else
35675 +               printk("kdb flag %s not recognised\n", str);
35676 +       return 0;
35677 +}
35678 +
35679 +__setup("kdb=", kdb_setup);
35680 +#endif /* CONFIG_KDB */
35681 +
35682  static int __init obsolete_checksetup(char *line)
35683  {
35684         struct obs_kernel_param *p;
35685 @@ -609,6 +633,14 @@ asmlinkage void __init start_kernel(void
35686         pgtable_cache_init();
35687         prio_tree_init();
35688         anon_vma_init();
35689 +
35690 +#ifdef CONFIG_KDB
35691 +       kdb_init();
35692 +       if (KDB_FLAG(EARLYKDB)) {
35693 +               KDB_ENTER();
35694 +       }
35695 +#endif /* CONFIG_KDB */
35696 +
35697  #ifdef CONFIG_X86
35698         if (efi_enabled)
35699                 efi_enter_virtual_mode();
35700 diff -Nurp linux-2.6.22-590/kdb/ChangeLog linux-2.6.22-600/kdb/ChangeLog
35701 --- linux-2.6.22-590/kdb/ChangeLog      1970-01-01 01:00:00.000000000 +0100
35702 +++ linux-2.6.22-600/kdb/ChangeLog      2008-04-09 18:14:28.000000000 +0200
35703 @@ -0,0 +1,1693 @@
35704 +2007-07-26 Keith Owens  <kaos@sgi.com>
35705 +
35706 +       * New x86 backtrace code.
35707 +       * kdb v4.4-2.6.22-common-4.
35708 +
35709 +2007-07-17 Keith Owens  <kaos@sgi.com>
35710 +
35711 +       * Make kdb_printf_lock an irq lock to keep lockdep happy.
35712 +       * kdb v4.4-2.6.22-common-3.
35713 +
35714 +2007-07-13 Keith Owens  <kaos@sgi.com>
35715 +
35716 +       * Increase the size of the debug_alloc pool.
35717 +       * Add the caller that obtained each entry in the debug_alloc pool.
35718 +       * Poison entries in the debug_alloc pool.
35719 +       * Track current and maximum usage in debug_alloc pool.
35720 +       * Print the debug_alloc entries that are still in use when kdb exits
35721 +         (memory leaks).
35722 +       * Increase the default value of BTARGS to 9.
35723 +       * kdb v4.4-2.6.22-common-2.
35724 +
35725 +2007-07-09 Keith Owens  <kaos@sgi.com>
35726 +
35727 +       * kdb v4.4-2.6.22-common-1.
35728 +
35729 +2007-07-02 Keith Owens  <kaos@sgi.com>
35730 +
35731 +       * kdb v4.4-2.6.22-rc7-common-1.
35732 +
35733 +2007-06-20 Keith Owens  <kaos@sgi.com>
35734 +
35735 +       * kdb v4.4-2.6.22-rc5-common-1.
35736 +
35737 +2007-06-15 Keith Owens  <kaos@sgi.com>
35738 +
35739 +       * Do not include asm/kdb.h unless CONFIG_KDB is on.  Dave Jiang.
35740 +       * kdb v4.4-2.6.22-rc4-common-2.
35741 +
35742 +2007-06-08 Keith Owens  <kaos@sgi.com>
35743 +
35744 +       * kdb v4.4-2.6.22-rc4-common-1.
35745 +
35746 +2007-05-28 Keith Owens  <kaos@sgi.com>
35747 +
35748 +       * kdb v4.4-2.6.22-rc3-common-1.
35749 +
35750 +2007-05-22 Keith Owens  <kaos@sgi.com>
35751 +
35752 +       * kdb v4.4-2.6.22-rc2-common-1.
35753 +
35754 +2007-05-22 Keith Owens  <kaos@sgi.com>
35755 +
35756 +       * kdb v4.4-2.6.22-rc1-common-1.
35757 +
35758 +2007-05-17 Keith Owens  <kaos@sgi.com>
35759 +
35760 +       * Add rdmsr and wrmsr commands for i386 and x86_64.  Original patch by
35761 +         Bernardo Innocenti for i386, reworked by Keith Owens to make it safe
35762 +         on all cpu models and to handle both i386 and x86_64.
35763 +       * kdb v4.4-2.6.21-common-3.
35764 +
35765 +2007-05-15 Keith Owens  <kaos@sgi.com>
35766 +
35767 +       * Correct alignment of debug_alloc_header.
35768 +       * kdb v4.4-2.6.21-common-2.
35769 +
35770 +2007-04-29 Keith Owens  <kaos@sgi.com>
35771 +
35772 +       * kdb v4.4-2.6.21-common-1.
35773 +
35774 +2007-04-16 Keith Owens  <kaos@sgi.com>
35775 +
35776 +       * Remove dead symbol declarations.
35777 +       * kdb v4.4-2.6.21-rc7-common-2.
35778 +
35779 +2007-04-16 Keith Owens  <kaos@sgi.com>
35780 +
35781 +       * kdb v4.4-2.6.21-rc7-common-1.
35782 +
35783 +2007-04-10 Keith Owens  <kaos@sgi.com>
35784 +
35785 +       * kdb v4.4-2.6.21-rc6-common-1.
35786 +
35787 +2007-04-02 Keith Owens  <kaos@sgi.com>
35788 +
35789 +       * kdb v4.4-2.6.21-rc5-common-1.
35790 +
35791 +2007-03-19 Keith Owens  <kaos@sgi.com>
35792 +
35793 +       * kdb v4.4-2.6.21-rc4-common-1.
35794 +
35795 +2007-03-14 Keith Owens  <kaos@sgi.com>
35796 +
35797 +       * kdb v4.4-2.6.21-rc3-common-1.
35798 +
35799 +2007-03-14 Keith Owens  <kaos@sgi.com>
35800 +
35801 +       * kdb v4.4-2.6.21-rc2-common-1.
35802 +
35803 +2007-03-01 Keith Owens  <kaos@sgi.com>
35804 +
35805 +       * kdb v4.4-2.6.21-rc1-common-1.
35806 +
35807 +2007-03-01 Keith Owens  <kaos@sgi.com>
35808 +
35809 +       * Remove sparse warnings.
35810 +       * kdb v4.4-2.6.20-common-6.
35811 +
35812 +2007-02-27 Keith Owens  <kaos@sgi.com>
35813 +
35814 +       * set_irq_regs() on entry to kdb() if they are not already set.
35815 +       * kdb v4.4-2.6.20-common-5.
35816 +
35817 +2007-02-22 Keith Owens  <kaos@sgi.com>
35818 +
35819 +       * Initialise struct disassemble_info in kdb_id1().
35820 +       * kdb v4.4-2.6.20-common-4.
35821 +
35822 +2007-02-16 Keith Owens  <kaos@sgi.com>
35823 +
35824 +       * Clean up debug_alloc_pool code.
35825 +       * kdb v4.4-2.6.20-common-3.
35826 +
35827 +2007-02-16 Keith Owens  <kaos@sgi.com>
35828 +
35829 +       * Initialise variable bits of struct disassemble_info each time.
35830 +       * kdb v4.4-2.6.20-common-2.
35831 +
35832 +2007-02-06 Keith Owens  <kaos@sgi.com>
35833 +
35834 +       * kdb v4.4-2.6.20-common-1.
35835 +
35836 +2007-02-01 Keith Owens  <kaos@sgi.com>
35837 +
35838 +       * kdb v4.4-2.6.20-rc7-common-1.
35839 +
35840 +2007-01-08 Keith Owens  <kaos@sgi.com>
35841 +
35842 +       * kdb v4.4-2.6.20-rc4-common-1.
35843 +
35844 +2007-01-02 Keith Owens  <kaos@sgi.com>
35845 +
35846 +       * kdb v4.4-2.6.20-rc3-common-1.
35847 +
35848 +2006-12-21 Keith Owens  <kaos@sgi.com>
35849 +
35850 +       * Initialize the debug_kmalloc pool on the first call, so it can be
35851 +         used at any time.
35852 +       * kdb v4.4-2.6.20-rc1-common-2.
35853 +
35854 +2006-12-20 Keith Owens  <kaos@sgi.com>
35855 +
35856 +       * kdb v4.4-2.6.20-rc1-common-1.
35857 +
35858 +2006-11-30 Keith Owens  <kaos@sgi.com>
35859 +
35860 +       * kdb v4.4-2.6.19-common-1.
35861 +
35862 +2006-11-30 Keith Owens  <kaos@sgi.com>
35863 +
35864 +       * Do not access registers if kdb_current_regs is NULL.
35865 +       * kdb v4.4-2.6.19-rc6-common-3.
35866 +
35867 +2006-11-27 Keith Owens  <kaos@sgi.com>
35868 +
35869 +       * Only use VT keyboard if the command line allows it and ACPI indicates
35870 +         that there is an i8042.
35871 +       * Optimize kdb_read() to reduce the risk of dropping input characters.
35872 +       * Print cpumasks as lists instead of hex, also cope with long lists.
35873 +       * kdb v4.4-2.6.19-rc6-common-2.
35874 +
35875 +2006-11-20 Keith Owens  <kaos@sgi.com>
35876 +
35877 +       * kdb v4.4-2.6.19-rc6-common-1.
35878 +
35879 +2006-11-09 Keith Owens  <kaos@sgi.com>
35880 +
35881 +       * Change kdb() to fastcall.
35882 +       * Correct loop in kdb_help().  Georg Nikodym.
35883 +       * Only use VT console if the command line allows it.
35884 +       * kdb v4.4-2.6.19-rc5-common-2.
35885 +
35886 +2006-11-08 Keith Owens  <kaos@sgi.com>
35887 +
35888 +       * kdb v4.4-2.6.19-rc5-common-1.
35889 +
35890 +2006-11-01 Keith Owens  <kaos@sgi.com>
35891 +
35892 +       * kdb v4.4-2.6.19-rc4-common-1.
35893 +
35894 +2006-10-24 Keith Owens  <kaos@sgi.com>
35895 +
35896 +       * kdb v4.4-2.6.19-rc3-common-1.
35897 +
35898 +2006-10-24 Keith Owens  <kaos@sgi.com>
35899 +
35900 +       * Remove redundant regs and envp parameters.
35901 +       * kdb v4.4-2.6.19-rc2-common-2.
35902 +
35903 +2006-10-18 Keith Owens  <kaos@sgi.com>
35904 +
35905 +       * kdb v4.4-2.6.19-rc2-common-1.
35906 +
35907 +2006-10-11 Keith Owens  <kaos@sgi.com>
35908 +
35909 +       * Move kdbm_x86.c from the i386 to the common KDB patch.
35910 +       * Expand kdbm_x86.c to work on x86_64 as well as i386.
35911 +       * kdb v4.4-2.6.19-rc1-common-2.
35912 +
35913 +2006-10-09 Keith Owens  <kaos@sgi.com>
35914 +
35915 +       * kdb v4.4-2.6.19-rc1-common-1.
35916 +
35917 +2006-10-06 Keith Owens  <kaos@sgi.com>
35918 +
35919 +       * Remove #include <linux/config.h>
35920 +       * kdb v4.4-2.6.18-common-2.
35921 +
35922 +2006-09-20 Keith Owens  <kaos@sgi.com>
35923 +
35924 +       * kdb v4.4-2.6.18-common-1.
35925 +
35926 +2006-09-15 Keith Owens  <kaos@sgi.com>
35927 +
35928 +       * kdb v4.4-2.6.18-rc7-common-1.
35929 +
35930 +2006-08-29 Keith Owens  <kaos@sgi.com>
35931 +
35932 +       * Rewrite all backtrace code.
35933 +       * kdb v4.4-2.6.18-rc5-common-2.
35934 +
35935 +2006-08-28 Keith Owens  <kaos@sgi.com>
35936 +
35937 +       * kdb v4.4-2.6.18-rc5-common-1.
35938 +
35939 +2006-08-08 Keith Owens  <kaos@sgi.com>
35940 +
35941 +       * kdb v4.4-2.6.18-rc4-common-1.
35942 +
35943 +2006-08-04 Keith Owens  <kaos@sgi.com>
35944 +
35945 +       * kdb v4.4-2.6.18-rc3-common-1.
35946 +
35947 +2006-07-18 Keith Owens  <kaos@sgi.com>
35948 +
35949 +       * 8250.c locking has been fixed so there is no need to break spinlocks
35950 +         for keyboard entry.
35951 +       * kdb v4.4-2.6.18-rc2-common-2.
35952 +
35953 +2006-07-18 Keith Owens  <kaos@sgi.com>
35954 +
35955 +       * kdb v4.4-2.6.18-rc2-common-1.
35956 +
35957 +2006-07-12 Keith Owens  <kaos@sgi.com>
35958 +
35959 +       * Remove dead KDB_REASON codes.
35960 +       * The main kdb() function is now always entered with interrupts
35961 +         disabled, so there is no need to disable bottom halves.
35962 +       * sparse cleanups.
35963 +       * kdb v4.4-2.6.18-rc1-common-2.
35964 +
35965 +2006-07-07 Keith Owens  <kaos@sgi.com>
35966 +
35967 +       * kdb v4.4-2.6.18-rc1-common-1.
35968 +
35969 +2006-07-04 Keith Owens  <kaos@sgi.com>
35970 +
35971 +       * Add KDB_REASON_CPU_UP and callbacks for cpus coming online.
35972 +       * Relegate KDB_REASON_SILENT to KDB internal use only.
35973 +       * Backout the v4.4-2.6.15-common-3 change that made KDB_REASON_SILENT
35974 +         wait for cpus, the Dell Xeon problem has been fixed.
35975 +       * notify_die() is not called for KDB_REASON_SILENT nor
35976 +         KDB_REASON_CPU_UP, these events do not stay in KDB.
35977 +       * Export kdb_current_task for kdbm_x86.  SuSE patch
35978 +         kdb-missing-export.diff
35979 +       * Scale kdb_wait_for_cpus_secs by the number of online cpus.
35980 +       * Delete kdb_enablehwfault, architectures now do their own setup.
35981 +       * Delete kdba_enable_mce, architectures now do their own setup.
35982 +       * Delete kdba_enable_lbr, kdba_disable_lbr, kdba_print_lbr,
35983 +         page_fault_mca.  Only ever implemented on x86, difficult to maintain
35984 +         and rarely used in the field.
35985 +       * Replace #ifdef KDB_HAVE_LONGJMP with #ifdef kdba_setjmp.
35986 +       * kdb v4.4-2.6.17-common-2.
35987 +
35988 +2006-06-19 Keith Owens  <kaos@sgi.com>
35989 +
35990 +       * kdb v4.4-2.6.17-common-1.
35991 +
35992 +2006-05-31 Keith Owens  <kaos@sgi.com>
35993 +
35994 +       * Break spinlocks for keyboard entry.  Hopefully a temporary hack while
35995 +         I track down why keyboard entry to KDB is hanging.
35996 +       * kdb v4.4-2.6.17-rc5-common-2.
35997 +
35998 +2006-05-25 Keith Owens  <kaos@sgi.com>
35999 +
36000 +       * kdb v4.4-2.6.17-rc5-common-1.
36001 +
36002 +2006-05-15 Keith Owens  <kaos@sgi.com>
36003 +
36004 +       * Refresh bfd related files from binutils 2.16.91.0.2.
36005 +       * kdb v4.4-2.6.17-rc4-common-2.
36006 +
36007 +2006-05-12 Keith Owens  <kaos@sgi.com>
36008 +
36009 +       * kdb v4.4-2.6.17-rc4-common-1.
36010 +
36011 +2006-04-28 Keith Owens  <kaos@sgi.com>
36012 +
36013 +       * kdb v4.4-2.6.17-rc3-common-1.
36014 +
36015 +2006-04-22 Keith Owens  <kaos@sgi.com>
36016 +
36017 +       * kdb v4.4-2.6.17-rc2-common-1.
36018 +
36019 +2006-04-11 Keith Owens  <kaos@sgi.com>
36020 +
36021 +       * kdb v4.4-2.6.17-rc1-common-1.
36022 +
36023 +2006-04-05 Keith Owens  <kaos@sgi.com>
36024 +
36025 +       * More fixes for the timing race with KDB_ENTER_SLAVE.
36026 +       * kdb v4.4-2.6.16-common-5.
36027 +
36028 +2006-03-30 Keith Owens  <kaos@sgi.com>
36029 +
36030 +       * Some code was testing KDB_IS_RUNNING() twice, which left it open to
36031 +         races.  Cache the result instead.
36032 +       * kdb v4.4-2.6.16-common-4.
36033 +
36034 +2006-03-30 Keith Owens  <kaos@sgi.com>
36035 +
36036 +       * Change CONFIG_LKCD to CONFIG_LKCD_DUMP.
36037 +       * kdb v4.4-2.6.16-common-3.
36038 +
36039 +2006-03-22 Keith Owens  <kaos@sgi.com>
36040 +
36041 +       * Add some more xpc flags.  Dean Nelson, SGI.
36042 +       * Replace open coded counter references with atomic_read().
36043 +       * Pass early_uart_console to early_uart_setup().  Francois
36044 +         Wellenreiter, Bull.
36045 +       * Replace open code with for_each_online_cpu().
36046 +       * If cpus do not come into kdb after a few seconds then let
36047 +         architectures send a more forceful interrupt.
36048 +       * Close a timing race with KDB_ENTER_SLAVE.
36049 +       * kdb v4.4-2.6.16-common-2.
36050 +
36051 +2006-03-21 Keith Owens  <kaos@sgi.com>
36052 +
36053 +       * kdb v4.4-2.6.16-common-1.
36054 +
36055 +2006-03-14 Nathan Scott  <nathans@sgi.com>
36056 +
36057 +       * kdb v4.4-2.6.16-rc6-common-1.
36058 +
36059 +2006-02-28 Nathan Scott  <nathans@sgi.com>
36060 +
36061 +       * kdb v4.4-2.6.16-rc5-common-1.
36062 +
36063 +2006-02-20 Nathan Scott  <nathans@sgi.com>
36064 +
36065 +       * kdb v4.4-2.6.16-rc4-common-1.
36066 +
36067 +2006-02-06 Keith Owens  <kaos@sgi.com>
36068 +
36069 +       * Change CONFIG_CRASH_DUMP to CONFIG_LKCD.
36070 +       * Remove obsolete kdb_notifier_list.
36071 +       * kdb v4.4-2.6.16-rc2-common-2.
36072 +
36073 +2006-02-06 Keith Owens  <kaos@sgi.com>
36074 +
36075 +       * Add xpcusers command.  Dean Nelson, SGI.
36076 +       * kdb v4.4-2.6.16-rc2-common-1.
36077 +
36078 +2006-02-02 Keith Owens  <kaos@sgi.com>
36079 +
36080 +       * Check if we have a console before using it for KDB.
36081 +       * kdb v4.4-2.6.16-rc1-common-3.
36082 +
36083 +2006-02-01 Keith Owens  <kaos@sgi.com>
36084 +
36085 +       * Add option 'R' to the pid command to reset to the original task.
36086 +       * Include 'pid R' in archkdb* commands to reset up the original failing
36087 +         task.  Users may have switched to other cpus and/or tasks before
36088 +         issuing archkdb.
36089 +       * Compile fix for kdbm_pg.c on i386.
36090 +       * kdb v4.4-2.6.16-rc1-common-2.
36091 +
36092 +2006-01-18 Keith Owens  <kaos@sgi.com>
36093 +
36094 +       * kdb v4.4-2.6.16-rc1-common-1.
36095 +
36096 +2006-01-11 Keith Owens  <kaos@sgi.com>
36097 +
36098 +       * Plug a timing race between KDB_ENTER_SLAVE and KDB_ENTER, and allow
36099 +         the cpu command to switch to a slave cpu.
36100 +       * KDB_REASON_SILENT now waits for other cpus, to avoid spurious NMI
36101 +         events that were seen on some Xeon systems.
36102 +       * kdb v4.4-2.6.15-common-3.
36103 +
36104 +2006-01-08 Keith Owens  <kaos@sgi.com>
36105 +
36106 +       * kdb mainline invokes DIE_KDEBUG_ENTER and DIE_KDEBUG_LEAVE via
36107 +         notify_die.
36108 +       * Move xpc debug support from xpc to mainline kdb.
36109 +       * kdbm_cm.c: check if file_lock_operations or lock_manager_operations
36110 +         are set before dereferencing them.  Felix Blyakher, SGI.
36111 +       * kdb v4.4-2.6.15-common-2.
36112 +
36113 +2006-01-04 Keith Owens  <kaos@sgi.com>
36114 +
36115 +       * Print all buffers on a page in inode pages and update formatting to be
36116 +         legible, too.  David Chinner, SGI.
36117 +       * Update page flags in kdbm_pg.
36118 +       * Remove inline from *.c files.
36119 +       * kdb v4.4-2.6.15-common-1.
36120 +
36121 +2005-12-25 Keith Owens  <kaos@sgi.com>
36122 +
36123 +       * kdb v4.4-2.6.15-rc7-common-1.
36124 +
36125 +2005-12-20 Keith Owens  <kaos@sgi.com>
36126 +
36127 +       * kdb v4.4-2.6.15-rc6-common-1.
36128 +
36129 +2005-12-10 Keith Owens  <kaos@sgi.com>
36130 +
36131 +       * Update mapping of flags to strings in kdbm_pg.c and kdbm_vm.c.
36132 +       * kdb v4.4-2.6.15-rc5-common-3.
36133 +
36134 +2005-12-06 Keith Owens  <kaos@sgi.com>
36135 +
36136 +       * Add RECOVERY flag to global KDB flags.
36137 +       * Add kdb_{save,restore}_flags.
36138 +       * kdb v4.4-2.6.15-rc5-common-2.
36139 +
36140 +2005-12-05 Keith Owens  <kaos@sgi.com>
36141 +
36142 +       * kdb v4.4-2.6.15-rc5-common-1.
36143 +
36144 +2005-12-02 Keith Owens  <kaos@sgi.com>
36145 +
36146 +       * kdbm_vm.c: offsets of page macros should be unsigned long.  Reported
36147 +         by Dean Nelson, SGI.
36148 +       * kdb v4.4-2.6.15-rc4-common-1.
36149 +
36150 +2005-11-30 Keith Owens  <kaos@sgi.com>
36151 +
36152 +       * New follow_page() API.
36153 +       * kdb v4.4-2.6.15-rc3-common-1.
36154 +
36155 +2005-11-21 Keith Owens  <kaos@sgi.com>
36156 +
36157 +       * kdb v4.4-2.6.15-rc2-common-1.
36158 +
36159 +2005-11-15 Keith Owens  <kaos@sgi.com>
36160 +
36161 +       * kdb v4.4-2.6.15-rc1-common-1.
36162 +
36163 +2005-11-15 Keith Owens  <kaos@sgi.com>
36164 +
36165 +       * Allow kdb_printf() to be used outside kdb, in preemptible context.
36166 +       * Build with CONFIG_SWAP=n.  Reported by Leo Yuriev.
36167 +       * kdb v4.4-2.6.14-common-2.
36168 +
36169 +2005-10-28 Keith Owens  <kaos@sgi.com>
36170 +
36171 +       * kdb v4.4-2.6.14-common-1.
36172 +
36173 +2005-10-21 Keith Owens  <kaos@sgi.com>
36174 +
36175 +       * kdb v4.4-2.6.14-rc5-common-1.
36176 +
36177 +2005-10-11 Keith Owens  <kaos@sgi.com>
36178 +
36179 +       * Handle removal of USB keyboard.  Aaron Young, SGI.
36180 +       * kdb v4.4-2.6.14-rc4-common-1.
36181 +
36182 +2005-10-05 Keith Owens  <kaos@sgi.com>
36183 +
36184 +       * Extend kdb_notifier_list() codes to include dumping.
36185 +       * Use emergency_restart() for reboot, it can be called from interrupt
36186 +         context, unlike machine_restart().
36187 +       * kdb v4.4-2.6.14-rc3-common-1.
36188 +
36189 +2005-09-21 Keith Owens  <kaos@sgi.com>
36190 +
36191 +       * Support kdb_current_task in register display and modify commands.
36192 +       * Document what changes kdb's notion of the current task.
36193 +       * Update rd documentation for IA64.
36194 +       * Move some definictions to kdbprivate.h and remove some unused symbol
36195 +         exports.
36196 +       * kdb v4.4-2.6.14-rc2-common-1.
36197 +
36198 +2005-09-20 Keith Owens  <kaos@sgi.com>
36199 +
36200 +       * Document IA64 handlers command.
36201 +       * Add more fields to the task command.
36202 +       * Cope with MCA/INIT handlers in the ps command.
36203 +       * Namespace cleanup, delete unused exports, make some functions static.
36204 +       * Add a kdb_notifier_list callback when kdb is about to reboot the
36205 +         system.
36206 +       * kdb v4.4-2.6.14-rc1-common-1.
36207 +
36208 +2005-08-29 Keith Owens  <kaos@sgi.com>
36209 +
36210 +       * kdb v4.4-2.6.13-common-1.
36211 +
36212 +2005-08-24 Keith Owens  <kaos@sgi.com>
36213 +
36214 +       * kdb v4.4-2.6.13-rc7-common-1.
36215 +
36216 +2005-08-08 Keith Owens  <kaos@sgi.com>
36217 +
36218 +       * kdb v4.4-2.6.13-rc6-common-1.
36219 +
36220 +2005-08-02 Keith Owens  <kaos@sgi.com>
36221 +
36222 +       * Print more fields from filp, dentry.
36223 +       * Add kdb=on-nokey to suppress kdb entry from the keyboard.
36224 +       * kdb v4.4-2.6.13-rc5-common-1.
36225 +
36226 +2005-07-30 Keith Owens  <kaos@sgi.com>
36227 +
36228 +       * kdb v4.4-2.6.13-rc4-common-1.
36229 +
36230 +2005-07-26 Keith Owens  <kaos@sgi.com>
36231 +
36232 +       * Fix compile problem with CONFIG_USB_KBD.
36233 +       * kdb v4.4-2.6.13-rc3-common-3.
36234 +
36235 +2005-07-22 Keith Owens  <kaos@sgi.com>
36236 +
36237 +       * The asmlinkage kdb() patch was lost during packaging.  Reinstate it.
36238 +       * kdb v4.4-2.6.13-rc3-common-2.
36239 +
36240 +2005-07-19 Keith Owens  <kaos@sgi.com>
36241 +
36242 +       * Add support for USB keyboard (OHCI only).  Aaron Young, SGI.
36243 +       * kdb v4.4-2.6.13-rc3-common-1.
36244 +
36245 +2005-07-08 Keith Owens  <kaos@sgi.com>
36246 +
36247 +       * kdb v4.4-2.6.13-rc2-common-1.
36248 +
36249 +2005-07-01 Keith Owens  <kaos@sgi.com>
36250 +
36251 +       * Make kdb() asmlinkage to avoid problems with CONFIG_REGPARM.
36252 +       * Change some uses of smp_processor_id() to be preempt safe.
36253 +       * Use DEFINE_SPINLOCK().
36254 +       * kdb v4.4-2.6.13-rc1-common-1.
36255 +
36256 +2005-06-18 Keith Owens  <kaos@sgi.com>
36257 +
36258 +       * kdb v4.4-2.6.12-common-1.
36259 +
36260 +2005-06-08 Keith Owens  <kaos@sgi.com>
36261 +
36262 +       * Correct early exit from bd *.
36263 +       * kdb v4.4-2.6.12-rc6-common-1.
36264 +
36265 +2005-05-25 Keith Owens  <kaos@sgi.com>
36266 +
36267 +       * Delete Documentation/kdb/dump.txt.  lkcd now has reasonable
36268 +         integration with kdb.
36269 +       * kdb v4.4-2.6.12-rc5-common-1.
36270 +
36271 +2005-05-08 Keith Owens  <kaos@sgi.com>
36272 +
36273 +       * kdb v4.4-2.6.12-rc4-common-1.
36274 +
36275 +2005-04-21 Keith Owens  <kaos@sgi.com>
36276 +
36277 +       * Add rpte command (find the pte for a physical page).
36278 +       * kdb v4.4-2.6.12-rc3-common-1.
36279 +
36280 +2005-04-06 Keith Owens  <kaos@sgi.com>
36281 +
36282 +       * Add rq and rqa commands.  John Hawkes, SGI.
36283 +       * kdb v4.4-2.6.12-rc2-common-1.
36284 +
36285 +2005-03-29 Keith Owens  <kaos@sgi.com>
36286 +
36287 +       * Use register_sysctl_table() instead of patching kernel/sysctl.c.
36288 +       * Non-ASCII characters are not printable.
36289 +       * kdb v4.4-2.6.12-rc1-common-1.
36290 +
36291 +2005-03-15 Keith Owens  <kaos@sgi.com>
36292 +
36293 +       * More coexistence patches for lkcd.  Jason Uhlenkott, SGI.
36294 +       * kdb v4.4-2.6.11-common-3.
36295 +
36296 +2005-03-08 Keith Owens  <kaos@sgi.com>
36297 +
36298 +       * Coexistence patches for lkcd.  Jason Uhlenkott, SGI.
36299 +       * kdb v4.4-2.6.11-common-2.
36300 +
36301 +2005-03-03 Keith Owens  <kaos@sgi.com>
36302 +
36303 +       * Add kdb to drivers/serial/8250_early.c.  Francois Wellenreiter, Bull.
36304 +       * kdb v4.4-2.6.11-common-1.
36305 +
36306 +2005-02-14 Keith Owens  <kaos@sgi.com>
36307 +
36308 +       * kdb v4.4-2.6.11-rc4-common-1.
36309 +
36310 +2005-02-08 Keith Owens  <kaos@sgi.com>
36311 +
36312 +       * kdb v4.4-2.6.11-rc3-bk4-common-1.
36313 +
36314 +2005-02-03 Keith Owens  <kaos@sgi.com>
36315 +
36316 +       * Print more superblock fields.  Nathan Scott, SGI.
36317 +       * Remove kallsyms correction for modules, Linus took it.
36318 +       * kdb v4.4-2.6.11-rc3-common-1.
36319 +
36320 +2005-01-27 Keith Owens  <kaos@sgi.com>
36321 +
36322 +       * Add bio command.  Nathan Scott, SGI.
36323 +       * kdb v4.4-2.6.11-rc2-common-1.
36324 +
36325 +2005-01-20 Keith Owens  <kaos@sgi.com>
36326 +
36327 +       * Include kallsyms correction for modules until Linus takes it.
36328 +       * kdb v4.4-2.6.11-rc1-bk7-common-1.
36329 +
36330 +2005-01-12 Keith Owens  <kaos@sgi.com>
36331 +
36332 +       * kallsyms now supports all symbols properly, remove kdb patch.
36333 +       * Add last ditch allocator for debugging.
36334 +       * Update kdb_meminfo_read_proc() for vmalloc changes.
36335 +       * Update kdbm_vm.c for 4 level page tables.
36336 +       * kdb v4.4-2.6.11-rc1-common-1.
36337 +
36338 +2004-12-25 Keith Owens  <kaos@sgi.com>
36339 +
36340 +       * Add kobject command.
36341 +       * Ignore low addresses and large offsets in kdbnearsym().
36342 +       * Console updates for sn2 simulator.
36343 +       * kdb v4.4-2.6.10-common-1.
36344 +
36345 +2004-12-07 Keith Owens  <kaos@sgi.com>
36346 +
36347 +       * kdb v4.4-2.6.10-rc3-common-1.
36348 +
36349 +2004-11-23 Keith Owens  <kaos@sgi.com>
36350 +
36351 +       * Remove warning message from kdb_get_one_user_page(), it was too noisy.
36352 +       * kdb v4.4-2.6.10-rc2-common-1.
36353 +
36354 +2004-11-02 Keith Owens  <kaos@sgi.com>
36355 +
36356 +       * Build with kdb patch applied but CONFIG_KDB=n.
36357 +       * kdb v4.4-2.6.10-rc1-common-2.
36358 +
36359 +2004-10-29 Keith Owens  <kaos@sgi.com>
36360 +
36361 +       * Handle new compression scheme for kallsyms.
36362 +       * Handle move of DEAD and ZOMBIE for task->state to task->exit_state.
36363 +       * Tweak the concept of a valid kernel address to get all symbols,
36364 +         including the symbols in the ia64 gate page.
36365 +       * kdb v4.4-2.6.10-rc1-common-1.
36366 +
36367 +2004-10-21 Keith Owens  <kaos@sgi.com>
36368 +
36369 +       * Handle variable size for the kernel log buffer.
36370 +       * kdb v4.4-2.6.9-common-2.
36371 +
36372 +2004-10-19 Keith Owens  <kaos@sgi.com>
36373 +
36374 +       * kdb v4.4-2.6.9-common-1.
36375 +
36376 +2004-10-12 Keith Owens  <kaos@sgi.com>
36377 +
36378 +       * kdb v4.4-2.6.9-rc4-common-1.
36379 +
36380 +2004-10-01 Keith Owens  <kaos@sgi.com>
36381 +
36382 +       * kdb v4.4-2.6.9-rc3-common-1.
36383 +
36384 +2004-09-30 Keith Owens  <kaos@sgi.com>
36385 +
36386 +       * Add stackdepth command to Documentation/kdb/kdb.mm.  stackdepth is
36387 +         only supported on i386 and ia64 at the moment.
36388 +       * Skip kdbm_pg memmap build on x86_64.  Scott Lurndal, 3leafnetworks.
36389 +       * Export kdb_serial_str for modular I/O.  Bryan Cardillo, UPenn.
36390 +       * Reinstate tab completion for symbols.
36391 +       * kdb v4.4-2.6.9-rc2-common-2.
36392 +
36393 +2004-09-14 Keith Owens  <kaos@sgi.com>
36394 +
36395 +       * Add task states C (traCed) and E (dEad).
36396 +       * kdb v4.4-2.6.9-rc2-common-1.
36397 +
36398 +2004-08-27 Keith Owens  <kaos@sgi.com>
36399 +
36400 +       * kdb v4.4-2.6.9-rc1-common-1.
36401 +
36402 +2004-08-14 Keith Owens  <kaos@sgi.com>
36403 +
36404 +       * kdb v4.4-2.6.8-common-1.
36405 +
36406 +2004-08-12 Keith Owens  <kaos@sgi.com>
36407 +
36408 +       * kdb v4.4-2.6.8-rc4-common-1.
36409 +
36410 +2004-08-05 Keith Owens  <kaos@sgi.com>
36411 +
36412 +       * Mark kdb_initcall as __attribute_used__ for newer gcc.
36413 +       * kdb v4.4-2.6.8-rc3-common-2.
36414 +
36415 +2004-08-04 Keith Owens  <kaos@sgi.com>
36416 +
36417 +       * Add mdp (memory display physical) comnmand.
36418 +         Ananth N Mavinakayanahalli, IBM.
36419 +       * kdb v4.4-2.6.8-rc3-common-1.
36420 +
36421 +2004-07-18 Keith Owens  <kaos@sgi.com>
36422 +
36423 +       * Patch for new sn_console.  Erik Jacobson. SGI.
36424 +       * kdb v4.4-2.6.8-rc2-common-1.
36425 +
36426 +2004-07-12 Keith Owens  <kaos@sgi.com>
36427 +
36428 +       * Convert kdbm_task to standard cpumask_t.
36429 +       * Document '*' (all breakpoints) option on bd/be/bc commands.
36430 +       * kdb v4.4-2.6.8-rc1-common-1.
36431 +
36432 +2004-06-30 Keith Owens  <kaos@sgi.com>
36433 +
36434 +       * Common changes to help the x86-64 port.
36435 +       * kdb v4.4-2.6.7-common-3.
36436 +
36437 +2004-06-20 Keith Owens  <kaos@sgi.com>
36438 +
36439 +       * Move kdb includes in mm/swapfile.c to reduce conflicts with other
36440 +         SGI patches.
36441 +       * kdb v4.4-2.6.7-common-2.
36442 +
36443 +2004-06-16 Keith Owens  <kaos@sgi.com>
36444 +
36445 +       * kdb v4.4-2.6.7-common-1.
36446 +
36447 +2004-06-09 Keith Owens  <kaos@sgi.com>
36448 +
36449 +       * kdb v4.4-2.6.7-rc3-common-1.
36450 +
36451 +2004-06-09 Keith Owens  <kaos@sgi.com>
36452 +
36453 +       * Namespace clean up.  Mark code/variables as static when it is only
36454 +         used in one file, delete dead code/variables.
36455 +       * Saved interrupt state requires long, not int.
36456 +       * kdb v4.4-2.6.7-rc2-common-3.
36457 +
36458 +2004-06-08 Keith Owens  <kaos@sgi.com>
36459 +
36460 +       * Whitespace clean up, no code changes.
36461 +       * kdb v4.4-2.6.7-rc2-common-2.
36462 +
36463 +2004-06-07 Keith Owens  <kaos@sgi.com>
36464 +
36465 +       * kdb v4.4-2.6.7-rc2-common-1.
36466 +
36467 +2004-06-06 Keith Owens  <kaos@sgi.com>
36468 +
36469 +       * Avoid recursion problems in kdb_init().
36470 +       * Add standard archkdb commands.
36471 +       * Add per_cpu command.
36472 +       * Move kdb_{get,put}userarea_size definitions to linux/kdb.h.
36473 +       * kdb v4.4-2.6.6-common-2.
36474 +
36475 +2004-05-23 Keith Owens  <kaos@sgi.com>
36476 +
36477 +       * Shrink the output from the cpu command.
36478 +       * Add cpu state 'I', the cpu is idle.
36479 +       * Add cpu state '+', some kdb data is available but the cpu is not
36480 +         responding.
36481 +       * Do not print tasks in state I or M by default in ps and bta commands.
36482 +       * Add states I (idle task) and M (sleeping system daemon) to ps and
36483 +         bta commands.
36484 +       * Delete unused variables.
36485 +       * Move private kdb fields from kdb.h to kdbprivate.h.
36486 +       * Print 'for keyboard entry' for the special cases when KDB_ENTER() is
36487 +         used to get registers.
36488 +       * Move bfd.h and ansidecl.h from arch/$(ARCH)/kdb to include/asm-$(ARCH)
36489 +         and remove -I arch/$(ARCH)/kdb.
36490 +       * dmesg command now prints from either the start or end of dmesg, or at
36491 +         an arbitrary point in the middle of the kernel log buffer.
36492 +       * Sensible string dump for multi byte md commands.
36493 +       * 'page' command handles ia64 correctly.
36494 +       * Show some activity when waiting for cpus to enter kdb.
36495 +       * Change the KDB entry code to <esc>KDB.
36496 +       * Allow comment commands, starting with '#'.
36497 +       * Commands defined using defcmd from kdb_cmds are not printed as they
36498 +         are entered, use defcmd with no parameters to print all the defined
36499 +         commands.
36500 +       * Add summary command.
36501 +       * Update copyright notices.
36502 +       * Zero suppression on md command.
36503 +       * Make set NOSECT=1 the default.
36504 +       * PPC64 uses OF-stdout instead of console.  Ananth N Mavinakayanahalli.
36505 +       * kdb v4.4-2.6.6-common-1.
36506 +
36507 +2004-05-10 Keith Owens  <kaos@sgi.com>
36508 +
36509 +       * kdb v4.3-2.6.6-common-1.
36510 +
36511 +2004-05-06 Keith Owens  <kaos@sgi.com>
36512 +
36513 +       * kdb v4.3-2.6.6-rc3-common-1.
36514 +
36515 +2004-05-06 Keith Owens  <kaos@sgi.com>
36516 +
36517 +       * kdb v4.3-2.6.6-rc2-common-1.
36518 +
36519 +2004-04-30 Keith Owens  <kaos@sgi.com>
36520 +
36521 +       * Rewrite inode_pages command for new radix code in struct page.
36522 +       * kdb v4.3-2.6.6-rc1-common-1.
36523 +
36524 +2004-04-11 Keith Owens  <kaos@sgi.com>
36525 +
36526 +       * Unlock sn_sal_lock before entering kdb from sn_serial.
36527 +       * kdb v4.3-2.6.5-common-2.
36528 +
36529 +2004-04-05 Keith Owens  <kaos@sgi.com>
36530 +
36531 +       * kdb v4.3-2.6.5-common-1.
36532 +
36533 +2004-03-22 Keith Owens  <kaos@sgi.com>
36534 +
36535 +       * kdb v4.3-2.6.5-rc2-common-1.
36536 +
36537 +2004-03-12 Keith Owens  <kaos@sgi.com>
36538 +
36539 +       * More work to avoid spurious messages from WARN_CONSOLE_UNLOCKED().
36540 +       * bh command bug fixes.  Nathan Scott.
36541 +       * kdb v4.3-2.6.4-common-1.
36542 +
36543 +2004-03-06 Keith Owens  <kaos@sgi.com>
36544 +
36545 +       * Set KDB_IS_RUNNING() during kdb_init to avoid spurious messages from
36546 +         WARN_CONSOLE_UNLOCKED().
36547 +       * Correct loss of symbol names in kdbnearsym.
36548 +       * kdb v4.3-2.6.4-rc2-common-1.
36549 +
36550 +2004-02-29 Keith Owens  <kaos@sgi.com>
36551 +
36552 +       * kdb v4.3-2.6.4-rc1-common-1.
36553 +
36554 +2004-02-21 Keith Owens  <kaos@sgi.com>
36555 +
36556 +       * Correct build of kdb_cmds when using a separate object directory and
36557 +         make it quiet.  j-nomura (NEC), Keith Owens.
36558 +       * kdb v4.3-2.6.3-common-2.
36559 +
36560 +2004-02-18 Keith Owens  <kaos@sgi.com>
36561 +
36562 +       * kdb v4.3-2.6.3-common-1.
36563 +
36564 +2004-02-17 Keith Owens  <kaos@sgi.com>
36565 +
36566 +       * Remove WAR for incorrect console registration patch.
36567 +       * kdb v4.3-2.6.3-rc4-common-1.
36568 +
36569 +2004-02-17 Keith Owens  <kaos@sgi.com>
36570 +
36571 +       * Convert longjmp buffers from static to dynamic allocation, for large
36572 +         cpu counts.
36573 +       * Tweak kdbm_task for SMP/UP.
36574 +       * Reconcile with kdb-v4.3 2.4.25-rc1-common-1.
36575 +       * Simplify coexistence with NPTL patches.
36576 +       * Support kill command on new scheduler.
36577 +       * Do not refetch data when printing a value as characters.
36578 +       * Document the pid command.
36579 +       * Work around 2.6 kallsyms 'feature'.
36580 +       * Upgrade to 2.6.3-rc3.
36581 +       * WAR for incorrect console registration patch.
36582 +       * kdb v4.3-2.6.3-rc3-common-1.
36583 +
36584 +2003-12-03 Keith Owens  <kaos@sgi.com>
36585 +
36586 +       * Reconcile 2.6-test versions from Xavier Bru (Bull), Greg Banks (SGI),
36587 +         Jim Houston (Concurrent Computer Corp).
36588 +       * Reconcile with kdb v4.3-2.4.23-common-2.
36589 +       * Clean up CONFIG_KDB changes to {scripts,kernel}/kallsyms.c.
36590 +       * Correct handling of kdb command line arguments.
36591 +       * Make hooks into module code less intrusive.
36592 +       * Delete kdb_active_task, not required with O(1) scheduler.
36593 +       * Port kdbm_task.c from 2.4.
36594 +       * Disable debug check in exit.c::next_thread() when kdb is running.
36595 +       * Remove "only bh_disable when interrupts are set".  BH must be disabled
36596 +         in kdb to prevent deadlock on breakpoints in interrupt handlers.
36597 +       * Add kdb to drivers/char/sn_serial.c.
36598 +       * kdb v4.3-2.6.0-test11-common-1.
36599 +
36600 +2003-11-11 Xavier Bru   <xavier.bru@bull.net>
36601 +       * Merge to 2.6.0-test9
36602 +2003-10-17 Xavier Bru   <xavier.bru@bull.net>
36603 +       * fix NUll ptr in kdb_ps at early prompt.
36604 +2003-10-14 Xavier Bru   <xavier.bru@bull.net>
36605 +       * fix NUll ptr in kdb_ps when cpu not present.
36606 +2003-10-06 Xavier Bru   <xavier.bru@bull.net>
36607 +       * Merge to 2.6.0-test5
36608 +       * fix compile error with CONFIG_MODULES not set.
36609 +
36610 +2003-09-08 Xavier Bru   <xavier.bru@bull.net>
36611 +       * Merge to 2.6.0-test4
36612 +
36613 +2003-07-10 Xavier Bru   <xavier.bru@bull.net>
36614 +
36615 +       * Merge kdb v4.3 to 2.5.72 ia64
36616 +       * don't call local_bh_enable() with interrupts masked.
36617 +
36618 +2003-04-07 Xavier Bru   <xavier.bru@bull.net>
36619 +
36620 +       * Merge kdb v4.1 to 2.5.64 ia64
36621 +       * new kernel parameters support
36622 +       * new module format
36623 +       * new kallsyms support
36624 +
36625 +2003-12-02 Keith Owens  <kaos@sgi.com>
36626 +
36627 +       * Use correct page alignment in kdb_get_one_user_page().
36628 +         Prasanna S Panchamukhi, IBM.
36629 +       * Split pte command into pte -m and pte -p.  Dean Roe, SGI.
36630 +       * kdb v4.3-2.4.23-common-2.
36631 +
36632 +2003-12-01 Keith Owens  <kaos@sgi.com>
36633 +
36634 +       * kdb v4.3-2.4.23-common-1.
36635 +
36636 +2003-11-11 Keith Owens  <kaos@sgi.com>
36637 +
36638 +       * Make KDB for USB keyboards build.  Peter T. Breuer.
36639 +       * Do not use USB keyboard if it has not been probed.
36640 +       * kdb v4.3-2.4.23-rc1-common-1.
36641 +
36642 +2003-10-10 Keith Owens  <kaos@sgi.com>
36643 +
36644 +       * Sync with XFS 2.4.22 tree.
36645 +       * kdb v4.3-2.4.22-common-2.
36646 +
36647 +2003-08-29 Keith Owens  <kaos@sgi.com>
36648 +
36649 +       * kdb v4.3-2.4.22-common-1.
36650 +
36651 +2003-07-27 Keith Owens  <kaos@sgi.com>
36652 +
36653 +       * kdb v4.3-2.4.22-pre8-common-8.
36654 +
36655 +2003-07-20 Keith Owens  <kaos@sgi.com>
36656 +
36657 +       * Make kdb_serial_str a common constant, the same for all consoles.
36658 +       * Support SGI L1 console.
36659 +       * kdb v4.3-2.4.21-common-8.
36660 +
36661 +2003-07-14 Keith Owens  <kaos@sgi.com>
36662 +
36663 +       * Correct ll command.
36664 +       * kdb v4.3-2.4.21-common-7.
36665 +
36666 +2003-07-08 Keith Owens  <kaos@sgi.com>
36667 +
36668 +       * Export more kdb symbols.  Vamsi Krishna S., IBM.
36669 +       * kdb v4.3-2.4.21-common-6.
36670 +
36671 +2003-07-07 Keith Owens  <kaos@sgi.com>
36672 +
36673 +       * Tweak 'waiting for cpus' message.
36674 +       * kdb v4.3-2.4.21-common-5.
36675 +
36676 +2003-07-07 Keith Owens  <kaos@sgi.com>
36677 +
36678 +       * 2.4.21-ia64-030702 patches common code that affects kdb.  Workaround
36679 +         this nuisance.
36680 +       * kdb v4.3-2.4.21-common-4.
36681 +
36682 +2003-06-24 Keith Owens  <kaos@sgi.com>
36683 +
36684 +       * Add task and sigset commands.  Mark Goodwin, SGI.
36685 +       * kdb v4.3-2.4.21-common-3.
36686 +
36687 +2003-06-23 Keith Owens  <kaos@sgi.com>
36688 +
36689 +       * Sync with XFS 2.4.21 tree.
36690 +       * kdb v4.3-2.4.21-common-2.
36691 +
36692 +2003-06-20 Keith Owens  <kaos@sgi.com>
36693 +
36694 +       * kdb v4.3-2.4.21-common-1.
36695 +
36696 +2003-06-20 Keith Owens  <kaos@sgi.com>
36697 +
36698 +       * More details on vm command, add vmp and pte commands.
36699 +         Dean Nelson, Dean Roe, SGI.
36700 +       * YAO1SCF (Yet Another O(1) Scheduler Coexistence Fix).
36701 +       * Changes to common code to build on sparc.  Tom Duffy.
36702 +       * Move Tom Duffy's changes to drivers/sbus from the sparc64
36703 +         patch to the common patch to keep all the serial changes
36704 +         together.
36705 +       * Changes to common code to build on Xscale.  Eddie Dong, Intel.
36706 +       * Remove CROSS_COMPILE_INC.
36707 +       * Remove obsolete boot parameter 'kdb', long since replaced by
36708 +         'kdb=on'.
36709 +       * Remove obsolete kdb_eframe_t casts.
36710 +       * Add CONFIG_KDB_CONTINUE_CATASTROPHIC.
36711 +       * Wait a short interval for cpus to join kdb before proceeding.
36712 +       * Automatically enable sysrq for sr command.
36713 +       * Correct double free of kdb_printf lock, spotted by Richard Sanders.
36714 +       * Add optional cpu parameter to btc command.
36715 +       * kdb v4.3-2.4.20-common-1.
36716 +
36717 +2003-05-02 Keith Owens  <kaos@sgi.com>
36718 +
36719 +       * Some architectures have problems with the initial empty kallsyms
36720 +         section so revert to three kallsyms passes.
36721 +       * Flush buffered input at startup and at 'more' prompt.
36722 +       * Only print 'more' prompt when longjmp data is available.
36723 +       * Print more data for buffers and inodes.
36724 +       * Disable kill command when O(1) scheduler is installed, the code
36725 +         needs to be redone for O(1).
36726 +       * The kernel has an undocumented assumption that enable_bh() is
36727 +         always called with interrupts enabled, make it so.
36728 +       * Print trailing punctuation even for symbols that are not in kernel.
36729 +       * Add read/write access to user pages.  Vamsi Krishna S., IBM
36730 +       * Rename cpu_is_online to cpu_online, as in 2.5.
36731 +       * O(1) scheduler removes init_task so kdb maintains its own list of
36732 +         active tasks.
36733 +       * Delete btp 0 <cpuid> option, it needed init_tasks.
36734 +       * Clean up USB keyboard support.  Steven Dake.
36735 +       * Sync with XFS 2.4.20 tree.
36736 +       * kdb v4.2-2.4.20-common-1.
36737 +
36738 +2003-04-04 Keith Owens  <kaos@sgi.com>
36739 +
36740 +       * Remove one kallsyms pass.
36741 +       * Automatic detection of O(1) scheduler.
36742 +       * Rename cpu_online to cpu_is_online.
36743 +       * Workarounds for scheduler bugs.
36744 +       * Tweak algorithm for detecting if cpu process data is available.
36745 +       * Add 'kill' command.  Sonic Zhang, Keith Owens.
36746 +       * kdb v4.1-2.4.20-common-1.
36747 +
36748 +2003-03-16 Keith Owens  <kaos@sgi.com>
36749 +
36750 +       * Each cpu saves its state as it enters kdb or before it enters code
36751 +         which cannot call kdb.
36752 +       * Allow btp on process 0 for a specified cpu.
36753 +       * Add btt command, backtrace given a struct task address.
36754 +       * btc command no longer switches cpus, instead it uses the saved data.
36755 +       * bta shows the idle task on each cpu as well as real tasks, the idle
36756 +         task could be handling an interrupt.
36757 +       * ps command shows the idle task on each cpu.
36758 +       * ps checks that the saved data for a cpu matches the process running on
36759 +         that cpu and warns about stale saved data or no saved data at all.
36760 +       * Remove special cases for i386 backtrace from common code and simplify
36761 +         common bt code.
36762 +       * Clean up kdb interaction with CONFIG_SERIAL_CONSOLE.
36763 +       * Do not automatically repeat commands after the user typed 'q'.
36764 +       * O(1) scheduler patch changes the process cpu field but does not set
36765 +         any indicator that O(1) is being used.  Adjust kdb_process_cpu() by
36766 +         hand after applying O(1).
36767 +       * Add kdb_print_nameval() to common code.
36768 +       * Convert tests of cpu_online_map to cpu_online() macro.
36769 +       * module.h needs errno.h when compiling with CONFIG_MODULES=n.
36770 +       * Correct duplicate breakpoint handling.
36771 +       * Do not try to send IPI during a catastrophic error, send_ipi can hang
36772 +         and take kdb with it.
36773 +       * kdb memmap command is i386 only, restrict it.
36774 +       * Add large block device (LBD) support from XFS tree.  Eric Sandeen.
36775 +       * kdb v4.0-2.4.20-common-1.
36776 +
36777 +2003-02-03 Keith Owens  <kaos@sgi.com>
36778 +
36779 +       * Register kdb commands early.
36780 +       * Decode oops via kallsyms if it is available.
36781 +       * Update copyright notices to 2003.
36782 +       * Add defcmd/endefcmd to allow users to package their own macros.
36783 +       * kdb commands that fail are ignored when prefixed with '-'.
36784 +       * Add selection options to bta command.
36785 +       * Add btc command (switch to each cpu and backtrace).
36786 +       * Do real time detection of dead cpus.
36787 +       * Clear ip adjusted flag when leaving kdb.
36788 +       * Clean up ps command.
36789 +       * Print ps output for each task when backtracing.
36790 +       * Bump to version v3.0 to reduce confusion between kdb and kernel
36791 +         version numbers.
36792 +       * Add kdba_local_arch_setup/kdba_local_arch_cleanup to correct
36793 +         keyboard freeze.  Ashish Kalra.
36794 +       * Refuse multiple breakpoints at the same address.
36795 +       * Add fl (file_lock) command, from XFS development tree.
36796 +       * Correct inode_pages, from XFS development tree.
36797 +       * Add command history and editing.  Sonic Zhang.
36798 +       * Extend command history and editing to handle vt100 escape sequences.
36799 +       * Allow tab completion at start of line.
36800 +       * Touch nmi watchdog on long running bta and btc commands.
36801 +       * Clean up ps output and standardize with bta codes.
36802 +       * Correctly handle escaped characters in commands.
36803 +       * Update man pages for btc and command history/editing.
36804 +       * kdb v3.0-2.4.20-common-1.
36805 +
36806 +2002-11-29 Keith Owens  <kaos@sgi.com>
36807 +
36808 +       * Upgrade to 2.4.20.
36809 +       * Correct Documentation/kdb/kdb_sr.man.
36810 +       * Remove leading zeroes from pids, they are decimal, not octal.
36811 +       * kdb v2.5-2.4.20-common-1.
36812 +
36813 +2002-11-14 Keith Owens  <kaos@sgi.com>
36814 +
36815 +       * Upgrade to 2.4.20-rc1.
36816 +       * kdb v2.5-2.4.20-rc1-common-1.
36817 +
36818 +2002-11-14 Keith Owens  <kaos@sgi.com>
36819 +
36820 +       * Fix processing with O(1) scheduler.
36821 +       * 'go' switches back to initial cpu first.
36822 +       * 'go <address>' only allowed on initial cpu.
36823 +       * 'go' installs the global breakpoints from the initial cpu before
36824 +          releasing the other cpus.
36825 +       * If 'go' has to single step over a breakpoint then it single steps just
36826 +         the initial cpu, installs the global breakpoints then releases the
36827 +         other cpus.
36828 +       * General clean up of handling for breakpoints and single stepping over
36829 +         software breakpoints.
36830 +       * Add kdb_notifier_block so other code can tell when kdb is in control.
36831 +       * kdb v2.5-2.4.19-common-1.
36832 +
36833 +2002-11-02 Keith Owens  <kaos@sgi.com>
36834 +
36835 +       * Correct build without CONFIG_KDB.
36836 +       * kdb v2.4-2.4.19-common-3.
36837 +
36838 +2002-11-01 Keith Owens  <kaos@sgi.com>
36839 +
36840 +       * Minimize differences from 2.5.44.
36841 +       * kdb v2.4-2.4.19-common-2.
36842 +
36843 +2002-10-31 Keith Owens  <kaos@sgi.com>
36844 +
36845 +       * Add defcmd/endefcmd feature.
36846 +       * Remove kdb_eframe_t.
36847 +       * Clear bp data before using.
36848 +       * Sanity check if we have pt_regs.
36849 +       * Force LINES > 1.
36850 +       * Remove special case for KDB_REASON_PANIC, use KDB_ENTER() instead.
36851 +       * Remove kdba_getcurrentframe().
36852 +       * Coexist with O(1) scheduler.
36853 +       * Add lines option to dmesg, speed up dmesg.
36854 +       * kdb v2.4-2.4.19-common-1.
36855 +
36856 +2002-10-17 Keith Owens  <kaos@sgi.com>
36857 +
36858 +       * Add selection critera to ps and bta commands.
36859 +       * kdb v2.3-2.4.19-common-4.
36860 +
36861 +2002-10-07 Keith Owens  <kaos@sgi.com>
36862 +
36863 +       * New man page, Documentation/kdb/kdb_sr.man.
36864 +
36865 +2002-10-04 Keith Owens  <kaos@sgi.com>
36866 +
36867 +       * Minimize differences between patches for 2.4 and 2.5 kernels.
36868 +       * Add Configure.help for CONFIG_KDB_USB.
36869 +       * Reduce stack usage.
36870 +       * kdb v2.3-2.4.19-common-3.
36871 +
36872 +2002-08-10 Keith Owens  <kaos@sgi.com>
36873 +
36874 +       * Replace kdb_port with kdb_serial to support memory mapped I/O.
36875 +         David Mosberger.
36876 +       * kdb v2.3-2.4.19-common-2.
36877 +
36878 +2002-08-07 Keith Owens <kaos@sgi.com>
36879 +
36880 +       * Upgrade to 2.4.19.
36881 +       * Remove individual SGI copyrights, the general SGI copyright applies.
36882 +       * Handle md0.  Reported by Hugh Dickins, different fix by Keith Owens.
36883 +       * Use page_address() in kdbm_pg.c.  Hugh Dickins.
36884 +       * Remove debugging printk from kdbm_pg.c.  Hugh Dickins.
36885 +       * Move breakpoint address verification into arch dependent code.
36886 +       * Dynamically resize kdb command table as required.
36887 +       * Common code to support USB keyboard.  Sebastien Lelarge.
36888 +       * kdb v2.3-2.4.19-common-1.
36889 +
36890 +2002-07-09 Keith Owens <kaos@sgi.com>
36891 +
36892 +       * Upgrade to 2.4.19-rc1.
36893 +       * Add dmesg command.
36894 +       * Clean up copyrights, Eric Sandeen.
36895 +       * kdb v2.2-2.4.19-rc1-common-1.
36896 +
36897 +2002-06-14 Keith Owens <kaos@sgi.com>
36898 +
36899 +       * Upgrade to 2.4.19-pre10.
36900 +       * Sync with XFS.
36901 +       * kdb v2.1-2.4.19-pre10-common-1.
36902 +
36903 +2002-04-09 Keith Owens <kaos@sgi.com>
36904 +
36905 +       * Upgrade to 2.4.19-pre6.
36906 +       * kdb v2.1-2.4.19-pre6-common-1.
36907 +
36908 +2002-03-18 Keith Owens <kaos@sgi.com>
36909 +
36910 +       * Syntax check mdWcN commands.
36911 +
36912 +2002-03-01 Keith Owens <kaos@sgi.com>
36913 +
36914 +       * Sync with XFS 2.4.18.
36915 +       * kdb v2.1-2.4.18-common-2.
36916 +
36917 +2002-02-26 Keith Owens <kaos@sgi.com>
36918 +
36919 +       * Upgrade to 2.4.18.
36920 +       * Add Paul Dorwin (IBM) magicpoint slides on using kdb as
36921 +         Documentation/kdb/slides.
36922 +       * kdb v2.1-2.4.18-common-1.
36923 +
36924 +2002-01-23 Keith Owens <kaos@sgi.com>
36925 +
36926 +       * Sync with XFS pagebuf changes.
36927 +       * kdb v2.1-2.4.17-common-2.
36928 +
36929 +2002-01-18 Keith Owens <kaos@sgi.com>
36930 +
36931 +       * Ignore single stepping during panic.
36932 +       * Remove kdba_getword, kdba_putword.  Replace with kdb_getword,
36933 +         kdb_putword that rely on copy_xx_user.  The new functions return
36934 +         an error code, like copy_xx_user.
36935 +       * New functions kdb_getarea, kdb_putarea for copying areas of data
36936 +         such as structures.  These functions also return an error code.
36937 +       * Change all common code to use the new functions.
36938 +       * bp command checks that it can read and write the word at the
36939 +         breakpoint before accepting the address.
36940 +       * Break points are now set FIFO and cleared LIFO so overlapping
36941 +         entries give sensible results.
36942 +       * Verify address before disassembling code.
36943 +       * Common changes for sparc64.  Ethan Solomita, Tom Duffy.
36944 +       * Remove ss <count>, never supported.
36945 +       * Remove kallsyms entries from arch vmlinux.lds files.
36946 +       * Specify which commands auto repeat.
36947 +       * kdb v2.1-2.4.17-common-1.
36948 +
36949 +2002-01-07 Keith Owens <kaos@sgi.com>
36950 +
36951 +       * Remove console semaphore code, not good in interrupt.
36952 +       * Remove fragment of ia64 patch that had crept into kdb.
36953 +       * Release as kdb v2.0-2.4.17-common-3.
36954 +
36955 +2002-01-04 Keith Owens  <kaos@sgi.com>
36956 +
36957 +       * Sync xfs <-> kdb common code.
36958 +
36959 +2001-12-22 Keith Owens  <kaos@sgi.com>
36960 +
36961 +       * Upgrade to 2.4.17.
36962 +       * Clean up ifdef CONFIG_KDB.
36963 +       * Add ifdef CONFIG_KDB around include kdb.h.
36964 +       * Delete dummy kdb.h files for unsupported architectures.
36965 +       * Delete arch i386 and ia64 specific files.  This changelog now
36966 +         applies to kdb common code only.
36967 +       * Release as kdb v2.0-2.4.17-common-1.
36968 +
36969 +2001-12-03 Keith Owens  <kaos@sgi.com>
36970 +
36971 +       * Upgrade to 2.4.16.
36972 +       * Add include/asm-um/kdb.h stub to allow XFS to be tested under UML.
36973 +       * Check if an interrupt frame on i386 came from user space.
36974 +       * Out of scope bug fix in kdb_id.c.  Ethan Solomita.
36975 +       * Changes to common code to support sparc64.  Ethan Solomita.
36976 +       * Change GFP_KERNEL to GFP_ATOMIC in disasm.  Ethan Solomita.
36977 +
36978 +2001-11-16 Keith Owens  <kaos@sgi.com>
36979 +
36980 +       * Upgrade to 2.4.15-pre5.
36981 +       * Wrap () around #define expressions with unary operators.
36982 +
36983 +2001-11-13 Keith Owens  <kaos@sgi.com>
36984 +
36985 +       * Upgrade to 2.4.15-pre4.
36986 +       * kbdm_pg.c patch from Hugh Dickins.
36987 +
36988 +2001-11-07 Keith Owens  <kaos@sgi.com>
36989 +
36990 +       * Upgrade to 2.4.14-ia64-011105.
36991 +       * Change name of l1 serial I/O routine, add ia64 init command.  SGI.
36992 +       * Sync kdbm_pg with XFS.
36993 +
36994 +2001-11-06 Keith Owens  <kaos@sgi.com>
36995 +
36996 +       * Upgrade to kernel 2.4.14.
36997 +
36998 +2001-11-02 Keith Owens  <kaos@sgi.com>
36999 +
37000 +       * Sync kdbm_pg.c with XFS.
37001 +
37002 +2001-10-24 Keith Owens  <kaos@sgi.com>
37003 +
37004 +       * Upgrade to kernel 2.4.13.
37005 +
37006 +2001-10-14 Keith Owens  <kaos@melbourne.sgi.com>
37007 +
37008 +       * More use of TMPPREFIX in top level Makefile to speed up NFS compiles.
37009 +
37010 +       * Correct repeat calculations in md/mds commands.
37011 +
37012 +2001-10-10 Keith Owens  <kaos@melbourne.sgi.com>
37013 +
37014 +       * Copy bfd.h and ansidecl.h to arch/$(ARCH)/kdb, remove dependecies on
37015 +         user space includes.
37016 +
37017 +       * Update kdb v1.9 to kernel 2.4.11.
37018 +
37019 +2001-10-01 Keith Owens  <kaos@melbourne.sgi.com>
37020 +
37021 +       * Update kdb v1.9 to kernel 2.4.11-pre1 and 2.4.10-ac1.
37022 +
37023 +       * Correct loop in kdb_parse, reported by Tachino Nobuhiro.
37024 +
37025 +2001-09-25 Keith Owens  <kaos@melbourne.sgi.com>
37026 +
37027 +       * Update kdb v1.8 to kernel 2.4.10.
37028 +
37029 +       * kdbm_pg patch from Hugh Dickens.
37030 +
37031 +       * DProbes patch from Bharata B Rao.
37032 +
37033 +       * mdWcn and mmW patch from Vamsi Krishna S.
37034 +
37035 +       * i386 disasm layout patch from Jean-Marc Saffroy.
37036 +
37037 +       * Work around for 64 bit binutils, Simon Munton.
37038 +
37039 +       * kdb.mm doc correction by Chris Pascoe.
37040 +
37041 +       * Enter repeats the last command, IA64 disasm only prints one
37042 +         instruction.  Don Dugger.
37043 +
37044 +       * Allow kdb/modules to be linked into vmlinux.
37045 +
37046 +       * Remove obsolete code from kdb/modules/kdbm_{pg,vm}.c.
37047 +
37048 +       * Warn when commands are entered at more prompt.
37049 +
37050 +       * Add MODULE_AUTHOR, DESCRIPTION, LICENSE.
37051 +
37052 +       * Release as kdb v1.9.
37053 +
37054 +2001-02-27 Keith Owens  <kaos@melbourne.sgi.com>
37055 +
37056 +       * Update kdb v1.8 to kernel 2.4.2, sync kdb/modules with XFS.
37057 +
37058 +       * Hook into panic() call.
37059 +
37060 +2000-12-18 Keith Owens  <kaos@melbourne.sgi.com>
37061 +
37062 +       * Update kdb v1.7 to kernel 2.4.0-test13-pre3, sync kdb/modules with
37063 +       XFS.
37064 +
37065 +2000-11-18 Keith Owens  <kaos@melbourne.sgi.com>
37066 +
37067 +       * Update to kernel 2.4.0-test11-pre7, including forward port of
37068 +       bug fixes from WIP 2.4.0-test9 tree.
37069 +
37070 +       * Update to Cygnus CVS trees for disassembly code.
37071 +
37072 +       * Bump to kdb v1.6.
37073 +
37074 +2000-10-19 Keith Owens  <kaos@melbourne.sgi.com>
37075 +
37076 +       * Update to kernel 2.4.0-test10-pre4.
37077 +
37078 +2000-10-15 Keith Owens  <kaos@melbourne.sgi.com>
37079 +
37080 +       * kdb/kdbmain.c (kdb_parse): Correctly handle blank input.
37081 +
37082 +       * kdb/kdbmain.c (kdb_local, kdb): Reason SILENT can have NULL regs.
37083 +
37084 +2000-10-13 Keith Owens  <kaos@melbourne.sgi.com>
37085 +
37086 +       * kdb/kdbmain.c: Reduce CMD_LEN to avoid overflowing kdb_printf buffer.
37087 +
37088 +2000-10-11 Keith Owens  <kaos@melbourne.sgi.com>
37089 +
37090 +       * kdb/kdbmain.c (kdb): Test for userspace breakpoints before driving
37091 +         other cpus into kdb.  Speeds up gdb and avoids SMP race.
37092 +
37093 +       * arch/i386/kdb/kdba_io.c (get_serial_char, get_kbd_char): Ignore
37094 +         unprintable characters.
37095 +
37096 +       * arch/i386/kdb/kdba_io.c (kdba_read): Better handling of buffer size.
37097 +
37098 +2000-10-04 Keith Owens  <kaos@melbourne.sgi.com>
37099 +
37100 +       * arch/i386/kdb/kdba_bt.c (kdba_bt_process): Verify that esp is inside
37101 +       task_struct.  Original patch by Mike Galbraith.
37102 +
37103 +       * kdb/kdb_io.c (kdb_getstr): Reset output line counter, remove
37104 +       unnecessary prompts.
37105 +
37106 +       * arch/i386/kdb/kdbasupport.c (kdb_getregcontents): Change " cs" to
37107 +       "xcs", ditto ss, ds, es.  gdb2kdb does not like leading spaces.
37108 +
37109 +       * include/asm-xxx/kdb.h: Add dummy kdb.h for all architectures except
37110 +       ix86.  This allows #include <linux/kdb.h> to appear in arch independent
37111 +       code without causing compile errors.
37112 +
37113 +       * kdb/modules/kdbm_pg: Sync with XFS.
37114 +
37115 +2000-10-03  Keith Owens  <kaos@melbourne.sgi.com>
37116 +
37117 +       * kdb/kdb_io.c (kdb_read): Ignore NMI while waiting for input.
37118 +
37119 +       * kdb/kdb_io.c, kdb/Makefile: Export kdb_read.
37120 +
37121 +2000-10-02  Keith Owens  <kaos@melbourne.sgi.com>
37122 +
37123 +       * arch/i386/kernel/smpboot.c (do_boot_cpu): Set nmi_watchdog_source to 2
37124 +       to avoid premature NMI oops during cpu bring up.  We have to assume that
37125 +       a box with more than 1 cpu has a working IO-APIC.
37126 +
37127 +       * Documentation/kdb/{kdb.mm,kdb_md.man}: Add mdr command.
37128 +
37129 +       * kdb/kdbmain.c (kdb_md): Add mdr command.
37130 +
37131 +       * Release as kdb v1.5 against 2.4.0-test9-pre8.
37132 +
37133 +       * arch/i386/kdb/kdba_io.c, arch/i386/kdb/kdbasupport.c, kdb/kdbmain.c,
37134 +       kdb/kdb_io.c, kdb/kdb_id.c: Remove zero initializers for static
37135 +       variables.
37136 +
37137 +2000-09-28  Keith Owens  <kaos@melbourne.sgi.com>
37138 +
37139 +       * various: Add nmi_watchdog_source, 1 local APIC, 2 IO-APIC.
37140 +       Test nmi_watchdog_source instead of nr_ioapics so UP works on SMP hardware.
37141 +
37142 +       * arch/i386/kernel/io_apic.c: Rename setup_nmi to setup_nmi_io for clarity.
37143 +
37144 +       * kdb/kdbmain.c (kdb_parse): Only set NO_WATCHDOG if it was already set.
37145 +
37146 +       * kdb/kdbmain.c (kdb): Clear NO_WATCHDOG on all exit paths.
37147 +
37148 +       * include/linux/kdb.h: Add KDB_REASON_SILENT.
37149 +
37150 +       * kdb/kdbmain.c (kdb_local): Treat reason SILENT as immediate 'go'.
37151 +
37152 +       * kdb/kdbmain.c (kdb_init): Invoke kdb with reason SILENT to instantiate
37153 +       any breakpoints on boot cpu.
37154 +
37155 +       * arch/i386/kernel/smpboot.c (smp_callin): Invoke kdb with reason SILENT
37156 +       to instantiate any global breakpoints on this cpu.
37157 +
37158 +       * kdb/kdb_cmds: Remove comment that said initial commands only worked on
37159 +       boot cpu.
37160 +
37161 +2000-09-27  Keith Owens  <kaos@melbourne.sgi.com>
37162 +
37163 +       * arch/i386/kernel/msr.c: Move {rd,wr}msr_eio to include/asm-i386/apic.h.
37164 +
37165 +       * include/asm-i386/apic.h: Define NMI interfaces.
37166 +
37167 +       * kernel/sysctl.c (kern_table):
37168 +       * kernel/sysctl.c (do_proc_set_nmi_watchdog):
37169 +       Add /proc/sys/kernel/nmi_watchdog.
37170 +
37171 +       * arch/i386/kernel/apic.c: New routines set_nmi_counter_local,
37172 +       setup_apic_nmi_watchdog.
37173 +
37174 +       * arch/i386/kernel/traps.c: New routine set_nmi_watchdog().  Call apic
37175 +       routines to set/clear local apic timer.
37176 +
37177 +2000-09-26  Keith Owens  <kaos@melbourne.sgi.com>
37178 +
37179 +       * include/linux/sysctl.h (enum): Add NMI_WATCHDOG.
37180 +
37181 +       * arch/i386/kernel/traps.c (nmi_watchdog_tick): Check nmi_watchdog is
37182 +       still on.
37183 +
37184 +       * arch/i386/config.in: Add CONFIG_UP_NMI_WATCHDOG.
37185 +
37186 +       * Documentation/Configure.help: Add CONFIG_UP_NMI_WATCHDOG.
37187 +
37188 +       * Documentation/nmi_watchdog.txt: Update for UP NMI watchdog.
37189 +
37190 +2000-09-25  Keith Owens  <kaos@melbourne.sgi.com>
37191 +
37192 +       * arch/i386/kernel/apic.c (init_apic_mappings):
37193 +       * arch/i386/kernel/io_apic.c (IO_APIC_init_uniprocessor):
37194 +       Merge Keir Fraser's local APIC for uniprocessors patch.
37195 +
37196 +2000-09-24  Keith Owens  <kaos@melbourne.sgi.com>
37197 +
37198 +       * Various: Declare initialization routines as __init.
37199 +
37200 +       * Makefile: Define and export AWK.
37201 +
37202 +       * kdb/Makefile: Generate gen-kdb_cmds.c from kdb/kdb_cmds.
37203 +
37204 +       * kdb/kdbmain.c (kdb_init): Call new routine kdb_cmds_init to execute
37205 +       whatever the user put in kdb/kdb_cmds.
37206 +
37207 +       * arch/i386/kdb/kdba_bt.c (kdba_bt_stack): New parameter to
37208 +       indicate if esp in regs is known to be valid or not.
37209 +
37210 +       * kdb/kdb_bp.c, arch/i386/kdb/kdba_bp.c: More trace prints for
37211 +       breakpoint handling.
37212 +
37213 +       * arch/i386/kdb/kdba_bp.c (kdba_installbp): Finally found and fixed the
37214 +       annoying breakpoint bug where breakpoints where not always installed
37215 +       after 'go'.
37216 +
37217 +       * Documentation/kdb: Update man pages kdb.mm, kdb_env.man, kdb_ss.man.
37218 +
37219 +       * Released as kdb-v1.5-beta1-2.4.0-test8.
37220 +
37221 +       * Sync to 2.4.0-test9-pre6 and release as kdb-v1.5-beta1-2.4.0-test9-pre6.
37222 +
37223 +2000-09-23  Keith Owens  <kaos@melbourne.sgi.com>
37224 +
37225 +       * arch/i386/kdb/kdbasupport.c (kdba_getregcontents): New pseudo
37226 +       registers cesp and ceflags to help with debugging the debugger.
37227 +
37228 +       * kdb/kdbmain.c (kdb_local, kdb): Add KDB_REASON_RECURSE.  Add
37229 +       environment variable RECURSE.  Add code to cope with some types of
37230 +       recursion.
37231 +
37232 +       * kdb/kdbmain.c (kdb), arch/i386/kdba/kdba_bp.c: Add
37233 +       kdba_clearsinglestep.
37234 +
37235 +2000-09-22  Keith Owens  <kaos@melbourne.sgi.com>
37236 +
37237 +       * drivers/video/vgacon.c (write_vga): No cli() if kdb is running, avoid
37238 +       console deadlock.
37239 +
37240 +       * arch/i386/kernel/irq.c (get_irqlock): Warn if kdb is running, may hang.
37241 +
37242 +       * include/linux/kdb.h: Define KDB_IS_RUNNING as (0) if no CONFIG_KDB.
37243 +
37244 +       * arch/i386/kdb/kdba_bt.c (kdba_bt_stack): Do not attempt a backtrace if
37245 +       the code segment is not in the kernel.
37246 +
37247 +       * kdb/modules: Change modules from MX_OBJS to M_OBJS.  Remove EXPORT_NOSYMBOLS.
37248 +
37249 +2000-09-21  Keith Owens  <kaos@melbourne.sgi.com>
37250 +
37251 +       * arch/i386/kernel/i386_ksyms.c: Move EXPORT_SYMBOLS for kdb to kdb/kdbmain.c.
37252 +
37253 +       * kdb/Makefile: Change kdb/kdbmain.o from O_OBJS to OX_OBJS.
37254 +
37255 +       * arch/i386/kernel/smp.c: Remove some #ifdef CONFIG_KDB.  Remove kdbprivate.h.
37256 +
37257 +       * include/linux/kdb.h: Add kdb_print_state.  Add KDB_STATE_WAIT_IPI.
37258 +
37259 +       * kdb/kdbmain.c (kdb): Only mark cpu as leaving if it is in KDB state.  Maintain
37260 +       WAIT_IPI state so a cpu is only driven through NMI once.
37261 +
37262 +       * arch/i386/kernel/smp.c (smp_kdb_stop): All state fiddling moved to kdb().
37263 +
37264 +2000-09-20  Keith Owens  <kaos@melbourne.sgi.com>
37265 +
37266 +       * include/linux/kdb.h: #define kdb() as (0) if kdb is not configured.
37267 +
37268 +       * arch/i386/kernel/traps.c: Remove some #ifdef CONFIG_KDB.
37269 +
37270 +       * include/linux/kdbprivate.h: Move per cpu state to kdb.h.
37271 +
37272 +       * include/linux/kdb.h: Add KDB_STATE_NO_WATCHDOG, KDB_STATE_PRINTF_LOCK.
37273 +       Rename KDB_DEBUG_xxx to KDB_DEBUG_FLAG_xxx.  Clean up debug flag
37274 +       definitions.
37275 +
37276 +       * arch/i386/kernel/traps.c (nmi_watchdog_tick): Check no watchdog.
37277 +
37278 +       * kdb/kdbmain.c (kdb): Set no watchdog in normal kdb code.
37279 +
37280 +       * kdb/kdbmain.c (kdb_parse): Allow watchdog in commands.
37281 +
37282 +       * kdb/kdb_io.c (kdb_printf): No watchdog during printing.  Clean up lock handling.
37283 +
37284 +       * kdb/kdbmain.c (kdb_set): Clean up debug flag handling.
37285 +
37286 +2000-09-19  Juan J. Quintela  <quintela@fi.udc.es>
37287 +
37288 +       * kdb/arch/i386/kdb/kdba_io.c: Allow kdb to compile without CONFIG_VT and/or
37289 +       serial console.
37290 +
37291 +2000-09-19  Keith Owens  <kaos@melbourne.sgi.com>
37292 +
37293 +       * include/linux/kdb.h: Define KDB_DEBUG_STATE().
37294 +
37295 +       * kdb/kdbmain.c (kdb): Add kdb_print_state(), calls to KDB_DEBUG_STATE().
37296 +
37297 +2000-09-16  Keith Owens  <kaos@melbourne.sgi.com>
37298 +
37299 +       * Move to finer grained control over individual processors in kdb with
37300 +       per cpu kdb state.  Needed to allow ss[b] to only release one processor,
37301 +       previously ss[b] released all processors.  Also need to recover from
37302 +       errors inside kdb commands, e.g. oops in kdbm_pg code.
37303 +
37304 +       * various:
37305 +         Move global flags KDB_FLAG_SSB, KDB_FLAG_SUPRESS, KDB_FLAG_FAULT,
37306 +         KDB_FLAG_SS, KDB_FLAG_SSBPT, kdb_active, to per cpu state and macros
37307 +         KDB_STATE(xxx).
37308 +         Replace kdb_flags & KDB_FLAG_xxx with KDB_FLAG(xxx).
37309 +         Replace kdb_flags & KDB_DEBUG_xxx with KDB_DEBUG(xxx).
37310 +         Replace specific tests with wrapper KDB_IS_RUNNING().
37311 +
37312 +       * various: Remove #ifdef CONFIG_SMP from kdb code wherever
37313 +       possible.  Simplifies the code and makes it much more readable.
37314 +
37315 +       * arch/i386/kdb/kdbasupport.c (kdb_setjmp): Record if we have reliable
37316 +       longjmp data instead of assuming it is always set.
37317 +
37318 +       * various: Replace smp_kdb_wait with per cpu state, HOLD_CPU.
37319 +
37320 +       * init/main.c : Replace #ifdef KDB_DEBUG with KDB_DEBUG(CALLBACK).
37321 +
37322 +       * include/linux/kdbprivate.h: Separate command return codes from error
37323 +       codes.  Add more detailed command codes.
37324 +
37325 +       * arch/i386/kernel/traps.c (die): Change spin_lock_irq to
37326 +       spin_lock_irqsave.  Why did I do this?
37327 +
37328 +       * kdb/kdbmain.c (kdb_parse): Set per cpu flag CMD before executing kdb
37329 +       command.  More detailed return codes for commands that affect
37330 +       processors.
37331 +
37332 +       * kdb/kdbmain.c (kdb_previous_event): New, check if any processors are
37333 +       still executing the previous kdb event.  Removes a race window where a
37334 +       second event could enter kdb before the first had completely ended.
37335 +
37336 +       * kdb/kdbmain.c (kdb): Document all the concurrency conditions and how
37337 +       kdb handles them.  ss[b] now releases only the current cpu.  Do not set
37338 +       breakpoints when releasing for ss[b].  Recover from errors in kdb
37339 +       commands.  Check that we have reliable longjmp data before using it.
37340 +
37341 +       * various: Update return code documentation.
37342 +
37343 +       * kdb/kdb_bp.c (kdb_ss): Separate ss and ssb return codes.
37344 +
37345 +       * kdb/kdbsupport.c (kdb_ipi): Finer grained algorithm for deciding
37346 +       whether to call send a stop signal to a cpu.
37347 +
37348 +       * arch/i386/kdb/kdba_bp.c (kdba_db_trap): Separate ss and ssb return
37349 +       codes.  Reinstall delayed software breakpoints per cpu instead of
37350 +       globally.  Changed algorithm for handling ss[b].
37351 +
37352 +       * arch/i386/kdb/kdba_bp.c (kdba_bp_trap): Match software breakpoints per
37353 +       cpu instead of globally.
37354 +
37355 +       * include/linux/kdb.h: Bump version to kdb v1.5.
37356 +
37357 +2000-09-16  Keith Owens  <kaos@melbourne.sgi.com>
37358 +
37359 +       * kernel/sysctl.c (kern_table): add /proc/sys/kernel/kdb.
37360 +
37361 +       * init/main.c (parse_options): add boot flags kdb=on, kdb=off,
37362 +       kdb=early.
37363 +
37364 +       * include/linux/sysctl.h (enum): add KERN_KDB.
37365 +
37366 +       * drivers/char/serial.c (receive_chars): check kdb_on.
37367 +
37368 +       * drivers/char/keyboard.c (handle_scancode): check kdb_on.
37369 +
37370 +       * arch/i386/kernel/traps.c (nmi_watchdog_tick): check kdb_on.
37371 +
37372 +       * arch/i386/config.in: add CONFIG_KDB_OFF.
37373 +
37374 +       * Documentation/Configure.help: add CONFIG_KDB_OFF.
37375 +
37376 +       * kdb/kdbmain.c: add kdb_initial_cpu, kdb_on.
37377 +
37378 +       * kdb/kdbmain.c (kdb): check kdb_on, set kdb_initial_cpu.
37379 +
37380 +       * kdb/kdbmain.c (kdb_init): add Keith Owens to kdb banner.
37381 +
37382 +       * kdb/kdb_io.c (kdb_printf): serialize kdb_printf output.
37383 +
37384 +       * kdb/kdb_bt.c (kdb_bt): check environment variable BTAPROMPT.
37385 +
37386 +       * kdb/kdbsupport.c (kdb_ipi): ignore NMI for kdb_initial_cpu.
37387 +
37388 +       * kdb/modules/kdbm_pg.c (kdbm_page): merge updates from 2.4.0-test5-xfs.
37389 +
37390 +       * kdb/kdb_bt.man: add btp, bta, BTAPROMPT.
37391 +
37392 +       * kdb/kdb.mm: add CONFIG_KDB_OFF, boot flags, btp, bta.
37393 +
37394 +       * include/linux/kdbprivate.h: add kdb_initial_cpu.
37395 +
37396 +       * include/linux/kdb.h: add kdb_on, bump version to kdb v1.4.
37397 diff -Nurp linux-2.6.22-590/kdb/kdba_bt_x86.c linux-2.6.22-600/kdb/kdba_bt_x86.c
37398 --- linux-2.6.22-590/kdb/kdba_bt_x86.c  1970-01-01 01:00:00.000000000 +0100
37399 +++ linux-2.6.22-600/kdb/kdba_bt_x86.c  2008-04-09 18:14:28.000000000 +0200
37400 @@ -0,0 +1,5142 @@
37401 +/*
37402 + * This file is subject to the terms and conditions of the GNU General Public
37403 + * License.  See the file "COPYING" in the main directory of this archive
37404 + * for more details.
37405 + *
37406 + * Copyright (c) 2006, 2007 Silicon Graphics, Inc.  All Rights Reserved.
37407 + *
37408 + * Common code for doing accurate backtraces on i386 and x86_64, including
37409 + * printing the values of arguments.
37410 + */
37411 +
37412 +#include <linux/init.h>
37413 +#include <linux/kallsyms.h>
37414 +#include <linux/kdb.h>
37415 +#include <linux/kdbprivate.h>
37416 +#include <linux/ctype.h>
37417 +#include <linux/string.h>
37418 +#include <linux/stringify.h>
37419 +#include <linux/kernel.h>
37420 +#include <linux/sched.h>
37421 +#include <linux/nmi.h>
37422 +#include <asm/asm-offsets.h>
37423 +#include <asm/system.h>
37424 +
37425 +#define KDB_DEBUG_BB(fmt, ...)                                                 \
37426 +       {if (KDB_DEBUG(BB)) kdb_printf(fmt, ## __VA_ARGS__);}
37427 +#define KDB_DEBUG_BB_OFFSET_PRINTF(offset, prefix, suffix)                     \
37428 +       kdb_printf(prefix "%c0x%x" suffix,                                      \
37429 +                  offset >= 0 ? '+' : '-',                                     \
37430 +                  offset >= 0 ? offset : -offset)
37431 +#define KDB_DEBUG_BB_OFFSET(offset, prefix, suffix)                            \
37432 +       {if (KDB_DEBUG(BB)) KDB_DEBUG_BB_OFFSET_PRINTF(offset, prefix, suffix);}
37433 +
37434 +#define        BB_CHECK(expr, val, ret)                                                \
37435 +({                                                                             \
37436 +       if (unlikely(expr)) {                                                   \
37437 +               kdb_printf("%s, line %d: BB_CHECK(" #expr ") failed "           \
37438 +                       #val "=%lx\n",                                          \
37439 +                       __FUNCTION__, __LINE__, (long)val);                     \
37440 +               bb_giveup = 1;                                                  \
37441 +               return ret;                                                     \
37442 +       }                                                                       \
37443 +})
37444 +
37445 +/* Use BBRG_Rxx for both i386 and x86_64.  RAX through R15 must be at the end,
37446 + * starting with RAX.  Some of these codes do not reflect actual registers,
37447 + * such codes are special cases when parsing the record of register changes.
37448 + * When updating BBRG_ entries, update bbrg_name as well.
37449 + */
37450 +
37451 +enum bb_reg_code
37452 +{
37453 +       BBRG_UNDEFINED = 0,     /* Register contents are undefined */
37454 +       BBRG_OSP,               /* original stack pointer on entry to function */
37455 +       BBRG_RAX,
37456 +       BBRG_RBX,
37457 +       BBRG_RCX,
37458 +       BBRG_RDX,
37459 +       BBRG_RDI,
37460 +       BBRG_RSI,
37461 +       BBRG_RBP,
37462 +       BBRG_RSP,
37463 +       BBRG_R8,
37464 +       BBRG_R9,
37465 +       BBRG_R10,
37466 +       BBRG_R11,
37467 +       BBRG_R12,
37468 +       BBRG_R13,
37469 +       BBRG_R14,
37470 +       BBRG_R15,
37471 +};
37472 +
37473 +const static char *bbrg_name[] = {
37474 +       [BBRG_UNDEFINED]   = "undefined",
37475 +       [BBRG_OSP]         = "osp",
37476 +       [BBRG_RAX]         = "rax",
37477 +       [BBRG_RBX]         = "rbx",
37478 +       [BBRG_RCX]         = "rcx",
37479 +       [BBRG_RDX]         = "rdx",
37480 +       [BBRG_RDI]         = "rdi",
37481 +       [BBRG_RSI]         = "rsi",
37482 +       [BBRG_RBP]         = "rbp",
37483 +       [BBRG_RSP]         = "rsp",
37484 +       [BBRG_R8]          = "r8",
37485 +       [BBRG_R9]          = "r9",
37486 +       [BBRG_R10]         = "r10",
37487 +       [BBRG_R11]         = "r11",
37488 +       [BBRG_R12]         = "r12",
37489 +       [BBRG_R13]         = "r13",
37490 +       [BBRG_R14]         = "r14",
37491 +       [BBRG_R15]         = "r15",
37492 +};
37493 +
37494 +/* Map a register name to its register code.  This includes the sub-register
37495 + * addressable fields, e.g. parts of rax can be addressed as ax, al, ah, eax.
37496 + * The list is sorted so it can be binary chopped, sort command is:
37497 + *   LANG=C sort -t '"' -k2
37498 + */
37499 +
37500 +struct bb_reg_code_map {
37501 +       enum bb_reg_code reg;
37502 +       const char *name;
37503 +};
37504 +
37505 +const static struct bb_reg_code_map
37506 +bb_reg_code_map[] = {
37507 +       { BBRG_RAX, "ah" },
37508 +       { BBRG_RAX, "al" },
37509 +       { BBRG_RAX, "ax" },
37510 +       { BBRG_RBX, "bh" },
37511 +       { BBRG_RBX, "bl" },
37512 +       { BBRG_RBP, "bp" },
37513 +       { BBRG_RBP, "bpl" },
37514 +       { BBRG_RBX, "bx" },
37515 +       { BBRG_RCX, "ch" },
37516 +       { BBRG_RCX, "cl" },
37517 +       { BBRG_RCX, "cx" },
37518 +       { BBRG_RDX, "dh" },
37519 +       { BBRG_RDI, "di" },
37520 +       { BBRG_RDI, "dil" },
37521 +       { BBRG_RDX, "dl" },
37522 +       { BBRG_RDX, "dx" },
37523 +       { BBRG_RAX, "eax" },
37524 +       { BBRG_RBP, "ebp" },
37525 +       { BBRG_RBX, "ebx" },
37526 +       { BBRG_RCX, "ecx" },
37527 +       { BBRG_RDI, "edi" },
37528 +       { BBRG_RDX, "edx" },
37529 +       { BBRG_RSI, "esi" },
37530 +       { BBRG_RSP, "esp" },
37531 +       { BBRG_R10, "r10" },
37532 +       { BBRG_R10, "r10d" },
37533 +       { BBRG_R10, "r10l" },
37534 +       { BBRG_R10, "r10w" },
37535 +       { BBRG_R11, "r11" },
37536 +       { BBRG_R11, "r11d" },
37537 +       { BBRG_R11, "r11l" },
37538 +       { BBRG_R11, "r11w" },
37539 +       { BBRG_R12, "r12" },
37540 +       { BBRG_R12, "r12d" },
37541 +       { BBRG_R12, "r12l" },
37542 +       { BBRG_R12, "r12w" },
37543 +       { BBRG_R13, "r13" },
37544 +       { BBRG_R13, "r13d" },
37545 +       { BBRG_R13, "r13l" },
37546 +       { BBRG_R13, "r13w" },
37547 +       { BBRG_R14, "r14" },
37548 +       { BBRG_R14, "r14d" },
37549 +       { BBRG_R14, "r14l" },
37550 +       { BBRG_R14, "r14w" },
37551 +       { BBRG_R15, "r15" },
37552 +       { BBRG_R15, "r15d" },
37553 +       { BBRG_R15, "r15l" },
37554 +       { BBRG_R15, "r15w" },
37555 +       { BBRG_R8,  "r8" },
37556 +       { BBRG_R8,  "r8d" },
37557 +       { BBRG_R8,  "r8l" },
37558 +       { BBRG_R8,  "r8w" },
37559 +       { BBRG_R9,  "r9" },
37560 +       { BBRG_R9,  "r9d" },
37561 +       { BBRG_R9,  "r9l" },
37562 +       { BBRG_R9,  "r9w" },
37563 +       { BBRG_RAX, "rax" },
37564 +       { BBRG_RBP, "rbp" },
37565 +       { BBRG_RBX, "rbx" },
37566 +       { BBRG_RCX, "rcx" },
37567 +       { BBRG_RDI, "rdi" },
37568 +       { BBRG_RDX, "rdx" },
37569 +       { BBRG_RSI, "rsi" },
37570 +       { BBRG_RSP, "rsp" },
37571 +       { BBRG_RSI, "si" },
37572 +       { BBRG_RSI, "sil" },
37573 +       { BBRG_RSP, "sp" },
37574 +       { BBRG_RSP, "spl" },
37575 +};
37576 +
37577 +/* Record register contents in terms of the values that were passed to this
37578 + * function, IOW track which registers contain an input value.  A register's
37579 + * contents can be undefined, it can contain an input register value or it can
37580 + * contain an offset from the original stack pointer.
37581 + *
37582 + * This structure is used to represent the current contents of the integer
37583 + * registers, it is held in an array that is indexed by BBRG_xxx.  The element
37584 + * for BBRG_xxx indicates what input value is currently in BBRG_xxx.  When
37585 + * 'value' is BBRG_OSP then register BBRG_xxx contains a stack pointer,
37586 + * pointing at 'offset' from the original stack pointer on entry to the
37587 + * function.  When 'value' is not BBRG_OSP then element BBRG_xxx contains the
37588 + * original contents of an input register and offset is ignored.
37589 + *
37590 + * An input register 'value' can be stored in more than one register and/or in
37591 + * more than one memory location.
37592 + */
37593 +
37594 +struct bb_reg_contains
37595 +{
37596 +       enum bb_reg_code value: 8;
37597 +       short offset;
37598 +};
37599 +
37600 +/* Note: the offsets in struct bb_mem_contains in this code are _NOT_ offsets
37601 + * from OSP, they are offsets from current RSP.  It fits better with the way
37602 + * that struct pt_regs is built, some code pushes extra data before pt_regs so
37603 + * working with OSP relative offsets gets messy.  struct bb_mem_contains
37604 + * entries must be in descending order of RSP offset.
37605 + */
37606 +
37607 +typedef struct { DECLARE_BITMAP(bits, BBRG_R15+1); } bbrgmask_t;
37608 +#define BB_SKIP(reg) (1 << (BBRG_ ## reg))
37609 +struct bb_mem_contains {
37610 +       short offset_address;
37611 +       enum bb_reg_code value: 8;
37612 +};
37613 +
37614 +/* Transfer of control to a label outside the current function.  If the
37615 + * transfer is to a known common restore path that expects known registers
37616 + * and/or a known memory state (e.g. struct pt_regs) then do a sanity check on
37617 + * the state at this point.
37618 + */
37619 +
37620 +struct bb_name_state {
37621 +       const char *name;                       /* target function */
37622 +       bfd_vma address;                        /* Address of target function */
37623 +       const char *fname;                      /* optional from function name */
37624 +       const struct bb_mem_contains *mem;      /* expected memory state */
37625 +       const struct bb_reg_contains *regs;     /* expected register state */
37626 +       const unsigned short mem_size;          /* ARRAY_SIZE(mem) */
37627 +       const unsigned short regs_size;         /* ARRAY_SIZE(regs) */
37628 +       const short osp_offset;                 /* RSP in regs == OSP+osp_offset */
37629 +       const bbrgmask_t skip_mem;              /* Some slots in mem may be undefined */
37630 +       const bbrgmask_t skip_regs;             /* Some slots in regs may be undefined */
37631 +};
37632 +
37633 +/* NS (NAME_STATE) macros define the register and memory state when we transfer
37634 + * control to or start decoding a special case name.  Use NS when the target
37635 + * label always has the same state.  Use NS_FROM and specify the source label
37636 + * if the target state is slightly different depending on where it is branched
37637 + * from.  This gives better state checking, by isolating the special cases.
37638 + *
37639 + * Note: for the same target label, NS_FROM entries must be followed by a
37640 + * single NS entry.
37641 + */
37642 +
37643 +#define        NS_FROM(iname, ifname, imem, iregs, iskip_mem, iskip_regs, iosp_offset) \
37644 +       { \
37645 +               .name = iname, \
37646 +               .fname = ifname, \
37647 +               .mem = imem, \
37648 +               .regs = iregs, \
37649 +               .mem_size = ARRAY_SIZE(imem), \
37650 +               .regs_size = ARRAY_SIZE(iregs), \
37651 +               .skip_mem.bits[0] = iskip_mem, \
37652 +               .skip_regs.bits[0] = iskip_regs, \
37653 +               .osp_offset = iosp_offset, \
37654 +                       .address = 0 \
37655 +       }
37656 +
37657 +/* Shorter forms for the common cases */
37658 +#define        NS(iname, imem, iregs, iskip_mem, iskip_regs, iosp_offset) \
37659 +         NS_FROM(iname, NULL, imem, iregs, iskip_mem, iskip_regs, iosp_offset)
37660 +#define        NS_MEM(iname, imem, iskip_mem) \
37661 +         NS_FROM(iname, NULL, imem, no_regs, iskip_mem, 0, 0)
37662 +#define        NS_MEM_FROM(iname, ifname, imem, iskip_mem) \
37663 +         NS_FROM(iname, ifname, imem, no_regs, iskip_mem, 0, 0)
37664 +#define        NS_REG(iname, iregs, iskip_regs) \
37665 +         NS_FROM(iname, NULL, no_memory, iregs, 0, iskip_regs, 0)
37666 +#define        NS_REG_FROM(iname, ifname, iregs, iskip_regs) \
37667 +         NS_FROM(iname, ifname, no_memory, iregs, 0, iskip_regs, 0)
37668 +
37669 +static void
37670 +bb_reg_code_set_value(enum bb_reg_code dst, enum bb_reg_code src);
37671 +
37672 +static const char *bb_mod_name, *bb_func_name;
37673 +
37674 +/*============================================================================*/
37675 +/*                                                                            */
37676 +/* Most of the basic block code and data is common to x86_64 and i386.  This  */
37677 +/* large ifdef  contains almost all of the differences between the two        */
37678 +/* architectures.                                                             */
37679 +/*                                                                            */
37680 +/* Make sure you update the correct section of this ifdef.                    */
37681 +/*                                                                            */
37682 +/*============================================================================*/
37683 +
37684 +#ifdef CONFIG_X86_64
37685 +
37686 +/* Registers that can be used to pass parameters, in the order that parameters
37687 + * are passed.
37688 + */
37689 +
37690 +const static enum bb_reg_code
37691 +bb_param_reg[] = {
37692 +       BBRG_RDI,
37693 +       BBRG_RSI,
37694 +       BBRG_RDX,
37695 +       BBRG_RCX,
37696 +       BBRG_R8,
37697 +       BBRG_R9,
37698 +};
37699 +
37700 +const static enum bb_reg_code
37701 +bb_preserved_reg[] = {
37702 +       BBRG_RBX,
37703 +       BBRG_RBP,
37704 +       BBRG_RSP,
37705 +       BBRG_R12,
37706 +       BBRG_R13,
37707 +       BBRG_R14,
37708 +       BBRG_R15,
37709 +};
37710 +
37711 +static const struct bb_mem_contains full_pt_regs[] = {
37712 +       { 0x70, BBRG_RDI },
37713 +       { 0x68, BBRG_RSI },
37714 +       { 0x60, BBRG_RDX },
37715 +       { 0x58, BBRG_RCX },
37716 +       { 0x50, BBRG_RAX },
37717 +       { 0x48, BBRG_R8  },
37718 +       { 0x40, BBRG_R9  },
37719 +       { 0x38, BBRG_R10 },
37720 +       { 0x30, BBRG_R11 },
37721 +       { 0x28, BBRG_RBX },
37722 +       { 0x20, BBRG_RBP },
37723 +       { 0x18, BBRG_R12 },
37724 +       { 0x10, BBRG_R13 },
37725 +       { 0x08, BBRG_R14 },
37726 +       { 0x00, BBRG_R15 },
37727 +};
37728 +static const struct bb_mem_contains partial_pt_regs[] = {
37729 +       { 0x40, BBRG_RDI },
37730 +       { 0x38, BBRG_RSI },
37731 +       { 0x30, BBRG_RDX },
37732 +       { 0x28, BBRG_RCX },
37733 +       { 0x20, BBRG_RAX },
37734 +       { 0x18, BBRG_R8  },
37735 +       { 0x10, BBRG_R9  },
37736 +       { 0x08, BBRG_R10 },
37737 +       { 0x00, BBRG_R11 },
37738 +};
37739 +static const struct bb_mem_contains partial_pt_regs_plus_1[] = {
37740 +       { 0x48, BBRG_RDI },
37741 +       { 0x40, BBRG_RSI },
37742 +       { 0x38, BBRG_RDX },
37743 +       { 0x30, BBRG_RCX },
37744 +       { 0x28, BBRG_RAX },
37745 +       { 0x20, BBRG_R8  },
37746 +       { 0x18, BBRG_R9  },
37747 +       { 0x10, BBRG_R10 },
37748 +       { 0x08, BBRG_R11 },
37749 +};
37750 +static const struct bb_mem_contains partial_pt_regs_plus_2[] = {
37751 +       { 0x50, BBRG_RDI },
37752 +       { 0x48, BBRG_RSI },
37753 +       { 0x40, BBRG_RDX },
37754 +       { 0x38, BBRG_RCX },
37755 +       { 0x30, BBRG_RAX },
37756 +       { 0x28, BBRG_R8  },
37757 +       { 0x20, BBRG_R9  },
37758 +       { 0x18, BBRG_R10 },
37759 +       { 0x10, BBRG_R11 },
37760 +};
37761 +static const struct bb_mem_contains no_memory[] = {
37762 +};
37763 +/* Hardware has already pushed an error_code on the stack.  Use undefined just
37764 + * to set the initial stack offset.
37765 + */
37766 +static const struct bb_mem_contains error_code[] = {
37767 +       { 0x0, BBRG_UNDEFINED },
37768 +};
37769 +/* error_code plus original rax */
37770 +static const struct bb_mem_contains error_code_rax[] = {
37771 +       { 0x8, BBRG_UNDEFINED },
37772 +       { 0x0, BBRG_RAX },
37773 +};
37774 +
37775 +static const struct bb_reg_contains all_regs[] = {
37776 +       [BBRG_RAX] = { BBRG_RAX, 0 },
37777 +       [BBRG_RBX] = { BBRG_RBX, 0 },
37778 +       [BBRG_RCX] = { BBRG_RCX, 0 },
37779 +       [BBRG_RDX] = { BBRG_RDX, 0 },
37780 +       [BBRG_RDI] = { BBRG_RDI, 0 },
37781 +       [BBRG_RSI] = { BBRG_RSI, 0 },
37782 +       [BBRG_RBP] = { BBRG_RBP, 0 },
37783 +       [BBRG_RSP] = { BBRG_OSP, 0 },
37784 +       [BBRG_R8 ] = { BBRG_R8,  0 },
37785 +       [BBRG_R9 ] = { BBRG_R9,  0 },
37786 +       [BBRG_R10] = { BBRG_R10, 0 },
37787 +       [BBRG_R11] = { BBRG_R11, 0 },
37788 +       [BBRG_R12] = { BBRG_R12, 0 },
37789 +       [BBRG_R13] = { BBRG_R13, 0 },
37790 +       [BBRG_R14] = { BBRG_R14, 0 },
37791 +       [BBRG_R15] = { BBRG_R15, 0 },
37792 +};
37793 +static const struct bb_reg_contains no_regs[] = {
37794 +};
37795 +
37796 +static struct bb_name_state bb_special_cases[] = {
37797 +
37798 +       /* First the cases that pass data only in memory.  We do not check any
37799 +        * register state for these cases.
37800 +        */
37801 +
37802 +       /* Simple cases, no exceptions */
37803 +       NS_MEM("ia32_ptregs_common", partial_pt_regs_plus_1, 0),
37804 +       NS_MEM("ia32_sysret", partial_pt_regs, 0),
37805 +       NS_MEM("int_careful", partial_pt_regs, 0),
37806 +       NS_MEM("int_restore_rest", full_pt_regs, 0),
37807 +       NS_MEM("int_signal", full_pt_regs, 0),
37808 +       NS_MEM("int_very_careful", partial_pt_regs, 0),
37809 +       NS_MEM("int_with_check", partial_pt_regs, 0),
37810 +#ifdef CONFIG_TRACE_IRQFLAGS
37811 +       NS_MEM("paranoid_exit0", full_pt_regs, 0),
37812 +#endif /* CONFIG_TRACE_IRQFLAGS */
37813 +       NS_MEM("paranoid_exit1", full_pt_regs, 0),
37814 +       NS_MEM("ptregscall_common", partial_pt_regs_plus_1, 0),
37815 +       NS_MEM("restore_norax", partial_pt_regs, 0),
37816 +       NS_MEM("restore", partial_pt_regs, 0),
37817 +       NS_MEM("ret_from_intr", partial_pt_regs_plus_2, 0),
37818 +       NS_MEM("stub32_clone", partial_pt_regs_plus_1, 0),
37819 +       NS_MEM("stub32_execve", partial_pt_regs_plus_1, 0),
37820 +       NS_MEM("stub32_fork", partial_pt_regs_plus_1, 0),
37821 +       NS_MEM("stub32_iopl", partial_pt_regs_plus_1, 0),
37822 +       NS_MEM("stub32_rt_sigreturn", partial_pt_regs_plus_1, 0),
37823 +       NS_MEM("stub32_rt_sigsuspend", partial_pt_regs_plus_1, 0),
37824 +       NS_MEM("stub32_sigaltstack", partial_pt_regs_plus_1, 0),
37825 +       NS_MEM("stub32_sigreturn", partial_pt_regs_plus_1, 0),
37826 +       NS_MEM("stub32_sigsuspend", partial_pt_regs_plus_1, 0),
37827 +       NS_MEM("stub32_vfork", partial_pt_regs_plus_1, 0),
37828 +       NS_MEM("stub_clone", partial_pt_regs_plus_1, 0),
37829 +       NS_MEM("stub_execve", partial_pt_regs_plus_1, 0),
37830 +       NS_MEM("stub_fork", partial_pt_regs_plus_1, 0),
37831 +       NS_MEM("stub_iopl", partial_pt_regs_plus_1, 0),
37832 +       NS_MEM("stub_rt_sigreturn", partial_pt_regs_plus_1, 0),
37833 +       NS_MEM("stub_rt_sigsuspend", partial_pt_regs_plus_1, 0),
37834 +       NS_MEM("stub_sigaltstack", partial_pt_regs_plus_1, 0),
37835 +       NS_MEM("stub_vfork", partial_pt_regs_plus_1, 0),
37836 +
37837 +       NS_MEM_FROM("ia32_badsys", "ia32_sysenter_target",
37838 +               partial_pt_regs,
37839 +               /* ia32_sysenter_target uses CLEAR_RREGS to clear R8-R11 on
37840 +                * some paths.  It also stomps on RAX.
37841 +                */
37842 +               BB_SKIP(R8) | BB_SKIP(R9) | BB_SKIP(R10) | BB_SKIP(R11) |
37843 +               BB_SKIP(RAX)),
37844 +       NS_MEM_FROM("ia32_badsys", "ia32_cstar_target",
37845 +               partial_pt_regs,
37846 +               /* ia32_cstar_target uses CLEAR_RREGS to clear R8-R11 on some
37847 +                * paths.  It also stomps on RAX.  Even more confusing, instead
37848 +                * of storing RCX it stores RBP.  WTF?
37849 +                */
37850 +               BB_SKIP(R8) | BB_SKIP(R9) | BB_SKIP(R10) | BB_SKIP(R11) |
37851 +               BB_SKIP(RAX) | BB_SKIP(RCX)),
37852 +       NS_MEM("ia32_badsys", partial_pt_regs, 0),
37853 +
37854 +       /* Various bits of code branch to int_ret_from_sys_call, with slightly
37855 +        * different missing values in pt_regs.
37856 +        */
37857 +       NS_MEM_FROM("int_ret_from_sys_call", "ret_from_fork",
37858 +               partial_pt_regs,
37859 +               BB_SKIP(R11)),
37860 +       NS_MEM_FROM("int_ret_from_sys_call", "stub_execve",
37861 +               partial_pt_regs,
37862 +               BB_SKIP(RAX) | BB_SKIP(RCX)),
37863 +       NS_MEM_FROM("int_ret_from_sys_call", "stub_rt_sigreturn",
37864 +               partial_pt_regs,
37865 +               BB_SKIP(RAX) | BB_SKIP(RCX)),
37866 +       NS_MEM_FROM("int_ret_from_sys_call", "kernel_execve",
37867 +               partial_pt_regs,
37868 +               BB_SKIP(RAX)),
37869 +       NS_MEM_FROM("int_ret_from_sys_call", "ia32_syscall",
37870 +               partial_pt_regs,
37871 +               /* ia32_syscall only saves RDI through RCX. */
37872 +               BB_SKIP(R8) | BB_SKIP(R9) | BB_SKIP(R10) | BB_SKIP(R11) |
37873 +               BB_SKIP(RAX)),
37874 +       NS_MEM_FROM("int_ret_from_sys_call", "ia32_sysenter_target",
37875 +               partial_pt_regs,
37876 +               /* ia32_sysenter_target uses CLEAR_RREGS to clear R8-R11 on
37877 +               * some paths.  It also stomps on RAX.
37878 +               */
37879 +               BB_SKIP(R8) | BB_SKIP(R9) | BB_SKIP(R10) | BB_SKIP(R11) |
37880 +               BB_SKIP(RAX)),
37881 +       NS_MEM_FROM("int_ret_from_sys_call", "ia32_cstar_target",
37882 +               partial_pt_regs,
37883 +               /* ia32_cstar_target uses CLEAR_RREGS to clear R8-R11 on some
37884 +                * paths.  It also stomps on RAX.  Even more confusing, instead
37885 +                * of storing RCX it stores RBP.  WTF?
37886 +                */
37887 +               BB_SKIP(R8) | BB_SKIP(R9) | BB_SKIP(R10) | BB_SKIP(R11) |
37888 +               BB_SKIP(RAX) | BB_SKIP(RCX)),
37889 +       NS_MEM("int_ret_from_sys_call", partial_pt_regs, 0),
37890 +
37891 +       NS_MEM("retint_kernel", partial_pt_regs, BB_SKIP(RAX)),
37892 +
37893 +       NS_MEM("retint_careful", partial_pt_regs, BB_SKIP(RAX)),
37894 +
37895 +       /* Horrible hack: For a brand new x86_64 task, switch_to() branches to
37896 +        * ret_from_fork with a totally different stack state from all the
37897 +        * other tasks that come out of switch_to().  This non-standard state
37898 +        * cannot be represented so just ignore the branch from switch_to() to
37899 +        * ret_from_fork.  Due to inlining and linker labels, switch_to() can
37900 +        * appear as several different function labels, including schedule,
37901 +        * context_switch and __sched_text_start.
37902 +        */
37903 +       NS_MEM_FROM("ret_from_fork", "schedule", no_memory, 0),
37904 +       NS_MEM_FROM("ret_from_fork", "__sched_text_start", no_memory, 0),
37905 +       NS_MEM_FROM("ret_from_fork", "context_switch", no_memory, 0),
37906 +       NS_MEM("ret_from_fork", full_pt_regs, 0),
37907 +
37908 +
37909 +       NS_MEM_FROM("ret_from_sys_call", "ret_from_fork",
37910 +               partial_pt_regs,
37911 +               BB_SKIP(R11)),
37912 +       NS_MEM("ret_from_sys_call", partial_pt_regs, 0),
37913 +
37914 +       NS_MEM("retint_restore_args",
37915 +               partial_pt_regs,
37916 +               BB_SKIP(RAX) | BB_SKIP(RCX)),
37917 +
37918 +       NS_MEM("retint_swapgs",
37919 +               partial_pt_regs,
37920 +               BB_SKIP(RAX) | BB_SKIP(RCX)),
37921 +
37922 +       /* Now the cases that pass data in registers.  We do not check any
37923 +        * memory state for these cases.
37924 +        */
37925 +
37926 +       NS_REG("bad_put_user",
37927 +               all_regs,
37928 +               BB_SKIP(RAX) | BB_SKIP(RCX) | BB_SKIP(R8)),
37929 +
37930 +       NS_REG("bad_get_user",
37931 +               all_regs,
37932 +               BB_SKIP(RAX) | BB_SKIP(RCX) | BB_SKIP(R8)),
37933 +
37934 +       NS_REG("bad_to_user",
37935 +               all_regs,
37936 +               BB_SKIP(RAX) | BB_SKIP(RCX)),
37937 +
37938 +       NS_REG("ia32_ptregs_common",
37939 +               all_regs,
37940 +               0),
37941 +
37942 +       NS_REG("copy_user_generic_unrolled",
37943 +               all_regs,
37944 +               BB_SKIP(RAX) | BB_SKIP(RCX)),
37945 +
37946 +       NS_REG("copy_user_generic_string",
37947 +               all_regs,
37948 +               0),
37949 +
37950 +       NS_REG("iret_label",
37951 +               all_regs,
37952 +               0),
37953 +
37954 +       /* Finally the cases that pass data in both registers and memory.
37955 +        */
37956 +
37957 +       NS("invalid_TSS", error_code, all_regs, 0, 0, 0),
37958 +       NS("segment_not_present", error_code, all_regs, 0, 0, 0),
37959 +       NS("alignment_check", error_code, all_regs, 0, 0, 0),
37960 +       NS("page_fault", error_code, all_regs, 0, 0, 0),
37961 +       NS("general_protection", error_code, all_regs, 0, 0, 0),
37962 +       NS("error_entry", error_code_rax, all_regs, 0, BB_SKIP(RAX), -0x10),
37963 +       NS("common_interrupt", error_code, all_regs, 0, 0, -0x8),
37964 +};
37965 +
37966 +static const char *bb_spurious[] = {
37967 +                               /* schedule */
37968 +       "thread_return",
37969 +                               /* ret_from_fork */
37970 +       "rff_action",
37971 +       "rff_trace",
37972 +                               /* system_call */
37973 +       "ret_from_sys_call",
37974 +       "sysret_check",
37975 +       "sysret_careful",
37976 +       "sysret_signal",
37977 +       "badsys",
37978 +       "tracesys",
37979 +       "int_ret_from_sys_call",
37980 +       "int_with_check",
37981 +       "int_careful",
37982 +       "int_very_careful",
37983 +       "int_signal",
37984 +       "int_restore_rest",
37985 +                               /* common_interrupt */
37986 +       "ret_from_intr",
37987 +       "exit_intr",
37988 +       "retint_with_reschedule",
37989 +       "retint_check",
37990 +       "retint_swapgs",
37991 +       "retint_restore_args",
37992 +       "restore_args",
37993 +       "iret_label",
37994 +       "bad_iret",
37995 +       "retint_careful",
37996 +       "retint_signal",
37997 +       "retint_kernel",
37998 +                               /* .macro paranoidexit */
37999 +#ifdef CONFIG_TRACE_IRQFLAGS
38000 +       "paranoid_exit0",
38001 +       "paranoid_userspace0",
38002 +       "paranoid_restore0",
38003 +       "paranoid_swapgs0",
38004 +       "paranoid_schedule0",
38005 +#endif /* CONFIG_TRACE_IRQFLAGS */
38006 +       "paranoid_exit1",
38007 +       "paranoid_swapgs1",
38008 +       "paranoid_restore1",
38009 +       "paranoid_userspace1",
38010 +       "paranoid_schedule1",
38011 +                               /* error_entry */
38012 +       "error_swapgs",
38013 +       "error_sti",
38014 +       "error_exit",
38015 +       "error_kernelspace",
38016 +                               /* load_gs_index */
38017 +       "gs_change",
38018 +       "bad_gs",
38019 +                               /* ia32_sysenter_target */
38020 +       "sysenter_do_call",
38021 +       "sysenter_tracesys",
38022 +                               /* ia32_cstar_target */
38023 +       "cstar_do_call",
38024 +       "cstar_tracesys",
38025 +       "ia32_badarg",
38026 +                               /* ia32_syscall */
38027 +       "ia32_do_syscall",
38028 +       "ia32_sysret",
38029 +       "ia32_tracesys",
38030 +       "ia32_badsys",
38031 +};
38032 +
38033 +#define        HARDWARE_PUSHED (5 * KDB_WORD_SIZE)
38034 +
38035 +static const char *bb_hardware_handlers[] = {
38036 +       "system_call",
38037 +       "common_interrupt",
38038 +       "error_entry",
38039 +       "debug",
38040 +       "nmi",
38041 +       "int3",
38042 +       "double_fault",
38043 +       "stack_segment",
38044 +       "machine_check",
38045 +       "kdb_call",
38046 +};
38047 +
38048 +static void
38049 +bb_start_block0(void)
38050 +{
38051 +       bb_reg_code_set_value(BBRG_RAX, BBRG_RAX);
38052 +       bb_reg_code_set_value(BBRG_RBX, BBRG_RBX);
38053 +       bb_reg_code_set_value(BBRG_RCX, BBRG_RCX);
38054 +       bb_reg_code_set_value(BBRG_RDX, BBRG_RDX);
38055 +       bb_reg_code_set_value(BBRG_RDI, BBRG_RDI);
38056 +       bb_reg_code_set_value(BBRG_RSI, BBRG_RSI);
38057 +       bb_reg_code_set_value(BBRG_RBP, BBRG_RBP);
38058 +       bb_reg_code_set_value(BBRG_RSP, BBRG_OSP);
38059 +       bb_reg_code_set_value(BBRG_R8, BBRG_R8);
38060 +       bb_reg_code_set_value(BBRG_R9, BBRG_R9);
38061 +       bb_reg_code_set_value(BBRG_R10, BBRG_R10);
38062 +       bb_reg_code_set_value(BBRG_R11, BBRG_R11);
38063 +       bb_reg_code_set_value(BBRG_R12, BBRG_R12);
38064 +       bb_reg_code_set_value(BBRG_R13, BBRG_R13);
38065 +       bb_reg_code_set_value(BBRG_R14, BBRG_R14);
38066 +       bb_reg_code_set_value(BBRG_R15, BBRG_R15);
38067 +}
38068 +
38069 +/* x86_64 does not have a special case for __switch_to */
38070 +
38071 +static void
38072 +bb_fixup_switch_to(char *p)
38073 +{
38074 +}
38075 +
38076 +static int
38077 +bb_asmlinkage_arch(void)
38078 +{
38079 +       return strncmp(bb_func_name, "__down", 6) == 0 ||
38080 +              strncmp(bb_func_name, "__up", 4) == 0 ||
38081 +              strncmp(bb_func_name, "stub_", 5) == 0 ||
38082 +              strcmp(bb_func_name, "ret_from_fork") == 0 ||
38083 +              strcmp(bb_func_name, "ptregscall_common") == 0;
38084 +}
38085 +
38086 +#else  /* !CONFIG_X86_64 */
38087 +
38088 +/* Registers that can be used to pass parameters, in the order that parameters
38089 + * are passed.
38090 + */
38091 +
38092 +const static enum bb_reg_code
38093 +bb_param_reg[] = {
38094 +       BBRG_RAX,
38095 +       BBRG_RDX,
38096 +       BBRG_RCX,
38097 +};
38098 +
38099 +const static enum bb_reg_code
38100 +bb_preserved_reg[] = {
38101 +       BBRG_RBX,
38102 +       BBRG_RBP,
38103 +       BBRG_RSP,
38104 +       BBRG_RSI,
38105 +       BBRG_RDI,
38106 +};
38107 +
38108 +static const struct bb_mem_contains full_pt_regs[] = {
38109 +       { 0x18, BBRG_RAX },
38110 +       { 0x14, BBRG_RBP },
38111 +       { 0x10, BBRG_RDI },
38112 +       { 0x0c, BBRG_RSI },
38113 +       { 0x08, BBRG_RDX },
38114 +       { 0x04, BBRG_RCX },
38115 +       { 0x00, BBRG_RBX },
38116 +};
38117 +static const struct bb_mem_contains no_memory[] = {
38118 +};
38119 +/* Hardware has already pushed an error_code on the stack.  Use undefined just
38120 + * to set the initial stack offset.
38121 + */
38122 +static const struct bb_mem_contains error_code[] = {
38123 +       { 0x0, BBRG_UNDEFINED },
38124 +};
38125 +/* rbx already pushed */
38126 +static const struct bb_mem_contains rbx_pushed[] = {
38127 +       { 0x0, BBRG_RBX },
38128 +};
38129 +
38130 +static const struct bb_reg_contains all_regs[] = {
38131 +       [BBRG_RAX] = { BBRG_RAX, 0 },
38132 +       [BBRG_RBX] = { BBRG_RBX, 0 },
38133 +       [BBRG_RCX] = { BBRG_RCX, 0 },
38134 +       [BBRG_RDX] = { BBRG_RDX, 0 },
38135 +       [BBRG_RDI] = { BBRG_RDI, 0 },
38136 +       [BBRG_RSI] = { BBRG_RSI, 0 },
38137 +       [BBRG_RBP] = { BBRG_RBP, 0 },
38138 +       [BBRG_RSP] = { BBRG_OSP, 0 },
38139 +};
38140 +static const struct bb_reg_contains no_regs[] = {
38141 +};
38142 +
38143 +static struct bb_name_state bb_special_cases[] = {
38144 +
38145 +       /* First the cases that pass data only in memory.  We do not check any
38146 +        * register state for these cases.
38147 +        */
38148 +
38149 +       /* Simple cases, no exceptions */
38150 +       NS_MEM("check_userspace", full_pt_regs, 0),
38151 +       NS_MEM("device_not_available_emulate", full_pt_regs, 0),
38152 +       NS_MEM("ldt_ss", full_pt_regs, 0),
38153 +       NS_MEM("no_singlestep", full_pt_regs, 0),
38154 +       NS_MEM("restore_all", full_pt_regs, 0),
38155 +       NS_MEM("restore_nocheck", full_pt_regs, 0),
38156 +       NS_MEM("restore_nocheck_notrace", full_pt_regs, 0),
38157 +       NS_MEM("ret_from_exception", full_pt_regs, 0),
38158 +       NS_MEM("ret_from_fork", full_pt_regs, 0),
38159 +       NS_MEM("ret_from_intr", full_pt_regs, 0),
38160 +       NS_MEM("work_notifysig", full_pt_regs, 0),
38161 +       NS_MEM("work_pending", full_pt_regs, 0),
38162 +
38163 +#ifdef CONFIG_PREEMPT
38164 +       NS_MEM("resume_kernel", full_pt_regs, 0),
38165 +#endif /* CONFIG_PREEMPT */
38166 +
38167 +       NS_MEM("common_interrupt", error_code, 0),
38168 +       NS_MEM("error_code", error_code, 0),
38169 +
38170 +       NS_MEM("bad_put_user", rbx_pushed, 0),
38171 +
38172 +       NS_MEM_FROM("resume_userspace", "syscall_badsys",
38173 +               full_pt_regs, BB_SKIP(RAX)),
38174 +       NS_MEM_FROM("resume_userspace", "syscall_fault",
38175 +               full_pt_regs, BB_SKIP(RAX)),
38176 +       NS_MEM_FROM("resume_userspace", "syscall_trace_entry",
38177 +               full_pt_regs, BB_SKIP(RAX)),
38178 +       /* Too difficult to trace through the various vm86 functions for now.
38179 +        * They are C functions that start off with some memory state, fiddle
38180 +        * the registers then jmp directly to resume_userspace.  For the
38181 +        * moment, just assume that they are valid and do no checks.
38182 +        */
38183 +       NS_FROM("resume_userspace", "do_int",
38184 +               no_memory, no_regs, 0, 0, 0),
38185 +       NS_FROM("resume_userspace", "do_sys_vm86",
38186 +               no_memory, no_regs, 0, 0, 0),
38187 +       NS_FROM("resume_userspace", "handle_vm86_fault",
38188 +               no_memory, no_regs, 0, 0, 0),
38189 +       NS_FROM("resume_userspace", "handle_vm86_trap",
38190 +               no_memory, no_regs, 0, 0, 0),
38191 +       NS_MEM("resume_userspace", full_pt_regs, 0),
38192 +
38193 +       NS_MEM_FROM("syscall_badsys", "sysenter_entry",
38194 +               full_pt_regs, BB_SKIP(RBP)),
38195 +       NS_MEM("syscall_badsys", full_pt_regs, 0),
38196 +
38197 +       NS_MEM_FROM("syscall_call", "syscall_trace_entry",
38198 +               full_pt_regs, BB_SKIP(RAX)),
38199 +       NS_MEM("syscall_call", full_pt_regs, 0),
38200 +
38201 +       NS_MEM_FROM("syscall_exit", "syscall_trace_entry",
38202 +               full_pt_regs, BB_SKIP(RAX)),
38203 +       NS_MEM("syscall_exit", full_pt_regs, 0),
38204 +
38205 +       NS_MEM_FROM("syscall_exit_work", "sysenter_entry",
38206 +               full_pt_regs, BB_SKIP(RAX) | BB_SKIP(RBP)),
38207 +       NS_MEM_FROM("syscall_exit_work", "system_call",
38208 +               full_pt_regs, BB_SKIP(RAX)),
38209 +       NS_MEM("syscall_exit_work", full_pt_regs, 0),
38210 +
38211 +       NS_MEM_FROM("syscall_trace_entry", "sysenter_entry",
38212 +               full_pt_regs, BB_SKIP(RBP)),
38213 +       NS_MEM_FROM("syscall_trace_entry", "system_call",
38214 +               full_pt_regs, BB_SKIP(RAX)),
38215 +       NS_MEM("syscall_trace_entry", full_pt_regs, 0),
38216 +
38217 +       /* Now the cases that pass data in registers.  We do not check any
38218 +        * memory state for these cases.
38219 +        */
38220 +
38221 +       NS_REG("syscall_fault", all_regs, 0),
38222 +
38223 +       NS_REG("bad_get_user", all_regs,
38224 +               BB_SKIP(RAX) | BB_SKIP(RDX)),
38225 +
38226 +       /* Finally the cases that pass data in both registers and memory.
38227 +       */
38228 +
38229 +       /* This entry is redundant now because bb_fixup_switch_to() hides the
38230 +        * jmp __switch_to case, however the entry is left here as
38231 +        * documentation.
38232 +        *
38233 +        * NS("__switch_to", no_memory, no_regs, 0, 0, 0),
38234 +        */
38235 +};
38236 +
38237 +static const char *bb_spurious[] = {
38238 +                               /* ret_from_exception */
38239 +       "ret_from_intr",
38240 +       "check_userspace",
38241 +       "resume_userspace",
38242 +                               /* resume_kernel */
38243 +#ifdef CONFIG_PREEMPT
38244 +       "need_resched",
38245 +#endif /* CONFIG_PREEMPT */
38246 +                               /* sysenter_entry */
38247 +       "sysenter_past_esp",
38248 +                               /* system_call */
38249 +       "no_singlestep",
38250 +       "syscall_call",
38251 +       "syscall_exit",
38252 +       "restore_all",
38253 +       "restore_nocheck",
38254 +       "restore_nocheck_notrace",
38255 +       "ldt_ss",
38256 +       /* do not include iret_exc, it is in a .fixup section */
38257 +                               /* work_pending */
38258 +       "work_resched",
38259 +       "work_notifysig",
38260 +#ifdef CONFIG_VM86
38261 +       "work_notifysig_v86",
38262 +#endif /* CONFIG_VM86 */
38263 +                               /* page_fault */
38264 +       "error_code",
38265 +                               /* device_not_available */
38266 +       "device_not_available_emulate",
38267 +                               /* debug */
38268 +       "debug_esp_fix_insn",
38269 +       "debug_stack_correct",
38270 +                               /* nmi */
38271 +       "nmi_stack_correct",
38272 +       "nmi_stack_fixup",
38273 +       "nmi_debug_stack_check",
38274 +       "nmi_espfix_stack",
38275 +};
38276 +
38277 +#define        HARDWARE_PUSHED (2 * KDB_WORD_SIZE)
38278 +
38279 +static const char *bb_hardware_handlers[] = {
38280 +       "ret_from_exception",
38281 +       "system_call",
38282 +       "work_pending",
38283 +       "syscall_fault",
38284 +       "page_fault",
38285 +       "coprocessor_error",
38286 +       "simd_coprocessor_error",
38287 +       "device_not_available",
38288 +       "debug",
38289 +       "nmi",
38290 +       "int3",
38291 +       "overflow",
38292 +       "bounds",
38293 +       "invalid_op",
38294 +       "coprocessor_segment_overrun",
38295 +       "invalid_TSS",
38296 +       "segment_not_present",
38297 +       "stack_segment",
38298 +       "general_protection",
38299 +       "alignment_check",
38300 +       "kdb_call",
38301 +       "divide_error",
38302 +       "machine_check",
38303 +       "spurious_interrupt_bug",
38304 +};
38305 +
38306 +static void
38307 +bb_start_block0(void)
38308 +{
38309 +       bb_reg_code_set_value(BBRG_RAX, BBRG_RAX);
38310 +       bb_reg_code_set_value(BBRG_RBX, BBRG_RBX);
38311 +       bb_reg_code_set_value(BBRG_RCX, BBRG_RCX);
38312 +       bb_reg_code_set_value(BBRG_RDX, BBRG_RDX);
38313 +       bb_reg_code_set_value(BBRG_RDI, BBRG_RDI);
38314 +       bb_reg_code_set_value(BBRG_RSI, BBRG_RSI);
38315 +       bb_reg_code_set_value(BBRG_RBP, BBRG_RBP);
38316 +       bb_reg_code_set_value(BBRG_RSP, BBRG_OSP);
38317 +}
38318 +
38319 +/* The i386 code that switches stack in a context switch is an extremely
38320 + * special case.  It saves the rip pointing to a label that is not otherwise
38321 + * referenced, saves the current rsp then pushes a word.  The magic code that
38322 + * resumes the new task picks up the saved rip and rsp, effectively referencing
38323 + * a label that otherwise is not used and ignoring the pushed word.
38324 + *
38325 + * The simplest way to handle this very strange case is to recognise jmp
38326 + * address <__switch_to> and treat it as a popfl instruction.  This avoids
38327 + * terminating the block on this jmp and removes one word from the stack state,
38328 + * which is the end effect of all the magic code.
38329 + *
38330 + * Called with the instruction line, starting after the first ':'.
38331 + */
38332 +
38333 +static void
38334 +bb_fixup_switch_to(char *p)
38335 +{
38336 +       char *p1 = p;
38337 +       p += strspn(p, " \t");          /* start of instruction */
38338 +       if (strncmp(p, "jmp", 3))
38339 +               return;
38340 +       p += strcspn(p, " \t");         /* end of instruction */
38341 +       p += strspn(p, " \t");          /* start of address */
38342 +       p += strcspn(p, " \t");         /* end of address */
38343 +       p += strspn(p, " \t");          /* start of comment */
38344 +       if (strcmp(p, "<__switch_to>") == 0)
38345 +               strcpy(p1, "popfl");
38346 +}
38347 +
38348 +static int
38349 +bb_asmlinkage_arch(void)
38350 +{
38351 +       return strcmp(bb_func_name, "ret_from_exception") == 0 ||
38352 +              strcmp(bb_func_name, "syscall_trace_entry") == 0;
38353 +}
38354 +
38355 +#endif /* CONFIG_X86_64 */
38356 +
38357 +
38358 +/*============================================================================*/
38359 +/*                                                                            */
38360 +/* Common code and data.                                                      */
38361 +/*                                                                            */
38362 +/*============================================================================*/
38363 +
38364 +
38365 +/* Tracking registers by decoding the instructions is quite a bit harder than
38366 + * doing the same tracking using compiler generated information.  Register
38367 + * contents can remain in the same register, they can be copied to other
38368 + * registers, they can be stored on stack or they can be modified/overwritten.
38369 + * At any one time, there are 0 or more copies of the original value that was
38370 + * supplied in each register on input to the current function.  If a register
38371 + * exists in multiple places, one copy of that register is the master version,
38372 + * the others are temporary copies which may or may not be destroyed before the
38373 + * end of the function.
38374 + *
38375 + * The compiler knows which copy of a register is the master and which are
38376 + * temporary copies, which makes it relatively easy to track register contents
38377 + * as they are saved and restored.  Without that compiler based knowledge, this
38378 + * code has to track _every_ possible copy of each register, simply because we
38379 + * do not know which is the master copy and which are temporary copies which
38380 + * may be destroyed later.
38381 + *
38382 + * It gets worse: registers that contain parameters can be copied to other
38383 + * registers which are then saved on stack in a lower level function.  Also the
38384 + * stack pointer may be held in multiple registers (typically RSP and RBP)
38385 + * which contain different offsets from the base of the stack on entry to this
38386 + * function.  All of which means that we have to track _all_ register
38387 + * movements, or at least as much as possible.
38388 + *
38389 + * Start with the basic block that contains the start of the function, by
38390 + * definition all registers contain their initial value.  Track each
38391 + * instruction's effect on register contents, this includes reading from a
38392 + * parameter register before any write to that register, IOW the register
38393 + * really does contain a parameter.  The register state is represented by a
38394 + * dynamically sized array with each entry containing :-
38395 + *
38396 + *   Register name
38397 + *   Location it is copied to (another register or stack + offset)
38398 + *
38399 + * Besides the register tracking array, we track which parameter registers are
38400 + * read before being written, to determine how many parameters are passed in
38401 + * registers.  We also track which registers contain stack pointers, including
38402 + * their offset from the original stack pointer on entry to the function.
38403 + *
38404 + * At each exit from the current basic block (via JMP instruction or drop
38405 + * through), the register state is cloned to form the state on input to the
38406 + * target basic block and the target is marked for processing using this state.
38407 + * When there are multiple ways to enter a basic block (e.g. several JMP
38408 + * instructions referencing the same target) then there will be multiple sets
38409 + * of register state to form the "input" for that basic block, there is no
38410 + * guarantee that all paths to that block will have the same register state.
38411 + *
38412 + * As each target block is processed, all the known sets of register state are
38413 + * merged to form a suitable subset of the state which agrees with all the
38414 + * inputs.  The most common case is where one path to this block copies a
38415 + * register to another register but another path does not, therefore the copy
38416 + * is only a temporary and should not be propogated into this block.
38417 + *
38418 + * If the target block already has an input state from the current transfer
38419 + * point and the new input state is identical to the previous input state then
38420 + * we have reached a steady state for the arc from the current location to the
38421 + * target block.  Therefore there is no need to process the target block again.
38422 + *
38423 + * The steps of "process a block, create state for target block(s), pick a new
38424 + * target block, merge state for target block, process target block" will
38425 + * continue until all the state changes have propogated all the way down the
38426 + * basic block tree, including round any cycles in the tree.  The merge step
38427 + * only deletes tracking entries from the input state(s), it never adds a
38428 + * tracking entry.  Therefore the overall algorithm is guaranteed to converge
38429 + * to a steady state, the worst possible case is that every tracking entry into
38430 + * a block is deleted, which will result in an empty output state.
38431 + *
38432 + * As each instruction is decoded, it is checked to see if this is the point at
38433 + * which execution left this function.  This can be a call to another function
38434 + * (actually the return address to this function) or is the instruction which
38435 + * was about to be executed when an interrupt occurred (including an oops).
38436 + * Save the register state at this point.
38437 + *
38438 + * We always know what the registers contain when execution left this function.
38439 + * For an interrupt, the registers are in struct pt_regs.  For a call to
38440 + * another function, we have already deduced the register state on entry to the
38441 + * other function by unwinding to the start of that function.  Given the
38442 + * register state on exit from this function plus the known register contents
38443 + * on entry to the next function, we can determine the stack pointer value on
38444 + * input to this function.  That in turn lets us calculate the address of input
38445 + * registers that have been stored on stack, giving us the input parameters.
38446 + * Finally the stack pointer gives us the return address which is the exit
38447 + * point from the calling function, repeat the unwind process on that function.
38448 + *
38449 + * The data that tracks which registers contain input parameters is function
38450 + * global, not local to any basic block.  To determine which input registers
38451 + * contain parameters, we have to decode the entire function.  Otherwise an
38452 + * exit early in the function might not have read any parameters yet.
38453 + */
38454 +
38455 +/* Record memory contents in terms of the values that were passed to this
38456 + * function, IOW track which memory locations contain an input value.  A memory
38457 + * location's contents can be undefined, it can contain an input register value
38458 + * or it can contain an offset from the original stack pointer.
38459 + *
38460 + * This structure is used to record register contents that have been stored in
38461 + * memory.  Location (BBRG_OSP + 'offset_address') contains the input value
38462 + * from register 'value'.  When 'value' is BBRG_OSP then offset_value contains
38463 + * the offset from the original stack pointer that was stored in this memory
38464 + * location.  When 'value' is not BBRG_OSP then the memory location contains
38465 + * the original contents of an input register and offset_value is ignored.
38466 + *
38467 + * An input register 'value' can be stored in more than one register and/or in
38468 + * more than one memory location.
38469 + */
38470 +
38471 +struct bb_memory_contains
38472 +{
38473 +       short offset_address;
38474 +       enum bb_reg_code value: 8;
38475 +       short offset_value;
38476 +};
38477 +
38478 +/* Track the register state in each basic block. */
38479 +
38480 +struct bb_reg_state
38481 +{
38482 +       /* Indexed by register value 'reg - BBRG_RAX' */
38483 +       struct bb_reg_contains contains[KDB_INT_REGISTERS];
38484 +       int ref_count;
38485 +       int mem_count;
38486 +       /* dynamic size for memory locations, see mem_count */
38487 +       struct bb_memory_contains memory[0];
38488 +};
38489 +
38490 +static struct bb_reg_state *bb_reg_state, *bb_exit_state;
38491 +static int bb_reg_state_max, bb_reg_params, bb_memory_params;
38492 +
38493 +struct bb_actual
38494 +{
38495 +       bfd_vma value;
38496 +       int valid;
38497 +};
38498 +
38499 +/* Contains the actual hex value of a register, plus a valid bit.  Indexed by
38500 + * register value 'reg - BBRG_RAX'
38501 + */
38502 +static struct bb_actual bb_actual[KDB_INT_REGISTERS];
38503 +
38504 +static bfd_vma bb_func_start, bb_func_end;
38505 +static bfd_vma bb_common_interrupt, bb_error_entry, bb_ret_from_intr,
38506 +              bb_thread_return, bb_sync_regs, bb_save_v86_state,
38507 +              bb__sched_text_start, bb__sched_text_end;
38508 +
38509 +/* Record jmp instructions, both conditional and unconditional.  These form the
38510 + * arcs between the basic blocks.  This is also used to record the state when
38511 + * one block drops through into the next.
38512 + *
38513 + * A bb can have multiple associated bb_jmp entries, one for each jcc
38514 + * instruction plus at most one bb_jmp for the drop through case.  If a bb
38515 + * drops through to the next bb then the drop through bb_jmp entry will be the
38516 + * last entry in the set of bb_jmp's that are associated with the bb.  This is
38517 + * enforced by the fact that jcc entries are added during the disassembly phase
38518 + * of pass 1, the drop through entries are added near the end of pass 1.
38519 + *
38520 + * At address 'from' in this block, we have a jump to address 'to'.  The
38521 + * register state at 'from' is copied to the target block.
38522 + */
38523 +
38524 +struct bb_jmp
38525 +{
38526 +       bfd_vma from;
38527 +       bfd_vma to;
38528 +       struct bb_reg_state *state;
38529 +       unsigned int drop_through: 1;
38530 +};
38531 +
38532 +struct bb
38533 +{
38534 +       bfd_vma start;
38535 +       /* The end address of a basic block is sloppy.  It can be the first
38536 +        * byte of the last instruction in the block or it can be the last byte
38537 +        * of the block.
38538 +        */
38539 +       bfd_vma end;
38540 +       unsigned int changed: 1;
38541 +       unsigned int drop_through: 1;
38542 +};
38543 +
38544 +static struct bb **bb_list, *bb_curr;
38545 +static int bb_max, bb_count;
38546 +
38547 +static struct bb_jmp *bb_jmp_list;
38548 +static int bb_jmp_max, bb_jmp_count;
38549 +
38550 +static int bb_giveup;
38551 +
38552 +/* Add a new bb entry to the list.  This does an insert sort. */
38553 +
38554 +static struct bb *
38555 +bb_new(bfd_vma order)
38556 +{
38557 +       int i, j;
38558 +       struct bb *bb, *p;
38559 +       if (bb_giveup)
38560 +               return NULL;
38561 +       if (bb_count == bb_max) {
38562 +               struct bb **bb_list_new;
38563 +               bb_max += 10;
38564 +               bb_list_new = debug_kmalloc(bb_max*sizeof(*bb_list_new),
38565 +                                           GFP_ATOMIC);
38566 +               if (!bb_list_new) {
38567 +                       kdb_printf("\n\n%s: out of debug_kmalloc\n", __FUNCTION__);
38568 +                       bb_giveup = 1;
38569 +                       return NULL;
38570 +               }
38571 +               memcpy(bb_list_new, bb_list, bb_count*sizeof(*bb_list));
38572 +               debug_kfree(bb_list);
38573 +               bb_list = bb_list_new;
38574 +       }
38575 +       bb = debug_kmalloc(sizeof(*bb), GFP_ATOMIC);
38576 +       if (!bb) {
38577 +               kdb_printf("\n\n%s: out of debug_kmalloc\n", __FUNCTION__);
38578 +               bb_giveup = 1;
38579 +               return NULL;
38580 +       }
38581 +       memset(bb, 0, sizeof(*bb));
38582 +       for (i = 0; i < bb_count; ++i) {
38583 +               p = bb_list[i];
38584 +               if ((p->start && p->start > order) ||
38585 +                   (p->end && p->end > order))
38586 +                       break;
38587 +       }
38588 +       for (j = bb_count-1; j >= i; --j)
38589 +               bb_list[j+1] = bb_list[j];
38590 +       bb_list[i] = bb;
38591 +       ++bb_count;
38592 +       return bb;
38593 +}
38594 +
38595 +/* Add a new bb_jmp entry to the list.  This list is not sorted. */
38596 +
38597 +static struct bb_jmp *
38598 +bb_jmp_new(bfd_vma from, bfd_vma to, unsigned int drop_through)
38599 +{
38600 +       struct bb_jmp *bb_jmp;
38601 +       if (bb_giveup)
38602 +               return NULL;
38603 +       if (bb_jmp_count == bb_jmp_max) {
38604 +               struct bb_jmp *bb_jmp_list_new;
38605 +               bb_jmp_max += 10;
38606 +               bb_jmp_list_new =
38607 +                       debug_kmalloc(bb_jmp_max*sizeof(*bb_jmp_list_new),
38608 +                                     GFP_ATOMIC);
38609 +               if (!bb_jmp_list_new) {
38610 +                       kdb_printf("\n\n%s: out of debug_kmalloc\n",
38611 +                                  __FUNCTION__);
38612 +                       bb_giveup = 1;
38613 +                       return NULL;
38614 +               }
38615 +               memcpy(bb_jmp_list_new, bb_jmp_list,
38616 +                      bb_jmp_count*sizeof(*bb_jmp_list));
38617 +               debug_kfree(bb_jmp_list);
38618 +               bb_jmp_list = bb_jmp_list_new;
38619 +       }
38620 +       bb_jmp = bb_jmp_list + bb_jmp_count++;
38621 +       bb_jmp->from = from;
38622 +       bb_jmp->to = to;
38623 +       bb_jmp->drop_through = drop_through;
38624 +       bb_jmp->state = NULL;
38625 +       return bb_jmp;
38626 +}
38627 +
38628 +static void
38629 +bb_delete(int i)
38630 +{
38631 +       struct bb *bb = bb_list[i];
38632 +       memcpy(bb_list+i, bb_list+i+1, (bb_count-i-1)*sizeof(*bb_list));
38633 +       bb_list[--bb_count] = NULL;
38634 +       debug_kfree(bb);
38635 +}
38636 +
38637 +static struct bb *
38638 +bb_add(bfd_vma start, bfd_vma end)
38639 +{
38640 +       int i;
38641 +       struct bb *bb;
38642 +       /* Ignore basic blocks whose start address is outside the current
38643 +        * function.  These occur for call instructions and for tail recursion.
38644 +        */
38645 +       if (start &&
38646 +           (start < bb_func_start || start >= bb_func_end))
38647 +                      return NULL;
38648 +       for (i = 0; i < bb_count; ++i) {
38649 +               bb = bb_list[i];
38650 +               if ((start && bb->start == start) ||
38651 +                   (end && bb->end == end))
38652 +                       return bb;
38653 +       }
38654 +       bb = bb_new(start ? start : end);
38655 +       if (bb) {
38656 +               bb->start = start;
38657 +               bb->end = end;
38658 +       }
38659 +       return bb;
38660 +}
38661 +
38662 +static struct bb_jmp *
38663 +bb_jmp_add(bfd_vma from, bfd_vma to, unsigned int drop_through)
38664 +{
38665 +       int i;
38666 +       struct bb_jmp *bb_jmp;
38667 +       for (i = 0, bb_jmp = bb_jmp_list; i < bb_jmp_count; ++i, ++bb_jmp) {
38668 +               if (bb_jmp->from == from &&
38669 +                   bb_jmp->to == to &&
38670 +                   bb_jmp->drop_through == drop_through)
38671 +                       return bb_jmp;
38672 +       }
38673 +       bb_jmp = bb_jmp_new(from, to, drop_through);
38674 +       return bb_jmp;
38675 +}
38676 +
38677 +static unsigned long bb_curr_addr, bb_exit_addr;
38678 +static char bb_buffer[256];    /* A bit too big to go on stack */
38679 +
38680 +/* Computed jmp uses 'jmp *addr(,%reg,[48])' where 'addr' is the start of a
38681 + * table of addresses that point into the current function.  Run the table and
38682 + * generate bb starts for each target address plus a bb_jmp from this address
38683 + * to the target address.
38684 + *
38685 + * Only called for 'jmp' instructions, with the pointer starting at 'jmp'.
38686 + */
38687 +
38688 +static void
38689 +bb_pass1_computed_jmp(char *p)
38690 +{
38691 +       unsigned long table, scale;
38692 +       kdb_machreg_t addr;
38693 +       struct bb* bb;
38694 +       p += strcspn(p, " \t");         /* end of instruction */
38695 +       p += strspn(p, " \t");          /* start of address */
38696 +       if (*p++ != '*')
38697 +               return;
38698 +       table = simple_strtoul(p, &p, 0);
38699 +       if (strncmp(p, "(,%", 3) != 0)
38700 +               return;
38701 +       p += 3;
38702 +       p += strcspn(p, ",");           /* end of reg */
38703 +       if (*p++ != ',')
38704 +               return;
38705 +       scale = simple_strtoul(p, &p, 0);
38706 +       if (scale != KDB_WORD_SIZE || strcmp(p, ")"))
38707 +               return;
38708 +       while (!bb_giveup) {
38709 +               if (kdb_getword(&addr, table, sizeof(addr)))
38710 +                       return;
38711 +               if (addr < bb_func_start || addr >= bb_func_end)
38712 +                       return;
38713 +               bb = bb_add(addr, 0);
38714 +               if (bb)
38715 +                       bb_jmp_add(bb_curr_addr, addr, 0);
38716 +               table += KDB_WORD_SIZE;
38717 +       }
38718 +}
38719 +
38720 +/* Pass 1, identify the start and end of each basic block */
38721 +
38722 +static int
38723 +bb_dis_pass1(PTR file, const char *fmt, ...)
38724 +{
38725 +       int l = strlen(bb_buffer);
38726 +       char *p;
38727 +       va_list ap;
38728 +       va_start(ap, fmt);
38729 +       vsnprintf(bb_buffer + l, sizeof(bb_buffer) - l, fmt, ap);
38730 +       va_end(ap);
38731 +       if ((p = strchr(bb_buffer, '\n'))) {
38732 +               *p = '\0';
38733 +               /* ret[q], iret[q], sysexit, sysret, ud2a or jmp[q] end a
38734 +                * block.
38735 +                */
38736 +               p = bb_buffer;
38737 +               p += strcspn(p, ":");
38738 +               if (*p++ == ':') {
38739 +                       bb_fixup_switch_to(p);
38740 +                       p += strspn(p, " \t");  /* start of instruction */
38741 +                       if (strncmp(p, "ret", 3) == 0 ||
38742 +                           strncmp(p, "iret", 4) == 0 ||
38743 +                           strncmp(p, "sysexit", 7) == 0 ||
38744 +                           strncmp(p, "sysret", 6) == 0 ||
38745 +                           strncmp(p, "ud2a", 4) == 0 ||
38746 +                           strncmp(p, "jmp", 3) == 0) {
38747 +                               if (strncmp(p, "jmp", 3) == 0)
38748 +                                       bb_pass1_computed_jmp(p);
38749 +                               bb_add(0, bb_curr_addr);
38750 +                       };
38751 +               }
38752 +               bb_buffer[0] = '\0';
38753 +       }
38754 +       return 0;
38755 +}
38756 +
38757 +static void
38758 +bb_printaddr_pass1(bfd_vma addr, disassemble_info *dip)
38759 +{
38760 +       kdb_symtab_t symtab;
38761 +       unsigned int offset;
38762 +       struct bb* bb;
38763 +       /* disasm only calls the printaddr routine for the target of jmp, loop
38764 +        * or call instructions, i.e. the start of a basic block.  call is
38765 +        * ignored by bb_add because the target address is outside the current
38766 +        * function.
38767 +        */
38768 +       dip->fprintf_func(dip->stream, "0x%lx", addr);
38769 +       kdbnearsym(addr, &symtab);
38770 +       if (symtab.sym_name) {
38771 +               dip->fprintf_func(dip->stream, " <%s", symtab.sym_name);
38772 +               if ((offset = addr - symtab.sym_start))
38773 +                       dip->fprintf_func(dip->stream, "+0x%x", offset);
38774 +               dip->fprintf_func(dip->stream, ">");
38775 +       }
38776 +       bb = bb_add(addr, 0);
38777 +       if (bb)
38778 +               bb_jmp_add(bb_curr_addr, addr, 0);
38779 +}
38780 +
38781 +static void
38782 +bb_pass1(void)
38783 +{
38784 +       int i;
38785 +       unsigned long addr;
38786 +       struct bb* bb;
38787 +       struct bb_jmp *bb_jmp;
38788 +
38789 +       if (KDB_DEBUG(BB) | KDB_DEBUG(BB_SUMM))
38790 +               kdb_printf("%s: func_name %s func_start " kdb_bfd_vma_fmt0
38791 +                          " func_end " kdb_bfd_vma_fmt0 "\n",
38792 +                          __FUNCTION__,
38793 +                          bb_func_name,
38794 +                          bb_func_start,
38795 +                          bb_func_end);
38796 +       kdb_di.fprintf_func = bb_dis_pass1;
38797 +       kdb_di.print_address_func = bb_printaddr_pass1;
38798 +
38799 +       bb_add(bb_func_start, 0);
38800 +       for (bb_curr_addr = bb_func_start;
38801 +            bb_curr_addr < bb_func_end;
38802 +            ++bb_curr_addr) {
38803 +               unsigned char c;
38804 +               if (kdb_getarea(c, bb_curr_addr)) {
38805 +                       kdb_printf("%s: unreadable function code at ",
38806 +                                  __FUNCTION__);
38807 +                       kdb_symbol_print(bb_curr_addr, NULL, KDB_SP_DEFAULT);
38808 +                       kdb_printf(", giving up\n");
38809 +                       bb_giveup = 1;
38810 +                       return;
38811 +               }
38812 +       }
38813 +       for (addr = bb_func_start; addr < bb_func_end; ) {
38814 +               bb_curr_addr = addr;
38815 +               addr += kdba_id_printinsn(addr, &kdb_di);
38816 +               kdb_di.fprintf_func(NULL, "\n");
38817 +       }
38818 +       if (bb_giveup)
38819 +               goto out;
38820 +
38821 +       /* Special case: a block consisting of a single instruction which is
38822 +        * both the target of a jmp and is also an ending instruction, so we
38823 +        * add two blocks using the same address, one as a start and one as an
38824 +        * end, in no guaranteed order.  The end must be ordered after the
38825 +        * start.
38826 +        */
38827 +       for (i = 0; i < bb_count-1; ++i) {
38828 +               struct bb *bb1 = bb_list[i], *bb2 = bb_list[i+1];
38829 +               if (bb1->end && bb1->end == bb2->start) {
38830 +                       bb = bb_list[i+1];
38831 +                       bb_list[i+1] = bb_list[i];
38832 +                       bb_list[i] = bb;
38833 +               }
38834 +       }
38835 +
38836 +       /* Some bb have a start address, some have an end address.  Collapse
38837 +        * them into entries that have both start and end addresses.  The first
38838 +        * entry is guaranteed to have a start address.
38839 +        */
38840 +       for (i = 0; i < bb_count-1; ++i) {
38841 +               struct bb *bb1 = bb_list[i], *bb2 = bb_list[i+1];
38842 +               if (bb1->end)
38843 +                       continue;
38844 +               if (bb2->start) {
38845 +                       bb1->end = bb2->start - 1;
38846 +                       bb1->drop_through = 1;
38847 +                       bb_jmp_add(bb1->end, bb2->start, 1);
38848 +               } else {
38849 +                       bb1->end = bb2->end;
38850 +                       bb_delete(i+1);
38851 +               }
38852 +       }
38853 +       bb = bb_list[bb_count-1];
38854 +       if (!bb->end)
38855 +               bb->end = bb_func_end - 1;
38856 +
38857 +       /* It would be nice to check that all bb have a valid start and end
38858 +        * address but there is just too much garbage code in the kernel to do
38859 +        * that check.  Aligned functions in assembler code mean that there is
38860 +        * space between the end of one function and the start of the next and
38861 +        * that space contains previous code from the assembler's buffers.  It
38862 +        * looks like dead code with nothing that branches to it, so no start
38863 +        * address.  do_sys_vm86() ends with 'jmp resume_userspace' which the C
38864 +        * compiler does not know about so gcc appends the normal exit code,
38865 +        * again nothing branches to this dangling code.
38866 +        *
38867 +        * The best we can do is delete bb entries with no start address.
38868 +        */
38869 +       for (i = 0; i < bb_count; ++i) {
38870 +               struct bb *bb = bb_list[i];
38871 +               if (!bb->start)
38872 +                       bb_delete(i--);
38873 +       }
38874 +       for (i = 0; i < bb_count; ++i) {
38875 +               struct bb *bb = bb_list[i];
38876 +               if (!bb->end) {
38877 +                       kdb_printf("%s: incomplete bb state\n", __FUNCTION__);
38878 +                       bb_giveup = 1;
38879 +                       goto debug;
38880 +               }
38881 +       }
38882 +
38883 +out:
38884 +       if (!KDB_DEBUG(BB))
38885 +               return;
38886 +debug:
38887 +       kdb_printf("%s: end\n", __FUNCTION__);
38888 +       for (i = 0; i < bb_count; ++i) {
38889 +               bb = bb_list[i];
38890 +               kdb_printf("  bb[%d] start "
38891 +                          kdb_bfd_vma_fmt0
38892 +                          " end " kdb_bfd_vma_fmt0
38893 +                          " drop_through %d",
38894 +                          i, bb->start, bb->end, bb->drop_through);
38895 +               kdb_printf("\n");
38896 +       }
38897 +       for (i = 0; i < bb_jmp_count; ++i) {
38898 +               bb_jmp = bb_jmp_list + i;
38899 +               kdb_printf("  bb_jmp[%d] from "
38900 +                          kdb_bfd_vma_fmt0
38901 +                          " to " kdb_bfd_vma_fmt0
38902 +                          " drop_through %d\n",
38903 +                          i, bb_jmp->from, bb_jmp->to, bb_jmp->drop_through);
38904 +       }
38905 +}
38906 +
38907 +/* Pass 2, record register changes in each basic block */
38908 +
38909 +/* For each opcode that we care about, indicate how it uses its operands.  Most
38910 + * opcodes can be handled generically because they completely specify their
38911 + * operands in the instruction, however many opcodes have side effects such as
38912 + * reading or writing rax or updating rsp.  Instructions that change registers
38913 + * that are not listed in the operands must be handled as special cases.  In
38914 + * addition, instructions that copy registers while preserving their contents
38915 + * (push, pop, mov) or change the contents in a well defined way (add with an
38916 + * immediate, lea) must be handled as special cases in order to track the
38917 + * register contents.
38918 + *
38919 + * The tables below only list opcodes that are actually used in the Linux
38920 + * kernel, so they omit most of the floating point and all of the SSE type
38921 + * instructions.  The operand usage entries only cater for accesses to memory
38922 + * and to the integer registers, accesses to floating point registers and flags
38923 + * are not relevant for kernel backtraces.
38924 + */
38925 +
38926 +enum bb_operand_usage {
38927 +       BBOU_UNKNOWN = 0,
38928 +               /* generic entries.  because xchg can do any combinations of
38929 +                * read src, write src, read dst and  write dst we need to
38930 +                * define all 16 possibilities.  These are ordered by rs = 1,
38931 +                * rd = 2, ws = 4, wd = 8, bb_usage_x*() functions rely on this
38932 +                * order.
38933 +                */
38934 +       BBOU_RS = 1,    /* read src */          /*  1 */
38935 +       BBOU_RD,        /* read dst */          /*  2 */
38936 +       BBOU_RSRD,                              /*  3 */
38937 +       BBOU_WS,        /* write src */         /*  4 */
38938 +       BBOU_RSWS,                              /*  5 */
38939 +       BBOU_RDWS,                              /*  6 */
38940 +       BBOU_RSRDWS,                            /*  7 */
38941 +       BBOU_WD,        /* write dst */         /*  8 */
38942 +       BBOU_RSWD,                              /*  9 */
38943 +       BBOU_RDWD,                              /* 10 */
38944 +       BBOU_RSRDWD,                            /* 11 */
38945 +       BBOU_WSWD,                              /* 12 */
38946 +       BBOU_RSWSWD,                            /* 13 */
38947 +       BBOU_RDWSWD,                            /* 14 */
38948 +       BBOU_RSRDWSWD,                          /* 15 */
38949 +               /* opcode specific entries */
38950 +       BBOU_ADD,
38951 +       BBOU_CALL,
38952 +       BBOU_CBW,
38953 +       BBOU_CMOV,
38954 +       BBOU_CMPXCHG,
38955 +       BBOU_CMPXCHGD,
38956 +       BBOU_CPUID,
38957 +       BBOU_CWD,
38958 +       BBOU_DIV,
38959 +       BBOU_IDIV,
38960 +       BBOU_IMUL,
38961 +       BBOU_IRET,
38962 +       BBOU_JMP,
38963 +       BBOU_LAHF,
38964 +       BBOU_LEA,
38965 +       BBOU_LEAVE,
38966 +       BBOU_LODS,
38967 +       BBOU_LOOP,
38968 +       BBOU_LSS,
38969 +       BBOU_MONITOR,
38970 +       BBOU_MOV,
38971 +       BBOU_MOVS,
38972 +       BBOU_MUL,
38973 +       BBOU_MWAIT,
38974 +       BBOU_NOP,
38975 +       BBOU_OUTS,
38976 +       BBOU_POP,
38977 +       BBOU_POPF,
38978 +       BBOU_PUSH,
38979 +       BBOU_PUSHF,
38980 +       BBOU_RDMSR,
38981 +       BBOU_RDTSC,
38982 +       BBOU_RET,
38983 +       BBOU_SAHF,
38984 +       BBOU_SCAS,
38985 +       BBOU_SUB,
38986 +       BBOU_SYSEXIT,
38987 +       BBOU_SYSRET,
38988 +       BBOU_WRMSR,
38989 +       BBOU_XADD,
38990 +       BBOU_XCHG,
38991 +       BBOU_XOR,
38992 +};
38993 +
38994 +struct bb_opcode_usage {
38995 +       int length;
38996 +       enum bb_operand_usage usage;
38997 +       const char *opcode;
38998 +};
38999 +
39000 +/* This table is sorted in alphabetical order of opcode, except that the
39001 + * trailing '"' is treated as a high value.  For example, 'in' sorts after
39002 + * 'inc', 'bt' after 'btc'.  This modified sort order ensures that shorter
39003 + * opcodes come after long ones.  A normal sort would put 'in' first, so 'in'
39004 + * would match both 'inc' and 'in'.  When adding any new entries to this table,
39005 + * be careful to put shorter entries last in their group.
39006 + *
39007 + * To automatically sort the table (in vi)
39008 + *   Mark the first and last opcode line with 'a and 'b
39009 + *   'a
39010 + *   !'bsed -e 's/"}/}}/' | LANG=C sort -t '"' -k2 | sed -e 's/}}/"}/'
39011 + *
39012 + * If a new instruction has to be added, first consider if it affects registers
39013 + * other than those listed in the operands.  Also consider if you want to track
39014 + * the results of issuing the instruction, IOW can you extract useful
39015 + * information by looking in detail at the modified registers or memory.  If
39016 + * either test is true then you need a special case to handle the instruction.
39017 + *
39018 + * The generic entries at the start of enum bb_operand_usage all have one thing
39019 + * in common, if a register or memory location is updated then that location
39020 + * becomes undefined, i.e. we lose track of anything that was previously saved
39021 + * in that location.  So only use a generic BBOU_* value when the result of the
39022 + * instruction cannot be calculated exactly _and_ when all the affected
39023 + * registers are listed in the operands.
39024 + *
39025 + * Examples:
39026 + *
39027 + * 'call' does not generate a known result, but as a side effect of call,
39028 + * several scratch registers become undefined, so it needs a special BBOU_CALL
39029 + * entry.
39030 + *
39031 + * 'adc' generates a variable result, it depends on the carry flag, so 'adc'
39032 + * gets a generic entry.  'add' can generate an exact result (add with
39033 + * immediate on a register that points to the stack) or it can generate an
39034 + * unknown result (add a variable, or add immediate to a register that does not
39035 + * contain a stack pointer) so 'add' has its own BBOU_ADD entry.
39036 + */
39037 +
39038 +static const struct bb_opcode_usage
39039 +bb_opcode_usage_all[] = {
39040 +       {3, BBOU_RSRDWD,  "adc"},
39041 +       {3, BBOU_ADD,     "add"},
39042 +       {3, BBOU_RSRDWD,  "and"},
39043 +       {3, BBOU_RSWD,    "bsf"},
39044 +       {3, BBOU_RSWD,    "bsr"},
39045 +       {5, BBOU_RSWS,    "bswap"},
39046 +       {3, BBOU_RSRDWD,  "btc"},
39047 +       {3, BBOU_RSRDWD,  "btr"},
39048 +       {3, BBOU_RSRDWD,  "bts"},
39049 +       {2, BBOU_RSRD,    "bt"},
39050 +       {4, BBOU_CALL,    "call"},
39051 +       {4, BBOU_CBW,     "cbtw"},      /* Intel cbw */
39052 +       {3, BBOU_NOP,     "clc"},
39053 +       {3, BBOU_NOP,     "cld"},
39054 +       {7, BBOU_RS,      "clflush"},
39055 +       {3, BBOU_NOP,     "cli"},
39056 +       {4, BBOU_CWD,     "cltd"},      /* Intel cdq */
39057 +       {4, BBOU_CBW,     "cltq"},      /* Intel cdqe */
39058 +       {4, BBOU_NOP,     "clts"},
39059 +       {4, BBOU_CMOV,    "cmov"},
39060 +       {9, BBOU_CMPXCHGD,"cmpxchg16"},
39061 +       {8, BBOU_CMPXCHGD,"cmpxchg8"},
39062 +       {7, BBOU_CMPXCHG, "cmpxchg"},
39063 +       {3, BBOU_RSRD,    "cmp"},
39064 +       {5, BBOU_CPUID,   "cpuid"},
39065 +       {4, BBOU_CWD,     "cqto"},      /* Intel cdo */
39066 +       {4, BBOU_CWD,     "cwtd"},      /* Intel cwd */
39067 +       {4, BBOU_CBW,     "cwtl"},      /* Intel cwde */
39068 +       {4, BBOU_NOP,     "data"},      /* alternative ASM_NOP<n> generates data16 on x86_64 */
39069 +       {3, BBOU_RSWS,    "dec"},
39070 +       {3, BBOU_DIV,     "div"},
39071 +       {5, BBOU_RS,      "fdivl"},
39072 +       {5, BBOU_NOP,     "finit"},
39073 +       {6, BBOU_RS,      "fistpl"},
39074 +       {4, BBOU_RS,      "fldl"},
39075 +       {5, BBOU_RS,      "fmull"},
39076 +       {6, BBOU_NOP,     "fnclex"},
39077 +       {6, BBOU_NOP,     "fninit"},
39078 +       {6, BBOU_RS,      "fnsave"},
39079 +       {7, BBOU_NOP,     "fnsetpm"},
39080 +       {6, BBOU_RS,      "frstor"},
39081 +       {5, BBOU_WS,      "fstsw"},
39082 +       {5, BBOU_RS,      "fsubp"},
39083 +       {5, BBOU_NOP,     "fwait"},
39084 +       {7, BBOU_RS,      "fxrstor"},
39085 +       {6, BBOU_RS,      "fxsave"},
39086 +       {3, BBOU_NOP,     "hlt"},
39087 +       {4, BBOU_IDIV,    "idiv"},
39088 +       {4, BBOU_IMUL,    "imul"},
39089 +       {3, BBOU_RSWS,    "inc"},
39090 +       {3, BBOU_NOP,     "int"},
39091 +       {6, BBOU_RS,      "invlpg"},
39092 +       {2, BBOU_RSWD,    "in"},
39093 +       {4, BBOU_IRET,    "iret"},
39094 +       {1, BBOU_JMP,     "j"},
39095 +       {4, BBOU_LAHF,    "lahf"},
39096 +       {3, BBOU_RSWD,    "lar"},
39097 +       {5, BBOU_RS,      "lcall"},
39098 +       {5, BBOU_LEAVE,   "leave"},
39099 +       {3, BBOU_LEA,     "lea"},
39100 +       {6, BBOU_NOP,     "lfence"},
39101 +       {4, BBOU_RS,      "lgdt"},
39102 +       {4, BBOU_RS,      "lidt"},
39103 +       {4, BBOU_RS,      "ljmp"},
39104 +       {4, BBOU_RS,      "lldt"},
39105 +       {4, BBOU_RS,      "lmsw"},
39106 +       {4, BBOU_LODS,    "lods"},
39107 +       {4, BBOU_LOOP,    "loop"},
39108 +       {4, BBOU_NOP,     "lret"},
39109 +       {3, BBOU_RSWD,    "lsl"},
39110 +       {3, BBOU_LSS,     "lss"},
39111 +       {3, BBOU_RS,      "ltr"},
39112 +       {6, BBOU_NOP,     "mfence"},
39113 +       {7, BBOU_MONITOR, "monitor"},
39114 +       {4, BBOU_MOVS,    "movs"},
39115 +       {3, BBOU_MOV,     "mov"},
39116 +       {3, BBOU_MUL,     "mul"},
39117 +       {5, BBOU_MWAIT,   "mwait"},
39118 +       {3, BBOU_RSWS,    "neg"},
39119 +       {3, BBOU_NOP,     "nop"},
39120 +       {3, BBOU_RSWS,    "not"},
39121 +       {2, BBOU_RSRDWD,  "or"},
39122 +       {4, BBOU_OUTS,    "outs"},
39123 +       {3, BBOU_RSRD,    "out"},
39124 +       {5, BBOU_NOP,     "pause"},
39125 +       {4, BBOU_POPF,    "popf"},
39126 +       {3, BBOU_POP,     "pop"},
39127 +       {8, BBOU_RS,      "prefetch"},
39128 +       {5, BBOU_PUSHF,   "pushf"},
39129 +       {4, BBOU_PUSH,    "push"},
39130 +       {3, BBOU_RSRDWD,  "rcr"},
39131 +       {5, BBOU_RDMSR,   "rdmsr"},
39132 +       {5, BBOU_RDTSC,   "rdtsc"},
39133 +       {3, BBOU_RET,     "ret"},
39134 +       {3, BBOU_RSRDWD,  "rol"},
39135 +       {3, BBOU_RSRDWD,  "ror"},
39136 +       {4, BBOU_SAHF,    "sahf"},
39137 +       {3, BBOU_RSRDWD,  "sar"},
39138 +       {3, BBOU_RSRDWD,  "sbb"},
39139 +       {4, BBOU_SCAS,    "scas"},
39140 +       {3, BBOU_WS,      "set"},
39141 +       {6, BBOU_NOP,     "sfence"},
39142 +       {4, BBOU_WS,      "sgdt"},
39143 +       {3, BBOU_RSRDWD,  "shl"},
39144 +       {3, BBOU_RSRDWD,  "shr"},
39145 +       {4, BBOU_WS,      "sidt"},
39146 +       {4, BBOU_WS,      "sldt"},
39147 +       {3, BBOU_NOP,     "stc"},
39148 +       {3, BBOU_NOP,     "std"},
39149 +       {3, BBOU_NOP,     "sti"},
39150 +       {4, BBOU_SCAS,    "stos"},
39151 +       {4, BBOU_WS,      "strl"},
39152 +       {3, BBOU_WS,      "str"},
39153 +       {3, BBOU_SUB,     "sub"},
39154 +       {6, BBOU_NOP,     "swapgs"},
39155 +       {7, BBOU_SYSEXIT, "sysexit"},
39156 +       {6, BBOU_SYSRET,  "sysret"},
39157 +       {4, BBOU_NOP,     "test"},
39158 +       {4, BBOU_NOP,     "ud2a"},
39159 +       {6, BBOU_NOP,     "wbinvd"},
39160 +       {5, BBOU_WRMSR,   "wrmsr"},
39161 +       {4, BBOU_XADD,    "xadd"},
39162 +       {4, BBOU_XCHG,    "xchg"},
39163 +       {3, BBOU_XOR,     "xor"},
39164 +};
39165 +
39166 +/* To speed up searching, index bb_opcode_usage_all by the first letter of each
39167 + * opcode.
39168 + */
39169 +static struct {
39170 +       const struct bb_opcode_usage *opcode;
39171 +       int size;
39172 +} bb_opcode_usage[26];
39173 +
39174 +struct bb_operand {
39175 +       char *base;
39176 +       char *index;
39177 +       char *segment;
39178 +       long disp;
39179 +       unsigned int scale;
39180 +       enum bb_reg_code base_rc;               /* UNDEFINED or RAX through R15 */
39181 +       enum bb_reg_code index_rc;              /* UNDEFINED or RAX through R15 */
39182 +       unsigned int present            :1;
39183 +       unsigned int disp_present       :1;
39184 +       unsigned int indirect           :1;     /* must be combined with reg or memory */
39185 +       unsigned int immediate          :1;     /* exactly one of these 3 must be set */
39186 +       unsigned int reg                :1;
39187 +       unsigned int memory             :1;
39188 +};
39189 +
39190 +struct bb_decode {
39191 +       char *prefix;
39192 +       char *opcode;
39193 +       const struct bb_opcode_usage *match;
39194 +       struct bb_operand src;
39195 +       struct bb_operand dst;
39196 +       struct bb_operand dst2;
39197 +};
39198 +
39199 +static struct bb_decode bb_decode;
39200 +
39201 +static enum bb_reg_code
39202 +bb_reg_map(const char *reg)
39203 +{
39204 +       int lo, hi, c;
39205 +       const struct bb_reg_code_map *p;
39206 +       lo = 0;
39207 +       hi = ARRAY_SIZE(bb_reg_code_map) - 1;
39208 +       while (lo <= hi) {
39209 +               int mid = (hi + lo) / 2;
39210 +               p = bb_reg_code_map + mid;
39211 +               c = strcmp(p->name, reg+1);
39212 +               if (c == 0)
39213 +                       return p->reg;
39214 +               else if (c > 0)
39215 +                       hi = mid - 1;
39216 +               else
39217 +                       lo = mid + 1;
39218 +       }
39219 +       return BBRG_UNDEFINED;
39220 +}
39221 +
39222 +static void
39223 +bb_parse_operand(char *str, struct bb_operand *operand)
39224 +{
39225 +       char *p = str;
39226 +       int sign = 1;
39227 +       operand->present = 1;
39228 +       /* extract any segment prefix */
39229 +       if (p[0] == '%' && p[1] && p[2] == 's' && p[3] == ':') {
39230 +               operand->memory = 1;
39231 +               operand->segment = p;
39232 +               p[3] = '\0';
39233 +               p += 4;
39234 +       }
39235 +       /* extract displacement, base, index, scale */
39236 +       if (*p == '*') {
39237 +               /* jmp/call *disp(%reg), *%reg or *0xnnn */
39238 +               operand->indirect = 1;
39239 +               ++p;
39240 +       }
39241 +       if (*p == '-') {
39242 +               sign = -1;
39243 +               ++p;
39244 +       }
39245 +       if (*p == '$') {
39246 +               operand->immediate = 1;
39247 +               operand->disp_present = 1;
39248 +               operand->disp = simple_strtoul(p+1, &p, 0);
39249 +       } else if (isdigit(*p)) {
39250 +               operand->memory = 1;
39251 +               operand->disp_present = 1;
39252 +               operand->disp = simple_strtoul(p, &p, 0) * sign;
39253 +       }
39254 +       if (*p == '%') {
39255 +               operand->reg = 1;
39256 +               operand->base = p;
39257 +       } else if (*p == '(') {
39258 +               operand->memory = 1;
39259 +               operand->base = ++p;
39260 +               p += strcspn(p, ",)");
39261 +               if (p == operand->base)
39262 +                       operand->base = NULL;
39263 +               if (*p == ',') {
39264 +                       *p = '\0';
39265 +                       operand->index = ++p;
39266 +                       p += strcspn(p, ",)");
39267 +                       if (p == operand->index)
39268 +                               operand->index = NULL;
39269 +               }
39270 +               if (*p == ',') {
39271 +                       *p = '\0';
39272 +                       operand->scale = simple_strtoul(p+1, &p, 0);
39273 +               }
39274 +               *p = '\0';
39275 +       } else if (*p) {
39276 +               kdb_printf("%s: unexpected token '%c' after disp '%s'\n",
39277 +                          __FUNCTION__, *p, str);
39278 +               bb_giveup = 1;
39279 +       }
39280 +       if ((operand->immediate + operand->reg + operand->memory != 1) ||
39281 +           (operand->indirect && operand->immediate)) {
39282 +               kdb_printf("%s: incorrect decode '%s' N %d I %d R %d M %d\n",
39283 +                          __FUNCTION__, str,
39284 +                          operand->indirect, operand->immediate, operand->reg,
39285 +                          operand->memory);
39286 +               bb_giveup = 1;
39287 +       }
39288 +       if (operand->base)
39289 +               operand->base_rc = bb_reg_map(operand->base);
39290 +       if (operand->index)
39291 +               operand->index_rc = bb_reg_map(operand->index);
39292 +}
39293 +
39294 +static void
39295 +bb_print_operand(const char *type, const struct bb_operand *operand)
39296 +{
39297 +       if (!operand->present)
39298 +               return;
39299 +       kdb_printf("  %s %c%c: ",
39300 +                  type,
39301 +                  operand->indirect ? 'N' : ' ',
39302 +                  operand->immediate ? 'I' :
39303 +                    operand->reg ? 'R' :
39304 +                    operand->memory ? 'M' :
39305 +                    '?'
39306 +                  );
39307 +       if (operand->segment)
39308 +               kdb_printf("%s:", operand->segment);
39309 +       if (operand->immediate) {
39310 +               kdb_printf("$0x%lx", operand->disp);
39311 +       } else if (operand->reg) {
39312 +               if (operand->indirect)
39313 +                       kdb_printf("*");
39314 +               kdb_printf("%s", operand->base);
39315 +       } else if (operand->memory) {
39316 +               if (operand->indirect && (operand->base || operand->index))
39317 +                       kdb_printf("*");
39318 +               if (operand->disp_present) {
39319 +                       kdb_printf("0x%lx", operand->disp);
39320 +               }
39321 +               if (operand->base || operand->index || operand->scale) {
39322 +                       kdb_printf("(");
39323 +                       if (operand->base)
39324 +                               kdb_printf("%s", operand->base);
39325 +                       if (operand->index || operand->scale)
39326 +                               kdb_printf(",");
39327 +                       if (operand->index)
39328 +                               kdb_printf("%s", operand->index);
39329 +                       if (operand->scale)
39330 +                               kdb_printf(",%d", operand->scale);
39331 +                       kdb_printf(")");
39332 +               }
39333 +       }
39334 +       if (operand->base_rc)
39335 +               kdb_printf(" base_rc %d (%s)",
39336 +                          operand->base_rc, bbrg_name[operand->base_rc]);
39337 +       if (operand->index_rc)
39338 +               kdb_printf(" index_rc %d (%s)",
39339 +                          operand->index_rc,
39340 +                          bbrg_name[operand->index_rc]);
39341 +       kdb_printf("\n");
39342 +}
39343 +
39344 +static void
39345 +bb_print_opcode(void)
39346 +{
39347 +       const struct bb_opcode_usage *o = bb_decode.match;
39348 +       kdb_printf("  ");
39349 +       if (bb_decode.prefix)
39350 +               kdb_printf("%s ", bb_decode.prefix);
39351 +       kdb_printf("opcode '%s' matched by '%s', usage %d\n",
39352 +                  bb_decode.opcode, o->opcode, o->usage);
39353 +}
39354 +
39355 +static int
39356 +bb_parse_opcode(void)
39357 +{
39358 +       int c, i;
39359 +       const struct bb_opcode_usage *o;
39360 +       static int bb_parse_opcode_error_limit = 5;
39361 +       c = bb_decode.opcode[0] - 'a';
39362 +       if (c < 0 || c >= ARRAY_SIZE(bb_opcode_usage))
39363 +               goto nomatch;
39364 +       o = bb_opcode_usage[c].opcode;
39365 +       if (!o)
39366 +               goto nomatch;
39367 +       for (i = 0; i < bb_opcode_usage[c].size; ++i, ++o) {
39368 +               if (strncmp(bb_decode.opcode, o->opcode, o->length) == 0) {
39369 +                       bb_decode.match = o;
39370 +                       if (KDB_DEBUG(BB))
39371 +                               bb_print_opcode();
39372 +                       return 0;
39373 +               }
39374 +       }
39375 +nomatch:
39376 +       if (!bb_parse_opcode_error_limit)
39377 +               return 1;
39378 +       --bb_parse_opcode_error_limit;
39379 +       kdb_printf("%s: no match at [%s]%s " kdb_bfd_vma_fmt0 " - '%s'\n",
39380 +                  __FUNCTION__,
39381 +                  bb_mod_name, bb_func_name, bb_curr_addr,
39382 +                  bb_decode.opcode);
39383 +       return 1;
39384 +}
39385 +
39386 +static bool
39387 +bb_is_int_reg(enum bb_reg_code reg)
39388 +{
39389 +       return reg >= BBRG_RAX && reg < (BBRG_RAX + KDB_INT_REGISTERS);
39390 +}
39391 +
39392 +static bool
39393 +bb_is_simple_memory(const struct bb_operand *operand)
39394 +{
39395 +       return operand->memory &&
39396 +              bb_is_int_reg(operand->base_rc) &&
39397 +              !operand->index_rc &&
39398 +              operand->scale == 0 &&
39399 +              !operand->segment;
39400 +}
39401 +
39402 +static bool
39403 +bb_is_static_disp(const struct bb_operand *operand)
39404 +{
39405 +       return operand->memory &&
39406 +              !operand->base_rc &&
39407 +              !operand->index_rc &&
39408 +              operand->scale == 0 &&
39409 +              !operand->segment &&
39410 +              !operand->indirect;
39411 +}
39412 +
39413 +static enum bb_reg_code
39414 +bb_reg_code_value(enum bb_reg_code reg)
39415 +{
39416 +       BB_CHECK(!bb_is_int_reg(reg), reg, 0);
39417 +       return bb_reg_state->contains[reg - BBRG_RAX].value;
39418 +}
39419 +
39420 +static short
39421 +bb_reg_code_offset(enum bb_reg_code reg)
39422 +{
39423 +       BB_CHECK(!bb_is_int_reg(reg), reg, 0);
39424 +       return bb_reg_state->contains[reg - BBRG_RAX].offset;
39425 +}
39426 +
39427 +static void
39428 +bb_reg_code_set_value(enum bb_reg_code dst, enum bb_reg_code src)
39429 +{
39430 +       BB_CHECK(!bb_is_int_reg(dst), dst, );
39431 +       bb_reg_state->contains[dst - BBRG_RAX].value = src;
39432 +}
39433 +
39434 +static void
39435 +bb_reg_code_set_offset(enum bb_reg_code dst, short offset)
39436 +{
39437 +       BB_CHECK(!bb_is_int_reg(dst), dst, );
39438 +       bb_reg_state->contains[dst - BBRG_RAX].offset = offset;
39439 +}
39440 +
39441 +static bool
39442 +bb_is_osp_defined(enum bb_reg_code reg)
39443 +{
39444 +       if (bb_is_int_reg(reg))
39445 +               return bb_reg_code_value(reg) == BBRG_OSP;
39446 +       else
39447 +               return 0;
39448 +}
39449 +
39450 +static bfd_vma
39451 +bb_actual_value(enum bb_reg_code reg)
39452 +{
39453 +       BB_CHECK(!bb_is_int_reg(reg), reg, 0);
39454 +       return bb_actual[reg - BBRG_RAX].value;
39455 +}
39456 +
39457 +static int
39458 +bb_actual_valid(enum bb_reg_code reg)
39459 +{
39460 +       BB_CHECK(!bb_is_int_reg(reg), reg, 0);
39461 +       return bb_actual[reg - BBRG_RAX].valid;
39462 +}
39463 +
39464 +static void
39465 +bb_actual_set_value(enum bb_reg_code reg, bfd_vma value)
39466 +{
39467 +       BB_CHECK(!bb_is_int_reg(reg), reg, );
39468 +       bb_actual[reg - BBRG_RAX].value = value;
39469 +}
39470 +
39471 +static void
39472 +bb_actual_set_valid(enum bb_reg_code reg, int valid)
39473 +{
39474 +       BB_CHECK(!bb_is_int_reg(reg), reg, );
39475 +       bb_actual[reg - BBRG_RAX].valid = valid;
39476 +}
39477 +
39478 +/* The scheduler code switches RSP then does PUSH, it is not an error for RSP
39479 + * to be undefined in this area of the code.
39480 + */
39481 +static bool
39482 +bb_is_scheduler_address(void)
39483 +{
39484 +       return bb_curr_addr >= bb__sched_text_start &&
39485 +              bb_curr_addr < bb__sched_text_end;
39486 +}
39487 +
39488 +static void
39489 +bb_reg_read(enum bb_reg_code reg)
39490 +{
39491 +       int i, o = 0;
39492 +       if (!bb_is_int_reg(reg) ||
39493 +           bb_reg_code_value(reg) != reg)
39494 +               return;
39495 +       for (i = 0;
39496 +            i < min_t(unsigned int, REGPARM, ARRAY_SIZE(bb_param_reg));
39497 +            ++i) {
39498 +               if (reg == bb_param_reg[i]) {
39499 +                       o = i + 1;
39500 +                       break;
39501 +               }
39502 +       }
39503 +       bb_reg_params = max(bb_reg_params, o);
39504 +}
39505 +
39506 +static void
39507 +bb_do_reg_state_print(const struct bb_reg_state *s)
39508 +{
39509 +       int i, offset_address, offset_value;
39510 +       struct bb_memory_contains *c;
39511 +       enum bb_reg_code value;
39512 +       kdb_printf("  bb_reg_state %p\n", s);
39513 +       for (i = 0; i < ARRAY_SIZE(s->contains); ++i) {
39514 +               value = s->contains[i].value;
39515 +               offset_value = s->contains[i].offset;
39516 +               kdb_printf("    %s = %s",
39517 +                          bbrg_name[i + BBRG_RAX], bbrg_name[value]);
39518 +               if (value == BBRG_OSP)
39519 +                       KDB_DEBUG_BB_OFFSET_PRINTF(offset_value, "", "");
39520 +               kdb_printf("\n");
39521 +       }
39522 +       for (i = 0, c = s->memory; i < s->mem_count; ++i, ++c) {
39523 +               offset_address = c->offset_address;
39524 +               value = c->value;
39525 +               offset_value = c->offset_value;
39526 +               kdb_printf("    slot %d offset_address %c0x%x %s",
39527 +                          i,
39528 +                          offset_address >= 0 ? '+' : '-',
39529 +                          offset_address >= 0 ? offset_address : -offset_address,
39530 +                          bbrg_name[value]);
39531 +               if (value == BBRG_OSP)
39532 +                       KDB_DEBUG_BB_OFFSET_PRINTF(offset_value, "", "");
39533 +               kdb_printf("\n");
39534 +       }
39535 +}
39536 +
39537 +static void
39538 +bb_reg_state_print(const struct bb_reg_state *s)
39539 +{
39540 +       if (KDB_DEBUG(BB))
39541 +               bb_do_reg_state_print(s);
39542 +}
39543 +
39544 +/* Set register 'dst' to contain the value from 'src'.  This includes reading
39545 + * from 'src' and writing to 'dst'.  The offset value is copied iff 'src'
39546 + * contains a stack pointer.
39547 + *
39548 + * Be very careful about the context here.  'dst' and 'src' reflect integer
39549 + * registers by name, _not_ by the value of their contents.  "mov %rax,%rsi"
39550 + * will call this function as bb_reg_set_reg(BBRG_RSI, BBRG_RAX), which
39551 + * reflects what the assembler code is doing.  However we need to track the
39552 + * _values_ in the registers, not their names.  IOW, we really care about "what
39553 + * value does rax contain when it is copied into rsi?", so we can record the
39554 + * fact that we now have two copies of that value, one in rax and one in rsi.
39555 + */
39556 +
39557 +static void
39558 +bb_reg_set_reg(enum bb_reg_code dst, enum bb_reg_code src)
39559 +{
39560 +       enum bb_reg_code src_value = BBRG_UNDEFINED;
39561 +       short offset_value = 0;
39562 +       KDB_DEBUG_BB("  %s = %s", bbrg_name[dst], bbrg_name[src]);
39563 +       if (bb_is_int_reg(src)) {
39564 +               bb_reg_read(src);
39565 +               src_value = bb_reg_code_value(src);
39566 +               KDB_DEBUG_BB(" (%s", bbrg_name[src_value]);
39567 +               if (bb_is_osp_defined(src)) {
39568 +                       offset_value = bb_reg_code_offset(src);
39569 +                       KDB_DEBUG_BB_OFFSET(offset_value, "", "");
39570 +               }
39571 +               KDB_DEBUG_BB(")");
39572 +       }
39573 +       if (bb_is_int_reg(dst)) {
39574 +               bb_reg_code_set_value(dst, src_value);
39575 +               bb_reg_code_set_offset(dst, offset_value);
39576 +       }
39577 +       KDB_DEBUG_BB("\n");
39578 +}
39579 +
39580 +static void
39581 +bb_reg_set_undef(enum bb_reg_code dst)
39582 +{
39583 +       bb_reg_set_reg(dst, BBRG_UNDEFINED);
39584 +}
39585 +
39586 +/* Delete any record of a stored register held in osp + 'offset' */
39587 +
39588 +static void
39589 +bb_delete_memory(short offset)
39590 +{
39591 +       int i;
39592 +       struct bb_memory_contains *c;
39593 +       for (i = 0, c = bb_reg_state->memory;
39594 +            i < bb_reg_state->mem_count;
39595 +            ++i, ++c) {
39596 +               if (c->offset_address == offset &&
39597 +                   c->value != BBRG_UNDEFINED) {
39598 +                       KDB_DEBUG_BB("  delete %s from ",
39599 +                                    bbrg_name[c->value]);
39600 +                       KDB_DEBUG_BB_OFFSET(offset, "osp", "");
39601 +                       KDB_DEBUG_BB(" slot %d\n",
39602 +                                    (int)(c - bb_reg_state->memory));
39603 +                       memset(c, BBRG_UNDEFINED, sizeof(*c));
39604 +                       if (i == bb_reg_state->mem_count - 1)
39605 +                               --bb_reg_state->mem_count;
39606 +               }
39607 +       }
39608 +}
39609 +
39610 +/* Set memory location *('dst' + 'offset_address') to contain the supplied
39611 + * value and offset.  'dst' is assumed to be a register that contains a stack
39612 + * pointer.
39613 + */
39614 +
39615 +static void
39616 +bb_memory_set_reg_value(enum bb_reg_code dst, short offset_address,
39617 +                       enum bb_reg_code value, short offset_value)
39618 +{
39619 +       int i;
39620 +       struct bb_memory_contains *c, *free = NULL;
39621 +       BB_CHECK(!bb_is_osp_defined(dst), dst, );
39622 +       KDB_DEBUG_BB("  *(%s", bbrg_name[dst]);
39623 +       KDB_DEBUG_BB_OFFSET(offset_address, "", "");
39624 +       offset_address += bb_reg_code_offset(dst);
39625 +       KDB_DEBUG_BB_OFFSET(offset_address, " osp", ") = ");
39626 +       KDB_DEBUG_BB("%s", bbrg_name[value]);
39627 +       if (value == BBRG_OSP)
39628 +               KDB_DEBUG_BB_OFFSET(offset_value, "", "");
39629 +       for (i = 0, c = bb_reg_state->memory;
39630 +            i < bb_reg_state_max;
39631 +            ++i, ++c) {
39632 +               if (c->offset_address == offset_address)
39633 +                       free = c;
39634 +               else if (c->value == BBRG_UNDEFINED && !free)
39635 +                       free = c;
39636 +       }
39637 +       if (!free) {
39638 +               struct bb_reg_state *new, *old = bb_reg_state;
39639 +               size_t old_size, new_size;
39640 +               int slot;
39641 +               old_size = sizeof(*old) + bb_reg_state_max *
39642 +                                 sizeof(old->memory[0]);
39643 +               slot = bb_reg_state_max;
39644 +               bb_reg_state_max += 5;
39645 +               new_size = sizeof(*new) + bb_reg_state_max *
39646 +                                 sizeof(new->memory[0]);
39647 +               new = debug_kmalloc(new_size, GFP_ATOMIC);
39648 +               if (!new) {
39649 +                       kdb_printf("\n\n%s: out of debug_kmalloc\n", __FUNCTION__);
39650 +                       bb_giveup = 1;
39651 +               } else {
39652 +                       memcpy(new, old, old_size);
39653 +                       memset((char *)new + old_size, BBRG_UNDEFINED,
39654 +                              new_size - old_size);
39655 +                       bb_reg_state = new;
39656 +                       debug_kfree(old);
39657 +                       free = bb_reg_state->memory + slot;
39658 +               }
39659 +       }
39660 +       if (free) {
39661 +               int slot = free - bb_reg_state->memory;
39662 +               free->offset_address = offset_address;
39663 +               free->value = value;
39664 +               free->offset_value = offset_value;
39665 +               KDB_DEBUG_BB(" slot %d", slot);
39666 +               bb_reg_state->mem_count = max(bb_reg_state->mem_count, slot+1);
39667 +       }
39668 +       KDB_DEBUG_BB("\n");
39669 +}
39670 +
39671 +/* Set memory location *('dst' + 'offset') to contain the value from register
39672 + * 'src'.  'dst' is assumed to be a register that contains a stack pointer.
39673 + * This differs from bb_memory_set_reg_value because it takes a src register
39674 + * which contains a value and possibly an offset, bb_memory_set_reg_value is
39675 + * passed the value and offset directly.
39676 + */
39677 +
39678 +static void
39679 +bb_memory_set_reg(enum bb_reg_code dst, enum bb_reg_code src,
39680 +                 short offset_address)
39681 +{
39682 +       int offset_value;
39683 +       enum bb_reg_code value;
39684 +       BB_CHECK(!bb_is_osp_defined(dst), dst, );
39685 +       if (!bb_is_int_reg(src))
39686 +               return;
39687 +       value = bb_reg_code_value(src);
39688 +       if (value == BBRG_UNDEFINED) {
39689 +               bb_delete_memory(offset_address + bb_reg_code_offset(dst));
39690 +               return;
39691 +       }
39692 +       offset_value = bb_reg_code_offset(src);
39693 +       bb_reg_read(src);
39694 +       bb_memory_set_reg_value(dst, offset_address, value, offset_value);
39695 +}
39696 +
39697 +/* Set register 'dst' to contain the value from memory *('src' + offset_address).
39698 + * 'src' is assumed to be a register that contains a stack pointer.
39699 + */
39700 +
39701 +static void
39702 +bb_reg_set_memory(enum bb_reg_code dst, enum bb_reg_code src, short offset_address)
39703 +{
39704 +       int i, defined = 0;
39705 +       struct bb_memory_contains *s;
39706 +       BB_CHECK(!bb_is_osp_defined(src), src, );
39707 +       KDB_DEBUG_BB("  %s = *(%s",
39708 +                    bbrg_name[dst], bbrg_name[src]);
39709 +       KDB_DEBUG_BB_OFFSET(offset_address, "", ")");
39710 +       offset_address += bb_reg_code_offset(src);
39711 +       KDB_DEBUG_BB_OFFSET(offset_address, " (osp", ")");
39712 +       for (i = 0, s = bb_reg_state->memory;
39713 +            i < bb_reg_state->mem_count;
39714 +            ++i, ++s) {
39715 +               if (s->offset_address == offset_address && bb_is_int_reg(dst)) {
39716 +                       bb_reg_code_set_value(dst, s->value);
39717 +                       KDB_DEBUG_BB(" value %s", bbrg_name[s->value]);
39718 +                       if (s->value == BBRG_OSP) {
39719 +                               bb_reg_code_set_offset(dst, s->offset_value);
39720 +                               KDB_DEBUG_BB_OFFSET(s->offset_value, "", "");
39721 +                       } else {
39722 +                               bb_reg_code_set_offset(dst, 0);
39723 +                       }
39724 +                       defined = 1;
39725 +               }
39726 +       }
39727 +       if (!defined)
39728 +               bb_reg_set_reg(dst, BBRG_UNDEFINED);
39729 +       else
39730 +               KDB_DEBUG_BB("\n");
39731 +}
39732 +
39733 +/* A generic read from an operand. */
39734 +
39735 +static void
39736 +bb_read_operand(const struct bb_operand *operand)
39737 +{
39738 +       int o = 0;
39739 +       if (operand->base_rc)
39740 +               bb_reg_read(operand->base_rc);
39741 +       if (operand->index_rc)
39742 +               bb_reg_read(operand->index_rc);
39743 +       if (bb_is_simple_memory(operand) &&
39744 +           bb_is_osp_defined(operand->base_rc) &&
39745 +           bb_decode.match->usage != BBOU_LEA) {
39746 +               o = (bb_reg_code_offset(operand->base_rc) + operand->disp +
39747 +                    KDB_WORD_SIZE - 1) / KDB_WORD_SIZE;
39748 +               bb_memory_params = max(bb_memory_params, o);
39749 +       }
39750 +}
39751 +
39752 +/* A generic write to an operand, resulting in an undefined value in that
39753 + * location.  All well defined operands are handled separately, this function
39754 + * only handles the opcodes where the result is undefined.
39755 + */
39756 +
39757 +static void
39758 +bb_write_operand(const struct bb_operand *operand)
39759 +{
39760 +       enum bb_reg_code base_rc = operand->base_rc;
39761 +       if (operand->memory) {
39762 +               if (base_rc)
39763 +                       bb_reg_read(base_rc);
39764 +               if (operand->index_rc)
39765 +                       bb_reg_read(operand->index_rc);
39766 +       } else if (operand->reg && base_rc) {
39767 +               bb_reg_set_undef(base_rc);
39768 +       }
39769 +       if (bb_is_simple_memory(operand) && bb_is_osp_defined(base_rc)) {
39770 +               int offset;
39771 +               offset = bb_reg_code_offset(base_rc) + operand->disp;
39772 +               offset = ALIGN(offset - KDB_WORD_SIZE + 1, KDB_WORD_SIZE);
39773 +               bb_delete_memory(offset);
39774 +       }
39775 +}
39776 +
39777 +/* Adjust a register that contains a stack pointer */
39778 +
39779 +static void
39780 +bb_adjust_osp(enum bb_reg_code reg, int adjust)
39781 +{
39782 +       int offset = bb_reg_code_offset(reg), old_offset = offset;
39783 +       KDB_DEBUG_BB("  %s osp offset ", bbrg_name[reg]);
39784 +       KDB_DEBUG_BB_OFFSET(bb_reg_code_offset(reg), "", " -> ");
39785 +       offset += adjust;
39786 +       bb_reg_code_set_offset(reg, offset);
39787 +       KDB_DEBUG_BB_OFFSET(bb_reg_code_offset(reg), "", "\n");
39788 +       /* When RSP is adjusted upwards, it invalidates any memory
39789 +        * stored between the old and current stack offsets.
39790 +        */
39791 +       if (reg == BBRG_RSP) {
39792 +               while (old_offset < bb_reg_code_offset(reg)) {
39793 +                       bb_delete_memory(old_offset);
39794 +                       old_offset += KDB_WORD_SIZE;
39795 +               }
39796 +       }
39797 +}
39798 +
39799 +/* The current instruction adjusts a register that contains a stack pointer.
39800 + * Direction is 1 or -1, depending on whether the instruction is add/lea or
39801 + * sub.
39802 + */
39803 +
39804 +static void
39805 +bb_adjust_osp_instruction(int direction)
39806 +{
39807 +       enum bb_reg_code dst_reg = bb_decode.dst.base_rc;
39808 +       if (bb_decode.src.immediate ||
39809 +           bb_decode.match->usage == BBOU_LEA /* lea has its own checks */) {
39810 +               int adjust = direction * bb_decode.src.disp;
39811 +               bb_adjust_osp(dst_reg, adjust);
39812 +       } else {
39813 +               /* variable stack adjustment, osp offset is not well defined */
39814 +               KDB_DEBUG_BB("  %s osp offset ", bbrg_name[dst_reg]);
39815 +               KDB_DEBUG_BB_OFFSET(bb_reg_code_offset(dst_reg), "", " -> undefined\n");
39816 +               bb_reg_code_set_value(dst_reg, BBRG_UNDEFINED);
39817 +               bb_reg_code_set_offset(dst_reg, 0);
39818 +       }
39819 +}
39820 +
39821 +/* Some instructions using memory have an explicit length suffix (b, w, l, q).
39822 + * The equivalent instructions using a register imply the length from the
39823 + * register name.  Deduce the operand length.
39824 + */
39825 +
39826 +static int
39827 +bb_operand_length(const struct bb_operand *operand, char opcode_suffix)
39828 +{
39829 +       int l = 0;
39830 +       switch (opcode_suffix) {
39831 +       case 'b':
39832 +               l = 8;
39833 +               break;
39834 +       case 'w':
39835 +               l = 16;
39836 +               break;
39837 +       case 'l':
39838 +               l = 32;
39839 +               break;
39840 +       case 'q':
39841 +               l = 64;
39842 +               break;
39843 +       }
39844 +       if (l == 0 && operand->reg) {
39845 +               switch (strlen(operand->base)) {
39846 +               case 3:
39847 +                       switch (operand->base[2]) {
39848 +                       case 'h':
39849 +                       case 'l':
39850 +                               l = 8;
39851 +                               break;
39852 +                       default:
39853 +                               l = 16;
39854 +                               break;
39855 +                       }
39856 +               case 4:
39857 +                       if (operand->base[1] == 'r')
39858 +                               l = 64;
39859 +                       else
39860 +                               l = 32;
39861 +                       break;
39862 +               }
39863 +       }
39864 +       return l;
39865 +}
39866 +
39867 +static int
39868 +bb_reg_state_size(const struct bb_reg_state *state)
39869 +{
39870 +       return sizeof(*state) +
39871 +              state->mem_count * sizeof(state->memory[0]);
39872 +}
39873 +
39874 +/* Canonicalize the current bb_reg_state so it can be compared against
39875 + * previously created states.  Sort the memory entries in descending order of
39876 + * offset_address (stack grows down).  Empty slots are moved to the end of the
39877 + * list and trimmed.
39878 + */
39879 +
39880 +static void
39881 +bb_reg_state_canonicalize(void)
39882 +{
39883 +       int i, o, changed;
39884 +       struct bb_memory_contains *p1, *p2, temp;
39885 +       do {
39886 +               changed = 0;
39887 +               for (i = 0, p1 = bb_reg_state->memory;
39888 +                    i < bb_reg_state->mem_count-1;
39889 +                    ++i, ++p1) {
39890 +                       p2 = p1 + 1;
39891 +                       if (p2->value == BBRG_UNDEFINED) {
39892 +                               o = 0;
39893 +                       } else if (p1->value == BBRG_UNDEFINED) {
39894 +                               o = 1;
39895 +                       } else if (p1->offset_address < p2->offset_address) {
39896 +                               o = 1;
39897 +                       } else if (p1->offset_address > p2->offset_address) {
39898 +                               o = -1;
39899 +                       } else {
39900 +                               o = 0;
39901 +                       }
39902 +                       if (o > 0) {
39903 +                               temp = *p2;
39904 +                               *p2 = *p1;
39905 +                               *p1 = temp;
39906 +                               changed = 1;
39907 +                       }
39908 +               }
39909 +       } while(changed);
39910 +       for (i = 0, p1 = bb_reg_state->memory;
39911 +            i < bb_reg_state_max;
39912 +            ++i, ++p1) {
39913 +               if (p1->value != BBRG_UNDEFINED)
39914 +                       bb_reg_state->mem_count = i + 1;
39915 +       }
39916 +       bb_reg_state_print(bb_reg_state);
39917 +}
39918 +
39919 +static int
39920 +bb_special_case(bfd_vma to)
39921 +{
39922 +       int i, j, rsp_offset, expect_offset, offset, errors = 0, max_errors = 40;
39923 +       enum bb_reg_code reg, expect_value, value;
39924 +       struct bb_name_state *r;
39925 +
39926 +       for (i = 0, r = bb_special_cases;
39927 +            i < ARRAY_SIZE(bb_special_cases);
39928 +            ++i, ++r) {
39929 +               if (to == r->address &&
39930 +                   (r->fname == NULL || strcmp(bb_func_name, r->fname) == 0))
39931 +                       goto match;
39932 +       }
39933 +       /* Some inline assembler code has jumps to .fixup sections which result
39934 +        * in out of line transfers with undefined state, ignore them.
39935 +        */
39936 +       if (strcmp(bb_func_name, "strnlen_user") == 0 ||
39937 +           strcmp(bb_func_name, "copy_from_user") == 0)
39938 +               return 1;
39939 +       return 0;
39940 +
39941 +match:
39942 +       /* Check the running registers match */
39943 +       for (reg = BBRG_RAX; reg < r->regs_size; ++reg) {
39944 +               expect_value = r->regs[reg].value;
39945 +               if (test_bit(expect_value, r->skip_regs.bits)) {
39946 +                       /* this regs entry is not defined for this label */
39947 +                       continue;
39948 +               }
39949 +               if (expect_value == BBRG_UNDEFINED)
39950 +                       continue;
39951 +               expect_offset = r->regs[reg].offset;
39952 +               value = bb_reg_code_value(reg);
39953 +               offset = bb_reg_code_offset(reg);
39954 +               if (expect_value == value &&
39955 +                   (value != BBRG_OSP || r->osp_offset == offset))
39956 +                       continue;
39957 +               kdb_printf("%s: Expected %s to contain %s",
39958 +                          __FUNCTION__,
39959 +                          bbrg_name[reg],
39960 +                          bbrg_name[expect_value]);
39961 +               if (r->osp_offset)
39962 +                       KDB_DEBUG_BB_OFFSET_PRINTF(r->osp_offset, "", "");
39963 +               kdb_printf(".  It actually contains %s", bbrg_name[value]);
39964 +               if (offset)
39965 +                       KDB_DEBUG_BB_OFFSET_PRINTF(offset, "", "");
39966 +               kdb_printf("\n");
39967 +               ++errors;
39968 +               if (max_errors-- == 0)
39969 +                       goto fail;
39970 +       }
39971 +       /* Check that any memory data on stack matches */
39972 +       i = j = 0;
39973 +       while (i < bb_reg_state->mem_count &&
39974 +              j < r->mem_size) {
39975 +               expect_value = r->mem[j].value;
39976 +               if (test_bit(expect_value, r->skip_mem.bits) ||
39977 +                   expect_value == BBRG_UNDEFINED) {
39978 +                       /* this memory slot is not defined for this label */
39979 +                       ++j;
39980 +                       continue;
39981 +               }
39982 +               rsp_offset = bb_reg_state->memory[i].offset_address -
39983 +                       bb_reg_code_offset(BBRG_RSP);
39984 +               if (rsp_offset >
39985 +                   r->mem[j].offset_address) {
39986 +                       /* extra slots in memory are OK */
39987 +                       ++i;
39988 +               } else if (rsp_offset <
39989 +                          r->mem[j].offset_address) {
39990 +                       /* Required memory slot is missing */
39991 +                       kdb_printf("%s: Invalid bb_reg_state.memory, "
39992 +                                  "missing memory entry[%d] %s\n",
39993 +                          __FUNCTION__, j, bbrg_name[expect_value]);
39994 +                       ++errors;
39995 +                       if (max_errors-- == 0)
39996 +                               goto fail;
39997 +                       ++j;
39998 +               } else {
39999 +                       if (bb_reg_state->memory[i].offset_value ||
40000 +                           bb_reg_state->memory[i].value != expect_value) {
40001 +                               /* memory slot is present but contains wrong
40002 +                                * value.
40003 +                                */
40004 +                               kdb_printf("%s: Invalid bb_reg_state.memory, "
40005 +                                           "wrong value in slot %d, "
40006 +                                           "should be %s, it is %s\n",
40007 +                                  __FUNCTION__, i,
40008 +                                  bbrg_name[expect_value],
40009 +                                  bbrg_name[bb_reg_state->memory[i].value]);
40010 +                               ++errors;
40011 +                               if (max_errors-- == 0)
40012 +                                       goto fail;
40013 +                       }
40014 +                       ++i;
40015 +                       ++j;
40016 +               }
40017 +       }
40018 +       while (j < r->mem_size) {
40019 +               expect_value = r->mem[j].value;
40020 +               if (test_bit(expect_value, r->skip_mem.bits) ||
40021 +                   expect_value == BBRG_UNDEFINED)
40022 +                       ++j;
40023 +               else
40024 +                       break;
40025 +       }
40026 +       if (j != r->mem_size) {
40027 +               /* Hit end of memory before testing all the pt_reg slots */
40028 +               kdb_printf("%s: Invalid bb_reg_state.memory, "
40029 +                           "missing trailing entries\n",
40030 +                  __FUNCTION__);
40031 +               ++errors;
40032 +               if (max_errors-- == 0)
40033 +                       goto fail;
40034 +       }
40035 +       if (errors)
40036 +               goto fail;
40037 +       return 1;
40038 +fail:
40039 +       kdb_printf("%s: on transfer to %s\n", __FUNCTION__, r->name);
40040 +       bb_giveup = 1;
40041 +       return 1;
40042 +}
40043 +
40044 +/* Transfer of control to a label outside the current function.  If the
40045 + * transfer is to a known common code path then do a sanity check on the state
40046 + * at this point.
40047 + */
40048 +
40049 +static void
40050 +bb_sanity_check(int type)
40051 +{
40052 +       enum bb_reg_code expect, actual;
40053 +       int i, offset, error = 0;
40054 +
40055 +       for (i = 0; i < ARRAY_SIZE(bb_preserved_reg); ++i) {
40056 +               expect = bb_preserved_reg[i];
40057 +               actual = bb_reg_code_value(expect);
40058 +               offset = bb_reg_code_offset(expect);
40059 +               if (expect == actual)
40060 +                       continue;
40061 +               /* type == 1 is sysret/sysexit, ignore RSP */
40062 +               if (type && expect == BBRG_RSP)
40063 +                       continue;
40064 +#ifndef        CONFIG_X86_64
40065 +               /* type == 1 is sysret/sysexit, ignore RBP for i386 */
40066 +               if (type && expect == BBRG_RBP)
40067 +                       continue;
40068 +#endif /* !CONFIG_X86_64 */
40069 +               /* RSP should contain OSP+0.  Except for ptregscall_common and
40070 +                * ia32_ptregs_common, they get a partial pt_regs, fudge the
40071 +                * stack to make it a full pt_regs then reverse the effect on
40072 +                * exit, so the offset is -0x50 on exit.
40073 +                */
40074 +               if (expect == BBRG_RSP &&
40075 +                   bb_is_osp_defined(expect) &&
40076 +                   (offset == 0 ||
40077 +                    (offset == -0x50 &&
40078 +                     (strcmp(bb_func_name, "ptregscall_common") == 0 ||
40079 +                      strcmp(bb_func_name, "ia32_ptregs_common") == 0))))
40080 +                       continue;
40081 +               kdb_printf("%s: Expected %s, got %s",
40082 +                          __FUNCTION__,
40083 +                          bbrg_name[expect], bbrg_name[actual]);
40084 +               if (offset)
40085 +                       KDB_DEBUG_BB_OFFSET_PRINTF(offset, "", "");
40086 +               kdb_printf("\n");
40087 +               error = 1;
40088 +       }
40089 +       BB_CHECK(error, error, );
40090 +}
40091 +
40092 +/* Transfer of control.  Follow the arc and save the current state as input to
40093 + * another basic block.
40094 + */
40095 +
40096 +static void
40097 +bb_transfer(bfd_vma from, bfd_vma to, unsigned int drop_through)
40098 +{
40099 +       int i, found;
40100 +       size_t size;
40101 +       struct bb* bb = NULL;   /*stupid gcc */
40102 +       struct bb_jmp *bb_jmp;
40103 +       struct bb_reg_state *state;
40104 +       bb_reg_state_canonicalize();
40105 +       found = 0;
40106 +       for (i = 0; i < bb_jmp_count; ++i) {
40107 +               bb_jmp = bb_jmp_list + i;
40108 +               if (bb_jmp->from == from &&
40109 +                   bb_jmp->to == to &&
40110 +                   bb_jmp->drop_through == drop_through) {
40111 +                       found = 1;
40112 +                       break;
40113 +               }
40114 +       }
40115 +       if (!found) {
40116 +               /* Transfer outside the current function.  Check the special
40117 +                * cases (mainly in entry.S) first.  If it is not a known
40118 +                * special case then check if the target address is the start
40119 +                * of a function or not.  If it is the start of a function then
40120 +                * assume tail recursion and require that the state be the same
40121 +                * as on entry.  Otherwise assume out of line code (e.g.
40122 +                * spinlock contention path) and ignore it, the state can be
40123 +                * anything.
40124 +                */
40125 +               kdb_symtab_t symtab;
40126 +               if (bb_special_case(to))
40127 +                       return;
40128 +               kdbnearsym(to, &symtab);
40129 +               if (symtab.sym_start != to)
40130 +                       return;
40131 +               bb_sanity_check(0);
40132 +               if (bb_giveup)
40133 +                       return;
40134 +#ifdef NO_SIBLINGS
40135 +               /* Only print this message when the kernel is compiled with
40136 +                * -fno-optimize-sibling-calls.  Otherwise it would print a
40137 +                * message for every tail recursion call.  If you see the
40138 +                * message below then you probably have an assembler label that
40139 +                * is not listed in the special cases.
40140 +                */
40141 +               kdb_printf("  not matched: from "
40142 +                          kdb_bfd_vma_fmt0
40143 +                          " to " kdb_bfd_vma_fmt0
40144 +                          " drop_through %d bb_jmp[%d]\n",
40145 +                          from, to, drop_through, i);
40146 +#endif /* NO_SIBLINGS */
40147 +               return;
40148 +       }
40149 +       KDB_DEBUG_BB("  matched: from " kdb_bfd_vma_fmt0
40150 +                    " to " kdb_bfd_vma_fmt0
40151 +                    " drop_through %d bb_jmp[%d]\n",
40152 +                    from, to, drop_through, i);
40153 +       found = 0;
40154 +       for (i = 0; i < bb_count; ++i) {
40155 +               bb = bb_list[i];
40156 +               if (bb->start == to) {
40157 +                       found = 1;
40158 +                       break;
40159 +               }
40160 +       }
40161 +       BB_CHECK(!found, to, );
40162 +       /* If the register state for this arc has already been set (we are
40163 +        * rescanning the block that originates the arc) and the state is the
40164 +        * same as the previous state for this arc then this input to the
40165 +        * target block is the same as last time, so there is no need to rescan
40166 +        * the target block.
40167 +        */
40168 +       state = bb_jmp->state;
40169 +       size = bb_reg_state_size(bb_reg_state);
40170 +       if (state) {
40171 +               bb_reg_state->ref_count = state->ref_count;
40172 +               if (memcmp(state, bb_reg_state, size) == 0) {
40173 +                       KDB_DEBUG_BB("  no state change\n");
40174 +                       return;
40175 +               }
40176 +               if (--state->ref_count == 0)
40177 +                       debug_kfree(state);
40178 +               bb_jmp->state = NULL;
40179 +       }
40180 +       /* New input state is required.  To save space, check if any other arcs
40181 +        * have the same state and reuse them where possible.  The overall set
40182 +        * of inputs to the target block is now different so the target block
40183 +        * must be rescanned.
40184 +        */
40185 +       bb->changed = 1;
40186 +       for (i = 0; i < bb_jmp_count; ++i) {
40187 +               state = bb_jmp_list[i].state;
40188 +               if (!state)
40189 +                       continue;
40190 +               bb_reg_state->ref_count = state->ref_count;
40191 +               if (memcmp(state, bb_reg_state, size) == 0) {
40192 +                       KDB_DEBUG_BB("  reuse bb_jmp[%d]\n", i);
40193 +                       bb_jmp->state = state;
40194 +                       ++state->ref_count;
40195 +                       return;
40196 +               }
40197 +       }
40198 +       state = debug_kmalloc(size, GFP_ATOMIC);
40199 +       if (!state) {
40200 +               kdb_printf("\n\n%s: out of debug_kmalloc\n", __FUNCTION__);
40201 +               bb_giveup = 1;
40202 +               return;
40203 +       }
40204 +       memcpy(state, bb_reg_state, size);
40205 +       state->ref_count = 1;
40206 +       bb_jmp->state = state;
40207 +       KDB_DEBUG_BB("  new state %p\n", state);
40208 +}
40209 +
40210 +/* Isolate the processing for 'mov' so it can be used for 'xadd'/'xchg' as
40211 + * well.
40212 + */
40213 +
40214 +static enum bb_operand_usage
40215 +bb_usage_mov(const struct bb_operand *src, const struct bb_operand *dst, int l)
40216 +{
40217 +       int full_register_src, full_register_dst;
40218 +       full_register_src = bb_operand_length(src, bb_decode.opcode[l])
40219 +                           == KDB_WORD_SIZE * 8;
40220 +       full_register_dst = bb_operand_length(dst, bb_decode.opcode[l])
40221 +                           == KDB_WORD_SIZE * 8;
40222 +       /* If both src and dst are full integer registers then record the
40223 +        * register change.
40224 +        */
40225 +       if (src->reg &&
40226 +           bb_is_int_reg(src->base_rc) &&
40227 +           dst->reg &&
40228 +           bb_is_int_reg(dst->base_rc) &&
40229 +           full_register_src &&
40230 +           full_register_dst) {
40231 +               bb_reg_set_reg(dst->base_rc, src->base_rc);
40232 +               return BBOU_NOP;
40233 +       }
40234 +       /* If the move is from a full integer register to stack then record it.
40235 +        */
40236 +       if (src->reg &&
40237 +           bb_is_simple_memory(dst) &&
40238 +           bb_is_osp_defined(dst->base_rc) &&
40239 +           full_register_src) {
40240 +               /* Ugly special case.  Initializing list heads on stack causes
40241 +                * false references to stack variables when the list head is
40242 +                * used.  Static code analysis cannot detect that the list head
40243 +                * has been changed by a previous execution loop and that a
40244 +                * basic block is only executed after the list head has been
40245 +                * changed.
40246 +                *
40247 +                * These false references can result in valid stack variables
40248 +                * being incorrectly cleared on some logic paths.  Ignore
40249 +                * stores to stack variables which point to themselves or to
40250 +                * the previous word so the list head initialization is not
40251 +                * recorded.
40252 +                */
40253 +               if (bb_is_osp_defined(src->base_rc)) {
40254 +                       int stack1 = bb_reg_code_offset(src->base_rc);
40255 +                       int stack2 = bb_reg_code_offset(dst->base_rc) +
40256 +                                    dst->disp;
40257 +                       if (stack1 == stack2 ||
40258 +                           stack1 == stack2 - KDB_WORD_SIZE)
40259 +                               return BBOU_NOP;
40260 +               }
40261 +               bb_memory_set_reg(dst->base_rc, src->base_rc, dst->disp);
40262 +               return BBOU_NOP;
40263 +       }
40264 +       /* If the move is from stack to a full integer register then record it.
40265 +        */
40266 +       if (bb_is_simple_memory(src) &&
40267 +           bb_is_osp_defined(src->base_rc) &&
40268 +           dst->reg &&
40269 +           bb_is_int_reg(dst->base_rc) &&
40270 +           full_register_dst) {
40271 +#ifndef        CONFIG_X86_64
40272 +               /* mov from TSS_sysenter_esp0+offset to esp to fix up the
40273 +                * sysenter stack, it leaves esp well defined.  mov
40274 +                * TSS_sysenter_esp0+offset(%esp),%esp is followed by up to 5
40275 +                * push instructions to mimic the hardware stack push.  If
40276 +                * TSS_sysenter_esp0 is offset then only 3 words will be
40277 +                * pushed.
40278 +                */
40279 +               if (dst->base_rc == BBRG_RSP &&
40280 +                   src->disp >= TSS_sysenter_esp0 &&
40281 +                   bb_is_osp_defined(BBRG_RSP)) {
40282 +                       int pushes;
40283 +                       pushes = src->disp == TSS_sysenter_esp0 ? 5 : 3;
40284 +                       bb_reg_code_set_offset(BBRG_RSP,
40285 +                               bb_reg_code_offset(BBRG_RSP) +
40286 +                                       pushes * KDB_WORD_SIZE);
40287 +                       KDB_DEBUG_BB_OFFSET(
40288 +                               bb_reg_code_offset(BBRG_RSP),
40289 +                               "  sysenter fixup, RSP",
40290 +                              "\n");
40291 +                       return BBOU_NOP;
40292 +               }
40293 +#endif /* !CONFIG_X86_64 */
40294 +               bb_read_operand(src);
40295 +               bb_reg_set_memory(dst->base_rc, src->base_rc, src->disp);
40296 +               return BBOU_NOP;
40297 +       }
40298 +       /* move %gs:0x<nn>,%rsp is used to unconditionally switch to another
40299 +        * stack.  Ignore this special case, it is handled by the stack
40300 +        * unwinding code.
40301 +        */
40302 +       if (src->segment &&
40303 +           strcmp(src->segment, "%gs") == 0 &&
40304 +           dst->reg &&
40305 +           dst->base_rc == BBRG_RSP)
40306 +               return BBOU_NOP;
40307 +       /* move %reg,%reg is a nop */
40308 +       if (src->reg &&
40309 +           dst->reg &&
40310 +           !src->segment &&
40311 +           !dst->segment &&
40312 +           strcmp(src->base, dst->base) == 0)
40313 +               return BBOU_NOP;
40314 +       /* Special case for the code that switches stacks in the scheduler
40315 +        * (switch_to()).  That code must modify RSP but it does it in a well
40316 +        * defined manner.  Do not invalidate RSP.
40317 +        */
40318 +       if (dst->reg &&
40319 +           dst->base_rc == BBRG_RSP &&
40320 +           full_register_dst &&
40321 +           bb_is_scheduler_address())
40322 +               return BBOU_RS;
40323 +       return BBOU_RSWD;
40324 +}
40325 +
40326 +static enum bb_operand_usage
40327 +bb_usage_xadd(const struct bb_operand *src, const struct bb_operand *dst)
40328 +{
40329 +       /* Simulate xadd as a series of instructions including mov, that way we
40330 +        * get the benefit of all the special cases already handled by
40331 +        * BBOU_MOV.
40332 +        *
40333 +        * tmp = src + dst, src = dst, dst = tmp.
40334 +        *
40335 +        * For tmp, pick a register that is undefined.  If all registers are
40336 +        * defined then pick one that is not being used by xadd.
40337 +        */
40338 +       enum bb_reg_code reg = BBRG_UNDEFINED;
40339 +       struct bb_operand tmp;
40340 +       struct bb_reg_contains save_tmp;
40341 +       enum bb_operand_usage usage;
40342 +       int undefined = 0;
40343 +       for (reg = BBRG_RAX; reg < BBRG_RAX + KDB_INT_REGISTERS; ++reg) {
40344 +               if (bb_reg_code_value(reg) == BBRG_UNDEFINED) {
40345 +                       undefined = 1;
40346 +                       break;
40347 +               }
40348 +       }
40349 +       if (!undefined) {
40350 +               for (reg = BBRG_RAX; reg < BBRG_RAX + KDB_INT_REGISTERS; ++reg) {
40351 +                       if (reg != src->base_rc &&
40352 +                           reg != src->index_rc &&
40353 +                           reg != dst->base_rc &&
40354 +                           reg != dst->index_rc &&
40355 +                           reg != BBRG_RSP)
40356 +                               break;
40357 +               }
40358 +       }
40359 +       KDB_DEBUG_BB("  %s saving tmp %s\n", __FUNCTION__, bbrg_name[reg]);
40360 +       save_tmp = bb_reg_state->contains[reg - BBRG_RAX];
40361 +       bb_reg_set_undef(reg);
40362 +       memset(&tmp, 0, sizeof(tmp));
40363 +       tmp.present = 1;
40364 +       tmp.reg = 1;
40365 +       tmp.base = (char *)bbrg_name[reg];
40366 +       tmp.base_rc = reg;
40367 +       bb_read_operand(src);
40368 +       bb_read_operand(dst);
40369 +       if (bb_usage_mov(src, dst, sizeof("xadd")-1) == BBOU_NOP)
40370 +               usage = BBOU_RSRD;
40371 +       else
40372 +               usage = BBOU_RSRDWS;
40373 +       bb_usage_mov(&tmp, dst, sizeof("xadd")-1);
40374 +       KDB_DEBUG_BB("  %s restoring tmp %s\n", __FUNCTION__, bbrg_name[reg]);
40375 +       bb_reg_state->contains[reg - BBRG_RAX] = save_tmp;
40376 +       return usage;
40377 +}
40378 +
40379 +static enum bb_operand_usage
40380 +bb_usage_xchg(const struct bb_operand *src, const struct bb_operand *dst)
40381 +{
40382 +       /* Simulate xchg as a series of mov instructions, that way we get the
40383 +        * benefit of all the special cases already handled by BBOU_MOV.
40384 +        *
40385 +        * mov dst,tmp; mov src,dst; mov tmp,src;
40386 +        *
40387 +        * For tmp, pick a register that is undefined.  If all registers are
40388 +        * defined then pick one that is not being used by xchg.
40389 +        */
40390 +       enum bb_reg_code reg = BBRG_UNDEFINED;
40391 +       int rs = BBOU_RS, rd = BBOU_RD, ws = BBOU_WS, wd = BBOU_WD;
40392 +       struct bb_operand tmp;
40393 +       struct bb_reg_contains save_tmp;
40394 +       int undefined = 0;
40395 +       for (reg = BBRG_RAX; reg < BBRG_RAX + KDB_INT_REGISTERS; ++reg) {
40396 +               if (bb_reg_code_value(reg) == BBRG_UNDEFINED) {
40397 +                       undefined = 1;
40398 +                       break;
40399 +               }
40400 +       }
40401 +       if (!undefined) {
40402 +               for (reg = BBRG_RAX; reg < BBRG_RAX + KDB_INT_REGISTERS; ++reg) {
40403 +                       if (reg != src->base_rc &&
40404 +                           reg != src->index_rc &&
40405 +                           reg != dst->base_rc &&
40406 +                           reg != dst->index_rc &&
40407 +                           reg != BBRG_RSP)
40408 +                               break;
40409 +               }
40410 +       }
40411 +       KDB_DEBUG_BB("  %s saving tmp %s\n", __FUNCTION__, bbrg_name[reg]);
40412 +       save_tmp = bb_reg_state->contains[reg - BBRG_RAX];
40413 +       memset(&tmp, 0, sizeof(tmp));
40414 +       tmp.present = 1;
40415 +       tmp.reg = 1;
40416 +       tmp.base = (char *)bbrg_name[reg];
40417 +       tmp.base_rc = reg;
40418 +       if (bb_usage_mov(dst, &tmp, sizeof("xchg")-1) == BBOU_NOP)
40419 +               rd = 0;
40420 +       if (bb_usage_mov(src, dst, sizeof("xchg")-1) == BBOU_NOP) {
40421 +               rs = 0;
40422 +               wd = 0;
40423 +       }
40424 +       if (bb_usage_mov(&tmp, src, sizeof("xchg")-1) == BBOU_NOP)
40425 +               ws = 0;
40426 +       KDB_DEBUG_BB("  %s restoring tmp %s\n", __FUNCTION__, bbrg_name[reg]);
40427 +       bb_reg_state->contains[reg - BBRG_RAX] = save_tmp;
40428 +       return rs | rd | ws | wd;
40429 +}
40430 +
40431 +/* Invalidate all the scratch registers */
40432 +
40433 +static void
40434 +bb_invalidate_scratch_reg(void)
40435 +{
40436 +       int i, j;
40437 +       for (i = BBRG_RAX; i < BBRG_RAX + KDB_INT_REGISTERS; ++i) {
40438 +               for (j = 0; j < ARRAY_SIZE(bb_preserved_reg); ++j) {
40439 +                       if (i == bb_preserved_reg[j])
40440 +                               goto preserved;
40441 +               }
40442 +               bb_reg_set_undef(i);
40443 +preserved:
40444 +               continue;
40445 +       }
40446 +}
40447 +
40448 +
40449 +static void
40450 +bb_pass2_computed_jmp(const struct bb_operand *src)
40451 +{
40452 +       unsigned long table = src->disp;
40453 +       kdb_machreg_t addr;
40454 +       while (!bb_giveup) {
40455 +               if (kdb_getword(&addr, table, sizeof(addr)))
40456 +                       return;
40457 +               if (addr < bb_func_start || addr >= bb_func_end)
40458 +                       return;
40459 +               bb_transfer(bb_curr_addr, addr, 0);
40460 +               table += KDB_WORD_SIZE;
40461 +       }
40462 +}
40463 +
40464 +/* The current instruction has been decoded and all the information is in
40465 + * bb_decode.  Based on the opcode, track any operand usage that we care about.
40466 + */
40467 +
40468 +static void
40469 +bb_usage(void)
40470 +{
40471 +       enum bb_operand_usage usage = bb_decode.match->usage;
40472 +       struct bb_operand *src = &bb_decode.src;
40473 +       struct bb_operand *dst = &bb_decode.dst;
40474 +       struct bb_operand *dst2 = &bb_decode.dst2;
40475 +       int opcode_suffix, operand_length;
40476 +
40477 +       /* First handle all the special usage cases, and map them to a generic
40478 +        * case after catering for the side effects.
40479 +        */
40480 +
40481 +       if (usage == BBOU_IMUL &&
40482 +           src->present && !dst->present && !dst2->present) {
40483 +               /* single operand imul, same effects as mul */
40484 +               usage = BBOU_MUL;
40485 +       }
40486 +
40487 +       /* AT&T syntax uses movs<l1><l2> for move with sign extension, instead
40488 +        * of the Intel movsx.  The AT&T syntax causes problems for the opcode
40489 +        * mapping; movs with sign extension needs to be treated as a generic
40490 +        * read src, write dst, but instead it falls under the movs I/O
40491 +        * instruction.  Fix it.
40492 +        */
40493 +       if (usage == BBOU_MOVS && strlen(bb_decode.opcode) > 5)
40494 +               usage = BBOU_RSWD;
40495 +
40496 +       /* This switch statement deliberately does not use 'default' at the top
40497 +        * level.  That way the compiler will complain if a new BBOU_ enum is
40498 +        * added above and not explicitly handled here.
40499 +        */
40500 +       switch (usage) {
40501 +       case BBOU_UNKNOWN:      /* drop through */
40502 +       case BBOU_RS:           /* drop through */
40503 +       case BBOU_RD:           /* drop through */
40504 +       case BBOU_RSRD:         /* drop through */
40505 +       case BBOU_WS:           /* drop through */
40506 +       case BBOU_RSWS:         /* drop through */
40507 +       case BBOU_RDWS:         /* drop through */
40508 +       case BBOU_RSRDWS:       /* drop through */
40509 +       case BBOU_WD:           /* drop through */
40510 +       case BBOU_RSWD:         /* drop through */
40511 +       case BBOU_RDWD:         /* drop through */
40512 +       case BBOU_RSRDWD:       /* drop through */
40513 +       case BBOU_WSWD:         /* drop through */
40514 +       case BBOU_RSWSWD:       /* drop through */
40515 +       case BBOU_RDWSWD:       /* drop through */
40516 +       case BBOU_RSRDWSWD:
40517 +               break;          /* ignore generic usage for now */
40518 +       case BBOU_ADD:
40519 +               /* Special case for add instructions that adjust registers
40520 +                * which are mapping the stack.
40521 +                */
40522 +               if (dst->reg && bb_is_osp_defined(dst->base_rc)) {
40523 +                       bb_adjust_osp_instruction(1);
40524 +                       usage = BBOU_RS;
40525 +               } else {
40526 +                       usage = BBOU_RSRDWD;
40527 +               }
40528 +               break;
40529 +       case BBOU_CALL:
40530 +               /* Invalidate the scratch registers.  Functions sync_regs and
40531 +                * save_v86_state are special, their return value is the new
40532 +                * stack pointer.
40533 +                */
40534 +               bb_reg_state_print(bb_reg_state);
40535 +               bb_invalidate_scratch_reg();
40536 +               if (bb_is_static_disp(src)) {
40537 +                       if (src->disp == bb_sync_regs) {
40538 +                               bb_reg_set_reg(BBRG_RAX, BBRG_RSP);
40539 +                       } else if (src->disp == bb_save_v86_state) {
40540 +                               bb_reg_set_reg(BBRG_RAX, BBRG_RSP);
40541 +                               bb_adjust_osp(BBRG_RAX, +KDB_WORD_SIZE);
40542 +                       }
40543 +               }
40544 +               usage = BBOU_NOP;
40545 +               break;
40546 +       case BBOU_CBW:
40547 +               /* Convert word in RAX.  Read RAX, write RAX */
40548 +               bb_reg_read(BBRG_RAX);
40549 +               bb_reg_set_undef(BBRG_RAX);
40550 +               usage = BBOU_NOP;
40551 +               break;
40552 +       case BBOU_CMOV:
40553 +               /* cmove %gs:0x<nn>,%rsp is used to conditionally switch to
40554 +                * another stack.  Ignore this special case, it is handled by
40555 +                * the stack unwinding code.
40556 +                */
40557 +               if (src->segment &&
40558 +                   strcmp(src->segment, "%gs") == 0 &&
40559 +                   dst->reg &&
40560 +                   dst->base_rc == BBRG_RSP)
40561 +                       usage = BBOU_NOP;
40562 +               else
40563 +                       usage = BBOU_RSWD;
40564 +               break;
40565 +       case BBOU_CMPXCHG:
40566 +               /* Read RAX, write RAX plus src read, dst write */
40567 +               bb_reg_read(BBRG_RAX);
40568 +               bb_reg_set_undef(BBRG_RAX);
40569 +               usage = BBOU_RSWD;
40570 +               break;
40571 +       case BBOU_CMPXCHGD:
40572 +               /* Read RAX, RBX, RCX, RDX, write RAX, RDX plus src read/write */
40573 +               bb_reg_read(BBRG_RAX);
40574 +               bb_reg_read(BBRG_RBX);
40575 +               bb_reg_read(BBRG_RCX);
40576 +               bb_reg_read(BBRG_RDX);
40577 +               bb_reg_set_undef(BBRG_RAX);
40578 +               bb_reg_set_undef(BBRG_RDX);
40579 +               usage = BBOU_RSWS;
40580 +               break;
40581 +       case BBOU_CPUID:
40582 +               /* Read RAX, write RAX, RBX, RCX, RDX */
40583 +               bb_reg_read(BBRG_RAX);
40584 +               bb_reg_set_undef(BBRG_RAX);
40585 +               bb_reg_set_undef(BBRG_RBX);
40586 +               bb_reg_set_undef(BBRG_RCX);
40587 +               bb_reg_set_undef(BBRG_RDX);
40588 +               usage = BBOU_NOP;
40589 +               break;
40590 +       case BBOU_CWD:
40591 +               /* Convert word in RAX, RDX.  Read RAX, write RDX */
40592 +               bb_reg_read(BBRG_RAX);
40593 +               bb_reg_set_undef(BBRG_RDX);
40594 +               usage = BBOU_NOP;
40595 +               break;
40596 +       case BBOU_DIV:  /* drop through */
40597 +       case BBOU_IDIV:
40598 +               /* The 8 bit variants only affect RAX, the 16, 32 and 64 bit
40599 +                * variants affect RDX as well.
40600 +                */
40601 +               switch (usage) {
40602 +               case BBOU_DIV:
40603 +                       opcode_suffix = bb_decode.opcode[3];
40604 +                       break;
40605 +               case BBOU_IDIV:
40606 +                       opcode_suffix = bb_decode.opcode[4];
40607 +                       break;
40608 +               default:
40609 +                       opcode_suffix = 'q';
40610 +                       break;
40611 +               }
40612 +               operand_length = bb_operand_length(src, opcode_suffix);
40613 +               bb_reg_read(BBRG_RAX);
40614 +               bb_reg_set_undef(BBRG_RAX);
40615 +               if (operand_length != 8) {
40616 +                       bb_reg_read(BBRG_RDX);
40617 +                       bb_reg_set_undef(BBRG_RDX);
40618 +               }
40619 +               usage = BBOU_RS;
40620 +               break;
40621 +       case BBOU_IMUL:
40622 +               /* Only the two and three operand forms get here.  The one
40623 +                * operand form is treated as mul.
40624 +                */
40625 +               if (dst2->present) {
40626 +                       /* The three operand form is a special case, read the first two
40627 +                        * operands, write the third.
40628 +                        */
40629 +                       bb_read_operand(src);
40630 +                       bb_read_operand(dst);
40631 +                       bb_write_operand(dst2);
40632 +                       usage = BBOU_NOP;
40633 +               } else {
40634 +                       usage = BBOU_RSRDWD;
40635 +               }
40636 +               break;
40637 +       case BBOU_IRET:
40638 +               bb_sanity_check(0);
40639 +               usage = BBOU_NOP;
40640 +               break;
40641 +       case BBOU_JMP:
40642 +               if (bb_is_static_disp(src))
40643 +                       bb_transfer(bb_curr_addr, src->disp, 0);
40644 +               else if (src->indirect &&
40645 +                        src->disp &&
40646 +                        src->base == NULL &&
40647 +                        src->index &&
40648 +                        src->scale == KDB_WORD_SIZE)
40649 +                       bb_pass2_computed_jmp(src);
40650 +               usage = BBOU_RS;
40651 +               break;
40652 +       case BBOU_LAHF:
40653 +               /* Write RAX */
40654 +               bb_reg_set_undef(BBRG_RAX);
40655 +               usage = BBOU_NOP;
40656 +               break;
40657 +       case BBOU_LEA:
40658 +               /* dst = src + disp.  Often used to calculate offsets into the
40659 +                * stack, so check if it uses a stack pointer.
40660 +                */
40661 +               usage = BBOU_RSWD;
40662 +               if (bb_is_simple_memory(src)) {
40663 +                      if (bb_is_osp_defined(src->base_rc)) {
40664 +                               bb_reg_set_reg(dst->base_rc, src->base_rc);
40665 +                               bb_adjust_osp_instruction(1);
40666 +                               usage = BBOU_RS;
40667 +                       } else if (src->disp == 0 &&
40668 +                                  src->base_rc == dst->base_rc) {
40669 +                               /* lea 0(%reg),%reg is generated by i386
40670 +                                * GENERIC_NOP7.
40671 +                                */
40672 +                               usage = BBOU_NOP;
40673 +                       }
40674 +               }
40675 +               break;
40676 +       case BBOU_LEAVE:
40677 +               /* RSP = RBP; RBP = *(RSP); RSP += KDB_WORD_SIZE; */
40678 +               bb_reg_set_reg(BBRG_RSP, BBRG_RBP);
40679 +               if (bb_is_osp_defined(BBRG_RSP))
40680 +                       bb_reg_set_memory(BBRG_RBP, BBRG_RSP, 0);
40681 +               else
40682 +                       bb_reg_set_undef(BBRG_RBP);
40683 +               if (bb_is_osp_defined(BBRG_RSP))
40684 +                       bb_adjust_osp(BBRG_RSP, KDB_WORD_SIZE);
40685 +               /* common_interrupt uses leave in a non-standard manner */
40686 +               if (strcmp(bb_func_name, "common_interrupt") != 0)
40687 +                       bb_sanity_check(0);
40688 +               usage = BBOU_NOP;
40689 +               break;
40690 +       case BBOU_LODS:
40691 +               /* Read RSI, write RAX, RSI */
40692 +               bb_reg_read(BBRG_RSI);
40693 +               bb_reg_set_undef(BBRG_RAX);
40694 +               bb_reg_set_undef(BBRG_RSI);
40695 +               usage = BBOU_NOP;
40696 +               break;
40697 +       case BBOU_LOOP:
40698 +               /* Read and write RCX */
40699 +               bb_reg_read(BBRG_RCX);
40700 +               bb_reg_set_undef(BBRG_RCX);
40701 +               if (bb_is_static_disp(src))
40702 +                       bb_transfer(bb_curr_addr, src->disp, 0);
40703 +               usage = BBOU_NOP;
40704 +               break;
40705 +       case BBOU_LSS:
40706 +               /* lss offset(%esp),%esp leaves esp well defined */
40707 +               if (dst->reg &&
40708 +                   dst->base_rc == BBRG_RSP &&
40709 +                   bb_is_simple_memory(src) &&
40710 +                   src->base_rc == BBRG_RSP) {
40711 +                       bb_adjust_osp(BBRG_RSP, 2*KDB_WORD_SIZE + src->disp);
40712 +                       usage = BBOU_NOP;
40713 +               } else {
40714 +                       usage = BBOU_RSWD;
40715 +               }
40716 +               break;
40717 +       case BBOU_MONITOR:
40718 +               /* Read RAX, RCX, RDX */
40719 +               bb_reg_set_undef(BBRG_RAX);
40720 +               bb_reg_set_undef(BBRG_RCX);
40721 +               bb_reg_set_undef(BBRG_RDX);
40722 +               usage = BBOU_NOP;
40723 +               break;
40724 +       case BBOU_MOV:
40725 +               usage = bb_usage_mov(src, dst, sizeof("mov")-1);
40726 +               break;
40727 +       case BBOU_MOVS:
40728 +               /* Read RSI, RDI, write RSI, RDI */
40729 +               bb_reg_read(BBRG_RSI);
40730 +               bb_reg_read(BBRG_RDI);
40731 +               bb_reg_set_undef(BBRG_RSI);
40732 +               bb_reg_set_undef(BBRG_RDI);
40733 +               usage = BBOU_NOP;
40734 +               break;
40735 +       case BBOU_MUL:
40736 +               /* imul (one operand form only) or mul.  Read RAX.  If the
40737 +                * operand length is not 8 then write RDX.
40738 +                */
40739 +               if (bb_decode.opcode[0] == 'i')
40740 +                       opcode_suffix = bb_decode.opcode[4];
40741 +               else
40742 +                       opcode_suffix = bb_decode.opcode[3];
40743 +               operand_length = bb_operand_length(src, opcode_suffix);
40744 +               bb_reg_read(BBRG_RAX);
40745 +               if (operand_length != 8)
40746 +                       bb_reg_set_undef(BBRG_RDX);
40747 +               usage = BBOU_NOP;
40748 +               break;
40749 +       case BBOU_MWAIT:
40750 +               /* Read RAX, RCX */
40751 +               bb_reg_read(BBRG_RAX);
40752 +               bb_reg_read(BBRG_RCX);
40753 +               usage = BBOU_NOP;
40754 +               break;
40755 +       case BBOU_NOP:
40756 +               break;
40757 +       case BBOU_OUTS:
40758 +               /* Read RSI, RDX, write RSI */
40759 +               bb_reg_read(BBRG_RSI);
40760 +               bb_reg_read(BBRG_RDX);
40761 +               bb_reg_set_undef(BBRG_RSI);
40762 +               usage = BBOU_NOP;
40763 +               break;
40764 +       case BBOU_POP:
40765 +               /* Complicated by the fact that you can pop from top of stack
40766 +                * to a stack location, for this case the destination location
40767 +                * is calculated after adjusting RSP.  Analysis of the kernel
40768 +                * code shows that gcc only uses this strange format to get the
40769 +                * flags into a local variable, e.g. pushf; popl 0x10(%esp); so
40770 +                * I am going to ignore this special case.
40771 +                */
40772 +               usage = BBOU_WS;
40773 +               if (!bb_is_osp_defined(BBRG_RSP)) {
40774 +                       if (!bb_is_scheduler_address()) {
40775 +                               kdb_printf("pop when BBRG_RSP is undefined?\n");
40776 +                               bb_giveup = 1;
40777 +                       }
40778 +               } else {
40779 +                       if (src->reg) {
40780 +                               bb_reg_set_memory(src->base_rc, BBRG_RSP, 0);
40781 +                               usage = BBOU_NOP;
40782 +                       }
40783 +                       bb_adjust_osp(BBRG_RSP, KDB_WORD_SIZE);
40784 +               }
40785 +               break;
40786 +       case BBOU_POPF:
40787 +               /* Do not care about flags, just adjust RSP */
40788 +               if (!bb_is_osp_defined(BBRG_RSP)) {
40789 +                       if (!bb_is_scheduler_address()) {
40790 +                               kdb_printf("popf when BBRG_RSP is undefined?\n");
40791 +                               bb_giveup = 1;
40792 +                       }
40793 +               } else {
40794 +                       bb_adjust_osp(BBRG_RSP, KDB_WORD_SIZE);
40795 +               }
40796 +               usage = BBOU_WS;
40797 +               break;
40798 +       case BBOU_PUSH:
40799 +               /* Complicated by the fact that you can push from a stack
40800 +                * location to top of stack, the source location is calculated
40801 +                * before adjusting RSP.  Analysis of the kernel code shows
40802 +                * that gcc only uses this strange format to restore the flags
40803 +                * from a local variable, e.g. pushl 0x10(%esp); popf; so I am
40804 +                * going to ignore this special case.
40805 +                */
40806 +               usage = BBOU_RS;
40807 +               if (!bb_is_osp_defined(BBRG_RSP)) {
40808 +                       if (!bb_is_scheduler_address()) {
40809 +                               kdb_printf("push when BBRG_RSP is undefined?\n");
40810 +                               bb_giveup = 1;
40811 +                       }
40812 +               } else {
40813 +                       bb_adjust_osp(BBRG_RSP, -KDB_WORD_SIZE);
40814 +                       if (src->reg &&
40815 +                           bb_reg_code_offset(BBRG_RSP) <= 0)
40816 +                               bb_memory_set_reg(BBRG_RSP, src->base_rc, 0);
40817 +               }
40818 +               break;
40819 +       case BBOU_PUSHF:
40820 +               /* Do not care about flags, just adjust RSP */
40821 +               if (!bb_is_osp_defined(BBRG_RSP)) {
40822 +                       if (!bb_is_scheduler_address()) {
40823 +                               kdb_printf("pushf when BBRG_RSP is undefined?\n");
40824 +                               bb_giveup = 1;
40825 +                       }
40826 +               } else {
40827 +                       bb_adjust_osp(BBRG_RSP, -KDB_WORD_SIZE);
40828 +               }
40829 +               usage = BBOU_WS;
40830 +               break;
40831 +       case BBOU_RDMSR:
40832 +               /* Read RCX, write RAX, RDX */
40833 +               bb_reg_read(BBRG_RCX);
40834 +               bb_reg_set_undef(BBRG_RAX);
40835 +               bb_reg_set_undef(BBRG_RDX);
40836 +               usage = BBOU_NOP;
40837 +               break;
40838 +       case BBOU_RDTSC:
40839 +               /* Write RAX, RDX */
40840 +               bb_reg_set_undef(BBRG_RAX);
40841 +               bb_reg_set_undef(BBRG_RDX);
40842 +               usage = BBOU_NOP;
40843 +               break;
40844 +       case BBOU_RET:
40845 +               bb_sanity_check(0);
40846 +               usage = BBOU_NOP;
40847 +               break;
40848 +       case BBOU_SAHF:
40849 +               /* Read RAX */
40850 +               bb_reg_read(BBRG_RAX);
40851 +               usage = BBOU_NOP;
40852 +               break;
40853 +       case BBOU_SCAS:
40854 +               /* Read RAX, RDI, write RDI */
40855 +               bb_reg_read(BBRG_RAX);
40856 +               bb_reg_read(BBRG_RDI);
40857 +               bb_reg_set_undef(BBRG_RDI);
40858 +               usage = BBOU_NOP;
40859 +               break;
40860 +       case BBOU_SUB:
40861 +               /* Special case for sub instructions that adjust registers
40862 +                * which are mapping the stack.
40863 +                */
40864 +               if (dst->reg && bb_is_osp_defined(dst->base_rc)) {
40865 +                       bb_adjust_osp_instruction(-1);
40866 +                       usage = BBOU_RS;
40867 +               } else {
40868 +                       usage = BBOU_RSRDWD;
40869 +               }
40870 +               break;
40871 +       case BBOU_SYSEXIT:
40872 +               bb_sanity_check(1);
40873 +               usage = BBOU_NOP;
40874 +               break;
40875 +       case BBOU_SYSRET:
40876 +               bb_sanity_check(1);
40877 +               usage = BBOU_NOP;
40878 +               break;
40879 +       case BBOU_WRMSR:
40880 +               /* Read RCX, RAX, RDX */
40881 +               bb_reg_read(BBRG_RCX);
40882 +               bb_reg_read(BBRG_RAX);
40883 +               bb_reg_read(BBRG_RDX);
40884 +               usage = BBOU_NOP;
40885 +               break;
40886 +       case BBOU_XADD:
40887 +               usage = bb_usage_xadd(src, dst);
40888 +               break;
40889 +       case BBOU_XCHG:
40890 +               /* i386 do_IRQ with 4K stacks does xchg %ebx,%esp; call
40891 +                * irq_handler; mov %ebx,%esp; to switch stacks.  Ignore this
40892 +                * stack switch when tracking registers, it is handled by
40893 +                * higher level backtrace code.  Convert xchg %ebx,%esp to mov
40894 +                * %esp,%ebx so the later mov %ebx,%esp becomes a NOP and the
40895 +                * stack remains defined so we can backtrace through do_IRQ's
40896 +                * stack switch.
40897 +                */
40898 +               if (src->reg &&
40899 +                   dst->reg &&
40900 +                   src->base_rc == BBRG_RBX &&
40901 +                   dst->base_rc == BBRG_RSP &&
40902 +                   strcmp(bb_func_name, "do_IRQ") == 0) {
40903 +                       strcpy(bb_decode.opcode, "mov");
40904 +                       usage = bb_usage_mov(dst, src, sizeof("mov")-1);
40905 +               } else {
40906 +                       usage = bb_usage_xchg(src, dst);
40907 +               }
40908 +               break;
40909 +       case BBOU_XOR:
40910 +               /* xor %reg,%reg only counts as a register write, the original
40911 +                * contents of reg are irrelevant.
40912 +                */
40913 +               if (src->reg && dst->reg && src->base_rc == dst->base_rc)
40914 +                       usage = BBOU_WS;
40915 +               else
40916 +                       usage = BBOU_RSRDWD;
40917 +               break;
40918 +       }
40919 +
40920 +       /* The switch statement above handled all the special cases.  Every
40921 +        * opcode should now have a usage of NOP or one of the generic cases.
40922 +        */
40923 +       if (usage == BBOU_UNKNOWN || usage == BBOU_NOP) {
40924 +               /* nothing to do */
40925 +       } else if (usage >= BBOU_RS && usage <= BBOU_RSRDWSWD) {
40926 +               if (usage & BBOU_RS)
40927 +                       bb_read_operand(src);
40928 +               if (usage & BBOU_RD)
40929 +                       bb_read_operand(dst);
40930 +               if (usage & BBOU_WS)
40931 +                       bb_write_operand(src);
40932 +               if (usage & BBOU_WD)
40933 +                       bb_write_operand(dst);
40934 +       } else {
40935 +               kdb_printf("%s: opcode not fully handled\n", __FUNCTION__);
40936 +               if (!KDB_DEBUG(BB)) {
40937 +                       bb_print_opcode();
40938 +                       if (bb_decode.src.present)
40939 +                               bb_print_operand("src", &bb_decode.src);
40940 +                       if (bb_decode.dst.present)
40941 +                               bb_print_operand("dst", &bb_decode.dst);
40942 +                       if (bb_decode.dst2.present)
40943 +                               bb_print_operand("dst2", &bb_decode.dst2);
40944 +               }
40945 +               bb_giveup = 1;
40946 +       }
40947 +}
40948 +
40949 +static void
40950 +bb_parse_buffer(void)
40951 +{
40952 +       char *p, *src, *dst = NULL, *dst2 = NULL;
40953 +       int paren = 0;
40954 +       p = bb_buffer;
40955 +       memset(&bb_decode, 0, sizeof(bb_decode));
40956 +       KDB_DEBUG_BB(" '%s'\n", p);
40957 +       p += strcspn(p, ":");   /* skip address and function name+offset: */
40958 +       if (*p++ != ':') {
40959 +               kdb_printf("%s: cannot find ':' in buffer '%s'\n",
40960 +                          __FUNCTION__, bb_buffer);
40961 +               bb_giveup = 1;
40962 +               return;
40963 +       }
40964 +       p += strspn(p, " \t");  /* step to opcode */
40965 +       if (strncmp(p, "(bad)", 5) == 0)
40966 +               strcpy(p, "nop");
40967 +       /* separate any opcode prefix */
40968 +       if (strncmp(p, "lock", 4) == 0 ||
40969 +           strncmp(p, "rep", 3) == 0 ||
40970 +           strncmp(p, "rex", 3) == 0 ||
40971 +           strncmp(p, "addr", 4) == 0) {
40972 +               bb_decode.prefix = p;
40973 +               p += strcspn(p, " \t");
40974 +               *p++ = '\0';
40975 +               p += strspn(p, " \t");
40976 +       }
40977 +       bb_decode.opcode = p;
40978 +       strsep(&p, " \t");      /* step to end of opcode */
40979 +       if (bb_parse_opcode())
40980 +               return;
40981 +       if (!p)
40982 +               goto no_operands;
40983 +       p += strspn(p, " \t");  /* step to operand(s) */
40984 +       if (!*p)
40985 +               goto no_operands;
40986 +       src = p;
40987 +       p = strsep(&p, " \t");  /* strip comments after operands */
40988 +       /* split 'src','dst' but ignore ',' inside '(' ')' */
40989 +       while (*p) {
40990 +               if (*p == '(') {
40991 +                       ++paren;
40992 +               } else if (*p == ')') {
40993 +                       --paren;
40994 +               } else if (*p == ',' && paren == 0) {
40995 +                       *p = '\0';
40996 +                       if (dst)
40997 +                               dst2 = p+1;
40998 +                       else
40999 +                               dst = p+1;
41000 +               }
41001 +               ++p;
41002 +       }
41003 +       bb_parse_operand(src, &bb_decode.src);
41004 +       if (KDB_DEBUG(BB))
41005 +               bb_print_operand("src", &bb_decode.src);
41006 +       if (dst && !bb_giveup) {
41007 +               bb_parse_operand(dst, &bb_decode.dst);
41008 +               if (KDB_DEBUG(BB))
41009 +                       bb_print_operand("dst", &bb_decode.dst);
41010 +       }
41011 +       if (dst2 && !bb_giveup) {
41012 +               bb_parse_operand(dst2, &bb_decode.dst2);
41013 +               if (KDB_DEBUG(BB))
41014 +                       bb_print_operand("dst2", &bb_decode.dst2);
41015 +       }
41016 +no_operands:
41017 +       if (!bb_giveup)
41018 +               bb_usage();
41019 +}
41020 +
41021 +static int
41022 +bb_dis_pass2(PTR file, const char *fmt, ...)
41023 +{
41024 +       char *p;
41025 +       int l = strlen(bb_buffer);
41026 +       va_list ap;
41027 +       va_start(ap, fmt);
41028 +       vsnprintf(bb_buffer + l, sizeof(bb_buffer) - l, fmt, ap);
41029 +       va_end(ap);
41030 +       if ((p = strchr(bb_buffer, '\n'))) {
41031 +               *p = '\0';
41032 +               p = bb_buffer;
41033 +               p += strcspn(p, ":");
41034 +               if (*p++ == ':')
41035 +                       bb_fixup_switch_to(p);
41036 +               bb_parse_buffer();
41037 +               bb_buffer[0] = '\0';
41038 +       }
41039 +       return 0;
41040 +}
41041 +
41042 +static void
41043 +bb_printaddr_pass2(bfd_vma addr, disassemble_info *dip)
41044 +{
41045 +       kdb_symtab_t symtab;
41046 +       unsigned int offset;
41047 +       dip->fprintf_func(dip->stream, "0x%lx", addr);
41048 +       kdbnearsym(addr, &symtab);
41049 +       if (symtab.sym_name) {
41050 +               dip->fprintf_func(dip->stream, " <%s", symtab.sym_name);
41051 +               if ((offset = addr - symtab.sym_start))
41052 +                       dip->fprintf_func(dip->stream, "+0x%x", offset);
41053 +               dip->fprintf_func(dip->stream, ">");
41054 +       }
41055 +}
41056 +
41057 +/* Set the starting register and memory state for the current bb */
41058 +
41059 +static void
41060 +bb_start_block0_special(void)
41061 +{
41062 +       int i;
41063 +       short offset_address;
41064 +       enum bb_reg_code reg, value;
41065 +       struct bb_name_state *r;
41066 +       for (i = 0, r = bb_special_cases;
41067 +            i < ARRAY_SIZE(bb_special_cases);
41068 +            ++i, ++r) {
41069 +               if (bb_func_start == r->address && r->fname == NULL)
41070 +                       goto match;
41071 +       }
41072 +       return;
41073 +match:
41074 +       /* Set the running registers */
41075 +       for (reg = BBRG_RAX; reg < r->regs_size; ++reg) {
41076 +               value = r->regs[reg].value;
41077 +               if (test_bit(value, r->skip_regs.bits)) {
41078 +                       /* this regs entry is not defined for this label */
41079 +                       continue;
41080 +               }
41081 +               bb_reg_code_set_value(reg, value);
41082 +               bb_reg_code_set_offset(reg, r->regs[reg].offset);
41083 +       }
41084 +       /* Set any memory contents, e.g. pt_regs.  Adjust RSP as required. */
41085 +       offset_address = 0;
41086 +       for (i = 0; i < r->mem_size; ++i) {
41087 +               offset_address = max_t(int,
41088 +                               r->mem[i].offset_address + KDB_WORD_SIZE,
41089 +                               offset_address);
41090 +       }
41091 +       if (bb_reg_code_offset(BBRG_RSP) > -offset_address)
41092 +               bb_adjust_osp(BBRG_RSP, -offset_address - bb_reg_code_offset(BBRG_RSP));
41093 +       for (i = 0; i < r->mem_size; ++i) {
41094 +               value = r->mem[i].value;
41095 +               if (test_bit(value, r->skip_mem.bits)) {
41096 +                       /* this memory entry is not defined for this label */
41097 +                       continue;
41098 +               }
41099 +               bb_memory_set_reg_value(BBRG_RSP, r->mem[i].offset_address,
41100 +                                       value, 0);
41101 +               bb_reg_set_undef(value);
41102 +       }
41103 +       return;
41104 +}
41105 +
41106 +static void
41107 +bb_pass2_start_block(int number)
41108 +{
41109 +       int i, j, k, first, changed;
41110 +       size_t size;
41111 +       struct bb_jmp *bb_jmp;
41112 +       struct bb_reg_state *state;
41113 +       struct bb_memory_contains *c1, *c2;
41114 +       bb_reg_state->mem_count = bb_reg_state_max;
41115 +       size = bb_reg_state_size(bb_reg_state);
41116 +       memset(bb_reg_state, 0, size);
41117 +
41118 +       if (number == 0) {
41119 +               /* The first block is assumed to have well defined inputs */
41120 +               bb_start_block0();
41121 +               /* Some assembler labels have non-standard entry
41122 +                * states.
41123 +                */
41124 +               bb_start_block0_special();
41125 +               bb_reg_state_print(bb_reg_state);
41126 +               return;
41127 +       }
41128 +
41129 +       /* Merge all the input states for the current bb together */
41130 +       first = 1;
41131 +       changed = 0;
41132 +       for (i = 0; i < bb_jmp_count; ++i) {
41133 +               bb_jmp = bb_jmp_list + i;
41134 +               if (bb_jmp->to != bb_curr->start)
41135 +                       continue;
41136 +               state = bb_jmp->state;
41137 +               if (!state)
41138 +                       continue;
41139 +               if (first) {
41140 +                       size = bb_reg_state_size(state);
41141 +                       memcpy(bb_reg_state, state, size);
41142 +                       KDB_DEBUG_BB("  first state %p\n", state);
41143 +                       bb_reg_state_print(bb_reg_state);
41144 +                       first = 0;
41145 +                       continue;
41146 +               }
41147 +
41148 +               KDB_DEBUG_BB("  merging state %p\n", state);
41149 +               /* Merge the register states */
41150 +               for (j = 0; j < ARRAY_SIZE(state->contains); ++j) {
41151 +                       if (memcmp(bb_reg_state->contains + j,
41152 +                                  state->contains + j,
41153 +                                  sizeof(bb_reg_state->contains[0]))) {
41154 +                               /* Different states for this register from two
41155 +                                * or more inputs, make it undefined.
41156 +                                */
41157 +                               if (bb_reg_state->contains[j].value !=
41158 +                                   BBRG_UNDEFINED) {
41159 +                                       bb_reg_set_undef(BBRG_RAX + j);
41160 +                                       changed = 1;
41161 +                               }
41162 +                       }
41163 +               }
41164 +
41165 +               /* Merge the memory states.  This relies on both
41166 +                * bb_reg_state->memory and state->memory being sorted in
41167 +                * descending order, with undefined entries at the end.
41168 +                */
41169 +               c1 = bb_reg_state->memory;
41170 +               c2 = state->memory;
41171 +               j = k = 0;
41172 +               while (j < bb_reg_state->mem_count &&
41173 +                      k < state->mem_count) {
41174 +                       if (c1->offset_address < c2->offset_address) {
41175 +                               KDB_DEBUG_BB_OFFSET(c2->offset_address,
41176 +                                                   "  ignoring c2->offset_address ",
41177 +                                                   "\n");
41178 +                               ++c2;
41179 +                               ++k;
41180 +                               continue;
41181 +                       }
41182 +                       if (c1->offset_address > c2->offset_address) {
41183 +                               /* Memory location is not in all input states,
41184 +                                * delete the memory location.
41185 +                                */
41186 +                               bb_delete_memory(c1->offset_address);
41187 +                               changed = 1;
41188 +                               ++c1;
41189 +                               ++j;
41190 +                               continue;
41191 +                       }
41192 +                       if (memcmp(c1, c2, sizeof(*c1))) {
41193 +                               /* Same location, different contents, delete
41194 +                                * the memory location.
41195 +                                */
41196 +                               bb_delete_memory(c1->offset_address);
41197 +                               KDB_DEBUG_BB_OFFSET(c2->offset_address,
41198 +                                                   "  ignoring c2->offset_address ",
41199 +                                                   "\n");
41200 +                               changed = 1;
41201 +                       }
41202 +                       ++c1;
41203 +                       ++c2;
41204 +                       ++j;
41205 +                       ++k;
41206 +               }
41207 +               while (j < bb_reg_state->mem_count) {
41208 +                       bb_delete_memory(c1->offset_address);
41209 +                       changed = 1;
41210 +                       ++c1;
41211 +                       ++j;
41212 +               }
41213 +       }
41214 +       if (changed) {
41215 +               KDB_DEBUG_BB("  final state\n");
41216 +               bb_reg_state_print(bb_reg_state);
41217 +       }
41218 +}
41219 +
41220 +/* We have reached the exit point from the current function, either a call to
41221 + * the next function or the instruction that was about to executed when an
41222 + * interrupt occurred.  Save the current register state in bb_exit_state.
41223 + */
41224 +
41225 +static void
41226 +bb_save_exit_state(void)
41227 +{
41228 +       size_t size;
41229 +       debug_kfree(bb_exit_state);
41230 +       bb_exit_state = NULL;
41231 +       bb_reg_state_canonicalize();
41232 +       size = bb_reg_state_size(bb_reg_state);
41233 +       bb_exit_state = debug_kmalloc(size, GFP_ATOMIC);
41234 +       if (!bb_exit_state) {
41235 +               kdb_printf("\n\n%s: out of debug_kmalloc\n", __FUNCTION__);
41236 +               bb_giveup = 1;
41237 +               return;
41238 +       }
41239 +       memcpy(bb_exit_state, bb_reg_state, size);
41240 +}
41241 +
41242 +static int
41243 +bb_pass2_do_changed_blocks(int allow_missing)
41244 +{
41245 +       int i, j, missing, changed, maxloops;
41246 +       unsigned long addr;
41247 +       struct bb_jmp *bb_jmp;
41248 +       KDB_DEBUG_BB("\n  %s: allow_missing %d\n", __FUNCTION__, allow_missing);
41249 +       /* Absolute worst case is we have to iterate over all the basic blocks,
41250 +        * each iteration losing one register or memory state.  Any more loops
41251 +        * than that is a bug.
41252 +        */
41253 +       maxloops = KDB_INT_REGISTERS + bb_reg_state_max;
41254 +       changed = 1;
41255 +       do {
41256 +               changed = 0;
41257 +               for (i = 0; i < bb_count; ++i) {
41258 +                       bb_curr = bb_list[i];
41259 +                       if (!bb_curr->changed)
41260 +                               continue;
41261 +                       missing = 0;
41262 +                       for (j = 0, bb_jmp = bb_jmp_list;
41263 +                            j < bb_jmp_count;
41264 +                            ++j, ++bb_jmp) {
41265 +                               if (bb_jmp->to == bb_curr->start &&
41266 +                                   !bb_jmp->state)
41267 +                                       ++missing;
41268 +                       }
41269 +                       if (missing > allow_missing)
41270 +                               continue;
41271 +                       bb_curr->changed = 0;
41272 +                       changed = 1;
41273 +                       KDB_DEBUG_BB("\n  bb[%d]\n", i);
41274 +                       bb_pass2_start_block(i);
41275 +                       for (addr = bb_curr->start;
41276 +                            addr <= bb_curr->end; ) {
41277 +                               bb_curr_addr = addr;
41278 +                               if (addr == bb_exit_addr)
41279 +                                       bb_save_exit_state();
41280 +                               addr += kdba_id_printinsn(addr, &kdb_di);
41281 +                               kdb_di.fprintf_func(NULL, "\n");
41282 +                               if (bb_giveup)
41283 +                                       goto done;
41284 +                       }
41285 +                       if (addr == bb_exit_addr)
41286 +                               bb_save_exit_state();
41287 +                       if (bb_curr->drop_through)
41288 +                               bb_transfer(bb_curr->end,
41289 +                                           bb_list[i+1]->start, 1);
41290 +               }
41291 +               if (maxloops-- == 0) {
41292 +                       kdb_printf("\n\n%s maxloops reached\n",
41293 +                                  __FUNCTION__);
41294 +                       bb_giveup = 1;
41295 +                       goto done;
41296 +               }
41297 +       } while(changed);
41298 +done:
41299 +       for (i = 0; i < bb_count; ++i) {
41300 +               bb_curr = bb_list[i];
41301 +               if (bb_curr->changed)
41302 +                       return 1;       /* more to do, increase allow_missing */
41303 +       }
41304 +       return 0;       /* all blocks done */
41305 +}
41306 +
41307 +/* Assume that the current function is a pass through function that does not
41308 + * refer to its register parameters.  Exclude known asmlinkage functions and
41309 + * assume the other functions actually use their registers.
41310 + */
41311 +
41312 +static void
41313 +bb_assume_pass_through(void)
41314 +{
41315 +       static int first_time = 1;
41316 +       if (strncmp(bb_func_name, "sys_", 4) == 0 ||
41317 +           strncmp(bb_func_name, "compat_sys_", 11) == 0 ||
41318 +           strcmp(bb_func_name, "schedule") == 0 ||
41319 +           strcmp(bb_func_name, "do_softirq") == 0 ||
41320 +           strcmp(bb_func_name, "printk") == 0 ||
41321 +           strcmp(bb_func_name, "vprintk") == 0 ||
41322 +           strcmp(bb_func_name, "preempt_schedule") == 0 ||
41323 +           strcmp(bb_func_name, "start_kernel") == 0 ||
41324 +           strcmp(bb_func_name, "csum_partial") == 0 ||
41325 +           strcmp(bb_func_name, "csum_partial_copy_generic") == 0 ||
41326 +           strcmp(bb_func_name, "math_state_restore") == 0 ||
41327 +           strcmp(bb_func_name, "panic") == 0 ||
41328 +           strcmp(bb_func_name, "kdb_printf") == 0 ||
41329 +           strcmp(bb_func_name, "kdb_interrupt") == 0)
41330 +               return;
41331 +       if (bb_asmlinkage_arch())
41332 +               return;
41333 +       bb_reg_params = REGPARM;
41334 +       if (first_time) {
41335 +               kdb_printf("  %s has memory parameters but no register "
41336 +                          "parameters.\n  Assuming it is a 'pass "
41337 +                          "through' function that does not refer to "
41338 +                          "its register\n  parameters and setting %d "
41339 +                          "register parameters\n",
41340 +                          bb_func_name, REGPARM);
41341 +               first_time = 0;
41342 +               return;
41343 +       }
41344 +       kdb_printf("  Assuming %s is 'pass through' with %d register "
41345 +                  "parameters\n",
41346 +                  bb_func_name, REGPARM);
41347 +}
41348 +
41349 +static void
41350 +bb_pass2(void)
41351 +{
41352 +       int allow_missing;
41353 +       if (KDB_DEBUG(BB) | KDB_DEBUG(BB_SUMM))
41354 +               kdb_printf("%s: start\n", __FUNCTION__);
41355 +
41356 +       kdb_di.fprintf_func = bb_dis_pass2;
41357 +       kdb_di.print_address_func = bb_printaddr_pass2;
41358 +
41359 +       bb_reg_state = debug_kmalloc(sizeof(*bb_reg_state), GFP_ATOMIC);
41360 +       if (!bb_reg_state) {
41361 +               kdb_printf("\n\n%s: out of debug_kmalloc\n", __FUNCTION__);
41362 +               bb_giveup = 1;
41363 +               return;
41364 +       }
41365 +       bb_list[0]->changed = 1;
41366 +
41367 +       /* If a block does not have all its input states available then it is
41368 +        * possible for a register to initially appear to hold a known value,
41369 +        * but when other inputs are available then it becomes a variable
41370 +        * value.  The initial false state of "known" can generate false values
41371 +        * for other registers and can even make it look like stack locations
41372 +        * are being changed.
41373 +        *
41374 +        * To avoid these false positives, only process blocks which have all
41375 +        * their inputs defined.  That gives a clean depth first traversal of
41376 +        * the tree, except for loops.  If there are any loops, then start
41377 +        * processing blocks with one missing input, then two missing inputs
41378 +        * etc.
41379 +        *
41380 +        * Absolute worst case is we have to iterate over all the jmp entries,
41381 +        * each iteration allowing one more missing input.  Any more loops than
41382 +        * that is a bug.  Watch out for the corner case of 0 jmp entries.
41383 +        */
41384 +       for (allow_missing = 0; allow_missing <= bb_jmp_count; ++allow_missing) {
41385 +               if (!bb_pass2_do_changed_blocks(allow_missing))
41386 +                       break;
41387 +               if (bb_giveup)
41388 +                       break;
41389 +       }
41390 +       if (allow_missing > bb_jmp_count) {
41391 +               kdb_printf("\n\n%s maxloops reached\n",
41392 +                          __FUNCTION__);
41393 +               bb_giveup = 1;
41394 +               return;
41395 +       }
41396 +
41397 +       if (bb_memory_params && bb_reg_params)
41398 +               bb_reg_params = REGPARM;
41399 +       if (REGPARM &&
41400 +           bb_memory_params &&
41401 +           !bb_reg_params)
41402 +               bb_assume_pass_through();
41403 +       if (KDB_DEBUG(BB) | KDB_DEBUG(BB_SUMM)) {
41404 +               kdb_printf("%s: end bb_reg_params %d bb_memory_params %d\n",
41405 +                          __FUNCTION__, bb_reg_params, bb_memory_params);
41406 +               if (bb_exit_state) {
41407 +                       kdb_printf("%s: bb_exit_state at " kdb_bfd_vma_fmt0 "\n",
41408 +                                  __FUNCTION__, bb_exit_addr);
41409 +                       bb_do_reg_state_print(bb_exit_state);
41410 +               }
41411 +       }
41412 +}
41413 +
41414 +static void
41415 +bb_cleanup(void)
41416 +{
41417 +       int i;
41418 +       struct bb* bb;
41419 +       struct bb_reg_state *state;
41420 +       while (bb_count) {
41421 +               bb = bb_list[0];
41422 +               bb_delete(0);
41423 +       }
41424 +       debug_kfree(bb_list);
41425 +       bb_list = NULL;
41426 +       bb_count = bb_max = 0;
41427 +       for (i = 0; i < bb_jmp_count; ++i) {
41428 +               state = bb_jmp_list[i].state;
41429 +               if (state && --state->ref_count == 0)
41430 +                       debug_kfree(state);
41431 +       }
41432 +       debug_kfree(bb_jmp_list);
41433 +       bb_jmp_list = NULL;
41434 +       bb_jmp_count = bb_jmp_max = 0;
41435 +       debug_kfree(bb_reg_state);
41436 +       bb_reg_state = NULL;
41437 +       bb_reg_state_max = 0;
41438 +       debug_kfree(bb_exit_state);
41439 +       bb_exit_state = NULL;
41440 +       bb_reg_params = bb_memory_params = 0;
41441 +       bb_giveup = 0;
41442 +}
41443 +
41444 +static int
41445 +bb_spurious_global_label(const char *func_name)
41446 +{
41447 +       int i;
41448 +       for (i = 0; i < ARRAY_SIZE(bb_spurious); ++i) {
41449 +               if (strcmp(bb_spurious[i], func_name) == 0)
41450 +                       return 1;
41451 +       }
41452 +       return 0;
41453 +}
41454 +
41455 +/* Given the current actual register contents plus the exit state deduced from
41456 + * a basic block analysis of the current function, rollback the actual register
41457 + * contents to the values they had on entry to this function.
41458 + */
41459 +
41460 +static void
41461 +bb_actual_rollback(const struct kdb_activation_record *ar)
41462 +{
41463 +       int i, offset_address;
41464 +       struct bb_memory_contains *c;
41465 +       enum bb_reg_code reg;
41466 +       unsigned long address, new_rsp = 0;
41467 +       struct bb_actual new[ARRAY_SIZE(bb_actual)];
41468 +
41469 +
41470 +       if (!bb_exit_state) {
41471 +               kdb_printf("%s: no bb_exit_state, cannot rollback\n",
41472 +                          __FUNCTION__);
41473 +               bb_giveup = 1;
41474 +               return;
41475 +       }
41476 +       memcpy(bb_reg_state, bb_exit_state, bb_reg_state_size(bb_exit_state));
41477 +       memset(new, 0, sizeof(new));
41478 +
41479 +       /* The most important register for obtaining saved state is rsp so get
41480 +        * its new value first.  Prefer rsp if it is valid, then other
41481 +        * registers.  Saved values of rsp in memory are unusable without a
41482 +        * register that points to memory.
41483 +        */
41484 +       if (!bb_actual_valid(BBRG_RSP)) {
41485 +               kdb_printf("%s: no starting value for RSP, cannot rollback\n",
41486 +                          __FUNCTION__);
41487 +               bb_giveup = 1;
41488 +               return;
41489 +       }
41490 +       if (KDB_DEBUG(BB) | KDB_DEBUG(BB_SUMM))
41491 +               kdb_printf("%s: rsp " kdb_bfd_vma_fmt0,
41492 +                          __FUNCTION__, bb_actual_value(BBRG_RSP));
41493 +       i = BBRG_RSP;
41494 +       if (!bb_is_osp_defined(i)) {
41495 +               for (i = BBRG_RAX; i < BBRG_RAX + KDB_INT_REGISTERS; ++i) {
41496 +                       if (bb_is_osp_defined(i) && bb_actual_valid(i))
41497 +                               break;
41498 +               }
41499 +       }
41500 +       if (bb_is_osp_defined(i) && bb_actual_valid(i)) {
41501 +               new_rsp = new[BBRG_RSP - BBRG_RAX].value =
41502 +                       bb_actual_value(i) - bb_reg_code_offset(i);
41503 +               new[BBRG_RSP - BBRG_RAX].valid = 1;
41504 +               if (KDB_DEBUG(BB) | KDB_DEBUG(BB_SUMM))
41505 +                       kdb_printf(" -> " kdb_bfd_vma_fmt0 "\n", new_rsp);
41506 +       } else {
41507 +               bb_actual_set_valid(BBRG_RSP, 0);
41508 +               if (KDB_DEBUG(BB) | KDB_DEBUG(BB_SUMM))
41509 +                       kdb_printf(" -> undefined\n");
41510 +               kdb_printf("%s: no ending value for RSP, cannot rollback\n",
41511 +                          __FUNCTION__);
41512 +               bb_giveup = 1;
41513 +               return;
41514 +       }
41515 +
41516 +       /* Now the other registers.  First look at register values that have
41517 +        * been copied to other registers.
41518 +        */
41519 +       for (i = BBRG_RAX; i < BBRG_RAX + KDB_INT_REGISTERS; ++i) {
41520 +               reg = bb_reg_code_value(i);
41521 +               if (bb_is_int_reg(reg)) {
41522 +                       new[reg - BBRG_RAX] = bb_actual[i - BBRG_RAX];
41523 +                       if (KDB_DEBUG(BB) | KDB_DEBUG(BB_SUMM))
41524 +                               kdb_printf("%s: %s is in %s, "
41525 +                                           kdb_bfd_vma_fmt0 "\n",
41526 +                                           __FUNCTION__,
41527 +                                           bbrg_name[reg],
41528 +                                           bbrg_name[i],
41529 +                                           bb_actual_value(reg));
41530 +               }
41531 +       }
41532 +
41533 +       /* Finally register values that have been saved on stack */
41534 +       for (i = 0, c = bb_reg_state->memory;
41535 +            i < bb_reg_state->mem_count;
41536 +            ++i, ++c) {
41537 +               offset_address = c->offset_address;
41538 +               reg = c->value;
41539 +               if (!bb_is_int_reg(reg))
41540 +                       continue;
41541 +               address = new_rsp + offset_address;
41542 +               if (address < ar->stack.logical_start ||
41543 +                   address >= ar->stack.logical_end) {
41544 +                       new[reg - BBRG_RAX].value = 0;
41545 +                       new[reg - BBRG_RAX].valid = 0;
41546 +                       if (KDB_DEBUG(BB) | KDB_DEBUG(BB_SUMM))
41547 +                               kdb_printf("%s: %s -> undefined\n",
41548 +                                          __FUNCTION__,
41549 +                                          bbrg_name[reg]);
41550 +               } else {
41551 +                       new[reg - BBRG_RAX].value = *(bfd_vma *)address;
41552 +                       new[reg - BBRG_RAX].valid = 1;
41553 +                       if (KDB_DEBUG(BB) | KDB_DEBUG(BB_SUMM))
41554 +                               kdb_printf("%s: %s -> " kdb_bfd_vma_fmt0 "\n",
41555 +                                          __FUNCTION__,
41556 +                                          bbrg_name[reg],
41557 +                                          new[reg - BBRG_RAX].value);
41558 +               }
41559 +       }
41560 +
41561 +       memcpy(bb_actual, new, sizeof(bb_actual));
41562 +}
41563 +
41564 +/* Return the number of bytes pushed on stack by the hardware.  Either 0 or the
41565 + * size of the hardware specific data.
41566 + *
41567 + */
41568 +
41569 +static int
41570 +bb_hardware_pushed(kdb_machreg_t rip)
41571 +{
41572 +       unsigned long disp8, disp32, target, addr = (unsigned long)rip;
41573 +       unsigned char code[5];
41574 +       int i;
41575 +
41576 +       for (i = 0; i < ARRAY_SIZE(bb_hardware_handlers); ++i)
41577 +               if (strcmp(bb_func_name, bb_hardware_handlers[i]) == 0)
41578 +                       return HARDWARE_PUSHED;
41579 +
41580 +       /* Given the large number of interrupt handlers, it is easiest to look
41581 +        * at the next instruction and see if it is a jmp to the common exit
41582 +        * routines.
41583 +        */
41584 +       if (kdb_getarea(code, addr) ||
41585 +           kdb_getword(&disp32, addr+1, 4) ||
41586 +           kdb_getword(&disp8, addr+1, 1))
41587 +               return 0;       /* not a valid code address */
41588 +       if (code[0] == 0xe9) {
41589 +               target = addr + (s32) disp32 + 5;       /* jmp disp32 */
41590 +               if (target == bb_ret_from_intr ||
41591 +                   target == bb_common_interrupt ||
41592 +                   target == bb_error_entry)
41593 +                       return HARDWARE_PUSHED;
41594 +       }
41595 +       if (code[0] == 0xeb) {
41596 +               target = addr + (s8) disp8 + 2;         /* jmp disp8 */
41597 +               if (target == bb_ret_from_intr ||
41598 +                   target == bb_common_interrupt ||
41599 +                   target == bb_error_entry)
41600 +                       return HARDWARE_PUSHED;
41601 +       }
41602 +       if (strcmp(bb_func_name, "kdb_call") == 0)
41603 +               return HARDWARE_PUSHED;
41604 +
41605 +       return 0;
41606 +}
41607 +
41608 +/* Copy argument information that was deduced by the basic block analysis and
41609 + * rollback into the kdb stack activation record.
41610 + */
41611 +
41612 +static void
41613 +bb_arguments(struct kdb_activation_record *ar)
41614 +{
41615 +       int i;
41616 +       enum bb_reg_code reg;
41617 +       kdb_machreg_t rsp;
41618 +       ar->args = bb_reg_params + bb_memory_params;
41619 +       bitmap_zero(ar->valid.bits, KDBA_MAXARGS);
41620 +       for (i = 0; i < bb_reg_params; ++i) {
41621 +               reg = bb_param_reg[i];
41622 +               if (bb_actual_valid(reg)) {
41623 +                       ar->arg[i] = bb_actual_value(reg);
41624 +                       set_bit(i, ar->valid.bits);
41625 +               }
41626 +       }
41627 +       if (!bb_actual_valid(BBRG_RSP))
41628 +               return;
41629 +       rsp = bb_actual_value(BBRG_RSP);
41630 +       for (i = bb_reg_params; i < ar->args; ++i) {
41631 +               rsp += KDB_WORD_SIZE;
41632 +               if (kdb_getarea(ar->arg[i], rsp) == 0)
41633 +                       set_bit(i, ar->valid.bits);
41634 +       }
41635 +}
41636 +
41637 +/* Given an exit address from a function, decompose the entire function into
41638 + * basic blocks and determine the register state at the exit point.
41639 + */
41640 +
41641 +static void
41642 +kdb_bb(unsigned long exit)
41643 +{
41644 +       kdb_symtab_t symtab;
41645 +       if (!kdbnearsym(exit, &symtab)) {
41646 +               kdb_printf("%s: address " kdb_bfd_vma_fmt0 " not recognised\n",
41647 +                          __FUNCTION__, exit);
41648 +               bb_giveup = 1;
41649 +               return;
41650 +       }
41651 +       bb_exit_addr = exit;
41652 +       bb_mod_name = symtab.mod_name;
41653 +       bb_func_name = symtab.sym_name;
41654 +       bb_func_start = symtab.sym_start;
41655 +       bb_func_end = symtab.sym_end;
41656 +       /* Various global labels exist in the middle of assembler code and have
41657 +        * a non-standard state.  Ignore these labels and use the start of the
41658 +        * previous label instead.
41659 +        */
41660 +       while (bb_spurious_global_label(symtab.sym_name)) {
41661 +               if (!kdbnearsym(symtab.sym_start - 1, &symtab))
41662 +                       break;
41663 +               bb_func_start = symtab.sym_start;
41664 +       }
41665 +       bb_mod_name = symtab.mod_name;
41666 +       bb_func_name = symtab.sym_name;
41667 +       bb_func_start = symtab.sym_start;
41668 +       /* Ignore spurious labels past this point and use the next non-spurious
41669 +        * label as the end point.
41670 +        */
41671 +       if (kdbnearsym(bb_func_end, &symtab)) {
41672 +               while (bb_spurious_global_label(symtab.sym_name)) {
41673 +                       bb_func_end = symtab.sym_end;
41674 +                       if (!kdbnearsym(symtab.sym_end + 1, &symtab))
41675 +                               break;
41676 +               }
41677 +       }
41678 +       bb_pass1();
41679 +       if (!bb_giveup)
41680 +               bb_pass2();
41681 +       if (bb_giveup)
41682 +               kdb_printf("%s: " kdb_bfd_vma_fmt0
41683 +                          " [%s]%s failed at " kdb_bfd_vma_fmt0 "\n\n",
41684 +                          __FUNCTION__, exit,
41685 +                          bb_mod_name, bb_func_name, bb_curr_addr);
41686 +}
41687 +
41688 +static int
41689 +kdb_bb1(int argc, const char **argv)
41690 +{
41691 +       int diag;
41692 +       unsigned long addr;
41693 +       bb_cleanup();   /* in case previous command was interrupted */
41694 +       kdba_id_init(&kdb_di);
41695 +       if (argc != 1)
41696 +               return KDB_ARGCOUNT;
41697 +       if ((diag = kdbgetularg((char *)argv[1], &addr)))
41698 +               return diag;
41699 +       kdb_save_flags();
41700 +       kdb_flags |= KDB_DEBUG_FLAG_BB << KDB_DEBUG_FLAG_SHIFT;
41701 +       kdb_bb(addr);
41702 +       bb_cleanup();
41703 +       kdb_restore_flags();
41704 +       kdbnearsym_cleanup();
41705 +       return 0;
41706 +}
41707 +
41708 +/* Run a basic block analysis on every function in the base kernel.  Used as a
41709 + * global sanity check to find errors in the basic block code.
41710 + */
41711 +
41712 +static int
41713 +kdb_bb_all(int argc, const char **argv)
41714 +{
41715 +       loff_t pos = 0;
41716 +       const char *symname;
41717 +       unsigned long addr;
41718 +       int i, max_errors = 20;
41719 +       struct bb_name_state *r;
41720 +       kdb_printf("%s: conditional build variables:"
41721 +#ifdef CONFIG_X86_64
41722 +                  " CONFIG_X86_64"
41723 +#endif
41724 +#ifdef CONFIG_4KSTACKS
41725 +                  " CONFIG_4KSTACKS"
41726 +#endif
41727 +#ifdef CONFIG_PREEMPT
41728 +                  " CONFIG_PREEMPT"
41729 +#endif
41730 +#ifdef CONFIG_VM86
41731 +                  " CONFIG_VM86"
41732 +#endif
41733 +#ifdef CONFIG_FRAME_POINTER
41734 +                  " CONFIG_FRAME_POINTER"
41735 +#endif
41736 +#ifdef CONFIG_TRACE_IRQFLAGS
41737 +                  " CONFIG_TRACE_IRQFLAGS"
41738 +#endif
41739 +#ifdef NO_SIBLINGS
41740 +                  " NO_SIBLINGS"
41741 +#endif
41742 +                  " REGPARM=" __stringify(REGPARM)
41743 +                  "\n\n", __FUNCTION__);
41744 +       for (i = 0, r = bb_special_cases;
41745 +            i < ARRAY_SIZE(bb_special_cases);
41746 +            ++i, ++r) {
41747 +               if (!r->address)
41748 +                       kdb_printf("%s: cannot find special_case name %s\n",
41749 +                                  __FUNCTION__, r->name);
41750 +       }
41751 +       for (i = 0; i < ARRAY_SIZE(bb_spurious); ++i) {
41752 +               if (!kallsyms_lookup_name(bb_spurious[i]))
41753 +                       kdb_printf("%s: cannot find spurious label %s\n",
41754 +                                  __FUNCTION__, bb_spurious[i]);
41755 +       }
41756 +       while ((symname = kdb_walk_kallsyms(&pos))) {
41757 +               ++pos;
41758 +               if (strcmp(symname, "_stext") == 0 ||
41759 +                   strcmp(symname, "stext") == 0)
41760 +                       break;
41761 +       }
41762 +       if (!symname) {
41763 +               kdb_printf("%s: cannot find _stext\n", __FUNCTION__);
41764 +               return 0;
41765 +       }
41766 +       kdba_id_init(&kdb_di);
41767 +       i = 0;
41768 +       while ((symname = kdb_walk_kallsyms(&pos))) {
41769 +               if (strcmp(symname, "_etext") == 0)
41770 +                       break;
41771 +               if (i++ % 100 == 0)
41772 +                       kdb_printf(".");
41773 +               /* x86_64 has some 16 bit functions that appear between stext
41774 +                * and _etext.  Skip them.
41775 +                */
41776 +               if (strcmp(symname, "verify_cpu") == 0 ||
41777 +                   strcmp(symname, "verify_cpu_noamd") == 0 ||
41778 +                   strcmp(symname, "verify_cpu_sse_test") == 0 ||
41779 +                   strcmp(symname, "verify_cpu_no_longmode") == 0 ||
41780 +                   strcmp(symname, "verify_cpu_sse_ok") == 0 ||
41781 +                   strcmp(symname, "mode_seta") == 0 ||
41782 +                   strcmp(symname, "bad_address") == 0 ||
41783 +                   strcmp(symname, "wakeup_code") == 0 ||
41784 +                   strcmp(symname, "wakeup_code_start") == 0 ||
41785 +                   strcmp(symname, "wakeup_start") == 0 ||
41786 +                   strcmp(symname, "wakeup_32_vector") == 0 ||
41787 +                   strcmp(symname, "wakeup_32") == 0 ||
41788 +                   strcmp(symname, "wakeup_long64_vector") == 0 ||
41789 +                   strcmp(symname, "wakeup_long64") == 0 ||
41790 +                   strcmp(symname, "gdta") == 0 ||
41791 +                   strcmp(symname, "idt_48a") == 0 ||
41792 +                   strcmp(symname, "gdt_48a") == 0 ||
41793 +                   strcmp(symname, "bogus_real_magic") == 0 ||
41794 +                   strcmp(symname, "bogus_64_magic") == 0 ||
41795 +                   strcmp(symname, "no_longmode") == 0 ||
41796 +                   strcmp(symname, "mode_seta") == 0 ||
41797 +                   strcmp(symname, "setbada") == 0 ||
41798 +                   strcmp(symname, "check_vesaa") == 0 ||
41799 +                   strcmp(symname, "_setbada") == 0 ||
41800 +                   strcmp(symname, "wakeup_stack_begin") == 0 ||
41801 +                   strcmp(symname, "wakeup_stack") == 0 ||
41802 +                   strcmp(symname, "wakeup_level4_pgt") == 0 ||
41803 +                   strcmp(symname, "acpi_copy_wakeup_routine") == 0 ||
41804 +                   strcmp(symname, "wakeup_end") == 0 ||
41805 +                   strcmp(symname, "do_suspend_lowlevel_s4bios") == 0 ||
41806 +                   strcmp(symname, "do_suspend_lowlevel") == 0)
41807 +                       continue;
41808 +               /* __kprobes_text_end contains branches to the middle of code,
41809 +                * with undefined states.
41810 +                */
41811 +               if (strcmp(symname, "__kprobes_text_end") == 0)
41812 +                       continue;
41813 +               if (bb_spurious_global_label(symname))
41814 +                       continue;
41815 +               if ((addr = kallsyms_lookup_name(symname)) == 0)
41816 +                       continue;
41817 +               // kdb_printf("BB " kdb_bfd_vma_fmt0 " %s\n", addr, symname);
41818 +               bb_cleanup();   /* in case previous command was interrupted */
41819 +               kdbnearsym_cleanup();
41820 +               kdb_bb(addr);
41821 +               touch_nmi_watchdog();
41822 +               if (bb_giveup) {
41823 +                       if (max_errors-- == 0) {
41824 +                               kdb_printf("%s: max_errors reached, giving up\n",
41825 +                                          __FUNCTION__);
41826 +                               break;
41827 +                       } else {
41828 +                               bb_giveup = 0;
41829 +                       }
41830 +               }
41831 +       }
41832 +       kdb_printf("\n");
41833 +       bb_cleanup();
41834 +       kdbnearsym_cleanup();
41835 +       return 0;
41836 +}
41837 +
41838 +/*
41839 + *=============================================================================
41840 + *
41841 + * Everything above this line is doing basic block analysis, function by
41842 + * function.  Everything below this line uses the basic block data to do a
41843 + * complete backtrace over all functions that are used by a process.
41844 + *
41845 + *=============================================================================
41846 + */
41847 +
41848 +
41849 +/*============================================================================*/
41850 +/*                                                                            */
41851 +/* Most of the backtrace code and data is common to x86_64 and i386.  This    */
41852 +/* large ifdef contains all of the differences between the two architectures. */
41853 +/*                                                                            */
41854 +/* Make sure you update the correct section of this ifdef.                    */
41855 +/*                                                                            */
41856 +/*============================================================================*/
41857 +
41858 +#ifdef CONFIG_X86_64
41859 +
41860 +#define XCS "cs"
41861 +#define RSP "rsp"
41862 +#define RIP "rip"
41863 +#define ARCH_RSP rsp
41864 +#define ARCH_RIP rip
41865 +#define ARCH_NORMAL_PADDING (16 * 8)
41866 +
41867 +/* x86_64 has multiple alternate stacks, with different sizes and different
41868 + * offsets to get the link from one stack to the next.  Some of the stacks are
41869 + * referenced via cpu_pda, some via per_cpu orig_ist.  Debug events can even
41870 + * have multiple nested stacks within the single physical stack, each nested
41871 + * stack has its own link and some of those links are wrong.
41872 + *
41873 + * Consistent it's not!
41874 + *
41875 + * Do not assume that these stacks are aligned on their size.
41876 + */
41877 +#define INTERRUPT_STACK (N_EXCEPTION_STACKS + 1)
41878 +void
41879 +kdba_get_stack_info_alternate(kdb_machreg_t addr, int cpu,
41880 +                             struct kdb_activation_record *ar)
41881 +{
41882 +       static struct {
41883 +               const char *id;
41884 +               unsigned int total_size;
41885 +               unsigned int nested_size;
41886 +               unsigned int next;
41887 +       } *sdp, stack_data[] = {
41888 +               [STACKFAULT_STACK - 1] =  { "stackfault",    EXCEPTION_STKSZ, EXCEPTION_STKSZ, EXCEPTION_STKSZ - 2*sizeof(void *) },
41889 +               [DOUBLEFAULT_STACK - 1] = { "doublefault",   EXCEPTION_STKSZ, EXCEPTION_STKSZ, EXCEPTION_STKSZ - 2*sizeof(void *) },
41890 +               [NMI_STACK - 1] =         { "nmi",           EXCEPTION_STKSZ, EXCEPTION_STKSZ, EXCEPTION_STKSZ - 2*sizeof(void *) },
41891 +               [DEBUG_STACK - 1] =       { "debug",         DEBUG_STKSZ,     EXCEPTION_STKSZ, EXCEPTION_STKSZ - 2*sizeof(void *) },
41892 +               [MCE_STACK - 1] =         { "machine check", EXCEPTION_STKSZ, EXCEPTION_STKSZ, EXCEPTION_STKSZ - 2*sizeof(void *) },
41893 +               [INTERRUPT_STACK - 1] =   { "interrupt",     IRQSTACKSIZE,    IRQSTACKSIZE,    IRQSTACKSIZE    -   sizeof(void *) },
41894 +       };
41895 +       unsigned long total_start = 0, total_size, total_end;
41896 +       int sd, found = 0;
41897 +       extern unsigned long kdba_orig_ist(int, int);
41898 +
41899 +       for (sd = 0, sdp = stack_data;
41900 +            sd < ARRAY_SIZE(stack_data);
41901 +            ++sd, ++sdp) {
41902 +               total_size = sdp->total_size;
41903 +               if (!total_size)
41904 +                       continue;       /* in case stack_data[] has any holes */
41905 +               if (cpu < 0) {
41906 +                       /* Arbitrary address which can be on any cpu, see if it
41907 +                        * falls within any of the alternate stacks
41908 +                        */
41909 +                       int c;
41910 +                       for_each_online_cpu(c) {
41911 +                               if (sd == INTERRUPT_STACK - 1)
41912 +                                       total_end = (unsigned long)cpu_pda(c)->irqstackptr;
41913 +                               else
41914 +                                       total_end = per_cpu(orig_ist, c).ist[sd];
41915 +                               total_start = total_end - total_size;
41916 +                               if (addr >= total_start && addr < total_end) {
41917 +                                       found = 1;
41918 +                                       cpu = c;
41919 +                                       break;
41920 +                               }
41921 +                       }
41922 +                       if (!found)
41923 +                               continue;
41924 +               }
41925 +               /* Only check the supplied or found cpu */
41926 +               if (sd == INTERRUPT_STACK - 1)
41927 +                       total_end = (unsigned long)cpu_pda(cpu)->irqstackptr;
41928 +               else
41929 +                       total_end = per_cpu(orig_ist, cpu).ist[sd];
41930 +               total_start = total_end - total_size;
41931 +               if (addr >= total_start && addr < total_end) {
41932 +                       found = 1;
41933 +                       break;
41934 +               }
41935 +       }
41936 +       if (!found)
41937 +               return;
41938 +       /* find which nested stack the address is in */
41939 +       while (addr > total_start + sdp->nested_size)
41940 +               total_start += sdp->nested_size;
41941 +       ar->stack.physical_start = total_start;
41942 +       ar->stack.physical_end = total_start + sdp->nested_size;
41943 +       ar->stack.logical_start = total_start;
41944 +       ar->stack.logical_end = total_start + sdp->next;
41945 +       ar->stack.next = *(unsigned long *)ar->stack.logical_end;
41946 +       ar->stack.id = sdp->id;
41947 +
41948 +       /* Nasty: when switching to the interrupt stack, the stack state of the
41949 +        * caller is split over two stacks, the original stack and the
41950 +        * interrupt stack.  One word (the previous frame pointer) is stored on
41951 +        * the interrupt stack, the rest of the interrupt data is in the old
41952 +        * frame.  To make the interrupted stack state look as though it is
41953 +        * contiguous, copy the missing word from the interrupt stack to the
41954 +        * original stack and adjust the new stack pointer accordingly.
41955 +        */
41956 +
41957 +       if (sd == INTERRUPT_STACK - 1) {
41958 +               *(unsigned long *)(ar->stack.next - KDB_WORD_SIZE) =
41959 +                       ar->stack.next;
41960 +               ar->stack.next -= KDB_WORD_SIZE;
41961 +       }
41962 +}
41963 +
41964 +/* rip is not in the thread struct for x86_64.  We know that the stack value
41965 + * was saved in schedule near the label thread_return.  Setting rip to
41966 + * thread_return lets the stack trace find that we are in schedule and
41967 + * correctly decode its prologue.
41968 + */
41969 +
41970 +static kdb_machreg_t
41971 +kdba_bt_stack_rip(const struct task_struct *p)
41972 +{
41973 +       return bb_thread_return;
41974 +}
41975 +
41976 +#else  /* !CONFIG_X86_64 */
41977 +
41978 +#define XCS "xcs"
41979 +#define RSP "esp"
41980 +#define RIP "eip"
41981 +#define ARCH_RSP esp
41982 +#define ARCH_RIP eip
41983 +#define ARCH_NORMAL_PADDING (19 * 4)
41984 +
41985 +#ifdef CONFIG_4KSTACKS
41986 +static struct thread_info **kdba_hardirq_ctx, **kdba_softirq_ctx;
41987 +#endif /* CONFIG_4KSTACKS */
41988 +
41989 +/* On a 4K stack kernel, hardirq_ctx and softirq_ctx are [NR_CPUS] arrays.  The
41990 + * first element of each per-cpu stack is a struct thread_info.
41991 + */
41992 +void
41993 +kdba_get_stack_info_alternate(kdb_machreg_t addr, int cpu,
41994 +                             struct kdb_activation_record *ar)
41995 +{
41996 +#ifdef CONFIG_4KSTACKS
41997 +       struct thread_info *tinfo;
41998 +       tinfo = (struct thread_info *)(addr & -THREAD_SIZE);
41999 +       if (cpu < 0) {
42000 +               /* Arbitrary address, see if it falls within any of the irq
42001 +                * stacks
42002 +                */
42003 +               int found = 0;
42004 +               for_each_online_cpu(cpu) {
42005 +                       if (tinfo == kdba_hardirq_ctx[cpu] ||
42006 +                           tinfo == kdba_softirq_ctx[cpu]) {
42007 +                               found = 1;
42008 +                               break;
42009 +                       }
42010 +               }
42011 +               if (!found)
42012 +                       return;
42013 +       }
42014 +       if (tinfo == kdba_hardirq_ctx[cpu] ||
42015 +           tinfo == kdba_softirq_ctx[cpu]) {
42016 +               ar->stack.physical_start = (kdb_machreg_t)tinfo;
42017 +               ar->stack.physical_end = ar->stack.physical_start + THREAD_SIZE;
42018 +               ar->stack.logical_start = ar->stack.physical_start +
42019 +                                         sizeof(struct thread_info);
42020 +               ar->stack.logical_end = ar->stack.physical_end;
42021 +               ar->stack.next = tinfo->previous_esp;
42022 +               if (tinfo == kdba_hardirq_ctx[cpu])
42023 +                       ar->stack.id = "hardirq_ctx";
42024 +               else
42025 +                       ar->stack.id = "softirq_ctx";
42026 +       }
42027 +#endif /* CONFIG_4KSTACKS */
42028 +}
42029 +
42030 +/* rip is in the thread struct for i386 */
42031 +
42032 +static kdb_machreg_t
42033 +kdba_bt_stack_rip(const struct task_struct *p)
42034 +{
42035 +       return p->thread.eip;
42036 +}
42037 +
42038 +#endif /* CONFIG_X86_64 */
42039 +
42040 +/* Given an address which claims to be on a stack, an optional cpu number and
42041 + * an optional task address, get information about the stack.
42042 + *
42043 + * t == NULL, cpu < 0 indicates an arbitrary stack address with no associated
42044 + * struct task, the address can be in an alternate stack or any task's normal
42045 + * stack.
42046 + *
42047 + * t != NULL, cpu >= 0 indicates a running task, the address can be in an
42048 + * alternate stack or that task's normal stack.
42049 + *
42050 + * t != NULL, cpu < 0 indicates a blocked task, the address can only be in that
42051 + * task's normal stack.
42052 + *
42053 + * t == NULL, cpu >= 0 is not a valid combination.
42054 + */
42055 +
42056 +static void
42057 +kdba_get_stack_info(kdb_machreg_t rsp, int cpu,
42058 +                   struct kdb_activation_record *ar,
42059 +                   const struct task_struct *t)
42060 +{
42061 +       struct thread_info *tinfo;
42062 +       struct task_struct *g, *p;
42063 +       memset(&ar->stack, 0, sizeof(ar->stack));
42064 +       if (KDB_DEBUG(ARA))
42065 +               kdb_printf("%s: " RSP "=0x%lx cpu=%d task=%p\n",
42066 +                          __FUNCTION__, rsp, cpu, t);
42067 +       if (t == NULL || cpu >= 0) {
42068 +               kdba_get_stack_info_alternate(rsp, cpu, ar);
42069 +               if (ar->stack.logical_start)
42070 +                       goto out;
42071 +       }
42072 +       rsp &= -THREAD_SIZE;
42073 +       tinfo = (struct thread_info *)rsp;
42074 +       if (t == NULL) {
42075 +               /* Arbitrary stack address without an associated task, see if
42076 +                * it falls within any normal process stack, including the idle
42077 +                * tasks.
42078 +                */
42079 +               kdb_do_each_thread(g, p) {
42080 +                       if (tinfo == task_thread_info(p)) {
42081 +                               t = p;
42082 +                               goto found;
42083 +                       }
42084 +               } kdb_while_each_thread(g, p);
42085 +               for_each_online_cpu(cpu) {
42086 +                       p = idle_task(cpu);
42087 +                       if (tinfo == task_thread_info(p)) {
42088 +                               t = p;
42089 +                               goto found;
42090 +                       }
42091 +               }
42092 +       found:
42093 +               if (KDB_DEBUG(ARA))
42094 +                       kdb_printf("%s: found task %p\n", __FUNCTION__, t);
42095 +       } else if (cpu >= 0) {
42096 +               /* running task */
42097 +               struct kdb_running_process *krp = kdb_running_process + cpu;
42098 +               if (krp->p != t || tinfo != task_thread_info(t))
42099 +                       t = NULL;
42100 +               if (KDB_DEBUG(ARA))
42101 +                       kdb_printf("%s: running task %p\n", __FUNCTION__, t);
42102 +       } else {
42103 +               /* blocked task */
42104 +               if (tinfo != task_thread_info(t))
42105 +                       t = NULL;
42106 +               if (KDB_DEBUG(ARA))
42107 +                       kdb_printf("%s: blocked task %p\n", __FUNCTION__, t);
42108 +       }
42109 +       if (t) {
42110 +               ar->stack.physical_start = rsp;
42111 +               ar->stack.physical_end = rsp + THREAD_SIZE;
42112 +               ar->stack.logical_start = rsp + sizeof(struct thread_info);
42113 +               ar->stack.logical_end = ar->stack.physical_end - ARCH_NORMAL_PADDING;
42114 +               ar->stack.next = 0;
42115 +               ar->stack.id = "normal";
42116 +       }
42117 +out:
42118 +       if (ar->stack.physical_start && KDB_DEBUG(ARA)) {
42119 +               kdb_printf("%s: ar->stack\n", __FUNCTION__);
42120 +               kdb_printf("    physical_start=0x%lx\n", ar->stack.physical_start);
42121 +               kdb_printf("    physical_end=0x%lx\n", ar->stack.physical_end);
42122 +               kdb_printf("    logical_start=0x%lx\n", ar->stack.logical_start);
42123 +               kdb_printf("    logical_end=0x%lx\n", ar->stack.logical_end);
42124 +               kdb_printf("    next=0x%lx\n", ar->stack.next);
42125 +               kdb_printf("    id=%s\n", ar->stack.id);
42126 +               kdb_printf("    set MDCOUNT %ld\n",
42127 +                          (ar->stack.physical_end - ar->stack.physical_start) /
42128 +                          KDB_WORD_SIZE);
42129 +               kdb_printf("    mds " kdb_machreg_fmt0 "\n",
42130 +                          ar->stack.physical_start);
42131 +       }
42132 +}
42133 +
42134 +static void
42135 +bt_print_one(kdb_machreg_t rip, kdb_machreg_t rsp,
42136 +             const struct kdb_activation_record *ar,
42137 +             const kdb_symtab_t *symtab, int argcount)
42138 +{
42139 +       int btsymarg = 0;
42140 +       int nosect = 0;
42141 +
42142 +       kdbgetintenv("BTSYMARG", &btsymarg);
42143 +       kdbgetintenv("NOSECT", &nosect);
42144 +
42145 +       kdb_printf(kdb_machreg_fmt0, rsp);
42146 +       kdb_symbol_print(rip, symtab,
42147 +                        KDB_SP_SPACEB|KDB_SP_VALUE);
42148 +       if (argcount && ar->args) {
42149 +               int i, argc = ar->args;
42150 +               kdb_printf(" (");
42151 +               if (argc > argcount)
42152 +                       argc = argcount;
42153 +               for (i = 0; i < argc; i++) {
42154 +                       if (i)
42155 +                               kdb_printf(", ");
42156 +                       if (test_bit(i, ar->valid.bits))
42157 +                               kdb_printf("0x%lx", ar->arg[i]);
42158 +                       else
42159 +                               kdb_printf("invalid");
42160 +               }
42161 +               kdb_printf(")");
42162 +       }
42163 +       kdb_printf("\n");
42164 +       if (symtab->sym_name) {
42165 +               if (!nosect) {
42166 +                       kdb_printf("                               %s",
42167 +                                  symtab->mod_name);
42168 +                       if (symtab->sec_name && symtab->sec_start)
42169 +                               kdb_printf(" 0x%lx 0x%lx",
42170 +                                          symtab->sec_start, symtab->sec_end);
42171 +                       kdb_printf(" 0x%lx 0x%lx\n",
42172 +                                  symtab->sym_start, symtab->sym_end);
42173 +               }
42174 +       }
42175 +       if (argcount && ar->args && btsymarg) {
42176 +               int i, argc = ar->args;
42177 +               kdb_symtab_t arg_symtab;
42178 +               for (i = 0; i < argc; i++) {
42179 +                       kdb_machreg_t arg = ar->arg[i];
42180 +                       if (test_bit(i, ar->valid.bits) &&
42181 +                           kdbnearsym(arg, &arg_symtab)) {
42182 +                               kdb_printf("                       ARG %2d ", i);
42183 +                               kdb_symbol_print(arg, &arg_symtab,
42184 +                                                KDB_SP_DEFAULT|KDB_SP_NEWLINE);
42185 +                       }
42186 +               }
42187 +       }
42188 +}
42189 +
42190 +static void
42191 +kdba_bt_new_stack(struct kdb_activation_record *ar, kdb_machreg_t *rsp,
42192 +                  int *count, int *suppress)
42193 +{
42194 +       /* Nasty: common_interrupt builds a partial pt_regs, with r15 through
42195 +        * rbx not being filled in.  It passes struct pt_regs* to do_IRQ (in
42196 +        * rdi) but the stack pointer is not adjusted to account for r15
42197 +        * through rbx.  This has two effects :-
42198 +        *
42199 +        * (1) struct pt_regs on an external interrupt actually overlaps with
42200 +        *     the local stack area used by do_IRQ.  Not only are r15-rbx
42201 +        *     undefined, the area that claims to hold their values can even
42202 +        *     change as the irq is processed.
42203 +        *
42204 +        * (2) The back stack pointer saved for the new frame is not pointing
42205 +        *     at pt_regs, it is pointing at rbx within the pt_regs passed to
42206 +        *     do_IRQ.
42207 +        *
42208 +        * There is nothing that I can do about (1) but I have to fix (2)
42209 +        * because kdb backtrace looks for the "start" address of pt_regs as it
42210 +        * walks back through the stacks.  When switching from the interrupt
42211 +        * stack to another stack, we have to assume that pt_regs has been
42212 +        * seen and turn off backtrace supression.
42213 +        */
42214 +       int probable_pt_regs = strcmp(ar->stack.id, "interrupt") == 0;
42215 +       *rsp = ar->stack.next;
42216 +       if (KDB_DEBUG(ARA))
42217 +               kdb_printf("new " RSP "=" kdb_machreg_fmt0 "\n", *rsp);
42218 +       bb_actual_set_value(BBRG_RSP, *rsp);
42219 +       kdba_get_stack_info(*rsp, -1, ar, NULL);
42220 +       if (!ar->stack.physical_start) {
42221 +               kdb_printf("+++ Cannot resolve next stack\n");
42222 +       } else if (!*suppress) {
42223 +               kdb_printf(" ======================= <%s>\n",
42224 +                          ar->stack.id);
42225 +               ++*count;
42226 +       }
42227 +       if (probable_pt_regs)
42228 +               *suppress = 0;
42229 +}
42230 +
42231 +/*
42232 + * kdba_bt_stack
42233 + *
42234 + * Inputs:
42235 + *     addr    Address provided to 'bt' command, if any.
42236 + *     argcount
42237 + *     p       Pointer to task for 'btp' command.
42238 + * Outputs:
42239 + *     None.
42240 + * Returns:
42241 + *     zero for success, a kdb diagnostic if error
42242 + * Locking:
42243 + *     none.
42244 + * Remarks:
42245 + *     Ultimately all the bt* commands come through this routine.  If
42246 + *     old_style is 0 then it uses the basic block analysis to get an accurate
42247 + *     backtrace with arguments, otherwise it falls back to the old method of
42248 + *     printing anything on stack that looks like a kernel address.
42249 + */
42250 +
42251 +static int
42252 +kdba_bt_stack(kdb_machreg_t addr, int argcount, const struct task_struct *p,
42253 +              int old_style)
42254 +{
42255 +       struct kdb_activation_record ar;
42256 +       kdb_machreg_t rip = 0, rsp = 0, prev_rsp;
42257 +       kdb_symtab_t symtab;
42258 +       int rip_at_rsp = 0, count = 0, btsp = 0, suppress, hardware_pushed = 0;
42259 +       struct pt_regs *regs = NULL;
42260 +
42261 +       kdbgetintenv("BTSP", &btsp);
42262 +       suppress = !btsp;
42263 +       memset(&ar, 0, sizeof(ar));
42264 +       if (old_style)
42265 +               kdb_printf("Using old style backtrace, unreliable with no arguments\n");
42266 +
42267 +       /*
42268 +        * The caller may have supplied an address at which the stack traceback
42269 +        * operation should begin.  This address is assumed by this code to
42270 +        * point to a return address on the stack to be traced back.
42271 +        *
42272 +        * Warning: type in the wrong address and you will get garbage in the
42273 +        * backtrace.
42274 +        */
42275 +       if (addr) {
42276 +               rsp = addr;
42277 +               kdb_getword(&rip, rsp, sizeof(rip));
42278 +               rip_at_rsp = 1;
42279 +               suppress = 0;
42280 +               kdba_get_stack_info(rsp, -1, &ar, NULL);
42281 +       } else {
42282 +               if (task_curr(p)) {
42283 +                       struct kdb_running_process *krp =
42284 +                           kdb_running_process + task_cpu(p);
42285 +                       kdb_machreg_t cs;
42286 +                       regs = krp->regs;
42287 +                       if (krp->seqno &&
42288 +                           krp->p == p &&
42289 +                           krp->seqno >= kdb_seqno - 1 &&
42290 +                           !KDB_NULL_REGS(regs)) {
42291 +                               /* valid saved state, continue processing */
42292 +                       } else {
42293 +                               kdb_printf
42294 +                                   ("Process did not save state, cannot backtrace\n");
42295 +                               kdb_ps1(p);
42296 +                               return 0;
42297 +                       }
42298 +                       kdba_getregcontents(XCS, regs, &cs);
42299 +                       if ((cs & 0xffff) != __KERNEL_CS) {
42300 +                               kdb_printf("Stack is not in kernel space, backtrace not available\n");
42301 +                               return 0;
42302 +                       }
42303 +                       rip = krp->arch.ARCH_RIP;
42304 +                       rsp = krp->arch.ARCH_RSP;
42305 +                       kdba_get_stack_info(rsp, kdb_process_cpu(p), &ar, p);
42306 +               } else {
42307 +                       /* Not on cpu, assume blocked.  Blocked tasks do not
42308 +                        * have pt_regs.  p->thread contains some data, alas
42309 +                        * what it contains differs between i386 and x86_64.
42310 +                        */
42311 +                       rip = kdba_bt_stack_rip(p);
42312 +                       rsp = p->thread.ARCH_RSP;
42313 +                       suppress = 0;
42314 +                       kdba_get_stack_info(rsp, -1, &ar, p);
42315 +               }
42316 +       }
42317 +       if (!ar.stack.physical_start) {
42318 +               kdb_printf(RSP "=0x%lx is not in a valid kernel stack, backtrace not available\n",
42319 +                          rsp);
42320 +               return 0;
42321 +       }
42322 +       memset(&bb_actual, 0, sizeof(bb_actual));
42323 +       bb_actual_set_value(BBRG_RSP, rsp);
42324 +       bb_actual_set_valid(BBRG_RSP, 1);
42325 +
42326 +       kdb_printf(RSP "%*s" RIP "%*sFunction (args)\n",
42327 +                  2*KDB_WORD_SIZE, " ",
42328 +                  2*KDB_WORD_SIZE, " ");
42329 +       if (ar.stack.next && !suppress)
42330 +               kdb_printf(" ======================= <%s>\n",
42331 +                          ar.stack.id);
42332 +
42333 +       bb_cleanup();
42334 +       /* Run through all the stacks */
42335 +       while (ar.stack.physical_start) {
42336 +               if (rip_at_rsp)
42337 +                       rip = *(kdb_machreg_t *)rsp;
42338 +               kdbnearsym(rip, &symtab);
42339 +               if (old_style) {
42340 +                       if (__kernel_text_address(rip) && !suppress) {
42341 +                               bt_print_one(rip, rsp, &ar, &symtab, 0);
42342 +                               ++count;
42343 +                       }
42344 +                       if (rsp == (unsigned long)regs) {
42345 +                               if (ar.stack.next && suppress)
42346 +                                       kdb_printf(" ======================= <%s>\n",
42347 +                                                  ar.stack.id);
42348 +                               ++count;
42349 +                               suppress = 0;
42350 +                       }
42351 +                       rsp += sizeof(rip);
42352 +                       rip_at_rsp = 1;
42353 +                       if (rsp >= ar.stack.logical_end) {
42354 +                               if (!ar.stack.next)
42355 +                                       break;
42356 +                               kdba_bt_new_stack(&ar, &rsp, &count, &suppress);
42357 +                               rip_at_rsp = 0;
42358 +                               continue;
42359 +                       }
42360 +               } else {
42361 +                       /* Start each analysis with no dynamic data from the
42362 +                        * previous kdb_bb() run.
42363 +                        */
42364 +                       bb_cleanup();
42365 +                       kdb_bb(rip);
42366 +                       if (bb_giveup)
42367 +                               break;
42368 +                       prev_rsp = rsp;
42369 +                       if (rip_at_rsp) {
42370 +                               rsp += sizeof(rip) + hardware_pushed;
42371 +                               hardware_pushed = 0;
42372 +                               if (rsp >= ar.stack.logical_end &&
42373 +                                   ar.stack.next) {
42374 +                                       kdba_bt_new_stack(&ar, &rsp, &count,
42375 +                                                          &suppress);
42376 +                                       rip_at_rsp = 0;
42377 +                                       continue;
42378 +                               }
42379 +                               bb_actual_set_value(BBRG_RSP, rsp);
42380 +                       }
42381 +                       rip_at_rsp = 1;
42382 +                       bb_actual_rollback(&ar);
42383 +                       if (bb_giveup)
42384 +                               break;
42385 +                       if (bb_actual_value(BBRG_RSP) < rsp) {
42386 +                               kdb_printf("%s: " RSP " is going backwards, "
42387 +                                          kdb_machreg_fmt0 " -> "
42388 +                                          kdb_machreg_fmt0 "\n",
42389 +                                          __FUNCTION__,
42390 +                                          rsp,
42391 +                                          bb_actual_value(BBRG_RSP));
42392 +                               bb_giveup = 1;
42393 +                               break;
42394 +                       }
42395 +                       bb_arguments(&ar);
42396 +                       if (!suppress) {
42397 +                               bt_print_one(rip, prev_rsp, &ar, &symtab, argcount);
42398 +                               ++count;
42399 +                       }
42400 +                       /* Functions that terminate the backtrace */
42401 +                       if (strcmp(bb_func_name, "cpu_idle") == 0)
42402 +                               break;
42403 +                       if (rsp >= ar.stack.logical_end &&
42404 +                           !ar.stack.next)
42405 +                               break;
42406 +                       if (rsp <= (unsigned long)regs &&
42407 +                           bb_actual_value(BBRG_RSP) > (unsigned long)regs) {
42408 +                               if (ar.stack.next && suppress)
42409 +                                       kdb_printf(" ======================= <%s>\n",
42410 +                                                  ar.stack.id);
42411 +                               ++count;
42412 +                               suppress = 0;
42413 +                       }
42414 +                       rsp = bb_actual_value(BBRG_RSP);
42415 +                       hardware_pushed = bb_hardware_pushed(rip);
42416 +               }
42417 +               if (count > 200)
42418 +                       break;
42419 +       }
42420 +       if (bb_giveup)
42421 +               return 1;
42422 +       bb_cleanup();
42423 +       kdbnearsym_cleanup();
42424 +
42425 +       if (count > 200) {
42426 +               kdb_printf("bt truncated, count limit reached\n");
42427 +               return 1;
42428 +       } else if (suppress) {
42429 +               kdb_printf
42430 +                   ("bt did not find pt_regs - no trace produced.  Suggest 'set BTSP 1'\n");
42431 +               return 1;
42432 +       }
42433 +
42434 +       return 0;
42435 +}
42436 +
42437 +/*
42438 + * kdba_bt_address
42439 + *
42440 + *     Do a backtrace starting at a specified stack address.  Use this if the
42441 + *     heuristics get the stack decode wrong.
42442 + *
42443 + * Inputs:
42444 + *     addr    Address provided to 'bt' command.
42445 + *     argcount
42446 + * Outputs:
42447 + *     None.
42448 + * Returns:
42449 + *     zero for success, a kdb diagnostic if error
42450 + * Locking:
42451 + *     none.
42452 + * Remarks:
42453 + *     mds %rsp comes in handy when examining the stack to do a manual
42454 + *     traceback.
42455 + */
42456 +
42457 +int kdba_bt_address(kdb_machreg_t addr, int argcount)
42458 +{
42459 +       int ret;
42460 +       kdba_id_init(&kdb_di);                  /* kdb_bb needs this done once */
42461 +       ret = kdba_bt_stack(addr, argcount, NULL, 0);
42462 +       if (ret == 1)
42463 +               ret = kdba_bt_stack(addr, argcount, NULL, 1);
42464 +       return ret;
42465 +}
42466 +
42467 +/*
42468 + * kdba_bt_process
42469 + *
42470 + *     Do a backtrace for a specified process.
42471 + *
42472 + * Inputs:
42473 + *     p       Struct task pointer extracted by 'bt' command.
42474 + *     argcount
42475 + * Outputs:
42476 + *     None.
42477 + * Returns:
42478 + *     zero for success, a kdb diagnostic if error
42479 + * Locking:
42480 + *     none.
42481 + */
42482 +
42483 +int kdba_bt_process(const struct task_struct *p, int argcount)
42484 +{
42485 +       int ret;
42486 +       kdba_id_init(&kdb_di);                  /* kdb_bb needs this done once */
42487 +       ret = kdba_bt_stack(0, argcount, p, 0);
42488 +       if (ret == 1)
42489 +               ret = kdba_bt_stack(0, argcount, p, 1);
42490 +       return ret;
42491 +}
42492 +
42493 +static int __init kdba_bt_x86_init(void)
42494 +{
42495 +       int i, c, cp = -1;
42496 +       struct bb_name_state *r;
42497 +
42498 +       kdb_register_repeat("bb1", kdb_bb1, "<vaddr>",  "Analyse one basic block", 0, KDB_REPEAT_NONE);
42499 +       kdb_register_repeat("bb_all", kdb_bb_all, "",   "Backtrace check on all built in functions", 0, KDB_REPEAT_NONE);
42500 +
42501 +       /* Split the opcode usage table by the first letter of each set of
42502 +        * opcodes, for faster mapping of opcode to its operand usage.
42503 +        */
42504 +       for (i = 0; i < ARRAY_SIZE(bb_opcode_usage_all); ++i) {
42505 +               c = bb_opcode_usage_all[i].opcode[0] - 'a';
42506 +               if (c != cp) {
42507 +                       cp = c;
42508 +                       bb_opcode_usage[c].opcode = bb_opcode_usage_all + i;
42509 +               }
42510 +               ++bb_opcode_usage[c].size;
42511 +       }
42512 +
42513 +       bb_common_interrupt = kallsyms_lookup_name("common_interrupt");
42514 +       bb_error_entry = kallsyms_lookup_name("error_entry");
42515 +       bb_ret_from_intr = kallsyms_lookup_name("ret_from_intr");
42516 +       bb_thread_return = kallsyms_lookup_name("thread_return");
42517 +       bb_sync_regs = kallsyms_lookup_name("sync_regs");
42518 +       bb_save_v86_state = kallsyms_lookup_name("save_v86_state");
42519 +       bb__sched_text_start = kallsyms_lookup_name("__sched_text_start");
42520 +       bb__sched_text_end = kallsyms_lookup_name("__sched_text_end");
42521 +       for (i = 0, r = bb_special_cases;
42522 +            i < ARRAY_SIZE(bb_special_cases);
42523 +            ++i, ++r) {
42524 +               r->address = kallsyms_lookup_name(r->name);
42525 +       }
42526 +
42527 +#ifdef CONFIG_4KSTACKS
42528 +       kdba_hardirq_ctx = (struct thread_info **)kallsyms_lookup_name("hardirq_ctx");
42529 +       kdba_softirq_ctx = (struct thread_info **)kallsyms_lookup_name("softirq_ctx");
42530 +#endif /* CONFIG_4KSTACKS */
42531 +
42532 +       return 0;
42533 +}
42534 +
42535 +static void __exit kdba_bt_x86_exit(void)
42536 +{
42537 +       kdb_unregister("bb1");
42538 +       kdb_unregister("bb_all");
42539 +}
42540 +
42541 +module_init(kdba_bt_x86_init)
42542 +module_exit(kdba_bt_x86_exit)
42543 diff -Nurp linux-2.6.22-590/kdb/kdb_bp.c linux-2.6.22-600/kdb/kdb_bp.c
42544 --- linux-2.6.22-590/kdb/kdb_bp.c       1970-01-01 01:00:00.000000000 +0100
42545 +++ linux-2.6.22-600/kdb/kdb_bp.c       2008-04-09 18:14:28.000000000 +0200
42546 @@ -0,0 +1,619 @@
42547 +/*
42548 + * Kernel Debugger Architecture Independent Breakpoint Handler
42549 + *
42550 + * This file is subject to the terms and conditions of the GNU General Public
42551 + * License.  See the file "COPYING" in the main directory of this archive
42552 + * for more details.
42553 + *
42554 + * Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
42555 + */
42556 +
42557 +#include <linux/string.h>
42558 +#include <linux/kernel.h>
42559 +#include <linux/init.h>
42560 +#include <linux/kdb.h>
42561 +#include <linux/kdbprivate.h>
42562 +#include <linux/smp.h>
42563 +#include <linux/sched.h>
42564 +#include <linux/interrupt.h>
42565 +#include <asm/system.h>
42566 +
42567 +/*
42568 + * Table of kdb_breakpoints
42569 + */
42570 +kdb_bp_t kdb_breakpoints[KDB_MAXBPT];
42571 +
42572 +/*
42573 + * kdb_bp_install_global
42574 + *
42575 + *     Install global kdb_breakpoints prior to returning from the
42576 + *     kernel debugger.  This allows the kdb_breakpoints to be set
42577 + *     upon functions that are used internally by kdb, such as
42578 + *     printk().
42579 + *
42580 + * Parameters:
42581 + *     regs    Execution frame.
42582 + * Outputs:
42583 + *     None.
42584 + * Returns:
42585 + *     None.
42586 + * Locking:
42587 + *     None.
42588 + * Remarks:
42589 + *
42590 + *     This function is only called once per kdb session.
42591 + */
42592 +
42593 +void
42594 +kdb_bp_install_global(struct pt_regs *regs)
42595 +{
42596 +       int i;
42597 +
42598 +       for(i=0; i<KDB_MAXBPT; i++) {
42599 +               if (KDB_DEBUG(BP)) {
42600 +                       kdb_printf("kdb_bp_install_global bp %d bp_enabled %d bp_global %d\n",
42601 +                               i, kdb_breakpoints[i].bp_enabled, kdb_breakpoints[i].bp_global);
42602 +               }
42603 +               if (kdb_breakpoints[i].bp_enabled
42604 +                && kdb_breakpoints[i].bp_global) {
42605 +                       kdba_installbp(regs, &kdb_breakpoints[i]);
42606 +               }
42607 +       }
42608 +}
42609 +
42610 +/*
42611 + * kdb_bp_install_local
42612 + *
42613 + *     Install local kdb_breakpoints prior to returning from the
42614 + *     kernel debugger.  This allows the kdb_breakpoints to be set
42615 + *     upon functions that are used internally by kdb, such as
42616 + *     printk().
42617 + *
42618 + * Parameters:
42619 + *     regs    Execution frame.
42620 + * Outputs:
42621 + *     None.
42622 + * Returns:
42623 + *     None.
42624 + * Locking:
42625 + *     None.
42626 + * Remarks:
42627 + *
42628 + *     This function is called once per processor.
42629 + */
42630 +
42631 +void
42632 +kdb_bp_install_local(struct pt_regs *regs)
42633 +{
42634 +       int i;
42635 +
42636 +       for(i=0; i<KDB_MAXBPT; i++) {
42637 +               if (KDB_DEBUG(BP)) {
42638 +                       kdb_printf("kdb_bp_install_local bp %d bp_enabled %d bp_global %d cpu %d bp_cpu %d\n",
42639 +                               i, kdb_breakpoints[i].bp_enabled, kdb_breakpoints[i].bp_global,
42640 +                               smp_processor_id(), kdb_breakpoints[i].bp_cpu);
42641 +               }
42642 +               if (kdb_breakpoints[i].bp_enabled
42643 +                && kdb_breakpoints[i].bp_cpu == smp_processor_id()
42644 +                && !kdb_breakpoints[i].bp_global){
42645 +                       kdba_installbp(regs, &kdb_breakpoints[i]);
42646 +               }
42647 +       }
42648 +}
42649 +
42650 +/*
42651 + * kdb_bp_remove_global
42652 + *
42653 + *     Remove global kdb_breakpoints upon entry to the kernel debugger.
42654 + *
42655 + * Parameters:
42656 + *     None.
42657 + * Outputs:
42658 + *     None.
42659 + * Returns:
42660 + *     None.
42661 + * Locking:
42662 + *     None.
42663 + * Remarks:
42664 + */
42665 +
42666 +void
42667 +kdb_bp_remove_global(void)
42668 +{
42669 +       int i;
42670 +
42671 +       for(i=KDB_MAXBPT-1; i>=0; i--) {
42672 +               if (KDB_DEBUG(BP)) {
42673 +                       kdb_printf("kdb_bp_remove_global bp %d bp_enabled %d bp_global %d\n",
42674 +                               i, kdb_breakpoints[i].bp_enabled, kdb_breakpoints[i].bp_global);
42675 +               }
42676 +               if (kdb_breakpoints[i].bp_enabled
42677 +                && kdb_breakpoints[i].bp_global) {
42678 +                       kdba_removebp(&kdb_breakpoints[i]);
42679 +               }
42680 +       }
42681 +}
42682 +
42683 +
42684 +/*
42685 + * kdb_bp_remove_local
42686 + *
42687 + *     Remove local kdb_breakpoints upon entry to the kernel debugger.
42688 + *
42689 + * Parameters:
42690 + *     None.
42691 + * Outputs:
42692 + *     None.
42693 + * Returns:
42694 + *     None.
42695 + * Locking:
42696 + *     None.
42697 + * Remarks:
42698 + */
42699 +
42700 +void
42701 +kdb_bp_remove_local(void)
42702 +{
42703 +       int i;
42704 +
42705 +       for(i=KDB_MAXBPT-1; i>=0; i--) {
42706 +               if (KDB_DEBUG(BP)) {
42707 +                       kdb_printf("kdb_bp_remove_local bp %d bp_enabled %d bp_global %d cpu %d bp_cpu %d\n",
42708 +                               i, kdb_breakpoints[i].bp_enabled, kdb_breakpoints[i].bp_global,
42709 +                               smp_processor_id(), kdb_breakpoints[i].bp_cpu);
42710 +               }
42711 +               if (kdb_breakpoints[i].bp_enabled
42712 +                && kdb_breakpoints[i].bp_cpu == smp_processor_id()
42713 +                && !kdb_breakpoints[i].bp_global){
42714 +                       kdba_removebp(&kdb_breakpoints[i]);
42715 +               }
42716 +       }
42717 +}
42718 +
42719 +/*
42720 + * kdb_printbp
42721 + *
42722 + *     Internal function to format and print a breakpoint entry.
42723 + *
42724 + * Parameters:
42725 + *     None.
42726 + * Outputs:
42727 + *     None.
42728 + * Returns:
42729 + *     None.
42730 + * Locking:
42731 + *     None.
42732 + * Remarks:
42733 + */
42734 +
42735 +static void
42736 +kdb_printbp(kdb_bp_t *bp, int i)
42737 +{
42738 +       if (bp->bp_forcehw) {
42739 +               kdb_printf("Forced ");
42740 +       }
42741 +
42742 +       if (!bp->bp_template.bph_free) {
42743 +               kdb_printf("%s ", kdba_bptype(&bp->bp_template));
42744 +       } else {
42745 +               kdb_printf("Instruction(i) ");
42746 +       }
42747 +
42748 +       kdb_printf("BP #%d at ", i);
42749 +       kdb_symbol_print(bp->bp_addr, NULL, KDB_SP_DEFAULT);
42750 +
42751 +       if (bp->bp_enabled) {
42752 +               kdba_printbp(bp);
42753 +               if (bp->bp_global)
42754 +                       kdb_printf(" globally");
42755 +               else
42756 +                       kdb_printf(" on cpu %d", bp->bp_cpu);
42757 +               if (bp->bp_adjust)
42758 +                       kdb_printf(" adjust %d", bp->bp_adjust);
42759 +       } else {
42760 +               kdb_printf("\n    is disabled");
42761 +       }
42762 +
42763 +       kdb_printf("\n");
42764 +}
42765 +
42766 +/*
42767 + * kdb_bp
42768 + *
42769 + *     Handle the bp, and bpa commands.
42770 + *
42771 + *     [bp|bpa|bph] <addr-expression> [DATAR|DATAW|IO [length]]
42772 + *
42773 + * Parameters:
42774 + *     argc    Count of arguments in argv
42775 + *     argv    Space delimited command line arguments
42776 + * Outputs:
42777 + *     None.
42778 + * Returns:
42779 + *     Zero for success, a kdb diagnostic if failure.
42780 + * Locking:
42781 + *     None.
42782 + * Remarks:
42783 + *
42784 + *     bp      Set breakpoint.  Only use hardware assist if necessary.
42785 + *     bpa     Set breakpoint on all cpus, only use hardware regs if necessary
42786 + *     bph     Set breakpoint - force hardware register
42787 + *     bpha    Set breakpoint on all cpus, force hardware register
42788 + */
42789 +
42790 +static int
42791 +kdb_bp(int argc, const char **argv)
42792 +{
42793 +       int i, bpno;
42794 +       kdb_bp_t *bp, *bp_check;
42795 +       int diag;
42796 +       int free;
42797 +       kdb_machreg_t addr;
42798 +       char *symname = NULL;
42799 +       long offset = 0ul;
42800 +       int nextarg;
42801 +       int hardware;
42802 +       int global;
42803 +
42804 +       if (argc == 0) {
42805 +               /*
42806 +                * Display breakpoint table
42807 +                */
42808 +               for(bpno=0,bp=kdb_breakpoints; bpno<KDB_MAXBPT; bpno++, bp++) {
42809 +                       if (bp->bp_free) continue;
42810 +
42811 +                       kdb_printbp(bp, bpno);
42812 +               }
42813 +
42814 +               return 0;
42815 +       }
42816 +
42817 +       global = ((strcmp(argv[0], "bpa") == 0)
42818 +              || (strcmp(argv[0], "bpha") == 0));
42819 +       hardware = ((strcmp(argv[0], "bph") == 0)
42820 +                || (strcmp(argv[0], "bpha") == 0));
42821 +
42822 +       nextarg = 1;
42823 +       diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, &symname);
42824 +       if (diag)
42825 +               return diag;
42826 +       if (!addr)
42827 +               return KDB_BADINT;
42828 +
42829 +       /*
42830 +        * Allocate a new bp structure
42831 +        */
42832 +       free = KDB_MAXBPT;
42833 +       for(bpno=0,bp=kdb_breakpoints; bpno<KDB_MAXBPT; bpno++,bp++) {
42834 +               if (bp->bp_free) {
42835 +                       break;
42836 +               }
42837 +       }
42838 +
42839 +       if (bpno == KDB_MAXBPT)
42840 +               return KDB_TOOMANYBPT;
42841 +
42842 +       memset(bp, 0, sizeof(*bp));
42843 +       bp->bp_free = 1;
42844 +       kdba_check_pc(&addr);
42845 +       for(i=0,bp_check=kdb_breakpoints; i<KDB_MAXBPT; i++,bp_check++) {
42846 +               if (!bp_check->bp_free && bp_check->bp_addr == addr) {
42847 +                       kdb_printf("You already have a breakpoint at " kdb_bfd_vma_fmt0 "\n", addr);
42848 +                       return KDB_DUPBPT;
42849 +               }
42850 +       }
42851 +       bp->bp_addr = addr;
42852 +       bp->bp_free = 0;
42853 +
42854 +       bp->bp_forcehw = hardware;
42855 +       if (KDB_DEBUG(BP))
42856 +               kdb_printf("kdb_bp: forcehw is %d hardware is %d\n", bp->bp_forcehw, hardware);
42857 +
42858 +       /*
42859 +        * Handle architecture dependent parsing
42860 +        */
42861 +       diag = kdba_parsebp(argc, argv, &nextarg, bp);
42862 +       if (diag) {
42863 +               return diag;
42864 +       }
42865 +
42866 +       bp->bp_enabled = 1;
42867 +       bp->bp_global = 1;      /* Most breakpoints are global */
42868 +
42869 +       if (hardware && !global) {
42870 +               bp->bp_global = 0;
42871 +               bp->bp_cpu = smp_processor_id();
42872 +       }
42873 +
42874 +       /*
42875 +        * Allocate a hardware breakpoint.  If one is not available,
42876 +        * disable the breakpoint, but leave it in the breakpoint
42877 +        * table.  When the breakpoint is re-enabled (via 'be'), we'll
42878 +        * attempt to allocate a hardware register for it.
42879 +        */
42880 +       if (!bp->bp_template.bph_free) {
42881 +               bp->bp_hard = kdba_allocbp(&bp->bp_template, &diag);
42882 +               if (diag) {
42883 +                       bp->bp_enabled = 0;
42884 +                       return diag;
42885 +               }
42886 +               bp->bp_hardtype = 1;
42887 +       }
42888 +
42889 +       kdb_printbp(bp, bpno);
42890 +
42891 +       return 0;
42892 +}
42893 +
42894 +/*
42895 + * kdb_bc
42896 + *
42897 + *     Handles the 'bc', 'be', and 'bd' commands
42898 + *
42899 + *     [bd|bc|be] <breakpoint-number>
42900 + *     [bd|bc|be] *
42901 + *
42902 + * Parameters:
42903 + *     argc    Count of arguments in argv
42904 + *     argv    Space delimited command line arguments
42905 + * Outputs:
42906 + *     None.
42907 + * Returns:
42908 + *     Zero for success, a kdb diagnostic for failure
42909 + * Locking:
42910 + *     None.
42911 + * Remarks:
42912 + */
42913 +
42914 +#define KDBCMD_BC      0
42915 +#define KDBCMD_BE      1
42916 +#define KDBCMD_BD      2
42917 +
42918 +static int
42919 +kdb_bc(int argc, const char **argv)
42920 +{
42921 +       kdb_machreg_t addr;
42922 +       kdb_bp_t *bp = NULL;
42923 +       int lowbp = KDB_MAXBPT;
42924 +       int highbp = 0;
42925 +       int done = 0;
42926 +       int i;
42927 +       int diag;
42928 +       int cmd;                        /* KDBCMD_B? */
42929 +
42930 +       if (strcmp(argv[0], "be") == 0) {
42931 +               cmd = KDBCMD_BE;
42932 +       } else if (strcmp(argv[0], "bd") == 0) {
42933 +               cmd = KDBCMD_BD;
42934 +       } else
42935 +               cmd = KDBCMD_BC;
42936 +
42937 +       if (argc != 1)
42938 +               return KDB_ARGCOUNT;
42939 +
42940 +       if (strcmp(argv[1], "*") == 0) {
42941 +               lowbp = 0;
42942 +               highbp = KDB_MAXBPT;
42943 +       } else {
42944 +               diag = kdbgetularg(argv[1], &addr);
42945 +               if (diag)
42946 +                       return diag;
42947 +
42948 +               /*
42949 +                * For addresses less than the maximum breakpoint number,
42950 +                * assume that the breakpoint number is desired.
42951 +                */
42952 +               if (addr < KDB_MAXBPT) {
42953 +                       bp = &kdb_breakpoints[addr];
42954 +                       lowbp = highbp = addr;
42955 +                       highbp++;
42956 +               } else {
42957 +                       for(i=0, bp=kdb_breakpoints; i<KDB_MAXBPT; i++, bp++) {
42958 +                               if (bp->bp_addr == addr) {
42959 +                                       lowbp = highbp = i;
42960 +                                       highbp++;
42961 +                                       break;
42962 +                               }
42963 +                       }
42964 +               }
42965 +       }
42966 +
42967 +       /*
42968 +        * Now operate on the set of breakpoints matching the input
42969 +        * criteria (either '*' for all, or an individual breakpoint).
42970 +        */
42971 +       for(bp=&kdb_breakpoints[lowbp], i=lowbp;
42972 +           i < highbp;
42973 +           i++, bp++) {
42974 +               if (bp->bp_free)
42975 +                       continue;
42976 +
42977 +               done++;
42978 +
42979 +               switch (cmd) {
42980 +               case KDBCMD_BC:
42981 +                       if (bp->bp_hardtype) {
42982 +                               kdba_freebp(bp->bp_hard);
42983 +                               bp->bp_hard = NULL;
42984 +                               bp->bp_hardtype = 0;
42985 +                       }
42986 +
42987 +                       bp->bp_enabled = 0;
42988 +                       bp->bp_global = 0;
42989 +
42990 +                       kdb_printf("Breakpoint %d at " kdb_bfd_vma_fmt " cleared\n",
42991 +                               i, bp->bp_addr);
42992 +
42993 +                       bp->bp_addr = 0;
42994 +                       bp->bp_free = 1;
42995 +
42996 +                       break;
42997 +               case KDBCMD_BE:
42998 +                       /*
42999 +                        * Allocate a hardware breakpoint.  If one is not
43000 +                        * available, don't enable the breakpoint.
43001 +                        */
43002 +                       if (!bp->bp_template.bph_free
43003 +                        && !bp->bp_hardtype) {
43004 +                               bp->bp_hard = kdba_allocbp(&bp->bp_template, &diag);
43005 +                               if (diag) {
43006 +                                       bp->bp_enabled = 0;
43007 +                                       return diag;
43008 +                               }
43009 +                               bp->bp_hardtype = 1;
43010 +                       }
43011 +
43012 +                       bp->bp_enabled = 1;
43013 +
43014 +                       kdb_printf("Breakpoint %d at " kdb_bfd_vma_fmt " enabled",
43015 +                               i, bp->bp_addr);
43016 +
43017 +                       kdb_printf("\n");
43018 +                       break;
43019 +               case KDBCMD_BD:
43020 +                       if (!bp->bp_enabled)
43021 +                               break;
43022 +
43023 +                       /*
43024 +                        * Since this breakpoint is now disabled, we can
43025 +                        * give up the hardware register which is allocated
43026 +                        * to it.
43027 +                        */
43028 +                       if (bp->bp_hardtype) {
43029 +                               kdba_freebp(bp->bp_hard);
43030 +                               bp->bp_hard = NULL;
43031 +                               bp->bp_hardtype = 0;
43032 +                       }
43033 +
43034 +                       bp->bp_enabled = 0;
43035 +
43036 +                       kdb_printf("Breakpoint %d at " kdb_bfd_vma_fmt " disabled\n",
43037 +                               i, bp->bp_addr);
43038 +
43039 +                       break;
43040 +               }
43041 +               if (bp->bp_delay && (cmd == KDBCMD_BC || cmd == KDBCMD_BD)) {
43042 +                       bp->bp_delay = 0;
43043 +                       KDB_STATE_CLEAR(SSBPT);
43044 +               }
43045 +       }
43046 +
43047 +       return (!done)?KDB_BPTNOTFOUND:0;
43048 +}
43049 +
43050 +/*
43051 + * kdb_ss
43052 + *
43053 + *     Process the 'ss' (Single Step) and 'ssb' (Single Step to Branch)
43054 + *     commands.
43055 + *
43056 + *     ss
43057 + *     ssb
43058 + *
43059 + * Parameters:
43060 + *     argc    Argument count
43061 + *     argv    Argument vector
43062 + * Outputs:
43063 + *     None.
43064 + * Returns:
43065 + *     KDB_CMD_SS[B] for success, a kdb error if failure.
43066 + * Locking:
43067 + *     None.
43068 + * Remarks:
43069 + *
43070 + *     Set the arch specific option to trigger a debug trap after the next
43071 + *     instruction.
43072 + *
43073 + *     For 'ssb', set the trace flag in the debug trap handler
43074 + *     after printing the current insn and return directly without
43075 + *     invoking the kdb command processor, until a branch instruction
43076 + *     is encountered.
43077 + */
43078 +
43079 +static int
43080 +kdb_ss(int argc, const char **argv)
43081 +{
43082 +       int ssb = 0;
43083 +       struct pt_regs *regs = get_irq_regs();
43084 +
43085 +       ssb = (strcmp(argv[0], "ssb") == 0);
43086 +       if (argc != 0)
43087 +               return KDB_ARGCOUNT;
43088 +
43089 +       if (!regs) {
43090 +               kdb_printf("%s: pt_regs not available\n", __FUNCTION__);
43091 +               return KDB_BADREG;
43092 +       }
43093 +
43094 +       /*
43095 +        * Set trace flag and go.
43096 +        */
43097 +       KDB_STATE_SET(DOING_SS);
43098 +       if (ssb)
43099 +               KDB_STATE_SET(DOING_SSB);
43100 +
43101 +       kdba_setsinglestep(regs);               /* Enable single step */
43102 +
43103 +       if (ssb)
43104 +               return KDB_CMD_SSB;
43105 +       return KDB_CMD_SS;
43106 +}
43107 +
43108 +/*
43109 + * kdb_initbptab
43110 + *
43111 + *     Initialize the breakpoint table.  Register breakpoint commands.
43112 + *
43113 + * Parameters:
43114 + *     None.
43115 + * Outputs:
43116 + *     None.
43117 + * Returns:
43118 + *     None.
43119 + * Locking:
43120 + *     None.
43121 + * Remarks:
43122 + */
43123 +
43124 +void __init
43125 +kdb_initbptab(void)
43126 +{
43127 +       int i;
43128 +       kdb_bp_t *bp;
43129 +
43130 +       /*
43131 +        * First time initialization.
43132 +        */
43133 +       memset(&kdb_breakpoints, '\0', sizeof(kdb_breakpoints));
43134 +
43135 +       for (i=0, bp=kdb_breakpoints; i<KDB_MAXBPT; i++, bp++) {
43136 +               bp->bp_free = 1;
43137 +               /*
43138 +                * The bph_free flag is architecturally required.  It
43139 +                * is set by architecture-dependent code to false (zero)
43140 +                * in the event a hardware breakpoint register is required
43141 +                * for this breakpoint.
43142 +                *
43143 +                * The rest of the template is reserved to the architecture
43144 +                * dependent code and _must_ not be touched by the architecture
43145 +                * independent code.
43146 +                */
43147 +               bp->bp_template.bph_free = 1;
43148 +       }
43149 +
43150 +       kdb_register_repeat("bp", kdb_bp, "[<vaddr>]", "Set/Display breakpoints", 0, KDB_REPEAT_NO_ARGS);
43151 +       kdb_register_repeat("bl", kdb_bp, "[<vaddr>]", "Display breakpoints", 0, KDB_REPEAT_NO_ARGS);
43152 +       kdb_register_repeat("bpa", kdb_bp, "[<vaddr>]", "Set/Display global breakpoints", 0, KDB_REPEAT_NO_ARGS);
43153 +       kdb_register_repeat("bph", kdb_bp, "[<vaddr>]", "Set hardware breakpoint", 0, KDB_REPEAT_NO_ARGS);
43154 +       kdb_register_repeat("bpha", kdb_bp, "[<vaddr>]", "Set global hardware breakpoint", 0, KDB_REPEAT_NO_ARGS);
43155 +       kdb_register_repeat("bc", kdb_bc, "<bpnum>",   "Clear Breakpoint", 0, KDB_REPEAT_NONE);
43156 +       kdb_register_repeat("be", kdb_bc, "<bpnum>",   "Enable Breakpoint", 0, KDB_REPEAT_NONE);
43157 +       kdb_register_repeat("bd", kdb_bc, "<bpnum>",   "Disable Breakpoint", 0, KDB_REPEAT_NONE);
43158 +
43159 +       kdb_register_repeat("ss", kdb_ss, "", "Single Step", 1, KDB_REPEAT_NO_ARGS);
43160 +       kdb_register_repeat("ssb", kdb_ss, "", "Single step to branch/call", 0, KDB_REPEAT_NO_ARGS);
43161 +       /*
43162 +        * Architecture dependent initialization.
43163 +        */
43164 +       kdba_initbp();
43165 +}
43166 diff -Nurp linux-2.6.22-590/kdb/kdb_bt.c linux-2.6.22-600/kdb/kdb_bt.c
43167 --- linux-2.6.22-590/kdb/kdb_bt.c       1970-01-01 01:00:00.000000000 +0100
43168 +++ linux-2.6.22-600/kdb/kdb_bt.c       2008-04-09 18:14:28.000000000 +0200
43169 @@ -0,0 +1,180 @@
43170 +/*
43171 + * Kernel Debugger Architecture Independent Stack Traceback
43172 + *
43173 + * This file is subject to the terms and conditions of the GNU General Public
43174 + * License.  See the file "COPYING" in the main directory of this archive
43175 + * for more details.
43176 + *
43177 + * Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
43178 + */
43179 +
43180 +#include <linux/ctype.h>
43181 +#include <linux/string.h>
43182 +#include <linux/kernel.h>
43183 +#include <linux/sched.h>
43184 +#include <linux/kdb.h>
43185 +#include <linux/kdbprivate.h>
43186 +#include <linux/nmi.h>
43187 +#include <asm/system.h>
43188 +
43189 +
43190 +/*
43191 + * kdb_bt
43192 + *
43193 + *     This function implements the 'bt' command.  Print a stack
43194 + *     traceback.
43195 + *
43196 + *     bt [<address-expression>]       (addr-exp is for alternate stacks)
43197 + *     btp <pid>                       Kernel stack for <pid>
43198 + *     btt <address-expression>        Kernel stack for task structure at <address-expression>
43199 + *     bta [DRSTCZEUIMA]               All useful processes, optionally filtered by state
43200 + *     btc [<cpu>]                     The current process on one cpu, default is all cpus
43201 + *
43202 + *     bt <address-expression> refers to a address on the stack, that location
43203 + *     is assumed to contain a return address.
43204 + *
43205 + *     btt <address-expression> refers to the address of a struct task.
43206 + *
43207 + * Inputs:
43208 + *     argc    argument count
43209 + *     argv    argument vector
43210 + * Outputs:
43211 + *     None.
43212 + * Returns:
43213 + *     zero for success, a kdb diagnostic if error
43214 + * Locking:
43215 + *     none.
43216 + * Remarks:
43217 + *     Backtrack works best when the code uses frame pointers.  But even
43218 + *     without frame pointers we should get a reasonable trace.
43219 + *
43220 + *     mds comes in handy when examining the stack to do a manual traceback or
43221 + *     to get a starting point for bt <address-expression>.
43222 + */
43223 +
43224 +static int
43225 +kdb_bt1(const struct task_struct *p, unsigned long mask, int argcount, int btaprompt)
43226 +{
43227 +       int diag;
43228 +       char buffer[2];
43229 +       if (kdb_getarea(buffer[0], (unsigned long)p) ||
43230 +           kdb_getarea(buffer[0], (unsigned long)(p+1)-1))
43231 +               return KDB_BADADDR;
43232 +       if (!kdb_task_state(p, mask))
43233 +               return 0;
43234 +       kdb_printf("Stack traceback for pid %d\n", p->pid);
43235 +       kdb_ps1(p);
43236 +       diag = kdba_bt_process(p, argcount);
43237 +       if (btaprompt) {
43238 +               kdb_getstr(buffer, sizeof(buffer), "Enter <q> to end, <cr> to continue:");
43239 +               if (buffer[0] == 'q') {
43240 +                       kdb_printf("\n");
43241 +                       return 1;
43242 +               }
43243 +       }
43244 +       touch_nmi_watchdog();
43245 +       return 0;
43246 +}
43247 +
43248 +int
43249 +kdb_bt(int argc, const char **argv)
43250 +{
43251 +       int diag;
43252 +       int argcount = 5;
43253 +       int btaprompt = 1;
43254 +       int nextarg;
43255 +       unsigned long addr;
43256 +       long offset;
43257 +
43258 +       kdbgetintenv("BTARGS", &argcount);      /* Arguments to print */
43259 +       kdbgetintenv("BTAPROMPT", &btaprompt);  /* Prompt after each proc in bta */
43260 +
43261 +       if (strcmp(argv[0], "bta") == 0) {
43262 +               struct task_struct *g, *p;
43263 +               unsigned long cpu;
43264 +               unsigned long mask = kdb_task_state_string(argc ? argv[1] : NULL);
43265 +               if (argc == 0)
43266 +                       kdb_ps_suppressed();
43267 +               /* Run the active tasks first */
43268 +               for (cpu = 0; cpu < NR_CPUS; ++cpu) {
43269 +                       if (!cpu_online(cpu))
43270 +                               continue;
43271 +                       p = kdb_curr_task(cpu);
43272 +                       if (kdb_bt1(p, mask, argcount, btaprompt))
43273 +                               return 0;
43274 +               }
43275 +               /* Now the inactive tasks */
43276 +               kdb_do_each_thread(g, p) {
43277 +                       if (task_curr(p))
43278 +                               continue;
43279 +                       if (kdb_bt1(p, mask, argcount, btaprompt))
43280 +                               return 0;
43281 +               } kdb_while_each_thread(g, p);
43282 +       } else if (strcmp(argv[0], "btp") == 0) {
43283 +               struct task_struct *p;
43284 +               unsigned long pid;
43285 +               if (argc != 1)
43286 +                       return KDB_ARGCOUNT;
43287 +               if ((diag = kdbgetularg((char *)argv[1], &pid)))
43288 +                       return diag;
43289 +               if ((p = find_task_by_pid(pid))) {
43290 +                       kdba_set_current_task(p);
43291 +                       return kdb_bt1(p, ~0UL, argcount, 0);
43292 +               }
43293 +               kdb_printf("No process with pid == %ld found\n", pid);
43294 +               return 0;
43295 +       } else if (strcmp(argv[0], "btt") == 0) {
43296 +               if (argc != 1)
43297 +                       return KDB_ARGCOUNT;
43298 +               if ((diag = kdbgetularg((char *)argv[1], &addr)))
43299 +                       return diag;
43300 +               kdba_set_current_task((struct task_struct *)addr);
43301 +               return kdb_bt1((struct task_struct *)addr, ~0UL, argcount, 0);
43302 +       } else if (strcmp(argv[0], "btc") == 0) {
43303 +               unsigned long cpu = ~0;
43304 +               struct kdb_running_process *krp;
43305 +               const struct task_struct *save_current_task = kdb_current_task;
43306 +               char buf[80];
43307 +               if (argc > 1)
43308 +                       return KDB_ARGCOUNT;
43309 +               if (argc == 1 && (diag = kdbgetularg((char *)argv[1], &cpu)))
43310 +                       return diag;
43311 +               /* Recursive use of kdb_parse, do not use argv after this point */
43312 +               argv = NULL;
43313 +               if (cpu != ~0) {
43314 +                       krp = kdb_running_process + cpu;
43315 +                       if (cpu >= NR_CPUS || !krp->seqno || !cpu_online(cpu)) {
43316 +                               kdb_printf("no process for cpu %ld\n", cpu);
43317 +                               return 0;
43318 +                       }
43319 +                       sprintf(buf, "btt 0x%p\n", krp->p);
43320 +                       kdb_parse(buf);
43321 +                       return 0;
43322 +               }
43323 +               kdb_printf("btc: cpu status: ");
43324 +               kdb_parse("cpu\n");
43325 +               for (cpu = 0, krp = kdb_running_process; cpu < NR_CPUS; ++cpu, ++krp) {
43326 +                       if (!cpu_online(cpu) || !krp->seqno)
43327 +                               continue;
43328 +                       sprintf(buf, "btt 0x%p\n", krp->p);
43329 +                       kdb_parse(buf);
43330 +                       touch_nmi_watchdog();
43331 +               }
43332 +               kdba_set_current_task(save_current_task);
43333 +               return 0;
43334 +       } else {
43335 +               if (argc) {
43336 +                       nextarg = 1;
43337 +                       diag = kdbgetaddrarg(argc, argv, &nextarg, &addr,
43338 +                                            &offset, NULL);
43339 +                       if (diag)
43340 +                               return diag;
43341 +                       return kdba_bt_address(addr, argcount);
43342 +               } else {
43343 +                       return kdb_bt1(kdb_current_task, ~0UL, argcount, 0);
43344 +               }
43345 +       }
43346 +
43347 +       /* NOTREACHED */
43348 +       return 0;
43349 +}
43350 diff -Nurp linux-2.6.22-590/kdb/kdb_cmds linux-2.6.22-600/kdb/kdb_cmds
43351 --- linux-2.6.22-590/kdb/kdb_cmds       1970-01-01 01:00:00.000000000 +0100
43352 +++ linux-2.6.22-600/kdb/kdb_cmds       2008-04-09 18:14:28.000000000 +0200
43353 @@ -0,0 +1,32 @@
43354 +# Initial commands for kdb, alter to suit your needs.
43355 +# These commands are executed in kdb_init() context, no SMP, no
43356 +# processes.  Commands that require process data (including stack or
43357 +# registers) are not reliable this early.  set and bp commands should
43358 +# be safe.  Global breakpoint commands affect each cpu as it is booted.
43359 +
43360 +# Standard debugging information for first level support, just type archkdb
43361 +# or archkdbcpu or archkdbshort at the kdb prompt.
43362 +
43363 +defcmd archkdb "" "First line arch debugging"
43364 +  set BTSYMARG 1
43365 +  set BTARGS 9
43366 +  pid R
43367 +  -archkdbcommon
43368 +  -bta
43369 +endefcmd
43370 +
43371 +defcmd archkdbcpu "" "archkdb with only tasks on cpus"
43372 +  set BTSYMARG 1
43373 +  set BTARGS 9
43374 +  pid R
43375 +  -archkdbcommon
43376 +  -btc
43377 +endefcmd
43378 +
43379 +defcmd archkdbshort "" "archkdb with less detailed backtrace"
43380 +  set BTSYMARG 0
43381 +  set BTARGS 0
43382 +  pid R
43383 +  -archkdbcommon
43384 +  -bta
43385 +endefcmd
43386 diff -Nurp linux-2.6.22-590/kdb/kdb_id.c linux-2.6.22-600/kdb/kdb_id.c
43387 --- linux-2.6.22-590/kdb/kdb_id.c       1970-01-01 01:00:00.000000000 +0100
43388 +++ linux-2.6.22-600/kdb/kdb_id.c       2008-04-09 18:14:28.000000000 +0200
43389 @@ -0,0 +1,236 @@
43390 +/*
43391 + * Kernel Debugger Architecture Independent Instruction Disassembly
43392 + *
43393 + * This file is subject to the terms and conditions of the GNU General Public
43394 + * License.  See the file "COPYING" in the main directory of this archive
43395 + * for more details.
43396 + *
43397 + * Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
43398 + */
43399 +
43400 +#include <stdarg.h>
43401 +#include <linux/kernel.h>
43402 +#include <linux/init.h>
43403 +#include <linux/ctype.h>
43404 +#include <linux/string.h>
43405 +#include <linux/kdb.h>
43406 +#include <linux/kdbprivate.h>
43407 +
43408 +disassemble_info kdb_di;
43409 +
43410 +/*
43411 + * kdb_id
43412 + *
43413 + *     Handle the id (instruction display) command.
43414 + *
43415 + *     id  [<addr>]
43416 + *
43417 + * Parameters:
43418 + *     argc    Count of arguments in argv
43419 + *     argv    Space delimited command line arguments
43420 + * Outputs:
43421 + *     None.
43422 + * Returns:
43423 + *     Zero for success, a kdb diagnostic if failure.
43424 + * Locking:
43425 + *     None.
43426 + * Remarks:
43427 + */
43428 +
43429 +int
43430 +kdb_id(int argc, const char **argv)
43431 +{
43432 +       kdb_machreg_t pc;
43433 +       int icount;
43434 +       int diag;
43435 +       int i;
43436 +       char *mode;
43437 +       int nextarg;
43438 +       long offset = 0;
43439 +       static kdb_machreg_t lastpc;
43440 +       struct disassemble_info *dip = &kdb_di;
43441 +       char lastbuf[50];
43442 +       unsigned long word;
43443 +
43444 +       kdb_di.fprintf_func = kdb_dis_fprintf;
43445 +       kdba_id_init(&kdb_di);
43446 +
43447 +       if (argc != 1)  {
43448 +               if (lastpc == 0) {
43449 +                       return KDB_ARGCOUNT;
43450 +               } else {
43451 +                       sprintf(lastbuf, "0x%lx", lastpc);
43452 +                       argv[1] = lastbuf;
43453 +                       argc = 1;
43454 +               }
43455 +       }
43456 +
43457 +
43458 +       /*
43459 +        * Fetch PC.  First, check to see if it is a symbol, if not,
43460 +        * try address.
43461 +        */
43462 +       nextarg = 1;
43463 +       diag = kdbgetaddrarg(argc, argv, &nextarg, &pc, &offset, NULL);
43464 +       if (diag)
43465 +               return diag;
43466 +       kdba_check_pc(&pc);
43467 +       if (kdb_getarea(word, pc))
43468 +               return(0);
43469 +
43470 +       /*
43471 +        * Number of lines to display
43472 +        */
43473 +       diag = kdbgetintenv("IDCOUNT", &icount);
43474 +       if (diag)
43475 +               return diag;
43476 +
43477 +       mode = kdbgetenv("IDMODE");
43478 +       diag = kdba_id_parsemode(mode, dip);
43479 +       if (diag) {
43480 +               return diag;
43481 +       }
43482 +
43483 +       for(i=0; i<icount; i++) {
43484 +               pc += kdba_id_printinsn(pc, &kdb_di);
43485 +               kdb_printf("\n");
43486 +       }
43487 +
43488 +       lastpc = pc;
43489 +
43490 +       return 0;
43491 +}
43492 +
43493 +/*
43494 + * kdb_id1
43495 + *
43496 + *     Disassemble a single instruction at 'pc'.
43497 + *
43498 + * Parameters:
43499 + *     pc      Address of instruction to disassemble
43500 + * Outputs:
43501 + *     None.
43502 + * Returns:
43503 + *     Zero for success, a kdb diagnostic if failure.
43504 + * Locking:
43505 + *     None.
43506 + * Remarks:
43507 + */
43508 +
43509 +void
43510 +kdb_id1(unsigned long pc)
43511 +{
43512 +       char *mode;
43513 +       int diag;
43514 +
43515 +       kdb_di.fprintf_func = kdb_dis_fprintf;
43516 +       kdba_id_init(&kdb_di);
43517 +
43518 +       /*
43519 +        * Allow the user to specify that this instruction
43520 +        * should be treated differently.
43521 +        */
43522 +
43523 +       mode = kdbgetenv("IDMODE");
43524 +       diag = kdba_id_parsemode(mode, &kdb_di);
43525 +       if (diag) {
43526 +               kdb_printf("kdb_id: bad value in 'IDMODE' environment variable ignored\n");
43527 +       }
43528 +
43529 +       (void) kdba_id_printinsn(pc, &kdb_di);
43530 +       kdb_printf("\n");
43531 +}
43532 +
43533 +/*
43534 + * kdb_dis_fprintf
43535 + *
43536 + *     Format and print a string.
43537 + *
43538 + * Parameters:
43539 + *     file    Unused paramter.
43540 + *     fmt     Format string
43541 + *     ...     Optional additional parameters.
43542 + * Returns:
43543 + *     0
43544 + * Locking:
43545 + * Remarks:
43546 + *     Result of format conversion cannot exceed 255 bytes.
43547 + */
43548 +
43549 +int
43550 +kdb_dis_fprintf(PTR file, const char *fmt, ...)
43551 +{
43552 +       char buffer[256];
43553 +       va_list ap;
43554 +
43555 +       va_start(ap, fmt);
43556 +       vsprintf(buffer, fmt, ap);
43557 +       va_end(ap);
43558 +
43559 +       kdb_printf("%s", buffer);
43560 +
43561 +       return 0;
43562 +}
43563 +
43564 +/*
43565 + * kdb_dis_fprintf_dummy
43566 + *
43567 + *     A dummy printf function for the disassembler, it does nothing.
43568 + *     This lets code call the disassembler to step through
43569 + *     instructions without actually printing anything.
43570 + * Inputs:
43571 + *     Always ignored.
43572 + * Outputs:
43573 + *     None.
43574 + * Returns:
43575 + *     Always 0.
43576 + * Locking:
43577 + *     none.
43578 + * Remarks:
43579 + *     None.
43580 + */
43581 +
43582 +int
43583 +kdb_dis_fprintf_dummy(PTR file, const char *fmt, ...)
43584 +{
43585 +       return(0);
43586 +}
43587 +
43588 +/*
43589 + * kdb_disinit
43590 + *
43591 + *     Initialize the disassembly information structure
43592 + *     for the GNU disassembler.
43593 + *
43594 + * Parameters:
43595 + *     None.
43596 + * Outputs:
43597 + *     None.
43598 + * Returns:
43599 + *     Zero for success, a kdb diagnostic if failure.
43600 + * Locking:
43601 + *     None.
43602 + * Remarks:
43603 + */
43604 +
43605 +void __init
43606 +kdb_id_init(void)
43607 +{
43608 +       kdb_di.stream           = NULL;
43609 +       kdb_di.application_data = NULL;
43610 +       kdb_di.symbols          = NULL;
43611 +       kdb_di.num_symbols      = 0;
43612 +       kdb_di.flags            = 0;
43613 +       kdb_di.private_data     = NULL;
43614 +       kdb_di.buffer           = NULL;
43615 +       kdb_di.buffer_vma       = 0;
43616 +       kdb_di.buffer_length    = 0;
43617 +       kdb_di.bytes_per_line   = 0;
43618 +       kdb_di.bytes_per_chunk  = 0;
43619 +       kdb_di.insn_info_valid  = 0;
43620 +       kdb_di.branch_delay_insns = 0;
43621 +       kdb_di.data_size        = 0;
43622 +       kdb_di.insn_type        = 0;
43623 +       kdb_di.target           = 0;
43624 +       kdb_di.target2          = 0;
43625 +}
43626 diff -Nurp linux-2.6.22-590/kdb/kdb_io.c linux-2.6.22-600/kdb/kdb_io.c
43627 --- linux-2.6.22-590/kdb/kdb_io.c       1970-01-01 01:00:00.000000000 +0100
43628 +++ linux-2.6.22-600/kdb/kdb_io.c       2008-04-09 18:14:28.000000000 +0200
43629 @@ -0,0 +1,672 @@
43630 +/*
43631 + * Kernel Debugger Architecture Independent Console I/O handler
43632 + *
43633 + * This file is subject to the terms and conditions of the GNU General Public
43634 + * License.  See the file "COPYING" in the main directory of this archive
43635 + * for more details.
43636 + *
43637 + * Copyright (c) 1999-2006 Silicon Graphics, Inc.  All Rights Reserved.
43638 + */
43639 +
43640 +#include <linux/module.h>
43641 +#include <linux/types.h>
43642 +#include <linux/ctype.h>
43643 +#include <linux/kernel.h>
43644 +#include <linux/init.h>
43645 +#include <linux/kdev_t.h>
43646 +#include <linux/console.h>
43647 +#include <linux/string.h>
43648 +#include <linux/sched.h>
43649 +#include <linux/smp.h>
43650 +#include <linux/nmi.h>
43651 +#include <linux/delay.h>
43652 +
43653 +#include <linux/kdb.h>
43654 +#include <linux/kdbprivate.h>
43655 +#include <linux/kallsyms.h>
43656 +
43657 +static struct console *kdbcons;
43658 +
43659 +#ifdef CONFIG_PPC64
43660 +#include <asm/udbg.h>
43661 +#endif
43662 +
43663 +#define CMD_BUFLEN 256
43664 +char kdb_prompt_str[CMD_BUFLEN];
43665 +
43666 +/*
43667 + * kdb_read
43668 + *
43669 + *     This function reads a string of characters, terminated by
43670 + *     a newline, or by reaching the end of the supplied buffer,
43671 + *     from the current kernel debugger console device.
43672 + * Parameters:
43673 + *     buffer  - Address of character buffer to receive input characters.
43674 + *     bufsize - size, in bytes, of the character buffer
43675 + * Returns:
43676 + *     Returns a pointer to the buffer containing the received
43677 + *     character string.  This string will be terminated by a
43678 + *     newline character.
43679 + * Locking:
43680 + *     No locks are required to be held upon entry to this
43681 + *     function.  It is not reentrant - it relies on the fact
43682 + *     that while kdb is running on any one processor all other
43683 + *     processors will be spinning at the kdb barrier.
43684 + * Remarks:
43685 + *
43686 + * Davidm asks, why doesn't kdb use the console abstraction;
43687 + * here are some reasons:
43688 + *      - you cannot debug the console abstraction with kdb if
43689 + *       kdb uses it.
43690 + *      - you rely on the correct functioning of the abstraction
43691 + *       in the presence of general system failures.
43692 + *      - You must acquire the console spinlock thus restricting
43693 + *       the usability - what if the kernel fails with the spinlock
43694 + *       held - one still wishes to debug such situations.
43695 + *      - How about debugging before the console(s) are registered?
43696 + *      - None of the current consoles (sercons, vt_console_driver)
43697 + *       have read functions defined.
43698 + *     - The standard pc keyboard and terminal drivers are interrupt
43699 + *       driven.   We cannot enable interrupts while kdb is active,
43700 + *       so the standard input functions cannot be used by kdb.
43701 + *
43702 + * An implementation could be improved by removing the need for
43703 + * lock acquisition - just keep a 'struct console *kdbconsole;' global
43704 + * variable which refers to the preferred kdb console.
43705 + *
43706 + * The bulk of this function is architecture dependent.
43707 + *
43708 + * The buffer size must be >= 2.  A buffer size of 2 means that the caller only
43709 + * wants a single key.
43710 + *
43711 + * An escape key could be the start of a vt100 control sequence such as \e[D
43712 + * (left arrow) or it could be a character in its own right.  The standard
43713 + * method for detecting the difference is to wait for 2 seconds to see if there
43714 + * are any other characters.  kdb is complicated by the lack of a timer service
43715 + * (interrupts are off), by multiple input sources and by the need to sometimes
43716 + * return after just one key.  Escape sequence processing has to be done as
43717 + * states in the polling loop.
43718 + */
43719 +
43720 +char *
43721 +kdb_read(char *buffer, size_t bufsize)
43722 +{
43723 +       char *cp = buffer;
43724 +       char *bufend = buffer+bufsize-2;        /* Reserve space for newline and null byte */
43725 +
43726 +       char *lastchar;
43727 +       char *p_tmp;
43728 +       char tmp;
43729 +       static char tmpbuffer[CMD_BUFLEN];
43730 +       int len = strlen(buffer);
43731 +       int len_tmp;
43732 +       int tab=0;
43733 +       int count;
43734 +       int i;
43735 +       int diag, dtab_count;
43736 +
43737 +#define ESCAPE_UDELAY 1000
43738 +#define ESCAPE_DELAY 2*1000000/ESCAPE_UDELAY   /* 2 seconds worth of udelays */
43739 +       char escape_data[5];    /* longest vt100 escape sequence is 4 bytes */
43740 +       char *ped = escape_data;
43741 +       int escape_delay = 0;
43742 +       get_char_func *f, *f_escape = NULL;
43743 +
43744 +       diag = kdbgetintenv("DTABCOUNT",&dtab_count);
43745 +       if (diag)
43746 +               dtab_count = 30;
43747 +
43748 +       if (len > 0 ) {
43749 +               cp += len;
43750 +               if (*(buffer+len-1) == '\n')
43751 +                       cp--;
43752 +       }
43753 +
43754 +       lastchar = cp;
43755 +       *cp = '\0';
43756 +       kdb_printf("%s", buffer);
43757 +
43758 +       for (;;) {
43759 +               int key;
43760 +               for (f = &poll_funcs[0]; ; ++f) {
43761 +                       if (*f == NULL) {
43762 +                               /* Reset NMI watchdog once per poll loop */
43763 +                               touch_nmi_watchdog();
43764 +                               f = &poll_funcs[0];
43765 +                       }
43766 +                       if (escape_delay == 2) {
43767 +                               *ped = '\0';
43768 +                               ped = escape_data;
43769 +                               --escape_delay;
43770 +                       }
43771 +                       if (escape_delay == 1) {
43772 +                               key = *ped++;
43773 +                               if (!*ped)
43774 +                                       --escape_delay;
43775 +                               break;
43776 +                       }
43777 +                       key = (*f)();
43778 +                       if (key == -1) {
43779 +                               if (escape_delay) {
43780 +                                       udelay(ESCAPE_UDELAY);
43781 +                                       --escape_delay;
43782 +                               }
43783 +                               continue;
43784 +                       }
43785 +                       if (bufsize <= 2) {
43786 +                               if (key == '\r')
43787 +                                       key = '\n';
43788 +                               kdb_printf("%c", key);
43789 +                               *buffer++ = key;
43790 +                               *buffer = '\0';
43791 +                               return buffer;
43792 +                       }
43793 +                       if (escape_delay == 0 && key == '\e') {
43794 +                               escape_delay = ESCAPE_DELAY;
43795 +                               ped = escape_data;
43796 +                               f_escape = f;
43797 +                       }
43798 +                       if (escape_delay) {
43799 +                               *ped++ = key;
43800 +                               if (f_escape != f) {
43801 +                                       escape_delay = 2;
43802 +                                       continue;
43803 +                               }
43804 +                               if (ped - escape_data == 1) {
43805 +                                       /* \e */
43806 +                                       continue;
43807 +                               }
43808 +                               else if (ped - escape_data == 2) {
43809 +                                       /* \e<something> */
43810 +                                       if (key != '[')
43811 +                                               escape_delay = 2;
43812 +                                       continue;
43813 +                               } else if (ped - escape_data == 3) {
43814 +                                       /* \e[<something> */
43815 +                                       int mapkey = 0;
43816 +                                       switch (key) {
43817 +                                       case 'A': mapkey = 16; break;   /* \e[A, up arrow */
43818 +                                       case 'B': mapkey = 14; break;   /* \e[B, down arrow */
43819 +                                       case 'C': mapkey = 6; break;    /* \e[C, right arrow */
43820 +                                       case 'D': mapkey = 2; break;    /* \e[D, left arrow */
43821 +                                       case '1': /* dropthrough */
43822 +                                       case '3': /* dropthrough */
43823 +                                       case '4': mapkey = -1; break;   /* \e[<1,3,4>], may be home, del, end */
43824 +                                       }
43825 +                                       if (mapkey != -1) {
43826 +                                               if (mapkey > 0) {
43827 +                                                       escape_data[0] = mapkey;
43828 +                                                       escape_data[1] = '\0';
43829 +                                               }
43830 +                                               escape_delay = 2;
43831 +                                       }
43832 +                                       continue;
43833 +                               } else if (ped - escape_data == 4) {
43834 +                                       /* \e[<1,3,4><something> */
43835 +                                       int mapkey = 0;
43836 +                                       if (key == '~') {
43837 +                                               switch (escape_data[2]) {
43838 +                                               case '1': mapkey = 1; break;    /* \e[1~, home */
43839 +                                               case '3': mapkey = 4; break;    /* \e[3~, del */
43840 +                                               case '4': mapkey = 5; break;    /* \e[4~, end */
43841 +                                               }
43842 +                                       }
43843 +                                       if (mapkey > 0) {
43844 +                                               escape_data[0] = mapkey;
43845 +                                               escape_data[1] = '\0';
43846 +                                       }
43847 +                                       escape_delay = 2;
43848 +                                       continue;
43849 +                               }
43850 +                       }
43851 +                       break;  /* A key to process */
43852 +               }
43853 +
43854 +               if (key != 9)
43855 +                       tab = 0;
43856 +               switch (key) {
43857 +               case 8: /* backspace */
43858 +                       if (cp > buffer) {
43859 +                               if (cp < lastchar) {
43860 +                                       memcpy(tmpbuffer, cp, lastchar - cp);
43861 +                                       memcpy(cp-1, tmpbuffer, lastchar - cp);
43862 +                               }
43863 +                               *(--lastchar) = '\0';
43864 +                               --cp;
43865 +                               kdb_printf("\b%s \r", cp);
43866 +                               tmp = *cp;
43867 +                               *cp = '\0';
43868 +                               kdb_printf(kdb_prompt_str);
43869 +                               kdb_printf("%s", buffer);
43870 +                               *cp = tmp;
43871 +                       }
43872 +                       break;
43873 +               case 13: /* enter */
43874 +                       *lastchar++ = '\n';
43875 +                       *lastchar++ = '\0';
43876 +                       kdb_printf("\n");
43877 +                       return buffer;
43878 +               case 4: /* Del */
43879 +                       if(cp < lastchar) {
43880 +                               memcpy(tmpbuffer, cp+1, lastchar - cp -1);
43881 +                               memcpy(cp, tmpbuffer, lastchar - cp -1);
43882 +                               *(--lastchar) = '\0';
43883 +                               kdb_printf("%s \r", cp);
43884 +                               tmp = *cp;
43885 +                               *cp = '\0';
43886 +                               kdb_printf(kdb_prompt_str);
43887 +                               kdb_printf("%s", buffer);
43888 +                               *cp = tmp;
43889 +                       }
43890 +                       break;
43891 +               case 1: /* Home */
43892 +                       if(cp > buffer) {
43893 +                               kdb_printf("\r");
43894 +                               kdb_printf(kdb_prompt_str);
43895 +                               cp = buffer;
43896 +                       }
43897 +                       break;
43898 +               case 5: /* End */
43899 +                       if(cp < lastchar) {
43900 +                               kdb_printf("%s", cp);
43901 +                               cp = lastchar;
43902 +                       }
43903 +                       break;
43904 +               case 2: /* Left */
43905 +                       if (cp > buffer) {
43906 +                               kdb_printf("\b");
43907 +                               --cp;
43908 +                       }
43909 +                       break;
43910 +               case 14: /* Down */
43911 +                       memset(tmpbuffer, ' ', strlen(kdb_prompt_str)+(lastchar-buffer));
43912 +                       *(tmpbuffer+strlen(kdb_prompt_str)+(lastchar-buffer)) = '\0';
43913 +                       kdb_printf("\r%s\r", tmpbuffer);
43914 +                       *lastchar = (char)key;
43915 +                       *(lastchar+1) = '\0';
43916 +                       return lastchar;
43917 +               case 6: /* Right */
43918 +                       if (cp < lastchar) {
43919 +                               kdb_printf("%c", *cp);
43920 +                               ++cp;
43921 +                       }
43922 +                       break;
43923 +               case 16: /* Up */
43924 +                       memset(tmpbuffer, ' ', strlen(kdb_prompt_str)+(lastchar-buffer));
43925 +                       *(tmpbuffer+strlen(kdb_prompt_str)+(lastchar-buffer)) = '\0';
43926 +                       kdb_printf("\r%s\r", tmpbuffer);
43927 +                       *lastchar = (char)key;
43928 +                       *(lastchar+1) = '\0';
43929 +                       return lastchar;
43930 +               case 9: /* Tab */
43931 +                       if (tab < 2)
43932 +                               ++tab;
43933 +                       p_tmp = buffer;
43934 +                       while(*p_tmp==' ') p_tmp++;
43935 +                       if (p_tmp<=cp) {
43936 +                               memcpy(tmpbuffer, p_tmp, cp-p_tmp);
43937 +                               *(tmpbuffer + (cp-p_tmp)) = '\0';
43938 +                               p_tmp = strrchr(tmpbuffer, ' ');
43939 +                               if (p_tmp)
43940 +                                       ++p_tmp;
43941 +                               else
43942 +                                       p_tmp = tmpbuffer;
43943 +                               len = strlen(p_tmp);
43944 +                               count = kallsyms_symbol_complete(p_tmp, sizeof(tmpbuffer) - (p_tmp - tmpbuffer));
43945 +                               if (tab == 2) {
43946 +                                       if (count > 0) {
43947 +                                               kdb_printf("\n%d symbols are found.", count);
43948 +                                               if(count>dtab_count) {
43949 +                                                       count=dtab_count;
43950 +                                                       kdb_printf(" But only first %d symbols will be printed.\nYou can change the environment variable DTABCOUNT.", count);
43951 +                                               }
43952 +                                               kdb_printf("\n");
43953 +                                               for(i=0;i<count;i++) {
43954 +                                                       if(kallsyms_symbol_next(p_tmp, i)<0)
43955 +                                                               break;
43956 +                                                       kdb_printf("%s ",p_tmp);
43957 +                                                       *(p_tmp+len)='\0';
43958 +                                               }
43959 +                                               if(i>=dtab_count)kdb_printf("...");
43960 +                                               kdb_printf("\n");
43961 +                                               kdb_printf(kdb_prompt_str);
43962 +                                               kdb_printf("%s", buffer);
43963 +                                       }
43964 +                               }
43965 +                               else {
43966 +                                       if (count > 0) {
43967 +                                               len_tmp = strlen(p_tmp);
43968 +                                               strncpy(p_tmp+len_tmp,cp, lastchar-cp+1);
43969 +                                               len_tmp = strlen(p_tmp);
43970 +                                               strncpy(cp, p_tmp+len, len_tmp-len+1);
43971 +                                               len = len_tmp - len;
43972 +                                               kdb_printf("%s", cp);
43973 +                                               cp+=len;
43974 +                                               lastchar+=len;
43975 +                                       }
43976 +                               }
43977 +                               kdb_nextline = 1;               /* reset output line number */
43978 +                       }
43979 +                       break;
43980 +               default:
43981 +                       if (key >= 32 &&lastchar < bufend) {
43982 +                               if (cp < lastchar) {
43983 +                                       memcpy(tmpbuffer, cp, lastchar - cp);
43984 +                                       memcpy(cp+1, tmpbuffer, lastchar - cp);
43985 +                                       *++lastchar = '\0';
43986 +                                       *cp = key;
43987 +                                       kdb_printf("%s\r", cp);
43988 +                                       ++cp;
43989 +                                       tmp = *cp;
43990 +                                       *cp = '\0';
43991 +                                       kdb_printf(kdb_prompt_str);
43992 +                                       kdb_printf("%s", buffer);
43993 +                                       *cp = tmp;
43994 +                               } else {
43995 +                                       *++lastchar = '\0';
43996 +                                       *cp++ = key;
43997 +                                       kdb_printf("%c", key);
43998 +                               }
43999 +                       }
44000 +                       break;
44001 +               }
44002 +       }
44003 +}
44004 +
44005 +/*
44006 + * kdb_getstr
44007 + *
44008 + *     Print the prompt string and read a command from the
44009 + *     input device.
44010 + *
44011 + * Parameters:
44012 + *     buffer  Address of buffer to receive command
44013 + *     bufsize Size of buffer in bytes
44014 + *     prompt  Pointer to string to use as prompt string
44015 + * Returns:
44016 + *     Pointer to command buffer.
44017 + * Locking:
44018 + *     None.
44019 + * Remarks:
44020 + *     For SMP kernels, the processor number will be
44021 + *     substituted for %d, %x or %o in the prompt.
44022 + */
44023 +
44024 +char *
44025 +kdb_getstr(char *buffer, size_t bufsize, char *prompt)
44026 +{
44027 +       if(prompt && kdb_prompt_str!=prompt)
44028 +               strncpy(kdb_prompt_str, prompt, CMD_BUFLEN);
44029 +       kdb_printf(kdb_prompt_str);
44030 +       kdb_nextline = 1;       /* Prompt and input resets line number */
44031 +       return kdb_read(buffer, bufsize);
44032 +}
44033 +
44034 +/*
44035 + * kdb_input_flush
44036 + *
44037 + *     Get rid of any buffered console input.
44038 + *
44039 + * Parameters:
44040 + *     none
44041 + * Returns:
44042 + *     nothing
44043 + * Locking:
44044 + *     none
44045 + * Remarks:
44046 + *     Call this function whenever you want to flush input.  If there is any
44047 + *     outstanding input, it ignores all characters until there has been no
44048 + *     data for approximately half a second.
44049 + */
44050 +
44051 +#define FLUSH_UDELAY 100
44052 +#define FLUSH_DELAY 500000/FLUSH_UDELAY        /* 0.5 seconds worth of udelays */
44053 +
44054 +static void
44055 +kdb_input_flush(void)
44056 +{
44057 +       get_char_func *f;
44058 +       int flush_delay = 1;
44059 +       while (flush_delay--) {
44060 +               touch_nmi_watchdog();
44061 +               for (f = &poll_funcs[0]; *f; ++f) {
44062 +                       if ((*f)() != -1) {
44063 +                               flush_delay = FLUSH_DELAY;
44064 +                               break;
44065 +                       }
44066 +               }
44067 +               if (flush_delay)
44068 +                       udelay(FLUSH_UDELAY);
44069 +       }
44070 +}
44071 +
44072 +/*
44073 + * kdb_printf
44074 + *
44075 + *     Print a string to the output device(s).
44076 + *
44077 + * Parameters:
44078 + *     printf-like format and optional args.
44079 + * Returns:
44080 + *     0
44081 + * Locking:
44082 + *     None.
44083 + * Remarks:
44084 + *     use 'kdbcons->write()' to avoid polluting 'log_buf' with
44085 + *     kdb output.
44086 + */
44087 +
44088 +static char kdb_buffer[256];   /* A bit too big to go on stack */
44089 +
44090 +void
44091 +kdb_printf(const char *fmt, ...)
44092 +{
44093 +       va_list ap;
44094 +       int diag;
44095 +       int linecount;
44096 +       int logging, saved_loglevel = 0;
44097 +       int do_longjmp = 0;
44098 +       int got_printf_lock = 0;
44099 +       struct console *c = console_drivers;
44100 +       static DEFINE_SPINLOCK(kdb_printf_lock);
44101 +       unsigned long uninitialized_var(flags);
44102 +
44103 +       preempt_disable();
44104 +       /* Serialize kdb_printf if multiple cpus try to write at once.
44105 +        * But if any cpu goes recursive in kdb, just print the output,
44106 +        * even if it is interleaved with any other text.
44107 +        */
44108 +       if (!KDB_STATE(PRINTF_LOCK)) {
44109 +               KDB_STATE_SET(PRINTF_LOCK);
44110 +               spin_lock_irqsave(&kdb_printf_lock, flags);
44111 +               got_printf_lock = 1;
44112 +               atomic_inc(&kdb_event);
44113 +       } else {
44114 +               __acquire(kdb_printf_lock);
44115 +       }
44116 +
44117 +       diag = kdbgetintenv("LINES", &linecount);
44118 +       if (diag || linecount <= 1)
44119 +               linecount = 22;
44120 +
44121 +       diag = kdbgetintenv("LOGGING", &logging);
44122 +       if (diag)
44123 +               logging = 0;
44124 +
44125 +       va_start(ap, fmt);
44126 +       vsnprintf(kdb_buffer, sizeof(kdb_buffer), fmt, ap);
44127 +       va_end(ap);
44128 +
44129 +       /*
44130 +        * Write to all consoles.
44131 +        */
44132 +#ifdef CONFIG_SPARC64
44133 +       if (c == NULL)
44134 +               prom_printf("%s", kdb_buffer);
44135 +       else
44136 +#endif
44137 +
44138 +#ifdef CONFIG_PPC64
44139 +       if (udbg_write)
44140 +               udbg_write(kdb_buffer, strlen(kdb_buffer));
44141 +       else
44142 +#endif
44143 +
44144 +       while (c) {
44145 +               c->write(c, kdb_buffer, strlen(kdb_buffer));
44146 +               c = c->next;
44147 +       }
44148 +       if (logging) {
44149 +               saved_loglevel = console_loglevel;
44150 +               console_loglevel = 0;
44151 +               printk("%s", kdb_buffer);
44152 +       }
44153 +
44154 +       if (KDB_STATE(LONGJMP) && strchr(kdb_buffer, '\n'))
44155 +               kdb_nextline++;
44156 +
44157 +       if (kdb_nextline == linecount) {
44158 +               char buf1[16]="";
44159 +#if defined(CONFIG_SMP)
44160 +               char buf2[32];
44161 +#endif
44162 +               char *moreprompt;
44163 +
44164 +               /* Watch out for recursion here.  Any routine that calls
44165 +                * kdb_printf will come back through here.  And kdb_read
44166 +                * uses kdb_printf to echo on serial consoles ...
44167 +                */
44168 +               kdb_nextline = 1;       /* In case of recursion */
44169 +
44170 +               /*
44171 +                * Pause until cr.
44172 +                */
44173 +               moreprompt = kdbgetenv("MOREPROMPT");
44174 +               if (moreprompt == NULL) {
44175 +                       moreprompt = "more> ";
44176 +               }
44177 +
44178 +#if defined(CONFIG_SMP)
44179 +               if (strchr(moreprompt, '%')) {
44180 +                       sprintf(buf2, moreprompt, get_cpu());
44181 +                       put_cpu();
44182 +                       moreprompt = buf2;
44183 +               }
44184 +#endif
44185 +
44186 +               kdb_input_flush();
44187 +               c = console_drivers;
44188 +#ifdef CONFIG_SPARC64
44189 +               if (c == NULL)
44190 +                       prom_printf("%s", moreprompt);
44191 +               else
44192 +#endif
44193 +
44194 +#ifdef CONFIG_PPC64
44195 +               if (udbg_write)
44196 +                       udbg_write(moreprompt, strlen(moreprompt));
44197 +               else
44198 +#endif
44199 +
44200 +               while (c) {
44201 +                       c->write(c, moreprompt, strlen(moreprompt));
44202 +                       c = c->next;
44203 +               }
44204 +
44205 +               if (logging)
44206 +                       printk("%s", moreprompt);
44207 +
44208 +               kdb_read(buf1, 2); /* '2' indicates to return immediately after getting one key. */
44209 +               kdb_nextline = 1;       /* Really set output line 1 */
44210 +
44211 +               if ((buf1[0] == 'q') || (buf1[0] == 'Q')) {
44212 +                       do_longjmp = 1;
44213 +                       KDB_FLAG_SET(CMD_INTERRUPT);    /* command was interrupted */
44214 +                       kdb_printf("\n");
44215 +               }
44216 +               else if (buf1[0] && buf1[0] != '\n') {
44217 +                       kdb_printf("\nOnly 'q' or 'Q' are processed at more prompt, input ignored\n");
44218 +               }
44219 +               kdb_input_flush();
44220 +       }
44221 +
44222 +       if (logging) {
44223 +               console_loglevel = saved_loglevel;
44224 +       }
44225 +       if (KDB_STATE(PRINTF_LOCK) && got_printf_lock) {
44226 +               got_printf_lock = 0;
44227 +               spin_unlock_irqrestore(&kdb_printf_lock, flags);
44228 +               KDB_STATE_CLEAR(PRINTF_LOCK);
44229 +               atomic_dec(&kdb_event);
44230 +       } else {
44231 +               __release(kdb_printf_lock);
44232 +       }
44233 +       preempt_enable();
44234 +       if (do_longjmp)
44235 +#ifdef kdba_setjmp
44236 +               kdba_longjmp(&kdbjmpbuf[smp_processor_id()], 1)
44237 +#endif /* kdba_setjmp */
44238 +               ;
44239 +}
44240 +
44241 +/*
44242 + * kdb_io_init
44243 + *
44244 + *     Initialize kernel debugger output environment.
44245 + *
44246 + * Parameters:
44247 + *     None.
44248 + * Returns:
44249 + *     None.
44250 + * Locking:
44251 + *     None.
44252 + * Remarks:
44253 + *     Select a console device.  Only use a VT console if the user specified
44254 + *     or defaulted console= /^tty[0-9]*$/
44255 + *
44256 + *     FIXME: 2.6.22-rc1 initializes the serial console long after kdb starts,
44257 + *     so booting with 'console=tty console=ttyS0' does not create the console
44258 + *     entry for ttyS0 in time.  For now simply assume that we have a working
44259 + *     console, until a better solution can be found.
44260 + */
44261 +
44262 +void __init
44263 +kdb_io_init(void)
44264 +{
44265 +       /*
44266 +        * Select a console.
44267 +        */
44268 +       struct console *c = console_drivers;
44269 +       int vt_console = 0;
44270 +
44271 +       while (c) {
44272 +#if 0 /* FIXME: we don't register serial consoles in time */
44273 +               if ((c->flags & CON_CONSDEV) && !kdbcons)
44274 +                       kdbcons = c;
44275 +#else
44276 +               if (!kdbcons)
44277 +                       kdbcons = c;
44278 +#endif
44279 +               if ((c->flags & CON_ENABLED) &&
44280 +                   strncmp(c->name, "tty", 3) == 0) {
44281 +                       char *p = c->name + 3;
44282 +                       while (isdigit(*p))
44283 +                               ++p;
44284 +                       if (*p == '\0')
44285 +                               vt_console = 1;
44286 +               }
44287 +               c = c->next;
44288 +       }
44289 +
44290 +       if (kdbcons == NULL) {
44291 +               printk(KERN_ERR "kdb: Initialization failed - no console.  kdb is disabled.\n");
44292 +               KDB_FLAG_SET(NO_CONSOLE);
44293 +               kdb_on = 0;
44294 +       }
44295 +       if (!vt_console)
44296 +               KDB_FLAG_SET(NO_VT_CONSOLE);
44297 +       kdb_input_flush();
44298 +       return;
44299 +}
44300 +
44301 +EXPORT_SYMBOL(kdb_read);
44302 diff -Nurp linux-2.6.22-590/kdb/kdbmain.c linux-2.6.22-600/kdb/kdbmain.c
44303 --- linux-2.6.22-590/kdb/kdbmain.c      1970-01-01 01:00:00.000000000 +0100
44304 +++ linux-2.6.22-600/kdb/kdbmain.c      2008-04-09 18:14:28.000000000 +0200
44305 @@ -0,0 +1,4034 @@
44306 +/*
44307 + * Kernel Debugger Architecture Independent Main Code
44308 + *
44309 + * This file is subject to the terms and conditions of the GNU General Public
44310 + * License.  See the file "COPYING" in the main directory of this archive
44311 + * for more details.
44312 + *
44313 + * Copyright (C) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
44314 + * Copyright (C) 2000 Stephane Eranian <eranian@hpl.hp.com>
44315 + * Xscale (R) modifications copyright (C) 2003 Intel Corporation.
44316 + */
44317 +
44318 +/*
44319 + * Updated for Xscale (R) architecture support
44320 + * Eddie Dong <eddie.dong@intel.com> 8 Jan 03
44321 + */
44322 +
44323 +#include <linux/ctype.h>
44324 +#include <linux/string.h>
44325 +#include <linux/kernel.h>
44326 +#include <linux/reboot.h>
44327 +#include <linux/sched.h>
44328 +#include <linux/sysrq.h>
44329 +#include <linux/smp.h>
44330 +#include <linux/utsname.h>
44331 +#include <linux/vmalloc.h>
44332 +#include <linux/module.h>
44333 +#include <linux/mm.h>
44334 +#include <linux/init.h>
44335 +#include <linux/kallsyms.h>
44336 +#include <linux/kdb.h>
44337 +#include <linux/kdbprivate.h>
44338 +#include <linux/notifier.h>
44339 +#include <linux/interrupt.h>
44340 +#include <linux/delay.h>
44341 +#include <linux/nmi.h>
44342 +#include <linux/ptrace.h>
44343 +#include <linux/sysctl.h>
44344 +#if defined(CONFIG_LKCD_DUMP) || defined(CONFIG_LKCD_DUMP_MODULE)
44345 +#include <linux/dump.h>
44346 +#endif
44347 +#include <linux/cpu.h>
44348 +#include <linux/kdebug.h>
44349 +
44350 +#include <acpi/acpi_bus.h>
44351 +
44352 +#include <asm/system.h>
44353 +#include <asm/kdebug.h>
44354 +
44355 +/*
44356 + * Kernel debugger state flags
44357 + */
44358 +volatile int kdb_flags;
44359 +atomic_t kdb_event;
44360 +atomic_t kdb_8250;
44361 +
44362 +/*
44363 + * kdb_lock protects updates to kdb_initial_cpu.  Used to
44364 + * single thread processors through the kernel debugger.
44365 + */
44366 +static DEFINE_SPINLOCK(kdb_lock);
44367 +volatile int kdb_initial_cpu = -1;             /* cpu number that owns kdb */
44368 +int kdb_seqno = 2;                             /* how many times kdb has been entered */
44369 +
44370 +volatile int kdb_nextline = 1;
44371 +static volatile int kdb_new_cpu;               /* Which cpu to switch to */
44372 +
44373 +volatile int kdb_state[NR_CPUS];               /* Per cpu state */
44374 +
44375 +const struct task_struct *kdb_current_task;
44376 +EXPORT_SYMBOL(kdb_current_task);
44377 +struct pt_regs *kdb_current_regs;
44378 +
44379 +#ifdef CONFIG_KDB_OFF
44380 +int kdb_on = 0;                                /* Default is off */
44381 +#else
44382 +int kdb_on = 1;                                /* Default is on */
44383 +#endif /* CONFIG_KDB_OFF */
44384 +
44385 +const char *kdb_diemsg;
44386 +static int kdb_go_count;
44387 +#ifdef CONFIG_KDB_CONTINUE_CATASTROPHIC
44388 +static unsigned int kdb_continue_catastrophic = CONFIG_KDB_CONTINUE_CATASTROPHIC;
44389 +#else
44390 +static unsigned int kdb_continue_catastrophic = 0;
44391 +#endif
44392 +
44393 +#ifdef kdba_setjmp
44394 +       /*
44395 +        * Must have a setjmp buffer per CPU.  Switching cpus will
44396 +        * cause the jump buffer to be setup for the new cpu, and
44397 +        * subsequent switches (and pager aborts) will use the
44398 +        * appropriate per-processor values.
44399 +        */
44400 +kdb_jmp_buf *kdbjmpbuf;
44401 +#endif /* kdba_setjmp */
44402 +
44403 +       /*
44404 +        * kdb_commands describes the available commands.
44405 +        */
44406 +static kdbtab_t *kdb_commands;
44407 +static int kdb_max_commands;
44408 +
44409 +typedef struct _kdbmsg {
44410 +       int     km_diag;        /* kdb diagnostic */
44411 +       char    *km_msg;        /* Corresponding message text */
44412 +} kdbmsg_t;
44413 +
44414 +#define KDBMSG(msgnum, text) \
44415 +       { KDB_##msgnum, text }
44416 +
44417 +static kdbmsg_t kdbmsgs[] = {
44418 +       KDBMSG(NOTFOUND,"Command Not Found"),
44419 +       KDBMSG(ARGCOUNT, "Improper argument count, see usage."),
44420 +       KDBMSG(BADWIDTH, "Illegal value for BYTESPERWORD use 1, 2, 4 or 8, 8 is only allowed on 64 bit systems"),
44421 +       KDBMSG(BADRADIX, "Illegal value for RADIX use 8, 10 or 16"),
44422 +       KDBMSG(NOTENV, "Cannot find environment variable"),
44423 +       KDBMSG(NOENVVALUE, "Environment variable should have value"),
44424 +       KDBMSG(NOTIMP, "Command not implemented"),
44425 +       KDBMSG(ENVFULL, "Environment full"),
44426 +       KDBMSG(ENVBUFFULL, "Environment buffer full"),
44427 +       KDBMSG(TOOMANYBPT, "Too many breakpoints defined"),
44428 +#ifdef  CONFIG_CPU_XSCALE
44429 +       KDBMSG(TOOMANYDBREGS, "More breakpoints than ibcr registers defined"),
44430 +#else
44431 +       KDBMSG(TOOMANYDBREGS, "More breakpoints than db registers defined"),
44432 +#endif
44433 +       KDBMSG(DUPBPT, "Duplicate breakpoint address"),
44434 +       KDBMSG(BPTNOTFOUND, "Breakpoint not found"),
44435 +       KDBMSG(BADMODE, "Invalid IDMODE"),
44436 +       KDBMSG(BADINT, "Illegal numeric value"),
44437 +       KDBMSG(INVADDRFMT, "Invalid symbolic address format"),
44438 +       KDBMSG(BADREG, "Invalid register name"),
44439 +       KDBMSG(BADCPUNUM, "Invalid cpu number"),
44440 +       KDBMSG(BADLENGTH, "Invalid length field"),
44441 +       KDBMSG(NOBP, "No Breakpoint exists"),
44442 +       KDBMSG(BADADDR, "Invalid address"),
44443 +};
44444 +#undef KDBMSG
44445 +
44446 +static const int __nkdb_err = sizeof(kdbmsgs) / sizeof(kdbmsg_t);
44447 +
44448 +
44449 +/*
44450 + * Initial environment.   This is all kept static and local to
44451 + * this file.   We don't want to rely on the memory allocation
44452 + * mechanisms in the kernel, so we use a very limited allocate-only
44453 + * heap for new and altered environment variables.  The entire
44454 + * environment is limited to a fixed number of entries (add more
44455 + * to __env[] if required) and a fixed amount of heap (add more to
44456 + * KDB_ENVBUFSIZE if required).
44457 + */
44458 +
44459 +static char *__env[] = {
44460 +#if defined(CONFIG_SMP)
44461 + "PROMPT=[%d]kdb> ",
44462 + "MOREPROMPT=[%d]more> ",
44463 +#else
44464 + "PROMPT=kdb> ",
44465 + "MOREPROMPT=more> ",
44466 +#endif
44467 + "RADIX=16",
44468 + "LINES=24",
44469 + "COLUMNS=80",
44470 + "MDCOUNT=8",                  /* lines of md output */
44471 + "BTARGS=9",                   /* 9 possible args in bt */
44472 + KDB_PLATFORM_ENV,
44473 + "DTABCOUNT=30",
44474 + "NOSECT=1",
44475 + (char *)0,
44476 + (char *)0,
44477 + (char *)0,
44478 + (char *)0,
44479 + (char *)0,
44480 + (char *)0,
44481 + (char *)0,
44482 + (char *)0,
44483 + (char *)0,
44484 + (char *)0,
44485 + (char *)0,
44486 + (char *)0,
44487 + (char *)0,
44488 + (char *)0,
44489 + (char *)0,
44490 + (char *)0,
44491 + (char *)0,
44492 + (char *)0,
44493 + (char *)0,
44494 + (char *)0,
44495 + (char *)0,
44496 + (char *)0,
44497 + (char *)0,
44498 +};
44499 +
44500 +static const int __nenv = (sizeof(__env) / sizeof(char *));
44501 +
44502 +/*
44503 + * kdb_serial_str is the sequence that the user must enter on a serial
44504 + * console to invoke kdb.  It can be a single character such as "\001"
44505 + * (control-A) or multiple characters such as "\eKDB".  NOTE: All except the
44506 + * last character are passed through to the application reading from the serial
44507 + * console.
44508 + *
44509 + * I tried to make the sequence a CONFIG_ option but most of CML1 cannot cope
44510 + * with '\' in strings.  CML2 would have been able to do it but we lost CML2.
44511 + * KAO.
44512 + */
44513 +const char kdb_serial_str[] = "\eKDB";
44514 +EXPORT_SYMBOL(kdb_serial_str);
44515 +
44516 +struct task_struct *
44517 +kdb_curr_task(int cpu)
44518 +{
44519 +       struct task_struct *p = curr_task(cpu);
44520 +#ifdef _TIF_MCA_INIT
44521 +       struct kdb_running_process *krp = kdb_running_process + cpu;
44522 +       if ((task_thread_info(p)->flags & _TIF_MCA_INIT) && krp->p)
44523 +               p = krp->p;
44524 +#endif
44525 +       return p;
44526 +}
44527 +
44528 +/*
44529 + * kdbgetenv
44530 + *
44531 + *     This function will return the character string value of
44532 + *     an environment variable.
44533 + *
44534 + * Parameters:
44535 + *     match   A character string representing an environment variable.
44536 + * Outputs:
44537 + *     None.
44538 + * Returns:
44539 + *     NULL    No environment variable matches 'match'
44540 + *     char*   Pointer to string value of environment variable.
44541 + * Locking:
44542 + *     No locking considerations required.
44543 + * Remarks:
44544 + */
44545 +char *
44546 +kdbgetenv(const char *match)
44547 +{
44548 +       char **ep = __env;
44549 +       int matchlen = strlen(match);
44550 +       int i;
44551 +
44552 +       for(i=0; i<__nenv; i++) {
44553 +               char *e = *ep++;
44554 +
44555 +               if (!e) continue;
44556 +
44557 +               if ((strncmp(match, e, matchlen) == 0)
44558 +                && ((e[matchlen] == '\0')
44559 +                  ||(e[matchlen] == '='))) {
44560 +                       char *cp = strchr(e, '=');
44561 +                       return (cp ? ++cp :"");
44562 +               }
44563 +       }
44564 +       return NULL;
44565 +}
44566 +
44567 +/*
44568 + * kdballocenv
44569 + *
44570 + *     This function is used to allocate bytes for environment entries.
44571 + *
44572 + * Parameters:
44573 + *     match   A character string representing a numeric value
44574 + * Outputs:
44575 + *     *value  the unsigned long represntation of the env variable 'match'
44576 + * Returns:
44577 + *     Zero on success, a kdb diagnostic on failure.
44578 + * Locking:
44579 + *     No locking considerations required.  Must be called with all
44580 + *     processors halted.
44581 + * Remarks:
44582 + *     We use a static environment buffer (envbuffer) to hold the values
44583 + *     of dynamically generated environment variables (see kdb_set).  Buffer
44584 + *     space once allocated is never free'd, so over time, the amount of space
44585 + *     (currently 512 bytes) will be exhausted if env variables are changed
44586 + *     frequently.
44587 + */
44588 +static char *
44589 +kdballocenv(size_t bytes)
44590 +{
44591 +#define        KDB_ENVBUFSIZE  512
44592 +       static char envbuffer[KDB_ENVBUFSIZE];
44593 +       static int envbufsize;
44594 +       char *ep = NULL;
44595 +
44596 +       if ((KDB_ENVBUFSIZE - envbufsize) >= bytes) {
44597 +               ep = &envbuffer[envbufsize];
44598 +               envbufsize += bytes;
44599 +       }
44600 +       return ep;
44601 +}
44602 +
44603 +/*
44604 + * kdbgetulenv
44605 + *
44606 + *     This function will return the value of an unsigned long-valued
44607 + *     environment variable.
44608 + *
44609 + * Parameters:
44610 + *     match   A character string representing a numeric value
44611 + * Outputs:
44612 + *     *value  the unsigned long represntation of the env variable 'match'
44613 + * Returns:
44614 + *     Zero on success, a kdb diagnostic on failure.
44615 + * Locking:
44616 + *     No locking considerations required.
44617 + * Remarks:
44618 + */
44619 +
44620 +static int
44621 +kdbgetulenv(const char *match, unsigned long *value)
44622 +{
44623 +       char *ep;
44624 +
44625 +       ep = kdbgetenv(match);
44626 +       if (!ep) return KDB_NOTENV;
44627 +       if (strlen(ep) == 0) return KDB_NOENVVALUE;
44628 +
44629 +       *value = simple_strtoul(ep, NULL, 0);
44630 +
44631 +       return 0;
44632 +}
44633 +
44634 +/*
44635 + * kdbgetintenv
44636 + *
44637 + *     This function will return the value of an integer-valued
44638 + *     environment variable.
44639 + *
44640 + * Parameters:
44641 + *     match   A character string representing an integer-valued env variable
44642 + * Outputs:
44643 + *     *value  the integer representation of the environment variable 'match'
44644 + * Returns:
44645 + *     Zero on success, a kdb diagnostic on failure.
44646 + * Locking:
44647 + *     No locking considerations required.
44648 + * Remarks:
44649 + */
44650 +
44651 +int
44652 +kdbgetintenv(const char *match, int *value) {
44653 +       unsigned long val;
44654 +       int diag;
44655 +
44656 +       diag = kdbgetulenv(match, &val);
44657 +       if (!diag) {
44658 +               *value = (int) val;
44659 +       }
44660 +       return diag;
44661 +}
44662 +
44663 +/*
44664 + * kdbgetularg
44665 + *
44666 + *     This function will convert a numeric string
44667 + *     into an unsigned long value.
44668 + *
44669 + * Parameters:
44670 + *     arg     A character string representing a numeric value
44671 + * Outputs:
44672 + *     *value  the unsigned long represntation of arg.
44673 + * Returns:
44674 + *     Zero on success, a kdb diagnostic on failure.
44675 + * Locking:
44676 + *     No locking considerations required.
44677 + * Remarks:
44678 + */
44679 +
44680 +int
44681 +kdbgetularg(const char *arg, unsigned long *value)
44682 +{
44683 +       char *endp;
44684 +       unsigned long val;
44685 +
44686 +       val = simple_strtoul(arg, &endp, 0);
44687 +
44688 +       if (endp == arg) {
44689 +               /*
44690 +                * Try base 16, for us folks too lazy to type the
44691 +                * leading 0x...
44692 +                */
44693 +               val = simple_strtoul(arg, &endp, 16);
44694 +               if (endp == arg)
44695 +                       return KDB_BADINT;
44696 +       }
44697 +
44698 +       *value = val;
44699 +
44700 +       return 0;
44701 +}
44702 +
44703 +/*
44704 + * kdb_set
44705 + *
44706 + *     This function implements the 'set' command.  Alter an existing
44707 + *     environment variable or create a new one.
44708 + *
44709 + * Inputs:
44710 + *     argc    argument count
44711 + *     argv    argument vector
44712 + * Outputs:
44713 + *     None.
44714 + * Returns:
44715 + *     zero for success, a kdb diagnostic if error
44716 + * Locking:
44717 + *     none.
44718 + * Remarks:
44719 + */
44720 +
44721 +static int
44722 +kdb_set(int argc, const char **argv)
44723 +{
44724 +       int i;
44725 +       char *ep;
44726 +       size_t varlen, vallen;
44727 +
44728 +       /*
44729 +        * we can be invoked two ways:
44730 +        *   set var=value    argv[1]="var", argv[2]="value"
44731 +        *   set var = value  argv[1]="var", argv[2]="=", argv[3]="value"
44732 +        * - if the latter, shift 'em down.
44733 +        */
44734 +       if (argc == 3) {
44735 +               argv[2] = argv[3];
44736 +               argc--;
44737 +       }
44738 +
44739 +       if (argc != 2)
44740 +               return KDB_ARGCOUNT;
44741 +
44742 +       /*
44743 +        * Check for internal variables
44744 +        */
44745 +       if (strcmp(argv[1], "KDBDEBUG") == 0) {
44746 +               unsigned int debugflags;
44747 +               char *cp;
44748 +
44749 +               debugflags = simple_strtoul(argv[2], &cp, 0);
44750 +               if (cp == argv[2] || debugflags & ~KDB_DEBUG_FLAG_MASK) {
44751 +                       kdb_printf("kdb: illegal debug flags '%s'\n",
44752 +                                   argv[2]);
44753 +                       return 0;
44754 +               }
44755 +               kdb_flags = (kdb_flags & ~(KDB_DEBUG_FLAG_MASK << KDB_DEBUG_FLAG_SHIFT))
44756 +                         | (debugflags << KDB_DEBUG_FLAG_SHIFT);
44757 +
44758 +               return 0;
44759 +       }
44760 +
44761 +       /*
44762 +        * Tokenizer squashed the '=' sign.  argv[1] is variable
44763 +        * name, argv[2] = value.
44764 +        */
44765 +       varlen = strlen(argv[1]);
44766 +       vallen = strlen(argv[2]);
44767 +       ep = kdballocenv(varlen + vallen + 2);
44768 +       if (ep == (char *)0)
44769 +               return KDB_ENVBUFFULL;
44770 +
44771 +       sprintf(ep, "%s=%s", argv[1], argv[2]);
44772 +
44773 +       ep[varlen+vallen+1]='\0';
44774 +
44775 +       for(i=0; i<__nenv; i++) {
44776 +               if (__env[i]
44777 +                && ((strncmp(__env[i], argv[1], varlen)==0)
44778 +                  && ((__env[i][varlen] == '\0')
44779 +                   || (__env[i][varlen] == '=')))) {
44780 +                       __env[i] = ep;
44781 +                       return 0;
44782 +               }
44783 +       }
44784 +
44785 +       /*
44786 +        * Wasn't existing variable.  Fit into slot.
44787 +        */
44788 +       for(i=0; i<__nenv-1; i++) {
44789 +               if (__env[i] == (char *)0) {
44790 +                       __env[i] = ep;
44791 +                       return 0;
44792 +               }
44793 +       }
44794 +
44795 +       return KDB_ENVFULL;
44796 +}
44797 +
44798 +static int
44799 +kdb_check_regs(void)
44800 +{
44801 +       if (!kdb_current_regs) {
44802 +               kdb_printf("No current kdb registers."
44803 +                          "  You may need to select another task\n");
44804 +               return KDB_BADREG;
44805 +       }
44806 +       return 0;
44807 +}
44808 +
44809 +/*
44810 + * kdbgetaddrarg
44811 + *
44812 + *     This function is responsible for parsing an
44813 + *     address-expression and returning the value of
44814 + *     the expression, symbol name, and offset to the caller.
44815 + *
44816 + *     The argument may consist of a numeric value (decimal or
44817 + *     hexidecimal), a symbol name, a register name (preceeded
44818 + *     by the percent sign), an environment variable with a numeric
44819 + *     value (preceeded by a dollar sign) or a simple arithmetic
44820 + *     expression consisting of a symbol name, +/-, and a numeric
44821 + *     constant value (offset).
44822 + *
44823 + * Parameters:
44824 + *     argc    - count of arguments in argv
44825 + *     argv    - argument vector
44826 + *     *nextarg - index to next unparsed argument in argv[]
44827 + *     regs    - Register state at time of KDB entry
44828 + * Outputs:
44829 + *     *value  - receives the value of the address-expression
44830 + *     *offset - receives the offset specified, if any
44831 + *     *name   - receives the symbol name, if any
44832 + *     *nextarg - index to next unparsed argument in argv[]
44833 + *
44834 + * Returns:
44835 + *     zero is returned on success, a kdb diagnostic code is
44836 + *      returned on error.
44837 + *
44838 + * Locking:
44839 + *     No locking requirements.
44840 + *
44841 + * Remarks:
44842 + *
44843 + */
44844 +
44845 +int
44846 +kdbgetaddrarg(int argc, const char **argv, int *nextarg,
44847 +             kdb_machreg_t *value,  long *offset,
44848 +             char **name)
44849 +{
44850 +       kdb_machreg_t addr;
44851 +       unsigned long off = 0;
44852 +       int positive;
44853 +       int diag;
44854 +       int found = 0;
44855 +       char *symname;
44856 +       char symbol = '\0';
44857 +       char *cp;
44858 +       kdb_symtab_t symtab;
44859 +
44860 +       /*
44861 +        * Process arguments which follow the following syntax:
44862 +        *
44863 +        *  symbol | numeric-address [+/- numeric-offset]
44864 +        *  %register
44865 +        *  $environment-variable
44866 +        */
44867 +
44868 +       if (*nextarg > argc) {
44869 +               return KDB_ARGCOUNT;
44870 +       }
44871 +
44872 +       symname = (char *)argv[*nextarg];
44873 +
44874 +       /*
44875 +        * If there is no whitespace between the symbol
44876 +        * or address and the '+' or '-' symbols, we
44877 +        * remember the character and replace it with a
44878 +        * null so the symbol/value can be properly parsed
44879 +        */
44880 +       if ((cp = strpbrk(symname, "+-")) != NULL) {
44881 +               symbol = *cp;
44882 +               *cp++ = '\0';
44883 +       }
44884 +
44885 +       if (symname[0] == '$') {
44886 +               diag = kdbgetulenv(&symname[1], &addr);
44887 +               if (diag)
44888 +                       return diag;
44889 +       } else if (symname[0] == '%') {
44890 +               if ((diag = kdb_check_regs()))
44891 +                       return diag;
44892 +               diag = kdba_getregcontents(&symname[1], kdb_current_regs, &addr);
44893 +               if (diag)
44894 +                       return diag;
44895 +       } else {
44896 +               found = kdbgetsymval(symname, &symtab);
44897 +               if (found) {
44898 +                       addr = symtab.sym_start;
44899 +               } else {
44900 +                       diag = kdbgetularg(argv[*nextarg], &addr);
44901 +                       if (diag)
44902 +                               return diag;
44903 +               }
44904 +       }
44905 +
44906 +       if (!found)
44907 +               found = kdbnearsym(addr, &symtab);
44908 +
44909 +       (*nextarg)++;
44910 +
44911 +       if (name)
44912 +               *name = symname;
44913 +       if (value)
44914 +               *value = addr;
44915 +       if (offset && name && *name)
44916 +               *offset = addr - symtab.sym_start;
44917 +
44918 +       if ((*nextarg > argc)
44919 +        && (symbol == '\0'))
44920 +               return 0;
44921 +
44922 +       /*
44923 +        * check for +/- and offset
44924 +        */
44925 +
44926 +       if (symbol == '\0') {
44927 +               if ((argv[*nextarg][0] != '+')
44928 +                && (argv[*nextarg][0] != '-')) {
44929 +                       /*
44930 +                        * Not our argument.  Return.
44931 +                        */
44932 +                       return 0;
44933 +               } else {
44934 +                       positive = (argv[*nextarg][0] == '+');
44935 +                       (*nextarg)++;
44936 +               }
44937 +       } else
44938 +               positive = (symbol == '+');
44939 +
44940 +       /*
44941 +        * Now there must be an offset!
44942 +        */
44943 +       if ((*nextarg > argc)
44944 +        && (symbol == '\0')) {
44945 +               return KDB_INVADDRFMT;
44946 +       }
44947 +
44948 +       if (!symbol) {
44949 +               cp = (char *)argv[*nextarg];
44950 +               (*nextarg)++;
44951 +       }
44952 +
44953 +       diag = kdbgetularg(cp, &off);
44954 +       if (diag)
44955 +               return diag;
44956 +
44957 +       if (!positive)
44958 +               off = -off;
44959 +
44960 +       if (offset)
44961 +               *offset += off;
44962 +
44963 +       if (value)
44964 +               *value += off;
44965 +
44966 +       return 0;
44967 +}
44968 +
44969 +static void
44970 +kdb_cmderror(int diag)
44971 +{
44972 +       int i;
44973 +
44974 +       if (diag >= 0) {
44975 +               kdb_printf("no error detected\n");
44976 +               return;
44977 +       }
44978 +
44979 +       for(i=0; i<__nkdb_err; i++) {
44980 +               if (kdbmsgs[i].km_diag == diag) {
44981 +                       kdb_printf("diag: %d: %s\n", diag, kdbmsgs[i].km_msg);
44982 +                       return;
44983 +               }
44984 +       }
44985 +
44986 +       kdb_printf("Unknown diag %d\n", -diag);
44987 +}
44988 +
44989 +/*
44990 + * kdb_defcmd, kdb_defcmd2
44991 + *
44992 + *     This function implements the 'defcmd' command which defines one
44993 + *     command as a set of other commands, terminated by endefcmd.
44994 + *     kdb_defcmd processes the initial 'defcmd' command, kdb_defcmd2
44995 + *     is invoked from kdb_parse for the following commands until
44996 + *     'endefcmd'.
44997 + *
44998 + * Inputs:
44999 + *     argc    argument count
45000 + *     argv    argument vector
45001 + * Outputs:
45002 + *     None.
45003 + * Returns:
45004 + *     zero for success, a kdb diagnostic if error
45005 + * Locking:
45006 + *     none.
45007 + * Remarks:
45008 + */
45009 +
45010 +struct defcmd_set {
45011 +       int count;
45012 +       int usable;
45013 +       char *name;
45014 +       char *usage;
45015 +       char *help;
45016 +       char **command;
45017 +};
45018 +static struct defcmd_set *defcmd_set;
45019 +static int defcmd_set_count;
45020 +static int defcmd_in_progress;
45021 +
45022 +/* Forward references */
45023 +static int kdb_exec_defcmd(int argc, const char **argv);
45024 +
45025 +static int
45026 +kdb_defcmd2(const char *cmdstr, const char *argv0)
45027 +{
45028 +       struct defcmd_set *s = defcmd_set + defcmd_set_count - 1;
45029 +       char **save_command = s->command;
45030 +       if (strcmp(argv0, "endefcmd") == 0) {
45031 +               defcmd_in_progress = 0;
45032 +               if (!s->count)
45033 +                       s->usable = 0;
45034 +               if (s->usable)
45035 +                       kdb_register(s->name, kdb_exec_defcmd, s->usage, s->help, 0);
45036 +               return 0;
45037 +       }
45038 +       if (!s->usable)
45039 +               return KDB_NOTIMP;
45040 +       s->command = kmalloc((s->count + 1) * sizeof(*(s->command)), GFP_KDB);
45041 +       if (!s->command) {
45042 +               kdb_printf("Could not allocate new kdb_defcmd table for %s\n", cmdstr);
45043 +               s->usable = 0;
45044 +               return KDB_NOTIMP;
45045 +       }
45046 +       memcpy(s->command, save_command, s->count * sizeof(*(s->command)));
45047 +       s->command[s->count++] = kdb_strdup(cmdstr, GFP_KDB);
45048 +       kfree(save_command);
45049 +       return 0;
45050 +}
45051 +
45052 +static int
45053 +kdb_defcmd(int argc, const char **argv)
45054 +{
45055 +       struct defcmd_set *save_defcmd_set = defcmd_set, *s;
45056 +       if (defcmd_in_progress) {
45057 +               kdb_printf("kdb: nested defcmd detected, assuming missing endefcmd\n");
45058 +               kdb_defcmd2("endefcmd", "endefcmd");
45059 +       }
45060 +       if (argc == 0) {
45061 +               int i;
45062 +               for (s = defcmd_set; s < defcmd_set + defcmd_set_count; ++s) {
45063 +                       kdb_printf("defcmd %s \"%s\" \"%s\"\n", s->name, s->usage, s->help);
45064 +                       for (i = 0; i < s->count; ++i)
45065 +                               kdb_printf("%s", s->command[i]);
45066 +                       kdb_printf("endefcmd\n");
45067 +               }
45068 +               return 0;
45069 +       }
45070 +       if (argc != 3)
45071 +               return KDB_ARGCOUNT;
45072 +       defcmd_set = kmalloc((defcmd_set_count + 1) * sizeof(*defcmd_set), GFP_KDB);
45073 +       if (!defcmd_set) {
45074 +               kdb_printf("Could not allocate new defcmd_set entry for %s\n", argv[1]);
45075 +               defcmd_set = save_defcmd_set;
45076 +               return KDB_NOTIMP;
45077 +       }
45078 +       memcpy(defcmd_set, save_defcmd_set, defcmd_set_count * sizeof(*defcmd_set));
45079 +       kfree(save_defcmd_set);
45080 +       s = defcmd_set + defcmd_set_count;
45081 +       memset(s, 0, sizeof(*s));
45082 +       s->usable = 1;
45083 +       s->name = kdb_strdup(argv[1], GFP_KDB);
45084 +       s->usage = kdb_strdup(argv[2], GFP_KDB);
45085 +       s->help = kdb_strdup(argv[3], GFP_KDB);
45086 +       if (s->usage[0] == '"') {
45087 +               strcpy(s->usage, s->usage+1);
45088 +               s->usage[strlen(s->usage)-1] = '\0';
45089 +       }
45090 +       if (s->help[0] == '"') {
45091 +               strcpy(s->help, s->help+1);
45092 +               s->help[strlen(s->help)-1] = '\0';
45093 +       }
45094 +       ++defcmd_set_count;
45095 +       defcmd_in_progress = 1;
45096 +       return 0;
45097 +}
45098 +
45099 +/*
45100 + * kdb_exec_defcmd
45101 + *
45102 + *     Execute the set of commands associated with this defcmd name.
45103 + *
45104 + * Inputs:
45105 + *     argc    argument count
45106 + *     argv    argument vector
45107 + * Outputs:
45108 + *     None.
45109 + * Returns:
45110 + *     zero for success, a kdb diagnostic if error
45111 + * Locking:
45112 + *     none.
45113 + * Remarks:
45114 + */
45115 +
45116 +static int
45117 +kdb_exec_defcmd(int argc, const char **argv)
45118 +{
45119 +       int i, ret;
45120 +       struct defcmd_set *s;
45121 +       if (argc != 0)
45122 +               return KDB_ARGCOUNT;
45123 +       for (s = defcmd_set, i = 0; i < defcmd_set_count; ++i, ++s) {
45124 +               if (strcmp(s->name, argv[0]) == 0)
45125 +                       break;
45126 +       }
45127 +       if (i == defcmd_set_count) {
45128 +               kdb_printf("kdb_exec_defcmd: could not find commands for %s\n", argv[0]);
45129 +               return KDB_NOTIMP;
45130 +       }
45131 +       for (i = 0; i < s->count; ++i) {
45132 +               /* Recursive use of kdb_parse, do not use argv after this point */
45133 +               argv = NULL;
45134 +               kdb_printf("[%s]kdb> %s\n", s->name, s->command[i]);
45135 +               if ((ret = kdb_parse(s->command[i])))
45136 +                       return ret;
45137 +       }
45138 +       return 0;
45139 +}
45140 +
45141 +/* Command history */
45142 +#define KDB_CMD_HISTORY_COUNT  32
45143 +#define CMD_BUFLEN             200     /* kdb_printf: max printline size == 256 */
45144 +static unsigned int cmd_head=0, cmd_tail=0;
45145 +static unsigned int cmdptr;
45146 +static char cmd_hist[KDB_CMD_HISTORY_COUNT][CMD_BUFLEN];
45147 +static char cmd_cur[CMD_BUFLEN];
45148 +
45149 +/*
45150 + * kdb_parse
45151 + *
45152 + *     Parse the command line, search the command table for a
45153 + *     matching command and invoke the command function.
45154 + *     This function may be called recursively, if it is, the second call
45155 + *     will overwrite argv and cbuf.  It is the caller's responsibility to
45156 + *     save their argv if they recursively call kdb_parse().
45157 + *
45158 + * Parameters:
45159 + *      cmdstr The input command line to be parsed.
45160 + *     regs    The registers at the time kdb was entered.
45161 + * Outputs:
45162 + *     None.
45163 + * Returns:
45164 + *     Zero for success, a kdb diagnostic if failure.
45165 + * Locking:
45166 + *     None.
45167 + * Remarks:
45168 + *     Limited to 20 tokens.
45169 + *
45170 + *     Real rudimentary tokenization. Basically only whitespace
45171 + *     is considered a token delimeter (but special consideration
45172 + *     is taken of the '=' sign as used by the 'set' command).
45173 + *
45174 + *     The algorithm used to tokenize the input string relies on
45175 + *     there being at least one whitespace (or otherwise useless)
45176 + *     character between tokens as the character immediately following
45177 + *     the token is altered in-place to a null-byte to terminate the
45178 + *     token string.
45179 + */
45180 +
45181 +#define MAXARGC        20
45182 +
45183 +int
45184 +kdb_parse(const char *cmdstr)
45185 +{
45186 +       static char *argv[MAXARGC];
45187 +       static int argc = 0;
45188 +       static char cbuf[CMD_BUFLEN+2];
45189 +       const char *cp;
45190 +       char *cpp, quoted;
45191 +       kdbtab_t *tp;
45192 +       int i, escaped, ignore_errors = 0;
45193 +
45194 +       /*
45195 +        * First tokenize the command string.
45196 +        */
45197 +       cp = cmdstr;
45198 +
45199 +       if (KDB_FLAG(CMD_INTERRUPT)) {
45200 +               /* Previous command was interrupted, newline must not repeat the command */
45201 +               KDB_FLAG_CLEAR(CMD_INTERRUPT);
45202 +               argc = 0;       /* no repeat */
45203 +       }
45204 +
45205 +       if (*cp != '\n' && *cp != '\0') {
45206 +               argc = 0;
45207 +               cpp = cbuf;
45208 +               while (*cp) {
45209 +                       /* skip whitespace */
45210 +                       while (isspace(*cp)) cp++;
45211 +                       if ((*cp == '\0') || (*cp == '\n') || (*cp == '#' && !defcmd_in_progress))
45212 +                               break;
45213 +                       if (cpp >= cbuf + CMD_BUFLEN) {
45214 +                               kdb_printf("kdb_parse: command buffer overflow, command ignored\n%s\n", cmdstr);
45215 +                               return KDB_NOTFOUND;
45216 +                       }
45217 +                       if (argc >= MAXARGC - 1) {
45218 +                               kdb_printf("kdb_parse: too many arguments, command ignored\n%s\n", cmdstr);
45219 +                               return KDB_NOTFOUND;
45220 +                       }
45221 +                       argv[argc++] = cpp;
45222 +                       escaped = 0;
45223 +                       quoted = '\0';
45224 +                       /* Copy to next unquoted and unescaped whitespace or '=' */
45225 +                       while (*cp && *cp != '\n' && (escaped || quoted || !isspace(*cp))) {
45226 +                               if (cpp >= cbuf + CMD_BUFLEN)
45227 +                                       break;
45228 +                               if (escaped) {
45229 +                                       escaped = 0;
45230 +                                       *cpp++ = *cp++;
45231 +                                       continue;
45232 +                               }
45233 +                               if (*cp == '\\') {
45234 +                                       escaped = 1;
45235 +                                       ++cp;
45236 +                                       continue;
45237 +                               }
45238 +                               if (*cp == quoted) {
45239 +                                       quoted = '\0';
45240 +                               } else if (*cp == '\'' || *cp == '"') {
45241 +                                       quoted = *cp;
45242 +                               }
45243 +                               if ((*cpp = *cp++) == '=' && !quoted)
45244 +                                       break;
45245 +                               ++cpp;
45246 +                       }
45247 +                       *cpp++ = '\0';  /* Squash a ws or '=' character */
45248 +               }
45249 +       }
45250 +       if (!argc)
45251 +               return 0;
45252 +       if (defcmd_in_progress) {
45253 +               int result = kdb_defcmd2(cmdstr, argv[0]);
45254 +               if (!defcmd_in_progress) {
45255 +                       argc = 0;       /* avoid repeat on endefcmd */
45256 +                       *(argv[0]) = '\0';
45257 +               }
45258 +               return result;
45259 +       }
45260 +       if (argv[0][0] == '-' && argv[0][1] && (argv[0][1] < '0' || argv[0][1] > '9')) {
45261 +               ignore_errors = 1;
45262 +               ++argv[0];
45263 +       }
45264 +
45265 +       for(tp=kdb_commands, i=0; i < kdb_max_commands; i++,tp++) {
45266 +               if (tp->cmd_name) {
45267 +                       /*
45268 +                        * If this command is allowed to be abbreviated,
45269 +                        * check to see if this is it.
45270 +                        */
45271 +
45272 +                       if (tp->cmd_minlen
45273 +                        && (strlen(argv[0]) <= tp->cmd_minlen)) {
45274 +                               if (strncmp(argv[0],
45275 +                                           tp->cmd_name,
45276 +                                           tp->cmd_minlen) == 0) {
45277 +                                       break;
45278 +                               }
45279 +                       }
45280 +
45281 +                       if (strcmp(argv[0], tp->cmd_name)==0) {
45282 +                               break;
45283 +                       }
45284 +               }
45285 +       }
45286 +
45287 +       /*
45288 +        * If we don't find a command by this name, see if the first
45289 +        * few characters of this match any of the known commands.
45290 +        * e.g., md1c20 should match md.
45291 +        */
45292 +       if (i == kdb_max_commands) {
45293 +               for(tp=kdb_commands, i=0; i < kdb_max_commands; i++,tp++) {
45294 +                       if (tp->cmd_name) {
45295 +                               if (strncmp(argv[0],
45296 +                                           tp->cmd_name,
45297 +                                           strlen(tp->cmd_name))==0) {
45298 +                                       break;
45299 +                               }
45300 +                       }
45301 +               }
45302 +       }
45303 +
45304 +       if (i < kdb_max_commands) {
45305 +               int result;
45306 +               KDB_STATE_SET(CMD);
45307 +               result = (*tp->cmd_func)(argc-1,
45308 +                                      (const char**)argv);
45309 +               if (result && ignore_errors && result > KDB_CMD_GO)
45310 +                       result = 0;
45311 +               KDB_STATE_CLEAR(CMD);
45312 +               switch (tp->cmd_repeat) {
45313 +               case KDB_REPEAT_NONE:
45314 +                       argc = 0;
45315 +                       if (argv[0])
45316 +                               *(argv[0]) = '\0';
45317 +                       break;
45318 +               case KDB_REPEAT_NO_ARGS:
45319 +                       argc = 1;
45320 +                       if (argv[1])
45321 +                               *(argv[1]) = '\0';
45322 +                       break;
45323 +               case KDB_REPEAT_WITH_ARGS:
45324 +                       break;
45325 +               }
45326 +               return result;
45327 +       }
45328 +
45329 +       /*
45330 +        * If the input with which we were presented does not
45331 +        * map to an existing command, attempt to parse it as an
45332 +        * address argument and display the result.   Useful for
45333 +        * obtaining the address of a variable, or the nearest symbol
45334 +        * to an address contained in a register.
45335 +        */
45336 +       {
45337 +               kdb_machreg_t value;
45338 +               char *name = NULL;
45339 +               long offset;
45340 +               int nextarg = 0;
45341 +
45342 +               if (kdbgetaddrarg(0, (const char **)argv, &nextarg,
45343 +                                 &value, &offset, &name)) {
45344 +                       return KDB_NOTFOUND;
45345 +               }
45346 +
45347 +               kdb_printf("%s = ", argv[0]);
45348 +               kdb_symbol_print(value, NULL, KDB_SP_DEFAULT);
45349 +               kdb_printf("\n");
45350 +               return 0;
45351 +       }
45352 +}
45353 +
45354 +
45355 +static int
45356 +handle_ctrl_cmd(char *cmd)
45357 +{
45358 +#define CTRL_P 16
45359 +#define CTRL_N 14
45360 +
45361 +       /* initial situation */
45362 +       if (cmd_head == cmd_tail) return 0;
45363 +
45364 +       switch(*cmd) {
45365 +               case CTRL_P:
45366 +                       if (cmdptr != cmd_tail)
45367 +                               cmdptr = (cmdptr-1) % KDB_CMD_HISTORY_COUNT;
45368 +                       strncpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN);
45369 +                       return 1;
45370 +               case CTRL_N:
45371 +                       if (cmdptr != cmd_head)
45372 +                               cmdptr = (cmdptr+1) % KDB_CMD_HISTORY_COUNT;
45373 +                       strncpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN);
45374 +                       return 1;
45375 +       }
45376 +       return 0;
45377 +}
45378 +
45379 +/*
45380 + * kdb_do_dump
45381 + *
45382 + *     Call the dump() function if the kernel is configured for LKCD.
45383 + * Inputs:
45384 + *     None.
45385 + * Outputs:
45386 + *     None.
45387 + * Returns:
45388 + *     None.  dump() may or may not return.
45389 + * Locking:
45390 + *     none.
45391 + * Remarks:
45392 + */
45393 +
45394 +static void
45395 +kdb_do_dump(void)
45396 +{
45397 +#if defined(CONFIG_LKCD_DUMP) || defined(CONFIG_LKCD_DUMP_MODULE)
45398 +       kdb_printf("Forcing dump (if configured)\n");
45399 +       console_loglevel = 8;   /* to see the dump messages */
45400 +       dump("kdb_do_dump");
45401 +#endif
45402 +}
45403 +
45404 +/*
45405 + * kdb_reboot
45406 + *
45407 + *     This function implements the 'reboot' command.  Reboot the system
45408 + *     immediately.
45409 + *
45410 + * Inputs:
45411 + *     argc    argument count
45412 + *     argv    argument vector
45413 + * Outputs:
45414 + *     None.
45415 + * Returns:
45416 + *     zero for success, a kdb diagnostic if error
45417 + * Locking:
45418 + *     none.
45419 + * Remarks:
45420 + *     Shouldn't return from this function.
45421 + */
45422 +
45423 +static int
45424 +kdb_reboot(int argc, const char **argv)
45425 +{
45426 +       emergency_restart();
45427 +       kdb_printf("Hmm, kdb_reboot did not reboot, spinning here\n");
45428 +       while (1) {};
45429 +       /* NOTREACHED */
45430 +       return 0;
45431 +}
45432 +
45433 +static int
45434 +kdb_quiet(int reason)
45435 +{
45436 +       return (reason == KDB_REASON_CPU_UP || reason == KDB_REASON_SILENT);
45437 +}
45438 +
45439 +/*
45440 + * kdb_local
45441 + *
45442 + *     The main code for kdb.  This routine is invoked on a specific
45443 + *     processor, it is not global.  The main kdb() routine ensures
45444 + *     that only one processor at a time is in this routine.  This
45445 + *     code is called with the real reason code on the first entry
45446 + *     to a kdb session, thereafter it is called with reason SWITCH,
45447 + *     even if the user goes back to the original cpu.
45448 + *
45449 + * Inputs:
45450 + *     reason          The reason KDB was invoked
45451 + *     error           The hardware-defined error code
45452 + *     regs            The exception frame at time of fault/breakpoint.  NULL
45453 + *                     for reason SILENT or CPU_UP, otherwise valid.
45454 + *     db_result       Result code from the break or debug point.
45455 + * Returns:
45456 + *     0       KDB was invoked for an event which it wasn't responsible
45457 + *     1       KDB handled the event for which it was invoked.
45458 + *     KDB_CMD_GO      User typed 'go'.
45459 + *     KDB_CMD_CPU     User switched to another cpu.
45460 + *     KDB_CMD_SS      Single step.
45461 + *     KDB_CMD_SSB     Single step until branch.
45462 + * Locking:
45463 + *     none
45464 + * Remarks:
45465 + *     none
45466 + */
45467 +
45468 +static int
45469 +kdb_local(kdb_reason_t reason, int error, struct pt_regs *regs, kdb_dbtrap_t db_result)
45470 +{
45471 +       char *cmdbuf;
45472 +       int diag;
45473 +       struct task_struct *kdb_current = kdb_curr_task(smp_processor_id());
45474 +
45475 +       /* If kdb has been entered for an event which has been/will be
45476 +        * recovered then silently return.  We have to get this far into kdb in
45477 +        * order to synchronize all the cpus, typically only one cpu (monarch)
45478 +        * knows that the event is recoverable but the other cpus (slaves) may
45479 +        * also be driven into kdb before that decision is made by the monarch.
45480 +        *
45481 +        * To pause in kdb even for recoverable events, 'set RECOVERY_PAUSE 1'
45482 +        */
45483 +       KDB_DEBUG_STATE("kdb_local 1", reason);
45484 +       if (reason == KDB_REASON_ENTER
45485 +           && KDB_FLAG(RECOVERY)
45486 +           && !KDB_FLAG(CATASTROPHIC)) {
45487 +               int recovery_pause = 0;
45488 +               kdbgetintenv("RECOVERY_PAUSE", &recovery_pause);
45489 +               if (recovery_pause == 0)
45490 +                       reason = KDB_REASON_SILENT;
45491 +               else
45492 +                       kdb_printf("%s: Recoverable error detected but"
45493 +                                  " RECOVERY_PAUSE is set, staying in KDB\n",
45494 +                                  __FUNCTION__);
45495 +       }
45496 +
45497 +       KDB_DEBUG_STATE("kdb_local 2", reason);
45498 +       kdb_go_count = 0;
45499 +       if (kdb_quiet(reason)) {
45500 +               /* no message */
45501 +       } else if (reason == KDB_REASON_DEBUG) {
45502 +               /* special case below */
45503 +       } else {
45504 +               kdb_printf("\nEntering kdb (current=0x%p, pid %d) ", kdb_current, kdb_current->pid);
45505 +#if defined(CONFIG_SMP)
45506 +               kdb_printf("on processor %d ", smp_processor_id());
45507 +#endif
45508 +       }
45509 +
45510 +       switch (reason) {
45511 +       case KDB_REASON_DEBUG:
45512 +       {
45513 +               /*
45514 +                * If re-entering kdb after a single step
45515 +                * command, don't print the message.
45516 +                */
45517 +               switch(db_result) {
45518 +               case KDB_DB_BPT:
45519 +                       kdb_printf("\nEntering kdb (0x%p, pid %d) ", kdb_current, kdb_current->pid);
45520 +#if defined(CONFIG_SMP)
45521 +                       kdb_printf("on processor %d ", smp_processor_id());
45522 +#endif
45523 +                       kdb_printf("due to Debug @ " kdb_machreg_fmt "\n", kdba_getpc(regs));
45524 +                       break;
45525 +               case KDB_DB_SSB:
45526 +                       /*
45527 +                        * In the midst of ssb command. Just return.
45528 +                        */
45529 +                       KDB_DEBUG_STATE("kdb_local 3", reason);
45530 +                       return KDB_CMD_SSB;     /* Continue with SSB command */
45531 +
45532 +                       break;
45533 +               case KDB_DB_SS:
45534 +                       break;
45535 +               case KDB_DB_SSBPT:
45536 +                       KDB_DEBUG_STATE("kdb_local 4", reason);
45537 +                       return 1;       /* kdba_db_trap did the work */
45538 +               default:
45539 +                       kdb_printf("kdb: Bad result from kdba_db_trap: %d\n",
45540 +                                  db_result);
45541 +                       break;
45542 +               }
45543 +
45544 +       }
45545 +               break;
45546 +       case KDB_REASON_ENTER:
45547 +               if (KDB_STATE(KEYBOARD))
45548 +                       kdb_printf("due to Keyboard Entry\n");
45549 +               else
45550 +                       kdb_printf("due to KDB_ENTER()\n");
45551 +               break;
45552 +       case KDB_REASON_KEYBOARD:
45553 +               KDB_STATE_SET(KEYBOARD);
45554 +               kdb_printf("due to Keyboard Entry\n");
45555 +               break;
45556 +       case KDB_REASON_ENTER_SLAVE:    /* drop through, slaves only get released via cpu switch */
45557 +       case KDB_REASON_SWITCH:
45558 +               kdb_printf("due to cpu switch\n");
45559 +               if (KDB_STATE(GO_SWITCH)) {
45560 +                       KDB_STATE_CLEAR(GO_SWITCH);
45561 +                       KDB_DEBUG_STATE("kdb_local 5", reason);
45562 +                       return KDB_CMD_GO;
45563 +               }
45564 +               break;
45565 +       case KDB_REASON_OOPS:
45566 +               kdb_printf("Oops: %s\n", kdb_diemsg);
45567 +               kdb_printf("due to oops @ " kdb_machreg_fmt "\n", kdba_getpc(regs));
45568 +               kdba_dumpregs(regs, NULL, NULL);
45569 +               break;
45570 +       case KDB_REASON_NMI:
45571 +               kdb_printf("due to NonMaskable Interrupt @ " kdb_machreg_fmt "\n",
45572 +                         kdba_getpc(regs));
45573 +               kdba_dumpregs(regs, NULL, NULL);
45574 +               break;
45575 +       case KDB_REASON_BREAK:
45576 +               kdb_printf("due to Breakpoint @ " kdb_machreg_fmt "\n", kdba_getpc(regs));
45577 +               /*
45578 +                * Determine if this breakpoint is one that we
45579 +                * are interested in.
45580 +                */
45581 +               if (db_result != KDB_DB_BPT) {
45582 +                       kdb_printf("kdb: error return from kdba_bp_trap: %d\n", db_result);
45583 +                       KDB_DEBUG_STATE("kdb_local 6", reason);
45584 +                       return 0;       /* Not for us, dismiss it */
45585 +               }
45586 +               break;
45587 +       case KDB_REASON_RECURSE:
45588 +               kdb_printf("due to Recursion @ " kdb_machreg_fmt "\n", kdba_getpc(regs));
45589 +               break;
45590 +       case KDB_REASON_CPU_UP:
45591 +       case KDB_REASON_SILENT:
45592 +               KDB_DEBUG_STATE("kdb_local 7", reason);
45593 +               if (reason == KDB_REASON_CPU_UP)
45594 +                       kdba_cpu_up();
45595 +               return KDB_CMD_GO;      /* Silent entry, silent exit */
45596 +               break;
45597 +       default:
45598 +               kdb_printf("kdb: unexpected reason code: %d\n", reason);
45599 +               KDB_DEBUG_STATE("kdb_local 8", reason);
45600 +               return 0;       /* Not for us, dismiss it */
45601 +       }
45602 +
45603 +       kdba_local_arch_setup();
45604 +
45605 +       kdba_set_current_task(kdb_current);
45606 +
45607 +       while (1) {
45608 +               /*
45609 +                * Initialize pager context.
45610 +                */
45611 +               kdb_nextline = 1;
45612 +               KDB_STATE_CLEAR(SUPPRESS);
45613 +#ifdef kdba_setjmp
45614 +               /*
45615 +                * Use kdba_setjmp/kdba_longjmp to break out of
45616 +                * the pager early and to attempt to recover from kdb errors.
45617 +                */
45618 +               KDB_STATE_CLEAR(LONGJMP);
45619 +               if (kdbjmpbuf) {
45620 +                       if (kdba_setjmp(&kdbjmpbuf[smp_processor_id()])) {
45621 +                               /* Command aborted (usually in pager) */
45622 +                               continue;
45623 +                       }
45624 +                       else
45625 +                               KDB_STATE_SET(LONGJMP);
45626 +               }
45627 +#endif /* kdba_setjmp */
45628 +
45629 +               cmdbuf = cmd_cur;
45630 +               *cmdbuf = '\0';
45631 +               *(cmd_hist[cmd_head])='\0';
45632 +
45633 +               if (KDB_FLAG(ONLY_DO_DUMP)) {
45634 +                       /* kdb is off but a catastrophic error requires a dump.
45635 +                        * Take the dump and reboot.
45636 +                        * Turn on logging so the kdb output appears in the log
45637 +                        * buffer in the dump.
45638 +                        */
45639 +                       const char *setargs[] = { "set", "LOGGING", "1" };
45640 +                       kdb_set(2, setargs);
45641 +                       kdb_do_dump();
45642 +                       kdb_reboot(0, NULL);
45643 +                       /*NOTREACHED*/
45644 +               }
45645 +
45646 +do_full_getstr:
45647 +#if defined(CONFIG_SMP)
45648 +               snprintf(kdb_prompt_str, CMD_BUFLEN, kdbgetenv("PROMPT"), smp_processor_id());
45649 +#else
45650 +               snprintf(kdb_prompt_str, CMD_BUFLEN, kdbgetenv("PROMPT"));
45651 +#endif
45652 +               if (defcmd_in_progress)
45653 +                       strncat(kdb_prompt_str, "[defcmd]", CMD_BUFLEN);
45654 +
45655 +               /*
45656 +                * Fetch command from keyboard
45657 +                */
45658 +               cmdbuf = kdb_getstr(cmdbuf, CMD_BUFLEN, kdb_prompt_str);
45659 +               if (*cmdbuf != '\n') {
45660 +                       if (*cmdbuf < 32) {
45661 +                               if(cmdptr == cmd_head) {
45662 +                                       strncpy(cmd_hist[cmd_head], cmd_cur, CMD_BUFLEN);
45663 +                                       *(cmd_hist[cmd_head]+strlen(cmd_hist[cmd_head])-1) = '\0';
45664 +                               }
45665 +                               if(!handle_ctrl_cmd(cmdbuf))
45666 +                                       *(cmd_cur+strlen(cmd_cur)-1) = '\0';
45667 +                               cmdbuf = cmd_cur;
45668 +                               goto do_full_getstr;
45669 +                       }
45670 +                       else
45671 +                               strncpy(cmd_hist[cmd_head], cmd_cur, CMD_BUFLEN);
45672 +
45673 +                       cmd_head = (cmd_head+1) % KDB_CMD_HISTORY_COUNT;
45674 +                       if (cmd_head == cmd_tail) cmd_tail = (cmd_tail+1) % KDB_CMD_HISTORY_COUNT;
45675 +
45676 +               }
45677 +
45678 +               cmdptr = cmd_head;
45679 +               diag = kdb_parse(cmdbuf);
45680 +               if (diag == KDB_NOTFOUND) {
45681 +                       kdb_printf("Unknown kdb command: '%s'\n", cmdbuf);
45682 +                       diag = 0;
45683 +               }
45684 +               if (diag == KDB_CMD_GO
45685 +                || diag == KDB_CMD_CPU
45686 +                || diag == KDB_CMD_SS
45687 +                || diag == KDB_CMD_SSB)
45688 +                       break;
45689 +
45690 +               if (diag)
45691 +                       kdb_cmderror(diag);
45692 +       }
45693 +
45694 +       kdba_local_arch_cleanup();
45695 +
45696 +       KDB_DEBUG_STATE("kdb_local 9", diag);
45697 +       return diag;
45698 +}
45699 +
45700 +
45701 +/*
45702 + * kdb_print_state
45703 + *
45704 + *     Print the state data for the current processor for debugging.
45705 + *
45706 + * Inputs:
45707 + *     text            Identifies the debug point
45708 + *     value           Any integer value to be printed, e.g. reason code.
45709 + * Returns:
45710 + *     None.
45711 + * Locking:
45712 + *     none
45713 + * Remarks:
45714 + *     none
45715 + */
45716 +
45717 +void kdb_print_state(const char *text, int value)
45718 +{
45719 +       kdb_printf("state: %s cpu %d value %d initial %d state %x\n",
45720 +               text, smp_processor_id(), value, kdb_initial_cpu, kdb_state[smp_processor_id()]);
45721 +}
45722 +
45723 +/*
45724 + * kdb_previous_event
45725 + *
45726 + *     Return a count of cpus that are leaving kdb, i.e. the number
45727 + *     of processors that are still handling the previous kdb event.
45728 + *
45729 + * Inputs:
45730 + *     None.
45731 + * Returns:
45732 + *     Count of cpus in previous event.
45733 + * Locking:
45734 + *     none
45735 + * Remarks:
45736 + *     none
45737 + */
45738 +
45739 +static int
45740 +kdb_previous_event(void)
45741 +{
45742 +       int i, leaving = 0;
45743 +       for (i = 0; i < NR_CPUS; ++i) {
45744 +               if (KDB_STATE_CPU(LEAVING, i))
45745 +                       ++leaving;
45746 +       }
45747 +       return leaving;
45748 +}
45749 +
45750 +/*
45751 + * kdb_wait_for_cpus
45752 + *
45753 + * Invoked once at the start of a kdb event, from the controlling cpu.  Wait a
45754 + * short period for the other cpus to enter kdb state.
45755 + *
45756 + * Inputs:
45757 + *     none
45758 + * Returns:
45759 + *     none
45760 + * Locking:
45761 + *     none
45762 + * Remarks:
45763 + *     none
45764 + */
45765 +
45766 +int kdb_wait_for_cpus_secs;
45767 +
45768 +static void
45769 +kdb_wait_for_cpus(void)
45770 +{
45771 +#ifdef CONFIG_SMP
45772 +       int online = 0, kdb_data = 0, prev_kdb_data = 0, c, time;
45773 +       mdelay(100);
45774 +       for (time = 0; time < kdb_wait_for_cpus_secs; ++time) {
45775 +               online = 0;
45776 +               kdb_data = 0;
45777 +               for_each_online_cpu(c) {
45778 +                       ++online;
45779 +                       if (kdb_running_process[c].seqno >= kdb_seqno - 1)
45780 +                               ++kdb_data;
45781 +               }
45782 +               if (online == kdb_data)
45783 +                       break;
45784 +               if (prev_kdb_data != kdb_data) {
45785 +                       kdb_nextline = 0;       /* no prompt yet */
45786 +                       kdb_printf("  %d out of %d cpus in kdb, waiting for the rest, timeout in %d second(s)\n",
45787 +                               kdb_data, online, kdb_wait_for_cpus_secs - time);
45788 +                       prev_kdb_data = kdb_data;
45789 +               }
45790 +               touch_nmi_watchdog();
45791 +               mdelay(1000);
45792 +               /* Architectures may want to send a more forceful interrupt */
45793 +               if (time == min(kdb_wait_for_cpus_secs / 2, 5))
45794 +                       kdba_wait_for_cpus();
45795 +               if (time % 4 == 0)
45796 +                       kdb_printf(".");
45797 +       }
45798 +       if (time) {
45799 +               int wait = online - kdb_data;
45800 +               if (wait == 0)
45801 +                       kdb_printf("All cpus are now in kdb\n");
45802 +               else
45803 +                       kdb_printf("%d cpu%s not in kdb, %s state is unknown\n",
45804 +                                       wait,
45805 +                                       wait == 1 ? " is" : "s are",
45806 +                                       wait == 1 ? "its" : "their");
45807 +       }
45808 +#endif /* CONFIG_SMP */
45809 +}
45810 +
45811 +/*
45812 + * kdb_main_loop
45813 + *
45814 + * The main kdb loop.  After initial setup and assignment of the controlling
45815 + * cpu, all cpus are in this loop.  One cpu is in control and will issue the kdb
45816 + * prompt, the others will spin until 'go' or cpu switch.
45817 + *
45818 + * To get a consistent view of the kernel stacks for all processes, this routine
45819 + * is invoked from the main kdb code via an architecture specific routine.
45820 + * kdba_main_loop is responsible for making the kernel stacks consistent for all
45821 + * processes, there should be no difference between a blocked process and a
45822 + * running process as far as kdb is concerned.
45823 + *
45824 + * Inputs:
45825 + *     reason          The reason KDB was invoked
45826 + *     error           The hardware-defined error code
45827 + *     reason2         kdb's current reason code.  Initially error but can change
45828 + *                     acording to kdb state.
45829 + *     db_result       Result code from break or debug point.
45830 + *     regs            The exception frame at time of fault/breakpoint.  If reason
45831 + *                     is SILENT or CPU_UP then regs is NULL, otherwise it
45832 + *                     should always be valid.
45833 + * Returns:
45834 + *     0       KDB was invoked for an event which it wasn't responsible
45835 + *     1       KDB handled the event for which it was invoked.
45836 + * Locking:
45837 + *     none
45838 + * Remarks:
45839 + *     none
45840 + */
45841 +
45842 +int
45843 +kdb_main_loop(kdb_reason_t reason, kdb_reason_t reason2, int error,
45844 +             kdb_dbtrap_t db_result, struct pt_regs *regs)
45845 +{
45846 +       int result = 1;
45847 +       /* Stay in kdb() until 'go', 'ss[b]' or an error */
45848 +       while (1) {
45849 +               /*
45850 +                * All processors except the one that is in control
45851 +                * will spin here.
45852 +                */
45853 +               KDB_DEBUG_STATE("kdb_main_loop 1", reason);
45854 +               while (KDB_STATE(HOLD_CPU)) {
45855 +                       /* state KDB is turned off by kdb_cpu to see if the
45856 +                        * other cpus are still live, each cpu in this loop
45857 +                        * turns it back on.
45858 +                        */
45859 +                       if (!KDB_STATE(KDB)) {
45860 +                               KDB_STATE_SET(KDB);
45861 +                       }
45862 +               }
45863 +               KDB_STATE_CLEAR(SUPPRESS);
45864 +               KDB_DEBUG_STATE("kdb_main_loop 2", reason);
45865 +               if (KDB_STATE(LEAVING))
45866 +                       break;  /* Another cpu said 'go' */
45867 +
45868 +               if (!kdb_quiet(reason))
45869 +                       kdb_wait_for_cpus();
45870 +               /* Still using kdb, this processor is in control */
45871 +               result = kdb_local(reason2, error, regs, db_result);
45872 +               KDB_DEBUG_STATE("kdb_main_loop 3", result);
45873 +
45874 +               if (result == KDB_CMD_CPU) {
45875 +                       /* Cpu switch, hold the current cpu, release the target one. */
45876 +                       reason2 = KDB_REASON_SWITCH;
45877 +                       KDB_STATE_SET(HOLD_CPU);
45878 +                       KDB_STATE_CLEAR_CPU(HOLD_CPU, kdb_new_cpu);
45879 +                       continue;
45880 +               }
45881 +
45882 +               if (result == KDB_CMD_SS) {
45883 +                       KDB_STATE_SET(DOING_SS);
45884 +                       break;
45885 +               }
45886 +
45887 +               if (result == KDB_CMD_SSB) {
45888 +                       KDB_STATE_SET(DOING_SS);
45889 +                       KDB_STATE_SET(DOING_SSB);
45890 +                       break;
45891 +               }
45892 +
45893 +               if (result && result != 1 && result != KDB_CMD_GO)
45894 +                       kdb_printf("\nUnexpected kdb_local return code %d\n", result);
45895 +
45896 +               KDB_DEBUG_STATE("kdb_main_loop 4", reason);
45897 +               break;
45898 +       }
45899 +       if (KDB_STATE(DOING_SS))
45900 +               KDB_STATE_CLEAR(SSBPT);
45901 +       return result;
45902 +}
45903 +
45904 +/* iapc_boot_arch was defined in ACPI 2.0, FADT revision 3 onwards.  For any
45905 + * FADT prior to revision 3, we have to assume that we have an i8042 I/O
45906 + * device.  ACPI initialises after KDB initialises but before using KDB, so
45907 + * check iapc_boot_arch on each entry to KDB.
45908 + */
45909 +static void
45910 +kdb_check_i8042(void)
45911 +{
45912 +       KDB_FLAG_CLEAR(NO_I8042);
45913 +#ifdef CONFIG_ACPI
45914 +       if (acpi_gbl_FADT.header.revision >= 3 &&
45915 +           (acpi_gbl_FADT.boot_flags & BAF_8042_KEYBOARD_CONTROLLER) == 0)
45916 +               KDB_FLAG_SET(NO_I8042);
45917 +#endif /* CONFIG_ACPI */
45918 +}
45919 +
45920 +/*
45921 + * kdb
45922 + *
45923 + *     This function is the entry point for the kernel debugger.  It
45924 + *     provides a command parser and associated support functions to
45925 + *     allow examination and control of an active kernel.
45926 + *
45927 + *     The breakpoint trap code should invoke this function with
45928 + *     one of KDB_REASON_BREAK (int 03) or KDB_REASON_DEBUG (debug register)
45929 + *
45930 + *     the die_if_kernel function should invoke this function with
45931 + *     KDB_REASON_OOPS.
45932 + *
45933 + *     In single step mode, one cpu is released to run without
45934 + *     breakpoints.   Interrupts and NMI are reset to their original values,
45935 + *     the cpu is allowed to do one instruction which causes a trap
45936 + *     into kdb with KDB_REASON_DEBUG.
45937 + *
45938 + * Inputs:
45939 + *     reason          The reason KDB was invoked
45940 + *     error           The hardware-defined error code
45941 + *     regs            The exception frame at time of fault/breakpoint.  If reason
45942 + *                     is SILENT or CPU_UP then regs is NULL, otherwise it
45943 + *                     should always be valid.
45944 + * Returns:
45945 + *     0       KDB was invoked for an event which it wasn't responsible
45946 + *     1       KDB handled the event for which it was invoked.
45947 + * Locking:
45948 + *     none
45949 + * Remarks:
45950 + *     No assumptions of system state.  This function may be invoked
45951 + *     with arbitrary locks held.  It will stop all other processors
45952 + *     in an SMP environment, disable all interrupts and does not use
45953 + *     the operating systems keyboard driver.
45954 + *
45955 + *     This code is reentrant but only for cpu switch.  Any other
45956 + *     reentrancy is an error, although kdb will attempt to recover.
45957 + *
45958 + *     At the start of a kdb session the initial processor is running
45959 + *     kdb() and the other processors can be doing anything.  When the
45960 + *     initial processor calls smp_kdb_stop() the other processors are
45961 + *     driven through kdb_ipi which calls kdb() with reason SWITCH.
45962 + *     That brings all processors into this routine, one with a "real"
45963 + *     reason code, the other with SWITCH.
45964 + *
45965 + *     Because the other processors are driven via smp_kdb_stop(),
45966 + *     they enter here from the NMI handler.  Until the other
45967 + *     processors exit from here and exit from kdb_ipi, they will not
45968 + *     take any more NMI requests.  The initial cpu will still take NMI.
45969 + *
45970 + *     Multiple race and reentrancy conditions, each with different
45971 + *     advoidance mechanisms.
45972 + *
45973 + *     Two cpus hit debug points at the same time.
45974 + *
45975 + *       kdb_lock and kdb_initial_cpu ensure that only one cpu gets
45976 + *       control of kdb.  The others spin on kdb_initial_cpu until
45977 + *       they are driven through NMI into kdb_ipi.  When the initial
45978 + *       cpu releases the others from NMI, they resume trying to get
45979 + *       kdb_initial_cpu to start a new event.
45980 + *
45981 + *     A cpu is released from kdb and starts a new event before the
45982 + *     original event has completely ended.
45983 + *
45984 + *       kdb_previous_event() prevents any cpu from entering
45985 + *       kdb_initial_cpu state until the previous event has completely
45986 + *       ended on all cpus.
45987 + *
45988 + *     An exception occurs inside kdb.
45989 + *
45990 + *       kdb_initial_cpu detects recursive entry to kdb and attempts
45991 + *       to recover.  The recovery uses longjmp() which means that
45992 + *       recursive calls to kdb never return.  Beware of assumptions
45993 + *       like
45994 + *
45995 + *         ++depth;
45996 + *         kdb();
45997 + *         --depth;
45998 + *
45999 + *       If the kdb call is recursive then longjmp takes over and
46000 + *       --depth is never executed.
46001 + *
46002 + *     NMI handling.
46003 + *
46004 + *       NMI handling is tricky.  The initial cpu is invoked by some kdb event,
46005 + *       this event could be NMI driven but usually is not.  The other cpus are
46006 + *       driven into kdb() via kdb_ipi which uses NMI so at the start the other
46007 + *       cpus will not accept NMI.  Some operations such as SS release one cpu
46008 + *       but hold all the others.  Releasing a cpu means it drops back to
46009 + *       whatever it was doing before the kdb event, this means it drops out of
46010 + *       kdb_ipi and hence out of NMI status.  But the software watchdog uses
46011 + *       NMI and we do not want spurious watchdog calls into kdb.  kdba_read()
46012 + *       resets the watchdog counters in its input polling loop, when a kdb
46013 + *       command is running it is subject to NMI watchdog events.
46014 + *
46015 + *       Another problem with NMI handling is the NMI used to drive the other
46016 + *       cpus into kdb cannot be distinguished from the watchdog NMI.  State
46017 + *       flag WAIT_IPI indicates that a cpu is waiting for NMI via kdb_ipi,
46018 + *       if not set then software NMI is ignored by kdb_ipi.
46019 + *
46020 + *     Cpu switching.
46021 + *
46022 + *       All cpus are in kdb (or they should be), all but one are
46023 + *       spinning on KDB_STATE(HOLD_CPU).  Only one cpu is not in
46024 + *       HOLD_CPU state, only that cpu can handle commands.
46025 + *
46026 + *     Go command entered.
46027 + *
46028 + *       If necessary, go will switch to the initial cpu first.  If the event
46029 + *       was caused by a software breakpoint (assumed to be global) that
46030 + *       requires single-step to get over the breakpoint then only release the
46031 + *       initial cpu, after the initial cpu has single-stepped the breakpoint
46032 + *       then release the rest of the cpus.  If SSBPT is not required then
46033 + *       release all the cpus at once.
46034 + */
46035 +
46036 +fastcall int
46037 +kdb(kdb_reason_t reason, int error, struct pt_regs *regs)
46038 +{
46039 +       kdb_intstate_t int_state;       /* Interrupt state */
46040 +       kdb_reason_t reason2 = reason;
46041 +       int result = 0; /* Default is kdb did not handle it */
46042 +       int ss_event, old_regs_saved = 0;
46043 +       struct pt_regs *old_regs = NULL;
46044 +       kdb_dbtrap_t db_result=KDB_DB_NOBPT;
46045 +       preempt_disable();
46046 +       atomic_inc(&kdb_event);
46047 +
46048 +       switch(reason) {
46049 +       case KDB_REASON_OOPS:
46050 +       case KDB_REASON_NMI:
46051 +               KDB_FLAG_SET(CATASTROPHIC);     /* kernel state is dubious now */
46052 +               break;
46053 +       default:
46054 +               break;
46055 +       }
46056 +       switch(reason) {
46057 +       case KDB_REASON_ENTER:
46058 +       case KDB_REASON_ENTER_SLAVE:
46059 +       case KDB_REASON_BREAK:
46060 +       case KDB_REASON_DEBUG:
46061 +       case KDB_REASON_OOPS:
46062 +       case KDB_REASON_SWITCH:
46063 +       case KDB_REASON_KEYBOARD:
46064 +       case KDB_REASON_NMI:
46065 +               if (regs && regs != get_irq_regs()) {
46066 +                       old_regs = set_irq_regs(regs);
46067 +                       old_regs_saved = 1;
46068 +               }
46069 +               break;
46070 +       default:
46071 +               break;
46072 +       }
46073 +       if (kdb_continue_catastrophic > 2) {
46074 +               kdb_printf("kdb_continue_catastrophic is out of range, setting to 2\n");
46075 +               kdb_continue_catastrophic = 2;
46076 +       }
46077 +       if (!kdb_on && KDB_FLAG(CATASTROPHIC) && kdb_continue_catastrophic == 2) {
46078 +               KDB_FLAG_SET(ONLY_DO_DUMP);
46079 +       }
46080 +       if (!kdb_on && !KDB_FLAG(ONLY_DO_DUMP))
46081 +               goto out;
46082 +
46083 +       KDB_DEBUG_STATE("kdb 1", reason);
46084 +       KDB_STATE_CLEAR(SUPPRESS);
46085 +
46086 +       /* Filter out userspace breakpoints first, no point in doing all
46087 +        * the kdb smp fiddling when it is really a gdb trap.
46088 +        * Save the single step status first, kdba_db_trap clears ss status.
46089 +        * kdba_b[dp]_trap sets SSBPT if required.
46090 +        */
46091 +       ss_event = KDB_STATE(DOING_SS) || KDB_STATE(SSBPT);
46092 +#ifdef  CONFIG_CPU_XSCALE
46093 +       if ( KDB_STATE(A_XSC_ICH) ) {
46094 +               /* restore changed I_BIT */
46095 +               KDB_STATE_CLEAR(A_XSC_ICH);
46096 +               kdba_restore_retirq(regs, KDB_STATE(A_XSC_IRQ));
46097 +               if ( !ss_event ) {
46098 +                       kdb_printf("Stranger!!! Why IRQ bit is changed====\n");
46099 +               }
46100 +       }
46101 +#endif
46102 +       if (reason == KDB_REASON_BREAK) {
46103 +               db_result = kdba_bp_trap(regs, error);  /* Only call this once */
46104 +       }
46105 +       if (reason == KDB_REASON_DEBUG) {
46106 +               db_result = kdba_db_trap(regs, error);  /* Only call this once */
46107 +       }
46108 +
46109 +       if ((reason == KDB_REASON_BREAK || reason == KDB_REASON_DEBUG)
46110 +        && db_result == KDB_DB_NOBPT) {
46111 +               KDB_DEBUG_STATE("kdb 2", reason);
46112 +               goto out;       /* Not one of mine */
46113 +       }
46114 +
46115 +       /* Turn off single step if it was being used */
46116 +       if (ss_event) {
46117 +               kdba_clearsinglestep(regs);
46118 +               /* Single step after a breakpoint removes the need for a delayed reinstall */
46119 +               if (reason == KDB_REASON_BREAK || reason == KDB_REASON_DEBUG)
46120 +                       KDB_STATE_CLEAR(SSBPT);
46121 +       }
46122 +
46123 +       /* kdb can validly reenter but only for certain well defined conditions */
46124 +       if (reason == KDB_REASON_DEBUG
46125 +        && !KDB_STATE(HOLD_CPU)
46126 +        && ss_event)
46127 +               KDB_STATE_SET(REENTRY);
46128 +       else
46129 +               KDB_STATE_CLEAR(REENTRY);
46130 +
46131 +       /* Wait for previous kdb event to completely exit before starting
46132 +        * a new event.
46133 +        */
46134 +       while (kdb_previous_event())
46135 +               ;
46136 +       KDB_DEBUG_STATE("kdb 3", reason);
46137 +
46138 +       /*
46139 +        * If kdb is already active, print a message and try to recover.
46140 +        * If recovery is not possible and recursion is allowed or
46141 +        * forced recursion without recovery is set then try to recurse
46142 +        * in kdb.  Not guaranteed to work but it makes an attempt at
46143 +        * debugging the debugger.
46144 +        */
46145 +       if (reason != KDB_REASON_SWITCH &&
46146 +           reason != KDB_REASON_ENTER_SLAVE) {
46147 +               if (KDB_IS_RUNNING() && !KDB_STATE(REENTRY)) {
46148 +                       int recover = 1;
46149 +                       unsigned long recurse = 0;
46150 +                       kdb_printf("kdb: Debugger re-entered on cpu %d, new reason = %d\n",
46151 +                               smp_processor_id(), reason);
46152 +                       /* Should only re-enter from released cpu */
46153 +
46154 +                       if (KDB_STATE(HOLD_CPU)) {
46155 +                               kdb_printf("     Strange, cpu %d should not be running\n", smp_processor_id());
46156 +                               recover = 0;
46157 +                       }
46158 +                       if (!KDB_STATE(CMD)) {
46159 +                               kdb_printf("     Not executing a kdb command\n");
46160 +                               recover = 0;
46161 +                       }
46162 +                       if (!KDB_STATE(LONGJMP)) {
46163 +                               kdb_printf("     No longjmp available for recovery\n");
46164 +                               recover = 0;
46165 +                       }
46166 +                       kdbgetulenv("RECURSE", &recurse);
46167 +                       if (recurse > 1) {
46168 +                               kdb_printf("     Forced recursion is set\n");
46169 +                               recover = 0;
46170 +                       }
46171 +                       if (recover) {
46172 +                               kdb_printf("     Attempting to abort command and recover\n");
46173 +#ifdef kdba_setjmp
46174 +                               kdba_longjmp(&kdbjmpbuf[smp_processor_id()], 0);
46175 +#endif /* kdba_setjmp */
46176 +                       }
46177 +                       if (recurse) {
46178 +                               if (KDB_STATE(RECURSE)) {
46179 +                                       kdb_printf("     Already in recursive mode\n");
46180 +                               } else {
46181 +                                       kdb_printf("     Attempting recursive mode\n");
46182 +                                       KDB_STATE_SET(RECURSE);
46183 +                                       KDB_STATE_SET(REENTRY);
46184 +                                       reason2 = KDB_REASON_RECURSE;
46185 +                                       recover = 1;
46186 +                               }
46187 +                       }
46188 +                       if (!recover) {
46189 +                               kdb_printf("     Cannot recover, allowing event to proceed\n");
46190 +                               /*temp*/
46191 +                               while (KDB_IS_RUNNING())
46192 +                                       cpu_relax();
46193 +                               goto out;
46194 +                       }
46195 +               }
46196 +       } else if (reason == KDB_REASON_SWITCH && !KDB_IS_RUNNING()) {
46197 +               kdb_printf("kdb: CPU switch without kdb running, I'm confused\n");
46198 +               goto out;
46199 +       }
46200 +
46201 +       /*
46202 +        * Disable interrupts, breakpoints etc. on this processor
46203 +        * during kdb command processing
46204 +        */
46205 +       KDB_STATE_SET(KDB);
46206 +       kdba_disableint(&int_state);
46207 +       if (!KDB_STATE(KDB_CONTROL)) {
46208 +               kdb_bp_remove_local();
46209 +               KDB_STATE_SET(KDB_CONTROL);
46210 +       }
46211 +
46212 +       /*
46213 +        * If not entering the debugger due to CPU switch or single step
46214 +        * reentry, serialize access here.
46215 +        * The processors may race getting to this point - if,
46216 +        * for example, more than one processor hits a breakpoint
46217 +        * at the same time.   We'll serialize access to kdb here -
46218 +        * other processors will loop here, and the NMI from the stop
46219 +        * IPI will take them into kdb as switch candidates.  Once
46220 +        * the initial processor releases the debugger, the rest of
46221 +        * the processors will race for it.
46222 +        *
46223 +        * The above describes the normal state of affairs, where two or more
46224 +        * cpus that are entering kdb at the "same" time are assumed to be for
46225 +        * separate events.  However some processes such as ia64 MCA/INIT will
46226 +        * drive all the cpus into error processing at the same time.  For that
46227 +        * case, all of the cpus entering kdb at the "same" time are really a
46228 +        * single event.
46229 +        *
46230 +        * That case is handled by the use of KDB_ENTER by one cpu (the
46231 +        * monarch) and KDB_ENTER_SLAVE on the other cpus (the slaves).
46232 +        * KDB_ENTER_SLAVE maps to KDB_REASON_ENTER_SLAVE.  The slave events
46233 +        * will be treated as if they had just responded to the kdb IPI, i.e.
46234 +        * as if they were KDB_REASON_SWITCH.
46235 +        *
46236 +        * Because of races across multiple cpus, ENTER_SLAVE can occur before
46237 +        * the main ENTER.   Hold up ENTER_SLAVE here until the main ENTER
46238 +        * arrives.
46239 +        */
46240 +
46241 +       if (reason == KDB_REASON_ENTER_SLAVE) {
46242 +               spin_lock(&kdb_lock);
46243 +               while (!KDB_IS_RUNNING()) {
46244 +                       spin_unlock(&kdb_lock);
46245 +                       while (!KDB_IS_RUNNING())
46246 +                               cpu_relax();
46247 +                       spin_lock(&kdb_lock);
46248 +               }
46249 +               reason = KDB_REASON_SWITCH;
46250 +               KDB_STATE_SET(HOLD_CPU);
46251 +               spin_unlock(&kdb_lock);
46252 +       }
46253 +
46254 +       if (reason == KDB_REASON_SWITCH || KDB_STATE(REENTRY))
46255 +               ;       /* drop through */
46256 +       else {
46257 +               KDB_DEBUG_STATE("kdb 4", reason);
46258 +               spin_lock(&kdb_lock);
46259 +               while (KDB_IS_RUNNING() || kdb_previous_event()) {
46260 +                       spin_unlock(&kdb_lock);
46261 +                       while (KDB_IS_RUNNING() || kdb_previous_event())
46262 +                               cpu_relax();
46263 +                       spin_lock(&kdb_lock);
46264 +               }
46265 +               KDB_DEBUG_STATE("kdb 5", reason);
46266 +
46267 +               kdb_initial_cpu = smp_processor_id();
46268 +               ++kdb_seqno;
46269 +               spin_unlock(&kdb_lock);
46270 +               if (!kdb_quiet(reason))
46271 +                       notify_die(DIE_KDEBUG_ENTER, "KDEBUG ENTER", regs, error, 0, 0);
46272 +       }
46273 +
46274 +       if (smp_processor_id() == kdb_initial_cpu
46275 +        && !KDB_STATE(REENTRY)) {
46276 +               KDB_STATE_CLEAR(HOLD_CPU);
46277 +               KDB_STATE_CLEAR(WAIT_IPI);
46278 +               kdb_check_i8042();
46279 +               /*
46280 +                * Remove the global breakpoints.  This is only done
46281 +                * once from the initial processor on initial entry.
46282 +                */
46283 +               if (!kdb_quiet(reason) || smp_processor_id() == 0)
46284 +                       kdb_bp_remove_global();
46285 +
46286 +               /*
46287 +                * If SMP, stop other processors.  The other processors
46288 +                * will enter kdb() with KDB_REASON_SWITCH and spin in
46289 +                * kdb_main_loop().
46290 +                */
46291 +               KDB_DEBUG_STATE("kdb 6", reason);
46292 +               if (NR_CPUS > 1 && !kdb_quiet(reason)) {
46293 +                       int i;
46294 +                       for (i = 0; i < NR_CPUS; ++i) {
46295 +                               if (!cpu_online(i))
46296 +                                       continue;
46297 +                               if (i != kdb_initial_cpu) {
46298 +                                       KDB_STATE_SET_CPU(HOLD_CPU, i);
46299 +                                       KDB_STATE_SET_CPU(WAIT_IPI, i);
46300 +                               }
46301 +                       }
46302 +                       KDB_DEBUG_STATE("kdb 7", reason);
46303 +                       smp_kdb_stop();
46304 +                       KDB_DEBUG_STATE("kdb 8", reason);
46305 +               }
46306 +       }
46307 +
46308 +       if (KDB_STATE(GO1)) {
46309 +               kdb_bp_remove_global();         /* They were set for single-step purposes */
46310 +               KDB_STATE_CLEAR(GO1);
46311 +               reason = KDB_REASON_SILENT;     /* Now silently go */
46312 +       }
46313 +
46314 +       /* Set up a consistent set of process stacks before talking to the user */
46315 +       KDB_DEBUG_STATE("kdb 9", result);
46316 +       result = kdba_main_loop(reason, reason2, error, db_result, regs);
46317 +
46318 +       KDB_DEBUG_STATE("kdb 10", result);
46319 +       kdba_adjust_ip(reason2, error, regs);
46320 +       KDB_STATE_CLEAR(LONGJMP);
46321 +       KDB_DEBUG_STATE("kdb 11", result);
46322 +       /* go which requires single-step over a breakpoint must only release
46323 +        * one cpu.
46324 +        */
46325 +       if (result == KDB_CMD_GO && KDB_STATE(SSBPT))
46326 +               KDB_STATE_SET(GO1);
46327 +
46328 +       if (smp_processor_id() == kdb_initial_cpu &&
46329 +         !KDB_STATE(DOING_SS) &&
46330 +         !KDB_STATE(RECURSE)) {
46331 +               /*
46332 +                * (Re)install the global breakpoints and cleanup the cached
46333 +                * symbol table.  This is only done once from the initial
46334 +                * processor on go.
46335 +                */
46336 +               KDB_DEBUG_STATE("kdb 12", reason);
46337 +               if (!kdb_quiet(reason) || smp_processor_id() == 0) {
46338 +                       kdb_bp_install_global(regs);
46339 +                       kdbnearsym_cleanup();
46340 +                       debug_kusage();
46341 +               }
46342 +               if (!KDB_STATE(GO1)) {
46343 +                       /*
46344 +                        * Release all other cpus which will see KDB_STATE(LEAVING) is set.
46345 +                        */
46346 +                       int i;
46347 +                       for (i = 0; i < NR_CPUS; ++i) {
46348 +                               if (KDB_STATE_CPU(KDB, i))
46349 +                                       KDB_STATE_SET_CPU(LEAVING, i);
46350 +                               KDB_STATE_CLEAR_CPU(WAIT_IPI, i);
46351 +                               KDB_STATE_CLEAR_CPU(HOLD_CPU, i);
46352 +                       }
46353 +                       /* Wait until all the other processors leave kdb */
46354 +                       while (kdb_previous_event() != 1)
46355 +                               ;
46356 +                       if (!kdb_quiet(reason))
46357 +                               notify_die(DIE_KDEBUG_LEAVE, "KDEBUG LEAVE", regs, error, 0, 0);
46358 +                       kdb_initial_cpu = -1;   /* release kdb control */
46359 +                       KDB_DEBUG_STATE("kdb 13", reason);
46360 +               }
46361 +       }
46362 +
46363 +       KDB_DEBUG_STATE("kdb 14", result);
46364 +       kdba_restoreint(&int_state);
46365 +#ifdef  CONFIG_CPU_XSCALE
46366 +       if ( smp_processor_id() == kdb_initial_cpu &&
46367 +            ( KDB_STATE(SSBPT) | KDB_STATE(DOING_SS) )
46368 +             ) {
46369 +               kdba_setsinglestep(regs);
46370 +               // disable IRQ in stack frame
46371 +               KDB_STATE_SET(A_XSC_ICH);
46372 +               if ( kdba_disable_retirq(regs) ) {
46373 +                       KDB_STATE_SET(A_XSC_IRQ);
46374 +               }
46375 +               else {
46376 +                       KDB_STATE_CLEAR(A_XSC_IRQ);
46377 +               }
46378 +       }
46379 +#endif
46380 +
46381 +       /* Only do this work if we are really leaving kdb */
46382 +       if (!(KDB_STATE(DOING_SS) || KDB_STATE(SSBPT) || KDB_STATE(RECURSE))) {
46383 +               KDB_DEBUG_STATE("kdb 15", result);
46384 +               kdb_bp_install_local(regs);
46385 +               if (old_regs_saved)
46386 +                       set_irq_regs(old_regs);
46387 +               KDB_STATE_CLEAR(KDB_CONTROL);
46388 +       }
46389 +
46390 +       KDB_DEBUG_STATE("kdb 16", result);
46391 +       KDB_FLAG_CLEAR(CATASTROPHIC);
46392 +       KDB_STATE_CLEAR(IP_ADJUSTED);   /* Re-adjust ip next time in */
46393 +       KDB_STATE_CLEAR(KEYBOARD);
46394 +       KDB_STATE_CLEAR(KDB);           /* Main kdb state has been cleared */
46395 +       KDB_STATE_CLEAR(RECURSE);
46396 +       KDB_STATE_CLEAR(LEAVING);       /* No more kdb work after this */
46397 +       KDB_DEBUG_STATE("kdb 17", reason);
46398 +out:
46399 +       atomic_dec(&kdb_event);
46400 +       preempt_enable();
46401 +       return result != 0;
46402 +}
46403 +
46404 +/*
46405 + * kdb_mdr
46406 + *
46407 + *     This function implements the guts of the 'mdr' command.
46408 + *
46409 + *     mdr  <addr arg>,<byte count>
46410 + *
46411 + * Inputs:
46412 + *     addr    Start address
46413 + *     count   Number of bytes
46414 + * Outputs:
46415 + *     None.
46416 + * Returns:
46417 + *     Always 0.  Any errors are detected and printed by kdb_getarea.
46418 + * Locking:
46419 + *     none.
46420 + * Remarks:
46421 + */
46422 +
46423 +static int
46424 +kdb_mdr(kdb_machreg_t addr, unsigned int count)
46425 +{
46426 +       unsigned char c;
46427 +       while (count--) {
46428 +               if (kdb_getarea(c, addr))
46429 +                       return 0;
46430 +               kdb_printf("%02x", c);
46431 +               addr++;
46432 +       }
46433 +       kdb_printf("\n");
46434 +       return 0;
46435 +}
46436 +
46437 +/*
46438 + * kdb_md
46439 + *
46440 + *     This function implements the 'md', 'md1', 'md2', 'md4', 'md8'
46441 + *     'mdr' and 'mds' commands.
46442 + *
46443 + *     md|mds  [<addr arg> [<line count> [<radix>]]]
46444 + *     mdWcN   [<addr arg> [<line count> [<radix>]]]
46445 + *             where W = is the width (1, 2, 4 or 8) and N is the count.
46446 + *             for eg., md1c20 reads 20 bytes, 1 at a time.
46447 + *     mdr  <addr arg>,<byte count>
46448 + *
46449 + * Inputs:
46450 + *     argc    argument count
46451 + *     argv    argument vector
46452 + * Outputs:
46453 + *     None.
46454 + * Returns:
46455 + *     zero for success, a kdb diagnostic if error
46456 + * Locking:
46457 + *     none.
46458 + * Remarks:
46459 + */
46460 +
46461 +static void
46462 +kdb_md_line(const char *fmtstr, kdb_machreg_t addr,
46463 +           int symbolic, int nosect, int bytesperword,
46464 +           int num, int repeat, int phys)
46465 +{
46466 +       /* print just one line of data */
46467 +       kdb_symtab_t symtab;
46468 +       char cbuf[32];
46469 +       char *c = cbuf;
46470 +       int i;
46471 +       unsigned long word;
46472 +
46473 +       memset(cbuf, '\0', sizeof(cbuf));
46474 +       if (phys)
46475 +               kdb_printf("phys " kdb_machreg_fmt0 " ", addr);
46476 +       else
46477 +               kdb_printf(kdb_machreg_fmt0 " ", addr);
46478 +
46479 +       for (i = 0; i < num && repeat--; i++) {
46480 +               if (phys) {
46481 +                       if (kdb_getphysword(&word, addr, bytesperword))
46482 +                               break;
46483 +               } else if (kdb_getword(&word, addr, bytesperword))
46484 +                       break;
46485 +               kdb_printf(fmtstr, word);
46486 +               if (symbolic)
46487 +                       kdbnearsym(word, &symtab);
46488 +               else
46489 +                       memset(&symtab, 0, sizeof(symtab));
46490 +               if (symtab.sym_name) {
46491 +                       kdb_symbol_print(word, &symtab, 0);
46492 +                       if (!nosect) {
46493 +                               kdb_printf("\n");
46494 +                               kdb_printf("                       %s %s "
46495 +                                          kdb_machreg_fmt " " kdb_machreg_fmt " " kdb_machreg_fmt,
46496 +                                       symtab.mod_name,
46497 +                                       symtab.sec_name,
46498 +                                       symtab.sec_start,
46499 +                                       symtab.sym_start,
46500 +                                       symtab.sym_end);
46501 +                       }
46502 +                       addr += bytesperword;
46503 +               } else {
46504 +                       union {
46505 +                               u64 word;
46506 +                               unsigned char c[8];
46507 +                       } wc;
46508 +                       unsigned char *cp;
46509 +#ifdef __BIG_ENDIAN
46510 +                       cp = wc.c + 8 - bytesperword;
46511 +#else
46512 +                       cp = wc.c;
46513 +#endif
46514 +                       wc.word = word;
46515 +#define printable_char(c) ({unsigned char __c = c; isascii(__c) && isprint(__c) ? __c : '.';})
46516 +                       switch (bytesperword) {
46517 +                       case 8:
46518 +                               *c++ = printable_char(*cp++);
46519 +                               *c++ = printable_char(*cp++);
46520 +                               *c++ = printable_char(*cp++);
46521 +                               *c++ = printable_char(*cp++);
46522 +                               addr += 4;
46523 +                       case 4:
46524 +                               *c++ = printable_char(*cp++);
46525 +                               *c++ = printable_char(*cp++);
46526 +                               addr += 2;
46527 +                       case 2:
46528 +                               *c++ = printable_char(*cp++);
46529 +                               addr++;
46530 +                       case 1:
46531 +                               *c++ = printable_char(*cp++);
46532 +                               addr++;
46533 +                               break;
46534 +                       }
46535 +#undef printable_char
46536 +               }
46537 +       }
46538 +       kdb_printf("%*s %s\n", (int)((num-i)*(2*bytesperword + 1)+1), " ", cbuf);
46539 +}
46540 +
46541 +static int
46542 +kdb_md(int argc, const char **argv)
46543 +{
46544 +       static kdb_machreg_t last_addr;
46545 +       static int last_radix, last_bytesperword, last_repeat;
46546 +       int radix = 16, mdcount = 8, bytesperword = KDB_WORD_SIZE, repeat;
46547 +       int nosect = 0;
46548 +       char fmtchar, fmtstr[64];
46549 +       kdb_machreg_t addr;
46550 +       unsigned long word;
46551 +       long offset = 0;
46552 +       int symbolic = 0;
46553 +       int valid = 0;
46554 +       int phys = 0;
46555 +
46556 +       kdbgetintenv("MDCOUNT", &mdcount);
46557 +       kdbgetintenv("RADIX", &radix);
46558 +       kdbgetintenv("BYTESPERWORD", &bytesperword);
46559 +
46560 +       /* Assume 'md <addr>' and start with environment values */
46561 +       repeat = mdcount * 16 / bytesperword;
46562 +
46563 +       if (strcmp(argv[0], "mdr") == 0) {
46564 +               if (argc != 2)
46565 +                       return KDB_ARGCOUNT;
46566 +               valid = 1;
46567 +       } else if (isdigit(argv[0][2])) {
46568 +               bytesperword = (int)(argv[0][2] - '0');
46569 +               if (bytesperword == 0) {
46570 +                       bytesperword = last_bytesperword;
46571 +                       if (bytesperword == 0) {
46572 +                               bytesperword = 4;
46573 +                       }
46574 +               }
46575 +               last_bytesperword = bytesperword;
46576 +               repeat = mdcount * 16 / bytesperword;
46577 +               if (!argv[0][3])
46578 +                       valid = 1;
46579 +               else if (argv[0][3] == 'c' && argv[0][4]) {
46580 +                       char *p;
46581 +                       repeat = simple_strtoul(argv[0]+4, &p, 10);
46582 +                       mdcount = ((repeat * bytesperword) + 15) / 16;
46583 +                       valid = !*p;
46584 +               }
46585 +               last_repeat = repeat;
46586 +       } else if (strcmp(argv[0], "md") == 0)
46587 +               valid = 1;
46588 +       else if (strcmp(argv[0], "mds") == 0)
46589 +               valid = 1;
46590 +       else if (strcmp(argv[0], "mdp") == 0) {
46591 +               phys = valid = 1;
46592 +       }
46593 +       if (!valid)
46594 +               return KDB_NOTFOUND;
46595 +
46596 +       if (argc == 0) {
46597 +               if (last_addr == 0)
46598 +                       return KDB_ARGCOUNT;
46599 +               addr = last_addr;
46600 +               radix = last_radix;
46601 +               bytesperword = last_bytesperword;
46602 +               repeat = last_repeat;
46603 +               mdcount = ((repeat * bytesperword) + 15) / 16;
46604 +       }
46605 +
46606 +       if (argc) {
46607 +               kdb_machreg_t val;
46608 +               int diag, nextarg = 1;
46609 +               diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL);
46610 +               if (diag)
46611 +                       return diag;
46612 +               if (argc > nextarg+2)
46613 +                       return KDB_ARGCOUNT;
46614 +
46615 +               if (argc >= nextarg) {
46616 +                       diag = kdbgetularg(argv[nextarg], &val);
46617 +                       if (!diag) {
46618 +                               mdcount = (int) val;
46619 +                               repeat = mdcount * 16 / bytesperword;
46620 +                       }
46621 +               }
46622 +               if (argc >= nextarg+1) {
46623 +                       diag = kdbgetularg(argv[nextarg+1], &val);
46624 +                       if (!diag)
46625 +                               radix = (int) val;
46626 +               }
46627 +       }
46628 +
46629 +       if (strcmp(argv[0], "mdr") == 0) {
46630 +               return kdb_mdr(addr, mdcount);
46631 +       }
46632 +
46633 +       switch (radix) {
46634 +       case 10:
46635 +               fmtchar = 'd';
46636 +               break;
46637 +       case 16:
46638 +               fmtchar = 'x';
46639 +               break;
46640 +       case 8:
46641 +               fmtchar = 'o';
46642 +               break;
46643 +       default:
46644 +               return KDB_BADRADIX;
46645 +       }
46646 +
46647 +       last_radix = radix;
46648 +
46649 +       if (bytesperword > KDB_WORD_SIZE)
46650 +               return KDB_BADWIDTH;
46651 +
46652 +       switch (bytesperword) {
46653 +       case 8:
46654 +               sprintf(fmtstr, "%%16.16l%c ", fmtchar);
46655 +               break;
46656 +       case 4:
46657 +               sprintf(fmtstr, "%%8.8l%c ", fmtchar);
46658 +               break;
46659 +       case 2:
46660 +               sprintf(fmtstr, "%%4.4l%c ", fmtchar);
46661 +               break;
46662 +       case 1:
46663 +               sprintf(fmtstr, "%%2.2l%c ", fmtchar);
46664 +               break;
46665 +       default:
46666 +               return KDB_BADWIDTH;
46667 +       }
46668 +
46669 +       last_repeat = repeat;
46670 +       last_bytesperword = bytesperword;
46671 +
46672 +       if (strcmp(argv[0], "mds") == 0) {
46673 +               symbolic = 1;
46674 +               /* Do not save these changes as last_*, they are temporary mds
46675 +                * overrides.
46676 +                */
46677 +               bytesperword = KDB_WORD_SIZE;
46678 +               repeat = mdcount;
46679 +               kdbgetintenv("NOSECT", &nosect);
46680 +       }
46681 +
46682 +       /* Round address down modulo BYTESPERWORD */
46683 +
46684 +       addr &= ~(bytesperword-1);
46685 +
46686 +       while (repeat > 0) {
46687 +               unsigned long a;
46688 +               int n, z, num = (symbolic ? 1 : (16 / bytesperword));
46689 +
46690 +               for (a = addr, z = 0; z < repeat; a += bytesperword, ++z) {
46691 +                       if (phys) {
46692 +                               if (kdb_getphysword(&word, a, bytesperword)
46693 +                                               || word)
46694 +                                       break;
46695 +                       } else if (kdb_getword(&word, a, bytesperword) || word)
46696 +                               break;
46697 +               }
46698 +               n = min(num, repeat);
46699 +               kdb_md_line(fmtstr, addr, symbolic, nosect, bytesperword, num, repeat, phys);
46700 +               addr += bytesperword * n;
46701 +               repeat -= n;
46702 +               z = (z + num - 1) / num;
46703 +               if (z > 2) {
46704 +                       int s = num * (z-2);
46705 +                       kdb_printf(kdb_machreg_fmt0 "-" kdb_machreg_fmt0 " zero suppressed\n",
46706 +                               addr, addr + bytesperword * s - 1);
46707 +                       addr += bytesperword * s;
46708 +                       repeat -= s;
46709 +               }
46710 +       }
46711 +       last_addr = addr;
46712 +
46713 +       return 0;
46714 +}
46715 +
46716 +/*
46717 + * kdb_mm
46718 + *
46719 + *     This function implements the 'mm' command.
46720 + *
46721 + *     mm address-expression new-value
46722 + *
46723 + * Inputs:
46724 + *     argc    argument count
46725 + *     argv    argument vector
46726 + * Outputs:
46727 + *     None.
46728 + * Returns:
46729 + *     zero for success, a kdb diagnostic if error
46730 + * Locking:
46731 + *     none.
46732 + * Remarks:
46733 + *     mm works on machine words, mmW works on bytes.
46734 + */
46735 +
46736 +static int
46737 +kdb_mm(int argc, const char **argv)
46738 +{
46739 +       int diag;
46740 +       kdb_machreg_t addr;
46741 +       long offset = 0;
46742 +       unsigned long contents;
46743 +       int nextarg;
46744 +       int width;
46745 +
46746 +       if (argv[0][2] && !isdigit(argv[0][2]))
46747 +               return KDB_NOTFOUND;
46748 +
46749 +       if (argc < 2) {
46750 +               return KDB_ARGCOUNT;
46751 +       }
46752 +
46753 +       nextarg = 1;
46754 +       if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)))
46755 +               return diag;
46756 +
46757 +       if (nextarg > argc)
46758 +               return KDB_ARGCOUNT;
46759 +
46760 +       if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &contents, NULL, NULL)))
46761 +               return diag;
46762 +
46763 +       if (nextarg != argc + 1)
46764 +               return KDB_ARGCOUNT;
46765 +
46766 +       width = argv[0][2] ? (argv[0][2] - '0') : (KDB_WORD_SIZE);
46767 +       if ((diag = kdb_putword(addr, contents, width)))
46768 +               return diag;
46769 +
46770 +       kdb_printf(kdb_machreg_fmt " = " kdb_machreg_fmt "\n", addr, contents);
46771 +
46772 +       return 0;
46773 +}
46774 +
46775 +/*
46776 + * kdb_go
46777 + *
46778 + *     This function implements the 'go' command.
46779 + *
46780 + *     go [address-expression]
46781 + *
46782 + * Inputs:
46783 + *     argc    argument count
46784 + *     argv    argument vector
46785 + * Outputs:
46786 + *     None.
46787 + * Returns:
46788 + *     KDB_CMD_GO for success, a kdb diagnostic if error
46789 + * Locking:
46790 + *     none.
46791 + * Remarks:
46792 + */
46793 +
46794 +static int
46795 +kdb_go(int argc, const char **argv)
46796 +{
46797 +       kdb_machreg_t addr;
46798 +       int diag;
46799 +       int nextarg;
46800 +       long offset;
46801 +       struct pt_regs *regs = get_irq_regs();
46802 +
46803 +       if (argc == 1) {
46804 +               if (smp_processor_id() != kdb_initial_cpu) {
46805 +                       kdb_printf("go <address> must be issued from the initial cpu, do cpu %d first\n", kdb_initial_cpu);
46806 +                       return KDB_ARGCOUNT;
46807 +               }
46808 +               nextarg = 1;
46809 +               diag = kdbgetaddrarg(argc, argv, &nextarg,
46810 +                                    &addr, &offset, NULL);
46811 +               if (diag)
46812 +                       return diag;
46813 +
46814 +               kdba_setpc(regs, addr);
46815 +       } else if (argc)
46816 +               return KDB_ARGCOUNT;
46817 +
46818 +       diag = KDB_CMD_GO;
46819 +       if (KDB_FLAG(CATASTROPHIC)) {
46820 +               kdb_printf("Catastrophic error detected\n");
46821 +               kdb_printf("kdb_continue_catastrophic=%d, ",
46822 +                       kdb_continue_catastrophic);
46823 +               if (kdb_continue_catastrophic == 0 && kdb_go_count++ == 0) {
46824 +                       kdb_printf("type go a second time if you really want to continue\n");
46825 +                       return 0;
46826 +               }
46827 +               if (kdb_continue_catastrophic == 2) {
46828 +                       kdb_do_dump();
46829 +                       kdb_printf("forcing reboot\n");
46830 +                       kdb_reboot(0, NULL);
46831 +               }
46832 +               kdb_printf("attempting to continue\n");
46833 +       }
46834 +       if (smp_processor_id() != kdb_initial_cpu) {
46835 +               char buf[80];
46836 +               kdb_printf("go was not issued from initial cpu, switching back to cpu %d\n", kdb_initial_cpu);
46837 +               sprintf(buf, "cpu %d\n", kdb_initial_cpu);
46838 +               /* Recursive use of kdb_parse, do not use argv after this point */
46839 +               argv = NULL;
46840 +               diag = kdb_parse(buf);
46841 +               if (diag == KDB_CMD_CPU)
46842 +                       KDB_STATE_SET_CPU(GO_SWITCH, kdb_initial_cpu);
46843 +       }
46844 +       return diag;
46845 +}
46846 +
46847 +/*
46848 + * kdb_rd
46849 + *
46850 + *     This function implements the 'rd' command.
46851 + *
46852 + *     rd              display all general registers.
46853 + *     rd  c           display all control registers.
46854 + *     rd  d           display all debug registers.
46855 + *
46856 + * Inputs:
46857 + *     argc    argument count
46858 + *     argv    argument vector
46859 + * Outputs:
46860 + *     None.
46861 + * Returns:
46862 + *     zero for success, a kdb diagnostic if error
46863 + * Locking:
46864 + *     none.
46865 + * Remarks:
46866 + */
46867 +
46868 +static int
46869 +kdb_rd(int argc, const char **argv)
46870 +{
46871 +       int diag;
46872 +       if (argc == 0) {
46873 +               if ((diag = kdb_check_regs()))
46874 +                       return diag;
46875 +               return kdba_dumpregs(kdb_current_regs, NULL, NULL);
46876 +       }
46877 +
46878 +       if (argc > 2) {
46879 +               return KDB_ARGCOUNT;
46880 +       }
46881 +
46882 +       if ((diag = kdb_check_regs()))
46883 +               return diag;
46884 +       return kdba_dumpregs(kdb_current_regs, argv[1], argc==2 ? argv[2]: NULL);
46885 +}
46886 +
46887 +/*
46888 + * kdb_rm
46889 + *
46890 + *     This function implements the 'rm' (register modify)  command.
46891 + *
46892 + *     rm register-name new-contents
46893 + *
46894 + * Inputs:
46895 + *     argc    argument count
46896 + *     argv    argument vector
46897 + * Outputs:
46898 + *     None.
46899 + * Returns:
46900 + *     zero for success, a kdb diagnostic if error
46901 + * Locking:
46902 + *     none.
46903 + * Remarks:
46904 + *     Currently doesn't allow modification of control or
46905 + *     debug registers.
46906 + */
46907 +
46908 +static int
46909 +kdb_rm(int argc, const char **argv)
46910 +{
46911 +       int diag;
46912 +       int ind = 0;
46913 +       kdb_machreg_t contents;
46914 +
46915 +       if (argc != 2) {
46916 +               return KDB_ARGCOUNT;
46917 +       }
46918 +
46919 +       /*
46920 +        * Allow presence or absence of leading '%' symbol.
46921 +        */
46922 +
46923 +       if (argv[1][0] == '%')
46924 +               ind = 1;
46925 +
46926 +       diag = kdbgetularg(argv[2], &contents);
46927 +       if (diag)
46928 +               return diag;
46929 +
46930 +       if ((diag = kdb_check_regs()))
46931 +               return diag;
46932 +       diag = kdba_setregcontents(&argv[1][ind], kdb_current_regs, contents);
46933 +       if (diag)
46934 +               return diag;
46935 +
46936 +       return 0;
46937 +}
46938 +
46939 +#if defined(CONFIG_MAGIC_SYSRQ)
46940 +/*
46941 + * kdb_sr
46942 + *
46943 + *     This function implements the 'sr' (SYSRQ key) command which
46944 + *     interfaces to the soi-disant MAGIC SYSRQ functionality.
46945 + *
46946 + *     sr <magic-sysrq-code>
46947 + *
46948 + * Inputs:
46949 + *     argc    argument count
46950 + *     argv    argument vector
46951 + * Outputs:
46952 + *     None.
46953 + * Returns:
46954 + *     zero for success, a kdb diagnostic if error
46955 + * Locking:
46956 + *     none.
46957 + * Remarks:
46958 + *     None.
46959 + */
46960 +static int
46961 +kdb_sr(int argc, const char **argv)
46962 +{
46963 +       extern int __sysrq_enabled;
46964 +       if (argc != 1) {
46965 +               return KDB_ARGCOUNT;
46966 +       }
46967 +       if (!__sysrq_enabled) {
46968 +               kdb_printf("Auto activating sysrq\n");
46969 +               __sysrq_enabled = 1;
46970 +       }
46971 +
46972 +       handle_sysrq(*argv[1], NULL);
46973 +
46974 +       return 0;
46975 +}
46976 +#endif /* CONFIG_MAGIC_SYSRQ */
46977 +
46978 +/*
46979 + * kdb_ef
46980 + *
46981 + *     This function implements the 'regs' (display exception frame)
46982 + *     command.  This command takes an address and expects to find
46983 + *     an exception frame at that address, formats and prints it.
46984 + *
46985 + *     regs address-expression
46986 + *
46987 + * Inputs:
46988 + *     argc    argument count
46989 + *     argv    argument vector
46990 + * Outputs:
46991 + *     None.
46992 + * Returns:
46993 + *     zero for success, a kdb diagnostic if error
46994 + * Locking:
46995 + *     none.
46996 + * Remarks:
46997 + *     Not done yet.
46998 + */
46999 +
47000 +static int
47001 +kdb_ef(int argc, const char **argv)
47002 +{
47003 +       int diag;
47004 +       kdb_machreg_t addr;
47005 +       long offset;
47006 +       int nextarg;
47007 +
47008 +       if (argc == 1) {
47009 +               nextarg = 1;
47010 +               diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL);
47011 +               if (diag)
47012 +                       return diag;
47013 +
47014 +               return kdba_dumpregs((struct pt_regs *)addr, NULL, NULL);
47015 +       }
47016 +
47017 +       return KDB_ARGCOUNT;
47018 +}
47019 +
47020 +#if defined(CONFIG_MODULES)
47021 +extern struct list_head *kdb_modules;
47022 +extern void free_module(struct module *);
47023 +
47024 +/* modules using other modules */
47025 +struct module_use
47026 +{
47027 +       struct list_head list;
47028 +       struct module *module_which_uses;
47029 +};
47030 +
47031 +/*
47032 + * kdb_lsmod
47033 + *
47034 + *     This function implements the 'lsmod' command.  Lists currently
47035 + *     loaded kernel modules.
47036 + *
47037 + *     Mostly taken from userland lsmod.
47038 + *
47039 + * Inputs:
47040 + *     argc    argument count
47041 + *     argv    argument vector
47042 + * Outputs:
47043 + *     None.
47044 + * Returns:
47045 + *     zero for success, a kdb diagnostic if error
47046 + * Locking:
47047 + *     none.
47048 + * Remarks:
47049 + *
47050 + */
47051 +
47052 +static int
47053 +kdb_lsmod(int argc, const char **argv)
47054 +{
47055 +       struct module *mod;
47056 +
47057 +       if (argc != 0)
47058 +               return KDB_ARGCOUNT;
47059 +
47060 +       kdb_printf("Module                  Size  modstruct     Used by\n");
47061 +       list_for_each_entry(mod, kdb_modules, list) {
47062 +
47063 +               kdb_printf("%-20s%8lu  0x%p ", mod->name,
47064 +                          mod->core_size, (void *)mod);
47065 +#ifdef CONFIG_MODULE_UNLOAD
47066 +               kdb_printf("%4d ", module_refcount(mod));
47067 +#endif
47068 +               if (mod->state == MODULE_STATE_GOING)
47069 +                       kdb_printf(" (Unloading)");
47070 +               else if (mod->state == MODULE_STATE_COMING)
47071 +                       kdb_printf(" (Loading)");
47072 +               else
47073 +                       kdb_printf(" (Live)");
47074 +
47075 +#ifdef CONFIG_MODULE_UNLOAD
47076 +               {
47077 +                       struct module_use *use;
47078 +                       kdb_printf(" [ ");
47079 +                       list_for_each_entry(use, &mod->modules_which_use_me, list)
47080 +                               kdb_printf("%s ", use->module_which_uses->name);
47081 +                       kdb_printf("]\n");
47082 +               }
47083 +#endif
47084 +       }
47085 +
47086 +       return 0;
47087 +}
47088 +
47089 +#endif /* CONFIG_MODULES */
47090 +
47091 +/*
47092 + * kdb_env
47093 + *
47094 + *     This function implements the 'env' command.  Display the current
47095 + *     environment variables.
47096 + *
47097 + * Inputs:
47098 + *     argc    argument count
47099 + *     argv    argument vector
47100 + * Outputs:
47101 + *     None.
47102 + * Returns:
47103 + *     zero for success, a kdb diagnostic if error
47104 + * Locking:
47105 + *     none.
47106 + * Remarks:
47107 + */
47108 +
47109 +static int
47110 +kdb_env(int argc, const char **argv)
47111 +{
47112 +       int i;
47113 +
47114 +       for(i=0; i<__nenv; i++) {
47115 +               if (__env[i]) {
47116 +                       kdb_printf("%s\n", __env[i]);
47117 +               }
47118 +       }
47119 +
47120 +       if (KDB_DEBUG(MASK))
47121 +               kdb_printf("KDBFLAGS=0x%x\n", kdb_flags);
47122 +
47123 +       return 0;
47124 +}
47125 +
47126 +/*
47127 + * kdb_dmesg
47128 + *
47129 + *     This function implements the 'dmesg' command to display the contents
47130 + *     of the syslog buffer.
47131 + *
47132 + *     dmesg [lines] [adjust]
47133 + *
47134 + * Inputs:
47135 + *     argc    argument count
47136 + *     argv    argument vector
47137 + * Outputs:
47138 + *     None.
47139 + * Returns:
47140 + *     zero for success, a kdb diagnostic if error
47141 + * Locking:
47142 + *     none.
47143 + * Remarks:
47144 + *     None.
47145 + */
47146 +
47147 +static int
47148 +kdb_dmesg(int argc, const char **argv)
47149 +{
47150 +       char *syslog_data[4], *start, *end, c = '\0', *p;
47151 +       int diag, logging, logsize, lines = 0, adjust = 0, n;
47152 +
47153 +       if (argc > 2)
47154 +               return KDB_ARGCOUNT;
47155 +       if (argc) {
47156 +               char *cp;
47157 +               lines = simple_strtol(argv[1], &cp, 0);
47158 +               if (*cp)
47159 +                       lines = 0;
47160 +               if (argc > 1) {
47161 +                       adjust = simple_strtoul(argv[2], &cp, 0);
47162 +                       if (*cp || adjust < 0)
47163 +                               adjust = 0;
47164 +               }
47165 +       }
47166 +
47167 +       /* disable LOGGING if set */
47168 +       diag = kdbgetintenv("LOGGING", &logging);
47169 +       if (!diag && logging) {
47170 +               const char *setargs[] = { "set", "LOGGING", "0" };
47171 +               kdb_set(2, setargs);
47172 +       }
47173 +
47174 +       /* syslog_data[0,1] physical start, end+1.  syslog_data[2,3] logical start, end+1. */
47175 +       kdb_syslog_data(syslog_data);
47176 +       if (syslog_data[2] == syslog_data[3])
47177 +               return 0;
47178 +       logsize = syslog_data[1] - syslog_data[0];
47179 +       start = syslog_data[2];
47180 +       end = syslog_data[3];
47181 +#define KDB_WRAP(p) (((p - syslog_data[0]) % logsize) + syslog_data[0])
47182 +       for (n = 0, p = start; p < end; ++p) {
47183 +               if ((c = *KDB_WRAP(p)) == '\n')
47184 +                       ++n;
47185 +       }
47186 +       if (c != '\n')
47187 +               ++n;
47188 +       if (lines < 0) {
47189 +               if (adjust >= n)
47190 +                       kdb_printf("buffer only contains %d lines, nothing printed\n", n);
47191 +               else if (adjust - lines >= n)
47192 +                       kdb_printf("buffer only contains %d lines, last %d lines printed\n",
47193 +                               n, n - adjust);
47194 +               if (adjust) {
47195 +                       for (; start < end && adjust; ++start) {
47196 +                               if (*KDB_WRAP(start) == '\n')
47197 +                                       --adjust;
47198 +                       }
47199 +                       if (start < end)
47200 +                               ++start;
47201 +               }
47202 +               for (p = start; p < end && lines; ++p) {
47203 +                       if (*KDB_WRAP(p) == '\n')
47204 +                               ++lines;
47205 +               }
47206 +               end = p;
47207 +       } else if (lines > 0) {
47208 +               int skip = n - (adjust + lines);
47209 +               if (adjust >= n) {
47210 +                       kdb_printf("buffer only contains %d lines, nothing printed\n", n);
47211 +                       skip = n;
47212 +               } else if (skip < 0) {
47213 +                       lines += skip;
47214 +                       skip = 0;
47215 +                       kdb_printf("buffer only contains %d lines, first %d lines printed\n",
47216 +                               n, lines);
47217 +               }
47218 +               for (; start < end && skip; ++start) {
47219 +                       if (*KDB_WRAP(start) == '\n')
47220 +                               --skip;
47221 +               }
47222 +               for (p = start; p < end && lines; ++p) {
47223 +                       if (*KDB_WRAP(p) == '\n')
47224 +                               --lines;
47225 +               }
47226 +               end = p;
47227 +       }
47228 +       /* Do a line at a time (max 200 chars) to reduce protocol overhead */
47229 +       c = '\n';
47230 +       while (start != end) {
47231 +               char buf[201];
47232 +               p = buf;
47233 +               while (start < end && (c = *KDB_WRAP(start)) && (p - buf) < sizeof(buf)-1) {
47234 +                       ++start;
47235 +                       *p++ = c;
47236 +                       if (c == '\n')
47237 +                               break;
47238 +               }
47239 +               *p = '\0';
47240 +               kdb_printf("%s", buf);
47241 +       }
47242 +       if (c != '\n')
47243 +               kdb_printf("\n");
47244 +
47245 +       return 0;
47246 +}
47247 +
47248 +/*
47249 + * kdb_cpu
47250 + *
47251 + *     This function implements the 'cpu' command.
47252 + *
47253 + *     cpu     [<cpunum>]
47254 + *
47255 + * Inputs:
47256 + *     argc    argument count
47257 + *     argv    argument vector
47258 + * Outputs:
47259 + *     None.
47260 + * Returns:
47261 + *     KDB_CMD_CPU for success, a kdb diagnostic if error
47262 + * Locking:
47263 + *     none.
47264 + * Remarks:
47265 + *     All cpu's should be spinning in kdb().  However just in case
47266 + *     a cpu did not take the smp_kdb_stop NMI, check that a cpu
47267 + *     entered kdb() before passing control to it.
47268 + */
47269 +
47270 +static void
47271 +kdb_cpu_status(void)
47272 +{
47273 +       int i, start_cpu, first_print = 1;
47274 +       char state, prev_state = '?';
47275 +
47276 +       kdb_printf("Currently on cpu %d\n", smp_processor_id());
47277 +       kdb_printf("Available cpus: ");
47278 +       for (start_cpu = -1, i = 0; i < NR_CPUS; i++) {
47279 +               if (!cpu_online(i))
47280 +                       state = 'F';    /* cpu is offline */
47281 +               else {
47282 +                       struct kdb_running_process *krp = kdb_running_process+i;
47283 +                       if (KDB_STATE_CPU(KDB, i)) {
47284 +                               state = ' ';    /* cpu is responding to kdb */
47285 +                               if (kdb_task_state_char(krp->p) == 'I')
47286 +                                       state = 'I';    /* running the idle task */
47287 +                       } else if (krp->seqno && krp->p && krp->seqno >= kdb_seqno - 1)
47288 +                               state = '+';    /* some kdb data, but not responding */
47289 +                       else
47290 +                               state = '*';    /* no kdb data */
47291 +               }
47292 +               if (state != prev_state) {
47293 +                       if (prev_state != '?') {
47294 +                               if (!first_print)
47295 +                                       kdb_printf(", ");
47296 +                               first_print = 0;
47297 +                               kdb_printf("%d", start_cpu);
47298 +                               if (start_cpu < i-1)
47299 +                                       kdb_printf("-%d", i-1);
47300 +                               if (prev_state != ' ')
47301 +                                       kdb_printf("(%c)", prev_state);
47302 +                       }
47303 +                       prev_state = state;
47304 +                       start_cpu = i;
47305 +               }
47306 +       }
47307 +       /* print the trailing cpus, ignoring them if they are all offline */
47308 +       if (prev_state != 'F') {
47309 +               if (!first_print)
47310 +                       kdb_printf(", ");
47311 +               kdb_printf("%d", start_cpu);
47312 +               if (start_cpu < i-1)
47313 +                       kdb_printf("-%d", i-1);
47314 +               if (prev_state != ' ')
47315 +                       kdb_printf("(%c)", prev_state);
47316 +       }
47317 +       kdb_printf("\n");
47318 +}
47319 +
47320 +static int
47321 +kdb_cpu(int argc, const char **argv)
47322 +{
47323 +       unsigned long cpunum;
47324 +       int diag, i;
47325 +
47326 +       /* ask the other cpus if they are still active */
47327 +       for (i=0; i<NR_CPUS; i++) {
47328 +               if (cpu_online(i))
47329 +                       KDB_STATE_CLEAR_CPU(KDB, i);
47330 +       }
47331 +       KDB_STATE_SET(KDB);
47332 +       barrier();
47333 +       /* wait for the other cpus to notice and set state KDB again,
47334 +        * see kdb_main_loop
47335 +        */
47336 +       udelay(1000);
47337 +
47338 +       if (argc == 0) {
47339 +               kdb_cpu_status();
47340 +               return 0;
47341 +       }
47342 +
47343 +       if (argc != 1)
47344 +               return KDB_ARGCOUNT;
47345 +
47346 +       diag = kdbgetularg(argv[1], &cpunum);
47347 +       if (diag)
47348 +               return diag;
47349 +
47350 +       /*
47351 +        * Validate cpunum
47352 +        */
47353 +       if ((cpunum > NR_CPUS)
47354 +        || !cpu_online(cpunum)
47355 +        || !KDB_STATE_CPU(KDB, cpunum))
47356 +               return KDB_BADCPUNUM;
47357 +
47358 +       kdb_new_cpu = cpunum;
47359 +
47360 +       /*
47361 +        * Switch to other cpu
47362 +        */
47363 +       return KDB_CMD_CPU;
47364 +}
47365 +
47366 +/* The user may not realize that ps/bta with no parameters does not print idle
47367 + * or sleeping system daemon processes, so tell them how many were suppressed.
47368 + */
47369 +void
47370 +kdb_ps_suppressed(void)
47371 +{
47372 +       int idle = 0, daemon = 0;
47373 +       unsigned long mask_I = kdb_task_state_string("I"),
47374 +                     mask_M = kdb_task_state_string("M");
47375 +       unsigned long cpu;
47376 +       const struct task_struct *p, *g;
47377 +       for (cpu = 0; cpu < NR_CPUS; ++cpu) {
47378 +               if (!cpu_online(cpu))
47379 +                       continue;
47380 +               p = kdb_curr_task(cpu);
47381 +               if (kdb_task_state(p, mask_I))
47382 +                       ++idle;
47383 +       }
47384 +       kdb_do_each_thread(g, p) {
47385 +               if (kdb_task_state(p, mask_M))
47386 +                       ++daemon;
47387 +       } kdb_while_each_thread(g, p);
47388 +       if (idle || daemon) {
47389 +               if (idle)
47390 +                       kdb_printf("%d idle process%s (state I)%s",
47391 +                                  idle, idle == 1 ? "" : "es",
47392 +                                  daemon ? " and " : "");
47393 +               if (daemon)
47394 +                       kdb_printf("%d sleeping system daemon (state M) process%s",
47395 +                                  daemon, daemon == 1 ? "" : "es");
47396 +               kdb_printf(" suppressed\n");
47397 +       }
47398 +}
47399 +
47400 +/*
47401 + * kdb_ps
47402 + *
47403 + *     This function implements the 'ps' command which shows
47404 + *     a list of the active processes.
47405 + *
47406 + *     ps [DRSTCZEUIMA]                All processes, optionally filtered by state
47407 + *
47408 + * Inputs:
47409 + *     argc    argument count
47410 + *     argv    argument vector
47411 + * Outputs:
47412 + *     None.
47413 + * Returns:
47414 + *     zero for success, a kdb diagnostic if error
47415 + * Locking:
47416 + *     none.
47417 + * Remarks:
47418 + */
47419 +
47420 +void
47421 +kdb_ps1(const struct task_struct *p)
47422 +{
47423 +       struct kdb_running_process *krp = kdb_running_process + kdb_process_cpu(p);
47424 +       kdb_printf("0x%p %8d %8d  %d %4d   %c  0x%p %c%s\n",
47425 +                  (void *)p, p->pid, p->parent->pid,
47426 +                  kdb_task_has_cpu(p), kdb_process_cpu(p),
47427 +                  kdb_task_state_char(p),
47428 +                  (void *)(&p->thread),
47429 +                  p == kdb_curr_task(smp_processor_id()) ? '*': ' ',
47430 +                  p->comm);
47431 +       if (kdb_task_has_cpu(p)) {
47432 +               if (!krp->seqno || !krp->p)
47433 +                       kdb_printf("  Error: no saved data for this cpu\n");
47434 +               else {
47435 +                       if (krp->seqno < kdb_seqno - 1)
47436 +                               kdb_printf("  Warning: process state is stale\n");
47437 +                       if (krp->p != p)
47438 +                               kdb_printf("  Error: does not match running process table (0x%p)\n", krp->p);
47439 +               }
47440 +       }
47441 +}
47442 +
47443 +static int
47444 +kdb_ps(int argc, const char **argv)
47445 +{
47446 +       struct task_struct *g, *p;
47447 +       unsigned long mask, cpu;
47448 +
47449 +       if (argc == 0)
47450 +               kdb_ps_suppressed();
47451 +       kdb_printf("%-*s      Pid   Parent [*] cpu State %-*s Command\n",
47452 +               (int)(2*sizeof(void *))+2, "Task Addr",
47453 +               (int)(2*sizeof(void *))+2, "Thread");
47454 +       mask = kdb_task_state_string(argc ? argv[1] : NULL);
47455 +       /* Run the active tasks first */
47456 +       for (cpu = 0; cpu < NR_CPUS; ++cpu) {
47457 +               if (!cpu_online(cpu))
47458 +                       continue;
47459 +               p = kdb_curr_task(cpu);
47460 +               if (kdb_task_state(p, mask))
47461 +                       kdb_ps1(p);
47462 +       }
47463 +       kdb_printf("\n");
47464 +       /* Now the real tasks */
47465 +       kdb_do_each_thread(g, p) {
47466 +               if (kdb_task_state(p, mask))
47467 +                       kdb_ps1(p);
47468 +       } kdb_while_each_thread(g, p);
47469 +
47470 +       return 0;
47471 +}
47472 +
47473 +/*
47474 + * kdb_pid
47475 + *
47476 + *     This function implements the 'pid' command which switches
47477 + *     the currently active process.
47478 + *
47479 + *     pid [<pid> | R]
47480 + *
47481 + * Inputs:
47482 + *     argc    argument count
47483 + *     argv    argument vector
47484 + * Outputs:
47485 + *     None.
47486 + * Returns:
47487 + *     zero for success, a kdb diagnostic if error
47488 + * Locking:
47489 + *     none.
47490 + * Remarks:
47491 + */
47492 +
47493 +
47494 +static int
47495 +kdb_pid(int argc, const char **argv)
47496 +{
47497 +       struct task_struct *p;
47498 +       unsigned long val;
47499 +       int diag;
47500 +
47501 +       if (argc > 1)
47502 +               return KDB_ARGCOUNT;
47503 +
47504 +       if (argc) {
47505 +               if (strcmp(argv[1], "R") == 0) {
47506 +                       p = KDB_RUNNING_PROCESS_ORIGINAL[kdb_initial_cpu].p;
47507 +               } else {
47508 +                       diag = kdbgetularg(argv[1], &val);
47509 +                       if (diag)
47510 +                               return KDB_BADINT;
47511 +
47512 +                       p = find_task_by_pid((pid_t)val);
47513 +                       if (!p) {
47514 +                               kdb_printf("No task with pid=%d\n", (pid_t)val);
47515 +                               return 0;
47516 +                       }
47517 +               }
47518 +
47519 +               kdba_set_current_task(p);
47520 +       }
47521 +
47522 +       kdb_printf("KDB current process is %s(pid=%d)\n", kdb_current_task->comm,
47523 +                  kdb_current_task->pid);
47524 +
47525 +       return 0;
47526 +}
47527 +
47528 +/*
47529 + * kdb_ll
47530 + *
47531 + *     This function implements the 'll' command which follows a linked
47532 + *     list and executes an arbitrary command for each element.
47533 + *
47534 + * Inputs:
47535 + *     argc    argument count
47536 + *     argv    argument vector
47537 + * Outputs:
47538 + *     None.
47539 + * Returns:
47540 + *     zero for success, a kdb diagnostic if error
47541 + * Locking:
47542 + *     none.
47543 + * Remarks:
47544 + */
47545 +
47546 +static int
47547 +kdb_ll(int argc, const char **argv)
47548 +{
47549 +       int diag;
47550 +       kdb_machreg_t addr;
47551 +       long offset = 0;
47552 +       kdb_machreg_t va;
47553 +       unsigned long linkoffset;
47554 +       int nextarg;
47555 +       const char *command;
47556 +
47557 +       if (argc != 3) {
47558 +               return KDB_ARGCOUNT;
47559 +       }
47560 +
47561 +       nextarg = 1;
47562 +       diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL);
47563 +       if (diag)
47564 +               return diag;
47565 +
47566 +       diag = kdbgetularg(argv[2], &linkoffset);
47567 +       if (diag)
47568 +               return diag;
47569 +
47570 +       /*
47571 +        * Using the starting address as
47572 +        * the first element in the list, and assuming that
47573 +        * the list ends with a null pointer.
47574 +        */
47575 +
47576 +       va = addr;
47577 +       if (!(command = kdb_strdup(argv[3], GFP_KDB))) {
47578 +               kdb_printf("%s: cannot duplicate command\n", __FUNCTION__);
47579 +               return 0;
47580 +       }
47581 +       /* Recursive use of kdb_parse, do not use argv after this point */
47582 +       argv = NULL;
47583 +
47584 +       while (va) {
47585 +               char buf[80];
47586 +
47587 +               sprintf(buf, "%s " kdb_machreg_fmt "\n", command, va);
47588 +               diag = kdb_parse(buf);
47589 +               if (diag)
47590 +                       return diag;
47591 +
47592 +               addr = va + linkoffset;
47593 +               if (kdb_getword(&va, addr, sizeof(va)))
47594 +                       return 0;
47595 +       }
47596 +       kfree(command);
47597 +
47598 +       return 0;
47599 +}
47600 +
47601 +/*
47602 + * kdb_help
47603 + *
47604 + *     This function implements the 'help' and '?' commands.
47605 + *
47606 + * Inputs:
47607 + *     argc    argument count
47608 + *     argv    argument vector
47609 + * Outputs:
47610 + *     None.
47611 + * Returns:
47612 + *     zero for success, a kdb diagnostic if error
47613 + * Locking:
47614 + *     none.
47615 + * Remarks:
47616 + */
47617 +
47618 +static int
47619 +kdb_help(int argc, const char **argv)
47620 +{
47621 +       kdbtab_t *kt;
47622 +       int i;
47623 +
47624 +       kdb_printf("%-15.15s %-20.20s %s\n", "Command", "Usage", "Description");
47625 +       kdb_printf("----------------------------------------------------------\n");
47626 +       for(i=0, kt=kdb_commands; i<kdb_max_commands; i++, kt++) {
47627 +               if (kt->cmd_name)
47628 +                       kdb_printf("%-15.15s %-20.20s %s\n", kt->cmd_name,
47629 +                                  kt->cmd_usage, kt->cmd_help);
47630 +       }
47631 +       return 0;
47632 +}
47633 +
47634 +extern int kdb_wake_up_process(struct task_struct * p);
47635 +
47636 +/*
47637 + * kdb_kill
47638 + *
47639 + *     This function implements the 'kill' commands.
47640 + *
47641 + * Inputs:
47642 + *     argc    argument count
47643 + *     argv    argument vector
47644 + * Outputs:
47645 + *     None.
47646 + * Returns:
47647 + *     zero for success, a kdb diagnostic if error
47648 + * Locking:
47649 + *     none.
47650 + * Remarks:
47651 + */
47652 +
47653 +static int
47654 +kdb_kill(int argc, const char **argv)
47655 +{
47656 +       long sig, pid;
47657 +       char *endp;
47658 +       struct task_struct *p;
47659 +       struct siginfo info;
47660 +
47661 +       if (argc!=2)
47662 +               return KDB_ARGCOUNT;
47663 +
47664 +       sig = simple_strtol(argv[1], &endp, 0);
47665 +       if (*endp)
47666 +               return KDB_BADINT;
47667 +       if (sig >= 0 ) {
47668 +               kdb_printf("Invalid signal parameter.<-signal>\n");
47669 +               return 0;
47670 +       }
47671 +       sig=-sig;
47672 +
47673 +       pid = simple_strtol(argv[2], &endp, 0);
47674 +       if (*endp)
47675 +               return KDB_BADINT;
47676 +       if (pid <=0 ) {
47677 +               kdb_printf("Process ID must be large than 0.\n");
47678 +               return 0;
47679 +       }
47680 +
47681 +       /* Find the process. */
47682 +       if (!(p = find_task_by_pid(pid))) {
47683 +               kdb_printf("The specified process isn't found.\n");
47684 +               return 0;
47685 +       }
47686 +       p = p->group_leader;
47687 +       info.si_signo = sig;
47688 +       info.si_errno = 0;
47689 +       info.si_code = SI_USER;
47690 +       info.si_pid = pid;      /* use same capabilities as process being signalled */
47691 +       info.si_uid = 0;        /* kdb has root authority */
47692 +       kdb_send_sig_info(p, &info, kdb_seqno);
47693 +       return 0;
47694 +}
47695 +
47696 +struct kdb_tm {
47697 +       int tm_sec;     /* seconds */
47698 +       int tm_min;     /* minutes */
47699 +       int tm_hour;    /* hours */
47700 +       int tm_mday;    /* day of the month */
47701 +       int tm_mon;     /* month */
47702 +       int tm_year;    /* year */
47703 +};
47704 +
47705 +static void
47706 +kdb_gmtime(struct timespec *tv, struct kdb_tm *tm)
47707 +{
47708 +       /* This will work from 1970-2099, 2100 is not a leap year */
47709 +       static int mon_day[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
47710 +       memset(tm, 0, sizeof(*tm));
47711 +       tm->tm_sec  = tv->tv_sec % (24 * 60 * 60);
47712 +       tm->tm_mday = tv->tv_sec / (24 * 60 * 60) + (2 * 365 + 1); /* shift base from 1970 to 1968 */
47713 +       tm->tm_min =  tm->tm_sec / 60 % 60;
47714 +       tm->tm_hour = tm->tm_sec / 60 / 60;
47715 +       tm->tm_sec =  tm->tm_sec % 60;
47716 +       tm->tm_year = 68 + 4*(tm->tm_mday / (4*365+1));
47717 +       tm->tm_mday %= (4*365+1);
47718 +       mon_day[1] = 29;
47719 +       while (tm->tm_mday >= mon_day[tm->tm_mon]) {
47720 +               tm->tm_mday -= mon_day[tm->tm_mon];
47721 +               if (++tm->tm_mon == 12) {
47722 +                       tm->tm_mon = 0;
47723 +                       ++tm->tm_year;
47724 +                       mon_day[1] = 28;
47725 +               }
47726 +       }
47727 +       ++tm->tm_mday;
47728 +}
47729 +
47730 +/*
47731 + * Most of this code has been lifted from kernel/timer.c::sys_sysinfo().
47732 + * I cannot call that code directly from kdb, it has an unconditional
47733 + * cli()/sti() and calls routines that take locks which can stop the debugger.
47734 + */
47735 +
47736 +static void
47737 +kdb_sysinfo(struct sysinfo *val)
47738 +{
47739 +       struct timespec uptime;
47740 +       do_posix_clock_monotonic_gettime(&uptime);
47741 +       memset(val, 0, sizeof(*val));
47742 +       val->uptime = uptime.tv_sec;
47743 +       val->loads[0] = avenrun[0];
47744 +       val->loads[1] = avenrun[1];
47745 +       val->loads[2] = avenrun[2];
47746 +       val->procs = nr_threads-1;
47747 +       si_meminfo(val);
47748 +       kdb_si_swapinfo(val);
47749 +
47750 +       return;
47751 +}
47752 +
47753 +/*
47754 + * kdb_summary
47755 + *
47756 + *     This function implements the 'summary' command.
47757 + *
47758 + * Inputs:
47759 + *     argc    argument count
47760 + *     argv    argument vector
47761 + * Outputs:
47762 + *     None.
47763 + * Returns:
47764 + *     zero for success, a kdb diagnostic if error
47765 + * Locking:
47766 + *     none.
47767 + * Remarks:
47768 + */
47769 +
47770 +static int
47771 +kdb_summary(int argc, const char **argv)
47772 +{
47773 +       extern struct timespec xtime;
47774 +       extern struct timezone sys_tz;
47775 +       struct kdb_tm tm;
47776 +       struct sysinfo val;
47777 +
47778 +       if (argc)
47779 +               return KDB_ARGCOUNT;
47780 +
47781 +       kdb_printf("sysname    %s\n", init_uts_ns.name.sysname);
47782 +       kdb_printf("release    %s\n", init_uts_ns.name.release);
47783 +       kdb_printf("version    %s\n", init_uts_ns.name.version);
47784 +       kdb_printf("machine    %s\n", init_uts_ns.name.machine);
47785 +       kdb_printf("nodename   %s\n", init_uts_ns.name.nodename);
47786 +       kdb_printf("domainname %s\n", init_uts_ns.name.domainname);
47787 +
47788 +       kdb_gmtime(&xtime, &tm);
47789 +       kdb_printf("date       %04d-%02d-%02d %02d:%02d:%02d tz_minuteswest %d\n",
47790 +               1900+tm.tm_year, tm.tm_mon+1, tm.tm_mday,
47791 +               tm.tm_hour, tm.tm_min, tm.tm_sec,
47792 +               sys_tz.tz_minuteswest);
47793 +
47794 +       kdb_sysinfo(&val);
47795 +       kdb_printf("uptime     ");
47796 +       if (val.uptime > (24*60*60)) {
47797 +               int days = val.uptime / (24*60*60);
47798 +               val.uptime %= (24*60*60);
47799 +               kdb_printf("%d day%s ", days, days == 1 ? "" : "s");
47800 +       }
47801 +       kdb_printf("%02ld:%02ld\n", val.uptime/(60*60), (val.uptime/60)%60);
47802 +
47803 +       /* lifted from fs/proc/proc_misc.c::loadavg_read_proc() */
47804 +
47805 +#define LOAD_INT(x) ((x) >> FSHIFT)
47806 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
47807 +       kdb_printf("load avg   %ld.%02ld %ld.%02ld %ld.%02ld\n",
47808 +               LOAD_INT(val.loads[0]), LOAD_FRAC(val.loads[0]),
47809 +               LOAD_INT(val.loads[1]), LOAD_FRAC(val.loads[1]),
47810 +               LOAD_INT(val.loads[2]), LOAD_FRAC(val.loads[2]));
47811 +       kdb_printf("\n");
47812 +#undef LOAD_INT
47813 +#undef LOAD_FRAC
47814 +
47815 +       kdb_meminfo_read_proc();        /* in fs/proc/proc_misc.c */
47816 +
47817 +       return 0;
47818 +}
47819 +
47820 +/*
47821 + * kdb_per_cpu
47822 + *
47823 + *     This function implements the 'per_cpu' command.
47824 + *
47825 + * Inputs:
47826 + *     argc    argument count
47827 + *     argv    argument vector
47828 + * Outputs:
47829 + *     None.
47830 + * Returns:
47831 + *     zero for success, a kdb diagnostic if error
47832 + * Locking:
47833 + *     none.
47834 + * Remarks:
47835 + */
47836 +
47837 +static int
47838 +kdb_per_cpu(int argc, const char **argv)
47839 +{
47840 +       char buf[256], fmtstr[64];
47841 +       kdb_symtab_t symtab;
47842 +       cpumask_t suppress = CPU_MASK_NONE;
47843 +       int cpu, diag;
47844 +       unsigned long addr, val, bytesperword = 0, whichcpu = ~0UL;
47845 +
47846 +       if (argc < 1 || argc > 3)
47847 +               return KDB_ARGCOUNT;
47848 +
47849 +       snprintf(buf, sizeof(buf), "per_cpu__%s", argv[1]);
47850 +       if (!kdbgetsymval(buf, &symtab)) {
47851 +               kdb_printf("%s is not a per_cpu variable\n", argv[1]);
47852 +               return KDB_BADADDR;
47853 +       }
47854 +       if (argc >=2 && (diag = kdbgetularg(argv[2], &bytesperword)))
47855 +               return diag;
47856 +       if (!bytesperword)
47857 +               bytesperword = KDB_WORD_SIZE;
47858 +       else if (bytesperword > KDB_WORD_SIZE)
47859 +               return KDB_BADWIDTH;
47860 +       sprintf(fmtstr, "%%0%dlx ", (int)(2*bytesperword));
47861 +       if (argc >= 3) {
47862 +               if ((diag = kdbgetularg(argv[3], &whichcpu)))
47863 +                       return diag;
47864 +               if (!cpu_online(whichcpu)) {
47865 +                       kdb_printf("cpu %ld is not online\n", whichcpu);
47866 +                       return KDB_BADCPUNUM;
47867 +               }
47868 +       }
47869 +
47870 +       /* Most architectures use __per_cpu_offset[cpu], some use
47871 +        * __per_cpu_offset(cpu), smp has no __per_cpu_offset.
47872 +        */
47873 +#ifdef __per_cpu_offset
47874 +#define KDB_PCU(cpu) __per_cpu_offset(cpu)
47875 +#else
47876 +#ifdef CONFIG_SMP
47877 +#define KDB_PCU(cpu) __per_cpu_offset[cpu]
47878 +#else
47879 +#define KDB_PCU(cpu) 0
47880 +#endif
47881 +#endif
47882 +
47883 +       for_each_online_cpu(cpu) {
47884 +               if (whichcpu != ~0UL && whichcpu != cpu)
47885 +                       continue;
47886 +               addr = symtab.sym_start + KDB_PCU(cpu);
47887 +               if ((diag = kdb_getword(&val, addr, bytesperword))) {
47888 +                       kdb_printf("%5d " kdb_bfd_vma_fmt0 " - unable to read, diag=%d\n",
47889 +                               cpu, addr, diag);
47890 +                       continue;
47891 +               }
47892 +#ifdef CONFIG_SMP
47893 +               if (!val) {
47894 +                       cpu_set(cpu, suppress);
47895 +                       continue;
47896 +               }
47897 +#endif /* CONFIG_SMP */
47898 +               kdb_printf("%5d ", cpu);
47899 +               kdb_md_line(fmtstr, addr,
47900 +                       bytesperword == KDB_WORD_SIZE,
47901 +                       1, bytesperword, 1, 1, 0);
47902 +       }
47903 +       if (cpus_weight(suppress) == 0)
47904 +               return 0;
47905 +       kdb_printf("Zero suppressed cpu(s):");
47906 +       for (cpu = first_cpu(suppress); cpu < NR_CPUS; cpu = next_cpu(cpu, suppress)) {
47907 +               kdb_printf(" %d", cpu);
47908 +               if (cpu == NR_CPUS-1 || next_cpu(cpu, suppress) != cpu + 1)
47909 +                       continue;
47910 +               while (cpu < NR_CPUS && next_cpu(cpu, suppress) == cpu + 1)
47911 +                       ++cpu;
47912 +               kdb_printf("-%d", cpu);
47913 +       }
47914 +       kdb_printf("\n");
47915 +
47916 +#undef KDB_PCU
47917 +
47918 +       return 0;
47919 +}
47920 +
47921 +
47922 +/*
47923 + * kdb_register_repeat
47924 + *
47925 + *     This function is used to register a kernel debugger command.
47926 + *
47927 + * Inputs:
47928 + *     cmd     Command name
47929 + *     func    Function to execute the command
47930 + *     usage   A simple usage string showing arguments
47931 + *     help    A simple help string describing command
47932 + *     repeat  Does the command auto repeat on enter?
47933 + * Outputs:
47934 + *     None.
47935 + * Returns:
47936 + *     zero for success, one if a duplicate command.
47937 + * Locking:
47938 + *     none.
47939 + * Remarks:
47940 + *
47941 + */
47942 +
47943 +#define kdb_command_extend 50  /* arbitrary */
47944 +int
47945 +kdb_register_repeat(char *cmd,
47946 +                   kdb_func_t func,
47947 +                   char *usage,
47948 +                   char *help,
47949 +                   short minlen,
47950 +                   kdb_repeat_t repeat)
47951 +{
47952 +       int i;
47953 +       kdbtab_t *kp;
47954 +
47955 +       /*
47956 +        *  Brute force method to determine duplicates
47957 +        */
47958 +       for (i=0, kp=kdb_commands; i<kdb_max_commands; i++, kp++) {
47959 +               if (kp->cmd_name && (strcmp(kp->cmd_name, cmd)==0)) {
47960 +                       kdb_printf("Duplicate kdb command registered: '%s'\n",
47961 +                                  cmd);
47962 +                       return 1;
47963 +               }
47964 +       }
47965 +
47966 +       /*
47967 +        * Insert command into first available location in table
47968 +        */
47969 +       for (i=0, kp=kdb_commands; i<kdb_max_commands; i++, kp++) {
47970 +               if (kp->cmd_name == NULL) {
47971 +                       break;
47972 +               }
47973 +       }
47974 +
47975 +       if (i >= kdb_max_commands) {
47976 +               kdbtab_t *new = kmalloc((kdb_max_commands + kdb_command_extend) * sizeof(*new), GFP_KDB);
47977 +               if (!new) {
47978 +                       kdb_printf("Could not allocate new kdb_command table\n");
47979 +                       return 1;
47980 +               }
47981 +               if (kdb_commands) {
47982 +                       memcpy(new, kdb_commands, kdb_max_commands * sizeof(*new));
47983 +                       kfree(kdb_commands);
47984 +               }
47985 +               memset(new + kdb_max_commands, 0, kdb_command_extend * sizeof(*new));
47986 +               kdb_commands = new;
47987 +               kp = kdb_commands + kdb_max_commands;
47988 +               kdb_max_commands += kdb_command_extend;
47989 +       }
47990 +
47991 +       kp->cmd_name   = cmd;
47992 +       kp->cmd_func   = func;
47993 +       kp->cmd_usage  = usage;
47994 +       kp->cmd_help   = help;
47995 +       kp->cmd_flags  = 0;
47996 +       kp->cmd_minlen = minlen;
47997 +       kp->cmd_repeat = repeat;
47998 +
47999 +       return 0;
48000 +}
48001 +
48002 +/*
48003 + * kdb_register
48004 + *
48005 + *     Compatibility register function for commands that do not need to
48006 + *     specify a repeat state.  Equivalent to kdb_register_repeat with
48007 + *     KDB_REPEAT_NONE.
48008 + *
48009 + * Inputs:
48010 + *     cmd     Command name
48011 + *     func    Function to execute the command
48012 + *     usage   A simple usage string showing arguments
48013 + *     help    A simple help string describing command
48014 + * Outputs:
48015 + *     None.
48016 + * Returns:
48017 + *     zero for success, one if a duplicate command.
48018 + * Locking:
48019 + *     none.
48020 + * Remarks:
48021 + *
48022 + */
48023 +
48024 +int
48025 +kdb_register(char *cmd,
48026 +            kdb_func_t func,
48027 +            char *usage,
48028 +            char *help,
48029 +            short minlen)
48030 +{
48031 +       return kdb_register_repeat(cmd, func, usage, help, minlen, KDB_REPEAT_NONE);
48032 +}
48033 +
48034 +/*
48035 + * kdb_unregister
48036 + *
48037 + *     This function is used to unregister a kernel debugger command.
48038 + *     It is generally called when a module which implements kdb
48039 + *     commands is unloaded.
48040 + *
48041 + * Inputs:
48042 + *     cmd     Command name
48043 + * Outputs:
48044 + *     None.
48045 + * Returns:
48046 + *     zero for success, one command not registered.
48047 + * Locking:
48048 + *     none.
48049 + * Remarks:
48050 + *
48051 + */
48052 +
48053 +int
48054 +kdb_unregister(char *cmd)
48055 +{
48056 +       int i;
48057 +       kdbtab_t *kp;
48058 +
48059 +       /*
48060 +        *  find the command.
48061 +        */
48062 +       for (i=0, kp=kdb_commands; i<kdb_max_commands; i++, kp++) {
48063 +               if (kp->cmd_name && (strcmp(kp->cmd_name, cmd)==0)) {
48064 +                       kp->cmd_name = NULL;
48065 +                       return 0;
48066 +               }
48067 +       }
48068 +
48069 +       /*
48070 +        * Couldn't find it.
48071 +        */
48072 +       return 1;
48073 +}
48074 +
48075 +/*
48076 + * kdb_inittab
48077 + *
48078 + *     This function is called by the kdb_init function to initialize
48079 + *     the kdb command table.   It must be called prior to any other
48080 + *     call to kdb_register_repeat.
48081 + *
48082 + * Inputs:
48083 + *     None.
48084 + * Outputs:
48085 + *     None.
48086 + * Returns:
48087 + *     None.
48088 + * Locking:
48089 + *     None.
48090 + * Remarks:
48091 + *
48092 + */
48093 +
48094 +static void __init
48095 +kdb_inittab(void)
48096 +{
48097 +       int i;
48098 +       kdbtab_t *kp;
48099 +
48100 +       for(i=0, kp=kdb_commands; i < kdb_max_commands; i++,kp++) {
48101 +               kp->cmd_name = NULL;
48102 +       }
48103 +
48104 +       kdb_register_repeat("md", kdb_md, "<vaddr>",   "Display Memory Contents, also mdWcN, e.g. md8c1", 1, KDB_REPEAT_NO_ARGS);
48105 +       kdb_register_repeat("mdr", kdb_md, "<vaddr> <bytes>",   "Display Raw Memory", 0, KDB_REPEAT_NO_ARGS);
48106 +       kdb_register_repeat("mdp", kdb_md, "<paddr> <bytes>",   "Display Physical Memory", 0, KDB_REPEAT_NO_ARGS);
48107 +       kdb_register_repeat("mds", kdb_md, "<vaddr>",   "Display Memory Symbolically", 0, KDB_REPEAT_NO_ARGS);
48108 +       kdb_register_repeat("mm", kdb_mm, "<vaddr> <contents>",   "Modify Memory Contents", 0, KDB_REPEAT_NO_ARGS);
48109 +       kdb_register_repeat("id", kdb_id, "<vaddr>",   "Display Instructions", 1, KDB_REPEAT_NO_ARGS);
48110 +       kdb_register_repeat("go", kdb_go, "[<vaddr>]", "Continue Execution", 1, KDB_REPEAT_NONE);
48111 +       kdb_register_repeat("rd", kdb_rd, "",           "Display Registers", 1, KDB_REPEAT_NONE);
48112 +       kdb_register_repeat("rm", kdb_rm, "<reg> <contents>", "Modify Registers", 0, KDB_REPEAT_NONE);
48113 +       kdb_register_repeat("ef", kdb_ef, "<vaddr>",   "Display exception frame", 0, KDB_REPEAT_NONE);
48114 +       kdb_register_repeat("bt", kdb_bt, "[<vaddr>]", "Stack traceback", 1, KDB_REPEAT_NONE);
48115 +       kdb_register_repeat("btp", kdb_bt, "<pid>",     "Display stack for process <pid>", 0, KDB_REPEAT_NONE);
48116 +       kdb_register_repeat("bta", kdb_bt, "[DRSTCZEUIMA]",     "Display stack all processes", 0, KDB_REPEAT_NONE);
48117 +       kdb_register_repeat("btc", kdb_bt, "",  "Backtrace current process on each cpu", 0, KDB_REPEAT_NONE);
48118 +       kdb_register_repeat("btt", kdb_bt, "<vaddr>",   "Backtrace process given its struct task address", 0, KDB_REPEAT_NONE);
48119 +       kdb_register_repeat("ll", kdb_ll, "<first-element> <linkoffset> <cmd>", "Execute cmd for each element in linked list", 0, KDB_REPEAT_NONE);
48120 +       kdb_register_repeat("env", kdb_env, "",         "Show environment variables", 0, KDB_REPEAT_NONE);
48121 +       kdb_register_repeat("set", kdb_set, "",         "Set environment variables", 0, KDB_REPEAT_NONE);
48122 +       kdb_register_repeat("help", kdb_help, "",       "Display Help Message", 1, KDB_REPEAT_NONE);
48123 +       kdb_register_repeat("?", kdb_help, "",         "Display Help Message", 0, KDB_REPEAT_NONE);
48124 +       kdb_register_repeat("cpu", kdb_cpu, "<cpunum>","Switch to new cpu", 0, KDB_REPEAT_NONE);
48125 +       kdb_register_repeat("ps", kdb_ps, "",           "Display active task list", 0, KDB_REPEAT_NONE);
48126 +       kdb_register_repeat("pid", kdb_pid, "<pidnum>", "Switch to another task", 0, KDB_REPEAT_NONE);
48127 +       kdb_register_repeat("reboot", kdb_reboot, "",  "Reboot the machine immediately", 0, KDB_REPEAT_NONE);
48128 +#if defined(CONFIG_MODULES)
48129 +       kdb_register_repeat("lsmod", kdb_lsmod, "",     "List loaded kernel modules", 0, KDB_REPEAT_NONE);
48130 +#endif
48131 +#if defined(CONFIG_MAGIC_SYSRQ)
48132 +       kdb_register_repeat("sr", kdb_sr, "<key>",      "Magic SysRq key", 0, KDB_REPEAT_NONE);
48133 +#endif
48134 +       kdb_register_repeat("dmesg", kdb_dmesg, "[lines]",      "Display syslog buffer", 0, KDB_REPEAT_NONE);
48135 +       kdb_register_repeat("defcmd", kdb_defcmd, "name \"usage\" \"help\"", "Define a set of commands, down to endefcmd", 0, KDB_REPEAT_NONE);
48136 +       kdb_register_repeat("kill", kdb_kill, "<-signal> <pid>", "Send a signal to a process", 0, KDB_REPEAT_NONE);
48137 +       kdb_register_repeat("summary", kdb_summary, "", "Summarize the system", 4, KDB_REPEAT_NONE);
48138 +       kdb_register_repeat("per_cpu", kdb_per_cpu, "", "Display per_cpu variables", 3, KDB_REPEAT_NONE);
48139 +}
48140 +
48141 +/*
48142 + * kdb_cmd_init
48143 + *
48144 + *     This function is called by the kdb_init function to execute any
48145 + *     commands defined in kdb_cmds.
48146 + *
48147 + * Inputs:
48148 + *     Commands in *kdb_cmds[];
48149 + * Outputs:
48150 + *     None.
48151 + * Returns:
48152 + *     None.
48153 + * Locking:
48154 + *     None.
48155 + * Remarks:
48156 + *
48157 + */
48158 +
48159 +static void __init
48160 +kdb_cmd_init(void)
48161 +{
48162 +       int i, diag;
48163 +       for (i = 0; kdb_cmds[i]; ++i) {
48164 +               if (!defcmd_in_progress)
48165 +                       kdb_printf("kdb_cmd[%d]: %s", i, kdb_cmds[i]);
48166 +               diag = kdb_parse(kdb_cmds[i]);
48167 +               if (diag)
48168 +                       kdb_printf("command failed, kdb diag %d\n", diag);
48169 +       }
48170 +       if (defcmd_in_progress) {
48171 +               kdb_printf("Incomplete 'defcmd' set, forcing endefcmd\n");
48172 +               kdb_parse("endefcmd");
48173 +       }
48174 +}
48175 +
48176 +/*
48177 + * kdb_panic
48178 + *
48179 + *     Invoked via the panic_notifier_list.
48180 + *
48181 + * Inputs:
48182 + *     None.
48183 + * Outputs:
48184 + *     None.
48185 + * Returns:
48186 + *     Zero.
48187 + * Locking:
48188 + *     None.
48189 + * Remarks:
48190 + *     When this function is called from panic(), the other cpus have already
48191 + *     been stopped.
48192 + *
48193 + */
48194 +
48195 +static int
48196 +kdb_panic(struct notifier_block *self, unsigned long command, void *ptr)
48197 +{
48198 +       KDB_FLAG_SET(CATASTROPHIC);     /* kernel state is dubious now */
48199 +       KDB_ENTER();
48200 +       return 0;
48201 +}
48202 +
48203 +static struct notifier_block kdb_block = { kdb_panic, NULL, 0 };
48204 +
48205 +#ifdef CONFIG_SYSCTL
48206 +static int proc_do_kdb(ctl_table *table, int write, struct file *filp,
48207 +                      void __user *buffer, size_t *lenp, loff_t *ppos)
48208 +{
48209 +       if (KDB_FLAG(NO_CONSOLE) && write) {
48210 +               printk(KERN_ERR "kdb has no working console and has switched itself off\n");
48211 +               return -EINVAL;
48212 +       }
48213 +       return proc_dointvec(table, write, filp, buffer, lenp, ppos);
48214 +}
48215 +
48216 +static ctl_table kdb_kern_table[] = {
48217 +       {
48218 +               .ctl_name       = KERN_KDB,
48219 +               .procname       = "kdb",
48220 +               .data           = &kdb_on,
48221 +               .maxlen         = sizeof(int),
48222 +               .mode           = 0644,
48223 +               .proc_handler   = &proc_do_kdb,
48224 +       },
48225 +       {}
48226 +};
48227 +
48228 +static ctl_table kdb_root_table[] = {
48229 +       {
48230 +               .ctl_name       = CTL_KERN,
48231 +               .procname       = "kernel",
48232 +               .mode           = 0555,
48233 +               .child          = kdb_kern_table,
48234 +       },
48235 +       {}
48236 +};
48237 +#endif /* CONFIG_SYSCTL */
48238 +
48239 +static int
48240 +kdb_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
48241 +{
48242 +       if (action == CPU_ONLINE) {
48243 +               int cpu =(unsigned long)hcpu;
48244 +               cpumask_t save_cpus_allowed = current->cpus_allowed;
48245 +               cpumask_t new_cpus_allowed = cpumask_of_cpu(cpu);
48246 +               set_cpus_allowed(current, new_cpus_allowed);
48247 +               kdb(KDB_REASON_CPU_UP, 0, NULL);        /* do kdb setup on this cpu */
48248 +               set_cpus_allowed(current, save_cpus_allowed);
48249 +       }
48250 +       return NOTIFY_OK;
48251 +}
48252 +
48253 +static struct notifier_block kdb_cpu_nfb = {
48254 +       .notifier_call = kdb_cpu_callback
48255 +};
48256 +
48257 +/*
48258 + * kdb_init
48259 + *
48260 + *     Initialize the kernel debugger environment.
48261 + *
48262 + * Parameters:
48263 + *     None.
48264 + * Returns:
48265 + *     None.
48266 + * Locking:
48267 + *     None.
48268 + * Remarks:
48269 + *     None.
48270 + */
48271 +
48272 +void __init
48273 +kdb_init(void)
48274 +{
48275 +       kdb_initial_cpu = smp_processor_id();
48276 +       /*
48277 +        * This must be called before any calls to kdb_printf.
48278 +        */
48279 +       kdb_io_init();
48280 +
48281 +       kdb_inittab();          /* Initialize Command Table */
48282 +       kdb_initbptab();        /* Initialize Breakpoint Table */
48283 +       kdb_id_init();          /* Initialize Disassembler */
48284 +       kdba_init();            /* Architecture Dependent Initialization */
48285 +
48286 +       /*
48287 +        * Use printk() to get message in log_buf[];
48288 +        */
48289 +       printk("kdb version %d.%d%s by Keith Owens, Scott Lurndal. "\
48290 +              "Copyright SGI, All Rights Reserved\n",
48291 +               KDB_MAJOR_VERSION, KDB_MINOR_VERSION, KDB_TEST_VERSION);
48292 +
48293 +       kdb_cmd_init();         /* Preset commands from kdb_cmds */
48294 +       kdb_initial_cpu = -1;   /* Avoid recursion problems */
48295 +       kdb(KDB_REASON_CPU_UP, 0, NULL);        /* do kdb setup on boot cpu */
48296 +       kdb_initial_cpu = smp_processor_id();
48297 +       atomic_notifier_chain_register(&panic_notifier_list, &kdb_block);
48298 +       register_cpu_notifier(&kdb_cpu_nfb);
48299 +
48300 +#ifdef kdba_setjmp
48301 +       kdbjmpbuf = vmalloc(NR_CPUS * sizeof(*kdbjmpbuf));
48302 +       if (!kdbjmpbuf)
48303 +               printk(KERN_ERR "Cannot allocate kdbjmpbuf, no kdb recovery will be possible\n");
48304 +#endif /* kdba_setjmp */
48305 +
48306 +       kdb_initial_cpu = -1;
48307 +       kdb_wait_for_cpus_secs = max(10, 2*num_online_cpus());
48308 +}
48309 +
48310 +#ifdef CONFIG_SYSCTL
48311 +static int __init
48312 +kdb_late_init(void)
48313 +{
48314 +       register_sysctl_table(kdb_root_table);
48315 +       return 0;
48316 +}
48317 +
48318 +__initcall(kdb_late_init);
48319 +#endif
48320 +
48321 +EXPORT_SYMBOL(kdb_register);
48322 +EXPORT_SYMBOL(kdb_register_repeat);
48323 +EXPORT_SYMBOL(kdb_unregister);
48324 +EXPORT_SYMBOL(kdb_getarea_size);
48325 +EXPORT_SYMBOL(kdb_putarea_size);
48326 +EXPORT_SYMBOL(kdb_getuserarea_size);
48327 +EXPORT_SYMBOL(kdb_putuserarea_size);
48328 +EXPORT_SYMBOL(kdbgetularg);
48329 +EXPORT_SYMBOL(kdbgetenv);
48330 +EXPORT_SYMBOL(kdbgetintenv);
48331 +EXPORT_SYMBOL(kdbgetaddrarg);
48332 +EXPORT_SYMBOL(kdb);
48333 +EXPORT_SYMBOL(kdb_on);
48334 +EXPORT_SYMBOL(kdb_seqno);
48335 +EXPORT_SYMBOL(kdb_initial_cpu);
48336 +EXPORT_SYMBOL(kdbnearsym);
48337 +EXPORT_SYMBOL(kdb_printf);
48338 +EXPORT_SYMBOL(kdb_symbol_print);
48339 +EXPORT_SYMBOL(kdb_running_process);
48340 diff -Nurp linux-2.6.22-590/kdb/kdbsupport.c linux-2.6.22-600/kdb/kdbsupport.c
48341 --- linux-2.6.22-590/kdb/kdbsupport.c   1970-01-01 01:00:00.000000000 +0100
48342 +++ linux-2.6.22-600/kdb/kdbsupport.c   2008-04-09 18:14:28.000000000 +0200
48343 @@ -0,0 +1,1162 @@
48344 +/*
48345 + * Kernel Debugger Architecture Independent Support Functions
48346 + *
48347 + * This file is subject to the terms and conditions of the GNU General Public
48348 + * License.  See the file "COPYING" in the main directory of this archive
48349 + * for more details.
48350 + *
48351 + * Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
48352 + * 03/02/13    added new 2.5 kallsyms <xavier.bru@bull.net>
48353 + */
48354 +
48355 +#include <stdarg.h>
48356 +#include <linux/types.h>
48357 +#include <linux/sched.h>
48358 +#include <linux/mm.h>
48359 +#include <linux/kallsyms.h>
48360 +#include <linux/stddef.h>
48361 +#include <linux/vmalloc.h>
48362 +#include <linux/ptrace.h>
48363 +#include <linux/module.h>
48364 +#include <linux/highmem.h>
48365 +#include <linux/hardirq.h>
48366 +#include <linux/delay.h>
48367 +
48368 +#include <asm/uaccess.h>
48369 +
48370 +#include <linux/kdb.h>
48371 +#include <linux/kdbprivate.h>
48372 +
48373 +/*
48374 + * Symbol table functions.
48375 + */
48376 +
48377 +/*
48378 + * kdbgetsymval
48379 + *
48380 + *     Return the address of the given symbol.
48381 + *
48382 + * Parameters:
48383 + *     symname Character string containing symbol name
48384 + *      symtab  Structure to receive results
48385 + * Outputs:
48386 + * Returns:
48387 + *     0       Symbol not found, symtab zero filled
48388 + *     1       Symbol mapped to module/symbol/section, data in symtab
48389 + * Locking:
48390 + *     None.
48391 + * Remarks:
48392 + */
48393 +
48394 +int
48395 +kdbgetsymval(const char *symname, kdb_symtab_t *symtab)
48396 +{
48397 +       if (KDB_DEBUG(AR))
48398 +               kdb_printf("kdbgetsymval: symname=%s, symtab=%p\n", symname, symtab);
48399 +       memset(symtab, 0, sizeof(*symtab));
48400 +
48401 +       if ((symtab->sym_start = kallsyms_lookup_name(symname))) {
48402 +               if (KDB_DEBUG(AR))
48403 +                       kdb_printf("kdbgetsymval: returns 1, symtab->sym_start=0x%lx\n", symtab->sym_start);
48404 +               return 1;
48405 +       }
48406 +       if (KDB_DEBUG(AR))
48407 +               kdb_printf("kdbgetsymval: returns 0\n");
48408 +       return 0;
48409 +}
48410 +
48411 +/*
48412 + * kdbnearsym
48413 + *
48414 + *     Return the name of the symbol with the nearest address
48415 + *     less than 'addr'.
48416 + *
48417 + * Parameters:
48418 + *     addr    Address to check for symbol near
48419 + *     symtab  Structure to receive results
48420 + * Outputs:
48421 + * Returns:
48422 + *     0       No sections contain this address, symtab zero filled
48423 + *     1       Address mapped to module/symbol/section, data in symtab
48424 + * Locking:
48425 + *     None.
48426 + * Remarks:
48427 + *     2.6 kallsyms has a "feature" where it unpacks the name into a string.
48428 + *     If that string is reused before the caller expects it then the caller
48429 + *     sees its string change without warning.  To avoid cluttering up the
48430 + *     main kdb code with lots of kdb_strdup, tests and kfree calls, kdbnearsym
48431 + *     maintains an LRU list of the last few unique strings.  The list is sized
48432 + *     large enough to hold active strings, no kdb caller of kdbnearsym makes
48433 + *     more than ~20 later calls before using a saved value.
48434 + */
48435 +
48436 +static char *kdb_name_table[100];      /* arbitrary size */
48437 +
48438 +int
48439 +kdbnearsym(unsigned long addr, kdb_symtab_t *symtab)
48440 +{
48441 +       int ret = 0;
48442 +       unsigned long symbolsize;
48443 +       unsigned long offset;
48444 +#define knt1_size 128          /* must be >= kallsyms table size */
48445 +       char *knt1 = NULL;
48446 +
48447 +       if (KDB_DEBUG(AR))
48448 +               kdb_printf("kdbnearsym: addr=0x%lx, symtab=%p\n", addr, symtab);
48449 +       memset(symtab, 0, sizeof(*symtab));
48450 +
48451 +       if (addr < 4096)
48452 +               goto out;
48453 +       knt1 = debug_kmalloc(knt1_size, GFP_ATOMIC);
48454 +       if (!knt1) {
48455 +               kdb_printf("kdbnearsym: addr=0x%lx cannot kmalloc knt1\n", addr);
48456 +               goto out;
48457 +       }
48458 +       symtab->sym_name = kallsyms_lookup(addr, &symbolsize , &offset, (char **)(&symtab->mod_name), knt1);
48459 +       if (offset > 8*1024*1024) {
48460 +               symtab->sym_name = NULL;
48461 +               addr = offset = symbolsize = 0;
48462 +       }
48463 +       symtab->sym_start = addr - offset;
48464 +       symtab->sym_end = symtab->sym_start + symbolsize;
48465 +       ret = symtab->sym_name != NULL && *(symtab->sym_name) != '\0';
48466 +
48467 +       if (ret) {
48468 +               int i;
48469 +               /* Another 2.6 kallsyms "feature".  Sometimes the sym_name is
48470 +                * set but the buffer passed into kallsyms_lookup is not used,
48471 +                * so it contains garbage.  The caller has to work out which
48472 +                * buffer needs to be saved.
48473 +                *
48474 +                * What was Rusty smoking when he wrote that code?
48475 +                */
48476 +               if (symtab->sym_name != knt1) {
48477 +                       strncpy(knt1, symtab->sym_name, knt1_size);
48478 +                       knt1[knt1_size-1] = '\0';
48479 +               }
48480 +               for (i = 0; i < ARRAY_SIZE(kdb_name_table); ++i) {
48481 +                       if (kdb_name_table[i] && strcmp(kdb_name_table[i], knt1) == 0)
48482 +                               break;
48483 +               }
48484 +               if (i >= ARRAY_SIZE(kdb_name_table)) {
48485 +                       debug_kfree(kdb_name_table[0]);
48486 +                       memcpy(kdb_name_table, kdb_name_table+1,
48487 +                              sizeof(kdb_name_table[0])*(ARRAY_SIZE(kdb_name_table)-1));
48488 +               } else {
48489 +                       debug_kfree(knt1);
48490 +                       knt1 = kdb_name_table[i];
48491 +                       memcpy(kdb_name_table+i, kdb_name_table+i+1,
48492 +                              sizeof(kdb_name_table[0])*(ARRAY_SIZE(kdb_name_table)-i-1));
48493 +               }
48494 +               i = ARRAY_SIZE(kdb_name_table) - 1;
48495 +               kdb_name_table[i] = knt1;
48496 +               symtab->sym_name = kdb_name_table[i];
48497 +               knt1 = NULL;
48498 +       }
48499 +
48500 +       if (symtab->mod_name == NULL)
48501 +               symtab->mod_name = "kernel";
48502 +       if (KDB_DEBUG(AR))
48503 +               kdb_printf("kdbnearsym: returns %d symtab->sym_start=0x%lx, symtab->mod_name=%p, symtab->sym_name=%p (%s)\n", ret, symtab->sym_start, symtab->mod_name, symtab->sym_name, symtab->sym_name);
48504 +
48505 +out:
48506 +       debug_kfree(knt1);
48507 +       return ret;
48508 +}
48509 +
48510 +void
48511 +kdbnearsym_cleanup(void)
48512 +{
48513 +       int i;
48514 +       for (i = 0; i < ARRAY_SIZE(kdb_name_table); ++i) {
48515 +               if (kdb_name_table[i]) {
48516 +                       debug_kfree(kdb_name_table[i]);
48517 +                       kdb_name_table[i] = NULL;
48518 +               }
48519 +       }
48520 +}
48521 +
48522 +/*
48523 + * kallsyms_symbol_complete
48524 + *
48525 + * Parameters:
48526 + *     prefix_name     prefix of a symbol name to lookup
48527 + *     max_len         maximum length that can be returned
48528 + * Returns:
48529 + *     Number of symbols which match the given prefix.
48530 + * Notes:
48531 + *     prefix_name is changed to contain the longest unique prefix that
48532 + *     starts with this prefix (tab completion).
48533 + */
48534 +
48535 +static char ks_namebuf[KSYM_NAME_LEN+1], ks_namebuf_prev[KSYM_NAME_LEN+1];
48536 +
48537 +int kallsyms_symbol_complete(char *prefix_name, int max_len)
48538 +{
48539 +       loff_t pos = 0;
48540 +       int prefix_len = strlen(prefix_name), prev_len = 0;
48541 +       int i, number = 0;
48542 +       const char *name;
48543 +
48544 +       while ((name = kdb_walk_kallsyms(&pos))) {
48545 +               if (strncmp(name, prefix_name, prefix_len) == 0) {
48546 +                       strcpy(ks_namebuf, name);
48547 +                       /* Work out the longest name that matches the prefix */
48548 +                       if (++number == 1) {
48549 +                               prev_len = min_t(int, max_len-1, strlen(ks_namebuf));
48550 +                               memcpy(ks_namebuf_prev, ks_namebuf, prev_len);
48551 +                               ks_namebuf_prev[prev_len] = '\0';
48552 +                       } else for (i = 0; i < prev_len; ++i) {
48553 +                               if (ks_namebuf[i] != ks_namebuf_prev[i]) {
48554 +                                       prev_len = i;
48555 +                                       ks_namebuf_prev[i] = '\0';
48556 +                                       break;
48557 +                               }
48558 +                       }
48559 +               }
48560 +       }
48561 +       if (prev_len > prefix_len)
48562 +               memcpy(prefix_name, ks_namebuf_prev, prev_len+1);
48563 +       return number;
48564 +}
48565 +
48566 +/*
48567 + * kallsyms_symbol_next
48568 + *
48569 + * Parameters:
48570 + *     prefix_name     prefix of a symbol name to lookup
48571 + *     flag    0 means search from the head, 1 means continue search.
48572 + * Returns:
48573 + *     1 if a symbol matches the given prefix.
48574 + *     0 if no string found
48575 + */
48576 +
48577 +int kallsyms_symbol_next(char *prefix_name, int flag)
48578 +{
48579 +       int prefix_len = strlen(prefix_name);
48580 +       static loff_t pos;
48581 +       const char *name;
48582 +
48583 +       if (!flag)
48584 +               pos = 0;
48585 +
48586 +       while ((name = kdb_walk_kallsyms(&pos))) {
48587 +               if (strncmp(name, prefix_name, prefix_len) == 0) {
48588 +                       strncpy(prefix_name, name, strlen(name)+1);
48589 +                       return 1;
48590 +               }
48591 +       }
48592 +       return 0;
48593 +}
48594 +
48595 +#if defined(CONFIG_SMP)
48596 +/*
48597 + * kdb_ipi
48598 + *
48599 + *     This function is called from the non-maskable interrupt
48600 + *     handler to handle a kdb IPI instruction.
48601 + *
48602 + * Inputs:
48603 + *     regs    = Exception frame pointer
48604 + * Outputs:
48605 + *     None.
48606 + * Returns:
48607 + *     0       - Did not handle NMI
48608 + *     1       - Handled NMI
48609 + * Locking:
48610 + *     None.
48611 + * Remarks:
48612 + *     Initially one processor is invoked in the kdb() code.  That
48613 + *     processor sends an ipi which drives this routine on the other
48614 + *     processors.  All this does is call kdb() with reason SWITCH.
48615 + *     This puts all processors into the kdb() routine and all the
48616 + *     code for breakpoints etc. is in one place.
48617 + *     One problem with the way the kdb NMI is sent, the NMI has no
48618 + *     identification that says it came from kdb.  If the cpu's kdb state is
48619 + *     marked as "waiting for kdb_ipi" then the NMI is treated as coming from
48620 + *     kdb, otherwise it is assumed to be for another reason and is ignored.
48621 + */
48622 +
48623 +int
48624 +kdb_ipi(struct pt_regs *regs, void (*ack_interrupt)(void))
48625 +{
48626 +       /* Do not print before checking and clearing WAIT_IPI, IPIs are
48627 +        * going all the time.
48628 +        */
48629 +       if (KDB_STATE(WAIT_IPI)) {
48630 +               /*
48631 +                * Stopping other processors via smp_kdb_stop().
48632 +                */
48633 +               if (ack_interrupt)
48634 +                       (*ack_interrupt)();     /* Acknowledge the interrupt */
48635 +               KDB_STATE_CLEAR(WAIT_IPI);
48636 +               KDB_DEBUG_STATE("kdb_ipi 1", 0);
48637 +               kdb(KDB_REASON_SWITCH, 0, regs);        /* Spin in kdb() */
48638 +               KDB_DEBUG_STATE("kdb_ipi 2", 0);
48639 +               return 1;
48640 +       }
48641 +       return 0;
48642 +}
48643 +#endif /* CONFIG_SMP */
48644 +
48645 +/*
48646 + * kdb_symbol_print
48647 + *
48648 + *     Standard method for printing a symbol name and offset.
48649 + * Inputs:
48650 + *     addr    Address to be printed.
48651 + *     symtab  Address of symbol data, if NULL this routine does its
48652 + *             own lookup.
48653 + *     punc    Punctuation for string, bit field.
48654 + * Outputs:
48655 + *     None.
48656 + * Returns:
48657 + *     Always 0.
48658 + * Locking:
48659 + *     none.
48660 + * Remarks:
48661 + *     The string and its punctuation is only printed if the address
48662 + *     is inside the kernel, except that the value is always printed
48663 + *     when requested.
48664 + */
48665 +
48666 +void
48667 +kdb_symbol_print(kdb_machreg_t addr, const kdb_symtab_t *symtab_p, unsigned int punc)
48668 +{
48669 +       kdb_symtab_t symtab, *symtab_p2;
48670 +       if (symtab_p) {
48671 +               symtab_p2 = (kdb_symtab_t *)symtab_p;
48672 +       }
48673 +       else {
48674 +               symtab_p2 = &symtab;
48675 +               kdbnearsym(addr, symtab_p2);
48676 +       }
48677 +       if (symtab_p2->sym_name || (punc & KDB_SP_VALUE)) {
48678 +               ;       /* drop through */
48679 +       }
48680 +       else {
48681 +               return;
48682 +       }
48683 +       if (punc & KDB_SP_SPACEB) {
48684 +               kdb_printf(" ");
48685 +       }
48686 +       if (punc & KDB_SP_VALUE) {
48687 +               kdb_printf(kdb_machreg_fmt0, addr);
48688 +       }
48689 +       if (symtab_p2->sym_name) {
48690 +               if (punc & KDB_SP_VALUE) {
48691 +                       kdb_printf(" ");
48692 +               }
48693 +               if (punc & KDB_SP_PAREN) {
48694 +                       kdb_printf("(");
48695 +               }
48696 +               if (strcmp(symtab_p2->mod_name, "kernel")) {
48697 +                       kdb_printf("[%s]", symtab_p2->mod_name);
48698 +               }
48699 +               kdb_printf("%s", symtab_p2->sym_name);
48700 +               if (addr != symtab_p2->sym_start) {
48701 +                       kdb_printf("+0x%lx", addr - symtab_p2->sym_start);
48702 +               }
48703 +               if (punc & KDB_SP_SYMSIZE) {
48704 +                       kdb_printf("/0x%lx", symtab_p2->sym_end - symtab_p2->sym_start);
48705 +               }
48706 +               if (punc & KDB_SP_PAREN) {
48707 +                       kdb_printf(")");
48708 +               }
48709 +       }
48710 +       if (punc & KDB_SP_SPACEA) {
48711 +               kdb_printf(" ");
48712 +       }
48713 +       if (punc & KDB_SP_NEWLINE) {
48714 +               kdb_printf("\n");
48715 +       }
48716 +}
48717 +
48718 +/*
48719 + * kdb_strdup
48720 + *
48721 + *     kdb equivalent of strdup, for disasm code.
48722 + * Inputs:
48723 + *     str     The string to duplicate.
48724 + *     type    Flags to kmalloc for the new string.
48725 + * Outputs:
48726 + *     None.
48727 + * Returns:
48728 + *     Address of the new string, NULL if storage could not be allocated.
48729 + * Locking:
48730 + *     none.
48731 + * Remarks:
48732 + *     This is not in lib/string.c because it uses kmalloc which is not
48733 + *     available when string.o is used in boot loaders.
48734 + */
48735 +
48736 +char *kdb_strdup(const char *str, gfp_t type)
48737 +{
48738 +       int n = strlen(str)+1;
48739 +       char *s = kmalloc(n, type);
48740 +       if (!s) return NULL;
48741 +       return strcpy(s, str);
48742 +}
48743 +
48744 +/*
48745 + * kdb_getarea_size
48746 + *
48747 + *     Read an area of data.  The kdb equivalent of copy_from_user, with
48748 + *     kdb messages for invalid addresses.
48749 + * Inputs:
48750 + *     res     Pointer to the area to receive the result.
48751 + *     addr    Address of the area to copy.
48752 + *     size    Size of the area.
48753 + * Outputs:
48754 + *     none.
48755 + * Returns:
48756 + *     0 for success, < 0 for error.
48757 + * Locking:
48758 + *     none.
48759 + */
48760 +
48761 +int kdb_getarea_size(void *res, unsigned long addr, size_t size)
48762 +{
48763 +       int ret = kdba_getarea_size(res, addr, size);
48764 +       if (ret) {
48765 +               if (!KDB_STATE(SUPPRESS)) {
48766 +                       kdb_printf("kdb_getarea: Bad address 0x%lx\n", addr);
48767 +                       KDB_STATE_SET(SUPPRESS);
48768 +               }
48769 +               ret = KDB_BADADDR;
48770 +       }
48771 +       else {
48772 +               KDB_STATE_CLEAR(SUPPRESS);
48773 +       }
48774 +       return(ret);
48775 +}
48776 +
48777 +/*
48778 + * kdb_putarea_size
48779 + *
48780 + *     Write an area of data.  The kdb equivalent of copy_to_user, with
48781 + *     kdb messages for invalid addresses.
48782 + * Inputs:
48783 + *     addr    Address of the area to write to.
48784 + *     res     Pointer to the area holding the data.
48785 + *     size    Size of the area.
48786 + * Outputs:
48787 + *     none.
48788 + * Returns:
48789 + *     0 for success, < 0 for error.
48790 + * Locking:
48791 + *     none.
48792 + */
48793 +
48794 +int kdb_putarea_size(unsigned long addr, void *res, size_t size)
48795 +{
48796 +       int ret = kdba_putarea_size(addr, res, size);
48797 +       if (ret) {
48798 +               if (!KDB_STATE(SUPPRESS)) {
48799 +                       kdb_printf("kdb_putarea: Bad address 0x%lx\n", addr);
48800 +                       KDB_STATE_SET(SUPPRESS);
48801 +               }
48802 +               ret = KDB_BADADDR;
48803 +       }
48804 +       else {
48805 +               KDB_STATE_CLEAR(SUPPRESS);
48806 +       }
48807 +       return(ret);
48808 +}
48809 +
48810 +/*
48811 + * kdb_getphys
48812 + *
48813 + * Read data from a physical address. Validate the address is in range,
48814 + * use kmap_atomic() to get data
48815 + *
48816 + * Similar to kdb_getarea() - but for phys addresses
48817 + *
48818 + * Inputs:
48819 + *     res     Pointer to the word to receive the result
48820 + *     addr    Physical address of the area to copy
48821 + *     size    Size of the area
48822 + * Outputs:
48823 + *     none.
48824 + * Returns:
48825 + *     0 for success, < 0 for error.
48826 + * Locking:
48827 + *     none.
48828 + */
48829 +static int kdb_getphys(void *res, unsigned long addr, size_t size)
48830 +{
48831 +       unsigned long pfn;
48832 +       void *vaddr;
48833 +       struct page *page;
48834 +
48835 +       pfn = (addr >> PAGE_SHIFT);
48836 +       if (!pfn_valid(pfn))
48837 +               return 1;
48838 +       page = pfn_to_page(pfn);
48839 +       vaddr = kmap_atomic(page, KM_KDB);
48840 +       memcpy(res, vaddr + (addr & (PAGE_SIZE -1)), size);
48841 +       kunmap_atomic(vaddr, KM_KDB);
48842 +
48843 +       return 0;
48844 +}
48845 +
48846 +/*
48847 + * kdb_getphysword
48848 + *
48849 + * Inputs:
48850 + *     word    Pointer to the word to receive the result.
48851 + *     addr    Address of the area to copy.
48852 + *     size    Size of the area.
48853 + * Outputs:
48854 + *     none.
48855 + * Returns:
48856 + *     0 for success, < 0 for error.
48857 + * Locking:
48858 + *     none.
48859 + */
48860 +int kdb_getphysword(unsigned long *word, unsigned long addr, size_t size)
48861 +{
48862 +       int diag;
48863 +       __u8  w1;
48864 +       __u16 w2;
48865 +       __u32 w4;
48866 +       __u64 w8;
48867 +       *word = 0;      /* Default value if addr or size is invalid */
48868 +
48869 +       switch (size) {
48870 +       case 1:
48871 +               if (!(diag = kdb_getphys(&w1, addr, sizeof(w1))))
48872 +                       *word = w1;
48873 +               break;
48874 +       case 2:
48875 +               if (!(diag = kdb_getphys(&w2, addr, sizeof(w2))))
48876 +                       *word = w2;
48877 +               break;
48878 +       case 4:
48879 +               if (!(diag = kdb_getphys(&w4, addr, sizeof(w4))))
48880 +                       *word = w4;
48881 +               break;
48882 +       case 8:
48883 +               if (size <= sizeof(*word)) {
48884 +                       if (!(diag = kdb_getphys(&w8, addr, sizeof(w8))))
48885 +                               *word = w8;
48886 +                       break;
48887 +               }
48888 +               /* drop through */
48889 +       default:
48890 +               diag = KDB_BADWIDTH;
48891 +               kdb_printf("kdb_getphysword: bad width %ld\n", (long) size);
48892 +       }
48893 +       return(diag);
48894 +}
48895 +
48896 +/*
48897 + * kdb_getword
48898 + *
48899 + *     Read a binary value.  Unlike kdb_getarea, this treats data as numbers.
48900 + * Inputs:
48901 + *     word    Pointer to the word to receive the result.
48902 + *     addr    Address of the area to copy.
48903 + *     size    Size of the area.
48904 + * Outputs:
48905 + *     none.
48906 + * Returns:
48907 + *     0 for success, < 0 for error.
48908 + * Locking:
48909 + *     none.
48910 + */
48911 +
48912 +int kdb_getword(unsigned long *word, unsigned long addr, size_t size)
48913 +{
48914 +       int diag;
48915 +       __u8  w1;
48916 +       __u16 w2;
48917 +       __u32 w4;
48918 +       __u64 w8;
48919 +       *word = 0;      /* Default value if addr or size is invalid */
48920 +       switch (size) {
48921 +       case 1:
48922 +               if (!(diag = kdb_getarea(w1, addr)))
48923 +                       *word = w1;
48924 +               break;
48925 +       case 2:
48926 +               if (!(diag = kdb_getarea(w2, addr)))
48927 +                       *word = w2;
48928 +               break;
48929 +       case 4:
48930 +               if (!(diag = kdb_getarea(w4, addr)))
48931 +                       *word = w4;
48932 +               break;
48933 +       case 8:
48934 +               if (size <= sizeof(*word)) {
48935 +                       if (!(diag = kdb_getarea(w8, addr)))
48936 +                               *word = w8;
48937 +                       break;
48938 +               }
48939 +               /* drop through */
48940 +       default:
48941 +               diag = KDB_BADWIDTH;
48942 +               kdb_printf("kdb_getword: bad width %ld\n", (long) size);
48943 +       }
48944 +       return(diag);
48945 +}
48946 +
48947 +/*
48948 + * kdb_putword
48949 + *
48950 + *     Write a binary value.  Unlike kdb_putarea, this treats data as numbers.
48951 + * Inputs:
48952 + *     addr    Address of the area to write to..
48953 + *     word    The value to set.
48954 + *     size    Size of the area.
48955 + * Outputs:
48956 + *     none.
48957 + * Returns:
48958 + *     0 for success, < 0 for error.
48959 + * Locking:
48960 + *     none.
48961 + */
48962 +
48963 +int kdb_putword(unsigned long addr, unsigned long word, size_t size)
48964 +{
48965 +       int diag;
48966 +       __u8  w1;
48967 +       __u16 w2;
48968 +       __u32 w4;
48969 +       __u64 w8;
48970 +       switch (size) {
48971 +       case 1:
48972 +               w1 = word;
48973 +               diag = kdb_putarea(addr, w1);
48974 +               break;
48975 +       case 2:
48976 +               w2 = word;
48977 +               diag = kdb_putarea(addr, w2);
48978 +               break;
48979 +       case 4:
48980 +               w4 = word;
48981 +               diag = kdb_putarea(addr, w4);
48982 +               break;
48983 +       case 8:
48984 +               if (size <= sizeof(word)) {
48985 +                       w8 = word;
48986 +                       diag = kdb_putarea(addr, w8);
48987 +                       break;
48988 +               }
48989 +               /* drop through */
48990 +       default:
48991 +               diag = KDB_BADWIDTH;
48992 +               kdb_printf("kdb_putword: bad width %ld\n", (long) size);
48993 +       }
48994 +       return(diag);
48995 +}
48996 +
48997 +/*
48998 + * kdb_task_state_string
48999 + *
49000 + *     Convert a string containing any of the letters DRSTCZEUIMA to a mask
49001 + *     for the process state field and return the value.  If no argument is
49002 + *     supplied, return the mask that corresponds to environment variable PS,
49003 + *     DRSTCZEU by default.
49004 + * Inputs:
49005 + *     s       String to convert
49006 + * Outputs:
49007 + *     none.
49008 + * Returns:
49009 + *     Mask for process state.
49010 + * Locking:
49011 + *     none.
49012 + * Notes:
49013 + *     The mask folds data from several sources into a single long value, so
49014 + *     be carefull not to overlap the bits.  TASK_* bits are in the LSB,
49015 + *     special cases like UNRUNNABLE are in the MSB.  As of 2.6.10-rc1 there
49016 + *     is no overlap between TASK_* and EXIT_* but that may not always be
49017 + *     true, so EXIT_* bits are shifted left 16 bits before being stored in
49018 + *     the mask.
49019 + */
49020 +
49021 +#define UNRUNNABLE     (1UL << (8*sizeof(unsigned long) - 1))  /* unrunnable is < 0 */
49022 +#define RUNNING                (1UL << (8*sizeof(unsigned long) - 2))
49023 +#define IDLE           (1UL << (8*sizeof(unsigned long) - 3))
49024 +#define DAEMON         (1UL << (8*sizeof(unsigned long) - 4))
49025 +
49026 +unsigned long
49027 +kdb_task_state_string(const char *s)
49028 +{
49029 +       long res = 0;
49030 +       if (!s && !(s = kdbgetenv("PS"))) {
49031 +               s = "DRSTCZEU"; /* default value for ps */
49032 +       }
49033 +       while (*s) {
49034 +               switch (*s) {
49035 +               case 'D': res |= TASK_UNINTERRUPTIBLE; break;
49036 +               case 'R': res |= RUNNING; break;
49037 +               case 'S': res |= TASK_INTERRUPTIBLE; break;
49038 +               case 'T': res |= TASK_STOPPED; break;
49039 +               case 'C': res |= TASK_TRACED; break;
49040 +               case 'Z': res |= EXIT_ZOMBIE << 16; break;
49041 +               case 'E': res |= EXIT_DEAD << 16; break;
49042 +               case 'U': res |= UNRUNNABLE; break;
49043 +               case 'I': res |= IDLE; break;
49044 +               case 'M': res |= DAEMON; break;
49045 +               case 'A': res = ~0UL; break;
49046 +               default:
49047 +                         kdb_printf("%s: unknown flag '%c' ignored\n", __FUNCTION__, *s);
49048 +                         break;
49049 +               }
49050 +               ++s;
49051 +       }
49052 +       return res;
49053 +}
49054 +
49055 +/*
49056 + * kdb_task_state_char
49057 + *
49058 + *     Return the character that represents the task state.
49059 + * Inputs:
49060 + *     p       struct task for the process
49061 + * Outputs:
49062 + *     none.
49063 + * Returns:
49064 + *     One character to represent the task state.
49065 + * Locking:
49066 + *     none.
49067 + */
49068 +
49069 +char
49070 +kdb_task_state_char (const struct task_struct *p)
49071 +{
49072 +       int cpu = kdb_process_cpu(p);
49073 +       struct kdb_running_process *krp = kdb_running_process + cpu;
49074 +       char state = (p->state == 0) ? 'R' :
49075 +                    (p->state < 0) ? 'U' :
49076 +                    (p->state & TASK_UNINTERRUPTIBLE) ? 'D' :
49077 +                    (p->state & TASK_STOPPED) ? 'T' :
49078 +                    (p->state & TASK_TRACED) ? 'C' :
49079 +                    (p->exit_state & EXIT_ZOMBIE) ? 'Z' :
49080 +                    (p->exit_state & EXIT_DEAD) ? 'E' :
49081 +                    (p->state & TASK_INTERRUPTIBLE) ? 'S' : '?';
49082 +       if (p->pid == 0) {
49083 +               /* Idle task.  Is it really idle, apart from the kdb interrupt? */
49084 +               if (!kdb_task_has_cpu(p) || krp->irq_depth == 1) {
49085 +                       /* There is a corner case when the idle task takes an
49086 +                        * interrupt and dies in the interrupt code.  It has an
49087 +                        * interrupt count of 1 but that did not come from kdb.
49088 +                        * This corner case can only occur on the initial cpu,
49089 +                        * all the others were entered via the kdb IPI.
49090 +                        */
49091 +                       if (cpu != kdb_initial_cpu || KDB_STATE_CPU(KEYBOARD, cpu))
49092 +                               state = 'I';    /* idle task */
49093 +               }
49094 +       }
49095 +       else if (!p->mm && state == 'S') {
49096 +               state = 'M';    /* sleeping system daemon */
49097 +       }
49098 +       return state;
49099 +}
49100 +
49101 +/*
49102 + * kdb_task_state
49103 + *
49104 + *     Return true if a process has the desired state given by the mask.
49105 + * Inputs:
49106 + *     p       struct task for the process
49107 + *     mask    mask from kdb_task_state_string to select processes
49108 + * Outputs:
49109 + *     none.
49110 + * Returns:
49111 + *     True if the process matches at least one criteria defined by the mask.
49112 + * Locking:
49113 + *     none.
49114 + */
49115 +
49116 +unsigned long
49117 +kdb_task_state(const struct task_struct *p, unsigned long mask)
49118 +{
49119 +       char state[] = { kdb_task_state_char(p), '\0' };
49120 +       return (mask & kdb_task_state_string(state)) != 0;
49121 +}
49122 +
49123 +struct kdb_running_process kdb_running_process[NR_CPUS];
49124 +
49125 +/*
49126 + * kdb_save_running
49127 + *
49128 + *     Save the state of a running process.  This is invoked on the current
49129 + *     process on each cpu (assuming the cpu is responding).
49130 + * Inputs:
49131 + *     regs    struct pt_regs for the process
49132 + * Outputs:
49133 + *     Updates kdb_running_process[] for this cpu.
49134 + * Returns:
49135 + *     none.
49136 + * Locking:
49137 + *     none.
49138 + */
49139 +
49140 +void
49141 +kdb_save_running(struct pt_regs *regs)
49142 +{
49143 +       struct kdb_running_process *krp = kdb_running_process + smp_processor_id();
49144 +       krp->p = current;
49145 +       krp->regs = regs;
49146 +       krp->seqno = kdb_seqno;
49147 +       krp->irq_depth = hardirq_count() >> HARDIRQ_SHIFT;
49148 +       kdba_save_running(&(krp->arch), regs);
49149 +}
49150 +
49151 +/*
49152 + * kdb_unsave_running
49153 + *
49154 + *     Reverse the effect of kdb_save_running.
49155 + * Inputs:
49156 + *     regs    struct pt_regs for the process
49157 + * Outputs:
49158 + *     Updates kdb_running_process[] for this cpu.
49159 + * Returns:
49160 + *     none.
49161 + * Locking:
49162 + *     none.
49163 + */
49164 +
49165 +void
49166 +kdb_unsave_running(struct pt_regs *regs)
49167 +{
49168 +       struct kdb_running_process *krp = kdb_running_process + smp_processor_id();
49169 +       kdba_unsave_running(&(krp->arch), regs);
49170 +       krp->seqno = 0;
49171 +}
49172 +
49173 +
49174 +/*
49175 + * kdb_print_nameval
49176 + *
49177 + *     Print a name and its value, converting the value to a symbol lookup
49178 + *     if possible.
49179 + * Inputs:
49180 + *     name    field name to print
49181 + *     val     value of field
49182 + * Outputs:
49183 + *     none.
49184 + * Returns:
49185 + *     none.
49186 + * Locking:
49187 + *     none.
49188 + */
49189 +
49190 +void
49191 +kdb_print_nameval(const char *name, unsigned long val)
49192 +{
49193 +       kdb_symtab_t symtab;
49194 +       kdb_printf("  %-11.11s ", name);
49195 +       if (kdbnearsym(val, &symtab))
49196 +               kdb_symbol_print(val, &symtab, KDB_SP_VALUE|KDB_SP_SYMSIZE|KDB_SP_NEWLINE);
49197 +       else
49198 +               kdb_printf("0x%lx\n", val);
49199 +}
49200 +
49201 +static struct page * kdb_get_one_user_page(const struct task_struct *tsk, unsigned long start,
49202 +               int len, int write)
49203 +{
49204 +       struct mm_struct *mm = tsk->mm;
49205 +       unsigned int flags;
49206 +       struct vm_area_struct * vma;
49207 +
49208 +       /* shouldn't cross a page boundary. */
49209 +       if ((start & PAGE_MASK) != ((start+len) & PAGE_MASK))
49210 +               return NULL;
49211 +
49212 +       /* we need to align start address to the current page boundy, PAGE_ALIGN
49213 +        * aligns to next page boundry.
49214 +        * FIXME: What about hugetlb?
49215 +        */
49216 +       start = start & PAGE_MASK;
49217 +       flags = write ? (VM_WRITE | VM_MAYWRITE) : (VM_READ | VM_MAYREAD);
49218 +
49219 +       vma = find_extend_vma(mm, start);
49220 +
49221 +       /* may be we can allow access to VM_IO pages inside KDB? */
49222 +       if (!vma || (vma->vm_flags & VM_IO) || !(flags & vma->vm_flags))
49223 +               return NULL;
49224 +
49225 +       return follow_page(vma, start, write ? FOLL_WRITE : 0);
49226 +}
49227 +
49228 +int kdb_getuserarea_size(void *to, unsigned long from, size_t size)
49229 +{
49230 +       struct page *page;
49231 +       void *vaddr;
49232 +
49233 +       page = kdb_get_one_user_page(kdb_current_task, from, size, 0);
49234 +       if (!page)
49235 +               return size;
49236 +
49237 +       vaddr = kmap_atomic(page, KM_KDB);
49238 +       memcpy(to, vaddr+ (from & (PAGE_SIZE - 1)), size);
49239 +       kunmap_atomic(vaddr, KM_KDB);
49240 +
49241 +       return 0;
49242 +}
49243 +
49244 +int kdb_putuserarea_size(unsigned long to, void *from, size_t size)
49245 +{
49246 +       struct page *page;
49247 +       void *vaddr;
49248 +
49249 +       page = kdb_get_one_user_page(kdb_current_task, to, size, 1);
49250 +       if (!page)
49251 +               return size;
49252 +
49253 +       vaddr = kmap_atomic(page, KM_KDB);
49254 +       memcpy(vaddr+ (to & (PAGE_SIZE - 1)), from, size);
49255 +       kunmap_atomic(vaddr, KM_KDB);
49256 +
49257 +       return 0;
49258 +}
49259 +
49260 +/* Last ditch allocator for debugging, so we can still debug even when the
49261 + * GFP_ATOMIC pool has been exhausted.  The algorithms are tuned for space
49262 + * usage, not for speed.  One smallish memory pool, the free chain is always in
49263 + * ascending address order to allow coalescing, allocations are done in brute
49264 + * force best fit.
49265 + */
49266 +
49267 +struct debug_alloc_header {
49268 +       u32 next;       /* offset of next header from start of pool */
49269 +       u32 size;
49270 +       void *caller;
49271 +};
49272 +
49273 +/* The memory returned by this allocator must be aligned, which means so must
49274 + * the header size.  Do not assume that sizeof(struct debug_alloc_header) is a
49275 + * multiple of the alignment, explicitly calculate the overhead of this header,
49276 + * including the alignment.  The rest of this code must not use sizeof() on any
49277 + * header or pointer to a header.
49278 + */
49279 +#define dah_align 8
49280 +#define dah_overhead ALIGN(sizeof(struct debug_alloc_header), dah_align)
49281 +
49282 +static u64 debug_alloc_pool_aligned[128*1024/dah_align];       /* 128K pool */
49283 +static char *debug_alloc_pool = (char *)debug_alloc_pool_aligned;
49284 +static u32 dah_first, dah_first_call = 1, dah_used = 0, dah_used_max = 0;
49285 +
49286 +/* Locking is awkward.  The debug code is called from all contexts, including
49287 + * non maskable interrupts.  A normal spinlock is not safe in NMI context.  Try
49288 + * to get the debug allocator lock, if it cannot be obtained after a second
49289 + * then give up.  If the lock could not be previously obtained on this cpu then
49290 + * only try once.
49291 + *
49292 + * sparse has no annotation for "this function _sometimes_ acquires a lock", so
49293 + * fudge the acquire/release notation.
49294 + */
49295 +static DEFINE_SPINLOCK(dap_lock);
49296 +static int
49297 +get_dap_lock(void)
49298 +       __acquires(dap_lock)
49299 +{
49300 +       static int dap_locked = -1;
49301 +       int count;
49302 +       if (dap_locked == smp_processor_id())
49303 +               count = 1;
49304 +       else
49305 +               count = 1000;
49306 +       while (1) {
49307 +               if (spin_trylock(&dap_lock)) {
49308 +                       dap_locked = -1;
49309 +                       return 1;
49310 +               }
49311 +               if (!count--)
49312 +                       break;
49313 +               udelay(1000);
49314 +       }
49315 +       dap_locked = smp_processor_id();
49316 +       __acquire(dap_lock);
49317 +       return 0;
49318 +}
49319 +
49320 +void
49321 +*debug_kmalloc(size_t size, gfp_t flags)
49322 +{
49323 +       unsigned int rem, h_offset;
49324 +       struct debug_alloc_header *best, *bestprev, *prev, *h;
49325 +       void *p = NULL;
49326 +       if (!get_dap_lock()) {
49327 +               __release(dap_lock);    /* we never actually got it */
49328 +               return NULL;
49329 +       }
49330 +       h = (struct debug_alloc_header *)(debug_alloc_pool + dah_first);
49331 +       if (dah_first_call) {
49332 +               h->size = sizeof(debug_alloc_pool_aligned) - dah_overhead;
49333 +               dah_first_call = 0;
49334 +       }
49335 +       size = ALIGN(size, dah_align);
49336 +       prev = best = bestprev = NULL;
49337 +       while (1) {
49338 +               if (h->size >= size && (!best || h->size < best->size)) {
49339 +                       best = h;
49340 +                       bestprev = prev;
49341 +                       if (h->size == size)
49342 +                               break;
49343 +               }
49344 +               if (!h->next)
49345 +                       break;
49346 +               prev = h;
49347 +               h = (struct debug_alloc_header *)(debug_alloc_pool + h->next);
49348 +       }
49349 +       if (!best)
49350 +               goto out;
49351 +       rem = best->size - size;
49352 +       /* The pool must always contain at least one header */
49353 +       if (best->next == 0 && bestprev == NULL && rem < dah_overhead)
49354 +               goto out;
49355 +       if (rem >= dah_overhead) {
49356 +               best->size = size;
49357 +               h_offset = ((char *)best - debug_alloc_pool) +
49358 +                          dah_overhead + best->size;
49359 +               h = (struct debug_alloc_header *)(debug_alloc_pool + h_offset);
49360 +               h->size = rem - dah_overhead;
49361 +               h->next = best->next;
49362 +       } else
49363 +               h_offset = best->next;
49364 +       best->caller = __builtin_return_address(0);
49365 +       dah_used += best->size;
49366 +       dah_used_max = max(dah_used, dah_used_max);
49367 +       if (bestprev)
49368 +               bestprev->next = h_offset;
49369 +       else
49370 +               dah_first = h_offset;
49371 +       p = (char *)best + dah_overhead;
49372 +       memset(p, POISON_INUSE, best->size - 1);
49373 +       *((char *)p + best->size - 1) = POISON_END;
49374 +out:
49375 +       spin_unlock(&dap_lock);
49376 +       return p;
49377 +}
49378 +
49379 +void
49380 +debug_kfree(void *p)
49381 +{
49382 +       struct debug_alloc_header *h;
49383 +       unsigned int h_offset;
49384 +       if (!p)
49385 +               return;
49386 +       if ((char *)p < debug_alloc_pool ||
49387 +           (char *)p >= debug_alloc_pool + sizeof(debug_alloc_pool_aligned)) {
49388 +               kfree(p);
49389 +               return;
49390 +       }
49391 +       if (!get_dap_lock()) {
49392 +               __release(dap_lock);    /* we never actually got it */
49393 +               return;         /* memory leak, cannot be helped */
49394 +       }
49395 +       h = (struct debug_alloc_header *)((char *)p - dah_overhead);
49396 +       memset(p, POISON_FREE, h->size - 1);
49397 +       *((char *)p + h->size - 1) = POISON_END;
49398 +       h->caller = NULL;
49399 +       dah_used -= h->size;
49400 +       h_offset = (char *)h - debug_alloc_pool;
49401 +       if (h_offset < dah_first) {
49402 +               h->next = dah_first;
49403 +               dah_first = h_offset;
49404 +       } else {
49405 +               struct debug_alloc_header *prev;
49406 +               unsigned int prev_offset;
49407 +               prev = (struct debug_alloc_header *)(debug_alloc_pool + dah_first);
49408 +               while (1) {
49409 +                       if (!prev->next || prev->next > h_offset)
49410 +                               break;
49411 +                       prev = (struct debug_alloc_header *)
49412 +                               (debug_alloc_pool + prev->next);
49413 +               }
49414 +               prev_offset = (char *)prev - debug_alloc_pool;
49415 +               if (prev_offset + dah_overhead + prev->size == h_offset) {
49416 +                       prev->size += dah_overhead + h->size;
49417 +                       memset(h, POISON_FREE, dah_overhead - 1);
49418 +                       *((char *)h + dah_overhead - 1) = POISON_END;
49419 +                       h = prev;
49420 +                       h_offset = prev_offset;
49421 +               } else {
49422 +                       h->next = prev->next;
49423 +                       prev->next = h_offset;
49424 +               }
49425 +       }
49426 +       if (h_offset + dah_overhead + h->size == h->next) {
49427 +               struct debug_alloc_header *next;
49428 +               next = (struct debug_alloc_header *)
49429 +                       (debug_alloc_pool + h->next);
49430 +               h->size += dah_overhead + next->size;
49431 +               h->next = next->next;
49432 +               memset(next, POISON_FREE, dah_overhead - 1);
49433 +               *((char *)next + dah_overhead - 1) = POISON_END;
49434 +       }
49435 +       spin_unlock(&dap_lock);
49436 +}
49437 +
49438 +void
49439 +debug_kusage(void)
49440 +{
49441 +       struct debug_alloc_header *h_free, *h_used;
49442 +#ifdef CONFIG_IA64
49443 +       /* FIXME: using dah for ia64 unwind always results in a memory leak.
49444 +        * Fix that memory leak first, then set debug_kusage_one_time = 1 for
49445 +        * all architectures.
49446 +        */
49447 +       static int debug_kusage_one_time = 0;
49448 +#else
49449 +       static int debug_kusage_one_time = 1;
49450 +#endif
49451 +       if (!get_dap_lock()) {
49452 +               __release(dap_lock);    /* we never actually got it */
49453 +               return;
49454 +       }
49455 +       h_free = (struct debug_alloc_header *)(debug_alloc_pool + dah_first);
49456 +       if (dah_first == 0 &&
49457 +           (h_free->size == sizeof(debug_alloc_pool_aligned) - dah_overhead ||
49458 +            dah_first_call))
49459 +               goto out;
49460 +       if (!debug_kusage_one_time)
49461 +               goto out;
49462 +       debug_kusage_one_time = 0;
49463 +       kdb_printf("%s: debug_kmalloc memory leak dah_first %d\n",
49464 +                  __FUNCTION__, dah_first);
49465 +       if (dah_first) {
49466 +               h_used = (struct debug_alloc_header *)debug_alloc_pool;
49467 +               kdb_printf("%s: h_used %p size %d\n", __FUNCTION__, h_used, h_used->size);
49468 +       }
49469 +       do {
49470 +               h_used = (struct debug_alloc_header *)
49471 +                         ((char *)h_free + dah_overhead + h_free->size);
49472 +               kdb_printf("%s: h_used %p size %d caller %p\n",
49473 +                          __FUNCTION__, h_used, h_used->size, h_used->caller);
49474 +               h_free = (struct debug_alloc_header *)
49475 +                         (debug_alloc_pool + h_free->next);
49476 +       } while (h_free->next);
49477 +       h_used = (struct debug_alloc_header *)
49478 +                 ((char *)h_free + dah_overhead + h_free->size);
49479 +       if ((char *)h_used - debug_alloc_pool !=
49480 +           sizeof(debug_alloc_pool_aligned))
49481 +               kdb_printf("%s: h_used %p size %d caller %p\n",
49482 +                          __FUNCTION__, h_used, h_used->size, h_used->caller);
49483 +out:
49484 +       spin_unlock(&dap_lock);
49485 +}
49486 +
49487 +/* Maintain a small stack of kdb_flags to allow recursion without disturbing
49488 + * the global kdb state.
49489 + */
49490 +
49491 +static int kdb_flags_stack[4], kdb_flags_index;
49492 +
49493 +void
49494 +kdb_save_flags(void)
49495 +{
49496 +       BUG_ON(kdb_flags_index >= ARRAY_SIZE(kdb_flags_stack));
49497 +       kdb_flags_stack[kdb_flags_index++] = kdb_flags;
49498 +}
49499 +
49500 +void
49501 +kdb_restore_flags(void)
49502 +{
49503 +       BUG_ON(kdb_flags_index <= 0);
49504 +       kdb_flags = kdb_flags_stack[--kdb_flags_index];
49505 +}
49506 diff -Nurp linux-2.6.22-590/kdb/Makefile linux-2.6.22-600/kdb/Makefile
49507 --- linux-2.6.22-590/kdb/Makefile       1970-01-01 01:00:00.000000000 +0100
49508 +++ linux-2.6.22-600/kdb/Makefile       2008-04-09 18:14:28.000000000 +0200
49509 @@ -0,0 +1,45 @@
49510 +#
49511 +# This file is subject to the terms and conditions of the GNU General Public
49512 +# License.  See the file "COPYING" in the main directory of this archive
49513 +# for more details.
49514 +#
49515 +# Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
49516 +#
49517 +
49518 +obj-y          := kdb_bt.o kdb_bp.o kdb_id.o kdbsupport.o gen-kdb_cmds.o kdbmain.o kdb_io.o
49519 +
49520 +# The i386 and x86_64 backtrace commands are handled by common code.
49521 +ifdef CONFIG_X86
49522 +  obj-y                += kdba_bt_x86.o
49523 +  ifneq (,$(findstring -fno-optimize-sibling-calls,$(CFLAGS)))
49524 +    CFLAGS_kdba_bt_x86.o += -DNO_SIBLINGS
49525 +  endif
49526 +  REGPARM := $(subst -mregparm=,,$(filter -mregparm=%,$(CFLAGS)))
49527 +  ifeq (,$(REGPARM))
49528 +    ifdef CONFIG_X86_64
49529 +      REGPARM := 6
49530 +    else
49531 +      REGPARM := 0
49532 +    endif
49533 +  endif
49534 +  CFLAGS_kdba_bt_x86.o += -DREGPARM=$(REGPARM)
49535 +endif
49536 +
49537 +subdir-$(CONFIG_KDB_MODULES) := modules
49538 +obj-y += $(addsuffix /built-in.o, $(subdir-y))
49539 +
49540 +clean-files := gen-kdb_cmds.c
49541 +
49542 +override CFLAGS := $(CFLAGS:%-pg=% )
49543 +
49544 +quiet_cmd_gen-kdb = GENKDB  $@
49545 +      cmd_gen-kdb = $(AWK) 'BEGIN {print "\#include <linux/stddef.h>"; print "\#include <linux/init.h>"} \
49546 +               /^\#/{next} \
49547 +               /^[ \t]*$$/{next} \
49548 +               {gsub(/"/, "\\\"", $$0); \
49549 +                 print "static __initdata char kdb_cmd" cmds++ "[] = \"" $$0 "\\n\";"} \
49550 +               END {print "extern char *kdb_cmds[]; char __initdata *kdb_cmds[] = {"; for (i = 0; i < cmds; ++i) {print "  kdb_cmd" i ","}; print("  NULL\n};");}' \
49551 +               $(filter-out %/Makefile,$^) > $@
49552 +
49553 +$(obj)/gen-kdb_cmds.c: $(src)/kdb_cmds $(wildcard $(TOPDIR)/arch/$(ARCH)/kdb/kdb_cmds) $(src)/Makefile
49554 +       $(call cmd,gen-kdb)
49555 diff -Nurp linux-2.6.22-590/kdb/modules/kdbm_pg.c linux-2.6.22-600/kdb/modules/kdbm_pg.c
49556 --- linux-2.6.22-590/kdb/modules/kdbm_pg.c      1970-01-01 01:00:00.000000000 +0100
49557 +++ linux-2.6.22-600/kdb/modules/kdbm_pg.c      2008-04-09 18:14:28.000000000 +0200
49558 @@ -0,0 +1,645 @@
49559 +/*
49560 + * This file is subject to the terms and conditions of the GNU General Public
49561 + * License.  See the file "COPYING" in the main directory of this archive
49562 + * for more details.
49563 + *
49564 + * Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
49565 + */
49566 +
49567 +#include <linux/module.h>
49568 +#include <linux/init.h>
49569 +#include <linux/mm.h>
49570 +#include <linux/pagemap.h>
49571 +#include <linux/fs.h>
49572 +#include <linux/bio.h>
49573 +#include <linux/buffer_head.h>
49574 +#include <linux/kdb.h>
49575 +#include <linux/kdbprivate.h>
49576 +#include <linux/blkdev.h>
49577 +#include <linux/ctype.h>
49578 +
49579 +MODULE_AUTHOR("SGI");
49580 +MODULE_DESCRIPTION("Debug page information");
49581 +MODULE_LICENSE("GPL");
49582 +
49583 +/* Standard Linux page stuff */
49584 +
49585 +#ifndef CONFIG_DISCONTIGMEM
49586 +/* From include/linux/page-flags.h */
49587 +static char *pg_flag_vals[] = {
49588 +       "PG_locked", "PG_error", "PG_referenced", "PG_uptodate",
49589 +       "PG_dirty", "PG_lru", "PG_active", "PG_slab",
49590 +       "PG_checked", "PG_arch_1", "PG_reserved", "PG_private",
49591 +       "PG_writeback", "?? 13 ??", "PG_compound", "PG_swapcache",
49592 +       "PG_mappedtodisk", "PG_reclaim", "?? 18 ??", "PG_buddy",
49593 +       NULL };
49594 +#endif
49595 +
49596 +/* From include/linux/buffer_head.h */
49597 +static char *bh_state_vals[] = {
49598 +       "Uptodate", "Dirty", "Lock", "Req",
49599 +       "Uptodate_Lock", "Mapped", "New", "Async_read",
49600 +       "Async_write", "Delay", "Boundary", "Write_EIO",
49601 +       "Ordered", "Eopnotsupp", "Unwritten", "Private",
49602 +       NULL };
49603 +
49604 +/* From include/linux/bio.h */
49605 +static char *bio_flag_vals[] = {
49606 +       "Uptodate", "RW_block", "EOF", "Seg_valid",
49607 +       "Cloned", "Bounced", "User_mapped", "Eopnotsupp",
49608 +       NULL };
49609 +
49610 +/* From include/linux/fs.h */
49611 +static char *inode_flag_vals[] = {
49612 +       "I_DIRTY_SYNC", "I_DIRTY_DATASYNC", "I_DIRTY_PAGES", "I_LOCK",
49613 +       "I_FREEING", "I_CLEAR", "I_NEW", "I_WILL_FREE",
49614 +       NULL };
49615 +
49616 +static char *map_flags(unsigned long flags, char *mapping[])
49617 +{
49618 +       static char buffer[256];
49619 +       int index;
49620 +       int offset = 12;
49621 +
49622 +       buffer[0] = '\0';
49623 +
49624 +       for (index = 0; flags && mapping[index]; flags >>= 1, index++) {
49625 +               if (flags & 1) {
49626 +                       if ((offset + strlen(mapping[index]) + 1) >= 80) {
49627 +                               strcat(buffer, "\n            ");
49628 +                               offset = 12;
49629 +                       } else if (offset > 12) {
49630 +                               strcat(buffer, " ");
49631 +                               offset++;
49632 +                       }
49633 +                       strcat(buffer, mapping[index]);
49634 +                       offset += strlen(mapping[index]);
49635 +               }
49636 +       }
49637 +
49638 +       return (buffer);
49639 +}
49640 +
49641 +static int
49642 +kdbm_buffers(int argc, const char **argv)
49643 +{
49644 +       struct buffer_head bh;
49645 +       unsigned long addr;
49646 +       long offset = 0;
49647 +       int nextarg;
49648 +       int diag;
49649 +
49650 +       if (argc != 1)
49651 +               return KDB_ARGCOUNT;
49652 +
49653 +       nextarg = 1;
49654 +       if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) ||
49655 +           (diag = kdb_getarea(bh, addr)))
49656 +               return(diag);
49657 +
49658 +       kdb_printf("buffer_head at 0x%lx\n", addr);
49659 +       kdb_printf("  bno %llu size %llu dev 0x%x\n",
49660 +               (unsigned long long)bh.b_blocknr,
49661 +               (unsigned long long)bh.b_size,
49662 +               bh.b_bdev ? bh.b_bdev->bd_dev : 0);
49663 +       kdb_printf("  count %d state 0x%lx [%s]\n",
49664 +               bh.b_count.counter, bh.b_state,
49665 +               map_flags(bh.b_state, bh_state_vals));
49666 +       kdb_printf("  b_data 0x%p\n",
49667 +               bh.b_data);
49668 +       kdb_printf("  b_page 0x%p b_this_page 0x%p b_private 0x%p\n",
49669 +               bh.b_page, bh.b_this_page, bh.b_private);
49670 +       kdb_printf("  b_end_io ");
49671 +       if (bh.b_end_io)
49672 +               kdb_symbol_print(kdba_funcptr_value(bh.b_end_io), NULL, KDB_SP_VALUE);
49673 +       else
49674 +               kdb_printf("(NULL)");
49675 +       kdb_printf("\n");
49676 +
49677 +       return 0;
49678 +}
49679 +
49680 +static int
49681 +print_biovec(struct bio_vec *vec, int vcount)
49682 +{
49683 +       struct bio_vec bvec;
49684 +       unsigned long addr;
49685 +       int diag;
49686 +       int i;
49687 +
49688 +       if (vcount < 1 || vcount > BIO_MAX_PAGES) {
49689 +               kdb_printf("  [skipped iovecs, vcnt is %d]\n", vcount);
49690 +               return 0;
49691 +       }
49692 +
49693 +       addr = (unsigned long)vec;
49694 +       for (i = 0; i < vcount; i++) {
49695 +               if ((diag = kdb_getarea(bvec, addr)))
49696 +                       return(diag);
49697 +               addr += sizeof(bvec);
49698 +               kdb_printf("  [%d] page 0x%p length=%u offset=%u\n",
49699 +                       i, bvec.bv_page, bvec.bv_len, bvec.bv_offset);
49700 +       }
49701 +       return 0;
49702 +}
49703 +
49704 +static int
49705 +kdbm_bio(int argc, const char **argv)
49706 +{
49707 +       struct bio bio;
49708 +       unsigned long addr;
49709 +       long offset = 0;
49710 +       int nextarg;
49711 +       int diag;
49712 +
49713 +       if (argc != 1)
49714 +               return KDB_ARGCOUNT;
49715 +
49716 +       nextarg = 1;
49717 +       if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) ||
49718 +           (diag = kdb_getarea(bio, addr)))
49719 +               return(diag);
49720 +
49721 +       kdb_printf("bio at 0x%lx\n", addr);
49722 +       kdb_printf("  bno %llu  next 0x%p  dev 0x%x\n",
49723 +               (unsigned long long)bio.bi_sector,
49724 +               bio.bi_next, bio.bi_bdev ? bio.bi_bdev->bd_dev : 0);
49725 +       kdb_printf("  vcnt %u vec 0x%p  rw 0x%lx flags 0x%lx [%s]\n",
49726 +               bio.bi_vcnt, bio.bi_io_vec, bio.bi_rw, bio.bi_flags,
49727 +               map_flags(bio.bi_flags, bio_flag_vals));
49728 +       print_biovec(bio.bi_io_vec, bio.bi_vcnt);
49729 +       kdb_printf("  count %d  private 0x%p\n",
49730 +               atomic_read(&bio.bi_cnt), bio.bi_private);
49731 +       kdb_printf("  bi_end_io ");
49732 +       if (bio.bi_end_io)
49733 +               kdb_symbol_print(kdba_funcptr_value(bio.bi_end_io), NULL, KDB_SP_VALUE);
49734 +       else
49735 +               kdb_printf("(NULL)");
49736 +       kdb_printf("\n");
49737 +
49738 +       return 0;
49739 +}
49740 +
49741 +#ifndef CONFIG_DISCONTIGMEM
49742 +static char *page_flags(unsigned long flags)
49743 +{
49744 +       return(map_flags(flags, pg_flag_vals));
49745 +}
49746 +
49747 +static int
49748 +kdbm_page(int argc, const char **argv)
49749 +{
49750 +       struct page page;
49751 +       unsigned long addr;
49752 +       long offset = 0;
49753 +       int nextarg;
49754 +       int diag;
49755 +
49756 +       if (argc != 1)
49757 +               return KDB_ARGCOUNT;
49758 +
49759 +       nextarg = 1;
49760 +       diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL);
49761 +       if (diag)
49762 +               return diag;
49763 +
49764 +#ifdef __ia64__
49765 +       if (rgn_index(addr) == 0)
49766 +               addr = (unsigned long) &mem_map[addr];  /* assume region 0 is a page index, not an address */
49767 +#else
49768 +       if (addr < PAGE_OFFSET)
49769 +               addr = (unsigned long) &mem_map[addr];
49770 +#endif
49771 +
49772 +       if ((diag = kdb_getarea(page, addr)))
49773 +               return(diag);
49774 +
49775 +       kdb_printf("struct page at 0x%lx\n", addr);
49776 +       kdb_printf("  addr space 0x%p index %lu (offset 0x%llx)\n",
49777 +                  page.mapping, page.index,
49778 +                  (unsigned long long)page.index << PAGE_CACHE_SHIFT);
49779 +       kdb_printf("  count %d flags %s\n",
49780 +                  page._count.counter, page_flags(page.flags));
49781 +       kdb_printf("  virtual 0x%p\n", page_address((struct page *)addr));
49782 +       if (page_has_buffers(&page))
49783 +               kdb_printf("  buffers 0x%p\n", page_buffers(&page));
49784 +       else
49785 +               kdb_printf("  private 0x%lx\n", page_private(&page));
49786 +
49787 +       return 0;
49788 +}
49789 +#endif /* CONFIG_DISCONTIGMEM */
49790 +
49791 +static unsigned long
49792 +print_request(unsigned long addr)
49793 +{
49794 +       struct request rq;
49795 +
49796 +       if (kdb_getarea(rq, addr))
49797 +               return(0);
49798 +
49799 +       kdb_printf("struct request at 0x%lx\n", addr);
49800 +       kdb_printf("  errors %d sector %llu nr_sectors %lu\n",
49801 +                       rq.errors,
49802 +                       (unsigned long long)rq.sector, rq.nr_sectors);
49803 +
49804 +       kdb_printf("  hsect %llu hnrsect %lu nrseg %u nrhwseg %u currnrsect %u\n",
49805 +                       (unsigned long long)rq.hard_sector, rq.hard_nr_sectors,
49806 +                       rq.nr_phys_segments, rq.nr_hw_segments,
49807 +                       rq.current_nr_sectors);
49808 +
49809 +       return (unsigned long) rq.queuelist.next;
49810 +}
49811 +
49812 +static int
49813 +kdbm_request(int argc, const char **argv)
49814 +{
49815 +       long offset = 0;
49816 +       unsigned long addr;
49817 +       int nextarg;
49818 +       int diag;
49819 +
49820 +       if (argc != 1)
49821 +               return KDB_ARGCOUNT;
49822 +
49823 +       nextarg = 1;
49824 +       diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL);
49825 +       if (diag)
49826 +               return diag;
49827 +
49828 +       print_request(addr);
49829 +       return 0;
49830 +}
49831 +
49832 +
49833 +static int
49834 +kdbm_rqueue(int argc, const char **argv)
49835 +{
49836 +       struct request_queue rq;
49837 +       unsigned long addr, head_addr, next;
49838 +       long offset = 0;
49839 +       int nextarg;
49840 +       int i, diag;
49841 +
49842 +       if (argc != 1)
49843 +               return KDB_ARGCOUNT;
49844 +
49845 +       nextarg = 1;
49846 +       if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) ||
49847 +           (diag = kdb_getarea(rq, addr)))
49848 +               return(diag);
49849 +
49850 +       kdb_printf("struct request_queue at 0x%lx\n", addr);
49851 +       i = 0;
49852 +       next = (unsigned long)rq.queue_head.next;
49853 +       head_addr = addr + offsetof(struct request_queue, queue_head);
49854 +       kdb_printf(" request queue: %s\n", next == head_addr ?
49855 +               "empty" : "");
49856 +       while (next != head_addr) {
49857 +               i++;
49858 +               next = print_request(next);
49859 +       }
49860 +
49861 +       if (i)
49862 +               kdb_printf("%d requests found\n", i);
49863 +
49864 +       return 0;
49865 +}
49866 +
49867 +
49868 +static void
49869 +do_buffer(unsigned long addr)
49870 +{
49871 +       struct buffer_head bh;
49872 +
49873 +       if (kdb_getarea(bh, addr))
49874 +               return;
49875 +
49876 +       kdb_printf("\tbh 0x%lx bno %8llu [%s]\n", addr,
49877 +                (unsigned long long)bh.b_blocknr,
49878 +                map_flags(bh.b_state, bh_state_vals));
49879 +}
49880 +
49881 +static void
49882 +kdbm_show_page(struct page *page, int first)
49883 +{
49884 +       if (first)
49885 +               kdb_printf("page_struct       index   cnt zone nid flags\n");
49886 +       kdb_printf("%p%s %6lu %5d %3d %3d 0x%lx",
49887 +               page_address(page), sizeof(void *) == 4 ? "        " : "",
49888 +               page->index, atomic_read(&(page->_count)),
49889 +               page_zonenum(page), page_to_nid(page),
49890 +               page->flags & (~0UL >> ZONES_SHIFT));
49891 +#define kdb_page_flags(page, type) if (Page ## type(page)) kdb_printf(" " #type);
49892 +       kdb_page_flags(page, Locked);
49893 +       kdb_page_flags(page, Error);
49894 +       kdb_page_flags(page, Referenced);
49895 +       kdb_page_flags(page, Uptodate);
49896 +       kdb_page_flags(page, Dirty);
49897 +       kdb_page_flags(page, LRU);
49898 +       kdb_page_flags(page, Active);
49899 +       kdb_page_flags(page, Slab);
49900 +       kdb_page_flags(page, Checked);
49901 +       if (page->flags & (1UL << PG_arch_1))
49902 +               kdb_printf(" arch_1");
49903 +       kdb_page_flags(page, Reserved);
49904 +       kdb_page_flags(page, Private);
49905 +       kdb_page_flags(page, Writeback);
49906 +       kdb_page_flags(page, Compound);
49907 +       kdb_page_flags(page, SwapCache);
49908 +       kdb_page_flags(page, MappedToDisk);
49909 +       kdb_page_flags(page, Reclaim);
49910 +       kdb_page_flags(page, Buddy);
49911 +
49912 +       /* PageHighMem is not a flag any more, but treat it as one */
49913 +       kdb_page_flags(page, HighMem);
49914 +
49915 +       if (page_has_buffers(page)) {
49916 +               struct buffer_head *head, *bh;
49917 +               kdb_printf("\n");
49918 +               head = bh = page_buffers(page);
49919 +               do {
49920 +                       do_buffer((unsigned long) bh);
49921 +               } while ((bh = bh->b_this_page) != head);
49922 +       } else if (page_private(page)) {
49923 +               kdb_printf(" private= 0x%lx", page_private(page));
49924 +       }
49925 +       /* Cannot use page_mapping(page) here, it needs swapper_space which is
49926 +        * not exported.
49927 +        */
49928 +       if (page->mapping)
49929 +               kdb_printf(" mapping= %p", page->mapping);
49930 +       kdb_printf("\n");
49931 +#undef kdb_page_flags
49932 +}
49933 +
49934 +static int
49935 +kdbm_inode_pages(int argc, const char **argv)
49936 +{
49937 +       struct inode *inode = NULL;
49938 +       struct address_space *ap = NULL;
49939 +       unsigned long addr, addr1 = 0;
49940 +       long offset = 0;
49941 +       int nextarg;
49942 +       int diag;
49943 +       pgoff_t next = 0;
49944 +       struct page *page;
49945 +       int first;
49946 +
49947 +       nextarg = 1;
49948 +       diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL);
49949 +       if (diag)
49950 +               goto out;
49951 +
49952 +       if (argc == 2) {
49953 +               nextarg = 2;
49954 +               diag = kdbgetaddrarg(argc, argv, &nextarg, &addr1,
49955 +                                       &offset, NULL);
49956 +               if (diag)
49957 +                       goto out;
49958 +               kdb_printf("Looking for page index 0x%lx ... \n", addr1);
49959 +               next = addr1;
49960 +       }
49961 +
49962 +       if (!(inode = kmalloc(sizeof(*inode), GFP_ATOMIC))) {
49963 +               kdb_printf("kdbm_inode_pages: cannot kmalloc inode\n");
49964 +               goto out;
49965 +       }
49966 +       if (!(ap = kmalloc(sizeof(*ap), GFP_ATOMIC))) {
49967 +               kdb_printf("kdbm_inode_pages: cannot kmalloc ap\n");
49968 +               goto out;
49969 +       }
49970 +       if ((diag = kdb_getarea(*inode, addr)))
49971 +               goto out;
49972 +       if (!inode->i_mapping) {
49973 +               kdb_printf("inode has no mapping\n");
49974 +               goto out;
49975 +       }
49976 +       if ((diag = kdb_getarea(*ap, (unsigned long) inode->i_mapping)))
49977 +               goto out;
49978 +
49979 +       /* Run the pages in the radix tree, printing the state of each page */
49980 +       first = 1;
49981 +       while (radix_tree_gang_lookup(&ap->page_tree, (void **)&page, next, 1)) {
49982 +               kdbm_show_page(page, first);
49983 +               if (addr1)
49984 +                       break;
49985 +               first = 0;
49986 +               next = page->index + 1;
49987 +       }
49988 +
49989 +out:
49990 +       if (inode)
49991 +               kfree(inode);
49992 +       if (ap)
49993 +               kfree(ap);
49994 +       return diag;
49995 +}
49996 +
49997 +static int
49998 +kdbm_inode(int argc, const char **argv)
49999 +{
50000 +       struct inode *inode = NULL;
50001 +       unsigned long addr;
50002 +       unsigned char *iaddr;
50003 +       long offset = 0;
50004 +       int nextarg;
50005 +       int diag;
50006 +
50007 +       if (argc != 1)
50008 +               return KDB_ARGCOUNT;
50009 +
50010 +       nextarg = 1;
50011 +       if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)))
50012 +               goto out;
50013 +       if (!(inode = kmalloc(sizeof(*inode), GFP_ATOMIC))) {
50014 +               kdb_printf("kdbm_inode: cannot kmalloc inode\n");
50015 +               goto out;
50016 +       }
50017 +       if ((diag = kdb_getarea(*inode, addr)))
50018 +               goto out;
50019 +
50020 +       kdb_printf("struct inode at  0x%lx\n", addr);
50021 +
50022 +       kdb_printf(" i_ino = %lu i_count = %u i_size %Ld\n",
50023 +                                       inode->i_ino, atomic_read(&inode->i_count),
50024 +                                       inode->i_size);
50025 +
50026 +       kdb_printf(" i_mode = 0%o  i_nlink = %d  i_rdev = 0x%x\n",
50027 +                                       inode->i_mode, inode->i_nlink,
50028 +                                       inode->i_rdev);
50029 +
50030 +       kdb_printf(" i_hash.nxt = 0x%p i_hash.pprev = 0x%p\n",
50031 +               inode->i_hash.next,
50032 +               inode->i_hash.pprev);
50033 +
50034 +       kdb_printf(" i_list.nxt = 0x%p i_list.prv = 0x%p\n",
50035 +               list_entry(inode->i_list.next, struct inode, i_list),
50036 +               list_entry(inode->i_list.prev, struct inode, i_list));
50037 +
50038 +       kdb_printf(" i_dentry.nxt = 0x%p i_dentry.prv = 0x%p\n",
50039 +               list_entry(inode->i_dentry.next, struct dentry, d_alias),
50040 +               list_entry(inode->i_dentry.prev, struct dentry, d_alias));
50041 +
50042 +       kdb_printf(" i_sb = 0x%p i_op = 0x%p i_data = 0x%lx nrpages = %lu\n",
50043 +                                       inode->i_sb, inode->i_op,
50044 +                                       addr + offsetof(struct inode, i_data),
50045 +                                       inode->i_data.nrpages);
50046 +       kdb_printf(" i_fop= 0x%p i_flock = 0x%p i_mapping = 0x%p\n",
50047 +                          inode->i_fop, inode->i_flock, inode->i_mapping);
50048 +
50049 +       kdb_printf(" i_flags 0x%x i_state 0x%lx [%s]",
50050 +                          inode->i_flags, inode->i_state,
50051 +                          map_flags(inode->i_state, inode_flag_vals));
50052 +
50053 +       iaddr  = (char *)addr;
50054 +       iaddr += offsetof(struct inode, i_private);
50055 +
50056 +       kdb_printf("  fs specific info @ 0x%p\n", iaddr);
50057 +out:
50058 +       if (inode)
50059 +               kfree(inode);
50060 +       return diag;
50061 +}
50062 +
50063 +static int
50064 +kdbm_sb(int argc, const char **argv)
50065 +{
50066 +       struct super_block *sb = NULL;
50067 +       unsigned long addr;
50068 +       long offset = 0;
50069 +       int nextarg;
50070 +       int diag;
50071 +
50072 +       if (argc != 1)
50073 +               return KDB_ARGCOUNT;
50074 +
50075 +       nextarg = 1;
50076 +       if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)))
50077 +               goto out;
50078 +       if (!(sb = kmalloc(sizeof(*sb), GFP_ATOMIC))) {
50079 +               kdb_printf("kdbm_sb: cannot kmalloc sb\n");
50080 +               goto out;
50081 +       }
50082 +       if ((diag = kdb_getarea(*sb, addr)))
50083 +               goto out;
50084 +
50085 +       kdb_printf("struct super_block at  0x%lx\n", addr);
50086 +       kdb_printf(" s_dev 0x%x blocksize 0x%lx\n", sb->s_dev, sb->s_blocksize);
50087 +       kdb_printf(" s_flags 0x%lx s_root 0x%p\n", sb->s_flags, sb->s_root);
50088 +       kdb_printf(" s_dirt %d s_dirty.next 0x%p s_dirty.prev 0x%p\n",
50089 +               sb->s_dirt, sb->s_dirty.next, sb->s_dirty.prev);
50090 +       kdb_printf(" s_frozen %d s_id [%s]\n", sb->s_frozen, sb->s_id);
50091 +out:
50092 +       if (sb)
50093 +               kfree(sb);
50094 +       return diag;
50095 +}
50096 +
50097 +
50098 +
50099 +#if defined(CONFIG_X86) && !defined(CONFIG_X86_64)
50100 +/* According to Steve Lord, this code is ix86 specific.  Patches to extend it to
50101 + * other architectures will be greatefully accepted.
50102 + */
50103 +static int
50104 +kdbm_memmap(int argc, const char **argv)
50105 +{
50106 +       struct page page;
50107 +       int i, page_count;
50108 +       int slab_count = 0;
50109 +       int dirty_count = 0;
50110 +       int locked_count = 0;
50111 +       int page_counts[9];
50112 +       int buffered_count = 0;
50113 +#ifdef buffer_delay
50114 +       int delay_count = 0;
50115 +#endif
50116 +       int diag;
50117 +       unsigned long addr;
50118 +
50119 +       addr = (unsigned long)mem_map;
50120 +       page_count = max_mapnr;
50121 +       memset(page_counts, 0, sizeof(page_counts));
50122 +
50123 +       for (i = 0; i < page_count; i++) {
50124 +               if ((diag = kdb_getarea(page, addr)))
50125 +                       return(diag);
50126 +               addr += sizeof(page);
50127 +
50128 +               if (PageSlab(&page))
50129 +                       slab_count++;
50130 +               if (PageDirty(&page))
50131 +                       dirty_count++;
50132 +               if (PageLocked(&page))
50133 +                       locked_count++;
50134 +               if (page._count.counter < 8)
50135 +                       page_counts[page._count.counter]++;
50136 +               else
50137 +                       page_counts[8]++;
50138 +               if (page_has_buffers(&page)) {
50139 +                       buffered_count++;
50140 +#ifdef buffer_delay
50141 +                       if (buffer_delay(page.buffers))
50142 +                               delay_count++;
50143 +#endif
50144 +               }
50145 +
50146 +       }
50147 +
50148 +       kdb_printf("  Total pages:      %6d\n", page_count);
50149 +       kdb_printf("  Slab pages:       %6d\n", slab_count);
50150 +       kdb_printf("  Dirty pages:      %6d\n", dirty_count);
50151 +       kdb_printf("  Locked pages:     %6d\n", locked_count);
50152 +       kdb_printf("  Buffer pages:     %6d\n", buffered_count);
50153 +#ifdef buffer_delay
50154 +       kdb_printf("  Delalloc pages:   %6d\n", delay_count);
50155 +#endif
50156 +       for (i = 0; i < 8; i++) {
50157 +               kdb_printf("  %d page count:     %6d\n",
50158 +                       i, page_counts[i]);
50159 +       }
50160 +       kdb_printf("  high page count:  %6d\n", page_counts[8]);
50161 +       return 0;
50162 +}
50163 +#endif /* CONFIG_X86 && !CONFIG_X86_64 */
50164 +
50165 +static int __init kdbm_pg_init(void)
50166 +{
50167 +#ifndef CONFIG_DISCONTIGMEM
50168 +       kdb_register("page", kdbm_page, "<vaddr>", "Display page", 0);
50169 +#endif
50170 +       kdb_register("inode", kdbm_inode, "<vaddr>", "Display inode", 0);
50171 +       kdb_register("sb", kdbm_sb, "<vaddr>", "Display super_block", 0);
50172 +       kdb_register("bh", kdbm_buffers, "<buffer head address>", "Display buffer", 0);
50173 +       kdb_register("bio", kdbm_bio, "<bio address>", "Display bio", 0);
50174 +       kdb_register("inode_pages", kdbm_inode_pages, "<inode *>", "Display pages in an inode", 0);
50175 +       kdb_register("req", kdbm_request, "<vaddr>", "dump request struct", 0);
50176 +       kdb_register("rqueue", kdbm_rqueue, "<vaddr>", "dump request queue", 0);
50177 +#if defined(CONFIG_X86) && !defined(CONFIG_X86_64)
50178 +       kdb_register("memmap", kdbm_memmap, "", "page table summary", 0);
50179 +#endif
50180 +
50181 +       return 0;
50182 +}
50183 +
50184 +
50185 +static void __exit kdbm_pg_exit(void)
50186 +{
50187 +#ifndef CONFIG_DISCONTIGMEM
50188 +       kdb_unregister("page");
50189 +#endif
50190 +       kdb_unregister("inode");
50191 +       kdb_unregister("sb");
50192 +       kdb_unregister("bh");
50193 +       kdb_unregister("bio");
50194 +       kdb_unregister("inode_pages");
50195 +       kdb_unregister("req");
50196 +       kdb_unregister("rqueue");
50197 +#if defined(CONFIG_X86) && !defined(CONFIG_X86_64)
50198 +       kdb_unregister("memmap");
50199 +#endif
50200 +}
50201 +
50202 +module_init(kdbm_pg_init)
50203 +module_exit(kdbm_pg_exit)
50204 diff -Nurp linux-2.6.22-590/kdb/modules/kdbm_sched.c linux-2.6.22-600/kdb/modules/kdbm_sched.c
50205 --- linux-2.6.22-590/kdb/modules/kdbm_sched.c   1970-01-01 01:00:00.000000000 +0100
50206 +++ linux-2.6.22-600/kdb/modules/kdbm_sched.c   2008-04-09 18:14:28.000000000 +0200
50207 @@ -0,0 +1,57 @@
50208 +/*
50209 + * This file is subject to the terms and conditions of the GNU General Public
50210 + * License.  See the file "COPYING" in the main directory of this archive
50211 + * for more details.
50212 + *
50213 + * Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
50214 + */
50215 +
50216 +#include <linux/kdb.h>
50217 +#include <linux/kdbprivate.h>
50218 +#include <linux/module.h>
50219 +#include <linux/init.h>
50220 +#include <linux/sched.h>
50221 +
50222 +MODULE_AUTHOR("SGI");
50223 +MODULE_DESCRIPTION("Debug scheduler information");
50224 +MODULE_LICENSE("GPL");
50225 +
50226 +static int
50227 +kdbm_runqueues(int argc, const char **argv)
50228 +{
50229 +       unsigned long cpu;
50230 +       int ret = 0;
50231 +
50232 +       if (argc == 1) {
50233 +               ret = kdbgetularg((char *)argv[1], &cpu);
50234 +               if (!ret) {
50235 +                       if (!cpu_online(cpu)) {
50236 +                               kdb_printf("Invalid cpu number\n");
50237 +                       } else
50238 +                               kdb_runqueue(cpu, kdb_printf);
50239 +               }
50240 +       } else if (argc == 0) {
50241 +               for_each_online_cpu(cpu)
50242 +                       kdb_runqueue(cpu, kdb_printf);
50243 +       } else {
50244 +               /* More than one arg */
50245 +               kdb_printf("Specify one cpu number\n");
50246 +       }
50247 +       return ret;
50248 +}
50249 +
50250 +static int __init kdbm_sched_init(void)
50251 +{
50252 +       kdb_register("rq",  kdbm_runqueues, "<cpunum>", "Display runqueue for <cpunum>", 0);
50253 +       kdb_register("rqa", kdbm_runqueues, "", "Display all runqueues", 0);
50254 +       return 0;
50255 +}
50256 +
50257 +static void __exit kdbm_sched_exit(void)
50258 +{
50259 +       kdb_unregister("rq");
50260 +       kdb_unregister("rqa");
50261 +}
50262 +
50263 +module_init(kdbm_sched_init)
50264 +module_exit(kdbm_sched_exit)
50265 diff -Nurp linux-2.6.22-590/kdb/modules/kdbm_task.c linux-2.6.22-600/kdb/modules/kdbm_task.c
50266 --- linux-2.6.22-590/kdb/modules/kdbm_task.c    1970-01-01 01:00:00.000000000 +0100
50267 +++ linux-2.6.22-600/kdb/modules/kdbm_task.c    2008-04-09 18:14:28.000000000 +0200
50268 @@ -0,0 +1,199 @@
50269 +/*
50270 + * This file is subject to the terms and conditions of the GNU General Public
50271 + * License.  See the file "COPYING" in the main directory of this archive
50272 + * for more details.
50273 + *
50274 + * Copyright (c) 1999-2006 Silicon Graphics, Inc.  All Rights Reserved.
50275 + */
50276 +
50277 +#include <linux/blkdev.h>
50278 +#include <linux/types.h>
50279 +#include <linux/kdb.h>
50280 +#include <linux/kdbprivate.h>
50281 +#include <linux/module.h>
50282 +#include <linux/init.h>
50283 +#include <linux/mm.h>
50284 +#include <linux/sched.h>
50285 +#include <asm/signal.h>
50286 +
50287 +MODULE_AUTHOR("SGI");
50288 +MODULE_DESCRIPTION("Debug struct task and sigset information");
50289 +MODULE_LICENSE("GPL");
50290 +
50291 +static char *
50292 +kdb_cpus_allowed_string(struct task_struct *tp)
50293 +{
50294 +       static char maskbuf[NR_CPUS * 8];
50295 +       if (cpus_equal(tp->cpus_allowed, cpu_online_map))
50296 +               strcpy(maskbuf, "ALL");
50297 +       else if (cpus_full(tp->cpus_allowed))
50298 +               strcpy(maskbuf, "ALL(NR_CPUS)");
50299 +       else if (cpus_empty(tp->cpus_allowed))
50300 +               strcpy(maskbuf, "NONE");
50301 +       else if (cpus_weight(tp->cpus_allowed) == 1)
50302 +               snprintf(maskbuf, sizeof(maskbuf), "ONLY(%d)", first_cpu(tp->cpus_allowed));
50303 +       else
50304 +               cpulist_scnprintf(maskbuf, sizeof(maskbuf), tp->cpus_allowed);
50305 +       return maskbuf;
50306 +}
50307 +
50308 +static int
50309 +kdbm_task(int argc, const char **argv)
50310 +{
50311 +       unsigned long addr;
50312 +       long offset=0;
50313 +       int nextarg;
50314 +       int e = 0;
50315 +       struct task_struct *tp = NULL, *tp1;
50316 +
50317 +       if (argc != 1)
50318 +               return KDB_ARGCOUNT;
50319 +
50320 +       nextarg = 1;
50321 +       if ((e = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) != 0)
50322 +               return(e);
50323 +
50324 +       if (!(tp = kmalloc(sizeof(*tp), GFP_ATOMIC))) {
50325 +           kdb_printf("%s: cannot kmalloc tp\n", __FUNCTION__);
50326 +           goto out;
50327 +       }
50328 +       if ((e = kdb_getarea(*tp, addr))) {
50329 +           kdb_printf("%s: invalid task address\n", __FUNCTION__);
50330 +           goto out;
50331 +       }
50332 +
50333 +       tp1 = (struct task_struct *)addr;
50334 +       kdb_printf(
50335 +           "struct task at 0x%lx, pid=%d flags=0x%x state=%ld comm=\"%s\"\n",
50336 +           addr, tp->pid, tp->flags, tp->state, tp->comm);
50337 +
50338 +       kdb_printf("  cpu=%d policy=%u ", kdb_process_cpu(tp), tp->policy);
50339 +       kdb_printf(
50340 +           "prio=%d static_prio=%d cpus_allowed=",
50341 +           tp->prio, tp->static_prio);
50342 +       {
50343 +               /* The cpus allowed string may be longer than kdb_printf() can
50344 +                * handle.  Print it in chunks.
50345 +                */
50346 +               char c, *p;
50347 +               p = kdb_cpus_allowed_string(tp);
50348 +               while (1) {
50349 +                       if (strlen(p) < 100) {
50350 +                               kdb_printf("%s", p);
50351 +                               break;
50352 +                       }
50353 +                       c = p[100];
50354 +                       p[100] = '\0';
50355 +                       kdb_printf("%s", p);
50356 +                       p[100] = c;
50357 +                       p += 100;
50358 +               }
50359 +       }
50360 +       kdb_printf(" &thread=0x%p\n", &tp1->thread);
50361 +
50362 +       kdb_printf("  need_resched=%d ",
50363 +               test_tsk_thread_flag(tp, TIF_NEED_RESCHED));
50364 +       kdb_printf(
50365 +           "timestamp=%llu time_slice=%u",
50366 +           tp->timestamp, tp->time_slice);
50367 +       kdb_printf(" lock_depth=%d\n", tp->lock_depth);
50368 +
50369 +       kdb_printf(
50370 +           "  fs=0x%p files=0x%p mm=0x%p\n",
50371 +           tp->fs, tp->files, tp->mm);
50372 +
50373 +       kdb_printf(
50374 +           "  uid=%d euid=%d suid=%d fsuid=%d gid=%d egid=%d sgid=%d fsgid=%d\n",
50375 +           tp->uid, tp->euid, tp->suid, tp->fsuid, tp->gid, tp->egid, tp->sgid, tp->fsgid);
50376 +
50377 +       kdb_printf(
50378 +           "  user=0x%p\n",
50379 +           tp->user);
50380 +
50381 +       if (tp->sysvsem.undo_list)
50382 +               kdb_printf(
50383 +                   "  sysvsem.sem_undo refcnt %d proc_list=0x%p\n",
50384 +                   atomic_read(&tp->sysvsem.undo_list->refcnt),
50385 +                   tp->sysvsem.undo_list->proc_list);
50386 +
50387 +       kdb_printf(
50388 +           "  signal=0x%p &blocked=0x%p &pending=0x%p\n",
50389 +           tp->signal, &tp1->blocked, &tp1->pending);
50390 +
50391 +       kdb_printf(
50392 +           "  utime=%ld stime=%ld cutime=%ld cstime=%ld\n",
50393 +           tp->utime, tp->stime,
50394 +           tp->signal ? tp->signal->cutime : 0L,
50395 +           tp->signal ? tp->signal->cstime : 0L);
50396 +
50397 +       kdb_printf("  thread_info=0x%p\n", task_thread_info(tp));
50398 +       kdb_printf("  ti flags=0x%lx\n", (unsigned long)task_thread_info(tp)->flags);
50399 +
50400 +out:
50401 +       if (tp)
50402 +           kfree(tp);
50403 +       return e;
50404 +}
50405 +
50406 +static int
50407 +kdbm_sigset(int argc, const char **argv)
50408 +{
50409 +       sigset_t *sp = NULL;
50410 +       unsigned long addr;
50411 +       long offset=0;
50412 +       int nextarg;
50413 +       int e = 0;
50414 +       int i;
50415 +       char fmt[32];
50416 +
50417 +       if (argc != 1)
50418 +               return KDB_ARGCOUNT;
50419 +
50420 +#ifndef _NSIG_WORDS
50421 +       kdb_printf("unavailable on this platform, _NSIG_WORDS not defined.\n");
50422 +#else
50423 +       nextarg = 1;
50424 +       if ((e = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) != 0)
50425 +               return(e);
50426 +
50427 +       if (!(sp = kmalloc(sizeof(*sp), GFP_ATOMIC))) {
50428 +           kdb_printf("%s: cannot kmalloc sp\n", __FUNCTION__);
50429 +           goto out;
50430 +       }
50431 +       if ((e = kdb_getarea(*sp, addr))) {
50432 +           kdb_printf("%s: invalid sigset address\n", __FUNCTION__);
50433 +           goto out;
50434 +       }
50435 +
50436 +       sprintf(fmt, "[%%d]=0x%%0%dlx ", (int)sizeof(sp->sig[0])*2);
50437 +       kdb_printf("sigset at 0x%p : ", sp);
50438 +       for (i=_NSIG_WORDS-1; i >= 0; i--) {
50439 +           if (i == 0 || sp->sig[i]) {
50440 +               kdb_printf(fmt, i, sp->sig[i]);
50441 +           }
50442 +       }
50443 +       kdb_printf("\n");
50444 +#endif /* _NSIG_WORDS */
50445 +
50446 +out:
50447 +       if (sp)
50448 +           kfree(sp);
50449 +       return e;
50450 +}
50451 +
50452 +static int __init kdbm_task_init(void)
50453 +{
50454 +       kdb_register("task", kdbm_task, "<vaddr>", "Display task_struct", 0);
50455 +       kdb_register("sigset", kdbm_sigset, "<vaddr>", "Display sigset_t", 0);
50456 +
50457 +       return 0;
50458 +}
50459 +
50460 +static void __exit kdbm_task_exit(void)
50461 +{
50462 +       kdb_unregister("task");
50463 +       kdb_unregister("sigset");
50464 +}
50465 +
50466 +module_init(kdbm_task_init)
50467 +module_exit(kdbm_task_exit)
50468 diff -Nurp linux-2.6.22-590/kdb/modules/kdbm_vm.c linux-2.6.22-600/kdb/modules/kdbm_vm.c
50469 --- linux-2.6.22-590/kdb/modules/kdbm_vm.c      1970-01-01 01:00:00.000000000 +0100
50470 +++ linux-2.6.22-600/kdb/modules/kdbm_vm.c      2008-04-09 18:14:28.000000000 +0200
50471 @@ -0,0 +1,841 @@
50472 +/*
50473 + * This file is subject to the terms and conditions of the GNU General Public
50474 + * License.  See the file "COPYING" in the main directory of this archive
50475 + * for more details.
50476 + *
50477 + * Copyright (c) 1999-2006 Silicon Graphics, Inc.  All Rights Reserved.
50478 + */
50479 +
50480 +#include <linux/blkdev.h>
50481 +#include <linux/types.h>
50482 +#include <linux/kdb.h>
50483 +#include <linux/kdbprivate.h>
50484 +#include <linux/module.h>
50485 +#include <linux/init.h>
50486 +#include <linux/mm.h>
50487 +#include <linux/swap.h>
50488 +#include <linux/swapops.h>
50489 +
50490 +#include <scsi.h>
50491 +#include <scsi/scsi_host.h>
50492 +
50493 +MODULE_AUTHOR("SGI");
50494 +MODULE_DESCRIPTION("Debug VM information");
50495 +MODULE_LICENSE("GPL");
50496 +
50497 +struct __vmflags {
50498 +       unsigned long mask;
50499 +       char *name;
50500 +};
50501 +
50502 +static struct __vmflags vmflags[] = {
50503 +       { VM_READ, "VM_READ " },
50504 +       { VM_WRITE, "VM_WRITE " },
50505 +       { VM_EXEC, "VM_EXEC " },
50506 +       { VM_SHARED, "VM_SHARED " },
50507 +       { VM_MAYREAD, "VM_MAYREAD " },
50508 +       { VM_MAYWRITE, "VM_MAYWRITE " },
50509 +       { VM_MAYEXEC, "VM_MAYEXEC " },
50510 +       { VM_MAYSHARE, "VM_MAYSHARE " },
50511 +       { VM_GROWSDOWN, "VM_GROWSDOWN " },
50512 +       { VM_GROWSUP, "VM_GROWSUP " },
50513 +       { VM_PFNMAP, "VM_PFNMAP " },
50514 +       { VM_DENYWRITE, "VM_DENYWRITE " },
50515 +       { VM_EXECUTABLE, "VM_EXECUTABLE " },
50516 +       { VM_LOCKED, "VM_LOCKED " },
50517 +       { VM_IO, "VM_IO " },
50518 +       { VM_SEQ_READ, "VM_SEQ_READ " },
50519 +       { VM_RAND_READ, "VM_RAND_READ " },
50520 +       { VM_DONTCOPY, "VM_DONTCOPY " },
50521 +       { VM_DONTEXPAND, "VM_DONTEXPAND " },
50522 +       { VM_RESERVED, "VM_RESERVED " },
50523 +       { VM_ACCOUNT, "VM_ACCOUNT " },
50524 +       { VM_HUGETLB, "VM_HUGETLB " },
50525 +       { VM_NONLINEAR, "VM_NONLINEAR " },
50526 +       { VM_MAPPED_COPY, "VM_MAPPED_COPY " },
50527 +       { VM_INSERTPAGE, "VM_INSERTPAGE " },
50528 +       { 0, "" }
50529 +};
50530 +
50531 +static int
50532 +kdbm_print_vm(struct vm_area_struct *vp, unsigned long addr, int verbose_flg)
50533 +{
50534 +       struct __vmflags *tp;
50535 +
50536 +       kdb_printf("struct vm_area_struct at 0x%lx for %d bytes\n",
50537 +                  addr, (int) sizeof (struct vm_area_struct));
50538 +
50539 +       kdb_printf("vm_start = 0x%p   vm_end = 0x%p\n", (void *) vp->vm_start,
50540 +                  (void *) vp->vm_end);
50541 +       kdb_printf("vm_page_prot = 0x%lx\n", pgprot_val(vp->vm_page_prot));
50542 +
50543 +       kdb_printf("vm_flags: ");
50544 +       for (tp = vmflags; tp->mask; tp++) {
50545 +               if (vp->vm_flags & tp->mask) {
50546 +                       kdb_printf(" %s", tp->name);
50547 +               }
50548 +       }
50549 +       kdb_printf("\n");
50550 +
50551 +       if (!verbose_flg)
50552 +               return 0;
50553 +
50554 +       kdb_printf("vm_mm = 0x%p\n", (void *) vp->vm_mm);
50555 +       kdb_printf("vm_next = 0x%p\n", (void *) vp->vm_next);
50556 +       kdb_printf("shared.vm_set.list.next = 0x%p\n", (void *) vp->shared.vm_set.list.next);
50557 +       kdb_printf("shared.vm_set.list.prev = 0x%p\n", (void *) vp->shared.vm_set.list.prev);
50558 +       kdb_printf("shared.vm_set.parent = 0x%p\n", (void *) vp->shared.vm_set.parent);
50559 +       kdb_printf("shared.vm_set.head = 0x%p\n", (void *) vp->shared.vm_set.head);
50560 +       kdb_printf("anon_vma_node.next = 0x%p\n", (void *) vp->anon_vma_node.next);
50561 +       kdb_printf("anon_vma_node.prev = 0x%p\n", (void *) vp->anon_vma_node.prev);
50562 +       kdb_printf("vm_ops = 0x%p\n", (void *) vp->vm_ops);
50563 +       if (vp->vm_ops != NULL) {
50564 +               kdb_printf("vm_ops->open = 0x%p\n", vp->vm_ops->open);
50565 +               kdb_printf("vm_ops->close = 0x%p\n", vp->vm_ops->close);
50566 +               kdb_printf("vm_ops->nopage = 0x%p\n", vp->vm_ops->nopage);
50567 +#ifdef HAVE_VMOP_MPROTECT
50568 +               kdb_printf("vm_ops->mprotect = 0x%p\n", vp->vm_ops->mprotect);
50569 +#endif
50570 +       }
50571 +       kdb_printf("vm_pgoff = 0x%lx\n", vp->vm_pgoff);
50572 +       kdb_printf("vm_file = 0x%p\n", (void *) vp->vm_file);
50573 +       kdb_printf("vm_private_data = 0x%p\n", vp->vm_private_data);
50574 +
50575 +       return 0;
50576 +}
50577 +
50578 +static int
50579 +kdbm_print_vmp(struct vm_area_struct *vp, int verbose_flg)
50580 +{
50581 +       struct __vmflags *tp;
50582 +
50583 +       if (verbose_flg) {
50584 +               kdb_printf("0x%lx:  ", (unsigned long) vp);
50585 +       }
50586 +
50587 +       kdb_printf("0x%p  0x%p ", (void *) vp->vm_start, (void *) vp->vm_end);
50588 +
50589 +       for (tp = vmflags; tp->mask; tp++) {
50590 +               if (vp->vm_flags & tp->mask) {
50591 +                       kdb_printf(" %s", tp->name);
50592 +               }
50593 +       }
50594 +       kdb_printf("\n");
50595 +
50596 +       return 0;
50597 +}
50598 +
50599 +/*
50600 + * kdbm_vm
50601 + *
50602 + *     This function implements the 'vm' command.  Print a vm_area_struct.
50603 + *
50604 + *     vm [-v] <address>       Print vm_area_struct at <address>
50605 + *     vmp [-v] <pid>          Print all vm_area_structs for <pid>
50606 + */
50607 +
50608 +static int
50609 +kdbm_vm(int argc, const char **argv)
50610 +{
50611 +       unsigned long addr;
50612 +       long offset = 0;
50613 +       int nextarg;
50614 +       int diag;
50615 +       int verbose_flg = 0;
50616 +
50617 +       if (argc == 2) {
50618 +               if (strcmp(argv[1], "-v") != 0) {
50619 +                       return KDB_ARGCOUNT;
50620 +               }
50621 +               verbose_flg = 1;
50622 +       } else if (argc != 1) {
50623 +               return KDB_ARGCOUNT;
50624 +       }
50625 +
50626 +       if (strcmp(argv[0], "vmp") == 0) {
50627 +               struct task_struct *g, *tp;
50628 +               struct vm_area_struct *vp;
50629 +               pid_t pid;
50630 +
50631 +               if ((diag = kdbgetularg(argv[argc], (unsigned long *) &pid)))
50632 +                       return diag;
50633 +
50634 +               kdb_do_each_thread(g, tp) {
50635 +                       if (tp->pid == pid) {
50636 +                               if (tp->mm != NULL) {
50637 +                                       if (verbose_flg)
50638 +                                               kdb_printf
50639 +                                                   ("vm_area_struct       ");
50640 +                                       kdb_printf
50641 +                                           ("vm_start            vm_end              vm_flags\n");
50642 +                                       vp = tp->mm->mmap;
50643 +                                       while (vp != NULL) {
50644 +                                               kdbm_print_vmp(vp, verbose_flg);
50645 +                                               vp = vp->vm_next;
50646 +                                       }
50647 +                               }
50648 +                               return 0;
50649 +                       }
50650 +               } kdb_while_each_thread(g, tp);
50651 +
50652 +               kdb_printf("No process with pid == %d found\n", pid);
50653 +
50654 +       } else {
50655 +               struct vm_area_struct v;
50656 +
50657 +               nextarg = argc;
50658 +               if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset,
50659 +                                         NULL))
50660 +                   || (diag = kdb_getarea(v, addr)))
50661 +                       return (diag);
50662 +
50663 +               kdbm_print_vm(&v, addr, verbose_flg);
50664 +       }
50665 +
50666 +       return 0;
50667 +}
50668 +
50669 +static int
50670 +kdbm_print_pte(pte_t * pte)
50671 +{
50672 +       kdb_printf("0x%lx (", (unsigned long) pte_val(*pte));
50673 +
50674 +       if (pte_present(*pte)) {
50675 +               if (pte_exec(*pte))
50676 +                       kdb_printf("X");
50677 +               if (pte_write(*pte))
50678 +                       kdb_printf("W");
50679 +               if (pte_read(*pte))
50680 +                       kdb_printf("R");
50681 +               if (pte_young(*pte))
50682 +                       kdb_printf("A");
50683 +               if (pte_dirty(*pte))
50684 +                       kdb_printf("D");
50685 +
50686 +       } else {
50687 +               kdb_printf("OFFSET=0x%lx ", swp_offset(pte_to_swp_entry(*pte)));
50688 +               kdb_printf("TYPE=0x%ulx", swp_type(pte_to_swp_entry(*pte)));
50689 +       }
50690 +
50691 +       kdb_printf(")");
50692 +
50693 +       /* final newline is output by caller of kdbm_print_pte() */
50694 +
50695 +       return 0;
50696 +}
50697 +
50698 +/*
50699 + * kdbm_pte
50700 + *
50701 + *     This function implements the 'pte' command.  Print all pte_t structures
50702 + *     that map to the given virtual address range (<address> through <address>
50703 + *     plus <nbytes>) for the given process. The default value for nbytes is
50704 + *     one.
50705 + *
50706 + *     pte -m <mm> <address> [<nbytes>]    Print all pte_t structures for
50707 + *                                        virtual <address> in address space
50708 + *                                        of <mm> which is a pointer to a
50709 + *                                        mm_struct
50710 + *     pte -p <pid> <address> [<nbytes>]   Print all pte_t structures for
50711 + *                                        virtual <address> in address space
50712 + *                                        of <pid>
50713 + */
50714 +
50715 +static int
50716 +kdbm_pte(int argc, const char **argv)
50717 +{
50718 +       unsigned long addr;
50719 +       long offset = 0;
50720 +       int nextarg;
50721 +       unsigned long nbytes = 1;
50722 +       long npgs;
50723 +       int diag;
50724 +       int found;
50725 +       pid_t pid;
50726 +       struct task_struct *tp;
50727 +       struct mm_struct *mm, copy_of_mm;
50728 +       pgd_t *pgd;
50729 +       pud_t *pud;
50730 +       pmd_t *pmd;
50731 +       pte_t *pte;
50732 +
50733 +       if (argc < 3 || argc > 4) {
50734 +               return KDB_ARGCOUNT;
50735 +       }
50736 +
50737 +        if (strcmp(argv[1], "-p") == 0) {
50738 +               if ((diag = kdbgetularg(argv[2], (unsigned long *) &pid))) {
50739 +                       return diag;
50740 +               }
50741 +
50742 +               found = 0;
50743 +               for_each_process(tp) {
50744 +                       if (tp->pid == pid) {
50745 +                               if (tp->mm != NULL) {
50746 +                                       found = 1;
50747 +                                       break;
50748 +                               }
50749 +                               kdb_printf("task structure's mm field is NULL\n");
50750 +                               return 0;
50751 +                       }
50752 +               }
50753 +
50754 +               if (!found) {
50755 +                       kdb_printf("No process with pid == %d found\n", pid);
50756 +                       return 0;
50757 +               }
50758 +               mm = tp->mm;
50759 +       } else if (strcmp(argv[1], "-m") == 0) {
50760 +
50761 +
50762 +               nextarg = 2;
50763 +               if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset,
50764 +                                         NULL))
50765 +                   || (diag = kdb_getarea(copy_of_mm, addr)))
50766 +                       return (diag);
50767 +               mm = &copy_of_mm;
50768 +       } else {
50769 +               return KDB_ARGCOUNT;
50770 +       }
50771 +
50772 +       if ((diag = kdbgetularg(argv[3], &addr))) {
50773 +               return diag;
50774 +       }
50775 +
50776 +       if (argc == 4) {
50777 +               if ((diag = kdbgetularg(argv[4], &nbytes))) {
50778 +                       return diag;
50779 +               }
50780 +       }
50781 +
50782 +       kdb_printf("vaddr              pte\n");
50783 +
50784 +       npgs = ((((addr & ~PAGE_MASK) + nbytes) + ~PAGE_MASK) >> PAGE_SHIFT);
50785 +       while (npgs-- > 0) {
50786 +
50787 +               kdb_printf("0x%p ", (void *) (addr & PAGE_MASK));
50788 +
50789 +               pgd = pgd_offset(mm, addr);
50790 +               if (pgd_present(*pgd)) {
50791 +                       pud = pud_offset(pgd, addr);
50792 +                       if (pud_present(*pud)) {
50793 +                               pmd = pmd_offset(pud, addr);
50794 +                               if (pmd_present(*pmd)) {
50795 +                                       pte = pte_offset_map(pmd, addr);
50796 +                                       if (pte_present(*pte)) {
50797 +                                               kdbm_print_pte(pte);
50798 +                                       }
50799 +                               }
50800 +                       }
50801 +               }
50802 +
50803 +               kdb_printf("\n");
50804 +               addr += PAGE_SIZE;
50805 +       }
50806 +
50807 +       return 0;
50808 +}
50809 +
50810 +/*
50811 + * kdbm_rpte
50812 + *
50813 + *     This function implements the 'rpte' command.  Print all pte_t structures
50814 + *     that contain the given physical page range (<pfn> through <pfn>
50815 + *     plus <npages>) for the given process. The default value for npages is
50816 + *     one.
50817 + *
50818 + *     rpte -m <mm> <pfn> [<npages>]      Print all pte_t structures for
50819 + *                                        physical page <pfn> in address space
50820 + *                                        of <mm> which is a pointer to a
50821 + *                                        mm_struct
50822 + *     rpte -p <pid> <pfn> [<npages>]     Print all pte_t structures for
50823 + *                                        physical page <pfn> in address space
50824 + *                                        of <pid>
50825 + */
50826 +
50827 +static int
50828 +kdbm_rpte(int argc, const char **argv)
50829 +{
50830 +       unsigned long addr;
50831 +       unsigned long pfn;
50832 +       long offset = 0;
50833 +       int nextarg;
50834 +       unsigned long npages = 1;
50835 +       int diag;
50836 +       int found;
50837 +       pid_t pid;
50838 +       struct task_struct *tp;
50839 +       struct mm_struct *mm, copy_of_mm;
50840 +       pgd_t *pgd;
50841 +       pud_t *pud;
50842 +       pmd_t *pmd;
50843 +       pte_t *pte;
50844 +       unsigned long g, u, m, t;
50845 +
50846 +       if (argc < 3 || argc > 4) {
50847 +               return KDB_ARGCOUNT;
50848 +       }
50849 +
50850 +        if (strcmp(argv[1], "-p") == 0) {
50851 +               if ((diag = kdbgetularg(argv[2], (unsigned long *) &pid))) {
50852 +                       return diag;
50853 +               }
50854 +
50855 +               found = 0;
50856 +               for_each_process(tp) {
50857 +                       if (tp->pid == pid) {
50858 +                               if (tp->mm != NULL) {
50859 +                                       found = 1;
50860 +                                       break;
50861 +                               }
50862 +                               kdb_printf("task structure's mm field is NULL\n");
50863 +                               return 0;
50864 +                       }
50865 +               }
50866 +
50867 +               if (!found) {
50868 +                       kdb_printf("No process with pid == %d found\n", pid);
50869 +                       return 0;
50870 +               }
50871 +               mm = tp->mm;
50872 +       } else if (strcmp(argv[1], "-m") == 0) {
50873 +
50874 +
50875 +               nextarg = 2;
50876 +               if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset,
50877 +                                         NULL))
50878 +                   || (diag = kdb_getarea(copy_of_mm, addr)))
50879 +                       return (diag);
50880 +               mm = &copy_of_mm;
50881 +       } else {
50882 +               return KDB_ARGCOUNT;
50883 +       }
50884 +
50885 +       if ((diag = kdbgetularg(argv[3], &pfn))) {
50886 +               return diag;
50887 +       }
50888 +
50889 +       if (argc == 4) {
50890 +               if ((diag = kdbgetularg(argv[4], &npages))) {
50891 +                       return diag;
50892 +               }
50893 +       }
50894 +
50895 +       /* spaces after vaddr depends on sizeof(unsigned long) */
50896 +       kdb_printf("pfn              vaddr%*s pte\n",
50897 +                  (int)(2*sizeof(unsigned long) + 2 - 5), " ");
50898 +
50899 +       for (g = 0, pgd = pgd_offset(mm, 0UL); g < PTRS_PER_PGD; ++g, ++pgd) {
50900 +               if (pgd_none(*pgd) || pgd_bad(*pgd))
50901 +                       continue;
50902 +               for (u = 0, pud = pud_offset(pgd, 0UL); u < PTRS_PER_PUD; ++u, ++pud) {
50903 +                       if (pud_none(*pud) || pud_bad(*pud))
50904 +                               continue;
50905 +                       for (m = 0, pmd = pmd_offset(pud, 0UL); m < PTRS_PER_PMD; ++m, ++pmd) {
50906 +                               if (pmd_none(*pmd) || pmd_bad(*pmd))
50907 +                                       continue;
50908 +                               for (t = 0, pte = pte_offset_map(pmd, 0UL); t < PTRS_PER_PTE; ++t, ++pte) {
50909 +                                       if (pte_none(*pte))
50910 +                                               continue;
50911 +                                       if (pte_pfn(*pte) < pfn || pte_pfn(*pte) >= (pfn + npages))
50912 +                                               continue;
50913 +                                       addr = g << PGDIR_SHIFT;
50914 +#ifdef __ia64__
50915 +                                       /* IA64 plays tricks with the pgd mapping to save space.
50916 +                                        * This reverses pgd_index().
50917 +                                        */
50918 +                                       {
50919 +                                               unsigned long region = g >> (PAGE_SHIFT - 6);
50920 +                                               unsigned long l1index = g - (region << (PAGE_SHIFT - 6));
50921 +                                               addr = (region << 61) + (l1index << PGDIR_SHIFT);
50922 +                                       }
50923 +#endif
50924 +                                       addr += (m << PMD_SHIFT) + (t << PAGE_SHIFT);
50925 +                                       kdb_printf("0x%-14lx " kdb_bfd_vma_fmt0 " ",
50926 +                                                  pte_pfn(*pte), addr);
50927 +                                       kdbm_print_pte(pte);
50928 +                                       kdb_printf("\n");
50929 +                               }
50930 +                       }
50931 +               }
50932 +       }
50933 +
50934 +       return 0;
50935 +}
50936 +
50937 +static int
50938 +kdbm_print_dentry(unsigned long daddr)
50939 +{
50940 +       struct dentry d;
50941 +       int diag;
50942 +       char buf[256];
50943 +
50944 +       kdb_printf("Dentry at 0x%lx\n", daddr);
50945 +       if ((diag = kdb_getarea(d, (unsigned long)daddr)))
50946 +               return diag;
50947 +
50948 +       if ((d.d_name.len > sizeof(buf)) || (diag = kdb_getarea_size(buf, (unsigned long)(d.d_name.name), d.d_name.len)))
50949 +               kdb_printf(" d_name.len = %d d_name.name = 0x%p\n",
50950 +                                       d.d_name.len, d.d_name.name);
50951 +       else
50952 +               kdb_printf(" d_name.len = %d d_name.name = 0x%p <%.*s>\n",
50953 +                                       d.d_name.len, d.d_name.name,
50954 +                                       (int)(d.d_name.len), d.d_name.name);
50955 +
50956 +       kdb_printf(" d_count = %d d_flags = 0x%x d_inode = 0x%p\n",
50957 +                                       atomic_read(&d.d_count), d.d_flags, d.d_inode);
50958 +
50959 +       kdb_printf(" d_parent = 0x%p\n", d.d_parent);
50960 +
50961 +       kdb_printf(" d_hash.nxt = 0x%p d_hash.prv = 0x%p\n",
50962 +                                       d.d_hash.next, d.d_hash.pprev);
50963 +
50964 +       kdb_printf(" d_lru.nxt = 0x%p d_lru.prv = 0x%p\n",
50965 +                                       d.d_lru.next, d.d_lru.prev);
50966 +
50967 +       kdb_printf(" d_child.nxt = 0x%p d_child.prv = 0x%p\n",
50968 +                                       d.d_u.d_child.next, d.d_u.d_child.prev);
50969 +
50970 +       kdb_printf(" d_subdirs.nxt = 0x%p d_subdirs.prv = 0x%p\n",
50971 +                                       d.d_subdirs.next, d.d_subdirs.prev);
50972 +
50973 +       kdb_printf(" d_alias.nxt = 0x%p d_alias.prv = 0x%p\n",
50974 +                                       d.d_alias.next, d.d_alias.prev);
50975 +
50976 +       kdb_printf(" d_op = 0x%p d_sb = 0x%p d_fsdata = 0x%p\n",
50977 +                                       d.d_op, d.d_sb, d.d_fsdata);
50978 +
50979 +       kdb_printf(" d_iname = %s\n",
50980 +                                       d.d_iname);
50981 +
50982 +       if (d.d_inode) {
50983 +               struct inode i;
50984 +               kdb_printf("\nInode Entry at 0x%p\n", d.d_inode);
50985 +               if ((diag = kdb_getarea(i, (unsigned long)d.d_inode)))
50986 +                       return diag;
50987 +               kdb_printf(" i_mode = 0%o  i_nlink = %d  i_rdev = 0x%x\n",
50988 +                                               i.i_mode, i.i_nlink, i.i_rdev);
50989 +
50990 +               kdb_printf(" i_ino = %ld i_count = %d\n",
50991 +                                               i.i_ino, atomic_read(&i.i_count));
50992 +
50993 +               kdb_printf(" i_hash.nxt = 0x%p i_hash.prv = 0x%p\n",
50994 +                                               i.i_hash.next, i.i_hash.pprev);
50995 +
50996 +               kdb_printf(" i_list.nxt = 0x%p i_list.prv = 0x%p\n",
50997 +                                               i.i_list.next, i.i_list.prev);
50998 +
50999 +               kdb_printf(" i_dentry.nxt = 0x%p i_dentry.prv = 0x%p\n",
51000 +                                               i.i_dentry.next, i.i_dentry.prev);
51001 +
51002 +       }
51003 +       kdb_printf("\n");
51004 +       return 0;
51005 +}
51006 +
51007 +static int
51008 +kdbm_filp(int argc, const char **argv)
51009 +{
51010 +       struct file   f;
51011 +       int nextarg;
51012 +       unsigned long addr;
51013 +       long offset;
51014 +       int diag;
51015 +
51016 +       if (argc != 1)
51017 +               return KDB_ARGCOUNT;
51018 +
51019 +       nextarg = 1;
51020 +       if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) ||
51021 +           (diag = kdb_getarea(f, addr)))
51022 +               return diag;
51023 +
51024 +       kdb_printf("File Pointer at 0x%lx\n", addr);
51025 +
51026 +       kdb_printf(" fu_list.nxt = 0x%p fu_list.prv = 0x%p\n",
51027 +                                       f.f_u.fu_list.next, f.f_u.fu_list.prev);
51028 +
51029 +       kdb_printf(" f_dentry = 0x%p f_vfsmnt = 0x%p f_op = 0x%p\n",
51030 +                                       f.f_dentry, f.f_vfsmnt, f.f_op);
51031 +
51032 +       kdb_printf(" f_count = %d f_flags = 0x%x f_mode = 0x%x\n",
51033 +                                       atomic_read(&f.f_count), f.f_flags, f.f_mode);
51034 +
51035 +       kdb_printf(" f_pos = %Ld\n", f.f_pos);
51036 +#ifdef CONFIG_SECURITY
51037 +       kdb_printf(" security = 0x%p\n", f.f_security);
51038 +#endif
51039 +
51040 +       kdb_printf(" private_data = 0x%p f_mapping = 0x%p\n\n",
51041 +                                       f.private_data, f.f_mapping);
51042 +
51043 +       return kdbm_print_dentry((unsigned long)f.f_dentry);
51044 +}
51045 +
51046 +static int
51047 +kdbm_fl(int argc, const char **argv)
51048 +{
51049 +       struct file_lock fl;
51050 +       int nextarg;
51051 +       unsigned long addr;
51052 +       long offset;
51053 +       int diag;
51054 +
51055 +
51056 +       if (argc != 1)
51057 +               return KDB_ARGCOUNT;
51058 +
51059 +       nextarg = 1;
51060 +       if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) ||
51061 +               (diag = kdb_getarea(fl, addr)))
51062 +                       return diag;
51063 +
51064 +       kdb_printf("File_lock at 0x%lx\n", addr);
51065 +
51066 +       kdb_printf(" fl_next = 0x%p fl_link.nxt = 0x%p fl_link.prv = 0x%p\n",
51067 +                       fl.fl_next, fl.fl_link.next, fl.fl_link.prev);
51068 +       kdb_printf(" fl_block.nxt = 0x%p fl_block.prv = 0x%p\n",
51069 +                       fl.fl_block.next, fl.fl_block.prev);
51070 +       kdb_printf(" fl_owner = 0x%p fl_pid = %d fl_wait = 0x%p\n",
51071 +                       fl.fl_owner, fl.fl_pid, &fl.fl_wait);
51072 +       kdb_printf(" fl_file = 0x%p fl_flags = 0x%x\n",
51073 +                       fl.fl_file, fl.fl_flags);
51074 +       kdb_printf(" fl_type = %d fl_start = 0x%llx fl_end = 0x%llx\n",
51075 +                       fl.fl_type, fl.fl_start, fl.fl_end);
51076 +
51077 +       kdb_printf(" file_lock_operations");
51078 +       if (fl.fl_ops)
51079 +               kdb_printf("\n   fl_insert = 0x%p fl_remove = 0x%p fl_copy_lock = 0x%p fl_release_private = 0x%p\n",
51080 +                       fl.fl_ops->fl_insert, fl.fl_ops->fl_remove,
51081 +                       fl.fl_ops->fl_copy_lock, fl.fl_ops->fl_release_private);
51082 +       else
51083 +               kdb_printf("   empty\n");
51084 +
51085 +       kdb_printf(" lock_manager_operations");
51086 +       if (fl.fl_lmops)
51087 +               kdb_printf("\n   fl_compare_owner = 0x%p fl_notify = 0x%p\n",
51088 +                       fl.fl_lmops->fl_compare_owner, fl.fl_lmops->fl_notify);
51089 +       else
51090 +               kdb_printf("   empty\n");
51091 +
51092 +       kdb_printf(" fl_fasync = 0x%p fl_break 0x%lx\n",
51093 +                       fl.fl_fasync, fl.fl_break_time);
51094 +
51095 +       return 0;
51096 +}
51097 +
51098 +
51099 +static int
51100 +kdbm_dentry(int argc, const char **argv)
51101 +{
51102 +       int nextarg;
51103 +       unsigned long addr;
51104 +       long offset;
51105 +       int diag;
51106 +
51107 +       if (argc != 1)
51108 +               return KDB_ARGCOUNT;
51109 +
51110 +       nextarg = 1;
51111 +       if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)))
51112 +               return diag;
51113 +
51114 +       return kdbm_print_dentry(addr);
51115 +}
51116 +
51117 +static int
51118 +kdbm_kobject(int argc, const char **argv)
51119 +{
51120 +       struct kobject k;
51121 +       int nextarg;
51122 +       unsigned long addr;
51123 +       long offset;
51124 +       int diag;
51125 +
51126 +       if (argc != 1)
51127 +               return KDB_ARGCOUNT;
51128 +
51129 +       nextarg = 1;
51130 +       if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) ||
51131 +           (diag = kdb_getarea(k, addr)))
51132 +               return diag;
51133 +
51134 +
51135 +       kdb_printf("kobject at 0x%lx\n", addr);
51136 +
51137 +       if (k.k_name) {
51138 +               char c;
51139 +               kdb_printf(" k_name 0x%p", k.k_name);
51140 +               if (kdb_getarea(c, (unsigned long)k.k_name) == 0)
51141 +                       kdb_printf(" '%s'", k.k_name);
51142 +               kdb_printf("\n");
51143 +       }
51144 +
51145 +       if (k.k_name != ((struct kobject *)addr)->name)
51146 +               kdb_printf(" name '%." __stringify(KOBJ_NAME_LEN) "s'\n", k.k_name);
51147 +
51148 +       kdb_printf(" kref.refcount %d'\n", atomic_read(&k.kref.refcount));
51149 +
51150 +       kdb_printf(" entry.next = 0x%p entry.prev = 0x%p\n",
51151 +                                       k.entry.next, k.entry.prev);
51152 +
51153 +       kdb_printf(" parent = 0x%p kset = 0x%p ktype = 0x%p dentry = 0x%p\n",
51154 +                                       k.parent, k.kset, k.ktype, k.dentry);
51155 +
51156 +       return 0;
51157 +}
51158 +
51159 +static int
51160 +kdbm_sh(int argc, const char **argv)
51161 +{
51162 +       int diag;
51163 +       int nextarg;
51164 +       unsigned long addr;
51165 +       long offset = 0L;
51166 +       struct Scsi_Host sh;
51167 +
51168 +       if (argc != 1)
51169 +               return KDB_ARGCOUNT;
51170 +
51171 +       nextarg = 1;
51172 +       if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) ||
51173 +           (diag = kdb_getarea(sh, addr)))
51174 +               return diag;
51175 +
51176 +       kdb_printf("Scsi_Host at 0x%lx\n", addr);
51177 +       kdb_printf("host_queue = 0x%p\n", sh.__devices.next);
51178 +       kdb_printf("ehandler = 0x%p eh_action = 0x%p\n",
51179 +                  sh.ehandler, sh.eh_action);
51180 +       kdb_printf("host_wait = 0x%p hostt = 0x%p\n",
51181 +                  &sh.host_wait, sh.hostt);
51182 +       kdb_printf("host_failed = %d  host_no = %d resetting = %d\n",
51183 +                  sh.host_failed, sh.host_no, sh.resetting);
51184 +       kdb_printf("max id/lun/channel = [%d/%d/%d]  this_id = %d\n",
51185 +                  sh.max_id, sh.max_lun, sh.max_channel, sh.this_id);
51186 +       kdb_printf("can_queue = %d cmd_per_lun = %d  sg_tablesize = %d u_isa_dma = %d\n",
51187 +                  sh.can_queue, sh.cmd_per_lun, sh.sg_tablesize, sh.unchecked_isa_dma);
51188 +       kdb_printf("host_blocked = %d  reverse_ordering = %d \n",
51189 +                  sh.host_blocked, sh.reverse_ordering);
51190 +
51191 +       return 0;
51192 +}
51193 +
51194 +static int
51195 +kdbm_sd(int argc, const char **argv)
51196 +{
51197 +       int diag;
51198 +       int nextarg;
51199 +       unsigned long addr;
51200 +       long offset = 0L;
51201 +       struct scsi_device *sd = NULL;
51202 +
51203 +       if (argc != 1)
51204 +               return KDB_ARGCOUNT;
51205 +
51206 +       nextarg = 1;
51207 +       if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)))
51208 +               goto out;
51209 +       if (!(sd = kmalloc(sizeof(*sd), GFP_ATOMIC))) {
51210 +               kdb_printf("kdbm_sd: cannot kmalloc sd\n");
51211 +               goto out;
51212 +       }
51213 +       if ((diag = kdb_getarea(*sd, addr)))
51214 +               goto out;
51215 +
51216 +       kdb_printf("scsi_device at 0x%lx\n", addr);
51217 +       kdb_printf("next = 0x%p   prev = 0x%p  host = 0x%p\n",
51218 +                  sd->siblings.next, sd->siblings.prev, sd->host);
51219 +       kdb_printf("device_busy = %d   current_cmnd 0x%p\n",
51220 +                  sd->device_busy, sd->current_cmnd);
51221 +       kdb_printf("id/lun/chan = [%d/%d/%d]  single_lun = %d  device_blocked = %d\n",
51222 +                  sd->id, sd->lun, sd->channel, sd->single_lun, sd->device_blocked);
51223 +       kdb_printf("queue_depth = %d current_tag = %d  scsi_level = %d\n",
51224 +                  sd->queue_depth, sd->current_tag, sd->scsi_level);
51225 +       kdb_printf("%8.8s %16.16s %4.4s\n", sd->vendor, sd->model, sd->rev);
51226 +out:
51227 +       if (sd)
51228 +               kfree(sd);
51229 +       return diag;
51230 +}
51231 +
51232 +static int
51233 +kdbm_sc(int argc, const char **argv)
51234 +{
51235 +       int diag;
51236 +       int nextarg;
51237 +       unsigned long addr;
51238 +       long offset = 0L;
51239 +       struct scsi_cmnd *sc = NULL;
51240 +
51241 +       if (argc != 1)
51242 +               return KDB_ARGCOUNT;
51243 +
51244 +       nextarg = 1;
51245 +       if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)))
51246 +               goto out;
51247 +       if (!(sc = kmalloc(sizeof(*sc), GFP_ATOMIC))) {
51248 +               kdb_printf("kdbm_sc: cannot kmalloc sc\n");
51249 +               goto out;
51250 +       }
51251 +       if ((diag = kdb_getarea(*sc, addr)))
51252 +               goto out;
51253 +
51254 +       kdb_printf("scsi_cmnd at 0x%lx\n", addr);
51255 +       kdb_printf("device = 0x%p  next = 0x%p  done = 0x%p\n",
51256 +                  sc->device, sc->list.next, sc->done);
51257 +       kdb_printf("serial_number = %ld  retries = %d\n",
51258 +                  sc->serial_number, sc->retries);
51259 +       kdb_printf("cmd_len = %d\n", sc->cmd_len);
51260 +       kdb_printf("cmnd = [%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x]\n",
51261 +                  sc->cmnd[0], sc->cmnd[1], sc->cmnd[2], sc->cmnd[3], sc->cmnd[4],
51262 +                  sc->cmnd[5], sc->cmnd[6], sc->cmnd[7], sc->cmnd[8], sc->cmnd[9],
51263 +                  sc->cmnd[10], sc->cmnd[11]);
51264 +       kdb_printf("request_buffer = 0x%p  request_bufflen = %d\n",
51265 +                  sc->request_buffer, sc->request_bufflen);
51266 +       kdb_printf("use_sg = %d  sglist_len = %d\n",
51267 +                  sc->use_sg, sc->sglist_len);
51268 +       kdb_printf("underflow = %d transfersize = %d\n",
51269 +                  sc->underflow, sc->transfersize);
51270 +       kdb_printf("tag = %d pid = %ld\n",
51271 +                  sc->tag, sc->pid);
51272 +
51273 +out:
51274 +       if (sc)
51275 +               kfree(sc);
51276 +       return diag;
51277 +}
51278 +
51279 +static int __init kdbm_vm_init(void)
51280 +{
51281 +       kdb_register("vm", kdbm_vm, "[-v] <vaddr>", "Display vm_area_struct", 0);
51282 +       kdb_register("vmp", kdbm_vm, "[-v] <pid>", "Display all vm_area_struct for <pid>", 0);
51283 +       kdb_register("pte", kdbm_pte, "( -m <mm> | -p <pid> ) <vaddr> [<nbytes>]", "Display pte_t for mm_struct or pid", 0);
51284 +       kdb_register("rpte", kdbm_rpte, "( -m <mm> | -p <pid> ) <pfn> [<npages>]", "Find pte_t containing pfn for mm_struct or pid", 0);
51285 +       kdb_register("dentry", kdbm_dentry, "<dentry>", "Display interesting dentry stuff", 0);
51286 +       kdb_register("kobject", kdbm_kobject, "<kobject>", "Display interesting kobject stuff", 0);
51287 +       kdb_register("filp", kdbm_filp, "<filp>", "Display interesting filp stuff", 0);
51288 +       kdb_register("fl", kdbm_fl, "<fl>", "Display interesting file_lock stuff", 0);
51289 +       kdb_register("sh", kdbm_sh, "<vaddr>", "Show scsi_host", 0);
51290 +       kdb_register("sd", kdbm_sd, "<vaddr>", "Show scsi_device", 0);
51291 +       kdb_register("sc", kdbm_sc, "<vaddr>", "Show scsi_cmnd", 0);
51292 +
51293 +       return 0;
51294 +}
51295 +
51296 +static void __exit kdbm_vm_exit(void)
51297 +{
51298 +       kdb_unregister("vm");
51299 +       kdb_unregister("vmp");
51300 +       kdb_unregister("pte");
51301 +       kdb_unregister("rpte");
51302 +       kdb_unregister("dentry");
51303 +       kdb_unregister("kobject");
51304 +       kdb_unregister("filp");
51305 +       kdb_unregister("fl");
51306 +       kdb_unregister("sh");
51307 +       kdb_unregister("sd");
51308 +       kdb_unregister("sc");
51309 +}
51310 +
51311 +module_init(kdbm_vm_init)
51312 +module_exit(kdbm_vm_exit)
51313 diff -Nurp linux-2.6.22-590/kdb/modules/kdbm_x86.c linux-2.6.22-600/kdb/modules/kdbm_x86.c
51314 --- linux-2.6.22-590/kdb/modules/kdbm_x86.c     1970-01-01 01:00:00.000000000 +0100
51315 +++ linux-2.6.22-600/kdb/modules/kdbm_x86.c     2008-04-09 18:14:28.000000000 +0200
51316 @@ -0,0 +1,1096 @@
51317 +/*
51318 + * This file is subject to the terms and conditions of the GNU General Public
51319 + * License.  See the file "COPYING" in the main directory of this archive
51320 + * for more details.
51321 + *
51322 + * Author: Vamsi Krishna S. <vamsi_krishna@in.ibm.com>
51323 + * (C) 2003 IBM Corporation.
51324 + * 2006-10-10 Keith Owens
51325 + *   Reworked to include x86_64 support
51326 + * Copyright (c) 2006 Silicon Graphics, Inc.  All Rights Reserved.
51327 + */
51328 +
51329 +#include <linux/interrupt.h>
51330 +#include <linux/types.h>
51331 +#include <linux/kdb.h>
51332 +#include <linux/kdbprivate.h>
51333 +#include <linux/module.h>
51334 +#include <linux/init.h>
51335 +#include <linux/mm.h>
51336 +
51337 +#include <asm/processor.h>
51338 +#include <asm/uaccess.h>
51339 +#include <asm/desc.h>
51340 +#include <asm/debugreg.h>
51341 +#if 0
51342 +#include <asm/pgtable.h>
51343 +#endif
51344 +
51345 +MODULE_AUTHOR("Vamsi Krishna S./IBM");
51346 +MODULE_DESCRIPTION("x86 specific information (gdt/idt/ldt/page tables)");
51347 +MODULE_LICENSE("GPL");
51348 +
51349 +/* Isolate as many of the i386/x86_64 differences as possible in one spot */
51350 +
51351 +#ifdef CONFIG_X86_64
51352 +
51353 +#define KDB_X86_64 1
51354 +#define        MOVLQ "movq"
51355 +
51356 +typedef struct desc_struct kdb_desc_t;
51357 +typedef struct gate_struct kdb_gate_desc_t;
51358 +
51359 +#define KDB_SYS_DESC_OFFSET(d) ((unsigned long)d->offset_high << 32 | d->offset_middle << 16 | d->offset_low)
51360 +#define KDB_SYS_DESC_CALLG_COUNT(d) 0
51361 +
51362 +#else  /* !CONFIG_X86_64 */
51363 +
51364 +#define KDB_X86_64 0
51365 +#define desc_ptr Xgt_desc_struct
51366 +#define        MOVLQ "movl"
51367 +
51368 +/* i386 has no detailed mapping for the 8 byte segment descriptor, copy the
51369 + * x86_64 one and merge the l and avl bits.
51370 + */
51371 +struct kdb_desc {
51372 +       u16 limit0;
51373 +       u16 base0;
51374 +       unsigned base1 : 8, type : 4, s : 1, dpl : 2, p : 1;
51375 +       unsigned limit : 4, avl : 2, d : 1, g : 1, base2 : 8;
51376 +} __attribute__((packed));
51377 +typedef struct kdb_desc kdb_desc_t;
51378 +
51379 +/* i386 has no detailed mapping for the 8 byte gate descriptor, base it on the
51380 + * x86_64 one.
51381 + */
51382 +struct kdb_gate_desc {
51383 +       u16 offset_low;
51384 +       u16 segment;
51385 +       unsigned res : 8, type : 4, s : 1, dpl : 2, p : 1;
51386 +       u16 offset_middle;
51387 +} __attribute__((packed));
51388 +typedef struct kdb_gate_desc kdb_gate_desc_t;
51389 +
51390 +#define KDB_SYS_DESC_OFFSET(d) ((unsigned long)(d->offset_middle << 16 | d->offset_low))
51391 +#define KDB_SYS_DESC_CALLG_COUNT(d) ((unsigned int)(d->res & 0x0F))
51392 +
51393 +#endif /* CONFIG_X86_64 */
51394 +
51395 +#define KDB_SEL_MAX                    0x2000
51396 +#define KDB_IDT_MAX                    0x100
51397 +#define KDB_SYS_DESC_TYPE_TSS16                0x01
51398 +#define KDB_SYS_DESC_TYPE_LDT          0x02
51399 +#define KDB_SYS_DESC_TYPE_TSSB16       0x03
51400 +#define KDB_SYS_DESC_TYPE_CALLG16      0x04
51401 +#define KDB_SYS_DESC_TYPE_TASKG                0x05
51402 +#define KDB_SYS_DESC_TYPE_INTG16       0x06
51403 +#define KDB_SYS_DESC_TYPE_TRAP16       0x07
51404 +
51405 +#define KDB_SYS_DESC_TYPE_TSS          0x09
51406 +#define KDB_SYS_DESC_TYPE_TSSB         0x0b
51407 +#define KDB_SYS_DESC_TYPE_CALLG                0x0c
51408 +#define KDB_SYS_DESC_TYPE_INTG         0x0e
51409 +#define KDB_SYS_DESC_TYPE_TRAPG                0x0f
51410 +
51411 +#define KDB_SEG_DESC_TYPE_CODE         0x08
51412 +#define KDB_SEG_DESC_TYPE_CODE_R       0x02
51413 +#define KDB_SEG_DESC_TYPE_DATA_W       0x02
51414 +#define KDB_SEG_DESC_TYPE_CODE_C       0x02    /* conforming */
51415 +#define KDB_SEG_DESC_TYPE_DATA_D       0x02    /* expand-down */
51416 +#define KDB_SEG_DESC_TYPE_A            0x01    /* accessed */
51417 +
51418 +#define _LIMIT(d) ((unsigned long)((d)->limit << 16 | (d)->limit0))
51419 +#define KDB_SEG_DESC_LIMIT(d) ((d)->g ? ((_LIMIT(d)+1) << 12) -1 : _LIMIT(d))
51420 +
51421 +static unsigned long kdb_seg_desc_base(kdb_desc_t *d)
51422 +{
51423 +       unsigned long base = d->base2 << 24 | d->base1 << 16 | d->base0;
51424 +#ifdef CONFIG_X86_64
51425 +       switch (d->type) {
51426 +       case KDB_SYS_DESC_TYPE_TSS:
51427 +       case KDB_SYS_DESC_TYPE_TSSB:
51428 +       case KDB_SYS_DESC_TYPE_LDT:
51429 +               base += (unsigned long)(((struct ldttss_desc *)d)->base3) << 32;
51430 +               break;
51431 +       }
51432 +#endif
51433 +       return base;
51434 +}
51435 +
51436 +/* helper functions to display system registers in verbose mode */
51437 +static void display_gdtr(void)
51438 +{
51439 +       struct desc_ptr gdtr;
51440 +
51441 +       __asm__ __volatile__ ("sgdt %0\n\t" : "=m"(gdtr));
51442 +       kdb_printf("gdtr.address = " kdb_machreg_fmt0 ", gdtr.size = 0x%x\n",
51443 +                  gdtr.address, gdtr.size);
51444 +
51445 +       return;
51446 +}
51447 +
51448 +static void display_ldtr(void)
51449 +{
51450 +       struct desc_ptr gdtr;
51451 +       unsigned long ldtr;
51452 +
51453 +       __asm__ __volatile__ ("sgdt %0\n\t" : "=m"(gdtr));
51454 +       __asm__ __volatile__ ("sldt %0\n\t" : "=m"(ldtr));
51455 +       ldtr &= 0xfff8;         /* extract the index */
51456 +
51457 +       kdb_printf("ldtr = " kdb_machreg_fmt0 " ", ldtr);
51458 +
51459 +       if (ldtr < gdtr.size) {
51460 +               kdb_desc_t *ldt_desc =
51461 +                       (kdb_desc_t *)(gdtr.address + ldtr);
51462 +               kdb_printf("base=" kdb_machreg_fmt0
51463 +                          ", limit=" kdb_machreg_fmt "\n",
51464 +                               kdb_seg_desc_base(ldt_desc),
51465 +                               KDB_SEG_DESC_LIMIT(ldt_desc));
51466 +       } else {
51467 +               kdb_printf("invalid\n");
51468 +       }
51469 +
51470 +       return;
51471 +}
51472 +
51473 +static void display_idtr(void)
51474 +{
51475 +       struct desc_ptr idtr;
51476 +       __asm__ __volatile__ ("sidt %0\n\t" : "=m"(idtr));
51477 +       kdb_printf("idtr.address = " kdb_machreg_fmt0 ", idtr.size = 0x%x\n",
51478 +                  idtr.address, idtr.size);
51479 +       return;
51480 +}
51481 +
51482 +static const char *cr0_flags[] = {
51483 +       "pe", "mp", "em", "ts", "et", "ne", NULL, NULL,
51484 +       NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
51485 +       "wp", NULL, "am", NULL, NULL, NULL, NULL, NULL,
51486 +       NULL, NULL, NULL, NULL, NULL, "nw", "cd", "pg"};
51487 +
51488 +static void display_cr0(void)
51489 +{
51490 +       kdb_machreg_t cr0;
51491 +       int i;
51492 +       __asm__ (MOVLQ " %%cr0,%0\n\t":"=r"(cr0));
51493 +       kdb_printf("cr0 = " kdb_machreg_fmt0, cr0);
51494 +       for (i = 0; i < ARRAY_SIZE(cr0_flags); i++) {
51495 +               if (test_bit(i, &cr0) && cr0_flags[i])
51496 +                       kdb_printf(" %s", cr0_flags[i]);
51497 +       }
51498 +       kdb_printf("\n");
51499 +       return;
51500 +}
51501 +
51502 +static void display_cr3(void)
51503 +{
51504 +       kdb_machreg_t cr3;
51505 +       __asm__ (MOVLQ " %%cr3,%0\n\t":"=r"(cr3));
51506 +       kdb_printf("cr3 = " kdb_machreg_fmt0 " ", cr3);
51507 +       if (cr3 & 0x08)
51508 +               kdb_printf("pwt ");
51509 +       if (cr3 & 0x10)
51510 +               kdb_printf("pcd ");
51511 +       kdb_printf("%s=" kdb_machreg_fmt0 "\n",
51512 +                  KDB_X86_64 ? "pml4" : "pgdir", cr3 & PAGE_MASK);
51513 +       return;
51514 +}
51515 +
51516 +static const char *cr4_flags[] = {
51517 +       "vme", "pvi", "tsd", "de",
51518 +       "pse", "pae", "mce", "pge",
51519 +       "pce", "osfxsr" "osxmmexcpt"};
51520 +
51521 +static void display_cr4(void)
51522 +{
51523 +       kdb_machreg_t cr4;
51524 +       int i;
51525 +       __asm__ (MOVLQ " %%cr4,%0\n\t":"=r"(cr4));
51526 +       kdb_printf("cr4 = " kdb_machreg_fmt0, cr4);
51527 +       for (i = 0; i < ARRAY_SIZE(cr4_flags); i++) {
51528 +               if (test_bit(i, &cr4))
51529 +                       kdb_printf(" %s", cr4_flags[i]);
51530 +       }
51531 +       kdb_printf("\n");
51532 +       return;
51533 +}
51534 +
51535 +static void display_cr8(void)
51536 +{
51537 +#ifdef CONFIG_X86_64
51538 +       kdb_machreg_t cr8;
51539 +       __asm__ (MOVLQ " %%cr8,%0\n\t":"=r"(cr8));
51540 +       kdb_printf("cr8 = " kdb_machreg_fmt0 "\n", cr8);
51541 +       return;
51542 +#endif /* CONFIG_X86_64 */
51543 +}
51544 +
51545 +static char *dr_type_name[] = { "exec", "write", "io", "rw" };
51546 +
51547 +static void display_dr_status(int nr, int enabled, int local, int len, int type)
51548 +{
51549 +       if (!enabled) {
51550 +               kdb_printf("\tdebug register %d: not enabled\n", nr);
51551 +               return;
51552 +       }
51553 +
51554 +       kdb_printf("    debug register %d: %s, len = %d, type = %s\n",
51555 +                       nr,
51556 +                       local? " local":"global",
51557 +                       len,
51558 +                       dr_type_name[type]);
51559 +}
51560 +
51561 +static void display_dr(void)
51562 +{
51563 +       kdb_machreg_t dr0, dr1, dr2, dr3, dr6, dr7;
51564 +       int dbnr, set;
51565 +
51566 +       __asm__ (MOVLQ " %%db0,%0\n\t":"=r"(dr0));
51567 +       __asm__ (MOVLQ " %%db1,%0\n\t":"=r"(dr1));
51568 +       __asm__ (MOVLQ " %%db2,%0\n\t":"=r"(dr2));
51569 +       __asm__ (MOVLQ " %%db3,%0\n\t":"=r"(dr3));
51570 +       __asm__ (MOVLQ " %%db6,%0\n\t":"=r"(dr6));
51571 +       __asm__ (MOVLQ " %%db7,%0\n\t":"=r"(dr7));
51572 +
51573 +       kdb_printf("dr0 = " kdb_machreg_fmt0 " dr1 = " kdb_machreg_fmt0
51574 +                  " dr2 = " kdb_machreg_fmt0 " dr3 = " kdb_machreg_fmt0 "\n",
51575 +                  dr0, dr1, dr2, dr3);
51576 +       kdb_printf("dr6 = " kdb_machreg_fmt0 " ", dr6);
51577 +       dbnr = dr6 & DR6_DR_MASK;
51578 +       if (dbnr) {
51579 +               int nr;
51580 +               switch(dbnr) {
51581 +               case 1:
51582 +                       nr = 0; break;
51583 +               case 2:
51584 +                       nr = 1; break;
51585 +               case 4:
51586 +                       nr = 2; break;
51587 +               default:
51588 +                       nr = 3; break;
51589 +               }
51590 +               kdb_printf("debug register hit = %d", nr);
51591 +       } else if (dr6 & DR_STEP) {
51592 +               kdb_printf("single step");
51593 +       } else if (dr6 & DR_SWITCH) {
51594 +               kdb_printf("task switch");
51595 +       }
51596 +       kdb_printf("\n");
51597 +
51598 +       kdb_printf("dr7 = " kdb_machreg_fmt0 "\n", dr7);
51599 +       set = DR7_L0(dr7) || DR7_G0(dr7);
51600 +       display_dr_status(0, set, DR7_L0(dr7), DR7_LEN0(dr7), DR7_RW0(dr7));
51601 +       set = DR7_L1(dr7) || DR7_G1(dr7);
51602 +       display_dr_status(1, set, DR7_L1(dr7), DR7_LEN1(dr7), DR7_RW1(dr7));
51603 +       set = DR7_L2(dr7) || DR7_G2(dr7);
51604 +       display_dr_status(2, set, DR7_L2(dr7), DR7_LEN2(dr7), DR7_RW2(dr7));
51605 +       set = DR7_L3(dr7) || DR7_G3(dr7);
51606 +       display_dr_status(3, set, DR7_L3(dr7), DR7_LEN3(dr7), DR7_RW3(dr7));
51607 +}
51608 +
51609 +static char *set_eflags[] = {
51610 +       "carry", NULL, "parity",  NULL, "adjust",  NULL, "zero", "sign",
51611 +       "trace", "intr-on", "dir", "overflow",  NULL, NULL, "nestedtask", NULL,
51612 +       "resume", "vm", "align", "vif", "vip", "id"};
51613 +
51614 +static void display_eflags(unsigned long ef)
51615 +{
51616 +       int i, iopl;
51617 +       kdb_printf("eflags = " kdb_machreg_fmt0 " ", ef);
51618 +       for (i = 0; i < ARRAY_SIZE(set_eflags); i++) {
51619 +               if (test_bit(i, &ef) && set_eflags[i])
51620 +                       kdb_printf("%s ", set_eflags[i]);
51621 +       }
51622 +
51623 +       iopl = (ef & 0x00003000) >> 12;
51624 +       kdb_printf("iopl=%d\n", iopl);
51625 +       return;
51626 +}
51627 +
51628 +static void display_tss(struct tss_struct *t)
51629 +{
51630 +#ifdef CONFIG_X86_64
51631 +       int i;
51632 +       kdb_printf("    rsp0 = 0x%016Lx,  rsp1 = 0x%016Lx\n",
51633 +                  t->rsp0, t->rsp1);
51634 +       kdb_printf("    rsp2 = 0x%016Lx\n", t->rsp2);
51635 +       for (i = 0; i < ARRAY_SIZE(t->ist); ++i)
51636 +               kdb_printf("    ist[%d] = 0x%016Lx\n",
51637 +                         i, t->ist[i]);
51638 +       kdb_printf("   iomap = 0x%04x\n", t->io_bitmap_base);
51639 +#else  /* !CONFIG_X86_64 */
51640 +       kdb_printf("    cs = %04x,  eip = " kdb_machreg_fmt0 "\n",
51641 +                  t->x86_tss.es, t->x86_tss.eip);
51642 +       kdb_printf("    ss = %04x,  esp = " kdb_machreg_fmt0 "\n",
51643 +                  t->x86_tss.ss, t->x86_tss.esp);
51644 +       kdb_printf("   ss0 = %04x, esp0 = " kdb_machreg_fmt0 "\n",
51645 +                  t->x86_tss.ss0, t->x86_tss.esp0);
51646 +       kdb_printf("   ss1 = %04x, esp1 = " kdb_machreg_fmt0 "\n",
51647 +                  t->x86_tss.ss1, t->x86_tss.esp1);
51648 +       kdb_printf("   ss2 = %04x, esp2 = " kdb_machreg_fmt0 "\n",
51649 +                  t->x86_tss.ss2, t->x86_tss.esp2);
51650 +       kdb_printf("   ldt = %04x, cr3 = " kdb_machreg_fmt0 "\n",
51651 +                  t->x86_tss.ldt, t->x86_tss.__cr3);
51652 +       kdb_printf("    ds = %04x, es = %04x fs = %04x gs = %04x\n",
51653 +                       t->x86_tss.ds, t->x86_tss.es, t->x86_tss.fs, t->x86_tss.gs);
51654 +       kdb_printf("   eax = " kdb_machreg_fmt0 ", ebx = " kdb_machreg_fmt0
51655 +                  " ecx = " kdb_machreg_fmt0 " edx = " kdb_machreg_fmt0 "\n",
51656 +                  t->x86_tss.eax, t->x86_tss.ebx, t->x86_tss.ecx, t->x86_tss.edx);
51657 +       kdb_printf("   esi = " kdb_machreg_fmt0 ", edi = " kdb_machreg_fmt0
51658 +                  " ebp = " kdb_machreg_fmt0 "\n",
51659 +                  t->x86_tss.esi, t->x86_tss.edi, t->x86_tss.ebp);
51660 +       kdb_printf("   trace = %d, iomap = 0x%04x\n", t->x86_tss.trace, t->x86_tss.io_bitmap_base);
51661 +#endif /* CONFIG_X86_64 */
51662 +}
51663 +
51664 +static char *gate_desc_types[] = {
51665 +#ifdef CONFIG_X86_64
51666 +       "reserved-0", "reserved-1", "ldt", "reserved-3",
51667 +       "reserved-4", "reserved-5", "reserved-6", "reserved-7",
51668 +       "reserved-8", "tss-avlb", "reserved-10", "tss-busy",
51669 +       "callgate", "reserved-13", "intgate", "trapgate",
51670 +#else  /* CONFIG_X86_64 */
51671 +       "reserved-0", "tss16-avlb", "ldt", "tss16-busy",
51672 +       "callgate16", "taskgate", "intgate16", "trapgate16",
51673 +       "reserved-8", "tss-avlb", "reserved-10", "tss-busy",
51674 +       "callgate", "reserved-13", "intgate", "trapgate",
51675 +#endif /* CONFIG_X86_64 */
51676 +};
51677 +
51678 +static void
51679 +display_gate_desc(kdb_gate_desc_t *d)
51680 +{
51681 +       kdb_printf("%-11s ", gate_desc_types[d->type]);
51682 +
51683 +       switch(d->type) {
51684 +       case KDB_SYS_DESC_TYPE_LDT:
51685 +               kdb_printf("base=");
51686 +               kdb_symbol_print(kdb_seg_desc_base((kdb_desc_t *)d), NULL,
51687 +                                KDB_SP_DEFAULT);
51688 +               kdb_printf(" limit=" kdb_machreg_fmt " dpl=%d\n",
51689 +                          KDB_SEG_DESC_LIMIT((kdb_desc_t *)d), d->dpl);
51690 +               break;
51691 +       case KDB_SYS_DESC_TYPE_TSS:
51692 +       case KDB_SYS_DESC_TYPE_TSS16:
51693 +       case KDB_SYS_DESC_TYPE_TSSB:
51694 +       case KDB_SYS_DESC_TYPE_TSSB16:
51695 +       {
51696 +               struct tss_struct *tss =
51697 +                       (struct tss_struct *)
51698 +                       kdb_seg_desc_base((kdb_desc_t *)d);
51699 +               kdb_printf("base=");
51700 +               kdb_symbol_print((unsigned long)tss, NULL, KDB_SP_DEFAULT);
51701 +               kdb_printf(" limit=" kdb_machreg_fmt " dpl=%d\n",
51702 +                          KDB_SEG_DESC_LIMIT((kdb_desc_t *)d), d->dpl);
51703 +               display_tss(tss);
51704 +               break;
51705 +       }
51706 +       case KDB_SYS_DESC_TYPE_CALLG16:
51707 +               kdb_printf("segment=0x%4.4x off=", d->segment);
51708 +               kdb_symbol_print(KDB_SYS_DESC_OFFSET(d), NULL, KDB_SP_DEFAULT);
51709 +               kdb_printf(" dpl=%d wc=%d\n",
51710 +                          d->dpl, KDB_SYS_DESC_CALLG_COUNT(d));
51711 +               break;
51712 +       case KDB_SYS_DESC_TYPE_CALLG:
51713 +               kdb_printf("segment=0x%4.4x off=", d->segment);
51714 +               kdb_symbol_print(KDB_SYS_DESC_OFFSET(d), NULL, KDB_SP_DEFAULT);
51715 +               kdb_printf(" dpl=%d\n", d->dpl);
51716 +               break;
51717 +       default:
51718 +               kdb_printf("segment=0x%4.4x off=", d->segment);
51719 +               if (KDB_SYS_DESC_OFFSET(d))
51720 +                       kdb_symbol_print(KDB_SYS_DESC_OFFSET(d), NULL,
51721 +                                        KDB_SP_DEFAULT);
51722 +               else
51723 +                       kdb_printf(kdb_machreg_fmt0, KDB_SYS_DESC_OFFSET(d));
51724 +               kdb_printf(" dpl=%d", d->dpl);
51725 +#ifdef CONFIG_X86_64
51726 +               if (d->ist)
51727 +                       kdb_printf(" ist=%d", d->ist);
51728 +#endif /* CONFIG_X86_64 */
51729 +               kdb_printf("\n");
51730 +               break;
51731 +       }
51732 +}
51733 +
51734 +static void
51735 +display_seg_desc(kdb_desc_t *d)
51736 +{
51737 +       unsigned char type = d->type;
51738 +
51739 +       if (type & KDB_SEG_DESC_TYPE_CODE) {
51740 +               kdb_printf("%-11s base=" kdb_machreg_fmt0 " limit="
51741 +                          kdb_machreg_fmt " dpl=%d %c%c%c %s %s %s \n",
51742 +                          "code",
51743 +                          kdb_seg_desc_base(d), KDB_SEG_DESC_LIMIT(d),
51744 +                          d->dpl,
51745 +                          (type & KDB_SEG_DESC_TYPE_CODE_R)?'r':'-',
51746 +                          '-', 'x',
51747 +#ifdef CONFIG_X86_64
51748 +                          d->l ? "64b" : d->d ? "32b" : "16b",
51749 +#else  /* !CONFIG_X86_64 */
51750 +                          d->d ? "32b" : "16b",
51751 +#endif /* CONFIG_X86_64 */
51752 +                          (type & KDB_SEG_DESC_TYPE_A)?"ac":"",
51753 +                          (type & KDB_SEG_DESC_TYPE_CODE_C)?"conf":"");
51754 +       } else {
51755 +               kdb_printf("%-11s base=" kdb_machreg_fmt0 " limit="
51756 +                          kdb_machreg_fmt " dpl=%d %c%c%c %s %s %s \n",
51757 +                          "data",
51758 +                          kdb_seg_desc_base(d), KDB_SEG_DESC_LIMIT(d),
51759 +                          d->dpl,
51760 +                          'r',
51761 +                          (type & KDB_SEG_DESC_TYPE_DATA_W)?'w':'-',
51762 +                          '-',
51763 +                          d->d ? "32b" : "16b",
51764 +                          (type & KDB_SEG_DESC_TYPE_A)?"ac":"",
51765 +                          (type & KDB_SEG_DESC_TYPE_DATA_D)?"down":"");
51766 +       }
51767 +}
51768 +
51769 +static int
51770 +kdb_parse_two_numbers(int argc, const char **argv, int *sel, int *count,
51771 +                     int *last_sel, int *last_count)
51772 +{
51773 +       int diag;
51774 +
51775 +       if (argc > 2)
51776 +               return KDB_ARGCOUNT;
51777 +
51778 +       kdbgetintenv("MDCOUNT", count);
51779 +
51780 +       if (argc == 0) {
51781 +               *sel = *last_sel;
51782 +               if (*last_count)
51783 +                       *count = *last_count;
51784 +       } else {
51785 +               unsigned long val;
51786 +
51787 +               if (argc >= 1) {
51788 +                       diag = kdbgetularg(argv[1], &val);
51789 +                       if (diag)
51790 +                               return diag;
51791 +                       *sel = val;
51792 +               }
51793 +               if (argc >= 2) {
51794 +                       diag = kdbgetularg(argv[2], &val);
51795 +                       if (diag)
51796 +                               return diag;
51797 +                       *count = (int) val;
51798 +                       *last_count = (int) val;
51799 +               } else if (*last_count) {
51800 +                       *count = *last_count;
51801 +               }
51802 +       }
51803 +       return 0;
51804 +}
51805 +
51806 +/*
51807 + * kdb_gdt
51808 + *
51809 + *     This function implements the 'gdt' command.
51810 + *
51811 + *     gdt [<selector> [<line count>]]
51812 + *
51813 + * Inputs:
51814 + *     argc    argument count
51815 + *     argv    argument vector
51816 + * Outputs:
51817 + *     None.
51818 + * Returns:
51819 + *     zero for success, a kdb diagnostic if error
51820 + * Locking:
51821 + *     none.
51822 + * Remarks:
51823 + */
51824 +static int
51825 +kdb_gdt(int argc, const char **argv)
51826 +{
51827 +       int sel = 0;
51828 +       struct desc_ptr gdtr;
51829 +       int diag, count = 8;
51830 +       kdb_desc_t *gdt;
51831 +       unsigned int max_sel;
51832 +       static int last_sel = 0, last_count = 0;
51833 +
51834 +       diag = kdb_parse_two_numbers(argc, argv, &sel, &count,
51835 +                                    &last_sel, &last_count);
51836 +       if (diag)
51837 +               return diag;
51838 +
51839 +       __asm__ __volatile__ ("sgdt %0\n\t" : "=m"(gdtr));
51840 +       gdt = (kdb_desc_t *) gdtr.address;
51841 +
51842 +       max_sel = (gdtr.size + 1) / sizeof(kdb_desc_t);
51843 +       if (sel >= max_sel) {
51844 +               kdb_printf("Maximum selector (%d) reached\n", max_sel);
51845 +               return 0;
51846 +       }
51847 +
51848 +       if (sel + count > max_sel)
51849 +               count = max_sel - sel;
51850 +
51851 +       while (count--) {
51852 +               kdb_desc_t *d = &gdt[sel];
51853 +               kdb_printf("0x%4.4x ", sel++);
51854 +
51855 +               if (!d->p) {
51856 +                       kdb_printf("not present\n");
51857 +                       continue;
51858 +               }
51859 +               if (d->s) {
51860 +                       display_seg_desc(d);
51861 +               } else {
51862 +                       display_gate_desc((kdb_gate_desc_t *)d);
51863 +                       if (KDB_X86_64 && count) {
51864 +                               ++sel;  /* this descriptor occupies two slots */
51865 +                               --count;
51866 +                       }
51867 +               }
51868 +       }
51869 +
51870 +       last_sel = sel;
51871 +       return 0;
51872 +}
51873 +
51874 +/*
51875 + * kdb_ldt
51876 + *
51877 + *     This function implements the 'ldt' command.
51878 + *
51879 + *     ldt [<selector> [<line count>]]
51880 + *
51881 + * Inputs:
51882 + *     argc    argument count
51883 + *     argv    argument vector
51884 + * Outputs:
51885 + *     None.
51886 + * Returns:
51887 + *     zero for success, a kdb diagnostic if error
51888 + * Locking:
51889 + *     none.
51890 + * Remarks:
51891 + */
51892 +static int
51893 +kdb_ldt(int argc, const char **argv)
51894 +{
51895 +       int sel = 0;
51896 +       struct desc_ptr gdtr;
51897 +       unsigned long ldtr = 0;
51898 +       int diag, count = 8;
51899 +       kdb_desc_t *ldt, *ldt_desc;
51900 +       unsigned int max_sel;
51901 +       static int last_sel = 0, last_count = 0;
51902 +
51903 +       diag = kdb_parse_two_numbers(argc, argv, &sel, &count,
51904 +                                    &last_sel, &last_count);
51905 +       if (diag)
51906 +               return diag;
51907 +
51908 +       if (strcmp(argv[0], "ldtp") == 0) {
51909 +               kdb_printf("pid=%d, process=%s\n",
51910 +                          kdb_current_task->pid, kdb_current_task->comm);
51911 +               if (!kdb_current_task->mm ||
51912 +                   !kdb_current_task->mm->context.ldt) {
51913 +                       kdb_printf("no special LDT for this process\n");
51914 +                       return 0;
51915 +               }
51916 +               ldt = kdb_current_task->mm->context.ldt;
51917 +               max_sel = kdb_current_task->mm->context.size;
51918 +       } else {
51919 +
51920 +               /* sldt gives the GDT selector for the segment containing LDT */
51921 +               __asm__ __volatile__ ("sgdt %0\n\t" : "=m"(gdtr));
51922 +               __asm__ __volatile__ ("sldt %0\n\t" : "=m"(ldtr));
51923 +               ldtr &= 0xfff8;         /* extract the index */
51924 +
51925 +               if (ldtr > gdtr.size+1) {
51926 +                       kdb_printf("invalid ldtr\n");
51927 +                       return 0;
51928 +               }
51929 +
51930 +               ldt_desc = (kdb_desc_t *)(gdtr.address + ldtr);
51931 +               ldt = (kdb_desc_t *)kdb_seg_desc_base(ldt_desc);
51932 +               max_sel = (KDB_SEG_DESC_LIMIT(ldt_desc)+1) / sizeof(kdb_desc_t);
51933 +       }
51934 +
51935 +       if (sel >= max_sel) {
51936 +               kdb_printf("Maximum selector (%d) reached\n", max_sel);
51937 +               return 0;
51938 +       }
51939 +
51940 +       if (sel + count > max_sel)
51941 +               count = max_sel - sel;
51942 +
51943 +       while (count--) {
51944 +               kdb_desc_t *d = &ldt[sel];
51945 +               kdb_printf("0x%4.4x ", sel++);
51946 +
51947 +               if (!d->p) {
51948 +                       kdb_printf("not present\n");
51949 +                       continue;
51950 +               }
51951 +               if (d->s) {
51952 +                       display_seg_desc(d);
51953 +               } else {
51954 +                       display_gate_desc((kdb_gate_desc_t *)d);
51955 +                       if (KDB_X86_64 && count) {
51956 +                               ++sel;  /* this descriptor occupies two slots */
51957 +                               --count;
51958 +                       }
51959 +               }
51960 +       }
51961 +
51962 +       last_sel = sel;
51963 +       return 0;
51964 +}
51965 +
51966 +/*
51967 + * kdb_idt
51968 + *
51969 + *     This function implements the 'idt' command.
51970 + *
51971 + *     idt [<vector> [<line count>]]
51972 + *
51973 + * Inputs:
51974 + *     argc    argument count
51975 + *     argv    argument vector
51976 + * Outputs:
51977 + *     None.
51978 + * Returns:
51979 + *     zero for success, a kdb diagnostic if error
51980 + * Locking:
51981 + *     none.
51982 + * Remarks:
51983 + */
51984 +static int
51985 +kdb_idt(int argc, const char **argv)
51986 +{
51987 +       int vec = 0;
51988 +       struct desc_ptr idtr;
51989 +       int diag, count = 8;
51990 +       kdb_gate_desc_t *idt;
51991 +       unsigned int max_entries;
51992 +       static int last_vec = 0, last_count = 0;
51993 +
51994 +       diag = kdb_parse_two_numbers(argc, argv, &vec, &count,
51995 +                                    &last_vec, &last_count);
51996 +       if (diag)
51997 +               return diag;
51998 +
51999 +       __asm__ __volatile__ ("sidt %0\n\t" : "=m"(idtr));
52000 +       idt = (kdb_gate_desc_t *)idtr.address;
52001 +
52002 +       max_entries = (idtr.size+1) / sizeof(kdb_gate_desc_t);
52003 +       if (vec >= max_entries) {
52004 +               kdb_printf("Maximum vector (%d) reached\n", max_entries);
52005 +               return 0;
52006 +       }
52007 +
52008 +       if (vec + count > max_entries)
52009 +               count = max_entries - vec;
52010 +
52011 +       while (count--) {
52012 +               kdb_gate_desc_t *d = &idt[vec];
52013 +               kdb_printf("0x%4.4x ", vec++);
52014 +               if (!d->p) {
52015 +                       kdb_printf("not present\n");
52016 +                       continue;
52017 +               }
52018 +#ifndef        CONFIG_X86_64
52019 +               if (d->s) {
52020 +                       kdb_printf("invalid\n");
52021 +                       continue;
52022 +               }
52023 +#endif /* CONFIG_X86_64 */
52024 +               display_gate_desc(d);
52025 +       }
52026 +
52027 +       last_vec = vec;
52028 +
52029 +       return 0;
52030 +}
52031 +
52032 +#define _PAGE_PSE 0x080
52033 +
52034 +#if 0
52035 +static int
52036 +get_pagetables(unsigned long addr, pgd_t **pgdir, pmd_t **pgmiddle, pte_t **pte)
52037 +{
52038 +       pgd_t *d;
52039 +       pmd_t *m;
52040 +       pte_t *t;
52041 +
52042 +       if (addr > PAGE_OFFSET) {
52043 +               d = pgd_offset_k(addr);
52044 +       } else {
52045 +               kdb_printf("pid=%d, process=%s\n", kdb_current_task->pid, kdb_current_task->comm);
52046 +               d = pgd_offset(kdb_current_task->mm, addr);
52047 +       }
52048 +
52049 +       if (pgd_none(*d) || pgd_bad(*d)) {
52050 +               *pgdir = NULL;
52051 +               *pgmiddle = NULL;
52052 +               *pte = NULL;
52053 +               return 0;
52054 +       } else {
52055 +               *pgdir = d;
52056 +       }
52057 +
52058 +       /* if _PAGE_PSE is set, pgdir points directly to the page. */
52059 +       if (pgd_val(*d) & _PAGE_PSE) {
52060 +               *pgmiddle = NULL;
52061 +               *pte = NULL;
52062 +               return 0;
52063 +       }
52064 +
52065 +       m = pmd_offset(d, addr);
52066 +       if (pmd_none(*m) || pmd_bad(*m)) {
52067 +               *pgmiddle = NULL;
52068 +               *pte = NULL;
52069 +               return 0;
52070 +       } else {
52071 +               *pgmiddle = m;
52072 +       }
52073 +
52074 +       t = pte_offset(m, addr);
52075 +       if (pte_none(*t)) {
52076 +               *pte = NULL;
52077 +               return 0;
52078 +       } else {
52079 +               *pte = t;
52080 +       }
52081 +       kdb_printf("\naddr=%08lx, pgd=%08lx, pmd=%08lx, pte=%08lx\n",
52082 +                       addr,
52083 +                       (unsigned long) pgd_val(*d),
52084 +                       (unsigned long) pmd_val(*m),
52085 +                       (unsigned long) pte_val(*t));
52086 +       return 0;
52087 +}
52088 +#endif
52089 +
52090 +#define FORMAT_PGDIR(entry) \
52091 +       kdb_printf("frame=%05lx %c %s %c %c %c %s %c %s %s \n",\
52092 +                       (entry >> PAGE_SHIFT),                          \
52093 +                       (entry & _PAGE_PRESENT)?'p':'n',                \
52094 +                       (entry & _PAGE_RW)?"rw":"ro",                   \
52095 +                       (entry & _PAGE_USER)?'u':'s',                   \
52096 +                       (entry & _PAGE_ACCESSED)?'a':' ',               \
52097 +                       ' ',                                            \
52098 +                       (entry & _PAGE_PSE)?"4M":"4K",                  \
52099 +                       (entry & _PAGE_GLOBAL)?'g':' ',                 \
52100 +                       (entry & _PAGE_PWT)?"wt":"wb",                  \
52101 +                       (entry & _PAGE_PCD)?"cd":"  ");
52102 +
52103 +#define FORMAT_PTE(p, entry) \
52104 +       kdb_printf("frame=%05lx %c%c%c %c %c %c %s %c %s %s\n", \
52105 +                       (entry >> PAGE_SHIFT),                  \
52106 +                       (pte_read(p))? 'r':'-',                 \
52107 +                       (pte_write(p))? 'w':'-',                \
52108 +                       (pte_exec(p))? 'x':'-',                 \
52109 +                       (pte_dirty(p))? 'd':' ',                \
52110 +                       (pte_young(p))? 'a':' ',                \
52111 +                       (entry & _PAGE_USER)? 'u':'s',          \
52112 +                       "  ",                                   \
52113 +                       (entry & _PAGE_GLOBAL)? 'g':' ',        \
52114 +                       (entry & _PAGE_PWT)? "wt":"wb",         \
52115 +                       (entry & _PAGE_PCD)? "cd":"  ");
52116 +#if 0
52117 +static int
52118 +display_pgdir(unsigned long addr, pgd_t *pgdir, int count)
52119 +{
52120 +       unsigned long entry;
52121 +       int i;
52122 +       int index = pgdir - ((pgd_t *)(((unsigned long)pgdir) & PAGE_MASK));
52123 +
52124 +       count = min(count, PTRS_PER_PGD - index);
52125 +       addr &= ~(PGDIR_SIZE-1);
52126 +
52127 +       for (i = 0; i < count; i++, pgdir++) {
52128 +               entry = pgd_val(*pgdir);
52129 +               kdb_printf("pgd: addr=%08lx ", addr);
52130 +               if (pgd_none(*pgdir)) {
52131 +                       kdb_printf("pgdir not present\n");
52132 +               } else {
52133 +                       FORMAT_PGDIR(entry);
52134 +               }
52135 +               addr += PGDIR_SIZE;
52136 +       }
52137 +       return i;
52138 +}
52139 +#endif
52140 +
52141 +#if 0  /* for now, let's not print pgmiddle. */
52142 +static int
52143 +display_pgmiddle(unsigned long addr, pmd_t *pgmiddle, int count)
52144 +{
52145 +       unsigned long entry;
52146 +       int i;
52147 +       int index = pgmiddle - ((pmd_t *)(((unsigned long)pgmiddle) & PAGE_MASK));
52148 +
52149 +       count = min(count, PTRS_PER_PMD - index);
52150 +       addr &= ~(PMD_SIZE-1);
52151 +
52152 +       for (i = 0; i < count; i++, pgmiddle++) {
52153 +               entry = pmd_val(*pgmiddle);
52154 +               kdb_printf("pmd: addr=%08lx ", addr);
52155 +               if (pmd_none(*pgmiddle)) {
52156 +                       kdb_printf("pgmiddle not present\n");
52157 +               } else {
52158 +                       FORMAT_PGDIR(entry);
52159 +               }
52160 +               addr += PMD_SIZE;
52161 +       }
52162 +       return i;
52163 +}
52164 +#endif
52165 +
52166 +#if 0
52167 +static int
52168 +display_pte(unsigned long addr, pte_t *pte, int count)
52169 +{
52170 +       unsigned long entry;
52171 +       int i;
52172 +       int index = pte - ((pte_t *)(((unsigned long)pte) & PAGE_MASK));
52173 +
52174 +       count = min(count, PTRS_PER_PTE - index);
52175 +       addr &= PAGE_MASK;
52176 +
52177 +       for (i = 0; i < count; i++, pte++) {
52178 +               entry = pte_val(*pte);
52179 +               kdb_printf("pte: addr=%08lx ", addr);
52180 +               if (pte_none(*pte)) {
52181 +                       kdb_printf("pte not present\n");
52182 +               } else if (!pte_present(*pte)) {
52183 +                       kdb_printf("page swapped out. swp_offset=%08lx ", SWP_OFFSET(pte_to_swp_entry(*pte)));
52184 +                       kdb_printf("swp_type=%8lx", SWP_TYPE(pte_to_swp_entry(*pte)));
52185 +               } else {
52186 +                       FORMAT_PTE(*pte, entry);
52187 +               }
52188 +               addr += PAGE_SIZE;
52189 +       }
52190 +       return i;
52191 +}
52192 +
52193 +
52194 +/*
52195 + * kdb_pte
52196 + *
52197 + *     This function implements the 'pte' command.
52198 + *
52199 + *     pte  <addr arg> [<line count>]
52200 + *
52201 + * Inputs:
52202 + *     argc    argument count
52203 + *     argv    argument vector
52204 + * Outputs:
52205 + *     None.
52206 + * Returns:
52207 + *     zero for success, a kdb diagnostic if error
52208 + * Locking:
52209 + *     none.
52210 + * Remarks:
52211 + */
52212 +static int
52213 +kdb_pte(int argc, const char **argv)
52214 +{
52215 +       static unsigned long last_addr = 0, last_count = 0;
52216 +       int count = 8;
52217 +       unsigned long addr;
52218 +       long offset = 0;
52219 +       pgd_t *pgdir;
52220 +       pmd_t *pgmiddle;
52221 +       pte_t *pte;
52222 +
52223 +#ifdef CONFIG_X86_PAE
52224 +       kdb_printf("This kernel is compiled with PAE support.");
52225 +       return KDB_NOTIMP;
52226 +#endif
52227 +       kdbgetintenv("MDCOUNT", &count);
52228 +
52229 +       if (argc == 0) {
52230 +               if (last_addr == 0)
52231 +                       return KDB_ARGCOUNT;
52232 +               addr = last_addr;
52233 +               if (last_count)
52234 +                       count = last_count;
52235 +       } else {
52236 +               kdb_machreg_t val;
52237 +               int diag, nextarg = 1;
52238 +               diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL);
52239 +               if (diag)
52240 +                       return diag;
52241 +               if (argc > nextarg+1)
52242 +                       return KDB_ARGCOUNT;
52243 +
52244 +               if (argc >= nextarg) {
52245 +                       diag = kdbgetularg(argv[nextarg], &val);
52246 +                       if (!diag) {
52247 +                               count = (int) val;
52248 +                               last_count = count;
52249 +                       } else if (last_count) {
52250 +                               count = last_count;
52251 +                       }
52252 +               }
52253 +       }
52254 +
52255 +       /*
52256 +        * round off the addr to a page boundary.
52257 +        */
52258 +       addr &= PAGE_MASK;
52259 +
52260 +       get_pagetables(addr, &pgdir, &pgmiddle, &pte);
52261 +
52262 +       if (pgdir)
52263 +               display_pgdir(addr, pgdir, 1);
52264 +#if 0  /* for now, let's not print pgmiddle. */
52265 +          if (pgmiddle)
52266 +               display_pgmiddle(addr, pgmiddle, 1);
52267 +#endif
52268 +       if (pte) {
52269 +               int displayed;
52270 +               displayed = display_pte(addr, pte, count);
52271 +               addr += (displayed << PAGE_SHIFT);
52272 +       }
52273 +       last_addr = addr;
52274 +       return 0;
52275 +}
52276 +#else
52277 +/*
52278 + * Todo - In 2.5 the pte_offset macro in asm/pgtable.h seems to be
52279 + * renamed to pte_offset_kernel.
52280 + */
52281 +static int
52282 +kdb_pte(int argc, const char **argv)
52283 +{
52284 +       kdb_printf("not supported.");
52285 +       return KDB_NOTIMP;
52286 +}
52287 +#endif
52288 +
52289 +/*
52290 + * kdb_rdv
52291 + *
52292 + *     This function implements the 'rdv' command.
52293 + *     It displays all registers of the current processor
52294 + *     included control registers in verbose mode.
52295 + *
52296 + * Inputs:
52297 + *     argc    argument count
52298 + *     argv    argument vector
52299 + * Outputs:
52300 + *     None.
52301 + * Returns:
52302 + *     zero for success, a kdb diagnostic if error
52303 + * Locking:
52304 + *     none.
52305 + * Remarks:
52306 + *     This should have been an option to rd command say "rd v",
52307 + *     but it is here as it is a non-essential x86-only command,
52308 + *     that need not clutter arch/i386/kdb/kdbasupport.c.
52309 + */
52310 +static int
52311 +kdb_rdv(int argc, const char **argv)
52312 +{
52313 +       struct pt_regs *regs = get_irq_regs();
52314 +       kdba_dumpregs(regs, NULL, NULL);
52315 +       kdb_printf("\n");
52316 +       display_eflags(regs->eflags);
52317 +       kdb_printf("\n");
52318 +       display_gdtr();
52319 +       display_idtr();
52320 +       display_ldtr();
52321 +       kdb_printf("\n");
52322 +       display_cr0();
52323 +       display_cr3();
52324 +       display_cr4();
52325 +       display_cr8();
52326 +       kdb_printf("\n");
52327 +       display_dr();
52328 +       return 0;
52329 +}
52330 +
52331 +static int
52332 +kdb_rdmsr(int argc, const char **argv)
52333 +{
52334 +       unsigned long addr;
52335 +       uint32_t l, h;
52336 +       int diag;
52337 +       struct cpuinfo_x86 *c = cpu_data + smp_processor_id();
52338 +
52339 +       if (argc != 1)
52340 +               return KDB_ARGCOUNT;
52341 +
52342 +       if ((diag = kdbgetularg(argv[1], &addr)))
52343 +               return diag;
52344 +
52345 +       if (!cpu_has(c, X86_FEATURE_MSR))
52346 +               return KDB_NOTIMP;
52347 +
52348 +       kdb_printf("msr(0x%lx) = ", addr);
52349 +       if ((diag = rdmsr_safe(addr, &l, &h))) {
52350 +               kdb_printf("error %d\n", diag);
52351 +               return KDB_BADINT;
52352 +       } else {
52353 +               kdb_printf("0x%08x_%08x\n", h, l);
52354 +       }
52355 +
52356 +       return 0;
52357 +}
52358 +
52359 +static int
52360 +kdb_wrmsr(int argc, const char **argv)
52361 +{
52362 +       unsigned long addr;
52363 +       unsigned long l, h;
52364 +       int diag;
52365 +       struct cpuinfo_x86 *c = cpu_data + smp_processor_id();
52366 +
52367 +       if (argc != 3)
52368 +               return KDB_ARGCOUNT;
52369 +
52370 +       if ((diag = kdbgetularg(argv[1], &addr))
52371 +                       || (diag = kdbgetularg(argv[2], &h))
52372 +                       || (diag = kdbgetularg(argv[3], &l)))
52373 +               return diag;
52374 +
52375 +       if (!cpu_has(c, X86_FEATURE_MSR))
52376 +               return KDB_NOTIMP;
52377 +
52378 +       if ((diag = wrmsr_safe(addr, l, h))) {
52379 +               kdb_printf("error %d\n", diag);
52380 +               return KDB_BADINT;
52381 +       }
52382 +
52383 +       return 0;
52384 +}
52385 +
52386 +static int __init kdbm_x86_init(void)
52387 +{
52388 +       kdb_register("rdv", kdb_rdv, NULL, "Display registers in verbose mode", 0);
52389 +       kdb_register_repeat("gdt", kdb_gdt, "<sel> [<count>]", "Display GDT", 0, KDB_REPEAT_NO_ARGS);
52390 +       kdb_register_repeat("idt", kdb_idt, "<int> [<count>]", "Display IDT", 0, KDB_REPEAT_NO_ARGS);
52391 +       kdb_register_repeat("ldt", kdb_ldt, "<sel> [<count>]", "Display LDT", 0, KDB_REPEAT_NO_ARGS);
52392 +       kdb_register_repeat("ptex", kdb_pte, "<addr> [<count>]", "Display pagetables", 0, KDB_REPEAT_NO_ARGS);
52393 +       kdb_register_repeat("ldtp", kdb_ldt, "<sel> [<count>]", "Display Process LDT", 0, KDB_REPEAT_NO_ARGS);
52394 +       kdb_register("rdmsr", kdb_rdmsr, "<maddr>", "Display Model Specific Register", 0);
52395 +       kdb_register("wrmsr", kdb_wrmsr, "<maddr> <h> <l>", "Modify Model Specific Register", 0);
52396 +       return 0;
52397 +}
52398 +
52399 +static void __exit kdbm_x86_exit(void)
52400 +{
52401 +       kdb_unregister("rdv");
52402 +       kdb_unregister("gdt");
52403 +       kdb_unregister("ldt");
52404 +       kdb_unregister("idt");
52405 +       kdb_unregister("ptex");
52406 +       kdb_unregister("ldtp");
52407 +       kdb_unregister("rdmsr");
52408 +       kdb_unregister("wrmsr");
52409 +}
52410 +
52411 +module_init(kdbm_x86_init)
52412 +module_exit(kdbm_x86_exit)
52413 diff -Nurp linux-2.6.22-590/kdb/modules/kdbm_xpc.c linux-2.6.22-600/kdb/modules/kdbm_xpc.c
52414 --- linux-2.6.22-590/kdb/modules/kdbm_xpc.c     1970-01-01 01:00:00.000000000 +0100
52415 +++ linux-2.6.22-600/kdb/modules/kdbm_xpc.c     2008-04-09 18:14:28.000000000 +0200
52416 @@ -0,0 +1,1105 @@
52417 +/*
52418 + * This file is subject to the terms and conditions of the GNU General Public
52419 + * License.  See the file "COPYING" in the main directory of this archive
52420 + * for more details.
52421 + *
52422 + * Copyright (c) 2006 Silicon Graphics, Inc.  All Rights Reserved.
52423 + */
52424 +
52425 +
52426 +/*
52427 + * Cross Partition Communication (XPC) kdb support.
52428 + *
52429 + *     This provides kdb commands for debugging XPC.
52430 + */
52431 +
52432 +#include <linux/kernel.h>
52433 +#include <linux/module.h>
52434 +#include <linux/kdb.h>
52435 +#include <linux/kdbprivate.h>
52436 +#include <asm/sn/sn_sal.h>
52437 +#include <asm/sn/xpc.h>
52438 +
52439 +
52440 +MODULE_AUTHOR("SGI");
52441 +MODULE_DESCRIPTION("Debug XPC information");
52442 +MODULE_LICENSE("GPL");
52443 +
52444 +
52445 +static int
52446 +kdbm_xpc_down(int argc, const char **argv)
52447 +{
52448 +       if (xpc_rsvd_page == NULL) {
52449 +               kdb_printf("Reserved Page has not been initialized.\n");
52450 +
52451 +       } else if (xpc_kdebug_force_disengage()) {
52452 +               kdb_printf("Unable to force XPC disengage.\n");
52453 +       }
52454 +       return 0;
52455 +}
52456 +
52457 +
52458 +static char *
52459 +kdbm_xpc_get_ascii_reason_code(enum xpc_retval reason)
52460 +{
52461 +       switch (reason) {
52462 +       case xpcSuccess:                return "";
52463 +       case xpcNotConnected:           return "xpcNotConnected";
52464 +       case xpcConnected:              return "xpcConnected";
52465 +       case xpcRETIRED1:               return "xpcRETIRED1";
52466 +       case xpcMsgReceived:            return "xpcMsgReceived";
52467 +       case xpcMsgDelivered:           return "xpcMsgDelivered";
52468 +       case xpcRETIRED2:               return "xpcRETIRED2";
52469 +       case xpcNoWait:                 return "xpcNoWait";
52470 +       case xpcRetry:                  return "xpcRetry";
52471 +       case xpcTimeout:                return "xpcTimeout";
52472 +       case xpcInterrupted:            return "xpcInterrupted";
52473 +       case xpcUnequalMsgSizes:        return "xpcUnequalMsgSizes";
52474 +       case xpcInvalidAddress:         return "xpcInvalidAddress";
52475 +       case xpcNoMemory:               return "xpcNoMemory";
52476 +       case xpcLackOfResources:        return "xpcLackOfResources";
52477 +       case xpcUnregistered:           return "xpcUnregistered";
52478 +       case xpcAlreadyRegistered:      return "xpcAlreadyRegistered";
52479 +       case xpcPartitionDown:          return "xpcPartitionDown";
52480 +       case xpcNotLoaded:              return "xpcNotLoaded";
52481 +       case xpcUnloading:              return "xpcUnloading";
52482 +       case xpcBadMagic:               return "xpcBadMagic";
52483 +       case xpcReactivating:           return "xpcReactivating";
52484 +       case xpcUnregistering:          return "xpcUnregistering";
52485 +       case xpcOtherUnregistering:     return "xpcOtherUnregistering";
52486 +       case xpcCloneKThread:           return "xpcCloneKThread";
52487 +       case xpcCloneKThreadFailed:     return "xpcCloneKThreadFailed";
52488 +       case xpcNoHeartbeat:            return "xpcNoHeartbeat";
52489 +       case xpcPioReadError:           return "xpcPioReadError";
52490 +       case xpcPhysAddrRegFailed:      return "xpcPhysAddrRegFailed";
52491 +       case xpcBteDirectoryError:      return "xpcBteDirectoryError";
52492 +       case xpcBtePoisonError:         return "xpcBtePoisonError";
52493 +       case xpcBteWriteError:          return "xpcBteWriteError";
52494 +       case xpcBteAccessError:         return "xpcBteAccessError";
52495 +       case xpcBtePWriteError:         return "xpcBtePWriteError";
52496 +       case xpcBtePReadError:          return "xpcBtePReadError";
52497 +       case xpcBteTimeOutError:        return "xpcBteTimeOutError";
52498 +       case xpcBteXtalkError:          return "xpcBteXtalkError";
52499 +       case xpcBteNotAvailable:        return "xpcBteNotAvailable";
52500 +       case xpcBteUnmappedError:       return "xpcBteUnmappedError";
52501 +       case xpcBadVersion:             return "xpcBadVersion";
52502 +       case xpcVarsNotSet:             return "xpcVarsNotSet";
52503 +       case xpcNoRsvdPageAddr:         return "xpcNoRsvdPageAddr";
52504 +       case xpcInvalidPartid:          return "xpcInvalidPartid";
52505 +       case xpcLocalPartid:            return "xpcLocalPartid";
52506 +       case xpcOtherGoingDown:         return "xpcOtherGoingDown";
52507 +       case xpcSystemGoingDown:        return "xpcSystemGoingDown";
52508 +       case xpcSystemHalt:             return "xpcSystemHalt";
52509 +       case xpcSystemReboot:           return "xpcSystemReboot";
52510 +       case xpcSystemPoweroff:         return "xpcSystemPoweroff";
52511 +       case xpcDisconnecting:          return "xpcDisconnecting";
52512 +       case xpcOpenCloseError:         return "xpcOpenCloseError";
52513 +       case xpcUnknownReason:          return "xpcUnknownReason";
52514 +       default:                        return "undefined reason code";
52515 +       }
52516 +}
52517 +
52518 +
52519 +/*
52520 + * Display the reserved page used by XPC.
52521 + *
52522 + *     xpcrp
52523 + */
52524 +static int
52525 +kdbm_xpc_rsvd_page(int argc, const char **argv)
52526 +{
52527 +       struct xpc_rsvd_page *rp = (struct xpc_rsvd_page *) xpc_rsvd_page;
52528 +
52529 +
52530 +       if (argc > 0) {
52531 +               return KDB_ARGCOUNT;
52532 +       }
52533 +
52534 +       if (rp == NULL) {
52535 +               kdb_printf("Reserved Page has not been initialized.\n");
52536 +               return 0;
52537 +       }
52538 +
52539 +       kdb_printf("struct xpc_rsvd_page @ (0x%p):\n", (void *) rp);
52540 +       kdb_printf("\tSAL_signature=0x%lx\n", rp->SAL_signature);
52541 +       kdb_printf("\tSAL_version=0x%lx\n", rp->SAL_version);
52542 +       kdb_printf("\tpartid=%d\n", rp->partid);
52543 +       kdb_printf("\tversion=0x%x %d.%d\n", rp->version,
52544 +                               XPC_VERSION_MAJOR(rp->version),
52545 +                               XPC_VERSION_MINOR(rp->version));
52546 +       kdb_printf("\tvars_pa=0x%lx\n", rp->vars_pa);
52547 +       kdb_printf("\tstamp=0x%lx:0x%lx\n",
52548 +                               rp->stamp.tv_sec, rp->stamp.tv_nsec);
52549 +       kdb_printf("\tnasids_size=%ld\n", rp->nasids_size);
52550 +
52551 +       return 0;
52552 +}
52553 +
52554 +
52555 +static void
52556 +kdbm_xpc_print_vars_part(struct xpc_vars_part *vars_part, partid_t partid)
52557 +{
52558 +       kdb_printf("struct xpc_vars_part @ (0x%p) [partid=%d]:\n",
52559 +                                               (void *) vars_part, partid);
52560 +       kdb_printf("\tmagic=0x%lx ", vars_part->magic);
52561 +       if (vars_part->magic != 0) {
52562 +               kdb_printf("%s", (char *) &vars_part->magic);
52563 +       }
52564 +       kdb_printf("\n");
52565 +       kdb_printf("\tGPs_pa=0x%lx\n", vars_part->GPs_pa);
52566 +       kdb_printf("\topenclose_args_pa=0x%lx\n",
52567 +                               vars_part->openclose_args_pa);
52568 +       kdb_printf("\tIPI_amo_pa=0x%lx\n", vars_part->IPI_amo_pa);
52569 +       kdb_printf("\tIPI_nasid=0x%x\n", vars_part->IPI_nasid);
52570 +       kdb_printf("\tIPI_phys_cpuid=0x%x\n", vars_part->IPI_phys_cpuid);
52571 +       kdb_printf("\tnchannels=%d\n", vars_part->nchannels);
52572 +}
52573 +
52574 +
52575 +/*
52576 + * Display XPC variables.
52577 + *
52578 + *      xpcvars [ <partid> ]
52579 + *
52580 + *         no partid - displays xpc_vars structure
52581 + *         partid=0  - displays all initialized xpc_vars_part structures
52582 + *         partid=i  - displays xpc_vars_part structure for specified
52583 + *                     partition, if initialized
52584 + */
52585 +static int
52586 +kdbm_xpc_variables(int argc, const char **argv)
52587 +{
52588 +       int ret;
52589 +       unsigned long ulong_partid;
52590 +       partid_t partid;
52591 +       struct xpc_vars_part *vars_part;
52592 +
52593 +
52594 +       if (xpc_rsvd_page == NULL) {
52595 +               kdb_printf("Reserved Page has not been initialized.\n");
52596 +               return 0;
52597 +       }
52598 +       DBUG_ON(xpc_vars == NULL);
52599 +
52600 +       if (argc == 0) {
52601 +
52602 +               /* just display the xpc_vars structure */
52603 +
52604 +               kdb_printf("struct xpc_vars @ (0x%p):\n", (void *) xpc_vars);
52605 +               kdb_printf("\tversion=0x%x %d.%d\n", xpc_vars->version,
52606 +                               XPC_VERSION_MAJOR(xpc_vars->version),
52607 +                               XPC_VERSION_MINOR(xpc_vars->version));
52608 +               kdb_printf("\theartbeat=%ld\n", xpc_vars->heartbeat);
52609 +               kdb_printf("\theartbeating_to_mask=0x%lx",
52610 +                                       xpc_vars->heartbeating_to_mask);
52611 +               for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
52612 +                       if (xpc_hb_allowed(partid, xpc_vars)) {
52613 +                               kdb_printf(" %d", partid);
52614 +                       }
52615 +               }
52616 +               kdb_printf("\n");
52617 +               kdb_printf("\theartbeat_offline=0x%lx\n",
52618 +                                       xpc_vars->heartbeat_offline);
52619 +               kdb_printf("\tact_nasid=0x%x\n", xpc_vars->act_nasid);
52620 +               kdb_printf("\tact_phys_cpuid=0x%x\n",
52621 +                                       xpc_vars->act_phys_cpuid);
52622 +               kdb_printf("\tvars_part_pa=0x%lx\n", xpc_vars->vars_part_pa);
52623 +               kdb_printf("\tamos_page_pa=0x%lx\n", xpc_vars->amos_page_pa);
52624 +               kdb_printf("\tamos_page=0x%p\n", (void *) xpc_vars->amos_page);
52625 +               return 0;
52626 +
52627 +       } else if (argc != 1) {
52628 +               return KDB_ARGCOUNT;
52629 +       }
52630 +
52631 +       ret = kdbgetularg(argv[1], (unsigned long *) &ulong_partid);
52632 +       if (ret) {
52633 +               return ret;
52634 +       }
52635 +       partid = (partid_t) ulong_partid;
52636 +       if (partid < 0 || partid >= XP_MAX_PARTITIONS) {
52637 +               kdb_printf("invalid partid\n");
52638 +               return KDB_BADINT;
52639 +       }
52640 +
52641 +       vars_part = (struct xpc_vars_part *) __va(xpc_vars->vars_part_pa);
52642 +       DBUG_ON(vars_part == NULL);
52643 +
52644 +       if (partid == 0) {
52645 +
52646 +               /* display all initialized xpc_vars_part structure */
52647 +
52648 +               for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
52649 +                       if (vars_part[partid].magic == 0) {
52650 +                               continue;
52651 +                       }
52652 +                       kdbm_xpc_print_vars_part(&vars_part[partid], partid);
52653 +               }
52654 +
52655 +       } else {
52656 +
52657 +               /* display specified xpc_vars_part structure */
52658 +
52659 +               if (vars_part[partid].magic != 0) {
52660 +                       kdbm_xpc_print_vars_part(&vars_part[partid], partid);
52661 +               } else {
52662 +                       kdb_printf("struct xpc_vars_part for partid %d not "
52663 +                               "initialized\n", partid);
52664 +               }
52665 +       }
52666 +
52667 +       return 0;
52668 +}
52669 +
52670 +
52671 +static void
52672 +kdbm_xpc_print_engaged(char *string, u64 mask, int verbose)
52673 +{
52674 +       partid_t partid;
52675 +
52676 +
52677 +       kdb_printf("%s=0x%lx", string, mask);
52678 +
52679 +       if (verbose) {
52680 +               partid = 0;
52681 +               while (mask != 0) {
52682 +                       if (mask & 1UL) {
52683 +                               kdb_printf(" %d", partid);
52684 +                       }
52685 +                       partid++;
52686 +                       mask >>= 1;
52687 +               }
52688 +       }
52689 +       kdb_printf("\n");
52690 +}
52691 +
52692 +
52693 +/*
52694 + * Display XPC's 'engaged partitions' and 'disengage request' AMOs.
52695 + *
52696 + *      xpcengaged [ -v ]
52697 + *
52698 + *         -v  - verbose mode, displays partition numbers.
52699 + */
52700 +static int
52701 +kdbm_xpc_engaged(int argc, const char **argv)
52702 +{
52703 +       int nextarg = 1;
52704 +       int verbose = 0;
52705 +       u64 mask;
52706 +
52707 +
52708 +       if (argc > 1) {
52709 +               return KDB_ARGCOUNT;
52710 +       }
52711 +       if (argc == 1) {
52712 +               if (strcmp(argv[nextarg], "-v") != 0) {
52713 +                       return KDB_ARGCOUNT;
52714 +               }
52715 +               verbose = 1;
52716 +       }
52717 +
52718 +       mask = xpc_partition_engaged(-1UL);
52719 +       kdbm_xpc_print_engaged("engaged partitions", mask, verbose);
52720 +
52721 +       mask = xpc_partition_disengage_requested(-1UL);
52722 +       kdbm_xpc_print_engaged("disengage request", mask, verbose);
52723 +
52724 +       return 0;
52725 +}
52726 +
52727 +
52728 +static void
52729 +kdbm_xpc_print_IPI_flags_for_channel(u8 IPI_flags)
52730 +{
52731 +       if (IPI_flags & XPC_IPI_MSGREQUEST)   kdb_printf(" MSGREQUEST");
52732 +       if (IPI_flags & XPC_IPI_OPENREPLY)    kdb_printf(" OPENREPLY");
52733 +       if (IPI_flags & XPC_IPI_OPENREQUEST)  kdb_printf(" OPENREQUEST");
52734 +       if (IPI_flags & XPC_IPI_CLOSEREPLY)   kdb_printf(" CLOSEREPLY");
52735 +       if (IPI_flags & XPC_IPI_CLOSEREQUEST) kdb_printf(" CLOSEREQUEST");
52736 +}
52737 +
52738 +
52739 +static void
52740 +kdbm_xpc_print_IPI_flags(u64 IPI_amo)
52741 +{
52742 +       int ch_number;
52743 +       u8 IPI_flags;
52744 +
52745 +
52746 +       for (ch_number = 0; ch_number < XPC_NCHANNELS; ch_number++) {
52747 +
52748 +               /* get the IPI flags for the specific channel */
52749 +               IPI_flags = XPC_GET_IPI_FLAGS(IPI_amo, ch_number);
52750 +               if (IPI_flags == 0) {
52751 +                       continue;
52752 +               }
52753 +
52754 +               kdb_printf("\t    channel_%d=0x%x", ch_number, IPI_flags);
52755 +               kdbm_xpc_print_IPI_flags_for_channel(IPI_flags);
52756 +               kdb_printf("\n");
52757 +       }
52758 +}
52759 +
52760 +
52761 +static void
52762 +kdbm_xpc_print_part(struct xpc_partition *part, partid_t partid)
52763 +{
52764 +       kdb_printf("xpc_partitions[partid=%d] (0x%p):\n", partid,
52765 +                                                       (void *) part);
52766 +       kdb_printf("\tremote_rp_version=0x%x %d.%d\n", part->remote_rp_version,
52767 +                               XPC_VERSION_MAJOR(part->remote_rp_version),
52768 +                               XPC_VERSION_MINOR(part->remote_rp_version));
52769 +       kdb_printf("\tremote_rp_stamp=0x%lx:0x%lx\n",
52770 +               part->remote_rp_stamp.tv_sec, part->remote_rp_stamp.tv_nsec);
52771 +       kdb_printf("\tremote_rp_pa=0x%lx\n", part->remote_rp_pa);
52772 +       kdb_printf("\tremote_vars_pa=0x%lx\n", part->remote_vars_pa);
52773 +       kdb_printf("\tremote_vars_part_pa=0x%lx\n", part->remote_vars_part_pa);
52774 +       kdb_printf("\tlast_heartbeat=%ld\n", part->last_heartbeat);
52775 +       kdb_printf("\tremote_amos_page_pa=0x%lx\n", part->remote_amos_page_pa);
52776 +       kdb_printf("\tremote_act_nasid=0x%x\n", part->remote_act_nasid);
52777 +       kdb_printf("\tremote_act_phys_cpuid=0x%x\n",
52778 +                                               part->remote_act_phys_cpuid);
52779 +       kdb_printf("\tact_IRQ_rcvd=%d\n", part->act_IRQ_rcvd);
52780 +       kdb_printf("\tact_state=%d", part->act_state);
52781 +       switch (part->act_state) {
52782 +       case XPC_P_INACTIVE:          kdb_printf(" INACTIVE\n"); break;
52783 +       case XPC_P_ACTIVATION_REQ:    kdb_printf(" ACTIVATION_REQ\n"); break;
52784 +       case XPC_P_ACTIVATING:        kdb_printf(" ACTIVATING\n"); break;
52785 +       case XPC_P_ACTIVE:            kdb_printf(" ACTIVE\n"); break;
52786 +       case XPC_P_DEACTIVATING:      kdb_printf(" DEACTIVATING\n"); break;
52787 +       default:                      kdb_printf(" unknown\n");
52788 +       }
52789 +       kdb_printf("\tremote_vars_version=0x%x %d.%d\n",
52790 +                               part->remote_vars_version,
52791 +                               XPC_VERSION_MAJOR(part->remote_vars_version),
52792 +                               XPC_VERSION_MINOR(part->remote_vars_version));
52793 +       kdb_printf("\treactivate_nasid=%d\n", part->reactivate_nasid);
52794 +       kdb_printf("\treason=%d %s\n", part->reason,
52795 +                               kdbm_xpc_get_ascii_reason_code(part->reason));
52796 +       kdb_printf("\treason_line=%d\n", part->reason_line);
52797 +
52798 +       kdb_printf("\tdisengage_request_timeout=0x%lx\n",
52799 +                               part->disengage_request_timeout);
52800 +       kdb_printf("\t&disengage_request_timer=0x%p\n",
52801 +                               (void *) &part->disengage_request_timer);
52802 +
52803 +       kdb_printf("\tsetup_state=%d", part->setup_state);
52804 +       switch (part->setup_state) {
52805 +       case XPC_P_UNSET:       kdb_printf(" UNSET\n"); break;
52806 +       case XPC_P_SETUP:       kdb_printf(" SETUP\n"); break;
52807 +       case XPC_P_WTEARDOWN:   kdb_printf(" WTEARDOWN\n"); break;
52808 +       case XPC_P_TORNDOWN:    kdb_printf(" TORNDOWN\n"); break;
52809 +       default:                kdb_printf(" unknown\n");
52810 +       }
52811 +       kdb_printf("\treferences=%d\n", atomic_read(&part->references));
52812 +       kdb_printf("\tnchannels=%d\n", part->nchannels);
52813 +       kdb_printf("\tnchannels_active=%d\n",
52814 +                                       atomic_read(&part->nchannels_active));
52815 +       kdb_printf("\tnchannels_engaged=%d\n",
52816 +                                       atomic_read(&part->nchannels_engaged));
52817 +       kdb_printf("\tchannels=0x%p\n", (void *) part->channels);
52818 +       kdb_printf("\tlocal_GPs=0x%p\n", (void *) part->local_GPs);
52819 +       kdb_printf("\tremote_GPs=0x%p\n", (void *) part->remote_GPs);
52820 +       kdb_printf("\tremote_GPs_pa=0x%lx\n", part->remote_GPs_pa);
52821 +       kdb_printf("\tlocal_openclose_args=0x%p\n",
52822 +                                       (void *) part->local_openclose_args);
52823 +       kdb_printf("\tremote_openclose_args=0x%p\n",
52824 +                                       (void *) part->remote_openclose_args);
52825 +       kdb_printf("\tremote_openclose_args_pa=0x%lx\n",
52826 +                                       part->remote_openclose_args_pa);
52827 +       kdb_printf("\tremote_IPI_nasid=0x%x\n", part->remote_IPI_nasid);
52828 +       kdb_printf("\tremote_IPI_phys_cpuid=0x%x\n",
52829 +                                       part->remote_IPI_phys_cpuid);
52830 +       kdb_printf("\tremote_IPI_amo_va=0x%p\n",
52831 +                                       (void *) part->remote_IPI_amo_va);
52832 +       kdb_printf("\tlocal_IPI_amo_va=0x%p\n",
52833 +                                       (void *) part->local_IPI_amo_va);
52834 +       kdb_printf("\tlocal_IPI_amo=0x%lx\n", part->local_IPI_amo);
52835 +       kdbm_xpc_print_IPI_flags(part->local_IPI_amo);
52836 +       kdb_printf("\tIPI_owner=%s\n", part->IPI_owner);
52837 +       kdb_printf("\t&dropped_IPI_timer=0x%p\n",
52838 +                                       (void *) &part->dropped_IPI_timer);
52839 +
52840 +       kdb_printf("\tchannel_mgr_requests=%d\n", atomic_read(&part->
52841 +                                                       channel_mgr_requests));
52842 +}
52843 +
52844 +
52845 +/*
52846 + * Display XPC partitions.
52847 + *
52848 + *     xpcpart [ <vaddr> | <partid> ]
52849 + */
52850 +static int
52851 +kdbm_xpc_partitions(int argc, const char **argv)
52852 +{
52853 +       int ret;
52854 +       int nextarg = 1;
52855 +       long offset = 0;
52856 +       unsigned long addr;
52857 +       struct xpc_partition *part;
52858 +       partid_t partid;
52859 +
52860 +
52861 +       if (argc > 1) {
52862 +               return KDB_ARGCOUNT;
52863 +
52864 +       } else if (argc == 1) {
52865 +               ret = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset,
52866 +                                                               NULL);
52867 +               if (ret) {
52868 +                       return ret;
52869 +               }
52870 +               if (addr > 0 && addr < XP_MAX_PARTITIONS) {
52871 +                       partid = (partid_t) addr;
52872 +                       part = &xpc_partitions[partid];
52873 +               } else {
52874 +                       part = (struct xpc_partition *) addr;
52875 +                       partid = part - &xpc_partitions[0];
52876 +                       if (partid <= 0 || partid >= XP_MAX_PARTITIONS ||
52877 +                                       part != &xpc_partitions[partid]) {
52878 +                               kdb_printf("invalid partition entry address\n");
52879 +                               return KDB_BADADDR;
52880 +                       }
52881 +               }
52882 +               kdbm_xpc_print_part(part, partid);
52883 +
52884 +       } else {
52885 +               for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
52886 +                       part = &xpc_partitions[partid];
52887 +                       if (part->setup_state == XPC_P_UNSET &&
52888 +                                                       part->reason == 0) {
52889 +                               continue;
52890 +                       }
52891 +                       kdbm_xpc_print_part(part, partid);
52892 +               }
52893 +       }
52894 +       return 0;
52895 +}
52896 +
52897 +
52898 +static void
52899 +kdbm_xpc_print_channel_flags(u32 flags)
52900 +{
52901 +       kdb_printf("\tflags=0x%x", flags);
52902 +
52903 +       if (flags & XPC_C_WDISCONNECT)          kdb_printf(" WDISCONNECT");
52904 +       if (flags & XPC_C_DISCONNECTINGCALLOUT_MADE) kdb_printf(" DISCONNECTINGCALLOUT_MADE");
52905 +       if (flags & XPC_C_DISCONNECTINGCALLOUT) kdb_printf(" DISCONNECTINGCALLOUT");
52906 +       if (flags & XPC_C_DISCONNECTING)        kdb_printf(" DISCONNECTING");
52907 +       if (flags & XPC_C_DISCONNECTED)         kdb_printf(" DISCONNECTED");
52908 +
52909 +       if (flags & XPC_C_CLOSEREQUEST)         kdb_printf(" CLOSEREQUEST");
52910 +       if (flags & XPC_C_RCLOSEREQUEST)        kdb_printf(" RCLOSEREQUEST");
52911 +       if (flags & XPC_C_CLOSEREPLY)           kdb_printf(" CLOSEREPLY");
52912 +       if (flags & XPC_C_RCLOSEREPLY)          kdb_printf(" RCLOSEREPLY");
52913 +
52914 +       if (flags & XPC_C_CONNECTING)           kdb_printf(" CONNECTING");
52915 +       if (flags & XPC_C_CONNECTED)            kdb_printf(" CONNECTED");
52916 +       if (flags & XPC_C_CONNECTEDCALLOUT_MADE) kdb_printf(" CONNECTEDCALLOUT_MADE");
52917 +       if (flags & XPC_C_CONNECTEDCALLOUT)     kdb_printf(" CONNECTEDCALLOUT");
52918 +       if (flags & XPC_C_SETUP)                kdb_printf(" SETUP");
52919 +
52920 +       if (flags & XPC_C_OPENREQUEST)          kdb_printf(" OPENREQUEST");
52921 +       if (flags & XPC_C_ROPENREQUEST)         kdb_printf(" ROPENREQUEST");
52922 +       if (flags & XPC_C_OPENREPLY)            kdb_printf(" OPENREPLY");
52923 +       if (flags & XPC_C_ROPENREPLY)           kdb_printf(" ROPENREPLY");
52924 +
52925 +       if (flags & XPC_C_WASCONNECTED)         kdb_printf(" WASCONNECTED");
52926 +
52927 +       kdb_printf("\n");
52928 +}
52929 +
52930 +
52931 +static void
52932 +kdbm_xpc_print_channel(struct xpc_channel *ch)
52933 +{
52934 +       kdb_printf("channel %d (0x%p):\n", ch->number, (void *) ch);
52935 +       kdb_printf("\tpartid=%d\n", ch->partid);
52936 +
52937 +       kdbm_xpc_print_channel_flags(ch->flags);
52938 +
52939 +       kdb_printf("\treason=%d %s\n", ch->reason,
52940 +                               kdbm_xpc_get_ascii_reason_code(ch->reason));
52941 +       kdb_printf("\treason_line=%d\n", ch->reason_line);
52942 +       kdb_printf("\tnumber=%d\n", ch->number);
52943 +       kdb_printf("\tmsg_size=%d\n", ch->msg_size);
52944 +       kdb_printf("\tlocal_nentries=%d\n", ch->local_nentries);
52945 +       kdb_printf("\tremote_nentries=%d\n", ch->remote_nentries);
52946 +       kdb_printf("\tlocal_msgqueue=0x%p\n", (void *) ch->local_msgqueue);
52947 +       kdb_printf("\tremote_msgqueue_pa=0x%lx\n", ch->remote_msgqueue_pa);
52948 +       kdb_printf("\tremote_msgqueue=0x%p\n",
52949 +                                       (void *) ch->remote_msgqueue);
52950 +       kdb_printf("\treferences=%d\n", atomic_read(&ch->references));
52951 +       kdb_printf("\tn_on_msg_allocate_wq=%d\n",
52952 +                               atomic_read(&ch->n_on_msg_allocate_wq));
52953 +       kdb_printf("\t&msg_allocate_wq=0x%p\n",
52954 +                               (void *) &ch->msg_allocate_wq);
52955 +
52956 +       kdb_printf("\tdelayed_IPI_flags=0x%x", ch->delayed_IPI_flags);
52957 +       kdbm_xpc_print_IPI_flags_for_channel(ch->delayed_IPI_flags);
52958 +       kdb_printf("\n");
52959 +
52960 +       kdb_printf("\tn_to_notify=%d\n", atomic_read(&ch->n_to_notify));
52961 +       kdb_printf("\tnotify_queue=0x%p\n", (void *) ch->notify_queue);
52962 +       kdb_printf("\tfunc=0x%p\n", (void *) ch->func);
52963 +       kdb_printf("\tkey=0x%p\n", ch->key);
52964 +       kdb_printf("\t&msg_to_pull_mutex=0x%p\n",
52965 +                                       (void *) &ch->msg_to_pull_mutex);
52966 +       kdb_printf("\t&wdisconnect_wait=0x%p\n",
52967 +                                       (void *) &ch->wdisconnect_wait);
52968 +       kdb_printf("\tlocal_GP=0x%p (%ld:%ld)\n", (void *) ch->local_GP,
52969 +                                               ch->local_GP->get,
52970 +                                               ch->local_GP->put);
52971 +       kdb_printf("\tremote_GP=%ld:%ld\n", ch->remote_GP.get,
52972 +                                               ch->remote_GP.put);
52973 +       kdb_printf("\tw_local_GP=%ld:%ld\n", ch->w_local_GP.get,
52974 +                                               ch->w_local_GP.put);
52975 +       kdb_printf("\tw_remote_GP=%ld:%ld\n", ch->w_remote_GP.get,
52976 +                                               ch->w_remote_GP.put);
52977 +       kdb_printf("\tnext_msg_to_pull=%ld\n", ch->next_msg_to_pull);
52978 +       kdb_printf("\tkthreads_assigned=%d\n",
52979 +                               atomic_read(&ch->kthreads_assigned));
52980 +       kdb_printf("\tkthreads_assigned_limit=%d\n",
52981 +                               ch->kthreads_assigned_limit);
52982 +       kdb_printf("\tkthreads_idle=%d\n",
52983 +                               atomic_read(&ch->kthreads_idle));
52984 +       kdb_printf("\tkthreads_idle_limit=%d\n", ch->kthreads_idle_limit);
52985 +       kdb_printf("\tkthreads_active=%d\n",
52986 +                               atomic_read(&ch->kthreads_active));
52987 +       kdb_printf("\tkthreads_created=%d\n", ch->kthreads_created);
52988 +       kdb_printf("\t&idle_wq=0x%p\n", (void *) &ch->idle_wq);
52989 +
52990 +       if (ch->flags & XPC_C_CONNECTED) {
52991 +               kdb_printf("\n\t#of local msg queue entries available =%ld\n",
52992 +                               ch->local_nentries - (ch->w_local_GP.put -
52993 +                                                       ch->w_remote_GP.get));
52994 +
52995 +               kdb_printf("\t#of local msgs allocated !sent =%ld\n",
52996 +                               ch->w_local_GP.put - ch->local_GP->put);
52997 +               kdb_printf("\t#of local msgs allocated sent !ACK'd =%ld\n",
52998 +                               ch->local_GP->put - ch->remote_GP.get);
52999 +               kdb_printf("\t#of local msgs allocated sent ACK'd !notified ="
53000 +                       "%ld\n", ch->remote_GP.get - ch->w_remote_GP.get);
53001 +
53002 +               kdb_printf("\t#of remote msgs sent !pulled =%ld\n",
53003 +                               ch->w_remote_GP.put - ch->next_msg_to_pull);
53004 +               kdb_printf("\t#of remote msgs sent !delivered =%ld\n",
53005 +                               ch->next_msg_to_pull - ch->w_local_GP.get);
53006 +               kdb_printf("\t#of remote msgs sent delivered !received =%ld\n",
53007 +                               ch->w_local_GP.get - ch->local_GP->get);
53008 +       }
53009 +}
53010 +
53011 +
53012 +/*
53013 + * Display a XPC partition's channels.
53014 + *
53015 + *     xpcchan <vaddr> | <partid> [ <channel> ]
53016 + */
53017 +static int
53018 +kdbm_xpc_channels(int argc, const char **argv)
53019 +{
53020 +       int ret;
53021 +       int nextarg = 1;
53022 +       long offset = 0;
53023 +       unsigned long addr;
53024 +       partid_t partid;
53025 +       struct xpc_partition *part;
53026 +       int ch_number;
53027 +       struct xpc_channel *ch;
53028 +
53029 +
53030 +       if (argc < 1 || argc > 2) {
53031 +               return KDB_ARGCOUNT;
53032 +       }
53033 +
53034 +       ret = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL);
53035 +       if (ret) {
53036 +               return ret;
53037 +       }
53038 +       if (addr > 0 && addr < XP_MAX_PARTITIONS) {
53039 +               partid = (partid_t) addr;
53040 +               part = &xpc_partitions[partid];
53041 +               if (part->setup_state == XPC_P_UNSET) {
53042 +                       kdb_printf("partition is UNSET\n");
53043 +                       return 0;
53044 +               }
53045 +               if (part->setup_state == XPC_P_TORNDOWN) {
53046 +                       kdb_printf("partition is TORNDOWN\n");
53047 +                       return 0;
53048 +               }
53049 +
53050 +               if (argc == 2) {
53051 +                       ret = kdbgetularg(argv[2],
53052 +                                       (unsigned long *) &ch_number);
53053 +                       if (ret) {
53054 +                               return ret;
53055 +                       }
53056 +                       if (ch_number < 0 || ch_number >= part->nchannels) {
53057 +                               kdb_printf("invalid channel #\n");
53058 +                               return KDB_BADINT;
53059 +                       }
53060 +                       kdbm_xpc_print_channel(&part->channels[ch_number]);
53061 +               } else {
53062 +                       for (ch_number = 0; ch_number < part->nchannels;
53063 +                                                               ch_number++) {
53064 +                               kdbm_xpc_print_channel(&part->
53065 +                                                       channels[ch_number]);
53066 +                       }
53067 +               }
53068 +
53069 +       } else {
53070 +               ch = (struct xpc_channel *) addr;
53071 +
53072 +               for (partid = 1; partid < XP_MAX_PARTITIONS; partid++) {
53073 +                       part = &xpc_partitions[partid];
53074 +                       if (part->setup_state != XPC_P_UNSET &&
53075 +                                       part->setup_state != XPC_P_TORNDOWN &&
53076 +                                               ch >= part->channels) {
53077 +                               ch_number = ch - part->channels;
53078 +                               if (ch_number < part->nchannels &&
53079 +                                            ch == &part->channels[ch_number]) {
53080 +                                       break;
53081 +                               }
53082 +                       }
53083 +               }
53084 +               if (partid == XP_MAX_PARTITIONS) {
53085 +                       kdb_printf("invalid channel address\n");
53086 +                       return KDB_BADADDR;
53087 +               }
53088 +               kdbm_xpc_print_channel(ch);
53089 +       }
53090 +
53091 +       return 0;
53092 +}
53093 +
53094 +
53095 +static void
53096 +kdbm_xpc_print_local_msgqueue(struct xpc_channel *ch)
53097 +{
53098 +       int i;
53099 +       char *prefix;
53100 +       struct xpc_msg *msg = ch->local_msgqueue;
53101 +       s64 w_remote_GP_get = ch->w_remote_GP.get % ch->local_nentries;
53102 +       s64 remote_GP_get = ch->remote_GP.get % ch->local_nentries;
53103 +       s64 local_GP_put = ch->local_GP->put % ch->local_nentries;
53104 +       s64 w_local_GP_put = ch->w_local_GP.put % ch->local_nentries;
53105 +
53106 +
53107 +       kdb_printf("local message queue (0x%p):\n\n", (void *) msg);
53108 +
53109 +       for (i = 0; i < ch->local_nentries; i++) {
53110 +               kdb_printf("0x%p: flags=0x%x number=%ld", (void *) msg,
53111 +                               msg->flags, msg->number);
53112 +
53113 +               prefix = "  <--";
53114 +
53115 +               if (i == w_remote_GP_get) {
53116 +                       kdb_printf("%s w_remote_GP.get", prefix);
53117 +                       prefix = ",";
53118 +               }
53119 +               if (i == remote_GP_get) {
53120 +                       kdb_printf("%s remote_GP.get", prefix);
53121 +                       prefix = ",";
53122 +               }
53123 +               if (i == local_GP_put) {
53124 +                       kdb_printf("%s local_GP->put", prefix);
53125 +                       prefix = ",";
53126 +               }
53127 +               if (i == w_local_GP_put) {
53128 +                       kdb_printf("%s w_local_GP.put", prefix);
53129 +               }
53130 +               kdb_printf("\n");
53131 +
53132 +               msg = (struct xpc_msg *) ((u64) msg + ch->msg_size);
53133 +       }
53134 +}
53135 +
53136 +
53137 +static void
53138 +kdbm_xpc_print_remote_msgqueue(struct xpc_channel *ch)
53139 +{
53140 +       int i;
53141 +       char *prefix;
53142 +       struct xpc_msg *msg = ch->remote_msgqueue;
53143 +       s64 local_GP_get = ch->local_GP->get % ch->remote_nentries;
53144 +       s64 w_local_GP_get = ch->w_local_GP.get % ch->remote_nentries;
53145 +       s64 next_msg_to_pull = ch->next_msg_to_pull % ch->remote_nentries;
53146 +       s64 w_remote_GP_put = ch->w_remote_GP.put % ch->remote_nentries;
53147 +       s64 remote_GP_put = ch->remote_GP.put % ch->remote_nentries;
53148 +
53149 +
53150 +       kdb_printf("cached remote message queue (0x%p):\n\n", (void *) msg);
53151 +
53152 +       for (i = 0; i < ch->remote_nentries; i++) {
53153 +               kdb_printf("0x%p: flags=0x%x number=%ld", (void *) msg,
53154 +                               msg->flags, msg->number);
53155 +
53156 +               prefix = "  <--";
53157 +
53158 +               if (i == local_GP_get) {
53159 +                       kdb_printf("%s local_GP->get", prefix);
53160 +                       prefix = ",";
53161 +               }
53162 +               if (i == w_local_GP_get) {
53163 +                       kdb_printf("%s w_local_GP.get", prefix);
53164 +                       prefix = ",";
53165 +               }
53166 +               if (i == next_msg_to_pull) {
53167 +                       kdb_printf("%s next_msg_to_pull", prefix);
53168 +                       prefix = ",";
53169 +               }
53170 +               if (i == w_remote_GP_put) {
53171 +                       kdb_printf("%s w_remote_GP.put", prefix);
53172 +                       prefix = ",";
53173 +               }
53174 +               if (i == remote_GP_put) {
53175 +                       kdb_printf("%s remote_GP.put", prefix);
53176 +               }
53177 +               kdb_printf("\n");
53178 +
53179 +               msg = (struct xpc_msg *) ((u64) msg + ch->msg_size);
53180 +       }
53181 +}
53182 +
53183 +
53184 +/*
53185 + * Display XPC specified message queue.
53186 + *
53187 + *     xpcmque <partid> <channel> local|remote
53188 + */
53189 +static int
53190 +kdbm_xpc_msgqueue(int argc, const char **argv)
53191 +{
53192 +       int ret, ch_number;
53193 +       unsigned long ulong_partid;
53194 +       partid_t partid;
53195 +       struct xpc_partition *part;
53196 +       struct xpc_channel *ch;
53197 +
53198 +
53199 +       if (argc != 3) {
53200 +               return KDB_ARGCOUNT;
53201 +       }
53202 +
53203 +       ret = kdbgetularg(argv[1], (unsigned long *) &ulong_partid);
53204 +       if (ret) {
53205 +               return ret;
53206 +       }
53207 +       partid = (partid_t) ulong_partid;
53208 +       if (partid <= 0 || partid >= XP_MAX_PARTITIONS) {
53209 +               kdb_printf("invalid partid\n");
53210 +               return KDB_BADINT;
53211 +       }
53212 +
53213 +       ret = kdbgetularg(argv[2], (unsigned long *) &ch_number);
53214 +       if (ret) {
53215 +               return ret;
53216 +       }
53217 +       if (ch_number < 0 || ch_number >= XPC_NCHANNELS) {
53218 +               kdb_printf("invalid channel #\n");
53219 +               return KDB_BADINT;
53220 +       }
53221 +
53222 +       part = &xpc_partitions[partid];
53223 +
53224 +       if (part->setup_state == XPC_P_UNSET) {
53225 +               kdb_printf("partition is UNSET\n");
53226 +               return 0;
53227 +       }
53228 +       if (part->setup_state == XPC_P_TORNDOWN) {
53229 +               kdb_printf("partition is TORNDOWN\n");
53230 +               return 0;
53231 +       }
53232 +
53233 +       if (ch_number >= part->nchannels) {
53234 +               kdb_printf("unsupported channel #\n");
53235 +               return KDB_BADINT;
53236 +       }
53237 +
53238 +       ch = &part->channels[ch_number];
53239 +
53240 +       if (!(ch->flags & XPC_C_SETUP)) {
53241 +               kdb_printf("message queues are not SETUP\n");
53242 +               return 0;
53243 +       }
53244 +
53245 +       if (strcmp(argv[3], "r") == 0 || strcmp(argv[3], "remote") == 0) {
53246 +               kdbm_xpc_print_remote_msgqueue(ch);
53247 +       } else if (strcmp(argv[3], "l") == 0 || strcmp(argv[3], "local") == 0) {
53248 +               kdbm_xpc_print_local_msgqueue(ch);
53249 +       } else {
53250 +               kdb_printf("unknown msg queue selected\n");
53251 +               return KDB_BADINT;
53252 +       }
53253 +
53254 +       return 0;
53255 +}
53256 +
53257 +
53258 +static void
53259 +kdbm_xpc_print_msg_flags(u8 flags)
53260 +{
53261 +       kdb_printf("\tflags=0x%x", flags);
53262 +
53263 +       if (flags & XPC_M_INTERRUPT)    kdb_printf(" INTERRUPT");
53264 +       if (flags & XPC_M_READY)        kdb_printf(" READY");
53265 +       if (flags & XPC_M_DONE)         kdb_printf(" DONE");
53266 +
53267 +       kdb_printf("\n");
53268 +}
53269 +
53270 +
53271 +/*
53272 + * Display XPC message.
53273 + *
53274 + *     xpcmsg <vaddr>
53275 + */
53276 +static int
53277 +kdbm_xpc_msg(int argc, const char **argv)
53278 +{
53279 +       int ret, nextarg = argc;
53280 +       long offset = 0;
53281 +       unsigned long addr;
53282 +       struct xpc_msg *msg;
53283 +
53284 +
53285 +       if (argc != 1) {
53286 +               return KDB_ARGCOUNT;
53287 +       }
53288 +
53289 +       ret = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL);
53290 +       if (ret) {
53291 +               return ret;
53292 +       }
53293 +
53294 +       msg = (struct xpc_msg *) addr;
53295 +       kdb_printf("msg (0x%p):\n", (void *) msg);
53296 +       kdbm_xpc_print_msg_flags(msg->flags);
53297 +       kdb_printf("\tnumber=%ld\n", msg->number);
53298 +       kdb_printf("\t&payload=0x%p\n", (void *) &msg->payload);
53299 +
53300 +       return 0;
53301 +}
53302 +
53303 +
53304 +static void
53305 +kdbm_xpc_print_notify_queue(struct xpc_channel *ch)
53306 +{
53307 +       int i;
53308 +       char *prefix;
53309 +       struct xpc_notify *notify = ch->notify_queue;
53310 +       s64 w_remote_GP_get = ch->w_remote_GP.get % ch->local_nentries;
53311 +       s64 remote_GP_get = ch->remote_GP.get % ch->local_nentries;
53312 +       s64 local_GP_put = ch->local_GP->put % ch->local_nentries;
53313 +       s64 w_local_GP_put = ch->w_local_GP.put % ch->local_nentries;
53314 +
53315 +
53316 +       kdb_printf("notify queue (0x%p):\n\n", (void *) notify);
53317 +
53318 +       for (i = 0; i < ch->local_nentries; i++) {
53319 +               kdb_printf("0x%p: type=0x%x", (void *) notify, notify->type);
53320 +
53321 +               if (notify->type == XPC_N_CALL) {
53322 +                       kdb_printf(" CALL  func=0x%p key=0x%p",
53323 +                                       (void *) notify->func, notify->key);
53324 +               }
53325 +
53326 +               prefix = "  <--";
53327 +
53328 +               if (i == w_remote_GP_get) {
53329 +                       kdb_printf("%s w_remote_GP.get", prefix);
53330 +                       prefix = ",";
53331 +               }
53332 +               if (i == remote_GP_get) {
53333 +                       kdb_printf("%s remote_GP.get", prefix);
53334 +                       prefix = ",";
53335 +               }
53336 +               if (i == local_GP_put) {
53337 +                       kdb_printf("%s local_GP->put", prefix);
53338 +                       prefix = ",";
53339 +               }
53340 +               if (i == w_local_GP_put) {
53341 +                       kdb_printf("%s w_local_GP.put", prefix);
53342 +               }
53343 +               kdb_printf("\n");
53344 +
53345 +               notify++;
53346 +       }
53347 +}
53348 +
53349 +
53350 +/*
53351 + * Display XPC specified notify queue.
53352 + *
53353 + *     xpcnque <partid> <channel>
53354 + */
53355 +static int
53356 +kdbm_xpc_notify_queue(int argc, const char **argv)
53357 +{
53358 +       int ret, ch_number;
53359 +       unsigned long ulong_partid;
53360 +       partid_t partid;
53361 +       struct xpc_partition *part;
53362 +       struct xpc_channel *ch;
53363 +
53364 +
53365 +       if (argc != 2) {
53366 +               return KDB_ARGCOUNT;
53367 +       }
53368 +
53369 +       ret = kdbgetularg(argv[1], (unsigned long *) &ulong_partid);
53370 +       if (ret) {
53371 +               return ret;
53372 +       }
53373 +       partid = (partid_t) ulong_partid;
53374 +       if (partid <= 0 || partid >= XP_MAX_PARTITIONS) {
53375 +               kdb_printf("invalid partid\n");
53376 +               return KDB_BADINT;
53377 +       }
53378 +
53379 +       ret = kdbgetularg(argv[2], (unsigned long *) &ch_number);
53380 +       if (ret) {
53381 +               return ret;
53382 +       }
53383 +       if (ch_number < 0 || ch_number >= XPC_NCHANNELS) {
53384 +               kdb_printf("invalid channel #\n");
53385 +               return KDB_BADINT;
53386 +       }
53387 +
53388 +       part = &xpc_partitions[partid];
53389 +
53390 +       if (part->setup_state == XPC_P_UNSET) {
53391 +               kdb_printf("partition is UNSET\n");
53392 +               return 0;
53393 +       }
53394 +       if (part->setup_state == XPC_P_TORNDOWN) {
53395 +               kdb_printf("partition is TORNDOWN\n");
53396 +               return 0;
53397 +       }
53398 +
53399 +       if (ch_number >= part->nchannels) {
53400 +               kdb_printf("unsupported channel #\n");
53401 +               return KDB_BADINT;
53402 +       }
53403 +
53404 +       ch = &part->channels[ch_number];
53405 +
53406 +       if (!(ch->flags & XPC_C_SETUP)) {
53407 +               kdb_printf("notify queue is not SETUP\n");
53408 +               return 0;
53409 +       }
53410 +
53411 +       kdbm_xpc_print_notify_queue(ch);
53412 +
53413 +       return 0;
53414 +}
53415 +
53416 +
53417 +static void
53418 +kdbm_xpc_print_users(struct xpc_registration *registration, int ch_number)
53419 +{
53420 +       kdb_printf("xpc_registrations[channel=%d] (0x%p):\n", ch_number,
53421 +                                                       (void *) registration);
53422 +
53423 +       kdb_printf("\t&mutex=0x%p\n", (void *) &registration->mutex);
53424 +       kdb_printf("\tfunc=0x%p\n", (void *) registration->func);
53425 +       kdb_printf("\tkey=0x%p\n", registration->key);
53426 +       kdb_printf("\tnentries=%d\n", registration->nentries);
53427 +       kdb_printf("\tmsg_size=%d\n", registration->msg_size);
53428 +       kdb_printf("\tassigned_limit=%d\n", registration->assigned_limit);
53429 +       kdb_printf("\tidle_limit=%d\n", registration->idle_limit);
53430 +}
53431 +
53432 +
53433 +/*
53434 + * Display current XPC users who have registered via xpc_connect().
53435 + *
53436 + *     xpcusers [ <channel> ]
53437 + */
53438 +static int
53439 +kdbm_xpc_users(int argc, const char **argv)
53440 +{
53441 +       int ret;
53442 +       struct xpc_registration *registration;
53443 +       int ch_number;
53444 +
53445 +
53446 +       if (argc > 1) {
53447 +               return KDB_ARGCOUNT;
53448 +
53449 +       } else if (argc == 1) {
53450 +               ret = kdbgetularg(argv[1], (unsigned long *) &ch_number);
53451 +               if (ret) {
53452 +                       return ret;
53453 +               }
53454 +               if (ch_number < 0 || ch_number >= XPC_NCHANNELS) {
53455 +                       kdb_printf("invalid channel #\n");
53456 +                       return KDB_BADINT;
53457 +               }
53458 +               registration = &xpc_registrations[ch_number];
53459 +               kdbm_xpc_print_users(registration, ch_number);
53460 +
53461 +       } else {
53462 +               for (ch_number = 0; ch_number < XPC_NCHANNELS; ch_number++) {
53463 +                       registration = &xpc_registrations[ch_number];
53464 +
53465 +                       /* if !XPC_CHANNEL_REGISTERED(ch_number) */
53466 +                       if (registration->func == NULL) {
53467 +                               continue;
53468 +                       }
53469 +                       kdbm_xpc_print_users(registration, ch_number);
53470 +               }
53471 +       }
53472 +       return 0;
53473 +}
53474 +
53475 +
53476 +static int __init
53477 +kdbm_xpc_register(void)
53478 +{
53479 +       (void) kdb_register("xpcdown", kdbm_xpc_down, "",
53480 +                       "Mark this partition as being down", 0);
53481 +       (void) kdb_register("xpcrp", kdbm_xpc_rsvd_page, "",
53482 +                       "Display XPC reserved page", 0);
53483 +       (void) kdb_register("xpcvars", kdbm_xpc_variables, "[<partid>]",
53484 +                       "Display XPC variables", 0);
53485 +       (void) kdb_register("xpcengaged", kdbm_xpc_engaged, "[-v]",
53486 +                       "Display XPC engaged partitions AMOs", 0);
53487 +       (void) kdb_register("xpcpart", kdbm_xpc_partitions, "[<vaddr>|"
53488 +                       "<partid>]", "Display struct xpc_partition entries", 0);
53489 +       (void) kdb_register("xpcchan", kdbm_xpc_channels, "<vaddr> | <partid> "
53490 +                       "[<channel>]", "Display struct xpc_channel entries", 0);
53491 +       (void) kdb_register("xpcmque", kdbm_xpc_msgqueue, "<partid> <channel> "
53492 +                       "local|remote", "Display local or remote msg queue", 0);
53493 +       (void) kdb_register("xpcmsg", kdbm_xpc_msg, "<vaddr>",
53494 +                       "Display struct xpc_msg", 0);
53495 +       (void) kdb_register("xpcnque", kdbm_xpc_notify_queue, "<partid> "
53496 +                       "<channel>", "Display notify queue", 0);
53497 +       (void) kdb_register("xpcusers", kdbm_xpc_users, "[ <channel> ]",
53498 +                       "Display struct xpc_registration entries", 0);
53499 +       return 0;
53500 +}
53501 +
53502 +
53503 +static void __exit
53504 +kdbm_xpc_unregister(void)
53505 +{
53506 +       (void) kdb_unregister("xpcdown");
53507 +       (void) kdb_unregister("xpcrp");
53508 +       (void) kdb_unregister("xpcvars");
53509 +       (void) kdb_unregister("xpcengaged");
53510 +       (void) kdb_unregister("xpcpart");
53511 +       (void) kdb_unregister("xpcchan");
53512 +       (void) kdb_unregister("xpcmque");
53513 +       (void) kdb_unregister("xpcmsg");
53514 +       (void) kdb_unregister("xpcnque");
53515 +       (void) kdb_unregister("xpcusers");
53516 +}
53517 +
53518 +
53519 +module_init(kdbm_xpc_register);
53520 +module_exit(kdbm_xpc_unregister);
53521 +
53522 diff -Nurp linux-2.6.22-590/kdb/modules/Makefile linux-2.6.22-600/kdb/modules/Makefile
53523 --- linux-2.6.22-590/kdb/modules/Makefile       1970-01-01 01:00:00.000000000 +0100
53524 +++ linux-2.6.22-600/kdb/modules/Makefile       2008-04-09 18:14:28.000000000 +0200
53525 @@ -0,0 +1,14 @@
53526 +#
53527 +# This file is subject to the terms and conditions of the GNU General Public
53528 +# License.  See the file "COPYING" in the main directory of this archive
53529 +# for more details.
53530 +#
53531 +# Copyright (c) 1999-2006 Silicon Graphics, Inc.  All Rights Reserved.
53532 +#
53533 +
53534 +obj-$(CONFIG_KDB_MODULES) += kdbm_pg.o kdbm_task.o kdbm_vm.o kdbm_sched.o
53535 +ifdef CONFIG_X86
53536 +obj-$(CONFIG_KDB_MODULES) += kdbm_x86.o
53537 +endif
53538 +obj-$(CONFIG_KDB_MODULES_XP) += kdbm_xpc.o
53539 +CFLAGS_kdbm_vm.o       += -I $(srctree)/drivers/scsi
53540 diff -Nurp linux-2.6.22-590/kernel/exit.c linux-2.6.22-600/kernel/exit.c
53541 --- linux-2.6.22-590/kernel/exit.c      2008-04-09 18:10:53.000000000 +0200
53542 +++ linux-2.6.22-600/kernel/exit.c      2008-04-09 18:14:28.000000000 +0200
53543 @@ -4,6 +4,9 @@
53544   *  Copyright (C) 1991, 1992  Linus Torvalds
53545   */
53546  
53547 +#ifdef CONFIG_KDB
53548 +#include <linux/kdb.h>
53549 +#endif
53550  #include <linux/mm.h>
53551  #include <linux/slab.h>
53552  #include <linux/interrupt.h>
53553 diff -Nurp linux-2.6.22-590/kernel/kallsyms.c linux-2.6.22-600/kernel/kallsyms.c
53554 --- linux-2.6.22-590/kernel/kallsyms.c  2007-07-09 01:32:17.000000000 +0200
53555 +++ linux-2.6.22-600/kernel/kallsyms.c  2008-04-09 18:14:28.000000000 +0200
53556 @@ -491,3 +491,25 @@ __initcall(kallsyms_init);
53557  
53558  EXPORT_SYMBOL(__print_symbol);
53559  EXPORT_SYMBOL_GPL(sprint_symbol);
53560 +
53561 +#ifdef CONFIG_KDB
53562 +#include <linux/kdb.h>
53563 +#include <linux/kdbprivate.h>
53564 +
53565 +const char *kdb_walk_kallsyms(loff_t *pos)
53566 +{
53567 +       static struct kallsym_iter kdb_walk_kallsyms_iter;
53568 +       if (*pos == 0) {
53569 +               memset(&kdb_walk_kallsyms_iter, 0, sizeof(kdb_walk_kallsyms_iter));
53570 +               reset_iter(&kdb_walk_kallsyms_iter, 0);
53571 +       }
53572 +       while (1) {
53573 +               if (!update_iter(&kdb_walk_kallsyms_iter, *pos))
53574 +                       return NULL;
53575 +               ++*pos;
53576 +               /* Some debugging symbols have no name.  Ignore them. */
53577 +               if (kdb_walk_kallsyms_iter.name[0])
53578 +                       return kdb_walk_kallsyms_iter.name;
53579 +       }
53580 +}
53581 +#endif /* CONFIG_KDB */
53582 diff -Nurp linux-2.6.22-590/kernel/module.c linux-2.6.22-600/kernel/module.c
53583 --- linux-2.6.22-590/kernel/module.c    2007-07-09 01:32:17.000000000 +0200
53584 +++ linux-2.6.22-600/kernel/module.c    2008-04-09 18:14:28.000000000 +0200
53585 @@ -2176,12 +2176,23 @@ out:
53586         return -ERANGE;
53587  }
53588  
53589 +#ifdef CONFIG_KDB
53590 +#include <linux/kdb.h>
53591 +struct list_head *kdb_modules = &modules;      /* kdb needs the list of modules */
53592 +#endif /* CONFIG_KDB */
53593 +
53594  int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
53595                         char *name, char *module_name, int *exported)
53596  {
53597         struct module *mod;
53598 +#ifdef CONFIG_KDB
53599 +       int get_lock = !KDB_IS_RUNNING();
53600 +#else
53601 +#define        get_lock 1
53602 +#endif
53603  
53604 -       mutex_lock(&module_mutex);
53605 +       if (get_lock)
53606 +               mutex_lock(&module_mutex);
53607         list_for_each_entry(mod, &modules, list) {
53608                 if (symnum < mod->num_symtab) {
53609                         *value = mod->symtab[symnum].st_value;
53610 @@ -2190,12 +2201,14 @@ int module_get_kallsym(unsigned int symn
53611                                 KSYM_NAME_LEN + 1);
53612                         strlcpy(module_name, mod->name, MODULE_NAME_LEN + 1);
53613                         *exported = is_exported(name, mod);
53614 -                       mutex_unlock(&module_mutex);
53615 +                       if (get_lock)
53616 +                               mutex_unlock(&module_mutex);
53617                         return 0;
53618                 }
53619                 symnum -= mod->num_symtab;
53620         }
53621 -       mutex_unlock(&module_mutex);
53622 +       if (get_lock)
53623 +               mutex_unlock(&module_mutex);
53624         return -ERANGE;
53625  }
53626  
53627 diff -Nurp linux-2.6.22-590/kernel/printk.c linux-2.6.22-600/kernel/printk.c
53628 --- linux-2.6.22-590/kernel/printk.c    2008-04-09 18:10:53.000000000 +0200
53629 +++ linux-2.6.22-600/kernel/printk.c    2008-04-09 18:14:28.000000000 +0200
53630 @@ -313,6 +313,20 @@ asmlinkage long sys_syslog(int type, cha
53631         return do_syslog(type, buf, len);
53632  }
53633  
53634 +#ifdef CONFIG_KDB
53635 +/* kdb dmesg command needs access to the syslog buffer.  do_syslog() uses locks
53636 + * so it cannot be used during debugging.  Just tell kdb where the start and
53637 + * end of the physical and logical logs are.  This is equivalent to do_syslog(3).
53638 + */
53639 +void kdb_syslog_data(char *syslog_data[4])
53640 +{
53641 +       syslog_data[0] = log_buf;
53642 +       syslog_data[1] = log_buf + log_buf_len;
53643 +       syslog_data[2] = log_buf + log_end - (logged_chars < log_buf_len ? logged_chars : log_buf_len);
53644 +       syslog_data[3] = log_buf + log_end;
53645 +}
53646 +#endif /* CONFIG_KDB */
53647 +
53648  /*
53649   * Call the console drivers on a range of log_buf
53650   */
53651 diff -Nurp linux-2.6.22-590/kernel/sched.c linux-2.6.22-600/kernel/sched.c
53652 --- linux-2.6.22-590/kernel/sched.c     2008-04-09 18:11:16.000000000 +0200
53653 +++ linux-2.6.22-600/kernel/sched.c     2008-04-09 18:14:28.000000000 +0200
53654 @@ -7315,7 +7315,7 @@ void normalize_rt_tasks(void)
53655  
53656  #endif /* CONFIG_MAGIC_SYSRQ */
53657  
53658 -#ifdef CONFIG_IA64
53659 +#if    defined(CONFIG_IA64) || defined(CONFIG_KDB)
53660  /*
53661   * These functions are only useful for the IA64 MCA handling.
53662   *
53663 @@ -7364,3 +7364,80 @@ void (*rec_event)(void *,unsigned int);
53664  EXPORT_SYMBOL(rec_event);
53665  EXPORT_SYMBOL(in_sched_functions);
53666  #endif
53667 +
53668 +#ifdef CONFIG_KDB
53669 +
53670 +#include <linux/kdb.h>
53671 +
53672 +static void
53673 +kdb_prio(char *name, struct prio_array *array, kdb_printf_t xxx_printf)
53674 +{
53675 +       int pri;
53676 +
53677 +       xxx_printf("  %s nr_active:%d  bitmap: 0x%lx 0x%lx 0x%lx\n",
53678 +               name, array->nr_active,
53679 +               array->bitmap[0], array->bitmap[1], array->bitmap[2]);
53680 +
53681 +       pri = sched_find_first_bit(array->bitmap);
53682 +       if (pri != MAX_PRIO) {
53683 +               xxx_printf("   bitmap priorities:");
53684 +               while (pri != MAX_PRIO) {
53685 +                       xxx_printf(" %d", pri);
53686 +                       pri++;
53687 +                       pri = find_next_bit(array->bitmap, MAX_PRIO, pri);
53688 +               }
53689 +               xxx_printf("\n");
53690 +       }
53691 +
53692 +       for (pri = 0; pri < MAX_PRIO; pri++) {
53693 +               int printed_hdr = 0;
53694 +               struct list_head *head, *curr;
53695 +
53696 +               head = array->queue + pri;
53697 +               curr = head->next;
53698 +               while(curr != head) {
53699 +                       struct task_struct *task;
53700 +                       if (!printed_hdr) {
53701 +                               xxx_printf("   queue at priority=%d\n", pri);
53702 +                               printed_hdr = 1;
53703 +                       }
53704 +                       task = list_entry(curr, struct task_struct, run_list);
53705 +                       xxx_printf("    0x%p %d %s  time_slice:%d\n",
53706 +                                  task, task->pid, task->comm,
53707 +                                  task->time_slice);
53708 +                       curr = curr->next;
53709 +               }
53710 +       }
53711 +}
53712 +
53713 +/* This code must be in sched.c because struct rq is only defined in this
53714 + * source.  To allow most of kdb to be modular, this code cannot call any kdb
53715 + * functions directly, any external functions that it needs must be passed in
53716 + * as parameters.
53717 + */
53718 +
53719 +void
53720 +kdb_runqueue(unsigned long cpu, kdb_printf_t xxx_printf)
53721 +{
53722 +       struct rq *rq;
53723 +
53724 +       rq = cpu_rq(cpu);
53725 +
53726 +       xxx_printf("CPU%ld lock:%s curr:0x%p(%d)(%s)",
53727 +                  cpu, (spin_is_locked(&rq->lock))?"LOCKED":"free",
53728 +                  rq->curr, rq->curr->pid, rq->curr->comm);
53729 +       if (rq->curr == rq->idle)
53730 +               xxx_printf(" is idle");
53731 +       xxx_printf("\n ");
53732 +#ifdef CONFIG_SMP
53733 +       xxx_printf(" cpu_load:%lu %lu %lu",
53734 +                       rq->cpu_load[0], rq->cpu_load[1], rq->cpu_load[2]);
53735 +#endif
53736 +       xxx_printf(" nr_running:%lu nr_switches:%llu\n",
53737 +                  rq->nr_running, rq->nr_switches);
53738 +       kdb_prio("active", rq->active, xxx_printf);
53739 +       kdb_prio("expired", rq->expired, xxx_printf);
53740 +}
53741 +EXPORT_SYMBOL(kdb_runqueue);
53742 +
53743 +#endif /* CONFIG_KDB */
53744 diff -Nurp linux-2.6.22-590/kernel/signal.c linux-2.6.22-600/kernel/signal.c
53745 --- linux-2.6.22-590/kernel/signal.c    2008-04-09 18:10:53.000000000 +0200
53746 +++ linux-2.6.22-600/kernel/signal.c    2008-04-09 18:14:28.000000000 +0200
53747 @@ -2586,3 +2586,52 @@ void __init signals_init(void)
53748  {
53749         sigqueue_cachep = KMEM_CACHE(sigqueue, SLAB_PANIC);
53750  }
53751 +
53752 +#ifdef CONFIG_KDB
53753 +#include <linux/kdb.h>
53754 +/*
53755 + * kdb_send_sig_info
53756 + *
53757 + *     Allows kdb to send signals without exposing signal internals.
53758 + *
53759 + * Inputs:
53760 + *     t       task
53761 + *     siginfo signal information
53762 + *     seqno   current kdb sequence number (avoid including kdbprivate.h)
53763 + * Outputs:
53764 + *     None.
53765 + * Returns:
53766 + *     None.
53767 + * Locking:
53768 + *     Checks if the required locks are available before calling the main
53769 + *     signal code, to avoid kdb deadlocks.
53770 + * Remarks:
53771 + */
53772 +void
53773 +kdb_send_sig_info(struct task_struct *t, struct siginfo *info, int seqno)
53774 +{
53775 +       static struct task_struct *kdb_prev_t;
53776 +       static int kdb_prev_seqno;
53777 +       int sig, new_t;
53778 +       if (!spin_trylock(&t->sighand->siglock)) {
53779 +               kdb_printf("Can't do kill command now.\n"
53780 +                       "The sigmask lock is held somewhere else in kernel, try again later\n");
53781 +               return;
53782 +       }
53783 +       spin_unlock(&t->sighand->siglock);
53784 +       new_t = kdb_prev_t != t || kdb_prev_seqno != seqno;
53785 +       kdb_prev_t = t;
53786 +       kdb_prev_seqno = seqno;
53787 +       if (t->state != TASK_RUNNING && new_t) {
53788 +               kdb_printf("Process is not RUNNING, sending a signal from kdb risks deadlock\n"
53789 +                          "on the run queue locks.  The signal has _not_ been sent.\n"
53790 +                          "Reissue the kill command if you want to risk the deadlock.\n");
53791 +               return;
53792 +       }
53793 +       sig = info->si_signo;
53794 +       if (send_sig_info(sig, info, t))
53795 +               kdb_printf("Fail to deliver Signal %d to process %d.\n", sig, t->pid);
53796 +       else
53797 +               kdb_printf("Signal %d is sent to process %d.\n", sig, t->pid);
53798 +}
53799 +#endif /* CONFIG_KDB */
53800 diff -Nurp linux-2.6.22-590/Makefile linux-2.6.22-600/Makefile
53801 --- linux-2.6.22-590/Makefile   2008-04-09 18:11:17.000000000 +0200
53802 +++ linux-2.6.22-600/Makefile   2008-04-09 18:14:28.000000000 +0200
53803 @@ -560,6 +560,7 @@ export mod_strip_cmd
53804  
53805  ifeq ($(KBUILD_EXTMOD),)
53806  core-y         += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
53807 +core-$(CONFIG_KDB) += kdb/
53808  
53809  vmlinux-dirs   := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
53810                      $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
53811 diff -Nurp linux-2.6.22-590/mm/hugetlb.c linux-2.6.22-600/mm/hugetlb.c
53812 --- linux-2.6.22-590/mm/hugetlb.c       2008-04-09 18:10:53.000000000 +0200
53813 +++ linux-2.6.22-600/mm/hugetlb.c       2008-04-09 18:14:28.000000000 +0200
53814 @@ -266,6 +266,25 @@ int hugetlb_sysctl_handler(struct ctl_ta
53815  }
53816  #endif /* CONFIG_SYSCTL */
53817  
53818 +#ifdef CONFIG_KDB
53819 +#include <linux/kdb.h>
53820 +#include <linux/kdbprivate.h>
53821 +/* Like hugetlb_report_meminfo() but using kdb_printf() */
53822 +void
53823 +kdb_hugetlb_report_meminfo(void)
53824 +{
53825 +       kdb_printf(
53826 +               "HugePages_Total: %5lu\n"
53827 +               "HugePages_Free:  %5lu\n"
53828 +               "HugePages_Rsvd:  %5lu\n"
53829 +               "Hugepagesize:    %5lu kB\n",
53830 +               nr_huge_pages,
53831 +               free_huge_pages,
53832 +               resv_huge_pages,
53833 +               HPAGE_SIZE/1024);
53834 +}
53835 +#endif /* CONFIG_KDB */
53836 +
53837  int hugetlb_report_meminfo(char *buf)
53838  {
53839         return sprintf(buf,
53840 diff -Nurp linux-2.6.22-590/mm/swapfile.c linux-2.6.22-600/mm/swapfile.c
53841 --- linux-2.6.22-590/mm/swapfile.c      2008-04-09 18:10:53.000000000 +0200
53842 +++ linux-2.6.22-600/mm/swapfile.c      2008-04-09 18:14:28.000000000 +0200
53843 @@ -13,6 +13,10 @@
53844  #include <linux/swap.h>
53845  #include <linux/vmalloc.h>
53846  #include <linux/pagemap.h>
53847 +#ifdef CONFIG_KDB
53848 +#include <linux/kdb.h>
53849 +#include <linux/kdbprivate.h>
53850 +#endif /* CONFIG_KDB */
53851  #include <linux/namei.h>
53852  #include <linux/shm.h>
53853  #include <linux/blkdev.h>
53854 @@ -1718,6 +1722,24 @@ void si_swapinfo(struct sysinfo *val)
53855                 vx_vsi_swapinfo(val);
53856  }
53857  
53858 +#ifdef CONFIG_KDB
53859 +/* Like si_swapinfo() but without the locks */
53860 +void kdb_si_swapinfo(struct sysinfo *val)
53861 +{
53862 +       unsigned int i;
53863 +       unsigned long nr_to_be_unused = 0;
53864 +
53865 +       for (i = 0; i < nr_swapfiles; i++) {
53866 +               if (!(swap_info[i].flags & SWP_USED) ||
53867 +                    (swap_info[i].flags & SWP_WRITEOK))
53868 +                       continue;
53869 +               nr_to_be_unused += swap_info[i].inuse_pages;
53870 +       }
53871 +       val->freeswap = nr_swap_pages + nr_to_be_unused;
53872 +       val->totalswap = total_swap_pages + nr_to_be_unused;
53873 +}
53874 +#endif /* CONFIG_KDB */
53875 +
53876  /*
53877   * Verify that a swap entry is valid and increment its swap map count.
53878   *