Subversion Repositories HelenOS

Rev

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

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