Commit 984aa1e8 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] ppc64: update xmon debugger

From: Paul Mackerras <paulus@samba.org>

This patch fixes a whole pile of problems in the xmon kernel debugger for
ppc64.  This basically makes xmon SMP-safe.  Now, when we enter xmon it
sends an IPI to the other CPUs to get them into xmon too.  It also changes
the way we do single-stepping and breakpoints so that we don't have to
remove a breakpoint to proceed from it (instead we either emulate the
instruction where the breakpoint was, or execute it out of place).  With
this patch, if we get an exception inside xmon, it will just return to the
xmon command loop instead of hanging the system as at present.

The patch is quite large because it updates the disassembler to the latest
version from binutils (trimmed a bit), which is why I didn't cc lkml.
parent 68a6cd9b
...@@ -618,7 +618,7 @@ void smp_message_recv(int msg, struct pt_regs *regs) ...@@ -618,7 +618,7 @@ void smp_message_recv(int msg, struct pt_regs *regs)
#endif #endif
#ifdef CONFIG_DEBUGGER #ifdef CONFIG_DEBUGGER
case PPC_MSG_DEBUGGER_BREAK: case PPC_MSG_DEBUGGER_BREAK:
debugger(regs); debugger_ipi(regs);
break; break;
#endif #endif
default: default:
......
...@@ -44,6 +44,7 @@ extern int fwnmi_active; ...@@ -44,6 +44,7 @@ extern int fwnmi_active;
#ifdef CONFIG_DEBUGGER #ifdef CONFIG_DEBUGGER
int (*__debugger)(struct pt_regs *regs); int (*__debugger)(struct pt_regs *regs);
int (*__debugger_ipi)(struct pt_regs *regs);
int (*__debugger_bpt)(struct pt_regs *regs); int (*__debugger_bpt)(struct pt_regs *regs);
int (*__debugger_sstep)(struct pt_regs *regs); int (*__debugger_sstep)(struct pt_regs *regs);
int (*__debugger_iabr_match)(struct pt_regs *regs); int (*__debugger_iabr_match)(struct pt_regs *regs);
...@@ -51,6 +52,7 @@ int (*__debugger_dabr_match)(struct pt_regs *regs); ...@@ -51,6 +52,7 @@ int (*__debugger_dabr_match)(struct pt_regs *regs);
int (*__debugger_fault_handler)(struct pt_regs *regs); int (*__debugger_fault_handler)(struct pt_regs *regs);
EXPORT_SYMBOL(__debugger); EXPORT_SYMBOL(__debugger);
EXPORT_SYMBOL(__debugger_ipi);
EXPORT_SYMBOL(__debugger_bpt); EXPORT_SYMBOL(__debugger_bpt);
EXPORT_SYMBOL(__debugger_sstep); EXPORT_SYMBOL(__debugger_sstep);
EXPORT_SYMBOL(__debugger_iabr_match); EXPORT_SYMBOL(__debugger_iabr_match);
...@@ -69,9 +71,6 @@ int die(const char *str, struct pt_regs *regs, long err) ...@@ -69,9 +71,6 @@ int die(const char *str, struct pt_regs *regs, long err)
static int die_counter; static int die_counter;
int nl = 0; int nl = 0;
if (debugger_fault_handler(regs))
return 1;
if (debugger(regs)) if (debugger(regs))
return 1; return 1;
...@@ -266,6 +265,8 @@ MachineCheckException(struct pt_regs *regs) ...@@ -266,6 +265,8 @@ MachineCheckException(struct pt_regs *regs)
} }
#endif #endif
if (debugger_fault_handler(regs))
return;
die("Machine check", regs, 0); die("Machine check", regs, 0);
/* Must die if the interrupt is not recoverable */ /* Must die if the interrupt is not recoverable */
......
...@@ -22,37 +22,28 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ...@@ -22,37 +22,28 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
#include "ansidecl.h" #include "ansidecl.h"
#include "ppc.h" #include "ppc.h"
static int print_insn_powerpc PARAMS ((FILE *, unsigned long insn, extern void print_address (unsigned long memaddr);
unsigned long memaddr, int dialect));
extern void print_address PARAMS((unsigned long memaddr));
/* Print a big endian PowerPC instruction. For convenience, also
disassemble instructions supported by the Motorola PowerPC 601. */
int
print_insn_big_powerpc (FILE *out, unsigned long insn, unsigned long memaddr)
{
return print_insn_powerpc (out, insn, memaddr,
PPC_OPCODE_PPC | PPC_OPCODE_601);
}
/* Print a PowerPC or POWER instruction. */ /* Print a PowerPC or POWER instruction. */
static int int
print_insn_powerpc (FILE *out, unsigned long insn, unsigned long memaddr, print_insn_powerpc (unsigned long insn, unsigned long memaddr, int dialect)
int dialect)
{ {
const struct powerpc_opcode *opcode; const struct powerpc_opcode *opcode;
const struct powerpc_opcode *opcode_end; const struct powerpc_opcode *opcode_end;
unsigned long op; unsigned long op;
if (dialect == 0)
dialect = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_COMMON
| PPC_OPCODE_64 | PPC_OPCODE_POWER4 | PPC_OPCODE_ALTIVEC;
/* Get the major opcode of the instruction. */ /* Get the major opcode of the instruction. */
op = PPC_OP (insn); op = PPC_OP (insn);
/* Find the first match in the opcode table. We could speed this up /* Find the first match in the opcode table. We could speed this up
a bit by doing a binary search on the major opcode. */ a bit by doing a binary search on the major opcode. */
opcode_end = powerpc_opcodes + powerpc_num_opcodes; opcode_end = powerpc_opcodes + powerpc_num_opcodes;
again:
for (opcode = powerpc_opcodes; opcode < opcode_end; opcode++) for (opcode = powerpc_opcodes; opcode < opcode_end; opcode++)
{ {
unsigned long table_op; unsigned long table_op;
...@@ -64,109 +55,106 @@ print_insn_powerpc (FILE *out, unsigned long insn, unsigned long memaddr, ...@@ -64,109 +55,106 @@ print_insn_powerpc (FILE *out, unsigned long insn, unsigned long memaddr,
table_op = PPC_OP (opcode->opcode); table_op = PPC_OP (opcode->opcode);
if (op < table_op) if (op < table_op)
break; break;
if (op > table_op) if (op > table_op)
continue; continue;
if ((insn & opcode->mask) != opcode->opcode if ((insn & opcode->mask) != opcode->opcode
|| (opcode->flags & dialect) == 0) || (opcode->flags & dialect) == 0)
continue; continue;
/* Make two passes over the operands. First see if any of them /* Make two passes over the operands. First see if any of them
have extraction functions, and, if they do, make sure the have extraction functions, and, if they do, make sure the
instruction is valid. */ instruction is valid. */
invalid = 0; invalid = 0;
for (opindex = opcode->operands; *opindex != 0; opindex++) for (opindex = opcode->operands; *opindex != 0; opindex++)
{ {
operand = powerpc_operands + *opindex; operand = powerpc_operands + *opindex;
if (operand->extract) if (operand->extract)
(*operand->extract) (insn, &invalid); (*operand->extract) (insn, dialect, &invalid);
} }
if (invalid) if (invalid)
continue; continue;
/* The instruction is valid. */ /* The instruction is valid. */
fprintf(out, "%s", opcode->name); printf("%s", opcode->name);
if (opcode->operands[0] != 0) if (opcode->operands[0] != 0)
fprintf(out, "\t"); printf("\t");
/* Now extract and print the operands. */ /* Now extract and print the operands. */
need_comma = 0; need_comma = 0;
need_paren = 0; need_paren = 0;
for (opindex = opcode->operands; *opindex != 0; opindex++) for (opindex = opcode->operands; *opindex != 0; opindex++)
{
long value;
operand = powerpc_operands + *opindex;
/* Operands that are marked FAKE are simply ignored. We
already made sure that the extract function considered
the instruction to be valid. */
if ((operand->flags & PPC_OPERAND_FAKE) != 0)
continue;
/* Extract the value from the instruction. */
if (operand->extract)
value = (*operand->extract) (insn, dialect, &invalid);
else
{
value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
if ((operand->flags & PPC_OPERAND_SIGNED) != 0
&& (value & (1 << (operand->bits - 1))) != 0)
value -= 1 << operand->bits;
}
/* If the operand is optional, and the value is zero, don't
print anything. */
if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
&& (operand->flags & PPC_OPERAND_NEXT) == 0
&& value == 0)
continue;
if (need_comma)
{
printf(",");
need_comma = 0;
}
/* Print the operand as directed by the flags. */
if ((operand->flags & PPC_OPERAND_GPR) != 0)
printf("r%ld", value);
else if ((operand->flags & PPC_OPERAND_FPR) != 0)
printf("f%ld", value);
else if ((operand->flags & PPC_OPERAND_VR) != 0)
printf("v%ld", value);
else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0)
print_address (memaddr + value);
else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
print_address (value & 0xffffffff);
else if ((operand->flags & PPC_OPERAND_CR) == 0
|| (dialect & PPC_OPCODE_PPC) == 0)
printf("%ld", value);
else
{
if (operand->bits == 3)
printf("cr%d", value);
else
{ {
long value; static const char *cbnames[4] = { "lt", "gt", "eq", "so" };
int cr;
operand = powerpc_operands + *opindex; int cc;
/* Operands that are marked FAKE are simply ignored. We cr = value >> 2;
already made sure that the extract function considered if (cr != 0)
the instruction to be valid. */ printf("4*cr%d+", cr);
if ((operand->flags & PPC_OPERAND_FAKE) != 0) cc = value & 3;
continue; printf("%s", cbnames[cc]);
}
/* Extract the value from the instruction. */
if (operand->extract)
value = (*operand->extract) (insn, (int *) 0);
else
{
value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
if ((operand->flags & PPC_OPERAND_SIGNED) != 0
&& (value & (1 << (operand->bits - 1))) != 0)
value -= 1 << operand->bits;
}
/* If the operand is optional, and the value is zero, don't
print anything. */
if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
&& (operand->flags & PPC_OPERAND_NEXT) == 0
&& value == 0)
continue;
if (need_comma)
{
fprintf(out, ",");
need_comma = 0;
}
/* Print the operand as directed by the flags. */
if ((operand->flags & PPC_OPERAND_GPR) != 0)
fprintf(out, "r%ld", value);
else if ((operand->flags & PPC_OPERAND_FPR) != 0)
fprintf(out, "f%ld", value);
else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0)
print_address (memaddr + value);
else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
print_address (value & 0xffffffff);
else if ((operand->flags & PPC_OPERAND_CR) == 0
|| (dialect & PPC_OPCODE_PPC) == 0)
fprintf(out, "%ld", value);
else
{
if (operand->bits == 3)
fprintf(out, "cr%d", value);
else
{
static const char *cbnames[4] = { "lt", "gt", "eq", "so" };
int cr;
int cc;
cr = value >> 2;
if (cr != 0)
fprintf(out, "4*cr%d", cr);
cc = value & 3;
if (cc != 0)
{
if (cr != 0)
fprintf(out, "+");
fprintf(out, "%s", cbnames[cc]);
}
}
} }
if (need_paren) if (need_paren)
{ {
fprintf(out, ")"); printf(")");
need_paren = 0; need_paren = 0;
} }
...@@ -174,7 +162,7 @@ print_insn_powerpc (FILE *out, unsigned long insn, unsigned long memaddr, ...@@ -174,7 +162,7 @@ print_insn_powerpc (FILE *out, unsigned long insn, unsigned long memaddr,
need_comma = 1; need_comma = 1;
else else
{ {
fprintf(out, "("); printf("(");
need_paren = 1; need_paren = 1;
} }
} }
...@@ -183,8 +171,14 @@ print_insn_powerpc (FILE *out, unsigned long insn, unsigned long memaddr, ...@@ -183,8 +171,14 @@ print_insn_powerpc (FILE *out, unsigned long insn, unsigned long memaddr,
return 4; return 4;
} }
if ((dialect & PPC_OPCODE_ANY) != 0)
{
dialect = ~PPC_OPCODE_ANY;
goto again;
}
/* We could not find a match. */ /* We could not find a match. */
fprintf(out, ".long 0x%lx", insn); printf(".long 0x%lx", insn);
return 4; return 4;
} }
This diff is collapsed.
/* ppc.h -- Header file for PowerPC opcode table /* ppc.h -- Header file for PowerPC opcode table
Copyright 1994 Free Software Foundation, Inc. Copyright 1994, 1995, 1999, 2000, 2001, 2002, 2003
Free Software Foundation, Inc.
Written by Ian Lance Taylor, Cygnus Support Written by Ian Lance Taylor, Cygnus Support
This file is part of GDB, GAS, and the GNU binutils. This file is part of GDB, GAS, and the GNU binutils.
...@@ -58,24 +59,80 @@ extern const int powerpc_num_opcodes; ...@@ -58,24 +59,80 @@ extern const int powerpc_num_opcodes;
/* Values defined for the flags field of a struct powerpc_opcode. */ /* Values defined for the flags field of a struct powerpc_opcode. */
/* Opcode is defined for the PowerPC architecture. */ /* Opcode is defined for the PowerPC architecture. */
#define PPC_OPCODE_PPC (01) #define PPC_OPCODE_PPC 1
/* Opcode is defined for the POWER (RS/6000) architecture. */ /* Opcode is defined for the POWER (RS/6000) architecture. */
#define PPC_OPCODE_POWER (02) #define PPC_OPCODE_POWER 2
/* Opcode is defined for the POWER2 (Rios 2) architecture. */ /* Opcode is defined for the POWER2 (Rios 2) architecture. */
#define PPC_OPCODE_POWER2 (04) #define PPC_OPCODE_POWER2 4
/* Opcode is only defined on 32 bit architectures. */ /* Opcode is only defined on 32 bit architectures. */
#define PPC_OPCODE_32 (010) #define PPC_OPCODE_32 8
/* Opcode is only defined on 64 bit architectures. */ /* Opcode is only defined on 64 bit architectures. */
#define PPC_OPCODE_64 (020) #define PPC_OPCODE_64 0x10
/* Opcode is supported by the Motorola PowerPC 601 processor. The 601 /* Opcode is supported by the Motorola PowerPC 601 processor. The 601
is assumed to support all PowerPC (PPC_OPCODE_PPC) instructions, is assumed to support all PowerPC (PPC_OPCODE_PPC) instructions,
but it also supports many additional POWER instructions. */ but it also supports many additional POWER instructions. */
#define PPC_OPCODE_601 (040) #define PPC_OPCODE_601 0x20
/* Opcode is supported in both the Power and PowerPC architectures
(ie, compiler's -mcpu=common or assembler's -mcom). */
#define PPC_OPCODE_COMMON 0x40
/* Opcode is supported for any Power or PowerPC platform (this is
for the assembler's -many option, and it eliminates duplicates). */
#define PPC_OPCODE_ANY 0x80
/* Opcode is supported as part of the 64-bit bridge. */
#define PPC_OPCODE_64_BRIDGE 0x100
/* Opcode is supported by Altivec Vector Unit */
#define PPC_OPCODE_ALTIVEC 0x200
/* Opcode is supported by PowerPC 403 processor. */
#define PPC_OPCODE_403 0x400
/* Opcode is supported by PowerPC BookE processor. */
#define PPC_OPCODE_BOOKE 0x800
/* Opcode is only supported by 64-bit PowerPC BookE processor. */
#define PPC_OPCODE_BOOKE64 0x1000
/* Opcode is supported by PowerPC 440 processor. */
#define PPC_OPCODE_440 0x2000
/* Opcode is only supported by Power4 architecture. */
#define PPC_OPCODE_POWER4 0x4000
/* Opcode isn't supported by Power4 architecture. */
#define PPC_OPCODE_NOPOWER4 0x8000
/* Opcode is only supported by POWERPC Classic architecture. */
#define PPC_OPCODE_CLASSIC 0x10000
/* Opcode is only supported by e500x2 Core. */
#define PPC_OPCODE_SPE 0x20000
/* Opcode is supported by e500x2 Integer select APU. */
#define PPC_OPCODE_ISEL 0x40000
/* Opcode is an e500 SPE floating point instruction. */
#define PPC_OPCODE_EFS 0x80000
/* Opcode is supported by branch locking APU. */
#define PPC_OPCODE_BRLOCK 0x100000
/* Opcode is supported by performance monitor APU. */
#define PPC_OPCODE_PMR 0x200000
/* Opcode is supported by cache locking APU. */
#define PPC_OPCODE_CACHELCK 0x400000
/* Opcode is supported by machine check APU. */
#define PPC_OPCODE_RFMCI 0x800000
/* A macro to extract the major opcode from an instruction. */ /* A macro to extract the major opcode from an instruction. */
#define PPC_OP(i) (((i) >> 26) & 0x3f) #define PPC_OP(i) (((i) >> 26) & 0x3f)
...@@ -106,8 +163,8 @@ struct powerpc_operand ...@@ -106,8 +163,8 @@ struct powerpc_operand
string (the operand will be inserted in any case). If the string (the operand will be inserted in any case). If the
operand value is legal, *ERRMSG will be unchanged (most operands operand value is legal, *ERRMSG will be unchanged (most operands
can accept any value). */ can accept any value). */
unsigned long (*insert) PARAMS ((unsigned long instruction, long op, unsigned long (*insert)
const char **errmsg)); (unsigned long instruction, long op, int dialect, const char **errmsg);
/* Extraction function. This is used by the disassembler. To /* Extraction function. This is used by the disassembler. To
extract this operand type from an instruction, check this field. extract this operand type from an instruction, check this field.
...@@ -126,7 +183,7 @@ struct powerpc_operand ...@@ -126,7 +183,7 @@ struct powerpc_operand
non-zero if this operand type can not actually be extracted from non-zero if this operand type can not actually be extracted from
this operand (i.e., the instruction does not match). If the this operand (i.e., the instruction does not match). If the
operand is valid, *INVALID will not be changed. */ operand is valid, *INVALID will not be changed. */
long (*extract) PARAMS ((unsigned long instruction, int *invalid)); long (*extract) (unsigned long instruction, int dialect, int *invalid);
/* One bit syntax flags. */ /* One bit syntax flags. */
unsigned long flags; unsigned long flags;
...@@ -210,6 +267,16 @@ extern const struct powerpc_operand powerpc_operands[]; ...@@ -210,6 +267,16 @@ extern const struct powerpc_operand powerpc_operands[];
number is allowed). This flag will only be set for a signed number is allowed). This flag will only be set for a signed
operand. */ operand. */
#define PPC_OPERAND_NEGATIVE (04000) #define PPC_OPERAND_NEGATIVE (04000)
/* This operand names a vector unit register. The disassembler
prints these with a leading 'v'. */
#define PPC_OPERAND_VR (010000)
/* This operand is for the DS field in a DS form instruction. */
#define PPC_OPERAND_DS (020000)
/* This operand is for the DQ field in a DQ form instruction. */
#define PPC_OPERAND_DQ (040000)
/* The POWER and PowerPC assemblers use a few macros. We keep them /* The POWER and PowerPC assemblers use a few macros. We keep them
with the operands table for simplicity. The macro table is an with the operands table for simplicity. The macro table is an
......
This diff is collapsed.
...@@ -64,6 +64,7 @@ struct pt_regs; ...@@ -64,6 +64,7 @@ struct pt_regs;
#ifdef CONFIG_DEBUGGER #ifdef CONFIG_DEBUGGER
extern int (*__debugger)(struct pt_regs *regs); extern int (*__debugger)(struct pt_regs *regs);
extern int (*__debugger_ipi)(struct pt_regs *regs);
extern int (*__debugger_bpt)(struct pt_regs *regs); extern int (*__debugger_bpt)(struct pt_regs *regs);
extern int (*__debugger_sstep)(struct pt_regs *regs); extern int (*__debugger_sstep)(struct pt_regs *regs);
extern int (*__debugger_iabr_match)(struct pt_regs *regs); extern int (*__debugger_iabr_match)(struct pt_regs *regs);
...@@ -79,6 +80,7 @@ static inline int __NAME(struct pt_regs *regs) \ ...@@ -79,6 +80,7 @@ static inline int __NAME(struct pt_regs *regs) \
} }
DEBUGGER_BOILERPLATE(debugger) DEBUGGER_BOILERPLATE(debugger)
DEBUGGER_BOILERPLATE(debugger_ipi)
DEBUGGER_BOILERPLATE(debugger_bpt) DEBUGGER_BOILERPLATE(debugger_bpt)
DEBUGGER_BOILERPLATE(debugger_sstep) DEBUGGER_BOILERPLATE(debugger_sstep)
DEBUGGER_BOILERPLATE(debugger_iabr_match) DEBUGGER_BOILERPLATE(debugger_iabr_match)
...@@ -91,6 +93,7 @@ extern void xmon_init(void); ...@@ -91,6 +93,7 @@ extern void xmon_init(void);
#else #else
static inline int debugger(struct pt_regs *regs) { return 0; } static inline int debugger(struct pt_regs *regs) { return 0; }
static inline int debugger_ipi(struct pt_regs *regs) { return 0; }
static inline int debugger_bpt(struct pt_regs *regs) { return 0; } static inline int debugger_bpt(struct pt_regs *regs) { return 0; }
static inline int debugger_sstep(struct pt_regs *regs) { return 0; } static inline int debugger_sstep(struct pt_regs *regs) { return 0; }
static inline int debugger_iabr_match(struct pt_regs *regs) { return 0; } static inline int debugger_iabr_match(struct pt_regs *regs) { return 0; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment