Subversion Repositories HelenOS

Rev

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

Rev 777 Rev 788
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 <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
/** Data and methods for 'cpus' command. */
296
/** Data and methods for 'cpus' command. */
297
static int cmd_cpus(cmd_arg_t *argv);
297
static int cmd_cpus(cmd_arg_t *argv);
298
cmd_info_t cpus_info = {
298
cmd_info_t cpus_info = {
299
    .name = "cpus",
299
    .name = "cpus",
300
    .description = "List all processors.",
300
    .description = "List all processors.",
301
    .help = NULL,
301
    .help = NULL,
302
    .func = cmd_cpus,
302
    .func = cmd_cpus,
303
    .argc = 0,
303
    .argc = 0,
304
    .argv = NULL
304
    .argv = NULL
305
};
305
};
306
 
306
 
307
/** Data and methods for 'version' command. */
307
/** Data and methods for 'version' command. */
308
static int cmd_version(cmd_arg_t *argv);
308
static int cmd_version(cmd_arg_t *argv);
309
cmd_info_t version_info = {
309
cmd_info_t version_info = {
310
    .name = "version",
310
    .name = "version",
311
    .description = "Print version information.",
311
    .description = "Print version information.",
312
    .help = NULL,
312
    .help = NULL,
313
    .func = cmd_version,
313
    .func = cmd_version,
314
    .argc = 0,
314
    .argc = 0,
315
    .argv = NULL
315
    .argv = NULL
316
};
316
};
317
 
317
 
318
static cmd_info_t *basic_commands[] = {
318
static cmd_info_t *basic_commands[] = {
319
    &call0_info,
319
    &call0_info,
320
    &call1_info,
320
    &call1_info,
321
    &call2_info,
321
    &call2_info,
322
    &call3_info,
322
    &call3_info,
323
    &cpus_info,
323
    &cpus_info,
324
    &desc_info,
324
    &desc_info,
325
    &exit_info,
325
    &exit_info,
326
    &halt_info,
326
    &halt_info,
327
    &help_info,
327
    &help_info,
328
    &set4_info,
328
    &set4_info,
329
    &slabs_info,
329
    &slabs_info,
330
    &symaddr_info,
330
    &symaddr_info,
331
    &sched_info,
331
    &sched_info,
332
    &threads_info,
332
    &threads_info,
333
    &tlb_info,
333
    &tlb_info,
334
    &version_info,
334
    &version_info,
335
    &zones_info,
335
    &zones_info,
336
    &zone_info,
336
    &zone_info,
337
    NULL
337
    NULL
338
};
338
};
339
 
339
 
340
 
340
 
341
/** Initialize command info structure.
341
/** Initialize command info structure.
342
 *
342
 *
343
 * @param cmd Command info structure.
343
 * @param cmd Command info structure.
344
 *
344
 *
345
 */
345
 */
346
void cmd_initialize(cmd_info_t *cmd)
346
void cmd_initialize(cmd_info_t *cmd)
347
{
347
{
348
    spinlock_initialize(&cmd->lock, "cmd");
348
    spinlock_initialize(&cmd->lock, "cmd");
349
    link_initialize(&cmd->link);
349
    link_initialize(&cmd->link);
350
}
350
}
351
 
351
 
352
/** Initialize and register commands. */
352
/** Initialize and register commands. */
353
void cmd_init(void)
353
void cmd_init(void)
354
{
354
{
355
    int i;
355
    int i;
356
 
356
 
357
    for (i=0;basic_commands[i]; i++) {
357
    for (i=0;basic_commands[i]; i++) {
358
        cmd_initialize(basic_commands[i]);
358
        cmd_initialize(basic_commands[i]);
359
        if (!cmd_register(basic_commands[i]))
359
        if (!cmd_register(basic_commands[i]))
360
            panic("could not register command %s\n",
360
            panic("could not register command %s\n",
361
                  basic_commands[i]->name);
361
                  basic_commands[i]->name);
362
    }
362
    }
363
}
363
}
364
 
