Subversion Repositories HelenOS

Rev

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

Rev 3022 Rev 4055
Line 48... Line 48...
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 <config.h>
52
#include <func.h>
52
#include <func.h>
-
 
53
#include <string.h>
53
#include <macros.h>
54
#include <macros.h>
54
#include <debug.h>
55
#include <debug.h>
55
#include <symtab.h>
56
#include <symtab.h>
56
#include <cpu.h>
57
#include <cpu.h>
57
#include <mm/tlb.h>
58
#include <mm/tlb.h>
Line 396... Line 397...
396
    .description = "List of memory zones.",
397
    .description = "List of memory zones.",
397
    .func = cmd_zones,
398
    .func = cmd_zones,
398
    .argc = 0
399
    .argc = 0
399
};
400
};
400
 
401
 
401
/* Data and methods for 'ipc_task' command */
402
/* Data and methods for 'ipc' command */
402
static int cmd_ipc_task(cmd_arg_t *argv);
403
static int cmd_ipc(cmd_arg_t *argv);
403
static cmd_arg_t ipc_task_argv = {
404
static cmd_arg_t ipc_argv = {
404
    .type = ARG_TYPE_INT,
405
    .type = ARG_TYPE_INT,
405
};
406
};
406
static cmd_info_t ipc_task_info = {
407
static cmd_info_t ipc_info = {
407
    .name = "ipc_task",
408
    .name = "ipc",
408
    .description = "ipc_task <taskid> Show IPC information of given task.",
409
    .description = "ipc <taskid> Show IPC information of given task.",
409
    .func = cmd_ipc_task,
410
    .func = cmd_ipc,
410
    .argc = 1,
411
    .argc = 1,
411
    .argv = &ipc_task_argv
412
    .argv = &ipc_argv
412
};
413
};
413
 
414
 
414
/* Data and methods for 'zone' command */
415
/* Data and methods for 'zone' command */
415
static int cmd_zone(cmd_arg_t *argv);
416
static int cmd_zone(cmd_arg_t *argv);
416
static cmd_arg_t zone_argv = {
417
static cmd_arg_t zone_argv = {
Line 459... Line 460...
459
    &exit_info,
460
    &exit_info,
460
    &reboot_info,
461
    &reboot_info,
461
    &uptime_info,
462
    &uptime_info,
462
    &halt_info,
463
    &halt_info,
463
    &help_info,
464
    &help_info,
464
    &ipc_task_info,
465
    &ipc_info,
465
    &set4_info,
466
    &set4_info,
466
    &slabs_info,
467
    &slabs_info,
467
    &symaddr_info,
468
    &symaddr_info,
468
    &sched_info,
469
    &sched_info,
469
    &threads_info,
470
    &threads_info,
Line 499... Line 500...
499
    unsigned int i;
500
    unsigned int i;
500
 
501
 
501
    for (i = 0; basic_commands[i]; i++) {
502
    for (i = 0; basic_commands[i]; i++) {
502
        cmd_initialize(basic_commands[i]);
503
        cmd_initialize(basic_commands[i]);
503
        if (!cmd_register(basic_commands[i]))
504
        if (!cmd_register(basic_commands[i]))
504
            panic("could not register command %s\n", basic_commands[i]->name);
505
            printf("Cannot register command %s\n", basic_commands[i]->name);
505
    }
506
    }
506
}
507
}
507
 
508
 
508
 
509
 
509
/** List supported commands.
510
/** List supported commands.
Line 512... Line 513...
512
 *
513
 *
513
 * @return 0 on failure, 1 on success.
514
 * @return 0 on failure, 1 on success.
514
 */
515
 */
