Subversion Repositories HelenOS

Rev

Rev 2050 | Rev 2071 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
596 jermar 1
/*
2
 * Copyright (C) 2005 Jakub Jermar
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
1888 jermar 29
/** @addtogroup genericconsole
1702 cejka 30
 * @{
31
 */
32
 
596 jermar 33
/**
1264 jermar 34
 * @file    cmd.c
35
 * @brief   Kernel console command wrappers.
36
 *
596 jermar 37
 * This file is meant to contain all wrapper functions for
38
 * all kconsole commands. The point is in separating
39
 * kconsole specific wrappers from kconsole-unaware functions
40
 * from other subsystems.
41
 */
42
 
43
#include <console/cmd.h>
1474 palkovsky 44
#include <console/console.h>
596 jermar 45
#include <console/kconsole.h>
46
#include <print.h>
47
#include <panic.h>
48
#include <typedefs.h>
49
#include <arch/types.h>
788 jermar 50
#include <adt/list.h>
596 jermar 51
#include <arch.h>
52
#include <func.h>
53
#include <macros.h>
54
#include <debug.h>
55
#include <symtab.h>
673 jermar 56
#include <cpu.h>
596 jermar 57
#include <mm/tlb.h>
58
#include <arch/mm/tlb.h>
668 bondari 59
#include <mm/frame.h>
673 jermar 60
#include <main/version.h>
759 palkovsky 61
#include <mm/slab.h>
775 palkovsky 62
#include <proc/scheduler.h>
777 palkovsky 63
#include <proc/thread.h>
1060 palkovsky 64
#include <proc/task.h>
1573 palkovsky 65
#include <ipc/ipc.h>
1712 palkovsky 66
#include <ipc/irq.h>
596 jermar 67
 
2019 decky 68
#ifdef CONFIG_TEST
69
#include <test.h>
70
#endif
71
 
1702 cejka 72
/* Data and methods for 'help' command. */
596 jermar 73
static int cmd_help(cmd_arg_t *argv);
74
static cmd_info_t help_info = {
75
    .name = "help",
76
    .description = "List of supported commands.",
77
    .func = cmd_help,
78
    .argc = 0
79
};
80
 
609 palkovsky 81
static cmd_info_t exit_info = {
82
    .name = "exit",
2019 decky 83
    .description = "Exit kconsole",
609 palkovsky 84
    .argc = 0
85
};
86
 
1474 palkovsky 87
static int cmd_continue(cmd_arg_t *argv);
88
static cmd_info_t continue_info = {
89
    .name = "continue",
2019 decky 90
    .description = "Return console back to userspace.",
1474 palkovsky 91
    .func = cmd_continue,
92
    .argc = 0
93
};
94
 
2019 decky 95
#ifdef CONFIG_TEST
96
static int cmd_tests(cmd_arg_t *argv);
97
static cmd_info_t tests_info = {
98
    .name = "tests",
99
    .description = "Print available kernel tests.",
100
    .func = cmd_tests,
101
    .argc = 0
102
};
103
 
104
static char test_buf[MAX_CMDLINE + 1];
105
static int cmd_test(cmd_arg_t *argv);
106
static cmd_arg_t test_argv[] = {
107
    {
108
        .type = ARG_TYPE_STRING,
109
        .buffer = test_buf,
110
        .len = sizeof(test_buf)
111
    }
112
};
113
static cmd_info_t test_info = {
114
    .name = "test",
115
    .description = "Run kernel test.",
116
    .func = cmd_test,
117
    .argc = 1,
118
    .argv = test_argv
119
};
2050 decky 120
 
121
static int cmd_bench(cmd_arg_t *argv);
122
static cmd_arg_t bench_argv[] = {
123
    {
124
        .type = ARG_TYPE_STRING,
125
        .buffer = test_buf,
126
        .len = sizeof(test_buf)
127
    },
128
    {
129
        .type = ARG_TYPE_INT,
130
    }
131
};
132
static cmd_info_t bench_info = {
133
    .name = "bench",
134
    .description = "Run kernel test as benchmark.",
135
    .func = cmd_bench,
136
    .argc = 2,
137
    .argv = bench_argv
138
};
2019 decky 139
#endif
140
 
1702 cejka 141
/* Data and methods for 'description' command. */
596 jermar 142
static int cmd_desc(cmd_arg_t *argv);
143
static void desc_help(void);
144
static char desc_buf[MAX_CMDLINE+1];
145
static cmd_arg_t desc_argv = {
146
    .type = ARG_TYPE_STRING,
147
    .buffer = desc_buf,
148
    .len = sizeof(desc_buf)
149
};
150
static cmd_info_t desc_info = {
151
    .name = "describe",
152
    .description = "Describe specified command.",
153
    .help = desc_help,
154
    .func = cmd_desc,
155
    .argc = 1,
156
    .argv = &desc_argv
157
};
158
 
