Index: generic/src/console/kconsole.c
===================================================================
--- generic/src/console/kconsole.c	(revision 02055415de88e14263875749327fac1df82289b1)
+++ generic/src/console/kconsole.c	(revision 7910cffd4851e0ac56b045bf13deddbae09ae9ee)
@@ -30,4 +30,5 @@
 #include <console/console.h>
 #include <console/chardev.h>
+#include <console/cmd.h>
 #include <print.h>
 #include <panic.h>
@@ -36,12 +37,8 @@
 #include <list.h>
 #include <arch.h>
-#include <func.h>
 #include <macros.h>
 #include <debug.h>
+#include <func.h>
 #include <symtab.h>
-
-#include <mm/tlb_cmd.h>
-
-#define MAX_CMDLINE	256
 
 /** Simple kernel console.
@@ -74,155 +71,4 @@
 static bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end);
 
-/** Data and methods for 'help' command. */
-static int cmd_help(cmd_arg_t *argv);
-static cmd_info_t help_info = {
-	.name = "help",
-	.description = "List of supported commands.",
-	.func = cmd_help,
-	.argc = 0
-};
-
-/** Data and methods for 'description' command. */
-static int cmd_desc(cmd_arg_t *argv);
-static void desc_help(void);
-static char desc_buf[MAX_CMDLINE+1];
-static cmd_arg_t desc_argv = {
-	.type = ARG_TYPE_STRING,
-	.buffer = desc_buf,
-	.len = sizeof(desc_buf)
-};
-static cmd_info_t desc_info = {
-	.name = "describe",
-	.description = "Describe specified command.",
-	.help = desc_help,
-	.func = cmd_desc,
-	.argc = 1,
-	.argv = &desc_argv
-};
-
-/** Data and methods for 'symaddr' command. */
-static int cmd_symaddr(cmd_arg_t *argv);
-static char symaddr_buf[MAX_CMDLINE+1];
-static cmd_arg_t symaddr_argv = {
-	.type = ARG_TYPE_STRING,
-	.buffer = symaddr_buf,
-	.len = sizeof(symaddr_buf)
-};
-static cmd_info_t symaddr_info = {
-	.name = "symaddr",
-	.description = "Return symbol address.",
-	.func = cmd_symaddr,
-	.argc = 1,
-	.argv = &symaddr_argv
-};
-
-/** Call0 - call function with no parameters */
-static char call0_buf[MAX_CMDLINE+1];
-static char carg1_buf[MAX_CMDLINE+1];
-static char carg2_buf[MAX_CMDLINE+1];
-static char carg3_buf[MAX_CMDLINE+1];
-
-static int cmd_call0(cmd_arg_t *argv);
-static cmd_arg_t call0_argv = {
-	.type = ARG_TYPE_STRING,
-	.buffer = call0_buf,
-	.len = sizeof(call0_buf)
-};
-static cmd_info_t call0_info = {
-	.name = "call0",
-	.description = "call0 <function> -> call function().",
-	.func = cmd_call0,
-	.argc = 1,
-	.argv = &call0_argv
-};
-
-static int cmd_call1(cmd_arg_t *argv);
-static cmd_arg_t call1_argv[] = {
-	{
-		.type = ARG_TYPE_STRING,
-		.buffer = call0_buf,
-		.len = sizeof(call0_buf)
-	},
-	{ 
-		.type = ARG_TYPE_VAR,
-		.buffer = carg1_buf,
-		.len = sizeof(carg1_buf)
-	}
-};
-static cmd_info_t call1_info = {
-	.name = "call1",
-	.description = "call1 <function> <arg1> -> call function(arg1).",
-	.func = cmd_call1,
-	.argc = 2,
-	.argv = call1_argv
-};
-
-static int cmd_call2(cmd_arg_t *argv);
-static cmd_arg_t call2_argv[] = {
-	{
-		.type = ARG_TYPE_STRING,
-		.buffer = call0_buf,
-		.len = sizeof(call0_buf)
-	},
-	{ 
-		.type = ARG_TYPE_VAR,
-		.buffer = carg1_buf,
-		.len = sizeof(carg1_buf)
-	},
-	{ 
-		.type = ARG_TYPE_VAR,
-		.buffer = carg2_buf,
-		.len = sizeof(carg2_buf)
-	}
-};
-static cmd_info_t call2_info = {
-	.name = "call2",
-	.description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).",
-	.func = cmd_call2,
-	.argc = 3,
-	.argv = call2_argv
-};
-
-static int cmd_call3(cmd_arg_t *argv);
-static cmd_arg_t call3_argv[] = {
-	{
-		.type = ARG_TYPE_STRING,
-		.buffer = call0_buf,
-		.len = sizeof(call0_buf)
-	},
-	{ 
-		.type = ARG_TYPE_VAR,
-		.buffer = carg1_buf,
-		.len = sizeof(carg1_buf)
-	},
-	{ 
-		.type = ARG_TYPE_VAR,
-		.buffer = carg2_buf,
-		.len = sizeof(carg2_buf)
-	},
-	{ 
-		.type = ARG_TYPE_VAR,
-		.buffer = carg3_buf,
-		.len = sizeof(carg3_buf)
-	}
-
-};
-static cmd_info_t call3_info = {
-	.name = "call3",
-	.description = "call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).",
-	.func = cmd_call3,
-	.argc = 4,
-	.argv = call3_argv
-};
-
-/** Data and methods for 'halt' command. */
-static int cmd_halt(cmd_arg_t *argv);
-static cmd_info_t halt_info = {
-	.name = "halt",
-	.description = "Halt the kernel.",
-	.func = cmd_halt,
-	.argc = 0
-};
-
 /** Initialize kconsole data structures. */
 void kconsole_init(void)
