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 |
|
---|
29 | /** @addtogroup genericconsole
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * @file cmd.c
|
---|
35 | * @brief Kernel console command wrappers.
|
---|
36 | *
|
---|
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>
|
---|
44 | #include <console/console.h>
|
---|
45 | #include <console/kconsole.h>
|
---|
46 | #include <print.h>
|
---|
47 | #include <panic.h>
|
---|
48 | #include <typedefs.h>
|
---|
49 | #include <adt/list.h>
|
---|
50 | #include <arch.h>
|
---|
51 | #include <config.h>
|
---|
52 | #include <func.h>
|
---|
53 | #include <str.h>
|
---|
54 | #include <macros.h>
|
---|
55 | #include <debug.h>
|
---|
56 | #include <cpu.h>
|
---|
57 | #include <mm/tlb.h>
|
---|
58 | #include <arch/mm/tlb.h>
|
---|
59 | #include <mm/frame.h>
|
---|
60 | #include <main/version.h>
|
---|
61 | #include <mm/slab.h>
|
---|
62 | #include <proc/scheduler.h>
|
---|
63 | #include <proc/thread.h>
|
---|
64 | #include <proc/task.h>
|
---|
65 | #include <ipc/ipc.h>
|
---|
66 | #include <ipc/irq.h>
|
---|
67 | #include <ipc/event.h>
|
---|
68 | #include <sysinfo/sysinfo.h>
|
---|
69 | #include <symtab.h>
|
---|
70 | #include <synch/workqueue.h>
|
---|
71 | #include <errno.h>
|
---|
72 |
|
---|
73 | #ifdef CONFIG_TEST
|
---|
74 | #include <test.h>
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | /* Data and methods for 'help' command. */
|
---|
78 | static int cmd_help(cmd_arg_t *argv);
|
---|
79 | static cmd_info_t help_info = {
|
---|
80 | .name = "help",
|
---|
81 | .description = "List supported commands.",
|
---|
82 | .func = cmd_help,
|
---|
83 | .argc = 0
|
---|
84 | };
|
---|
85 |
|
---|
86 | /* Data and methods for 'reboot' command. */
|
---|
87 | static int cmd_reboot(cmd_arg_t *argv);
|
---|
88 | static cmd_info_t reboot_info = {
|
---|
89 | .name = "reboot",
|
---|
90 | .description = "Reboot system.",
|
---|
91 | .func = cmd_reboot,
|
---|
92 | .argc = 0
|
---|
93 | };
|
---|
94 |
|
---|
95 | /* Data and methods for 'uptime' command. */
|
---|
96 | static int cmd_uptime(cmd_arg_t *argv);
|
---|
97 | static cmd_info_t uptime_info = {
|
---|
98 | .name = "uptime",
|
---|
99 | .description = "Show system uptime.",
|
---|
100 | .func = cmd_uptime,
|
---|
101 | .argc = 0
|
---|
102 | };
|
---|
103 |
|
---|
104 | /* Data and methods for 'continue' command. */
|
---|
105 | static int cmd_continue(cmd_arg_t *argv);
|
---|
106 | static cmd_info_t continue_info = {
|
---|
107 | .name = "continue",
|
---|
108 | .description = "Return console back to userspace.",
|
---|
109 | .func = cmd_continue,
|
---|
110 | .argc = 0
|
---|
111 | };
|
---|
112 |
|
---|
113 | #ifdef CONFIG_TEST
|
---|
114 |
|
---|
115 | /* Data and methods for 'test' command. */
|
---|
116 | static char test_buf[MAX_CMDLINE + 1];
|
---|
117 | static int cmd_test(cmd_arg_t *argv);
|
---|
118 | static cmd_arg_t test_argv[] = {
|
---|
119 | {
|
---|
120 | .type = ARG_TYPE_STRING_OPTIONAL,
|
---|
121 | .buffer = test_buf,
|
---|
122 | .len = sizeof(test_buf)
|
---|
123 | }
|
---|
124 | };
|
---|
125 | static cmd_info_t test_info = {
|
---|
126 | .name = "test",
|
---|
127 | .description = "<test> List kernel tests or run a test.",
|
---|
128 | .func = cmd_test,
|
---|
129 | .argc = 1,
|
---|
130 | .argv = test_argv
|
---|
131 | };
|
---|
132 |
|
---|
133 | /* Data and methods for 'bench' command. */
|
---|
134 | static int cmd_bench(cmd_arg_t *argv);
|
---|
135 | static cmd_arg_t bench_argv[] = {
|
---|
136 | {
|
---|
137 | .type = ARG_TYPE_STRING,
|
---|
138 | .buffer = test_buf,
|
---|
139 | .len = sizeof(test_buf)
|
---|
140 | },
|
---|
141 | {
|
---|
142 | .type = ARG_TYPE_INT,
|
---|
143 | }
|
---|
144 | };
|
---|
145 | static cmd_info_t bench_info = {
|
---|
146 | .name = "bench",
|
---|
147 | .description = "<test> <count> Run kernel test as benchmark.",
|
---|
148 | .func = cmd_bench,
|
---|
149 | .argc = 2,
|
---|
150 | .argv = bench_argv
|
---|
151 | };
|
---|
152 |
|
---|
153 | #endif /* CONFIG_TEST */
|
---|
154 |
|
---|
155 | /* Data and methods for 'description' command. */
|
---|
156 | static int cmd_desc(cmd_arg_t *argv);
|
---|
157 | static void desc_help(void);
|
---|
158 | static char desc_buf[MAX_CMDLINE + 1];
|
---|
159 | static cmd_arg_t desc_argv = {
|
---|
160 | .type = ARG_TYPE_STRING,
|
---|
161 | .buffer = desc_buf,
|
---|
162 | .len = sizeof(desc_buf)
|
---|
163 | };
|
---|
164 | static cmd_info_t desc_info = {
|
---|
165 | .name = "describe",
|
---|
166 | .description = "<command> Describe specified command.",
|
---|
167 | .help = desc_help,
|
---|
168 | .func = cmd_desc,
|
---|
169 | .argc = 1,
|
---|
170 | .argv = &desc_argv
|
---|
171 | };
|
---|
172 |
|
---|
173 | /* Data and methods for 'symaddr' command. */
|
---|
174 | static int cmd_symaddr(cmd_arg_t *argv);
|
---|
175 | static char symaddr_buf[MAX_CMDLINE + 1];
|
---|
176 | static cmd_arg_t symaddr_argv = {
|
---|
177 | .type = ARG_TYPE_STRING,
|
---|
178 | .buffer = symaddr_buf,
|
---|
179 | .len = sizeof(symaddr_buf)
|
---|
180 | };
|
---|
181 | static cmd_info_t symaddr_info = {
|
---|
182 | .name = "symaddr",
|
---|
183 | .description = "<symbol> Return symbol address.",
|
---|
184 | .func = cmd_symaddr,
|
---|
185 | .argc = 1,
|
---|
186 | .argv = &symaddr_argv
|
---|
187 | };
|
---|
188 |
|
---|
189 | /* Data and methods for 'set4' command. */
|
---|
190 | static char set_buf[MAX_CMDLINE + 1];
|
---|
191 | static int cmd_set4(cmd_arg_t *argv);
|
---|
192 | static cmd_arg_t set4_argv[] = {
|
---|
193 | {
|
---|
194 | .type = ARG_TYPE_STRING,
|
---|
195 | .buffer = set_buf,
|
---|
196 | .len = sizeof(set_buf)
|
---|
197 | },
|
---|
198 | {
|
---|
199 | .type = ARG_TYPE_INT
|
---|
200 | }
|
---|
201 | };
|
---|
202 | static cmd_info_t set4_info = {
|
---|
203 | .name = "set4",
|
---|
204 | .description = "<addr> <value> Set 4B memory location to a value.",
|
---|
205 | .func = cmd_set4,
|
---|
206 | .argc = 2,
|
---|
207 | .argv = set4_argv
|
---|
208 | };
|
---|
209 |
|
---|
210 | /* Data and methods for 'call0' and 'mcall0' command. */
|
---|
211 | static char call0_buf[MAX_CMDLINE + 1];
|
---|
212 | static char carg1_buf[MAX_CMDLINE + 1];
|
---|
213 | static char carg2_buf[MAX_CMDLINE + 1];
|
---|
214 | static char carg3_buf[MAX_CMDLINE + 1];
|
---|
215 |
|
---|
216 | static int cmd_call0(cmd_arg_t *argv);
|
---|
217 | static cmd_arg_t call0_argv = {
|
---|
218 | .type = ARG_TYPE_STRING,
|
---|
219 | .buffer = call0_buf,
|
---|
220 | .len = sizeof(call0_buf)
|
---|
221 | };
|
---|
222 | static cmd_info_t call0_info = {
|
---|
223 | .name = "call0",
|
---|
224 | .description = "<function> Call function().",
|
---|
225 | .func = cmd_call0,
|
---|
226 | .argc = 1,
|
---|
227 | .argv = &call0_argv
|
---|
228 | };
|
---|
229 |
|
---|
230 | /* Data and methods for 'mcall0' command. */
|
---|
231 | static int cmd_mcall0(cmd_arg_t *argv);
|
---|
232 | static cmd_arg_t mcall0_argv = {
|
---|
233 | .type = ARG_TYPE_STRING,
|
---|
234 | .buffer = call0_buf,
|
---|
235 | .len = sizeof(call0_buf)
|
---|
236 | };
|
---|
237 | static cmd_info_t mcall0_info = {
|
---|
238 | .name = "mcall0",
|
---|
239 | .description = "<function> Call function() on each CPU.",
|
---|
240 | .func = cmd_mcall0,
|
---|
241 | .argc = 1,
|
---|
242 | .argv = &mcall0_argv
|
---|
243 | };
|
---|
244 |
|
---|
245 | /* Data and methods for 'call1' command. */
|
---|
246 | static int cmd_call1(cmd_arg_t *argv);
|
---|
247 | static cmd_arg_t call1_argv[] = {
|
---|
248 | {
|
---|
249 | .type = ARG_TYPE_STRING,
|
---|
250 | .buffer = call0_buf,
|
---|
251 | .len = sizeof(call0_buf)
|
---|
252 | },
|
---|
253 | {
|
---|
254 | .type = ARG_TYPE_VAR,
|
---|
255 | .buffer = carg1_buf,
|
---|
256 | .len = sizeof(carg1_buf)
|
---|
257 | }
|
---|
258 | };
|
---|
259 | static cmd_info_t call1_info = {
|
---|
260 | .name = "call1",
|
---|
261 | .description = "<function> <arg1> Call function(arg1).",
|
---|
262 | .func = cmd_call1,
|
---|
263 | .argc = 2,
|
---|
264 | .argv = call1_argv
|
---|
265 | };
|
---|
266 |
|
---|
267 | /* Data and methods for 'call2' command. */
|
---|
268 | static int cmd_call2(cmd_arg_t *argv);
|
---|
269 | static cmd_arg_t call2_argv[] = {
|
---|
270 | {
|
---|
271 | .type = ARG_TYPE_STRING,
|
---|
272 | .buffer = call0_buf,
|
---|
273 | .len = sizeof(call0_buf)
|
---|
274 | },
|
---|
275 | {
|
---|
276 | .type = ARG_TYPE_VAR,
|
---|
277 | .buffer = carg1_buf,
|
---|
278 | .len = sizeof(carg1_buf)
|
---|
279 | },
|
---|
280 | {
|
---|
281 | .type = ARG_TYPE_VAR,
|
---|
282 | .buffer = carg2_buf,
|
---|
283 | .len = sizeof(carg2_buf)
|
---|
284 | }
|
---|
285 | };
|
---|
286 | static cmd_info_t call2_info = {
|
---|
287 | .name = "call2",
|
---|
288 | .description = "<function> <arg1> <arg2> Call function(arg1, arg2).",
|
---|
289 | .func = cmd_call2,
|
---|
290 | .argc = 3,
|
---|
291 | .argv = call2_argv
|
---|
292 | };
|
---|
293 |
|
---|
294 | /* Data and methods for 'call3' command. */
|
---|
295 | static int cmd_call3(cmd_arg_t *argv);
|
---|
296 | static cmd_arg_t call3_argv[] = {
|
---|
297 | {
|
---|
298 | .type = ARG_TYPE_STRING,
|
---|
299 | .buffer = call0_buf,
|
---|
300 | .len = sizeof(call0_buf)
|
---|
301 | },
|
---|
302 | {
|
---|
303 | .type = ARG_TYPE_VAR,
|
---|
304 | .buffer = carg1_buf,
|
---|
305 | .len = sizeof(carg1_buf)
|
---|
306 | },
|
---|
307 | {
|
---|
308 | .type = ARG_TYPE_VAR,
|
---|
309 | .buffer = carg2_buf,
|
---|
310 | .len = sizeof(carg2_buf)
|
---|
311 | },
|
---|
312 | {
|
---|
313 | .type = ARG_TYPE_VAR,
|
---|
314 | .buffer = carg3_buf,
|
---|
315 | .len = sizeof(carg3_buf)
|
---|
316 | }
|
---|
317 |
|
---|
318 | };
|
---|
319 | static cmd_info_t call3_info = {
|
---|
320 | .name = "call3",
|
---|
321 | .description = "<function> <arg1> <arg2> <arg3> Call function(arg1, arg2, arg3).",
|
---|
322 | .func = cmd_call3,
|
---|
323 | .argc = 4,
|
---|
324 | .argv = call3_argv
|
---|
325 | };
|
---|
326 |
|
---|
327 | /* Data and methods for 'halt' command. */
|
---|
328 | static int cmd_halt(cmd_arg_t *argv);
|
---|
329 | static cmd_info_t halt_info = {
|
---|
330 | .name = "halt",
|
---|
331 | .description = "Halt the kernel.",
|
---|
332 | .func = cmd_halt,
|
---|
333 | .argc = 0
|
---|
334 | };
|
---|
335 |
|
---|
336 | /* Data and methods for 'physmem' command. */
|
---|
337 | static int cmd_physmem(cmd_arg_t *argv);
|
---|
338 | cmd_info_t physmem_info = {
|
---|
339 | .name = "physmem",
|
---|
340 | .description = "Print physical memory configuration.",
|
---|
341 | .help = NULL,
|
---|
342 | .func = cmd_physmem,
|
---|
343 | .argc = 0,
|
---|
344 | .argv = NULL
|
---|
345 | };
|
---|
346 |
|
---|
347 | /* Data and methods for 'tlb' command. */
|
---|
348 | static int cmd_tlb(cmd_arg_t *argv);
|
---|
349 | cmd_info_t tlb_info = {
|
---|
350 | .name = "tlb",
|
---|
351 | .description = "Print TLB of the current CPU.",
|
---|
352 | .help = NULL,
|
---|
353 | .func = cmd_tlb,
|
---|
354 | .argc = 0,
|
---|
355 | .argv = NULL
|
---|
356 | };
|
---|
357 |
|
---|
358 | static char flag_buf[MAX_CMDLINE + 1];
|
---|
359 |
|
---|
360 | static int cmd_threads(cmd_arg_t *argv);
|
---|
361 | static cmd_arg_t threads_argv = {
|
---|
362 | .type = ARG_TYPE_STRING_OPTIONAL,
|
---|
363 | .buffer = flag_buf,
|
---|
364 | .len = sizeof(flag_buf)
|
---|
365 | };
|
---|
366 | static cmd_info_t threads_info = {
|
---|
367 | .name = "threads",
|
---|
368 | .description = "List all threads (use -a for additional information).",
|
---|
369 | .func = cmd_threads,
|
---|
370 | .argc = 1,
|
---|
371 | .argv = &threads_argv
|
---|
372 | };
|
---|
373 |
|
---|
374 | static int cmd_tasks(cmd_arg_t *argv);
|
---|
375 | static cmd_arg_t tasks_argv = {
|
---|
376 | .type = ARG_TYPE_STRING_OPTIONAL,
|
---|
377 | .buffer = flag_buf,
|
---|
378 | .len = sizeof(flag_buf)
|
---|
379 | };
|
---|
380 | static cmd_info_t tasks_info = {
|
---|
381 | .name = "tasks",
|
---|
382 | .description = "List all tasks (use -a for additional information).",
|
---|
383 | .func = cmd_tasks,
|
---|
384 | .argc = 1,
|
---|
385 | .argv = &tasks_argv
|
---|
386 | };
|
---|
387 |
|
---|
388 | #ifdef CONFIG_UDEBUG
|
---|
389 |
|
---|
390 | /* Data and methods for 'btrace' command */
|
---|
391 | static int cmd_btrace(cmd_arg_t *argv);
|
---|
392 | static cmd_arg_t btrace_argv = {
|
---|
393 | .type = ARG_TYPE_INT,
|
---|
394 | };
|
---|
395 | static cmd_info_t btrace_info = {
|
---|
396 | .name = "btrace",
|
---|
397 | .description = "<threadid> Show thread stack trace.",
|
---|
398 | .func = cmd_btrace,
|
---|
399 | .argc = 1,
|
---|
400 | .argv = &btrace_argv
|
---|
401 | };
|
---|
402 |
|
---|
403 | #endif /* CONFIG_UDEBUG */
|
---|
404 |
|
---|
405 | static int cmd_sched(cmd_arg_t *argv);
|
---|
406 | static cmd_info_t sched_info = {
|
---|
407 | .name = "scheduler",
|
---|
408 | .description = "Show scheduler information.",
|
---|
409 | .func = cmd_sched,
|
---|
410 | .argc = 0
|
---|
411 | };
|
---|
412 |
|
---|
413 | static int cmd_slabs(cmd_arg_t *argv);
|
---|
414 | static cmd_info_t slabs_info = {
|
---|
415 | .name = "slabs",
|
---|
416 | .description = "List slab caches.",
|
---|
417 | .func = cmd_slabs,
|
---|
418 | .argc = 0
|
---|
419 | };
|
---|
420 |
|
---|
421 | static int cmd_sysinfo(cmd_arg_t *argv);
|
---|
422 | static cmd_info_t sysinfo_info = {
|
---|
423 | .name = "sysinfo",
|
---|
424 | .description = "Dump sysinfo.",
|
---|
425 | .func = cmd_sysinfo,
|
---|
426 | .argc = 0
|
---|
427 | };
|
---|
428 |
|
---|
429 | /* Data and methods for 'zones' command */
|
---|
430 | static int cmd_zones(cmd_arg_t *argv);
|
---|
431 | static cmd_info_t zones_info = {
|
---|
432 | .name = "zones",
|
---|
433 | .description = "List memory zones.",
|
---|
434 | .func = cmd_zones,
|
---|
435 | .argc = 0
|
---|
436 | };
|
---|
437 |
|
---|
438 | /* Data and methods for 'zone' command */
|
---|
439 | static int cmd_zone(cmd_arg_t *argv);
|
---|
440 | static cmd_arg_t zone_argv = {
|
---|
441 | .type = ARG_TYPE_INT,
|
---|
442 | };
|
---|
443 |
|
---|
444 | static cmd_info_t zone_info = {
|
---|
445 | .name = "zone",
|
---|
446 | .description = "<zone> Show memory zone structure.",
|
---|
447 | .func = cmd_zone,
|
---|
448 | .argc = 1,
|
---|
449 | .argv = &zone_argv
|
---|
450 | };
|
---|
451 |
|
---|
452 | /* Data and methods for the 'workq' command */
|
---|
453 | static int cmd_workq(cmd_arg_t *argv);
|
---|
454 | static cmd_info_t workq_info = {
|
---|
455 | .name = "workq",
|
---|
456 | .description = "Show global workq information.",
|
---|
457 | .func = cmd_workq,
|
---|
458 | .argc = 0
|
---|
459 | };
|
---|
460 |
|
---|
461 | /* Data and methods for 'ipc' command */
|
---|
462 | static int cmd_ipc(cmd_arg_t *argv);
|
---|
463 | static cmd_arg_t ipc_argv = {
|
---|
464 | .type = ARG_TYPE_INT,
|
---|
465 | };
|
---|
466 | static cmd_info_t ipc_info = {
|
---|
467 | .name = "ipc",
|
---|
468 | .description = "<taskid> Show IPC information of a task.",
|
---|
469 | .func = cmd_ipc,
|
---|
470 | .argc = 1,
|
---|
471 | .argv = &ipc_argv
|
---|
472 | };
|
---|
473 |
|
---|
474 | /* Data and methods for 'kill' command */
|
---|
475 | static int cmd_kill(cmd_arg_t *argv);
|
---|
476 | static cmd_arg_t kill_argv = {
|
---|
477 | .type = ARG_TYPE_INT,
|
---|
478 | };
|
---|
479 | static cmd_info_t kill_info = {
|
---|
480 | .name = "kill",
|
---|
481 | .description = "<taskid> Kill a task.",
|
---|
482 | .func = cmd_kill,
|
---|
483 | .argc = 1,
|
---|
484 | .argv = &kill_argv
|
---|
485 | };
|
---|
486 |
|
---|
487 | /* Data and methods for 'cpus' command. */
|
---|
488 | static int cmd_cpus(cmd_arg_t *argv);
|
---|
489 | cmd_info_t cpus_info = {
|
---|
490 | .name = "cpus",
|
---|
491 | .description = "List all processors.",
|
---|
492 | .help = NULL,
|
---|
493 | .func = cmd_cpus,
|
---|
494 | .argc = 0,
|
---|
495 | .argv = NULL
|
---|
496 | };
|
---|
497 |
|
---|
498 | /* Data and methods for 'version' command. */
|
---|
499 | static int cmd_version(cmd_arg_t *argv);
|
---|
500 | cmd_info_t version_info = {
|
---|
501 | .name = "version",
|
---|
502 | .description = "Print version information.",
|
---|
503 | .help = NULL,
|
---|
504 | .func = cmd_version,
|
---|
505 | .argc = 0,
|
---|
506 | .argv = NULL
|
---|
507 | };
|
---|
508 |
|
---|
509 | static cmd_info_t *basic_commands[] = {
|
---|
510 | &call0_info,
|
---|
511 | &mcall0_info,
|
---|
512 | &call1_info,
|
---|
513 | &call2_info,
|
---|
514 | &call3_info,
|
---|
515 | &continue_info,
|
---|
516 | &cpus_info,
|
---|
517 | &desc_info,
|
---|
518 | &halt_info,
|
---|
519 | &help_info,
|
---|
520 | &ipc_info,
|
---|
521 | &kill_info,
|
---|
522 | &physmem_info,
|
---|
523 | &reboot_info,
|
---|
524 | &sched_info,
|
---|
525 | &set4_info,
|
---|
526 | &slabs_info,
|
---|
527 | &symaddr_info,
|
---|
528 | &sysinfo_info,
|
---|
529 | &tasks_info,
|
---|
530 | &threads_info,
|
---|
531 | &tlb_info,
|
---|
532 | &uptime_info,
|
---|
533 | &version_info,
|
---|
534 | &workq_info,
|
---|
535 | &zones_info,
|
---|
536 | &zone_info,
|
---|
537 | #ifdef CONFIG_TEST
|
---|
538 | &test_info,
|
---|
539 | &bench_info,
|
---|
540 | #endif
|
---|
541 | #ifdef CONFIG_UDEBUG
|
---|
542 | &btrace_info,
|
---|
543 | #endif
|
---|
544 | NULL
|
---|
545 | };
|
---|
546 |
|
---|
547 |
|
---|
548 | /** Initialize command info structure.
|
---|
549 | *
|
---|
550 | * @param cmd Command info structure.
|
---|
551 | *
|
---|
552 | */
|
---|
553 | void cmd_initialize(cmd_info_t *cmd)
|
---|
554 | {
|
---|
555 | spinlock_initialize(&cmd->lock, "cmd.lock");
|
---|
556 | link_initialize(&cmd->link);
|
---|
557 | }
|
---|
558 |
|
---|
559 | /** Initialize and register commands. */
|
---|
560 | void cmd_init(void)
|
---|
561 | {
|
---|
562 | unsigned int i;
|
---|
563 |
|
---|
564 | for (i = 0; basic_commands[i]; i++) {
|
---|
565 | cmd_initialize(basic_commands[i]);
|
---|
566 | }
|
---|
567 |
|
---|
568 | for (i = 0; basic_commands[i]; i++) {
|
---|
569 | if (!cmd_register(basic_commands[i])) {
|
---|
570 | printf("Cannot register command %s\n",
|
---|
571 | basic_commands[i]->name);
|
---|
572 | }
|
---|
573 | }
|
---|
574 | }
|
---|
575 |
|
---|
576 | /** List supported commands.
|
---|
577 | *
|
---|
578 | * @param argv Argument vector.
|
---|
579 | *
|
---|
580 | * @return 0 on failure, 1 on success.
|
---|
581 | */
|
---|
582 | int cmd_help(cmd_arg_t *argv)
|
---|
583 | {
|
---|
584 | spinlock_lock(&cmd_lock);
|
---|
585 |
|
---|
586 | size_t len = 0;
|
---|
587 | list_foreach(cmd_list, cur) {
|
---|
588 | cmd_info_t *hlp;
|
---|
589 | hlp = list_get_instance(cur, cmd_info_t, link);
|
---|
590 |
|
---|
591 | spinlock_lock(&hlp->lock);
|
---|
592 | if (str_length(hlp->name) > len)
|
---|
593 | len = str_length(hlp->name);
|
---|
594 | spinlock_unlock(&hlp->lock);
|
---|
595 | }
|
---|
596 |
|
---|
597 | unsigned int _len = (unsigned int) len;
|
---|
598 | if ((_len != len) || (((int) _len) < 0)) {
|
---|
599 | printf("Command length overflow\n");
|
---|
600 | return 1;
|
---|
601 | }
|
---|
602 |
|
---|
603 | list_foreach(cmd_list, cur) {
|
---|
604 | cmd_info_t *hlp;
|
---|
605 | hlp = list_get_instance(cur, cmd_info_t, link);
|
---|
606 |
|
---|
607 | spinlock_lock(&hlp->lock);
|
---|
608 | printf("%-*s %s\n", _len, hlp->name, hlp->description);
|
---|
609 | spinlock_unlock(&hlp->lock);
|
---|
610 | }
|
---|
611 |
|
---|
612 | spinlock_unlock(&cmd_lock);
|
---|
613 |
|
---|
614 | return 1;
|
---|
615 | }
|
---|
616 |
|
---|
617 | /** Reboot the system.
|
---|
618 | *
|
---|
619 | * @param argv Argument vector.
|
---|
620 | *
|
---|
621 | * @return 0 on failure, 1 on success.
|
---|
622 | */
|
---|
623 | int cmd_reboot(cmd_arg_t *argv)
|
---|
624 | {
|
---|
625 | reboot();
|
---|
626 |
|
---|
627 | /* Not reached */
|
---|
628 | return 1;
|
---|
629 | }
|
---|
630 |
|
---|
631 | /** Print system uptime information.
|
---|
632 | *
|
---|
633 | * @param argv Argument vector.
|
---|
634 | *
|
---|
635 | * @return 0 on failure, 1 on success.
|
---|
636 | */
|
---|
637 | int cmd_uptime(cmd_arg_t *argv)
|
---|
638 | {
|
---|
639 | ASSERT(uptime);
|
---|
640 |
|
---|
641 | /* This doesn't have to be very accurate */
|
---|
642 | sysarg_t sec = uptime->seconds1;
|
---|
643 |
|
---|
644 | printf("Up %" PRIun " days, %" PRIun " hours, %" PRIun " minutes, %" PRIun " seconds\n",
|
---|
645 | sec / 86400, (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
|
---|
646 |
|
---|
647 | return 1;
|
---|
648 | }
|
---|
649 |
|
---|
650 | /** Describe specified command.
|
---|
651 | *
|
---|
652 | * @param argv Argument vector.
|
---|
653 | *
|
---|
654 | * @return 0 on failure, 1 on success.
|
---|
655 | */
|
---|
656 | int cmd_desc(cmd_arg_t *argv)
|
---|
657 | {
|
---|
658 | spinlock_lock(&cmd_lock);
|
---|
659 |
|
---|
660 | list_foreach(cmd_list, cur) {
|
---|
661 | cmd_info_t *hlp;
|
---|
662 |
|
---|
663 | hlp = list_get_instance(cur, cmd_info_t, link);
|
---|
664 | spinlock_lock(&hlp->lock);
|
---|
665 |
|
---|
666 | if (str_lcmp(hlp->name, (const char *) argv->buffer, str_length(hlp->name)) == 0) {
|
---|
667 | printf("%s - %s\n", hlp->name, hlp->description);
|
---|
668 | if (hlp->help)
|
---|
669 | hlp->help();
|
---|
670 | spinlock_unlock(&hlp->lock);
|
---|
671 | break;
|
---|
672 | }
|
---|
673 |
|
---|
674 | spinlock_unlock(&hlp->lock);
|
---|
675 | }
|
---|
676 |
|
---|
677 | spinlock_unlock(&cmd_lock);
|
---|
678 |
|
---|
679 | return 1;
|
---|
680 | }
|
---|
681 |
|
---|
682 | /** Search symbol table */
|
---|
683 | int cmd_symaddr(cmd_arg_t *argv)
|
---|
684 | {
|
---|
685 | symtab_print_search((char *) argv->buffer);
|
---|
686 |
|
---|
687 | return 1;
|
---|
688 | }
|
---|
689 |
|
---|
690 | /** Call function with zero parameters */
|
---|
691 | int cmd_call0(cmd_arg_t *argv)
|
---|
692 | {
|
---|
693 | uintptr_t symaddr;
|
---|
694 | char *symbol;
|
---|
695 | sysarg_t (*fnc)(void);
|
---|
696 | fncptr_t fptr;
|
---|
697 | int rc;
|
---|
698 |
|
---|
699 | symbol = (char *) argv->buffer;
|
---|
700 | rc = symtab_addr_lookup(symbol, &symaddr);
|
---|
701 |
|
---|
702 | if (rc == ENOENT)
|
---|
703 | printf("Symbol %s not found.\n", symbol);
|
---|
704 | else if (rc == EOVERFLOW) {
|
---|
705 | symtab_print_search(symbol);
|
---|
706 | printf("Duplicate symbol, be more specific.\n");
|
---|
707 | } else if (rc == EOK) {
|
---|
708 | ipl_t ipl;
|
---|
709 |
|
---|
710 | ipl = interrupts_disable();
|
---|
711 | fnc = (sysarg_t (*)(void)) arch_construct_function(&fptr,
|
---|
712 | (void *) symaddr, (void *) cmd_call0);
|
---|
713 | printf("Calling %s() (%p)\n", symbol, (void *) symaddr);
|
---|
714 | printf("Result: %#" PRIxn "\n", fnc());
|
---|
715 | interrupts_restore(ipl);
|
---|
716 | } else {
|
---|
717 | printf("No symbol information available.\n");
|
---|
718 | }
|
---|
719 | return 1;
|
---|
720 | }
|
---|
721 |
|
---|
722 | /** Call function with zero parameters on each CPU */
|
---|
723 | int cmd_mcall0(cmd_arg_t *argv)
|
---|
724 | {
|
---|
725 | /*
|
---|
726 | * For each CPU, create a thread which will
|
---|
727 | * call the function.
|
---|
728 | */
|
---|
729 |
|
---|
730 | unsigned int i;
|
---|
731 | for (i = 0; i < config.cpu_count; i++) {
|
---|
732 | if (!cpus[i].active)
|
---|
733 | continue;
|
---|
734 |
|
---|
735 | thread_t *thread;
|
---|
736 | if ((thread = thread_create((void (*)(void *)) cmd_call0,
|
---|
737 | (void *) argv, TASK, THREAD_FLAG_NONE, "call0"))) {
|
---|
738 | printf("cpu%u: ", i);
|
---|
739 | thread_wire(thread, &cpus[i]);
|
---|
740 | thread_ready(thread);
|
---|
741 | thread_join(thread);
|
---|
742 | thread_detach(thread);
|
---|
743 | } else
|
---|
744 | printf("Unable to create thread for cpu%u\n", i);
|
---|
745 | }
|
---|
746 |
|
---|
747 | return 1;
|
---|
748 | }
|
---|
749 |
|
---|
750 | /** Call function with one parameter */
|
---|
751 | int cmd_call1(cmd_arg_t *argv)
|
---|
752 | {
|
---|
753 | uintptr_t symaddr;
|
---|
754 | char *symbol;
|
---|
755 | sysarg_t (*fnc)(sysarg_t, ...);
|
---|
756 | sysarg_t arg1 = argv[1].intval;
|
---|
757 | fncptr_t fptr;
|
---|
758 | int rc;
|
---|
759 |
|
---|
760 | symbol = (char *) argv->buffer;
|
---|
761 | rc = symtab_addr_lookup(symbol, &symaddr);
|
---|
762 |
|
---|
763 | if (rc == ENOENT) {
|
---|
764 | printf("Symbol %s not found.\n", symbol);
|
---|
765 | } else if (rc == EOVERFLOW) {
|
---|
766 | symtab_print_search(symbol);
|
---|
767 | printf("Duplicate symbol, be more specific.\n");
|
---|
768 | } else if (rc == EOK) {
|
---|
769 | ipl_t ipl;
|
---|
770 |
|
---|
771 | ipl = interrupts_disable();
|
---|
772 | fnc = (sysarg_t (*)(sysarg_t, ...))
|
---|
773 | arch_construct_function(&fptr, (void *) symaddr,
|
---|
774 | (void *) cmd_call1);
|
---|
775 | printf("Calling f(%#" PRIxn "): %p: %s\n", arg1,
|
---|
776 | (void *) symaddr, symbol);
|
---|
777 | printf("Result: %#" PRIxn "\n", fnc(arg1));
|
---|
778 | interrupts_restore(ipl);
|
---|
779 | } else {
|
---|
780 | printf("No symbol information available.\n");
|
---|
781 | }
|
---|
782 |
|
---|
783 | return 1;
|
---|
784 | }
|
---|
785 |
|
---|
786 | /** Call function with two parameters */
|
---|
787 | int cmd_call2(cmd_arg_t *argv)
|
---|
788 | {
|
---|
789 | uintptr_t symaddr;
|
---|
790 | char *symbol;
|
---|
791 | sysarg_t (*fnc)(sysarg_t, sysarg_t, ...);
|
---|
792 | sysarg_t arg1 = argv[1].intval;
|
---|
793 | sysarg_t arg2 = argv[2].intval;
|
---|
794 | fncptr_t fptr;
|
---|
795 | int rc;
|
---|
796 |
|
---|
797 | symbol = (char *) argv->buffer;
|
---|
798 | rc = symtab_addr_lookup(symbol, &symaddr);
|
---|
799 |
|
---|
800 | if (rc == ENOENT) {
|
---|
801 | printf("Symbol %s not found.\n", symbol);
|
---|
802 | } else if (rc == EOVERFLOW) {
|
---|
803 | symtab_print_search(symbol);
|
---|
804 | printf("Duplicate symbol, be more specific.\n");
|
---|
805 | } else if (rc == EOK) {
|
---|
806 | ipl_t ipl;
|
---|
807 |
|
---|
808 | ipl = interrupts_disable();
|
---|
809 | fnc = (sysarg_t (*)(sysarg_t, sysarg_t, ...))
|
---|
810 | arch_construct_function(&fptr, (void *) symaddr,
|
---|
811 | (void *) cmd_call2);
|
---|
812 | printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n",
|
---|
813 | arg1, arg2, (void *) symaddr, symbol);
|
---|
814 | printf("Result: %#" PRIxn "\n", fnc(arg1, arg2));
|
---|
815 | interrupts_restore(ipl);
|
---|
816 | } else {
|
---|
817 | printf("No symbol information available.\n");
|
---|
818 | }
|
---|
819 | return 1;
|
---|
820 | }
|
---|
821 |
|
---|
822 | /** Call function with three parameters */
|
---|
823 | int cmd_call3(cmd_arg_t *argv)
|
---|
824 | {
|
---|
825 | uintptr_t symaddr;
|
---|
826 | char *symbol;
|
---|
827 | sysarg_t (*fnc)(sysarg_t, sysarg_t, sysarg_t, ...);
|
---|
828 | sysarg_t arg1 = argv[1].intval;
|
---|
829 | sysarg_t arg2 = argv[2].intval;
|
---|
830 | sysarg_t arg3 = argv[3].intval;
|
---|
831 | fncptr_t fptr;
|
---|
832 | int rc;
|
---|
833 |
|
---|
834 | symbol = (char *) argv->buffer;
|
---|
835 | rc = symtab_addr_lookup(symbol, &symaddr);
|
---|
836 |
|
---|
837 | if (rc == ENOENT) {
|
---|
838 | printf("Symbol %s not found.\n", symbol);
|
---|
839 | } else if (rc == EOVERFLOW) {
|
---|
840 | symtab_print_search(symbol);
|
---|
841 | printf("Duplicate symbol, be more specific.\n");
|
---|
842 | } else if (rc == EOK) {
|
---|
843 | ipl_t ipl;
|
---|
844 |
|
---|
845 | ipl = interrupts_disable();
|
---|
846 | fnc = (sysarg_t (*)(sysarg_t, sysarg_t, sysarg_t, ...))
|
---|
847 | arch_construct_function(&fptr, (void *) symaddr,
|
---|
848 | (void *) cmd_call3);
|
---|
849 | printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n",
|
---|
850 | arg1, arg2, arg3, (void *) symaddr, symbol);
|
---|
851 | printf("Result: %#" PRIxn "\n", fnc(arg1, arg2, arg3));
|
---|
852 | interrupts_restore(ipl);
|
---|
853 | } else {
|
---|
854 | printf("No symbol information available.\n");
|
---|
855 | }
|
---|
856 | return 1;
|
---|
857 | }
|
---|
858 |
|
---|
859 | /** Print detailed description of 'describe' command. */
|
---|
860 | void desc_help(void)
|
---|
861 | {
|
---|
862 | printf("Syntax: describe command_name\n");
|
---|
863 | }
|
---|
864 |
|
---|
865 | /** Halt the kernel.
|
---|
866 | *
|
---|
867 | * @param argv Argument vector (ignored).
|
---|
868 | *
|
---|
869 | * @return 0 on failure, 1 on success (never returns).
|
---|
870 | */
|
---|
871 | int cmd_halt(cmd_arg_t *argv)
|
---|
872 | {
|
---|
873 | halt();
|
---|
874 | return 1;
|
---|
875 | }
|
---|
876 |
|
---|
877 | /** Command for printing TLB contents.
|
---|
878 | *
|
---|
879 | * @param argv Not used.
|
---|
880 | *
|
---|
881 | * @return Always returns 1.
|
---|
882 | */
|
---|
883 | int cmd_tlb(cmd_arg_t *argv)
|
---|
884 | {
|
---|
885 | tlb_print();
|
---|
886 | return 1;
|
---|
887 | }
|
---|
888 |
|
---|
889 | /** Command for printing physical memory configuration.
|
---|
890 | *
|
---|
891 | * @param argv Not used.
|
---|
892 | *
|
---|
893 | * @return Always returns 1.
|
---|
894 | */
|
---|
895 | int cmd_physmem(cmd_arg_t *argv)
|
---|
896 | {
|
---|
897 | physmem_print();
|
---|
898 | return 1;
|
---|
899 | }
|
---|
900 |
|
---|
901 | /** Write 4 byte value to address */
|
---|
902 | int cmd_set4(cmd_arg_t *argv)
|
---|
903 | {
|
---|
904 | uintptr_t addr;
|
---|
905 | uint32_t arg1 = argv[1].intval;
|
---|
906 | bool pointer = false;
|
---|
907 | int rc;
|
---|
908 |
|
---|
909 | if (((char *) argv->buffer)[0] == '*') {
|
---|
910 | rc = symtab_addr_lookup((char *) argv->buffer + 1, &addr);
|
---|
911 | pointer = true;
|
---|
912 | } else if (((char *) argv->buffer)[0] >= '0' &&
|
---|
913 | ((char *) argv->buffer)[0] <= '9') {
|
---|
914 | uint64_t value;
|
---|
915 | rc = str_uint64_t((char *) argv->buffer, NULL, 0, true, &value);
|
---|
916 | if (rc == EOK)
|
---|
917 | addr = (uintptr_t) value;
|
---|
918 | } else
|
---|
919 | rc = symtab_addr_lookup((char *) argv->buffer, &addr);
|
---|
920 |
|
---|
921 | if (rc == ENOENT)
|
---|
922 | printf("Symbol %s not found.\n", (char *) argv->buffer);
|
---|
923 | else if (rc == EINVAL)
|
---|
924 | printf("Invalid address.\n");
|
---|
925 | else if (rc == EOVERFLOW) {
|
---|
926 | symtab_print_search((char *) argv->buffer);
|
---|
927 | printf("Duplicate symbol (be more specific) or address overflow.\n");
|
---|
928 | } else if (rc == EOK) {
|
---|
929 | if (pointer)
|
---|
930 | addr = *(uintptr_t *) addr;
|
---|
931 | printf("Writing %#" PRIx32" -> %p\n", arg1, (void *) addr);
|
---|
932 | *(uint32_t *) addr = arg1;
|
---|
933 | } else
|
---|
934 | printf("No symbol information available.\n");
|
---|
935 |
|
---|
936 | return 1;
|
---|
937 | }
|
---|
938 |
|
---|
939 | /** Command for listings SLAB caches
|
---|
940 | *
|
---|
941 | * @param argv Ignores
|
---|
942 | *
|
---|
943 | * @return Always 1
|
---|
944 | */
|
---|
945 | int cmd_slabs(cmd_arg_t *argv)
|
---|
946 | {
|
---|
947 | slab_print_list();
|
---|
948 | return 1;
|
---|
949 | }
|
---|
950 |
|
---|
951 | /** Command for dumping sysinfo
|
---|
952 | *
|
---|
953 | * @param argv Ignores
|
---|
954 | *
|
---|
955 | * @return Always 1
|
---|
956 | */
|
---|
957 | int cmd_sysinfo(cmd_arg_t *argv)
|
---|
958 | {
|
---|
959 | sysinfo_dump(NULL);
|
---|
960 | return 1;
|
---|
961 | }
|
---|
962 |
|
---|
963 | /** Command for listing thread information
|
---|
964 | *
|
---|
965 | * @param argv Ignored
|
---|
966 | *
|
---|
967 | * @return Always 1
|
---|
968 | */
|
---|
969 | int cmd_threads(cmd_arg_t *argv)
|
---|
970 | {
|
---|
971 | if (str_cmp(flag_buf, "-a") == 0)
|
---|
972 | thread_print_list(true);
|
---|
973 | else if (str_cmp(flag_buf, "") == 0)
|
---|
974 | thread_print_list(false);
|
---|
975 | else
|
---|
976 | printf("Unknown argument \"%s\".\n", flag_buf);
|
---|
977 |
|
---|
978 | return 1;
|
---|
979 | }
|
---|
980 |
|
---|
981 | /** Command for listing task information
|
---|
982 | *
|
---|
983 | * @param argv Ignored
|
---|
984 | *
|
---|
985 | * @return Always 1
|
---|
986 | */
|
---|
987 | int cmd_tasks(cmd_arg_t *argv)
|
---|
988 | {
|
---|
989 | if (str_cmp(flag_buf, "-a") == 0)
|
---|
990 | task_print_list(true);
|
---|
991 | else if (str_cmp(flag_buf, "") == 0)
|
---|
992 | task_print_list(false);
|
---|
993 | else
|
---|
994 | printf("Unknown argument \"%s\".\n", flag_buf);
|
---|
995 |
|
---|
996 | return 1;
|
---|
997 | }
|
---|
998 |
|
---|
999 | #ifdef CONFIG_UDEBUG
|
---|
1000 |
|
---|
1001 | /** Command for printing thread stack trace
|
---|
1002 | *
|
---|
1003 | * @param argv Integer argument from cmdline expected
|
---|
1004 | *
|
---|
1005 | * return Always 1
|
---|
1006 | *
|
---|
1007 | */
|
---|
1008 | int cmd_btrace(cmd_arg_t *argv)
|
---|
1009 | {
|
---|
1010 | thread_stack_trace(argv[0].intval);
|
---|
1011 | return 1;
|
---|
1012 | }
|
---|
1013 |
|
---|
1014 | #endif /* CONFIG_UDEBUG */
|
---|
1015 |
|
---|
1016 | /** Command for printing scheduler information
|
---|
1017 | *
|
---|
1018 | * @param argv Ignores
|
---|
1019 | *
|
---|
1020 | * @return Always 1
|
---|
1021 | */
|
---|
1022 | int cmd_sched(cmd_arg_t *argv)
|
---|
1023 | {
|
---|
1024 | sched_print_list();
|
---|
1025 | return 1;
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | /** Prints information about the global work queue.
|
---|
1029 | *
|
---|
1030 | * @param argv Ignores
|
---|
1031 | *
|
---|
1032 | * @return Always 1
|
---|
1033 | */
|
---|
1034 | int cmd_workq(cmd_arg_t *argv)
|
---|
1035 | {
|
---|
1036 | workq_global_print_info();
|
---|
1037 | return 1;
|
---|
1038 | }
|
---|
1039 |
|
---|
1040 |
|
---|
1041 | /** Command for listing memory zones
|
---|
1042 | *
|
---|
1043 | * @param argv Ignored
|
---|
1044 | *
|
---|
1045 | * return Always 1
|
---|
1046 | */
|
---|
1047 | int cmd_zones(cmd_arg_t *argv)
|
---|
1048 | {
|
---|
1049 | zones_print_list();
|
---|
1050 | return 1;
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | /** Command for memory zone details
|
---|
1054 | *
|
---|
1055 | * @param argv Integer argument from cmdline expected
|
---|
1056 | *
|
---|
1057 | * return Always 1
|
---|
1058 | */
|
---|
1059 | int cmd_zone(cmd_arg_t *argv)
|
---|
1060 | {
|
---|
1061 | zone_print_one(argv[0].intval);
|
---|
1062 | return 1;
|
---|
1063 | }
|
---|
1064 |
|
---|
1065 | /** Command for printing task IPC details
|
---|
1066 | *
|
---|
1067 | * @param argv Integer argument from cmdline expected
|
---|
1068 | *
|
---|
1069 | * return Always 1
|
---|
1070 | */
|
---|
1071 | int cmd_ipc(cmd_arg_t *argv)
|
---|
1072 | {
|
---|
1073 | ipc_print_task(argv[0].intval);
|
---|
1074 | return 1;
|
---|
1075 | }
|
---|
1076 |
|
---|
1077 | /** Command for killing a task
|
---|
1078 | *
|
---|
1079 | * @param argv Integer argument from cmdline expected
|
---|
1080 | *
|
---|
1081 | * return 0 on failure, 1 on success.
|
---|
1082 | */
|
---|
1083 | int cmd_kill(cmd_arg_t *argv)
|
---|
1084 | {
|
---|
1085 | if (task_kill(argv[0].intval) != EOK)
|
---|
1086 | return 0;
|
---|
1087 |
|
---|
1088 | return 1;
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 | /** Command for listing processors.
|
---|
1092 | *
|
---|
1093 | * @param argv Ignored.
|
---|
1094 | *
|
---|
1095 | * return Always 1.
|
---|
1096 | */
|
---|
1097 | int cmd_cpus(cmd_arg_t *argv)
|
---|
1098 | {
|
---|
1099 | cpu_list();
|
---|
1100 | return 1;
|
---|
1101 | }
|
---|
1102 |
|
---|
1103 | /** Command for printing kernel version.
|
---|
1104 | *
|
---|
1105 | * @param argv Ignored.
|
---|
1106 | *
|
---|
1107 | * return Always 1.
|
---|
1108 | */
|
---|
1109 | int cmd_version(cmd_arg_t *argv)
|
---|
1110 | {
|
---|
1111 | version_print();
|
---|
1112 | return 1;
|
---|
1113 | }
|
---|
1114 |
|
---|
1115 | /** Command for returning console back to userspace.
|
---|
1116 | *
|
---|
1117 | * @param argv Ignored.
|
---|
1118 | *
|
---|
1119 | * return Always 1.
|
---|
1120 | */
|
---|
1121 | int cmd_continue(cmd_arg_t *argv)
|
---|
1122 | {
|
---|
1123 | printf("The kernel will now relinquish the console.\n");
|
---|
1124 | release_console();
|
---|
1125 |
|
---|
1126 | event_notify_0(EVENT_KCONSOLE, false);
|
---|
1127 | indev_pop_character(stdin);
|
---|
1128 |
|
---|
1129 | return 1;
|
---|
1130 | }
|
---|
1131 |
|
---|
1132 | #ifdef CONFIG_TEST
|
---|
1133 | static bool run_test(const test_t *test)
|
---|
1134 | {
|
---|
1135 | printf("%s (%s)\n", test->name, test->desc);
|
---|
1136 |
|
---|
1137 | /* Update and read thread accounting
|
---|
1138 | for benchmarking */
|
---|
1139 | irq_spinlock_lock(&TASK->lock, true);
|
---|
1140 | uint64_t ucycles0, kcycles0;
|
---|
1141 | task_get_accounting(TASK, &ucycles0, &kcycles0);
|
---|
1142 | irq_spinlock_unlock(&TASK->lock, true);
|
---|
1143 |
|
---|
1144 | /* Execute the test */
|
---|
1145 | test_quiet = false;
|
---|
1146 | const char *ret = test->entry();
|
---|
1147 |
|
---|
1148 | /* Update and read thread accounting */
|
---|
1149 | uint64_t ucycles1, kcycles1;
|
---|
1150 | irq_spinlock_lock(&TASK->lock, true);
|
---|
1151 | task_get_accounting(TASK, &ucycles1, &kcycles1);
|
---|
1152 | irq_spinlock_unlock(&TASK->lock, true);
|
---|
1153 |
|
---|
1154 | uint64_t ucycles, kcycles;
|
---|
1155 | char usuffix, ksuffix;
|
---|
1156 | order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix);
|
---|
1157 | order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix);
|
---|
1158 |
|
---|
1159 | printf("Time: %" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles\n",
|
---|
1160 | ucycles, usuffix, kcycles, ksuffix);
|
---|
1161 |
|
---|
1162 | if (ret == NULL) {
|
---|
1163 | printf("Test passed\n");
|
---|
1164 | return true;
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 | printf("%s\n", ret);
|
---|
1168 | return false;
|
---|
1169 | }
|
---|
1170 |
|
---|
1171 | static bool run_bench(const test_t *test, const uint32_t cnt)
|
---|
1172 | {
|
---|
1173 | uint32_t i;
|
---|
1174 | bool ret = true;
|
---|
1175 | uint64_t ucycles, kcycles;
|
---|
1176 | char usuffix, ksuffix;
|
---|
1177 |
|
---|
1178 | if (cnt < 1)
|
---|
1179 | return true;
|
---|
1180 |
|
---|
1181 | uint64_t *data = (uint64_t *) malloc(sizeof(uint64_t) * cnt, 0);
|
---|
1182 | if (data == NULL) {
|
---|
1183 | printf("Error allocating memory for statistics\n");
|
---|
1184 | return false;
|
---|
1185 | }
|
---|
1186 |
|
---|
1187 | for (i = 0; i < cnt; i++) {
|
---|
1188 | printf("%s (%u/%u) ... ", test->name, i + 1, cnt);
|
---|
1189 |
|
---|
1190 | /* Update and read thread accounting
|
---|
1191 | for benchmarking */
|
---|
1192 | irq_spinlock_lock(&TASK->lock, true);
|
---|
1193 | uint64_t ucycles0, kcycles0;
|
---|
1194 | task_get_accounting(TASK, &ucycles0, &kcycles0);
|
---|
1195 | irq_spinlock_unlock(&TASK->lock, true);
|
---|
1196 |
|
---|
1197 | /* Execute the test */
|
---|
1198 | test_quiet = true;
|
---|
1199 | const char *test_ret = test->entry();
|
---|
1200 |
|
---|
1201 | /* Update and read thread accounting */
|
---|
1202 | irq_spinlock_lock(&TASK->lock, true);
|
---|
1203 | uint64_t ucycles1, kcycles1;
|
---|
1204 | task_get_accounting(TASK, &ucycles1, &kcycles1);
|
---|
1205 | irq_spinlock_unlock(&TASK->lock, true);
|
---|
1206 |
|
---|
1207 | if (test_ret != NULL) {
|
---|
1208 | printf("%s\n", test_ret);
|
---|
1209 | ret = false;
|
---|
1210 | break;
|
---|
1211 | }
|
---|
1212 |
|
---|
1213 | data[i] = ucycles1 - ucycles0 + kcycles1 - kcycles0;
|
---|
1214 | order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix);
|
---|
1215 | order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix);
|
---|
1216 | printf("OK (%" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles)\n",
|
---|
1217 | ucycles, usuffix, kcycles, ksuffix);
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | if (ret) {
|
---|
1221 | printf("\n");
|
---|
1222 |
|
---|
1223 | uint64_t sum = 0;
|
---|
1224 |
|
---|
1225 | for (i = 0; i < cnt; i++) {
|
---|
1226 | sum += data[i];
|
---|
1227 | }
|
---|
1228 |
|
---|
1229 | order_suffix(sum / (uint64_t) cnt, &ucycles, &usuffix);
|
---|
1230 | printf("Average\t\t%" PRIu64 "%c\n", ucycles, usuffix);
|
---|
1231 | }
|
---|
1232 |
|
---|
1233 | free(data);
|
---|
1234 |
|
---|
1235 | return ret;
|
---|
1236 | }
|
---|
1237 |
|
---|
1238 | static void list_tests(void)
|
---|
1239 | {
|
---|
1240 | size_t len = 0;
|
---|
1241 | test_t *test;
|
---|
1242 |
|
---|
1243 | for (test = tests; test->name != NULL; test++) {
|
---|
1244 | if (str_length(test->name) > len)
|
---|
1245 | len = str_length(test->name);
|
---|
1246 | }
|
---|
1247 |
|
---|
1248 | unsigned int _len = (unsigned int) len;
|
---|
1249 | if ((_len != len) || (((int) _len) < 0)) {
|
---|
1250 | printf("Command length overflow\n");
|
---|
1251 | return;
|
---|
1252 | }
|
---|
1253 |
|
---|
1254 | for (test = tests; test->name != NULL; test++)
|
---|
1255 | printf("%-*s %s%s\n", _len, test->name, test->desc,
|
---|
1256 | (test->safe ? "" : " (unsafe)"));
|
---|
1257 |
|
---|
1258 | printf("%-*s Run all safe tests\n", _len, "*");
|
---|
1259 | }
|
---|
1260 |
|
---|
1261 | /** Command for listing and running kernel tests
|
---|
1262 | *
|
---|
1263 | * @param argv Argument vector.
|
---|
1264 | *
|
---|
1265 | * return Always 1.
|
---|
1266 | *
|
---|
1267 | */
|
---|
1268 | int cmd_test(cmd_arg_t *argv)
|
---|
1269 | {
|
---|
1270 | test_t *test;
|
---|
1271 |
|
---|
1272 | if (str_cmp((char *) argv->buffer, "*") == 0) {
|
---|
1273 | for (test = tests; test->name != NULL; test++) {
|
---|
1274 | if (test->safe) {
|
---|
1275 | printf("\n");
|
---|
1276 | if (!run_test(test))
|
---|
1277 | break;
|
---|
1278 | }
|
---|
1279 | }
|
---|
1280 | } else if (str_cmp((char *) argv->buffer, "") != 0) {
|
---|
1281 | bool fnd = false;
|
---|
1282 |
|
---|
1283 | for (test = tests; test->name != NULL; test++) {
|
---|
1284 | if (str_cmp(test->name, (char *) argv->buffer) == 0) {
|
---|
1285 | fnd = true;
|
---|
1286 | run_test(test);
|
---|
1287 | break;
|
---|
1288 | }
|
---|
1289 | }
|
---|
1290 |
|
---|
1291 | if (!fnd)
|
---|
1292 | printf("Unknown test\n");
|
---|
1293 | } else
|
---|
1294 | list_tests();
|
---|
1295 |
|
---|
1296 | return 1;
|
---|
1297 | }
|
---|
1298 |
|
---|
1299 | /** Command for returning kernel tests as benchmarks
|
---|
1300 | *
|
---|
1301 | * @param argv Argument vector.
|
---|
1302 | *
|
---|
1303 | * return Always 1.
|
---|
1304 | */
|
---|
1305 | int cmd_bench(cmd_arg_t *argv)
|
---|
1306 | {
|
---|
1307 | test_t *test;
|
---|
1308 | uint32_t cnt = argv[1].intval;
|
---|
1309 |
|
---|
1310 | if (str_cmp((char *) argv->buffer, "*") == 0) {
|
---|
1311 | for (test = tests; test->name != NULL; test++) {
|
---|
1312 | if (test->safe) {
|
---|
1313 | if (!run_bench(test, cnt))
|
---|
1314 | break;
|
---|
1315 | }
|
---|
1316 | }
|
---|
1317 | } else {
|
---|
1318 | bool fnd = false;
|
---|
1319 |
|
---|
1320 | for (test = tests; test->name != NULL; test++) {
|
---|
1321 | if (str_cmp(test->name, (char *) argv->buffer) == 0) {
|
---|
1322 | fnd = true;
|
---|
1323 |
|
---|
1324 | if (test->safe)
|
---|
1325 | run_bench(test, cnt);
|
---|
1326 | else
|
---|
1327 | printf("Unsafe test\n");
|
---|
1328 |
|
---|
1329 | break;
|
---|
1330 | }
|
---|
1331 | }
|
---|
1332 |
|
---|
1333 | if (!fnd)
|
---|
1334 | printf("Unknown test\n");
|
---|
1335 | }
|
---|
1336 |
|
---|
1337 | return 1;
|
---|
1338 | }
|
---|
1339 |
|
---|
1340 | #endif
|
---|
1341 |
|
---|
1342 | /** @}
|
---|
1343 | */
|
---|