8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / efcode / engine / package.c
blobbe241d01ac0889dad2cdcbc54eef645da799b336
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <stddef.h>
31 #include <string.h>
33 #include <fcode/private.h>
34 #include <fcode/log.h>
36 #include <fcdriver/fcdriver.h>
38 #define MIN_VALUES 100
40 static void
41 check_my_self(fcode_env_t *env, char *fn)
43 if (!MYSELF)
44 forth_abort(env, "%s: MYSELF is NULL", fn);
47 uint_t
48 get_number_of_parent_address_cells(fcode_env_t *env)
50 uint_t ncells;
51 device_t *d;
52 static char func_name[] = "get_number_of_parent_address_cells";
54 if (MYSELF == NULL) /* Kludge for testing */
55 return (2);
56 d = MYSELF->device;
57 ncells = d->parent_adr_cells;
58 if (ncells == 0) {
59 ncells = get_default_intprop(env, "#address-cells", d->parent,
60 2);
61 if (ncells > MAX_MY_ADDR) {
62 log_message(MSG_ERROR, "%s: %s:"
63 " ncells (%d) > MAX_MY_ADDR (%d)\n", func_name,
64 get_path(env, d->parent), ncells, MAX_MY_ADDR);
65 ncells = MAX_MY_ADDR;
67 d->parent_adr_cells = ncells;
69 return (ncells);
72 instance_t *
73 create_ihandle(fcode_env_t *env, device_t *phandle, instance_t *parent)
75 instance_t *ihandle;
76 int i;
78 ihandle = MALLOC(sizeof (instance_t));
80 i = max(phandle->data_size[INIT_DATA], MIN_VALUES);
81 ihandle->data[INIT_DATA] = MALLOC(sizeof (fstack_t) * i);
82 memcpy(ihandle->data[INIT_DATA], phandle->init_data,
83 (size_t) (sizeof (fstack_t) * i));
85 i = max(phandle->data_size[UINIT_DATA], MIN_VALUES);
86 ihandle->data[UINIT_DATA] = MALLOC(sizeof (fstack_t) * i);
88 ihandle->my_space = phandle->my_space;
89 memcpy(ihandle->my_addr, phandle->my_addr, sizeof (ihandle->my_addr));
90 ihandle->parent = parent;
91 ihandle->device = phandle;
92 return (ihandle);
95 device_t *
96 create_phandle(fcode_env_t *env, device_t *parent)
98 device_t *phandle;
100 phandle = MALLOC(sizeof (device_t));
101 phandle->init_data = MALLOC(sizeof (fstack_t) * MIN_VALUES);
102 phandle->data_size[INIT_DATA] = 0;
103 phandle->data_size[UINIT_DATA] = 0;
104 phandle->parent = parent;
105 return (phandle);
109 static void
110 do_push_package(fcode_env_t *env, device_t *d)
112 do_previous(env);
113 do_also(env);
114 if (d != NULL) {
115 CONTEXT = (token_t *)(&d->vocabulary);
116 debug_msg(DEBUG_CONTEXT, "CONTEXT:push_package: %s%d/%p/%p\n",
117 get_path(env, d), env->order_depth, CONTEXT, env->current);
121 static void
122 push_package(fcode_env_t *env)
124 device_t *d;
125 phandle_t ph;
127 CHECK_DEPTH(env, 1, "push-package");
128 ph = POP(DS);
129 CONVERT_PHANDLE(env, d, ph);
130 do_push_package(env, d);
133 static void
134 pop_package(fcode_env_t *env)
136 do_previous(env);
137 do_definitions(env);
140 static void
141 interpose(fcode_env_t *env)
143 TODO; /* interpose - not yet implemented */
146 void
147 activate_device(fcode_env_t *env, device_t *d)
149 env->current_device = d;
150 do_push_package(env, d);
151 do_definitions(env);
154 void
155 deactivate_device(fcode_env_t *env, device_t *d)
157 env->current_device = d;
158 do_previous(env);
159 if (d != NULL) {
160 CONTEXT = (token_t *)(&d->vocabulary);
161 debug_msg(DEBUG_CONTEXT, "CONTEXT:deactivate_device:"
162 " %s%d/%p/%p\n", get_path(env, d), env->order_depth,
163 CONTEXT, env->current);
165 do_definitions(env);
169 * Starfire hack to set '/' device_type to 'upa'
171 #include <sys/systeminfo.h>
172 static void
173 starfire_hack(fcode_env_t *env)
175 char platform[100];
177 sysinfo(SI_PLATFORM, platform, sizeof (platform));
178 if (strcmp(platform, "SUNW,Ultra-Enterprise-10000") == 0 &&
179 find_property(env->root_node, "device_type") == NULL) {
180 create_string_prop(env, "device_type", "upa");
184 void
185 root_node(fcode_env_t *env)
187 do_also(env);
188 activate_device(env, env->root_node);
189 starfire_hack(env);
192 void
193 child_node(fcode_env_t *env)
195 device_t *d;
197 CHECK_DEPTH(env, 1, "child");
198 CONVERT_PHANDLE(env, d, TOS);
199 TOS = (fstack_t)d->child;
200 REVERT_PHANDLE(env, TOS, d->child);
203 void
204 peer_node(fcode_env_t *env)
206 device_t *d;
208 CHECK_DEPTH(env, 1, "peer");
209 CONVERT_PHANDLE(env, d, TOS);
210 REVERT_PHANDLE(env, TOS, d->peer);
213 void
214 new_device(fcode_env_t *env)
216 device_t *phandle, *parent;
217 device_t *peer;
219 check_my_self(env, "new-device");
221 parent = MYSELF->device;
222 phandle = create_phandle(env, parent);
223 MYSELF = create_ihandle(env, phandle, MYSELF);
224 activate_device(env, phandle);
225 if (parent->child) {
226 /* Insert new child at end of peer list */
227 for (peer = parent->child; peer->peer; peer = peer->peer)
229 peer->peer = phandle;
230 } else
231 parent->child = phandle; /* First child */
232 ALLOCATE_PHANDLE(env);
235 void
236 finish_device(fcode_env_t *env)
238 fstack_t *mem;
239 device_t *my_dev, *parent_dev;
240 instance_t *parent, *myself = MYSELF;
241 int n;
243 check_my_self(env, "finish-device");
244 ASSERT(myself->device);
245 ASSERT(env->current_device);
246 n = myself->device->data_size[INIT_DATA];
249 * Paranoia.. reserve a little more instance data than we need
251 mem = MALLOC(sizeof (fstack_t) * (n+8));
252 memcpy(mem, MYSELF->device->init_data, sizeof (fstack_t) * n);
253 FREE(myself->device->init_data);
254 my_dev = myself->device;
255 my_dev->init_data = mem;
256 parent = MYSELF->parent;
257 parent_dev = env->current_device->parent;
258 FREE(MYSELF);
259 MYSELF = parent;
260 activate_device(env, parent_dev);
263 static void
264 create_internal_value(fcode_env_t *env, char *name, int offset, int token)
266 header(env, name, strlen(name), 0);
267 COMPILE_TOKEN(&noop);
268 EXPOSE_ACF;
269 if (token) {
270 SET_TOKEN(token, 0, name, LINK_TO_ACF(env->lastlink));
272 PUSH(DS, offset);
273 lcomma(env);
274 set_internal_value_actions(env);
277 static void
278 create_my_self(fcode_env_t *env)
280 int offset = offsetof(fcode_env_t, my_self);
282 create_internal_value(env, "my-self", offset, 0x203);
285 static void
286 create_my_space(fcode_env_t *env)
288 int offset = offsetof(instance_t, my_space);
290 create_internal_value(env, "my-space", -offset, 0x103);
293 void
294 my_address(fcode_env_t *env)
296 fstack_t *adr_ptr;
297 uint_t ncells;
299 check_my_self(env, "my-address");
300 ncells = get_number_of_parent_address_cells(env);
301 adr_ptr = MYSELF->my_addr;
302 while (--ncells) {
303 PUSH(DS, *adr_ptr);
304 adr_ptr++;
308 void
309 my_unit(fcode_env_t *env)
311 check_my_self(env, "my-unit");
312 my_address(env);
313 PUSH(DS, MYSELF->my_space);
316 static void
317 my_args(fcode_env_t *env)
319 check_my_self(env, "my-args");
320 PUSH(DS, (fstack_t)MYSELF->my_args);
321 PUSH(DS, (fstack_t)MYSELF->my_args_len);
325 call_my_parent(fcode_env_t *env, char *method)
327 push_a_string(env, method);
328 dollar_call_parent(env);
329 return (env->last_error);
332 void
333 set_args(fcode_env_t *env)
335 int args_len;
336 common_data_t *cdp;
337 uint_t ncells;
338 fstack_t *adr_ptr, *adr_ptr1, space;
340 CHECK_DEPTH(env, 4, "set-args");
342 check_my_self(env, "set-args");
345 * Handle args argument of set-args.
347 if (MYSELF->my_args) {
348 FREE(MYSELF->my_args);
349 MYSELF->my_args = NULL;
351 two_swap(env);
352 MYSELF->my_args = pop_a_duped_string(env, &args_len);
353 MYSELF->my_args_len = args_len;
355 if (call_my_parent(env, "decode-unit"))
356 forth_abort(env, "set-args: decode-unit failed");
358 ncells = get_number_of_parent_address_cells(env);
361 * Kludge: For GP2, my-space comes from decode-unit hi.address.
362 * for PCI, my-space from decode-unit won't have the bus#, so we need
363 * to get it from config_address. Unfortunately, there is no easy
364 * way to figure out here which one we're looking at. We take the
365 * expediant of or'ing the two values together.
367 space = POP(DS); /* pop phys.hi */
368 if ((cdp = (common_data_t *)env->private) != NULL)
369 space |= cdp->fc.config_address;
371 MYSELF->device->my_space = MYSELF->my_space = space;
373 adr_ptr = MYSELF->my_addr;
374 adr_ptr1 = MYSELF->device->my_addr;
375 while (--ncells) {
376 *adr_ptr++ = *adr_ptr1++ = POP(DS);
380 void
381 my_parent(fcode_env_t *env)
383 check_my_self(env, "my-parent");
384 PUSH(DS, (fstack_t)MYSELF->parent);
387 instance_t *
388 open_instance_chain(fcode_env_t *env, device_t *phandle, int exec)
390 instance_t *parent;
392 if (!phandle)
393 return (NULL);
394 parent = open_instance_chain(env, phandle->parent, exec);
395 return (create_ihandle(env, phandle, parent));
398 void
399 close_instance_chain(fcode_env_t *env, instance_t *ihandle, int exec)
401 instance_t *parent;
403 if (ihandle) {
404 parent = ihandle->parent;
405 close_instance_chain(env, parent, exec);
406 if (ihandle->my_args)
407 FREE(ihandle->my_args);
408 FREE(ihandle);
412 void
413 begin_package(fcode_env_t *env)
415 fstack_t ok;
416 char *name;
418 CHECK_DEPTH(env, 6, "begin-package");
419 two_dup(env);
420 name = pop_a_string(env, NULL);
421 find_package(env);
422 ok = POP(DS);
423 if (ok) {
424 PUSH(DS, 0);
425 PUSH(DS, 0);
426 rot(env);
427 open_package(env);
428 MYSELF = (instance_t *)POP(DS);
429 check_my_self(env, "begin-package");
430 new_device(env);
431 set_args(env);
432 } else {
433 log_message(MSG_INFO, "Package '%s' not found\n", name);
437 void
438 open_package(fcode_env_t *env)
440 device_t *phandle;
441 instance_t *ihandle;
442 int len;
444 CHECK_DEPTH(env, 3, "open-package");
445 CONVERT_PHANDLE(env, phandle, POP(DS));
446 ihandle = open_instance_chain(env, phandle, 1);
447 ihandle->my_args = pop_a_duped_string(env, &len);
448 ihandle->my_args_len = len;
449 PUSH(DS, (fstack_t)ihandle);
452 void
453 dollar_open_package(fcode_env_t *env)
455 fstack_t ok;
457 CHECK_DEPTH(env, 4, "$open-package");
458 find_package(env);
459 ok = POP(DS);
460 if (ok) {
461 open_package(env);
462 } else {
463 (void) POP(DS);
464 (void) POP(DS);
465 PUSH(DS, 0);
469 void
470 close_package(fcode_env_t *env)
472 instance_t *ihandle;
474 CHECK_DEPTH(env, 1, "close-package");
475 ihandle = (instance_t *)POP(DS);
476 close_instance_chain(env, ihandle, 1);
479 static void (*find_method_hook)(fcode_env_t *);
481 void
482 set_find_method_hook(fcode_env_t *env, void (*hook)(fcode_env_t *))
484 find_method_hook = hook;
487 void
488 find_method(fcode_env_t *env)
490 fstack_t d;
491 device_t *device;
492 acf_t acf = 0;
494 CHECK_DEPTH(env, 3, "find-method");
495 if (find_method_hook) {
496 (*find_method_hook)(env);
497 if (TOS) /* Found it */
498 return;
499 POP(DS);
502 d = POP(DS);
503 CONVERT_PHANDLE(env, device, d);
504 PUSH(DS, (fstack_t)&device->vocabulary);
505 acf = voc_find(env);
506 PUSH(DS, (fstack_t)acf);
507 if (acf) {
508 PUSH(DS, TRUE);
513 * 'call-package' Fcode
515 void
516 call_package(fcode_env_t *env)
518 instance_t *ihandle, *saved_myself;
520 CHECK_DEPTH(env, 2, "call-package");
521 ihandle = (instance_t *)POP(DS);
522 saved_myself = MYSELF;
523 MYSELF = ihandle;
524 execute(env);
525 MYSELF = saved_myself;
528 void
529 ihandle_to_phandle(fcode_env_t *env)
531 instance_t *i;
533 CHECK_DEPTH(env, 1, "ihandle>phandle");
534 i = (instance_t *)TOS;
535 REVERT_PHANDLE(env, TOS, i->device);
538 char *
539 get_package_name(fcode_env_t *env, device_t *d)
541 char *name;
542 prop_t *prop;
544 prop = lookup_package_property(env, "name", d);
545 if (prop == NULL) {
546 name = "<Unnamed>";
547 } else {
548 name = (char *)prop->data;
550 return (name);
553 static char *package_search_path = "/packages:/openprom";
555 device_t *
556 match_package_path(fcode_env_t *env, char *path)
558 device_t *d;
559 char *name;
560 int len;
562 if (*path == '/') {
563 d = env->root_node->child;
564 path++;
565 } else
566 d = env->current_device;
567 while (*path != '\0' && d != NULL) {
568 name = get_package_name(env, d);
569 len = strlen(name);
570 if (strncmp(name, path, len) == 0) {
571 path += len;
572 if (*path == '\0') {
573 return (d);
575 /* skip the '/' */
576 if (*path++ != '/')
577 break;
578 d = d->child;
579 } else {
580 d = d->peer;
583 return (NULL);
586 device_t *
587 locate_package(fcode_env_t *env, char *start)
589 device_t *d;
590 char *p, *next_p;
591 char *tpath, *fpath;
593 if ((d = match_package_path(env, start)) != NULL)
594 return (d);
597 * ignore starting '/'
599 if (*start == '/')
600 *start++;
602 fpath = STRDUP(package_search_path);
603 for (p = fpath; p != NULL; p = next_p) {
604 if ((next_p = strchr(p, ':')) != NULL)
605 *next_p++ = '\0';
606 tpath = MALLOC(strlen(p) + strlen(start) + 2);
607 sprintf(tpath, "%s/%s", p, start);
608 if ((d = match_package_path(env, tpath)) != NULL) {
609 FREE(fpath);
610 FREE(tpath);
611 return (d);
613 FREE(tpath);
615 FREE(fpath);
616 return (NULL);
619 void
620 find_package(fcode_env_t *env)
622 char *path;
623 device_t *package;
624 fstack_t ph = 0;
626 CHECK_DEPTH(env, 2, "find-package");
627 if ((path = pop_a_duped_string(env, NULL)) != NULL) {
628 if (strcmp(path, "/") == 0)
629 package = env->root_node;
630 else
631 package = locate_package(env, path);
632 FREE(path);
633 REVERT_PHANDLE(env, ph, package);
635 PUSH(DS, ph);
636 if (package)
637 PUSH(DS, TRUE);
640 static void
641 encode_unit_hack(fcode_env_t *env)
643 int hi, i;
644 uint_t ncells = get_number_of_parent_address_cells(env);
646 for (i = 0; i < ncells; i++)
647 POP(DS);
648 push_a_string(env, NULL);
651 void
652 dollar_call_method(fcode_env_t *env)
654 instance_t *old_myself;
655 instance_t *myself;
656 device_t *device;
657 char *method;
659 CHECK_DEPTH(env, 3, "$call-method");
660 check_my_self(env, "$call-method");
661 old_myself = MYSELF;
662 myself = (instance_t *)POP(DS);
664 method = (char *)DS[-1];
665 debug_msg(DEBUG_CALL_METHOD, "$call_method %s\n", method);
667 if (old_myself && !myself) {
668 /* We hit the root of our tree */
669 device = old_myself->device;
670 return;
673 MYSELF = myself;
674 check_my_self(env, "$call-method");
675 device = MYSELF->device;
676 do_push_package(env, device);
677 PUSH(DS, (fstack_t)device);
678 REVERT_PHANDLE(env, TOS, device);
679 find_method(env);
680 if (TOS) {
681 (void) POP(DS);
682 execute(env);
683 } else if (strcmp(method, "encode-unit") == 0) {
684 encode_unit_hack(env);
685 } else {
686 throw_from_fclib(env, 1, "Unimplemented package method: %s%s",
687 get_path(env, device), method);
689 MYSELF = old_myself;
690 do_push_package(env, MYSELF->device);
693 void
694 dollar_call_parent(fcode_env_t *env)
696 CHECK_DEPTH(env, 2, "$call-parent");
698 check_my_self(env, "$call-parent");
700 PUSH(DS, (fstack_t)MYSELF->parent);
701 dollar_call_method(env);
704 #ifdef DEBUG
705 void
706 current_device(fcode_env_t *env)
708 PUSH(DS, (fstack_t)&env->current_device);
711 char *
712 get_path(fcode_env_t *env, device_t *d)
714 char *pre_path, *name, *path;
715 int n;
717 if (d->parent)
718 pre_path = get_path(env, d->parent);
719 else
720 pre_path = STRDUP("");
722 name = get_package_name(env, d);
723 n = strlen(pre_path) + strlen(name) + 1;
724 path = MALLOC(n);
725 strcpy(path, pre_path);
726 strcat(path, name);
727 if (d->child && d->parent)
728 strcat(path, "/");
729 FREE(pre_path);
730 return (path);
733 static void
734 pwd_dollar(fcode_env_t *env)
736 if (env->current_device)
737 push_a_string(env, get_path(env, env->current_device));
738 else
739 push_a_string(env, NULL);
742 void
743 pwd(fcode_env_t *env)
745 if (env->current_device) {
746 log_message(MSG_INFO, "%s\n",
747 get_path(env, env->current_device));
748 } else {
749 log_message(MSG_INFO, "No device context\n");
753 void
754 do_ls(fcode_env_t *env)
756 device_t *d;
758 if (env->current_device == NULL) {
759 log_message(MSG_INFO, "No device context\n");
760 return;
763 d = env->current_device->child;
764 while (d) {
765 char *name;
766 fstack_t ph;
767 name = get_package_name(env, d);
768 REVERT_PHANDLE(env, ph, d);
769 log_message(MSG_INFO, "%llx %s\n", (uint64_t)ph, name);
770 d = d->peer;
774 void
775 paren_cd(fcode_env_t *env)
777 char *str;
778 device_t *p;
780 str = pop_a_string(env, NULL);
781 if (strcmp(str, "/") == 0) {
782 root_node(env);
783 return;
786 if (env->current_device == NULL) {
787 log_message(MSG_INFO, "No device context\n");
788 return;
791 if (strcmp(str, "..") == 0)
792 p = env->current_device->parent;
793 else {
794 device_t *n = env->current_device->child;
796 p = NULL;
797 while (n) {
798 char *name;
800 name = get_package_name(env, n);
801 if (strcmp(name, str) == 0) {
802 p = n;
803 break;
805 n = n->peer;
809 if (p) {
810 activate_device(env, p);
811 } else {
812 log_message(MSG_INFO, "No such node: %s\n", str);
816 void
817 do_cd(fcode_env_t *env)
819 parse_word(env);
820 paren_cd(env);
823 void
824 do_unselect_dev(fcode_env_t *env)
826 check_my_self(env, "unselect-dev");
827 PUSH(DS, (fstack_t)MYSELF);
828 close_package(env);
829 deactivate_device(env, NULL);
832 void
833 do_select_dev(fcode_env_t *env)
835 PUSH(DS, 0);
836 PUSH(DS, 0);
837 two_swap(env);
838 dollar_open_package(env);
839 if (TOS) {
840 MYSELF = (instance_t *)POP(DS);
841 check_my_self(env, "select-dev");
842 activate_device(env, MYSELF->device);
843 } else {
844 drop(env);
845 log_message(MSG_INFO, "Can't open package\n");
849 void
850 device_end(fcode_env_t *env)
852 if (env->current_device) {
853 deactivate_device(env, NULL);
857 void
858 end_package(fcode_env_t *env)
860 finish_device(env);
861 close_instance_chain(env, MYSELF, 0);
862 device_end(env);
863 MYSELF = NULL;
866 void
867 exec_parent_method(fcode_env_t *env)
869 instance_t *old_myself;
870 instance_t *myself;
871 device_t *device;
872 char *method;
873 fstack_t d;
875 check_my_self(env, "exec-parent-method");
876 old_myself = MYSELF;
877 MYSELF = MYSELF->parent;
879 method = (char *)DS[-1];
880 debug_msg(DEBUG_FIND_FCODE, "exec_parent_method: '%s'\n", method);
882 check_my_self(env, "exec-parent-method");
883 device = MYSELF->device;
884 do_push_package(env, device);
885 PUSH(DS, (fstack_t)device);
886 REVERT_PHANDLE(env, TOS, device);
887 find_method(env);
888 d = POP(DS);
889 if (d) {
890 debug_msg(DEBUG_FIND_FCODE, "exec-parent-method: '%s'/%x"
891 " execute\n", method, (int)TOS);
892 execute(env);
893 PUSH(DS, TRUE);
894 } else {
895 debug_msg(DEBUG_FIND_FCODE, "exec-parent-method: '%s'"
896 " not found\n", method);
897 PUSH(DS, FALSE);
899 MYSELF = old_myself;
900 do_push_package(env, MYSELF->device);
903 void
904 dump_device(fcode_env_t *env)
906 device_t *phandle;
907 int i;
909 CONVERT_PHANDLE(env, phandle, POP(DS));
910 log_message(MSG_DEBUG, "Node: %p\n", phandle);
911 log_message(MSG_DEBUG, " Parent: (%8p) %p\n",
912 &phandle->parent, phandle->parent);
913 log_message(MSG_DEBUG, " Child: (%8p) %p\n",
914 &phandle->child, phandle->child);
915 log_message(MSG_DEBUG, " Peer: (%8p) %p\n",
916 &phandle->peer, phandle->peer);
917 log_message(MSG_DEBUG, " Private: (%8p) %p\n",
918 &phandle->private, phandle->private);
919 log_message(MSG_DEBUG, " Props: (%8p) %p\n",
920 &phandle->properties, phandle->properties);
921 log_message(MSG_DEBUG, " Voc: (%8p) %p\n",
922 &phandle->vocabulary, phandle->vocabulary);
923 log_message(MSG_DEBUG, " sizes: (%8p) %d %d\n",
924 &phandle->data_size,
925 phandle->data_size[INIT_DATA],
926 phandle->data_size[UINIT_DATA]);
927 log_message(MSG_DEBUG, " my_space: %x\n", phandle->my_space);
928 log_message(MSG_DEBUG, " my_addr :");
929 for (i = 0; i < MAX_MY_ADDR; i++)
930 log_message(MSG_DEBUG, " %x", (int)phandle->my_addr[i]);
931 log_message(MSG_DEBUG, "\n");
932 log_message(MSG_DEBUG, " data: (%8p)\n", phandle->init_data);
933 for (i = 0; i < phandle->data_size[INIT_DATA]; i++) {
934 log_message(MSG_DEBUG, " %3d -> (%8p) %x\n", i,
935 &phandle->init_data[i], phandle->init_data[i]);
939 void
940 dump_instance(fcode_env_t *env)
942 int i;
943 instance_t *ihandle;
945 ihandle = (instance_t *)POP(DS);
946 log_message(MSG_DEBUG, "Ihandle: %p\n", ihandle);
947 log_message(MSG_DEBUG, " Parent: (%8p) %p\n",
948 &ihandle->parent, ihandle->parent);
949 log_message(MSG_DEBUG, " Device: (%8p) %p\n",
950 &ihandle->device, ihandle->device);
951 log_message(MSG_DEBUG, " args: '%s'\n",
952 ((ihandle->my_args) ? ihandle->my_args : ""));
953 log_message(MSG_DEBUG, " my-space: %x\n", ihandle->my_space);
954 log_message(MSG_DEBUG, " my_addr :");
955 for (i = 0; i < MAX_MY_ADDR; i++)
956 log_message(MSG_DEBUG, " %x", (int)ihandle->my_addr[i]);
957 log_message(MSG_DEBUG, "\n");
958 log_message(MSG_DEBUG, " sizes: %d %d\n",
959 ihandle->device->data_size[INIT_DATA],
960 ihandle->device->data_size[UINIT_DATA]);
961 log_message(MSG_DEBUG, " data: (%8p) %x %x\n",
962 ihandle->data, ihandle->data[0], ihandle->data[1]);
963 if (ihandle->device->data_size[INIT_DATA]) {
964 log_message(MSG_DEBUG, " Initialised:\n");
965 for (i = 0; i < ihandle->device->data_size[INIT_DATA]; i++) {
966 log_message(MSG_DEBUG, " %3d -> (%8p) %x\n", i,
967 &ihandle->data[INIT_DATA][i],
968 ihandle->data[INIT_DATA][i]);
971 if (ihandle->device->data_size[INIT_DATA]) {
972 log_message(MSG_DEBUG, " UnInitialised:\n");
973 for (i = 0; i < ihandle->device->data_size[UINIT_DATA]; i++) {
974 log_message(MSG_DEBUG, " %3d -> (%8p) %x\n", i,
975 &ihandle->data[UINIT_DATA][i],
976 ihandle->data[UINIT_DATA][i]);
981 #endif
983 #pragma init(_init)
985 #ifdef CONVERT_HANDLES
986 static device_t *
987 safe_convert_phandle(fcode_env_t *env, fstack_t d)
989 return ((device_t *)d);
992 static fstack_t
993 safe_revert_phandle(fcode_env_t *env, device_t *d)
995 return ((fstack_t)d);
998 static void
999 safe_allocate_phandle(fcode_env_t *env)
1003 #endif
1005 static void
1006 _init(void)
1008 fcode_env_t *env = initial_env;
1009 char *name = "/";
1010 device_t *d;
1012 ASSERT(env);
1013 NOTICE;
1015 #ifdef CONVERT_HANDLES
1016 env->convert_phandle = safe_convert_phandle;
1017 env->revert_phandle = safe_revert_phandle;
1018 env->allocate_phandle = safe_allocate_phandle;
1019 #endif
1021 /* build the root node */
1022 d = create_phandle(env, NULL);
1023 env->current_device = d;
1024 env->root_node = d;
1025 push_a_string(env, name);
1026 device_name(env);
1027 env->current_device = NULL;
1029 create_my_self(env);
1030 create_my_space(env);
1032 P1275(0x102, 0, "my-address", my_address);
1033 /* Fcode 0x103 "my-space" is created using create_internal_value */
1035 P1275(0x11f, 0, "new-device", new_device);
1037 P1275(0x127, 0, "finish-device", finish_device);
1039 FCODE(0x129, 0, "push-package", push_package);
1040 FCODE(0x12a, 0, "pop-package", pop_package);
1041 FCODE(0x12b, 0, "interpose", interpose);
1043 P1275(0x202, 0, "my-args", my_args);
1044 /* Fcode 0x203 "my-self" is created using create_internal_value */
1045 P1275(0x204, 0, "find-package", find_package);
1046 P1275(0x205, 0, "open-package", open_package);
1047 P1275(0x206, 0, "close-package", close_package);
1048 P1275(0x207, 0, "find-method", find_method);
1049 P1275(0x208, 0, "call-package", call_package);
1050 P1275(0x209, 0, "$call-parent", dollar_call_parent);
1051 P1275(0x20a, 0, "my-parent", my_parent);
1052 P1275(0x20b, 0, "ihandle>phandle", ihandle_to_phandle);
1054 P1275(0x20d, 0, "my-unit", my_unit);
1055 P1275(0x20e, 0, "$call-method", dollar_call_method);
1056 P1275(0x20f, 0, "$open-package", dollar_open_package);
1058 P1275(0x23b, 0, "child", child_node);
1059 P1275(0x23c, 0, "peer", peer_node);
1061 P1275(0x23f, 0, "set-args", set_args);
1063 FORTH(IMMEDIATE, "root-node", root_node);
1064 FORTH(0, "current-device", current_device);
1065 FORTH(0, "pwd$", pwd_dollar);
1066 FORTH(IMMEDIATE, "pwd", pwd);
1067 FORTH(IMMEDIATE, "ls", do_ls);
1068 FORTH(IMMEDIATE, "(cd)", paren_cd);
1069 FORTH(IMMEDIATE, "cd", do_cd);
1070 FORTH(IMMEDIATE, "device-end", device_end);
1071 FORTH(0, "select-dev", do_select_dev);
1072 FORTH(0, "unselect-dev", do_unselect_dev);
1073 FORTH(0, "begin-package", begin_package);
1074 FORTH(0, "end-package", end_package);
1075 FORTH(IMMEDIATE, "dump-device", dump_device);
1076 FORTH(IMMEDIATE, "dump-instance", dump_instance);
1077 FORTH(0, "exec-parent-method", exec_parent_method);