Subversion Repositories HelenOS

Rev

Rev 4345 | Rev 4347 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4345 Rev 4346
Line 48... Line 48...
48
#include <arch.h>
48
#include <arch.h>
49
#include <macros.h>
49
#include <macros.h>
50
#include <debug.h>
50
#include <debug.h>
51
#include <func.h>
51
#include <func.h>
52
#include <string.h>
52
#include <string.h>
53
#include <symtab.h>
-
 
54
#include <macros.h>
53
#include <macros.h>
55
#include <sysinfo/sysinfo.h>
54
#include <sysinfo/sysinfo.h>
56
#include <ddi/device.h>
55
#include <ddi/device.h>
-
 
56
#include <symtab.h>
-
 
57
#include <errno.h>
57
 
58
 
58
/** Simple kernel console.
59
/** Simple kernel console.
59
 *
60
 *
60
 * The console is realized by kernel thread kconsole.
61
 * The console is realized by kernel thread kconsole.
61
 * It doesn't understand any useful command on its own,
62
 * It doesn't understand any useful command on its own,
Line 256... Line 257...
256
 * @param name - string to match, changed to hint on exit
257
 * @param name - string to match, changed to hint on exit
257
 * @return number of found matches
258
 * @return number of found matches
258
 */
259
 */
259
static int cmdtab_compl(char *name)
260
static int cmdtab_compl(char *name)
260
{
261
{
261
    static char output[MAX_SYMBOL_NAME + 1];
262
    static char output[/*MAX_SYMBOL_NAME*/128 + 1];
262
    link_t *startpos = NULL;
263
    link_t *startpos = NULL;
263
    const char *foundtxt;
264
    const char *foundtxt;
264
    int found = 0;
265
    int found = 0;
265
    int i;
266
    int i;
266
 
267
 
Line 288... Line 289...
288
            hlp = list_get_instance(startpos, cmd_info_t, link);
289
            hlp = list_get_instance(startpos, cmd_info_t, link);
289
            printf("%s - %s\n", hlp->name, hlp->description);
290
            printf("%s - %s\n", hlp->name, hlp->description);
290
            startpos = startpos->next;
291
            startpos = startpos->next;
291
        }
292
        }
292
    }
293
    }
293
    strncpy(name, output, MAX_SYMBOL_NAME);
294
    strncpy(name, output, 128/*MAX_SYMBOL_NAME*/);
294
    return found;
295
    return found;
295
   
-
 
296
}
296
}
297
 
297
 
298
static char *clever_readline(const char *prompt, chardev_t *input)
298
static char *clever_readline(const char *prompt, indev_t *input)
299
{
299
{
300
    static int histposition = 0;
300
    static int histposition = 0;
301
 
301
 
302
    static char tmp[MAX_CMDLINE + 1];
302
    static char tmp[MAX_CMDLINE + 1];
303
    int curlen = 0, position = 0;
303
    int curlen = 0, position = 0;
Line 454... Line 454...
454
    }
454
    }
455
    current[curlen] = '\0';
455
    current[curlen] = '\0';
456
    return current;
456
    return current;
457
}
457
}
458
 
458
 
-
 
459
bool kconsole_check_poll(void)
-
 
460
{
-
 
461
    return check_poll(stdin);
-
 
462
}
-
 
463
 
