Subversion Repositories HelenOS

Rev

Rev 2131 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2131 Rev 2307
Line 46... Line 46...
46
#include <print.h>
46
#include <print.h>
47
#include <panic.h>
47
#include <panic.h>
48
#include <arch/types.h>
48
#include <arch/types.h>
49
#include <adt/list.h>
49
#include <adt/list.h>
50
#include <arch.h>
50
#include <arch.h>
-
 
51
#include <config.h>
51
#include <func.h>
52
#include <func.h>
52
#include <macros.h>
53
#include <macros.h>
53
#include <debug.h>
54
#include <debug.h>
54
#include <symtab.h>
55
#include <symtab.h>
55
#include <cpu.h>
56
#include <cpu.h>
Line 77... Line 78...
77
    .argc = 0
78
    .argc = 0
78
};
79
};
79
 
80
 
80
static cmd_info_t exit_info = {
81
static cmd_info_t exit_info = {
81
    .name = "exit",
82
    .name = "exit",
82
    .description = "Exit kconsole",
83
    .description = "Exit kconsole.",
-
 
84
    .argc = 0
-
 
85
};
-
 
86
 
-
 
87
static int cmd_reboot(cmd_arg_t *argv);
-
 
88
static cmd_info_t reboot_info = {
-
 
89
    .name = "reboot",
-
 
90
    .description = "Reboot.",
-
 
91
    .func = cmd_reboot,
-
 
92
    .argc = 0
-
 
93
};
-
 
94
 
-
 
95
static int cmd_uptime(cmd_arg_t *argv);
-
 
96
static cmd_info_t uptime_info = {
-
 
97
    .name = "uptime",
-
 
98
    .description = "Print uptime information.",
-
 
99
    .func = cmd_uptime,
83
    .argc = 0
100
    .argc = 0
84
};
101
};
85
 
102
 
86
static int cmd_continue(cmd_arg_t *argv);
103
static int cmd_continue(cmd_arg_t *argv);
87
static cmd_info_t continue_info = {
104
static cmd_info_t continue_info = {
Line 190... Line 207...
190
    .argc = 2,
207
    .argc = 2,
191
    .argv = set4_argv
208
    .argv = set4_argv
192
};
209
};
193
 
210
 
194
/* Data and methods for 'call0' command. */
211
/* Data and methods for 'call0' command. */
195
static char call0_buf[MAX_CMDLINE+1];
212
static char call0_buf[MAX_CMDLINE + 1];
196
static char carg1_buf[MAX_CMDLINE+1];
213
static char carg1_buf[MAX_CMDLINE + 1];
197
static char carg2_buf[MAX_CMDLINE+1];
214
static char carg2_buf[MAX_CMDLINE + 1];
198
static char carg3_buf[MAX_CMDLINE+1];
215
static char carg3_buf[MAX_CMDLINE + 1];
199
 
216
 
200
static int cmd_call0(cmd_arg_t *argv);
217
static int cmd_call0(cmd_arg_t *argv);
201
static cmd_arg_t call0_argv = {
218
static cmd_arg_t call0_argv = {
202
    .type = ARG_TYPE_STRING,
219
    .type = ARG_TYPE_STRING,
203
    .buffer = call0_buf,
220
    .buffer = call0_buf,
Line 209... Line 226...
209
    .func = cmd_call0,
226
    .func = cmd_call0,
210
    .argc = 1,
227
    .argc = 1,
211
    .argv = &call0_argv
228
    .argv = &call0_argv
212
};
229
};
213
 
230
 
-
 
231
/* Data and methods for 'mcall0' command. */
-
 
232
static int cmd_mcall0(cmd_arg_t *argv);
-
 
233
static cmd_arg_t mcall0_argv = {
-
 
234
    .type = ARG_TYPE_STRING,
-
 
235
    .buffer = call0_buf,
-
 
236
    .len = sizeof(call0_buf)
-
 
237
};
-
 
