From 9df824055306985290f48b453be62dc62b100c63 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Mon, 6 Nov 2000 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2000-11-06 --- alphapc/fns.h | 1 + bitsy/dat.h | 1 + "bitsy/dev\302\265c.c" | 2 +- bitsy/fns.h | 3 +- bitsy/l.s | 26 +++++-------- bitsy/mmu.c | 4 +- bitsy/sa1110uart.c | 8 +--- bitsy/screen.c | 24 ++++++++---- carrera/fns.h | 1 + mpc/fns.h | 1 + pc/clock.c | 59 +---------------------------- pc/dat.h | 1 + pc/devi82365.c | 4 ++ pc/fns.h | 1 + port/devcons.c | 7 ++-- port/portclock.c | 85 ++++++++++++++++++++++++++++++++++++++++++ port/portfns.h | 2 + port/proc.c | 2 +- port/taslock.c | 26 ++++++++----- 19 files changed, 150 insertions(+), 108 deletions(-) create mode 100644 port/portclock.c diff --git a/alphapc/fns.h b/alphapc/fns.h index 24392836d183a4c851065f409367aa2735766b3d..4b55bddd843bb970f5c0a3c9d31ed949add246c1 100644 --- a/alphapc/fns.h +++ b/alphapc/fns.h @@ -92,6 +92,7 @@ void trapinit(void); void unaligned(void); ulong upamalloc(ulong, int, int); void upafree(ulong, int); +#define userureg(ur) ((ur)->status & UMODE) void wrent(int, void*); void wrvptptr(uvlong); diff --git a/bitsy/dat.h b/bitsy/dat.h index 858018e70538dfd534a3ff53e3046f3ef4152781..7b5e039cb5b283b304ad7193f8fe8c9b584a2b6c 100644 --- a/bitsy/dat.h +++ b/bitsy/dat.h @@ -108,6 +108,7 @@ struct Mach Label sched; /* scheduler wakeup */ Lock alarmlock; /* access to alarm list */ void* alarm; /* alarms bound to this clock */ + int inclockintr; ulong fairness; /* for runproc */ diff --git "a/bitsy/dev\302\265c.c" "b/bitsy/dev\302\265c.c" index f632117262fe9faf63b99f02ca30af2bd0061f0b..0420befb5c7f1e35ee4ba1838e646a2dc7d11b2b 100644 --- "a/bitsy/dev\302\265c.c" +++ "b/bitsy/dev\302\265c.c" @@ -346,7 +346,7 @@ static long sendmsgwithack(BLbacklight, data, cmd->nf); break; case Qcruft: - lcdtweak(cmd); +// lcdtweak(cmd); break; default: error(Ebadarg); diff --git a/bitsy/fns.h b/bitsy/fns.h index fc7872a836c8881512c371cec64129642b33b1da..89b62cb5aacce9311b4d4e745bbedb8e38fa2215 100644 --- a/bitsy/fns.h +++ b/bitsy/fns.h @@ -3,7 +3,7 @@ void cacheflush(void); void cachewb(void); void cachewbaddr(void*); -void cachewbregion(void*, int); +void cachewbregion(ulong, int); void dcacheinvalidate(void); int cistrcmp(char*, char*); int cistrncmp(char*, char*, int); @@ -71,6 +71,7 @@ int uartstageoutput(Uart*); void uartkick(void*); void uartrecv(Uart*, char); int unsac(uchar*, uchar*, int, int); +#define userureg(ur) (((ur)->psr & PsrMask) == PsrMusr) void vectors(void); void vtable(void); void wbflush(void); diff --git a/bitsy/l.s b/bitsy/l.s index 7f9a0d1f6fa1a02d454f22ad478bc9f053f442a8..f61ecec698fd2d0beec359e742bef965599d42a8 100644 --- a/bitsy/l.s +++ b/bitsy/l.s @@ -51,7 +51,7 @@ TEXT cacheflush(SB), $-4 ADD $(8*1024),R0,R1 _cfloop: MOVW.P 32(R0),R2 - CMP R0,R1 + CMP.S R0,R1 BNE _cfloop /* drain write buffer and invalidate i&d cache contents */ @@ -68,12 +68,13 @@ _cfloop: /* write back d cache */ TEXT cachewb(SB), $-4 /* write back any dirty data */ +_cachewb: MOVW $0xe0000000,R0 ADD $(8*1024),R0,R1 _cwbloop: MOVW.P 32(R0),R2 - CMP R0,R1 - BNE _cfloop + CMP.S R0,R1 + BNE _cwbloop /* drain write buffer */ MCR CpMMU, 0, R0, C(CpCacheFlush), C(0xa), 4 @@ -88,14 +89,15 @@ TEXT cachewbaddr(SB), $-4 /* write back a region of cache lines */ TEXT cachewbregion(SB), $-4 MOVW 4(FP),R1 - BIC $31,R0 + CMP.S $(4*1024),R1 + BGT _cachewb ADD R0,R1 - ADD $32,R1 -_cfrloop: + BIC $31,R0 +_cwbrloop: MCR CpMMU, 0, R0, C(CpCacheFlush), C(0xa), 1 ADD $32,R0 CMP.S R0,R1 - BNE _cfrloop + BGT _cwbrloop B _wbflush /* invalidate the dcache */ @@ -408,16 +410,6 @@ TEXT spsrr(SB), $-4 MOVW SPSR, R0 RET -TEXT aamloop(SB), $-4 /* 3 */ -_aamloop: - MOVW R0, R0 /* 1 */ - MOVW R0, R0 /* 1 */ - MOVW R0, R0 /* 1 */ - SUB $1, R0 /* 1 */ - CMP $0, R0 /* 1 */ - BNE _aamloop /* 3 */ - RET /* 3 */ - TEXT getcallerpc(SB), $-4 MOVW 0(R13), R0 RET diff --git a/bitsy/mmu.c b/bitsy/mmu.c index 04cd25a9b9058db674a999320198239e78f9edc4..361350ff4256415de5ed81a538b88e5d65b7d902 100644 --- a/bitsy/mmu.c +++ b/bitsy/mmu.c @@ -318,7 +318,7 @@ mmurelease(Proc* p) p->mmufree = nil; memset(l1table, 0, sizeof(p->l1table)); - cachewbregion(l1table, sizeof(p->l1table)); + cachewbregion((ulong)l1table, sizeof(p->l1table)); } void @@ -340,7 +340,7 @@ mmuswitch(Proc *p) memmove(l1table, p->l1table, sizeof(p->l1table)); /* make sure map is in memory */ - cachewbregion(l1table, sizeof(p->l1table)); + cachewbregion((ulong)l1table, sizeof(p->l1table)); /* lose any possible stale tlb entries */ mmuinvalidate(); diff --git a/bitsy/sa1110uart.c b/bitsy/sa1110uart.c index 8052761a5445ca4683912b8433f60f80602b41d8..e491a1f0f58d658be47a93246a97330e3b8a698f 100644 --- a/bitsy/sa1110uart.c +++ b/bitsy/sa1110uart.c @@ -316,13 +316,7 @@ sa1100_uartkick(Uart *p) if(p->cts == 0 || p->blocked) return; - /* - * 128 here is an arbitrary limit to make sure - * we don't stay in this loop too long. If the - * chips output queue is longer than 128, too - * bad -- presotto - */ - for(i = 0; i < 128; i++){ + for(i = 0; i < 1024; i++){ if(!(R(p)->status[1] & Tnotfull)){ R(p)->ctl[3] |= Tintena; break; diff --git a/bitsy/screen.c b/bitsy/screen.c index f46d58506386e4200cab2240c2b207fbadebea3d..5139680dec8c2c5945f710fe64b40866bc9752b7 100644 --- a/bitsy/screen.c +++ b/bitsy/screen.c @@ -15,7 +15,7 @@ #define MINX 8 -int landscape; /* orientation of the screen, default is 0: portait */ +int landscape = 0; /* orientation of the screen, default is 0: portait */ enum { Wid = 240, @@ -164,6 +164,7 @@ lcdstop(void) { static void lcdinit(void) { + /* the following line works because main memory is direct mapped */ lcd->dbar1 = framebuf->palette; lcd->lccr3 = pcd<lccr2 = (Wid-1)< Wid) r.max.x = Wid; + if (r.min.y < 0) r.min.y = 0; + if (r.max.y > Ht) r.max.y = Ht; for (x = r.min.x; x < r.max.x; x++) for (y = r.min.y; y < r.max.y; y++) - framebuf->pixel[(x+1)*Ht-y-1] = vscreen[y*Wid+x]; - cachewb(); + framebuf->pixel[(x+1)*Ht-1-y] = vscreen[y*Wid+x]; + start = (ulong)&framebuf->pixel[(r.min.x+1)*Ht-1-(r.max.y-1)]; + end = (ulong)&framebuf->pixel[(r.max.x-1+1)*Ht-1-(r.min.y)]; + } else { + start = (ulong)&framebuf->pixel[r.min.y*Ht + r.min.x]; + end = (ulong)&framebuf->pixel[(r.max.y-1)*Ht + r.max.x - 1]; + } + cachewbregion(start, end-start); } /* @@ -269,7 +280,7 @@ attachscreen(Rectangle *r, ulong *chan, int* d, int *width, int *softscreen) *d = gscreen->depth; *chan = gscreen->chan; *width = gscreen->width; - *softscreen = landscape == 0; + *softscreen = (landscape == 0); return (uchar*)gscreen->data->bdata; } @@ -337,7 +348,6 @@ screenwin(void) back = memwhite; conscol = memblack; - /* a lot of work to get a orange color */ orange = allocmemimage(Rect(0,0,1,1), RGB16); orange->flags |= Frepl; orange->clipr = gscreen->r; diff --git a/carrera/fns.h b/carrera/fns.h index e9fa35b8b624d112fd292ece348494807351f6bd..34e32416f719365dc5557581d252cde573df2e45 100644 --- a/carrera/fns.h +++ b/carrera/fns.h @@ -61,6 +61,7 @@ int tas(ulong*); void tlbinit(void); ulong tlbvirt(void); void touser(void*); +#define userureg(ur) ((ur)->status & KUSER) void vecinit(void); void vector0(void); void vector100(void); diff --git a/mpc/fns.h b/mpc/fns.h index 7d65b60473d4270e3378adebe37b1a3db0ec594a..3f7e9237786ffd38ce52982c8940188294ed14ca 100644 --- a/mpc/fns.h +++ b/mpc/fns.h @@ -103,6 +103,7 @@ void tlbflushall(void); void uartinstall(void); void uartwait(void); /* debugging */ int unsac(uchar *dst, uchar *src, int n, int nsrc); +#define userureg(ur) ((ur)->status & KUSER) void wbflush(void); #define waserror() (up->nerrlab++, setlabel(&up->errlab[up->nerrlab-1])) diff --git a/pc/clock.c b/pc/clock.c index 7d14d6487b6689e495ff47bfa9134d8a8be957e1..a35b2309f0b8490a467dec259ce8859b1ef941b7 100644 --- a/pc/clock.c +++ b/pc/clock.c @@ -6,60 +6,12 @@ #include "io.h" #include "ureg.h" -void (*kproftimer)(ulong); - -typedef struct Clock0link Clock0link; -typedef struct Clock0link { - void (*clock)(void); - Clock0link* link; -} Clock0link; - -static Clock0link *clock0link; -static Lock clock0lock; - -void -addclock0link(void (*clock)(void)) -{ - Clock0link *lp; - - if((lp = malloc(sizeof(Clock0link))) == 0){ - print("addclock0link: too many links\n"); - return; - } - ilock(&clock0lock); - lp->clock = clock; - lp->link = clock0link; - clock0link = lp; - iunlock(&clock0lock); -} - void clockintr(Ureg* ureg, void*) { - Clock0link *lp; - // this needs to be here for synchronizing mp clocks // see mp.c's squidboy() fastticks(nil); - m->ticks++; - if(m->proc) - m->proc->pc = ureg->pc; - - accounttime(); - if(kproftimer != nil) - kproftimer(ureg->pc); - if((active.machs & (1<machno)) == 0) - return; - if(active.exiting && (active.machs & (1<machno))) - exit(0); - - checkalarms(); - if(m->machno == 0){ - ilock(&clock0lock); - for(lp = clock0link; lp; lp = lp->link) - lp->clock(); - iunlock(&clock0lock); - } if(m->flushmmu){ if(up) @@ -67,16 +19,7 @@ clockintr(Ureg* ureg, void*) m->flushmmu = 0; } - if(up == 0 || up->state != Running) - return; - - if(anyready()) - sched(); - - if((ureg->cs & 0xFFFF) == UESEL) { - (*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1); - segclock(ureg->pc); - } + portclock(ureg); } void diff --git a/pc/dat.h b/pc/dat.h index 29c17aa66115aca20289d18b710ee2ba8871b7ee..54fe86decb4b843760d86edbd4df30d3cf674f2c 100644 --- a/pc/dat.h +++ b/pc/dat.h @@ -160,6 +160,7 @@ struct Mach Label sched; /* scheduler wakeup */ Lock alarmlock; /* access to alarm list */ void* alarm; /* alarms bound to this clock */ + int inclockintr; ulong fairness; /* for runproc */ diff --git a/pc/devi82365.c b/pc/devi82365.c index b24d980dfc5cc28d057c7f918bf27c5c0ce8564c..1157afd2500a9e7c731dacbbb20a93b8bd49549b 100644 --- a/pc/devi82365.c +++ b/pc/devi82365.c @@ -441,21 +441,25 @@ pcmspecial(char *idstr, ISAConf *isa) static int resetdone; i82365reset(); +print("pcmcia: looking for %s: ", idstr); for(pp = slot; pp < lastslot; pp++){ if(pp->special) continue; /* already taken */ increfp(pp); if(pp->occupied) { +print("[%8.8s]", pp->verstr); if(strstr(pp->verstr, idstr)) if(isa == 0 || pcmio(pp->slotno, isa) == 0){ pp->special = 1; +print(" - found\n"); return pp->slotno; } } else pp->special = 1; decrefp(pp); } +print("\n"); return -1; } diff --git a/pc/fns.h b/pc/fns.h index e812a5ee4052d39bdbc2f8cbac4ed65321161187..a8bdb2c5545ea44b278e750591779cffe0d92881 100644 --- a/pc/fns.h +++ b/pc/fns.h @@ -120,6 +120,7 @@ ulong umbrwmalloc(ulong, int, int); void umbrwfree(ulong, int); ulong upamalloc(ulong, int, int); void upafree(ulong, int); +#define userureg(ur) (((ur)->cs & 0xFFFF) == UESEL) void vectortable(void); void wrmsr(int, vlong); void wbflush(void); diff --git a/port/devcons.c b/port/devcons.c index d68b960bc050ce4d6867fe1d727d31b4866901ad..98412a59c3ad13f230c46185c24835eea080dbe2 100644 --- a/port/devcons.c +++ b/port/devcons.c @@ -365,10 +365,9 @@ echo(char *buf, int n) consdebug(); return; case 'p': - //x = spllo(); - //procdump(); - //splx(x); -print("procdump temporarily disabled\n"); + x = spllo(); + procdump(); + splx(x); return; case 'q': scheddump(); diff --git a/port/portclock.c b/port/portclock.c new file mode 100644 index 0000000000000000000000000000000000000000..78dbd20036c454b1487327b3816e9bb115c413ac --- /dev/null +++ b/port/portclock.c @@ -0,0 +1,85 @@ +#include "u.h" +#include "../port/lib.h" +#include "mem.h" +#include "dat.h" +#include "fns.h" +#include "io.h" +#include "ureg.h" + +void (*kproftimer)(ulong); + +typedef struct Clock0link Clock0link; +typedef struct Clock0link { + void (*clock)(void); + Clock0link* link; +} Clock0link; + +static Clock0link *clock0link; +static Lock clock0lock; + +void +addclock0link(void (*clock)(void)) +{ + Clock0link *lp; + + if((lp = malloc(sizeof(Clock0link))) == 0){ + print("addclock0link: too many links\n"); + return; + } + ilock(&clock0lock); + lp->clock = clock; + lp->link = clock0link; + clock0link = lp; + iunlock(&clock0lock); +} + +void +portclock(Ureg *ur) +{ + Clock0link *lp; + + m->ticks++; + if(m->proc) + m->proc->pc = ur->pc; + + if(m->inclockintr) + return; /* interrupted ourself */ + m->inclockintr = 1; + + accounttime(); + + if(kproftimer != nil) + kproftimer(ur->pc); + + if((active.machs&(1<machno)) == 0) + return; + + if(active.exiting && (active.machs & (1<machno))) { + print("someone's exiting\n"); + exit(0); + } + + checkalarms(); + if(m->machno == 0){ + ilock(&clock0lock); + for(lp = clock0link; lp; lp = lp->link){ + lp->clock(); + splhi(); + } + iunlock(&clock0lock); + } + + m->inclockintr = 0; + + if(up == 0 || up->state != Running) + return; + + if(anyready()) + sched(); + + /* user profiling clock */ + if(userureg(ur)) { + (*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1); + segclock(ur->pc); + } +} diff --git a/port/portfns.h b/port/portfns.h index fd09446ff1966b0f90d789776ea12277b0e25ffd..318155c5db51ebb1eeff7c4c65731619975ef157 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -200,8 +200,10 @@ void pgrpnote(ulong, char*, long, int); Pgrp* pgrptab(int); void pio(Segment *, ulong, ulong, Page **); #define poperror() up->nerrlab-- +void portclock(Ureg*); int postnote(Proc*, int, char*, int); int pprint(char*, ...); +void prflush(void); void printinit(void); ulong procalarm(ulong); int proccounter(char *name); diff --git a/port/proc.c b/port/proc.c index 2aa7721edb5c9d43ad0e908de60bffb35f46b8c3..d2bd92a47498aa519748eccfe91eb426f13be26c 100644 --- a/port/proc.c +++ b/port/proc.c @@ -938,7 +938,7 @@ procdump(void) continue; dumpaproc(p); - delay(150); + prflush(); } } diff --git a/port/taslock.c b/port/taslock.c index 751972d38bb542754d50d96f3246dc1d12adca26..19a763f72a15b9a8baf4a91d124b7de24bb7d093 100644 --- a/port/taslock.c +++ b/port/taslock.c @@ -11,22 +11,25 @@ struct { ulong inglare; } lockstats; +static void +dumplockmem(char *tag, Lock *l) +{ + uchar *cp; + int i; + + iprint("%s: ", tag); + cp = (uchar*)l; + for(i = 0; i < 64; i++) + iprint("%2.2ux ", cp[i]); + iprint("\n"); +} + void lockloop(Lock *l, ulong pc) { Proc *p; p = l->p; -{ -ulong x = (ulong)p; -uchar *cp; -int i; -if(x < KTZERO) { - cp = (uchar*)l; - for(i = 0; i < 64; i++) print("%2.2ux ", cp[i]); - print("\n"); -} -} print("lock loop key 0x%lux pc 0x%lux held by pc 0x%lux proc %lud\n", l->key, pc, l->pc, p ? p->pid : 0); dumpaproc(up); @@ -120,7 +123,10 @@ ilock(Lock *l) } else oldpri = 0; if(conf.nmach < 2) +{ +dumplockmem("ilock:", l); panic("ilock: no way out: pc %uX\n", pc); +} for(;;){ lockstats.inglare++;