459
/** Kernel console prompt.
464
/** Kernel console prompt.
460
 *
465
 *
461
 * @param prompt Kernel console prompt (e.g kconsole/panic).
466
 * @param prompt Kernel console prompt (e.g kconsole/panic).
462
 * @param msg    Message to display in the beginning.
467
 * @param msg    Message to display in the beginning.
463
 * @param kcon   Wait for keypress to show the prompt
468
 * @param kcon   Wait for keypress to show the prompt
Line 467... Line 472...
467
void kconsole(char *prompt, char *msg, bool kcon)
472
void kconsole(char *prompt, char *msg, bool kcon)
468
{
473
{
469
    cmd_info_t *cmd_info;
474
    cmd_info_t *cmd_info;
470
    count_t len;
475
    count_t len;
471
    char *cmdline;
476
    char *cmdline;
472
 
477
   
473
    if (!stdin) {
478
    if (!stdin) {
474
        LOG("No stdin for kernel console");
479
        LOG("No stdin for kernel console");
475
        return;
480
        return;
476
    }
481
    }
477
   
482
   
478
    if (msg)
483
    if (msg)
479
        printf("%s", msg);
484
        printf("%s", msg);
480
   
485
   
481
    if (kcon)
486
    if (kcon)
482
        _getc(stdin);
487
        _getc(stdin);
-
 
488
    else
-
 
489
        printf("Type \"exit\" to leave the console.\n");
483
   
490
   
484
    while (true) {
491
    while (true) {
485
        cmdline = clever_readline((char *) prompt, stdin);
492
        cmdline = clever_readline((char *) prompt, stdin);
486
        len = strlen(cmdline);
493
        len = strlen(cmdline);
487
        if (!len)
494
        if (!len)
488
            continue;
495
            continue;
489
       
496
       
-
 
497
        if ((!kcon) && (len == 4) && (strncmp(cmdline, "exit", 4) == 0))
-
 
498
            break;
-
 
499
       
490
        cmd_info = parse_cmdline(cmdline, len);
500
        cmd_info = parse_cmdline(cmdline, len);
491
        if (!cmd_info)
501
        if (!cmd_info)
492
            continue;
502
            continue;
493
       
503
       
494
        if ((!kcon)
-
 
495
            && (strncmp(cmd_info->name, "exit", min(strlen(cmd_info->name), 5)) == 0))
-
 
496
            break;
-
 
497
       
-
 
498
        (void) cmd_info->func(cmd_info->argv);
504
        (void) cmd_info->func(cmd_info->argv);
499
    }
505
    }
500
}
506
}
501
 
507
 
502
/** Kernel console managing thread.
508
/** Kernel console managing thread.
Line 507... Line 513...
507
    kconsole("kconsole", "Kernel console ready (press any key to activate)\n", true);
513
    kconsole("kconsole", "Kernel console ready (press any key to activate)\n", true);
508
}
514
}
509
 
515
 
510
static int parse_int_arg(char *text, size_t len, unative_t *result)
516
static int parse_int_arg(char *text, size_t len, unative_t *result)
511
{
517
{
512
    static char symname[MAX_SYMBOL_NAME];
-
 
513
    uintptr_t symaddr;
518
    uintptr_t symaddr;
514
    bool isaddr = false;
519
    bool isaddr = false;
515
    bool isptr = false;
520
    bool isptr = false;
-
 
521
    int rc;
-
 
522
 
-
 
523
    static char symname[MAX_SYMBOL_NAME];
516
   
524
   
517
    /* If we get a name, try to find it in symbol table */
525
    /* If we get a name, try to find it in symbol table */
518
    if (text[0] == '&') {
526
    if (text[0] == '&') {
519
        isaddr = true;
527
        isaddr = true;
520
        text++;
528
        text++;
Line 524... Line 532...
524
        text++;
532
        text++;
525
        len--;
533
        len--;
526
    }
534
    }
527
    if (text[0] < '0' || text[0] > '9') {
535
    if (text[0] < '0' || text[0] > '9') {
528
        strncpy(symname, text, min(len + 1, MAX_SYMBOL_NAME));
536
        strncpy(symname, text, min(len + 1, MAX_SYMBOL_NAME));
529
        symaddr = get_symbol_addr(symname);
537
        rc = symtab_addr_lookup(symname, &symaddr);
530
        if (!symaddr) {
538
        switch (rc) {
-
 
539
        case ENOENT:
531
            printf("Symbol %s not found.\n", symname);
540
            printf("Symbol %s not found.\n", symname);
532
            return -1;
541
            return -1;
533
        }
-
 
534
        if (symaddr == (uintptr_t) -1) {
542
        case EOVERFLOW:
535
            printf("Duplicate symbol %s.\n", symname);
543
            printf("Duplicate symbol %s.\n", symname);
536
            symtab_print_search(symname);
544
            symtab_print_search(symname);
537
            return -1;
545
            return -1;
-
 
546
        default:
-
 
547
            printf("No symbol information available.\n");
-
 
548
            return -1;
538
        }
549
        }
-
 
550
 
539
        if (isaddr)
551
        if (isaddr)
540
            *result = (unative_t)symaddr;
552
            *result = (unative_t)symaddr;
541
        else if (isptr)
553
        else if (isptr)
542
            *result = **((unative_t **)symaddr);
554
            *result = **((unative_t **)symaddr);
543
        else
555
        else