annotate cos/kernel/kernel.c @ 24:d8627924d40d

Split up in more files and reboot command
author windel
date Fri, 02 Dec 2011 14:00:02 +0100
parents 5dd47d6eebac
children dcce92b1efbc
rev   line source
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
1 #include "kernel.h"
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
2
19
f454e3c592dd Cleanup of bochs config file
windel
parents: 18
diff changeset
3 void startPython()
f454e3c592dd Cleanup of bochs config file
windel
parents: 18
diff changeset
4 {
f454e3c592dd Cleanup of bochs config file
windel
parents: 18
diff changeset
5 // TODO: connect to Py_Main
23
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 22
diff changeset
6 //PyRun_SimpleString("print('hello world')");
19
f454e3c592dd Cleanup of bochs config file
windel
parents: 18
diff changeset
7 }
f454e3c592dd Cleanup of bochs config file
windel
parents: 18
diff changeset
8
20
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
9 void testMalloc()
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
10 {
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
11 char *a, *b;
23
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 22
diff changeset
12
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 22
diff changeset
13 printf("Testing malloc\n");
20
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
14 a = kmalloc(100);
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
15 printf("Got a at %x\n", a);
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
16 a[0] = 'A';
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
17 b = kmalloc(22);
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
18 printf("Got b at %x\n", b);
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
19 b[0] = 'B';
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
20 kfree(a);
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
21 }
b1fed2171e1a Now working with 2 MB pages
windel
parents: 19
diff changeset
22
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
23 void reboot()
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
24 {
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
25 while ( (inb(0x64) & 0x02) == 0x02)
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
26 {
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
27 ;
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
28 }
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
29 outb(0x64, 0xFE);
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
30 }
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
31
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
32 void kmain()
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 init_screen();
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
35 setupIDT(); // This causes error on real hardware
23
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 22
diff changeset
36 init_heap();
14
a58904747019 Added asm interrupt handler things, not yet working
windel
parents: 9
diff changeset
37
23
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 22
diff changeset
38 printf("Welcome!\n");
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
39
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
40 while (1==1)
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
41 {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
42 char buffer[70];
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
43 printf(">>>");
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
44 getline(buffer, 70);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
45 // TODO: interpret this line with python :)
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
46 printf("\n");
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
47 if (buffer[0] == 'x')
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
48 {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
49 printf("System time in ms: %d\n", getTimeMS());
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
50 }
23
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 22
diff changeset
51 if (buffer[0] == 't')
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 22
diff changeset
52 {
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 22
diff changeset
53 testMalloc();
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 22
diff changeset
54 }
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
55 if ( strncmp(buffer, "help", 4))
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
56 {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
57 printf("Help\n Try one of these commands:\n");
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
58 printf(" x: print system time in ms\n");
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
59 }
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
60 if (strncmp(buffer, "r", 1))
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
61 {
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
62 reboot();
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
63 }
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
64 }
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