1702 cejka 159
/* Data and methods for 'symaddr' command. */
596 jermar 160
static int cmd_symaddr(cmd_arg_t *argv);
161
static char symaddr_buf[MAX_CMDLINE+1];
162
static cmd_arg_t symaddr_argv = {
163
    .type = ARG_TYPE_STRING,
164
    .buffer = symaddr_buf,
165
    .len = sizeof(symaddr_buf)
166
};
167
static cmd_info_t symaddr_info = {
168
    .name = "symaddr",
169
    .description = "Return symbol address.",
170
    .func = cmd_symaddr,
171
    .argc = 1,
172
    .argv = &symaddr_argv
173
};
174
 
603 palkovsky 175
static char set_buf[MAX_CMDLINE+1];
176
static int cmd_set4(cmd_arg_t *argv);
177
static cmd_arg_t set4_argv[] = {
178
    {
179
        .type = ARG_TYPE_STRING,
180
        .buffer = set_buf,
181
        .len = sizeof(set_buf)
182
    },
183
    {
184
        .type = ARG_TYPE_INT
185
    }
186
};
187
static cmd_info_t set4_info = {
188
    .name = "set4",
189
    .description = "set <dest_addr> <value> - 4byte version",
190
    .func = cmd_set4,
191
    .argc = 2,
192
    .argv = set4_argv
193
};
194
 
1702 cejka 195
/* Data and methods for 'call0' command. */
596 jermar 196
static char call0_buf[MAX_CMDLINE+1];
197
static char carg1_buf[MAX_CMDLINE+1];
198
static char carg2_buf[MAX_CMDLINE+1];
199
static char carg3_buf[MAX_CMDLINE+1];
200
 
201
static int cmd_call0(cmd_arg_t *argv);
202
static cmd_arg_t call0_argv = {
203
    .type = ARG_TYPE_STRING,
204
    .buffer = call0_buf,
205
    .len = sizeof(call0_buf)
206
};
207
static cmd_info_t call0_info = {
208
    .name = "call0",
209
    .description = "call0 <function> -> call function().",
210
    .func = cmd_call0,
211
    .argc = 1,
212
    .argv = &call0_argv
213
};
214
 
1702 cejka 215
/* Data and methods for 'call1' command. */
596 jermar 216
static int cmd_call1(cmd_arg_t *argv);
217
static cmd_arg_t call1_argv[] = {
218
    {
219
        .type = ARG_TYPE_STRING,
220
        .buffer = call0_buf,
221
        .len = sizeof(call0_buf)
222
    },
223
    {
224
        .type = ARG_TYPE_VAR,
225
        .buffer = carg1_buf,
226
        .len = sizeof(carg1_buf)
227
    }
228
};
229
static cmd_info_t call1_info = {
230
    .name = "call1",
231
    .description = "call1 <function> <arg1> -> call function(arg1).",
232
    .func = cmd_call1,
233
    .argc = 2,
234
    .argv = call1_argv
235
};
236
 
1702 cejka 237
/* Data and methods for 'call2' command. */
596 jermar 238
static int cmd_call2(cmd_arg_t *argv);
239
static cmd_arg_t call2_argv[] = {
240
    {
241
        .type = ARG_TYPE_STRING,
242
        .buffer = call0_buf,
243
        .len = sizeof(call0_buf)
244
    },
245
    {
246
        .type = ARG_TYPE_VAR,
247
        .buffer = carg1_buf,
248
        .len = sizeof(carg1_buf)
249
    },
250
    {
251
        .type = ARG_TYPE_VAR,
252
        .buffer = carg2_buf,
253
        .len = sizeof(carg2_buf)
254
    }
255
};
256
static cmd_info_t call2_info = {
257
    .name = "call2",
258
    .description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).",
259
    .func = cmd_call2,
260
    .argc = 3,
261
    .argv = call2_argv
262
};
263
 
