revert a/ updates, needs more testing (sorry) - vx32 - Local 9vx git repository for patches.
       
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) commit d50c4073bcb81436fccd540ef99ecbeb22125b5d
 (DIR) parent 0018e7182c4aae8db0a756dd84b73e287484e682
 (HTM) Author: Jesus Galan Lopez (yiyus) <yiyu.jgl@gmail.com>
       Date:   Sat, 11 Sep 2010 19:21:34 +0200
       
       revert a/ updates, needs more testing (sorry)
       
       Diffstat:
         src/9vx/a/a.out.h                   |       2 +-
         src/9vx/a/auth.c                    |       6 +++---
         src/9vx/a/convS2M.c                 |       9 +++------
         src/9vx/a/devcap.c                  |       2 +-
         src/9vx/a/devcons.c                 |       7 ++-----
         src/9vx/a/devdraw.c                 |       9 ++++-----
         src/9vx/a/devproc.c                 |       6 +++---
         src/9vx/a/devsrv.c                  |       1 -
         src/9vx/a/devssl.c                  |       2 +-
         src/9vx/a/devtls.c                  |       2 +-
         src/9vx/a/eipfmt.c                  |       4 ++--
         src/9vx/a/error.h                   |       1 -
         src/9vx/a/fault.c                   |      75 ++++++++++++++++++++-----------
         src/9vx/a/fns.h                     |       1 -
         src/9vx/a/fs.h                      |      12 +++++++-----
         src/9vx/a/io.h                      |      10 ++--------
         src/9vx/a/ip.h                      |      55 -------------------------------
         src/9vx/a/libsec.h                  |      36 ++++---------------------------
         src/9vx/a/mem.h                     |       2 +-
         src/9vx/a/part.c                    |      26 ++++++++------------------
         src/9vx/a/portdat.h                 |       5 ++---
         src/9vx/a/proc.c                    |      10 ++--------
         src/9vx/a/qlock.c                   |       8 ++++----
         src/9vx/a/segment.c                 |      34 +++++++++++++++----------------
         src/9vx/a/swap.c                    |      65 +++++++-------------------------
         src/9vx/a/sysproc.c                 |       2 +-
         src/9vx/a/tos.h                     |      21 +++++++++++++++++++++
         src/9vx/a/unthwack.c                |       3 +--
       
       28 files changed, 152 insertions(+), 264 deletions(-)
       ---
 (DIR) diff --git a/src/9vx/a/a.out.h b/src/9vx/a/a.out.h
       @@ -6,7 +6,7 @@ struct        Exec
                int32        data;                 /* size of initialized data */
                int32        bss;                  /* size of uninitialized data */
                int32        syms;                 /* size of symbol table */
       -        int32        entry;                 /* entry point */
       +        int32        entry;                 /* entry point32 */
                int32        spsz;                /* size of pc/sp offset table */
                int32        pcsz;                /* size of pc/line number table */
        };
 (DIR) diff --git a/src/9vx/a/auth.c b/src/9vx/a/auth.c
       @@ -27,8 +27,8 @@ sysfversion(uint32 *arg)
                Chan *c;
        
                msize = arg[1];
       -        vers = uvalidaddr(arg[2], arglen, 1);
                arglen = arg[3];
       +        vers = uvalidaddr(arg[2], arglen, 1);
                /* check there's a NUL in the version string */
                if(arglen==0 || memchr(vers, 0, arglen)==0)
                        error(Ebadarg);
       @@ -76,10 +76,10 @@ sysfauth(uint32 *arg)
        
                ac = mntauth(c, aname);
                /* at this point ac is responsible for keeping c alive */
       -        poperror();        /* c */
                cclose(c);
       -        poperror();        /* aname */
       +        poperror();        /* c */
                free(aname);
       +        poperror();        /* aname */
        
                if(waserror()){
                        cclose(ac);
 (DIR) diff --git a/src/9vx/a/convS2M.c b/src/9vx/a/convS2M.c
       @@ -15,13 +15,10 @@ pstring(uchar *p, char *s)
                }
        
                n = strlen(s);
       -        /*
       -         * We are moving the string before the length,
       -         * so you can S2M a struct into an existing message
       -         */
       -        memmove(p + BIT16SZ, s, n);
                PBIT16(p, n);
       -        p += n + BIT16SZ;
       +        p += BIT16SZ;
       +        memmove(p, s, n);
       +        p += n;
                return p;
        }
        
 (DIR) 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
        {
 (DIR) 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;
       @@ -103,8 +103,7 @@ prflush(void)
         */
        struct {
                Lock lk;
       -//        char buf[16384];                /* normal */
       -        char buf[256*1024];                /* for acpi debugging */
       +        char buf[16384];
                uint n;
        } kmesg;
        
       @@ -1341,8 +1340,6 @@ writebintime(char *buf, int n)
                        if(n < sizeof(uvlong))
                                error(Ebadtimectl);
                        le2vlong(&fasthz, p);
       -                if(fasthz <= 0)
       -                        error(Ebadtimectl);
                        todsetfreq(fasthz);
                        break;
                }
 (DIR) diff --git a/src/9vx/a/devdraw.c b/src/9vx/a/devdraw.c
       @@ -6,10 +6,10 @@
        #include        "error.h"
        
        #define        Image        IMAGE
       -#include "draw.h"
       -#include "memdraw.h"
       -#include "memlayer.h"
       -#include "cursor.h"
       +#include        "draw.h"
       +#include        "memdraw.h"
       +#include        "memlayer.h"
       +#include        "cursor.h"
        #include        "screen.h"
        
        #define blankscreen(x)
       @@ -1377,7 +1377,6 @@ printmesg(char *fmt, uchar *a, int plsprnt)
                char *p, *q;
        
                if(1|| plsprnt==0){
       -                ;
                        return;
                }
                q = buf;
 (DIR) diff --git a/src/9vx/a/devproc.c b/src/9vx/a/devproc.c
       @@ -1,5 +1,5 @@
        #include        "u.h"
       -#include "trace.h"
       +#include        "trace.h"
        #include        "tos.h"
        #include        "lib.h"
        #include        "mem.h"
       @@ -86,7 +86,6 @@ Dirtab procdir[] =
                "wait",                {Qwait},        0,                        0400,
                "profile",        {Qprofile},        0,                        0400,
                "syscall",        {Qsyscall},        0,                        0400,
       -        "syscall",        {Qsyscall},        0,                        0400,        
        };
        
        static
       @@ -387,7 +386,7 @@ procopen(Chan *c, int omode)
                case Qwait:
                case Qregs:
                case Qfpregs:
       -        case Qsyscall:        
       +        case Qsyscall:
                        nonone(p);
                        break;
        
       @@ -696,6 +695,7 @@ procread(Chan *c, void *va, long n, vlong off)
                                n = j-offset;
                        memmove(a, &up->genbuf[offset], n);
                        return n;
       +
                case Qsyscall:
                        if(!p->syscalltrace)
                                return 0;
 (DIR) diff --git a/src/9vx/a/devsrv.c b/src/9vx/a/devsrv.c
       @@ -224,7 +224,6 @@ srvremove(Chan *c)
        
                if(sp->chan)
                        cclose(sp->chan);
       -        free(sp->owner);
                free(sp->name);
                free(sp);
        }
 (DIR) diff --git a/src/9vx/a/devssl.c b/src/9vx/a/devssl.c
       @@ -8,7 +8,7 @@
        #include        "fns.h"
        #include        "error.h"
        
       -#include "libsec.h"
       +#include        "libsec.h"
        
        #define NOSPOOKS 1
        
 (DIR) diff --git a/src/9vx/a/devtls.c b/src/9vx/a/devtls.c
       @@ -8,7 +8,7 @@
        #include        "fns.h"
        #include        "error.h"
        
       -#include "libsec.h"
       +#include        "libsec.h"
        
        ttypedef struct OneWay        OneWay;
        ttypedef struct Secret                Secret;
 (DIR) 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;
       +        uint32 *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, uint32*);
                        for(i = 0; i < 4; i++)
                                hnputl(ip+4*i, *lp++);
                        p = ip;
 (DIR) diff --git a/src/9vx/a/error.h b/src/9vx/a/error.h
       @@ -50,4 +50,3 @@ extern char Ebadstat[];                /* malformed stat buffer */
        extern char Enegoff[];                /* negative i/o offset */
        extern char Ecmdargs[];                /* wrong #args in control message */
        extern char Ebadip[];                /* bad ip address syntax */
       -extern char Edirseek[];                /* seek in directory */
 (DIR) diff --git a/src/9vx/a/fault.c b/src/9vx/a/fault.c
       @@ -150,6 +150,12 @@ fixfault(Segment *s, ulong addr, int read, int doputmmu)
                        if(ref > 1) {
                                unlock(&lkp->lk);
        
       +                        if(swapfull()){
       +                                qunlock(&s->lk);
       +                                pprint("swap space full\n");
       +                                faulterror(Enoswap, nil, 1);
       +                        }
       +
                                new = newpage(0, &s, addr);
                                if(s == 0)
                                        return -1;
       @@ -159,7 +165,7 @@ fixfault(Segment *s, ulong addr, int read, int doputmmu)
                        }
                        else {
                                /* save a copy of the original for the image cache */
       -                        if(lkp->image)
       +                        if(lkp->image && !swapfull())
                                        duppage(lkp);
        
                                unlock(&lkp->lk);
       @@ -216,11 +222,6 @@ retry:
                                *p = new;
                                return;
                        }
       -
       -                c = s->image->c;
       -                ask = s->flen-soff;
       -                if(ask > BY2PG)
       -                        ask = BY2PG;
                }
                else {                        /* from a swap image */
                        daddr = swapaddr(loadrec);
       @@ -230,34 +231,39 @@ retry:
                                *p = new;
                                return;
                        }
       -
       -                c = swapimage.c;
       -                ask = BY2PG;
                }
       +
       +
                qunlock(&s->lk);
        
                new = newpage(0, 0, addr);
                k = kmap(new);
                kaddr = (char*)VA(k);
        
       -        while(waserror()) {
       -                if(strcmp(up->errstr, Eintr) == 0)
       -                        continue;
       -                kunmap(k);
       -                putpage(new);
       -                faulterror(Eioload, c, 0);
       -        }
       +        if(loadrec == 0) {                        /* This is demand load */
       +                c = s->image->c;
       +                while(waserror()) {
       +                        if(strcmp(up->errstr, Eintr) == 0)
       +                                continue;
       +                        kunmap(k);
       +                        putpage(new);
       +                        faulterror("sys: demand load I/O error", c, 0);
       +                }
       +
       +                ask = s->flen-soff;
       +                if(ask > BY2PG)
       +                        ask = BY2PG;
        
       -        n = devtab[c->type]->read(c, kaddr, ask, daddr);
       -        if(n != ask)
       -                faulterror(Eioload, c, 0);
       -        if(ask < BY2PG)
       -                memset(kaddr+ask, 0, BY2PG-ask);
       +                n = devtab[c->type]->read(c, kaddr, ask, daddr);
       +                if(n != ask)
       +                        faulterror(Eioload, c, 0);
       +                if(ask < BY2PG)
       +                        memset(kaddr+ask, 0, BY2PG-ask);
       +
       +                poperror();
       +                kunmap(k);
       +                qlock(&s->lk);
        
       -        poperror();
       -        kunmap(k);
       -        qlock(&s->lk);
       -        if(loadrec == 0) {        /* This is demand load */
                        /*
                         *  race, another proc may have gotten here first while
                         *  s->lk was unlocked
       @@ -270,7 +276,24 @@ retry:
                        else
                                putpage(new);
                }
       -        else {                        /* This is paged out */
       +        else {                                /* This is paged out */
       +                c = swapimage.c;
       +                if(waserror()) {
       +                        kunmap(k);
       +                        putpage(new);
       +                        qlock(&s->lk);
       +                        qunlock(&s->lk);
       +                        faulterror("sys: page in I/O error", c, 0);
       +                }
       +
       +                n = devtab[c->type]->read(c, kaddr, BY2PG, daddr);
       +                if(n != BY2PG)
       +                        faulterror(Eioload, c, 0);
       +
       +                poperror();
       +                kunmap(k);
       +                qlock(&s->lk);
       +
                        /*
                         *  race, another proc may have gotten here first
                         *  (and the pager may have run on that page) while
 (DIR) diff --git a/src/9vx/a/fns.h b/src/9vx/a/fns.h
       @@ -125,7 +125,6 @@ void        realmode(Ureg*);
        void        screeninit(void);
        void        (*screenputs)(char*, int);
        void        syncclock(void);
       -void        syscallretprint(Ureg *ureg, int syscallno, uvlong start, uvlong stop);
        void*        tmpmap(Page*);
        void        tmpunmap(void*);
        void        touser(void*);
 (DIR) diff --git a/src/9vx/a/fs.h b/src/9vx/a/fs.h
       @@ -27,10 +27,12 @@ struct Fs{
                File        root;
        };
        
       -// extern int chatty;
       -// extern int dotini(Fs*);
       -// extern int fswalk(Fs*, char*, File*);
       -// extern int fsread(File*, void*, long);
       -// extern int fsboot(Fs*, char*, Boot*);
       +/*
       +extern int chatty;
       +extern int dotini(Fs*);
       +extern int fswalk(Fs*, char*, File*);
       +extern int fsread(File*, void*, long);
       +extern int fsboot(Fs*, char*, Boot*);
       +*/
        
        #define BADPTR(x) ((ulong)x < 0x80000000)
 (DIR) diff --git a/src/9vx/a/io.h b/src/9vx/a/io.h
       @@ -1,7 +1,7 @@
        #define X86STEPPING(x)        ((x) & 0x0F)
       -/* incorporates extended-model and -family bits */
       +/* incorporate extended-model bits */
        #define X86MODEL(x)        ((((x)>>4) & 0x0F) | (((x)>>16) & 0x0F)<<4)
       -#define X86FAMILY(x)        ((((x)>>8) & 0x0F) | (((x)>>20) & 0xFF)<<4)
       +#define X86FAMILY(x)        (((x)>>8) & 0x0F)
        
        enum {
                VectorNMI        = 2,                /* non-maskable interrupt */
       @@ -259,12 +259,6 @@ struct Pcidev
                int        pmrb;                        /* power management register block */
        };
        
       -enum {
       -        /* vendor ids */
       -        Vintel        = 0x8086,
       -        Vmyricom= 0x14c1,
       -};
       -
        #define PCIWINDOW        0
        #define PCIWADDR(va)        (PADDR(va)+PCIWINDOW)
        #define ISAWINDOW        0
 (DIR) diff --git a/src/9vx/a/ip.h b/src/9vx/a/ip.h
       @@ -12,59 +12,6 @@ enum
                IP_VER6=        0x60,
        };
        
       -/*
       - *  for reading /net/ipifc
       - */
       -ttypedef struct Ipifc Ipifc;
       -ttypedef struct Iplifc Iplifc;
       -ttypedef struct Ipv6rp Ipv6rp;
       -
       -/* local address */
       -struct Iplifc
       -{
       -        Iplifc        *next;
       -
       -        /* per address on the ip interface */
       -        uchar        ip[IPaddrlen];
       -        uchar        mask[IPaddrlen];
       -        uchar        net[IPaddrlen];                /* ip & mask */
       -        ulong        preflt;                        /* preferred lifetime */
       -        ulong        validlt;                /* valid lifetime */
       -};
       -
       -/* default values, one per stack */
       -struct Ipv6rp
       -{
       -        int        mflag;
       -        int        oflag;
       -        int         maxraint;
       -        int        minraint;
       -        int        linkmtu;
       -        int        reachtime;
       -        int        rxmitra;
       -        int        ttl;
       -        int        routerlt;        
       -};
       -
       -/* actual interface */
       -struct Ipifc
       -{
       -        Ipifc        *next;
       -        Iplifc        *lifc;
       -
       -        /* per ip interface */
       -        int        index;                        /* number of interface in ipifc dir */
       -        char        dev[64];
       -        uchar        sendra6;                /* on == send router adv */
       -        uchar        recvra6;                /* on == rcv router adv */
       -        int        mtu;
       -        ulong        pktin;
       -        ulong        pktout;
       -        ulong        errin;
       -        ulong        errout;
       -        Ipv6rp        rp;
       -};
       -
        #define ISIPV6MCAST(addr)        ((addr)[0] == 0xff)
        #define ISIPV6LINKLOCAL(addr) ((addr)[0] == 0xfe && ((addr)[1] & 0xc0) == 0x80)
        
       @@ -168,8 +115,6 @@ int        myetheraddr(uchar*, char*);
        int        equivip4(uchar*, uchar*);
        int        equivip6(uchar*, uchar*);
        
       -Ipifc*        readipifc(char*, Ipifc*, int);
       -
        void        hnputv(void*, uvlong);
        void        hnputl(void*, uint);
        void        hnputs(void*, ushort);
 (DIR) diff --git a/src/9vx/a/libsec.h b/src/9vx/a/libsec.h
       @@ -21,26 +21,17 @@ struct AESstate
                ulong        setup;
                int        rounds;
                int        keybytes;
       -        uint        ctrsz;
       +//        uint        ctrsz;
                uchar        key[AESmaxkey];                        /* unexpanded key */
                ulong        ekey[4*(AESmaxrounds + 1)];        /* encryption key */
                ulong        dkey[4*(AESmaxrounds + 1)];        /* decryption key */
                uchar        ivec[AESbsize];                        /* initialization vector */
       -        uchar        mackey[3 * AESbsize];                /* 3 XCBC mac 96 keys */
       +//        uchar        mackey[3 * AESbsize];                /* 3 XCBC mac 96 keys */
        };
        
       -/* block ciphers */
       -void        aes_encrypt(ulong rk[], int Nr, uchar pt[16], uchar ct[16]);
       -void        aes_decrypt(ulong rk[], int Nr, uchar ct[16], uchar pt[16]);
       -
        void        setupAESstate(AESstate *s, uchar key[], int keybytes, uchar *ivec);
        void        aesCBCencrypt(uchar *p, int len, AESstate *s);
        void        aesCBCdecrypt(uchar *p, int len, AESstate *s);
       -void        aesCTRdecrypt(uchar *p, int len, AESstate *s);
       -void        aesCTRencrypt(uchar *p, int len, AESstate *s);
       -
       -void        setupAESXCBCstate(AESstate *s);
       -uchar*        aesXCBCmac(uchar *p, int len, AESstate *s);
        
        /*
         * Blowfish Definitions
       @@ -136,10 +127,6 @@ void        des3ECBdecrypt(uchar*, int, DES3state*);
        enum
        {
                SHA1dlen=        20,        /* SHA digest length */
       -        SHA2_224dlen=        28,        /* SHA-224 digest length */
       -        SHA2_256dlen=        32,        /* SHA-256 digest length */
       -        SHA2_384dlen=        48,        /* SHA-384 digest length */
       -        SHA2_512dlen=        64,        /* SHA-512 digest length */
                MD4dlen=        16,        /* MD4 digest length */
                MD5dlen=        16,        /* MD5 digest length */
                AESdlen=        16,        /* TODO: see rfc */
       @@ -151,21 +138,14 @@ typedef struct DigestState DigestState;
        struct DigestState
        {
                uvlong        len;
       -        union {
       -                uint32        state[8];
       -                uint64        bstate[8];
       -        };
       -        uchar        buf[256];
       +        uint32        state[5];
       +        uchar        buf[128];
                int        blen;
                char        malloced;
                char        seeded;
        };
        ttypedef struct DigestState SHAstate;        /* obsolete name */
        ttypedef struct DigestState SHA1state;
       -ttypedef struct DigestState SHA2_224state;
       -ttypedef struct DigestState SHA2_256state;
       -ttypedef struct DigestState SHA2_384state;
       -ttypedef struct DigestState SHA2_512state;
        ttypedef struct DigestState MD5state;
        ttypedef struct DigestState MD4state;
        ttypedef struct DigestState AEShstate;
       @@ -173,10 +153,6 @@ typedef struct DigestState AEShstate;
        DigestState*        md4(uchar*, ulong, uchar*, DigestState*);
        DigestState*        md5(uchar*, ulong, uchar*, DigestState*);
        DigestState*        sha1(uchar*, ulong, uchar*, DigestState*);
       -DigestState*        sha2_224(uchar*, ulong, uchar*, DigestState*);
       -DigestState*        sha2_256(uchar*, ulong, uchar*, DigestState*);
       -DigestState*        sha2_384(uchar*, ulong, uchar*, DigestState*);
       -DigestState*        sha2_512(uchar*, ulong, uchar*, DigestState*);
        DigestState*        aes(uchar*, ulong, uchar*, DigestState*);
        DigestState*        hmac_x(uchar *p, ulong len, uchar *key, ulong klen,
                                uchar *digest, DigestState *s,
       @@ -184,10 +160,6 @@ DigestState*        hmac_x(uchar *p, ulong len, uchar *key, ulong klen,
                                int xlen);
        DigestState*        hmac_md5(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
        DigestState*        hmac_sha1(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
       -DigestState*        hmac_sha2_224(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
       -DigestState*        hmac_sha2_256(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
       -DigestState*        hmac_sha2_384(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
       -DigestState*        hmac_sha2_512(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
        DigestState*        hmac_aes(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
        char*                md5pickle(MD5state*);
        MD5state*        md5unpickle(char*);
 (DIR) diff --git a/src/9vx/a/mem.h b/src/9vx/a/mem.h
       @@ -17,7 +17,7 @@
        #define        PGROUND(s)        ROUND(s, BY2PG)
        #define        BLOCKALIGN        8
        
       -#define        MAXMACH                24                        /* max # cpus system can run */
       +#define        MAXMACH                128                        /* max # cpus system can run */
        #define        KSTACK                65536                        /* Size of kernel stack */
        
        /*
 (DIR) diff --git a/src/9vx/a/part.c b/src/9vx/a/part.c
       @@ -13,7 +13,6 @@ enum {
        
        uchar *mbrbuf, *partbuf;
        int nbuf;
       -
        #define trace 0
        
        int
       @@ -105,7 +104,7 @@ p9part(SDunit *unit, char *name)
                char *field[4], *line[Npart+1];
                uvlong start, end;
                int i, n;
       -
       +        
                p = sdfindpart(unit, name);
                if(p == nil)
                        return;
       @@ -126,7 +125,7 @@ p9part(SDunit *unit, char *name)
                        if(getfields(line[i], field, 4, 0, " ") != 4)
                                break;
                        start = strtoull(field[2], 0, 0);
       -                end   = strtoull(field[3], 0, 0);
       +                end = strtoull(field[3], 0, 0);
                        if(start >= end || end > unit->sectors)
                                break;
                        sdaddpart(unit, field[1], p->start+start, p->start+end);
       @@ -160,18 +159,16 @@ mbrpart(SDunit *unit)
        
                taboffset = 0;
                dp = (Dospart*)&mbrbuf[0x1BE];
       -        {
       +        if(1) {
                        /* get the MBR (allowing for DMDDO) */
       -                if(tsdbio(unit, &unit->part[0], mbrbuf,
       -                    (vlong)taboffset * unit->secsize, 1) < 0)
       +                if(tsdbio(unit, &unit->part[0], mbrbuf, (vlong)taboffset*unit->secsize, 1) < 0)
                                return -1;
                        for(i=0; i<4; i++)
                                if(dp[i].type == DMDDO) {
                                        if(trace)
                                                print("DMDDO partition found\n");
                                        taboffset = 63;
       -                                if(tsdbio(unit, &unit->part[0], mbrbuf,
       -                                    (vlong)taboffset * unit->secsize, 1) < 0)
       +                                if(tsdbio(unit, &unit->part[0], mbrbuf, (vlong)taboffset*unit->secsize, 1) < 0)
                                                return -1;
                                        i = -1;        /* start over */
                                }
       @@ -185,8 +182,7 @@ mbrpart(SDunit *unit)
                havedos = 0;
                firstxpart = 0;
                for(;;) {
       -                if(tsdbio(unit, &unit->part[0], mbrbuf,
       -                    (vlong)taboffset * unit->secsize, 1) < 0)
       +                if(tsdbio(unit, &unit->part[0], mbrbuf, (vlong)taboffset*unit->secsize, 1) < 0)
                                return -1;
                        if(trace) {
                                if(firstxpart)
       @@ -255,7 +251,7 @@ part9660(SDunit *unit)
                if(unit->secsize != 2048)
                        return -1;
        
       -        if(unit->dev->ifc->bio(unit, 0, 0, buf, 2048/unit->secsize, (a*2048)/unit->secsize) < 0)
       +        if(unit->dev->ifc->bio(unit, 0, 0, buf, 2048/unit->secsize, (17*2048)/unit->secsize) < 0)
                        return -1;
        
                if(buf[0] || strcmp((char*)buf+1, "CD001\x01EL TORITO SPECIFICATION") != 0)
       @@ -337,15 +333,9 @@ partition(SDunit *unit)
                        nbuf = unit->secsize;
                }
        
       -        /*
       -         * there might be no mbr (e.g. on a very large device), so look for
       -         * a bare plan 9 partition table if mbrpart fails.
       -         */
                if((type & NEW) && mbrpart(unit) >= 0){
       -                /* nothing to do */
       +                /* nothing to do */;
                }
       -        else if (type & NEW)
       -                p9part(unit, "data");
                else if(type & OLD)
                        oldp9part(unit);
        }
 (DIR) diff --git a/src/9vx/a/portdat.h b/src/9vx/a/portdat.h
       @@ -310,7 +310,6 @@ struct Page
                ulong        pa;                        /* Physical address in memory */
                ulong        va;                        /* Virtual address for user */
                ulong        daddr;                        /* Disc address on swap */
       -        ulong        gen;                        /* Generation counter for swap */
                ushort        ref;                        /* Reference count */
                char        modref;                        /* Simulated modify/reference bits */
                char        color;                        /* Cache coloring */
       @@ -753,7 +752,8 @@ struct Proc
                 *  machine specific MMU
                 */
                PMMU pmmu;
       -        char        *syscalltrace;        /* syscall trace */
       +        /* syscall trace */
       +        char *syscalltrace;
        };
        
        enum
       @@ -784,7 +784,6 @@ extern        char*        statename[];
        extern        Image        swapimage;
        extern        char*        sysname;
        extern        uint        qiomaxatomic;
       -extern        char*        sysctab[];
        
        enum
        {
 (DIR) diff --git a/src/9vx/a/proc.c b/src/9vx/a/proc.c
       @@ -1,11 +1,11 @@
        #define        WANT_M
       -#include "u.h"
       +#include        "u.h"
        #include        "lib.h"
        #include        "mem.h"
        #include        "dat.h"
        #include        "fns.h"
        #include        "error.h"
       -#include "trace.h"
       +#include        "trace.h"
        
        int        schedgain = 30;        /* units in seconds */
        int        nrdy;
       @@ -619,12 +619,8 @@ newproc(void)
                if(up && up->procctl == Proc_tracesyscall)
                        p->procctl = Proc_tracesyscall;
                else
       -        if(up && up->procctl == Proc_tracesyscall)
       -                p->procctl = Proc_tracesyscall;
       -        else
                        p->procctl = 0;
                p->syscalltrace = 0;
       -        p->syscalltrace = 0;        
                p->notepending = 0;
                p->ureg = 0;
                p->privatemem = 0;
       @@ -1058,8 +1054,6 @@ pexit(char *exitstr, int freemem)
        
                if(up->syscalltrace)
                        free(up->syscalltrace);
       -        if(up->syscalltrace)
       -                free(up->syscalltrace);
                up->alarm = 0;
                if (up->timer.tt)
                        timerdel(&up->timer);
 (DIR) diff --git a/src/9vx/a/qlock.c b/src/9vx/a/qlock.c
       @@ -4,8 +4,8 @@
        #include "mem.h"
        #include "dat.h"
        #include "fns.h"
       -int tracelock = 0;
        
       +int tracelock = 0;
        
        struct {
                ulong rlock;
       @@ -22,12 +22,12 @@ __qlock(QLock *q)
                Proc *p;
        
                if(m->ilockdepth != 0)
       -                print("qlock: %#p: ilockdepth %d\n", getcallerpc(&q), m->ilockdepth);
       +                print("qlock: %lux: ilockdepth %d\n", getcallerpc(&q), m->ilockdepth);
                if(up != nil && up->nlocks.ref)
       -                print("qlock: %#p: nlocks %lud\n", getcallerpc(&q), up->nlocks.ref);
       +                print("qlock: %lux: nlocks %lud\n", getcallerpc(&q), up->nlocks.ref);
        
                if(q->use.key == 0x55555555)
       -                panic("qlock: q %#p, key 5*\n", q);
       +                panic("qlock: q %p, key 5*\n", q);
                lock(&q->use);
                rwstats.qlock++;
                if(!q->locked) {
 (DIR) diff --git a/src/9vx/a/segment.c b/src/9vx/a/segment.c
       @@ -64,6 +64,8 @@ newseg(int type, ulong base, ulong size)
                if(size > (SEGMAPSIZE*PTEPERTAB))
                        error(Enovmem);
        
       +        if(swapfull())
       +                error(Enoswap);
                s = smalloc(sizeof(Segment));
                s->ref.ref = 1;
                s->type = type;
       @@ -158,7 +160,7 @@ dupseg(Segment **seg, int segno, int share)
                Pte *pte;
                Segment *n, *s;
        
       -        ;
       +        n = 0;
                s = seg[segno];
        
                qlock(&s->lk);
       @@ -463,14 +465,6 @@ ibrk(ulong addr, int seg)
                newtop = PGROUND(addr);
                newsize = (newtop-s->base)/BY2PG;
                if(newtop < s->top) {
       -                /*
       -                 * do not shrink a segment shared with other procs, as the
       -                 * to-be-freed address space may have been passed to the kernel
       -                 */
       -                if(s->ref.ref > 1){
       -                        qunlock(&s->lk);
       -                        error(Einuse);
       -                }
                        mfreeseg(s, newtop, (s->top-newtop)/BY2PG);
                        s->top = newtop;
                        s->size = newsize;
       @@ -479,6 +473,11 @@ ibrk(ulong addr, int seg)
                        return 0;
                }
        
       +        if(swapfull()){
       +                qunlock(&s->lk);
       +                error(Enoswap);
       +        }
       +
                for(i = 0; i < NSEG; i++) {
                        ns = up->seg[i];
                        if(ns == 0 || ns == s)
       @@ -676,23 +675,22 @@ segattach(Proc *p, ulong attr, char *name, ulong va, ulong len)
                 * Starting at the lowest possible stack address - len,
                 * check for an overlapping segment, and repeat at the
                 * base of that segment - len until either a hole is found
       -         * or the address space is exhausted.  Ensure that we don't
       -         * map the zero page.
       +         * or the address space is exhausted.
                 */
                if(va == 0) {
       -                for (os = p->seg[SSEG]; os != nil; os = isoverlap(p, va, len)) {
       +                va = p->seg[SSEG]->base - len;
       +                for(;;) {
       +                        os = isoverlap(p, va, len);
       +                        if(os == nil)
       +                                break;
                                va = os->base;
       -                        if(len >= va)
       +                        if(len > va)
                                        error(Enovmem);
                                va -= len;
                        }
       -                va &= ~(BY2PG-1);
       -        } else {
       -                va &= ~(BY2PG-1);
       -                if(va == 0 || va >= USTKTOP)
       -                        error(Ebadarg);
                }
        
       +        va = va&~(BY2PG-1);
                if(isoverlap(p, va, len) != nil)
                        error(Esoverlap);
        
 (DIR) diff --git a/src/9vx/a/swap.c b/src/9vx/a/swap.c
       @@ -12,25 +12,10 @@ static void        pageout(Proc*, Segment*);
        static void        pagepte(int, Page**);
        static void        pager(void *v);
        
       -Image         swapimage;
       -
       +        Image         swapimage;
        static        Page        **iolist;
        static        int        ioptr;
        
       -static        ulong        genage, genclock, gencount;
       -static        uvlong        gensum;
       -
       -static void
       -gentick(void)
       -{
       -        genclock++;
       -        if(gencount)
       -                genage = gensum / gencount;
       -        else
       -                genage = 0;
       -        gensum = gencount = 0;
       -}
       -
        void
        swapinit(void)
        {
       @@ -129,17 +114,15 @@ pager(void *junk)
        
        loop:
                up->psstate = "Idle";
       -        wakeup(&palloc.r);
                sleep(&swapalloc.r, needpages, 0);
        
                while(needpages(junk)) {
       +
                        if(swapimage.c) {
                                p++;
       -                        if(p >= ep){
       +                        if(p >= ep)
                                        p = proctab(0);
       -                                gentick();                        
       -                        }
       -
       +        
                                if(p->state == Dead || p->noswap)
                                        continue;
        
       @@ -174,14 +157,15 @@ loop:
                                        }
                                }
                                qunlock(&p->seglock);
       -                } else {
       -                        print("out of memory\n");
       -                        killbig("out of memory");
       -                        freebroken();                /* can use the memory */
       +                }
       +                else {
       +                        print("out of physical memory; no swap configured\n");
       +                        if(!cpuserver || freebroken() == 0)
       +                                killbig("out of memory");
        
                                /* Emulate the old system if no swap channel */
       -                        if(!swapimage.c)
       -                                tsleep(&up->sleep, return0, 0, 5000);
       +                        tsleep(&up->sleep, return0, 0, 5000);
       +                        wakeup(&palloc.r);
                        }
                }
                goto loop;
       @@ -191,7 +175,6 @@ static void
        pageout(Proc *p, Segment *s)
        {
                int type, i, size;
       -        ulong age;
                Pte *l;
                Page **pg, *entry;
        
       @@ -229,17 +212,8 @@ pageout(Proc *p, Segment *s)
        
                                if(entry->modref & PG_REF) {
                                        entry->modref &= ~PG_REF;
       -                                entry->gen = genclock;
       -                        }
       -
       -                        if(genclock < entry->gen)
       -                                age = ~(entry->gen - genclock);
       -                        else
       -                                age = genclock - entry->gen;
       -                        gensum += age;
       -                        gencount++;
       -                        if(age <= genage)
                                        continue;
       +                        }
        
                                pagepte(type, pg);
        
       @@ -347,19 +321,6 @@ pagersummary(void)
                        ioptr);
        }
        
       -static int
       -pageiocomp(void *a, void *b)
       -{
       -        Page *p1, *p2;
       -
       -        p1 = *(Page **)a;
       -        p2 = *(Page **)b;
       -        if(p1->daddr > p2->daddr)
       -                return 1;
       -        else
       -                return -1;
       -}
       -
        static void
        executeio(void)
        {
       @@ -370,7 +331,7 @@ executeio(void)
                KMap *k;
        
                c = swapimage.c;
       -        qsort(iolist, ioptr, sizeof iolist[0], pageiocomp);
       +
                for(i = 0; i < ioptr; i++) {
                        if(ioptr > conf.nswppo)
                                panic("executeio: ioptr %d > %d", ioptr, conf.nswppo);
 (DIR) diff --git a/src/9vx/a/sysproc.c b/src/9vx/a/sysproc.c
       @@ -7,7 +7,7 @@
        #include        "fns.h"
        #include        "error.h"
        
       -#include "a.out.h"
       +#include        "a.out.h"
        
        int        shargs(char*, int, char**);
        
 (DIR) diff --git a/src/9vx/a/tos.h b/src/9vx/a/tos.h
       @@ -1,6 +1,7 @@
        ttypedef struct Tos Tos;
        ttypedef struct Plink Plink;
        
       +#if 0
        
        struct Tos {
                struct                        /* Per process profiling */
       @@ -19,5 +20,25 @@ struct Tos {
                ulong        clock;
                /* top of stack is here */
        };
       +#else
       +
       +struct Tos {
       +        struct                        /* Per process profiling */
       +        {
       +                uint32_t pp;        /* known to be 0(ptr) */
       +                uint32_t next;        /* known to be 4(ptr) */
       +                uint32_t last;
       +                uint32_t first;
       +                uint32_t        pid;
       +                uint32_t        what;
       +        } prof;
       +        uvlong        cyclefreq;        /* cycle clock frequency if there is one, 0 otherwise */
       +        vlong        kcycles;        /* cycles spent in kernel */
       +        vlong        pcycles;        /* cycles spent in process (kernel + user) */
       +        uint32_t        pid;                /* might as well put the pid here */
       +        uint32_t        clock;
       +        /* top of stack is here */
       +};
       +#endif
        
        extern Tos *_tos;
 (DIR) diff --git a/src/9vx/a/unthwack.c b/src/9vx/a/unthwack.c
       @@ -171,8 +171,7 @@ unthwack(Unthwack *ut, uchar *dst, int ndst, uchar *src, int nsrc, ulong seq)
                }
                eblocks = b;
                if(cseq != seq){
       -                print("unthwack: blocks dropped: seq=%ld cseq=%ld %d cmask=%#lx %#x\n",
       -                        seq, cseq, src[0], cmask, src[1]);
       +                print("blocks dropped: seq=%ld cseq=%ld %d cmask=%#lx %#x\n", seq, cseq, src[0], cmask, src[1]);
                        return -2;
                }