Module Name: src
Committed By: martin
Date: Tue Aug 1 14:36:59 UTC 2023
Modified Files:
src/sys/arch/powerpc/powerpc [netbsd-10]: db_disasm.c db_trace.c
src/usr.sbin/crash [netbsd-10]: Makefile crash.c
src/usr.sbin/crash/arch [netbsd-10]: generic.c
Added Files:
src/usr.sbin/crash/arch [netbsd-10]: powerpc.c powerpc64.c
Log Message:
Pull up following revision(s) (requested by riastradh in ticket #283):
usr.sbin/crash/arch/powerpc.c: revision 1.1
sys/arch/powerpc/powerpc/db_trace.c: revision 1.61
sys/arch/powerpc/powerpc/db_trace.c: revision 1.62
sys/arch/powerpc/powerpc/db_trace.c: revision 1.63
usr.sbin/crash/crash.c: revision 1.15
sys/arch/powerpc/powerpc/db_disasm.c: revision 1.30
sys/arch/powerpc/powerpc/db_disasm.c: revision 1.31
usr.sbin/crash/arch/generic.c: revision 1.2
usr.sbin/crash/Makefile: revision 1.47
usr.sbin/crash/arch/powerpc64.c: revision 1.1
crash(8): Add powerpc support.
powerpc/ddb: Use db_read_bytes, not direct pointer access.
Mark some powerpc-variant ifdefs with XXX crash(8), not sure yet what
to do about them.
powerpc/ddb: Fix one more load to use db_read_bytes.
Fix some typos in crash(8) comments too.
To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.29.20.1 src/sys/arch/powerpc/powerpc/db_disasm.c
cvs rdiff -u -r1.60 -r1.60.20.1 src/sys/arch/powerpc/powerpc/db_trace.c
cvs rdiff -u -r1.46 -r1.46.6.1 src/usr.sbin/crash/Makefile
cvs rdiff -u -r1.14 -r1.14.6.1 src/usr.sbin/crash/crash.c
cvs rdiff -u -r1.1 -r1.1.58.1 src/usr.sbin/crash/arch/generic.c
cvs rdiff -u -r0 -r1.1.2.2 src/usr.sbin/crash/arch/powerpc.c \
src/usr.sbin/crash/arch/powerpc64.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/powerpc/powerpc/db_disasm.c
diff -u src/sys/arch/powerpc/powerpc/db_disasm.c:1.29 src/sys/arch/powerpc/powerpc/db_disasm.c:1.29.20.1
--- src/sys/arch/powerpc/powerpc/db_disasm.c:1.29 Mon Jul 6 10:31:24 2020
+++ src/sys/arch/powerpc/powerpc/db_disasm.c Tue Aug 1 14:36:59 2023
@@ -1,14 +1,16 @@
-/* $NetBSD: db_disasm.c,v 1.29 2020/07/06 10:31:24 rin Exp $ */
+/* $NetBSD: db_disasm.c,v 1.29.20.1 2023/08/01 14:36:59 martin Exp $ */
/* $OpenBSD: db_disasm.c,v 1.2 1996/12/28 06:21:48 rahnds Exp $ */
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.29 2020/07/06 10:31:24 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.29.20.1 2023/08/01 14:36:59 martin Exp $");
#ifdef _KERNEL_OPT
#include "opt_ppcarch.h"
#endif
#include <sys/param.h>
+#include <sys/types.h>
+
#include <sys/proc.h>
#include <sys/systm.h>
@@ -84,8 +86,7 @@ typedef u_int32_t instr_t;
typedef void (op_class_func) (instr_t, vaddr_t);
u_int32_t extract_field(u_int32_t value, u_int32_t base, u_int32_t width);
-void disasm_fields(const struct opcode *popcode, instr_t instr, vaddr_t loc,
- char *disasm_str, size_t slen);
+void disasm_fields(const struct opcode *popcode, instr_t instr, vaddr_t loc);
void dis_ppc(const struct opcode *opcodeset, instr_t instr, vaddr_t loc);
op_class_func op_ill, op_base;
@@ -412,7 +413,7 @@ const struct opcode opcodes_3f[] = {
struct specialreg {
- int reg;
+ unsigned reg;
const char *name;
};
@@ -619,22 +620,9 @@ extract_field(u_int32_t value, u_int32_t
const struct opcode * search_op(const struct opcode *);
void
-disasm_fields(const struct opcode *popcode, instr_t instr, vaddr_t loc,
- char *disasm_str, size_t slen)
+disasm_fields(const struct opcode *popcode, instr_t instr, vaddr_t loc)
{
- char * pstr;
enum function_mask func;
- int len;
-
-#define ADD_LEN(s) do { \
- len = (s); \
- slen -= len; \
- pstr += len; \
- } while(0)
-#define APP_PSTR(fmt, arg) ADD_LEN(snprintf(pstr, slen, (fmt), (arg)))
-#define APP_PSTRS(fmt) ADD_LEN(snprintf(pstr, slen, "%s", (fmt)))
-
- pstr = disasm_str;
func = popcode->func;
if (func & Op_BC) {
@@ -646,12 +634,13 @@ disasm_fields(const struct opcode *popco
/* standard, no decrement */
if (BO & 16) {
if (popcode->code == 0x40000000) {
- APP_PSTRS("c");
+ db_printf("c");
func |= Op_BO | Op_BI;
}
}
else {
- APP_PSTRS(condstr[((BO & 8) >> 1) + (BI & 3)]);
+ db_printf("%s",
+ condstr[((BO & 8) >> 1) + (BI & 3)]);
if (BI >= 4)
func |= Op_crfS;
}
@@ -659,20 +648,20 @@ disasm_fields(const struct opcode *popco
else {
/* decrement and branch */
if (BO & 2)
- APP_PSTRS("dz");
+ db_printf("dz");
else
- APP_PSTRS("dnz");
+ db_printf("dnz");
if ((BO & 24) == 0)
- APP_PSTRS("f");
+ db_printf("f");
else if ((BO & 24) == 8)
- APP_PSTRS("t");
+ db_printf("t");
else
func |= Op_BI;
}
if (popcode->code == 0x4c000020)
- APP_PSTRS("lr");
+ db_printf("lr");
else if (popcode->code == 0x4c000420)
- APP_PSTRS("ctr");
+ db_printf("ctr");
if ((BO & 20) != 20 && (func & Op_BO) == 0)
func |= Op_BP; /* branch prediction hint */
}
@@ -680,26 +669,26 @@ disasm_fields(const struct opcode *popco
u_int OE;
OE = extract_field(instr, 31 - 21, 1);
if (OE) {
- APP_PSTRS("o");
+ db_printf("o");
}
func &= ~Op_OE;
}
switch (func & Op_LKM) {
case Op_Rc:
if (instr & 0x1)
- APP_PSTRS(".");
+ db_printf(".");
break;
case Op_AA:
if (instr & 0x1)
- APP_PSTRS("l");
+ db_printf("l");
if (instr & 0x2) {
- APP_PSTRS("a");
+ db_printf("a");
loc = 0; /* Absolute address */
}
break;
case Op_LK:
if (instr & 0x1)
- APP_PSTRS("l");
+ db_printf("l");
break;
default:
func &= ~Op_LKM;
@@ -716,91 +705,91 @@ disasm_fields(const struct opcode *popco
if ((vaddr_t)BD < loc)
y ^= 1;
}
- APP_PSTR("%c", y ? '+' : '-');
+ db_printf("%c", y ? '+' : '-');
func &= ~Op_BP;
}
- APP_PSTRS("\t");
+ db_printf("\t");
/* XXX: special cases here, out of flags in a 32bit word. */
if (strcmp(popcode->name, "wrteei") == 0) {
int E;
E = extract_field(instr, 31 - 16, 5);
- APP_PSTR("%d", E);
+ db_printf("%d", E);
return;
}
else if (strcmp(popcode->name, "mtfsfi") == 0) {
u_int UI;
UI = extract_field(instr, 31 - 8, 3);
- APP_PSTR("crf%u, ", UI);
+ db_printf("crf%u, ", UI);
UI = extract_field(instr, 31 - 19, 4);
- APP_PSTR("0x%x", UI);
+ db_printf("0x%x", UI);
}
/* XXX: end of special cases here. */
if ((func & Op_FM) == Op_FM) {
u_int FM;
FM = extract_field(instr, 31 - 14, 8);
- APP_PSTR("0x%x, ", FM);
+ db_printf("0x%x, ", FM);
func &= ~Op_FM;
}
if (func & Op_D) { /* Op_ST is the same */
u_int D;
D = extract_field(instr, 31 - 10, 5);
- APP_PSTR("r%d, ", D);
+ db_printf("r%d, ", D);
func &= ~Op_D;
}
if (func & Op_crbD) {
u_int crbD;
crbD = extract_field(instr, 31 - 10, 5);
- APP_PSTR("crb%d, ", crbD);
+ db_printf("crb%d, ", crbD);
func &= ~Op_crbD;
}
if (func & Op_crfD) {
u_int crfD;
crfD = extract_field(instr, 31 - 8, 3);
- APP_PSTR("crf%d, ", crfD);
+ db_printf("crf%d, ", crfD);
func &= ~Op_crfD;
}
if (func & Op_TO) {
u_int TO;
TO = extract_field(instr, 31 - 10, 1);
- APP_PSTR("%d, ", TO);
+ db_printf("%d, ", TO);
func &= ~Op_TO;
}
if (func & Op_crfS) {
u_int crfS;
crfS = extract_field(instr, 31 - 13, 3);
- APP_PSTR("crf%d, ", crfS);
+ db_printf("crf%d, ", crfS);
func &= ~Op_crfS;
}
if (func & Op_CRM) {
u_int CRM;
CRM = extract_field(instr, 31 - 19, 8);
- APP_PSTR("0x%x, ", CRM);
+ db_printf("0x%x, ", CRM);
func &= ~Op_CRM;
}
if (func & Op_BO) {
u_int BO;
BO = extract_field(instr, 31 - 10, 5);
- APP_PSTR("%d, ", BO);
+ db_printf("%d, ", BO);
func &= ~Op_BO;
}
if (func & Op_BI) {
u_int BI;
BI = extract_field(instr, 31 - 15, 5);
- APP_PSTR("%d, ", BI);
+ db_printf("%d, ", BI);
func &= ~Op_BI;
}
if (func & Op_dA) { /* register A indirect with displacement */
u_int A;
A = extract_field(instr, 31 - 31, 16);
if (A & 0x8000) {
- APP_PSTRS("-");
+ db_printf("-");
A = 0x10000-A;
}
- APP_PSTR("0x%x", A);
+ db_printf("0x%x", A);
A = extract_field(instr, 31 - 15, 5);
- APP_PSTR("(r%d)", A);
+ db_printf("(r%d)", A);
func &= ~Op_dA;
}
if (func & Op_spr) {
@@ -822,56 +811,56 @@ disasm_fields(const struct opcode *popco
if (spr == regs[i].reg)
break;
if (regs[i].name == NULL)
- APP_PSTR("[unknown special reg (%d)]", spr);
+ db_printf("[unknown special reg (%d)]", spr);
else
- APP_PSTR("%s", regs[i].name);
+ db_printf("%s", regs[i].name);
if (popcode->name[1] == 't') /* spr is destination */
- APP_PSTRS(", ");
+ db_printf(", ");
func &= ~Op_spr;
}
if (func & Op_SR) {
u_int SR;
SR = extract_field(instr, 31 - 15, 3);
- APP_PSTR("sr%d", SR);
+ db_printf("sr%d", SR);
if (popcode->name[1] == 't') /* SR is destination */
- APP_PSTRS(", ");
+ db_printf(", ");
func &= ~Op_SR;
}
if (func & Op_A) {
u_int A;
A = extract_field(instr, 31 - 15, 5);
- APP_PSTR("r%d, ", A);
+ db_printf("r%d, ", A);
func &= ~Op_A;
}
if (func & Op_S) {
u_int D;
D = extract_field(instr, 31 - 10, 5);
- APP_PSTR("r%d, ", D);
+ db_printf("r%d, ", D);
func &= ~Op_S;
}
if (func & Op_C) {
u_int C;
C = extract_field(instr, 31 - 25, 5);
- APP_PSTR("r%d, ", C);
+ db_printf("r%d, ", C);
func &= ~Op_C;
}
if (func & Op_B) {
u_int B;
B = extract_field(instr, 31 - 20, 5);
- APP_PSTR("r%d", B);
+ db_printf("r%d", B);
func &= ~Op_B;
}
if (func & Op_crbA) {
u_int crbA;
crbA = extract_field(instr, 31 - 15, 5);
- APP_PSTR("%d, ", crbA);
+ db_printf("%d, ", crbA);
func &= ~Op_crbA;
}
if (func & Op_crbB) {
u_int crbB;
crbB = extract_field(instr, 31 - 20, 5);
- APP_PSTR("%d, ", crbB);
+ db_printf("%d, ", crbB);
func &= ~Op_crbB;
}
if (func & Op_LI) {
@@ -881,8 +870,7 @@ disasm_fields(const struct opcode *popco
LI = LI << 8;
LI = LI >> 6;
LI += loc;
- db_symstr(pstr, slen, LI, DB_STGY_ANY);
- ADD_LEN(strlen(pstr));
+ db_printsym(LI, DB_STGY_ANY, db_printf);
func &= ~Op_LI;
}
switch (func & Op_SIMM) {
@@ -890,7 +878,7 @@ disasm_fields(const struct opcode *popco
case Op_SIMM: /* same as Op_d */
IMM = extract_field(instr, 31 - 31, 16);
if (IMM & 0x8000) {
- APP_PSTRS("-");
+ db_printf("-");
IMM = 0x10000-IMM;
}
func &= ~Op_SIMM;
@@ -900,7 +888,7 @@ disasm_fields(const struct opcode *popco
func &= ~Op_UIMM;
goto common;
common:
- APP_PSTR("0x%x", IMM);
+ db_printf("0x%x", IMM);
break;
default:
;
@@ -912,14 +900,13 @@ disasm_fields(const struct opcode *popco
BD = BD << 18;
BD = BD >> 16;
BD += loc;
- db_symstr(pstr, slen, BD, DB_STGY_ANY);
- ADD_LEN(strlen(pstr));
+ db_printsym(BD, DB_STGY_ANY, db_printf);
func &= ~Op_BD;
}
if (func & Op_ds) {
u_int ds;
ds = extract_field(instr, 31 - 29, 14) << 2;
- APP_PSTR("0x%x", ds);
+ db_printf("0x%x", ds);
func &= ~Op_ds;
}
if (func & Op_me) {
@@ -927,42 +914,42 @@ disasm_fields(const struct opcode *popco
mel = extract_field(instr, 31 - 25, 4);
meh = extract_field(instr, 31 - 26, 1);
me = meh << 4 | mel;
- APP_PSTR(", 0x%x", me);
+ db_printf(", 0x%x", me);
func &= ~Op_me;
}
if ((func & Op_SH) && (func & Op_sh_mb_sh)) {
u_int SH;
SH = extract_field(instr, 31 - 20, 5);
- APP_PSTR("%d", SH);
+ db_printf("%d", SH);
}
if ((func & Op_MB) && (func & Op_sh_mb_sh)) {
u_int MB;
u_int ME;
MB = extract_field(instr, 31 - 25, 5);
- APP_PSTR(", %d", MB);
+ db_printf(", %d", MB);
ME = extract_field(instr, 31 - 30, 5);
- APP_PSTR(", %d", ME);
+ db_printf(", %d", ME);
}
if ((func & Op_sh) && ! (func & Op_sh_mb_sh)) {
u_int sh, shl, shh;
shl = extract_field(instr, 31 - 19, 4);
shh = extract_field(instr, 31 - 20, 1);
sh = shh << 4 | shl;
- APP_PSTR(", %d", sh);
+ db_printf(", %d", sh);
}
if ((func & Op_mb) && ! (func & Op_sh_mb_sh)) {
u_int mb, mbl, mbh;
mbl = extract_field(instr, 31 - 25, 4);
mbh = extract_field(instr, 31 - 26, 1);
mb = mbh << 4 | mbl;
- APP_PSTR(", %d", mb);
+ db_printf(", %d", mb);
}
if ((func & Op_me) && ! (func & Op_sh_mb_sh)) {
u_int me, mel, meh;
mel = extract_field(instr, 31 - 25, 4);
meh = extract_field(instr, 31 - 26, 1);
me = meh << 4 | mel;
- APP_PSTR(", %d", me);
+ db_printf(", %d", me);
}
if (func & Op_tbr) {
u_int tbr;
@@ -984,9 +971,9 @@ disasm_fields(const struct opcode *popco
reg = 0;
}
if (reg == 0)
- APP_PSTR(", [unknown tbr %d ]", tbr);
+ db_printf(", [unknown tbr %d ]", tbr);
else
- APP_PSTR(", %s", reg);
+ db_printf(", %s", reg);
func &= ~Op_tbr;
}
if (func & Op_NB) {
@@ -994,12 +981,9 @@ disasm_fields(const struct opcode *popco
NB = extract_field(instr, 31 - 20, 5);
if (NB == 0)
NB = 32;
- APP_PSTR(", %d", NB);
+ db_printf(", %d", NB);
func &= ~Op_SR;
}
-#undef ADD_LEN
-#undef APP_PSTR
-#undef APP_PSTRS
}
void
@@ -1056,16 +1040,14 @@ dis_ppc(const struct opcode *opcodeset,
const struct opcode *op;
int found = 0;
int i;
- char disasm_str[80];
for (i = 0, op = &opcodeset[0];
found == 0 && op->mask != 0;
i++, op = &opcodeset[i]) {
if ((instr & op->mask) == op->code) {
found = 1;
- disasm_fields(op, instr, loc, disasm_str,
- sizeof disasm_str);
- db_printf("%s%s\n", op->name, disasm_str);
+ db_printf("%s", op->name);
+ disasm_fields(op, instr, loc);
return;
}
}
@@ -1077,7 +1059,8 @@ db_disasm(db_addr_t loc, bool extended)
{
int class;
instr_t opcode;
- opcode = *(instr_t *)(loc);
+
+ db_read_bytes(loc, sizeof(opcode), (char *)&opcode);
class = opcode >> 26;
(opcodes_base[class])(opcode, loc);
Index: src/sys/arch/powerpc/powerpc/db_trace.c
diff -u src/sys/arch/powerpc/powerpc/db_trace.c:1.60 src/sys/arch/powerpc/powerpc/db_trace.c:1.60.20.1
--- src/sys/arch/powerpc/powerpc/db_trace.c:1.60 Mon Jul 6 09:34:18 2020
+++ src/sys/arch/powerpc/powerpc/db_trace.c Tue Aug 1 14:36:59 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: db_trace.c,v 1.60 2020/07/06 09:34:18 rin Exp $ */
+/* $NetBSD: db_trace.c,v 1.60.20.1 2023/08/01 14:36:59 martin Exp $ */
/* $OpenBSD: db_trace.c,v 1.3 1997/03/21 02:10:48 niklas Exp $ */
/*
@@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.60 2020/07/06 09:34:18 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.60.20.1 2023/08/01 14:36:59 martin Exp $");
#ifdef _KERNEL_OPT
#include "opt_ppcarch.h"
@@ -53,14 +53,29 @@ __KERNEL_RCSID(0, "$NetBSD: db_trace.c,v
#elif defined(PPC_BOOKE)
#include <powerpc/booke/spr.h>
#else
-#include unknown powerpc variants
+#ifdef _KERNEL
+#error unknown powerpc variants
+#endif
+#endif
+
+#ifndef _KERNEL /* crash(8) */
+#include <unistd.h>
+#define PAGE_SIZE ((unsigned)sysconf(_SC_PAGESIZE))
#endif
#include <ddb/db_access.h>
#include <ddb/db_interface.h>
+#include <ddb/db_proc.h>
#include <ddb/db_sym.h>
#include <ddb/db_variables.h>
+#define R(P) \
+({ \
+ __typeof__(*(P)) __db_tmp; \
+ db_read_bytes((db_addr_t)(P), sizeof(*(P)), (char *)&__db_tmp); \
+ __db_tmp; \
+})
+
const struct db_variable db_regs[] = {
{ "r0", (long *)&ddb_regs.r[0], FCN_NULL, NULL },
{ "r1", (long *)&ddb_regs.r[1], FCN_NULL, NULL },
@@ -101,7 +116,7 @@ const struct db_variable db_regs[] = {
{ "cr", (long *)&ddb_regs.cr, FCN_NULL, NULL },
{ "xer", (long *)&ddb_regs.xer, FCN_NULL, NULL },
{ "mq", (long *)&ddb_regs.mq, FCN_NULL, NULL },
-#ifdef PPC_IBM4XX
+#ifdef PPC_IBM4XX /* XXX crash(8) */
{ "dear", (long *)&ddb_regs.dear, FCN_NULL, NULL },
{ "esr", (long *)&ddb_regs.esr, FCN_NULL, NULL },
{ "pid", (long *)&ddb_regs.pid, FCN_NULL, NULL },
@@ -125,10 +140,14 @@ db_stack_trace_print(db_expr_t addr, boo
bool kernel_only = true;
bool trace_thread = false;
bool lwpaddr = false;
+#ifdef _KERNEL
extern int trapexit[], sctrapexit[];
#ifdef PPC_BOOKE
extern int intrcall[];
#endif
+#else
+ extern void *trapexit, *sctrapexit, *intrcall;
+#endif
bool full = false;
bool in_kernel = true;
@@ -153,24 +172,24 @@ db_stack_trace_print(db_expr_t addr, boo
if (lwpaddr) {
l = (struct lwp *)addr;
- p = l->l_proc;
- (*pr)("trace: pid %d ", p->p_pid);
+ p = R(&l->l_proc);
+ (*pr)("trace: pid %d ", R(&p->p_pid));
} else {
(*pr)("trace: pid %d ", (int)addr);
- p = proc_find_raw(addr);
+ p = db_proc_find((pid_t)addr);
if (p == NULL) {
(*pr)("not found\n");
return;
}
- l = LIST_FIRST(&p->p_lwps);
+ l = R(&LIST_FIRST(&p->p_lwps));
if (l == NULL) {
(*pr)("trace: no LWP?\n");
return;
}
}
- (*pr)("lid %d ", l->l_lid);
- pcb = lwp_getpcb(l);
- frame = (db_addr_t)pcb->pcb_sp;
+ (*pr)("lid %d ", R(&l->l_lid));
+ pcb = R(&l->l_addr); /* lwp_getpcb */
+ frame = (db_addr_t)R(&pcb->pcb_sp);
(*pr)("at %p\n", frame);
} else
frame = (db_addr_t)addr;
@@ -180,7 +199,7 @@ db_stack_trace_print(db_expr_t addr, boo
for (;;) {
if (frame < PAGE_SIZE)
break;
- frame = *(db_addr_t *)frame;
+ frame = R((db_addr_t *)frame);
next_frame:
args = (db_addr_t *)(frame + 8);
if (frame < PAGE_SIZE)
@@ -188,7 +207,7 @@ db_stack_trace_print(db_expr_t addr, boo
if (count-- == 0)
break;
- lr = *(db_addr_t *)(frame + 4) - 4;
+ lr = R((db_addr_t *)(frame + 4)) - 4;
if ((lr & 3) || (lr < 0x100)) {
(*pr)("saved LR(0x%x) is invalid.", lr);
break;
@@ -196,36 +215,42 @@ db_stack_trace_print(db_expr_t addr, boo
(*pr)("0x%08lx: ", frame);
if (lr + 4 == (db_addr_t) trapexit ||
-#ifdef PPC_BOOKE
+#if !defined(_KERNEL) || defined(PPC_BOOKE) /* XXX crash(8) */
lr + 4 == (db_addr_t) intrcall ||
#endif
lr + 4 == (db_addr_t) sctrapexit) {
const char *trapstr;
- struct trapframe *tf = &((struct ktrapframe *)frame)->ktf_tf;
- (*pr)("%s ", tf->tf_srr1 & PSL_PR ? "user" : "kernel");
+ struct trapframe *tf =
+ &((struct ktrapframe *)frame)->ktf_tf;
+ (*pr)("%s ",
+ R(&tf->tf_srr1) & PSL_PR ? "user" : "kernel");
if (lr + 4 == (db_addr_t) sctrapexit) {
- (*pr)("SC trap #%d by ", tf->tf_fixreg[0]);
+ (*pr)("SC trap #%d by ", R(&tf->tf_fixreg[0]));
goto print_trap;
}
- switch (tf->tf_exc) {
+ switch (R(&tf->tf_exc)) {
case EXC_DSI:
-#ifdef PPC_OEA
+#ifdef PPC_OEA /* XXX crash(8) */
(*pr)("DSI %s trap @ %#x by ",
- tf->tf_dsisr & DSISR_STORE ? "write" : "read",
- tf->tf_dar);
+ (R(&tf->tf_dsisr) & DSISR_STORE
+ ? "write"
+ : "read"),
+ R(&tf->tf_dar));
#endif
-#ifdef PPC_IBM4XX
+#ifdef PPC_IBM4XX /* XXX crash(8) */
trapstr = "DSI";
dsi:
(*pr)("%s %s trap @ %#x by ", trapstr,
- tf->tf_esr & ESR_DST ? "write" : "read",
- tf->tf_dear);
+ (R(&tf->tf_esr) & ESR_DST
+ ? "write"
+ : "read"),
+ R(&tf->tf_dear));
#endif
goto print_trap;
case EXC_ALI:
-#ifdef PPC_OEA
+#ifdef PPC_OEA /* XXX crash(8) */
(*pr)("ALI trap @ %#x (DSISR %#x) ",
- tf->tf_dar, tf->tf_dsisr);
+ R(&tf->tf_dar), R(&tf->tf_dsisr));
goto print_trap;
#else
trapstr = "ALI"; break;
@@ -246,7 +271,7 @@ dsi:
case EXC_SMI: trapstr = "SMI"; break;
case EXC_RST: trapstr = "RST"; break;
case EXC_DTMISS: trapstr = "DTMISS";
-#ifdef PPC_IBM4XX
+#ifdef PPC_IBM4XX /* XXX crash(8) */
goto dsi;
#endif
break;
@@ -259,41 +284,46 @@ dsi:
if (trapstr != NULL) {
(*pr)("%s trap by ", trapstr);
} else {
- (*pr)("trap %#x by ", tf->tf_exc);
+ (*pr)("trap %#x by ", R(&tf->tf_exc));
}
print_trap:
- lr = (db_addr_t) tf->tf_srr0;
+ lr = (db_addr_t)R(&tf->tf_srr0);
diff = 0;
symname = NULL;
- if (in_kernel && (tf->tf_srr1 & PSL_PR) == 0) {
+ if (in_kernel && (R(&tf->tf_srr1) & PSL_PR) == 0) {
sym = db_search_symbol(lr, DB_STGY_ANY, &diff);
db_symbol_values(sym, &symname, 0);
}
if (symname == NULL || !strcmp(symname, "end")) {
- (*pr)("%p: srr1=%#x\n", lr, tf->tf_srr1);
+ (*pr)("%p: srr1=%#x\n", lr, R(&tf->tf_srr1));
} else {
(*pr)("%s+%#x: srr1=%#x\n", symname,
- diff, tf->tf_srr1);
+ diff, R(&tf->tf_srr1));
}
(*pr)("%-10s r1=%#x cr=%#x xer=%#x ctr=%#x",
- "", tf->tf_fixreg[1], tf->tf_cr, tf->tf_xer, tf->tf_ctr);
-#ifdef PPC_OEA
- if (tf->tf_exc == EXC_DSI)
- (*pr)(" dsisr=%#x", tf->tf_dsisr);
-#ifdef PPC_OEA601
- if ((mfpvr() >> 16) == MPC601)
- (*pr)(" mq=%#x", tf->tf_mq);
+ "",
+ R(&tf->tf_fixreg[1]),
+ R(&tf->tf_cr),
+ R(&tf->tf_xer),
+ R(&tf->tf_ctr));
+#ifdef PPC_OEA /* XXX crash(8) */
+ if (R(&tf->tf_exc) == EXC_DSI)
+ (*pr)(" dsisr=%#x", R(&tf->tf_dsisr));
+#ifdef PPC_OEA601 /* XXX crash(8) */
+ if ((mfpvr() >> 16) == MPC601) /* XXX crash(8) */
+ (*pr)(" mq=%#x", R(&tf->tf_mq));
#endif /* PPC_OEA601 */
#endif /* PPC_OEA */
-#ifdef PPC_IBM4XX
- if (tf->tf_exc == EXC_DSI ||
- tf->tf_exc == EXC_DTMISS)
- (*pr)(" dear=%#x", tf->tf_dear);
- (*pr)(" esr=%#x pid=%#x", tf->tf_esr, tf->tf_pid);
+#ifdef PPC_IBM4XX /* XXX crash(8) */
+ if (R(&tf->tf_exc) == EXC_DSI ||
+ R(&tf->tf_exc) == EXC_DTMISS)
+ (*pr)(" dear=%#x", R(&tf->tf_dear));
+ (*pr)(" esr=%#x pid=%#x", R(&tf->tf_esr),
+ R(&tf->tf_pid));
#endif
(*pr)("\n");
- frame = (db_addr_t) tf->tf_fixreg[1];
- in_kernel = !(tf->tf_srr1 & PSL_PR);
+ frame = (db_addr_t)R(&tf->tf_fixreg[1]);
+ in_kernel = !(R(&tf->tf_srr1) & PSL_PR);
if (kernel_only && !in_kernel)
break;
goto next_frame;
@@ -312,8 +342,8 @@ dsi:
if (full)
/* Print all the args stored in that stackframe. */
(*pr)("(%lx, %lx, %lx, %lx, %lx, %lx, %lx, %lx)",
- args[0], args[1], args[2], args[3],
- args[4], args[5], args[6], args[7]);
+ R(&args[0]), R(&args[1]), R(&args[2]), R(&args[3]),
+ R(&args[4]), R(&args[5]), R(&args[6]), R(&args[7]));
(*pr)("\n");
}
}
Index: src/usr.sbin/crash/Makefile
diff -u src/usr.sbin/crash/Makefile:1.46 src/usr.sbin/crash/Makefile:1.46.6.1
--- src/usr.sbin/crash/Makefile:1.46 Tue Apr 13 08:55:06 2021
+++ src/usr.sbin/crash/Makefile Tue Aug 1 14:36:59 2023
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.46 2021/04/13 08:55:06 mrg Exp $
+# $NetBSD: Makefile,v 1.46.6.1 2023/08/01 14:36:59 martin Exp $
PROG= crash
MAN= crash.8
@@ -21,12 +21,16 @@ DPADD+= ${LIBUTIL} ${LIBKVM} ${LIBEDIT}
|| ${MACHINE_CPU} == "arm" \
|| ${MACHINE_CPU} == "aarch64" \
|| ${MACHINE_CPU} == "mips" \
- || ${MACHINE_ARCH} == "m68k"
+ || ${MACHINE_ARCH} == "m68k" \
+ || ${MACHINE_ARCH} == "powerpc" \
+ || ${MACHINE_ARCH} == "powerpc64"
SRCS+= db_trace.c
.if ${MACHINE_CPU} == "mips"
SRCS+= db_interface.c mips_stacktrace.c
CPPFLAGS+= -DDDB
-.elif ${MACHINE_ARCH} != "m68k"
+.elif ${MACHINE_ARCH} != "m68k" \
+ && ${MACHINE_ARCH} != "powerpc" \
+ && ${MACHINE_ARCH} != "powerpc64"
SRCS+= db_machdep.c
.endif
REALCRASH=yes
Index: src/usr.sbin/crash/crash.c
diff -u src/usr.sbin/crash/crash.c:1.14 src/usr.sbin/crash/crash.c:1.14.6.1
--- src/usr.sbin/crash/crash.c:1.14 Mon Aug 17 04:15:33 2020
+++ src/usr.sbin/crash/crash.c Tue Aug 1 14:36:59 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: crash.c,v 1.14 2020/08/17 04:15:33 mrg Exp $ */
+/* $NetBSD: crash.c,v 1.14.6.1 2023/08/01 14:36:59 martin Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -31,10 +31,10 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: crash.c,v 1.14 2020/08/17 04:15:33 mrg Exp $");
+__RCSID("$NetBSD: crash.c,v 1.14.6.1 2023/08/01 14:36:59 martin Exp $");
#endif /* not lint */
-#include <ddb/ddb.h>
+#include <sys/types.h>
#include <sys/fcntl.h>
#include <sys/mman.h>
@@ -45,6 +45,8 @@ __RCSID("$NetBSD: crash.c,v 1.14 2020/08
#include <machine/frame.h>
#endif
+#include <ddb/ddb.h>
+
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
Index: src/usr.sbin/crash/arch/generic.c
diff -u src/usr.sbin/crash/arch/generic.c:1.1 src/usr.sbin/crash/arch/generic.c:1.1.58.1
--- src/usr.sbin/crash/arch/generic.c:1.1 Sat Mar 7 22:08:08 2009
+++ src/usr.sbin/crash/arch/generic.c Tue Aug 1 14:36:59 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: generic.c,v 1.1 2009/03/07 22:08:08 ad Exp $ */
+/* $NetBSD: generic.c,v 1.1.58.1 2023/08/01 14:36:59 martin Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -31,9 +31,11 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: generic.c,v 1.1 2009/03/07 22:08:08 ad Exp $");
+__RCSID("$NetBSD: generic.c,v 1.1.58.1 2023/08/01 14:36:59 martin Exp $");
#endif /* not lint */
+#include <sys/types.h>
+
#include <ddb/ddb.h>
#include <kvm.h>
Added files:
Index: src/usr.sbin/crash/arch/powerpc.c
diff -u /dev/null src/usr.sbin/crash/arch/powerpc.c:1.1.2.2
--- /dev/null Tue Aug 1 14:36:59 2023
+++ src/usr.sbin/crash/arch/powerpc.c Tue Aug 1 14:36:59 2023
@@ -0,0 +1,66 @@
+/* $NetBSD: powerpc.c,v 1.1.2.2 2023/08/01 14:36:59 martin Exp $ */
+
+/*-
+ * Copyright (c) 2023 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: powerpc.c,v 1.1.2.2 2023/08/01 14:36:59 martin Exp $");
+
+#include <err.h>
+#include <kvm.h>
+#include <stdlib.h>
+
+#include "extern.h"
+
+enum {
+ N_TRAPEXIT,
+ N_SCTRAPEXIT,
+ N_INTRCALL,
+ N
+};
+
+void *trapexit;
+void *sctrapexit;
+void *intrcall;
+
+static struct nlist nl[] = {
+ [N_TRAPEXIT] = { .n_name = "trapexit" },
+ [N_SCTRAPEXIT] = { .n_name = "sctrapexit" },
+ [N_INTRCALL] = { .n_name = "intrcall" },
+ [N] = { .n_name = NULL },
+};
+
+void
+db_mach_init(kvm_t *kd)
+{
+
+ if (kvm_nlist(kd, nl) == -1)
+ errx(EXIT_FAILURE, "kvm_nlist: %s", kvm_geterr(kd));
+
+ trapexit = (void *)nl[N_TRAPEXIT].n_value;
+ sctrapexit = (void *)nl[N_SCTRAPEXIT].n_value;
+ intrcall = (void *)nl[N_INTRCALL].n_value;
+}
Index: src/usr.sbin/crash/arch/powerpc64.c
diff -u /dev/null src/usr.sbin/crash/arch/powerpc64.c:1.1.2.2
--- /dev/null Tue Aug 1 14:36:59 2023
+++ src/usr.sbin/crash/arch/powerpc64.c Tue Aug 1 14:36:59 2023
@@ -0,0 +1 @@
+#include "powerpc.c"