515
int cmd_help(cmd_arg_t *argv)
516
int cmd_help(cmd_arg_t *argv)
516
{
517
{
517
    link_t *cur;
-
 
518
 
-
 
519
    spinlock_lock(&cmd_lock);
518
    spinlock_lock(&cmd_lock);
520
   
519
   
-
 
520
    link_t *cur;
-
 
521
    size_t len = 0;
521
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
522
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
522
        cmd_info_t *hlp;
523
        cmd_info_t *hlp;
523
       
-
 
524
        hlp = list_get_instance(cur, cmd_info_t, link);
524
        hlp = list_get_instance(cur, cmd_info_t, link);
-
 
525
       
525
        spinlock_lock(&hlp->lock);
526
        spinlock_lock(&hlp->lock);
-
 
527
        if (strlen(hlp->name) > len)
-
 
528
            len = strlen(hlp->name);
-
 
529
        spinlock_unlock(&hlp->lock);
-
 
530
    }
-
 
531
   
-
 
532
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
-
 
533
        cmd_info_t *hlp;
-
 
534
        hlp = list_get_instance(cur, cmd_info_t, link);
526
       
535
       
-
 
536
        spinlock_lock(&hlp->lock);
527
        printf("%s - %s\n", hlp->name, hlp->description);
537
        printf("%-*s %s\n", len, hlp->name, hlp->description);
528
 
-
 
529
        spinlock_unlock(&hlp->lock);
538
        spinlock_unlock(&hlp->lock);
530
    }
539
    }
531
   
540
   
532
    spinlock_unlock(&cmd_lock);
541
    spinlock_unlock(&cmd_lock);
533
 
542
   
534
    return 1;
543
    return 1;
535
}
544
}
536
 
545
 
537
 
546
 
538
/** Reboot the system.
547
/** Reboot the system.
Line 561... Line 570...
561
    ASSERT(uptime);
570
    ASSERT(uptime);
562
   
571
   
563
    /* This doesn't have to be very accurate */
572
    /* This doesn't have to be very accurate */
564
    unative_t sec = uptime->seconds1;
573
    unative_t sec = uptime->seconds1;
565
   
574
   
