Subversion Repositories HelenOS-historic

Rev

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

Rev 548 Rev 552
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
/** Data and methods for 'halt' command. */
88
/** Data and methods for 'halt' command. */
89
static int cmd_halt(cmd_arg_t *argv);
89
static int cmd_halt(cmd_arg_t *argv);
90
static cmd_info_t halt_info;
90
static cmd_info_t halt_info;
91
 
91
 
92
/** Initialize kconsole data structures. */
92
/** Initialize kconsole data structures. */
93
void kconsole_init(void)
93
void kconsole_init(void)
94
{
94
{
95
    spinlock_initialize(&cmd_lock);
95
    spinlock_initialize(&cmd_lock, "kconsole_cmd");
96
    list_initialize(&cmd_head);
96
    list_initialize(&cmd_head);
97
   
97
   
98
    help_info.name = "help";
98
    help_info.name = "help";
99
    help_info.description = "List supported commands.";
99
    help_info.description = "List supported commands.";
100
    help_info.func = cmd_help;
100
    help_info.func = cmd_help;
101
    help_info.help = NULL;
101
    help_info.help = NULL;
102
    help_info.argc = 0;
102
    help_info.argc = 0;
103
    help_info.argv = NULL;
103
    help_info.argv = NULL;
104
 
104
 
105
    spinlock_initialize(&help_info.lock);
105
    spinlock_initialize(&help_info.lock, "kconsole_help");
106
    link_initialize(&help_info.link);
106
    link_initialize(&help_info.link);
107
 
107
 
108
    if (!cmd_register(&help_info))
108
    if (!cmd_register(&help_info))
109
        panic("could not register command %s\n", help_info.name);
109
        panic("could not register command %s\n", help_info.name);
110
 
110
 
111
 
111
 
112
    desc_info.name = "describe";
112
    desc_info.name = "describe";
113
    desc_info.description = "Describe specified command.";
113
    desc_info.description = "Describe specified command.";
114
    desc_info.help = desc_help;
114
    desc_info.help = desc_help;
115
    desc_info.func = cmd_desc;
115
    desc_info.func = cmd_desc;
116
    desc_info.argc = 1;
116
    desc_info.argc = 1;
117
    desc_info.argv = &desc_argv;
117
    desc_info.argv = &desc_argv;
118
   
118
   
119
    spinlock_initialize(&desc_info.lock);
119
    spinlock_initialize(&desc_info.lock, "kconsole_desc");
120
    link_initialize(&desc_info.link);
120
    link_initialize(&desc_info.link);
121
   
121
   
122
    if (!cmd_register(&desc_info))
122
    if (!cmd_register(&desc_info))
123
        panic("could not register command %s\n", desc_info.name);
123
        panic("could not register command %s\n", desc_info.name);
124
   
124
   
125
   
125
   
126
    halt_info.name = "halt";
126
    halt_info.name = "halt";
127
    halt_info.description = "Halt the kernel.";
127
    halt_info.description = "Halt the kernel.";
128
    halt_info.func = cmd_halt;
128
    halt_info.func = cmd_halt;
129
    halt_info.help = NULL;
129
    halt_info.help = NULL;
130
    halt_info.argc = 0;
130
    halt_info.argc = 0;
131
    halt_info.argv = NULL;
131
    halt_info.argv = NULL;
132
 
132
 
133
    spinlock_initialize(&halt_info.lock);
133
    spinlock_initialize(&halt_info.lock, "kconsole_halt");
134
    link_initialize(&halt_info.link);
134
    link_initialize(&halt_info.link);
135
 
135
 
136
    if (!cmd_register(&halt_info))
136
    if (!cmd_register(&halt_info))
137
        panic("could not register command %s\n", halt_info.name);
137
        panic("could not register command %s\n", halt_info.name);
138
}
138
}
139
 
139
 
140
 
140
 
141
/** Register kconsole command.
141
/** Register kconsole command.
142
 *
142
 *
143
 * @param cmd Structure describing the command.
143
 * @param cmd Structure describing the command.
144
 *
144
 *
145
 * @return 0 on failure, 1 on success.
145
 * @return 0 on failure, 1 on success.
146
 */
146
 */
