18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Created by: Jason Wessel <jason.wessel@windriver.com>
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (c) 2010 Wind River Systems, Inc.  All Rights Reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This file is licensed under the terms of the GNU General Public
78c2ecf20Sopenharmony_ci * License version 2. This program is licensed "as is" without any
88c2ecf20Sopenharmony_ci * warranty of any kind, whether express or implied.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/module.h>
128c2ecf20Sopenharmony_ci#include <linux/kdb.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/*
158c2ecf20Sopenharmony_ci * All kdb shell command call backs receive argc and argv, where
168c2ecf20Sopenharmony_ci * argv[0] is the command the end user typed
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_cistatic int kdb_hello_cmd(int argc, const char **argv)
198c2ecf20Sopenharmony_ci{
208c2ecf20Sopenharmony_ci	if (argc > 1)
218c2ecf20Sopenharmony_ci		return KDB_ARGCOUNT;
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci	if (argc)
248c2ecf20Sopenharmony_ci		kdb_printf("Hello %s.\n", argv[1]);
258c2ecf20Sopenharmony_ci	else
268c2ecf20Sopenharmony_ci		kdb_printf("Hello world!\n");
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci	return 0;
298c2ecf20Sopenharmony_ci}
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistatic int __init kdb_hello_cmd_init(void)
338c2ecf20Sopenharmony_ci{
348c2ecf20Sopenharmony_ci	/*
358c2ecf20Sopenharmony_ci	 * Registration of a dynamically added kdb command is done with
368c2ecf20Sopenharmony_ci	 * kdb_register() with the arguments being:
378c2ecf20Sopenharmony_ci	 *   1: The name of the shell command
388c2ecf20Sopenharmony_ci	 *   2: The function that processes the command
398c2ecf20Sopenharmony_ci	 *   3: Description of the usage of any arguments
408c2ecf20Sopenharmony_ci	 *   4: Descriptive text when you run help
418c2ecf20Sopenharmony_ci	 *   5: Number of characters to complete the command
428c2ecf20Sopenharmony_ci	 *      0 == type the whole command
438c2ecf20Sopenharmony_ci	 *      1 == match both "g" and "go" for example
448c2ecf20Sopenharmony_ci	 */
458c2ecf20Sopenharmony_ci	kdb_register("hello", kdb_hello_cmd, "[string]",
468c2ecf20Sopenharmony_ci		     "Say Hello World or Hello [string]", 0);
478c2ecf20Sopenharmony_ci	return 0;
488c2ecf20Sopenharmony_ci}
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistatic void __exit kdb_hello_cmd_exit(void)
518c2ecf20Sopenharmony_ci{
528c2ecf20Sopenharmony_ci	kdb_unregister("hello");
538c2ecf20Sopenharmony_ci}
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cimodule_init(kdb_hello_cmd_init);
568c2ecf20Sopenharmony_cimodule_exit(kdb_hello_cmd_exit);
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ciMODULE_AUTHOR("WindRiver");
598c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("KDB example to add a hello command");
608c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
61