Subversion Repositories HelenOS

Rev

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

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