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

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