Subversion Repositories HelenOS-historic

Rev

Rev 532 | Rev 544 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 532 Rev 534
1
/*
1
/*
2
 * Copyright (C) 2005 Jakub Jermar
2
 * Copyright (C) 2005 Jakub Jermar
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
#include <console/kconsole.h>
29
#include <console/kconsole.h>
30
#include <console/console.h>
30
#include <console/console.h>
31
#include <console/chardev.h>
31
#include <console/chardev.h>
32
#include <print.h>
32
#include <print.h>
33
#include <panic.h>
33
#include <panic.h>
34
#include <typedefs.h>
34
#include <typedefs.h>
35
#include <arch/types.h>
35
#include <arch/types.h>
36
#include <list.h>
36
#include <list.h>
37
#include <arch.h>
37
#include <arch.h>
38
#include <func.h>
38
#include <func.h>
39
#include <macros.h>
39
#include <macros.h>
40
#include <debug.h>
40
#include <debug.h>
41
 
41
 
42
#define MAX_CMDLINE 256
42
#define MAX_CMDLINE 256
43
 
43
 
44
/** Simple kernel console.
44
/** Simple kernel console.
45
 *
45
 *
46
 * The console is realized by kernel thread kconsole.
46
 * The console is realized by kernel thread kconsole.
47
 * It doesn't understand any useful command on its own,
47
 * It doesn't understand any useful command on its own,
48
 * but makes it possible for other kernel subsystems to
48
 * but makes it possible for other kernel subsystems to
49
 * register their own commands.
49
 * register their own commands.
50
 */
50
 */
51
 
51
 
52
/** Locking.
52
/** Locking.
53
 *
53
 *
54
 * There is a list of cmd_info_t structures. This list
54
 * There is a list of cmd_info_t structures. This list
55
 * is protected by cmd_lock spinlock. Note that specially
55
 * is protected by cmd_lock spinlock. Note that specially
56
 * the link elements of cmd_info_t are protected by
56
 * the link elements of cmd_info_t are protected by
57
 * this lock.
57
 * this lock.
58
 *
58
 *
59
 * Each cmd_info_t also has its own lock, which protects
59
 * Each cmd_info_t also has its own lock, which protects
60
 * all elements thereof except the link element.
60
 * all elements thereof except the link element.
61
 *
61
 *
62
 * cmd_lock must be acquired before any cmd_info lock.
62
 * cmd_lock must be acquired before any cmd_info lock.
63
 * When locking two cmd info structures, structure with
63
 * When locking two cmd info structures, structure with
64
 * lower address must be locked first.
64
 * lower address must be locked first.
65
 */
65
 */
66
 
66
 
67
spinlock_t cmd_lock;    /**< Lock protecting command list. */
67
spinlock_t cmd_lock;    /**< Lock protecting command list. */
68
link_t cmd_head;    /**< Command list. */
68
link_t cmd_head;    /**< Command list. */
69
 
69
 
70
static cmd_info_t *parse_cmdline(char *cmdline, size_t len);
70
static cmd_info_t *parse_cmdline(char *cmdline, size_t len);
71
static bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end);
71
static bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end);
72
 
72
 
73
/** Data and methods for 'help' command. */
73
/** Data and methods for 'help' command. */
74
static int cmd_help(cmd_arg_t *argv);
74
static int cmd_help(cmd_arg_t *argv);
75
static cmd_info_t help_info;
75
static cmd_info_t help_info;
76
 
76
 
77
/** Data and methods for 'description' command. */
77
/** Data and methods for 'description' command. */
78
static int cmd_desc(cmd_arg_t *argv);
78
static int cmd_desc(cmd_arg_t *argv);
79
static void desc_help(void);
79
static void desc_help(void);
80
static cmd_info_t desc_info;
80
static cmd_info_t desc_info;
81
static char desc_buf[MAX_CMDLINE+1];
81
static char desc_buf[MAX_CMDLINE+1];
82
static cmd_arg_t desc_argv = {
82
static cmd_arg_t desc_argv = {
83
    .type = ARG_TYPE_STRING,
83
    .type = ARG_TYPE_STRING,
84
    .buffer = desc_buf,
84
    .buffer = desc_buf,
85
    .len = sizeof(desc_buf)
85
    .len = sizeof(desc_buf)
86
};
86
};
87
 
