1 // Simple command-line kernel monitor useful for
2 // controlling the kernel and exploring the system interactively.
5 #include <inc/string.h>
7 #include <inc/assert.h>
10 #include <kern/console.h>
11 #include <kern/monitor.h>
12 #include <kern/trap.h>
14 #define CMDBUF_SIZE 80 // enough for one VGA text line
19 void (*func
)(int argc
, char **argv
);
22 static struct Command commands
[] = {
23 {"help", "Display this list of commands", mon_help
},
24 {"kerninfo", "Display information about the kernel", mon_kerninfo
},
26 #define NCOMMANDS (sizeof(commands)/sizeof(commands[0]))
30 /***** Implementations of basic kernel monitor commands *****/
33 mon_help(int argc
, char **argv
)
37 for (i
= 0; i
< NCOMMANDS
; i
++)
38 printf("%s - %s\n", commands
[i
].name
, commands
[i
].desc
);
42 mon_kerninfo(int argc
, char **argv
)
44 extern char _start
[], etext
[], edata
[], end
[];
46 printf("Special kernel symbols:\n");
47 printf(" _start %08x (virt) %08x (phys)\n", _start
, _start
-KERNBASE
);
48 printf(" etext %08x (virt) %08x (phys)\n", etext
, etext
-KERNBASE
);
49 printf(" edata %08x (virt) %08x (phys)\n", edata
, edata
-KERNBASE
);
50 printf(" end %08x (virt) %08x (phys)\n", end
, end
-KERNBASE
);
51 printf("Kernel executable memory footprint: %dKB\n",
52 (end
-_start
+1023)/1024);
56 mon_backtrace(int argc
, char **argv
)
62 /***** Kernel monitor command interpreter *****/
64 #define WHITESPACE "\t\r\n "
74 // Parse the command buffer into whitespace-separated arguments
79 while (*buf
&& strchr(WHITESPACE
, *buf
))
84 // save and scan past next arg
85 if (argc
== MAXARGS
-1) {
86 printf("Too many arguments (max %d)\n", MAXARGS
);
90 while (*buf
&& !strchr(WHITESPACE
, *buf
))
95 // Lookup and invoke the command
98 for (i
= 0; i
< NCOMMANDS
; i
++) {
99 if (strcmp(argv
[0], commands
[i
].name
) == 0) {
100 commands
[i
].func(argc
, argv
);
104 printf("Unknown command '%s'\n", argv
[0]);
108 monitor(struct Trapframe
*tf
)
112 printf("Welcome to the JOS kernel monitor!\n");
113 printf("Type 'help' for a list of commands.\n");
119 buf
= readline("K> ");