commit a693733fd50bf95ba59c6eb9a4e1cf59bb6803d5
parent 9ed785bcfd6fb893a6c55a00e2b82e208028af4c
Author: yiyus <yiyu.jgl@gmail.com>
Date: Fri, 16 Jul 2010 20:53:56 +0200
first round of updates to a/*.ed files
Diffstat:
13 files changed, 145 insertions(+), 92 deletions(-)
diff --git a/src/9vx/a/alarm.ed b/src/9vx/a/alarm.ed
@@ -1,2 +0,0 @@
-,s;alarmkproc(void\*);alarmkproc(void *v);
-,s;lock(\&alarms);lock(\&alarms.lk);g
diff --git a/src/9vx/a/allocb.c b/src/9vx/a/allocb.c
@@ -30,6 +30,7 @@ _allocb(int size)
b->list = nil;
b->free = 0;
b->flag = 0;
+ b->ref = 0;
/* align start of data portion by rounding up */
addr = (ulong)b;
@@ -61,11 +62,11 @@ allocb(int size)
* Can still error out of here, though.
*/
if(up == nil)
- panic("allocb without up: %luX\n", getcallerpc(&size));
+ panic("allocb without up: %#p", getcallerpc(&size));
if((b = _allocb(size)) == nil){
xsummary();
mallocsummary();
- panic("allocb: no memory for %d bytes\n", size);
+ panic("allocb: no memory for %d bytes", size);
}
setmalloctag(b, getcallerpc(&size));
@@ -115,10 +116,16 @@ void
freeb(Block *b)
{
void *dead = (void*)Bdead;
+ long ref;
if(b == nil)
return;
+ if(0){
+ dumpstack();
+ panic("freeb: ref %ld; caller pc %#p", ref, getcallerpc(&b));
+ }
+
/*
* drivers which perform non cache coherent DMA manage their own buffer
* pool of uncached buffers and provide their own free routine.
@@ -149,26 +156,25 @@ checkb(Block *b, char *msg)
void *dead = (void*)Bdead;
if(b == dead)
- panic("checkb b %s %lux", msg, b);
+ panic("checkb b %s %#p", msg, b);
if(b->base == dead || b->lim == dead || b->next == dead
|| b->rp == dead || b->wp == dead){
- print("checkb: base 0x%8.8luX lim 0x%8.8luX next 0x%8.8luX\n",
+ print("checkb: base %#p lim %#p next %#p\n",
b->base, b->lim, b->next);
- print("checkb: rp 0x%8.8luX wp 0x%8.8luX\n", b->rp, b->wp);
- panic("checkb dead: %s\n", msg);
+ print("checkb: rp %#p wp %#p\n", b->rp, b->wp);
+ panic("checkb dead: %s", msg);
}
if(b->base > b->lim)
- panic("checkb 0 %s %lux %lux", msg, b->base, b->lim);
+ panic("checkb 0 %s %#p %#p", msg, b->base, b->lim);
if(b->rp < b->base)
- panic("checkb 1 %s %lux %lux", msg, b->base, b->rp);
+ panic("checkb 1 %s %#p %#p", msg, b->base, b->rp);
if(b->wp < b->base)
- panic("checkb 2 %s %lux %lux", msg, b->base, b->wp);
+ panic("checkb 2 %s %#p %#p", msg, b->base, b->wp);
if(b->rp > b->lim)
- panic("checkb 3 %s %lux %lux", msg, b->rp, b->lim);
+ panic("checkb 3 %s %#p %#p", msg, b->rp, b->lim);
if(b->wp > b->lim)
- panic("checkb 4 %s %lux %lux", msg, b->wp, b->lim);
-
+ panic("checkb 4 %s %#p %#p", msg, b->wp, b->lim);
}
void
diff --git a/src/9vx/a/allocb.ed b/src/9vx/a/allocb.ed
@@ -1,4 +1,8 @@
+,s!"\.\./port/lib\.h"!"lib.h"!
,s!Lock;!Lock lk;!
,s!lock(&ialloc)!lock(\&ialloc.lk)!g
,s!msize(b)!sizeof(Block)+size+Hdrspc!
,s/exit(0)/panic("iallocb")/
+/_xinc/d
+/_xdec/s/ ||.*0//
+,s/ref < 0/0/
diff --git a/src/9vx/a/chan.c b/src/9vx/a/chan.c
@@ -28,7 +28,7 @@ struct Elemlist
{
char *aname; /* original name */
char *name; /* copy of name, so '/' can be overwritten */
- uint nelems;
+ int nelems;
char **elems;
int *off;
int mustbedir;
@@ -63,12 +63,12 @@ dumpmount(void) /* DEBUGGING */
he = &pg->mnthash[MNTHASH];
for(h = pg->mnthash; h < he; h++){
for(f = *h; f; f = f->hash){
- print("head: %p: %s 0x%llux.%lud %C %lud -> \n", f,
+ print("head: %#p: %s %#llux.%lud %C %lud -> \n", f,
f->from->path->s, f->from->qid.path,
f->from->qid.vers, devtab[f->from->type]->dc,
f->from->dev);
for(t = f->mount; t; t = t->next)
- print("\t%p: %s (umh %p) (path %.8llux dev %C %lud)\n", t, t->to->path->s, t->to->umh, t->to->qid.path, devtab[t->to->type]->dc, t->to->dev);
+ print("\t%#p: %s (umh %#p) (path %#.8llux dev %C %lud)\n", t, t->to->path->s, t->to->umh, t->to->qid.path, devtab[t->to->type]->dc, t->to->dev);
}
}
poperror();
@@ -113,7 +113,7 @@ decref(Ref *r)
x = --r->ref;
unlock(&r->lk);
if(x < 0)
- panic("decref pc=0x%lux", getcallerpc(&r));
+ panic("decref pc=%#p", getcallerpc(&r));
return x;
}
@@ -190,6 +190,7 @@ chandevreset(void)
{
int i;
+ todinit(); /* avoid later reentry causing infinite recursion */
for(i=0; devtab[i] != nil; i++)
devtab[i]->reset();
}
@@ -281,7 +282,7 @@ newpath(char *s)
* allowed, but other names with / in them draw warnings.
*/
if(strchr(s, '/') && strcmp(s, "#/") != 0 && strcmp(s, "/") != 0)
- print("newpath: %s from %lux\n", s, getcallerpc(&s));
+ print("newpath: %s from %#p\n", s, getcallerpc(&s));
p->mlen = 1;
p->malen = PATHMSLOP;
@@ -472,7 +473,7 @@ void
cclose(Chan *c)
{
if(c->flag&CFREE)
- panic("cclose %lux", getcallerpc(&c));
+ panic("cclose %#p", getcallerpc(&c));
DBG("cclose %p name=%s ref=%ld\n", c, c->path->s, c->ref.ref);
if(decref(&c->ref))
@@ -503,7 +504,7 @@ void
ccloseq(Chan *c)
{
if(c->flag&CFREE)
- panic("cclose %lux", getcallerpc(&c));
+ panic("cclose %#p", getcallerpc(&c));
DBG("ccloseq %p name=%s ref=%ld\n", c, c->path->s, c->ref.ref);
@@ -637,7 +638,7 @@ cmount(Chan **newp, Chan *old, int flag, char *spec)
error(Emount);
if(old->umh)
- print("cmount: unexpected umh, caller %.8lux\n", getcallerpc(&newp));
+ print("cmount: unexpected umh, caller %#p\n", getcallerpc(&newp));
order = flag&MORDER;
@@ -911,7 +912,7 @@ undomount(Chan *c, Path *path)
Chan *nc;
if(path->ref.ref != 1 || path->mlen == 0)
- print("undomount: path %s ref %ld mlen %d caller %lux\n",
+ print("undomount: path %s ref %ld mlen %d caller %#p\n",
path->s, path->ref.ref, path->mlen, getcallerpc(&c));
if(path->mlen>0 && (nc=path->mtpt[path->mlen-1]) != nil){
@@ -1313,9 +1314,8 @@ namec(char *aname, int amode, int omode, ulong perm)
free(aname);
nexterror();
}
-if(tracesyscalls)
- iprint("\tnamec %s\n", aname);
-
+ if(tracesyscalls)
+ iprint("\tnamec %s\n", aname);
DBG("namec %s %d %d\n", aname, amode, omode);
name = aname;
@@ -1682,8 +1682,7 @@ char isfrog[256]={
static char*
validname0(char *aname, int slashok, int dup, ulong pc)
{
- char *p, *ename, *name, *s;
- uint t;
+ char *ename, *name, *s;
int c, n;
Rune r;
@@ -1691,6 +1690,8 @@ validname0(char *aname, int slashok, int dup, ulong pc)
if(isuaddr(name)){
if(!dup)
print("warning: validname called from %lux with user pointer", pc);
+ char *p;
+ uint t;
p = name;
t = BY2PG-((ulong)p&(BY2PG-1));
while((ename=vmemchr(p, 0, t)) == nil){
diff --git a/src/9vx/a/chan.ed b/src/9vx/a/chan.ed
@@ -1,7 +1,8 @@
+,s!"\.\./port/lib\.h"!"lib.h"!
+,s!"\.\./port/error\.h"!"error.h"!
,s!Lock;!Lock lk;!g
/dumpmount/-1 s!static !/*static*/ !
,s!lock(r)!lock(\&r->lk)!g
-/static Lock l/d
,s!lock(\&chanalloc)!lock(\&chanalloc.lk)!g
,s!->ref!->ref.ref!g
,s!r->ref.ref!r->ref!g
@@ -18,3 +19,19 @@ g/^cl/ s/(void\*)/(void *v)/
,s!ref(cnew)!ref(\&cnew->ref)!g
,s!ref(cnew->path)!ref(\&cnew->path->ref)!g
/^addelem/-1 s;static;/*static*/;
+/DBG("namec/i
+ if(tracesyscalls)
+ iprint("\tnamec %s\n", aname);
+.
+,s/(ulong)name < KZERO/isuaddr(name)/
+/validaddr/d
+/ename = vmemchr(name, 0, (1<<16))/c
+ char *p;
+ uint t;
+ p = name;
+ t = BY2PG-((ulong)p&(BY2PG-1));
+ while((ename=vmemchr(p, 0, t)) == nil){
+ p += t;
+ t = BY2PG;
+ }
+.
diff --git a/src/9vx/a/dat.ed b/src/9vx/a/dat.ed
@@ -1,34 +1,43 @@
+,s!"\.\./port/portdat\.h"!"portdat.h"!
/BIOS32ci/,/BIOS32ci;/d
/^#define up/c
#define up (machp[0]->externup)
.
v/typedef/ s!Lock;!Lock lk;!g
-/mmupdb/c
- ulong lo; // Plan 9 VX
- ulong hi; // Plan 9 VX
+/^struct PMMU/+2;/^}/-1c
struct vxproc *vxproc; // Plan 9 VX
- struct vxmmap *vxmm; // Plan 9 VX
- void *sigstack; // Plan 9 VX
+ struct vxmem vxmem;
+ struct vxmmap vxmm; // Plan 9 VX
+ Uspace *us;
+ uchar *uzero;
.
+g/^#pragma/d
g/mmufree/d
g/mmuused/d
g/lastkmap/d
g/kmaptable/d
g/nkmap/d
-/^struct Label/+1a
- ulong bp; // Plan 9 VX
- ulong bx;
- ulong si;
- ulong di;
+/ Mach \*m/s/m/m_/
+/^struct Label/+2;/^}/-1c
+ uint64 bp; // Plan 9 VX
+ uint64 bx;
+ uint64 si;
+ uint64 di;
+ uint64 sp;
+ uint64 pc;
+ uint64 r12;
+ uint64 r13;
+ uint64 r14;
+ uint64 r15;
.
g/BIOS32ci/d
1i
#include <ucontext.h>
+#include "libvx32/vx32.h"
.
-/ ulong\* pbd/d
+/ ulong\* pdb/d
/ Tss\* tss/d
-/ Segdesc\* gdt/d
/ Proc\* externup/d
/ ulong ticks/d
/ Lock alarmlock/d
@@ -40,10 +49,29 @@ g/^ vlong mtrr/d
int spl; // Plan 9 VX
void *sigstack;
.
-/^Mach\* machp/ s/^/extern /
/^extern Mach \*m/c
-extern __thread Mach *m; // Plan 9 VX
-extern __thread Proc *up; // Plan 9 VX
+#ifdef TLS
+ extern __thread Mach *m; // Plan 9 VX
+ extern __thread Proc *up; // Plan 9 VX
+# define thismach m
+# define setmach(x) (m = (x))
+#else
+ extern Mach *getmach(void);
+ extern void setmach(Mach*);
+# define up getmach()->externup
+# ifdef WANT_M
+# define m getmach()
+# endif
+#endif
+.
+/^struct Mach/+1a
+#ifndef TLS
+ Proc* externup;
+#endif
+ int new;
+.
+/^struct PMMU/i
+typedef struct Uspace Uspace;
.
/^#define up/d
$a
@@ -51,4 +79,24 @@ $a
// Plan 9 VX
extern int traceprocs;
extern int tracesyscalls;
+extern int doabort;
+
+/* Pthreads-based sleep and wakeup. */
+typedef struct Psleep Psleep;
+typedef struct Pwaiter Pwaiter;
+struct Psleep
+{
+ int init;
+ pthread_mutex_t mutex;
+ Pwaiter *waiter;
+};
+
+struct Uspace
+{
+ Proc *p; // proc currently mapped
+ uchar *uzero;
+ ulong lo;
+ ulong hi;
+};
.
+g/^ u32int e..;$/d
diff --git a/src/9vx/a/dat.h b/src/9vx/a/dat.h
@@ -23,6 +23,7 @@ typedef vlong Tval;
typedef struct Ureg Ureg;
typedef struct Vctl Vctl;
+
#define MAXSYSARG 5 /* for mount(fd, afd, mpt, flag, arg) */
/*
@@ -180,10 +181,10 @@ struct Mach
#ifndef TLS
Proc* externup;
#endif
+ int new;
int machno; /* physical id of processor (KNOWN TO ASSEMBLY) */
ulong splpc; /* pc of last caller to splhi */
- ulong* pdb; /* page directory base for this processor (va) */
Segdesc *gdt; /* gdt for this processor */
Proc* proc; /* current process on this processor */
@@ -199,7 +200,6 @@ struct Mach
int tlbfault;
int tlbpurge;
int pfault;
- int new;
int cs;
int syscall;
int load;
@@ -228,6 +228,7 @@ struct Mach
int spl; // Plan 9 VX
+ void *sigstack;
int stack[1];
};
@@ -318,6 +319,7 @@ extern PCArch *arch; /* PC architecture */
* the clock which is only maintained by the bootstrap processor (0).
*/
Mach* machp[MAXMACH];
+
#define MACHP(n) (machp[n])
#ifdef TLS
@@ -373,4 +375,3 @@ struct Uspace
ulong lo;
ulong hi;
};
-
diff --git a/src/9vx/a/dev.c b/src/9vx/a/dev.c
@@ -25,7 +25,7 @@ devno(int c, int user)
return i;
}
if(user == 0)
- panic("devno %C 0x%ux", c, c);
+ panic("devno %C %#ux", c, c);
return -1;
}
diff --git a/src/9vx/a/dev.ed b/src/9vx/a/dev.ed
@@ -1,3 +1,4 @@
+,s!\.\./port/!!g
g/^decreate/ s/(Chan\*, char\*, int, ulong)/(Chan *c, char *name, int mode, ulong perm)/
g/^devremove/ s/(Chan\*)/(Chan *c)/
g/^devwstat/ s/(Chan\*, uchar\*, int)/(Chan *c, uchar *stat, int nstat)/
diff --git a/src/9vx/a/devcap.c b/src/9vx/a/devcap.c
@@ -5,7 +5,7 @@
#include "fns.h"
#include "error.h"
-#include "libsec.h"
+#include "libsec.h"
enum
{
diff --git a/src/9vx/a/devcap.ed b/src/9vx/a/devcap.ed
@@ -1,27 +1,8 @@
-197c
-capwrite(Chan *c, void *va, long n, vlong vl)
-.
-183c
-capread(Chan *c, void *va, long n, vlong vl)
-.
-178c
-capclose(Chan *c)
-.
-174c
- qunlock(&capalloc.l);
-.
-156c
- qlock(&capalloc.l);
-.
-154c
- p->ticks = msec();
-.
-140c
- qunlock(&capalloc.l);
-.
-126c
- qlock(&capalloc.l);
-.
-30c
- QLock l;
-.
+,s!\.\./port/!!g
+/libsec\.h/ s/[<>]/"/g
+/^capwrite/ s/vlong/vlong vl/
+/^capread/ s/vlong/vlong vl/
+/^capclose/ s/Chan\*/Chan *c/
+,s/m->ticks/msec()/
+,s/QLock/QLock l/
+g/lock/ s/capalloc/capalloc.l/
diff --git a/src/9vx/a/devcons.c b/src/9vx/a/devcons.c
@@ -5,7 +5,7 @@
#include "fns.h"
#include "error.h"
-#include "authsrv.h"
+#include "authsrv.h"
void (*consdebug)(void) = nil;
void (*screenputs)(char*, int) = nil;
@@ -300,8 +300,7 @@ panic(char *fmt, ...)
putstrn(buf, n+1);
dumpstack();
- restoretty();
- exit(1);
+ restoretty(); exit(1);
}
/* libmp at least contains a few calls to sysfatal; simulate with panic */
@@ -320,7 +319,7 @@ sysfatal(char *fmt, ...)
void
_assert(char *fmt)
{
- panic("assert failed at 0x%lux: %s", getcallerpc(&fmt), fmt);
+ panic("assert failed at %#p: %s", getcallerpc(&fmt), fmt);
}
#endif
@@ -465,7 +464,7 @@ echo(char *buf, int n)
consdebug = rdb;
else
consdebug = nil;
- print("consdebug now 0x%p\n", consdebug);
+ print("consdebug now %#p\n", consdebug);
return;
case 'D':
if(consdebug == nil)
@@ -484,8 +483,7 @@ echo(char *buf, int n)
killbig("^t ^t k");
return;
case 'r':
- restoretty();
- exit(0);
+ restoretty(); exit(0);
return;
}
}
@@ -786,7 +784,6 @@ consread(Chan *c, void *buf, long n, vlong off)
while(!qcanread(lineq)){
if(qread(kbdq, &ch, 1) == 0)
continue;
- //XXX TODO: startup blocks here
send = 0;
if(ch == 0){
/* flush output on rawoff -> rawon */
@@ -967,7 +964,7 @@ consread(Chan *c, void *buf, long n, vlong off)
return n;
default:
- print("consread 0x%llux\n", c->qid.path);
+ print("consread %#llux\n", c->qid.path);
error(Egreg);
}
return -1; /* never reached */
@@ -1122,7 +1119,7 @@ conswrite(Chan *c, void *va, long n, vlong off)
break;
default:
- print("conswrite: 0x%llux\n", c->qid.path);
+ print("conswrite: %#llux\n", c->qid.path);
error(Egreg);
}
return n;
diff --git a/src/9vx/a/devcons.ed b/src/9vx/a/devcons.ed
@@ -1,3 +1,6 @@
+,s!\.\./port/!!g
+/authsrv\.h/ s/[<>]/"/g
+g/exit(/ s/exit/restoretty(); &/
g/"pool.h"/d
,s!QLock;!QLock lk;!g
/vlong fasthz/ s!;! = 1000000000ULL; // Plan 9 VX = nsecs!
@@ -7,14 +10,10 @@ g/^kbd/ s/Queue\*,/Queue *q,/
,s!(a = strchr(a, ' '))!(&)!g
,s!MACHP(0)->ticks!msec()!g
/^long2le/-1 s!static!/*static*/!
-/fasthz == 0/,/fastticks/d
-/fasthz == 0/,/fastticks/d
/static int ctrlt, pid/ s/, pid//
/^ snprint(tmp/,/imagmem/c
tmp[0] = 0;
.
-,s/\.0lud/lud/g
-,s/\.0llud/llud/g
/^Queue\* serialoq/d
/^consactive/-1i
#if 0 // Plan 9 VX
@@ -34,7 +33,7 @@ g/^kbd/ s/Queue\*,/Queue *q,/
/^}/a
#endif
.
-/^putstrn0/
+/^putstrn0/ s;^;;
/ int m/d
/ char \*t/d
/ if(serialoq == nil)/i
@@ -47,7 +46,7 @@ g/^kbd/ s/Queue\*,/Queue *q,/
/^static Lock iprintlock/i
#if 0 // Plan 9 VX
.
-/^_assert/
+/^_assert/ s;^;;
/^}/a
#endif
.