1702 cejka 264
/* Data and methods for 'call3' command. */
596 jermar 265
static int cmd_call3(cmd_arg_t *argv);
266
static cmd_arg_t call3_argv[] = {
267
    {
268
        .type = ARG_TYPE_STRING,
269
        .buffer = call0_buf,
270
        .len = sizeof(call0_buf)
271
    },
272
    {
273
        .type = ARG_TYPE_VAR,
274
        .buffer = carg1_buf,
275
        .len = sizeof(carg1_buf)
276
    },
277
    {
278
        .type = ARG_TYPE_VAR,
279
        .buffer = carg2_buf,
280
        .len = sizeof(carg2_buf)
281
    },
282
    {
283
        .type = ARG_TYPE_VAR,
284
        .buffer = carg3_buf,
285
        .len = sizeof(carg3_buf)
286
    }
287
 
288
};
289
static cmd_info_t call3_info = {
290
    .name = "call3",
291
    .description = "call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).",
292
    .func = cmd_call3,
293
    .argc = 4,
294
    .argv = call3_argv
295
};
296
 
1702 cejka 297
/* Data and methods for 'halt' command. */
596 jermar 298
static int cmd_halt(cmd_arg_t *argv);
299
static cmd_info_t halt_info = {
300
    .name = "halt",
301
    .description = "Halt the kernel.",
302
    .func = cmd_halt,
303
    .argc = 0
304
};
305
 
1702 cejka 306
/* Data and methods for 'tlb' command. */
673 jermar 307
static int cmd_tlb(cmd_arg_t *argv);
308
cmd_info_t tlb_info = {
309
    .name = "tlb",
596 jermar 310
    .description = "Print TLB of current processor.",
311
    .help = NULL,
673 jermar 312
    .func = cmd_tlb,
596 jermar 313
    .argc = 0,
314
    .argv = NULL
315
};
316
 
777 palkovsky 317
static int cmd_threads(cmd_arg_t *argv);
318
static cmd_info_t threads_info = {
319
    .name = "threads",
1695 jermar 320
    .description = "List all threads.",
777 palkovsky 321
    .func = cmd_threads,
322
    .argc = 0
323
};
668 bondari 324
 
1060 palkovsky 325
static int cmd_tasks(cmd_arg_t *argv);
326
static cmd_info_t tasks_info = {
327
    .name = "tasks",
1695 jermar 328
    .description = "List all tasks.",
1060 palkovsky 329
    .func = cmd_tasks,
330
    .argc = 0
331
};
777 palkovsky 332
 
1060 palkovsky 333
 
775 palkovsky 334
static int cmd_sched(cmd_arg_t *argv);
335
static cmd_info_t sched_info = {
336
    .name = "scheduler",
1695 jermar 337
    .description = "List all scheduler information.",
775 palkovsky 338
    .func = cmd_sched,
339
    .argc = 0
340
};
341
 
759 palkovsky 342
static int cmd_slabs(cmd_arg_t *argv);
343
static cmd_info_t slabs_info = {
344
    .name = "slabs",
1695 jermar 345
    .description = "List slab caches.",
759 palkovsky 346
    .func = cmd_slabs,
347
    .argc = 0
348
};
349
 
1702 cejka 350
/* Data and methods for 'zones' command */
668 bondari 351
static int cmd_zones(cmd_arg_t *argv);
352
static cmd_info_t zones_info = {
353
    .name = "zones",
354
    .description = "List of memory zones.",
355
    .func = cmd_zones,
356
    .argc = 0
357
};
358
 
1702 cejka 359
/* Data and methods for 'ipc_task' command */
1573 palkovsky 360
static int cmd_ipc_task(cmd_arg_t *argv);
361
static cmd_arg_t ipc_task_argv = {
362
    .type = ARG_TYPE_INT,
363
};
364
static cmd_info_t ipc_task_info = {
365
    .name = "ipc_task",
1695 jermar 366
    .description = "ipc_task <taskid> Show IPC information of given task.",
1573 palkovsky 367
    .func = cmd_ipc_task,
368
    .argc = 1,
369
    .argv = &ipc_task_argv
370
};
371
 
1702 cejka 372
/* Data and methods for 'zone' command */
668 bondari 373
static int cmd_zone(cmd_arg_t *argv);
374
static cmd_arg_t zone_argv = {
375
    .type = ARG_TYPE_INT,
376
};
377
 
378
static cmd_info_t zone_info = {
379
    .name = "zone",
380
    .description = "Show memory zone structure.",
381
    .func = cmd_zone,
382
    .argc = 1,
383
    .argv = &zone_argv
384
};
385
 
1702 cejka 386
/* Data and methods for 'cpus' command. */
673 jermar 387
static int cmd_cpus(cmd_arg_t *argv);
388
cmd_info_t cpus_info = {
389
    .name = "cpus",
390
    .description = "List all processors.",
391
    .help = NULL,
392
    .func = cmd_cpus,
393
    .argc = 0,
394
    .argv = NULL
395
};
668 bondari 396
 
