9
|
1 #include "kernel.h"
|
|
2
|
29
|
3 static void testMalloc()
|
20
|
4 {
|
|
5 char *a, *b;
|
23
|
6
|
|
7 printf("Testing malloc\n");
|
20
|
8 a = kmalloc(100);
|
|
9 printf("Got a at %x\n", a);
|
|
10 a[0] = 'A';
|
|
11 b = kmalloc(22);
|
|
12 printf("Got b at %x\n", b);
|
|
13 b[0] = 'B';
|
|
14 kfree(a);
|
|
15 }
|
|
16
|
26
|
17 // A test program that prints 'Hoi' to the screen:
|
|
18 unsigned char hello_program[] = {0x55, 0x48, 0x89, 0xe5, 0x48, 0x83, 0xec, 0x10, 0x48, 0xc7, 0x45, 0xf8, 0x0, 0x80, 0xb, 0x0, 0x48, 0x8b, 0x45, 0xf8, 0xc6, 0x0, 0x48, 0x48, 0x8b, 0x45, 0xf8, 0x48, 0x83, 0xc0, 0x2, 0xc6, 0x0, 0x6f, 0x48, 0x8b, 0x45, 0xf8, 0x48, 0x83, 0xc0, 0x4, 0xc6, 0x0, 0x69, 0xeb, 0xfe, 0x0, 0x14, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x7a, 0x52, 0x0, 0x1, 0x78, 0x10, 0x1, 0x1b, 0xc, 0x7, 0x8, 0x90, 0x1, 0x0, 0x0, 0x1c, 0x0, 0x0, 0x0, 0x1c, 0x0, 0x0, 0x0, 0xb0, 0xff, 0xff, 0xff, 0x2f, 0x0, 0x0, 0x0, 0x0, 0x41, 0xe, 0x10, 0x86, 0x2, 0x43, 0xd, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
|
24
|
19
|
29
|
20 /* This routine initializes the kernel.
|
|
21 * We are left here in 64-bit long mode with the first 6 MB identity mapped.
|
|
22 * */
|
9
|
23 void kmain()
|
|
24 {
|
29
|
25 init_screen();
|
|
26 setupIDT();
|
|
27 // init_heap();
|
|
28
|
|
29 // Assume first 16MB:
|
|
30 // TODO: get size from grub
|
|
31 init_memory(0x1000000);
|
14
|
32
|
28
|
33 //new_task(hello_program);
|
|
34
|
|
35 // TODO: make below a user space program!
|
23
|
36 printf("Welcome!\n");
|
9
|
37
|
|
38 while (1==1)
|
|
39 {
|
|
40 char buffer[70];
|
27
|
41 printf(">");
|
9
|
42 getline(buffer, 70);
|
|
43 // TODO: interpret this line with python :)
|
|
44 printf("\n");
|
|
45 if (buffer[0] == 'x')
|
|
46 {
|
|
47 printf("System time in ms: %d\n", getTimeMS());
|
|
48 }
|
23
|
49 if (buffer[0] == 't')
|
|
50 {
|
|
51 testMalloc();
|
|
52 }
|
9
|
53 if ( strncmp(buffer, "help", 4))
|
|
54 {
|
|
55 printf("Help\n Try one of these commands:\n");
|
|
56 printf(" x: print system time in ms\n");
|
28
|
57 printf(" r: reboot\n");
|
|
58 printf(" t: test\n");
|
29
|
59 printf(" b: break\n");
|
9
|
60 }
|
24
|
61 if (strncmp(buffer, "r", 1))
|
|
62 {
|
|
63 reboot();
|
|
64 }
|
29
|
65 if (strncmp(buffer, "b", 1))
|
|
66 {
|
|
67 magicBochsBreak();
|
|
68 }
|
9
|
69 }
|
|
70 }
|
|
71
|
|
72
|