2 * Microblaze KGDB support
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
9 #include <linux/kgdb.h>
10 #include <linux/kdebug.h>
11 #include <linux/irq.h>
13 #include <asm/cacheflush.h>
14 #include <asm/asm-offsets.h>
30 #define GDB_RTLBSX 54 /* mfs can't read it */
34 /* keep pvr separately because it is unchangeble */
35 static struct pvr_s pvr
;
37 void pt_regs_to_gdb_regs(unsigned long *gdb_regs
, struct pt_regs
*regs
)
40 unsigned long *pt_regb
= (unsigned long *)regs
;
43 /* registers r0 - r31, pc, msr, ear, esr, fsr + do not save pt_mode */
44 for (i
= 0; i
< (sizeof(struct pt_regs
) / 4) - 1; i
++)
45 gdb_regs
[i
] = pt_regb
[i
];
47 /* Branch target register can't be changed */
48 __asm__
__volatile__ ("mfs %0, rbtr;" : "=r"(temp
) : );
49 gdb_regs
[GDB_BTR
] = temp
;
51 /* pvr part - we have 11 pvr regs */
52 for (i
= 0; i
< sizeof(struct pvr_s
)/4; i
++)
53 gdb_regs
[GDB_PVR
+ i
] = pvr
.pvr
[i
];
55 /* read special registers - can't be changed */
56 __asm__
__volatile__ ("mfs %0, redr;" : "=r"(temp
) : );
57 gdb_regs
[GDB_REDR
] = temp
;
58 __asm__
__volatile__ ("mfs %0, rpid;" : "=r"(temp
) : );
59 gdb_regs
[GDB_RPID
] = temp
;
60 __asm__
__volatile__ ("mfs %0, rzpr;" : "=r"(temp
) : );
61 gdb_regs
[GDB_RZPR
] = temp
;
62 __asm__
__volatile__ ("mfs %0, rtlbx;" : "=r"(temp
) : );
63 gdb_regs
[GDB_RTLBX
] = temp
;
64 __asm__
__volatile__ ("mfs %0, rtlblo;" : "=r"(temp
) : );
65 gdb_regs
[GDB_RTLBLO
] = temp
;
66 __asm__
__volatile__ ("mfs %0, rtlbhi;" : "=r"(temp
) : );
67 gdb_regs
[GDB_RTLBHI
] = temp
;
70 void gdb_regs_to_pt_regs(unsigned long *gdb_regs
, struct pt_regs
*regs
)
73 unsigned long *pt_regb
= (unsigned long *)regs
;
75 /* pt_regs and gdb_regs have the same 37 values.
76 * The rest of gdb_regs are unused and can't be changed.
77 * r0 register value can't be changed too. */
78 for (i
= 1; i
< (sizeof(struct pt_regs
) / 4) - 1; i
++)
79 pt_regb
[i
] = gdb_regs
[i
];
82 asmlinkage
void microblaze_kgdb_break(struct pt_regs
*regs
)
84 if (kgdb_handle_exception(1, SIGTRAP
, 0, regs
) != 0)
87 /* Jump over the first arch_kgdb_breakpoint which is barrier to
88 * get kgdb work. The same solution is used for powerpc */
89 if (*(u32
*) (regs
->pc
) == *(u32
*) (&arch_kgdb_ops
.gdb_bpt_instr
))
90 regs
->pc
+= BREAK_INSTR_SIZE
;
94 void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs
, struct task_struct
*p
)
97 unsigned long *pt_regb
= (unsigned long *)(p
->thread
.regs
);
99 /* registers r0 - r31, pc, msr, ear, esr, fsr + do not save pt_mode */
100 for (i
= 0; i
< (sizeof(struct pt_regs
) / 4) - 1; i
++)
101 gdb_regs
[i
] = pt_regb
[i
];
103 /* pvr part - we have 11 pvr regs */
104 for (i
= 0; i
< sizeof(struct pvr_s
)/4; i
++)
105 gdb_regs
[GDB_PVR
+ i
] = pvr
.pvr
[i
];
108 void kgdb_arch_set_pc(struct pt_regs
*regs
, unsigned long ip
)
113 int kgdb_arch_handle_exception(int vector
, int signo
, int err_code
,
114 char *remcom_in_buffer
, char *remcom_out_buffer
,
115 struct pt_regs
*regs
)
118 unsigned long address
;
120 switch (remcom_in_buffer
[0]) {
122 /* handle the optional parameter */
123 ptr
= &remcom_in_buffer
[1];
124 if (kgdb_hex2long(&ptr
, &address
))
129 return -1; /* this means that we do not want to exit from the handler */
132 int kgdb_arch_init(void)
134 get_pvr(&pvr
); /* Fill PVR structure */
138 void kgdb_arch_exit(void)
146 const struct kgdb_arch arch_kgdb_ops
= {
147 #ifdef __MICROBLAZEEL__
148 .gdb_bpt_instr
= {0x18, 0x00, 0x0c, 0xba}, /* brki r16, 0x18 */
150 .gdb_bpt_instr
= {0xba, 0x0c, 0x00, 0x18}, /* brki r16, 0x18 */