From cb382d00f751c5d8a48d515b87a10bb24ddb3891 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 9 Jun 2002 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2002-06-09 --- pc/fns.h | 5 +++-- pc/i8253.c | 38 ++++++++++++++++++++++++++++++++++++++ pc/main.c | 1 + 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/pc/fns.h b/pc/fns.h index 54ea0a43804bf312f9e326be2ad9552d38a417f8..e9c1709bd4c5feb2cf066d1577cb3e07ac44b0f2 100644 --- a/pc/fns.h +++ b/pc/fns.h @@ -41,10 +41,11 @@ void i8042reset(void); void i8250console(void); void* i8250alloc(int, int, int); void i8250mouse(char*, int (*)(Queue*, int), int); -void i8253init(void); void i8253enable(void); -void i8253timerset(uvlong); +void i8253init(void); +void i8253link(void); uvlong i8253read(uvlong*); +void i8253timerset(uvlong); void i8259init(void); int i8259isr(int); int i8259enable(Vctl*); diff --git a/pc/i8253.c b/pc/i8253.c index e13a455617e9e1fbfb3256ecb5209a366f31251c..63d21d13033fca7612faa2989cb6561c6fe4df96 100644 --- a/pc/i8253.c +++ b/pc/i8253.c @@ -186,6 +186,7 @@ guesscpuhz(int aalcycles) } ulong i8253periodset; +int i8253dotimerset = 1; void i8253timerset(uvlong next) @@ -194,6 +195,9 @@ i8253timerset(uvlong next) ulong want; ulong now; + if(i8253dotimerset == 0) + return; + want = next>>Tickshift; now = i8253.ticks; /* assuming whomever called us just did fastticks() */ @@ -235,6 +239,40 @@ i8253enable(void) intrenable(IrqCLOCK, i8253clock, 0, BUSUNKNOWN, "clock"); } +static long +i8253timerread(Chan*, void *a, long n, vlong offset) +{ + if(n < 16) + error("need more room"); + if(offset) + return 0; + return snprint(a, n, "timerset %s", i8253dotimerset ? "on" : "off"); +} + +static long +i8253timerwrite(Chan*, void *a, long n, vlong) +{ + if(n==3 && memcmp(a, "off", 3) == 0){ + i8253dotimerset = 0; + outb(Tmode, Load0|Square); + outb(T0cntr, (Freq/HZ)); + outb(T0cntr, (Freq/HZ)>>8); + return n; + } + if(n==2 && memcmp(a, "on", 2) == 0){ + i8253dotimerset = 1; + return n; + } + error("invalid control message"); + return -1; +} + +void +i8253link(void) +{ + addarchfile("i8253timerset", 0664, i8253timerread, i8253timerwrite); +} + /* * return the total ticks of counter 1. We shift by * 8 to give timesync more wriggle room for interpretation diff --git a/pc/main.c b/pc/main.c index a974090fabe25666aa71145cb548d28ec2170d3c..90e450771eab573b119e33f4236831b37d5f790a 100644 --- a/pc/main.c +++ b/pc/main.c @@ -105,6 +105,7 @@ main(void) links(); conf.monitor = 1; chandevreset(); + i8253link(); pageinit(); swapinit(); userinit();