@@ -230,51 +76,6 @@
 	spinlock_initialize(&cmd_lock, "kconsole_cmd");
 	list_initialize(&cmd_head);
-	
-	spinlock_initialize(&help_info.lock, "kconsole_help");
-	link_initialize(&help_info.link);
-	if (!cmd_register(&help_info))
-		panic("could not register command %s\n", help_info.name);
-
-
-	spinlock_initialize(&desc_info.lock, "kconsole_desc");
-	link_initialize(&desc_info.link);
-	if (!cmd_register(&desc_info))
-		panic("could not register command %s\n", desc_info.name);
-	
-	spinlock_initialize(&symaddr_info.lock, "kconsole_symaddr");
-	link_initialize(&symaddr_info.link);
-	if (!cmd_register(&symaddr_info))
-		panic("could not register command %s\n", symaddr_info.name);
-
-	spinlock_initialize(&call0_info.lock, "kconsole_call0");
-	link_initialize(&call0_info.link);
-	if (!cmd_register(&call0_info))
-		panic("could not register command %s\n", call0_info.name);
-
-	spinlock_initialize(&call1_info.lock, "kconsole_call1");
-	link_initialize(&call1_info.link);
-	if (!cmd_register(&call1_info))
-		panic("could not register command %s\n", call1_info.name);
-
-
-	spinlock_initialize(&call2_info.lock, "kconsole_call2");
-	link_initialize(&call2_info.link);
-	if (!cmd_register(&call2_info))
-		panic("could not register command %s\n", call2_info.name);
-
-	spinlock_initialize(&call3_info.lock, "kconsole_call3");
-	link_initialize(&call3_info.link);
-	if (!cmd_register(&call3_info))
-		panic("could not register command %s\n", call3_info.name);
-	
-	spinlock_initialize(&halt_info.lock, "kconsole_halt");
-	link_initialize(&halt_info.link);
-	if (!cmd_register(&halt_info))
-		panic("could not register command %s\n", halt_info.name);
-
-	spinlock_initialize(&desc_ptlb.lock, "kconsole_ptlb");
-	link_initialize(&desc_ptlb.link);
-	if (!cmd_register(&desc_ptlb))
-		panic("could not register command %s\n", desc_ptlb.name);
+
+	cmd_init();
 }
 
@@ -547,197 +348,2 @@
 	return found_start;
 }
