Subversion Repositories HelenOS

Rev

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

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