87
 
88
/** Initialize kconsole data structures. */
88
/** Initialize kconsole data structures. */
89
void kconsole_init(void)
89
void kconsole_init(void)
90
{
90
{
91
    spinlock_initialize(&cmd_lock);
91
    spinlock_initialize(&cmd_lock);
92
    list_initialize(&cmd_head);
92
    list_initialize(&cmd_head);
93
   
93
   
94
    help_info.name = "help";
94
    help_info.name = "help";
95
    help_info.description = "List supported commands.";
95
    help_info.description = "List supported commands.";
96
    help_info.func = cmd_help;
96
    help_info.func = cmd_help;
97
    help_info.help = NULL;
97
    help_info.help = NULL;
98
    help_info.argc = 0;
98
    help_info.argc = 0;
99
    help_info.argv = NULL;
99
    help_info.argv = NULL;
100
 
100
 
101
    spinlock_initialize(&help_info.lock);
101
    spinlock_initialize(&help_info.lock);
102
    link_initialize(&help_info.link);
102
    link_initialize(&help_info.link);
103
 
103
 
104
    if (!cmd_register(&help_info))
104
    if (!cmd_register(&help_info))
105
        panic("could not register command %s\n", help_info.name);
105
        panic("could not register command %s\n", help_info.name);
106
 
106
 
107
 
107
 
108
    desc_info.name = "describe";
108
    desc_info.name = "describe";
109
    desc_info.description = "Describe specified command.";
109
    desc_info.description = "Describe specified command.";
110
    desc_info.help = desc_help;
110
    desc_info.help = desc_help;
111
    desc_info.func = cmd_desc;
111
    desc_info.func = cmd_desc;
112
    desc_info.argc = 1;
112
    desc_info.argc = 1;
113
    desc_info.argv = &desc_argv;
113
    desc_info.argv = &desc_argv;
114
   
114
   
115
    spinlock_initialize(&desc_info.lock);
115
    spinlock_initialize(&desc_info.lock);
116
    link_initialize(&desc_info.link);
116
    link_initialize(&desc_info.link);
117
   
117
   
118
    if (!cmd_register(&desc_info))
118
    if (!cmd_register(&desc_info))
119
        panic("could not register command %s\n", desc_info.name);
119
        panic("could not register command %s\n", desc_info.name);
120
}
120
}
121
 
121
 
122
 
122
 
123
/** Register kconsole command.
123
/** Register kconsole command.
124
 *
124
 *
125
 * @param cmd Structure describing the command.
125
 * @param cmd Structure describing the command.
126
 *
126
 *
127
 * @return 0 on failure, 1 on success.
127
 * @return 0 on failure, 1 on success.
128
 */
128
 */
