Subversion Repositories HelenOS

Rev

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

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