Subversion Repositories HelenOS-historic

Rev

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

Rev 788 Rev 1053
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
/**
29
/**
30
 * This file is meant to contain all wrapper functions for
30
 * This file is meant to contain all wrapper functions for
31
 * all kconsole commands. The point is in separating
31
 * all kconsole commands. The point is in separating
32
 * kconsole specific wrappers from kconsole-unaware functions
32
 * kconsole specific wrappers from kconsole-unaware functions
33
 * from other subsystems.
33
 * from other subsystems.
34
 */
34
 */
35
 
35
 
36
#include <console/cmd.h>
36
#include <console/cmd.h>
37
#include <console/kconsole.h>
37
#include <console/kconsole.h>
38
#include <print.h>
38
#include <print.h>
39
#include <panic.h>
39
#include <panic.h>
40
#include <typedefs.h>
40
#include <typedefs.h>
41
#include <arch/types.h>
41
#include <arch/types.h>
42
#include <adt/list.h>
42
#include <adt/list.h>
43
#include <arch.h>
43
#include <arch.h>
44
#include <func.h>
44
#include <func.h>
45
#include <macros.h>
45
#include <macros.h>
46
#include <debug.h>
46
#include <debug.h>
47
#include <symtab.h>
47
#include <symtab.h>
48
#include <cpu.h>
48
#include <cpu.h>
49
#include <mm/tlb.h>
49
#include <mm/tlb.h>
50
#include <arch/mm/tlb.h>
50
#include <arch/mm/tlb.h>
51
#include <mm/frame.h>
51
#include <mm/frame.h>
52
#include <main/version.h>
52
#include <main/version.h>
53
#include <mm/slab.h>
53
#include <mm/slab.h>
54
#include <proc/scheduler.h>
54
#include <proc/scheduler.h>
55
#include <proc/thread.h>
55
#include <proc/thread.h>
56
 
56
 
57
/** Data and methods for 'help' command. */
57
/** Data and methods for 'help' command. */
58
static int cmd_help(cmd_arg_t *argv);
58
static int cmd_help(cmd_arg_t *argv);
59
static cmd_info_t help_info = {
59
static cmd_info_t help_info = {
60
    .name = "help",
60
    .name = "help",
61
    .description = "List of supported commands.",
61
    .description = "List of supported commands.",
62
    .func = cmd_help,
62
    .func = cmd_help,
63
    .argc = 0
63
    .argc = 0
64
};
64
};
65
 
65
 
66
static cmd_info_t exit_info = {
66
static cmd_info_t exit_info = {
67
    .name = "exit",
67
    .name = "exit",
68
    .description ="Exit kconsole",
68
    .description ="Exit kconsole",
69
    .argc = 0
69
    .argc = 0
70
};
70
};
71
 
71
 
72
/** Data and methods for 'description' command. */
72
/** Data and methods for 'description' command. */
73
static int cmd_desc(cmd_arg_t *argv);
73
static int cmd_desc(cmd_arg_t *argv);
74
static void desc_help(void);
74
static void desc_help(void);
75
static char desc_buf[MAX_CMDLINE+1];
75
static char desc_buf[MAX_CMDLINE+1];
76
static cmd_arg_t desc_argv = {
76
static cmd_arg_t desc_argv = {
77
    .type = ARG_TYPE_STRING,
77
    .type = ARG_TYPE_STRING,
78
    .buffer = desc_buf,
78
    .buffer = desc_buf,
79
    .len = sizeof(desc_buf)
79
    .len = sizeof(desc_buf)
80
};
80
};
81
static cmd_info_t desc_info = {
81
static cmd_info_t desc_info = {
82
    .name = "describe",
82
    .name = "describe",
83
    .description = "Describe specified command.",
83
    .description = "Describe specified command.",
84
    .help = desc_help,
84
    .help = desc_help,
85
    .func = cmd_desc,
85
    .func = cmd_desc,
86
    .argc = 1,
86
    .argc = 1,
87
    .argv = &desc_argv
87
    .argv = &desc_argv
88
};
88
};
89
 
89
 
90
/** Data and methods for 'symaddr' command. */
90
/** Data and methods for 'symaddr' command. */
91
static int cmd_symaddr(cmd_arg_t *argv);
91
static int cmd_symaddr(cmd_arg_t *argv);
92
static char symaddr_buf[MAX_CMDLINE+1];
92
static char symaddr_buf[MAX_CMDLINE+1];
93
static cmd_arg_t symaddr_argv = {
93
static cmd_arg_t symaddr_argv = {
94
    .type = ARG_TYPE_STRING,
94
    .type = ARG_TYPE_STRING,
95
    .buffer = symaddr_buf,
95
    .buffer = symaddr_buf,
96
    .len = sizeof(symaddr_buf)
96
    .len = sizeof(symaddr_buf)
97
};
97
};
98
static cmd_info_t symaddr_info = {
98
static cmd_info_t symaddr_info = {
99
    .name = "symaddr",
99
    .name = "symaddr",
100
    .description = "Return symbol address.",
100
    .description = "Return symbol address.",
101
    .func = cmd_symaddr,
101
    .func = cmd_symaddr,
102
    .argc = 1,
102
    .argc = 1,
103
    .argv = &symaddr_argv
103
    .argv = &symaddr_argv
104
};
104
};
105
 