1702 cejka 397
/* Data and methods for 'version' command. */
673 jermar 398
static int cmd_version(cmd_arg_t *argv);
399
cmd_info_t version_info = {
400
    .name = "version",
401
    .description = "Print version information.",
402
    .help = NULL,
403
    .func = cmd_version,
404
    .argc = 0,
405
    .argv = NULL
406
};
668 bondari 407
 
775 palkovsky 408
static cmd_info_t *basic_commands[] = {
409
    &call0_info,
410
    &call1_info,
411
    &call2_info,
412
    &call3_info,
1474 palkovsky 413
    &continue_info,
775 palkovsky 414
    &cpus_info,
415
    &desc_info,
416
    &exit_info,
417
    &halt_info,
418
    &help_info,
1573 palkovsky 419
    &ipc_task_info,
775 palkovsky 420
    &set4_info,
421
    &slabs_info,
422
    &symaddr_info,
423
    &sched_info,
777 palkovsky 424
    &threads_info,
1060 palkovsky 425
    &tasks_info,
775 palkovsky 426
    &tlb_info,
427
    &version_info,
428
    &zones_info,
429
    &zone_info,
2019 decky 430
#ifdef CONFIG_TEST
431
    &tests_info,
432
    &test_info,
2050 decky 433
    &bench_info,
2019 decky 434
#endif
775 palkovsky 435
    NULL
436
};
673 jermar 437
 
438
 
596 jermar 439
/** Initialize command info structure.
440
 *
441
 * @param cmd Command info structure.
442
 *
443
 */
444
void cmd_initialize(cmd_info_t *cmd)
445
{
446
    spinlock_initialize(&cmd->lock, "cmd");
447
    link_initialize(&cmd->link);
448
}
449
 
450
/** Initialize and register commands. */
451
void cmd_init(void)
452
{
775 palkovsky 453
    int i;
596 jermar 454
 
775 palkovsky 455
    for (i=0;basic_commands[i]; i++) {
456
        cmd_initialize(basic_commands[i]);
457
        if (!cmd_register(basic_commands[i]))
458
            panic("could not register command %s\n",
459
                  basic_commands[i]->name);
460
    }
596 jermar 461
}
462
 
463
 
464
/** List supported commands.
465
 *
466
 * @param argv Argument vector.
467
 *
468
 * @return 0 on failure, 1 on success.
469
 */
470
int cmd_help(cmd_arg_t *argv)
471
{
472
    link_t *cur;
473
 
474
    spinlock_lock(&cmd_lock);
475
 
476
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
477
        cmd_info_t *hlp;
478
 
479
        hlp = list_get_instance(cur, cmd_info_t, link);
480
        spinlock_lock(&hlp->lock);
481
 
482
        printf("%s - %s\n", hlp->name, hlp->description);
483
 
484
        spinlock_unlock(&hlp->lock);
485
    }
486
 
487
    spinlock_unlock(&cmd_lock);
488
 
489
    return 1;
490
}
491
 
492
/** Describe specified command.
493
 *
494
 * @param argv Argument vector.
495
 *
496
 * @return 0 on failure, 1 on success.
497
 */
498
int cmd_desc(cmd_arg_t *argv)
499
{
500
    link_t *cur;
501
 
502
    spinlock_lock(&cmd_lock);
503
 
504
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
505
        cmd_info_t *hlp;
506
 
507
        hlp = list_get_instance(cur, cmd_info_t, link);
508
        spinlock_lock(&hlp->lock);
509
 
510
        if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) {
511
            printf("%s - %s\n", hlp->name, hlp->description);
512
            if (hlp->help)
513
                hlp->help();
514
            spinlock_unlock(&hlp->lock);
515
            break;
516
        }
517
 
518
        spinlock_unlock(&hlp->lock);
519
    }
520
 
521
    spinlock_unlock(&cmd_lock);
522
 
523
    return 1;
524
}
525
 
526
/** Search symbol table */
527
int cmd_symaddr(cmd_arg_t *argv)
528
{
529
    symtab_print_search(argv->buffer);
530
 
531
    return 1;
532
}
533
 
