annotate cos/kernel/kernel.c @ 31:88590c42320f

Changed interrupt handler
author windel
date Tue, 10 Jan 2012 20:40:35 +0100
parents 7e3bdcb391dc
children 3a6a9b929db0
rev   line source
31
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
1
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
2 #include "kernel.h"
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
3
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
4 static void testMalloc()
20
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
5 {
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
6 char *a, *b;
23
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 22
diff changeset
7
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 22
diff changeset
8 printf("Testing malloc\n");
20
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
9 a = kmalloc(100);
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
10 printf("Got a at %x\n", a);
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
11 a[0] = 'A';
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
12 b = kmalloc(22);
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
13 printf("Got b at %x\n", b);
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
14 b[0] = 'B';
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
15 kfree(a);
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
16 }
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
17
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
18 /* This routine initializes the kernel.
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
19 * We are left here in 64-bit long mode with the first 6 MB identity mapped.
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
20 * */
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
21 void kmain()
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
22 {
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
23 init_screen();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
24 setupIDT();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
25 // init_heap();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
26
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
27 // Assume first 16MB:
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
28 // TODO: get size from grub
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
29 init_memory(0x1000000);
14
a58904747019 Added asm interrupt handler things, not yet working
windel
parents: 9
diff changeset
30
28
47b7df514243 Moved Makefiles
windel
parents: 27
diff changeset
31 // TODO: make below a user space program!
23
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 22
diff changeset
32 printf("Welcome!\n");
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
33
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
34 while (1==1)
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
35 {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
36 char buffer[70];
27
7f74363f4c82 Added some files for the python port
windel
parents: 26
diff changeset
37 printf(">");
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
38 getline(buffer, 70);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
39 // TODO: interpret this line with python :)
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
40 printf("\n");
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
41 if (buffer[0] == 'x')
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
42 {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
43 printf("System time in ms: %d\n", getTimeMS());
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
44 }
23
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 22
diff changeset
45 if (buffer[0] == 't')
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 22
diff changeset
46 {
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 22
diff changeset
47 testMalloc();
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 22
diff changeset
48 }
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
49 if ( strncmp(buffer, "help", 4))
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
50 {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
51 printf("Help\n Try one of these commands:\n");
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
52 printf(" x: print system time in ms\n");
28
47b7df514243 Moved Makefiles
windel
parents: 27
diff changeset
53 printf(" r: reboot\n");
47b7df514243 Moved Makefiles
windel
parents: 27
diff changeset
54 printf(" t: test\n");
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
55 printf(" b: break\n");
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
56 }
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
57 if (strncmp(buffer, "r", 1))
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
58 {
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
59 reboot();
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
60 }
29
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
61 if (strncmp(buffer, "b", 1))
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
62 {
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
63 magicBochsBreak();
7e3bdcb391dc Added get_page function to mm
windel
parents: 28
diff changeset
64 }
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
65 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
66 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
67
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
68