364
 
365
 
365
 
366
/** List supported commands.
366
/** List supported commands.
367
 *
367
 *
368
 * @param argv Argument vector.
368
 * @param argv Argument vector.
369
 *
369
 *
370
 * @return 0 on failure, 1 on success.
370
 * @return 0 on failure, 1 on success.
371
 */
371
 */
372
int cmd_help(cmd_arg_t *argv)
372
int cmd_help(cmd_arg_t *argv)
373
{
373
{
374
    link_t *cur;
374
    link_t *cur;
375
 
375
 
376
    spinlock_lock(&cmd_lock);
376
    spinlock_lock(&cmd_lock);
377
   
377
   
378
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
378
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
379
        cmd_info_t *hlp;
379
        cmd_info_t *hlp;
380
       
380
       
381
        hlp = list_get_instance(cur, cmd_info_t, link);
381
        hlp = list_get_instance(cur, cmd_info_t, link);
382
        spinlock_lock(&hlp->lock);
382
        spinlock_lock(&hlp->lock);
383
       
383
       
384
        printf("%s - %s\n", hlp->name, hlp->description);
384
        printf("%s - %s\n", hlp->name, hlp->description);
385
 
385
 
386
        spinlock_unlock(&hlp->lock);
386
        spinlock_unlock(&hlp->lock);
387
    }
387
    }
388
   
388
   
389
    spinlock_unlock(&cmd_lock);
389
    spinlock_unlock(&cmd_lock);
390
 
390
 
391
    return 1;
391
    return 1;
392
}
392
}
393
 
393
 
394
/** Describe specified command.
394
/** Describe specified command.
395
 *
395
 *
396
 * @param argv Argument vector.
396
 * @param argv Argument vector.
397
 *
397
 *
398
 * @return 0 on failure, 1 on success.
398
 * @return 0 on failure, 1 on success.
399
 */
399
 */
400
int cmd_desc(cmd_arg_t *argv)
400
int cmd_desc(cmd_arg_t *argv)
401
{
401
{
402
    link_t *cur;
402
    link_t *cur;
403
 
403
 
404
    spinlock_lock(&cmd_lock);
404
    spinlock_lock(&cmd_lock);
405
   
405
   
406
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
406
    for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
407
        cmd_info_t *hlp;
407
        cmd_info_t *hlp;
408
       
408
       
409
        hlp = list_get_instance(cur, cmd_info_t, link);
409
        hlp = list_get_instance(cur, cmd_info_t, link);
410
        spinlock_lock(&hlp->lock);
410
        spinlock_lock(&hlp->lock);
411
 
411
 
412
        if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) {
412
        if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) {
413
            printf("%s - %s\n", hlp->name, hlp->description);
413
            printf("%s - %s\n", hlp->name, hlp->description);
414
            if (hlp->help)
414
            if (hlp->help)
415
                hlp->help();
415
                hlp->help();
416
            spinlock_unlock(&hlp->lock);
416
            spinlock_unlock(&hlp->lock);
417
            break;
417
            break;
418
        }
418
        }
419
 
419
 
420
        spinlock_unlock(&hlp->lock);
420
        spinlock_unlock(&hlp->lock);
421
    }
421
    }
422
   
422
   
423
    spinlock_unlock(&cmd_lock);
423
    spinlock_unlock(&cmd_lock);
424
 
424
 
425
    return 1;
425
    return 1;
426
}
426
}
427
 
427
 
428
/** Search symbol table */
428
/** Search symbol table */
429
int cmd_symaddr(cmd_arg_t *argv)
429
int cmd_symaddr(cmd_arg_t *argv)
430
{
430
{
431
    symtab_print_search(argv->buffer);
431
    symtab_print_search(argv->buffer);
432
   
432
   
433
    return 1;
433
    return 1;
434
}
434
}
435
 
435
 
