rudimentary DDB support.

This commit is contained in:
ragge 1995-06-16 15:36:37 +00:00
parent 7aaf918c75
commit 63a9ff56e7
8 changed files with 319 additions and 93 deletions

View File

@ -0,0 +1,227 @@
/* $NetBSD: db_machdep.c,v 1.1 1995/06/16 15:36:43 ragge Exp $ */
/*
* Mach Operating System
* Copyright (c) 1991,1990 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*
* db_interface.c,v 2.4 1991/02/05 17:11:13 mrt (CMU)
*/
/*
* Interface to new debugger.
* Taken from i386 port and modified for vax.
*/
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/reboot.h>
#include <sys/systm.h> /* just for boothowto --eichin */
#include <ddb/db_variables.h>
#include <vm/vm.h>
#include <machine/db_machdep.h>
#include <machine/trap.h>
#include <machine/../vax/gencons.h>
#include <setjmp.h>
extern jmp_buf *db_recover;
int db_active = 0;
/*
* kdb_trap - field a TRACE or BPT trap
*/
int
kdb_trap(frame)
struct trapframe *frame;
{
int s;
if ((boothowto&RB_KDB) == 0)
return(0);
switch (frame->trap) {
case T_BPTFLT: /* breakpoint */
case T_TRCTRAP: /* single_step */
break;
default:
kdbprinttrap(frame->trap, frame->code);
if (db_recover != 0) {
db_error("Faulted in DDB; continuing...\n");
/*NOTREACHED*/
}
}
bcopy(frame, &ddb_regs, sizeof(struct trapframe));
/* XXX Should switch to interrupt stack here. */
s = splddb();
mtpr(0, PR_RXCS);
mtpr(0, PR_TXCS);
db_active++;
db_trap(frame->trap, frame->code);
db_active--;
mtpr(GC_RIE, PR_RXCS);
mtpr(GC_TIE, PR_TXCS);
splx(s);
bcopy(&ddb_regs, frame, sizeof(struct trapframe));
return (1);
}
extern char *traptypes[];
extern int no_traps;
/*
* Print trap reason.
*/
kdbprinttrap(type, code)
int type, code;
{
db_printf("kernel: ");
if (type >= no_traps || type < 0)
db_printf("type %d", type);
else
db_printf("%s", traptypes[type]);
db_printf(" trap, code=%x\n", code);
}
/*
* Read bytes from kernel address space for debugger.
*/
void
db_read_bytes(addr, size, data)
vm_offset_t addr;
register int size;
register char *data;
{
register char *src;
src = (char *)addr;
while (--size >= 0)
*data++ = *src++;
}
/*
* Write bytes to kernel address space for debugger.
*/
void
db_write_bytes(addr, size, data)
vm_offset_t addr;
register int size;
register char *data;
{
register char *dst;
printf("db_write_bytes: addr %x, size %x, data %x\n",addr, size, data);
}
int
Debugger()
{
int s=splx(0xe); /* Is this good? We must lower anyway... */
mtpr(0xf,PR_SIRR); /* beg for debugger */
splx(s);
}
/*
* Machine register set.
* XXX - lost stackpointer.
*/
struct db_variable db_regs[] = {
"r0", &ddb_regs.r0, FCN_NULL,
"r1", &ddb_regs.r1, FCN_NULL,
"r2", &ddb_regs.r2, FCN_NULL,
"r3", &ddb_regs.r3, FCN_NULL,
"r4", &ddb_regs.r4, FCN_NULL,
"r5", &ddb_regs.r5, FCN_NULL,
"r6", &ddb_regs.r6, FCN_NULL,
"r7", &ddb_regs.r7, FCN_NULL,
"r8", &ddb_regs.r8, FCN_NULL,
"r9", &ddb_regs.r9, FCN_NULL,
"r10", &ddb_regs.r10, FCN_NULL,
"r11", &ddb_regs.r11, FCN_NULL,
"ap", &ddb_regs.ap, FCN_NULL,
"fp", &ddb_regs.fp, FCN_NULL,
"pc", &ddb_regs.pc, FCN_NULL,
"psl", &ddb_regs.psl, FCN_NULL,
};
struct db_variable *db_eregs = db_regs + sizeof(db_regs)/sizeof(db_regs[0]);
void
db_stack_trace_cmd(addr, have_addr, count, modif)
db_expr_t addr;
boolean_t have_addr;
db_expr_t count;
char *modif;
{
printf("db_stack_trace_cmd - not yet...\n");
}
/*
* Disassemble instruction at 'loc'. 'altfmt' specifies an
* (optional) alternate format. Return address of start of
* next instruction.
*/
db_addr_t
db_disasm(loc, altfmt)
db_addr_t loc;
boolean_t altfmt;
{
printf("db_disasm - not yet...\n");
return loc;
}
static int ddbescape = 0;
int
kdbrint(tkn)
int tkn;
{
if (ddbescape && ((tkn & 0x7f) == 'D')) {
mtpr(0xf, PR_SIRR);
return 1;
}
if ((ddbescape == 0) && ((tkn & 0x7f) == 27)) {
ddbescape = 1;
return 1;
}
if (ddbescape) {
ddbescape = 0;
return 2;
}
ddbescape = 0;
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: gencons.c,v 1.4 1995/05/03 19:20:11 ragge Exp $ */
/* $NetBSD: gencons.c,v 1.5 1995/06/16 15:36:37 ragge Exp $ */
/*
* Copyright (c) 1994 Gordon W. Ross
@ -43,9 +43,12 @@
#include "sys/file.h"
#include "sys/conf.h"
#include "sys/device.h"
#include "sys/reboot.h"
#include "dev/cons.h"
#include "vax/include/mtpr.h"
#include "vax/vax/gencons.h"
#include "machine/mtpr.h"
#include "machine/../vax/gencons.h"
struct tty *gencntty[1];
@ -176,10 +179,24 @@ gencnstart(tp)
out: splx(s);
}
gencnrint(){
gencnrint()
{
struct tty *tp=gencntty[0];
int i, j;
(*linesw[tp->t_line].l_rint)(mfpr(PR_RXDB),tp);
i = mfpr(PR_RXDB);
#ifdef DDB
if (boothowto & RB_KDB) {
j = kdbrint(i);
if (j == 1)
return;
if (j == 2)
(*linesw[tp->t_line].l_rint)(27, tp);
}
#endif
(*linesw[tp->t_line].l_rint)(i,tp);
return;
}
@ -253,7 +270,7 @@ gencngetc(dev)
dev_t dev;
{
while((mfpr(PR_RXCS)&GC_DON)==0); /* Receive chr */
return mfpr(PR_RXDB);
return mfpr(PR_RXDB) & 0x7f;
}
conout(str)