105
 
106
static char set_buf[MAX_CMDLINE+1];
106
static char set_buf[MAX_CMDLINE+1];
107
static int cmd_set4(cmd_arg_t *argv);
107
static int cmd_set4(cmd_arg_t *argv);
108
static cmd_arg_t set4_argv[] = {
108
static cmd_arg_t set4_argv[] = {
109
    {
109
    {
110
        .type = ARG_TYPE_STRING,
110
        .type = ARG_TYPE_STRING,
111
        .buffer = set_buf,
111
        .buffer = set_buf,
112
        .len = sizeof(set_buf)
112
        .len = sizeof(set_buf)
113
    },
113
    },
114
    {
114
    {
115
        .type = ARG_TYPE_INT
115
        .type = ARG_TYPE_INT
116
    }
116
    }
117
};
117
};
118
static cmd_info_t set4_info = {
118
static cmd_info_t set4_info = {
119
    .name = "set4",
119
    .name = "set4",
120
    .description = "set <dest_addr> <value> - 4byte version",
120
    .description = "set <dest_addr> <value> - 4byte version",
121
    .func = cmd_set4,
121
    .func = cmd_set4,
122
    .argc = 2,
122
    .argc = 2,
123
    .argv = set4_argv
123
    .argv = set4_argv
124
};
124
};
125
 
125
 
126
/** Data and methods for 'call0' command. */
126
/** Data and methods for 'call0' command. */
127
static char call0_buf[MAX_CMDLINE+1];
127
static char call0_buf[MAX_CMDLINE+1];
128
static char carg1_buf[MAX_CMDLINE+1];
128
static char carg1_buf[MAX_CMDLINE+1];
129
static char carg2_buf[MAX_CMDLINE+1];
129
static char carg2_buf[MAX_CMDLINE+1];
130
static char carg3_buf[MAX_CMDLINE+1];
130
static char carg3_buf[MAX_CMDLINE+1];
131
 
131
 
132
static int cmd_call0(cmd_arg_t *argv);
132
static int cmd_call0(cmd_arg_t *argv);
133
static cmd_arg_t call0_argv = {
133
static cmd_arg_t call0_argv = {
134
    .type = ARG_TYPE_STRING,
134
    .type = ARG_TYPE_STRING,
135
    .buffer = call0_buf,
135
    .buffer = call0_buf,
136
    .len = sizeof(call0_buf)
136
    .len = sizeof(call0_buf)
137
};
137
};
138
static cmd_info_t call0_info = {
138
static cmd_info_t call0_info = {
139
    .name = "call0",
139
    .name = "call0",
140
    .description = "call0 <function> -> call function().",
140
    .description = "call0 <function> -> call function().",
141
    .func = cmd_call0,
141
    .func = cmd_call0,
142
    .argc = 1,
142
    .argc = 1,
143
    .argv = &call0_argv
143
    .argv = &call0_argv
144
};
144
};
145
 
145
 
146
/** Data and methods for 'call1' command. */
146
/** Data and methods for 'call1' command. */
147
static int cmd_call1(cmd_arg_t *argv);
147
static int cmd_call1(cmd_arg_t *argv);
148
static cmd_arg_t call1_argv[] = {
148
static cmd_arg_t call1_argv[] = {
149
    {
149
    {
150
        .type = ARG_TYPE_STRING,
150
        .type = ARG_TYPE_STRING,
151
        .buffer = call0_buf,
151
        .buffer = call0_buf,
152
        .len = sizeof(call0_buf)
152
        .len = sizeof(call0_buf)
153
    },
153
    },
154
    {
154
    {
155
        .type = ARG_TYPE_VAR,
155
        .type = ARG_TYPE_VAR,
156
        .buffer = carg1_buf,
156
        .buffer = carg1_buf,
157
        .len = sizeof(carg1_buf)
157
        .len = sizeof(carg1_buf)
158
    }
158
    }
159
};
159
};
160
static cmd_info_t call1_info = {
160
static cmd_info_t call1_info = {
161
    .name = "call1",
161
    .name = "call1",
162
    .description = "call1 <function> <arg1> -> call function(arg1).",
162
    .description = "call1 <function> <arg1> -> call function(arg1).",
163
    .func = cmd_call1,
163
    .func = cmd_call1,
164
    .argc = 2,
164
    .argc = 2,
165
    .argv = call1_argv
165
    .argv = call1_argv
166
};
166
};
167
 
167
 
