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 /* Convert the SPARC hardware trap type code to a unix signal number. */
43 * This table contains the mapping between PowerPC hardware trap types, and
44 * signals, which are primarily what GDB understands.
46 static struct hard_trap_info
48 unsigned int tt; /* Trap type code for powerpc */
49 unsigned char signo; /* Signal that we map this trap into */
50 } hard_trap_info[] = {
51 { 0x200, SIGSEGV }, /* machine check */
52 { 0x300, SIGSEGV }, /* address error (store) */
53 { 0x400, SIGBUS }, /* instruction bus error */
54 { 0x500, SIGINT }, /* interrupt */
55 { 0x600, SIGBUS }, /* alingment */
56 { 0x700, SIGTRAP }, /* breakpoint trap */
57 { 0x800, SIGFPE }, /* fpu unavail */
58 { 0x900, SIGALRM }, /* decrementer */
59 { 0xa00, SIGILL }, /* reserved */
60 { 0xb00, SIGILL }, /* reserved */
61 { 0xc00, SIGCHLD }, /* syscall */
62 { 0xd00, SIGTRAP }, /* single-step/watch */
63 { 0xe00, SIGFPE }, /* fp assist */
64 { 0, 0} /* Must be last */
68 computeSignal(unsigned int tt)
70 struct hard_trap_info *ht;
72 for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
76 return SIGHUP; /* default for things we don't know about */
80 kgdb_enter(struct pt_regs *regs, kgdb_data *kdp)
84 kdp->private[0] = msr = get_msr();
85 set_msr(msr & ~MSR_EE); /* disable interrupts */
87 if (regs->nip == (unsigned long)breakinst) {
88 /* Skip over breakpoint trap insn */
93 /* reply to host that an exception has occurred */
94 kdp->sigval = computeSignal(regs->trap);
98 kdp->regs[0].num = PC_REGNUM;
99 kdp->regs[0].val = regs->nip;
101 kdp->regs[1].num = SP_REGNUM;
102 kdp->regs[1].val = regs->gpr[SP_REGNUM];
106 kgdb_exit(struct pt_regs *regs, kgdb_data *kdp)
108 unsigned long msr = kdp->private[0];
110 if (kdp->extype & KGDBEXIT_WITHADDR)
111 regs->nip = kdp->exaddr;
113 switch (kdp->extype & KGDBEXIT_TYPEMASK) {
116 case KGDBEXIT_CONTINUE:
120 case KGDBEXIT_SINGLE:
123 set_msr(msr | MSR_SE);
130 kgdb_trap(struct pt_regs *regs)
135 /* return the value of the CPU registers.
136 * some of them are non-PowerPC names :(
137 * they are stored in gdb like:
141 * u32 pc, ps, cnd, lr; (ps=msr)
146 #define SPACE_REQUIRED ((32*4)+(32*8)+(6*4))
149 kgdb_getregs(struct pt_regs *regs, char *buf, int max)
152 unsigned long *ptr = (unsigned long *)buf;
154 if (max < SPACE_REQUIRED)
155 kgdb_error(KGDBERR_NOSPACE);
157 if ((unsigned long)ptr & 3)
158 kgdb_error(KGDBERR_ALIGNFAULT);
160 /* General Purpose Regs */
161 for (i = 0; i < 32; i++)
162 *ptr++ = regs->gpr[i];
164 /* Floating Point Regs */
165 for (i = 0; i < 32; i++) {
170 /* pc, msr, cr, lr, ctr, xer, (mq is unused) */
178 return (SPACE_REQUIRED);
181 /* set the value of the CPU registers */
183 kgdb_putreg(struct pt_regs *regs, int regno, char *buf, int length)
185 unsigned long *ptr = (unsigned long *)buf;
187 if (regno < 0 || regno >= 70)
188 kgdb_error(KGDBERR_BADPARAMS);
189 else if (regno >= 32 && regno < 64) {
191 kgdb_error(KGDBERR_NOSPACE);
195 kgdb_error(KGDBERR_NOSPACE);
198 if ((unsigned long)ptr & 3)
199 kgdb_error(KGDBERR_ALIGNFAULT);
201 if (regno >= 0 && regno < 32)
202 regs->gpr[regno] = *ptr;
203 else switch (regno) {
204 case 64: regs->nip = *ptr; break;
205 case 65: regs->msr = *ptr; break;
206 case 66: regs->ccr = *ptr; break;
207 case 67: regs->link = *ptr; break;
208 case 68: regs->ctr = *ptr; break;
209 case 69: regs->ctr = *ptr; break;
212 kgdb_error(KGDBERR_BADPARAMS);
217 kgdb_putregs(struct pt_regs *regs, char *buf, int length)
220 unsigned long *ptr = (unsigned long *)buf;
222 if (length < SPACE_REQUIRED)
223 kgdb_error(KGDBERR_NOSPACE);
225 if ((unsigned long)ptr & 3)
226 kgdb_error(KGDBERR_ALIGNFAULT);
229 * If the stack pointer has moved, you should pray.
230 * (cause only god can help you).
233 /* General Purpose Regs */
234 for (i = 0; i < 32; i++)
235 regs->gpr[i] = *ptr++;
237 /* Floating Point Regs */
240 /* pc, msr, cr, lr, ctr, xer, (mq is unused) */
249 /* This function will generate a breakpoint exception. It is used at the
250 beginning of a program to sync up with a debugger and can be used
251 otherwise as a quick means to stop program execution and "break" into
255 kgdb_breakpoint(int argc, char * const argv[])
257 asm(" .globl breakinst\n\
258 breakinst: .long 0x7d821008\n\