436
/** Call function with zero parameters */
436
/** Call function with zero parameters */
437
int cmd_call0(cmd_arg_t *argv)
437
int cmd_call0(cmd_arg_t *argv)
438
{
438
{
439
    __address symaddr;
439
    __address symaddr;
440
    char *symbol;
440
    char *symbol;
441
    __native (*f)(void);
441
    __native (*f)(void);
442
 
442
 
443
    symaddr = get_symbol_addr(argv->buffer);
443
    symaddr = get_symbol_addr(argv->buffer);
444
    if (!symaddr)
444
    if (!symaddr)
445
        printf("Symbol %s not found.\n", argv->buffer);
445
        printf("Symbol %s not found.\n", argv->buffer);
446
    else if (symaddr == (__address) -1) {
446
    else if (symaddr == (__address) -1) {
447
        symtab_print_search(argv->buffer);
447
        symtab_print_search(argv->buffer);
448
        printf("Duplicate symbol, be more specific.\n");
448
        printf("Duplicate symbol, be more specific.\n");
449
    } else {
449
    } else {
450
        symbol = get_symtab_entry(symaddr);
450
        symbol = get_symtab_entry(symaddr);
451
        printf("Calling f(): 0x%p: %s\n", symaddr, symbol);
451
        printf("Calling f(): 0x%p: %s\n", symaddr, symbol);
452
        f =  (__native (*)(void)) symaddr;
452
        f =  (__native (*)(void)) symaddr;
453
        printf("Result: 0x%p\n", f());
453
        printf("Result: 0x%p\n", f());
454
    }
454
    }
455
   
455
   
456
    return 1;
456
    return 1;
457
}
457
}
458
 
458
 
459
/** Call function with one parameter */
459
/** Call function with one parameter */
460
int cmd_call1(cmd_arg_t *argv)
460
int cmd_call1(cmd_arg_t *argv)
461
{
461
{
462
    __address symaddr;
462
    __address symaddr;
463
    char *symbol;
463
    char *symbol;
464
    __native (*f)(__native,...);
464
    __native (*f)(__native,...);
465
    __native arg1 = argv[1].intval;
465
    __native arg1 = argv[1].intval;
466
 
466
 
467
    symaddr = get_symbol_addr(argv->buffer);
467
    symaddr = get_symbol_addr(argv->buffer);
468
    if (!symaddr)
468
    if (!symaddr)
469
        printf("Symbol %s not found.\n", argv->buffer);
469
        printf("Symbol %s not found.\n", argv->buffer);
470
    else if (symaddr == (__address) -1) {
470
    else if (symaddr == (__address) -1) {
471
        symtab_print_search(argv->buffer);
471
        symtab_print_search(argv->buffer);
472
        printf("Duplicate symbol, be more specific.\n");
472
        printf("Duplicate symbol, be more specific.\n");
473
    } else {
473
    } else {
474
        symbol = get_symtab_entry(symaddr);
474
        symbol = get_symtab_entry(symaddr);
475
        printf("Calling f(0x%x): 0x%p: %s\n", arg1, symaddr, symbol);
475
        printf("Calling f(0x%x): 0x%p: %s\n", arg1, symaddr, symbol);
476
        f =  (__native (*)(__native,...)) symaddr;
476
        f =  (__native (*)(__native,...)) symaddr;
477
        printf("Result: 0x%p\n", f(arg1));
477
        printf("Result: 0x%p\n", f(arg1));
478
    }
478
    }
479
   
479
   
480
    return 1;
480
    return 1;
481
}
481
}
482
 
482
 
