vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

commit 782ab6b09be00536665dd4fb507e93a150ce1ebf
parent b873031f717b7e3860cb16d3ba289eafda73c161
Author: Russ Cox <rsc@swtch.com>
Date:   Mon,  8 Dec 2008 09:21:58 -0800

9vx: x86-64 support - not quite working

Runs until psu's awk starts and then crashes.
Feels like memory corruption but not sure where.

Diffstat:
src/9vx/Makefrag | 4----
src/9vx/a/a.out.h | 16++++++++--------
src/9vx/a/auth.c | 6+++---
src/9vx/a/dat.h | 18++++++++++++------
src/9vx/a/devproc.c | 2+-
src/9vx/a/devroot.c | 8++++----
src/9vx/a/eipfmt.c | 4++--
src/9vx/a/fmt.c | 2+-
src/9vx/a/mem.h | 2+-
src/9vx/a/memdraw.h | 46+++++++++++++++++++++++-----------------------
src/9vx/a/portdat.h | 2+-
src/9vx/a/segment.c | 2+-
src/9vx/a/sysfile.c | 77++++++++++++++++++++++++++++++++++++++---------------------------------------
src/9vx/a/sysproc.c | 79+++++++++++++++++++++++++++++++++++++++++--------------------------------------
src/9vx/a/systab.h | 2+-
src/9vx/a/ureg.h | 40++++++++++++++++++++--------------------
src/9vx/devaudio.c | 4++--
src/9vx/label.S | 62++++++++++++++++++++++++++++++++++++++++++++++++++++----------
src/9vx/libdraw/bytesperline.c | 2+-
src/9vx/libmemdraw/alloc.c | 28++++++++++++++--------------
src/9vx/libmemdraw/defont.c | 4++--
src/9vx/libmemdraw/draw.c | 102++++++++++++++++++++++++++++++++++++++++----------------------------------------
src/9vx/libmemdraw/fillpoly.c | 4++--
src/9vx/libmemdraw/line.c | 4++--
src/9vx/libmemdraw/load.c | 10+++++-----
src/9vx/libmemdraw/unload.c | 2+-
src/9vx/main.c | 29+++++++++++++++++------------
src/9vx/mmu.c | 25++++++++++++++++++++-----
src/9vx/stub.c | 13+++++++++++--
src/9vx/trap.c | 31+++++++++++++++++--------------
src/9vx/unix.h | 9+++++++--
src/9vx/vx32.c | 23+++++++++++++++++++++--
src/9vx/x11/x11-draw.c | 4+++-
src/9vx/x11/x11-init.c | 2++
src/9vx/x11/x11-itrans.c | 2+-
35 files changed, 388 insertions(+), 282 deletions(-)

