2 * This software is part of the SBCL system. See the README file for
5 * This software is derived from the CMU CL system, which was
6 * written at Carnegie Mellon University and released into the
7 * public domain. The software is in the public domain and is
8 * provided with absolutely no warranty. See the COPYING and CREDITS
9 * files for more information.
26 #include "interrupt.h"
32 static void skip_ws(char **ptr)
34 while (**ptr <= ' ' && **ptr != '\0')
38 static boolean string_to_long(char *token, long *value)
48 if (token[1] == 'x') {
56 else if (token[0] == '#') {
77 while (*ptr != '\0') {
78 if (*ptr >= 'a' && *ptr <= 'f')
79 digit = *ptr + 10 - 'a';
80 else if (*ptr >= 'A' && *ptr <= 'F')
81 digit = *ptr + 10 - 'A';
82 else if (*ptr >= '0' && *ptr <= '9')
86 if (digit < 0 || digit >= base)
90 num = num * base + digit;
97 static boolean lookup_variable(char *name, lispobj *result)
99 struct var *var = lookup_by_name(name);
104 *result = var_value(var);
121 char *parse_token(ptr)
145 static boolean number_p(token)
153 okay = "abcdefABCDEF987654321d0";
156 if (token[1] == 'x' || token[1] == 'X')
162 else if (token[0] == '#') {
178 while (*token != '\0')
179 if (index(okay, *token++) == NULL)
185 long parse_number(ptr)
188 char *token = parse_token(ptr);
192 printf("expected a number\n");
195 else if (string_to_long(token, &result))
198 printf("invalid number: ``%s''\n", token);
204 char *parse_addr(ptr)
207 char *token = parse_token(ptr);
211 printf("expected an address\n");
214 else if (token[0] == '$') {
215 if (!lookup_variable(token+1, (lispobj *)&result)) {
216 printf("unknown variable: ``%s''\n", token);
222 if (!string_to_long(token, &result)) {
223 printf("invalid number: ``%s''\n", token);
229 if (!is_valid_lisp_addr((os_vm_address_t)result)) {
230 printf("invalid Lisp-level address: 0x%lx\n", result);
234 return (char *)result;
237 static boolean lookup_symbol(char *name, lispobj *result)
242 /* Search static space. */
243 headerptr = static_space;
244 count = ((lispobj *) SymbolValue(STATIC_SPACE_FREE_POINTER) -
246 if (search_for_symbol(name, &headerptr, &count)) {
247 *result = (lispobj)headerptr | type_OtherPointer;
251 /* Search dynamic space. */
252 headerptr = current_dynamic_space;
253 #if !defined(ibmrt) && !defined(__i386__)
254 count = current_dynamic_space_free_pointer - current_dynamic_space;
256 count = (lispobj *)SymbolValue(ALLOCATION_POINTER) - current_dynamic_space;
258 if (search_for_symbol(name, &headerptr, &count)) {
259 *result = (lispobj)headerptr | type_OtherPointer;
267 parse_regnum(char *s)
269 if ((s[1] == 'R') || (s[1] == 'r')) {
275 /* skip the $R part and call atoi on the number */
276 regnum = atoi(s + 2);
277 if ((regnum >= 0) && (regnum < NREGS))
284 for (i = 0; i < NREGS ; i++)
285 if (strcasecmp(s + 1, lisp_register_names[i]) == 0)
296 lispobj parse_lispobj(ptr)
299 char *token = parse_token(ptr);
304 printf("expected an object\n");
306 } else if (token[0] == '$') {
307 if (isalpha(token[1])) {
310 os_context_t *context;
312 free = SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX)>>2;
315 printf("Variable ``%s'' is not valid -- there is no current interrupt context.\n", token);
319 context = lisp_interrupt_contexts[free - 1];
321 regnum = parse_regnum(token);
323 printf("bogus register: ``%s''\n", token);
327 result = *os_context_register_addr(context, regnum);
328 } else if (!lookup_variable(token+1, &result)) {
329 printf("unknown variable: ``%s''\n", token);
332 } else if (token[0] == '@') {
333 if (string_to_long(token+1, &pointer)) {
335 if (is_valid_lisp_addr((os_vm_address_t)pointer))
336 result = *(lispobj *)pointer;
338 printf("invalid Lisp-level address: ``%s''\n", token+1);
343 printf("invalid address: ``%s''\n", token+1);
347 else if (string_to_long(token, (long *)&result))
349 else if (lookup_symbol(token, &result))
352 printf("invalid Lisp object: ``%s''\n", token);