-
-
-/** List supported commands.
- *
- * @param argv Argument vector.
- *
- * @return 0 on failure, 1 on success.
- */
-int cmd_help(cmd_arg_t *argv)
-{
-	link_t *cur;
-	ipl_t ipl;
-
-	spinlock_lock(&cmd_lock);
-	
-	for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
-		cmd_info_t *hlp;
-		
-		hlp = list_get_instance(cur, cmd_info_t, link);
-		spinlock_lock(&hlp->lock);
-		
-		printf("%s - %s\n", hlp->name, hlp->description);
-
-		spinlock_unlock(&hlp->lock);
-	}
-	
-	spinlock_unlock(&cmd_lock);	
-
-	return 1;
-}
-
-/** Describe specified command.
- *
- * @param argv Argument vector.
- *
- * @return 0 on failure, 1 on success.
- */
-int cmd_desc(cmd_arg_t *argv)
-{
-	link_t *cur;
-	ipl_t ipl;
-
-	spinlock_lock(&cmd_lock);
-	
-	for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
-		cmd_info_t *hlp;
-		
-		hlp = list_get_instance(cur, cmd_info_t, link);
-		spinlock_lock(&hlp->lock);
-
-		if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) {
-			printf("%s - %s\n", hlp->name, hlp->description);
-			if (hlp->help)
-				hlp->help();
-			spinlock_unlock(&hlp->lock);
-			break;
-		}
-
-		spinlock_unlock(&hlp->lock);
-	}
-	
-	spinlock_unlock(&cmd_lock);	
-
-	return 1;
-}
-
-/** Search symbol table */
-int cmd_symaddr(cmd_arg_t *argv)
-{
-	__address symaddr;
-	char *symbol;
-
-	symtab_print_search(argv->buffer);
-	
-	return 1;
-}
-
-/** Call function with zero parameters */
-int cmd_call0(cmd_arg_t *argv)
-{
-	__address symaddr;
-	char *symbol;
-	__native (*f)(void);
-
-	symaddr = get_symbol_addr(argv->buffer);
-	if (!symaddr)
-		printf("Symbol %s not found.\n", argv->buffer);
-	else if (symaddr == (__address) -1) {
-		symtab_print_search(argv->buffer);
-		printf("Duplicate symbol, be more specific.\n");
-	} else {
-		symbol = get_symtab_entry(symaddr);
-		printf("Calling f(): 0x%p: %s\n", symaddr, symbol);
-		f =  (__native (*)(void)) symaddr;
-		printf("Result: 0x%X\n", f());
-	}
-	
-	return 1;
-}
-
-/** Call function with one parameter */
-int cmd_call1(cmd_arg_t *argv)
-{
-	__address symaddr;
-	char *symbol;
-	__native (*f)(__native);
-	__native arg1 = argv[1].intval;
-
-	symaddr = get_symbol_addr(argv->buffer);
-	if (!symaddr)
-		printf("Symbol %s not found.\n", argv->buffer);
-	else if (symaddr == (__address) -1) {
-		symtab_print_search(argv->buffer);
-		printf("Duplicate symbol, be more specific.\n");
-	} else {
-		symbol = get_symtab_entry(symaddr);
-		printf("Calling f(0x%x): 0x%p: %s\n", arg1, symaddr, symbol);
-		f =  (__native (*)(__native)) symaddr;
-		printf("Result: 0x%x\n", f(arg1));
-	}
-	
-	return 1;
-}
-
-/** Call function with two parameters */
-int cmd_call2(cmd_arg_t *argv)
-{
-	__address symaddr;
-	char *symbol;
-	__native (*f)(__native,__native);
-	__native arg1 = argv[1].intval;
-	__native arg2 = argv[2].intval;
-
-	symaddr = get_symbol_addr(argv->buffer);
-	if (!symaddr)
-		printf("Symbol %s not found.\n", argv->buffer);
-	else if (symaddr == (__address) -1) {
-		symtab_print_search(argv->buffer);
-		printf("Duplicate symbol, be more specific.\n");
-	} else {
-		symbol = get_symtab_entry(symaddr);
-		printf("Calling f(0x%x,0x%x): 0x%p: %s\n", 
-		       arg1, arg2, symaddr, symbol);
-		f =  (__native (*)(__native,__native)) symaddr;
-		printf("Result: 0x%x\n", f(arg1, arg2));
-	}
-	
-	return 1;
-}
-
-/** Call function with three parameters */
-int cmd_call3(cmd_arg_t *argv)
-{
-	__address symaddr;
-	char *symbol;
-	__native (*f)(__native,__native,__native);
-	__native arg1 = argv[1].intval;
-	__native arg2 = argv[2].intval;
-	__native arg3 = argv[3].intval;
-
-	symaddr = get_symbol_addr(argv->buffer);
-	if (!symaddr)
-		printf("Symbol %s not found.\n", argv->buffer);
-	else if (symaddr == (__address) -1) {
-		symtab_print_search(argv->buffer);
-		printf("Duplicate symbol, be more specific.\n");
-	} else {
-		symbol = get_symtab_entry(symaddr);
-		printf("Calling f(0x%x,0x%x, 0x%x): 0x%p: %s\n", 
-		       arg1, arg2, arg3, symaddr, symbol);
-		f =  (__native (*)(__native,__native,__native)) symaddr;
-		printf("Result: 0x%x\n", f(arg1, arg2, arg3));
-	}
-	
-	return 1;
-}
-
-
-/** Print detailed description of 'describe' command. */
-void desc_help(void)
-{
-	printf("Syntax: describe command_name\n");
-}
-
-/** Halt the kernel.
- *
- * @param argv Argument vector (ignored).
- *
- * @return 0 on failure, 1 on success (never returns).
- */
-int cmd_halt(cmd_arg_t *argv)
-{
-	halt();
-	return 1;
-}
