Subversion Repositories HelenOS

Rev

Rev 4346 | Rev 4348 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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