147
int cmd_register(cmd_info_t *cmd)
147
int cmd_register(cmd_info_t *cmd)
148
{
148
{
149
    ipl_t ipl;
149
    ipl_t ipl;
150
    link_t *cur;
150
    link_t *cur;
151
   
151
   
152
    ipl = interrupts_disable();
152
    ipl = interrupts_disable();
153
    spinlock_lock(&cmd_lock);
153
    spinlock_lock(&cmd_lock);
154
   
154
   
155
    /*
155
    /*
156
     * Make sure the command is not already listed.
156
     * Make sure the command is not already listed.
157
     */
157
     */
158
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
158
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
159
        cmd_info_t *hlp;
159
        cmd_info_t *hlp;
160
       
160
       
161
        hlp = list_get_instance(cur, cmd_info_t, link);
161
        hlp = list_get_instance(cur, cmd_info_t, link);
162
 
162
 
163
        if (hlp == cmd) {
163
        if (hlp == cmd) {
164
            /* The command is already there. */
164
            /* The command is already there. */
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
        /* Avoid deadlock. */
170
        /* Avoid deadlock. */
171
        if (hlp < cmd) {
171
        if (hlp < cmd) {
172
            spinlock_lock(&hlp->lock);
172
            spinlock_lock(&hlp->lock);
173
            spinlock_lock(&cmd->lock);
173
            spinlock_lock(&cmd->lock);
174
        } else {
174
        } else {
175
            spinlock_lock(&cmd->lock);
175
            spinlock_lock(&cmd->lock);
176
            spinlock_lock(&hlp->lock);
176
            spinlock_lock(&hlp->lock);
177
        }
177
        }
178
       
178
       
179
        if ((strncmp(hlp->name, cmd->name, strlen(cmd->name)) == 0)) {
179
        if ((strncmp(hlp->name, cmd->name, strlen(cmd->name)) == 0)) {
180
            /* The command is already there. */
180
            /* The command is already there. */
181
            spinlock_unlock(&hlp->lock);
181
            spinlock_unlock(&hlp->lock);
182
            spinlock_unlock(&cmd->lock);
182
            spinlock_unlock(&cmd->lock);
183
            spinlock_unlock(&cmd_lock);
183
            spinlock_unlock(&cmd_lock);
184
            interrupts_restore(ipl);
184
            interrupts_restore(ipl);
185
            return 0;
185
            return 0;
186
        }
186
        }
187
       
187
       
188
        spinlock_unlock(&hlp->lock);
188
        spinlock_unlock(&hlp->lock);
189
        spinlock_unlock(&cmd->lock);
189
        spinlock_unlock(&cmd->lock);
190
    }
190
    }
191
   
191
   
192
    /*
192
    /*
193
     * Now the command can be added.
193
     * Now the command can be added.
194
     */
194
     */
195
    list_append(&cmd->link, &cmd_head);
195
    list_append(&cmd->link, &cmd_head);
196
   
196
   
197
    spinlock_unlock(&cmd_lock);
197
    spinlock_unlock(&cmd_lock);
198
    interrupts_restore(ipl);
198
    interrupts_restore(ipl);
199
    return 1;
199
    return 1;
200
}
200
}
201
 
201
 
202
/** Kernel console managing thread.
202
/** Kernel console managing thread.
203
 *
203
 *
204
 * @param arg Not used.
204
 * @param arg Not used.
205
 */
205
 */
206
void kconsole(void *arg)
206
void kconsole(void *arg)
207
{
207
{
208
    char cmdline[MAX_CMDLINE+1];
208
    char cmdline[MAX_CMDLINE+1];
209
    cmd_info_t *cmd_info;
209
    cmd_info_t *cmd_info;
210
    count_t len;
210
    count_t len;
211
 
211
 
212
    if (!stdin) {
212
    if (!stdin) {
213
        printf("%s: no stdin\n", __FUNCTION__);
213
        printf("%s: no stdin\n", __FUNCTION__);
214
        return;
214
        return;
215
    }
215
    }
216
   
216
   
217
    while (true) {
217
    while (true) {
218
        printf("%s> ", __FUNCTION__);
218
        printf("%s> ", __FUNCTION__);
219
        if (!(len = gets(stdin, cmdline, sizeof(cmdline))))
219
        if (!(len = gets(stdin, cmdline, sizeof(cmdline))))
220
            continue;
220
            continue;
221
        cmdline[len] = '\0';
221
        cmdline[len] = '\0';
222
        cmd_info = parse_cmdline(cmdline, len);
222
        cmd_info = parse_cmdline(cmdline, len);
223
        if (!cmd_info)
223
        if (!cmd_info)
224
            continue;
224
            continue;
225
        (void) cmd_info->func(cmd_info->argv);
225
        (void) cmd_info->func(cmd_info->argv);
226
    }
226
    }
227
}
227
}
228
 
