(empty log message)
@@ -7,7 +7,8 @@ | ||
7 | 7 | struct memory *memory = (struct memory *) MEMORY_ADDR; |
8 | 8 | struct fifo *sysfifo = (struct fifo *) SYSFIFO_ADDR; |
9 | 9 | int fifobuf[64], i; |
10 | - unsigned char s[3]; | |
10 | + unsigned char s[32]; | |
11 | + struct timer *timer, *timer2; | |
11 | 12 | |
12 | 13 | memory_init(memory, 0x00200000, 0xbfffffff); |
13 | 14 | memory_free(memory, 0x00001000, 0x00006c00); |
@@ -15,7 +16,14 @@ | ||
15 | 16 | fifo_init(sysfifo, fifobuf, 64); |
16 | 17 | |
17 | 18 | idt_init(); |
19 | + sti(); | |
20 | + pit_init(); | |
18 | 21 | |
22 | + timer = timer_alloc(); | |
23 | + timer_set(timer, sysfifo, 1, 50); | |
24 | + timer2 = timer_alloc(); | |
25 | + timer_set(timer2, sysfifo, 3, 300); | |
26 | + | |
19 | 27 | for (i = 0; i < 1024 * 768; i++) { |
20 | 28 | binfo->vram[i] = 0; |
21 | 29 | } |
@@ -23,9 +31,8 @@ | ||
23 | 31 | memory->total / 1024); |
24 | 32 | graphic_puts(binfo->vram, 1024, 0, 16, 0xffffff, s); |
25 | 33 | |
26 | - outb(PIC0_IMR, 0xf9); | |
34 | + outb(PIC0_IMR, 0xf8); | |
27 | 35 | outb(PIC1_IMR, 0xff); |
28 | - sti(); | |
29 | 36 | |
30 | 37 | for(;;) { |
31 | 38 | cli(); |
@@ -41,6 +48,23 @@ | ||
41 | 48 | graphic_box(binfo->vram, 1024, 0, 0, 15, 15, 0); |
42 | 49 | graphic_puts(binfo->vram, 1024, 0, 0, |
43 | 50 | 0xffffff, s); |
51 | + } else if (i == 1) { | |
52 | + graphic_box(binfo->vram, 1024, 0, 32, 7, 47, | |
53 | + 0xffffff); | |
54 | + timer_set(timer, sysfifo, 2, 50); | |
55 | + } else if (i == 2) { | |
56 | + graphic_box(binfo->vram, 1024, 0, 32, 7, 47, | |
57 | + 0x000000); | |
58 | + timer_set(timer, sysfifo, 1, 50); | |
59 | + } else if (i == 3) { | |
60 | + graphic_puts(binfo->vram, 1024, 0, 32, | |
61 | + 0xffffff, " 3 sec"); | |
62 | + timer_set(timer2, sysfifo, 10, 700); | |
63 | + } else if (i == 10) { | |
64 | + graphic_box(binfo->vram, 1024, 0, 32, 55, 47, | |
65 | + 0x000000); | |
66 | + graphic_puts(binfo->vram, 1024, 0, 32, | |
67 | + 0xffffff, " 10 sec"); | |
44 | 68 | } |
45 | 69 | } |
46 | 70 | } |
@@ -21,6 +21,7 @@ | ||
21 | 21 | void cr0_store(unsigned int cr0); |
22 | 22 | unsigned int eflags_load(void); |
23 | 23 | void eflags_store(unsigned int eflags); |
24 | +void inthandler20(void); | |
24 | 25 | void inthandler21(void); |
25 | 26 | void inthandler27(void); |
26 | 27 | unsigned int memory_test(unsigned int start, unsigned int end); |
@@ -34,9 +35,24 @@ | ||
34 | 35 | unsigned char dw_count, ar; |
35 | 36 | unsigned short offset_high; |
36 | 37 | }; |
38 | +struct timer { | |
39 | + struct timer *next; | |
40 | + unsigned int time, flag; | |
41 | + struct fifo *fifo; | |
42 | + int data; | |
43 | +}; | |
44 | +struct timers { | |
45 | + unsigned int count, next; | |
46 | + struct timer *timer, timers[128]; | |
47 | +}; | |
37 | 48 | #define PIC0_IMR 0x0021 |
38 | 49 | #define PIC1_IMR 0x00a1 |
39 | 50 | void idt_init(void); |
51 | +void pit_init(void); | |
52 | +struct timer *timer_alloc(void); | |
53 | +void timer_free(struct timer *timer); | |
54 | +void timer_set(struct timer *timer, struct fifo *fifo, int data, | |
55 | + unsigned int time); | |
40 | 56 | |
41 | 57 | /* fifo.c */ |
42 | 58 | struct fifo { |
@@ -23,6 +23,7 @@ | ||
23 | 23 | for (i = 0; i <= IDT_LIMIT / 8; i++) { |
24 | 24 | gatedesc_set(idt + i, 0, 0, 0); |
25 | 25 | } |
26 | + gatedesc_set(idt + 0x20, (unsigned int) inthandler20, 2 * 8, AR_INTGATE32); | |
26 | 27 | gatedesc_set(idt + 0x21, (unsigned int) inthandler21, 2 * 8, AR_INTGATE32); |
27 | 28 | gatedesc_set(idt + 0x27, (unsigned int) inthandler27, 2 * 8, AR_INTGATE32); |
28 | 29 | lidt(IDT_LIMIT, IDT_ADDR); |
@@ -31,7 +32,7 @@ | ||
31 | 32 | |
32 | 33 | #define PORT_KEYDATA 0x0060 |
33 | 34 | |
34 | -void keyhandler(int *esp) | |
35 | +void keyboard_handler(int *esp) | |
35 | 36 | { |
36 | 37 | struct fifo *sysfifo = (struct fifo *) SYSFIFO_ADDR; |
37 | 38 | unsigned char data = inb(PORT_KEYDATA); |
@@ -39,3 +40,101 @@ | ||
39 | 40 | fifo_push(sysfifo, data + 256); |
40 | 41 | return; |
41 | 42 | } |
43 | + | |
44 | +struct timers *timers; | |
45 | + | |
46 | +#define PIT_CTRL 0x0043 | |
47 | +#define PIT_CNT0 0x0040 | |
48 | + | |
49 | +void pit_init(void) | |
50 | +{ | |
51 | + struct memory *memory = (struct memory *) MEMORY_ADDR; | |
52 | + struct timer *t; | |
53 | + int i; | |
54 | + | |
55 | + outb(PIT_CTRL, 0x34); | |
56 | + outb(PIT_CNT0, 0x9c); | |
57 | + outb(PIT_CNT0, 0x2e); | |
58 | + | |
59 | + timers = (struct timers *) memory_alloc(memory, sizeof(struct timers)); | |
60 | + timers->count = 0; | |
61 | + for (i = 0; i < 128; i++) { | |
62 | + timers->timers[i].flag = 0; | |
63 | + } | |
64 | + t = timer_alloc(); | |
65 | + t->time = 0xffffffff; | |
66 | + t->flag = 2; | |
67 | + t->next = 0; | |
68 | + timers->timer = t; | |
69 | + timers->next = 0xffffffff; | |
70 | + return; | |
71 | +} | |
72 | + | |
73 | +struct timer *timer_alloc(void) | |
74 | +{ | |
75 | + int i; | |
76 | + | |
77 | + for (i = 0; i < 128; i++) { | |
78 | + if (!timers->timers[i].flag) { | |
79 | + timers->timers[i].flag = 1; | |
80 | + return &timers->timers[i]; | |
81 | + } | |
82 | + } | |
83 | + return 0; | |
84 | +} | |
85 | + | |
86 | +void timer_free(struct timer *timer) | |
87 | +{ | |
88 | + timer->flag = 0; | |
89 | + return; | |
90 | +} | |
91 | + | |
92 | +void timer_set(struct timer *timer, struct fifo *fifo, int data, | |
93 | + unsigned int time) | |
94 | +{ | |
95 | + struct timer *t = timers->timer, *s; | |
96 | + int e = eflags_load(); | |
97 | + | |
98 | + timer->fifo = fifo; | |
99 | + timer->data = data; | |
100 | + timer->time = timers->count + time; | |
101 | + timer->flag = 2; | |
102 | + cli(); | |
103 | + if (timer->time <= t->time) { | |
104 | + timers->timer = timer; | |
105 | + timer->next = t; | |
106 | + timers->next = timer->time; | |
107 | + eflags_store(e); | |
108 | + return; | |
109 | + } | |
110 | + for (;;) { | |
111 | + s = t; | |
112 | + t = t->next; | |
113 | + if (timer->time <= t->time) { | |
114 | + s->next = timer; | |
115 | + timer->next = t; | |
116 | + eflags_store(e); | |
117 | + return; | |
118 | + } | |
119 | + } | |
120 | +} | |
121 | + | |
122 | +void timer_handler(int *esp) | |
123 | +{ | |
124 | + struct timer *t = timers->timer; | |
125 | + | |
126 | + if (timers->next > ++timers->count) { | |
127 | + return; | |
128 | + } | |
129 | + for (;;) { | |
130 | + if (t->time > timers->count) { | |
131 | + break; | |
132 | + } | |
133 | + t->flag = 1; | |
134 | + fifo_push(t->fifo, t->data); | |
135 | + t = t->next; | |
136 | + } | |
137 | + timers->timer = t; | |
138 | + timers->next = t->time; | |
139 | + return; | |
140 | +} |