public
Description: A just-in-time compiler for MIT 6.004's "Beta" processor.
Homepage:
Clone URL: git://github.com/nelhage/bemu.git
bemu / bclock.c
100644 28 lines (22 sloc) 0.619 kb
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
#include "bemu.h"
 
#include <sys/time.h>
#include <signal.h>
#include <errno.h>
 
static void clock_tick(int signal) {
    set_interrupt(INT_CLK);
}
 
void start_clock(void) {
    struct itimerval timer = {
        { 0, 1000000 / BETA_HZ }, /* Interval */
        { 0, 1000000 / BETA_HZ }, /* Current */
    };
 
    if(signal(SIGALRM, clock_tick) < 0) {
        perror("signal");
        panic("Can't set timer signal handler");
    }
 
    if(setitimer(ITIMER_REAL, &timer, NULL) < 0) {
        perror("setitimer");
        panic("Unable to start the Beta clock.");
    }
    LOG("Started the clock at %dHz", BETA_HZ);
}