comparison cos/kernel/shell.c @ 37:5c20bd53cccd

Cleanup
author windel
date Mon, 16 Jan 2012 21:38:55 +0100
parents
children 24ce177e01e8
comparison
equal deleted inserted replaced
36:91f91ff07ea8 37:5c20bd53cccd
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
20 void shell()
21 {
22 printf("Welcome!\n");
23 while (1)
24 {
25 char buffer[70];
26 printf(">");
27 getline(buffer, 70);
28 // TODO: interpret this line with python :)
29 printf("\n");
30 if (buffer[0] == 'x')
31 {
32 printf("System time in ms: %d\n", getTimeMS());
33 }
34 if (buffer[0] == 't')
35 {
36 testMalloc();
37 }
38 if ( strncmp(buffer, "help", 4))
39 {
40 printf("Help\n Try one of these commands:\n");
41 printf(" x: print system time in ms\n");
42 printf(" r: reboot\n");
43 printf(" t: test\n");
44 printf(" b: break\n");
45 }
46
47 if (strncmp(buffer, "r", 1))
48 {
49 reboot();
50 }
51
52 if (strncmp(buffer, "b", 1))
53 {
54 magicBochsBreak();
55 }
56
57 if (strncmp(buffer, "pf", 2))
58 {
59 /* Test general protection exception */
60 uint64_t *x;
61 x = (uint64_t*)0x4000000; // Address that is not mapped
62 *x = 0x2; // trigger paging exception
63 }
64 }
65 }
66