[comp.os.minix] Interesting problem with timer

ericr@ipmoea.UUCP (Eric Roskos) (07/29/87)

I just found an interesting problem... if this is already known or is fixed
in version 1.2, I apologise, and you can disregard the rest of this message.

For a good while, I've noticed that after working with Minix and then rebooting
DOS, the date and time on my machine would be wrong.  I first noticed it because
makefiles would not work due to file dates being wrong, and I thought that 
either there was something wrong with my multifunction-card-clone or its 
software, or that Minix was somehow addressing its clock and causing it 
problems.  Usually I'd find the date was sometime several days into the future,
and the time seemed to be random.

However, now I have begun to suspect that the problem may be simpler, though
maybe limited to some clones like mine with non-IBM BIOSes.

If you look on page 499 of the textbook, there's a comment "Initialize channel
2 of the 8253A timer to e.g. 60 Hz."  It turns out (at least in the
textbook version) that it does use 60 Hz, but the "channel 2" part seems
wrong; if you look at the code, it is actually initializing channel 0,
I think.

So, I looked at my IBM Technical Reference, and up in the text description
of the System Board, it says, "The three timer/counters are used by the
system as follows: Channel 0 is used to time and request refresh cycles
from the DMA channel, Channel 2 is used to support tone generation of the
audio speaker, and Channel 1 is used by the system as a general-purpose
timer providing a constant time base for implementing a time-of-day clock."
(This is on page 2-4, the second paragraph.)