483
/** Call function with two parameters */
483
/** Call function with two parameters */
484
int cmd_call2(cmd_arg_t *argv)
484
int cmd_call2(cmd_arg_t *argv)
485
{
485
{
486
    __address symaddr;
486
    __address symaddr;
487
    char *symbol;
487
    char *symbol;
488
    __native (*f)(__native,__native,...);
488
    __native (*f)(__native,__native,...);
489
    __native arg1 = argv[1].intval;
489
    __native arg1 = argv[1].intval;
490
    __native arg2 = argv[2].intval;
490
    __native arg2 = argv[2].intval;
491
 
491
 
492
    symaddr = get_symbol_addr(argv->buffer);
492
    symaddr = get_symbol_addr(argv->buffer);
493
    if (!symaddr)
493
    if (!symaddr)
494
        printf("Symbol %s not found.\n", argv->buffer);
494
        printf("Symbol %s not found.\n", argv->buffer);
495
    else if (symaddr == (__address) -1) {
495
    else if (symaddr == (__address) -1) {
496
        symtab_print_search(argv->buffer);
496
        symtab_print_search(argv->buffer);
497
        printf("Duplicate symbol, be more specific.\n");
497
        printf("Duplicate symbol, be more specific.\n");
498
    } else {
498
    } else {
499
        symbol = get_symtab_entry(symaddr);
499
        symbol = get_symtab_entry(symaddr);
500
        printf("Calling f(0x%x,0x%x): 0x%p: %s\n",
500
        printf("Calling f(0x%x,0x%x): 0x%p: %s\n",
501
               arg1, arg2, symaddr, symbol);
501
               arg1, arg2, symaddr, symbol);
502
        f =  (__native (*)(__native,__native,...)) symaddr;
502
        f =  (__native (*)(__native,__native,...)) symaddr;
503
        printf("Result: 0x%p\n", f(arg1, arg2));
503
        printf("Result: 0x%p\n", f(arg1, arg2));
504
    }
504
    }
505
   
505
   
506
    return 1;
506
    return 1;
507
}
507
}
508
 
508
 
509
/** Call function with three parameters */
509
/** Call function with three parameters */
510
int cmd_call3(cmd_arg_t *argv)
510
int cmd_call3(cmd_arg_t *argv)
511
{
511
{
512
    __address symaddr;
512
    __address symaddr;
513
    char *symbol;
513
    char *symbol;
514
    __native (*f)(__native,__native,__native,...);
514
    __native (*f)(__native,__native,__native,...);
515
    __native arg1 = argv[1].intval;
515
    __native arg1 = argv[1].intval;
516
    __native arg2 = argv[2].intval;
516
    __native arg2 = argv[2].intval;
517
    __native arg3 = argv[3].intval;
517
    __native arg3 = argv[3].intval;
518
 
518
 
519
    symaddr = get_symbol_addr(argv->buffer);
519
    symaddr = get_symbol_addr(argv->buffer);
520
    if (!symaddr)
520
    if (!symaddr)
521
        printf("Symbol %s not found.\n", argv->buffer);
521
        printf("Symbol %s not found.\n", argv->buffer);
522
    else if (symaddr == (__address) -1) {
522
    else if (symaddr == (__address) -1) {
523
        symtab_print_search(argv->buffer);
523
        symtab_print_search(argv->buffer);
524
        printf("Duplicate symbol, be more specific.\n");
524
        printf("Duplicate symbol, be more specific.\n");
525
    } else {
525
    } else {
526
        symbol = get_symtab_entry(symaddr);
526
        symbol = get_symtab_entry(symaddr);
527
        printf("Calling f(0x%x,0x%x, 0x%x): 0x%p: %s\n",
527
        printf("Calling f(0x%x,0x%x, 0x%x): 0x%p: %s\n",
528
               arg1, arg2, arg3, symaddr, symbol);
528
               arg1, arg2, arg3, symaddr, symbol);
529
        f =  (__native (*)(__native,__native,__native,...)) symaddr;
529
        f =  (__native (*)(__native,__native,__native,...)) symaddr;
530
        printf("Result: 0x%p\n", f(arg1, arg2, arg3));
530
        printf("Result: 0x%p\n", f(arg1, arg2, arg3));
531
    }
531
    }
532
   
532
   
533
    return 1;
533
    return 1;
534
}
534
}
535
 
