Subversion Repositories HelenOS

Rev

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

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