]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/doscmd/timer.c
This commit was generated by cvs2svn to compensate for changes in r85898,
[FreeBSD/FreeBSD.git] / usr.bin / doscmd / timer.c
1 /*
2 ** No copyright?!
3 **
4 ** $FreeBSD$
5 */
6 #include "doscmd.h"
7
8 static void
9 int08(regcontext_t *REGS)
10 {
11     *(u_long *)&BIOSDATA[0x6c] += 1;    /* ticks since midnight */
12     while (*(u_long *)&BIOSDATA[0x6c] >= 24*60*6*182) {
13         *(u_long *)&BIOSDATA[0x6c] -= 24*60*6*182;
14         BIOSDATA[0x70]++;               /* # times past mn */
15     }
16     /* What is the real BIOS' sequence? */
17     send_eoi();
18     softint(0x1c);
19 }
20
21 static void
22 int1c(regcontext_t *REGS)
23 {
24 }
25
26 unsigned char timer;
27
28 static u_char
29 inb_timer(int port)
30 {
31     return (--timer);
32 }
33
34 void
35 timer_init(void)
36 {
37     u_long              vec;
38     struct itimerval    itv;
39     struct timeval      tv;
40     time_t              tv_sec;
41     struct timezone     tz;
42     struct tm           tm;
43
44     vec = insert_hardint_trampoline();
45     ivec[0x08] = vec;
46     register_callback(vec, int08, "int 08");
47     
48     vec = insert_softint_trampoline();
49     ivec[0x1c] = vec;
50     register_callback(vec, int1c, "int 1c");
51
52     define_input_port_handler(0x42, inb_timer);
53     define_input_port_handler(0x40, inb_timer);
54     
55     /* Initialize time counter BIOS variable. */
56     gettimeofday(&tv, &tz);
57     tv_sec = tv.tv_sec;
58     tm = *localtime(&tv_sec);
59     *(u_long *)&BIOSDATA[0x6c] =
60         (((tm.tm_hour * 60 + tm.tm_min) * 60) + tm.tm_sec) * 182 / 10;
61
62     itv.it_interval.tv_sec = 0;
63     itv.it_interval.tv_usec = 54925;    /* 1193182/65536 times per second */
64     itv.it_value.tv_sec = 0;
65     itv.it_value.tv_usec = 54925;       /* 1193182/65536 times per second */
66     if (! timer_disable)
67         setitimer(ITIMER_REAL, &itv, 0);
68 }