-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
34 lines (26 loc) · 779 Bytes
/
main.c
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
#include "lib.h"
static volatile unsigned long TIMER_INTERRUPTS;
void interrupt_handler(int irq) {
switch(irq) {
case 32:
TIMER_INTERRUPTS++;
break;
default:
printlnf("Got interrupt: %d.", irq);
break;
}
}
void kernel_main() {
printlnf("Minikernel is running...");
const int approximate_timer_frequency = 18;
const int watchdog_period = 5;
unsigned long last_watchdog_uptime = 0;
while(1) {
unsigned long uptime = TIMER_INTERRUPTS / approximate_timer_frequency;
if(uptime - last_watchdog_uptime >= watchdog_period) {
printlnf("We're still alive (~%ds uptime).", uptime);
last_watchdog_uptime = uptime;
}
asm("hlt");
}
}