4 #include <asm/signal.h>
5 #include <asm/processor.h>
13 kgdb_setjmp(long *buf)
17 asm volatile("mflr %0; stw %0,0(%1);"
18 "stw %%r1,4(%1); stw %%r2,8(%1);"
19 "mfcr %0; stw %0,12(%1);"
21 : "=&r"(temp) : "r" (buf));
22 /* XXX should save fp regs as well */
27 kgdb_longjmp(long *buf, int val)
34 asm volatile("lmw %%r13,16(%1);"
35 "lwz %0,12(%1); mtcrf 0x38,%0;"
36 "lwz %0,0(%1); lwz %%r1,4(%1); lwz %%r2,8(%1);"
38 : "=&r"(temp) : "r" (buf), "r" (val));
41 static inline unsigned long
45 asm volatile("mfmsr %0" : "=r" (msr):);
50 set_msr(unsigned long msr)
52 asm volatile("mtmsr %0" : : "r" (msr));
55 /* Convert the SPARC hardware trap type code to a unix signal number. */
57 * This table contains the mapping between PowerPC hardware trap types, and
58 * signals, which are primarily what GDB understands.
60 static struct hard_trap_info
62 unsigned int tt; /* Trap type code for powerpc */
63 unsigned char signo; /* Signal that we map this trap into */
64 } hard_trap_info[] = {
65 { 0x200, SIGSEGV }, /* machine check */
66 { 0x300, SIGSEGV }, /* address error (store) */
67 { 0x400, SIGBUS }, /* instruction bus error */
68 { 0x500, SIGINT }, /* interrupt */
69 { 0x600, SIGBUS }, /* alingment */
70 { 0x700, SIGTRAP }, /* breakpoint trap */
71 { 0x800, SIGFPE }, /* fpu unavail */
72 { 0x900, SIGALRM }, /* decrementer */
73 { 0xa00, SIGILL }, /* reserved */
74 { 0xb00, SIGILL }, /* reserved */
75 { 0xc00, SIGCHLD }, /* syscall */
76 { 0xd00, SIGTRAP }, /* single-step/watch */
77 { 0xe00, SIGFPE }, /* fp assist */
78 { 0, 0} /* Must be last */
82 computeSignal(unsigned int tt)
84 struct hard_trap_info *ht;
86 for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
90 return SIGHUP; /* default for things we don't know about */
94 kgdb_enter(struct pt_regs *regs, kgdb_data *kdp)
98 kdp->private[0] = msr = get_msr();
99 set_msr(msr & ~MSR_EE); /* disable interrupts */
101 if (regs->nip == (unsigned long)breakinst) {
102 /* Skip over breakpoint trap insn */
105 regs->msr &= ~MSR_SE;
107 /* reply to host that an exception has occurred */
108 kdp->sigval = computeSignal(regs->trap);
112 kdp->regs[0].num = PC_REGNUM;
113 kdp->regs[0].val = regs->nip;
115 kdp->regs[1].num = SP_REGNUM;
116 kdp->regs[1].val = regs->gpr[SP_REGNUM];
120 kgdb_exit(struct pt_regs *regs, kgdb_data *kdp)
122 unsigned long msr = kdp->private[0];
124 if (kdp->extype & KGDBEXIT_WITHADDR)
125 regs->nip = kdp->exaddr;
127 switch (kdp->extype & KGDBEXIT_TYPEMASK) {
130 case KGDBEXIT_CONTINUE:
134 case KGDBEXIT_SINGLE:
137 set_msr(msr | MSR_SE);
144 kgdb_trap(struct pt_regs *regs)
149 /* return the value of the CPU registers.
150 * some of them are non-PowerPC names :(
151 * they are stored in gdb like:
155 * u32 pc, ps, cnd, lr; (ps=msr)
160 #define SPACE_REQUIRED ((32*4)+(32*8)+(6*4))
163 kgdb_getregs(struct pt_regs *regs, char *buf, int max)
166 unsigned long *ptr = (unsigned long *)buf;
168 if (max < SPACE_REQUIRED)
169 kgdb_error(KGDBERR_NOSPACE);
171 if ((unsigned long)ptr & 3)
172 kgdb_error(KGDBERR_ALIGNFAULT);
174 /* General Purpose Regs */
175 for (i = 0; i < 32; i++)
176 *ptr++ = regs->gpr[i];
178 /* Floating Point Regs */
179 for (i = 0; i < 32; i++) {
184 /* pc, msr, cr, lr, ctr, xer, (mq is unused) */
192 return (SPACE_REQUIRED);
195 /* set the value of the CPU registers */
197 kgdb_putreg(struct pt_regs *regs, int regno, char *buf, int length)
199 unsigned long *ptr = (unsigned long *)buf;
201 if (regno < 0 || regno >= 70)
202 kgdb_error(KGDBERR_BADPARAMS);
203 else if (regno >= 32 && regno < 64) {
205 kgdb_error(KGDBERR_NOSPACE);
209 kgdb_error(KGDBERR_NOSPACE);
212 if ((unsigned long)ptr & 3)
213 kgdb_error(KGDBERR_ALIGNFAULT);
215 if (regno >= 0 && regno < 32)
216 regs->gpr[regno] = *ptr;
217 else switch (regno) {
218 case 64: regs->nip = *ptr; break;
219 case 65: regs->msr = *ptr; break;
220 case 66: regs->ccr = *ptr; break;
221 case 67: regs->link = *ptr; break;
222 case 68: regs->ctr = *ptr; break;
223 case 69: regs->ctr = *ptr; break;
226 kgdb_error(KGDBERR_BADPARAMS);
231 kgdb_putregs(struct pt_regs *regs, char *buf, int length)
234 unsigned long *ptr = (unsigned long *)buf;
236 if (length < SPACE_REQUIRED)
237 kgdb_error(KGDBERR_NOSPACE);
239 if ((unsigned long)ptr & 3)
240 kgdb_error(KGDBERR_ALIGNFAULT);
243 * If the stack pointer has moved, you should pray.
244 * (cause only god can help you).
247 /* General Purpose Regs */
248 for (i = 0; i < 32; i++)
249 regs->gpr[i] = *ptr++;
251 /* Floating Point Regs */
254 /* pc, msr, cr, lr, ctr, xer, (mq is unused) */
263 /* This function will generate a breakpoint exception. It is used at the
264 beginning of a program to sync up with a debugger and can be used
265 otherwise as a quick means to stop program execution and "break" into
269 kgdb_breakpoint(int argc, char * const argv[])
271 asm(" .globl breakinst\n\
272 breakinst: .long 0x7d821008\n\