129
int cmd_register(cmd_info_t *cmd)
129
int cmd_register(cmd_info_t *cmd)
130
{
130
{
131
    ipl_t ipl;
131
    ipl_t ipl;
132
    link_t *cur;
132
    link_t *cur;
133
   
133
   
134
    ipl = interrupts_disable();
134
    ipl = interrupts_disable();
135
    spinlock_lock(&cmd_lock);
135
    spinlock_lock(&cmd_lock);
136
   
136
   
137
    /*
137
    /*
138
     * Make sure the command is not already listed.
138
     * Make sure the command is not already listed.
139
     */
139
     */
140
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
140
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
141
        cmd_info_t *hlp;
141
        cmd_info_t *hlp;
142
       
142
       
143
        hlp = list_get_instance(cur, cmd_info_t, link);
143
        hlp = list_get_instance(cur, cmd_info_t, link);
144
 
144
 
145
        if (hlp == cmd) {
145
        if (hlp == cmd) {
146
            /* The command is already there. */
146
            /* The command is already there. */
147
            spinlock_unlock(&cmd_lock);
147
            spinlock_unlock(&cmd_lock);
148
            interrupts_restore(ipl);
148
            interrupts_restore(ipl);
149
            return 0;
149
            return 0;
150
        }
150
        }
151
 
151
 
152
        /* Avoid deadlock. */
152
        /* Avoid deadlock. */
153
        if (hlp < cmd) {
153
        if (hlp < cmd) {
154
            spinlock_lock(&hlp->lock);
154
            spinlock_lock(&hlp->lock);
155
            spinlock_lock(&cmd->lock);
155
            spinlock_lock(&cmd->lock);
156
        } else {
156
        } else {
157
            spinlock_lock(&cmd->lock);
157
            spinlock_lock(&cmd->lock);
158
            spinlock_lock(&hlp->lock);
158
            spinlock_lock(&hlp->lock);
159
        }
159
        }
160
       
160
       
161
        if ((strncmp(hlp->name, cmd->name, strlen(cmd->name)) == 0)) {
161
        if ((strncmp(hlp->name, cmd->name, strlen(cmd->name)) == 0)) {
162
            /* The command is already there. */
162
            /* The command is already there. */
163
            spinlock_unlock(&hlp->lock);
163
            spinlock_unlock(&hlp->lock);
164
            spinlock_unlock(&cmd->lock);
164
            spinlock_unlock(&cmd->lock);
165
            spinlock_unlock(&cmd_lock);
165
            spinlock_unlock(&cmd_lock);
166
            interrupts_restore(ipl);
166
            interrupts_restore(ipl);
167
            return 0;
167
            return 0;
168
        }
168
        }
169
       
169
       
170
        spinlock_unlock(&hlp->lock);
170
        spinlock_unlock(&hlp->lock);
171
        spinlock_unlock(&cmd->lock);
171
        spinlock_unlock(&cmd->lock);
172
    }
172
    }
173
   
173
   
174
    /*
174
    /*
175
     * Now the command can be added.
175
     * Now the command can be added.
176
     */
176
     */
177
    list_append(&cmd->link, &cmd_head);
177
    list_append(&cmd->link, &cmd_head);
178
   
178
   
179
    spinlock_unlock(&cmd_lock);
179
    spinlock_unlock(&cmd_lock);
180
    interrupts_restore(ipl);
180
    interrupts_restore(ipl);
181
    return 1;
181
    return 1;
182
}
182
}
183
 
183
 
184
/** Kernel console managing thread.
184
/** Kernel console managing thread.
185
 *
185
 *
186
 * @param arg Not used.
186
 * @param arg Not used.
187
 */
187
 */
188
void kconsole(void *arg)
188
void kconsole(void *arg)
189
{
189
{
190
    char cmdline[MAX_CMDLINE+1];
190
    char cmdline[MAX_CMDLINE+1];
191
    cmd_info_t *cmd_info;
191
    cmd_info_t *cmd_info;
192
    count_t len;
192
    count_t len;
193
 
193
 
194
    if (!stdin) {
194
    if (!stdin) {
195
        printf("%s: no stdin\n", __FUNCTION__);
195
        printf("%s: no stdin\n", __FUNCTION__);
196
        return;
196
        return;
197
    }
197
    }
198
   
198
   
199
    while (true) {
199
    while (true) {
200
        printf("%s> ", __FUNCTION__);
200
        printf("%s> ", __FUNCTION__);
201
        if (!(len = gets(stdin, cmdline, sizeof(cmdline))))
201
        if (!(len = gets(stdin, cmdline, sizeof(cmdline))))
202
            continue;
202
            continue;
203
        cmdline[len] = '\0';
203
        cmdline[len] = '\0';
204
        cmd_info = parse_cmdline(cmdline, len);
204
        cmd_info = parse_cmdline(cmdline, len);
205
        if (!cmd_info)
205
        if (!cmd_info)
206
            continue;
206
            continue;
207
        (void) cmd_info->func(cmd_info->argv);
207
        (void) cmd_info->func(cmd_info->argv);
208
    }
208
    }
209
}
209
}
210
 
210
 
