Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/power/debugger.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname power/debugger.c 1992/1125
## diff -e /dev/null /n/bootesdump/1992/1125/sys/src/9/power/debugger.c
0a
#include	"u.h"
#include	"../port/lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"

IOQ dkbdq;
IOQ dprintq;

typedef struct Syslogbuf	Syslogbuf;
struct Syslogbuf
{
	char	*next;
	char	buf[4*1024];
};

Syslogbuf syslogbuf[4];

static int
dprint(char *fmt, ...)
{
	char buf[PRINTSIZE];
	int n;

	n = doprint(buf, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
	dprintq.puts(&dprintq, buf, n);
	return n;
}

static int
dgetline(char *p, int n)
{
	int c;
	char *end, *start;
	char buf[1];

	start = p;
	end = p + n - 1;
	for(;;){
		c = getc(&dkbdq);
		if(c <= 0)
			continue;

		/* echo */
		buf[0] = c;
		if(c == '\r' || c == '\n')
			dprintq.puts(&dprintq, "\r\n", 2);
		else
			dprintq.puts(&dprintq, buf, 1);

		if(c == '\b'){
			if(p != start)
				p--;
			continue;
		}
		if(c == '\r' || c == '\n')
			break;
		if(p >= end)
			continue;
		*p++ = c;
	}
	*p = 0;
	return p - start;
}

static void
printlog(char *cpu)
{
	int i, c;
	char *p, *end;
	Syslogbuf *s;

	if(cpu == 0)
		i = 0;
	else
		i = atoi(cpu);
	if(i < 0 || i > 3)
		return;
	s = &syslogbuf[i];

	end = s->next;
	p = end + 1;
	if(p >= &s->buf[sizeof(s->buf)])
		p = s->buf;
	while(p != end){
		c = *p & 0xff;
		if(c >= ' ' && c <= '~'){
			if(c == '\r' || c == '\n')
				dprintq.puts(&dprintq, "\r\n", 2);
			else
				dprintq.puts(&dprintq, p, 1);
		}
		p++;
		if(p >= &s->buf[sizeof(s->buf)])
			p = s->buf;
	}
}

static void
printhex(char *start, char *len)
{
	int i;
	ulong n;
	ulong *p;

	if(start == 0){
		dprint("!	h <location> <howmany> - hex display\r\n");
		return;
	}
	n = strtoul(start, 0, 0);
	if((n & KZERO) == 0)
		return;
	p = (ulong *)n;

	if(len)
		n = strtoul(len, 0, 0);
	else
		n = 1;

	while(n > 0){
		dprint("%lux/", p);
		for(i = 0; i < 8 && n > 0; i++, n--)
			dprint("	%lux", p[i]);
		dprint("\r\n");
	}
}

static void
printinfo(void)
{
	Mach *mp;
	Proc *p;
	Page *pg;
	ulong l;
	int i;

	for(i = 0; i < 4; i++){
		if((active.machs&(1<<i)) == 0)
			continue;
		mp = (void*)MACHADDR;
		mp += i;
		l = (ulong)(mp->proc);
		dprint("mach[%d]->proc/	%lux\r\n", i, l);
		dprint("mach[%d]->splpc/	%lux\r\n", i, mp->splpc);
		if((l & 0xf0000000) == KZERO){
			p = (Proc*)l;
			l = (ulong)(p->upage);
			if((l & 0xf0000000) == KZERO){
				pg = (Page*)l;
				l = pg->pa;
				dprint("mach[%d]->proc->upage->pa/	%lux\r\n", i, l);
			}
		}
	}
}

void
debugger(void *arg)
{
	int n, level;
	char buf[256];
	char *field[3];

	USED(arg);

	/*
 	 *  grab a port for a console
	 */
	duartspecial(3, &dprintq, &dkbdq, 9600);

	/*
	 *  sched() until we are on processor 1
	 */
	for(;;){
		level = splhi();
		if(m->machno == 1)
			break;
		splx(level);
		sched();
	}

	/*
	 *  take processor and process out of active groups
	 */
	active.machs &= ~(1<<1);
	splx(level);

	for(;;){
		dprint("kdb> ");
		dgetline(buf, sizeof(buf));
		memset(field, 0, sizeof(field));
		n = getfields(buf, field, 3, ' ');
		if(n == 0)
			continue;
		switch(*field[0]){
		case 'l':
			printlog(field[1]);
			break;
		case 'h':
			printhex(field[1], field[2]);
			break;
		case 'i':
			printinfo();
			break;
		default:
			dprint("!commands are:\r\n");
			dprint("!	l <cpu#> - print cpu log\r\n");
			dprint("!	h <location> <howmany> - hex display\r\n");
			dprint("!	i - display some addresses\r\n");
			break;
		}
	}
}

void
syslog(char *str, int n)
{
	Syslogbuf *s;
	int level;

	level = splhi();
	s = &syslogbuf[m->machno];
	if(s->next < s->buf || s->next >= &s->buf[sizeof(s->buf)])
		s->next = s->buf;
	while(n-- > 0){
		*s->next = *str++;
		if(s->next >= &s->buf[sizeof(s->buf)-1])
			s->next = s->buf;
		else
			s->next++;
	}
	splx(level);
}
.
## diffname power/debugger.c 1992/1126
## diff -e /n/bootesdump/1992/1125/sys/src/9/power/debugger.c /n/bootesdump/1992/1126/sys/src/9/power/debugger.c
180a

	/*
 	 *  grab a port for a console
	 */
	initq(&dprintq);
	initq(&dkbdq);
	duartspecial(3, &dprintq, &dkbdq, 9600);
.
167,171d
148c
			if(l & KZERO){
.
145c
		if(l & KZERO){
.
140,141c
		mp = (void*)(MACHADDR+i*BY2PG);
.
124a
		p += 8;
.
123c
			dprint(" %8.8lux", p[i]);
.
110c
	n = strtoul(start, 0, 16);
.
87,92c
		if(c == '\r' || c == '\n')
			dprintq.puts(&dprintq, "\r\n", 2);
		else if(c >= ' ' && c <= '~')
			dprintq.puts(&dprintq, p, 1);
.
## diffname power/debugger.c 1992/1128
## diff -e /n/bootesdump/1992/1126/sys/src/9/power/debugger.c /n/bootesdump/1992/1128/sys/src/9/power/debugger.c
209a
			dprint("!	q - quit/rebooot\r\n");
.
204a
		case 'q':
			firmware(cpuserver ? PROM_AUTOBOOT : PROM_REINIT);
			break;
.
83c
	if(p >= &s->buf[sizeof(s->buf)] || p < s->buf)
.
80a
	if(s->next < s->buf || s->next >= &s->buf[sizeof(s->buf)])
		s->next = s->buf;
.
5a
#include	"io.h"
.
## diffname power/debugger.c 1992/1129
## diff -e /n/bootesdump/1992/1128/sys/src/9/power/debugger.c /n/bootesdump/1992/1129/sys/src/9/power/debugger.c
145a

.
## diffname power/debugger.c 1992/1202
## diff -e /n/bootesdump/1992/1129/sys/src/9/power/debugger.c /n/bootesdump/1992/1202/sys/src/9/power/debugger.c
155a
		l = (ulong)(mp->ur);
		dprint("mach[%d] ur/%lux", i, l);
		ur = (Ureg*)l;
		dprint(" &status/%lux &cause/%lux &sp/%lux &pc/%lux",
				&ur->status, &ur->cause, &ur->sp, &ur->pc);
		dprint("\r\n");
.
153c
				dprint("mach[%d] proc->upage->pa/%lux\r\n", i, l);
.
144,145c
		dprint("mach[%d] proc/%lux\r\n", i, l);
		dprint("mach[%d] splpc/%lux\r\n", i, mp->splpc);
.
135a
	Ureg *ur;
.
6a
#include	"ureg.h"
.
## diffname power/debugger.c 1993/0806 # deleted
## diff -e /n/bootesdump/1992/1202/sys/src/9/power/debugger.c /n/fornaxdump/1993/0806/sys/src/brazil/power/debugger.c
1,249d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.