annotate cos/kernel/shell.c @ 140:104037b292cc

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