211
/** Parse command line.
211
/** Parse command line.
212
 *
212
 *
213
 * @param cmdline Command line as read from input device.
213
 * @param cmdline Command line as read from input device.
214
 * @param len Command line length.
214
 * @param len Command line length.
215
 *
215
 *
216
 * @return Structure describing the command.
216
 * @return Structure describing the command.
217
 */
217
 */
218
cmd_info_t *parse_cmdline(char *cmdline, size_t len)
218
cmd_info_t *parse_cmdline(char *cmdline, size_t len)
219
{
219
{
220
    index_t start = 0, end = 0;
220
    index_t start = 0, end = 0;
221
    cmd_info_t *cmd = NULL;
221
    cmd_info_t *cmd = NULL;
222
    link_t *cur;
222
    link_t *cur;
223
    ipl_t ipl;
223
    ipl_t ipl;
224
    int i;
224
    int i;
225
   
225
   
226
    if (!parse_argument(cmdline, len, &start, &end)) {
226
    if (!parse_argument(cmdline, len, &start, &end)) {
227
        /* Command line did not contain alphanumeric word. */
227
        /* Command line did not contain alphanumeric word. */
228
        return NULL;
228
        return NULL;
229
    }
229
    }
230
 
230
 
231
    ipl = interrupts_disable();
231
    ipl = interrupts_disable();
232
    spinlock_lock(&cmd_lock);
232
    spinlock_lock(&cmd_lock);
233
   
233
   
234
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
234
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
235
        cmd_info_t *hlp;
235
        cmd_info_t *hlp;
236
       
236
       
237
        hlp = list_get_instance(cur, cmd_info_t, link);
237
        hlp = list_get_instance(cur, cmd_info_t, link);
238
        spinlock_lock(&hlp->lock);
238
        spinlock_lock(&hlp->lock);
239
       
239
       
240
        if (strncmp(hlp->name, &cmdline[start], (end - start) + 1) == 0) {
240
        if (strncmp(hlp->name, &cmdline[start], (end - start) + 1) == 0) {
241
            cmd = hlp;
241
            cmd = hlp;
242
            break;
242
            break;
243
        }
243
        }
244
       
244
       
245
        spinlock_unlock(&hlp->lock);
245
        spinlock_unlock(&hlp->lock);
246
    }
246
    }
247
   
247
   
248
    spinlock_unlock(&cmd_lock);
248
    spinlock_unlock(&cmd_lock);
249
   
249
   
250
    if (!cmd) {
250
    if (!cmd) {
251
        /* Unknown command. */
251
        /* Unknown command. */
252
        printf("Unknown command.\n");
252
        printf("Unknown command.\n");
253
        interrupts_restore(ipl);
253
        interrupts_restore(ipl);
254
        return NULL;
254
        return NULL;
255
    }
255
    }
256
 
256
 
257
    /* cmd == hlp is locked */
257
    /* cmd == hlp is locked */
258
   
258
   
259
    /*
259
    /*
260
     * The command line must be further analyzed and
260
     * The command line must be further analyzed and
261
     * the parameters therefrom must be matched and
261
     * the parameters therefrom must be matched and
262
     * converted to those specified in the cmd info
262
     * converted to those specified in the cmd info
263
     * structure.
263
     * structure.
264
     */
264
     */
265
 
265
 
