shithub: drawcpu

Download patch

ref: 013b71c36516a6feddf4a9c792dd9fe2f7f1f475
parent: cc7216394dd7f921e6856a9ce7fa0344816a222e
author: halfwit <michaelmisch1985@gmail.com>
date: Sat Jan 3 09:36:42 EST 2026

More granular, compile-time enabled debugging

--- a/drawcpu.h
+++ b/drawcpu.h
@@ -1,4 +1,3 @@
 extern char *getuser(void);
 extern int aanclient(char*, int);
-extern void mntgen(char*, char*);
-extern int dbg;
\ No newline at end of file
+extern void mntgen(char*, char*);
\ No newline at end of file
--- a/include/u.h
+++ b/include/u.h
@@ -28,4 +28,10 @@
 #undef pipe
 #undef iounit
 #undef wait
-extern int debug;
+
+//#define DSEGM 1     /* Debug segments */
+//#define DINSTR 1    /* Debug Arm instructions */
+//#define DSYSCALL 1  /* Debug syscalls */
+//#define DTRACE 1    /* Debug program flow */
+//#define DVADDR  1    /* Debug vaddr calls */
+//#define DREGS 1     /* Debug registers */
--- a/kern/arm.c
+++ b/kern/arm.c
@@ -123,8 +123,9 @@
 		offset = - offset;
 	Rn = up->R + ((instr >> 16) & 15);
 	Rd = up->R + ((instr >> 12) & 15);
-    if(debug > 1)
-        print("single: Rn=%d Rd=%d offset=%.8ux pid=%d\n",  ((instr >> 16) & 15), ((instr >> 12) & 15), offset, up->pid);
+#ifdef DINSTR
+    print("single: Rn=%d Rd=%d offset=%.8ux pid=%d\n",  ((instr >> 16) & 15), ((instr >> 12) & 15), offset, up->pid);
+#endif
 	if((instr & (fW | fP)) == fW)
 		invalid(instr);
 	if(Rn == up->R + 15) {
@@ -173,8 +174,10 @@
     Rm = up->R + (instr & 15);
     Rd = up->R + ((instr >> 12) & 15);
     Rn = up->R + ((instr >> 16) & 15);
-    if(debug > 1)
+#ifdef DINSTR
+    if(DEBUG&INSTR)
         print("swap: Rm=%d Rd=%d Rn=%d pid=%d\n", (instr & 15), ((instr >> 12) & 15), ((instr >> 16) & 15), up->pid);
+#endif
     if(Rm == up->R + 15 || Rd == up->R + 15 || Rn == up->R + 15)
         invalid(instr);
     addr = *Rn;
@@ -266,8 +269,9 @@
 	case 15: result = ~operand; break;
 	default: result = 0; /* never happens */
 	}
