37
|
1 #include "kernel.h"
|
|
2
|
|
3 /* Interactive shell, should be eventually a user space
|
|
4 program */
|
|
5
|
|
6 static void testMalloc()
|
|
7 {
|
|
8 char *a, *b;
|
|
9
|
|
10 printf("Testing malloc\n");
|
|
11 a = kmalloc(100);
|
|
12 printf("Got a at %x\n", a);
|
|
13 a[0] = 'A';
|
|
14 b = kmalloc(22);
|
|
15 printf("Got b at %x\n", b);
|
|
16 b[0] = 'B';
|
|
17 kfree(a);
|
|
18 }
|
|
19
|
40
|
20 void memory_status(void);
|
|
21
|
37
|
22 void shell()
|
|
23 {
|
|
24 printf("Welcome!\n");
|
|
25 while (1)
|
|
26 {
|
|
27 char buffer[70];
|
|
28 printf(">");
|
|
29 getline(buffer, 70);
|
|
30 // TODO: interpret this line with python :)
|
|
31 printf("\n");
|
|
32 if (buffer[0] == 'x')
|
|
33 {
|
|
34 printf("System time in ms: %d\n", getTimeMS());
|
40
|
35 memory_status();
|
37
|
36 }
|
|
37 if (buffer[0] == 't')
|
|
38 {
|
|
39 testMalloc();
|
|
40 }
|
|
41 if ( strncmp(buffer, "help", 4))
|
|
42 {
|
|
43 printf("Help\n Try one of these commands:\n");
|
|
44 printf(" x: print system time in ms\n");
|
|
45 printf(" r: reboot\n");
|
|
46 printf(" t: test\n");
|
|
47 printf(" b: break\n");
|
|
48 }
|
|
49
|
|
50 if (strncmp(buffer, "r", 1))
|
|
51 {
|
|
52 reboot();
|
|
53 }
|
|
54
|
|
55 if (strncmp(buffer, "b", 1))
|
|
56 {
|
|
57 magicBochsBreak();
|
|
58 }
|
|
59
|
|
60 if (strncmp(buffer, "pf", 2))
|
|
61 {
|
|
62 /* Test general protection exception */
|
|
63 uint64_t *x;
|
|
64 x = (uint64_t*)0x4000000; // Address that is not mapped
|
|
65 *x = 0x2; // trigger paging exception
|
|
66 }
|
|
67 }
|
|
68 }
|
|
69
|