266
    for (i = 0; i < cmd->argc; i++) {
266
    for (i = 0; i < cmd->argc; i++) {
267
        char *buf;
267
        char *buf;
268
        start = end + 1;
268
        start = end + 1;
269
        if (!parse_argument(cmdline, len, &start, &end)) {
269
        if (!parse_argument(cmdline, len, &start, &end)) {
270
            printf("Too few arguments.\n");
270
            printf("Too few arguments.\n");
271
            spinlock_unlock(&cmd->lock);
271
            spinlock_unlock(&cmd->lock);
272
            interrupts_restore(ipl);
272
            interrupts_restore(ipl);
273
            return NULL;
273
            return NULL;
274
        }
274
        }
275
       
275
       
276
        switch (cmd->argv[i].type) {
276
        switch (cmd->argv[i].type) {
277
            case ARG_TYPE_STRING:
277
            case ARG_TYPE_STRING:
278
                buf = cmd->argv[i].buffer;
278
                buf = cmd->argv[i].buffer;
279
                strncpy(buf, (const char *) &cmdline[start], min((end - start) + 1, cmd->argv[i].len - 1));
279
                strncpy(buf, (const char *) &cmdline[start], min((end - start) + 1, cmd->argv[i].len - 1));
280
            buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0';
280
            buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0';
281
            break;
281
            break;
282
            case ARG_TYPE_INT:
282
            case ARG_TYPE_INT:
283
            case ARG_TYPE_INVALID:
283
            case ARG_TYPE_INVALID:
284
            default:
284
            default:
285
            panic("invalid argument type\n");
285
            panic("invalid argument type\n");
286
            break;
286
            break;
287
        }
287
        }
288
    }
288
    }
289
   
289
   
290
    start = end + 1;
290
    start = end + 1;
291
    if (parse_argument(cmdline, len, &start, &end)) {
291
    if (parse_argument(cmdline, len, &start, &end)) {
292
        printf("Too many arguments.\n");
292
        printf("Too many arguments.\n");
293
        spinlock_unlock(&cmd->lock);
293
        spinlock_unlock(&cmd->lock);
294
        interrupts_restore(ipl);
294
        interrupts_restore(ipl);
295
        return NULL;
295
        return NULL;
296
    }
296
    }
297
   
297
   
298
    spinlock_unlock(&cmd->lock);
298
    spinlock_unlock(&cmd->lock);
299
    interrupts_restore(ipl);
299
    interrupts_restore(ipl);
300
    return cmd;
300
    return cmd;
301
}
301
}
302
 
302
 
303
/** Parse argument.
303
/** Parse argument.
304
 *
304
 *
305
 * Find start and end positions of command line argument.
305
 * Find start and end positions of command line argument.
306
 *
306
 *
307
 * @param cmdline Command line as read from the input device.
307
 * @param cmdline Command line as read from the input device.
308
 * @param len Number of characters in cmdline.
308
 * @param len Number of characters in cmdline.
309
 * @param start On entry, 'start' contains pointer to the index
309
 * @param start On entry, 'start' contains pointer to the index
310
 *        of first unprocessed character of cmdline.
310
 *        of first unprocessed character of cmdline.
311
 *        On successful exit, it marks beginning of the next argument.
311
 *        On successful exit, it marks beginning of the next argument.
312
 * @param end Undefined on entry. On exit, 'end' points to the last character
312
 * @param end Undefined on entry. On exit, 'end' points to the last character
313
 *        of the next argument.
313
 *        of the next argument.
314
 *
314
 *
315
 * @return false on failure, true on success.
315
 * @return false on failure, true on success.
316
 */
316
 */
317
bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end)
317
bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end)
318
{
318
{
319
    int i;
319
    int i;
320
    bool found_start = false;
320
    bool found_start = false;
321
   
321
   
322
    ASSERT(start != NULL);
322
    ASSERT(start != NULL);
323
    ASSERT(end != NULL);
323
    ASSERT(end != NULL);
324
   
324
   
325
    for (i = *start; i < len; i++) {
325
    for (i = *start; i < len; i++) {
326
        if (!found_start) {
326
        if (!found_start) {
327
            if (is_white(cmdline[i]))
327
            if (is_white(cmdline[i]))
328
                (*start)++;
328
                (*start)++;
329
            else
329
            else
330
                found_start = true;
330
                found_start = true;
331
        } else {
331
        } else {
332
            if (is_white(cmdline[i]))
332
            if (is_white(cmdline[i]))
333
                break;
333
                break;
334
        }
334
        }
335
    }
335
    }
336
    *end = i - 1;
336
    *end = i - 1;
337
 
337
 
338
    return found_start;
338
    return found_start;
339
}
339
}
340
 
340
 
341
 
341
 