238
static cmd_info_t mcall0_info = {
-
 
239
    .name = "mcall0",
-
 
240
    .description = "mcall0 <function> -> call function() on each CPU.",
-
 
241
    .func = cmd_mcall0,
-
 
242
    .argc = 1,
-
 
243
    .argv = &mcall0_argv
-
 
244
};
-
 
245
 
214
/* Data and methods for 'call1' command. */
246
/* Data and methods for 'call1' command. */
215
static int cmd_call1(cmd_arg_t *argv);
247
static int cmd_call1(cmd_arg_t *argv);
216
static cmd_arg_t call1_argv[] = {
248
static cmd_arg_t call1_argv[] = {
217
    {
249
    {
218
        .type = ARG_TYPE_STRING,
250
        .type = ARG_TYPE_STRING,
Line 404... Line 436...
404
    .argv = NULL
436
    .argv = NULL
405
};
437
};
406
 
438
 
407
static cmd_info_t *basic_commands[] = {
439
static cmd_info_t *basic_commands[] = {
408
    &call0_info,
440
    &call0_info,
-
 
441
    &mcall0_info,
409
    &call1_info,
442
    &call1_info,
410
    &call2_info,
443
    &call2_info,
411
    &call3_info,
444
    &call3_info,
412
    &continue_info,
445
    &continue_info,
413
    &cpus_info,
446
    &cpus_info,
414
    &desc_info,
447
    &desc_info,
415
    &exit_info,
448
    &exit_info,
-
 
449
    &reboot_info,
-
 
450
    &uptime_info,
416
    &halt_info,
451
    &halt_info,
417
    &help_info,
452
    &help_info,
418
    &ipc_task_info,
453
    &ipc_task_info,
419
    &set4_info,
454
    &set4_info,
420
    &slabs_info,
455
    &slabs_info,
Line 486... Line 521...
486
    spinlock_unlock(&cmd_lock);
521
    spinlock_unlock(&cmd_lock);
487
 
522
 
488
    return 1;
523
    return 1;
489
}
524
}
490
 
525
 
-
 
526
 
-
 
527
/** Reboot the system.
-
 
528
 *
-
 
529
 * @param argv Argument vector.
-
 
530
 *
-
 
531
 * @return 0 on failure, 1 on success.
-
 
532
 */
-
 
533
int cmd_reboot(cmd_arg_t *argv)
-
 
534
{
-
 
535
    reboot();
-
 
536
   
-
 
537
    /* Not reached */
-
 
538
    return 1;
-
 
539
}
-
 
540
 
-
 
541
 
-
 
542
/** Print system uptime information.
-
 
543
 *
-
 
544
 * @param argv Argument vector.
-
 
545
 *
-
 
546
 * @return 0 on failure, 1 on success.
-
 
547
 */
-
 
548
int cmd_uptime(cmd_arg_t *argv)
-
 
549
{
-
 
550
    ASSERT(uptime);
-
 
551
   
-
 
552
    /* This doesn't have to be very accurate */
-
 
553
    unative_t sec = uptime->seconds1;
-
 
554
   
-
 
555
    printf("Up %u days, %u hours, %u minutes, %u seconds\n",
-
 
556
        sec / 86400, (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
-
 
557
   
-
 
558
    return 1;
-
 
559
}
-
 
560
 
491
/** Describe specified command.
561
/** Describe specified command.
492
 *
562
 *
493
 * @param argv Argument vector.
563
 * @param argv Argument vector.
494
 *
564
 *
495
 * @return 0 on failure, 1 on success.
565
 * @return 0 on failure, 1 on success.
Line 538... Line 608...
538
    unative_t (*f)(void);
608
    unative_t (*f)(void);
539
#ifdef ia64
609
#ifdef ia64
540
    struct {
610
    struct {
541
        unative_t f;
611
        unative_t f;
542
        unative_t gp;
612
        unative_t gp;
543
    }fptr;
613
    } fptr;
544
#endif
614
#endif
545
 
615
 
546
    symaddr = get_symbol_addr((char *) argv->buffer);
616
    symaddr = get_symbol_addr((char *) argv->buffer);
547
    if (!symaddr)
617
    if (!symaddr)
548
        printf("Symbol %s not found.\n", argv->buffer);
618
        printf("Symbol %s not found.\n", argv->buffer);
549
    else if (symaddr == (uintptr_t) -1) {
619
    else if (symaddr == (uintptr_t) -1) {
550
        symtab_print_search((char *) argv->buffer);
620
        symtab_print_search((char *) argv->buffer);
551
        printf("Duplicate symbol, be more specific.\n");
621
        printf("Duplicate symbol, be more specific.\n");
552
    } else {
622
    } else {
553
        symbol = get_symtab_entry(symaddr);
623
        symbol = get_symtab_entry(symaddr);
554
        printf("Calling f(): %.*p: %s\n", sizeof(uintptr_t) * 2, symaddr, symbol);
624
        printf("Calling %s() (%.*p)\n", symbol, sizeof(uintptr_t) * 2, symaddr);
555
#ifdef ia64
625
#ifdef ia64
556
        fptr.f = symaddr;
626
        fptr.f = symaddr;
557
        fptr.gp = ((unative_t *)cmd_call2)[1];
627
        fptr.gp = ((unative_t *)cmd_call2)[1];
558
        f =  (unative_t (*)(void)) &fptr;
628
        f =  (unative_t (*)(void)) &fptr;
559
#else
629
#else
Line 563... Line 633...
563
    }
633
    }
564
   
634
   
565
    return 1;
635
    return 1;
566
}
636
}
567
 
637
 
-
 
638
/** Call function with zero parameters on each CPU */
-
 
639
int cmd_mcall0(cmd_arg_t *argv)
-
 
640
{
-
 
641
    /*
-
 
642
     * For each CPU, create a thread which will
-
 
643
     * call the function.
-
 
644
     */
-
 
645
   
-
 
646
    count_t i;
-
 
647
    for (i = 0; i < config.cpu_count; i++) {
-
 
648
        thread_t *t;
-
 
649
        if ((t = thread_create((void (*)(void *)) cmd_call0, (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) {
-
 
650
            spinlock_lock(&t->lock);
-
 
651
            t->cpu = &cpus[i];
-
 
652
            spinlock_unlock(&t->lock);
-
 
653
            printf("cpu%u: ", i);
-
 
654
            thread_ready(t);
-
 
655
            thread_join(t);
-
 
656
            thread_detach(t);
-
 
657
        } else
-
 
658
            printf("Unable to create thread for cpu%u\n", i);
-
 
659
    }
-
 
660
   
-
 
661
    return 1;
-
 
662
}
-
 
663
 
568
/** Call function with one parameter */
664
/** Call function with one parameter */
569
int cmd_call1(cmd_arg_t *argv)
665
int cmd_call1(cmd_arg_t *argv)
570
{
666
{
571
    uintptr_t symaddr;
667
    uintptr_t symaddr;
572
    char *symbol;
668
    char *symbol;
Line 711... Line 807...
711
}
807
}
712
 
808
 
713
/** Write 4 byte value to address */
809
/** Write 4 byte value to address */
714
int cmd_set4(cmd_arg_t *argv)
810
int cmd_set4(cmd_arg_t *argv)
715
{
811
{
716
    uint32_t *addr ;
812
    uint32_t *addr;
717
    uint32_t arg1 = argv[1].intval;
813
    uint32_t arg1 = argv[1].intval;
718
    bool pointer = false;
814
    bool pointer = false;
719
 
815
 
720
    if (((char *)argv->buffer)[0] == '*') {
816
    if (((char *)argv->buffer)[0] == '*') {
721
        addr = (uint32_t *) get_symbol_addr((char *) argv->buffer + 1);
817
        addr = (uint32_t *) get_symbol_addr((char *) argv->buffer + 1);