Subversion Repositories HelenOS

Rev

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

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