157090Sakito /*
257090Sakito * Copyright (c) 1992 OMRON Corporation.
3*63199Sbostic * Copyright (c) 1992, 1993
4*63199Sbostic * The Regents of the University of California. All rights reserved.
557090Sakito *
657090Sakito * This code is derived from software contributed to Berkeley by
757090Sakito * OMRON Corporation.
857090Sakito *
957090Sakito * %sccs.include.redist.c%
1057090Sakito *
11*63199Sbostic * @(#)machdep.c 8.1 (Berkeley) 06/10/93
1257090Sakito */
1357090Sakito
1457090Sakito #include <sys/param.h>
1557090Sakito #include <luna68k/include/reg.h>
1657090Sakito
straytrap(addr)1757090Sakito straytrap(addr)
1857090Sakito register int addr;
1957090Sakito {
2057090Sakito printf("stray trap, addr 0x%x\n", addr);
2157090Sakito }
2257090Sakito
2357090Sakito int *nofault = 0;
2457090Sakito
badaddr(addr)2557090Sakito badaddr(addr)
2657090Sakito register caddr_t addr;
2757090Sakito {
2857090Sakito register int i;
2957090Sakito label_t faultbuf;
3057090Sakito
3157090Sakito #ifdef lint
3257090Sakito i = *addr; if (i) return(0);
3357090Sakito #endif
3457090Sakito nofault = (int *) &faultbuf;
3557090Sakito if (setjmp((label_t *)nofault)) {
3657090Sakito nofault = (int *) 0;
3757090Sakito return(1);
3857090Sakito }
3957090Sakito i = *(volatile short *)addr;
4057090Sakito nofault = (int *) 0;
4157090Sakito return(0);
4257090Sakito }
4357090Sakito
regdump(rp,sbytes)4457090Sakito regdump(rp, sbytes)
4557090Sakito int *rp; /* must not be register */
4657090Sakito int sbytes;
4757090Sakito {
4857090Sakito static int doingdump = 0;
4957090Sakito register int i;
5057090Sakito int s;
5157090Sakito extern char *hexstr();
5257090Sakito
5357090Sakito if (doingdump)
5457090Sakito return;
5557090Sakito s = splhigh();
5657090Sakito doingdump = 1;
5757090Sakito /* printf("pid = %d, pc = %s, ", u.u_procp->p_pid, hexstr(rp[PC], 8)); */
5857090Sakito printf("pc = %s, ", hexstr(rp[PC], 8));
5957090Sakito printf("ps = %s, ", hexstr(rp[PS], 4));
6057090Sakito printf("sfc = %s, ", hexstr(getsfc(), 4));
6157090Sakito printf("dfc = %s\n", hexstr(getdfc(), 4));
6257090Sakito /*
6357090Sakito printf("p0 = %x@%s, ",
6457090Sakito u.u_pcb.pcb_p0lr, hexstr((int)u.u_pcb.pcb_p0br, 8));
6557090Sakito printf("p1 = %x@%s\n\n",
6657090Sakito u.u_pcb.pcb_p1lr, hexstr((int)u.u_pcb.pcb_p1br, 8));
6757090Sakito */
6857090Sakito printf("Registers:\n ");
6957090Sakito for (i = 0; i < 8; i++)
7057090Sakito printf(" %d", i);
7157090Sakito printf("\ndreg:");
7257090Sakito for (i = 0; i < 8; i++)
7357090Sakito printf(" %s", hexstr(rp[i], 8));
7457090Sakito printf("\nareg:");
7557090Sakito for (i = 0; i < 8; i++)
7657090Sakito printf(" %s", hexstr(rp[i+8], 8));
7757090Sakito if (sbytes > 0) {
7857090Sakito /* if (rp[PS] & PSL_S) { */
7957090Sakito printf("\n\nKernel stack (%s):",
8057090Sakito hexstr((int)(((int *)&rp)-1), 8));
8157090Sakito dumpmem(((int *)&rp)-1, sbytes, 0);
8257090Sakito /*
8357090Sakito } else {
8457090Sakito printf("\n\nUser stack (%s):", hexstr(rp[SP], 8));
8557090Sakito dumpmem((int *)rp[SP], sbytes, 1);
8657090Sakito }
8757090Sakito */
8857090Sakito }
8957090Sakito doingdump = 0;
9057090Sakito splx(s);
9157090Sakito }
9257090Sakito
9357090Sakito /* #define KSADDR ((int *)&(((char *)&u)[(UPAGES-1)*NBPG])) */
9457090Sakito
dumpmem(ptr,sz,ustack)9557090Sakito dumpmem(ptr, sz, ustack)
9657090Sakito register int *ptr;
9757090Sakito int sz;
9857090Sakito {
9957090Sakito register int i, val;
10057090Sakito extern char *hexstr();
10157090Sakito
10257090Sakito for (i = 0; i < sz; i++) {
10357090Sakito if ((i & 7) == 0)
10457090Sakito printf("\n%s: ", hexstr((int)ptr, 6));
10557090Sakito else
10657090Sakito printf(" ");
10757090Sakito /*
10857090Sakito if (ustack == 1) {
10957090Sakito if ((val = fuword(ptr++)) == -1)
11057090Sakito break;
11157090Sakito } else {
11257090Sakito if (ustack == 0 && (ptr < KSADDR || ptr > KSADDR+(NBPG/4-1)))
11357090Sakito break;
11457090Sakito */
11557090Sakito val = *ptr++;
11657090Sakito /* } */
11757090Sakito printf("%s", hexstr(val, 8));
11857090Sakito }
11957090Sakito printf("\n");
12057090Sakito }
12157090Sakito
12257090Sakito char *
hexstr(val,len)12357090Sakito hexstr(val, len)
12457090Sakito register int val;
12557090Sakito {
12657090Sakito static char nbuf[9];
12757090Sakito register int x, i;
12857090Sakito
12957090Sakito if (len > 8)
13057090Sakito return("");
13157090Sakito nbuf[len] = '\0';
13257090Sakito for (i = len-1; i >= 0; --i) {
13357090Sakito x = val & 0xF;
13457090Sakito if (x > 9)
13557090Sakito nbuf[i] = x - 10 + 'A';
13657090Sakito else
13757090Sakito nbuf[i] = x + '0';
13857090Sakito val >>= 4;
13957090Sakito }
14057090Sakito return(nbuf);
14157090Sakito }
142