31
|
1
|
9
|
2 #include "kernel.h"
|
|
3
|
29
|
4 static void testMalloc()
|
20
|
5 {
|
|
6 char *a, *b;
|
23
|
7
|
|
8 printf("Testing malloc\n");
|
20
|
9 a = kmalloc(100);
|
|
10 printf("Got a at %x\n", a);
|
|
11 a[0] = 'A';
|
|
12 b = kmalloc(22);
|
|
13 printf("Got b at %x\n", b);
|
|
14 b[0] = 'B';
|
|
15 kfree(a);
|
|
16 }
|
|
17
|
29
|
18 /* This routine initializes the kernel.
|
|
19 * We are left here in 64-bit long mode with the first 6 MB identity mapped.
|
|
20 * */
|
9
|
21 void kmain()
|
|
22 {
|
29
|
23 init_screen();
|
|
24 setupIDT();
|
|
25 // init_heap();
|
|
26
|
|
27 // Assume first 16MB:
|
|
28 // TODO: get size from grub
|
|
29 init_memory(0x1000000);
|
14
|
30
|
28
|
31 // TODO: make below a user space program!
|
23
|
32 printf("Welcome!\n");
|
9
|
33
|
|
34 while (1==1)
|
|
35 {
|
|
36 char buffer[70];
|
27
|
37 printf(">");
|
9
|
38 getline(buffer, 70);
|
|
39 // TODO: interpret this line with python :)
|
|
40 printf("\n");
|
|
41 if (buffer[0] == 'x')
|
|
42 {
|
|
43 printf("System time in ms: %d\n", getTimeMS());
|
|
44 }
|
23
|
45 if (buffer[0] == 't')
|
|
46 {
|
|
47 testMalloc();
|
|
48 }
|
9
|
49 if ( strncmp(buffer, "help", 4))
|
|
50 {
|
|
51 printf("Help\n Try one of these commands:\n");
|
|
52 printf(" x: print system time in ms\n");
|
28
|
53 printf(" r: reboot\n");
|
|
54 printf(" t: test\n");
|
29
|
55 printf(" b: break\n");
|
9
|
56 }
|
24
|
57 if (strncmp(buffer, "r", 1))
|
|
58 {
|
|
59 reboot();
|
|
60 }
|
29
|
61 if (strncmp(buffer, "b", 1))
|
|
62 {
|
|
63 magicBochsBreak();
|
|
64 }
|
9
|
65 }
|
|
66 }
|
|
67
|
|
68
|