168
/** Data and methods for 'call2' command. */
168
/** Data and methods for 'call2' command. */
169
static int cmd_call2(cmd_arg_t *argv);
169
static int cmd_call2(cmd_arg_t *argv);
170
static cmd_arg_t call2_argv[] = {
170
static cmd_arg_t call2_argv[] = {
171
    {
171
    {
172
        .type = ARG_TYPE_STRING,
172
        .type = ARG_TYPE_STRING,
173
        .buffer = call0_buf,
173
        .buffer = call0_buf,
174
        .len = sizeof(call0_buf)
174
        .len = sizeof(call0_buf)
175
    },
175
    },
176
    {
176
    {
177
        .type = ARG_TYPE_VAR,
177
        .type = ARG_TYPE_VAR,
178
        .buffer = carg1_buf,
178
        .buffer = carg1_buf,
179
        .len = sizeof(carg1_buf)
179
        .len = sizeof(carg1_buf)
180
    },
180
    },
181
    {
181
    {
182
        .type = ARG_TYPE_VAR,
182
        .type = ARG_TYPE_VAR,
183
        .buffer = carg2_buf,
183
        .buffer = carg2_buf,
184
        .len = sizeof(carg2_buf)
184
        .len = sizeof(carg2_buf)
185
    }
185
    }
186
};
186
};
187
static cmd_info_t call2_info = {
187
static cmd_info_t call2_info = {
188
    .name = "call2",
188
    .name = "call2",
189
    .description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).",
189
    .description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).",
190
    .func = cmd_call2,
190
    .func = cmd_call2,
191
    .argc = 3,
191
    .argc = 3,
192
    .argv = call2_argv
192
    .argv = call2_argv
193
};
193
};
194
 
194
 
195
/** Data and methods for 'call3' command. */
195
/** Data and methods for 'call3' command. */
196
static int cmd_call3(cmd_arg_t *argv);
196
static int cmd_call3(cmd_arg_t *argv);
197
static cmd_arg_t call3_argv[] = {
197
static cmd_arg_t call3_argv[] = {
198
    {
198
    {
199
        .type = ARG_TYPE_STRING,
199
        .type = ARG_TYPE_STRING,
200
        .buffer = call0_buf,
200
        .buffer = call0_buf,
201
        .len = sizeof(call0_buf)
201
        .len = sizeof(call0_buf)
202
    },
202
    },
203
    {
203
    {
204
        .type = ARG_TYPE_VAR,
204
        .type = ARG_TYPE_VAR,
205
        .buffer = carg1_buf,
205
        .buffer = carg1_buf,
206
        .len = sizeof(carg1_buf)
206
        .len = sizeof(carg1_buf)
207
    },
207
    },
208
    {
208
    {
209
        .type = ARG_TYPE_VAR,
209
        .type = ARG_TYPE_VAR,
210
        .buffer = carg2_buf,
210
        .buffer = carg2_buf,
211
        .len = sizeof(carg2_buf)
211
        .len = sizeof(carg2_buf)
212
    },
212
    },
213
    {
213
    {
214
        .type = ARG_TYPE_VAR,
214
        .type = ARG_TYPE_VAR,
215
        .buffer = carg3_buf,
215
        .buffer = carg3_buf,
216
        .len = sizeof(carg3_buf)
216
        .len = sizeof(carg3_buf)
217
    }
217
    }
218
 
218
 
219
};
219
};
220
static cmd_info_t call3_info = {
220
static cmd_info_t call3_info = {
221
    .name = "call3",
221
    .name = "call3",
222
    .description = "call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).",
222
    .description = "call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).",
223
    .func = cmd_call3,
223
    .func = cmd_call3,
224
    .argc = 4,
224
    .argc = 4,
225
    .argv = call3_argv
225
    .argv = call3_argv
226
};
226
};
227
 
227
 
228
/** Data and methods for 'halt' command. */
228
/** Data and methods for 'halt' command. */
229
static int cmd_halt(cmd_arg_t *argv);
229
static int cmd_halt(cmd_arg_t *argv);
230
static cmd_info_t halt_info = {
230
static cmd_info_t halt_info = {
231
    .name = "halt",
231
    .name = "halt",
232
    .description = "Halt the kernel.",
232
    .description = "Halt the kernel.",
233
    .func = cmd_halt,
233
    .func = cmd_halt,
234
    .argc = 0
234
    .argc = 0
235
};
235
};
236
 
236
 
237
/** Data and methods for 'tlb' command. */
237
/** Data and methods for 'tlb' command. */
238
static int cmd_tlb(cmd_arg_t *argv);
238
static int cmd_tlb(cmd_arg_t *argv);
239
cmd_info_t tlb_info = {
239
cmd_info_t tlb_info = {
240
    .name = "tlb",
240
    .name = "tlb",
241
    .description = "Print TLB of current processor.",
241
    .description = "Print TLB of current processor.",
242
    .help = NULL,
242
    .help = NULL,
243
    .func = cmd_tlb,
243
    .func = cmd_tlb,
244
    .argc = 0,
244
    .argc = 0,
245
    .argv = NULL
245
    .argv = NULL
246
};
246
};
247
 
247
 
248
static int cmd_threads(cmd_arg_t *argv);
248
static int cmd_threads(cmd_arg_t *argv);
249
static cmd_info_t threads_info = {
249
static cmd_info_t threads_info = {
250
    .name = "threads",
250
    .name = "threads",
251
    .description = "List all threads",
251
    .description = "List all threads",
252
    .func = cmd_threads,
252
    .func = cmd_threads,
253
    .argc = 0
253
    .argc = 0
254
};
254
};
255
 
255
 
256
 
256
 
257
static int cmd_sched(cmd_arg_t *argv);
257
static int cmd_sched(cmd_arg_t *argv);
258
static cmd_info_t sched_info = {
258
static cmd_info_t sched_info = {
259
    .name = "scheduler",
259
    .name = "scheduler",
260
    .description = "List all scheduler information",
260
    .description = "List all scheduler information",
261
    .func = cmd_sched,
261
    .func = cmd_sched,
262
    .argc = 0
262
    .argc = 0
263
};
263
};
264
 
