1/*	$NetBSD: db_command.h,v 1.34 2009/01/05 22:19:40 haad Exp $	*/
2
3/*-
4 * Copyright (c) 1996, 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Adam Hamsik.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32/*
33 * Mach Operating System
34 * Copyright (c) 1991,1990 Carnegie Mellon University
35 * All Rights Reserved.
36 *
37 * Permission to use, copy, modify and distribute this software and its
38 * documentation is hereby granted, provided that both the copyright
39 * notice and this permission notice appear in all copies of the
40 * software, derivative works or modified versions, and any portions
41 * thereof, and that both notices appear in supporting documentation.
42 *
43 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
44 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
45 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 *
47 * Carnegie Mellon requests users of this software to return to
48 *
49 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
50 *  School of Computer Science
51 *  Carnegie Mellon University
52 *  Pittsburgh PA 15213-3890
53 *
54 * any improvements or extensions that they make and grant Carnegie the
55 * rights to redistribute these changes.
56 *
57 *	Author: David B. Golub, Carnegie Mellon University
58 *	Date:	7/90
59 */
60
61#ifndef _DDB_COMMAND_
62#define _DDB_COMMAND_
63
64void	db_skip_to_eol(void);
65void	db_command_loop(void);
66void	db_error(const char *) __dead;
67
68extern db_addr_t db_dot;	/* current location */
69extern db_addr_t db_last_addr;	/* last explicit address typed */
70extern db_addr_t db_prev;	/* last address examined
71				   or written */
72extern db_addr_t db_next;	/* next address to be examined
73				   or written */
74
75extern char db_cmd_on_enter[];
76
77struct db_command;
78
79
80
81/*
82 * Macro include help when DDB_VERBOSE_HELP option(9) is used
83 */
84#ifdef DDB_VERBOSE_HELP
85#define DDB_ADD_CMD(name,funct,type,cmd_descr,cmd_arg,arg_desc)\
86 name,funct,type,cmd_descr,cmd_arg,arg_desc
87#else
88#define DDB_ADD_CMD(name,funct,type,cmd_descr,cmd_arg,arg_desc)\
89 name,funct,type
90#endif
91
92
93
94/*
95 * we have two types of lists one for base commands like reboot
96 * and another list for show subcommands.
97 */
98
99#define DDB_BASE_CMD 0
100#define DDB_SHOW_CMD 1
101#define DDB_MACH_CMD 2
102
103
104int db_register_tbl(uint8_t, const struct db_command *);
105int db_unregister_tbl(uint8_t, const struct db_command *);
106
107/*
108 * Command table
109 */
110struct db_command {
111	const char	*name;		/* command name */
112
113	/* function to call */
114	void		(*fcn)(db_expr_t, bool, db_expr_t, const char *);
115	/*
116	 * Flag is used for modifing command behaviour.
117	 * CS_OWN && CS_MORE are specify type of command arguments.
118	 * CS_OWN commandmanage arguments in own way.
119	 * CS_MORE db_command() prepare argument list.
120	 *
121	 * CS_COMPAT is set for all level 2 commands with level 3 childs (show all pages)
122	 *
123	 * CS_SHOW identify show command in BASE command list
124	 * CS_MACH identify mach command in BASE command list
125	 *
126	 * CS_SET_DOT specify if this command is put to last added command memory.
127	 * CS_NOREPEAT this command does not repeat
128	 */
129	uint16_t		flag;		/* extra info: */
130#define	CS_OWN		0x1			/* non-standard syntax */
131#define	CS_MORE		0x2			/* standard syntax, but may have other
132					   				words at end */
133#define CS_COMPAT	0x4			/* is set for compatibilty with old
134									ddb versions*/
135#define CS_SHOW		0x8			/* select show list */
136#define CS_MACH		0x10		/* select machine dependent list */
137
138#define	CS_SET_DOT	0x100		/* set dot after command */
139#define	CS_NOREPEAT	0x200		/* don't set last_command */
140#ifdef DDB_VERBOSE_HELP
141	const char *cmd_descr; /* description of command */
142	const char *cmd_arg;   /* command arguments */
143	const char *cmd_arg_help;	/* arguments description */
144#endif
145};
146
147void	*db_alloc(size_t);
148void	*db_zalloc(size_t);
149void	db_free(void *, size_t);
150
151#endif /*_DDB_COMMAND_*/
152