Subversion Repositories HelenOS

Rev

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

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