566
    printf("Up %u days, %u hours, %u minutes, %u seconds\n",
575
    printf("Up %" PRIun " days, %" PRIun " hours, %" PRIun " minutes, %" PRIun " seconds\n",
567
        sec / 86400, (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
576
        sec / 86400, (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
568
   
577
   
569
    return 1;
578
    return 1;
570
}
579
}
571
 
580
 
Line 614... Line 623...
614
/** Call function with zero parameters */
623
/** Call function with zero parameters */
615
int cmd_call0(cmd_arg_t *argv)
624
int cmd_call0(cmd_arg_t *argv)
616
{
625
{
617
    uintptr_t symaddr;
626
    uintptr_t symaddr;
618
    char *symbol;
627
    char *symbol;
619
    unative_t (*f)(void);
628
    unative_t (*fnc)(void);
620
#ifdef ia64
-
 
621
    struct {
-
 
622
        unative_t f;
-
 
623
        unative_t gp;
629
    fncptr_t fptr;
624
    } fptr;
-
 
625
#endif
-
 
626
 
630
   
627
    symaddr = get_symbol_addr((char *) argv->buffer);
631
    symaddr = get_symbol_addr((char *) argv->buffer);
628
    if (!symaddr)
632
    if (!symaddr)
629
        printf("Symbol %s not found.\n", argv->buffer);
633
        printf("Symbol %s not found.\n", argv->buffer);
630
    else if (symaddr == (uintptr_t) -1) {
634
    else if (symaddr == (uintptr_t) -1) {
631
        symtab_print_search((char *) argv->buffer);
635
        symtab_print_search((char *) argv->buffer);
632
        printf("Duplicate symbol, be more specific.\n");
636
        printf("Duplicate symbol, be more specific.\n");
633
    } else {
637
    } else {
634
        symbol = get_symtab_entry(symaddr);
638
        symbol = get_symtab_entry(symaddr);
635
        printf("Calling %s() (%.*p)\n", symbol, sizeof(uintptr_t) * 2, symaddr);
639
        fnc = (unative_t (*)(void)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call0);
636
#ifdef ia64
-
 
637
        fptr.f = symaddr;
-
 
638
        fptr.gp = ((unative_t *)cmd_call2)[1];
-
 
639
        f =  (unative_t (*)(void)) &fptr;
-
 
640
#else
-
 
641
        f =  (unative_t (*)(void)) symaddr;
640
        printf("Calling %s() (%p)\n", symbol, symaddr);
642
#endif
-
 
643
        printf("Result: %#zx\n", f());
641
        printf("Result: %#" PRIxn "\n", fnc());
644
    }
642
    }
645
   
643
   
646
    return 1;
644
    return 1;
647
}
645
}
648
 
646
 
Line 678... Line 676...
678
/** Call function with one parameter */
676
/** Call function with one parameter */
679
int cmd_call1(cmd_arg_t *argv)
677
int cmd_call1(cmd_arg_t *argv)
680
{
678
{
681
    uintptr_t symaddr;
679
    uintptr_t symaddr;
682
    char *symbol;
680
    char *symbol;
683
    unative_t (*f)(unative_t,...);
681
    unative_t (*fnc)(unative_t, ...);
684
    unative_t arg1 = argv[1].intval;
682
    unative_t arg1 = argv[1].intval;
685
#ifdef ia64
-
 
686
    struct {
-
 
687
        unative_t f;
-
 
688
        unative_t gp;
683
    fncptr_t fptr;
689
    }fptr;
-
 
690
#endif
-
 
691
 
684
   
692
    symaddr = get_symbol_addr((char *) argv->buffer);
685
    symaddr = get_symbol_addr((char *) argv->buffer);
693
    if (!symaddr)
686
    if (!symaddr)
694
        printf("Symbol %s not found.\n", argv->buffer);
687
        printf("Symbol %s not found.\n", argv->buffer);
695
    else if (symaddr == (uintptr_t) -1) {
688
    else if (symaddr == (uintptr_t) -1) {
696
        symtab_print_search((char *) argv->buffer);
689
        symtab_print_search((char *) argv->buffer);
697
        printf("Duplicate symbol, be more specific.\n");
690
        printf("Duplicate symbol, be more specific.\n");
698
    } else {
691
    } else {
699
        symbol = get_symtab_entry(symaddr);
692
        symbol = get_symtab_entry(symaddr);
700
 
-
 
701
        printf("Calling f(%#zx): %.*p: %s\n", arg1, sizeof(uintptr_t) * 2, symaddr, symbol);
693
        fnc = (unative_t (*)(unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call1);
702
#ifdef ia64
-
 
703
        fptr.f = symaddr;
-
 
704
        fptr.gp = ((unative_t *)cmd_call2)[1];
-
 
705
        f =  (unative_t (*)(unative_t,...)) &fptr;
-
 
706
#else
-
 
707
        f =  (unative_t (*)(unative_t,...)) symaddr;
694
        printf("Calling f(%#" PRIxn "): %p: %s\n", arg1, symaddr, symbol);
708
#endif
-
 
709
        printf("Result: %#zx\n", f(arg1));
695
        printf("Result: %#" PRIxn "\n", fnc(arg1));
710
    }
696
    }
711
   
697
   
712
    return 1;
698
    return 1;
713
}
699
}
714
 
700
 
715
/** Call function with two parameters */
701
/** Call function with two parameters */
716
int cmd_call2(cmd_arg_t *argv)
702
int cmd_call2(cmd_arg_t *argv)
717
{
703
{
718
    uintptr_t symaddr;
704
    uintptr_t symaddr;
719
    char *symbol;
705
    char *symbol;
720
    unative_t (*f)(unative_t,unative_t,...);
706
    unative_t (*fnc)(unative_t, unative_t, ...);
721
    unative_t arg1 = argv[1].intval;
707
    unative_t arg1 = argv[1].intval;
722
    unative_t arg2 = argv[2].intval;
708
    unative_t arg2 = argv[2].intval;
723
#ifdef ia64
-
 
724
    struct {
-
 
725
        unative_t f;
-
 
726
        unative_t gp;
709
    fncptr_t fptr;
727
    }fptr;
-
 
728
#endif
-
 
729
 
710
   
730
    symaddr = get_symbol_addr((char *) argv->buffer);
711
    symaddr = get_symbol_addr((char *) argv->buffer);
731
    if (!symaddr)
712
    if (!symaddr)
732
        printf("Symbol %s not found.\n", argv->buffer);
713
        printf("Symbol %s not found.\n", argv->buffer);
733
    else if (symaddr == (uintptr_t) -1) {
714
    else if (symaddr == (uintptr_t) -1) {
734
        symtab_print_search((char *) argv->buffer);
715
        symtab_print_search((char *) argv->buffer);
735
        printf("Duplicate symbol, be more specific.\n");
716
        printf("Duplicate symbol, be more specific.\n");
736
    } else {
717
    } else {
737
        symbol = get_symtab_entry(symaddr);
718
        symbol = get_symtab_entry(symaddr);
-
 
719
        fnc = (unative_t (*)(unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call2);
738
        printf("Calling f(0x%zx,0x%zx): %.*p: %s\n",
720
        printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n",
739
               arg1, arg2, sizeof(uintptr_t) * 2, symaddr, symbol);
721
               arg1, arg2, symaddr, symbol);
740
#ifdef ia64
-
 
741
        fptr.f = symaddr;
-
 
742
        fptr.gp = ((unative_t *)cmd_call2)[1];
-
 
743
        f =  (unative_t (*)(unative_t,unative_t,...)) &fptr;
-
 
744
#else
-
 
745
        f =  (unative_t (*)(unative_t,unative_t,...)) symaddr;
-
 
746
#endif
-
 
747
        printf("Result: %#zx\n", f(arg1, arg2));
722
        printf("Result: %#" PRIxn "\n", fnc(arg1, arg2));
748
    }
723
    }
749
   
724
   
750
    return 1;
725
    return 1;
751
}
726
}
752
 
727
 
753
/** Call function with three parameters */
728
/** Call function with three parameters */
754
int cmd_call3(cmd_arg_t *argv)
729
int cmd_call3(cmd_arg_t *argv)
755
{
730
{
756
    uintptr_t symaddr;
731
    uintptr_t symaddr;
757
    char *symbol;
732
    char *symbol;
758
    unative_t (*f)(unative_t,unative_t,unative_t,...);
733
    unative_t (*fnc)(unative_t, unative_t, unative_t, ...);
759
    unative_t arg1 = argv[1].intval;
734
    unative_t arg1 = argv[1].intval;
760
    unative_t arg2 = argv[2].intval;
735
    unative_t arg2 = argv[2].intval;
761
    unative_t arg3 = argv[3].intval;
736
    unative_t arg3 = argv[3].intval;
762
#ifdef ia64
-
 
763
    struct {
-
 
764
        unative_t f;
-
 
765
        unative_t gp;
737
    fncptr_t fptr;
766
    }fptr;
-
 
767
#endif
-
 
768
 
738
   
769
    symaddr = get_symbol_addr((char *) argv->buffer);
739
    symaddr = get_symbol_addr((char *) argv->buffer);
770
    if (!symaddr)
740
    if (!symaddr)
771
        printf("Symbol %s not found.\n", argv->buffer);
741
        printf("Symbol %s not found.\n", argv->buffer);
772
    else if (symaddr == (uintptr_t) -1) {
742
    else if (symaddr == (uintptr_t) -1) {
773
        symtab_print_search((char *) argv->buffer);
743
        symtab_print_search((char *) argv->buffer);
774
        printf("Duplicate symbol, be more specific.\n");
744
        printf("Duplicate symbol, be more specific.\n");
775
    } else {
745
    } else {
776
        symbol = get_symtab_entry(symaddr);
746
        symbol = get_symtab_entry(symaddr);
-
 
747
        fnc = (unative_t (*)(unative_t, unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call3);
777
        printf("Calling f(0x%zx,0x%zx, 0x%zx): %.*p: %s\n",
748
        printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n",
778
               arg1, arg2, arg3, sizeof(uintptr_t) * 2, symaddr, symbol);
749
               arg1, arg2, arg3, symaddr, symbol);
779
#ifdef ia64
-
 
780
        fptr.f = symaddr;
-
 
781
        fptr.gp = ((unative_t *)cmd_call2)[1];
-
 
782
        f =  (unative_t (*)(unative_t,unative_t,unative_t,...)) &fptr;
-
 
783
#else
-
 
784
        f =  (unative_t (*)(unative_t,unative_t,unative_t,...)) symaddr;
-
 
785
#endif
-
 
786
        printf("Result: %#zx\n", f(arg1, arg2, arg3));
750
        printf("Result: %#" PRIxn "\n", fnc(arg1, arg2, arg3));
787
    }
751
    }
788
   
752
   
789
    return 1;
753
    return 1;
790
}
754
}
791
 
755
 
Line 854... Line 818...
854
        symtab_print_search((char *) argv->buffer);
818
        symtab_print_search((char *) argv->buffer);
855
        printf("Duplicate symbol, be more specific.\n");
819
        printf("Duplicate symbol, be more specific.\n");
856
    } else {
820
    } else {
857
        if (pointer)
821
        if (pointer)
858
            addr = (uint32_t *)(*(unative_t *)addr);
822
            addr = (uint32_t *)(*(unative_t *)addr);
859
        printf("Writing 0x%x -> %.*p\n", arg1, sizeof(uintptr_t) * 2, addr);
823
        printf("Writing %#" PRIx64 " -> %p\n", arg1, addr);
860
        *addr = arg1;
824
        *addr = arg1;
861
       
825
       
862
    }
826
    }
863
   
827
   
864
    return 1;
828
    return 1;
Line 935... Line 899...
935
 *
899
 *
936
 * @param argv Integer argument from cmdline expected
900
 * @param argv Integer argument from cmdline expected
937
 *
901
 *
938
 * return Always 1
902
 * return Always 1
939
 */
903
 */
940
int cmd_ipc_task(cmd_arg_t * argv) {
904
int cmd_ipc(cmd_arg_t * argv) {
941
    ipc_print_task(argv[0].intval);
905
    ipc_print_task(argv[0].intval);
942
    return 1;
906
    return 1;
943
}
907
}
944
 
908
 
945
 
909
 
Line 974... Line 938...
974
 * return Always 1.
938
 * return Always 1.
975
 */
939
 */
976
int cmd_continue(cmd_arg_t *argv)
940
int cmd_continue(cmd_arg_t *argv)
977
{
941
{
978
    printf("The kernel will now relinquish the console.\n");
942
    printf("The kernel will now relinquish the console.\n");
-
 
943
    release_console();
-
 
944
   
979
    printf("Use userspace controls to redraw the screen.\n");
945
    if ((kconsole_notify) && (kconsole_irq.notif_cfg.notify))
980
    arch_release_console();
946
        ipc_irq_send_msg_0(&kconsole_irq);
-
 
947
   
981
    return 1;
948
    return 1;
982
}
949
}
983
 
950
 
984
#ifdef CONFIG_TEST
951
#ifdef CONFIG_TEST
985
/** Command for printing kernel tests list.
952
/** Command for printing kernel tests list.
Line 988... Line 955...
988
 *
955
 *
989
 * return Always 1.
956
 * return Always 1.
990
 */
957
 */
991
int cmd_tests(cmd_arg_t *argv)
958
int cmd_tests(cmd_arg_t *argv)
992
{
959
{
-
 
960
    size_t len = 0;
993
    test_t *test;
961
    test_t *test;
-
 
962
    for (test = tests; test->name != NULL; test++) {
-
 
963
        if (strlen(test->name) > len)
-
 
964
            len = strlen(test->name);
-
 
965
    }
994
   
966
   
995
    for (test = tests; test->name != NULL; test++)
967
    for (test = tests; test->name != NULL; test++)
996
        printf("%s\t\t%s%s\n", test->name, test->desc, (test->safe ? "" : " (unsafe)"));
968
        printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
997
   
969
   
998
    printf("*\t\tRun all safe tests\n");
970
    printf("%-*s Run all safe tests\n", len, "*");
999
    return 1;
971
    return 1;
1000
}
972
}
1001
 
973
 
1002
static bool run_test(const test_t *test)
974
static bool run_test(const test_t *test)
1003
{
975
{
1004
    printf("%s\t\t%s\n", test->name, test->desc);
976
    printf("%s (%s)\n", test->name, test->desc);
1005
   
977
   
1006
    /* Update and read thread accounting
978
    /* Update and read thread accounting
1007
       for benchmarking */
979
       for benchmarking */
1008
    ipl_t ipl = interrupts_disable();
980
    ipl_t ipl = interrupts_disable();
1009
    spinlock_lock(&TASK->lock);
981
    spinlock_lock(&TASK->lock);
Line 1023... Line 995...
1023
   
995
   
1024
    uint64_t cycles;
996
    uint64_t cycles;
1025
    char suffix;
997
    char suffix;
1026
    order(dt, &cycles, &suffix);
998
    order(dt, &cycles, &suffix);
1027
       
999
       
1028
    printf("Time: %llu%c cycles\n", cycles, suffix);
1000
    printf("Time: %" PRIu64 "%c cycles\n", cycles, suffix);
1029
   
1001
   
1030
    if (ret == NULL) {
1002
    if (ret == NULL) {
1031
        printf("Test passed\n");
1003
        printf("Test passed\n");
1032
        return true;
1004
        return true;
1033
    }
1005
    }
Line 1051... Line 1023...
1051
        printf("Error allocating memory for statistics\n");
1023
        printf("Error allocating memory for statistics\n");
1052
        return false;
1024
        return false;
1053
    }
1025
    }
1054
   
1026
   
1055
    for (i = 0; i < cnt; i++) {
1027
    for (i = 0; i < cnt; i++) {
1056
        printf("%s (%d/%d) ... ", test->name, i + 1, cnt);
1028
        printf("%s (%u/%u) ... ", test->name, i + 1, cnt);
1057
       
1029
       
1058
        /* Update and read thread accounting
1030
        /* Update and read thread accounting
1059
           for benchmarking */
1031
           for benchmarking */
1060
        ipl_t ipl = interrupts_disable();
1032
        ipl_t ipl = interrupts_disable();
1061
        spinlock_lock(&TASK->lock);
1033
        spinlock_lock(&TASK->lock);
Line 1079... Line 1051...
1079
            break;
1051
            break;
1080
        }
1052
        }
1081
       
1053
       
1082
        data[i] = dt;
1054
        data[i] = dt;
1083
        order(dt, &cycles, &suffix);
1055
        order(dt, &cycles, &suffix);
1084
        printf("OK (%llu%c cycles)\n", cycles, suffix);
1056
        printf("OK (%" PRIu64 "%c cycles)\n", cycles, suffix);
1085
    }
1057
    }
1086
   
1058
   
1087
    if (ret) {
1059
    if (ret) {
1088
        printf("\n");
1060
        printf("\n");
1089
       
1061
       
Line 1092... Line 1064...
1092
        for (i = 0; i < cnt; i++) {
1064
        for (i = 0; i < cnt; i++) {
1093
            sum += data[i];
1065
            sum += data[i];
1094
        }
1066
        }
1095
       
1067
       
1096
        order(sum / (uint64_t) cnt, &cycles, &suffix);
1068
        order(sum / (uint64_t) cnt, &cycles, &suffix);
1097
        printf("Average\t\t%llu%c\n", cycles, suffix);
1069
        printf("Average\t\t%" PRIu64 "%c\n", cycles, suffix);
1098
    }
1070
    }
1099
   
1071
   
1100
    free(data);
1072
    free(data);
1101
   
1073
   
1102
    return ret;
1074
    return ret;