diff --git a/src/9vx/Makefrag b/src/9vx/Makefrag @@ -1,12 +1,8 @@ -# For now Linux32 only. Should work elsewhere but untested. ifeq ($(OS),linux) -ifeq ($(ARCH),x86_64) -else PLAN9VX=1 PLAN9GUI=x11 PLAN9AUDIO=unix endif -endif ifeq ($(OS),darwin) PLAN9VX=1 diff --git a/src/9vx/a/a.out.h b/src/9vx/a/a.out.h @@ -1,14 +1,14 @@ typedef struct Exec Exec; struct Exec { - long magic; /* magic number */ - long text; /* size of text segment */ - long data; /* size of initialized data */ - long bss; /* size of uninitialized data */ - long syms; /* size of symbol table */ - long entry; /* entry point */ - long spsz; /* size of pc/sp offset table */ - long pcsz; /* size of pc/line number table */ + int magic; /* magic number */ + int text; /* size of text segment */ + int data; /* size of initialized data */ + int bss; /* size of uninitialized data */ + int syms; /* size of symbol table */ + int entry; /* entry point */ + int spsz; /* size of pc/sp offset table */ + int pcsz; /* size of pc/line number table */ }; #define HDR_MAGIC 0x00008000 /* header expansion */ diff --git a/src/9vx/a/auth.c b/src/9vx/a/auth.c @@ -20,7 +20,7 @@ iseve(void) } long -sysfversion(ulong *arg) +sysfversion(u32int *arg) { char *vers; uint arglen, m, msize; @@ -46,7 +46,7 @@ sysfversion(ulong *arg) } long -sys_fsession(ulong *arg) +sys_fsession(u32int *arg) { /* deprecated; backwards compatibility only */ @@ -57,7 +57,7 @@ sys_fsession(ulong *arg) } long -sysfauth(ulong *arg) +sysfauth(u32int *arg) { Chan *c, *ac; char *aname; diff --git a/src/9vx/a/dat.h b/src/9vx/a/dat.h @@ -23,6 +23,8 @@ typedef vlong Tval; typedef struct Ureg Ureg; typedef struct Vctl Vctl; +typedef unsigned long long uint64; + #define MAXSYSARG 5 /* for mount(fd, afd, mpt, flag, arg) */ @@ -44,12 +46,16 @@ struct Lock struct Label { - ulong bp; // Plan 9 VX - ulong bx; - ulong si; - ulong di; - ulong sp; - ulong pc; + uint64 bp; // Plan 9 VX + uint64 bx; + uint64 si; + uint64 di; + uint64 sp; + uint64 pc; + uint64 r12; + uint64 r13; + uint64 r14; + uint64 r15; }; diff --git a/src/9vx/a/devproc.c b/src/9vx/a/devproc.c @@ -1424,7 +1424,7 @@ txt2data(Proc *p, Segment *s) for(i = 0; i < NSEG; i++) if(p->seg[i] == s) break; - if(p->seg[i] != s) + if(i == NSEG) panic("segment gone"); qunlock(&s->lk); diff --git a/src/9vx/a/devroot.c b/src/9vx/a/devroot.c @@ -221,11 +221,11 @@ rootread(Chan *c, void *buf, long n, vlong off) if(offset+n > d->length) n = d->length - offset; #ifdef asdf -print("[%d] kaddr %.8ulx base %.8ulx offset %ld (%.8ulx), n %d %.8ulx %.8ulx %.8ulx\n", +print("[%d] kaddr %.8ulx base %.8ulx offset %ld (%.8ulx), n %d %.8ux %.8ux %.8ux\n", t, buf, data, offset, offset, n, - ((ulong*)(data+offset))[0], - ((ulong*)(data+offset))[1], - ((ulong*)(data+offset))[2]); + ((u32int*)(data+offset))[0], + ((u32int*)(data+offset))[1], + ((u32int*)(data+offset))[2]); #endif memmove(buf, data+offset, n); return n; diff --git a/src/9vx/a/eipfmt.c b/src/9vx/a/eipfmt.c @@ -27,7 +27,7 @@ eipfmt(Fmt *f) static char *efmt = "%.2ux%.2ux%.2ux%.2ux%.2ux%.2ux"; static char *ifmt = "%d.%d.%d.%d"; uchar *p, ip[16]; - ulong *lp; + u32int *lp; ushort s; int i, j, n, eln, eli; @@ -73,7 +73,7 @@ common: return fmtstrcpy(f, buf); case 'i': /* v6 address as 4 longs */ - lp = va_arg(f->args, ulong*); + lp = va_arg(f->args, u32int*); for(i = 0; i < 4; i++) hnputl(ip+4*i, *lp++); p = ip; diff --git a/src/9vx/a/fmt.c b/src/9vx/a/fmt.c @@ -1893,7 +1893,7 @@ __fmtnullflush(Fmt *f) int fmtnullinit(Fmt *f) { - memset(&f, 0, sizeof *f); + memset(f, 0, sizeof *f); f->runes = 1; f->start = nullbuf; f->to = nullbuf; diff --git a/src/9vx/a/mem.h b/src/9vx/a/mem.h @@ -18,7 +18,7 @@ #define BLOCKALIGN 8 #define MAXMACH 128 /* max # cpus system can run */ -#define KSTACK (256*1024) /* Size of kernel stack */ +#define KSTACK (1024*1024) /* Size of kernel stack */ /* * Time diff --git a/src/9vx/a/memdraw.h b/src/9vx/a/memdraw.h @@ -17,7 +17,7 @@ typedef struct Memdrawparam Memdrawparam; struct Memdata { - ulong *base; /* allocated data pointer */ + u32int *base; /* allocated data pointer */ uchar *bdata; /* pointer to first byte of actual data; word-aligned */ int ref; /* number of Memimages using this data */ void* imref; @@ -39,14 +39,14 @@ struct Memimage Rectangle clipr; /* clipping region */ int depth; /* number of bits of storage per pixel */ int nchan; /* number of channels */ - ulong chan; /* channel descriptions */ + u32int chan; /* channel descriptions */ Memcmap *cmap; Memdata *data; /* pointer to data; shared by windows in this image */ int zero; /* data->bdata+zero==&byte containing (0,0) */ - ulong width; /* width in words of a single scan line */ + u32int width; /* width in words of a single scan line */ Memlayer *layer; /* nil if not a layer*/ - ulong flags; + u32int flags; int shift[NChan]; int mask[NChan]; @@ -103,20 +103,20 @@ struct Memdrawparam Rectangle mr; int op; - ulong state; - ulong mval; /* if Simplemask, the mask pixel in mask format */ - ulong mrgba; /* mval in rgba */ - ulong sval; /* if Simplesrc, the source pixel in src format */ - ulong srgba; /* sval in rgba */ - ulong sdval; /* sval in dst format */ + u32int state; + u32int mval; /* if Simplemask, the mask pixel in mask format */ + u32int mrgba; /* mval in rgba */ + u32int sval; /* if Simplesrc, the source pixel in src format */ + u32int srgba; /* sval in rgba */ + u32int sdval; /* sval in dst format */ }; /* * Memimage management */ -extern Memimage* allocmemimage(Rectangle, ulong); -extern Memimage* allocmemimaged(Rectangle, ulong, Memdata*, void*); +extern Memimage* allocmemimage(Rectangle, u32int); +extern Memimage* allocmemimaged(Rectangle, u32int, Memdata*, void*); extern Memimage* readmemimage(int); extern Memimage* creadmemimage(int); extern int writememimage(int, Memimage*); @@ -124,11 +124,11 @@ extern void freememimage(Memimage*); extern int loadmemimage(Memimage*, Rectangle, uchar*, int); extern int cloadmemimage(Memimage*, Rectangle, uchar*, int); extern int unloadmemimage(Memimage*, Rectangle, uchar*, int); -extern ulong* wordaddr(Memimage*, Point); +extern u32int* wordaddr(Memimage*, Point); extern uchar* byteaddr(Memimage*, Point); extern int drawclip(Memimage*, Rectangle*, Memimage*, Point*, Memimage*, Point*, Rectangle*, Rectangle*); -extern void memfillcolor(Memimage*, ulong); -extern int memsetchan(Memimage*, ulong); +extern void memfillcolor(Memimage*, u32int); +extern int memsetchan(Memimage*, u32int); /* * Graphics @@ -185,19 +185,19 @@ extern int drawdebug; */ -extern Memimage* _allocmemimage(Rectangle, ulong); +extern Memimage* _allocmemimage(Rectangle, u32int); extern void _freememimage(Memimage*); -extern void _memfillcolor(Memimage*, ulong); +extern void _memfillcolor(Memimage*, u32int); extern int _loadmemimage(Memimage*, Rectangle, uchar*, int); extern int _cloadmemimage(Memimage*, Rectangle, uchar*, int); extern int _unloadmemimage(Memimage*, Rectangle, uchar*, int); extern void _memimageinit(void); extern Memdrawparam *_memimagedrawsetup(Memimage*, Rectangle, Memimage*, Point, Memimage*, Point, int); extern void _memimagedraw(Memdrawparam*); -extern ulong _rgbatoimg(Memimage*, ulong); -extern ulong _pixelbits(Memimage*, Point); -extern ulong _imgtorgba(Memimage*, ulong); +extern u32int _rgbatoimg(Memimage*, u32int); +extern u32int _pixelbits(Memimage*, Point); +extern u32int _imgtorgba(Memimage*, u32int); -extern ulong rgbatoimg(Memimage*, ulong); -extern ulong pixelbits(Memimage*, Point); -extern ulong imgtorgba(Memimage*, ulong); +extern u32int rgbatoimg(Memimage*, u32int); +extern u32int pixelbits(Memimage*, Point); +extern u32int imgtorgba(Memimage*, u32int); diff --git a/src/9vx/a/portdat.h b/src/9vx/a/portdat.h @@ -92,7 +92,7 @@ struct Alarms struct Sargs { - ulong args[MAXSYSARG]; + u32int args[MAXSYSARG]; }; /* diff --git a/src/9vx/a/segment.c b/src/9vx/a/segment.c @@ -730,7 +730,7 @@ pteflush(Pte *pte, int s, int e) } long -syssegflush(ulong *arg) +syssegflush(u32int *arg) { Segment *s; ulong addr, l; diff --git a/src/9vx/a/sysfile.c b/src/9vx/a/sysfile.c @@ -171,7 +171,7 @@ openmode(ulong o) } long -sysfd2path(ulong *arg) +sysfd2path(u32int *arg) { Chan *c; char *buf; @@ -185,13 +185,13 @@ sysfd2path(ulong *arg) } long -syspipe(ulong *arg) +syspipe(u32int *arg) { int fd[2]; Chan *c[2]; Dev *d; static char *datastr[] = {"data", "data1"}; - long *ufd; + int *ufd; ufd = uvalidaddr(arg[0], 2*BY2WD, 1); evenaddr(arg[0]); @@ -224,7 +224,7 @@ syspipe(ulong *arg) } long -sysdup(ulong *arg) +sysdup(u32int *arg) { int fd; Chan *c, *oc; @@ -265,7 +265,7 @@ sysdup(ulong *arg) } long -sysopen(ulong *arg) +sysopen(u32int *arg) { int fd; Chan *c = 0; @@ -315,7 +315,7 @@ fdclose(int fd, int flag) } long -sysclose(ulong *arg) +sysclose(u32int *arg) { fdtochan(arg[0], -1, 0, 0); fdclose(arg[0], 0); @@ -628,7 +628,7 @@ mountfix(Chan *c, uchar *op, long n, long maxn) } static long -doread(ulong *arg, vlong *offp) +doread(u32int *arg, vlong *offp) { int dir; long n, nn, nnn; @@ -696,13 +696,13 @@ doread(ulong *arg, vlong *offp) } long -sys_read(ulong *arg) +sys_read(u32int *arg) { return doread(arg, nil); } long -syspread(ulong *arg) +syspread(u32int *arg) { vlong v; @@ -716,7 +716,7 @@ syspread(ulong *arg) } static long -dowrite(ulong *arg, vlong *offp) +dowrite(u32int *arg, vlong *offp) { Chan *c; long m, n; @@ -767,13 +767,13 @@ dowrite(ulong *arg, vlong *offp) } long -sys_write(ulong *arg) +sys_write(u32int *arg) { return dowrite(arg, nil); } long -syspwrite(ulong *arg) +syspwrite(u32int *arg) { vlong v; @@ -787,7 +787,7 @@ syspwrite(ulong *arg) } static void -sseek(ulong *arg) +sseek(vlong *ret, u32int *arg) { Chan *c; uchar buf[sizeof(Dir)+100]; @@ -796,7 +796,7 @@ sseek(ulong *arg) vlong off; union { vlong v; - ulong u[2]; + u32int u[2]; } o; c = fdtochan(arg[1], -1, 1, 1); @@ -848,7 +848,7 @@ sseek(ulong *arg) default: error(Ebadarg); } - *(vlong*)arg[0] = off; /* caller translated arg[0] already */ + *ret = off; /* caller translated arg[0] already */ c->uri = 0; c->dri = 0; cclose(c); @@ -856,29 +856,28 @@ sseek(ulong *arg) } long -sysseek(ulong *arg) +sysseek(u32int *arg) { - arg[0] = (ulong)uvalidaddr(arg[0], BY2V, 1); - sseek(arg); + sseek(uvalidaddr(arg[0], BY2V, 1), arg); return 0; } long -sysoseek(ulong *arg) +sysoseek(u32int *arg) { union { vlong v; - ulong u[2]; + u32int u[2]; } o; - ulong a[5]; + u32int a[5]; o.v = (long)arg[1]; - a[0] = (ulong)&o.v; + a[0] = 0; a[1] = arg[0]; a[2] = o.u[0]; a[3] = o.u[1]; a[4] = arg[2]; - sseek(a); + sseek(&o.v, a); return o.v; } @@ -925,7 +924,7 @@ pathlast(Path *p) } long -sysfstat(ulong *arg) +sysfstat(u32int *arg) { Chan *c; uint l; @@ -945,7 +944,7 @@ sysfstat(ulong *arg) } long -sysstat(ulong *arg) +sysstat(u32int *arg) { char *name; Chan *c; @@ -971,7 +970,7 @@ sysstat(ulong *arg) } long -syschdir(ulong *arg) +syschdir(u32int *arg) { Chan *c; char *name; @@ -1069,25 +1068,25 @@ bindmount(int ismount, int fd, int afd, char* arg0, char* arg1, ulong flag, char } long -sysbind(ulong *arg) +sysbind(u32int *arg) { return bindmount(0, -1, -1, uvalidaddr(arg[0], 1, 0), uvalidaddr(arg[1], 1, 0), arg[2], nil); } long -sysmount(ulong *arg) +sysmount(u32int *arg) { return bindmount(1, arg[0], arg[1], nil, uvalidaddr(arg[2], 1, 0), arg[3], uvalidaddr(arg[4], 1, 0)); } long -sys_mount(ulong *arg) +sys_mount(u32int *arg) { return bindmount(1, arg[0], -1, nil, uvalidaddr(arg[1], 1, 0), arg[2], uvalidaddr(arg[3], 1, 0)); } long -sysunmount(ulong *arg) +sysunmount(u32int *arg) { Chan *cmount, *cmounted; char *mount, *mounted; @@ -1129,7 +1128,7 @@ sysunmount(ulong *arg) } long -syscreate(ulong *arg) +syscreate(u32int *arg) { int fd; Chan *c = 0; @@ -1151,7 +1150,7 @@ syscreate(ulong *arg) } long -sysremove(ulong *arg) +sysremove(u32int *arg) { Chan *c; char *name; @@ -1208,7 +1207,7 @@ wstat(Chan *c, uchar *d, int nd) } long -syswstat(ulong *arg) +syswstat(u32int *arg) { Chan *c; uint l; @@ -1224,7 +1223,7 @@ syswstat(ulong *arg) } long -sysfwstat(ulong *arg) +sysfwstat(u32int *arg) { Chan *c; uint l; @@ -1272,7 +1271,7 @@ packoldstat(uchar *buf, Dir *d) } long -sys_stat(ulong *arg) +sys_stat(u32int *arg) { Chan *c; uint l; @@ -1307,7 +1306,7 @@ sys_stat(ulong *arg) } long -sys_fstat(ulong *arg) +sys_fstat(u32int *arg) { Chan *c; char *name; @@ -1342,14 +1341,14 @@ sys_fstat(ulong *arg) } long -sys_wstat(ulong *u) +sys_wstat(u32int *u) { error("old wstat system call - recompile"); return -1; } long -sys_fwstat(ulong *u) +sys_fwstat(u32int *u) { error("old fwstat system call - recompile"); return -1; @@ -1363,7 +1362,7 @@ kbind(char *new, char *old, int flag) } long -syspassfd(ulong *u) +syspassfd(u32int *u) { error("passfd unimplemented"); return -1; diff --git a/src/9vx/a/sysproc.c b/src/9vx/a/sysproc.c @@ -15,14 +15,14 @@ extern void checkpages(void); extern void checkpagerefs(void); long -sysr1(ulong *x) +sysr1(u32int *x) { vx32sysr1(); return 0; } long -sysrfork(ulong *arg) +sysrfork(u32int *arg) { Proc *p; int n, i; @@ -205,8 +205,8 @@ sysrfork(ulong *arg) return pid; } -static ulong -l2be(long l) +static u32int +l2be(u32int l) { uchar *cp; @@ -217,7 +217,7 @@ l2be(long l) static char Echanged[] = "exec arguments changed underfoot"; long -sysexec(ulong *arg) +sysexec(u32int *arg) { char *volatile elem, *volatile file, *ufile; Chan *volatile tc; @@ -238,10 +238,12 @@ sysexec(ulong *arg) nexterror(); } +iprint("sysexec %p %p\n", (void*)arg[0], (void*)arg[1]); ufile = uvalidaddr(arg[0], 1, 0); file = validnamedup(ufile, 1); tc = namec(file, Aopen, OEXEC, 0); kstrdup((char**)&elem, up->genbuf); +iprint("sysexec %s %p\n", file, (void*)arg[1]); /* * Read the header. If it's a #!, fill in progarg[] with info and repeat. @@ -283,7 +285,7 @@ sysexec(ulong *arg) /* * #! has had its chance, now we need a real binary */ - ulong magic, entry, text, etext, data, edata, bss, ebss; + u32int magic, entry, text, etext, data, edata, bss, ebss; magic = l2be(exec.magic); if(n != sizeof(Exec) || l2be(exec.magic) != AOUT_MAGIC) @@ -315,7 +317,7 @@ sysexec(ulong *arg) * Pass 1: count number of arguments, string bytes. */ int nargv, strbytes; - ulong argp, ssize, spage; + u32int argp, ssize, spage; strbytes = 0; for(i=0; i<nprogarg; i++) @@ -323,10 +325,11 @@ sysexec(ulong *arg) argp = arg[1]; for(nargv=0;; nargv++, argp += BY2WD){ - ulong a; + u32int a; char *str; - a = *(ulong*)uvalidaddr(argp, BY2WD, 0); + a = *(u32int*)uvalidaddr(argp, BY2WD, 0); +iprint("a%d = %p = %p\n", nargv, (void*)argp, (void*)a); if(a == 0) break; str = uvalidaddr(a, 1, 0); @@ -382,7 +385,7 @@ sysexec(ulong *arg) uchar *uzero; uzero = up->pmmu.uzero; Tos *tos; - ulong utos; + u32int utos; utos = USTKTOP - sizeof(Tos); tos = (Tos*)(uzero + utos + TSTKTOP - USTKTOP); tos->cyclefreq = m->cyclefreq; @@ -395,15 +398,15 @@ sysexec(ulong *arg) * Argument pointers and strings, together. */ char *bp, *ep; - ulong *targp; - ulong ustrp, uargp; + u32int *targp; + u32int ustrp, uargp; ustrp = utos - ROUND(strbytes, BY2WD); uargp = ustrp - BY2WD*((nprogarg+nargv)+1); bp = (char*)(uzero + ustrp + TSTKTOP - USTKTOP); ep = bp + strbytes; p = bp; - targp = (ulong*)(uzero + uargp + TSTKTOP - USTKTOP); + targp = (u32int*)(uzero + uargp + TSTKTOP - USTKTOP); /* #! args are trusted */ for(i=0; i<nprogarg; i++){ @@ -419,10 +422,10 @@ sysexec(ulong *arg) /* the rest are not */ argp = arg[1]; for(i=0; i<nargv; i++){ - ulong a; + u32int a; char *str; - a = *(ulong*)uvalidaddr(argp, BY2WD, 0); + a = *(u32int*)uvalidaddr(argp, BY2WD, 0); argp += BY2WD; str = uvalidaddr(a, 1, 0); @@ -435,7 +438,7 @@ sysexec(ulong *arg) ustrp += n; } - if(*(ulong*)uvalidaddr(argp, BY2WD, 0) != 0) + if(*(u32int*)uvalidaddr(argp, BY2WD, 0) != 0) error(Echanged); *targp = 0; @@ -603,7 +606,7 @@ return0(void *v) } long -syssleep(ulong *arg) +syssleep(u32int *arg) { int n; @@ -620,13 +623,13 @@ syssleep(ulong *arg) } long -sysalarm(ulong *arg) +sysalarm(u32int *arg) { return procalarm(arg[0]); } long -sysexits(ulong *arg) +sysexits(u32int *arg) { char *status; char *inval = "invalid exit string"; @@ -651,7 +654,7 @@ sysexits(ulong *arg) } long -sys_wait(ulong *arg) +sys_wait(u32int *arg) { int pid; Waitmsg w; @@ -675,12 +678,12 @@ sys_wait(ulong *arg) } long -sysawait(ulong *arg) +sysawait(u32int *arg) { int i; int pid; Waitmsg w; - ulong n; + u32int n; char *buf; n = arg[1]; @@ -710,7 +713,7 @@ werrstr(char *fmt, ...) } static long -generrstr(ulong addr, uint nbuf) +generrstr(u32int addr, uint nbuf) { char tmp[ERRMAX]; char *buf; @@ -731,20 +734,20 @@ generrstr(ulong addr, uint nbuf) } long -syserrstr(ulong *arg) +syserrstr(u32int *arg) { return generrstr(arg[0], arg[1]); } /* compatibility for old binaries */ long -sys_errstr(ulong *arg) +sys_errstr(u32int *arg) { return generrstr(arg[0], 64); } long -sysnotify(ulong *arg) +sysnotify(u32int *arg) { if(arg[0] != 0) uvalidaddr(arg[0], 1, 0); @@ -753,7 +756,7 @@ sysnotify(ulong *arg) } long -sysnoted(ulong *arg) +sysnoted(u32int *arg) { if(arg[0]!=NRSTR && !up->notified) error(Egreg); @@ -761,10 +764,10 @@ sysnoted(ulong *arg) } long -syssegbrk(ulong *arg) +syssegbrk(u32int *arg) { int i; - ulong addr; + u32int addr; Segment *s; addr = arg[0]; @@ -787,16 +790,16 @@ syssegbrk(ulong *arg) } long -syssegattach(ulong *arg) +syssegattach(u32int *arg) { return segattach(up, arg[0], uvalidaddr(arg[1], 1, 0), arg[2], arg[3]); } long -syssegdetach(ulong *arg) +syssegdetach(u32int *arg) { int i; - ulong addr; + u32int addr; Segment *s; qlock(&up->seglock); @@ -838,10 +841,10 @@ found: } long -syssegfree(ulong *arg) +syssegfree(u32int *arg) { Segment *s; - ulong from, to; + u32int from, to; from = arg[0]; s = seg(up, from, 1); @@ -864,13 +867,13 @@ syssegfree(ulong *arg) /* For binary compatibility */ long -sysbrk_(ulong *arg) +sysbrk_(u32int *arg) { return ibrk(arg[0], BSEG); } long -sysrendezvous(ulong *arg) +sysrendezvous(u32int *arg) { uintptr tag, val; Proc *p, **l; @@ -1103,7 +1106,7 @@ semacquire(Segment *s, long *addr, int block) } long -syssemacquire(ulong *arg) +syssemacquire(u32int *arg) { int block; long *addr; @@ -1121,7 +1124,7 @@ syssemacquire(ulong *arg) } long -syssemrelease(ulong *arg) +syssemrelease(u32int *arg) { long *addr, delta; Segment *s; diff --git a/src/9vx/a/systab.h b/src/9vx/a/systab.h @@ -1,6 +1,6 @@ #include "sys.h" -typedef long Syscall(ulong*); +typedef long Syscall(u32int*); Syscall sysr1; Syscall sys_errstr; diff --git a/src/9vx/a/ureg.h b/src/9vx/a/ureg.h @@ -1,25 +1,25 @@ struct Ureg { - ulong di; /* general registers */ - ulong si; /* ... */ - ulong bp; /* ... */ - ulong nsp; - ulong bx; /* ... */ - ulong dx; /* ... */ - ulong cx; /* ... */ - ulong ax; /* ... */ - ulong gs; /* data segments */ - ulong fs; /* ... */ - ulong es; /* ... */ - ulong ds; /* ... */ - ulong trap; /* trap type */ - ulong ecode; /* error code (or zero) */ - ulong pc; /* pc */ - ulong cs; /* old context */ - ulong flags; /* old flags */ + u32int di; /* general registers */ + u32int si; /* ... */ + u32int bp; /* ... */ + u32int nsp; + u32int bx; /* ... */ + u32int dx; /* ... */ + u32int cx; /* ... */ + u32int ax; /* ... */ + u32int gs; /* data segments */ + u32int fs; /* ... */ + u32int es; /* ... */ + u32int ds; /* ... */ + u32int trap; /* trap type */ + u32int ecode; /* error code (or zero) */ + u32int pc; /* pc */ + u32int cs; /* old context */ + u32int flags; /* old flags */ union { - ulong usp; - ulong sp; + u32int usp; + u32int sp; }; - ulong ss; /* old stack segment */ + u32int ss; /* old stack segment */ }; diff --git a/src/9vx/devaudio.c b/src/9vx/devaudio.c @@ -351,9 +351,9 @@ audiowrite(Chan *c, void *vp, long n, vlong off) void audioswab(uchar *a, uint n) { - ulong *p, *ep, b; + u32int *p, *ep, b; - p = (ulong*)a; + p = (u32int*)a; ep = p + (n>>2); while(p < ep) { b = *p; diff --git a/src/9vx/label.S b/src/9vx/label.S @@ -4,18 +4,20 @@ #define EXT(s) s #endif +#ifdef i386 + .globl EXT(setlabel) EXT(setlabel): movl 4(%esp), %eax movl %ebp, 0(%eax) - movl %ebx, 4(%eax) - movl %esi, 8(%eax) - movl %edi, 12(%eax) - movl %esp, 16(%eax) + movl %ebx, 8(%eax) + movl %esi, 16(%eax) + movl %edi, 24(%eax) + movl %esp, 32(%eax) movl 0(%esp), %ecx - movl %ecx, 20(%eax) + movl %ecx, 40(%eax) movl $0, %eax ret @@ -25,13 +27,53 @@ EXT(gotolabel): movl 4(%esp), %eax movl 0(%eax), %ebp - movl 4(%eax), %ebx - movl 8(%eax), %esi - movl 12(%eax), %edi - movl 16(%eax), %esp + movl 8(%eax), %ebx + movl 16(%eax), %esi + movl 24(%eax), %edi + movl 32(%eax), %esp - movl 20(%eax), %ecx + movl 40(%eax), %ecx movl %ecx, 0(%esp) movl $1, %eax ret + +#else + +// first param is %rdi +// need to save %rbp, %rbx, %rsp, %rip, %r12-%r15. +// %rsi and %rdi are not callee-save, unlike i386. + +.globl EXT(setlabel) +EXT(setlabel): + movq %rbp, 0(%rdi) + movq %rbx, 8(%rdi) + // 16(%rdi) is saved si (not used) + // 24(%rdi) is saved di (not used) + movq %rsp, 32(%rdi) + movq 0(%rsp), %rax + movq %rax, 40(%rdi) // %rip + movq %r12, 48(%rdi) + movq %r13, 56(%rdi) + movq %r14, 64(%rdi) + movq %r15, 72(%rdi) + + movq $0, %rax + ret + +.globl EXT(gotolabel) +EXT(gotolabel): + movq 0(%rdi), %rbp + movq 8(%rdi), %rbx + movq 32(%rdi), %rsp + movq 40(%rdi), %rax + movq %rax, 0(%rsp) // %rip + movq 48(%rdi), %r12 + movq 56(%rdi), %r13 + movq 64(%rdi), %r14 + movq 72(%rdi), %r15 + + movq $1, %rax + ret + +#endif diff --git a/src/9vx/libdraw/bytesperline.c b/src/9vx/libdraw/bytesperline.c @@ -24,7 +24,7 @@ unitsperline(Rectangle r, int d, int bitsperunit) int wordsperline(Rectangle r, int d) { - return unitsperline(r, d, 8*sizeof(ulong)); + return unitsperline(r, d, 8*sizeof(u32int)); } int diff --git a/src/9vx/libmemdraw/alloc.c b/src/9vx/libmemdraw/alloc.c @@ -18,14 +18,14 @@ memimagemove(void *from, void *to) md->base = to; /* if allocmemimage changes this must change too */ - md->bdata = (uchar*)md->base+sizeof(Memdata*)+sizeof(ulong); + md->bdata = (uchar*)md->base+sizeof(Memdata*)+sizeof(u32int); } Memimage* -allocmemimaged(Rectangle r, ulong chan, Memdata *md, void *X) +allocmemimaged(Rectangle r, u32int chan, Memdata *md, void *X) { int d; - ulong l; + u32int l; Memimage *i; if(Dx(r) <= 0 || Dy(r) <= 0){ @@ -45,7 +45,7 @@ allocmemimaged(Rectangle r, ulong chan, Memdata *md, void *X) i->data = md; i->x = X; - i->zero = sizeof(ulong)*l*r.min.y; + i->zero = sizeof(u32int)*l*r.min.y; if(r.min.x >= 0) i->zero += (r.min.x*d)/8; @@ -66,11 +66,11 @@ allocmemimaged(Rectangle r, ulong chan, Memdata *md, void *X) } Memimage* -_allocmemimage(Rectangle r, ulong chan) +_allocmemimage(Rectangle r, u32int chan) { int d; uchar *p; - ulong l, nw; + u32int l, nw; Memdata *md; Memimage *i; @@ -86,7 +86,7 @@ _allocmemimage(Rectangle r, ulong chan) return nil; md->ref = 1; - md->base = poolalloc(imagmem, sizeof(Memdata*)+(1+nw)*sizeof(ulong)); + md->base = poolalloc(imagmem, sizeof(Memdata*)+(1+nw)*sizeof(u32int)); if(md->base == nil){ free(md); return nil; @@ -96,8 +96,8 @@ _allocmemimage(Rectangle r, ulong chan) *(Memdata**)p = md; p += sizeof(Memdata*); - *(ulong*)p = getcallerpc(&r); - p += sizeof(ulong); + *(u32int*)p = getcallerpc(&r); + p += sizeof(u32int); /* if this changes, memimagemove must change too */ md->bdata = p; @@ -129,10 +129,10 @@ _freememimage(Memimage *i) /* * Wordaddr is deprecated. */ -ulong* +u32int* wordaddr(Memimage *i, Point p) { - return (ulong*) ((uintptr)byteaddr(i, p) & ~(sizeof(ulong)-1)); + return (u32int*) ((uintptr)byteaddr(i, p) & ~(sizeof(u32int)-1)); } uchar* @@ -140,7 +140,7 @@ byteaddr(Memimage *i, Point p) { uchar *a; - a = i->data->bdata+i->zero+sizeof(ulong)*p.y*i->width; + a = i->data->bdata+i->zero+sizeof(u32int)*p.y*i->width; if(i->depth < 8){ /* @@ -159,11 +159,11 @@ byteaddr(Memimage *i, Point p) } int -memsetchan(Memimage *i, ulong chan) +memsetchan(Memimage *i, u32int chan) { int d; int t, j, k; - ulong cc; + u32int cc; int bytes; if((d = chantodepth(chan)) == 0) { diff --git a/src/9vx/libmemdraw/defont.c b/src/9vx/libmemdraw/defont.c @@ -18,7 +18,7 @@ getmemdefont(void) /* * make sure data is word-aligned. this is true with Plan 9 compilers * but not in general. the byte order is right because the data is - * declared as char*, not ulong*. + * declared as char*, not u32int*. */ p = (char*)defontdata; n = (uintptr)p & 3; @@ -49,7 +49,7 @@ getmemdefont(void) return nil; } - hdr = p+Dy(r)*i->width*sizeof(ulong); + hdr = p+Dy(r)*i->width*sizeof(u32int); n = atoi(hdr); p = hdr+3*12; fc = malloc(sizeof(Fontchar)*(n+1)); diff --git a/src/9vx/libmemdraw/draw.c b/src/9vx/libmemdraw/draw.c @@ -386,7 +386,7 @@ struct Buffer { uchar *blu; uchar *alpha; uchar *grey; - ulong *rgba; + u32int *rgba; int delta; /* number of bytes to add to pointer to get next pixel to the right */ /* used by boolcalc* for mask data */ @@ -428,7 +428,7 @@ struct Param { int replcache; /* if set, cache buffers */ Buffer bcache[MAXBCACHE]; - ulong bfilled; + u32int bfilled; uchar *bufbase; int bufoff; int bufdelta; @@ -531,7 +531,7 @@ getparam(Param *p, Memimage *img, Rectangle r, int convgrey, int needbuf, int *n p->bytey0s = byteaddr(img, Pt(img->r.min.x, img->r.min.y)); p->bytermin = byteaddr(img, Pt(r.min.x, img->r.min.y)); p->bytey0e = byteaddr(img, Pt(img->r.max.x, img->r.min.y)); - p->bwidth = sizeof(ulong)*img->width; + p->bwidth = sizeof(u32int)*img->width; assert(p->bytey0s <= p->bytermin && p->bytermin <= p->bytey0e); @@ -809,7 +809,7 @@ alphacalc14(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) Buffer obdst; int fd, sadelta; int i, sa, ma, q; - ulong s, t; + u32int s, t; obdst = bdst; sadelta = bsrc.alpha == &ones ? 0 : bsrc.delta; @@ -861,7 +861,7 @@ alphacalc2810(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) Buffer obdst; int fs, sadelta; int i, ma, da, q; - ulong s, t; + u32int s, t; obdst = bdst; sadelta = bsrc.alpha == &ones ? 0 : bsrc.delta; @@ -915,7 +915,7 @@ alphacalc3679(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) Buffer obdst; int fs, fd, sadelta; int i, sa, ma, da, q; - ulong s, t, u, v; + u32int s, t, u, v; obdst = bdst; sadelta = bsrc.alpha == &ones ? 0 : bsrc.delta; @@ -988,7 +988,7 @@ alphacalc11(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) Buffer obdst; int fd, sadelta; int i, sa, ma, q; - ulong s, t, u, v; + u32int s, t, u, v; USED(op); obdst = bdst; @@ -1080,7 +1080,7 @@ alphacalcS(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) Buffer obdst; int fd; int i, ma; - ulong s, t; + u32int s, t; USED(op); obdst = bdst; @@ -1154,7 +1154,7 @@ boolcalc236789(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int grey, int op) Buffer obdst; int fs, fd; int i, ma, da, zero; - ulong s, t; + u32int s, t; obdst = bdst; zero = !(op&1); @@ -1289,7 +1289,7 @@ readnbit(Param *p, uchar *buf, int y) memset(&b, 0, sizeof b); // shut up gcc int i, n, sh, depth, x, dx, npack, nbits; - b.rgba = (ulong*)buf; + b.rgba = (u32int*)buf; b.grey = w = buf; b.red = b.blu = b.grn = w; b.alpha = &ones; @@ -1379,7 +1379,7 @@ static void writenbit(Param *p, uchar *w, Buffer src) { uchar *r; - ulong bits; + u32int bits; int i, sh, depth, npack, nbits, x, ex; assert(src.grey != nil && src.delta == 1); @@ -1468,7 +1468,7 @@ readcmap(Param *p, uchar *buf, int y) } } - b.rgba = (ulong*)(buf-copyalpha); + b.rgba = (u32int*)(buf-copyalpha); if(convgrey){ b.grey = buf; @@ -1511,7 +1511,7 @@ readbyte(Param *p, uchar *buf, int y) int dx, isgrey, convgrey, alphaonly, copyalpha, i, nb; uchar *begin, *end, *r, *w, *rrepl, *grepl, *brepl, *arepl, *krepl; uchar ured, ugrn, ublu; - ulong u; + u32int u; img = p->img; begin = p->bytey0s + y*p->bwidth; @@ -1535,7 +1535,7 @@ DBG print("copyalpha %d alphaonly %d convgrey %d isgrey %d\n", copyalpha, alphao memmove(buf, r, dx*nb); r = buf; } - b.rgba = (ulong*)r; + b.rgba = (u32int*)r; if(copyalpha) b.alpha = r+img->shift[CAlpha]/8; else @@ -1588,7 +1588,7 @@ DBG print("%x\n", w[-1]); } b.alpha = copyalpha ? buf : &ones; - b.rgba = (ulong*)buf; + b.rgba = (u32int*)buf; if(alphaonly){ b.red = b.grn = b.blu = b.grey = nil; if(!copyalpha) @@ -1617,7 +1617,7 @@ writebyte(Param *p, uchar *w, Buffer src) Memimage *img; int i, isalpha, isgrey, nb, delta, dx, adelta; uchar ff, *red, *grn, *blu, *grey, *alpha; - ulong u, mask; + u32int u, mask; img = p->img; @@ -1722,7 +1722,7 @@ readptr(Param *p, uchar *s, int y) q = p->bytermin + y*p->bwidth; b.red = q; /* ptr to data */ b.grn = b.blu = b.grey = b.alpha = nil; - b.rgba = (ulong*)q; + b.rgba = (u32int*)q; b.delta = p->img->depth/8; return b; } @@ -1802,13 +1802,13 @@ static Buffer boolcopy32(Buffer bdst, Buffer bsrc, Buffer bmask, int dx, int i, int o) { uchar *m; - ulong *r, *w, *ew; + u32int *r, *w, *ew; USED(i); USED(o); m = bmask.grey; - w = (ulong*)bdst.red; - r = (ulong*)bsrc.red; + w = (u32int*)bdst.red; + r = (u32int*)bsrc.red; ew = w+dx; for(; w < ew; w++,r++) if(*m++) @@ -1840,7 +1840,7 @@ genconv(Param *p, uchar *buf, int y) b.red = buf; b.blu = b.grn = b.grey = b.alpha = nil; - b.rgba = (ulong*)buf; + b.rgba = (u32int*)buf; b.delta = 0; return b; @@ -1877,11 +1877,11 @@ convfn(Memimage *dst, Param *dpar, Memimage *src, Param *spar, int *ndrawbuf) return genconv; } -ulong +u32int _pixelbits(Memimage *i, Point pt) { uchar *p; - ulong val; + u32int val; int off, bpp, npack; val = 0; @@ -1964,9 +1964,9 @@ memsets(void *vp, ushort val, int n) } static void -memsetl(void *vp, ulong val, int n) +memsetl(void *vp, u32int val, int n) { - ulong *p, *ep; + u32int *p, *ep; p = vp; ep = p+n; @@ -1975,7 +1975,7 @@ memsetl(void *vp, ulong val, int n) } static void -memset24(void *vp, ulong val, int n) +memset24(void *vp, u32int val, int n) { uchar *p, *ep; uchar a,b,c; @@ -1992,12 +1992,12 @@ memset24(void *vp, ulong val, int n) } } -ulong -_imgtorgba(Memimage *img, ulong val) +u32int +_imgtorgba(Memimage *img, u32int val) { uchar r, g, b, a; int nb, ov, v; - ulong chan; + u32int chan; uchar *p; a = 0xFF; @@ -2040,12 +2040,12 @@ _imgtorgba(Memimage *img, ulong val) return (r<<24)|(g<<16)|(b<<8)|a; } -ulong -_rgbatoimg(Memimage *img, ulong rgba) +u32int +_rgbatoimg(Memimage *img, u32int rgba) { - ulong chan; + u32int chan; int d, nb; - ulong v; + u32int v; uchar *p, r, g, b, a, m; v = 0; @@ -2090,7 +2090,7 @@ static int memoptdraw(Memdrawparam *par) { int m, y, dy, dx, op; - ulong v; + u32int v; Memimage *src; Memimage *dst; @@ -2112,7 +2112,7 @@ DBG print("state %lux mval %lux dd %d\n", par->state, par->mval, dst->depth); uchar lm, rm; DBG print("memopt, dst %p, dst->data->bdata %p\n", dst, dst->data->bdata); - dwid = dst->width*sizeof(ulong); + dwid = dst->width*sizeof(u32int); dp = byteaddr(dst, par->r.min); v = par->sdval; DBG print("sdval %lud, depth %d\n", v, dst->depth); @@ -2195,7 +2195,7 @@ DBG print("dp=%p; dx=%d; for(y=0; y<%d; y++, dp+=%d)\nmemsets(dp, v, dx);\n", p[1] = v>>8; p[2] = v>>16; p[3] = v>>24; - v = *(ulong*)p; + v = *(u32int*)p; for(y=0; y<dy; y++, dp+=dwid) memsetl(dp, v, dx); return 1; @@ -2221,8 +2221,8 @@ DBG print("dp=%p; dx=%d; for(y=0; y<%d; y++, dp+=%d)\nmemsets(dp, v, dx);\n", else dir = 1; - swid = src->width*sizeof(ulong); - dwid = dst->width*sizeof(ulong); + swid = src->width*sizeof(u32int); + dwid = dst->width*sizeof(u32int); sp = byteaddr(src, par->sr.min); dp = byteaddr(dst, par->r.min); if(dir == -1){ @@ -2253,9 +2253,9 @@ DBG print("dp=%p; dx=%d; for(y=0; y<%d; y++, dp+=%d)\nmemsets(dp, v, dx);\n", sp = byteaddr(src, par->sr.min); dp = byteaddr(dst, par->r.min); mp = byteaddr(par->mask, par->mr.min); - swid = src->width*sizeof(ulong); - dwid = dst->width*sizeof(ulong); - mwid = par->mask->width*sizeof(ulong); + swid = src->width*sizeof(u32int); + dwid = dst->width*sizeof(u32int); + mwid = par->mask->width*sizeof(u32int); if(src->data == dst->data && byteaddr(dst, par->r.min) > byteaddr(src, par->sr.min)){ dir = -1; @@ -2344,12 +2344,12 @@ DBG print("dp=%p; dx=%d; for(y=0; y<%d; y++, dp+=%d)\nmemsets(dp, v, dx);\n", static int chardraw(Memdrawparam *par) { - ulong bits; + u32int bits; int i, ddepth, dy, dx, x, bx, ex, y, npack, bsh, depth, op; - ulong v, maskwid, dstwid; + u32int v, maskwid, dstwid; uchar *wp, *rp, *q, *wc; ushort *ws; - ulong *wl; + u32int *wl; uchar sp[4]; Rectangle r, mr; Memimage *mask, *src, *dst; @@ -2373,13 +2373,13 @@ if(0) if(drawdebug) iprint("chardraw? mf %lux md %d sf %lux dxs %d dys %d dd %d //if(drawdebug) iprint("chardraw..."); depth = mask->depth; - maskwid = mask->width*sizeof(ulong); + maskwid = mask->width*sizeof(u32int); rp = byteaddr(mask, mr.min); npack = 8/depth; bsh = (mr.min.x % npack) * depth; wp = byteaddr(dst, r.min); - dstwid = dst->width*sizeof(ulong); + dstwid = dst->width*sizeof(u32int); DBG print("bsh %d\n", bsh); dy = Dy(r); dx = Dx(r); @@ -2451,8 +2451,8 @@ DBG print("bits %lux sh %d...", bits, i); } break; case 32: - wl = (ulong*)wp; - v = *(ulong*)sp; + wl = (u32int*)wp; + v = *(u32int*)sp; for(x=bx; x>ex; x--, wl++){ i = x&7; if(i == 8-1) @@ -2477,7 +2477,7 @@ DBG print("\n"); * * This code is just plain wrong for >8bpp. * -ulong +u32int membyteval(Memimage *src) { int i, val, bpp; @@ -2497,9 +2497,9 @@ membyteval(Memimage *src) */ void -_memfillcolor(Memimage *i, ulong val) +_memfillcolor(Memimage *i, u32int val) { - ulong bits; + u32int bits; int d, y; if(val == DNofill) diff --git a/src/9vx/libmemdraw/fillpoly.c b/src/9vx/libmemdraw/fillpoly.c @@ -127,7 +127,7 @@ mod(long x, long y) long z; z = x%y; - if((long)(((ulong)z)^((ulong)y)) > 0 || z == 0) + if((long)(((u32int)z)^((u32int)y)) > 0 || z == 0) return z; return z + y; } @@ -135,7 +135,7 @@ mod(long x, long y) static long sdiv(long x, long y) { - if((long)(((ulong)x)^((ulong)y)) >= 0 || x == 0) + if((long)(((u32int)x)^((u32int)y)) >= 0 || x == 0) return x/y; return (x+((y>>30)|1))/y-1; diff --git a/src/9vx/libmemdraw/line.c b/src/9vx/libmemdraw/line.c @@ -50,7 +50,7 @@ horline1(Memimage *dst, Point p0, Point p1, int srcval, Rectangle clipr) deltax = p1.x - p0.x; deltay = p1.y - p0.y; - dd = dst->width*sizeof(ulong); + dd = dst->width*sizeof(u32int); dy = 1; if(deltay < 0){ dd = -dd; @@ -117,7 +117,7 @@ verline1(Memimage *dst, Point p0, Point p1, int srcval, Rectangle clipr) e += deltay; }else e += deltax; - d += dst->width*sizeof(ulong); + d += dst->width*sizeof(u32int); m >>= bpp; if(m == 0) m = m0; diff --git a/src/9vx/libmemdraw/load.c b/src/9vx/libmemdraw/load.c @@ -26,7 +26,7 @@ _loadmemimage(Memimage *i, Rectangle r, uchar *data, int ndata) m ^= 0xFF >> rpart; for(y=r.min.y; y<r.max.y; y++){ *q ^= (*data^*q) & m; - q += i->width*sizeof(ulong); + q += i->width*sizeof(u32int); data++; } return ndata; @@ -34,7 +34,7 @@ _loadmemimage(Memimage *i, Rectangle r, uchar *data, int ndata) if(lpart==0 && rpart==0){ /* easy case */ for(y=r.min.y; y<r.max.y; y++){ memmove(q, data, l); - q += i->width*sizeof(ulong); + q += i->width*sizeof(u32int); data += l; } return ndata; @@ -45,7 +45,7 @@ _loadmemimage(Memimage *i, Rectangle r, uchar *data, int ndata) *q ^= (*data^*q) & m; if(l > 1) memmove(q+1, data+1, l-1); - q += i->width*sizeof(ulong); + q += i->width*sizeof(u32int); data += l; } return ndata; @@ -55,7 +55,7 @@ _loadmemimage(Memimage *i, Rectangle r, uchar *data, int ndata) if(l > 1) memmove(q, data, l-1); q[l-1] ^= (data[l-1]^q[l-1]) & mr; - q += i->width*sizeof(ulong); + q += i->width*sizeof(u32int); data += l; } return ndata; @@ -65,7 +65,7 @@ _loadmemimage(Memimage *i, Rectangle r, uchar *data, int ndata) if(l > 2) memmove(q+1, data+1, l-2); q[l-1] ^= (data[l-1]^q[l-1]) & mr; - q += i->width*sizeof(ulong); + q += i->width*sizeof(u32int); data += l; } return ndata; diff --git a/src/9vx/libmemdraw/unload.c b/src/9vx/libmemdraw/unload.c @@ -18,7 +18,7 @@ _unloadmemimage(Memimage *i, Rectangle r, uchar *data, int ndata) q = byteaddr(i, r.min); for(y=r.min.y; y<r.max.y; y++){ memmove(data, q, l); - q += i->width*sizeof(ulong); + q += i->width*sizeof(u32int); data += l; } return ndata; diff --git a/src/9vx/main.c b/src/9vx/main.c @@ -401,7 +401,7 @@ bootargs(void *base) { int i, ac; uchar *av[32]; - uchar **lsp; + u32int *lsp; sp = (uchar*)base + BY2PG - MAXSYSARG*BY2WD - sizeof(Tos); @@ -410,14 +410,14 @@ bootargs(void *base) /* TODO: could use command line argc, argv here if it was useful */ /* 4 byte word align stack */ - sp = (uchar*)((ulong)sp & ~3); + sp = (uchar*)((uintptr)sp & ~3); /* build argc, argv on stack */ - sp -= (ac+2)*sizeof(sp); - lsp = (uchar**)sp; - *lsp++ = (uchar*)ac; + sp -= (ac+2)*sizeof(u32int); + lsp = (u32int*)sp; + *lsp++ = ac; for(i = 0; i < ac; i++) - *lsp++ = av[i] + ((USTKTOP - BY2PG) - (ulong)base); + *lsp++ = (u32int)(uintptr)(av[i] + ((USTKTOP - BY2PG) - (ulong)base)); *lsp = 0; sp += (USTKTOP - BY2PG) - (ulong)base; } @@ -425,21 +425,21 @@ bootargs(void *base) void showexec(ulong sp) { - ulong *a, *argv; + u32int *a, *argv; int i, n; uchar *uzero; uzero = up->pmmu.uzero; - iprint("showexec %p\n", sp); + iprint("showexec %p\n", (uintptr)sp); if(sp >= USTKTOP || sp < USTKTOP-USTKSIZE) panic("showexec: bad sp"); - a = (ulong*)(uzero + sp); + a = (u32int*)(uzero + sp); n = *a++; iprint("argc=%d\n", n); argv = a; iprint("argv=%p\n", argv); for(i=0; i<n; i++){ - iprint("argv[%d]=%p\n", i, argv[i]); + iprint("argv[%d]=%p\n", i, (uintptr)argv[i]); iprint("\t%s\n", (uzero + argv[i])); } iprint("argv[%d]=%p\n", i, argv[i]); @@ -502,7 +502,7 @@ init0(void) poperror(); -//showexec((ulong)sp); +//showexec(sp); touser(sp); /* infinity, and beyond. */ } @@ -546,8 +546,13 @@ sigsegv(int signo, siginfo_t *info, void *v) ctx = (struct sigcontext*)mc; addr = (ulong)info->si_addr; read = !(ctx->err&2); +#ifdef i386 eip = ctx->eip; esp = ctx->esp; +#else + eip = ctx->rip; + esp = ctx->rsp; +#endif #elif defined(__FreeBSD__) mcontext_t *mc; mc = &uc->uc_mcontext; @@ -606,7 +611,7 @@ sigsegv(int signo, siginfo_t *info, void *v) * we screwed up. */ if(!isuaddr((uchar*)addr) || fault((uchar*)addr - uzero, read) < 0) - panic("kernel fault: signo=%d addr=%p[%p] %d", signo, addr, (uchar*)addr-uzero, read); + panic("kernel fault: signo=%d addr=%p[%p] %d eip=%p esp=%p", signo, addr, (uchar*)addr-uzero, read, eip, esp); } /* diff --git a/src/9vx/mmu.c b/src/9vx/mmu.c @@ -54,20 +54,35 @@ isuaddr(void *v) static void* mapzero(void) { - int fd; + int fd, bit32; void *v; +#ifdef i386 + bit32 = 0; +#else + bit32 = MAP_32BIT; +#endif /* First try mmaping /dev/zero. Some OS'es don't allow this. */ if((fd = open("/dev/zero", O_RDONLY)) >= 0){ - v = mmap(nil, USTKTOP, PROT_NONE, MAP_PRIVATE, fd, 0); - if(v != MAP_FAILED) + v = mmap(nil, USTKTOP, PROT_NONE, bit32|MAP_PRIVATE, fd, 0); + if(v != MAP_FAILED) { + if((uint32_t)(uintptr)v != (uintptr)v) { + iprint("mmap returned 64-bit pointer %p\n", v); + panic("mmap"); + } return v; + } } /* Next try an anonymous map. */ - v = mmap(nil, USTKTOP, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); - if(v != MAP_FAILED) + v = mmap(nil, USTKTOP, PROT_NONE, bit32|MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + if(v != MAP_FAILED) { + if((uint32_t)(uintptr)v != (uintptr)v) { + iprint("mmap returned 64-bit pointer %p\n", v); + panic("mmap"); + } return v; + } return nil; } diff --git a/src/9vx/stub.c b/src/9vx/stub.c @@ -252,11 +252,20 @@ tas(void *x) { int v; +#ifdef i386 __asm__( "movl $1, %%eax\n\t" "xchgl %%eax,(%%ecx)" : "=a" (v) : "c" (x) ); +#else + __asm__( "movl $1, %%eax\n\t" + "xchgl %%eax,(%%rcx)" + : "=a" (v) + : "c" (x) + ); +#endif + switch(v) { case 0: case 1: @@ -472,7 +481,7 @@ iprint(char *fmt, ...) va_start(arg, fmt); n = vseprint(buf, buf+sizeof(buf), fmt, arg) - buf; va_end(arg); - write(2, buf, n); + USED(write(2, buf, n)); return n; } @@ -496,7 +505,7 @@ panic(char *fmt, ...) n = vseprint(buf+strlen(buf), buf+sizeof(buf), fmt, arg) - buf; va_end(arg); buf[n] = '\n'; - write(2, buf, n+1); + USED(write(2, buf, n+1)); if(doabort){ #ifdef __APPLE__ fprint(2, "sleeping, so you can attach gdb to pid %d\n", (int)getpid()); diff --git a/src/9vx/trap.c b/src/9vx/trap.c @@ -90,17 +90,17 @@ trap(Ureg *ureg) case VXTRAP_SOFT+0x40: /* int $0x40 - system call */ if(tracesyscalls){ - ulong *sp = (ulong*)(up->pmmu.uzero + ureg->usp); - print("%d [%s] %s %#lux %08lux %08lux %08lux %08lux\n", + u32int *sp = (u32int*)(up->pmmu.uzero + ureg->usp); + iprint("%d [%s] %s %#ux %08ux %08ux %08ux %08ux\n", up->pid, up->text, sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]); } syscall(ureg); if(tracesyscalls){ if(ureg->ax == -1) - print("%d [%s] -> %s\n", up->pid, up->text, up->syserrstr); + iprint("%d [%s] -> %s\n", up->pid, up->text, up->syserrstr); else - print("%d [%s] -> %#ux\n", up->pid, up->text, ureg->ax); + iprint("%d [%s] -> %#ux\n", up->pid, up->text, ureg->ax); } return; @@ -262,7 +262,7 @@ syscall(Ureg *ureg) up->psstate = 0; if(scallnr == NOTED) - noted(ureg, *(ulong*)(up->pmmu.uzero + sp+BY2WD)); + noted(ureg, *(u32int*)(up->pmmu.uzero + sp+BY2WD)); if(scallnr!=RFORK && (up->procctl || up->nnote)){ splhi(); @@ -286,6 +286,9 @@ notify(Ureg* ureg) Note *n; Ureg *upureg; + if(tracesyscalls) + iprint("notify\n"); + if(up->procctl) procctl(up); if(up->nnote == 0) @@ -339,14 +342,14 @@ notify(Ureg* ureg) uzero = up->pmmu.uzero; upureg = (void*)(uzero + sp); memmove(upureg, ureg, sizeof(Ureg)); - *(ulong*)(uzero + sp-BY2WD) = up->ureg; /* word under Ureg is old up->ureg */ + *(u32int*)(uzero + sp-BY2WD) = up->ureg; /* word under Ureg is old up->ureg */ up->ureg = sp; sp -= BY2WD+ERRMAX; memmove((char*)(uzero + sp), up->note[0].msg, ERRMAX); sp -= 3*BY2WD; - *(ulong*)(uzero + sp+2*BY2WD) = sp+3*BY2WD; /* arg 2 is string */ - *(ulong*)(uzero + sp+1*BY2WD) = up->ureg; /* arg 1 is ureg* */ - *(ulong*)(uzero + sp+0*BY2WD) = 0; /* arg 0 is pc */ + *(u32int*)(uzero + sp+2*BY2WD) = sp+3*BY2WD; /* arg 2 is string */ + *(u32int*)(uzero + sp+1*BY2WD) = up->ureg; /* arg 1 is ureg* */ + *(u32int*)(uzero + sp+0*BY2WD) = 0; /* arg 0 is pc */ ureg->usp = sp; ureg->pc = up->notify; up->notified = 1; @@ -403,7 +406,7 @@ noted(Ureg* ureg, ulong arg0) pprint("suicide: trap in noted\n"); pexit("Suicide", 0); } - up->ureg = *(ulong*)(uzero+oureg-BY2WD); + up->ureg = *(u32int*)(uzero+oureg-BY2WD); qunlock(&up->debug); break; @@ -418,8 +421,8 @@ noted(Ureg* ureg, ulong arg0) sp = oureg-4*BY2WD-ERRMAX; splhi(); ureg->sp = sp; - ((ulong*)(uzero+sp))[1] = oureg; /* arg 1 0(FP) is ureg* */ - ((ulong*)(uzero+sp))[0] = 0; /* arg 0 is pc */ + ((u32int*)(uzero+sp))[1] = oureg; /* arg 1 0(FP) is ureg* */ + ((u32int*)(uzero+sp))[0] = 0; /* arg 0 is pc */ break; default: @@ -440,13 +443,13 @@ noted(Ureg* ureg, ulong arg0) long execregs(ulong entry, ulong ssize, ulong nargs) { - ulong *sp; + u32int *sp; Ureg *ureg; up->fpstate = FPinit; fpoff(); - sp = (ulong*)(up->pmmu.uzero + USTKTOP - ssize); + sp = (u32int*)(up->pmmu.uzero + USTKTOP - ssize); *--sp = nargs; ureg = up->dbgreg; diff --git a/src/9vx/unix.h b/src/9vx/unix.h @@ -1,3 +1,4 @@ +#undef _FORTIFY_SOURCE /* stupid ubuntu setting that warns about not checking the return value from write */ #define _BSD_SOURCE 1 #define _NETBSD_SOURCE 1 /* NetBSD */ #define _SVID_SOURCE 1 @@ -51,10 +52,14 @@ typedef unsigned long ulong; typedef unsigned long long uvlong; typedef long long vlong; typedef ulong uintptr; -typedef ulong u32int; +typedef unsigned int u32int; typedef signed char schar; typedef unsigned short Rune; -#define USED(x) ((void)(x)) +// gcc 4.3.2 is too smart - it warns about unused return values +// for functions like write and fchmod, even if you cast +// the result to (void). +// #define USED(x) ((void)(x)) +#define USED(x) do{typeof(x) __tmp__ = (x); (void)__tmp__; } while(0) diff --git a/src/9vx/vx32.c b/src/9vx/vx32.c @@ -223,6 +223,7 @@ touser(void *initsp) * User-mode execution loop. */ for(;;){ +iprint("X\n"); /* * Optimization: try to fault in code page and stack * page right now, since we're likely to need them. @@ -267,7 +268,7 @@ touser(void *initsp) int read; nfaults++; read = !(vp->cpu->traperr & 2); - addr = (uchar*)vp->cpu->trapva; + addr = (uchar*)(uintptr)vp->cpu->trapva; if(traceprocs) print("fault %p read=%d\n", addr, read); if(isuaddr(addr) && fault(addr - up->pmmu.uzero, read) >= 0) @@ -280,19 +281,36 @@ touser(void *initsp) if(abortonfault) abort(); } +iprint("U\n"); up->dbgreg = &u; +iprint("P\n"); +struct timeval tv; +tv.tv_sec = 0; +tv.tv_usec = 1000; +select(0, 0, 0, 0, &tv); +iprint("P1\n"); proc2ureg(vp, &u); +iprint("Q\n"); u.trap = rc; +iprint("T\n"); trap(&u); ureg2proc(&u, vp); } } +static void +breakme(void) +{ +} + static void proc2ureg(vxproc *vp, Ureg *u) { - memset(u, 0, sizeof *u); +static int x; +iprint("proc2ureg %p %p %d\n", vp, u, ++x); +if(x==1588) breakme(); +// memset(u, 0, sizeof *u); u->pc = vp->cpu->eip; u->ax = vp->cpu->reg[EAX]; u->bx = vp->cpu->reg[EBX]; @@ -301,6 +319,7 @@ proc2ureg(vxproc *vp, Ureg *u) u->si = vp->cpu->reg[ESI]; u->di = vp->cpu->reg[EDI]; u->usp = vp->cpu->reg[ESP]; +iprint("proc2ureg %p %p\n", vp, u); } static void diff --git a/src/9vx/x11/x11-draw.c b/src/9vx/x11/x11-draw.c @@ -40,6 +40,7 @@ _xallocmemimage(Rectangle r, u32int chan, int pixmap) xm = mallocz(sizeof(Xmem), 1); if(xm == nil){ + iprint("mallocz failed\n"); freememimage(m); return nil; } @@ -73,6 +74,7 @@ _xallocmemimage(Rectangle r, u32int chan, int pixmap) ZPixmap, 0, (char*)m->data->bdata, Dx(r), Dy(r), 32, m->width*sizeof(u32int)); if(xi == nil){ + iprint("XCreateImage %R %d %d failed\n", r, m->width, m->depth); freememimage(m); if(xm->pixmap != pixmap) XFreePixmap(_x.display, xm->pixmap); @@ -452,7 +454,7 @@ unloadmemimage(Memimage *i, Rectangle r, uchar *data, int ndata) return _unloadmemimage(i, r, data, ndata); } -ulong +u32int pixelbits(Memimage *m, Point p) { if(m->x) diff --git a/src/9vx/x11/x11-init.c b/src/9vx/x11/x11-init.c @@ -399,6 +399,8 @@ _xattach(char *label, char *winsize) _x.screenpm = XCreatePixmap(_x.display, _x.drawable, Dx(r), Dy(r), _x.depth); _x.nextscreenpm = _x.screenpm; _x.screenimage = _xallocmemimage(r, _x.chan, _x.screenpm); + if(_x.screenimage == nil) + panic("_xallocmemimage failed"); /* * Figure out physical window location. diff --git a/src/9vx/x11/x11-itrans.c b/src/9vx/x11/x11-itrans.c @@ -361,7 +361,7 @@ _xgetsnarffrom(XWindow w, Atom clipboard, Atom target, int timeout0, int timeout /* get the property */ xdata = nil; - XGetWindowProperty(_x.display, _x.drawable, prop, 0, SnarfSize/sizeof(ulong), 0, + XGetWindowProperty(_x.display, _x.drawable, prop, 0, SnarfSize/sizeof(u32int), 0, AnyPropertyType, &type, &fmt, &len, &dummy, &xdata); if((type != target && type != XA_STRING && type != _x.utf8string) || len == 0){ if(xdata)