summaryrefslogtreecommitdiffstats
path: root/rtemsbsd/src/rtems-bsd-shell.c
blob: cd075a1a9423ba826d19ec6627d3a8cb67ed354c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/**
 * @file
 *
 * @ingroup rtems_bsd_rtems
 *
 * @brief TODO.
 */

/*
 * Copyright (c) 2009, 2010 embedded brains GmbH.  All rights reserved.
 *
 *  embedded brains GmbH
 *  Obere Lagerstr. 30
 *  82178 Puchheim
 *  Germany
 *  <rtems@embedded-brains.de>
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.com/license/LICENSE.
 */

#include <freebsd/machine/rtems-bsd-config.h>

#include <freebsd/sys/param.h>
#include <freebsd/sys/types.h>
#include <freebsd/sys/systm.h>
#include <freebsd/sys/lock.h>
#include <freebsd/sys/mutex.h>
#include <freebsd/sys/callout.h>
#include <freebsd/sys/condvar.h>
#include <freebsd/sys/proc.h>

#include <freebsd/bsd.h>
#include <rtems/shell.h>

static void
rtems_bsd_dump_callout(void)
{
	rtems_chain_control *chain = &rtems_bsd_callout_chain;
	rtems_chain_node *node = rtems_chain_first(chain);

	printf("callout dump:\n");

	while (!rtems_chain_is_tail(chain, node)) {
		struct callout *c = (struct callout *) node;

		printf("\t%08x\n", c->c_id);

		node = rtems_chain_next(node);
	}
}

static void
rtems_bsd_dump_mtx(void)
{
	rtems_chain_control *chain = &rtems_bsd_mtx_chain;
	rtems_chain_node *node = rtems_chain_first(chain);

	printf("mtx dump:\n");

	while (!rtems_chain_is_tail(chain, node)) {
		struct lock_object *lo = (struct lock_object *) node;

		printf("\t%s: 0x%08x\n", lo->lo_name, lo->lo_id);

		node = rtems_chain_next(node);
	}
}

static void
rtems_bsd_dump_sx(void)
{
	rtems_chain_control *chain = &rtems_bsd_sx_chain;
	rtems_chain_node *node = rtems_chain_first(chain);

	printf("sx dump:\n");

	while (!rtems_chain_is_tail(chain, node)) {
		struct lock_object *lo = (struct lock_object *) node;

		printf("\t%s: 0x%08x\n", lo->lo_name, lo->lo_id);

		node = rtems_chain_next(node);
	}
}

static void
rtems_bsd_dump_condvar(void)
{
	rtems_chain_control *chain = &rtems_bsd_condvar_chain;
	rtems_chain_node *node = rtems_chain_first(chain);

	printf("condvar dump:\n");

	while (!rtems_chain_is_tail(chain, node)) {
		struct cv *cv = (struct cv *) node;

		printf("\t%s: 0x%08x\n", cv->cv_description, cv->cv_id);

		node = rtems_chain_next(node);
	}
}

static void
rtems_bsd_dump_thread(void)
{
	rtems_chain_control *chain = &rtems_bsd_thread_chain;
	rtems_chain_node *node = rtems_chain_first(chain);

	printf("thread dump:\n");

	while (!rtems_chain_is_tail(chain, node)) {
		struct thread *td = (struct thread *) node;

		printf("\t%s: 0x%08x\n", td->td_name, td->td_id);

		node = rtems_chain_next(node);
	}
}

static const char rtems_bsd_usage [] =
	"bsd {all|mtx|sx|condvar|thread|callout}";

#define CMP(s) all || strcasecmp(argv [1], s) == 0

static int
rtems_bsd_info(int argc, char **argv)
{
	bool usage = true;

	if (argc == 2) {
		bool all = false;

		if (CMP("all")) {
			all = true;
		}

		if (CMP("mtx")) {
			rtems_bsd_dump_mtx();
			usage = false;
		}
		if (CMP("sx")) {
			rtems_bsd_dump_sx();
			usage = false;
		}
		if (CMP("condvar")) {
			rtems_bsd_dump_condvar();
			usage = false;
		}
		if (CMP("thread")) {
			rtems_bsd_dump_thread();
			usage = false;
		}
		if (CMP("callout")) {
			rtems_bsd_dump_callout();
			usage = false;
		}
	}

	if (usage) {
		puts(rtems_bsd_usage);
	}

	return 0;
}

static rtems_shell_cmd_t rtems_bsd_info_command = {
	.name = "bsd",
	.usage = rtems_bsd_usage,
	.topic = "bsp",
	.command = rtems_bsd_info,
	.alias = NULL,
	.next = NULL
};

void
rtems_bsd_shell_initialize(void)
{
	rtems_shell_add_cmd_struct(&rtems_bsd_info_command);
}