534
/** Call function with zero parameters */
535
int cmd_call0(cmd_arg_t *argv)
536
{
1780 jermar 537
    uintptr_t symaddr;
596 jermar 538
    char *symbol;
1780 jermar 539
    unative_t (*f)(void);
1666 palkovsky 540
#ifdef ia64
541
    struct {
1780 jermar 542
        unative_t f;
543
        unative_t gp;
1666 palkovsky 544
    }fptr;
545
#endif
596 jermar 546
 
547
    symaddr = get_symbol_addr(argv->buffer);
548
    if (!symaddr)
549
        printf("Symbol %s not found.\n", argv->buffer);
1780 jermar 550
    else if (symaddr == (uintptr_t) -1) {
596 jermar 551
        symtab_print_search(argv->buffer);
552
        printf("Duplicate symbol, be more specific.\n");
553
    } else {
554
        symbol = get_symtab_entry(symaddr);
1780 jermar 555
        printf("Calling f(): %.*p: %s\n", sizeof(uintptr_t) * 2, symaddr, symbol);
1666 palkovsky 556
#ifdef ia64
557
        fptr.f = symaddr;
1780 jermar 558
        fptr.gp = ((unative_t *)cmd_call2)[1];
559
        f =  (unative_t (*)(void)) &fptr;
1666 palkovsky 560
#else
1780 jermar 561
        f =  (unative_t (*)(void)) symaddr;
1666 palkovsky 562
#endif
1224 cejka 563
        printf("Result: %#zx\n", f());
596 jermar 564
    }
565
 
566
    return 1;
567
}
568
 
569
/** Call function with one parameter */
570
int cmd_call1(cmd_arg_t *argv)
571
{
1780 jermar 572
    uintptr_t symaddr;
596 jermar 573
    char *symbol;
1780 jermar 574
    unative_t (*f)(unative_t,...);
575
    unative_t arg1 = argv[1].intval;
1666 palkovsky 576
#ifdef ia64
577
    struct {
1780 jermar 578
        unative_t f;
579
        unative_t gp;
1666 palkovsky 580
    }fptr;
581
#endif
596 jermar 582
 
583
    symaddr = get_symbol_addr(argv->buffer);
584
    if (!symaddr)
585
        printf("Symbol %s not found.\n", argv->buffer);
1780 jermar 586
    else if (symaddr == (uintptr_t) -1) {
596 jermar 587
        symtab_print_search(argv->buffer);
588
        printf("Duplicate symbol, be more specific.\n");
589
    } else {
590
        symbol = get_symtab_entry(symaddr);
1666 palkovsky 591
 
1780 jermar 592
        printf("Calling f(%#zx): %.*p: %s\n", arg1, sizeof(uintptr_t) * 2, symaddr, symbol);
1666 palkovsky 593
#ifdef ia64
594
        fptr.f = symaddr;
1780 jermar 595
        fptr.gp = ((unative_t *)cmd_call2)[1];
596
        f =  (unative_t (*)(unative_t,...)) &fptr;
1666 palkovsky 597
#else
1780 jermar 598
        f =  (unative_t (*)(unative_t,...)) symaddr;
1666 palkovsky 599
#endif
1224 cejka 600
        printf("Result: %#zx\n", f(arg1));
596 jermar 601
    }
602
 
603
    return 1;
604
}
605
 
606
/** Call function with two parameters */
607
int cmd_call2(cmd_arg_t *argv)
608
{
1780 jermar 609
    uintptr_t symaddr;
596 jermar 610
    char *symbol;
1780 jermar 611
    unative_t (*f)(unative_t,unative_t,...);
612
    unative_t arg1 = argv[1].intval;
613
    unative_t arg2 = argv[2].intval;
1666 palkovsky 614
#ifdef ia64
615
    struct {
1780 jermar 616
        unative_t f;
617
        unative_t gp;
1666 palkovsky 618
    }fptr;
619
#endif
596 jermar 620
 
621
    symaddr = get_symbol_addr(argv->buffer);
622
    if (!symaddr)
623
        printf("Symbol %s not found.\n", argv->buffer);
1780 jermar 624
    else if (symaddr == (uintptr_t) -1) {
596 jermar 625
        symtab_print_search(argv->buffer);
626
        printf("Duplicate symbol, be more specific.\n");
627
    } else {
628
        symbol = get_symtab_entry(symaddr);
1224 cejka 629
        printf("Calling f(0x%zx,0x%zx): %.*p: %s\n",
1780 jermar 630
               arg1, arg2, sizeof(uintptr_t) * 2, symaddr, symbol);
1666 palkovsky 631
#ifdef ia64
632
        fptr.f = symaddr;
1780 jermar 633
        fptr.gp = ((unative_t *)cmd_call2)[1];
634
        f =  (unative_t (*)(unative_t,unative_t,...)) &fptr;
1666 palkovsky 635
#else
1780 jermar 636
        f =  (unative_t (*)(unative_t,unative_t,...)) symaddr;
1666 palkovsky 637
#endif
1224 cejka 638
        printf("Result: %#zx\n", f(arg1, arg2));
596 jermar 639
    }
640
 
641
    return 1;
642
}
643
 
