summaryrefslogtreecommitdiffstats
path: root/usr.bin/doscmd/timer.c
blob: d2eec93a646befd6b642799fa5af406c1b65567a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
** No copyright?!
**
** $FreeBSD$
*/
#include "doscmd.h"

static void
int08(regcontext_t *REGS __unused)
{
    *(u_long *)&BIOSDATA[0x6c] += 1;    /* ticks since midnight */
    while (*(u_long *)&BIOSDATA[0x6c] >= 24*60*6*182) {
	*(u_long *)&BIOSDATA[0x6c] -= 24*60*6*182;
	BIOSDATA[0x70]++;               /* # times past mn */
    }
    /* What is the real BIOS' sequence? */
    send_eoi();
    softint(0x1c);
}

static void
int1c(regcontext_t *REGS __unused)
{
}

unsigned char timer;

static u_char
inb_timer(int port __unused)
{
    return (--timer);
}

void
timer_init(void)
{
    u_long 		vec;
    struct itimerval	itv;
    struct timeval	tv;
    time_t		tv_sec;
    struct timezone	tz;
    struct tm		tm;

    vec = insert_hardint_trampoline();
    ivec[0x08] = vec;
    register_callback(vec, int08, "int 08");
    
    vec = insert_softint_trampoline();
    ivec[0x1c] = vec;
    register_callback(vec, int1c, "int 1c");

    define_input_port_handler(0x42, inb_timer);
    define_input_port_handler(0x40, inb_timer);
    
    /* Initialize time counter BIOS variable. */
    gettimeofday(&tv, &tz);
    tv_sec = tv.tv_sec;
    tm = *localtime(&tv_sec);
    *(u_long *)&BIOSDATA[0x6c] =
        (((tm.tm_hour * 60 + tm.tm_min) * 60) + tm.tm_sec) * 182 / 10;

    itv.it_interval.tv_sec = 0;
    itv.it_interval.tv_usec = 54925;	/* 1193182/65536 times per second */
    itv.it_value.tv_sec = 0;
    itv.it_value.tv_usec = 54925;	/* 1193182/65536 times per second */
    if (! timer_disable)
        setitimer(ITIMER_REAL, &itv, 0);
}
OpenPOWER on IntegriCloud