From 3179b983938f02f22a8f91c5dbdfa29f902842b7 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 11 Apr 2002 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2002-04-11 --- bitsy/clock.c | 8 +++-- bitsy/power.c | 7 ++++ boot/boot.c | 5 ++- pc/cycintr.c | 96 ------------------------------------------------- pc/devarch.c | 9 +++-- pc/etherelnk3.c | 14 +++----- pc/fns.h | 1 + pc/kbd.c | 24 +++++++------ pc/main.c | 3 +- pc/mp.c | 14 ++++++-- port/chan.c | 14 ++++---- port/edf.c | 10 +++--- port/pgrp.c | 2 -- port/tod.c | 6 ++-- 14 files changed, 69 insertions(+), 144 deletions(-) delete mode 100644 pc/cycintr.c diff --git a/bitsy/clock.c b/bitsy/clock.c index a8893d57607166abbffcc863a6cbe5e7f68bf1ce..08b0932bdfae6ab634bd9e938a3db15f0987c26d 100644 --- a/bitsy/clock.c +++ b/bitsy/clock.c @@ -19,8 +19,10 @@ typedef struct OSTimer OSTimer *timerregs = (OSTimer*)OSTIMERREGS; static int clockinited; -static void clockintr(Ureg*, void*); -static uvlong when; /* scheduled time of next interrupt */ +static void clockintr(Ureg*, void*); +static uvlong when; /* scheduled time of next interrupt */ + +long timeradjust; enum { @@ -105,7 +107,7 @@ timerset(uvlong v) /* post next interrupt: calculate # of tics from now */ tics = next - timerregs->oscr - Maxfreq; if (tics > Minfreq){ - iprint("%lud %lud %lud %d\n", next, tics, timerregs->oscr, Minfreq); + timeradjust++; next = timerregs->oscr + Maxfreq; } timerregs->osmr[0] = next; diff --git a/bitsy/power.c b/bitsy/power.c index 6d8cac5823bb8fe010f1cae93148e162ccfe8caf..e982ba39491ade35b5dcf513e93bb81b3efb6bac 100644 --- a/bitsy/power.c +++ b/bitsy/power.c @@ -266,9 +266,16 @@ onoffintr(Ureg* , void*) wakeup(&powerr); } +static void +blanktimer(void) +{ + drawactive(0); +} + void powerinit(void) { + addclock0link(blanktimer); intrenable(GPIOrising, bitno(GPIO_PWR_ON_i), onoffintr, nil, "on/off"); } diff --git a/boot/boot.c b/boot/boot.c index a41e3b436d8c0e788e1a076b90ed551592ee91e0..b3f685e92c9f62fa2f8e0e799998db98e4d5f290 100644 --- a/boot/boot.c +++ b/boot/boot.c @@ -229,10 +229,13 @@ rootserver(char *arg) /* parse replies */ for(;;){ outin(prompt, reply, sizeof(reply)); + if(strlen(reply) == 0) + continue; mp = findmethod(reply); if(mp){ HaveMethod: - bargc = tokenize(reply, bargv, Nbarg-1); + bargc = tokenize(reply, bargv, Nbarg-2); + bargv[bargc] = nil; cp = strchr(reply, '!'); if(cp) strcpy(sys, cp+1); diff --git a/pc/cycintr.c b/pc/cycintr.c deleted file mode 100644 index a7cfe186c0641cfdae962830afc07c3651fb546e..0000000000000000000000000000000000000000 --- a/pc/cycintr.c +++ /dev/null @@ -1,96 +0,0 @@ -#include "u.h" -#include "../port/lib.h" -#include "mem.h" -#include "dat.h" -#include "fns.h" -#include "io.h" - - -static struct -{ - Lock; - Timer *ci; -}timers; - -/* - * called by clockintrsched() - */ -vlong -timernext(void) -{ - Timer *ci; - vlong when; - - ilock(&timers); - when = 0; - ci = timers.ci; - if(ci != nil) - when = ci->when; - iunlock(&timers); - return when; -} - -vlong -checktimer(Ureg *u, void*) -{ - Timer *ci; - vlong when; - - ilock(&timers); - while(ci = timers.ci){ - when = ci->when; - if(when > fastticks(nil)){ - iunlock(&timers); - return when; - } - timers.ci = ci->next; - iunlock(&timers); - (*ci->f)(u, ci); - ilock(&timers); - } - iunlock(&timers); - return 0; -} - -void -timeradd(Timer *nci) -{ - Timer *ci, **last; - - ilock(&timers); - last = &timers.ci; - while(ci = *last){ - if(ci == nci){ - *last = ci->next; - break; - } - last = &ci->next; - } - - last = &timers.ci; - while(ci = *last){ - if(ci->when > nci->when) - break; - last = &ci->next; - } - nci->next = *last; - *last = nci; - iunlock(&timers); -} - -void -timerdel(Timer *dci) -{ - Timer *ci, **last; - - ilock(&timers); - last = &timers.ci; - while(ci = *last){ - if(ci == dci){ - *last = ci->next; - break; - } - last = &ci->next; - } - iunlock(&timers); -} diff --git a/pc/devarch.c b/pc/devarch.c index 90c5ae19c0c61bec96b8058ef803abe336ba1c61..ad4f885cc3a7802d35f8ff8d25033692763ff024 100644 --- a/pc/devarch.c +++ b/pc/devarch.c @@ -734,14 +734,13 @@ archinit(void) } /* - * Decide whether to use copy-on-reference (386 and mp). + * Decide whether to use copy-on-reference (386 and mp). + * We get another chance to set it in mpinit() for a + * multiprocessor. */ - if(X86FAMILY(m->cpuidax) == 3 || conf.nmach > 1) + if(X86FAMILY(m->cpuidax) == 3) conf.copymode = 1; - if(X86FAMILY(m->cpuidax) >= 5 && conf.nmach > 1) - coherence = wbflush; - addarchfile("cputype", 0444, cputyperead, nil); } diff --git a/pc/etherelnk3.c b/pc/etherelnk3.c index 9178799ca080b06d0d7375270765e2bbf158623c..3d3f9edb6fab5a341b8bab6b757441fb41793d0e 100644 --- a/pc/etherelnk3.c +++ b/pc/etherelnk3.c @@ -1388,10 +1388,8 @@ tcm509isa(void) * it fully. */ while(port = activate()){ - if(ioalloc(port, 0x10, 0, "tcm509isa") < 0){ - print("tcm509isa: port 0x%uX in use\n", port); + if(ioalloc(port, 0x10, 0, "tcm509isa") < 0) continue; - } /* * 6. Tag the adapter so it won't respond in future. @@ -1450,10 +1448,9 @@ tcm5XXeisa(void) */ for(slot = 1; slot < MaxEISA; slot++){ port = slot*0x1000; - if(ioalloc(port, 0x1000, 0, "tcm5XXeisa") < 0){ - print("tcm5XXeisa: port 0x%uX in use\n", port); + if(ioalloc(port, 0x1000, 0, "tcm5XXeisa") < 0) continue; - } + if(ins(port+0xC80+ManufacturerID) != 0x6D50){ iofree(port); continue; @@ -1493,10 +1490,9 @@ tcm59Xpci(void) continue; port = p->mem[0].bar & ~0x01; if((port = ioalloc((port == 0)? -1: port, p->mem[0].size, - 0, "tcm59Xpci")) < 0){ - print("tcm59Xpci: port 0x%uX in use\n", port); + 0, "tcm59Xpci")) < 0) continue; - } + irq = p->intl; COMMAND(port, GlobalReset, 0); while(STATUS(port) & commandInProgress) diff --git a/pc/fns.h b/pc/fns.h index e8353a6b80b89007aa7512650a64d48a1140a269..3e1d42a6170a12e9d4e94531346111ff771d99d9 100644 --- a/pc/fns.h +++ b/pc/fns.h @@ -66,6 +66,7 @@ int ioalloc(int, int, int, char*); int ioreserve(int, int, int, char*); int iprint(char*, ...); int isaconfig(char*, int, ISAConf*); +void kbdenable(void); void kbdinit(void); #define kmapinval() void lapicclock(Ureg*, void*); diff --git a/pc/kbd.c b/pc/kbd.c index fe96fc3455a20195f20546940288de3c8e0968b6..e82f90128bd25c08384ca63e2ef1320a1a02ed13 100644 --- a/pc/kbd.c +++ b/pc/kbd.c @@ -398,16 +398,6 @@ kbdinit(void) { int c; - kbdq = qopen(4*1024, 0, 0, 0); - if(kbdq == nil) - panic("kbdinit"); - qnoblock(kbdq, 1); - - ioalloc(Data, 1, 0, "kbd"); - ioalloc(Cmd, 1, 0, "kbd"); - - intrenable(IrqKBD, i8042intr, 0, BUSUNKNOWN, "kbd"); - /* wait for a quiescent controller */ while((c = inb(Status)) & (Outbusy | Inready)) if(c & Inready) @@ -433,3 +423,17 @@ kbdinit(void) outb(Data, ccc); outready(); } + +void +kbdenable(void) +{ + kbdq = qopen(4*1024, 0, 0, 0); + if(kbdq == nil) + panic("kbdinit"); + qnoblock(kbdq, 1); + + ioalloc(Data, 1, 0, "kbd"); + ioalloc(Cmd, 1, 0, "kbd"); + + intrenable(IrqKBD, i8042intr, 0, BUSUNKNOWN, "kbd"); +} diff --git a/pc/main.c b/pc/main.c index 1e700f9d53c083f0bdd438113c6c7b6f2ca73293..99d72c64f89ce70f2cb20531fb81dc735097c1e4 100644 --- a/pc/main.c +++ b/pc/main.c @@ -81,6 +81,7 @@ main(void) print("\nPlan 9\n"); + kbdinit(); i8253init(); cpuidentify(); screeninit(); @@ -96,7 +97,7 @@ main(void) arch->intrinit(); timersinit(); mathinit(); - kbdinit(); + kbdenable(); if(arch->clockenable) arch->clockenable(); procinit0(); diff --git a/pc/mp.c b/pc/mp.c index 561111c340941cb616bc5dec9a891ee35f86e323..fa5094f6246d03d61741ca5374a31cc745fd909c 100644 --- a/pc/mp.c +++ b/pc/mp.c @@ -568,11 +568,19 @@ mpinit(void) } /* - * Remember to set conf.copymode here if nmach > 1. - * Should look for an ExtINT line and enable it. + * we don't really know the number of processors till + * here. + * + * set conf.copymode here if nmach > 1. + * Should look for an ExtINT line and enable it. + * + * also need to flush write buffer to make things + * visible to other processors. */ - if(conf.nmach > 1) + if(X86FAMILY(m->cpuidax) == 3 || conf.nmach > 1) conf.copymode = 1; + if(X86FAMILY(m->cpuidax) >= 5 && conf.nmach > 1) + coherence = wbflush; } static int diff --git a/port/chan.c b/port/chan.c index 18fed4e6c83d7dae2c833c9ccbba2be069dc7db4..acabd12d5b95cfb5bc1555276c9f71a13cab0db0 100644 --- a/port/chan.c +++ b/port/chan.c @@ -9,7 +9,6 @@ int chandebug=0; /* toggled by sysr1 */ QLock chanprint; /* probably asking for trouble (deadlocks) -rsc */ int domount(Chan**, Mhead**); -Ref mheadcounter; void dumpmount(void) /* DEBUGGING */ @@ -478,7 +477,6 @@ if(old->umh) * head and add to the hash table. */ m = smalloc(sizeof(Mhead)); -incref(&mheadcounter); m->ref = 1; m->from = old; incref(old); @@ -1364,13 +1362,14 @@ char isfrog[256]={ * or a valid character. */ void -validname(char *name, int slashok) +validname(char *aname, int slashok) { - char *p, *ename; + char *p, *ename, *name; uint t; int c; Rune r; + name = aname; if(((ulong)name & KZERO) != KZERO) { p = name; t = BY2PG-((ulong)p&(BY2PG-1)); @@ -1391,8 +1390,10 @@ validname(char *name, int slashok) name += chartorune(&r, name); else{ if(isfrog[c]) - if(!slashok || c!='/') - error(Ebadchar); + if(!slashok || c!='/'){ + snprint(up->genbuf, sizeof(up->genbuf), "%s: %q", Ebadchar, aname); + error(up->genbuf); + } name++; } } @@ -1429,7 +1430,6 @@ void putmhead(Mhead *m) { if(m && decref(m) == 0){ -decref(&mheadcounter); m->mount = (Mount*)0xCafeBeef; free(m); } diff --git a/port/edf.c b/port/edf.c index dbd603283818be72529ee8cc811b8881b0a48f49..fc1761209477332a1d869dda58fcacb6a4cc8b14 100644 --- a/port/edf.c +++ b/port/edf.c @@ -104,10 +104,7 @@ isedf(Proc *p) int edfanyready(void) { - /* If any edf tasks (with runnable procs in them) are released, - * at least one of them must be on the stack - */ - return edfstack[m->machno].head != nil; + return edfstack[m->machno].head || qreleased.head; } static void @@ -686,6 +683,11 @@ edfrunproc(void) static ulong nilcount; int i; + if (edfstack[m->machno].head == nil && qreleased.head== nil){ + // quick way out + nilcount++; + return nil; + } /* Figure out if the current proc should be preempted*/ ilock(&edflock); now = fastticks(nil); diff --git a/port/pgrp.c b/port/pgrp.c index b258e206745571fdf2ce2490b6a0fcaa2bda5d24..408598f0457700f4baccc1e13fda412d4c5cb062 100644 --- a/port/pgrp.c +++ b/port/pgrp.c @@ -133,10 +133,8 @@ pgrpcpy(Pgrp *to, Pgrp *from) for(i = 0; i < MNTHASH; i++) { l = tom++; for(f = from->mnthash[i]; f; f = f->hash) { -extern Ref mheadcounter; rlock(&f->lock); mh = smalloc(sizeof(Mhead)); -incref(&mheadcounter); mh->from = f->from; mh->ref = 1; incref(mh->from); diff --git a/port/tod.c b/port/tod.c index 75193d221a92f5ca84985857f419b289bbf9121b..f8eefb0169173bfb133c65b53e90b5eb4608c962 100644 --- a/port/tod.c +++ b/port/tod.c @@ -38,9 +38,9 @@ struct { vlong last; // last reading of fast clock vlong off; // offset from epoch to last vlong lasttime; // last return value from todget - vlong delta; // add 'delta' each slow clock tick from sstart to send - ulong sstart; // ... - ulong send; // ... + vlong delta; // add 'delta' each slow clock tick from sstart to send + ulong sstart; // ... + ulong send; // ... } tod; void