644
/** Call function with three parameters */
645
int cmd_call3(cmd_arg_t *argv)
646
{
1780 jermar 647
    uintptr_t symaddr;
596 jermar 648
    char *symbol;
1780 jermar 649
    unative_t (*f)(unative_t,unative_t,unative_t,...);
650
    unative_t arg1 = argv[1].intval;
651
    unative_t arg2 = argv[2].intval;
652
    unative_t arg3 = argv[3].intval;
1666 palkovsky 653
#ifdef ia64
654
    struct {
1780 jermar 655
        unative_t f;
656
        unative_t gp;
1666 palkovsky 657
    }fptr;
658
#endif
596 jermar 659
 
660
    symaddr = get_symbol_addr(argv->buffer);
661
    if (!symaddr)
662
        printf("Symbol %s not found.\n", argv->buffer);
1780 jermar 663
    else if (symaddr == (uintptr_t) -1) {
596 jermar 664
        symtab_print_search(argv->buffer);
665
        printf("Duplicate symbol, be more specific.\n");
666
    } else {
667
        symbol = get_symtab_entry(symaddr);
1224 cejka 668
        printf("Calling f(0x%zx,0x%zx, 0x%zx): %.*p: %s\n",
1780 jermar 669
               arg1, arg2, arg3, sizeof(uintptr_t) * 2, symaddr, symbol);
1666 palkovsky 670
#ifdef ia64
671
        fptr.f = symaddr;
1780 jermar 672
        fptr.gp = ((unative_t *)cmd_call2)[1];
673
        f =  (unative_t (*)(unative_t,unative_t,unative_t,...)) &fptr;
1666 palkovsky 674
#else
1780 jermar 675
        f =  (unative_t (*)(unative_t,unative_t,unative_t,...)) symaddr;
1666 palkovsky 676
#endif
1224 cejka 677
        printf("Result: %#zx\n", f(arg1, arg2, arg3));
596 jermar 678
    }
679
 
680
    return 1;
681
}
682
 
683
 
684
/** Print detailed description of 'describe' command. */
685
void desc_help(void)
686
{
687
    printf("Syntax: describe command_name\n");
688
}
689
 
690
/** Halt the kernel.
691
 *
692
 * @param argv Argument vector (ignored).
693
 *
694
 * @return 0 on failure, 1 on success (never returns).
695
 */
696
int cmd_halt(cmd_arg_t *argv)
697
{
698
    halt();
699
    return 1;
700
}
701
 
702
/** Command for printing TLB contents.
703
 *
704
 * @param argv Not used.
705
 *
706
 * @return Always returns 1.
707
 */
673 jermar 708
int cmd_tlb(cmd_arg_t *argv)
596 jermar 709
{
710
    tlb_print();
711
    return 1;
712
}
603 palkovsky 713
 
714
/** Write 4 byte value to address */
715
int cmd_set4(cmd_arg_t *argv)
716
{
1780 jermar 717
    uint32_t *addr ;
718
    uint32_t arg1 = argv[1].intval;
603 palkovsky 719
    bool pointer = false;
720
 
721
    if (((char *)argv->buffer)[0] == '*') {
1780 jermar 722
        addr = (uint32_t *) get_symbol_addr(argv->buffer+1);
603 palkovsky 723
        pointer = true;
724
    } else if (((char *)argv->buffer)[0] >= '0' &&
725
           ((char *)argv->buffer)[0] <= '9')
1780 jermar 726
        addr = (uint32_t *)atoi((char *)argv->buffer);
603 palkovsky 727
    else
1780 jermar 728
        addr = (uint32_t *)get_symbol_addr(argv->buffer);
603 palkovsky 729
 
730
    if (!addr)
731
        printf("Symbol %s not found.\n", argv->buffer);
1780 jermar 732
    else if (addr == (uint32_t *) -1) {
603 palkovsky 733
        symtab_print_search(argv->buffer);
734
        printf("Duplicate symbol, be more specific.\n");
735
    } else {
736
        if (pointer)
1780 jermar 737
            addr = (uint32_t *)(*(unative_t *)addr);
738
        printf("Writing 0x%x -> %.*p\n", arg1, sizeof(uintptr_t) * 2, addr);
603 palkovsky 739
        *addr = arg1;
740
 
741
    }
742
 
743
    return 1;
744
}
668 bondari 745
 
759 palkovsky 746
/** Command for listings SLAB caches
747
 *
748
 * @param argv Ignores
749
 *
750
 * @return Always 1
751
 */
752
int cmd_slabs(cmd_arg_t * argv) {
753
    slab_print_list();
754
    return 1;
755
}
756
 
777 palkovsky 757
 
775 palkovsky 758
/** Command for listings Thread information
759
 *
760
 * @param argv Ignores
761
 *
762
 * @return Always 1
763
 */
