Rev 591 | Rev 596 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 591 | Rev 594 | ||
---|---|---|---|
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 | #include <console/kconsole.h> |
29 | #include <console/kconsole.h> |
30 | #include <console/console.h> |
30 | #include <console/console.h> |
31 | #include <console/chardev.h> |
31 | #include <console/chardev.h> |
32 | #include <print.h> |
32 | #include <print.h> |
33 | #include <panic.h> |
33 | #include <panic.h> |
34 | #include <typedefs.h> |
34 | #include <typedefs.h> |
35 | #include <arch/types.h> |
35 | #include <arch/types.h> |
36 | #include <list.h> |
36 | #include <list.h> |
37 | #include <arch.h> |
37 | #include <arch.h> |
38 | #include <func.h> |
38 | #include <func.h> |
39 | #include <macros.h> |
39 | #include <macros.h> |
40 | #include <debug.h> |
40 | #include <debug.h> |
41 | #include <symtab.h> |
41 | #include <symtab.h> |
42 | 42 | ||
- | 43 | #include <mm/tlb_cmd.h> |
|
- | 44 | ||
43 | #define MAX_CMDLINE 256 |
45 | #define MAX_CMDLINE 256 |
44 | 46 | ||
45 | /** Simple kernel console. |
47 | /** Simple kernel console. |
46 | * |
48 | * |
47 | * The console is realized by kernel thread kconsole. |
49 | * The console is realized by kernel thread kconsole. |
48 | * It doesn't understand any useful command on its own, |
50 | * It doesn't understand any useful command on its own, |
49 | * but makes it possible for other kernel subsystems to |
51 | * but makes it possible for other kernel subsystems to |
50 | * register their own commands. |
52 | * register their own commands. |
51 | */ |
53 | */ |
52 | 54 | ||
53 | /** Locking. |
55 | /** Locking. |
54 | * |
56 | * |
55 | * There is a list of cmd_info_t structures. This list |
57 | * There is a list of cmd_info_t structures. This list |
56 | * is protected by cmd_lock spinlock. Note that specially |
58 | * is protected by cmd_lock spinlock. Note that specially |
57 | * the link elements of cmd_info_t are protected by |
59 | * the link elements of cmd_info_t are protected by |
58 | * this lock. |
60 | * this lock. |
59 | * |
61 | * |
60 | * Each cmd_info_t also has its own lock, which protects |
62 | * Each cmd_info_t also has its own lock, which protects |
61 | * all elements thereof except the link element. |
63 | * all elements thereof except the link element. |
62 | * |
64 | * |
63 | * cmd_lock must be acquired before any cmd_info lock. |
65 | * cmd_lock must be acquired before any cmd_info lock. |
64 | * When locking two cmd info structures, structure with |
66 | * When locking two cmd info structures, structure with |
65 | * lower address must be locked first. |
67 | * lower address must be locked first. |
66 | */ |
68 | */ |
67 | 69 | ||
68 | spinlock_t cmd_lock; /**< Lock protecting command list. */ |
70 | spinlock_t cmd_lock; /**< Lock protecting command list. */ |
69 | link_t cmd_head; /**< Command list. */ |
71 | link_t cmd_head; /**< Command list. */ |
70 | 72 | ||
71 | static cmd_info_t *parse_cmdline(char *cmdline, size_t len); |
73 | static cmd_info_t *parse_cmdline(char *cmdline, size_t len); |
72 | static bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end); |
74 | static bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end); |
73 | 75 | ||
74 | /** Data and methods for 'help' command. */ |
76 | /** Data and methods for 'help' command. */ |
75 | static int cmd_help(cmd_arg_t *argv); |
77 | static int cmd_help(cmd_arg_t *argv); |
76 | static cmd_info_t help_info = { |
78 | static cmd_info_t help_info = { |
77 | .name = "help", |
79 | .name = "help", |
78 | .description = "List of supported commands.", |
80 | .description = "List of supported commands.", |
79 | .func = cmd_help, |
81 | .func = cmd_help, |
80 | .argc = 0 |
82 | .argc = 0 |
81 | }; |
83 | }; |
82 | 84 | ||
83 | /** Data and methods for 'description' command. */ |
85 | /** Data and methods for 'description' command. */ |
84 | static int cmd_desc(cmd_arg_t *argv); |
86 | static int cmd_desc(cmd_arg_t *argv); |
85 | static void desc_help(void); |
87 | static void desc_help(void); |
86 | static char desc_buf[MAX_CMDLINE+1]; |
88 | static char desc_buf[MAX_CMDLINE+1]; |
87 | static cmd_arg_t desc_argv = { |
89 | static cmd_arg_t desc_argv = { |
88 | .type = ARG_TYPE_STRING, |
90 | .type = ARG_TYPE_STRING, |
89 | .buffer = desc_buf, |
91 | .buffer = desc_buf, |
90 | .len = sizeof(desc_buf) |
92 | .len = sizeof(desc_buf) |
91 | }; |
93 | }; |
92 | static cmd_info_t desc_info = { |
94 | static cmd_info_t desc_info = { |
93 | .name = "describe", |
95 | .name = "describe", |
94 | .description = "Describe specified command.", |
96 | .description = "Describe specified command.", |
95 | .help = desc_help, |
97 | .help = desc_help, |
96 | .func = cmd_desc, |
98 | .func = cmd_desc, |
97 | .argc = 1, |
99 | .argc = 1, |
98 | .argv = &desc_argv |
100 | .argv = &desc_argv |
99 | }; |
101 | }; |
100 | 102 | ||
101 | /** Data and methods for 'symaddr' command. */ |
103 | /** Data and methods for 'symaddr' command. */ |
102 | static int cmd_symaddr(cmd_arg_t *argv); |
104 | static int cmd_symaddr(cmd_arg_t *argv); |
103 | static char symaddr_buf[MAX_CMDLINE+1]; |
105 | static char symaddr_buf[MAX_CMDLINE+1]; |
104 | static cmd_arg_t symaddr_argv = { |
106 | static cmd_arg_t symaddr_argv = { |
105 | .type = ARG_TYPE_STRING, |
107 | .type = ARG_TYPE_STRING, |
106 | .buffer = symaddr_buf, |
108 | .buffer = symaddr_buf, |
107 | .len = sizeof(symaddr_buf) |
109 | .len = sizeof(symaddr_buf) |
108 | }; |
110 | }; |
109 | static cmd_info_t symaddr_info = { |
111 | static cmd_info_t symaddr_info = { |
110 | .name = "symaddr", |
112 | .name = "symaddr", |
111 | .description = "Return symbol address.", |
113 | .description = "Return symbol address.", |
112 | .func = cmd_symaddr, |
114 | .func = cmd_symaddr, |
113 | .argc = 1, |
115 | .argc = 1, |
114 | .argv = &symaddr_argv |
116 | .argv = &symaddr_argv |
115 | }; |
117 | }; |
116 | 118 | ||
117 | /** Call0 - call function with no parameters */ |
119 | /** Call0 - call function with no parameters */ |
118 | static char call0_buf[MAX_CMDLINE+1]; |
120 | static char call0_buf[MAX_CMDLINE+1]; |
119 | static char carg1_buf[MAX_CMDLINE+1]; |
121 | static char carg1_buf[MAX_CMDLINE+1]; |
120 | static char carg2_buf[MAX_CMDLINE+1]; |
122 | static char carg2_buf[MAX_CMDLINE+1]; |
121 | static char carg3_buf[MAX_CMDLINE+1]; |
123 | static char carg3_buf[MAX_CMDLINE+1]; |
122 | 124 | ||
123 | static int cmd_call0(cmd_arg_t *argv); |
125 | static int cmd_call0(cmd_arg_t *argv); |
124 | static cmd_arg_t call0_argv = { |
126 | static cmd_arg_t call0_argv = { |
125 | .type = ARG_TYPE_STRING, |
127 | .type = ARG_TYPE_STRING, |
126 | .buffer = call0_buf, |
128 | .buffer = call0_buf, |
127 | .len = sizeof(call0_buf) |
129 | .len = sizeof(call0_buf) |
128 | }; |
130 | }; |
129 | static cmd_info_t call0_info = { |
131 | static cmd_info_t call0_info = { |
130 | .name = "call0", |
132 | .name = "call0", |
131 | .description = "call0 <function> -> call function().", |
133 | .description = "call0 <function> -> call function().", |
132 | .func = cmd_call0, |
134 | .func = cmd_call0, |
133 | .argc = 1, |
135 | .argc = 1, |
134 | .argv = &call0_argv |
136 | .argv = &call0_argv |
135 | }; |
137 | }; |
136 | 138 | ||
137 | static int cmd_call1(cmd_arg_t *argv); |
139 | static int cmd_call1(cmd_arg_t *argv); |
138 | static cmd_arg_t call1_argv[] = { |
140 | static cmd_arg_t call1_argv[] = { |
139 | { |
141 | { |
140 | .type = ARG_TYPE_STRING, |
142 | .type = ARG_TYPE_STRING, |
141 | .buffer = call0_buf, |
143 | .buffer = call0_buf, |
142 | .len = sizeof(call0_buf) |
144 | .len = sizeof(call0_buf) |
143 | }, |
145 | }, |
144 | { |
146 | { |
145 | .type = ARG_TYPE_VAR, |
147 | .type = ARG_TYPE_VAR, |
146 | .buffer = carg1_buf, |
148 | .buffer = carg1_buf, |
147 | .len = sizeof(carg1_buf) |
149 | .len = sizeof(carg1_buf) |
148 | } |
150 | } |
149 | }; |
151 | }; |
150 | static cmd_info_t call1_info = { |
152 | static cmd_info_t call1_info = { |
151 | .name = "call1", |
153 | .name = "call1", |
152 | .description = "call1 <function> <arg1> -> call function(arg1).", |
154 | .description = "call1 <function> <arg1> -> call function(arg1).", |
153 | .func = cmd_call1, |
155 | .func = cmd_call1, |
154 | .argc = 2, |
156 | .argc = 2, |
155 | .argv = call1_argv |
157 | .argv = call1_argv |
156 | }; |
158 | }; |
157 | 159 | ||
158 | static int cmd_call2(cmd_arg_t *argv); |
160 | static int cmd_call2(cmd_arg_t *argv); |
159 | static cmd_arg_t call2_argv[] = { |
161 | static cmd_arg_t call2_argv[] = { |
160 | { |
162 | { |
161 | .type = ARG_TYPE_STRING, |
163 | .type = ARG_TYPE_STRING, |
162 | .buffer = call0_buf, |
164 | .buffer = call0_buf, |
163 | .len = sizeof(call0_buf) |
165 | .len = sizeof(call0_buf) |
164 | }, |
166 | }, |
165 | { |
167 | { |
166 | .type = ARG_TYPE_VAR, |
168 | .type = ARG_TYPE_VAR, |
167 | .buffer = carg1_buf, |
169 | .buffer = carg1_buf, |
168 | .len = sizeof(carg1_buf) |
170 | .len = sizeof(carg1_buf) |
169 | }, |
171 | }, |
170 | { |
172 | { |
171 | .type = ARG_TYPE_VAR, |
173 | .type = ARG_TYPE_VAR, |
172 | .buffer = carg2_buf, |
174 | .buffer = carg2_buf, |
173 | .len = sizeof(carg2_buf) |
175 | .len = sizeof(carg2_buf) |
174 | } |
176 | } |
175 | }; |
177 | }; |
176 | static cmd_info_t call2_info = { |
178 | static cmd_info_t call2_info = { |
177 | .name = "call2", |
179 | .name = "call2", |
178 | .description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).", |
180 | .description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).", |
179 | .func = cmd_call2, |
181 | .func = cmd_call2, |
180 | .argc = 3, |
182 | .argc = 3, |
181 | .argv = call2_argv |
183 | .argv = call2_argv |
182 | }; |
184 | }; |
183 | 185 | ||
184 | static int cmd_call3(cmd_arg_t *argv); |
186 | static int cmd_call3(cmd_arg_t *argv); |
185 | static cmd_arg_t call3_argv[] = { |
187 | static cmd_arg_t call3_argv[] = { |
186 | { |
188 | { |
187 | .type = ARG_TYPE_STRING, |
189 | .type = ARG_TYPE_STRING, |
188 | .buffer = call0_buf, |
190 | .buffer = call0_buf, |
189 | .len = sizeof(call0_buf) |
191 | .len = sizeof(call0_buf) |
190 | }, |
192 | }, |
191 | { |
193 | { |
192 | .type = ARG_TYPE_VAR, |
194 | .type = ARG_TYPE_VAR, |
193 | .buffer = carg1_buf, |
195 | .buffer = carg1_buf, |
194 | .len = sizeof(carg1_buf) |
196 | .len = sizeof(carg1_buf) |
195 | }, |
197 | }, |
196 | { |
198 | { |
197 | .type = ARG_TYPE_VAR, |
199 | .type = ARG_TYPE_VAR, |
198 | .buffer = carg2_buf, |
200 | .buffer = carg2_buf, |
199 | .len = sizeof(carg2_buf) |
201 | .len = sizeof(carg2_buf) |
200 | }, |
202 | }, |
201 | { |
203 | { |
202 | .type = ARG_TYPE_VAR, |
204 | .type = ARG_TYPE_VAR, |
203 | .buffer = carg3_buf, |
205 | .buffer = carg3_buf, |
204 | .len = sizeof(carg3_buf) |
206 | .len = sizeof(carg3_buf) |
205 | } |
207 | } |
206 | 208 | ||
207 | }; |
209 | }; |
208 | static cmd_info_t call3_info = { |
210 | static cmd_info_t call3_info = { |
209 | .name = "call3", |
211 | .name = "call3", |
210 | .description = "call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).", |
212 | .description = "call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).", |
211 | .func = cmd_call3, |
213 | .func = cmd_call3, |
212 | .argc = 4, |
214 | .argc = 4, |
213 | .argv = call3_argv |
215 | .argv = call3_argv |
214 | }; |
216 | }; |
215 | 217 | ||
216 | /** Data and methods for 'halt' command. */ |
218 | /** Data and methods for 'halt' command. */ |
217 | static int cmd_halt(cmd_arg_t *argv); |
219 | static int cmd_halt(cmd_arg_t *argv); |
218 | static cmd_info_t halt_info = { |
220 | static cmd_info_t halt_info = { |
219 | .name = "halt", |
221 | .name = "halt", |
220 | .description = "Halt the kernel.", |
222 | .description = "Halt the kernel.", |
221 | .func = cmd_halt, |
223 | .func = cmd_halt, |
222 | .argc = 0 |
224 | .argc = 0 |
223 | }; |
225 | }; |
224 | 226 | ||
225 | /** Initialize kconsole data structures. */ |
227 | /** Initialize kconsole data structures. */ |
226 | void kconsole_init(void) |
228 | void kconsole_init(void) |
227 | { |
229 | { |
228 | spinlock_initialize(&cmd_lock, "kconsole_cmd"); |
230 | spinlock_initialize(&cmd_lock, "kconsole_cmd"); |
229 | list_initialize(&cmd_head); |
231 | list_initialize(&cmd_head); |
230 | 232 | ||
231 | spinlock_initialize(&help_info.lock, "kconsole_help"); |
233 | spinlock_initialize(&help_info.lock, "kconsole_help"); |
232 | link_initialize(&help_info.link); |
234 | link_initialize(&help_info.link); |
233 | if (!cmd_register(&help_info)) |
235 | if (!cmd_register(&help_info)) |
234 | panic("could not register command %s\n", help_info.name); |
236 | panic("could not register command %s\n", help_info.name); |
235 | 237 | ||
236 | 238 | ||
237 | spinlock_initialize(&desc_info.lock, "kconsole_desc"); |
239 | spinlock_initialize(&desc_info.lock, "kconsole_desc"); |
238 | link_initialize(&desc_info.link); |
240 | link_initialize(&desc_info.link); |
239 | if (!cmd_register(&desc_info)) |
241 | if (!cmd_register(&desc_info)) |
240 | panic("could not register command %s\n", desc_info.name); |
242 | panic("could not register command %s\n", desc_info.name); |
241 | 243 | ||
242 | spinlock_initialize(&symaddr_info.lock, "kconsole_symaddr"); |
244 | spinlock_initialize(&symaddr_info.lock, "kconsole_symaddr"); |
243 | link_initialize(&symaddr_info.link); |
245 | link_initialize(&symaddr_info.link); |
244 | if (!cmd_register(&symaddr_info)) |
246 | if (!cmd_register(&symaddr_info)) |
245 | panic("could not register command %s\n", symaddr_info.name); |
247 | panic("could not register command %s\n", symaddr_info.name); |
246 | 248 | ||
247 | spinlock_initialize(&call0_info.lock, "kconsole_call0"); |
249 | spinlock_initialize(&call0_info.lock, "kconsole_call0"); |
248 | link_initialize(&call0_info.link); |
250 | link_initialize(&call0_info.link); |
249 | if (!cmd_register(&call0_info)) |
251 | if (!cmd_register(&call0_info)) |
250 | panic("could not register command %s\n", call0_info.name); |
252 | panic("could not register command %s\n", call0_info.name); |
251 | 253 | ||
252 | spinlock_initialize(&call1_info.lock, "kconsole_call1"); |
254 | spinlock_initialize(&call1_info.lock, "kconsole_call1"); |
253 | link_initialize(&call1_info.link); |
255 | link_initialize(&call1_info.link); |
254 | if (!cmd_register(&call1_info)) |
256 | if (!cmd_register(&call1_info)) |
255 | panic("could not register command %s\n", call1_info.name); |
257 | panic("could not register command %s\n", call1_info.name); |
256 | 258 | ||
257 | 259 | ||
258 | spinlock_initialize(&call2_info.lock, "kconsole_call2"); |
260 | spinlock_initialize(&call2_info.lock, "kconsole_call2"); |
259 | link_initialize(&call2_info.link); |
261 | link_initialize(&call2_info.link); |
260 | if (!cmd_register(&call2_info)) |
262 | if (!cmd_register(&call2_info)) |
261 | panic("could not register command %s\n", call2_info.name); |
263 | panic("could not register command %s\n", call2_info.name); |
262 | 264 | ||
263 | spinlock_initialize(&call3_info.lock, "kconsole_call3"); |
265 | spinlock_initialize(&call3_info.lock, "kconsole_call3"); |
264 | link_initialize(&call3_info.link); |
266 | link_initialize(&call3_info.link); |
265 | if (!cmd_register(&call3_info)) |
267 | if (!cmd_register(&call3_info)) |
266 | panic("could not register command %s\n", call3_info.name); |
268 | panic("could not register command %s\n", call3_info.name); |
267 | 269 | ||
268 | spinlock_initialize(&halt_info.lock, "kconsole_halt"); |
270 | spinlock_initialize(&halt_info.lock, "kconsole_halt"); |
269 | link_initialize(&halt_info.link); |
271 | link_initialize(&halt_info.link); |
270 | if (!cmd_register(&halt_info)) |
272 | if (!cmd_register(&halt_info)) |
271 | panic("could not register command %s\n", halt_info.name); |
273 | panic("could not register command %s\n", halt_info.name); |
- | 274 | ||
- | 275 | spinlock_initialize(&desc_ptlb.lock, "kconsole_ptlb"); |
|
- | 276 | link_initialize(&desc_ptlb.link); |
|
- | 277 | if (!cmd_register(&desc_ptlb)) |
|
- | 278 | panic("could not register command %s\n", desc_ptlb.name); |
|
272 | } |
279 | } |
273 | 280 | ||
274 | 281 | ||
275 | /** Register kconsole command. |
282 | /** Register kconsole command. |
276 | * |
283 | * |
277 | * @param cmd Structure describing the command. |
284 | * @param cmd Structure describing the command. |
278 | * |
285 | * |
279 | * @return 0 on failure, 1 on success. |
286 | * @return 0 on failure, 1 on success. |
280 | */ |
287 | */ |
281 | int cmd_register(cmd_info_t *cmd) |
288 | int cmd_register(cmd_info_t *cmd) |
282 | { |
289 | { |
283 | ipl_t ipl; |
290 | ipl_t ipl; |
284 | link_t *cur; |
291 | link_t *cur; |
285 | 292 | ||
286 | spinlock_lock(&cmd_lock); |
293 | spinlock_lock(&cmd_lock); |
287 | 294 | ||
288 | /* |
295 | /* |
289 | * Make sure the command is not already listed. |
296 | * Make sure the command is not already listed. |
290 | */ |
297 | */ |
291 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
298 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
292 | cmd_info_t *hlp; |
299 | cmd_info_t *hlp; |
293 | 300 | ||
294 | hlp = list_get_instance(cur, cmd_info_t, link); |
301 | hlp = list_get_instance(cur, cmd_info_t, link); |
295 | 302 | ||
296 | if (hlp == cmd) { |
303 | if (hlp == cmd) { |
297 | /* The command is already there. */ |
304 | /* The command is already there. */ |
298 | spinlock_unlock(&cmd_lock); |
305 | spinlock_unlock(&cmd_lock); |
299 | return 0; |
306 | return 0; |
300 | } |
307 | } |
301 | 308 | ||
302 | /* Avoid deadlock. */ |
309 | /* Avoid deadlock. */ |
303 | if (hlp < cmd) { |
310 | if (hlp < cmd) { |
304 | spinlock_lock(&hlp->lock); |
311 | spinlock_lock(&hlp->lock); |
305 | spinlock_lock(&cmd->lock); |
312 | spinlock_lock(&cmd->lock); |
306 | } else { |
313 | } else { |
307 | spinlock_lock(&cmd->lock); |
314 | spinlock_lock(&cmd->lock); |
308 | spinlock_lock(&hlp->lock); |
315 | spinlock_lock(&hlp->lock); |
309 | } |
316 | } |
310 | 317 | ||
311 | if ((strncmp(hlp->name, cmd->name, strlen(cmd->name)) == 0)) { |
318 | if ((strncmp(hlp->name, cmd->name, strlen(cmd->name)) == 0)) { |
312 | /* The command is already there. */ |
319 | /* The command is already there. */ |
313 | spinlock_unlock(&hlp->lock); |
320 | spinlock_unlock(&hlp->lock); |
314 | spinlock_unlock(&cmd->lock); |
321 | spinlock_unlock(&cmd->lock); |
315 | spinlock_unlock(&cmd_lock); |
322 | spinlock_unlock(&cmd_lock); |
316 | return 0; |
323 | return 0; |
317 | } |
324 | } |
318 | 325 | ||
319 | spinlock_unlock(&hlp->lock); |
326 | spinlock_unlock(&hlp->lock); |
320 | spinlock_unlock(&cmd->lock); |
327 | spinlock_unlock(&cmd->lock); |
321 | } |
328 | } |
322 | 329 | ||
323 | /* |
330 | /* |
324 | * Now the command can be added. |
331 | * Now the command can be added. |
325 | */ |
332 | */ |
326 | list_append(&cmd->link, &cmd_head); |
333 | list_append(&cmd->link, &cmd_head); |
327 | 334 | ||
328 | spinlock_unlock(&cmd_lock); |
335 | spinlock_unlock(&cmd_lock); |
329 | return 1; |
336 | return 1; |
330 | } |
337 | } |
331 | 338 | ||
332 | /** Kernel console managing thread. |
339 | /** Kernel console managing thread. |
333 | * |
340 | * |
334 | * @param arg Not used. |
341 | * @param arg Not used. |
335 | */ |
342 | */ |
336 | void kconsole(void *arg) |
343 | void kconsole(void *arg) |
337 | { |
344 | { |
338 | char cmdline[MAX_CMDLINE+1]; |
345 | char cmdline[MAX_CMDLINE+1]; |
339 | cmd_info_t *cmd_info; |
346 | cmd_info_t *cmd_info; |
340 | count_t len; |
347 | count_t len; |
341 | 348 | ||
342 | if (!stdin) { |
349 | if (!stdin) { |
343 | printf("%s: no stdin\n", __FUNCTION__); |
350 | printf("%s: no stdin\n", __FUNCTION__); |
344 | return; |
351 | return; |
345 | } |
352 | } |
346 | 353 | ||
347 | while (true) { |
354 | while (true) { |
348 | printf("%s> ", __FUNCTION__); |
355 | printf("%s> ", __FUNCTION__); |
349 | if (!(len = gets(stdin, cmdline, sizeof(cmdline)))) |
356 | if (!(len = gets(stdin, cmdline, sizeof(cmdline)))) |
350 | continue; |
357 | continue; |
351 | cmdline[len] = '\0'; |
358 | cmdline[len] = '\0'; |
352 | cmd_info = parse_cmdline(cmdline, len); |
359 | cmd_info = parse_cmdline(cmdline, len); |
353 | if (!cmd_info) |
360 | if (!cmd_info) |
354 | continue; |
361 | continue; |
355 | (void) cmd_info->func(cmd_info->argv); |
362 | (void) cmd_info->func(cmd_info->argv); |
356 | } |
363 | } |
357 | } |
364 | } |
358 | 365 | ||
359 | static int parse_int_arg(char *text, size_t len, __native *result) |
366 | static int parse_int_arg(char *text, size_t len, __native *result) |
360 | { |
367 | { |
361 | char symname[MAX_SYMBOL_NAME]; |
368 | char symname[MAX_SYMBOL_NAME]; |
362 | __address symaddr; |
369 | __address symaddr; |
363 | bool isaddr = false; |
370 | bool isaddr = false; |
364 | bool isptr = false; |
371 | bool isptr = false; |
365 | 372 | ||
366 | /* If we get a name, try to find it in symbol table */ |
373 | /* If we get a name, try to find it in symbol table */ |
367 | if (text[0] < '0' | text[0] > '9') { |
374 | if (text[0] < '0' | text[0] > '9') { |
368 | if (text[0] == '&') { |
375 | if (text[0] == '&') { |
369 | isaddr = true; |
376 | isaddr = true; |
370 | text++;len--; |
377 | text++;len--; |
371 | } else if (text[0] == '*') { |
378 | } else if (text[0] == '*') { |
372 | isptr = true; |
379 | isptr = true; |
373 | text++;len--; |
380 | text++;len--; |
374 | } |
381 | } |
375 | strncpy(symname, text, min(len+1, MAX_SYMBOL_NAME)); |
382 | strncpy(symname, text, min(len+1, MAX_SYMBOL_NAME)); |
376 | symaddr = get_symbol_addr(symname); |
383 | symaddr = get_symbol_addr(symname); |
377 | if (!symaddr) { |
384 | if (!symaddr) { |
378 | printf("Symbol %s not found.\n",symname); |
385 | printf("Symbol %s not found.\n",symname); |
379 | return -1; |
386 | return -1; |
380 | } |
387 | } |
381 | if (symaddr == (__address) -1) { |
388 | if (symaddr == (__address) -1) { |
382 | printf("Duplicate symbol %s.\n",symname); |
389 | printf("Duplicate symbol %s.\n",symname); |
383 | symtab_print_search(symname); |
390 | symtab_print_search(symname); |
384 | return -1; |
391 | return -1; |
385 | } |
392 | } |
386 | if (isaddr) |
393 | if (isaddr) |
387 | *result = (__native)symaddr; |
394 | *result = (__native)symaddr; |
388 | else if (isptr) |
395 | else if (isptr) |
389 | *result = **((__native **)symaddr); |
396 | *result = **((__native **)symaddr); |
390 | else |
397 | else |
391 | *result = *((__native *)symaddr); |
398 | *result = *((__native *)symaddr); |
392 | } else /* It's a number - convert it */ |
399 | } else /* It's a number - convert it */ |
393 | *result = atoi(text); |
400 | *result = atoi(text); |
394 | return 0; |
401 | return 0; |
395 | } |
402 | } |
396 | 403 | ||
397 | /** Parse command line. |
404 | /** Parse command line. |
398 | * |
405 | * |
399 | * @param cmdline Command line as read from input device. |
406 | * @param cmdline Command line as read from input device. |
400 | * @param len Command line length. |
407 | * @param len Command line length. |
401 | * |
408 | * |
402 | * @return Structure describing the command. |
409 | * @return Structure describing the command. |
403 | */ |
410 | */ |
404 | cmd_info_t *parse_cmdline(char *cmdline, size_t len) |
411 | cmd_info_t *parse_cmdline(char *cmdline, size_t len) |
405 | { |
412 | { |
406 | index_t start = 0, end = 0; |
413 | index_t start = 0, end = 0; |
407 | cmd_info_t *cmd = NULL; |
414 | cmd_info_t *cmd = NULL; |
408 | link_t *cur; |
415 | link_t *cur; |
409 | ipl_t ipl; |
416 | ipl_t ipl; |
410 | int i; |
417 | int i; |
411 | 418 | ||
412 | if (!parse_argument(cmdline, len, &start, &end)) { |
419 | if (!parse_argument(cmdline, len, &start, &end)) { |
413 | /* Command line did not contain alphanumeric word. */ |
420 | /* Command line did not contain alphanumeric word. */ |
414 | return NULL; |
421 | return NULL; |
415 | } |
422 | } |
416 | 423 | ||
417 | spinlock_lock(&cmd_lock); |
424 | spinlock_lock(&cmd_lock); |
418 | 425 | ||
419 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
426 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
420 | cmd_info_t *hlp; |
427 | cmd_info_t *hlp; |
421 | 428 | ||
422 | hlp = list_get_instance(cur, cmd_info_t, link); |
429 | hlp = list_get_instance(cur, cmd_info_t, link); |
423 | spinlock_lock(&hlp->lock); |
430 | spinlock_lock(&hlp->lock); |
424 | 431 | ||
425 | if (strncmp(hlp->name, &cmdline[start], (end - start) + 1) == 0) { |
432 | if (strncmp(hlp->name, &cmdline[start], (end - start) + 1) == 0) { |
426 | cmd = hlp; |
433 | cmd = hlp; |
427 | break; |
434 | break; |
428 | } |
435 | } |
429 | 436 | ||
430 | spinlock_unlock(&hlp->lock); |
437 | spinlock_unlock(&hlp->lock); |
431 | } |
438 | } |
432 | 439 | ||
433 | spinlock_unlock(&cmd_lock); |
440 | spinlock_unlock(&cmd_lock); |
434 | 441 | ||
435 | if (!cmd) { |
442 | if (!cmd) { |
436 | /* Unknown command. */ |
443 | /* Unknown command. */ |
437 | printf("Unknown command.\n"); |
444 | printf("Unknown command.\n"); |
438 | return NULL; |
445 | return NULL; |
439 | } |
446 | } |
440 | 447 | ||
441 | /* cmd == hlp is locked */ |
448 | /* cmd == hlp is locked */ |
442 | 449 | ||
443 | /* |
450 | /* |
444 | * The command line must be further analyzed and |
451 | * The command line must be further analyzed and |
445 | * the parameters therefrom must be matched and |
452 | * the parameters therefrom must be matched and |
446 | * converted to those specified in the cmd info |
453 | * converted to those specified in the cmd info |
447 | * structure. |
454 | * structure. |
448 | */ |
455 | */ |
449 | 456 | ||
450 | for (i = 0; i < cmd->argc; i++) { |
457 | for (i = 0; i < cmd->argc; i++) { |
451 | char *buf; |
458 | char *buf; |
452 | start = end + 1; |
459 | start = end + 1; |
453 | if (!parse_argument(cmdline, len, &start, &end)) { |
460 | if (!parse_argument(cmdline, len, &start, &end)) { |
454 | printf("Too few arguments.\n"); |
461 | printf("Too few arguments.\n"); |
455 | spinlock_unlock(&cmd->lock); |
462 | spinlock_unlock(&cmd->lock); |
456 | return NULL; |
463 | return NULL; |
457 | } |
464 | } |
458 | 465 | ||
459 | switch (cmd->argv[i].type) { |
466 | switch (cmd->argv[i].type) { |
460 | case ARG_TYPE_STRING: |
467 | case ARG_TYPE_STRING: |
461 | buf = cmd->argv[i].buffer; |
468 | buf = cmd->argv[i].buffer; |
462 | strncpy(buf, (const char *) &cmdline[start], min((end - start) + 2, cmd->argv[i].len)); |
469 | strncpy(buf, (const char *) &cmdline[start], min((end - start) + 2, cmd->argv[i].len)); |
463 | buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0'; |
470 | buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0'; |
464 | break; |
471 | break; |
465 | case ARG_TYPE_INT: |
472 | case ARG_TYPE_INT: |
466 | if (parse_int_arg(cmdline+start, end-start+1, |
473 | if (parse_int_arg(cmdline+start, end-start+1, |
467 | &cmd->argv[i].intval)) |
474 | &cmd->argv[i].intval)) |
468 | return NULL; |
475 | return NULL; |
469 | break; |
476 | break; |
470 | case ARG_TYPE_VAR: |
477 | case ARG_TYPE_VAR: |
471 | if (start != end && cmdline[start] == '"' && cmdline[end] == '"') { |
478 | if (start != end && cmdline[start] == '"' && cmdline[end] == '"') { |
472 | buf = cmd->argv[i].buffer; |
479 | buf = cmd->argv[i].buffer; |
473 | strncpy(buf, (const char *) &cmdline[start+1], |
480 | strncpy(buf, (const char *) &cmdline[start+1], |
474 | min((end-start), cmd->argv[i].len)); |
481 | min((end-start), cmd->argv[i].len)); |
475 | buf[min((end - start), cmd->argv[i].len - 1)] = '\0'; |
482 | buf[min((end - start), cmd->argv[i].len - 1)] = '\0'; |
476 | cmd->argv[i].intval = (__native) buf; |
483 | cmd->argv[i].intval = (__native) buf; |
477 | cmd->argv[i].vartype = ARG_TYPE_STRING; |
484 | cmd->argv[i].vartype = ARG_TYPE_STRING; |
478 | } else if (!parse_int_arg(cmdline+start, end-start+1, |
485 | } else if (!parse_int_arg(cmdline+start, end-start+1, |
479 | &cmd->argv[i].intval)) |
486 | &cmd->argv[i].intval)) |
480 | cmd->argv[i].vartype = ARG_TYPE_INT; |
487 | cmd->argv[i].vartype = ARG_TYPE_INT; |
481 | else { |
488 | else { |
482 | printf("Unrecognized variable argument.\n"); |
489 | printf("Unrecognized variable argument.\n"); |
483 | return NULL; |
490 | return NULL; |
484 | } |
491 | } |
485 | break; |
492 | break; |
486 | case ARG_TYPE_INVALID: |
493 | case ARG_TYPE_INVALID: |
487 | default: |
494 | default: |
488 | printf("invalid argument type\n"); |
495 | printf("invalid argument type\n"); |
489 | return NULL; |
496 | return NULL; |
490 | break; |
497 | break; |
491 | } |
498 | } |
492 | } |
499 | } |
493 | 500 | ||
494 | start = end + 1; |
501 | start = end + 1; |
495 | if (parse_argument(cmdline, len, &start, &end)) { |
502 | if (parse_argument(cmdline, len, &start, &end)) { |
496 | printf("Too many arguments.\n"); |
503 | printf("Too many arguments.\n"); |
497 | spinlock_unlock(&cmd->lock); |
504 | spinlock_unlock(&cmd->lock); |
498 | return NULL; |
505 | return NULL; |
499 | } |
506 | } |
500 | 507 | ||
501 | spinlock_unlock(&cmd->lock); |
508 | spinlock_unlock(&cmd->lock); |
502 | return cmd; |
509 | return cmd; |
503 | } |
510 | } |
504 | 511 | ||
505 | /** Parse argument. |
512 | /** Parse argument. |
506 | * |
513 | * |
507 | * Find start and end positions of command line argument. |
514 | * Find start and end positions of command line argument. |
508 | * |
515 | * |
509 | * @param cmdline Command line as read from the input device. |
516 | * @param cmdline Command line as read from the input device. |
510 | * @param len Number of characters in cmdline. |
517 | * @param len Number of characters in cmdline. |
511 | * @param start On entry, 'start' contains pointer to the index |
518 | * @param start On entry, 'start' contains pointer to the index |
512 | * of first unprocessed character of cmdline. |
519 | * of first unprocessed character of cmdline. |
513 | * On successful exit, it marks beginning of the next argument. |
520 | * On successful exit, it marks beginning of the next argument. |
514 | * @param end Undefined on entry. On exit, 'end' points to the last character |
521 | * @param end Undefined on entry. On exit, 'end' points to the last character |
515 | * of the next argument. |
522 | * of the next argument. |
516 | * |
523 | * |
517 | * @return false on failure, true on success. |
524 | * @return false on failure, true on success. |
518 | */ |
525 | */ |
519 | bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end) |
526 | bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end) |
520 | { |
527 | { |
521 | int i; |
528 | int i; |
522 | bool found_start = false; |
529 | bool found_start = false; |
523 | 530 | ||
524 | ASSERT(start != NULL); |
531 | ASSERT(start != NULL); |
525 | ASSERT(end != NULL); |
532 | ASSERT(end != NULL); |
526 | 533 | ||
527 | for (i = *start; i < len; i++) { |
534 | for (i = *start; i < len; i++) { |
528 | if (!found_start) { |
535 | if (!found_start) { |
529 | if (is_white(cmdline[i])) |
536 | if (is_white(cmdline[i])) |
530 | (*start)++; |
537 | (*start)++; |
531 | else |
538 | else |
532 | found_start = true; |
539 | found_start = true; |
533 | } else { |
540 | } else { |
534 | if (is_white(cmdline[i])) |
541 | if (is_white(cmdline[i])) |
535 | break; |
542 | break; |
536 | } |
543 | } |
537 | } |
544 | } |
538 | *end = i - 1; |
545 | *end = i - 1; |
539 | 546 | ||
540 | return found_start; |
547 | return found_start; |
541 | } |
548 | } |
542 | 549 | ||
543 | 550 | ||
544 | /** List supported commands. |
551 | /** List supported commands. |
545 | * |
552 | * |
546 | * @param argv Argument vector. |
553 | * @param argv Argument vector. |
547 | * |
554 | * |
548 | * @return 0 on failure, 1 on success. |
555 | * @return 0 on failure, 1 on success. |
549 | */ |
556 | */ |
550 | int cmd_help(cmd_arg_t *argv) |
557 | int cmd_help(cmd_arg_t *argv) |
551 | { |
558 | { |
552 | link_t *cur; |
559 | link_t *cur; |
553 | ipl_t ipl; |
560 | ipl_t ipl; |
554 | 561 | ||
555 | spinlock_lock(&cmd_lock); |
562 | spinlock_lock(&cmd_lock); |
556 | 563 | ||
557 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
564 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
558 | cmd_info_t *hlp; |
565 | cmd_info_t *hlp; |
559 | 566 | ||
560 | hlp = list_get_instance(cur, cmd_info_t, link); |
567 | hlp = list_get_instance(cur, cmd_info_t, link); |
561 | spinlock_lock(&hlp->lock); |
568 | spinlock_lock(&hlp->lock); |
562 | 569 | ||
563 | printf("%s - %s\n", hlp->name, hlp->description); |
570 | printf("%s - %s\n", hlp->name, hlp->description); |
564 | 571 | ||
565 | spinlock_unlock(&hlp->lock); |
572 | spinlock_unlock(&hlp->lock); |
566 | } |
573 | } |
567 | 574 | ||
568 | spinlock_unlock(&cmd_lock); |
575 | spinlock_unlock(&cmd_lock); |
569 | 576 | ||
570 | return 1; |
577 | return 1; |
571 | } |
578 | } |
572 | 579 | ||
573 | /** Describe specified command. |
580 | /** Describe specified command. |
574 | * |
581 | * |
575 | * @param argv Argument vector. |
582 | * @param argv Argument vector. |
576 | * |
583 | * |
577 | * @return 0 on failure, 1 on success. |
584 | * @return 0 on failure, 1 on success. |
578 | */ |
585 | */ |
579 | int cmd_desc(cmd_arg_t *argv) |
586 | int cmd_desc(cmd_arg_t *argv) |
580 | { |
587 | { |
581 | link_t *cur; |
588 | link_t *cur; |
582 | ipl_t ipl; |
589 | ipl_t ipl; |
583 | 590 | ||
584 | spinlock_lock(&cmd_lock); |
591 | spinlock_lock(&cmd_lock); |
585 | 592 | ||
586 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
593 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
587 | cmd_info_t *hlp; |
594 | cmd_info_t *hlp; |
588 | 595 | ||
589 | hlp = list_get_instance(cur, cmd_info_t, link); |
596 | hlp = list_get_instance(cur, cmd_info_t, link); |
590 | spinlock_lock(&hlp->lock); |
597 | spinlock_lock(&hlp->lock); |
591 | 598 | ||
592 | if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) { |
599 | if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) { |
593 | printf("%s - %s\n", hlp->name, hlp->description); |
600 | printf("%s - %s\n", hlp->name, hlp->description); |
594 | if (hlp->help) |
601 | if (hlp->help) |
595 | hlp->help(); |
602 | hlp->help(); |
596 | spinlock_unlock(&hlp->lock); |
603 | spinlock_unlock(&hlp->lock); |
597 | break; |
604 | break; |
598 | } |
605 | } |
599 | 606 | ||
600 | spinlock_unlock(&hlp->lock); |
607 | spinlock_unlock(&hlp->lock); |
601 | } |
608 | } |
602 | 609 | ||
603 | spinlock_unlock(&cmd_lock); |
610 | spinlock_unlock(&cmd_lock); |
604 | 611 | ||
605 | return 1; |
612 | return 1; |
606 | } |
613 | } |
607 | 614 | ||
608 | /** Search symbol table */ |
615 | /** Search symbol table */ |
609 | int cmd_symaddr(cmd_arg_t *argv) |
616 | int cmd_symaddr(cmd_arg_t *argv) |
610 | { |
617 | { |
611 | __address symaddr; |
618 | __address symaddr; |
612 | char *symbol; |
619 | char *symbol; |
613 | 620 | ||
614 | symtab_print_search(argv->buffer); |
621 | symtab_print_search(argv->buffer); |
615 | 622 | ||
616 | return 1; |
623 | return 1; |
617 | } |
624 | } |
618 | 625 | ||
619 | /** Call function with zero parameters */ |
626 | /** Call function with zero parameters */ |
620 | int cmd_call0(cmd_arg_t *argv) |
627 | int cmd_call0(cmd_arg_t *argv) |
621 | { |
628 | { |
622 | __address symaddr; |
629 | __address symaddr; |
623 | char *symbol; |
630 | char *symbol; |
624 | __native (*f)(void); |
631 | __native (*f)(void); |
625 | 632 | ||
626 | symaddr = get_symbol_addr(argv->buffer); |
633 | symaddr = get_symbol_addr(argv->buffer); |
627 | if (!symaddr) |
634 | if (!symaddr) |
628 | printf("Symbol %s not found.\n", argv->buffer); |
635 | printf("Symbol %s not found.\n", argv->buffer); |
629 | else if (symaddr == (__address) -1) { |
636 | else if (symaddr == (__address) -1) { |
630 | symtab_print_search(argv->buffer); |
637 | symtab_print_search(argv->buffer); |
631 | printf("Duplicate symbol, be more specific.\n"); |
638 | printf("Duplicate symbol, be more specific.\n"); |
632 | } else { |
639 | } else { |
633 | symbol = get_symtab_entry(symaddr); |
640 | symbol = get_symtab_entry(symaddr); |
634 | printf("Calling f(): 0x%p: %s\n", symaddr, symbol); |
641 | printf("Calling f(): 0x%p: %s\n", symaddr, symbol); |
635 | f = (__native (*)(void)) symaddr; |
642 | f = (__native (*)(void)) symaddr; |
636 | printf("Result: 0x%X\n", f()); |
643 | printf("Result: 0x%X\n", f()); |
637 | } |
644 | } |
638 | 645 | ||
639 | return 1; |
646 | return 1; |
640 | } |
647 | } |
641 | 648 | ||
642 | /** Call function with one parameter */ |
649 | /** Call function with one parameter */ |
643 | int cmd_call1(cmd_arg_t *argv) |
650 | int cmd_call1(cmd_arg_t *argv) |
644 | { |
651 | { |
645 | __address symaddr; |
652 | __address symaddr; |
646 | char *symbol; |
653 | char *symbol; |
647 | __native (*f)(__native); |
654 | __native (*f)(__native); |
648 | __native arg1 = argv[1].intval; |
655 | __native arg1 = argv[1].intval; |
649 | 656 | ||
650 | symaddr = get_symbol_addr(argv->buffer); |
657 | symaddr = get_symbol_addr(argv->buffer); |
651 | if (!symaddr) |
658 | if (!symaddr) |
652 | printf("Symbol %s not found.\n", argv->buffer); |
659 | printf("Symbol %s not found.\n", argv->buffer); |
653 | else if (symaddr == (__address) -1) { |
660 | else if (symaddr == (__address) -1) { |
654 | symtab_print_search(argv->buffer); |
661 | symtab_print_search(argv->buffer); |
655 | printf("Duplicate symbol, be more specific.\n"); |
662 | printf("Duplicate symbol, be more specific.\n"); |
656 | } else { |
663 | } else { |
657 | symbol = get_symtab_entry(symaddr); |
664 | symbol = get_symtab_entry(symaddr); |
658 | printf("Calling f(0x%x): 0x%p: %s\n", arg1, symaddr, symbol); |
665 | printf("Calling f(0x%x): 0x%p: %s\n", arg1, symaddr, symbol); |
659 | f = (__native (*)(__native)) symaddr; |
666 | f = (__native (*)(__native)) symaddr; |
660 | printf("Result: 0x%x\n", f(arg1)); |
667 | printf("Result: 0x%x\n", f(arg1)); |
661 | } |
668 | } |
662 | 669 | ||
663 | return 1; |
670 | return 1; |
664 | } |
671 | } |
665 | 672 | ||
666 | /** Call function with two parameters */ |
673 | /** Call function with two parameters */ |
667 | int cmd_call2(cmd_arg_t *argv) |
674 | int cmd_call2(cmd_arg_t *argv) |
668 | { |
675 | { |
669 | __address symaddr; |
676 | __address symaddr; |
670 | char *symbol; |
677 | char *symbol; |
671 | __native (*f)(__native,__native); |
678 | __native (*f)(__native,__native); |
672 | __native arg1 = argv[1].intval; |
679 | __native arg1 = argv[1].intval; |
673 | __native arg2 = argv[2].intval; |
680 | __native arg2 = argv[2].intval; |
674 | 681 | ||
675 | symaddr = get_symbol_addr(argv->buffer); |
682 | symaddr = get_symbol_addr(argv->buffer); |
676 | if (!symaddr) |
683 | if (!symaddr) |
677 | printf("Symbol %s not found.\n", argv->buffer); |
684 | printf("Symbol %s not found.\n", argv->buffer); |
678 | else if (symaddr == (__address) -1) { |
685 | else if (symaddr == (__address) -1) { |
679 | symtab_print_search(argv->buffer); |
686 | symtab_print_search(argv->buffer); |
680 | printf("Duplicate symbol, be more specific.\n"); |
687 | printf("Duplicate symbol, be more specific.\n"); |
681 | } else { |
688 | } else { |
682 | symbol = get_symtab_entry(symaddr); |
689 | symbol = get_symtab_entry(symaddr); |
683 | printf("Calling f(0x%x,0x%x): 0x%p: %s\n", |
690 | printf("Calling f(0x%x,0x%x): 0x%p: %s\n", |
684 | arg1, arg2, symaddr, symbol); |
691 | arg1, arg2, symaddr, symbol); |
685 | f = (__native (*)(__native,__native)) symaddr; |
692 | f = (__native (*)(__native,__native)) symaddr; |
686 | printf("Result: 0x%x\n", f(arg1, arg2)); |
693 | printf("Result: 0x%x\n", f(arg1, arg2)); |
687 | } |
694 | } |
688 | 695 | ||
689 | return 1; |
696 | return 1; |
690 | } |
697 | } |
691 | 698 | ||
692 | /** Call function with three parameters */ |
699 | /** Call function with three parameters */ |
693 | int cmd_call3(cmd_arg_t *argv) |
700 | int cmd_call3(cmd_arg_t *argv) |
694 | { |
701 | { |
695 | __address symaddr; |
702 | __address symaddr; |
696 | char *symbol; |
703 | char *symbol; |
697 | __native (*f)(__native,__native,__native); |
704 | __native (*f)(__native,__native,__native); |
698 | __native arg1 = argv[1].intval; |
705 | __native arg1 = argv[1].intval; |
699 | __native arg2 = argv[2].intval; |
706 | __native arg2 = argv[2].intval; |
700 | __native arg3 = argv[3].intval; |
707 | __native arg3 = argv[3].intval; |
701 | 708 | ||
702 | symaddr = get_symbol_addr(argv->buffer); |
709 | symaddr = get_symbol_addr(argv->buffer); |
703 | if (!symaddr) |
710 | if (!symaddr) |
704 | printf("Symbol %s not found.\n", argv->buffer); |
711 | printf("Symbol %s not found.\n", argv->buffer); |
705 | else if (symaddr == (__address) -1) { |
712 | else if (symaddr == (__address) -1) { |
706 | symtab_print_search(argv->buffer); |
713 | symtab_print_search(argv->buffer); |
707 | printf("Duplicate symbol, be more specific.\n"); |
714 | printf("Duplicate symbol, be more specific.\n"); |
708 | } else { |
715 | } else { |
709 | symbol = get_symtab_entry(symaddr); |
716 | symbol = get_symtab_entry(symaddr); |
710 | printf("Calling f(0x%x,0x%x, 0x%x): 0x%p: %s\n", |
717 | printf("Calling f(0x%x,0x%x, 0x%x): 0x%p: %s\n", |
711 | arg1, arg2, arg3, symaddr, symbol); |
718 | arg1, arg2, arg3, symaddr, symbol); |
712 | f = (__native (*)(__native,__native,__native)) symaddr; |
719 | f = (__native (*)(__native,__native,__native)) symaddr; |
713 | printf("Result: 0x%x\n", f(arg1, arg2, arg3)); |
720 | printf("Result: 0x%x\n", f(arg1, arg2, arg3)); |
714 | } |
721 | } |
715 | 722 | ||
716 | return 1; |
723 | return 1; |
717 | } |
724 | } |
718 | 725 | ||
719 | 726 | ||
720 | /** Print detailed description of 'describe' command. */ |
727 | /** Print detailed description of 'describe' command. */ |
721 | void desc_help(void) |
728 | void desc_help(void) |
722 | { |
729 | { |
723 | printf("Syntax: describe command_name\n"); |
730 | printf("Syntax: describe command_name\n"); |
724 | } |
731 | } |
725 | 732 | ||
726 | /** Halt the kernel. |
733 | /** Halt the kernel. |
727 | * |
734 | * |
728 | * @param argv Argument vector (ignored). |
735 | * @param argv Argument vector (ignored). |
729 | * |
736 | * |
730 | * @return 0 on failure, 1 on success (never returns). |
737 | * @return 0 on failure, 1 on success (never returns). |
731 | */ |
738 | */ |
732 | int cmd_halt(cmd_arg_t *argv) |
739 | int cmd_halt(cmd_arg_t *argv) |
733 | { |
740 | { |
734 | halt(); |
741 | halt(); |
735 | return 1; |
742 | return 1; |
736 | } |
743 | } |
737 | 744 |