264
 
265
static int cmd_slabs(cmd_arg_t *argv);
265
static int cmd_slabs(cmd_arg_t *argv);
266
static cmd_info_t slabs_info = {
266
static cmd_info_t slabs_info = {
267
    .name = "slabs",
267
    .name = "slabs",
268
    .description = "List SLAB caches.",
268
    .description = "List SLAB caches.",
269
    .func = cmd_slabs,
269
    .func = cmd_slabs,
270
    .argc = 0
270
    .argc = 0
271
};
271
};
272
 
272
 
273
/** Data and methods for 'zones' command */
273
/** Data and methods for 'zones' command */
274
static int cmd_zones(cmd_arg_t *argv);
274
static int cmd_zones(cmd_arg_t *argv);
275
static cmd_info_t zones_info = {
275
static cmd_info_t zones_info = {
276
    .name = "zones",
276
    .name = "zones",
277
    .description = "List of memory zones.",
277
    .description = "List of memory zones.",
278
    .func = cmd_zones,
278
    .func = cmd_zones,
279
    .argc = 0
279
    .argc = 0
280
};
280
};
281
 
281
 
282
/** Data and methods for 'zone' command */
282
/** Data and methods for 'zone' command */
283
static int cmd_zone(cmd_arg_t *argv);
283
static int cmd_zone(cmd_arg_t *argv);
284
static cmd_arg_t zone_argv = {
284
static cmd_arg_t zone_argv = {
285
    .type = ARG_TYPE_INT,
285
    .type = ARG_TYPE_INT,
286
};
286
};
287
 
287
 
288
static cmd_info_t zone_info = {
288
static cmd_info_t zone_info = {
289
    .name = "zone",
289
    .name = "zone",
290
    .description = "Show memory zone structure.",
290
    .description = "Show memory zone structure.",
291
    .func = cmd_zone,
291
    .func = cmd_zone,
292
    .argc = 1,
292
    .argc = 1,
293
    .argv = &zone_argv
293
    .argv = &zone_argv
294
};
294
};
295
 
295
 
-
 
296
static int cmd_hello(cmd_arg_t *argv);
-
 
297
static cmd_info_t hello_info = {
-
 
298
    .name = "hello",
-
 
299
    .description = "Hello Message",
-
 
300
    .func = cmd_hello,
-
 
301
    .argc = 0
-
 
302
};
-
 
303
 
296
/** Data and methods for 'cpus' command. */
304
/** Data and methods for 'cpus' command. */
297
static int cmd_cpus(cmd_arg_t *argv);
305
static int cmd_cpus(cmd_arg_t *argv);
298
cmd_info_t cpus_info = {
306
cmd_info_t cpus_info = {
299
    .name = "cpus",
307
    .name = "cpus",
300
    .description = "List all processors.",
308
    .description = "List all processors.",
301
    .help = NULL,
309
    .help = NULL,
302
    .func = cmd_cpus,
310
    .func = cmd_cpus,
303
    .argc = 0,
311
    .argc = 0,
304
    .argv = NULL
312
    .argv = NULL
305
};
313
};
306
 
314
 
307
/** Data and methods for 'version' command. */
315
/** Data and methods for 'version' command. */
308
static int cmd_version(cmd_arg_t *argv);
316
static int cmd_version(cmd_arg_t *argv);
309
cmd_info_t version_info = {
317
cmd_info_t version_info = {
310
    .name = "version",
318
    .name = "version",
311
    .description = "Print version information.",
319
    .description = "Print version information.",
312
    .help = NULL,
320
    .help = NULL,
313
    .func = cmd_version,
321
    .func = cmd_version,
314
    .argc = 0,
322
    .argc = 0,
315
    .argv = NULL
323
    .argv = NULL
316
};
324
};
317
 
325
 
318
static cmd_info_t *basic_commands[] = {
326
static cmd_info_t *basic_commands[] = {
319
    &call0_info,
327
    &call0_info,
320
    &call1_info,
328
    &call1_info,
321
    &call2_info,
329
    &call2_info,
322
    &call3_info,
330
    &call3_info,
323
    &cpus_info,
331
    &cpus_info,
324
    &desc_info,
332
    &desc_info,
325
    &exit_info,
333
    &exit_info,
326
    &halt_info,
334
    &halt_info,
327
    &help_info,
335
    &help_info,
328
    &set4_info,
336
    &set4_info,
329
    &slabs_info,
337
    &slabs_info,
330
    &symaddr_info,
338
    &symaddr_info,
331
    &sched_info,
339
    &sched_info,
332
    &threads_info,
340
    &threads_info,
333
    &tlb_info,
341
    &tlb_info,
334
    &version_info,
342
    &version_info,
335
    &zones_info,
343
    &zones_info,
336
    &zone_info,
344
    &zone_info,
-
 
345
    &hello_info,
337
    NULL
346
    NULL
338
};
347
};
339
 
348
 
340
 
349
 
341
/** Initialize command info structure.
350
/** Initialize command info structure.
342
 *
351
 *
343
 * @param cmd Command info structure.
352
 * @param cmd Command info structure.
344
 *
353
 *
345
 */
