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