228
 
229
/** Parse command line.
229
/** Parse command line.
230
 *
230
 *
231
 * @param cmdline Command line as read from input device.
231
 * @param cmdline Command line as read from input device.
232
 * @param len Command line length.
232
 * @param len Command line length.
233
 *
233
 *
234
 * @return Structure describing the command.
234
 * @return Structure describing the command.
235
 */
235
 */
236
cmd_info_t *parse_cmdline(char *cmdline, size_t len)
236
cmd_info_t *parse_cmdline(char *cmdline, size_t len)
237
{
237
{
238
    index_t start = 0, end = 0;
238
    index_t start = 0, end = 0;
239
    cmd_info_t *cmd = NULL;
239
    cmd_info_t *cmd = NULL;
240
    link_t *cur;
240
    link_t *cur;
241
    ipl_t ipl;
241
    ipl_t ipl;
242
    int i;
242
    int i;
243
   
243
   
244
    if (!parse_argument(cmdline, len, &start, &end)) {
244
    if (!parse_argument(cmdline, len, &start, &end)) {
245
        /* Command line did not contain alphanumeric word. */
245
        /* Command line did not contain alphanumeric word. */
246
        return NULL;
246
        return NULL;
247
    }
247
    }
248
 
248
 
249
    ipl = interrupts_disable();
249
    ipl = interrupts_disable();
250
    spinlock_lock(&cmd_lock);
250
    spinlock_lock(&cmd_lock);
251
   
251
   
252
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
252
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
253
        cmd_info_t *hlp;
253
        cmd_info_t *hlp;
254
       
254
       
255
        hlp = list_get_instance(cur, cmd_info_t, link);
255
        hlp = list_get_instance(cur, cmd_info_t, link);
256
        spinlock_lock(&hlp->lock);
256
        spinlock_lock(&hlp->lock);
257
       
257
       
258
        if (strncmp(hlp->name, &cmdline[start], (end - start) + 1) == 0) {
258
        if (strncmp(hlp->name, &cmdline[start], (end - start) + 1) == 0) {
259
            cmd = hlp;
259
            cmd = hlp;
260
            break;
260
            break;
261
        }
261
        }
262
       
262
       
263
        spinlock_unlock(&hlp->lock);
263
        spinlock_unlock(&hlp->lock);
264
    }
264
    }
265
   
265
   
266
    spinlock_unlock(&cmd_lock);
266
    spinlock_unlock(&cmd_lock);
267
   
267
   
268
    if (!cmd) {
268
    if (!cmd) {
269
        /* Unknown command. */
269
        /* Unknown command. */
270
        printf("Unknown command.\n");
270
        printf("Unknown command.\n");
271
        interrupts_restore(ipl);
271
        interrupts_restore(ipl);
272
        return NULL;
272
        return NULL;
273
    }
273
    }
274
 
274
 
275
    /* cmd == hlp is locked */
275
    /* cmd == hlp is locked */
276
   
276
   
277
    /*
277
    /*
278
     * The command line must be further analyzed and
278
     * The command line must be further analyzed and
279
     * the parameters therefrom must be matched and
279
     * the parameters therefrom must be matched and
280
     * converted to those specified in the cmd info
280
     * converted to those specified in the cmd info
281
     * structure.
281
     * structure.
282
     */
282
     */
283
 
283
 