535
 
536
 
536
 
537
/** Print detailed description of 'describe' command. */
537
/** Print detailed description of 'describe' command. */
538
void desc_help(void)
538
void desc_help(void)
539
{
539
{
540
    printf("Syntax: describe command_name\n");
540
    printf("Syntax: describe command_name\n");
541
}
541
}
542
 
542
 
543
/** Halt the kernel.
543
/** Halt the kernel.
544
 *
544
 *
545
 * @param argv Argument vector (ignored).
545
 * @param argv Argument vector (ignored).
546
 *
546
 *
547
 * @return 0 on failure, 1 on success (never returns).
547
 * @return 0 on failure, 1 on success (never returns).
548
 */
548
 */
549
int cmd_halt(cmd_arg_t *argv)
549
int cmd_halt(cmd_arg_t *argv)
550
{
550
{
551
    halt();
551
    halt();
552
    return 1;
552
    return 1;
553
}
553
}
554
 
554
 
555
/** Command for printing TLB contents.
555
/** Command for printing TLB contents.
556
 *
556
 *
557
 * @param argv Not used.
557
 * @param argv Not used.
558
 *
558
 *
559
 * @return Always returns 1.
559
 * @return Always returns 1.
560
 */
560
 */
561
int cmd_tlb(cmd_arg_t *argv)
561
int cmd_tlb(cmd_arg_t *argv)
562
{
562
{
563
    tlb_print();
563
    tlb_print();
564
    return 1;
564
    return 1;
565
}
565
}
566
 
566
 
567
/** Write 4 byte value to address */
567
/** Write 4 byte value to address */
568
int cmd_set4(cmd_arg_t *argv)
568
int cmd_set4(cmd_arg_t *argv)
569
{
569
{
570
    __u32 *addr ;
570
    __u32 *addr ;
571
    __u32 arg1 = argv[1].intval;
571
    __u32 arg1 = argv[1].intval;
572
    bool pointer = false;
572
    bool pointer = false;
573
 
573
 
574
    if (((char *)argv->buffer)[0] == '*') {
574
    if (((char *)argv->buffer)[0] == '*') {
575
        addr = (__u32 *) get_symbol_addr(argv->buffer+1);
575
        addr = (__u32 *) get_symbol_addr(argv->buffer+1);
576
        pointer = true;
576
        pointer = true;
577
    } else if (((char *)argv->buffer)[0] >= '0' &&
577
    } else if (((char *)argv->buffer)[0] >= '0' &&
578
           ((char *)argv->buffer)[0] <= '9')
578
           ((char *)argv->buffer)[0] <= '9')
579
        addr = (__u32 *)atoi((char *)argv->buffer);
579
        addr = (__u32 *)atoi((char *)argv->buffer);
580
    else
580
    else
581
        addr = (__u32 *)get_symbol_addr(argv->buffer);
581
        addr = (__u32 *)get_symbol_addr(argv->buffer);
582
 
582
 
583
    if (!addr)
583
    if (!addr)
584
        printf("Symbol %s not found.\n", argv->buffer);
584
        printf("Symbol %s not found.\n", argv->buffer);
585
    else if (addr == (__u32 *) -1) {
585
    else if (addr == (__u32 *) -1) {
586
        symtab_print_search(argv->buffer);
586
        symtab_print_search(argv->buffer);
587
        printf("Duplicate symbol, be more specific.\n");
587
        printf("Duplicate symbol, be more specific.\n");
588
    } else {
588
    } else {
589
        if (pointer)
589
        if (pointer)
590
            addr = (__u32 *)(*(__native *)addr);
590
            addr = (__u32 *)(*(__native *)addr);
591
        printf("Writing 0x%x -> 0x%p\n", arg1, addr);
591
        printf("Writing 0x%x -> 0x%p\n", arg1, addr);
592
        *addr = arg1;
592
        *addr = arg1;
593
       
593
       
594
    }
594
    }
595
   
595
   
596
    return 1;
596
    return 1;
597
}
597
}
598
 