View File

@ -1,4 +1,4 @@
/* $NetBSD: intvec.s,v 1.10 1995/06/05 16:26:43 ragge Exp $ */
/* $NetBSD: intvec.s,v 1.11 1995/06/16 15:36:40 ragge Exp $ */
/*
* Copyright (c) 1994 Ludd, University of Lule}, Sweden.
@ -114,7 +114,7 @@ _rpb:
INTVEC(netint, ISTACK) # Network interrupt
INTVEC(strayB4, ISTACK) # Unused, B4
INTVEC(strayB8, ISTACK) # Unused, B8
INTVEC(strayBC, ISTACK) # Unused, BC
INTVEC(ddbtrap, ISTACK) # Kernel debugger trap, BC
INTVEC(hardclock,ISTACK) # Interval Timer
INTVEC(strayC4, ISTACK) # Unused, C4
INTVEC(emulate, KSTACK) # Subset instruction emulation
@ -170,14 +170,11 @@ L4: addl2 (sp)+,sp # remove info pushed on stack
movl _memtest,(sp) # REI to new adress
rei
.align 2
STRAY(0, 08)
TRAPCALL(invkstk, T_KSPNOTVAL)
STRAY(0, 0C)
TRAPCALL(privinflt, T_PRIVINFLT)
STRAY(0, 14)
TRAPCALL(resopflt, T_RESOPFLT)
TRAPCALL(resadflt, T_RESADFLT)
@ -231,24 +228,6 @@ syscall:
mtpr $0x1f,$PR_IPL # Be sure we can REI
rei
.align 2 # Main system call
.globl invkstk
invkstk:
pushl $0
pushl $0
pushr $0xfff
pushl ap
pushl fp
pushl sp # pointer to syscall frame; defined in trap.h
calls $1,_invkstk
movl (sp)+,fp
movl (sp)+,ap
popr $0xfff
addl2 $8,sp
mtpr $0x1f,$PR_IPL # Be sure we can REI
rei
STRAY(0, 44)
STRAY(0, 48)
STRAY(0, 4C)
@ -285,7 +264,7 @@ invkstk:
STRAY(0, B4)
STRAY(0, B8)
STRAY(0, BC)
TRAPCALL(ddbtrap,T_KDBTRAP)
.align 2
.globl hardclock

View File

@ -1,4 +1,4 @@
/* $NetBSD: locore.c,v 1.7 1995/06/05 16:26:49 ragge Exp $ */
/* $NetBSD: locore.c,v 1.8 1995/06/16 15:36:42 ragge Exp $ */
/*
* Copyright (c) 1994 Ludd, University of Lule}, Sweden.
@ -35,6 +35,10 @@
#include "sys/param.h"
#include "sys/types.h"
#include "sys/reboot.h"
#include "vm/vm.h"
#include "machine/cpu.h"
#include "machine/sid.h"
#include "machine/uvaxII.h"
@ -42,12 +46,12 @@
#include "machine/param.h"
#include "machine/vmparam.h"
#include "machine/pcb.h"
#include "vm/vm.h"
#define ROUND_PAGE(x) (((uint)(x)+PAGE_SIZE-1)& ~(PAGE_SIZE-1))
u_int proc0paddr;
volatile int cpunumber, *Sysmap, boothowto, cpu_type;
volatile char *esym;
extern volatile int bootdev;
/*
@ -67,6 +71,7 @@ start(how, dev)
mtpr(0x1f,PR_IPL); /* No interrupts before istack is ok, please */
#ifdef COMPAT_RENO
asm("
movl r9,_esym
movl r10,_bootdev
movl r11,_boothowto
jsb ett
@ -90,13 +95,19 @@ to_kmem:
*/
PAGE_SIZE = NBPG*2; /* Set logical page size */
proc0paddr=ROUND_PAGE(&end);
#ifdef DDB
if ((boothowto & RB_KDB) != 0)
proc0paddr = ROUND_PAGE(esym) | 0x80000000;
else
#endif
proc0paddr = ROUND_PAGE(&end);
mtpr(proc0paddr, PR_PCBB); /* must be set before ksp for some cpus */
mtpr(proc0paddr+UPAGES*NBPG,PR_KSP); /* new kernel stack */
/*
* Set logical page size and put Sysmap on its place.
*/
/*
* Set logical page size and put Sysmap on its place.
*/
Sysmap=(u_int *)ROUND_PAGE(mfpr(PR_KSP));
/* Be sure some important internal registers have safe values */

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.13 1995/06/05 16:26:59 ragge Exp $ */
/* $NetBSD: machdep.c,v 1.14 1995/06/16 15:36:44 ragge Exp $ */
/*
* Copyright (c) 1994 Ludd, University of Lule}, Sweden.
@ -342,7 +342,9 @@ setstatclockrate()
consinit()
{
/* cninit(); */
#ifdef DDB
ddb_init();
#endif
}
struct sigretargs {

View File

@ -1,4 +1,4 @@
/* $NetBSD: pmap.c,v 1.13 1995/06/05 16:27:07 ragge Exp $ */
/* $NetBSD: pmap.c,v 1.14 1995/06/16 15:36:47 ragge Exp $ */
#define DEBUG
/*
* Copyright (c) 1994 Ludd, University of Lule}, Sweden.
@ -76,6 +76,7 @@ extern uint etext;
extern u_int *pte_cmap;
extern int maxproc;
extern struct vmspace vmspace0;
extern int edata, end;
uint* UMEMmap;
void* Numem;
void *scratch;
@ -91,12 +92,8 @@ vm_map_t pte_map;
vm_offset_t avail_start, avail_end;
vm_offset_t virtual_avail, virtual_end; /* Available virtual memory */
/******************************************************************************
*
* pmap_bootstrap()
*
******************************************************************************
*
/*
* pmap_bootstrap().
* Called as part of vm bootstrap, allocates internal pmap structures.
* Assumes that nothing is mapped, and that kernel stack is located
* immediately after end.
@ -107,6 +104,7 @@ pmap_bootstrap()
{
uint i;
extern u_int sigcode, esigcode, proc0paddr;
extern char *esym;
struct pmap *p0pmap=&vmspace0.vm_pmap;
vm_offset_t pend=0;
#define ROUND_PAGE(x) (((uint)(x) + PAGE_SIZE-1)& ~(PAGE_SIZE - 1))
@ -140,6 +138,8 @@ pmap_bootstrap()
virtual_end=SYSPTSIZE*NBPG+KERNBASE;
#ifdef DEBUG
printf("Sysmap %x, istack %x, scratch %x\n",Sysmap,istack,scratch);
printf("etext %x, edata %x, end %x, esym %x\n",
&etext,&edata, &end, esym);
printf("SYSPTSIZE %x, USRPTSIZE %x\n",SYSPTSIZE,USRPTSIZE);
printf("pv_table %x, vmmap %x, Numem %x, pte_cmap %x\n",
pv_table,vmmap,Numem,pte_cmap);

View File

@ -1,4 +1,4 @@
/* $NetBSD: subr.s,v 1.10 1995/06/05 16:27:13 ragge Exp $ */
/* $NetBSD: subr.s,v 1.11 1995/06/16 15:36:50 ragge Exp $ */
/*
* Copyright (c) 1994 Ludd, University of Lule}, Sweden.
@ -254,3 +254,26 @@ _pte_cmap: .long 0 ; .globl _pte_cmap /* Address of PTE
corresponding to cmap */
_memtest: .long 0 ; .globl _memtest # Memory test in progress.
#ifdef DDB
/*
* DDB is the only routine that uses setjmp/longjmp.
*/
.globl _setjmp, _longjmp
_setjmp:.word 0
movl 4(ap), r0
movl 8(fp), (r0)
movl 12(fp), 4(r0)
movl 16(fp), 8(r0)
addl3 fp,$28,12(r0)
clrl r0
ret
_longjmp:.word 0
movl 4(ap), r1
movl 8(ap), r0
movl (r1), ap
movl 4(r1), fp
movl 12(r1), sp
jmp *8(r1)
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: trap.c,v 1.11 1995/06/05 16:27:20 ragge Exp $ */
/* $NetBSD: trap.c,v 1.12 1995/06/16 15:36:53 ragge Exp $ */
/*
* Copyright (c) 1994 Ludd, University of Lule}, Sweden.
@ -100,7 +100,13 @@ char *traptypes[]={
"trace trap",
"compatibility mode fault",
"access violation fault",
"",
"",
"KSP invalid",
"",
"kernel debugger trap"
};
int no_traps = 18;
arithflt(frame)
struct trapframe *frame;
@ -125,29 +131,13 @@ fram:
default:
faulter:
if(frame->trap<12)
printf("\nKernel fault: %s. Stack dump:\n\n",
traptypes[frame->trap]);
else
printf("\nKernel fault: %d. Stack dump:\n\n",
frame->trap);
printf("FP %8x AP %8x R0 %8x R1 %8x\n",frame->fp,
frame->ap, frame->r0, frame->r1);
printf("R2 %8x R3 %8x R4 %8x R5 %8x\n",frame->r2,frame->r3,
frame->r4,frame->r5);
printf("TRAP %2x CODE %6x PC %8x PSL %8x\n",frame->trap,
frame->code, frame->pc, frame->psl);
i=(u_int*)&(frame->psl);
printf("(RET PC) %8x, (RET PSL) %8x\n",i[1],i[2]);
for(j=3;j<15;j+=4)
printf("%8x %8x %8x %8x\n",i[j],i[j+1],i[j+2],
i[j+3]);
asm("halt");
printf("trap type %x, code %x, pc %x, psl %x\n",
frame->trap, frame->code, frame->pc, frame->psl);
showstate(curproc);
asm("halt");
#ifdef DDB
if (kdb_trap(frame))
return;
#endif
panic("trap");
case T_KSPNOTVAL:
goto faulter;
case T_TRANSFLT|T_USER:
case T_TRANSFLT: /* Translation invalid - may be simul page ref */
@ -453,29 +443,6 @@ printstack(loaddr, highaddr)
tmp, *tmp, *(tmp + 1), *(tmp + 2), *(tmp + 3));
}
invkstk(frame)
struct trapframe *frame;
{
struct proc *p;
extern u_int scratch;
p = curproc;
printf("Kernel stack invalid: pid %d, name %s\n\n",
p->p_pid, p->p_comm);
printf("Register state:\n\n\n");
showregs(frame);
printf("\n\nProcess state:\n\n");
showstate(p);
asm("halt");
printf("\n\nKernel stack:\n\n");
printstack(mfpr(PR_KSP), (u_int)p->p_addr + USPACE);
printf("\n\nInterrupt stack:\n\n");
printstack(mfpr(PR_ISP), scratch);
panic("Invalid kernel stack");
}
showregs(frame)
struct trapframe *frame;
{