• R/O
  • SSH
  • HTTPS

haribote: Commit


Commit MetaInfo

Revisão205 (tree)
Hora2010-03-06 16:26:17
Autortatsupc

Mensagem de Log

(mensagem de log vazia)

Mudança Sumário

Diff

--- haribote/trunk/orbspace/orbspace/main.c (revision 204)
+++ haribote/trunk/orbspace/orbspace/main.c (revision 205)
@@ -7,7 +7,8 @@
77 struct memory *memory = (struct memory *) MEMORY_ADDR;
88 struct fifo *sysfifo = (struct fifo *) SYSFIFO_ADDR;
99 int fifobuf[64], i;
10- unsigned char s[3];
10+ unsigned char s[32];
11+ struct timer *timer, *timer2;
1112
1213 memory_init(memory, 0x00200000, 0xbfffffff);
1314 memory_free(memory, 0x00001000, 0x00006c00);
@@ -15,7 +16,14 @@
1516 fifo_init(sysfifo, fifobuf, 64);
1617
1718 idt_init();
19+ sti();
20+ pit_init();
1821
22+ timer = timer_alloc();
23+ timer_set(timer, sysfifo, 1, 50);
24+ timer2 = timer_alloc();
25+ timer_set(timer2, sysfifo, 3, 300);
26+
1927 for (i = 0; i < 1024 * 768; i++) {
2028 binfo->vram[i] = 0;
2129 }
@@ -23,9 +31,8 @@
2331 memory->total / 1024);
2432 graphic_puts(binfo->vram, 1024, 0, 16, 0xffffff, s);
2533
26- outb(PIC0_IMR, 0xf9);
34+ outb(PIC0_IMR, 0xf8);
2735 outb(PIC1_IMR, 0xff);
28- sti();
2936
3037 for(;;) {
3138 cli();
@@ -41,6 +48,23 @@
4148 graphic_box(binfo->vram, 1024, 0, 0, 15, 15, 0);
4249 graphic_puts(binfo->vram, 1024, 0, 0,
4350 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");
4468 }
4569 }
4670 }
--- haribote/trunk/orbspace/orbspace/main.h (revision 204)
+++ haribote/trunk/orbspace/orbspace/main.h (revision 205)
@@ -21,6 +21,7 @@
2121 void cr0_store(unsigned int cr0);
2222 unsigned int eflags_load(void);
2323 void eflags_store(unsigned int eflags);
24+void inthandler20(void);
2425 void inthandler21(void);
2526 void inthandler27(void);
2627 unsigned int memory_test(unsigned int start, unsigned int end);
@@ -34,9 +35,24 @@
3435 unsigned char dw_count, ar;
3536 unsigned short offset_high;
3637 };
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+};
3748 #define PIC0_IMR 0x0021
3849 #define PIC1_IMR 0x00a1
3950 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);
4056
4157 /* fifo.c */
4258 struct fifo {
--- haribote/trunk/orbspace/orbspace/int.c (revision 204)
+++ haribote/trunk/orbspace/orbspace/int.c (revision 205)
@@ -23,6 +23,7 @@
2323 for (i = 0; i <= IDT_LIMIT / 8; i++) {
2424 gatedesc_set(idt + i, 0, 0, 0);
2525 }
26+ gatedesc_set(idt + 0x20, (unsigned int) inthandler20, 2 * 8, AR_INTGATE32);
2627 gatedesc_set(idt + 0x21, (unsigned int) inthandler21, 2 * 8, AR_INTGATE32);
2728 gatedesc_set(idt + 0x27, (unsigned int) inthandler27, 2 * 8, AR_INTGATE32);
2829 lidt(IDT_LIMIT, IDT_ADDR);
@@ -31,7 +32,7 @@
3132
3233 #define PORT_KEYDATA 0x0060
3334
34-void keyhandler(int *esp)
35+void keyboard_handler(int *esp)
3536 {
3637 struct fifo *sysfifo = (struct fifo *) SYSFIFO_ADDR;
3738 unsigned char data = inb(PORT_KEYDATA);
@@ -39,3 +40,101 @@
3940 fifo_push(sysfifo, data + 256);
4041 return;
4142 }
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+}
Show on old repository browser