342
/** List supported commands.
342
/** List supported commands.
343
 *
343
 *
344
 * @param argv Argument vector.
344
 * @param argv Argument vector.
345
 *
345
 *
346
 * @return 0 on failure, 1 on success.
346
 * @return 0 on failure, 1 on success.
347
 */
347
 */
348
int cmd_help(cmd_arg_t *argv)
348
int cmd_help(cmd_arg_t *argv)
349
{
349
{
350
    link_t *cur;
350
    link_t *cur;
351
    ipl_t ipl;
351
    ipl_t ipl;
352
 
352
 
353
    ipl = interrupts_disable();
353
    ipl = interrupts_disable();
354
    spinlock_lock(&cmd_lock);
354
    spinlock_lock(&cmd_lock);
355
   
355
   
356
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
356
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
357
        cmd_info_t *hlp;
357
        cmd_info_t *hlp;
358
       
358
       
359
        hlp = list_get_instance(cur, cmd_info_t, link);
359
        hlp = list_get_instance(cur, cmd_info_t, link);
360
        spinlock_lock(&hlp->lock);
360
        spinlock_lock(&hlp->lock);
361
       
361
       
362
        printf("%s - %s\n", hlp->name, hlp->description);
362
        printf("%s - %s\n", hlp->name, hlp->description);
363
 
363
 
364
        spinlock_unlock(&hlp->lock);
364
        spinlock_unlock(&hlp->lock);
365
    }
365
    }
366
   
366
   
367
    spinlock_unlock(&cmd_lock);
367
    spinlock_unlock(&cmd_lock);
368
    interrupts_restore(ipl);
368
    interrupts_restore(ipl);
369
 
369
 
370
    return 1;
370
    return 1;
371
}
371
}
372
 
372
 
373
/** Describe specified command.
373
/** Describe specified command.
374
 *
374
 *
375
 * @param argv Argument vector.
375
 * @param argv Argument vector.
376
 *
376
 *
377
 * @return 0 on failure, 1 on success.
377
 * @return 0 on failure, 1 on success.
378
 */
378
 */
379
int cmd_desc(cmd_arg_t *argv)
379
int cmd_desc(cmd_arg_t *argv)
380
{
380
{
381
    link_t *cur;
381
    link_t *cur;
382
    ipl_t ipl;
382
    ipl_t ipl;
383
 
383
 
384
    ipl = interrupts_disable();
384
    ipl = interrupts_disable();
385
    spinlock_lock(&cmd_lock);
385
    spinlock_lock(&cmd_lock);
386
   
386
   
387
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
387
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
388
        cmd_info_t *hlp;
388
        cmd_info_t *hlp;
389
       
389
       
390
        hlp = list_get_instance(cur, cmd_info_t, link);
390
        hlp = list_get_instance(cur, cmd_info_t, link);
391
        spinlock_lock(&hlp->lock);
391
        spinlock_lock(&hlp->lock);
392
 
392
 
393
        if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) {
393
        if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) {
394
            printf("%s - %s\n", hlp->name, hlp->description);
394
            printf("%s - %s\n", hlp->name, hlp->description);
395
            if (hlp->help)
395
            if (hlp->help)
396
                hlp->help();
396
                hlp->help();
397
            spinlock_unlock(&hlp->lock);
397
            spinlock_unlock(&hlp->lock);
398
            break;
398
            break;
399
        }
399
        }
400
 
400
 
401
        spinlock_unlock(&hlp->lock);
401
        spinlock_unlock(&hlp->lock);
402
    }
402
    }
403
   
403
   
404
    spinlock_unlock(&cmd_lock);
404
    spinlock_unlock(&cmd_lock);
405
    interrupts_restore(ipl);
405
    interrupts_restore(ipl);
406
 
406
 
407
    return 1;
407
    return 1;
408
}
408
}
409
 
409
 
410
/** Print detailed description of 'describe' command. */
410
/** Print detailed description of 'describe' command. */
411
void desc_help(void)
411
void desc_help(void)
412
{
412
{
413
    printf("Syntax: describe command_name\n");
413
    printf("Syntax: describe command_name\n");
414
}
414
}
415
 
415