-    if(debug > 1)
-        print("alu: Rn=%d Rd=%d op=%d operand=%.8ux pid=%d\n", ((instr >> 16) & 15), ((instr >> 12) & 15), ((instr >> 21) & 15), operand, up->pid);
+#ifdef DINSTR
+    print("alu: Rn=%d Rd=%d op=%d operand=%.8ux pid=%d\n", ((instr >> 16) & 15), ((instr >> 12) & 15), ((instr >> 21) & 15), operand, up->pid);
+#endif
 	if(instr & fS) {
 		up->CPSR &= ~FLAGS;
 		if(result == 0)
@@ -292,8 +296,9 @@
     if(offset & (1<<23))
         offset |= ~((1 << 24) - 1);
     offset *= 4;
-    if(debug > 1)
-        print("branch: offset=%.8ux pid=%d\n", offset, up->pid);
+#ifdef DINSTR
+    print("branch: offset=%.8ux pid=%d\n", offset, up->pid);
+#endif
     if(instr & fLi)
         up->R[14] = up->R[15];
     up->R[15] += offset + 4;
@@ -318,8 +323,9 @@
         invalid(instr);
     Rn = up->R + ((instr >> 16) & 15);
     Rd = up->R + ((instr >> 12) & 15);
-    if(debug > 1)
-        print("halfword: Rn=%d, Rd=%d pid=%d\n", ((instr >> 16) & 15), ((instr >> 12) & 15), up->pid);  
+#ifdef DINSTR
+    print("halfword: Rn=%d, Rd=%d pid=%d\n", ((instr >> 16) & 15), ((instr >> 12) & 15), up->pid);  
+#endif
     target = *Rn;
     if(instr & fP)
         target += offset;
@@ -349,8 +355,9 @@
     if(instr & (1<<22))
         invalid(instr); 
     Rn = up->R +((instr >> 16) & 15);
-    if(debug > 1)
-        print("block: Rn=%d pid=%d\n", ((instr >> 16) & 15), up->pid);   
+#ifdef DINSTR
+    print("block: Rn=%d pid=%d\n", ((instr >> 16) & 15), up->pid);
+#endif
     targ = evenaddr(*Rn, 3);
     if(instr & fU) {
         for(i = 0; i < 16; i++) {
@@ -394,8 +401,9 @@
     Rs = up->R + ((instr >> 8) & 15);
     Rn = up->R + ((instr >> 12) & 15);
     Rd = up->R + ((instr >> 16) & 15);
-    if(debug > 1)
-        print("multiply: Rm=%d Rs=%d Rn=%d Rd=%d pid=%d\n", (instr & 15), ((instr >> 8) & 15), ((instr >> 12) & 15), ((instr >> 16) & 15), up->pid);
+#ifdef DINSTR
+    print("multiply: Rm=%d Rs=%d Rn=%d Rd=%d pid=%d\n", (instr & 15), ((instr >> 8) & 15), ((instr >> 12) & 15), ((instr >> 16) & 15), up->pid);
+#endif
     if(Rd == Rm || Rm == up->R + 15 || Rs == up->R + 15 || Rn == up->R + 15 || Rd == up->R + 15)
         invalid(instr);
     res = *Rm * *Rs;
@@ -416,8 +424,9 @@
 {
     u32int *RdH, *RdL, *Rs, *Rm;
     u64int res;
-    if(debug > 1)
-        print("multiplylong\n");
+#ifdef DINSTR
+    print("multiplylong\n");
+#endif
     Rm = up->R + (instr & 15);
     Rs = up->R + ((instr >> 8) & 15);
     RdL = up->R + ((instr >> 12) & 15);
@@ -450,8 +459,9 @@
 {
     u32int *Rn, *Rd, *Rm, *targ, addr;
     Segment *seg; 
-    if(debug > 1)
-        print("singleex: Rd=%d Rn=%d pid=%d\n", ((instr >> 12) & 15), ((instr >> 16) & 15), up->pid);
+#ifdef DINSTR
+    print("singleex: Rd=%d Rn=%d pid=%d\n", ((instr >> 12) & 15), ((instr >> 16) & 15), up->pid);
+#endif
     Rd = up->R + ((instr >> 12) & 15);
     Rn = up->R + ((instr >> 16) & 15);
     if(Rd == up->R + 15 || Rn == up->R + 15)
@@ -477,8 +487,9 @@
 void
 clrex(void)
 {
-    if(debug > 1)
-        print("clrex\n");
+#ifdef DINSTR
+    print("clrex\n");
+#endif
     up->lladdr = 0;
     up->llval = 0;
 }
@@ -486,8 +497,9 @@
 static void
 barrier(void)
 {
-    if(debug > 1)
-        print("barrier\n");
+#ifdef DINSTR
+    print("barrier\n");
+#endif
     static Lock l;
     lock(&l);
     unlock(&l);
@@ -531,15 +543,14 @@
 
     instr = *(u32int*) vaddr(up->R[15], 4, &seg);
     segunlock(seg);
-    if(debug > 2) {
-        print("%.8ux %.8ux %c%c%c%c\n", up->R[15], instr,
-            (up->CPSR & flZ) ? 'Z' : ' ',
-            (up->CPSR & flC) ? 'C' : ' ',
-            (up->CPSR & flN) ? 'N' : ' ',
-            (up->CPSR & flV) ? 'V' : ' '
-        );
-    }
-
+#ifdef DINSTR
+    print("%.8ux %.8ux %c%c%c%c\n", up->R[15], instr,
+        (up->CPSR & flZ) ? 'Z' : ' ',
+        (up->CPSR & flC) ? 'C' : ' ',
+        (up->CPSR & flN) ? 'N' : ' ',
+        (up->CPSR & flV) ? 'V' : ' '
+    );
+#endif
     up->R[15] += 4;
 
     // CPSR testing for conditional execution
--- a/kern/seg.c
+++ b/kern/seg.c
@@ -7,9 +7,9 @@
 newseg(u32int start, u32int size, int idx)
 {
 	Segment *s;
-
-	if(debug > 1)	
-		print("newseg: size=%.8ux start=%.8ux idx=%d\n", size, start, idx);
+#ifdef DSEGM
+	print("newseg: size=%.8ux start=%.8ux idx=%d\n", size, start, idx);
+#endif
 	s = malloc(sizeof(Segment));
 	if(s == nil)
 		panic("%r");
@@ -33,9 +33,10 @@
 		s->type = SG_STACK;
 	else
 		panic("newseg: unexpected index %d", idx);
-	if(debug > 1)
-		print("newseg: created idx=%d type=%d start=%.8ux size=%.8ux\n",
+#ifdef DSEGM
+	print("newseg: created idx=%d type=%d start=%.8ux size=%.8ux\n",
 		      idx, s->type, s->start, s->size);
+#endif
 	return s;
 }
 
@@ -77,9 +78,10 @@
 			if (s->flags & SEGFLLOCK)
 				rlock(&s->rw);
 			*seg = s;
-			if(debug > 1)
-				print("vaddr addr=%.8ux, len=%d, PC=%.8ux, index=%.8ux, segment=%d, type=%d, pid=%d\n",
-				      addr, len, up->R[15], s->start, count - 1, s->type, up->pid);
+#ifdef DVADDR
+			print("vaddr addr=%.8ux, len=%d, PC=%.8ux, index=%.8ux, segment=%d, type=%d, pid=%d\n",
+				addr, len, up->R[15], s->start, count - 1, s->type, up->pid);
+#endif
 			qunlock(&up->seglock);
 			return (char *)s->data + (addr - s->start);
 		}
@@ -93,9 +95,9 @@
 data2txt(Segment *s)
 {
 	Segment *ps;
-	
-	if(debug > 1)
-		print("data2txt: converting start=%.8ux size=%.8ux\n", s->start, s->size);
+#ifdef DSEGM
+	print("data2txt: converting start=%.8ux size=%.8ux\n", s->start, s->size);
+#endif
 	ps = newseg(s->start, s->size, TSEG);
 	ps->dref = s->dref;
 	memcpy(ps->data, s->data, s->size);
@@ -110,8 +112,9 @@
 	if(segno < 0 || segno >= NSEG)
 		panic("dupseg: invalid segment index %d", segno);
 	s = seg[segno];
-	if(debug > 1)
-		print("dupseg: segno=%d, type=%d, start=%.8ux, size=%.8ux, share=%d\n", segno, s->type, s->start, s->size, share);
+#ifdef DSEGM
+	print("dupseg: segno=%d, type=%d, start=%.8ux, size=%.8ux, share=%d\n", segno, s->type, s->start, s->size, share);
+#endif
 	rlock(&s->rw);
 	if(waserror()) {
 		runlock(&s->rw);
--- a/kern/syscall.c
+++ b/kern/syscall.c
@@ -72,8 +72,9 @@
 	flags = arg(1);
 	namet = copyifnec(name, -1, &copied);
 	fd = open(namet, flags);
-	if(debug)
-		print("sysopen: fd=%lux name=%s flags=%lux\n", fd, namet, flags);
+#ifdef DSYSCALL
+	print("sysopen: fd=%lux name=%s flags=%lux\n", fd, namet, flags);
+#endif
 	if(copied)
 		free(namet);
 	if(fd < 0) {
@@ -97,8 +98,9 @@
 	perm = arg(2);
 	namet = copyifnec(name, -1, &copied);
 	fd = create(namet, flags, perm);
-	if(debug)
-		print("syscreate: name=%s\n", namet);
+#ifdef DSYSCALL
+	print("syscreate: fd=%d name=%s\n", fd, namet);
+#endif
 	if(copied)
 		free(namet);
 	if(fd < 0) {
@@ -116,8 +118,9 @@
 	u32int fd;
 	
 	fd = arg(0);
-	if(debug)
-		print("sysclose: fd=%lux\n", fd);
+#ifdef DSYSCALL
+	print("sysclose: fd=%lux\n", fd);
+#endif
 	up->R[0] = noteerr(close(fd), 0);
 	if((fd & (1<<31)) == 0)
 		setcexec(up->fd, fd, 0);
@@ -135,8 +138,9 @@
 	buf = arg(1);
 	size = arg(2);
 	off = argv(3);
-	if(debug)
-		print("syspread: fd=%d size=0x%lux off=0x%lux\n", fd, size, off);
+#ifdef DSYSCALL
+	print("syspread: fd=%d size=0x%lux off=0x%lux\n", fd, size, off);
+#endif
 	targ = bufifnec(buf, size, &buffered);
 	up->R[0] = noteerr(pread(fd, targ, size, off), size);
 	if(buffered)
@@ -156,8 +160,9 @@
 	size = arg(2);
 	off = argv(3);
 	buft = copyifnec(buf, size, &copied);
-	if(debug)
-		print("syspwrite: fd=%ux buf=%s size=%lux off=%lux\n", fd, buft, size, off);
+#ifdef DSYSCALL
+	print("syspwrite: fd=%ux buf=%s size=%lux off=%lux\n", fd, buft, size, off);
+#endif
 	up->R[0] = noteerr(pwrite(fd, buft, size, off), size);
 	if(copied)
 		free(buft);
@@ -174,8 +179,9 @@
 	fd = arg(1);
 	n = argv(2);
 	type = arg(4);
-	if(debug)
-		print("sysseek: to=%d whence=%lux\n", n, type);
+#ifdef DSYSCALL
+	print("sysseek: to=%d whence=%lux\n", n, type);
+#endif
 	*ret = seek(fd, n, type);
 	if(*ret < 0) noteerr(0, 1);
 	segunlock(seg);
@@ -192,8 +198,9 @@
 	buf = arg(1);
 	nbuf = arg(2);
 	buft = bufifnec(buf, nbuf, &buffered);
-	if(debug)
-		print("fd2path\n");
+#ifdef DSYSCALL
+	print("fd2path\n");
+#endif
 	up->R[0] = noteerr(fd2path(fd, buft, nbuf), 0);
 	if(buffered)
 		copyback(buf, nbuf, buft);
@@ -212,8 +219,9 @@
     edir = arg(1); 
     nedir = arg(2);
 	edirt = bufifnec(edir, nedir, &buffered);
-	if(debug)
-	    print("sysstat: edir=%s, nedir=%d\n", edirt, nedir);
+#ifdef DSYSCALL
+	print("sysstat: edir=%s, nedir=%d\n", edirt, nedir);
+#endif
     up->R[0] = noteerr(stat(namet, edirt, nedir), nedir);
     if (copied)
         free(namet);
@@ -232,8 +240,9 @@
 	edir = arg(1);
 	nedir = arg(2);
 	edirt = bufifnec(edir, nedir, &buffered);
-	if(debug)
-		print("sysfstat: edir=%s, nedir=%d\n", edirt, nedir);
+#ifdef DSYSCALL
+	print("sysfstat: edir=%s, nedir=%d\n", edirt, nedir);
+#endif
 	up->R[0] = noteerr(fstat(fd, edirt, nedir), nedir);
 	if(buffered)
 		copyback(edir, up->R[0], edirt);
@@ -252,8 +261,9 @@
 	edir = arg(1);
 	nedir = arg(2);
 	edirt = copyifnec(edir, nedir, &copied2);
-	if(debug)
-		print("syswstate dir=%s, name=%s\n", edirt, namet);
+#ifdef DSYSCALL
+	print("syswstate dir=%s, name=%s\n", edirt, namet);
+#endif
 	up->R[0] = noteerr(wstat(namet, edirt, nedir), nedir);
 	if(copied)
 		free(namet);
@@ -271,8 +281,11 @@
 	fd = arg(0);
 	edir = arg(1);
 	nedir = arg(2);
+	
 	edirt = copyifnec(edir, nedir, &copied);
-		print("sysfwstat: fd=%d edir=%s nedir=%d copied=%d\n", fd, edirt, nedir, copied);
+#ifdef DSYSCALL
+	print("sysfwstat: fd=0x%ux edir=%us nedir=%d copied=%d\n", fd, edirt, nedir, copied);
+#endif
 	up->R[0] = noteerr(fwstat(fd, edirt, nedir), nedir);
 	if(copied)
 		free(edirt);
@@ -282,12 +295,14 @@
 _sysexits(void)
 {
 	if(arg(0) == 0) {
-		if(debug)
-			print("sysexits\n");
+#ifdef DSYSCALL
+		print("sysexits\n");
+#endif
 		pexit("", 0);
 	} else {
-		if(debug)
-			print("sysexits: %s\n", vaddrnol(arg(0), 0));
+#ifdef DSYSCALL
+		print("sysexits: %s\n", vaddrnol(arg(0), 0));
+#endif
 		pexit(vaddrnol(arg(0), 0), 0);		
 	}
 
@@ -301,8 +316,9 @@
 
 	v = arg(0);
 	v = v + 7 & -8;
-	if(debug)
-		print("sysbrk v=%#lux\n", v);
+#ifdef DSYSCALL
+	print("sysbrk v=%#lux\n", v);
+#endif
 	if(v >= up->seg[ESEG]->start)
 		panic("bss > stack, wtf?");
 	if(v < up->seg[BSEG]->start)
@@ -341,8 +357,9 @@
 	utfecpy(srct, srct + len, buf);
 	if(copied)
 		copyback(src, len, srct);
-	if(debug)
-		print("syserrstr buf=%s\n", buf);
+#ifdef DSYSCALL
+	print("syserrstr buf=%s\n", buf);
+#endif
 	up->R[0] = 0;
 }
 
@@ -355,8 +372,9 @@
 	
 	dir = arg(0);
 	dirt = copyifnec(dir, -1, &copied);
-	if(debug)
-		print("syschdir\n");
+#ifdef DSYSCALL
+	print("syschdir\n");
+#endif
 	up->R[0] = noteerr(chdir(dirt), 0);
 	if(copied)
 		free(dirt);
@@ -366,8 +384,9 @@
 _sysnotify(void)
 {
 	u32int handler;
-	if(debug)
-		print("sysnotify\n");
+#ifdef DSYSCALL
+	print("sysnotify\n");
+#endif
 	handler = arg(0);
 	up->notehandler = handler;
 	up->R[0] = 0;
@@ -379,8 +398,9 @@
 	u32int v;
 	
 	v = arg(0);
-	if(debug)
-		print("sysnoted\n");
+#ifdef DSYSCALL
+	print("sysnoted\n");
+#endif
 	if(up->innote)
 		longjmp(up->notejmp, v + 1);
 	cherrstr("the front fell off");
@@ -393,8 +413,9 @@
 	u32int flags;
 
 	flags = arg(0);
-	if(debug)
-		print("sysrfork(%#o) for proc pid=%lud\n", flags, up->pid);
+#ifdef DSYSCALL
+	print("sysrfork(%#o) for proc pid=%lud\n", flags, up->pid);
+#endif
 	up->R[0] = noteerr(rfork(flags), 0);
 }
 
@@ -411,8 +432,9 @@
 	namet = strdup(vaddr(name, 0, &seg1));
 	segunlock(seg1);
 	argvt = vaddr(argv, 0, &seg1);
-	if(debug)
-		fprint(2, "sysexec(%#ux=\"%s\", %#ux)\n", name, namet, argv);
+#ifdef DSYSCALL
+	print("sysexec(%#ux=\"%s\", %#ux)\n", name, namet, argv);
+#endif
 	for(argc = 0; argvt[argc]; argc++)
 		;
 	argvv = emalloc(sizeof(char *) * argc);
@@ -442,8 +464,9 @@
 	s = arg(0);
 	n = arg(1);
 	st = bufifnec(s, n, &buffered);
-	if(debug)
-		print("sysawait\n");
+#ifdef DSYSCALL
+	print("sysawait\n");
+#endif
 	up->R[0] = noteerr(await(st, n), 0);
 	if(buffered)
 		copyback(s, up->R[0], st);
@@ -457,8 +480,9 @@
 	
 	fd = arg(0);
 	fdt = bufifnec(fd, 8, &buffered);
-	if(debug)
-		print("syspipe\n");
+#ifdef DSYSCALL
+	print("syspipe\n");
+#endif
 	up->R[0] = noteerr(pipe((int *) fdt), 0);
 	if(buffered)
 		copyback(fd, 8, fdt);
@@ -471,8 +495,9 @@
 	
 	oldfd = arg(0);
 	newfd = arg(1);
-	if(debug)
-		print("sysdup\n");
+#ifdef DSYSCALL
+	print("sysdup\n");
+#endif
 	up->R[0] = noteerr(dup(oldfd, newfd), 0);
 }
 
@@ -482,8 +507,9 @@
 	u32int n;
 	
 	n = arg(0);
-	if(debug)
-		print("syssleep: nsec=%.8ux\n", n);
+#ifdef DSYSCALL
+	print("syssleep: nsec=%.8ux\n", n);
+#endif
 	osmsleep(n);
 	up->R[0] = 0;
 }
@@ -495,8 +521,9 @@
 	
 	tag = arg(0);
 	value = arg(1);
-	if(debug)
-		print("sysrendezvous: tag=%.8ux, value=%.8ux\n", tag, value);
+#ifdef DSYSCALL
+	print("sysrendezvous: tag=%.8ux, value=%.8ux\n", tag, value);
+#endif
 	up->R[0] = (u32int)(uintptr_t)(rendezvous((void*)(uintptr_t)tag, (void*)(uintptr_t)value));
 	if(up->R[0] == ~0)
 		noteerr(0, 1);
@@ -519,13 +546,15 @@
 		anamet = copyifnec(aname, -1, &copiedaname);
 		if(!anamet) 
 			anamet = "";
-		if(debug)
-			print("sysmount: aname=%s\n", anamet);
+#ifdef DSYSCALL
+		print("sysmount: aname=%s\n", anamet);
+#endif
 	} else {
 		anamet = nil;
 		copiedaname = 0;
-		if(debug)
-			print("sysmount\n");
+#ifdef DSYSCALL
+		print("sysmount\n");
+#endif
 	}
 	up->R[0] = noteerr(mount(fd, afd, oldt, flag, anamet), 0);
 	if(copiedold)
@@ -546,8 +575,9 @@
 	flags = arg(2);
 	namet = copyifnec(name, -1, &copiedname);
 	oldt = copyifnec(old, -1, &copiedold);
-	if(debug)
-		print("sysbind: name=%s, old=%s\n", namet, oldt);
+#ifdef DSYSCALL
+	print("sysbind: name=%s, old=%s\n", namet, oldt);
+#endif
 	up->R[0] = noteerr(bind(namet, oldt, flags), 0);
 	if(copiedname)
 		free(namet);
@@ -565,8 +595,9 @@
 	name = arg(0);
 	old = arg(1);
 	oldt = copyifnec(old, -1, &copiedold);
-	if(debug)
-		print("sysunmount: name=%s, old=%s\n", name, oldt);
+#ifdef DSYSCALL
+	print("sysunmount: name=%s, old=%s\n", name, oldt);
+#endif
 	if(name == 0) {
 		namet = nil;
 		copiedname = 0;
@@ -608,8 +639,9 @@
 		cclose(c);
 		nexterror();
 	}
-	if(debug)
-		print("sysfauth\n");
+#ifdef DSYSCALL
+	print("sysfauth\n");
+#endif
 	ac = mntauth(c, aname);
 	/* at this point ac is responsible for keeping c alive */
 	poperror();	/* c */
@@ -635,8 +667,9 @@
 	
 	file = arg(0);
 	filet = copyifnec(file, -1, &copied);
-	if(debug)
-		print("sysremove: file=%s\n", filet);
+#ifdef DSYSCALL
+	print("sysremove: file=%s\n", filet);
+#endif
 	up->R[0] = noteerr(remove(filet), 0);
 	if(copied)
 		free(filet);
@@ -648,8 +681,9 @@
 	u32int msec;
 	
 	msec = arg(0);
-	if(debug)
-		print("sysalarm: msec=%.8ux\n", msec);
+#ifdef DSYSCALL
+	print("sysalarm: msec=%.8ux\n", msec);
+#endif
 	up->R[0] = alarm(msec);
 }
 
@@ -662,8 +696,9 @@
 	addr = arg(0);
 	block = arg(1);
 	addrt = vaddrnol(addr, 4);
-	if(debug)
-		print("syssemacquire: addr=%s, block=%.8ux\n", addrt, block);
+#ifdef DSYSCALL
+	print("syssemacquire: addr=%s, block=%.8ux\n", addrt, block);
+#endif
 	up->R[0] = noteerr(semacquire(addrt, block), 0);
 }
 
@@ -677,8 +712,9 @@
 	addr = arg(0);
 	count = arg(1);
 	addrt = vaddr(addr, 4, &seg);
-	if(debug)
+#ifdef DSYSCALL
 		print("syssemrelease: addr=%s, count=%.8ux\n", addrt, count);
+#endif
 	up->R[0] = noteerr(semrelease(addrt, count), 0);
 	segunlock(seg);
 }
@@ -700,9 +736,9 @@
 		[EXITS] 		= _sysexits,
 		[_FSESSION]		= _sys_fsession,
 		[FAUTH]			= _sysfauth,
-		[_FSTAT]		= _sysfstat,
+		//[_FSTAT]		= _sys_fstat,
 		//[SEGBRK]			= _syssegbrk,
-		[_MOUNT]		= _sysmount,
+		//[_MOUNT]		= _sys_mount,
 		[OPEN]			= _sysopen,
 		//[_READ]			= _sys_read,
 		//[OSEEK]			= _sysoseek,
@@ -715,8 +751,8 @@
 		[FD2PATH]		= _sysfd2path,
 		[BRK_]			= _sysbrk,
 		[REMOVE]		= _sysremove,
-		[_WSTAT]		= _syswstat,
-		[_FWSTAT]		= _sysfwstat,
+		//[_WSTAT]		= _sys_wstat,
+		//[_FWSTAT]		= _sys_fwstat,
 		[NOTIFY] 		= _sysnotify,
 		[NOTED]			= _sysnoted,
 		//[SEGATTACH]		= _syssegattach,
--- a/kern/sysproc.c
+++ b/kern/sysproc.c
@@ -291,8 +291,9 @@
 	((Tos *) vaddrnol(tos, sizeof(Tos)))->pid = up->pid;
 
     sp = tos;
-    if(debug > 1)
-        print("initstack: tos=%.8ux tossz=%.8ux USTKTOP=%.8ux\n", tos, sizeof(Tos), USTKTOP);
+#ifdef DTRACE
+    print("initstack: tos=%.8ux tossz=%.8ux USTKTOP=%.8ux\n", tos, sizeof(Tos), USTKTOP);
+#endif
     size = 8;
     for(i = 0; i < argc; i++)
         size += strlen(argv[i]) + 5;
@@ -306,8 +307,9 @@
 	*(ulong *) vaddrnol(sp, 4) = argc;
     sp += 4;
     ap = sp + (argc + 1) * 4;
-    if(debug > 1)
-        print("initstack: argc=%d sp=%.8ux ap=%.8ux\n", argc, sp, ap);
+#ifdef DTRACE
+    print("initstack: argc=%d sp=%.8ux ap=%.8ux\n", argc, sp, ap);
+#endif
     for(i = 0; i < argc; i++) {
         *(ulong *) vaddrnol(sp, 4) = ap;
         sp += 4;
@@ -428,9 +430,9 @@
     fdclear(up->fd);
     initstack(argc, argv);
 
-    if(debug > 1)
-        print("loadtext: PC=%.8ux, R1=%.8ux, R13=%.8ux\n", up->R[15], up->R[1], up->R[13]);
-    
+#ifdef DTRACE
+    print("loadtext: PC=%.8ux, R1=%.8ux, R13=%.8ux\n", up->R[15], up->R[1], up->R[13]);
+#endif
     resetvfp();
     return 0;
 }
@@ -441,8 +443,9 @@
 {
 	USED(v);
 	for(;;) {
-		if(debug > 2)
-			dump();
+#ifdef DREGS
+		dump();
+#endif
 		step();
 		while((up->notein - up->noteout) % NNOTE) {
 			donote(up->notes[up->noteout % NNOTE], 0);
--- a/main.c
+++ b/main.c
@@ -10,7 +10,6 @@
 
 char *argv0;
 char cons[] = "/dev/cons";
-int  debug;
 
 void
 sizebug(void)
@@ -33,7 +32,7 @@
 static void
 usage(void)
 {
-	fprintf(stderr, "usage: drawcpu [-d] -f <fileserver> -a <authserver>\n");
+	fprintf(stderr, "usage: drawcpu -f <fileserver> -a <authserver>\n");
 	exit(1);
 }
 
@@ -70,14 +69,10 @@
 	int sfd, fd, tls = 0;
 
 	fs = auth = nil;
-	debug 		= 0;
 	kerndate 	= seconds();
 	eve 		= getuser();
 
 	ARGBEGIN {
-	case 'd':
-		debug++;
-		break;
 	case 'a':
 		auth = EARGF(usage());
 		break;
--