777 palkovsky 764
int cmd_threads(cmd_arg_t * argv) {
765
    thread_print_list();
766
    return 1;
767
}
768
 
1060 palkovsky 769
/** Command for listings Task information
770
 *
771
 * @param argv Ignores
772
 *
773
 * @return Always 1
774
 */
775
int cmd_tasks(cmd_arg_t * argv) {
776
    task_print_list();
777
    return 1;
778
}
779
 
777 palkovsky 780
/** Command for listings Thread information
781
 *
782
 * @param argv Ignores
783
 *
784
 * @return Always 1
785
 */
775 palkovsky 786
int cmd_sched(cmd_arg_t * argv) {
787
    sched_print_list();
788
    return 1;
789
}
790
 
677 bondari 791
/** Command for listing memory zones
792
 *
793
 * @param argv Ignored
794
 *
795
 * return Always 1
796
 */
668 bondari 797
int cmd_zones(cmd_arg_t * argv) {
676 bondari 798
    zone_print_list();
668 bondari 799
    return 1;
800
}
673 jermar 801
 
677 bondari 802
/** Command for memory zone details
803
 *
804
 * @param argv Integer argument from cmdline expected
805
 *
806
 * return Always 1
807
 */
668 bondari 808
int cmd_zone(cmd_arg_t * argv) {
676 bondari 809
    zone_print_one(argv[0].intval);
668 bondari 810
    return 1;
811
}
812
 
1573 palkovsky 813
/** Command for printing task ipc details
814
 *
815
 * @param argv Integer argument from cmdline expected
816
 *
817
 * return Always 1
818
 */
819
int cmd_ipc_task(cmd_arg_t * argv) {
820
    ipc_print_task(argv[0].intval);
821
    return 1;
822
}
823
 
824
 
673 jermar 825
/** Command for listing processors.
826
 *
827
 * @param argv Ignored.
828
 *
829
 * return Always 1.
830
 */
831
int cmd_cpus(cmd_arg_t *argv)
832
{
833
    cpu_list();
834
    return 1;
835
}
836
 
837
/** Command for printing kernel version.
838
 *
839
 * @param argv Ignored.
840
 *
841
 * return Always 1.
842
 */
843
int cmd_version(cmd_arg_t *argv)
844
{
845
    version_print();
846
    return 1;
847
}
1474 palkovsky 848
 
849
/** Command for returning console back to userspace.
850
 *
851
 * @param argv Ignored.
852
 *
853
 * return Always 1.
854
 */
855
int cmd_continue(cmd_arg_t *argv)
856
{
1695 jermar 857
    printf("The kernel will now relinquish the console.\n");
858
    printf("Use userspace controls to redraw the screen.\n");
1474 palkovsky 859
    arch_release_console();
860
    return 1;
861
}
1702 cejka 862
 
2020 decky 863
#ifdef CONFIG_TEST
2019 decky 864
/** Command for printing kernel tests list.
865
 *
866
 * @param argv Ignored.
867
 *
868
 * return Always 1.
869
 */
870
int cmd_tests(cmd_arg_t *argv)
871
{
872
    test_t *test;
873
 
874
    for (test = tests; test->name != NULL; test++)
2020 decky 875
        printf("%s\t\t%s%s\n", test->name, test->desc, (test->safe ? "" : " (unsafe)"));
2019 decky 876
 
2020 decky 877
    printf("*\t\tRun all safe tests\n");
2019 decky 878
    return 1;
879
}
880
 
2042 decky 881
static bool run_test(const test_t *test)
2027 decky 882
{
2042 decky 883
    printf("%s\t\t%s\n", test->name, test->desc);
2030 decky 884
 
885
    /* Update and read thread accounting
886
       for benchmarking */
887
    ipl_t ipl = interrupts_disable();
2039 decky 888
    spinlock_lock(&TASK->lock);
889
    uint64_t t0 = task_get_accounting(TASK);
890
    spinlock_unlock(&TASK->lock);
2030 decky 891
    interrupts_restore(ipl);
892
 
893
    /* Execute the test */
2050 decky 894
    char * ret = test->entry(false);
2030 decky 895
 
896
    /* Update and read thread accounting */
897
    ipl = interrupts_disable();
2039 decky 898
    spinlock_lock(&TASK->lock);
899
    uint64_t dt = task_get_accounting(TASK) - t0;
900
    spinlock_unlock(&TASK->lock);
2030 decky 901
    interrupts_restore(ipl);
902
 
2050 decky 903
    uint64_t cycles;
904
    char suffix;
905
    order(dt, &cycles, &suffix);
906
 
907
    printf("Time: %llu%c cycles\n", cycles, suffix);
2027 decky 908
 
909
    if (ret == NULL) {
910
        printf("Test passed\n");
2042 decky 911
        return true;
2027 decky 912
    }
913
 
914
    printf("%s\n", ret);
2042 decky 915
    return false;
2027 decky 916
}
917
 