354
 */
346
void cmd_initialize(cmd_info_t *cmd)
355
void cmd_initialize(cmd_info_t *cmd)
347
{
356
{
348
    spinlock_initialize(&cmd->lock, "cmd");
357
    spinlock_initialize(&cmd->lock, "cmd");
349
    link_initialize(&cmd->link);
358
    link_initialize(&cmd->link);
350
}
359
}
351
 
360
 
352
/** Initialize and register commands. */
361
/** Initialize and register commands. */
353
void cmd_init(void)
362
void cmd_init(void)
354
{
363
{
355
    int i;
364
    int i;
356
 
365
 
357
    for (i=0;basic_commands[i]; i++) {
366
    for (i=0;basic_commands[i]; i++) {
358
        cmd_initialize(basic_commands[i]);
367
        cmd_initialize(basic_commands[i]);
359
        if (!cmd_register(basic_commands[i]))
368
        if (!cmd_register(basic_commands[i]))
360
            panic("could not register command %s\n",
369
            panic("could not register command %s\n",
361
                  basic_commands[i]->name);
370
                  basic_commands[i]->name);
362
    }
371
    }
363
}
372
}
364
 
373
 
365
 
374
 
366
/** List supported commands.
375
/** List supported commands.
367
 *
376
 *
368
 * @param argv Argument vector.
377
 * @param argv Argument vector.
369
 *
378
 *
370
 * @return 0 on failure, 1 on success.
379
 * @return 0 on failure, 1 on success.
371
 */
380
 */
372
int cmd_help(cmd_arg_t *argv)
381
int cmd_help(cmd_arg_t *argv)
373
{
382
{
374
    link_t *cur;
383
    link_t *cur;
375
 
384
 
376
    spinlock_lock(&cmd_lock);
385
    spinlock_lock(&cmd_lock);
377
   
386
   
378
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
387
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
379
        cmd_info_t *hlp;
388
        cmd_info_t *hlp;
380
       
389
       
381
        hlp = list_get_instance(cur, cmd_info_t, link);
390
        hlp = list_get_instance(cur, cmd_info_t, link);
382
        spinlock_lock(&hlp->lock);
391
        spinlock_lock(&hlp->lock);
383
       
392
       
384
        printf("%s - %s\n", hlp->name, hlp->description);
393
        printf("%s - %s\n", hlp->name, hlp->description);
385
 
394
 
386
        spinlock_unlock(&hlp->lock);
395
        spinlock_unlock(&hlp->lock);
387
    }
396
    }
388
   
397
   
389
    spinlock_unlock(&cmd_lock);
398
    spinlock_unlock(&cmd_lock);
390
 
399
 
391
    return 1;
400
    return 1;
392
}
401
}
393
 
402
 
394
/** Describe specified command.
403
/** Describe specified command.
395
 *
404
 *
396
 * @param argv Argument vector.
405
 * @param argv Argument vector.
397
 *
406
 *
398
 * @return 0 on failure, 1 on success.
407
 * @return 0 on failure, 1 on success.
399
 */
408
 */
400
int cmd_desc(cmd_arg_t *argv)
409
int cmd_desc(cmd_arg_t *argv)
401
{
410
{
402
    link_t *cur;
411
    link_t *cur;
403
 
412
 
404
    spinlock_lock(&cmd_lock);
413
    spinlock_lock(&cmd_lock);
405
   
414
   
406
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
415
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
407
        cmd_info_t *hlp;
416
        cmd_info_t *hlp;
408
       
417
       
409
        hlp = list_get_instance(cur, cmd_info_t, link);
418
        hlp = list_get_instance(cur, cmd_info_t, link);
410
        spinlock_lock(&hlp->lock);
419
        spinlock_lock(&hlp->lock);
411
 
420
 
412
        if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) {
421
        if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) {
413
            printf("%s - %s\n", hlp->name, hlp->description);
422
            printf("%s - %s\n", hlp->name, hlp->description);
414
            if (hlp->help)
423
            if (hlp->help)
415
                hlp->help();
424
                hlp->help();
416
            spinlock_unlock(&hlp->lock);
425
            spinlock_unlock(&hlp->lock);
417
            break;
426
            break;
418
        }
427
        }
419
 
428
 
420
        spinlock_unlock(&hlp->lock);
429
        spinlock_unlock(&hlp->lock);
421
    }
430
    }
422
   
431
   
423
    spinlock_unlock(&cmd_lock);
432
    spinlock_unlock(&cmd_lock);
424
 
433
 
425
    return 1;
434
    return 1;
426
}
435
}
427
 
436
 
428
/** Search symbol table */
437
/** Search symbol table */
429
int cmd_symaddr(cmd_arg_t *argv)
438
int cmd_symaddr(cmd_arg_t *argv)
430
{
439
{
431
    symtab_print_search(argv->buffer);
440
    symtab_print_search(argv->buffer);
432
   
441
   
433
    return 1;
442
    return 1;
434
}
443
}
435
 
444
 