284
    for (i = 0; i < cmd->argc; i++) {
284
    for (i = 0; i < cmd->argc; i++) {
285
        char *buf;
285
        char *buf;
286
        start = end + 1;
286
        start = end + 1;
287
        if (!parse_argument(cmdline, len, &start, &end)) {
287
        if (!parse_argument(cmdline, len, &start, &end)) {
288
            printf("Too few arguments.\n");
288
            printf("Too few arguments.\n");
289
            spinlock_unlock(&cmd->lock);
289
            spinlock_unlock(&cmd->lock);
290
            interrupts_restore(ipl);
290
            interrupts_restore(ipl);
291
            return NULL;
291
            return NULL;
292
        }
292
        }
293
       
293
       
294
        switch (cmd->argv[i].type) {
294
        switch (cmd->argv[i].type) {
295
            case ARG_TYPE_STRING:
295
            case ARG_TYPE_STRING:
296
                buf = cmd->argv[i].buffer;
296
                buf = cmd->argv[i].buffer;
297
                strncpy(buf, (const char *) &cmdline[start], min((end - start) + 1, cmd->argv[i].len - 1));
297
                strncpy(buf, (const char *) &cmdline[start], min((end - start) + 1, cmd->argv[i].len - 1));
298
            buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0';
298
            buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0';
299
            break;
299
            break;
300
            case ARG_TYPE_INT:
300
            case ARG_TYPE_INT:
301
            case ARG_TYPE_INVALID:
301
            case ARG_TYPE_INVALID:
302
            default:
302
            default:
303
            panic("invalid argument type\n");
303
            panic("invalid argument type\n");
304
            break;
304
            break;
305
        }
305
        }
306
    }
306
    }
307
   
307
   
308
    start = end + 1;
308
    start = end + 1;
309
    if (parse_argument(cmdline, len, &start, &end)) {
309
    if (parse_argument(cmdline, len, &start, &end)) {
310
        printf("Too many arguments.\n");
310
        printf("Too many arguments.\n");
311
        spinlock_unlock(&cmd->lock);
311
        spinlock_unlock(&cmd->lock);
312
        interrupts_restore(ipl);
312
        interrupts_restore(ipl);
313
        return NULL;
313
        return NULL;
314
    }
314
    }
315
   
315
   
316
    spinlock_unlock(&cmd->lock);
316
    spinlock_unlock(&cmd->lock);
317
    interrupts_restore(ipl);
317
    interrupts_restore(ipl);
318
    return cmd;
318
    return cmd;
319
}
319
}
320
 
320
 
321
/** Parse argument.
321
/** Parse argument.
322
 *
322
 *
323
 * Find start and end positions of command line argument.
323
 * Find start and end positions of command line argument.
324
 *
324
 *
325
 * @param cmdline Command line as read from the input device.
325
 * @param cmdline Command line as read from the input device.
326
 * @param len Number of characters in cmdline.
326
 * @param len Number of characters in cmdline.
327
 * @param start On entry, 'start' contains pointer to the index
327
 * @param start On entry, 'start' contains pointer to the index
328
 *        of first unprocessed character of cmdline.
328
 *        of first unprocessed character of cmdline.
329
 *        On successful exit, it marks beginning of the next argument.
329
 *        On successful exit, it marks beginning of the next argument.
330
 * @param end Undefined on entry. On exit, 'end' points to the last character
330
 * @param end Undefined on entry. On exit, 'end' points to the last character
331
 *        of the next argument.
331
 *        of the next argument.
332
 *
332
 *
333
 * @return false on failure, true on success.
333
 * @return false on failure, true on success.
334
 */
334
 */
335
bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end)
335
bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end)
336
{
336
{
337
    int i;
337
    int i;
338
    bool found_start = false;
338
    bool found_start = false;
339
   
339
   
340
    ASSERT(start != NULL);
340
    ASSERT(start != NULL);
341
    ASSERT(end != NULL);
341
    ASSERT(end != NULL);
342
   
342
   
343
    for (i = *start; i < len; i++) {
343
    for (i = *start; i < len; i++) {
344
        if (!found_start) {
344
        if (!found_start) {
345
            if (is_white(cmdline[i]))
345
            if (is_white(cmdline[i]))
346
                (*start)++;
346
                (*start)++;
347
            else
347
            else
348
                found_start = true;
348
                found_start = true;
349
        } else {
349
        } else {
350
            if (is_white(cmdline[i]))
350
            if (is_white(cmdline[i]))
351
                break;
351
                break;
352
        }
352
        }
353
    }
353
    }
354
    *end = i - 1;
354
    *end = i - 1;
355
 
355
 
356
    return found_start;
356
    return found_start;
357
}
357
}
358
 
358
 
359
 
359
 
360
/** List supported commands.
360
/** List supported commands.
361
 *
361
 *
362
 * @param argv Argument vector.
362
 * @param argv Argument vector.
363
 *
363
 *
364
 * @return 0 on failure, 1 on success.
364
 * @return 0 on failure, 1 on success.
365
 */
365
 */
