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