--- /cfg/pxe/example-pi Thu Jan 1 01:00:00 1970 +++ /cfg/pxe/example-pi Fri Mar 22 20:38:09 2013 @@ -0,0 +1,7 @@ +# example raspberry pi +vgasize=1600x1200x16 +monitor=vesa +# console=0 b115200 +nobootprompt=tcp +readparts=1 +### --- /sys/man/8/booting Fri Mar 22 04:03:29 2013 +++ /sys/man/8/booting Fri Mar 22 20:57:50 2013 @@ -241,24 +241,24 @@ .EE .PP For Raspberry Pis, -type this after -.LR "setenv bootcmd" : -.IP -.EX -\&'usb start; dhcp 8000; tftp 100 %C; go 8000' -.EE +.I gunzip +the +.B pi.uboot.sd.img.gz +named below onto an SD card and insert that into your Pi. .PP Thereafter, the boards will automatically boot via BOOTP and TFTP when reset. . +.SH FILES +.B /n/sources/extra/pi.uboot.sd.img.gz +is a compressed bootable SD card image for Raspberry Pi, uses PXE booting. +.SH SOURCE +.B /sys/src/boot +.br +.B /sys/src/9/pcboot .SH "SEE ALSO" .IR ndb (6), .IR 9boot (8), .IR boot (8), .IR init (8), .IR plan9.ini (8) -.SH SOURCE -Sources for the various boot programs are under -.B /sys/src/boot -and -.BR /sys/src/9/pcboot . --- /sys/src/9/bcm/fpi.c Fri Jul 20 18:09:17 2012 +++ /sys/src/9/bcm/fpi.c Thu Jan 1 01:00:00 1970 @@ -1 +0,0 @@ -#include "../omap/fpi.c" --- /sys/src/9/bcm/fpi.h Fri Jul 20 18:06:36 2012 +++ /sys/src/9/bcm/fpi.h Thu Jan 1 01:00:00 1970 @@ -1 +0,0 @@ -#include "../omap/fpi.h" --- /sys/src/9/bcm/fpiarm.c Tue Jan 8 15:52:43 2013 +++ /sys/src/9/bcm/fpiarm.c Mon Mar 25 21:29:08 2013 @@ -13,7 +13,7 @@ #include "ureg.h" #include "arm.h" -#include "fpi.h" +#include "../port/fpi.h" #define ARM7500 /* emulate old pre-VFP opcodes */ --- /sys/src/9/bcm/fpimem.c Fri Jul 20 18:11:22 2012 +++ /sys/src/9/bcm/fpimem.c Thu Jan 1 01:00:00 1970 @@ -1 +0,0 @@ -#include "../omap/fpimem.c" --- /sys/src/9/bcm/mkfile Wed Feb 13 21:58:32 2013 +++ /sys/src/9/bcm/mkfile Tue Mar 26 04:38:21 2013 @@ -106,7 +106,7 @@ archbcm.$O devether.$0: etherif.h ../port/netif.h archbcm.$O: ../port/flashif.h -fpi.$O fpiarm.$O fpimem.$O: fpi.h +fpi.$O fpiarm.$O fpimem.$O: ../port/fpi.h l.$O lexception.$O lproc.$O mmu.$O: arm.s mem.h main.$O: errstr.h init.h reboot.h devmouse.$O mouse.$O screen.$O: screen.h --- /sys/src/9/bcm/random.c Fri Jul 20 18:23:36 2012 +++ /sys/src/9/bcm/random.c Thu Jan 1 01:00:00 1970 @@ -1 +0,0 @@ -#include "../omap/random.c" --- /sys/src/9/bcm/trap.c Fri Jan 25 23:43:37 2013 +++ /sys/src/9/bcm/trap.c Tue Mar 26 21:33:31 2013 @@ -18,6 +18,8 @@ typedef struct Vctl Vctl; enum { + Debug = 0, + Nvec = 8, /* # of vectors at start of lexception.s */ Fiqenable = 1<<7, }; @@ -194,6 +196,26 @@ return s; } +/* this is quite helpful during mmu and cache debugging */ +static void +ckfaultstuck(uintptr va) +{ + static int cnt, lastpid; + static uintptr lastva; + + if (va == lastva && up->pid == lastpid) { + ++cnt; + if (cnt >= 2) + /* fault() isn't fixing the underlying cause */ + panic("fault: %d consecutive faults for va %#p", + cnt+1, va); + } else { + cnt = 0; + lastva = va; + lastpid = up->pid; + } +} + /* * called by trap to handle access faults */ @@ -202,8 +224,6 @@ { int n, insyscall; char buf[ERRMAX]; - static int cnt, lastpid; - static ulong lastva; if(up == nil) { dumpregs(ureg); @@ -211,18 +231,8 @@ } insyscall = up->insyscall; up->insyscall = 1; - /* this is quite helpful during mmu and cache debugging */ - if(va == lastva && up->pid == lastpid) { - ++cnt; - if (cnt >= 2) - /* fault() isn't fixing the underlying cause */ - panic("fault: %d consecutive faults for va %#lux", - cnt+1, va); - } else { - cnt = 0; - lastva = va; - lastpid = up->pid; - } + if (Debug) + ckfaultstuck(va); n = fault(va, read); if(n < 0){ --- /sys/src/9/kw/fpi.c Wed Dec 19 16:36:51 2007 +++ /sys/src/9/kw/fpi.c Thu Jan 1 01:00:00 1970 @@ -1,300 +0,0 @@ -/* - * Floating Point Interpreter. - * shamelessly stolen from an original by ark. - */ -#include "fpi.h" - -void -fpiround(Internal *i) -{ - unsigned long guard; - - guard = i->l & GuardMask; - i->l &= ~GuardMask; - if(guard > (LsBit>>1) || (guard == (LsBit>>1) && (i->l & LsBit))){ - i->l += LsBit; - if(i->l & CarryBit){ - i->l &= ~CarryBit; - i->h++; - if(i->h & CarryBit){ - if (i->h & 0x01) - i->l |= CarryBit; - i->l >>= 1; - i->h >>= 1; - i->e++; - } - } - } -} - -static void -matchexponents(Internal *x, Internal *y) -{ - int count; - - count = y->e - x->e; - x->e = y->e; - if(count >= 2*FractBits){ - x->l = x->l || x->h; - x->h = 0; - return; - } - if(count >= FractBits){ - count -= FractBits; - x->l = x->h|(x->l != 0); - x->h = 0; - } - while(count > 0){ - count--; - if(x->h & 0x01) - x->l |= CarryBit; - if(x->l & 0x01) - x->l |= 2; - x->l >>= 1; - x->h >>= 1; - } -} - -static void -shift(Internal *i) -{ - i->e--; - i->h <<= 1; - i->l <<= 1; - if(i->l & CarryBit){ - i->l &= ~CarryBit; - i->h |= 0x01; - } -} - -static void -normalise(Internal *i) -{ - while((i->h & HiddenBit) == 0) - shift(i); -} - -static void -renormalise(Internal *i) -{ - if(i->e < -2 * FractBits) - i->e = -2 * FractBits; - while(i->e < 1){ - i->e++; - if(i->h & 0x01) - i->l |= CarryBit; - i->h >>= 1; - i->l = (i->l>>1)|(i->l & 0x01); - } - if(i->e >= ExpInfinity) - SetInfinity(i); -} - -void -fpinormalise(Internal *x) -{ - if(!IsWeird(x) && !IsZero(x)) - normalise(x); -} - -void -fpiadd(Internal *x, Internal *y, Internal *i) -{ - Internal *t; - - i->s = x->s; - if(IsWeird(x) || IsWeird(y)){ - if(IsNaN(x) || IsNaN(y)) - SetQNaN(i); - else - SetInfinity(i); - return; - } - if(x->e > y->e){ - t = x; - x = y; - y = t; - } - matchexponents(x, y); - i->e = x->e; - i->h = x->h + y->h; - i->l = x->l + y->l; - if(i->l & CarryBit){ - i->h++; - i->l &= ~CarryBit; - } - if(i->h & (HiddenBit<<1)){ - if(i->h & 0x01) - i->l |= CarryBit; - i->l = (i->l>>1)|(i->l & 0x01); - i->h >>= 1; - i->e++; - } - if(IsWeird(i)) - SetInfinity(i); -} - -void -fpisub(Internal *x, Internal *y, Internal *i) -{ - Internal *t; - - if(y->e < x->e - || (y->e == x->e && (y->h < x->h || (y->h == x->h && y->l < x->l)))){ - t = x; - x = y; - y = t; - } - i->s = y->s; - if(IsNaN(y)){ - SetQNaN(i); - return; - } - if(IsInfinity(y)){ - if(IsInfinity(x)) - SetQNaN(i); - else - SetInfinity(i); - return; - } - matchexponents(x, y); - i->e = y->e; - i->h = y->h - x->h; - i->l = y->l - x->l; - if(i->l < 0){ - i->l += CarryBit; - i->h--; - } - if(i->h == 0 && i->l == 0) - SetZero(i); - else while(i->e > 1 && (i->h & HiddenBit) == 0) - shift(i); -} - -#define CHUNK (FractBits/2) -#define CMASK ((1<>CHUNK) & CMASK) -#define LO(x) ((short)(x) & CMASK) -#define SPILL(x) ((x)>>CHUNK) -#define M(x, y) ((long)a[x]*(long)b[y]) -#define C(h, l) (((long)((h) & CMASK)<s = x->s^y->s; - if(IsWeird(x) || IsWeird(y)){ - if(IsNaN(x) || IsNaN(y) || IsZero(x) || IsZero(y)) - SetQNaN(i); - else - SetInfinity(i); - return; - } - else if(IsZero(x) || IsZero(y)){ - SetZero(i); - return; - } - normalise(x); - normalise(y); - i->e = x->e + y->e - (ExpBias - 1); - - a[0] = HI(x->h); b[0] = HI(y->h); - a[1] = LO(x->h); b[1] = LO(y->h); - a[2] = HI(x->l); b[2] = HI(y->l); - a[3] = LO(x->l); b[3] = LO(y->l); - - c[6] = M(3, 3); - c[5] = M(2, 3) + M(3, 2) + SPILL(c[6]); - c[4] = M(1, 3) + M(2, 2) + M(3, 1) + SPILL(c[5]); - c[3] = M(0, 3) + M(1, 2) + M(2, 1) + M(3, 0) + SPILL(c[4]); - c[2] = M(0, 2) + M(1, 1) + M(2, 0) + SPILL(c[3]); - c[1] = M(0, 1) + M(1, 0) + SPILL(c[2]); - c[0] = M(0, 0) + SPILL(c[1]); - - f[0] = c[0]; - f[1] = C(c[1], c[2]); - f[2] = C(c[3], c[4]); - f[3] = C(c[5], c[6]); - - if((f[0] & HiddenBit) == 0){ - f[0] <<= 1; - f[1] <<= 1; - f[2] <<= 1; - f[3] <<= 1; - if(f[1] & CarryBit){ - f[0] |= 1; - f[1] &= ~CarryBit; - } - if(f[2] & CarryBit){ - f[1] |= 1; - f[2] &= ~CarryBit; - } - if(f[3] & CarryBit){ - f[2] |= 1; - f[3] &= ~CarryBit; - } - i->e--; - } - i->h = f[0]; - i->l = f[1]; - if(f[2] || f[3]) - i->l |= 1; - renormalise(i); -} - -void -fpidiv(Internal *x, Internal *y, Internal *i) -{ - i->s = x->s^y->s; - if(IsNaN(x) || IsNaN(y) - || (IsInfinity(x) && IsInfinity(y)) || (IsZero(x) && IsZero(y))){ - SetQNaN(i); - return; - } - else if(IsZero(x) || IsInfinity(y)){ - SetInfinity(i); - return; - } - else if(IsInfinity(x) || IsZero(y)){ - SetZero(i); - return; - } - normalise(x); - normalise(y); - i->h = 0; - i->l = 0; - i->e = y->e - x->e + (ExpBias + 2*FractBits - 1); - do{ - if(y->h > x->h || (y->h == x->h && y->l >= x->l)){ - i->l |= 0x01; - y->h -= x->h; - y->l -= x->l; - if(y->l < 0){ - y->l += CarryBit; - y->h--; - } - } - shift(y); - shift(i); - }while ((i->h & HiddenBit) == 0); - if(y->h || y->l) - i->l |= 0x01; - renormalise(i); -} - -int -fpicmp(Internal *x, Internal *y) -{ - if(IsNaN(x) && IsNaN(y)) - return 0; - if(IsInfinity(x) && IsInfinity(y)) - return y->s - x->s; - if(x->e == y->e && x->h == y->h && x->l == y->l) - return y->s - x->s; - if(x->e < y->e - || (x->e == y->e && (x->h < y->h || (x->h == y->h && x->l < y->l)))) - return y->s ? 1: -1; - return x->s ? -1: 1; -} --- /sys/src/9/kw/fpi.h Wed Dec 19 16:36:51 2007 +++ /sys/src/9/kw/fpi.h Thu Jan 1 01:00:00 1970 @@ -1,61 +0,0 @@ -typedef long Word; -typedef unsigned long Single; -typedef struct { - unsigned long l; - unsigned long h; -} Double; - -enum { - FractBits = 28, - CarryBit = 0x10000000, - HiddenBit = 0x08000000, - MsBit = HiddenBit, - NGuardBits = 3, - GuardMask = 0x07, - LsBit = (1<e >= ExpInfinity) -#define IsInfinity(n) (IsWeird(n) && (n)->h == HiddenBit && (n)->l == 0) -#define SetInfinity(n) ((n)->e = ExpInfinity, (n)->h = HiddenBit, (n)->l = 0) -#define IsNaN(n) (IsWeird(n) && (((n)->h & ~HiddenBit) || (n)->l)) -#define SetQNaN(n) ((n)->s = 0, (n)->e = ExpInfinity, \ - (n)->h = HiddenBit|(LsBit<<1), (n)->l = 0) -#define IsZero(n) ((n)->e == 1 && (n)->h == 0 && (n)->l == 0) -#define SetZero(n) ((n)->e = 1, (n)->h = 0, (n)->l = 0) - -/* - * fpi.c - */ -extern void fpiround(Internal *); -extern void fpiadd(Internal *, Internal *, Internal *); -extern void fpisub(Internal *, Internal *, Internal *); -extern void fpimul(Internal *, Internal *, Internal *); -extern void fpidiv(Internal *, Internal *, Internal *); -extern int fpicmp(Internal *, Internal *); -extern void fpinormalise(Internal*); - -/* - * fpimem.c - */ -extern void fpis2i(Internal *, void *); -extern void fpid2i(Internal *, void *); -extern void fpiw2i(Internal *, void *); -extern void fpii2s(void *, Internal *); -extern void fpii2d(void *, Internal *); -extern void fpii2w(Word *, Internal *); --- /sys/src/9/kw/fpiarm.c Fri Jul 6 23:49:04 2012 +++ /sys/src/9/kw/fpiarm.c Mon Mar 25 21:29:04 2013 @@ -13,7 +13,7 @@ #include "ureg.h" #include "arm.h" -#include "fpi.h" +#include "../port/fpi.h" /* undef this if correct kernel r13 isn't in Ureg; * check calculation in fpiarm below --- /sys/src/9/kw/fpimem.c Wed Dec 19 16:36:51 2007 +++ /sys/src/9/kw/fpimem.c Thu Jan 1 01:00:00 1970 @@ -1,136 +0,0 @@ -#include "fpi.h" - -/* - * the following routines depend on memory format, not the machine - */ - -void -fpis2i(Internal *i, void *v) -{ - Single *s = v; - - i->s = (*s & 0x80000000) ? 1: 0; - if((*s & ~0x80000000) == 0){ - SetZero(i); - return; - } - i->e = ((*s>>23) & 0x00FF) - SingleExpBias + ExpBias; - i->h = (*s & 0x007FFFFF)<<(1+NGuardBits); - i->l = 0; - if(i->e) - i->h |= HiddenBit; - else - i->e++; -} - -void -fpid2i(Internal *i, void *v) -{ - Double *d = v; - - i->s = (d->h & 0x80000000) ? 1: 0; - i->e = (d->h>>20) & 0x07FF; - i->h = ((d->h & 0x000FFFFF)<<(4+NGuardBits))|((d->l>>25) & 0x7F); - i->l = (d->l & 0x01FFFFFF)<e) - i->h |= HiddenBit; - else - i->e++; -} - -void -fpiw2i(Internal *i, void *v) -{ - Word w, word = *(Word*)v; - short e; - - if(word < 0){ - i->s = 1; - word = -word; - } - else - i->s = 0; - if(word == 0){ - SetZero(i); - return; - } - if(word > 0){ - for (e = 0, w = word; w; w >>= 1, e++) - ; - } else - e = 32; - if(e > FractBits){ - i->h = word>>(e - FractBits); - i->l = (word & ((1<<(e - FractBits)) - 1))<<(2*FractBits - e); - } - else { - i->h = word<<(FractBits - e); - i->l = 0; - } - i->e = (e - 1) + ExpBias; -} - -void -fpii2s(void *v, Internal *i) -{ - short e; - Single *s = (Single*)v; - - fpiround(i); - if(i->h & HiddenBit) - i->h &= ~HiddenBit; - else - i->e--; - *s = i->s ? 0x80000000: 0; - e = i->e; - if(e < ExpBias){ - if(e <= (ExpBias - SingleExpBias)) - return; - e = SingleExpBias - (ExpBias - e); - } - else if(e >= (ExpBias + (SingleExpMax-SingleExpBias))){ - *s |= SingleExpMax<<23; - return; - } - else - e = SingleExpBias + (e - ExpBias); - *s |= (e<<23)|(i->h>>(1+NGuardBits)); -} - -void -fpii2d(void *v, Internal *i) -{ - Double *d = (Double*)v; - - fpiround(i); - if(i->h & HiddenBit) - i->h &= ~HiddenBit; - else - i->e--; - i->l = ((i->h & GuardMask)<<25)|(i->l>>NGuardBits); - i->h >>= NGuardBits; - d->h = i->s ? 0x80000000: 0; - d->h |= (i->e<<20)|((i->h & 0x00FFFFFF)>>4); - d->l = (i->h<<28)|i->l; -} - -void -fpii2w(Word *word, Internal *i) -{ - Word w; - short e; - - fpiround(i); - e = (i->e - ExpBias) + 1; - if(e <= 0) - w = 0; - else if(e > 31) - w = 0x7FFFFFFF; - else if(e > FractBits) - w = (i->h<<(e - FractBits))|(i->l>>(2*FractBits - e)); - else - w = i->h>>(FractBits-e); - if(i->s) - w = -w; - *word = w; -} --- /sys/src/9/kw/mkfile Wed Feb 13 22:03:09 2013 +++ /sys/src/9/kw/mkfile Tue Mar 26 04:37:22 2013 @@ -128,7 +128,7 @@ archkw.$O devether.$O ether1116.$O ethermii.$O: \ etherif.h ethermii.h ../port/netif.h archkw.$O devflash.$O flashkw.$O: ../port/flashif.h -fpi.$O fpiarm.$O fpimem.$O: fpi.h +fpi.$O fpiarm.$O fpimem.$O: ../port/fpi.h l.$O lexception.$O lproc.$O mmu.$O: arm.s arm.h mem.h main.$O: errstr.h init.h reboot.h mouse.$O: screen.h --- /sys/src/9/kw/random.c Sun Nov 8 07:31:28 2009 +++ /sys/src/9/kw/random.c Thu Jan 1 01:00:00 1970 @@ -1,138 +0,0 @@ -#include "u.h" -#include "../port/lib.h" -#include "mem.h" -#include "dat.h" -#include "fns.h" -#include "../port/error.h" - - -struct Rb -{ - QLock; - Rendez producer; - Rendez consumer; - ulong randomcount; - uchar buf[128]; - uchar *ep; - uchar *rp; - uchar *wp; - uchar next; - uchar wakeme; - ushort bits; - ulong randn; -} rb; - -static int -rbnotfull(void*) -{ - int i; - - i = rb.rp - rb.wp; - return i != 1 && i != (1 - sizeof(rb.buf)); -} - -static int -rbnotempty(void*) -{ - return rb.wp != rb.rp; -} - -static void -genrandom(void*) -{ - up->basepri = PriNormal; - up->priority = up->basepri; - - for(;;){ - for(;;) - if(++rb.randomcount > 100000) - break; - if(anyhigher()) - sched(); - if(!rbnotfull(0)) - sleep(&rb.producer, rbnotfull, 0); - } -} - -/* - * produce random bits in a circular buffer - */ -static void -randomclock(void) -{ - if(rb.randomcount == 0 || !rbnotfull(0)) - return; - - rb.bits = (rb.bits<<2) ^ rb.randomcount; - rb.randomcount = 0; - - rb.next++; - if(rb.next != 8/2) - return; - rb.next = 0; - - *rb.wp ^= rb.bits; - if(rb.wp+1 == rb.ep) - rb.wp = rb.buf; - else - rb.wp = rb.wp+1; - - if(rb.wakeme) - wakeup(&rb.consumer); -} - -void -randominit(void) -{ - addclock0link(randomclock, 1000/HZ); - rb.ep = rb.buf + sizeof(rb.buf); - rb.rp = rb.wp = rb.buf; - kproc("genrandom", genrandom, 0); -} - -/* - * consume random bytes from a circular buffer - */ -ulong -randomread(void *xp, ulong n) -{ - uchar *e, *p; - ulong x; - - p = xp; - - if(waserror()){ - qunlock(&rb); - nexterror(); - } - - qlock(&rb); - for(e = p + n; p < e; ){ - if(rb.wp == rb.rp){ - rb.wakeme = 1; - wakeup(&rb.producer); - sleep(&rb.consumer, rbnotempty, 0); - rb.wakeme = 0; - continue; - } - - /* - * beating clocks will be predictable if - * they are synchronized. Use a cheap pseudo - * random number generator to obscure any cycles. - */ - x = rb.randn*1103515245 ^ *rb.rp; - *p++ = rb.randn = x; - - if(rb.rp+1 == rb.ep) - rb.rp = rb.buf; - else - rb.rp = rb.rp+1; - } - qunlock(&rb); - poperror(); - - wakeup(&rb.producer); - - return n; -} --- /sys/src/9/kw/trap.c Mon Mar 26 23:12:04 2012 +++ /sys/src/9/kw/trap.c Tue Mar 26 21:33:31 2013 @@ -13,6 +13,8 @@ #include "arm.h" enum { + Debug = 0, + Ntimevec = 20, /* # of time buckets for each intr */ Nvecs = 256, }; @@ -311,6 +313,26 @@ return s; } +/* this is quite helpful during mmu and cache debugging */ +static void +ckfaultstuck(uintptr va) +{ + static int cnt, lastpid; + static uintptr lastva; + + if (va == lastva && up->pid == lastpid) { + ++cnt; + if (cnt >= 2) + /* fault() isn't fixing the underlying cause */ + panic("fault: %d consecutive faults for va %#p", + cnt+1, va); + } else { + cnt = 0; + lastva = va; + lastpid = up->pid; + } +} + /* * called by trap to handle access faults */ @@ -328,19 +350,8 @@ } insyscall = up->insyscall; up->insyscall = 1; - - /* this is quite helpful during mmu and cache debugging */ - if(va == lastva && up->pid == lastpid) { - ++cnt; - if (cnt >= 2) - /* fault() isn't fixing the underlying cause */ - panic("fault: %d consecutive faults for va %#lux", - cnt+1, va); - } else { - cnt = 0; - lastva = va; - lastpid = up->pid; - } + if (Debug) + ckfaultstuck(va); n = fault(va, read); if(n < 0){ --- /sys/src/9/mtx/random.c Sat Nov 9 04:46:38 2002 +++ /sys/src/9/mtx/random.c Thu Jan 1 01:00:00 1970 @@ -1,138 +0,0 @@ -#include "u.h" -#include "../port/lib.h" -#include "mem.h" -#include "dat.h" -#include "fns.h" -#include "../port/error.h" - - -struct Rb -{ - QLock; - Rendez producer; - Rendez consumer; - ulong randomcount; - uchar buf[1024]; - uchar *ep; - uchar *rp; - uchar *wp; - uchar next; - uchar wakeme; - ushort bits; - ulong randn; -} rb; - -static int -rbnotfull(void*) -{ - int i; - - i = rb.rp - rb.wp; - return i != 1 && i != (1 - sizeof(rb.buf)); -} - -static int -rbnotempty(void*) -{ - return rb.wp != rb.rp; -} - -static void -genrandom(void*) -{ - up->basepri = PriNormal; - up->priority = up->basepri; - - for(;;){ - for(;;) - if(++rb.randomcount > 100000) - break; - if(anyhigher()) - sched(); - if(!rbnotfull(0)) - sleep(&rb.producer, rbnotfull, 0); - } -} - -/* - * produce random bits in a circular buffer - */ -static void -randomclock(void) -{ - if(rb.randomcount == 0 || !rbnotfull(0)) - return; - - rb.bits = (rb.bits<<2) ^ rb.randomcount; - rb.randomcount = 0; - - rb.next++; - if(rb.next != 8/2) - return; - rb.next = 0; - - *rb.wp ^= rb.bits; - if(rb.wp+1 == rb.ep) - rb.wp = rb.buf; - else - rb.wp = rb.wp+1; - - if(rb.wakeme) - wakeup(&rb.consumer); -} - -void -randominit(void) -{ - addclock0link(randomclock, 1000/HZ); - rb.ep = rb.buf + sizeof(rb.buf); - rb.rp = rb.wp = rb.buf; - kproc("genrandom", genrandom, 0); -} - -/* - * consume random bytes from a circular buffer - */ -ulong -randomread(void *xp, ulong n) -{ - uchar *e, *p; - ulong x; - - p = xp; - - if(waserror()){ - qunlock(&rb); - nexterror(); - } - - qlock(&rb); - for(e = p + n; p < e; ){ - if(rb.wp == rb.rp){ - rb.wakeme = 1; - wakeup(&rb.producer); - sleep(&rb.consumer, rbnotempty, 0); - rb.wakeme = 0; - continue; - } - - /* - * beating clocks will be precictable if - * they are synchronized. Use a cheap pseudo - * random number generator to obscure any cycles. - */ - x = rb.randn*1103515245 ^ *rb.rp; - *p++ = rb.randn = x; - - if(rb.rp+1 == rb.ep) - rb.rp = rb.buf; - else - rb.rp = rb.rp+1; - } - qunlock(&rb); - poperror(); - - wakeup(&rb.producer); - - return n; -} --- /sys/src/9/omap/fpi.c Fri Apr 23 06:01:53 2010 +++ /sys/src/9/omap/fpi.c Thu Jan 1 01:00:00 1970 @@ -1,300 +0,0 @@ -/* - * Floating Point Interpreter. - * shamelessly stolen from an original by ark. - */ -#include "fpi.h" - -void -fpiround(Internal *i) -{ - unsigned long guard; - - guard = i->l & GuardMask; - i->l &= ~GuardMask; - if(guard > (LsBit>>1) || (guard == (LsBit>>1) && (i->l & LsBit))){ - i->l += LsBit; - if(i->l & CarryBit){ - i->l &= ~CarryBit; - i->h++; - if(i->h & CarryBit){ - if (i->h & 0x01) - i->l |= CarryBit; - i->l >>= 1; - i->h >>= 1; - i->e++; - } - } - } -} - -static void -matchexponents(Internal *x, Internal *y) -{ - int count; - - count = y->e - x->e; - x->e = y->e; - if(count >= 2*FractBits){ - x->l = x->l || x->h; - x->h = 0; - return; - } - if(count >= FractBits){ - count -= FractBits; - x->l = x->h|(x->l != 0); - x->h = 0; - } - while(count > 0){ - count--; - if(x->h & 0x01) - x->l |= CarryBit; - if(x->l & 0x01) - x->l |= 2; - x->l >>= 1; - x->h >>= 1; - } -} - -static void -shift(Internal *i) -{ - i->e--; - i->h <<= 1; - i->l <<= 1; - if(i->l & CarryBit){ - i->l &= ~CarryBit; - i->h |= 0x01; - } -} - -static void -normalise(Internal *i) -{ - while((i->h & HiddenBit) == 0) - shift(i); -} - -static void -renormalise(Internal *i) -{ - if(i->e < -2 * FractBits) - i->e = -2 * FractBits; - while(i->e < 1){ - i->e++; - if(i->h & 0x01) - i->l |= CarryBit; - i->h >>= 1; - i->l = (i->l>>1)|(i->l & 0x01); - } - if(i->e >= ExpInfinity) - SetInfinity(i); -} - -void -fpinormalise(Internal *x) -{ - if(!IsWeird(x) && !IsZero(x)) - normalise(x); -} - -void -fpiadd(Internal *x, Internal *y, Internal *i) -{ - Internal *t; - - i->s = x->s; - if(IsWeird(x) || IsWeird(y)){ - if(IsNaN(x) || IsNaN(y)) - SetQNaN(i); - else - SetInfinity(i); - return; - } - if(x->e > y->e){ - t = x; - x = y; - y = t; - } - matchexponents(x, y); - i->e = x->e; - i->h = x->h + y->h; - i->l = x->l + y->l; - if(i->l & CarryBit){ - i->h++; - i->l &= ~CarryBit; - } - if(i->h & (HiddenBit<<1)){ - if(i->h & 0x01) - i->l |= CarryBit; - i->l = (i->l>>1)|(i->l & 0x01); - i->h >>= 1; - i->e++; - } - if(IsWeird(i)) - SetInfinity(i); -} - -void -fpisub(Internal *x, Internal *y, Internal *i) -{ - Internal *t; - - if(y->e < x->e - || (y->e == x->e && (y->h < x->h || (y->h == x->h && y->l < x->l)))){ - t = x; - x = y; - y = t; - } - i->s = y->s; - if(IsNaN(y)){ - SetQNaN(i); - return; - } - if(IsInfinity(y)){ - if(IsInfinity(x)) - SetQNaN(i); - else - SetInfinity(i); - return; - } - matchexponents(x, y); - i->e = y->e; - i->h = y->h - x->h; - i->l = y->l - x->l; - if(i->l < 0){ - i->l += CarryBit; - i->h--; - } - if(i->h == 0 && i->l == 0) - SetZero(i); - else while(i->e > 1 && (i->h & HiddenBit) == 0) - shift(i); -} - -#define CHUNK (FractBits/2) -#define CMASK ((1<>CHUNK) & CMASK) -#define LO(x) ((short)(x) & CMASK) -#define SPILL(x) ((x)>>CHUNK) -#define M(x, y) ((long)a[x]*(long)b[y]) -#define C(h, l) (((long)((h) & CMASK)<s = x->s^y->s; - if(IsWeird(x) || IsWeird(y)){ - if(IsNaN(x) || IsNaN(y) || IsZero(x) || IsZero(y)) - SetQNaN(i); - else - SetInfinity(i); - return; - } - else if(IsZero(x) || IsZero(y)){ - SetZero(i); - return; - } - normalise(x); - normalise(y); - i->e = x->e + y->e - (ExpBias - 1); - - a[0] = HI(x->h); b[0] = HI(y->h); - a[1] = LO(x->h); b[1] = LO(y->h); - a[2] = HI(x->l); b[2] = HI(y->l); - a[3] = LO(x->l); b[3] = LO(y->l); - - c[6] = M(3, 3); - c[5] = M(2, 3) + M(3, 2) + SPILL(c[6]); - c[4] = M(1, 3) + M(2, 2) + M(3, 1) + SPILL(c[5]); - c[3] = M(0, 3) + M(1, 2) + M(2, 1) + M(3, 0) + SPILL(c[4]); - c[2] = M(0, 2) + M(1, 1) + M(2, 0) + SPILL(c[3]); - c[1] = M(0, 1) + M(1, 0) + SPILL(c[2]); - c[0] = M(0, 0) + SPILL(c[1]); - - f[0] = c[0]; - f[1] = C(c[1], c[2]); - f[2] = C(c[3], c[4]); - f[3] = C(c[5], c[6]); - - if((f[0] & HiddenBit) == 0){ - f[0] <<= 1; - f[1] <<= 1; - f[2] <<= 1; - f[3] <<= 1; - if(f[1] & CarryBit){ - f[0] |= 1; - f[1] &= ~CarryBit; - } - if(f[2] & CarryBit){ - f[1] |= 1; - f[2] &= ~CarryBit; - } - if(f[3] & CarryBit){ - f[2] |= 1; - f[3] &= ~CarryBit; - } - i->e--; - } - i->h = f[0]; - i->l = f[1]; - if(f[2] || f[3]) - i->l |= 1; - renormalise(i); -} - -void -fpidiv(Internal *x, Internal *y, Internal *i) -{ - i->s = x->s^y->s; - if(IsNaN(x) || IsNaN(y) - || (IsInfinity(x) && IsInfinity(y)) || (IsZero(x) && IsZero(y))){ - SetQNaN(i); - return; - } - else if(IsZero(x) || IsInfinity(y)){ - SetInfinity(i); - return; - } - else if(IsInfinity(x) || IsZero(y)){ - SetZero(i); - return; - } - normalise(x); - normalise(y); - i->h = 0; - i->l = 0; - i->e = y->e - x->e + (ExpBias + 2*FractBits - 1); - do{ - if(y->h > x->h || (y->h == x->h && y->l >= x->l)){ - i->l |= 0x01; - y->h -= x->h; - y->l -= x->l; - if(y->l < 0){ - y->l += CarryBit; - y->h--; - } - } - shift(y); - shift(i); - }while ((i->h & HiddenBit) == 0); - if(y->h || y->l) - i->l |= 0x01; - renormalise(i); -} - -int -fpicmp(Internal *x, Internal *y) -{ - if(IsNaN(x) && IsNaN(y)) - return 0; - if(IsInfinity(x) && IsInfinity(y)) - return y->s - x->s; - if(x->e == y->e && x->h == y->h && x->l == y->l) - return y->s - x->s; - if(x->e < y->e - || (x->e == y->e && (x->h < y->h || (x->h == y->h && x->l < y->l)))) - return y->s ? 1: -1; - return x->s ? -1: 1; -} --- /sys/src/9/omap/fpi.h Fri Apr 23 06:01:53 2010 +++ /sys/src/9/omap/fpi.h Thu Jan 1 01:00:00 1970 @@ -1,61 +0,0 @@ -typedef long Word; -typedef unsigned long Single; -typedef struct { - unsigned long l; - unsigned long h; -} Double; - -enum { - FractBits = 28, - CarryBit = 0x10000000, - HiddenBit = 0x08000000, - MsBit = HiddenBit, - NGuardBits = 3, - GuardMask = 0x07, - LsBit = (1<e >= ExpInfinity) -#define IsInfinity(n) (IsWeird(n) && (n)->h == HiddenBit && (n)->l == 0) -#define SetInfinity(n) ((n)->e = ExpInfinity, (n)->h = HiddenBit, (n)->l = 0) -#define IsNaN(n) (IsWeird(n) && (((n)->h & ~HiddenBit) || (n)->l)) -#define SetQNaN(n) ((n)->s = 0, (n)->e = ExpInfinity, \ - (n)->h = HiddenBit|(LsBit<<1), (n)->l = 0) -#define IsZero(n) ((n)->e == 1 && (n)->h == 0 && (n)->l == 0) -#define SetZero(n) ((n)->e = 1, (n)->h = 0, (n)->l = 0) - -/* - * fpi.c - */ -extern void fpiround(Internal *); -extern void fpiadd(Internal *, Internal *, Internal *); -extern void fpisub(Internal *, Internal *, Internal *); -extern void fpimul(Internal *, Internal *, Internal *); -extern void fpidiv(Internal *, Internal *, Internal *); -extern int fpicmp(Internal *, Internal *); -extern void fpinormalise(Internal*); - -/* - * fpimem.c - */ -extern void fpis2i(Internal *, void *); -extern void fpid2i(Internal *, void *); -extern void fpiw2i(Internal *, void *); -extern void fpii2s(void *, Internal *); -extern void fpii2d(void *, Internal *); -extern void fpii2w(Word *, Internal *); --- /sys/src/9/omap/fpiarm.c Fri Jul 6 23:18:22 2012 +++ /sys/src/9/omap/fpiarm.c Mon Mar 25 21:29:00 2013 @@ -13,7 +13,7 @@ #include "ureg.h" #include "arm.h" -#include "fpi.h" +#include "../port/fpi.h" /* undef this if correct kernel r13 isn't in Ureg; * check calculation in fpiarm below --- /sys/src/9/omap/fpimem.c Fri Apr 23 06:01:53 2010 +++ /sys/src/9/omap/fpimem.c Thu Jan 1 01:00:00 1970 @@ -1,136 +0,0 @@ -#include "fpi.h" - -/* - * the following routines depend on memory format, not the machine - */ - -void -fpis2i(Internal *i, void *v) -{ - Single *s = v; - - i->s = (*s & 0x80000000) ? 1: 0; - if((*s & ~0x80000000) == 0){ - SetZero(i); - return; - } - i->e = ((*s>>23) & 0x00FF) - SingleExpBias + ExpBias; - i->h = (*s & 0x007FFFFF)<<(1+NGuardBits); - i->l = 0; - if(i->e) - i->h |= HiddenBit; - else - i->e++; -} - -void -fpid2i(Internal *i, void *v) -{ - Double *d = v; - - i->s = (d->h & 0x80000000) ? 1: 0; - i->e = (d->h>>20) & 0x07FF; - i->h = ((d->h & 0x000FFFFF)<<(4+NGuardBits))|((d->l>>25) & 0x7F); - i->l = (d->l & 0x01FFFFFF)<e) - i->h |= HiddenBit; - else - i->e++; -} - -void -fpiw2i(Internal *i, void *v) -{ - Word w, word = *(Word*)v; - short e; - - if(word < 0){ - i->s = 1; - word = -word; - } - else - i->s = 0; - if(word == 0){ - SetZero(i); - return; - } - if(word > 0){ - for (e = 0, w = word; w; w >>= 1, e++) - ; - } else - e = 32; - if(e > FractBits){ - i->h = word>>(e - FractBits); - i->l = (word & ((1<<(e - FractBits)) - 1))<<(2*FractBits - e); - } - else { - i->h = word<<(FractBits - e); - i->l = 0; - } - i->e = (e - 1) + ExpBias; -} - -void -fpii2s(void *v, Internal *i) -{ - short e; - Single *s = (Single*)v; - - fpiround(i); - if(i->h & HiddenBit) - i->h &= ~HiddenBit; - else - i->e--; - *s = i->s ? 0x80000000: 0; - e = i->e; - if(e < ExpBias){ - if(e <= (ExpBias - SingleExpBias)) - return; - e = SingleExpBias - (ExpBias - e); - } - else if(e >= (ExpBias + (SingleExpMax-SingleExpBias))){ - *s |= SingleExpMax<<23; - return; - } - else - e = SingleExpBias + (e - ExpBias); - *s |= (e<<23)|(i->h>>(1+NGuardBits)); -} - -void -fpii2d(void *v, Internal *i) -{ - Double *d = (Double*)v; - - fpiround(i); - if(i->h & HiddenBit) - i->h &= ~HiddenBit; - else - i->e--; - i->l = ((i->h & GuardMask)<<25)|(i->l>>NGuardBits); - i->h >>= NGuardBits; - d->h = i->s ? 0x80000000: 0; - d->h |= (i->e<<20)|((i->h & 0x00FFFFFF)>>4); - d->l = (i->h<<28)|i->l; -} - -void -fpii2w(Word *word, Internal *i) -{ - Word w; - short e; - - fpiround(i); - e = (i->e - ExpBias) + 1; - if(e <= 0) - w = 0; - else if(e > 31) - w = 0x7FFFFFFF; - else if(e > FractBits) - w = (i->h<<(e - FractBits))|(i->l>>(2*FractBits - e)); - else - w = i->h>>(FractBits-e); - if(i->s) - w = -w; - *word = w; -} --- /sys/src/9/omap/mkfile Thu Feb 10 23:55:33 2011 +++ /sys/src/9/omap/mkfile Tue Mar 26 04:37:32 2013 @@ -106,7 +106,7 @@ archomap.$O devether.$0 ether9221.$O: etherif.h ../port/netif.h archomap.$O devflash.$O flashbeagle.$O flashigep.$O: ../port/flashif.h ecc.$O flashbeagle.$O flashigep.$O: ../port/nandecc.h io.h -fpi.$O fpiarm.$O fpimem.$O: fpi.h +fpi.$O fpiarm.$O fpimem.$O: ../port/fpi.h l.$O lexception.$O lproc.$O mmu.$O: arm.s arm.h mem.h l.$O rebootcode.$O: cache.v7.s main.$O: errstr.h init.h reboot.h --- /sys/src/9/omap/random.c Fri Apr 23 05:57:40 2010 +++ /sys/src/9/omap/random.c Thu Jan 1 01:00:00 1970 @@ -1,138 +0,0 @@ -#include "u.h" -#include "../port/lib.h" -#include "mem.h" -#include "dat.h" -#include "fns.h" -#include "../port/error.h" - - -struct Rb -{ - QLock; - Rendez producer; - Rendez consumer; - ulong randomcount; - uchar buf[128]; - uchar *ep; - uchar *rp; - uchar *wp; - uchar next; - uchar wakeme; - ushort bits; - ulong randn; -} rb; - -static int -rbnotfull(void*) -{ - int i; - - i = rb.rp - rb.wp; - return i != 1 && i != (1 - sizeof(rb.buf)); -} - -static int -rbnotempty(void*) -{ - return rb.wp != rb.rp; -} - -static void -genrandom(void*) -{ - up->basepri = PriNormal; - up->priority = up->basepri; - - for(;;){ - for(;;) - if(++rb.randomcount > 100000) - break; - if(anyhigher()) - sched(); - if(!rbnotfull(0)) - sleep(&rb.producer, rbnotfull, 0); - } -} - -/* - * produce random bits in a circular buffer - */ -static void -randomclock(void) -{ - if(rb.randomcount == 0 || !rbnotfull(0)) - return; - - rb.bits = (rb.bits<<2) ^ rb.randomcount; - rb.randomcount = 0; - - rb.next++; - if(rb.next != 8/2) - return; - rb.next = 0; - - *rb.wp ^= rb.bits; - if(rb.wp+1 == rb.ep) - rb.wp = rb.buf; - else - rb.wp = rb.wp+1; - - if(rb.wakeme) - wakeup(&rb.consumer); -} - -void -randominit(void) -{ - addclock0link(randomclock, 1000/HZ); - rb.ep = rb.buf + sizeof(rb.buf); - rb.rp = rb.wp = rb.buf; - kproc("genrandom", genrandom, 0); -} - -/* - * consume random bytes from a circular buffer - */ -ulong -randomread(void *xp, ulong n) -{ - uchar *e, *p; - ulong x; - - p = xp; - - if(waserror()){ - qunlock(&rb); - nexterror(); - } - - qlock(&rb); - for(e = p + n; p < e; ){ - if(rb.wp == rb.rp){ - rb.wakeme = 1; - wakeup(&rb.producer); - sleep(&rb.consumer, rbnotempty, 0); - rb.wakeme = 0; - continue; - } - - /* - * beating clocks will be predictable if - * they are synchronized. Use a cheap pseudo - * random number generator to obscure any cycles. - */ - x = rb.randn*1103515245 ^ *rb.rp; - *p++ = rb.randn = x; - - if(rb.rp+1 == rb.ep) - rb.rp = rb.buf; - else - rb.rp = rb.rp+1; - } - qunlock(&rb); - poperror(); - - wakeup(&rb.producer); - - return n; -} --- /sys/src/9/pc/random.c Wed Aug 26 16:36:33 2009 +++ /sys/src/9/pc/random.c Thu Jan 1 01:00:00 1970 @@ -1,139 +0,0 @@ -#include "u.h" -#include "../port/lib.h" -#include "mem.h" -#include "dat.h" -#include "fns.h" -#include "../port/error.h" - - -struct Rb -{ - QLock; - Rendez producer; - Rendez consumer; - ulong randomcount; - uchar buf[1024]; - uchar *ep; - uchar *rp; - uchar *wp; - uchar next; - uchar wakeme; - ushort bits; - ulong randn; -} rb; - -static int -rbnotfull(void*) -{ - int i; - - i = rb.rp - rb.wp; - return i != 1 && i != (1 - sizeof(rb.buf)); -} - -static int -rbnotempty(void*) -{ - return rb.wp != rb.rp; -} - -static void -genrandom(void*) -{ - up->basepri = PriNormal; - up->priority = up->basepri; - - for(;;){ - for(;;) - if(++rb.randomcount > 100000) - break; - if(anyhigher()) - sched(); - if(!rbnotfull(0)) - sleep(&rb.producer, rbnotfull, 0); - } -} - -/* - * produce random bits in a circular buffer - */ -static void -randomclock(void) -{ - if(rb.randomcount == 0 || !rbnotfull(0)) - return; - - rb.bits = (rb.bits<<2) ^ rb.randomcount; - rb.randomcount = 0; - - rb.next++; - if(rb.next != 8/2) - return; - rb.next = 0; - - *rb.wp ^= rb.bits; - if(rb.wp+1 == rb.ep) - rb.wp = rb.buf; - else - rb.wp = rb.wp+1; - - if(rb.wakeme) - wakeup(&rb.consumer); -} - -void -randominit(void) -{ - /* Frequency close but not equal to HZ */ - addclock0link(randomclock, 13); - rb.ep = rb.buf + sizeof(rb.buf); - rb.rp = rb.wp = rb.buf; - kproc("genrandom", genrandom, 0); -} - -/* - * consume random bytes from a circular buffer - */ -ulong -randomread(void *xp, ulong n) -{ - uchar *e, *p; - ulong x; - - p = xp; - - if(waserror()){ - qunlock(&rb); - nexterror(); - } - - qlock(&rb); - for(e = p + n; p < e; ){ - if(rb.wp == rb.rp){ - rb.wakeme = 1; - wakeup(&rb.producer); - sleep(&rb.consumer, rbnotempty, 0); - rb.wakeme = 0; - continue; - } - - /* - * beating clocks will be predictable if - * they are synchronized. Use a cheap pseudo- - * random number generator to obscure any cycles. - */ - x = rb.randn*1103515245 ^ *rb.rp; - *p++ = rb.randn = x; - - if(rb.rp+1 == rb.ep) - rb.rp = rb.buf; - else - rb.rp = rb.rp+1; - } - qunlock(&rb); - poperror(); - - wakeup(&rb.producer); - - return n; -} --- /sys/src/9/port/fpi.c Thu Jan 1 01:00:00 1970 +++ /sys/src/9/port/fpi.c Mon Mar 25 21:09:58 2013 @@ -0,0 +1,300 @@ +/* + * Floating Point Interpreter. + * shamelessly stolen from an original by ark. + */ +#include "fpi.h" + +void +fpiround(Internal *i) +{ + unsigned long guard; + + guard = i->l & GuardMask; + i->l &= ~GuardMask; + if(guard > (LsBit>>1) || (guard == (LsBit>>1) && (i->l & LsBit))){ + i->l += LsBit; + if(i->l & CarryBit){ + i->l &= ~CarryBit; + i->h++; + if(i->h & CarryBit){ + if (i->h & 0x01) + i->l |= CarryBit; + i->l >>= 1; + i->h >>= 1; + i->e++; + } + } + } +} + +static void +matchexponents(Internal *x, Internal *y) +{ + int count; + + count = y->e - x->e; + x->e = y->e; + if(count >= 2*FractBits){ + x->l = x->l || x->h; + x->h = 0; + return; + } + if(count >= FractBits){ + count -= FractBits; + x->l = x->h|(x->l != 0); + x->h = 0; + } + while(count > 0){ + count--; + if(x->h & 0x01) + x->l |= CarryBit; + if(x->l & 0x01) + x->l |= 2; + x->l >>= 1; + x->h >>= 1; + } +} + +static void +shift(Internal *i) +{ + i->e--; + i->h <<= 1; + i->l <<= 1; + if(i->l & CarryBit){ + i->l &= ~CarryBit; + i->h |= 0x01; + } +} + +static void +normalise(Internal *i) +{ + while((i->h & HiddenBit) == 0) + shift(i); +} + +static void +renormalise(Internal *i) +{ + if(i->e < -2 * FractBits) + i->e = -2 * FractBits; + while(i->e < 1){ + i->e++; + if(i->h & 0x01) + i->l |= CarryBit; + i->h >>= 1; + i->l = (i->l>>1)|(i->l & 0x01); + } + if(i->e >= ExpInfinity) + SetInfinity(i); +} + +void +fpinormalise(Internal *x) +{ + if(!IsWeird(x) && !IsZero(x)) + normalise(x); +} + +void +fpiadd(Internal *x, Internal *y, Internal *i) +{ + Internal *t; + + i->s = x->s; + if(IsWeird(x) || IsWeird(y)){ + if(IsNaN(x) || IsNaN(y)) + SetQNaN(i); + else + SetInfinity(i); + return; + } + if(x->e > y->e){ + t = x; + x = y; + y = t; + } + matchexponents(x, y); + i->e = x->e; + i->h = x->h + y->h; + i->l = x->l + y->l; + if(i->l & CarryBit){ + i->h++; + i->l &= ~CarryBit; + } + if(i->h & (HiddenBit<<1)){ + if(i->h & 0x01) + i->l |= CarryBit; + i->l = (i->l>>1)|(i->l & 0x01); + i->h >>= 1; + i->e++; + } + if(IsWeird(i)) + SetInfinity(i); +} + +void +fpisub(Internal *x, Internal *y, Internal *i) +{ + Internal *t; + + if(y->e < x->e + || (y->e == x->e && (y->h < x->h || (y->h == x->h && y->l < x->l)))){ + t = x; + x = y; + y = t; + } + i->s = y->s; + if(IsNaN(y)){ + SetQNaN(i); + return; + } + if(IsInfinity(y)){ + if(IsInfinity(x)) + SetQNaN(i); + else + SetInfinity(i); + return; + } + matchexponents(x, y); + i->e = y->e; + i->h = y->h - x->h; + i->l = y->l - x->l; + if(i->l < 0){ + i->l += CarryBit; + i->h--; + } + if(i->h == 0 && i->l == 0) + SetZero(i); + else while(i->e > 1 && (i->h & HiddenBit) == 0) + shift(i); +} + +#define CHUNK (FractBits/2) +#define CMASK ((1<>CHUNK) & CMASK) +#define LO(x) ((short)(x) & CMASK) +#define SPILL(x) ((x)>>CHUNK) +#define M(x, y) ((long)a[x]*(long)b[y]) +#define C(h, l) (((long)((h) & CMASK)<s = x->s^y->s; + if(IsWeird(x) || IsWeird(y)){ + if(IsNaN(x) || IsNaN(y) || IsZero(x) || IsZero(y)) + SetQNaN(i); + else + SetInfinity(i); + return; + } + else if(IsZero(x) || IsZero(y)){ + SetZero(i); + return; + } + normalise(x); + normalise(y); + i->e = x->e + y->e - (ExpBias - 1); + + a[0] = HI(x->h); b[0] = HI(y->h); + a[1] = LO(x->h); b[1] = LO(y->h); + a[2] = HI(x->l); b[2] = HI(y->l); + a[3] = LO(x->l); b[3] = LO(y->l); + + c[6] = M(3, 3); + c[5] = M(2, 3) + M(3, 2) + SPILL(c[6]); + c[4] = M(1, 3) + M(2, 2) + M(3, 1) + SPILL(c[5]); + c[3] = M(0, 3) + M(1, 2) + M(2, 1) + M(3, 0) + SPILL(c[4]); + c[2] = M(0, 2) + M(1, 1) + M(2, 0) + SPILL(c[3]); + c[1] = M(0, 1) + M(1, 0) + SPILL(c[2]); + c[0] = M(0, 0) + SPILL(c[1]); + + f[0] = c[0]; + f[1] = C(c[1], c[2]); + f[2] = C(c[3], c[4]); + f[3] = C(c[5], c[6]); + + if((f[0] & HiddenBit) == 0){ + f[0] <<= 1; + f[1] <<= 1; + f[2] <<= 1; + f[3] <<= 1; + if(f[1] & CarryBit){ + f[0] |= 1; + f[1] &= ~CarryBit; + } + if(f[2] & CarryBit){ + f[1] |= 1; + f[2] &= ~CarryBit; + } + if(f[3] & CarryBit){ + f[2] |= 1; + f[3] &= ~CarryBit; + } + i->e--; + } + i->h = f[0]; + i->l = f[1]; + if(f[2] || f[3]) + i->l |= 1; + renormalise(i); +} + +void +fpidiv(Internal *x, Internal *y, Internal *i) +{ + i->s = x->s^y->s; + if(IsNaN(x) || IsNaN(y) + || (IsInfinity(x) && IsInfinity(y)) || (IsZero(x) && IsZero(y))){ + SetQNaN(i); + return; + } + else if(IsZero(x) || IsInfinity(y)){ + SetInfinity(i); + return; + } + else if(IsInfinity(x) || IsZero(y)){ + SetZero(i); + return; + } + normalise(x); + normalise(y); + i->h = 0; + i->l = 0; + i->e = y->e - x->e + (ExpBias + 2*FractBits - 1); + do{ + if(y->h > x->h || (y->h == x->h && y->l >= x->l)){ + i->l |= 0x01; + y->h -= x->h; + y->l -= x->l; + if(y->l < 0){ + y->l += CarryBit; + y->h--; + } + } + shift(y); + shift(i); + }while ((i->h & HiddenBit) == 0); + if(y->h || y->l) + i->l |= 0x01; + renormalise(i); +} + +int +fpicmp(Internal *x, Internal *y) +{ + if(IsNaN(x) && IsNaN(y)) + return 0; + if(IsInfinity(x) && IsInfinity(y)) + return y->s - x->s; + if(x->e == y->e && x->h == y->h && x->l == y->l) + return y->s - x->s; + if(x->e < y->e + || (x->e == y->e && (x->h < y->h || (x->h == y->h && x->l < y->l)))) + return y->s ? 1: -1; + return x->s ? -1: 1; +} --- /sys/src/9/port/fpi.h Thu Jan 1 01:00:00 1970 +++ /sys/src/9/port/fpi.h Mon Mar 25 21:09:58 2013 @@ -0,0 +1,61 @@ +typedef long Word; +typedef unsigned long Single; +typedef struct { + unsigned long l; + unsigned long h; +} Double; + +enum { + FractBits = 28, + CarryBit = 0x10000000, + HiddenBit = 0x08000000, + MsBit = HiddenBit, + NGuardBits = 3, + GuardMask = 0x07, + LsBit = (1<e >= ExpInfinity) +#define IsInfinity(n) (IsWeird(n) && (n)->h == HiddenBit && (n)->l == 0) +#define SetInfinity(n) ((n)->e = ExpInfinity, (n)->h = HiddenBit, (n)->l = 0) +#define IsNaN(n) (IsWeird(n) && (((n)->h & ~HiddenBit) || (n)->l)) +#define SetQNaN(n) ((n)->s = 0, (n)->e = ExpInfinity, \ + (n)->h = HiddenBit|(LsBit<<1), (n)->l = 0) +#define IsZero(n) ((n)->e == 1 && (n)->h == 0 && (n)->l == 0) +#define SetZero(n) ((n)->e = 1, (n)->h = 0, (n)->l = 0) + +/* + * fpi.c + */ +extern void fpiround(Internal *); +extern void fpiadd(Internal *, Internal *, Internal *); +extern void fpisub(Internal *, Internal *, Internal *); +extern void fpimul(Internal *, Internal *, Internal *); +extern void fpidiv(Internal *, Internal *, Internal *); +extern int fpicmp(Internal *, Internal *); +extern void fpinormalise(Internal*); + +/* + * fpimem.c + */ +extern void fpis2i(Internal *, void *); +extern void fpid2i(Internal *, void *); +extern void fpiw2i(Internal *, void *); +extern void fpii2s(void *, Internal *); +extern void fpii2d(void *, Internal *); +extern void fpii2w(Word *, Internal *); --- /sys/src/9/port/fpimem.c Thu Jan 1 01:00:00 1970 +++ /sys/src/9/port/fpimem.c Mon Mar 25 21:24:04 2013 @@ -0,0 +1,136 @@ +#include "fpi.h" + +/* + * the following routines depend on memory format, not the machine + */ + +void +fpis2i(Internal *i, void *v) +{ + Single *s = v; + + i->s = (*s & 0x80000000) ? 1: 0; + if((*s & ~0x80000000) == 0){ + SetZero(i); + return; + } + i->e = ((*s>>23) & 0x00FF) - SingleExpBias + ExpBias; + i->h = (*s & 0x007FFFFF)<<(1+NGuardBits); + i->l = 0; + if(i->e) + i->h |= HiddenBit; + else + i->e++; +} + +void +fpid2i(Internal *i, void *v) +{ + Double *d = v; + + i->s = (d->h & 0x80000000) ? 1: 0; + i->e = (d->h>>20) & 0x07FF; + i->h = ((d->h & 0x000FFFFF)<<(4+NGuardBits))|((d->l>>25) & 0x7F); + i->l = (d->l & 0x01FFFFFF)<e) + i->h |= HiddenBit; + else + i->e++; +} + +void +fpiw2i(Internal *i, void *v) +{ + Word w, word = *(Word*)v; + short e; + + if(word < 0){ + i->s = 1; + word = -word; + } + else + i->s = 0; + if(word == 0){ + SetZero(i); + return; + } + if(word > 0){ + for (e = 0, w = word; w; w >>= 1, e++) + ; + } else + e = 32; + if(e > FractBits){ + i->h = word>>(e - FractBits); + i->l = (word & ((1<<(e - FractBits)) - 1))<<(2*FractBits - e); + } + else { + i->h = word<<(FractBits - e); + i->l = 0; + } + i->e = (e - 1) + ExpBias; +} + +void +fpii2s(void *v, Internal *i) +{ + short e; + Single *s = (Single*)v; + + fpiround(i); + if(i->h & HiddenBit) + i->h &= ~HiddenBit; + else + i->e--; + *s = i->s ? 0x80000000: 0; + e = i->e; + if(e < ExpBias){ + if(e <= (ExpBias - SingleExpBias)) + return; + e = SingleExpBias - (ExpBias - e); + } + else if(e >= (ExpBias + (SingleExpMax-SingleExpBias))){ + *s |= SingleExpMax<<23; + return; + } + else + e = SingleExpBias + (e - ExpBias); + *s |= (e<<23)|(i->h>>(1+NGuardBits)); +} + +void +fpii2d(void *v, Internal *i) +{ + Double *d = (Double*)v; + + fpiround(i); + if(i->h & HiddenBit) + i->h &= ~HiddenBit; + else + i->e--; + i->l = ((i->h & GuardMask)<<25)|(i->l>>NGuardBits); + i->h >>= NGuardBits; + d->h = i->s ? 0x80000000: 0; + d->h |= (i->e<<20)|((i->h & 0x00FFFFFF)>>4); + d->l = (i->h<<28)|i->l; +} + +void +fpii2w(Word *word, Internal *i) +{ + Word w; + short e; + + fpiround(i); + e = (i->e - ExpBias) + 1; + if(e <= 0) + w = 0; + else if(e > 31) + w = 0x7FFFFFFF; + else if(e > FractBits) + w = (i->h<<(e - FractBits))|(i->l>>(2*FractBits - e)); + else + w = i->h>>(FractBits-e); + if(i->s) + w = -w; + *word = w; +} --- /sys/src/9/port/random.c Thu Jan 1 01:00:00 1970 +++ /sys/src/9/port/random.c Mon Mar 25 21:04:46 2013 @@ -0,0 +1,139 @@ +#include "u.h" +#include "../port/lib.h" +#include "mem.h" +#include "dat.h" +#include "fns.h" +#include "../port/error.h" + + +struct Rb +{ + QLock; + Rendez producer; + Rendez consumer; + ulong randomcount; + uchar buf[1024]; + uchar *ep; + uchar *rp; + uchar *wp; + uchar next; + uchar wakeme; + ushort bits; + ulong randn; +} rb; + +static int +rbnotfull(void*) +{ + int i; + + i = rb.rp - rb.wp; + return i != 1 && i != (1 - sizeof(rb.buf)); +} + +static int +rbnotempty(void*) +{ + return rb.wp != rb.rp; +} + +static void +genrandom(void*) +{ + up->basepri = PriNormal; + up->priority = up->basepri; + + for(;;){ + for(;;) + if(++rb.randomcount > 100000) + break; + if(anyhigher()) + sched(); + if(!rbnotfull(0)) + sleep(&rb.producer, rbnotfull, 0); + } +} + +/* + * produce random bits in a circular buffer + */ +static void +randomclock(void) +{ + if(rb.randomcount == 0 || !rbnotfull(0)) + return; + + rb.bits = (rb.bits<<2) ^ rb.randomcount; + rb.randomcount = 0; + + rb.next++; + if(rb.next != 8/2) + return; + rb.next = 0; + + *rb.wp ^= rb.bits; + if(rb.wp+1 == rb.ep) + rb.wp = rb.buf; + else + rb.wp = rb.wp+1; + + if(rb.wakeme) + wakeup(&rb.consumer); +} + +void +randominit(void) +{ + /* Frequency close but not equal to HZ */ + addclock0link(randomclock, 13); + rb.ep = rb.buf + sizeof(rb.buf); + rb.rp = rb.wp = rb.buf; + kproc("genrandom", genrandom, 0); +} + +/* + * consume random bytes from a circular buffer + */ +ulong +randomread(void *xp, ulong n) +{ + uchar *e, *p; + ulong x; + + p = xp; + + if(waserror()){ + qunlock(&rb); + nexterror(); + } + + qlock(&rb); + for(e = p + n; p < e; ){ + if(rb.wp == rb.rp){ + rb.wakeme = 1; + wakeup(&rb.producer); + sleep(&rb.consumer, rbnotempty, 0); + rb.wakeme = 0; + continue; + } + + /* + * beating clocks will be predictable if + * they are synchronized. Use a cheap pseudo- + * random number generator to obscure any cycles. + */ + x = rb.randn*1103515245 ^ *rb.rp; + *p++ = rb.randn = x; + + if(rb.rp+1 == rb.ep) + rb.rp = rb.buf; + else + rb.rp = rb.rp+1; + } + qunlock(&rb); + poperror(); + + wakeup(&rb.producer); + + return n; +} --- /sys/src/9/ppc/mkfile Sat Jan 26 02:34:15 2013 +++ /sys/src/9/ppc/mkfile Wed Mar 27 00:19:44 2013 @@ -2,6 +2,7 @@ CONFLIST=blast ucu loadaddr = 0x80100000 +physaddr = 0x00100000 objtype=power basepri = PriNormal; - up->priority = up->basepri; - - for(;;){ - for(;;) - if(++rb.randomcount > 100000) - break; - if(anyhigher()) - sched(); - if(!rbnotfull(0)) - sleep(&rb.producer, rbnotfull, 0); - } -} - -/* - * produce random bits in a circular buffer - */ -static void -randomclock(void) -{ - if(rb.randomcount == 0 || !rbnotfull(0)) - return; - - rb.bits = (rb.bits<<2) ^ rb.randomcount; - rb.randomcount = 0; - - rb.next++; - if(rb.next != 8/2) - return; - rb.next = 0; - - *rb.wp ^= rb.bits; - if(rb.wp+1 == rb.ep) - rb.wp = rb.buf; - else - rb.wp = rb.wp+1; - - if(rb.wakeme) - wakeup(&rb.consumer); -} - -void -randominit(void) -{ - addclock0link(randomclock, 1000/HZ); - rb.ep = rb.buf + sizeof(rb.buf); - rb.rp = rb.wp = rb.buf; - kproc("genrandom", genrandom, 0); -} - -/* - * consume random bytes from a circular buffer - */ -ulong -randomread(void *xp, ulong n) -{ - uchar *e, *p; - ulong x; - - p = xp; - - if(waserror()){ - qunlock(&rb); - nexterror(); - } - - qlock(&rb); - for(e = p + n; p < e; ){ - if(rb.wp == rb.rp){ - rb.wakeme = 1; - wakeup(&rb.producer); - sleep(&rb.consumer, rbnotempty, 0); - rb.wakeme = 0; - continue; - } - - /* - * beating clocks will be precictable if - * they are synchronized. Use a cheap pseudo - * random number generator to obscure any cycles. - */ - x = rb.randn*1103515245 ^ *rb.rp; - *p++ = rb.randn = x; - - if(rb.rp+1 == rb.ep) - rb.rp = rb.buf; - else - rb.rp = rb.rp+1; - } - qunlock(&rb); - poperror(); - - wakeup(&rb.producer); - - return n; -} --- /sys/src/9/teg2/fpi.c Wed Dec 19 16:36:51 2007 +++ /sys/src/9/teg2/fpi.c Thu Jan 1 01:00:00 1970 @@ -1,300 +0,0 @@ -/* - * Floating Point Interpreter. - * shamelessly stolen from an original by ark. - */ -#include "fpi.h" - -void -fpiround(Internal *i) -{ - unsigned long guard; - - guard = i->l & GuardMask; - i->l &= ~GuardMask; - if(guard > (LsBit>>1) || (guard == (LsBit>>1) && (i->l & LsBit))){ - i->l += LsBit; - if(i->l & CarryBit){ - i->l &= ~CarryBit; - i->h++; - if(i->h & CarryBit){ - if (i->h & 0x01) - i->l |= CarryBit; - i->l >>= 1; - i->h >>= 1; - i->e++; - } - } - } -} - -static void -matchexponents(Internal *x, Internal *y) -{ - int count; - - count = y->e - x->e; - x->e = y->e; - if(count >= 2*FractBits){ - x->l = x->l || x->h; - x->h = 0; - return; - } - if(count >= FractBits){ - count -= FractBits; - x->l = x->h|(x->l != 0); - x->h = 0; - } - while(count > 0){ - count--; - if(x->h & 0x01) - x->l |= CarryBit; - if(x->l & 0x01) - x->l |= 2; - x->l >>= 1; - x->h >>= 1; - } -} - -static void -shift(Internal *i) -{ - i->e--; - i->h <<= 1; - i->l <<= 1; - if(i->l & CarryBit){ - i->l &= ~CarryBit; - i->h |= 0x01; - } -} - -static void -normalise(Internal *i) -{ - while((i->h & HiddenBit) == 0) - shift(i); -} - -static void -renormalise(Internal *i) -{ - if(i->e < -2 * FractBits) - i->e = -2 * FractBits; - while(i->e < 1){ - i->e++; - if(i->h & 0x01) - i->l |= CarryBit; - i->h >>= 1; - i->l = (i->l>>1)|(i->l & 0x01); - } - if(i->e >= ExpInfinity) - SetInfinity(i); -} - -void -fpinormalise(Internal *x) -{ - if(!IsWeird(x) && !IsZero(x)) - normalise(x); -} - -void -fpiadd(Internal *x, Internal *y, Internal *i) -{ - Internal *t; - - i->s = x->s; - if(IsWeird(x) || IsWeird(y)){ - if(IsNaN(x) || IsNaN(y)) - SetQNaN(i); - else - SetInfinity(i); - return; - } - if(x->e > y->e){ - t = x; - x = y; - y = t; - } - matchexponents(x, y); - i->e = x->e; - i->h = x->h + y->h; - i->l = x->l + y->l; - if(i->l & CarryBit){ - i->h++; - i->l &= ~CarryBit; - } - if(i->h & (HiddenBit<<1)){ - if(i->h & 0x01) - i->l |= CarryBit; - i->l = (i->l>>1)|(i->l & 0x01); - i->h >>= 1; - i->e++; - } - if(IsWeird(i)) - SetInfinity(i); -} - -void -fpisub(Internal *x, Internal *y, Internal *i) -{ - Internal *t; - - if(y->e < x->e - || (y->e == x->e && (y->h < x->h || (y->h == x->h && y->l < x->l)))){ - t = x; - x = y; - y = t; - } - i->s = y->s; - if(IsNaN(y)){ - SetQNaN(i); - return; - } - if(IsInfinity(y)){ - if(IsInfinity(x)) - SetQNaN(i); - else - SetInfinity(i); - return; - } - matchexponents(x, y); - i->e = y->e; - i->h = y->h - x->h; - i->l = y->l - x->l; - if(i->l < 0){ - i->l += CarryBit; - i->h--; - } - if(i->h == 0 && i->l == 0) - SetZero(i); - else while(i->e > 1 && (i->h & HiddenBit) == 0) - shift(i); -} - -#define CHUNK (FractBits/2) -#define CMASK ((1<>CHUNK) & CMASK) -#define LO(x) ((short)(x) & CMASK) -#define SPILL(x) ((x)>>CHUNK) -#define M(x, y) ((long)a[x]*(long)b[y]) -#define C(h, l) (((long)((h) & CMASK)<s = x->s^y->s; - if(IsWeird(x) || IsWeird(y)){ - if(IsNaN(x) || IsNaN(y) || IsZero(x) || IsZero(y)) - SetQNaN(i); - else - SetInfinity(i); - return; - } - else if(IsZero(x) || IsZero(y)){ - SetZero(i); - return; - } - normalise(x); - normalise(y); - i->e = x->e + y->e - (ExpBias - 1); - - a[0] = HI(x->h); b[0] = HI(y->h); - a[1] = LO(x->h); b[1] = LO(y->h); - a[2] = HI(x->l); b[2] = HI(y->l); - a[3] = LO(x->l); b[3] = LO(y->l); - - c[6] = M(3, 3); - c[5] = M(2, 3) + M(3, 2) + SPILL(c[6]); - c[4] = M(1, 3) + M(2, 2) + M(3, 1) + SPILL(c[5]); - c[3] = M(0, 3) + M(1, 2) + M(2, 1) + M(3, 0) + SPILL(c[4]); - c[2] = M(0, 2) + M(1, 1) + M(2, 0) + SPILL(c[3]); - c[1] = M(0, 1) + M(1, 0) + SPILL(c[2]); - c[0] = M(0, 0) + SPILL(c[1]); - - f[0] = c[0]; - f[1] = C(c[1], c[2]); - f[2] = C(c[3], c[4]); - f[3] = C(c[5], c[6]); - - if((f[0] & HiddenBit) == 0){ - f[0] <<= 1; - f[1] <<= 1; - f[2] <<= 1; - f[3] <<= 1; - if(f[1] & CarryBit){ - f[0] |= 1; - f[1] &= ~CarryBit; - } - if(f[2] & CarryBit){ - f[1] |= 1; - f[2] &= ~CarryBit; - } - if(f[3] & CarryBit){ - f[2] |= 1; - f[3] &= ~CarryBit; - } - i->e--; - } - i->h = f[0]; - i->l = f[1]; - if(f[2] || f[3]) - i->l |= 1; - renormalise(i); -} - -void -fpidiv(Internal *x, Internal *y, Internal *i) -{ - i->s = x->s^y->s; - if(IsNaN(x) || IsNaN(y) - || (IsInfinity(x) && IsInfinity(y)) || (IsZero(x) && IsZero(y))){ - SetQNaN(i); - return; - } - else if(IsZero(x) || IsInfinity(y)){ - SetInfinity(i); - return; - } - else if(IsInfinity(x) || IsZero(y)){ - SetZero(i); - return; - } - normalise(x); - normalise(y); - i->h = 0; - i->l = 0; - i->e = y->e - x->e + (ExpBias + 2*FractBits - 1); - do{ - if(y->h > x->h || (y->h == x->h && y->l >= x->l)){ - i->l |= 0x01; - y->h -= x->h; - y->l -= x->l; - if(y->l < 0){ - y->l += CarryBit; - y->h--; - } - } - shift(y); - shift(i); - }while ((i->h & HiddenBit) == 0); - if(y->h || y->l) - i->l |= 0x01; - renormalise(i); -} - -int -fpicmp(Internal *x, Internal *y) -{ - if(IsNaN(x) && IsNaN(y)) - return 0; - if(IsInfinity(x) && IsInfinity(y)) - return y->s - x->s; - if(x->e == y->e && x->h == y->h && x->l == y->l) - return y->s - x->s; - if(x->e < y->e - || (x->e == y->e && (x->h < y->h || (x->h == y->h && x->l < y->l)))) - return y->s ? 1: -1; - return x->s ? -1: 1; -} --- /sys/src/9/teg2/fpi.h Wed Dec 19 16:36:51 2007 +++ /sys/src/9/teg2/fpi.h Thu Jan 1 01:00:00 1970 @@ -1,61 +0,0 @@ -typedef long Word; -typedef unsigned long Single; -typedef struct { - unsigned long l; - unsigned long h; -} Double; - -enum { - FractBits = 28, - CarryBit = 0x10000000, - HiddenBit = 0x08000000, - MsBit = HiddenBit, - NGuardBits = 3, - GuardMask = 0x07, - LsBit = (1<e >= ExpInfinity) -#define IsInfinity(n) (IsWeird(n) && (n)->h == HiddenBit && (n)->l == 0) -#define SetInfinity(n) ((n)->e = ExpInfinity, (n)->h = HiddenBit, (n)->l = 0) -#define IsNaN(n) (IsWeird(n) && (((n)->h & ~HiddenBit) || (n)->l)) -#define SetQNaN(n) ((n)->s = 0, (n)->e = ExpInfinity, \ - (n)->h = HiddenBit|(LsBit<<1), (n)->l = 0) -#define IsZero(n) ((n)->e == 1 && (n)->h == 0 && (n)->l == 0) -#define SetZero(n) ((n)->e = 1, (n)->h = 0, (n)->l = 0) - -/* - * fpi.c - */ -extern void fpiround(Internal *); -extern void fpiadd(Internal *, Internal *, Internal *); -extern void fpisub(Internal *, Internal *, Internal *); -extern void fpimul(Internal *, Internal *, Internal *); -extern void fpidiv(Internal *, Internal *, Internal *); -extern int fpicmp(Internal *, Internal *); -extern void fpinormalise(Internal*); - -/* - * fpimem.c - */ -extern void fpis2i(Internal *, void *); -extern void fpid2i(Internal *, void *); -extern void fpiw2i(Internal *, void *); -extern void fpii2s(void *, Internal *); -extern void fpii2d(void *, Internal *); -extern void fpii2w(Word *, Internal *); --- /sys/src/9/teg2/fpiarm.c Fri Jan 25 01:34:36 2013 +++ /sys/src/9/teg2/fpiarm.c Mon Mar 25 21:28:56 2013 @@ -13,7 +13,7 @@ #include "ureg.h" #include "arm.h" -#include "fpi.h" +#include "../port/fpi.h" #define ARM7500 /* emulate old pre-VFP opcodes */ --- /sys/src/9/teg2/fpimem.c Wed Dec 19 16:36:51 2007 +++ /sys/src/9/teg2/fpimem.c Thu Jan 1 01:00:00 1970 @@ -1,136 +0,0 @@ -#include "fpi.h" - -/* - * the following routines depend on memory format, not the machine - */ - -void -fpis2i(Internal *i, void *v) -{ - Single *s = v; - - i->s = (*s & 0x80000000) ? 1: 0; - if((*s & ~0x80000000) == 0){ - SetZero(i); - return; - } - i->e = ((*s>>23) & 0x00FF) - SingleExpBias + ExpBias; - i->h = (*s & 0x007FFFFF)<<(1+NGuardBits); - i->l = 0; - if(i->e) - i->h |= HiddenBit; - else - i->e++; -} - -void -fpid2i(Internal *i, void *v) -{ - Double *d = v; - - i->s = (d->h & 0x80000000) ? 1: 0; - i->e = (d->h>>20) & 0x07FF; - i->h = ((d->h & 0x000FFFFF)<<(4+NGuardBits))|((d->l>>25) & 0x7F); - i->l = (d->l & 0x01FFFFFF)<e) - i->h |= HiddenBit; - else - i->e++; -} - -void -fpiw2i(Internal *i, void *v) -{ - Word w, word = *(Word*)v; - short e; - - if(word < 0){ - i->s = 1; - word = -word; - } - else - i->s = 0; - if(word == 0){ - SetZero(i); - return; - } - if(word > 0){ - for (e = 0, w = word; w; w >>= 1, e++) - ; - } else - e = 32; - if(e > FractBits){ - i->h = word>>(e - FractBits); - i->l = (word & ((1<<(e - FractBits)) - 1))<<(2*FractBits - e); - } - else { - i->h = word<<(FractBits - e); - i->l = 0; - } - i->e = (e - 1) + ExpBias; -} - -void -fpii2s(void *v, Internal *i) -{ - short e; - Single *s = (Single*)v; - - fpiround(i); - if(i->h & HiddenBit) - i->h &= ~HiddenBit; - else - i->e--; - *s = i->s ? 0x80000000: 0; - e = i->e; - if(e < ExpBias){ - if(e <= (ExpBias - SingleExpBias)) - return; - e = SingleExpBias - (ExpBias - e); - } - else if(e >= (ExpBias + (SingleExpMax-SingleExpBias))){ - *s |= SingleExpMax<<23; - return; - } - else - e = SingleExpBias + (e - ExpBias); - *s |= (e<<23)|(i->h>>(1+NGuardBits)); -} - -void -fpii2d(void *v, Internal *i) -{ - Double *d = (Double*)v; - - fpiround(i); - if(i->h & HiddenBit) - i->h &= ~HiddenBit; - else - i->e--; - i->l = ((i->h & GuardMask)<<25)|(i->l>>NGuardBits); - i->h >>= NGuardBits; - d->h = i->s ? 0x80000000: 0; - d->h |= (i->e<<20)|((i->h & 0x00FFFFFF)>>4); - d->l = (i->h<<28)|i->l; -} - -void -fpii2w(Word *word, Internal *i) -{ - Word w; - short e; - - fpiround(i); - e = (i->e - ExpBias) + 1; - if(e <= 0) - w = 0; - else if(e > 31) - w = 0x7FFFFFFF; - else if(e > FractBits) - w = (i->h<<(e - FractBits))|(i->l>>(2*FractBits - e)); - else - w = i->h>>(FractBits-e); - if(i->s) - w = -w; - *word = w; -} --- /sys/src/9/teg2/mkfile Wed Feb 13 22:07:00 2013 +++ /sys/src/9/teg2/mkfile Tue Mar 26 04:37:45 2013 @@ -120,7 +120,7 @@ archtegra.$O devether.$0 ether9221.$O: etherif.h ../port/netif.h archtegra.$O devflash.$O flashtegra.$O flashigep.$O: ../port/flashif.h ecc.$O flashtegra.$O flashigep.$O: ../port/nandecc.h io.h -fpi.$O fpiarm.$O fpimem.$O: fpi.h +fpi.$O fpiarm.$O fpimem.$O: ../port/fpi.h l.$O lexception.$O lproc.$O mmu.$O: arm.s mem.h l.$O rebootcode.$O: cache.v7.s main.$O: errstr.h init.h reboot.h --- /sys/src/9/teg2/random.c Sun Nov 8 07:31:28 2009 +++ /sys/src/9/teg2/random.c Thu Jan 1 01:00:00 1970 @@ -1,138 +0,0 @@ -#include "u.h" -#include "../port/lib.h" -#include "mem.h" -#include "dat.h" -#include "fns.h" -#include "../port/error.h" - - -struct Rb -{ - QLock; - Rendez producer; - Rendez consumer; - ulong randomcount; - uchar buf[128]; - uchar *ep; - uchar *rp; - uchar *wp; - uchar next; - uchar wakeme; - ushort bits; - ulong randn; -} rb; - -static int -rbnotfull(void*) -{ - int i; - - i = rb.rp - rb.wp; - return i != 1 && i != (1 - sizeof(rb.buf)); -} - -static int -rbnotempty(void*) -{ - return rb.wp != rb.rp; -} - -static void -genrandom(void*) -{ - up->basepri = PriNormal; - up->priority = up->basepri; - - for(;;){ - for(;;) - if(++rb.randomcount > 100000) - break; - if(anyhigher()) - sched(); - if(!rbnotfull(0)) - sleep(&rb.producer, rbnotfull, 0); - } -} - -/* - * produce random bits in a circular buffer - */ -static void -randomclock(void) -{ - if(rb.randomcount == 0 || !rbnotfull(0)) - return; - - rb.bits = (rb.bits<<2) ^ rb.randomcount; - rb.randomcount = 0; - - rb.next++; - if(rb.next != 8/2) - return; - rb.next = 0; - - *rb.wp ^= rb.bits; - if(rb.wp+1 == rb.ep) - rb.wp = rb.buf; - else - rb.wp = rb.wp+1; - - if(rb.wakeme) - wakeup(&rb.consumer); -} - -void -randominit(void) -{ - addclock0link(randomclock, 1000/HZ); - rb.ep = rb.buf + sizeof(rb.buf); - rb.rp = rb.wp = rb.buf; - kproc("genrandom", genrandom, 0); -} - -/* - * consume random bytes from a circular buffer - */ -ulong -randomread(void *xp, ulong n) -{ - uchar *e, *p; - ulong x; - - p = xp; - - if(waserror()){ - qunlock(&rb); - nexterror(); - } - - qlock(&rb); - for(e = p + n; p < e; ){ - if(rb.wp == rb.rp){ - rb.wakeme = 1; - wakeup(&rb.producer); - sleep(&rb.consumer, rbnotempty, 0); - rb.wakeme = 0; - continue; - } - - /* - * beating clocks will be predictable if - * they are synchronized. Use a cheap pseudo - * random number generator to obscure any cycles. - */ - x = rb.randn*1103515245 ^ *rb.rp; - *p++ = rb.randn = x; - - if(rb.rp+1 == rb.ep) - rb.rp = rb.buf; - else - rb.rp = rb.rp+1; - } - qunlock(&rb); - poperror(); - - wakeup(&rb.producer); - - return n; -} --- /sys/src/cmd/5l/asm.c Fri Jan 25 01:20:50 2013 +++ /sys/src/cmd/5l/asm.c Wed Mar 27 00:17:32 2013 @@ -216,58 +216,8 @@ lputl(0xe3300000); /* nop */ break; case 7: /* elf */ - strnput("\177ELF", 4); /* e_ident */ - cput(1); /* class = 32 bit */ - cput(2); /* data = MSB */ - cput(1); /* version = CURRENT */ - strnput("", 9); - lput((2L<<16)|40); /* type = EXEC; machine = ARM */ - lput(1L); /* version = CURRENT */ - lput(entryvalue()); /* entry vaddr */ - lput(52L); /* offset to first phdr */ - - debug['S'] = 1; /* no symbol table */ - if(debug['S']){ - lput(HEADR+textsize+datsize+symsize); /* offset to first shdr */ - lput(0L); /* flags = PPC */ - lput((52L<<16)|32L); /* Ehdr & Phdr sizes*/ - lput((4L<<16)|40L); /* # Phdrs & Shdr size */ - lput((4L<<16)|2L); /* # Shdrs & shdr string size */ - } - else{ - lput(0L); - lput(0L); /* flags = PPC */ - lput((52L<<16)|32L); /* Ehdr & Phdr sizes*/ - lput((4L<<16)|0L); /* # Phdrs & Shdr size */ - lput((4L<<16)|0L); /* # Shdrs & shdr string size */ - } - - lput(1L); /* text - type = PT_LOAD */ - lput(HEADR); /* file offset */ - lput(INITTEXT); /* vaddr */ - lput(INITTEXT); /* paddr */ - lput(textsize); /* file size */ - lput(textsize); /* memory size */ - lput(0x05L); /* protections = RX */ - lput(0); /* alignment */ - - lput(1L); /* data - type = PT_LOAD */ - lput(HEADR+textsize); /* file offset */ - lput(INITDAT); /* vaddr */ - lput(INITDAT); /* paddr */ - lput(datsize); /* file size */ - lput(datsize+bsssize); /* memory size */ - lput(0x07L); /* protections = RWX */ - lput(0); /* alignment */ - - lput(0L); /* data - type = PT_NULL */ - lput(HEADR+textsize+datsize); /* file offset */ - lput(0L); /* vaddr */ - lput(0L); /* paddr */ - lput(symsize); /* symbol table size */ - lput(lcsize); /* line number size */ - lput(0x04L); /* protections = R */ - lput(0x04L); /* alignment code?? */ + debug['S'] = 1; /* symbol table */ + elf32(ARM, ELFDATA2LSB, 0, nil); break; } cflush(); @@ -307,6 +257,18 @@ } void +wputl(long l) +{ + + cbp[0] = l; + cbp[1] = l>>8; + cbp += 2; + cbc -= 2; + if(cbc <= 0) + cflush(); +} + +void lput(long l) { @@ -332,6 +294,20 @@ cbc -= 4; if(cbc <= 0) cflush(); +} + +void +llput(vlong v) +{ + lput(v>>32); + lput(v); +} + +void +llputl(vlong v) +{ + lputl(v); + lputl(v>>32); } void --- /sys/src/cmd/5l/l.h Fri Jan 25 01:20:50 2013 +++ /sys/src/cmd/5l/l.h Wed Mar 27 00:18:09 2013 @@ -2,6 +2,7 @@ #include #include #include "../5c/5.out.h" +#include "../8l/elf.h" #ifndef EXTERN #define EXTERN extern @@ -224,6 +225,7 @@ EXTERN long INITDAT; /* data location */ EXTERN long INITRND; /* data round above text location */ EXTERN long INITTEXT; /* text location */ +EXTERN long INITTEXTP; /* text location (physical) */ EXTERN char* INITENTRY; /* entry point */ EXTERN long autosize; EXTERN Biobuf bso; @@ -359,6 +361,8 @@ void listinit(void); Sym* lookup(char*, int); void cput(int); +void llput(vlong); +void llputl(vlong); void lput(long); void lputl(long); void mkfwd(void); @@ -397,6 +401,7 @@ void undef(void); void undefsym(Sym*); void wput(long); +void wputl(long); void xdefine(char*, int, long); void xfol(Prog*); void zerosig(char*); --- /sys/src/cmd/5l/mkfile Sat Mar 24 00:30:48 2012 +++ /sys/src/cmd/5l/mkfile Wed Mar 27 00:18:22 2013 @@ -11,12 +11,15 @@ span.$O\ enam.$O\ compat.$O\ + elf.$O\ HFILES=\ l.h\ ../5c/5.out.h\ + ../8l/elf.h\ BIN=/$objtype/bin +CFLAGS=$CFLAGS -. -I. value; } -void -wputl(ushort w) +/* these need to take long arguments to be compatible with elf.c */void +wputl(long w) { cput(w); cput(w>>8); } void -wput(ushort w) +wput(long w) { cput(w>>8); cput(w); @@ -220,120 +220,10 @@ llput(vl); /* va of entry */ break; case 5: - strnput("\177ELF", 4); /* e_ident */ - cput(1); /* class = 32 bit */ - cput(1); /* data = LSB */ - cput(1); /* version = CURRENT */ - if(debug['P']){ /* boot/embedded/standalone */ - cput(255); - cput(0); - } - else{ - cput(0); /* osabi = SYSV */ - cput(0); /* abiversion = 3 */ - } - strnput("", 7); - wputl(2); /* type = EXEC */ - if(debug['8']) - wputl(3); /* machine = 386 */ - else - wputl(62); /* machine = AMD64 */ - lputl(1L); /* version = CURRENT */ - lputl(PADDR(entryvalue())); /* entry vaddr */ - lputl(52L); /* offset to first phdr */ - lputl(0L); /* offset to first shdr */ - lputl(0L); /* processor specific flags */ - wputl(52); /* Ehdr size */ - wputl(32); /* Phdr size */ - wputl(3); /* # of Phdrs */ - wputl(0); /* Shdr size */ - wputl(0); /* # of Shdrs */ - wputl(0); /* Shdr string size */ - - lputl(1L); /* text - type = PT_LOAD */ - lputl(HEADR); /* file offset */ - lputl(INITTEXT); /* vaddr */ - lputl(PADDR(INITTEXT)); /* paddr */ - lputl(textsize); /* file size */ - lputl(textsize); /* memory size */ - lputl(0x05L); /* protections = RX */ - lputl(INITRND); /* alignment */ - - lputl(1L); /* data - type = PT_LOAD */ - lputl(HEADR+textsize); /* file offset */ - lputl(INITDAT); /* vaddr */ - lputl(PADDR(INITDAT)); /* paddr */ - lputl(datsize); /* file size */ - lputl(datsize+bsssize); /* memory size */ - lputl(0x06L); /* protections = RW */ - lputl(INITRND); /* alignment */ - - lputl(0L); /* symbols - type = PT_NULL */ - lputl(HEADR+textsize+datsize); /* file offset */ - lputl(0L); - lputl(0L); - lputl(symsize); /* symbol table size */ - lputl(lcsize); /* line number size */ - lputl(0x04L); /* protections = R */ - lputl(0x04L); /* alignment */ + elf32(debug['8']? I386: AMD64, ELFDATA2LSB, 0, nil); break; case 6: - strnput("\177ELF", 4); /* e_ident */ - cput(2); /* class = 64 bit */ - cput(1); /* data = LSB */ - cput(1); /* version = CURRENT */ - if(debug['P']){ /* boot/embedded/standalone */ - cput(255); - cput(0); - } - else{ - cput(0); /* osabi = SYSV */ - cput(0); /* abiversion = 3 */ - } - strnput("", 7); - wputl(2); /* type = EXEC */ - wputl(62); /* machine = AMD64 */ - lputl(1L); /* version = CURRENT */ - if(debug['P']) /* boot/embedded/standalone */ - llputl(PADDR(entryvalue())); - else - llputl(entryvalue()); /* entry vaddr */ - llputl(64ull); /* offset to first phdr */ - llputl(0); /* offset to first shdr */ - lputl(0L); /* processor specific flags */ - wputl(64); /* E64hdr size */ - wputl(56); /* P64hdr size */ - wputl(3); /* # of P64hdrs */ - wputl(64); /* S64hdr size */ - wputl(0); /* # of S64hdrs */ - wputl(0); /* S64hdr string size */ - - lputl(1L); /* text - type = PT_LOAD */ - lputl(0x05L); /* protections = RX */ - llputl(HEADR); /* file offset */ - llputl(INITTEXT); /* vaddr */ - llput(PADDR(INITTEXT)); /* paddr */ - llput(textsize); /* file size */ - llput(textsize); /* memory size */ - llput(INITRND); /* alignment */ - - lputl(1L); /* data - type = PT_LOAD */ - lputl(0x06L); /* protections = RW */ - llputl(HEADR+textsize); /* file offset */ - llputl(INITDAT); /* vaddr */ - llputl(PADDR(INITDAT)); /* paddr */ - llputl(datsize); /* file size */ - llputl(datsize+bsssize); /* memory size */ - llputl(INITRND); /* alignment */ - - lputl(0L); /* symbols - type = PT_NULL */ - lputl(0x04L); /* protections = R */ - llputl(HEADR+textsize+datsize); /* file offset */ - llputl(0); - llputl(0); - llputl(symsize); /* symbol table size */ - llputl(lcsize); /* line number size */ - llputl(0x04ull); /* alignment */ + elf64(AMD64, ELFDATA2LSB, 0, nil); break; } cflush(); --- /sys/src/cmd/6l/l.h Mon Dec 17 20:33:08 2012 +++ /sys/src/cmd/6l/l.h Wed Mar 27 00:18:09 2013 @@ -2,6 +2,7 @@ #include #include #include "../6c/6.out.h" +#include "../8l/elf.h" #ifndef EXTERN #define EXTERN extern @@ -252,6 +253,7 @@ EXTERN vlong INITDAT; EXTERN long INITRND; EXTERN vlong INITTEXT; +EXTERN vlong INITTEXTP; EXTERN char* INITENTRY; /* entry point */ EXTERN Biobuf bso; EXTERN long bsssize; @@ -370,6 +372,8 @@ void loadlib(void); void listinit(void); Sym* lookup(char*, int); +void llput(vlong v); +void llputl(vlong v); void lput(long); void lputl(long); void main(int, char*[]); @@ -385,10 +389,12 @@ long reuse(Prog*, Sym*); vlong rnd(vlong, vlong); void span(void); +void strnput(char*, int); void undef(void); void undefsym(Sym*); vlong vaddr(Adr*); -void wput(ushort); +void wput(long); +void wputl(long); void xdefine(char*, int, vlong); void xfol(Prog*); int zaddr(uchar*, Adr*, Sym*[]); --- /sys/src/cmd/6l/mkfile Mon May 23 20:57:48 2005 +++ /sys/src/cmd/6l/mkfile Wed Mar 27 00:18:22 2013 @@ -10,12 +10,15 @@ list.$O\ enam.$O\ compat.$O\ + elf.$O\ HFILES=\ l.h\ ../6c/6.out.h\ + ../8l/elf.h\ BIN=/$objtype/bin +CFLAGS=$CFLAGS -. -I. CFILES=${OFILES:%.$O=%.c} CFILES=${CFILES:enam.c=../6c/enam.c} UPDATE=\ @@ -28,4 +31,5 @@ enam.$O: ../6c/enam.c $CC $CFLAGS ../6c/enam.c - +elf.$O: ../8l/elf.c + $CC $CFLAGS ../8l/elf.c --- /sys/src/cmd/6l/obj.c Tue Feb 5 22:12:26 2013 +++ /sys/src/cmd/6l/obj.c Wed Mar 27 00:16:29 2013 @@ -68,6 +68,7 @@ outfile = "6.out"; HEADTYPE = -1; INITTEXT = -1; + INITTEXTP = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; @@ -98,6 +99,11 @@ if(a) INITTEXT = atolwhex(a); break; + case 'P': + a = ARGF(); + if(a) + INITTEXTP = atolwhex(a); + break; case 'D': a = ARGF(); if(a) @@ -155,7 +161,7 @@ INITRND = 0x200000; break; case 5: /* elf32 executable */ - HEADR = rnd(52L+3*32L, 16); + HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16); if(INITTEXT == -1) INITTEXT = 0xf0110000L; if(INITDAT == -1) @@ -164,7 +170,7 @@ INITRND = 4096; break; case 6: /* ELF64 executable */ - HEADR = rnd(64L+3*56L, 16); + HEADR = rnd(Ehdr64sz+3*Phdr64sz, 16); if(INITTEXT == -1) INITTEXT = 0x200000+HEADR; if(INITDAT == -1) @@ -173,6 +179,8 @@ INITRND = 0x200000; break; } + if (INITTEXTP == -1) + INITTEXTP = INITTEXT; if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%llux is ignored because of -R0x%lux\n", INITDAT, INITRND); @@ -527,7 +535,8 @@ l |= (e[3] & 0xff) << 16; l |= (e[4] & 0xff) << 24; seek(f, l, 0); - l = read(f, &arhdr, SAR_HDR); + /* need readn to read the dumps (at least) */ + l = readn(f, &arhdr, SAR_HDR); if(l != SAR_HDR) goto bad; if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag))) --- /sys/src/cmd/8l/asm.c Thu Oct 1 05:36:40 2009 +++ /sys/src/cmd/8l/asm.c Wed Mar 27 00:15:33 2013 @@ -2,8 +2,6 @@ #define Dbufslop 100 -#define PADDR(a) ((ulong)(a) & ~0xF0000000) - long entryvalue(void) { @@ -28,15 +26,16 @@ return s->value; } +/* these need to take long arguments to be compatible with elf.c */ void -wputl(ushort w) +wputl(long w) { cput(w); cput(w>>8); } void -wput(ushort w) +wput(long w) { cput(w>>8); cput(w); @@ -61,6 +60,20 @@ } void +llput(vlong v) +{ + lput(v>>32); + lput(v); +} + +void +llputl(vlong v) +{ + lputl(v); + lputl(v>>32); +} + +void strnput(char *s, int n) { for(; *s && n > 0; s++){ @@ -335,51 +348,7 @@ wputl(0x0000); /* overlay number */ break; case 5: - strnput("\177ELF", 4); /* e_ident */ - cput(1); /* class = 32 bit */ - cput(1); /* data = LSB */ - cput(1); /* version = CURRENT */ - strnput("", 9); - wputl(2); /* type = EXEC */ - wputl(3); /* machine = 386 */ - lputl(1L); /* version = CURRENT */ - lputl(PADDR(entryvalue())); /* entry vaddr */ - lputl(52L); /* offset to first phdr */ - lputl(0L); /* offset to first shdr */ - lputl(0L); /* flags = 386 */ - wputl(52); /* Ehdr size */ - wputl(32); /* Phdr size */ - wputl(3); /* # of Phdrs */ - wputl(0); /* Shdr size */ - wputl(0); /* # of Shdrs */ - wputl(0); /* Shdr string size */ - - lputl(1L); /* text - type = PT_LOAD */ - lputl(HEADR); /* file offset */ - lputl(INITTEXT); /* vaddr */ - lputl(PADDR(INITTEXT)); /* paddr */ - lputl(textsize); /* file size */ - lputl(textsize); /* memory size */ - lputl(0x05L); /* protections = RX */ - lputl(INITRND); /* alignment */ - - lputl(1L); /* data - type = PT_LOAD */ - lputl(HEADR+textsize); /* file offset */ - lputl(INITDAT); /* vaddr */ - lputl(PADDR(INITDAT)); /* paddr */ - lputl(datsize); /* file size */ - lputl(datsize+bsssize); /* memory size */ - lputl(0x06L); /* protections = RW */ - lputl(INITRND); /* alignment */ - - lputl(0L); /* data - type = PT_NULL */ - lputl(HEADR+textsize+datsize); /* file offset */ - lputl(0L); - lputl(0L); - lputl(symsize); /* symbol table size */ - lputl(lcsize); /* line number size */ - lputl(0x04L); /* protections = R */ - lputl(0x04L); /* alignment */ + elf32(I386, ELFDATA2LSB, 0, nil); break; } cflush(); --- /sys/src/cmd/8l/l.h Mon Dec 17 20:33:07 2012 +++ /sys/src/cmd/8l/l.h Wed Mar 27 00:15:44 2013 @@ -2,6 +2,7 @@ #include #include #include "../8c/8.out.h" +#include "../8l/elf.h" #ifndef EXTERN #define EXTERN extern @@ -216,6 +217,7 @@ EXTERN long INITDAT; EXTERN long INITRND; EXTERN long INITTEXT; +EXTERN long INITTEXTP; EXTERN char* INITENTRY; /* entry point */ EXTERN Biobuf bso; EXTERN long bsssize; @@ -331,6 +333,8 @@ Sym* lookup(char*, int); void lput(long); void lputl(long); +void llput(vlong v); +void llputl(vlong v); void main(int, char*[]); void mkfwd(void); void* mysbrk(ulong); @@ -344,10 +348,12 @@ long reuse(Prog*, Sym*); long rnd(long, long); void span(void); +void strnput(char*, int); void undef(void); void undefsym(Sym*); long vaddr(Adr*); -void wput(ushort); +void wput(long); +void wputl(long); void xdefine(char*, int, long); void xfol(Prog*); int zaddr(uchar*, Adr*, Sym*[]); --- /sys/src/cmd/8l/mkfile Sun Sep 15 17:00:46 2002 +++ /sys/src/cmd/8l/mkfile Wed Mar 27 00:15:41 2013 @@ -10,12 +10,15 @@ list.$O\ enam.$O\ compat.$O\ + elf.$O\ HFILES=\ l.h\ ../8c/8.out.h\ + ../8l/elf.h\ BIN=/$objtype/bin +CFLAGS=$CFLAGS -. -I. CFILES=${OFILES:%.$O=%.c} CFILES=${CFILES:enam.c=../8c/enam.c} UPDATE=\ @@ -28,4 +31,5 @@ enam.$O: ../8c/enam.c $CC $CFLAGS ../8c/enam.c - +elf.$O: ../8l/elf.c + $CC $CFLAGS ../8l/elf.c --- /sys/src/cmd/8l/obj.c Tue Feb 5 22:12:44 2013 +++ /sys/src/cmd/8l/obj.c Wed Mar 27 00:15:33 2013 @@ -68,6 +68,7 @@ outfile = "8.out"; HEADTYPE = -1; INITTEXT = -1; + INITTEXTP = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; @@ -98,6 +99,11 @@ if(a) INITTEXT = atolwhex(a); break; + case 'P': + a = ARGF(); + if(a) + INITTEXTP = atolwhex(a); + break; case 'D': a = ARGF(); if(a) @@ -202,7 +208,7 @@ Bprint(&bso, "HEADR = 0x%ld\n", HEADR); break; case 5: /* elf executable */ - HEADR = rnd(52L+3*32L, 16); + HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16); if(INITTEXT == -1) INITTEXT = 0x80100020L; if(INITDAT == -1) @@ -211,6 +217,8 @@ INITRND = 4096; break; } + if (INITTEXTP == -1) + INITTEXTP = INITTEXT; if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%lux is ignored because of -R0x%lux\n", INITDAT, INITRND); @@ -511,7 +519,8 @@ l |= (e[3] & 0xff) << 16; l |= (e[4] & 0xff) << 24; seek(f, l, 0); - l = read(f, &arhdr, SAR_HDR); + /* need readn to read the dumps (at least) */ + l = readn(f, &arhdr, SAR_HDR); if(l != SAR_HDR) goto bad; if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag))) --- /sys/src/cmd/kl/obj.c Tue Feb 5 22:13:32 2013 +++ /sys/src/cmd/kl/obj.c Wed Mar 27 00:16:29 2013 @@ -379,7 +379,8 @@ l |= (e[3] & 0xff) << 16; l |= (e[4] & 0xff) << 24; seek(f, l, 0); - l = read(f, &arhdr, SAR_HDR); + /* need readn to read the dumps (at least) */ + l = readn(f, &arhdr, SAR_HDR); if(l != SAR_HDR) goto bad; if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag))) --- /sys/src/cmd/ql/asm.c Sat Feb 16 00:09:22 2013 +++ /sys/src/cmd/ql/asm.c Wed Mar 27 00:17:32 2013 @@ -1,6 +1,5 @@ #include "l.h" -#define KMASK 0xF0000000 #define JMPSZ sizeof(u32int) /* size of bootstrap jump section */ #define LPUT(c)\ @@ -46,52 +45,11 @@ } static void -endelfsectab(void) +elf32jmp(Putl putl) { - seek(cout, HEADR+textsize+datsize+symsize, 0); - lput(1); /* Section name (string tbl index) */ - lput(1); /* Section type */ - lput(2|4); /* Section flags */ - lput(INITTEXT & ~KMASK); /* Section virtual addr at execution */ - lput(HEADR); /* Section file offset */ - lput(textsize); /* Section size in bytes */ - lput(0); /* Link to another section */ - lput(0); /* Additional section information */ - lput(0x10000L); /* Section alignment */ - lput(0); /* Entry size if section holds table */ - - lput(7); /* Section name (string tbl index) */ - lput(1); /* Section type */ - lput(2|1); /* Section flags */ - lput(INITDAT & ~KMASK); /* Section virtual addr at execution */ - lput(HEADR+textsize); /* Section file offset */ - lput(datsize); /* Section size in bytes */ - lput(0); /* Link to another section */ - lput(0); /* Additional section information */ - lput(0x10000L); /* Section alignment */ - lput(0); /* Entry size if section holds table */ - - /* string section header */ - lput(12); /* Section name (string tbl index) */ - lput(3); /* Section type */ - lput(1 << 5); /* Section flags */ - lput(0); /* Section virtual addr at execution */ - lput(HEADR+textsize+datsize+symsize+3*40); /* Section file offset */ - lput(14); /* Section size in bytes */ - lput(0); /* Link to another section */ - lput(0); /* Additional section information */ - lput(1); /* Section alignment */ - lput(0); /* Entry size if section holds table */ - - /* string table */ - cput(0); - strnput(".text", 5); - cput(0); - strnput(".data", 5); - cput(0); - strnput(".strtab", 7); - cput(0); - cput(0); + /* describe a tiny text section at end with jmp to start; see below */ + elf32phdr(putl, PT_LOAD, HEADR+textsize-JMPSZ, 0xFFFFFFFC, 0xFFFFFFFC, + JMPSZ, JMPSZ, R|X, 0); /* text */ } void @@ -142,10 +100,6 @@ } prevpc = pc; } - /* for virtex 4, inject a jmp instruction after other text */ - if(HEADTYPE == 6) - /* branch to absolute entry address (0xfffe2100) */ - lput((18 << 26) | (0x03FFFFFC & entryvalue()) | 2); if(debug['a']) Bprint(&bso, "\n"); @@ -156,7 +110,13 @@ curtext = P; switch(HEADTYPE) { case 6: + /* + * but first, for virtex 4, inject a jmp instruction after + * other text: branch to absolute entry address (0xfffe2100). + */ + lput((18 << 26) | (0x03FFFFFC & entryvalue()) | 2); textsize += JMPSZ; + cflush(); /* fall through */ case 0: case 1: @@ -364,136 +324,16 @@ break; case 5: /* - * customised for blue/gene, - * notably the alignment and KMASK masking. + * intended for blue/gene */ - strnput("\177ELF", 4); /* e_ident */ - CPUT(1); /* class = 32 bit */ - CPUT(2); /* data = MSB */ - CPUT(1); /* version = CURRENT */ - strnput("", 9); - lput((2L<<16)|20L); /* type = EXEC; machine = PowerPC */ - lput(1L); /* version = CURRENT */ - lput(entryvalue() & ~KMASK); /* entry vaddr */ - lput(52L); /* offset to first phdr */ - - if(debug['S']){ - lput(HEADR+textsize+datsize+symsize); /* offset to first shdr */ - lput(0L); /* flags = PPC */ - lput((52L<<16)|32L); /* Ehdr & Phdr sizes*/ - lput((3L<<16)|40L); /* # Phdrs & Shdr size */ - lput((3L<<16)|2L); /* # Shdrs & shdr string size */ - } - else{ - lput(0L); - lput(0L); /* flags = PPC */ - lput((52L<<16)|32L); /* Ehdr & Phdr sizes*/ - lput((3L<<16)|0L); /* # Phdrs & Shdr size */ - lput((3L<<16)|0L); /* # Shdrs & shdr string size */ - } - - lput(1L); /* text - type = PT_LOAD */ - lput(HEADR); /* file offset */ - lput(INITTEXT & ~KMASK); /* vaddr */ - lput(INITTEXT); /* paddr */ - lput(textsize); /* file size */ - lput(textsize); /* memory size */ - lput(0x05L); /* protections = RX */ - lput(0x10000L); /* alignment */ - - lput(1L); /* data - type = PT_LOAD */ - lput(HEADR+textsize); /* file offset */ - lput(INITDAT & ~KMASK); /* vaddr */ - lput(INITDAT); /* paddr */ - lput(datsize); /* file size */ - lput(datsize); /* memory size */ - lput(0x07L); /* protections = RWX */ - lput(0x10000L); /* alignment */ - - lput(0L); /* data - type = PT_NULL */ - lput(HEADR+textsize+datsize); /* file offset */ - lput(0L); /* vaddr */ - lput(0L); /* paddr */ - lput(symsize); /* symbol table size */ - lput(lcsize); /* line number size */ - lput(0x04L); /* protections = R */ - lput(0x04L); /* alignment code?? */ - cflush(); - - if(debug['S']) - endelfsectab(); + elf32(POWER, ELFDATA2MSB, 0, nil); break; case 6: /* - * customised for virtex 4 boot, - * notably the alignment and KMASK masking. + * intended for virtex 4 boot */ - strnput("\177ELF", 4); /* e_ident */ - CPUT(1); /* class = 32 bit */ - CPUT(2); /* data = MSB */ - CPUT(1); /* version = CURRENT */ - strnput("", 9); - lput((2L<<16)|20L); /* type = EXEC; machine = PowerPC */ - lput(1L); /* version = CURRENT */ - lput(entryvalue()); /* entry vaddr */ - lput(52L); /* offset to first phdr */ - - debug['S'] = 1; /* no symbol table */ - if(debug['S']){ - lput(HEADR+textsize+datsize+symsize); /* offset to first shdr */ - lput(0L); /* flags = PPC */ - lput((52L<<16)|32L); /* Ehdr & Phdr sizes*/ - lput((4L<<16)|40L); /* # Phdrs & Shdr size */ - lput((3L<<16)|2L); /* # Shdrs & shdr string size */ - } - else{ - lput(0L); - lput(0L); /* flags = PPC */ - lput((52L<<16)|32L); /* Ehdr & Phdr sizes*/ - lput((4L<<16)|0L); /* # Phdrs & Shdr size */ - lput((3L<<16)|0L); /* # Shdrs & shdr string size */ - } - - lput(1L); /* text - type = PT_LOAD */ - lput(HEADR); /* file offset */ - lput(INITTEXT); /* vaddr */ - lput(INITTEXT); /* paddr */ - lput(textsize-JMPSZ); /* file size */ - lput(textsize-JMPSZ); /* memory size */ - lput(0x05L); /* protections = RX */ - lput(0); /* alignment */ - - lput(1L); /* data - type = PT_LOAD */ - lput(HEADR+textsize); /* file offset */ - lput(INITDAT); /* vaddr */ - lput(INITDAT); /* paddr */ - lput(datsize); /* file size */ - lput(datsize+bsssize); /* memory size */ - lput(0x07L); /* protections = RWX */ - lput(0); /* alignment */ - - lput(0L); /* data - type = PT_NULL */ - lput(HEADR+textsize+datsize); /* file offset */ - lput(0L); /* vaddr */ - lput(0L); /* paddr */ - lput(symsize); /* symbol table size */ - lput(lcsize); /* line number size */ - lput(0x04L); /* protections = R */ - lput(0x04L); /* alignment code?? */ - - /* add tiny text section at end with jmp to start */ - lput(1L); /* text - type = PT_LOAD */ - lput(HEADR+textsize-JMPSZ); /* file offset */ - lput(0xFFFFFFFC); /* vaddr */ - lput(0xFFFFFFFC); /* paddr */ - lput(JMPSZ); /* file size */ - lput(JMPSZ); /* memory size */ - lput(0x05L); /* protections = RX */ - lput(0); /* disable alignment */ - cflush(); - - if(debug['S']) - endelfsectab(); + debug['S'] = 1; /* symbol table */ + elf32(POWER, ELFDATA2MSB, 1, elf32jmp); break; } cflush(); @@ -528,10 +368,47 @@ } void -lput(long l) +wputl(long l) { + cbp[0] = l; + cbp[1] = l>>8; + cbp += 2; + cbc -= 2; + if(cbc <= 0) + cflush(); +} +void +lput(long l) +{ LPUT(l); +} + +void +lputl(long c) +{ + cbp[0] = (c); + cbp[1] = (c)>>8; + cbp[2] = (c)>>16; + cbp[3] = (c)>>24; + cbp += 4; + cbc -= 4; + if(cbc <= 0) + cflush(); +} + +void +llput(vlong v) +{ + lput(v>>32); + lput(v); +} + +void +llputl(vlong v) +{ + lputl(v); + lputl(v>>32); } void --- /sys/src/cmd/ql/l.h Mon Dec 17 20:33:07 2012 +++ /sys/src/cmd/ql/l.h Wed Mar 27 00:18:09 2013 @@ -2,6 +2,7 @@ #include #include #include "../qc/q.out.h" +#include "../8l/elf.h" #ifndef EXTERN #define EXTERN extern @@ -189,6 +190,7 @@ EXTERN long INITDAT; /* data location */ EXTERN long INITRND; /* data round above text location */ EXTERN long INITTEXT; /* text location */ +EXTERN long INITTEXTP; /* text location (physical) */ EXTERN char* INITENTRY; /* entry point */ EXTERN long autosize; EXTERN Biobuf bso; @@ -303,7 +305,10 @@ void listinit(void); void initmuldiv(void); Sym* lookup(char*, int); +void llput(vlong); +void llputl(vlong); void lput(long); +void lputl(long); void mkfwd(void); void* mysbrk(ulong); void names(void); @@ -327,9 +332,11 @@ long rnd(long, long); void sched(Prog*, Prog*); void span(void); +void strnput(char*, int); void undef(void); void undefsym(Sym*); void wput(long); +void wputl(long); void xdefine(char*, int, long); void xfol(Prog*); void zerosig(char*); --- /sys/src/cmd/ql/mkfile Thu Jul 8 17:06:06 2004 +++ /sys/src/cmd/ql/mkfile Wed Mar 27 00:18:22 2013 @@ -14,15 +14,20 @@ cnam.$O\ sched.$O\ compat.$O\ + elf.$O\ HFILES=\ l.h\ ../qc/q.out.h\ + ../8l/elf.h\ BIN=/$objtype/bin +CFLAGS=$CFLAGS -. -I. >8; + cbp[1] = l; + cbp += 2; + cbc -= 2; + if(cbc <= 0) + cflush(); +} + +void +wputl(long l) +{ + + cbp[0] = l; + cbp[1] = l>>8; + cbp += 2; + cbc -= 2; + if(cbc <= 0) + cflush(); +} + +void lput(long l) /* emit long in big-endian byte order */ { LBEPUT(l); } +void +lputl(long l) /* emit long in big-endian byte order */ +{ + LLEPUT(l); +} + +void +llput(vlong v) +{ + lput(v>>32); + lput(v); +} + +void +llputl(vlong v) +{ + lputl(v); + lputl(v>>32); +} + long entryvalue(void) { @@ -391,64 +441,7 @@ lput(0x80L); /* flags */ break; case 5: - /* first part of ELF is byte-wide parts, thus no byte-order issues */ - strnput("\177ELF", 4); /* e_ident */ - CPUT(1); /* class = 32 bit */ - CPUT(little? 1: 2); /* data: 1 = LSB, 2 = MSB */ - CPUT(1); /* version = 1 */ - strnput("", 9); /* reserved for expansion */ - /* entire remainder of ELF file is in target byte order */ - - /* file header part of ELF header */ - objhput(2); /* type = EXEC */ - objhput(8); /* machine = MIPS */ - objput(1L); /* version = CURRENT */ - objput(entryvalue()); /* entry vaddr */ - objput(52L); /* offset to first phdr */ - objput(0L); /* offset to first shdr */ - objput(0L); /* flags (no MIPS flags defined) */ - objhput(52); /* Ehdr size */ - objhput(32); /* Phdr size */ - objhput(3); /* # of Phdrs */ - objhput(0); /* Shdr size */ - objhput(0); /* # of Shdrs */ - objhput(0); /* Shdr string size */ - - /* "Program headers" - one per chunk of file to load */ - - /* - * include ELF headers in text -- 8l doesn't, - * but in theory it aids demand loading. - */ - objput(1L); /* text: type = PT_LOAD */ - objput(0L); /* file offset */ - objput(INITTEXT-HEADR); /* vaddr */ - objput(INITTEXT-HEADR); /* paddr */ - objput(HEADR+textsize); /* file size */ - objput(HEADR+textsize); /* memory size */ - objput(0x05L); /* protections = RX */ - objput(0x1000L); /* page-align text off's & vaddrs */ - - objput(1L); /* data: type = PT_LOAD */ - objput(HEADR+textsize); /* file offset */ - objput(INITDAT); /* vaddr */ - objput(INITDAT); /* paddr */ - objput(datsize); /* file size */ - objput(datsize+bsssize); /* memory size */ - objput(0x06L); /* protections = RW */ - if(INITDAT % 4096 == 0 && (HEADR + textsize) % 4096 == 0) - objput(0x1000L); /* page-align data off's & vaddrs */ - else - objput(0L); /* do not claim alignment */ - - objput(0L); /* P9 symbols: type = PT_NULL */ - objput(HEADR+textsize+datsize); /* file offset */ - objput(0L); - objput(0L); - objput(symsize); /* symbol table size */ - objput(lcsize); /* line number size */ - objput(0x04L); /* protections = R */ - objput(0L); /* do not claim alignment */ + elf32(MIPS, little? ELFDATA2LSB: ELFDATA2MSB, 0, nil); break; case 6: break; --- /sys/src/cmd/vl/l.h Mon Dec 17 20:33:07 2012 +++ /sys/src/cmd/vl/l.h Wed Mar 27 00:18:09 2013 @@ -2,6 +2,7 @@ #include #include #include "../vc/v.out.h" +#include "../8l/elf.h" #ifndef EXTERN #define EXTERN extern @@ -189,6 +190,7 @@ EXTERN long INITDAT; /* data location */ EXTERN long INITRND; /* data round above text location */ EXTERN long INITTEXT; /* text location */ +EXTERN long INITTEXTP; /* text location (physical) */ EXTERN char* INITENTRY; /* entry point */ EXTERN long autosize; EXTERN Biobuf bso; @@ -282,6 +284,7 @@ void buildrep(int, int); void cflush(void); int cmp(int, int); +void cput(long); int compound(Prog*); double cputime(void); void datblk(long, long, int); @@ -305,7 +308,10 @@ void loadlib(void); void listinit(void); Sym* lookup(char*, int); +void llput(vlong); +void llputl(vlong); void lput(long); +void lputl(long); void bput(long); void mkfwd(void); void* mysbrk(ulong); @@ -331,6 +337,8 @@ void span(void); void strnput(char*, int); void undef(void); +void wput(long); +void wputl(long); void xdefine(char*, int, long); void xfol(Prog*); void xfol(Prog*); --- /sys/src/cmd/vl/mkfile Sun Dec 12 02:15:42 1999 +++ /sys/src/cmd/vl/mkfile Wed Mar 27 00:18:23 2013 @@ -12,16 +12,21 @@ span.$O\ enam.$O\ compat.$O\ + elf.$O\ HFILES=\ l.h\ ../vc/v.out.h\ + ../8l/elf.h\ BIN=/$objtype/bin +CFLAGS=$CFLAGS -. -I.