At first I thought this meant that Minix was using the refresh timer as a
TOD clock, which didn't sound so good, but then I looked back in the
diagrams of the system board, and you can see back on page D-9 ("Logic
10 of 12") that actually channel 0 is connected to IRQ0, channel 1 is
connected to the refresh logic, and channel 2 goes out to the speaker
to produce the beep sounds.  So, channel 0 is the TOD clock channel.

So, it looks like the comment in the textbook is wrong, and also this
Technical Reference is wrong, but the actual code is right (this IBM Manual
is one I bought back when the PC first came out, so it may be that new
ones are corrected; this one is dated July 1982).

But, anyway, continuing this investigation, if you now go to page 469
of the textbook, you see that what the reboot code does is to reset
the PIC, write back the original interrupt vectors, and do an int 19H.

Now, next we go to the BIOS listing (page A-20 in my book, line 1355)
and look at int 19H, and see that all int 19H does is reenable interrupts,
set the DS to the BIOS's data area, read the equipment flags to
see if we're supposed to boot or just go to cassette BASIC, and then
assuming we are supposed to boot, it just reads the boot sector from
the disk and jumps to it. (On newer machines it probably skips the
cassette part.)

So, at least in the BIOS I have a listing for (which again is an old
BIOS), the timer doesn't get set.  But, the PC's timer interrupt frequency
is approx. 18.2 Hz (look back at TIMER_INT in the BIOS, near int 1A),
whereas this leaves it set at 60 Hz!  If I'm not mistaken, this means
the clock is left running too fast if you boot DOS by typing ctrl/alt/del
while MINIX is running.

In fact, that does seem to be the case on my machine (a clone with the
MCT BIOS), because the reason I began to suspect this might be the problem
was that a program I have that reads the TOD clock to use it in a timing
loop was running way too fast in the timing loop after I'd been working
with Minix and then rebooted.  Actually, on my machine, rebooting also
has other bad side effects; the display doesn't get properly reinitialized
until I reboot again after DOS has finished loading; but this timing loop
had worked for nearly 2 years with no problems.

I think that maybe a different reboot method would work better on a
wider variety of BIOSes...?  E.g., maybe zero out low memory up to the
start of MINIX, then jump to FFFF0H.  (Zeroing low memory because some
BIOSes may keep a flag down there deciding whether to do a "warm" or
"cold" reboot.)  Does this seem like a more compatible approach for
non-IBM compatibles?  On the other hand, it may be that I am just missing
some detail, and the problems I've observed are due to some problem with
my multifunction card... but the above seems likely to me.

ast@cs.vu.nl (Andy Tanenbaum) (07/30/87)

In article <9@ipmoea.UUCP> ericr@ipmoea.UUCP (Eric Roskos) writes:
>I just found an interesting problem... 
> [ goes on to describe timer and reboot problems]

The reboot stuff is different in 1.2; see the klib88.s that I posted a couple
of days ago.

As to the timer causing DOS to act funny, I don't know; I never run DOS.
If somebody can point to a specific error in the timer management, please
post it.

Andy Tanenbaum (ast@cs.vu.nl)

hamilton@uxc.cso.uiuc.edu (08/01/87)

on my wells-american "a*star" AT clone, i have to type ctrl-alt-del
twice to go from minix to dos.  the first results in the bios boot
code hanging; the second causes a more normal boot.

	wayne hamilton
	U of Il and US Army Corps of Engineers CERL
UUCP:	{ihnp4,seismo,pur-ee,convex}!uiucuxc!hamilton
ARPA:	hamilton@uxc.cso.uiuc.edu	USMail:	Box 476, Urbana, IL 61801
CSNET:	hamilton%uxc@uiuc.csnet		Phone:	(217)333-8703
CIS:    [73047,544]			PLink:  w hamilton

jcmorris@mitre-bedford.ARPA (Joseph C. Morris) (08/03/87)

In a recent posting Wayne Hamilton (hamilton@uxc.cso.uiuc.edu) writes:
 
>on my wells-american "a*star" AT clone, i have to type ctrl-alt-del
>twice to go from minix to dos.  the first results in the bios boot
>code hanging; the second causes a more normal boot.

I haven't seen that symoptom, but there have been a few Minix hangs
on my machine in which CTRL-ALT-DEL resulted in a hard disk boot,
ignoring the MINIX floppy in drive A: the boot routine never looked 
at the disk (i.e., the drive motor light never came on).  A second
CTRL-ALT-DEL worked fine.  My machine is an olde, original true blue
PC-1 with the new BIOS chip to support an expansion chassis
and hard disk.
 
I've never seen this problem except following a Minix hang.  Sound 
familiar to anyone?
 
Joe Morris

zemon@felix.UUCP (Art Zemon) (08/04/87)

In article <9@ipmoea.UUCP> ericr@ipmoea.UUCP (Eric Roskos) writes:
+ 
+ For a good while, I've noticed that after working with Minix and then rebooting
+ DOS, the date and time on my machine would be wrong.  I first noticed it because
+ makefiles would not work due to file dates being wrong, and I thought that 
+ either there was something wrong with my multifunction-card-clone or its 
+ software, or that Minix was somehow addressing its clock and causing it 
+ problems.  Usually I'd find the date was sometime several days into the future,
+ and the time seemed to be random.
+ 
+  . . .
+ 
+ If I'm not mistaken, this means
+ the clock is left running too fast if you boot DOS by typing ctrl/alt/del
+ while MINIX is running.

I have noticed this on my Zenith Z-151 (XT clone).  If you
repeatedly execute the MS-DOS TIME command, you will see
that the time is indeed running much too fast.

--
	-- Art Zemon
	   FileNet Corporation
	   Costa Mesa, California
	   ...!hplabs!felix!zemone

ast@cs.vu.nl (Andy Tanenbaum) (08/05/87)

In article <4345@felix.UUCP> zemon@felix.UUCP (Art Zemon) writes:
>In article <9@ipmoea.UUCP> ericr@ipmoea.UUCP (Eric Roskos) writes:
>+ 
>+ For a good while, I've noticed that after working with Minix and then rebooting
>+ DOS, the date and time on my machine would be wrong.  

The IBM clock speed is completely programmable.  MINIX sets it to 60 Hz.  I
vaguely recall seeing somewhere than MS-DOS sets it to 18 Hz or something
stupid like that.  If this is in fact true, you should reset it to 18 Hz
(or whatever it is) when restarting DOS.

Andy Tanenbaum (ast@cs.vu.nl)

rmtodd@uokmax.UUCP (Richard Michael Todd) (08/07/87)

In article <1553@botter.cs.vu.nl> ast@cs.vu.nl (Andy Tanenbaum) writes:
>In article <4345@felix.UUCP> zemon@felix.UUCP (Art Zemon) writes:
>>In article <9@ipmoea.UUCP> ericr@ipmoea.UUCP (Eric Roskos) writes:
>>+ 
>>+ For a good while, I've noticed that after working with Minix and then rebooting
>>+ DOS, the date and time on my machine would be wrong.  
>
>The IBM clock speed is completely programmable.  MINIX sets it to 60 Hz.  I
>vaguely recall seeing somewhere than MS-DOS sets it to 18 Hz or something
>stupid like that.  If this is in fact true, you should reset it to 18 Hz
>(or whatever it is) when restarting DOS.
It's 18.2Hz, to be precise. 
  I've just checked on my system, and upon booting DOS after being in MINIX, 
the clock runs at its usual speed.  One would expect that the proper timer
values is set in the BIOS startup, but maybe it isn't in some machines.  It
seems to be in mine.  
 On the similar subject of strangeness on rebooting from within MINIX: on
my system, when rebooting from within MINIX, the system will reboot only from
floppy and not from the hard drive.  I suspect this is because the MINIX
kernel trashes the low RAM areas needed by my WD hard disk controller.  Also,
when rebooting from MINIX, the ROM BIOS initialization code doesn't seem to
execute (on my system, the ROM copyright message appears on the screen during
reboot, and the speaker beeps.)  Rebooting a second time (after booting from
the MINIX floppy) works fine.  This is with the MINIX 1.1 kernel; I understand
that the reboot code in the klib88.asm for 1.2 recently posted has a different
reboot routine, but I haven't yet installed it.

Richard Todd
USSnail:820 Annie Court,Norman OK 73069
UUCP: {allegra!cbosgd|ihnp4}!okstate!uokmax!rmtodd

allbery@ncoast.UUCP (Brandon Allbery) (08/08/87)

As quoted from <194400003@uxc.cso.uiuc.edu> by hamilton@uxc.cso.uiuc.edu:
+---------------
| on my wells-american "a*star" AT clone, i have to type ctrl-alt-del
| twice to go from minix to dos.  the first results in the bios boot
| code hanging; the second causes a more normal boot.
+---------------

I've found that the following sequence occurs at reboot on my ITT XTRA:

- CTRL-ALT-DEL
- reboot; the screen is aligned strangely (i.e. (0, 0) is somewhere other than
the top left of the CRT); a second reboot fixes it.  If the screen happens
to be correct:
- go into Procomm, ALT-D, 3 (call ncoast)
- the dial times counts off ca. 3 "seconds" for every second on the clock.
Again, a second reboot cures it.

From what I've seen, a CTRL-ALT-DEL in Minix bypasses some of the warm-reboot
code, leaving the clock and 6845 registers uninitialized.  It's notable that
a reboot from DOS has ca. 2 seconds of "dead time", whereas there is no dead
time in a Minix reboot.  Maybe I should look at it, but as yet I haven't even
managed to get time to load Minix 1.2 into my machine (it's in a cpio file
on ncoast).
-- 
 Brandon S. Allbery, moderator of comp.sources.misc and comp.binaries.ibm.pc
  {{harvard,mit-eddie}!necntc,well!hoptoad,sun!cwruecmp!hal}!ncoast!allbery
ARPA: necntc!ncoast!allbery@harvard.harvard.edu  Fido: 157/502  MCI: BALLBERY
   <<ncoast Public Access UNIX: +1 216 781 6201 24hrs. 300/1200/2400 baud>>