source: rtems-libbsd/rtemsbsd/rtems/rtems-bsd-shell.c @ 150d4d6

4.115-freebsd-12freebsd-9.3
Last change on this file since 150d4d6 was 150d4d6, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 24, 2013 at 9:11:32 AM

Move content to new <machine/rtems-bsd-support.h>

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_bsd_rtems
5 *
6 * @brief TODO.
7 */
8
9/*
10 * Copyright (c) 2009-2013 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Dornierstr. 4
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 *    notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 *    notice, this list of conditions and the following disclaimer in the
25 *    documentation and/or other materials provided with the distribution.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 */
39
40#include <machine/rtems-bsd-config.h>
41#include <machine/rtems-bsd-thread.h>
42#include <machine/rtems-bsd-support.h>
43
44#include <rtems/bsd/sys/param.h>
45#include <rtems/bsd/sys/types.h>
46#include <sys/systm.h>
47#include <rtems/bsd/sys/lock.h>
48#include <sys/mutex.h>
49#include <sys/callout.h>
50#include <sys/condvar.h>
51#include <sys/proc.h>
52
53#include <rtems/bsd/bsd.h>
54#include <rtems/shell.h>
55
56static void
57rtems_bsd_dump_mtx(void)
58{
59        rtems_chain_control *chain = &rtems_bsd_mtx_chain;
60        rtems_chain_node *node = rtems_chain_first(chain);
61
62        printf("mtx dump:\n");
63
64        while (!rtems_chain_is_tail(chain, node)) {
65                struct lock_object *lo = (struct lock_object *) node;
66
67                printf("\t%s: 0x%08x\n", lo->lo_name, lo->lo_id);
68
69                node = rtems_chain_next(node);
70        }
71}
72
73static void
74rtems_bsd_dump_sx(void)
75{
76        rtems_chain_control *chain = &rtems_bsd_sx_chain;
77        rtems_chain_node *node = rtems_chain_first(chain);
78
79        printf("sx dump:\n");
80
81        while (!rtems_chain_is_tail(chain, node)) {
82                struct lock_object *lo = (struct lock_object *) node;
83
84                printf("\t%s: 0x%08x\n", lo->lo_name, lo->lo_id);
85
86                node = rtems_chain_next(node);
87        }
88}
89
90static void
91rtems_bsd_dump_condvar(void)
92{
93        rtems_chain_control *chain = &rtems_bsd_condvar_chain;
94        rtems_chain_node *node = rtems_chain_first(chain);
95
96        printf("condvar dump:\n");
97
98        while (!rtems_chain_is_tail(chain, node)) {
99                struct cv *cv = (struct cv *) node;
100
101                printf("\t%s: 0x%08x\n", cv->cv_description, cv->cv_id);
102
103                node = rtems_chain_next(node);
104        }
105}
106
107static void
108rtems_bsd_dump_thread(void)
109{
110        const rtems_chain_control *chain = &rtems_bsd_thread_chain;
111        const rtems_chain_node *node = rtems_chain_immutable_first(chain);
112
113        printf("thread dump:\n");
114
115        while (!rtems_chain_is_tail(chain, node)) {
116                const struct thread *td = (const struct thread *) node;
117
118                printf("\t%s: 0x%08x\n", td->td_name, rtems_bsd_get_task_id(td));
119
120                node = rtems_chain_immutable_next(node);
121        }
122}
123
124static const char rtems_bsd_usage [] =
125        "bsd {all|mtx|sx|condvar|thread|callout}";
126
127#define CMP(s) all || strcasecmp(argv [1], s) == 0
128
129static int
130rtems_bsd_info(int argc, char **argv)
131{
132        bool usage = true;
133
134        if (argc == 2) {
135                bool all = false;
136
137                if (CMP("all")) {
138                        all = true;
139                }
140
141                if (CMP("mtx")) {
142                        rtems_bsd_dump_mtx();
143                        usage = false;
144                }
145                if (CMP("sx")) {
146                        rtems_bsd_dump_sx();
147                        usage = false;
148                }
149                if (CMP("condvar")) {
150                        rtems_bsd_dump_condvar();
151                        usage = false;
152                }
153                if (CMP("thread")) {
154                        rtems_bsd_dump_thread();
155                        usage = false;
156                }
157        }
158
159        if (usage) {
160                puts(rtems_bsd_usage);
161        }
162
163        return 0;
164}
165
166static rtems_shell_cmd_t rtems_bsd_info_command = {
167        .name = "bsd",
168        .usage = rtems_bsd_usage,
169        .topic = "bsp",
170        .command = rtems_bsd_info,
171        .alias = NULL,
172        .next = NULL
173};
174
175void
176rtems_bsd_shell_initialize(void)
177{
178        rtems_shell_add_cmd_struct(&rtems_bsd_info_command);
179}
Note: See TracBrowser for help on using the repository browser.