366
int cmd_help(cmd_arg_t *argv)
366
int cmd_help(cmd_arg_t *argv)
367
{
367
{
368
    link_t *cur;
368
    link_t *cur;
369
    ipl_t ipl;
369
    ipl_t ipl;
370
 
370
 
371
    ipl = interrupts_disable();
371
    ipl = interrupts_disable();
372
    spinlock_lock(&cmd_lock);
372
    spinlock_lock(&cmd_lock);
373
   
373
   
374
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
374
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
375
        cmd_info_t *hlp;
375
        cmd_info_t *hlp;
376
       
376
       
377
        hlp = list_get_instance(cur, cmd_info_t, link);
377
        hlp = list_get_instance(cur, cmd_info_t, link);
378
        spinlock_lock(&hlp->lock);
378
        spinlock_lock(&hlp->lock);
379
       
379
       
380
        printf("%s - %s\n", hlp->name, hlp->description);
380
        printf("%s - %s\n", hlp->name, hlp->description);
381
 
381
 
382
        spinlock_unlock(&hlp->lock);
382
        spinlock_unlock(&hlp->lock);
383
    }
383
    }
384
   
384
   
385
    spinlock_unlock(&cmd_lock);
385
    spinlock_unlock(&cmd_lock);
386
    interrupts_restore(ipl);
386
    interrupts_restore(ipl);
387
 
387
 
388
    return 1;
388
    return 1;
389
}
389
}
390
 
390
 
391
/** Describe specified command.
391
/** Describe specified command.
392
 *
392
 *
393
 * @param argv Argument vector.
393
 * @param argv Argument vector.
394
 *
394
 *
395
 * @return 0 on failure, 1 on success.
395
 * @return 0 on failure, 1 on success.
396
 */
396
 */
397
int cmd_desc(cmd_arg_t *argv)
397
int cmd_desc(cmd_arg_t *argv)
398
{
398
{
399
    link_t *cur;
399
    link_t *cur;
400
    ipl_t ipl;
400
    ipl_t ipl;
401
 
401
 
402
    ipl = interrupts_disable();
402
    ipl = interrupts_disable();
403
    spinlock_lock(&cmd_lock);
403
    spinlock_lock(&cmd_lock);
404
   
404
   
405
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
405
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
406
        cmd_info_t *hlp;
406
        cmd_info_t *hlp;
407
       
407
       
408
        hlp = list_get_instance(cur, cmd_info_t, link);
408
        hlp = list_get_instance(cur, cmd_info_t, link);
409
        spinlock_lock(&hlp->lock);
409
        spinlock_lock(&hlp->lock);
410
 
410
 
411
        if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) {
411
        if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) {
412
            printf("%s - %s\n", hlp->name, hlp->description);
412
            printf("%s - %s\n", hlp->name, hlp->description);
413
            if (hlp->help)
413
            if (hlp->help)
414
                hlp->help();
414
                hlp->help();
415
            spinlock_unlock(&hlp->lock);
415
            spinlock_unlock(&hlp->lock);
416
            break;
416
            break;
417
        }
417
        }
418
 
418
 
419
        spinlock_unlock(&hlp->lock);
419
        spinlock_unlock(&hlp->lock);
420
    }
420
    }
421
   
421
   
422
    spinlock_unlock(&cmd_lock);
422
    spinlock_unlock(&cmd_lock);
423
    interrupts_restore(ipl);
423
    interrupts_restore(ipl);
424
 
424
 
425
    return 1;
425
    return 1;
426
}
426
}
427
 
427
 
428
/** Print detailed description of 'describe' command. */
428
/** Print detailed description of 'describe' command. */
429
void desc_help(void)
429
void desc_help(void)
430
{
430
{
431
    printf("Syntax: describe command_name\n");
431
    printf("Syntax: describe command_name\n");
432
}
432
}
433
 
433
 
434
/** Halt the kernel.
434
/** Halt the kernel.
435
 *
435
 *
436
 * @param argv Argument vector (ignored).
436
 * @param argv Argument vector (ignored).
437
 *
437
 *
438
 * @return 0 on failure, 1 on success (never returns).
438
 * @return 0 on failure, 1 on success (never returns).
439
 */
439
 */
440
int cmd_halt(cmd_arg_t *argv)
440
int cmd_halt(cmd_arg_t *argv)
441
{
441
{
442
    halt();
442
    halt();
443
    return 1;
443
    return 1;
444
}
444
}
445
 
445