436
/** Call function with zero parameters */
445
/** Call function with zero parameters */
437
int cmd_call0(cmd_arg_t *argv)
446
int cmd_call0(cmd_arg_t *argv)
438
{
447
{
439
    __address symaddr;
448
    __address symaddr;
440
    char *symbol;
449
    char *symbol;
441
    __native (*f)(void);
450
    __native (*f)(void);
442
 
451
 
443
    symaddr = get_symbol_addr(argv->buffer);
452
    symaddr = get_symbol_addr(argv->buffer);
444
    if (!symaddr)
453
    if (!symaddr)
445
        printf("Symbol %s not found.\n", argv->buffer);
454
        printf("Symbol %s not found.\n", argv->buffer);
446
    else if (symaddr == (__address) -1) {
455
    else if (symaddr == (__address) -1) {
447
        symtab_print_search(argv->buffer);
456
        symtab_print_search(argv->buffer);
448
        printf("Duplicate symbol, be more specific.\n");
457
        printf("Duplicate symbol, be more specific.\n");
449
    } else {
458
    } else {
450
        symbol = get_symtab_entry(symaddr);
459
        symbol = get_symtab_entry(symaddr);
451
        printf("Calling f(): 0x%p: %s\n", symaddr, symbol);
460
        printf("Calling f(): 0x%p: %s\n", symaddr, symbol);
452
        f =  (__native (*)(void)) symaddr;
461
        f =  (__native (*)(void)) symaddr;
453
        printf("Result: 0x%p\n", f());
462
        printf("Result: 0x%p\n", f());
454
    }
463
    }
455
   
464
   
456
    return 1;
465
    return 1;
457
}
466
}
458
 
467
 
459
/** Call function with one parameter */
468
/** Call function with one parameter */
460
int cmd_call1(cmd_arg_t *argv)
469
int cmd_call1(cmd_arg_t *argv)
461
{
470
{
462
    __address symaddr;
471
    __address symaddr;
463
    char *symbol;
472
    char *symbol;
464
    __native (*f)(__native,...);
473
    __native (*f)(__native,...);
465
    __native arg1 = argv[1].intval;
474
    __native arg1 = argv[1].intval;
466
 
475
 
467
    symaddr = get_symbol_addr(argv->buffer);
476
    symaddr = get_symbol_addr(argv->buffer);
468
    if (!symaddr)
477
    if (!symaddr)
469
        printf("Symbol %s not found.\n", argv->buffer);
478
        printf("Symbol %s not found.\n", argv->buffer);
470
    else if (symaddr == (__address) -1) {
479
    else if (symaddr == (__address) -1) {
471
        symtab_print_search(argv->buffer);
480
        symtab_print_search(argv->buffer);
472
        printf("Duplicate symbol, be more specific.\n");
481
        printf("Duplicate symbol, be more specific.\n");
473
    } else {
482
    } else {
474
        symbol = get_symtab_entry(symaddr);
483
        symbol = get_symtab_entry(symaddr);
475
        printf("Calling f(0x%x): 0x%p: %s\n", arg1, symaddr, symbol);
484
        printf("Calling f(0x%x): 0x%p: %s\n", arg1, symaddr, symbol);
476
        f =  (__native (*)(__native,...)) symaddr;
485
        f =  (__native (*)(__native,...)) symaddr;
477
        printf("Result: 0x%p\n", f(arg1));
486
        printf("Result: 0x%p\n", f(arg1));
478
    }
487
    }
479
   
488
   
480
    return 1;
489
    return 1;
481
}
490
}
482
 
491
 
483
/** Call function with two parameters */
492
/** Call function with two parameters */
484
int cmd_call2(cmd_arg_t *argv)
493
int cmd_call2(cmd_arg_t *argv)
485
{
494
{
486
    __address symaddr;
495
    __address symaddr;
487
    char *symbol;
496
    char *symbol;
488
    __native (*f)(__native,__native,...);
497
    __native (*f)(__native,__native,...);
489
    __native arg1 = argv[1].intval;
498
    __native arg1 = argv[1].intval;
490
    __native arg2 = argv[2].intval;
499
    __native arg2 = argv[2].intval;
491
 
500
 
492
    symaddr = get_symbol_addr(argv->buffer);
501
    symaddr = get_symbol_addr(argv->buffer);
493
    if (!symaddr)
502
    if (!symaddr)
494
        printf("Symbol %s not found.\n", argv->buffer);
503
        printf("Symbol %s not found.\n", argv->buffer);
495
    else if (symaddr == (__address) -1) {
504
    else if (symaddr == (__address) -1) {
496
        symtab_print_search(argv->buffer);
505
        symtab_print_search(argv->buffer);
497
        printf("Duplicate symbol, be more specific.\n");
506
        printf("Duplicate symbol, be more specific.\n");
498
    } else {
507
    } else {
499
        symbol = get_symtab_entry(symaddr);
508
        symbol = get_symtab_entry(symaddr);
500
        printf("Calling f(0x%x,0x%x): 0x%p: %s\n",
509
        printf("Calling f(0x%x,0x%x): 0x%p: %s\n",
501
               arg1, arg2, symaddr, symbol);
510
               arg1, arg2, symaddr, symbol);
502
        f =  (__native (*)(__native,__native,...)) symaddr;
511
        f =  (__native (*)(__native,__native,...)) symaddr;
503
        printf("Result: 0x%p\n", f(arg1, arg2));
512
        printf("Result: 0x%p\n", f(arg1, arg2));
504
    }
513
    }
505
   
514
   
506
    return 1;
515
    return 1;
507
}
516
}
508
 
