4 #include <asm/ptrace.h>
5 #include <asm/signal.h>
6 #include <asm/processor.h>
14 kgdb_setjmp(long *buf)
18 asm volatile("mflr %0; stw %0,0(%1);"
19 "stw %%r1,4(%1); stw %%r2,8(%1);"
20 "mfcr %0; stw %0,12(%1);"
22 : "=&r"(temp) : "r" (buf));
23 /* XXX should save fp regs as well */
28 kgdb_longjmp(long *buf, int val)
35 asm volatile("lmw %%r13,16(%1);"
36 "lwz %0,12(%1); mtcrf 0x38,%0;"
37 "lwz %0,0(%1); lwz %%r1,4(%1); lwz %%r2,8(%1);"
39 : "=&r"(temp) : "r" (buf), "r" (val));
42 /* Convert the SPARC hardware trap type code to a unix signal number. */
44 * This table contains the mapping between PowerPC hardware trap types, and
45 * signals, which are primarily what GDB understands.
47 static struct hard_trap_info
49 unsigned int tt; /* Trap type code for powerpc */
50 unsigned char signo; /* Signal that we map this trap into */
51 } hard_trap_info[] = {
52 { 0x200, SIGSEGV }, /* machine check */
53 { 0x300, SIGSEGV }, /* address error (store) */
54 { 0x400, SIGBUS }, /* instruction bus error */
55 { 0x500, SIGINT }, /* interrupt */
56 { 0x600, SIGBUS }, /* alignment */
57 { 0x700, SIGTRAP }, /* breakpoint trap */
58 { 0x800, SIGFPE }, /* fpu unavail */
59 { 0x900, SIGALRM }, /* decrementer */
60 { 0xa00, SIGILL }, /* reserved */
61 { 0xb00, SIGILL }, /* reserved */
62 { 0xc00, SIGCHLD }, /* syscall */
63 { 0xd00, SIGTRAP }, /* single-step/watch */
64 { 0xe00, SIGFPE }, /* fp assist */
65 { 0, 0} /* Must be last */
69 computeSignal(unsigned int tt)
71 struct hard_trap_info *ht;
73 for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
77 return SIGHUP; /* default for things we don't know about */
81 kgdb_enter(struct pt_regs *regs, kgdb_data *kdp)
85 kdp->private[0] = msr = get_msr();
86 set_msr(msr & ~MSR_EE); /* disable interrupts */
88 if (regs->nip == (unsigned long)breakinst) {
89 /* Skip over breakpoint trap insn */
94 /* reply to host that an exception has occurred */
95 kdp->sigval = computeSignal(regs->trap);
99 kdp->regs[0].num = PC_REGNUM;
100 kdp->regs[0].val = regs->nip;
102 kdp->regs[1].num = SP_REGNUM;
103 kdp->regs[1].val = regs->gpr[SP_REGNUM];
107 kgdb_exit(struct pt_regs *regs, kgdb_data *kdp)
109 unsigned long msr = kdp->private[0];
111 if (kdp->extype & KGDBEXIT_WITHADDR)
112 regs->nip = kdp->exaddr;
114 switch (kdp->extype & KGDBEXIT_TYPEMASK) {
117 case KGDBEXIT_CONTINUE:
121 case KGDBEXIT_SINGLE:
124 set_msr(msr | MSR_SE);
131 kgdb_trap(struct pt_regs *regs)
136 /* return the value of the CPU registers.
137 * some of them are non-PowerPC names :(
138 * they are stored in gdb like:
142 * u32 pc, ps, cnd, lr; (ps=msr)
147 #define SPACE_REQUIRED ((32*4)+(32*8)+(6*4))
150 kgdb_getregs(struct pt_regs *regs, char *buf, int max)
153 unsigned long *ptr = (unsigned long *)buf;
155 if (max < SPACE_REQUIRED)
156 kgdb_error(KGDBERR_NOSPACE);
158 if ((unsigned long)ptr & 3)
159 kgdb_error(KGDBERR_ALIGNFAULT);
161 /* General Purpose Regs */
162 for (i = 0; i < 32; i++)
163 *ptr++ = regs->gpr[i];
165 /* Floating Point Regs */
166 for (i = 0; i < 32; i++) {
171 /* pc, msr, cr, lr, ctr, xer, (mq is unused) */
179 return (SPACE_REQUIRED);
182 /* set the value of the CPU registers */
184 kgdb_putreg(struct pt_regs *regs, int regno, char *buf, int length)
186 unsigned long *ptr = (unsigned long *)buf;
188 if (regno < 0 || regno >= 70)
189 kgdb_error(KGDBERR_BADPARAMS);
190 else if (regno >= 32 && regno < 64) {
192 kgdb_error(KGDBERR_NOSPACE);
196 kgdb_error(KGDBERR_NOSPACE);
199 if ((unsigned long)ptr & 3)
200 kgdb_error(KGDBERR_ALIGNFAULT);
202 if (regno >= 0 && regno < 32)
203 regs->gpr[regno] = *ptr;
204 else switch (regno) {
205 case 64: regs->nip = *ptr; break;
206 case 65: regs->msr = *ptr; break;
207 case 66: regs->ccr = *ptr; break;
208 case 67: regs->link = *ptr; break;
209 case 68: regs->ctr = *ptr; break;
210 case 69: regs->ctr = *ptr; break;
213 kgdb_error(KGDBERR_BADPARAMS);
218 kgdb_putregs(struct pt_regs *regs, char *buf, int length)
221 unsigned long *ptr = (unsigned long *)buf;
223 if (length < SPACE_REQUIRED)
224 kgdb_error(KGDBERR_NOSPACE);
226 if ((unsigned long)ptr & 3)
227 kgdb_error(KGDBERR_ALIGNFAULT);
230 * If the stack pointer has moved, you should pray.
231 * (cause only god can help you).
234 /* General Purpose Regs */
235 for (i = 0; i < 32; i++)
236 regs->gpr[i] = *ptr++;
238 /* Floating Point Regs */
241 /* pc, msr, cr, lr, ctr, xer, (mq is unused) */
250 /* This function will generate a breakpoint exception. It is used at the
251 beginning of a program to sync up with a debugger and can be used
252 otherwise as a quick means to stop program execution and "break" into
256 kgdb_breakpoint(int argc, char *const argv[])
258 asm(" .globl breakinst\n\
259 breakinst: .long 0x7d821008\n\