2050 decky 918
static bool run_bench(const test_t *test, const uint32_t cnt)
919
{
920
    uint32_t i;
921
    bool ret = true;
922
    uint64_t cycles;
923
    char suffix;
924
 
925
    if (cnt < 1)
926
        return true;
927
 
928
    uint64_t *data = malloc(sizeof(uint64_t) * cnt, 0);
929
    if (data == NULL) {
930
        printf("Error allocating memory for statistics\n");
931
        return false;
932
    }
933
 
934
    for (i = 0; i < cnt; i++) {
935
        printf("%s (%d/%d) ... ", test->name, i + 1, cnt);
936
 
937
        /* Update and read thread accounting
938
           for benchmarking */
939
        ipl_t ipl = interrupts_disable();
940
        spinlock_lock(&TASK->lock);
941
        uint64_t t0 = task_get_accounting(TASK);
942
        spinlock_unlock(&TASK->lock);
943
        interrupts_restore(ipl);
944
 
945
        /* Execute the test */
946
        char * ret = test->entry(true);
947
 
948
        /* Update and read thread accounting */
949
        ipl = interrupts_disable();
950
        spinlock_lock(&TASK->lock);
951
        uint64_t dt = task_get_accounting(TASK) - t0;
952
        spinlock_unlock(&TASK->lock);
953
        interrupts_restore(ipl);
954
 
955
        if (ret != NULL) {
956
            printf("%s\n", ret);
957
            ret = false;
958
            break;
959
        }
960
 
961
        data[i] = dt;
962
        order(dt, &cycles, &suffix);
963
        printf("OK (%llu%c cycles)\n", cycles, suffix);
964
    }
965
 
966
    if (ret) {
967
        printf("\n");
968
 
969
        uint64_t sum = 0;
970
 
971
        for (i = 0; i < cnt; i++) {
972
            sum += data[i];
973
        }
974
 
975
        order(sum / (uint64_t) cnt, &cycles, &suffix);
976
        printf("Average\t\t%llu%c\n", cycles, suffix);
977
    }
978
 
979
    free(data);
980
 
981
    return ret;
982
}
983
 
2019 decky 984
/** Command for returning kernel tests
985
 *
986
 * @param argv Argument vector.
987
 *
988
 * return Always 1.
989
 */
990
int cmd_test(cmd_arg_t *argv)
991
{
992
    test_t *test;
993
 
2020 decky 994
    if (strcmp(argv->buffer, "*") == 0) {
995
        for (test = tests; test->name != NULL; test++) {
996
            if (test->safe) {
2027 decky 997
                printf("\n");
998
                if (!run_test(test))
999
                    break;
2020 decky 1000
            }
2019 decky 1001
        }
2020 decky 1002
    } else {
1003
        bool fnd = false;
1004
 
1005
        for (test = tests; test->name != NULL; test++) {
1006
            if (strcmp(test->name, argv->buffer) == 0) {
1007
                fnd = true;
2027 decky 1008
                run_test(test);
2020 decky 1009
                break;
1010
            }
1011
        }
1012
 
1013
        if (!fnd)
2027 decky 1014
            printf("Unknown test\n");
2019 decky 1015
    }
1016
 
1017
    return 1;
1018
}
2050 decky 1019
 
1020
/** Command for returning kernel tests as benchmarks
1021
 *
1022
 * @param argv Argument vector.
1023
 *
1024
 * return Always 1.
1025
 */
1026
int cmd_bench(cmd_arg_t *argv)
1027
{
1028
    test_t *test;
1029
    uint32_t cnt = argv[1].intval;
1030
 
1031
    bool fnd = false;
1032
 
1033
    for (test = tests; test->name != NULL; test++) {
1034
        if (strcmp(test->name, argv->buffer) == 0) {
1035
            fnd = true;
2051 decky 1036
 
1037
            if (test->safe)
1038
                run_bench(test, cnt);
1039
            else
1040
                printf("Unsafe test\n");
1041
 
2050 decky 1042
            break;
1043
        }
1044
    }
1045
 
1046
    if (!fnd)
1047
        printf("Unknown test\n");
1048
 
1049
    return 1;
1050
}
1051
 
2020 decky 1052
#endif
2019 decky 1053
 
1888 jermar 1054
/** @}
1702 cejka 1055
 */