517
 
509
/** Call function with three parameters */
518
/** Call function with three parameters */
510
int cmd_call3(cmd_arg_t *argv)
519
int cmd_call3(cmd_arg_t *argv)
511
{
520
{
512
    __address symaddr;
521
    __address symaddr;
513
    char *symbol;
522
    char *symbol;
514
    __native (*f)(__native,__native,__native,...);
523
    __native (*f)(__native,__native,__native,...);
515
    __native arg1 = argv[1].intval;
524
    __native arg1 = argv[1].intval;
516
    __native arg2 = argv[2].intval;
525
    __native arg2 = argv[2].intval;
517
    __native arg3 = argv[3].intval;
526
    __native arg3 = argv[3].intval;
518
 
527
 
519
    symaddr = get_symbol_addr(argv->buffer);
528
    symaddr = get_symbol_addr(argv->buffer);
520
    if (!symaddr)
529
    if (!symaddr)
521
        printf("Symbol %s not found.\n", argv->buffer);
530
        printf("Symbol %s not found.\n", argv->buffer);
522
    else if (symaddr == (__address) -1) {
531
    else if (symaddr == (__address) -1) {
523
        symtab_print_search(argv->buffer);
532
        symtab_print_search(argv->buffer);
524
        printf("Duplicate symbol, be more specific.\n");
533
        printf("Duplicate symbol, be more specific.\n");
525
    } else {
534
    } else {
526
        symbol = get_symtab_entry(symaddr);
535
        symbol = get_symtab_entry(symaddr);
527
        printf("Calling f(0x%x,0x%x, 0x%x): 0x%p: %s\n",
536
        printf("Calling f(0x%x,0x%x, 0x%x): 0x%p: %s\n",
528
               arg1, arg2, arg3, symaddr, symbol);
537
               arg1, arg2, arg3, symaddr, symbol);
529
        f =  (__native (*)(__native,__native,__native,...)) symaddr;
538
        f =  (__native (*)(__native,__native,__native,...)) symaddr;
530
        printf("Result: 0x%p\n", f(arg1, arg2, arg3));
539
        printf("Result: 0x%p\n", f(arg1, arg2, arg3));
531
    }
540
    }
532
   
541
   
533
    return 1;
542
    return 1;
534
}
543
}
535
 
544
 
536
 
545
 
537
/** Print detailed description of 'describe' command. */
546
/** Print detailed description of 'describe' command. */
538
void desc_help(void)
547
void desc_help(void)
539
{
548
{
540
    printf("Syntax: describe command_name\n");
549
    printf("Syntax: describe command_name\n");
541
}
550
}
542
 
551
 
543
/** Halt the kernel.
552
/** Halt the kernel.
544
 *
553
 *
545
 * @param argv Argument vector (ignored).
554
 * @param argv Argument vector (ignored).
546
 *
555
 *
547
 * @return 0 on failure, 1 on success (never returns).
556
 * @return 0 on failure, 1 on success (never returns).
548
 */
557
 */
549
int cmd_halt(cmd_arg_t *argv)
558
int cmd_halt(cmd_arg_t *argv)
550
{
559
{
551
    halt();
560
    halt();
552
    return 1;
561
    return 1;
553
}
562
}
554
 
563
 
555
/** Command for printing TLB contents.
564
/** Command for printing TLB contents.
556
 *
565
 *
557
 * @param argv Not used.
566
 * @param argv Not used.
558
 *
567
 *
559
 * @return Always returns 1.
568
 * @return Always returns 1.
560
 */
569
 */
561
int cmd_tlb(cmd_arg_t *argv)
570
int cmd_tlb(cmd_arg_t *argv)
562
{
571
{
563
    tlb_print();
572
    tlb_print();
564
    return 1;
573
    return 1;
565
}
574
}
566
 
575
 
567
/** Write 4 byte value to address */
576
/** Write 4 byte value to address */
568
int cmd_set4(cmd_arg_t *argv)
577
int cmd_set4(cmd_arg_t *argv)
569
{
578
{
570
    __u32 *addr ;
579
    __u32 *addr ;
571
    __u32 arg1 = argv[1].intval;
580
    __u32 arg1 = argv[1].intval;
572
    bool pointer = false;
581
    bool pointer = false;
573
 
582
 
574
    if (((char *)argv->buffer)[0] == '*') {
583
    if (((char *)argv->buffer)[0] == '*') {
575
        addr = (__u32 *) get_symbol_addr(argv->buffer+1);
584
        addr = (__u32 *) get_symbol_addr(argv->buffer+1);
576
        pointer = true;
585
        pointer = true;
577
    } else if (((char *)argv->buffer)[0] >= '0' &&
586
    } else if (((char *)argv->buffer)[0] >= '0' &&
578
           ((char *)argv->buffer)[0] <= '9')
587
           ((char *)argv->buffer)[0] <= '9')
579
        addr = (__u32 *)atoi((char *)argv->buffer);
588
        addr = (__u32 *)atoi((char *)argv->buffer);
580
    else
589
    else
581
        addr = (__u32 *)get_symbol_addr(argv->buffer);
590
        addr = (__u32 *)get_symbol_addr(argv->buffer);
582
 
591
 
583
    if (!addr)
592
    if (!addr)
584
        printf("Symbol %s not found.\n", argv->buffer);
593
        printf("Symbol %s not found.\n", argv->buffer);
585
    else if (addr == (__u32 *) -1) {
594
    else if (addr == (__u32 *) -1) {
586
        symtab_print_search(argv->buffer);
595
        symtab_print_search(argv->buffer);
587
        printf("Duplicate symbol, be more specific.\n");
596
        printf("Duplicate symbol, be more specific.\n");
588
    } else {
597
    } else {
589
        if (pointer)
598
        if (pointer)
590
            addr = (__u32 *)(*(__native *)addr);
599
            addr = (__u32 *)(*(__native *)addr);
591
        printf("Writing 0x%x -> 0x%p\n", arg1, addr);
600
        printf("Writing 0x%x -> 0x%p\n", arg1, addr);
592
        *addr = arg1;
601
        *addr = arg1;
593
       
602
       
594
    }
603
    }
595
   
604
   
596
    return 1;
605
    return 1;
597
}
606
}
598
 