598
 
599
/** Command for listings SLAB caches
599
/** Command for listings SLAB caches
600
 *
600
 *
601
 * @param argv Ignores
601
 * @param argv Ignores
602
 *
602
 *
603
 * @return Always 1
603
 * @return Always 1
604
 */
604
 */
605
int cmd_slabs(cmd_arg_t * argv) {
605
int cmd_slabs(cmd_arg_t * argv) {
606
    slab_print_list();
606
    slab_print_list();
607
    return 1;
607
    return 1;
608
}
608
}
609
 
609
 
610
 
610
 
611
/** Command for listings Thread information
611
/** Command for listings Thread information
612
 *
612
 *
613
 * @param argv Ignores
613
 * @param argv Ignores
614
 *
614
 *
615
 * @return Always 1
615
 * @return Always 1
616
 */
616
 */
617
int cmd_threads(cmd_arg_t * argv) {
617
int cmd_threads(cmd_arg_t * argv) {
618
    thread_print_list();
618
    thread_print_list();
619
    return 1;
619
    return 1;
620
}
620
}
621
 
621
 
622
/** Command for listings Thread information
622
/** Command for listings Thread information
623
 *
623
 *
624
 * @param argv Ignores
624
 * @param argv Ignores
625
 *
625
 *
626
 * @return Always 1
626
 * @return Always 1
627
 */
627
 */
628
int cmd_sched(cmd_arg_t * argv) {
628
int cmd_sched(cmd_arg_t * argv) {
629
    sched_print_list();
629
    sched_print_list();
630
    return 1;
630
    return 1;
631
}
631
}
632
 
632
 
633
/** Command for listing memory zones
633
/** Command for listing memory zones
634
 *
634
 *
635
 * @param argv Ignored
635
 * @param argv Ignored
636
 *
636
 *
637
 * return Always 1
637
 * return Always 1
638
 */
638
 */
639
int cmd_zones(cmd_arg_t * argv) {
639
int cmd_zones(cmd_arg_t * argv) {
640
    zone_print_list();
640
    zone_print_list();
641
    return 1;
641
    return 1;
642
}
642
}
643
 
643
 
644
/** Command for memory zone details
644
/** Command for memory zone details
645
 *
645
 *
646
 * @param argv Integer argument from cmdline expected
646
 * @param argv Integer argument from cmdline expected
647
 *
647
 *
648
 * return Always 1
648
 * return Always 1
649
 */
649
 */
650
int cmd_zone(cmd_arg_t * argv) {
650
int cmd_zone(cmd_arg_t * argv) {
651
    zone_print_one(argv[0].intval);
651
    zone_print_one(argv[0].intval);
652
    return 1;
652
    return 1;
653
}
653
}
654
 
654
 
655
/** Command for listing processors.
655
/** Command for listing processors.
656
 *
656
 *
657
 * @param argv Ignored.
657
 * @param argv Ignored.
658
 *
658
 *
659
 * return Always 1.
659
 * return Always 1.
660
 */
660
 */
661
int cmd_cpus(cmd_arg_t *argv)
661
int cmd_cpus(cmd_arg_t *argv)
662
{
662
{
663
    cpu_list();
663
    cpu_list();
664
    return 1;
664
    return 1;
665
}
665
}
666
 
666
 
667
/** Command for printing kernel version.
667
/** Command for printing kernel version.
668
 *
668
 *
669
 * @param argv Ignored.
669
 * @param argv Ignored.
670
 *
670
 *
671
 * return Always 1.
671
 * return Always 1.
672
 */
672
 */
673
int cmd_version(cmd_arg_t *argv)
673
int cmd_version(cmd_arg_t *argv)
674
{
674
{
675
    version_print();
675
    version_print();
676
    return 1;
676
    return 1;
677
}
677
}
678
 
678