remove _xinc and _ainc from the /sys/src/9 kernels. Reference: /n/atom/patch/applied/noxinc9 Date: Fri Jun 6 19:08:40 CES 2014 Signed-off-by: quanstro@quanstro.net --- /sys/src/9/alphapc/l.s Fri Jun 6 19:08:21 2014 +++ /sys/src/9/alphapc/l.s Fri Jun 6 19:08:22 2014 @@ -174,25 +174,6 @@ tas2: RET -TEXT _xdec(SB), $-8 - MOVQ R0, R1 /* p */ -dec1: - MOVLL (R1), R0 /* *p */ - SUBL $1, R0 - MOVQ R0, R2 - MOVLC R2, (R1) /* --(*p) */ - BEQ R2, dec1 /* write failed, retry */ - RET - -TEXT _xinc(SB), $-8 - MOVQ R0, R1 /* p */ -inc1: - MOVLL (R1), R0 /* *p */ - ADDL $1, R0 - MOVLC R0, (R1) /* (*p)++ */ - BEQ R0, inc1 /* write failed, retry */ - RET - TEXT cmpswap(SB), $-8 MOVQ R0, R1 /* p */ MOVL old+4(FP), R2 --- /sys/src/9/rb/l.s Fri Jun 6 19:08:22 2014 +++ /sys/src/9/rb/l.s Fri Jun 6 19:08:22 2014 @@ -836,35 +836,6 @@ NOP RETURN -TEXT _xinc(SB), $0 - MOVW R1, R2 /* address of counter */ -loop: - MOVW $1, R3 - LL(2, 1) - NOP - ADDU R1, R3 - MOVW R3, R1 /* return new value */ - SC(2, 3) - NOP - BEQ R3, loop - NOP - RETURN - -TEXT _xdec(SB), $0 - SYNC - MOVW R1, R2 /* address of counter */ -loop1: - MOVW $-1, R3 - LL(2, 1) - NOP - ADDU R1, R3 - MOVW R3, R1 /* return new value */ - SC(2, 3) - NOP - BEQ R3, loop1 - NOP - RETURN - /* used by the semaphore implementation */ TEXT cmpswap(SB), $0 MOVW R1, R2 /* address of key */ --- /sys/src/9/pcpae/l.s Fri Jun 6 19:08:22 2014 +++ /sys/src/9/pcpae/l.s Fri Jun 6 19:08:22 2014 @@ -631,25 +631,6 @@ XCHGL AX, (BX) /* lock->key */ RET -TEXT _xinc(SB), 1, $0 /* void _xinc(long*); */ - MOVL l+0(FP), AX - LOCK; INCL 0(AX) - RET - -TEXT _xdec(SB), 1, $0 /* long _xdec(long*); */ - MOVL l+0(FP), BX - XORL AX, AX - LOCK; DECL 0(BX) - JLT _xdeclt - JGT _xdecgt - RET -_xdecgt: - INCL AX - RET -_xdeclt: - DECL AX - RET - TEXT mb586(SB), 1, $0 XORL AX, AX CPUID --- /sys/src/9/pcpae/sdodin.c Fri Jun 6 19:08:22 2014 +++ /sys/src/9/pcpae/sdodin.c Fri Jun 6 19:08:22 2014 @@ -881,9 +881,9 @@ n = cmd | Ditor | i*Dsatareg | m*Dphyno | i*Dcslot; // print("cqwp\t%.8ux : n %ux : d%d; \n", c->cq[0], n, i); /* - * xinc doesn't return the previous value and i can't + * ainc doesn't return the previous value and i can't * figure out how to do this without a lock - * s = _xinc(&c->dqwp); + * s = ainc(&c->dqwp); */ d->cmd->cflag = Active; ilock(c); --- /sys/src/9/omap/arch.c Fri Jun 6 19:08:22 2014 +++ /sys/src/9/omap/arch.c Fri Jun 6 19:08:22 2014 @@ -165,27 +165,6 @@ * make sure that we don't drag in the C library versions */ -long -_xdec(long *p) -{ - int s, v; - - s = splhi(); - v = --*p; - splx(s); - return v; -} - -void -_xinc(long *p) -{ - int s; - - s = splhi(); - ++*p; - splx(s); -} - int ainc(int *p) { --- /sys/src/9/omap/fns.h Fri Jun 6 19:08:22 2014 +++ /sys/src/9/omap/fns.h Fri Jun 6 19:08:22 2014 @@ -146,14 +146,11 @@ * PCI stuff. */ -#define cas(a, ov, nv) cas32(a, ov, nv) int cas32(void*, u32int, u32int); int tas32(void*); -#define CASU(p, e, n) cas32((p), (u32int)(e), (u32int)(n)) -#define CASV(p, e, n) cas32((p), (u32int)(e), (u32int)(n)) -#define CASW(addr, exp, new) cas32((addr), (exp), (new)) -#define TAS(addr) tas32(addr) +#define cas(p, e, n) cas32((p), (u32int)(e), (u32int)(n)) +#define tas(addr) tas32(addr) extern void forkret(void); extern int userureg(Ureg*); --- /sys/src/9/omap/l.s Fri Jun 6 19:08:22 2014 +++ /sys/src/9/omap/l.s Fri Jun 6 19:08:22 2014 @@ -534,8 +534,7 @@ EOR $(PsrDirq), R0 RET -TEXT tas(SB), $-4 -TEXT _tas(SB), $-4 +TEXT tas32(SB), $-4 MOVW R0,R1 MOVW $1,R0 SWPW R0,(R1) /* fix: deprecated in armv7 */ --- /sys/src/9/mtx/l.s Fri Jun 6 19:08:22 2014 +++ /sys/src/9/mtx/l.s Fri Jun 6 19:08:22 2014 @@ -281,26 +281,6 @@ ISYNC RETURN -TEXT _xinc(SB),$0 /* void _xinc(long *); */ - MOVW R3, R4 -xincloop: - DCBF (R4) /* fix for 603x bug */ - LWAR (R4), R3 - ADD $1, R3 - STWCCC R3, (R4) - BNE xincloop - RETURN - -TEXT _xdec(SB),$0 /* long _xdec(long *); */ - MOVW R3, R4 -xdecloop: - DCBF (R4) /* fix for 603x bug */ - LWAR (R4), R3 - ADD $-1, R3 - STWCCC R3, (R4) - BNE xdecloop - RETURN - TEXT cmpswap(SB),$0 /* int cmpswap(long*, long, long) */ MOVW R3, R4 /* addr */ MOVW old+4(FP), R5 --- /sys/src/9/kw/arch.c Fri Jun 6 19:08:22 2014 +++ /sys/src/9/kw/arch.c Fri Jun 6 19:08:22 2014 @@ -53,6 +53,7 @@ tos->pcycles = up->pcycles; tos->cyclefreq = Frequency; tos->pid = up->pid; + tos->machno = m->machno; /* make visible immediately to user proc */ cachedwbinvse(tos, sizeof *tos); @@ -163,27 +164,6 @@ * atomic ops * make sure that we don't drag in the C library versions */ - -long -_xdec(long *p) -{ - int s, v; - - s = splhi(); - v = --*p; - splx(s); - return v; -} - -void -_xinc(long *p) -{ - int s; - - s = splhi(); - ++*p; - splx(s); -} int ainc(int *p) --- /sys/src/9/kw/fns.h Fri Jun 6 19:08:22 2014 +++ /sys/src/9/kw/fns.h Fri Jun 6 19:08:22 2014 @@ -158,10 +158,8 @@ int cas32(void*, u32int, u32int); int tas32(void*); -#define CASU(p, e, n) cas32((p), (u32int)(e), (u32int)(n)) -#define CASV(p, e, n) cas32((p), (u32int)(e), (u32int)(n)) -#define CASW(addr, exp, new) cas32((addr), (exp), (new)) -#define TAS(addr) tas32(addr) +#define cas(p, e, n) cas32((p), (u32int)(e), (u32int)(n)) +#define tas(addr) tas32(addr) void forkret(void); int userureg(Ureg*); --- /sys/src/9/kw/l.s Fri Jun 6 19:08:22 2014 +++ /sys/src/9/kw/l.s Fri Jun 6 19:08:22 2014 @@ -713,8 +713,7 @@ // MOVW R1, CPSR // RET -TEXT tas(SB), $-4 -TEXT _tas(SB), $-4 +TEXT tas32(SB), $-4 MOVW R0,R1 MOVW $1,R0 SWPW R0,(R1) /* fix: deprecated in armv7 */ --- /sys/src/9/kw/ether1116.c Fri Jun 6 19:08:22 2014 +++ /sys/src/9/kw/ether1116.c Fri Jun 6 19:08:22 2014 @@ -492,7 +492,7 @@ rxfreeb(Block *b) { // /* freeb(b) will have previously decremented b->ref to 0; raise to 1 */ -// _xinc(&b->ref); +// ainc(&b->ref); b->wp = b->rp = (uchar*)((uintptr)(b->lim - Rxblklen) & ~(Bufalign - 1)); assert(((uintptr)b->rp & (Bufalign - 1)) == 0); --- /sys/src/9/kw/etherkw.c Fri Jun 6 19:08:22 2014 +++ /sys/src/9/kw/etherkw.c Fri Jun 6 19:08:22 2014 @@ -480,7 +480,7 @@ rxfreeb(Block *b) { /* freeb(b) will have previously decremented b->ref to 0; raise to 1 */ -// _xinc(&b->ref); +// ainc(&b->ref); //iprint("fr %ld ", b->ref); b->wp = b->rp = (uchar*)((uintptr)(b->lim - Rxblklen) & ~(Bufalign - 1)); --- /sys/src/9/bitsy/main.c Fri Jun 6 19:08:22 2014 +++ /sys/src/9/bitsy/main.c Fri Jun 6 19:08:22 2014 @@ -527,7 +527,7 @@ } long -_xdec(long *p) +adec(long *p) { int s; long v; @@ -539,7 +539,7 @@ } void -_xinc(long *p) +ainc(long *p) { int s; --- /sys/src/9/port/devtrace.c Fri Jun 6 19:08:22 2014 +++ /sys/src/9/port/devtrace.c Fri Jun 6 19:08:22 2014 @@ -229,7 +229,7 @@ { Tracelog *t; -// _xinc(&traceinhits); +// ainc(&traceinhits); ilock(&traceinhitslk); traceinhits++; iunlock(&traceinhitslk); @@ -257,7 +257,7 @@ { Tracelog *t; -// _xinc(&traceouthits); +// ainc(&traceouthits); ilock(&traceouthitslk); traceouthits++; iunlock(&traceouthitslk); --- /sys/src/9/ppc/l.s Fri Jun 6 19:08:22 2014 +++ /sys/src/9/ppc/l.s Fri Jun 6 19:08:22 2014 @@ -361,24 +361,24 @@ SYNC RETURN -TEXT _xinc(SB), $0 /* void _xinc(long *); */ +TEXT ainc(SB), $0 /* void ainc(int *); */ MOVW R3, R4 -xincloop: +aincloop: DCBF (R4) /* fix for 603x bug */ LWAR (R4), R3 ADD $1, R3 STWCCC R3, (R4) - BNE xincloop + BNE aincloop RETURN -TEXT _xdec(SB), $0 /* long _xdec(long *); */ +TEXT adec(SB), $0 /* int adec(int *); */ MOVW R3, R4 -xdecloop: +adecloop: DCBF (R4) /* fix for 603x bug */ LWAR (R4), R3 ADD $-1, R3 STWCCC R3, (R4) - BNE xdecloop + BNE adecloop RETURN TEXT cmpswap(SB),$0 /* int cmpswap(long*, long, long) */ --- /sys/src/9/omap/ucallocb.c Thu Jan 1 00:00:00 1970 +++ /sys/src/9/omap/ucallocb.c Fri Jun 6 19:08:22 2014 @@ -0,0 +1,152 @@ +/* + * allocate Blocks from uncached memory + */ +#include "u.h" +#include "../port/lib.h" +#include "mem.h" +#include "dat.h" +#include "fns.h" +#include "error.h" + +enum +{ + Hdrspc = 64, /* leave room for high-level headers */ + Bdead = 0x51494F42, /* "QIOB" */ +}; + +struct +{ + Lock; + ulong bytes; +} ucialloc; + +static Block* +_ucallocb(int size) +{ + Block *b; + ulong addr; + + if((b = ucalloc(sizeof(Block)+size+Hdrspc)) == nil) + return nil; + + b->next = nil; + b->list = nil; + b->free = 0; + b->flag = 0; +// b->ref = 0; +// ainc(&b->ref); + + /* align start of data portion by rounding up */ + addr = (ulong)b; + addr = ROUND(addr + sizeof(Block), BLOCKALIGN); + b->base = (uchar*)addr; + + /* align end of data portion by rounding down */ + b->lim = ((uchar*)b) + msize(b); + addr = (ulong)(b->lim); + addr = addr & ~(BLOCKALIGN-1); + b->lim = (uchar*)addr; + + /* leave sluff at beginning for added headers */ + b->rp = b->lim - ROUND(size, BLOCKALIGN); + if(b->rp < b->base) + panic("_ucallocb"); + b->wp = b->rp; + + return b; +} + +Block* +ucallocb(int size) +{ + Block *b; + + /* + * Check in a process and wait until successful. + * Can still error out of here, though. + */ + if(up == nil) + panic("ucallocb without up: %#p", getcallerpc(&size)); + if((b = _ucallocb(size)) == nil) + panic("ucallocb: no memory for %d bytes", size); + setmalloctag(b, getcallerpc(&size)); + + return b; +} + +Block* +uciallocb(int size) +{ + Block *b; + static int m1, m2, mp; + + if(0 && ucialloc.bytes > conf.ialloc){ + if((m1++%10000)==0){ + if(mp++ > 1000){ + active.exiting = 1; + exit(0); + } + iprint("uciallocb: limited %lud/%ud\n", + ucialloc.bytes, conf.ialloc); + } + return nil; + } + + if((b = _ucallocb(size)) == nil){ + if(0 && (m2++%10000)==0){ + if(mp++ > 1000){ + active.exiting = 1; + exit(0); + } + iprint("uciallocb: no memory %lud/%ud\n", + ucialloc.bytes, conf.ialloc); + } + return nil; + } + setmalloctag(b, getcallerpc(&size)); + b->flag = BINTR; + + ilock(&ucialloc); + ucialloc.bytes += b->lim - b->base; + iunlock(&ucialloc); + + return b; +} + +void +ucfreeb(Block *b) +{ + void *dead = (void*)Bdead; +// long ref; + + if(b == nil /*|| (ref = _xdec(&b->ref)) > 0*/) + return; + +// if(ref < 0){ +// dumpstack(); +// panic("ucfreeb: 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. + */ + if(b->free) { + b->free(b); + return; + } + if(b->flag & BINTR) { + ilock(&ucialloc); + ucialloc.bytes -= b->lim - b->base; + iunlock(&ucialloc); + } + + /* poison the block in case someone is still holding onto it */ + b->next = dead; + b->rp = dead; + b->wp = dead; + b->lim = dead; + b->base = dead; + + ucfree(b); +} --- /sys/src/9/pcpae/sdodin.c Fri Jun 6 19:08:22 2014 +++ /sys/src/9/pcpae/sdodin.c Fri Jun 6 19:08:22 2014 @@ -881,9 +881,9 @@ n = cmd | Ditor | i*Dsatareg | m*Dphyno | i*Dcslot; // print("cqwp\t%.8ux : n %ux : d%d; \n", c->cq[0], n, i); /* - * xinc doesn't return the previous value and i can't + * ainc doesn't return the previous value and i can't * figure out how to do this without a lock - * s = _xinc(&c->dqwp); + * s = ainc(&c->dqwp); */ d->cmd->cflag = Active; ilock(c);