607
 
599
/** Command for listings SLAB caches
608
/** Command for listings SLAB caches
600
 *
609
 *
601
 * @param argv Ignores
610
 * @param argv Ignores
602
 *
611
 *
603
 * @return Always 1
612
 * @return Always 1
604
 */
613
 */
605
int cmd_slabs(cmd_arg_t * argv) {
614
int cmd_slabs(cmd_arg_t * argv) {
606
    slab_print_list();
615
    slab_print_list();
607
    return 1;
616
    return 1;
608
}
617
}
609
 
618
 
610
 
619
 
611
/** Command for listings Thread information
620
/** Command for listings Thread information
612
 *
621
 *
613
 * @param argv Ignores
622
 * @param argv Ignores
614
 *
623
 *
615
 * @return Always 1
624
 * @return Always 1
616
 */
625
 */
617
int cmd_threads(cmd_arg_t * argv) {
626
int cmd_threads(cmd_arg_t * argv) {
618
    thread_print_list();
627
    thread_print_list();
619
    return 1;
628
    return 1;
620
}
629
}
621
 
630
 
622
/** Command for listings Thread information
631
/** Command for listings Thread information
623
 *
632
 *
624
 * @param argv Ignores
633
 * @param argv Ignores
625
 *
634
 *
626
 * @return Always 1
635
 * @return Always 1
627
 */
636
 */
628
int cmd_sched(cmd_arg_t * argv) {
637
int cmd_sched(cmd_arg_t * argv) {
629
    sched_print_list();
638
    sched_print_list();
630
    return 1;
639
    return 1;
631
}
640
}
632
 
641
 
633
/** Command for listing memory zones
642
/** Command for listing memory zones
634
 *
643
 *
635
 * @param argv Ignored
644
 * @param argv Ignored
636
 *
645
 *
637
 * return Always 1
646
 * return Always 1
638
 */
647
 */
639
int cmd_zones(cmd_arg_t * argv) {
648
int cmd_zones(cmd_arg_t * argv) {
640
    zone_print_list();
649
    zone_print_list();
641
    return 1;
650
    return 1;
642
}
651
}
643
 
652
 
644
/** Command for memory zone details
653
/** Command for memory zone details
645
 *
654
 *
646
 * @param argv Integer argument from cmdline expected
655
 * @param argv Integer argument from cmdline expected
647
 *
656
 *
648
 * return Always 1
657
 * return Always 1
649
 */
658
 */
650
int cmd_zone(cmd_arg_t * argv) {
659
int cmd_zone(cmd_arg_t * argv) {
651
    zone_print_one(argv[0].intval);
660
    zone_print_one(argv[0].intval);
652
    return 1;
661
    return 1;
653
}
662
}
654
 
663
 
655
/** Command for listing processors.
664
/** Command for listing processors.
656
 *
665
 *
657
 * @param argv Ignored.
666
 * @param argv Ignored.
658
 *
667
 *
659
 * return Always 1.
668
 * return Always 1.
660
 */
669
 */
661
int cmd_cpus(cmd_arg_t *argv)
670
int cmd_cpus(cmd_arg_t *argv)
662
{
671
{
663
    cpu_list();
672
    cpu_list();
664
    return 1;
673
    return 1;
665
}
674
}
666
 
675
 
667
/** Command for printing kernel version.
676
/** Command for printing kernel version.
668
 *
677
 *
669
 * @param argv Ignored.
678
 * @param argv Ignored.
670
 *
679
 *
671
 * return Always 1.
680
 * return Always 1.
672
 */
681
 */
673
int cmd_version(cmd_arg_t *argv)
682
int cmd_version(cmd_arg_t *argv)
674
{
683
{
675
    version_print();
684
    version_print();
676
    return 1;
685
    return 1;
-
 
686
}
-
 
687
 
-
 
688
 
-
 
689
int cmd_hello(cmd_arg_t *argv)
-
 
690
{
-
 
691
    printf("\nHello, World !!!\n");
-
 
692
    return 1;
677
}
693
}
678
 
694