1 /* This file is part of the program psim.
3 Copyright 1994, 1995, 1996, 1997, 2003 Andrew Cagney
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #ifndef _EMUL_CHIRP_C_
23 #define _EMUL_CHIRP_C_
25 /* Note: this module is called via a table. There is no benefit in
28 #include "emul_generic.h"
29 #include "emul_chirp.h"
43 #ifndef STATIC_INLINE_EMUL_CHIRP
44 #define STATIC_INLINE_EMUL_CHIRP STATIC_INLINE
51 OpenFirmware - IEEE Standard for Boot (Initialization
52 Configuration) Firmware.
61 This code assumes that the memory node has #address-cells and
62 #size-cells set to one. For future implementations, this may not
70 /* Descriptor of the open boot services being emulated */
72 typedef int (chirp_handler
)
77 typedef struct _chirp_services
{
79 chirp_handler
*handler
;
83 /* The OpenBoot emulation is, at any time either waiting for a client
84 request or waiting on a client callback */
91 struct _os_emul_data
{
92 chirp_emul_state state
;
93 unsigned_word return_address
;
94 unsigned_word arguments
;
96 unsigned_word n_returns
;
97 chirp_services
*service
;
99 chirp_services
*services
;
101 unsigned_word memory_size
;
102 unsigned_word real_base
;
103 unsigned_word real_size
;
104 unsigned_word virt_base
;
105 unsigned_word virt_size
;
108 int floating_point_available
;
109 int interrupt_prefix
;
110 unsigned_word load_base
;
112 unsigned_word nr_page_table_entry_groups
;
113 unsigned_word htab_offset
;
114 unsigned_word htab_ra
;
115 unsigned_word htab_va
;
116 unsigned_word sizeof_htab
;
117 /* virtual address of htab */
118 unsigned_word stack_offset
;
119 unsigned_word stack_ra
;
120 unsigned_word stack_va
;
121 unsigned_word sizeof_stack
;
122 /* addresses of emulation instructions virtual/real */
123 unsigned_word code_offset
;
124 unsigned_word code_va
;
125 unsigned_word code_ra
;
126 unsigned_word sizeof_code
;
127 unsigned_word code_client_va
;
128 unsigned_word code_client_ra
;
129 unsigned_word code_callback_va
;
130 unsigned_word code_callback_ra
;
131 unsigned_word code_loop_va
;
132 unsigned_word code_loop_ra
;
136 /* returns the name of the corresponding Ihandle */
138 ihandle_name(device_instance
*ihandle
)
143 return device_name(device_instance_device(ihandle
));
148 /* Read/write the argument list making certain that all values are
149 converted to/from host byte order.
151 In the below only n_args+n_returns is read/written */
154 chirp_read_t2h_args(void *args
,
162 unsigned_cell
*words
;
164 /* check against the number of arguments specified by the client
166 if ((n_args
>= 0 && data
->n_args
!= n_args
)
167 || (n_returns
>= 0 && data
->n_returns
!= n_returns
)) {
168 TRACE(trace_os_emul
, ("%s - invalid nr of args - n_args=%ld, n_returns=%ld\n",
171 (long)data
->n_returns
));
174 /* check that there is enough space */
175 if (sizeof(unsigned_cell
) * (data
->n_args
+ data
->n_returns
) > sizeof_args
)
177 /* bring in the data */
178 memset(args
, 0, sizeof_args
);
179 emul_read_buffer(args
, data
->arguments
+ 3 * sizeof(unsigned_cell
),
180 sizeof(unsigned_cell
) * (data
->n_args
+ data
->n_returns
),
182 /* convert all words to host format */
184 for (i
= 0; i
< (sizeof_args
/ sizeof(unsigned_cell
)); i
++)
185 words
[i
] = T2H_cell(words
[i
]);
190 chirp_write_h2t_args(void *args
,
197 unsigned_cell
*words
;
198 /* convert to target everything */
200 for (i
= 0; i
< (sizeof_args
/ sizeof(unsigned_cell
)); i
++)
201 words
[i
] = H2T_cell(words
[i
]);
202 /* bring in the data */
203 emul_write_buffer(args
, data
->arguments
+ 3 * sizeof(unsigned_cell
),
204 sizeof(unsigned_cell
) * (data
->n_args
+ data
->n_returns
),
209 /* OpenBoot emulation functions */
211 /* client interface */
214 chirp_emul_test(os_emul_data
*data
,
220 unsigned_cell name
; /*string*/
222 unsigned_cell missing
;
225 chirp_services
*service
= NULL
;
226 /* read in the arguments */
227 if (chirp_read_t2h_args(&args
, sizeof(args
), 1, 1, data
, processor
, cia
))
229 emul_read_string(name
, args
.name
, sizeof(name
),
231 TRACE(trace_os_emul
, ("test - in - name=`%s'\n", name
));
232 /* see if we know about the service */
233 service
= data
->services
;
234 while (service
->name
!= NULL
&& strcmp(service
->name
, name
) != 0) {
237 if (service
->name
== NULL
)
241 /* write the arguments back out */
242 TRACE(trace_os_emul
, ("test - out - missing=%ld\n",
243 (long)args
.missing
));
244 chirp_write_h2t_args(&args
,
255 chirp_emul_peer(os_emul_data
*data
,
261 unsigned_cell phandle
;
263 unsigned_cell sibling_phandle
;
266 device
*sibling_phandle
= NULL
;
267 /* read in the arguments */
268 if (chirp_read_t2h_args(&args
, sizeof(args
), 1, 1, data
, processor
, cia
))
270 phandle
= external_to_device(data
->root
, args
.phandle
);
271 TRACE(trace_os_emul
, ("peer - in - phandle=0x%lx(0x%lx`%s')\n",
272 (unsigned long)args
.phandle
,
273 (unsigned long)phandle
,
274 (phandle
== NULL
? "" : device_name(phandle
))));
276 if (args
.phandle
== 0) {
277 sibling_phandle
= data
->root
;
278 args
.sibling_phandle
= device_to_external(sibling_phandle
);
280 else if (phandle
== NULL
) {
281 sibling_phandle
= NULL
;
282 args
.sibling_phandle
= -1;
285 sibling_phandle
= device_sibling(phandle
);
286 if (sibling_phandle
== NULL
)
287 args
.sibling_phandle
= 0;
289 args
.sibling_phandle
= device_to_external(sibling_phandle
);
291 /* write the arguments back out */
292 TRACE(trace_os_emul
, ("peer - out - sibling_phandle=0x%lx(0x%lx`%s')\n",
293 (unsigned long)args
.sibling_phandle
,
294 (unsigned long)sibling_phandle
,
295 (sibling_phandle
== NULL
? "" : device_name(sibling_phandle
))));
296 chirp_write_h2t_args(&args
,
304 chirp_emul_child(os_emul_data
*data
,
310 unsigned_cell phandle
;
312 unsigned_cell child_phandle
;
315 device
*child_phandle
;
316 /* read the arguments in */
317 if (chirp_read_t2h_args(&args
, sizeof(args
), 1, 1, data
, processor
, cia
))
319 phandle
= external_to_device(data
->root
, args
.phandle
);
320 TRACE(trace_os_emul
, ("child - in - phandle=0x%lx(0x%lx`%s')\n",
321 (unsigned long)args
.phandle
,
322 (unsigned long)phandle
,
323 (phandle
== NULL
? "" : device_name(phandle
))));
325 if (args
.phandle
== 0
326 || phandle
== NULL
) {
327 child_phandle
= NULL
;
328 args
.child_phandle
= -1;
331 child_phandle
= device_child(phandle
);
332 if (child_phandle
== NULL
)
333 args
.child_phandle
= 0;
335 args
.child_phandle
= device_to_external(child_phandle
);
337 /* write the result out */
338 TRACE(trace_os_emul
, ("child - out - child_phandle=0x%lx(0x%lx`%s')\n",
339 (unsigned long)args
.child_phandle
,
340 (unsigned long)child_phandle
,
341 (child_phandle
== NULL
? "" : device_name(child_phandle
))));
342 chirp_write_h2t_args(&args
,
350 chirp_emul_parent(os_emul_data
*data
,
356 unsigned_cell phandle
;
358 unsigned_cell parent_phandle
;
361 device
*parent_phandle
;
362 /* read the args in */
363 if (chirp_read_t2h_args(&args
, sizeof(args
), 1, 1, data
, processor
, cia
))
365 phandle
= external_to_device(data
->root
, args
.phandle
);
366 TRACE(trace_os_emul
, ("parent - in - phandle=0x%lx(0x%lx`%s')\n",
367 (unsigned long)args
.phandle
,
368 (unsigned long)phandle
,
369 (phandle
== NULL
? "" : device_name(phandle
))));
371 if (args
.phandle
== 0
372 || phandle
== NULL
) {
373 parent_phandle
= NULL
;
374 args
.parent_phandle
= -1;
377 parent_phandle
= device_parent(phandle
);
378 if (parent_phandle
== NULL
)
379 args
.parent_phandle
= 0;
381 args
.parent_phandle
= device_to_external(parent_phandle
);
383 /* return the result */
384 TRACE(trace_os_emul
, ("parent - out - parent_phandle=0x%lx(0x%lx`%s')\n",
385 (unsigned long)args
.parent_phandle
,
386 (unsigned long)parent_phandle
,
387 (parent_phandle
== NULL
? "" : device_name(parent_phandle
))));
388 chirp_write_h2t_args(&args
,
396 chirp_emul_instance_to_package(os_emul_data
*data
,
400 struct instance_to_package_args
{
402 unsigned_cell ihandle
;
404 unsigned_cell phandle
;
406 device_instance
*ihandle
;
407 device
*phandle
= NULL
;
408 /* read the args in */
409 if (chirp_read_t2h_args(&args
, sizeof(args
), 1, 1, data
, processor
, cia
))
411 ihandle
= external_to_device_instance(data
->root
, args
.ihandle
);
412 TRACE(trace_os_emul
, ("instance-to-package - in - ihandle=0x%lx(0x%lx`%s')\n",
413 (unsigned long)args
.ihandle
,
414 (unsigned long)ihandle
,
415 ihandle_name(ihandle
)));
416 /* find the corresponding phandle */
417 if (ihandle
== NULL
) {
422 phandle
= device_instance_device(ihandle
);
423 args
.phandle
= device_to_external(phandle
);
425 /* return the result */
426 TRACE(trace_os_emul
, ("instance-to-package - out - phandle=0x%lx(0x%lx`%s')\n",
427 (unsigned long)args
.phandle
,
428 (unsigned long)phandle
,
429 (phandle
== NULL
? "" : device_name(phandle
))));
430 chirp_write_h2t_args(&args
,
438 chirp_emul_getproplen(os_emul_data
*data
,
442 struct getproplen_args
{
444 unsigned_cell phandle
;
447 unsigned_cell proplen
;
451 /* read the args in */
452 if (chirp_read_t2h_args(&args
, sizeof(args
), 2, 1, data
, processor
, cia
))
454 phandle
= external_to_device(data
->root
, args
.phandle
);
455 emul_read_string(name
,
459 TRACE(trace_os_emul
, ("getproplen - in - phandle=0x%lx(0x%lx`%s') name=`%s'\n",
460 (unsigned long)args
.phandle
,
461 (unsigned long)phandle
,
462 (phandle
== NULL
? "" : device_name(phandle
)),
464 /* find our prop and get its length */
465 if (args
.phandle
== 0
466 || phandle
== NULL
) {
470 const device_property
*prop
= device_find_property(phandle
, name
);
471 if (prop
== (device_property
*)0) {
475 args
.proplen
= prop
->sizeof_array
;
478 /* return the result */
479 TRACE(trace_os_emul
, ("getproplen - out - proplen=%ld\n",
480 (unsigned long)args
.proplen
));
481 chirp_write_h2t_args(&args
,
489 chirp_emul_getprop(os_emul_data
*data
,
493 struct getprop_args
{
495 unsigned_cell phandle
;
498 unsigned_cell buflen
;
504 /* read in the args, the return is optional */
505 if (chirp_read_t2h_args(&args
, sizeof(args
), 4, -1, data
, processor
, cia
))
507 phandle
= external_to_device(data
->root
, args
.phandle
);
508 emul_read_string(name
,
512 TRACE(trace_os_emul
, ("getprop - in - phandle=0x%lx(0x%lx`%s') name=`%s' buf=0x%lx buflen=%ld\n",
513 (unsigned long)args
.phandle
,
514 (unsigned long)phandle
,
515 (phandle
== NULL
? "" : device_name(phandle
)),
517 (unsigned long)args
.buf
,
518 (unsigned long)args
.buflen
));
519 /* get the property */
520 if (args
.phandle
== 0
521 || phandle
== NULL
) {
525 const device_property
*prop
= device_find_property(phandle
, name
);
530 int size
= args
.buflen
;
531 if (size
> prop
->sizeof_array
)
532 size
= prop
->sizeof_array
;
533 emul_write_buffer(prop
->array
, args
.buf
,
537 switch (prop
->type
) {
538 case string_property
:
539 TRACE(trace_os_emul
, ("getprop - string `%s'\n",
540 device_find_string_property(phandle
, name
)));
542 case ihandle_property
:
543 TRACE(trace_os_emul
, ("getprop - ihandle=0x%lx(0x%lx`%s')\n",
544 BE2H_cell(*(unsigned_cell
*)prop
->array
),
545 (unsigned long)device_find_ihandle_property(phandle
, name
),
546 ihandle_name(device_find_ihandle_property(phandle
, name
))));
553 /* write back the result */
554 if (data
->n_returns
== 0)
555 TRACE(trace_os_emul
, ("getprop - out - size=%ld (not returned)\n",
556 (unsigned long)args
.size
));
558 TRACE(trace_os_emul
, ("getprop - out - size=%ld\n",
559 (unsigned long)args
.size
));
560 chirp_write_h2t_args(&args
,
569 chirp_emul_nextprop(os_emul_data
*data
,
573 struct nextprop_args
{
575 unsigned_cell phandle
;
576 unsigned_cell previous
;
583 /* read in the args */
584 if (chirp_read_t2h_args(&args
, sizeof(args
), 3, 1, data
, processor
, cia
))
586 phandle
= external_to_device(data
->root
, args
.phandle
);
587 if (args
.previous
!= 0)
588 emul_read_string(previous
,
593 /* If previous is NULL, make it look like the empty string. The
594 next property after the empty string is the first property. */
595 strcpy (previous
, "");
596 TRACE(trace_os_emul
, ("nextprop - in - phandle=0x%lx(0x%lx`%s') previous=`%s' buf=0x%lx\n",
597 (unsigned long)args
.phandle
,
598 (unsigned long)phandle
,
599 (phandle
== NULL
? "" : device_name(phandle
)),
601 (unsigned long)args
.buf
));
602 /* find the next property */
603 if (args
.phandle
== 0
604 || phandle
== NULL
) {
608 const device_property
*prev_prop
= device_find_property(phandle
, previous
);
609 if (prev_prop
== NULL
) {
610 if (strcmp (previous
, "") == 0)
611 args
.flag
= 0; /* No properties */
613 args
.flag
= -1; /* name invalid */
616 const device_property
*next_prop
;
617 if (strcmp (previous
, "") == 0) {
618 next_prop
= prev_prop
; /* The first property. */
621 next_prop
= device_next_property(prev_prop
);
623 if (next_prop
== NULL
) {
624 args
.flag
= 0; /* last property */
627 emul_write_buffer(next_prop
->name
, args
.buf
, strlen(next_prop
->name
),
629 TRACE(trace_os_emul
, ("nextprop - name=`%s'\n", next_prop
->name
));
630 args
.flag
= 1; /* worked ok */
634 /* write back the result */
635 TRACE(trace_os_emul
, ("nextprop - out - flag=%ld\n",
636 (unsigned long)args
.flag
));
637 chirp_write_h2t_args(&args
,
646 chirp_emul_setprop(os_emul_data
*data
,
650 error("chirp: setprop method not implemented\n");
656 chirp_emul_canon(os_emul_data
*data
,
662 unsigned_cell device_specifier
;
664 unsigned_cell buflen
;
666 unsigned_cell length
;
668 char device_specifier
[1024];
672 /* read in the args */
673 if (chirp_read_t2h_args(&args
, sizeof(args
), 3, 1, data
, processor
, cia
))
675 emul_read_string(device_specifier
,
676 args
.device_specifier
,
677 sizeof(device_specifier
),
679 TRACE(trace_os_emul
, ("canon - in - device_specifier=`%s' buf=0x%lx buflen=%lx\n",
681 (unsigned long)args
.buf
,
682 (unsigned long)args
.buflen
));
684 phandle
= tree_find_device(data
->root
, device_specifier
);
685 if (phandle
== NULL
) {
691 path
= device_path(phandle
);
692 length
= strlen(path
);
693 if (length
>= args
.buflen
)
694 length
= args
.buflen
- 1;
695 emul_write_buffer(path
, args
.buf
, length
,
697 args
.length
= length
;
699 /* write back the result */
700 TRACE(trace_os_emul
, ("canon - out - length=%ld buf=`%s'\n",
701 (unsigned long)args
.length
,
703 chirp_write_h2t_args(&args
,
711 chirp_emul_finddevice(os_emul_data
*data
,
715 struct finddevice_args
{
717 unsigned_cell device_specifier
;
719 unsigned_cell phandle
;
721 char device_specifier
[1024];
724 if (chirp_read_t2h_args(&args
, sizeof(args
), 1, 1, data
, processor
, cia
))
726 emul_read_string(device_specifier
,
727 args
.device_specifier
,
728 sizeof(device_specifier
),
730 TRACE(trace_os_emul
, ("finddevice - in - device_specifier=`%s'\n",
732 /* find the device */
733 phandle
= tree_find_device(data
->root
, device_specifier
);
737 args
.phandle
= device_to_external(phandle
);
738 /* return its phandle */
739 TRACE(trace_os_emul
, ("finddevice - out - phandle=0x%lx(0x%lx`%s')\n",
740 (unsigned long)args
.phandle
,
741 (unsigned long)phandle
,
742 (phandle
== NULL
? "" : device_name(phandle
))));
743 chirp_write_h2t_args(&args
,
751 chirp_emul_instance_to_path(os_emul_data
*data
,
755 struct instance_to_path_args
{
757 unsigned_cell ihandle
;
759 unsigned_cell buflen
;
761 unsigned_cell length
;
763 device_instance
*ihandle
;
767 if (chirp_read_t2h_args(&args
, sizeof(args
), 3, 1, data
, processor
, cia
))
769 ihandle
= external_to_device_instance(data
->root
, args
.ihandle
);
770 TRACE(trace_os_emul
, ("instance-to-path - in - ihandle=0x%lx(0x%lx`%s') buf=0x%lx buflen=%ld\n",
771 (unsigned long)args
.ihandle
,
772 (unsigned long)ihandle
,
773 ihandle_name(ihandle
),
774 (unsigned long)args
.buf
,
775 (unsigned long)args
.buflen
));
776 /* get the devices name */
777 if (ihandle
== NULL
) {
782 path
= device_instance_path(ihandle
);
783 length
= strlen(path
);
784 if (length
>= args
.buflen
)
785 length
= args
.buflen
- 1;
786 emul_write_buffer(path
, args
.buf
, length
,
788 args
.length
= length
;
790 /* return its phandle */
791 TRACE(trace_os_emul
, ("instance-to-path - out - length=%ld buf=`%s')\n",
792 (unsigned long)args
.length
,
794 chirp_write_h2t_args(&args
,
802 chirp_emul_package_to_path(os_emul_data
*data
,
806 struct package_to_path_args
{
808 unsigned_cell phandle
;
810 unsigned_cell buflen
;
812 unsigned_cell length
;
817 if (chirp_read_t2h_args(&args
, sizeof(args
), 3, 1, data
, processor
, cia
))
819 phandle
= external_to_device(data
->root
, args
.phandle
);
820 TRACE(trace_os_emul
, ("package-to-path - in - phandle=0x%lx(0x%lx`%s') buf=0x%lx buflen=%ld\n",
821 (unsigned long)args
.phandle
,
822 (unsigned long)phandle
,
823 (phandle
== NULL
? "" : device_name(phandle
)),
824 (unsigned long)args
.buf
,
825 (unsigned long)args
.buflen
));
826 /* get the devices name */
827 if (phandle
== NULL
) {
833 path
= device_path(phandle
);
834 length
= strlen(path
);
835 if (length
>= args
.buflen
)
836 length
= args
.buflen
- 1;
837 emul_write_buffer(path
, args
.buf
, length
,
839 args
.length
= length
;
841 /* return its phandle */
842 TRACE(trace_os_emul
, ("package-to-path - out - length=%ld buf=`%s')\n",
843 (unsigned long)args
.length
,
845 chirp_write_h2t_args(&args
,
853 chirp_emul_call_method(os_emul_data
*data
,
857 struct call_method_args
{
859 unsigned_cell method
;
860 unsigned_cell ihandle
;
862 unsigned_cell stack
[13]; /*6in + 6out + catch */
865 device_instance
*ihandle
;
866 /* some useful info about our mini stack */
869 int stack_catch_result
;
872 if (chirp_read_t2h_args(&args
, sizeof(args
), -1, -1, data
, processor
, cia
))
874 emul_read_string(method
,
878 ihandle
= external_to_device_instance(data
->root
, args
.ihandle
);
879 n_stack_args
= data
->n_args
- 2;
880 n_stack_returns
= data
->n_returns
- 1;
881 stack_catch_result
= n_stack_args
;
882 stack_returns
= stack_catch_result
+ 1;
883 TRACE(trace_os_emul
, ("call-method - in - n_args=%ld n_returns=%ld method=`%s' ihandle=0x%lx(0x%lx`%s')\n",
884 (unsigned long)data
->n_args
,
885 (unsigned long)data
->n_returns
,
887 (unsigned long)args
.ihandle
,
888 (unsigned long)ihandle
,
889 ihandle_name(ihandle
)));
890 /* see if we can emulate this method */
891 if (ihandle
== NULL
) {
892 /* OpenFirmware doesn't define this error */
893 error("chirp: invalid ihandle passed to call-method method");
896 args
.stack
[stack_catch_result
] =
897 device_instance_call_method(ihandle
,
902 &args
.stack
[stack_returns
]);
905 TRACE(trace_os_emul
, ("call-method - out - catch-result=%ld\n",
906 (unsigned long)args
.stack
[stack_catch_result
]));
907 chirp_write_h2t_args(&args
,
918 chirp_emul_open(os_emul_data
*data
,
924 unsigned_cell device_specifier
;
926 unsigned_cell ihandle
;
928 char device_specifier
[1024];
929 device_instance
*ihandle
;
931 if (chirp_read_t2h_args(&args
, sizeof(args
), 1, 1, data
, processor
, cia
))
933 emul_read_string(device_specifier
,
934 args
.device_specifier
,
935 sizeof(device_specifier
),
937 TRACE(trace_os_emul
, ("open - in - device_specifier=`%s'\n",
939 /* open the device */
940 ihandle
= tree_instance(data
->root
, device_specifier
);
944 args
.ihandle
= device_instance_to_external(ihandle
);
945 /* return the ihandle result */
946 TRACE(trace_os_emul
, ("open - out - ihandle=0x%lx(0x%lx`%s')\n",
947 (unsigned long)args
.ihandle
,
948 (unsigned long)ihandle
,
949 ihandle_name(ihandle
)));
950 chirp_write_h2t_args(&args
,
958 chirp_emul_close(os_emul_data
*data
,
964 unsigned_cell ihandle
;
967 device_instance
*ihandle
;
969 if (chirp_read_t2h_args(&args
, sizeof(args
), 1, 0, data
, processor
, cia
))
971 ihandle
= external_to_device_instance(data
->root
, args
.ihandle
);
972 TRACE(trace_os_emul
, ("close - in - ihandle=0x%lx(0x%lx`%s')\n",
973 (unsigned long)args
.ihandle
,
974 (unsigned long)ihandle
,
975 ihandle_name(ihandle
)));
976 /* close the device */
977 if (ihandle
== NULL
) {
978 /* OpenFirmware doesn't define this error */
979 error("chirp: invalid ihandle passed to close method");
982 device_instance_delete(ihandle
);
984 /* return the ihandle result */
985 TRACE(trace_os_emul
, ("close - out\n"));
986 chirp_write_h2t_args(&args
,
994 chirp_emul_read(os_emul_data
*data
,
1000 unsigned_cell ihandle
;
1004 unsigned_cell actual
;
1007 device_instance
*ihandle
;
1009 if (chirp_read_t2h_args(&args
, sizeof(args
), 3, 1, data
, processor
, cia
))
1011 ihandle
= external_to_device_instance(data
->root
, args
.ihandle
);
1012 TRACE(trace_os_emul
, ("read - in - ihandle=0x%lx(0x%lx`%s') addr=0x%lx len=%ld\n",
1013 (unsigned long)args
.ihandle
,
1014 (unsigned long)ihandle
,
1015 ihandle_name(ihandle
),
1016 (unsigned long)args
.addr
,
1017 (unsigned long)args
.len
));
1018 if (ihandle
== NULL
) {
1019 /* OpenFirmware doesn't define this error */
1020 error("chirp: invalid ihandle passed to read method");
1025 while (actual
< args
.len
) {
1026 int remaining
= args
.len
- actual
;
1027 int to_read
= (remaining
<= sizeof(buf
) ? remaining
: sizeof(buf
));
1028 int nr_read
= device_instance_read(ihandle
, buf
, to_read
);
1030 actual
= nr_read
; /* the error */
1033 else if (nr_read
== 0) {
1036 emul_write_buffer(buf
,
1043 args
.actual
= actual
;
1044 if (actual
< sizeof(buf
))
1047 buf
[sizeof(buf
) - 1] = '\0';
1054 case sim_io_not_ready
:
1055 ASSERT(sim_io_not_ready
== -2);
1056 args
.actual
= sim_io_not_ready
;
1059 error("Bad error value %ld", (long)actual
);
1064 /* return the result */
1065 TRACE(trace_os_emul
, ("read - out - actual=%ld `%s'\n",
1067 ((args
.actual
> 0 && args
.actual
< sizeof(buf
)) ? buf
: "")
1069 chirp_write_h2t_args(&args
,
1077 chirp_emul_write(os_emul_data
*data
,
1083 unsigned_cell ihandle
;
1087 unsigned_cell actual
;
1090 device_instance
*ihandle
;
1093 if (chirp_read_t2h_args(&args
, sizeof(args
), 3, 1, data
, processor
, cia
))
1096 if (actual
>= sizeof(buf
))
1097 actual
= sizeof(buf
) - 1;
1098 emul_read_buffer(buf
,
1103 ihandle
= external_to_device_instance(data
->root
, args
.ihandle
);
1104 TRACE(trace_os_emul
, ("write - in - ihandle=0x%lx(0x%lx`%s') `%s' (%ld)\n",
1105 (unsigned long)args
.ihandle
,
1106 (unsigned long)ihandle
,
1107 ihandle_name(ihandle
),
1108 buf
, (long)actual
));
1109 if (ihandle
== NULL
) {
1110 /* OpenFirmware doesn't define this error */
1111 error("chirp: invalid ihandle passed to write method");
1115 actual
= device_instance_write(ihandle
, buf
, actual
);
1119 args
.actual
= actual
;
1121 /* return the result */
1122 TRACE(trace_os_emul
, ("write - out - actual=%ld\n",
1123 (long)args
.actual
));
1124 chirp_write_h2t_args(&args
,
1132 chirp_emul_seek(os_emul_data
*data
,
1138 unsigned_cell ihandle
;
1139 unsigned_cell pos_hi
;
1140 unsigned_cell pos_lo
;
1142 unsigned_cell status
;
1145 device_instance
*ihandle
;
1147 if (chirp_read_t2h_args(&args
, sizeof(args
), 3, 1, data
, processor
, cia
))
1149 ihandle
= external_to_device_instance(data
->root
, args
.ihandle
);
1150 TRACE(trace_os_emul
, ("seek - in - ihandle=0x%lx(0x%lx`%s') pos.hi=0x%lx pos.lo=0x%lx\n",
1151 (unsigned long)args
.ihandle
,
1152 (unsigned long)ihandle
,
1153 ihandle_name(ihandle
),
1154 args
.pos_hi
, args
.pos_lo
));
1155 if (ihandle
== NULL
) {
1156 /* OpenFirmware doesn't define this error */
1157 error("chirp: invalid ihandle passed to seek method");
1161 status
= device_instance_seek(ihandle
, args
.pos_hi
, args
.pos_lo
);
1162 args
.status
= status
;
1164 /* return the result */
1165 TRACE(trace_os_emul
, ("seek - out - status=%ld\n",
1166 (long)args
.status
));
1167 chirp_write_h2t_args(&args
,
1178 chirp_emul_claim(os_emul_data
*data
,
1182 /* NOTE: the client interface claim routine is *very* different to
1183 the "claim" method described in IEEE-1275 appendix A. The latter
1184 uses real addresses while this uses virtual (effective)
1190 unsigned_cell align
;
1192 unsigned_cell baseaddr
;
1195 if (chirp_read_t2h_args(&args
, sizeof(args
),
1196 3 /*n_args*/, 1 /*n_returns*/,
1197 data
, processor
, cia
))
1199 TRACE(trace_os_emul
, ("claim - in - virt=0x%lx size=%ld align=%d\n",
1200 (unsigned long)args
.virt
,
1201 (long int)args
.size
,
1203 /* use the memory device to allocate (real) memory at the requested
1206 device_instance
*memory
= tree_find_ihandle_property(data
->root
, "/chosen/memory");
1207 unsigned_cell mem_in
[3];
1208 unsigned_cell mem_out
[1];
1209 mem_in
[0] = args
.align
; /*top-of-stack*/
1210 mem_in
[1] = args
.size
;
1211 mem_in
[2] = args
.virt
;
1212 if (device_instance_call_method(memory
, "claim",
1213 3, mem_in
, 1, mem_out
) < 0)
1214 error("chirp: claim failed to allocate memory virt=0x%lx size=%ld align=%d",
1215 (unsigned long)args
.virt
,
1216 (long int)args
.size
,
1218 args
.baseaddr
= mem_out
[0];
1220 /* if using virtual addresses, create a 1-1 map of this address space */
1221 if (!data
->real_mode
) {
1222 error("chirp: claim method does not support virtual mode");
1224 /* return the base address */
1225 TRACE(trace_os_emul
, ("claim - out - baseaddr=0x%lx\n",
1226 (unsigned long)args
.baseaddr
));
1227 chirp_write_h2t_args(&args
,
1235 chirp_emul_release(os_emul_data
*data
,
1239 /* NOTE: the client interface release routine is *very* different to
1240 the "claim" method described in IEEE-1275 appendix A. The latter
1241 uses real addresses while this uses virtual (effective)
1250 if (chirp_read_t2h_args(&args
, sizeof(args
),
1251 2 /*n_args*/, 0 /*n_returns*/,
1252 data
, processor
, cia
))
1254 TRACE(trace_os_emul
, ("release - in - virt=0x%lx size=%ld\n",
1255 (unsigned long)args
.virt
,
1256 (long int)args
.size
));
1257 /* use the memory device to release (real) memory at the requested
1260 device_instance
*memory
= tree_find_ihandle_property(data
->root
, "/chosen/memory");
1261 unsigned_cell mem_in
[2];
1262 mem_in
[0] = args
.size
;
1263 mem_in
[1] = args
.virt
;
1264 if (device_instance_call_method(memory
, "release",
1265 2, mem_in
, 0, NULL
) < 0)
1266 error("chirp: claim failed to release memory virt=0x%lx size=%ld",
1267 (unsigned long)args
.virt
,
1268 (long int)args
.size
);
1270 /* if using virtual addresses, remove the 1-1 map of this address space */
1271 if (!data
->real_mode
) {
1272 error("chirp: release method does not support virtual mode");
1274 /* return the base address */
1275 TRACE(trace_os_emul
, ("release - out\n"));
1276 chirp_write_h2t_args(&args
,
1284 /* Control transfer */
1287 chirp_emul_boot(os_emul_data
*data
,
1291 /* unlike OpenFirmware this one can take an argument */
1294 unsigned_cell bootspec
;
1297 char bootspec
[1024];
1298 /* read in the arguments */
1299 if (chirp_read_t2h_args(&args
, sizeof(args
), -1, 0, data
, processor
, cia
))
1300 cpu_halt(processor
, cia
, was_exited
, -1);
1301 if (args
.bootspec
!= 0)
1302 emul_read_string(bootspec
, args
.bootspec
, sizeof(bootspec
),
1305 strcpy(bootspec
, "(null)");
1306 TRACE(trace_os_emul
, ("boot - in bootspec=`%s'\n", bootspec
));
1307 /* just report this and exit */
1308 printf_filtered("chrp: boot %s called, exiting.\n", bootspec
);
1309 cpu_halt(processor
, cia
, was_exited
, 0);
1314 chirp_emul_enter(os_emul_data
*data
,
1318 error("chirp: enter method not implemented\n");
1323 chirp_emul_exit(os_emul_data
*data
,
1327 /* unlike OpenBoot this one can take an argument */
1333 if (chirp_read_t2h_args(&args
, sizeof(args
), -1, 0, data
, processor
, cia
))
1334 cpu_halt(processor
, cia
, was_exited
, -1);
1335 cpu_halt(processor
, cia
, was_exited
, args
.status
);
1340 chirp_emul_chain(os_emul_data
*data
,
1344 error("chirp: chain method not implemented\n");
1349 /* user interface */
1352 chirp_emul_interpret(os_emul_data
*data
,
1356 error("chirp: interpret method not implemented\n");
1361 chirp_emul_set_callback(os_emul_data
*data
,
1365 error("chirp: set_callback method not implemented\n");
1370 chirp_emul_set_symbol_lookup(os_emul_data
*data
,
1374 error("chirp: set_symbol_lookup method not implemented\n");
1382 chirp_emul_milliseconds(os_emul_data
*data
,
1392 /* read in the arguments */
1393 if (chirp_read_t2h_args(&args
, sizeof(args
), 1, 1, data
, processor
, cia
))
1395 /* make up a number */
1396 time
= event_queue_time(psim_event_queue(cpu_system(processor
))) / 1000000;
1398 /* write the arguments back out */
1399 TRACE(trace_os_emul
, ("milliseconds - out - ms=%ld\n",
1400 (unsigned long)args
.ms
));
1401 chirp_write_h2t_args(&args
,
1411 static chirp_services services
[] = {
1413 /* client interface */
1414 { "test", chirp_emul_test
},
1417 { "peer", chirp_emul_peer
},
1418 { "child", chirp_emul_child
},
1419 { "parent", chirp_emul_parent
},
1420 { "instance-to-package", chirp_emul_instance_to_package
},
1421 { "getproplen", chirp_emul_getproplen
},
1422 { "getprop", chirp_emul_getprop
},
1423 { "nextprop", chirp_emul_nextprop
},
1424 /* { "setprop", chirp_emul_setprop }, */
1425 { "canon", chirp_emul_canon
},
1426 { "finddevice", chirp_emul_finddevice
},
1427 { "instance-to-path", chirp_emul_instance_to_path
},
1428 { "package-to-path", chirp_emul_package_to_path
},
1429 { "call-method", chirp_emul_call_method
},
1432 { "open", chirp_emul_open
},
1433 { "close", chirp_emul_close
},
1434 { "read", chirp_emul_read
},
1435 { "write", chirp_emul_write
},
1436 { "seek", chirp_emul_seek
},
1437 { "write", chirp_emul_write
},
1440 { "claim", chirp_emul_claim
},
1441 { "release", chirp_emul_release
},
1443 /* control transfer */
1444 { "boot", chirp_emul_boot
},
1445 { "enter", chirp_emul_enter
},
1446 { "exit", chirp_emul_exit
},
1447 { "chain", chirp_emul_chain
},
1449 /* user interface */
1450 { "interpret", chirp_emul_interpret
},
1451 { "set_callback", chirp_emul_set_callback
},
1452 { "set_symbol_lookup", chirp_emul_set_symbol_lookup
},
1455 { "milliseconds", chirp_emul_milliseconds
},
1457 { 0, /* sentinal */ },
1463 /* Any starting address greater than this is assumed to be an Chirp
1466 #ifndef CHIRP_START_ADDRESS
1467 #define CHIRP_START_ADDRESS 0x80000000
1469 #ifndef CHIRP_LOAD_BASE
1470 #define CHIRP_LOAD_BASE -1
1474 typedef struct _chirp_note_desc
{
1487 } note_found_status
;
1488 typedef struct _chirp_note
{
1489 chirp_note_desc desc
;
1490 note_found_status found
;
1493 typedef struct _chirp_note_head
{
1500 map_over_chirp_note(bfd
*image
,
1504 chirp_note
*note
= (chirp_note
*)obj
;
1505 if (strcmp(sect
->name
, ".note") == 0) {
1506 chirp_note_head head
;
1508 /* check the head */
1509 if (!bfd_get_section_contents(image
, sect
,
1510 &head
, 0, sizeof(head
)))
1512 head
.namesz
= bfd_get_32(image
, (void*)&head
.namesz
);
1513 head
.descsz
= bfd_get_32(image
, (void*)&head
.descsz
);
1514 head
.type
= bfd_get_32(image
, (void*)&head
.type
);
1515 if (head
.type
!= 0x1275)
1517 /* check the name field */
1518 if (head
.namesz
> sizeof(name
)) {
1519 error("chirp: note name too long (%d > %d)\n", (int)head
.namesz
, sizeof(name
));
1521 if (!bfd_get_section_contents(image
, sect
,
1522 name
, sizeof(head
), head
.namesz
)) {
1523 error("chirp: note name unreadable\n");
1525 if (strcmp(name
, "PowerPC") != 0) {
1526 printf_filtered("chirp: note name (%s) not `PowerPC'\n", name
);
1528 /* check the size */
1529 if (head
.descsz
== sizeof(note
->desc
) - sizeof(signed32
)) {
1530 sim_io_printf_filtered("chirp: note descriptor missing load-base\n");
1532 else if (head
.descsz
!= sizeof(note
->desc
)) {
1533 sim_io_printf_filtered("chirp: note descriptor of wrong size\n");
1534 note
->found
= note_found
;
1537 note
->found
= note_correct
;
1538 /* get the contents */
1539 if (!bfd_get_section_contents(image
, sect
,
1540 ¬e
->desc
, /* page align start */
1541 ((sizeof(head
) + head
.namesz
) + 3) & ~3,
1543 error("chirp: note descriptor unreadable\n");
1545 note
->desc
.real_mode
= bfd_get_32(image
, (void*)¬e
->desc
.real_mode
);
1546 note
->desc
.real_base
= bfd_get_32(image
, (void*)¬e
->desc
.real_base
);
1547 note
->desc
.real_size
= bfd_get_32(image
, (void*)¬e
->desc
.real_size
);
1548 note
->desc
.virt_base
= bfd_get_32(image
, (void*)¬e
->desc
.virt_base
);
1549 note
->desc
.virt_size
= bfd_get_32(image
, (void*)¬e
->desc
.virt_size
);
1550 if (head
.descsz
== sizeof(note
->desc
))
1551 note
->desc
.load_base
= bfd_get_32(image
, (void*)¬e
->desc
.load_base
);
1553 note
->desc
.load_base
= (signed32
)-1;
1558 static os_emul_data
*
1559 emul_chirp_create(device
*root
,
1563 os_emul_data
*chirp
;
1568 /* Sanity check that this really is the chosen emulation */
1569 if (name
== NULL
&& image
== NULL
)
1572 && strcmp(name
, "ob") != 0
1573 && strcmp(name
, "ieee1274") != 0
1574 && strcmp(name
, "chrp") != 0
1575 && strcmp(name
, "chirp") != 0
1576 && strcmp(name
, "openboot") != 0)
1579 /* look for an elf note section, enter its values into the device tree */
1580 memset(¬e
, 0, sizeof(note
));
1582 bfd_map_over_sections(image
, map_over_chirp_note
, ¬e
);
1583 if (name
== NULL
&& image
!= NULL
&& note
.found
== note_missing
)
1586 /* Assume that it is a chirp emulation */
1588 chirp
= ZALLOC(os_emul_data
);
1590 chirp
->services
= services
;
1593 tree_parse(root
, "/name \"gpl,clayton");
1595 /* default options */
1596 emul_add_tree_options(root
, image
, "chirp", "oea",
1597 0 /*oea-interrupt-prefix*/);
1600 emul_add_tree_hardware(root
);
1602 /* basic information */
1604 = tree_find_integer_property(root
, "/openprom/options/oea-memory-size");
1605 chirp
->little_endian
1606 = tree_find_boolean_property(root
, "/options/little-endian?");
1607 chirp
->floating_point_available
1608 = tree_find_boolean_property(root
, "/openprom/options/floating-point?");
1609 chirp
->interrupt_prefix
=
1610 tree_find_integer_property(root
, "/openprom/options/oea-interrupt-prefix");
1613 /* Perform an interum layout of the openboot firmware in memory */
1616 /* a page for firmware calls */
1617 chirp
->sizeof_code
= 4096;
1618 chirp
->code_offset
= 0x4000; /* possible space for interrupt table */
1621 chirp
->sizeof_stack
= 32 * 1024;
1622 chirp
->stack_offset
= chirp
->code_offset
+ chirp
->sizeof_code
;
1624 /* the hash table */
1625 if (!note
.desc
.real_mode
) {
1626 chirp
->nr_page_table_entry_groups
= (chirp
->memory_size
< 0x800000
1627 ? 1024 /* min allowed */
1628 : (chirp
->memory_size
/ 4096 / 2));
1629 chirp
->sizeof_htab
= chirp
->nr_page_table_entry_groups
* 64;
1631 chirp
->htab_offset
= chirp
->stack_offset
+ chirp
->sizeof_stack
;
1633 /* the actual amount of space needed */
1634 chirp
->real_size
= chirp
->htab_offset
+ chirp
->sizeof_htab
;
1637 /* now go through and see if it fits in what is available */
1640 /* resolve real-mode? */
1641 if (note
.found
== note_correct
)
1642 chirp
->real_mode
= note
.desc
.real_mode
;
1643 else if (tree_find_property(root
, "/options/real-mode?") != NULL
)
1644 chirp
->real_mode
= tree_find_boolean_property(root
, "/options/real-mode?");
1646 chirp
->real_mode
= 0;
1647 if (tree_find_property(root
, "/options/real-mode?") != NULL
) {
1648 if (!chirp
->real_mode
1649 != !tree_find_boolean_property(root
, "/options/real-mode?"))
1650 error("chirp: /options/real-mode? conflicts with note section\n");
1653 tree_parse(root
, "/options/real-mode? %s",
1654 chirp
->real_mode
? "true" : "false");
1656 /* resolve real-base */
1657 if (note
.found
== note_correct
1658 && note
.desc
.real_base
!= (signed32
)-1)
1659 chirp
->real_base
= note
.desc
.real_base
;
1660 else if (tree_find_property(root
, "/options/real-base") != NULL
)
1661 chirp
->real_base
= tree_find_integer_property(root
, "/options/real-base");
1663 chirp
->real_base
= chirp
->memory_size
- chirp
->real_size
;
1664 if (tree_find_property(root
, "/options/real-base") != NULL
) {
1665 if (chirp
->real_base
!= tree_find_integer_property(root
, "/options/real-base"))
1666 error("chirp: /options/real-base conflicts with note section\n");
1669 tree_parse(root
, "/options/real-base 0x%lx",
1670 (unsigned long)chirp
->real_base
);
1672 /* resolve real-size */
1673 if (note
.found
== note_correct
1674 && note
.desc
.real_size
!= (signed32
)-1
1675 && note
.desc
.real_size
!= 0
1676 && chirp
->real_size
> note
.desc
.real_size
)
1677 error("chirp: insufficient physical memory for firmware\n");
1678 if (tree_find_property(root
, "/options/real-size") != NULL
) {
1679 if (chirp
->real_size
> tree_find_integer_property(root
, "/options/real-size"))
1680 error("chirp: /options/real-size conflicts with note section\n");
1683 tree_parse(root
, "/options/real-size 0x%lx",
1684 (unsigned long)chirp
->real_size
);
1686 /* resolve virt-base */
1687 if (chirp
->real_mode
)
1688 chirp
->virt_base
= chirp
->real_base
;
1689 else if (note
.found
== note_correct
&& note
.desc
.virt_base
!= -1)
1690 chirp
->virt_base
= note
.desc
.virt_base
;
1691 else if (tree_find_property(root
, "/options/virt-base") != NULL
)
1692 chirp
->virt_base
= tree_find_integer_property(root
, "/options/virt-base");
1694 chirp
->virt_base
= CHIRP_START_ADDRESS
;
1695 if (tree_find_property(root
, "/options/virt-base") != NULL
) {
1696 unsigned_word virt_base
= tree_find_integer_property(root
, "/options/virt-base");
1697 if (virt_base
!= -1 && chirp
->virt_base
!= virt_base
)
1698 error("chirp: /options/virt-base conflicts with note section\n");
1701 tree_parse(root
, "/options/virt-base 0x%lx",
1702 chirp
->real_mode
? -1 : (unsigned long)chirp
->virt_base
);
1704 /* resolve virt-size */
1705 chirp
->virt_size
= chirp
->real_size
;
1706 if (note
.found
== note_correct
1707 && note
.desc
.virt_size
!= (signed32
)-1
1708 && note
.desc
.virt_size
!= 0
1709 && !chirp
->real_mode
1710 && chirp
->virt_size
> note
.desc
.virt_size
)
1711 error("chirp: insufficent virtual memory for firmware\n");
1712 if (tree_find_property(root
, "/options/virt-size") != NULL
) {
1713 if (chirp
->virt_size
> tree_find_integer_property(root
, "/options/virt-size"))
1714 error("chirp: /options/virt-size conflicts with note section\n");
1717 tree_parse(root
, "/options/virt-size 0x%lx",
1718 chirp
->real_mode
? -1 : (unsigned long)chirp
->virt_size
);
1720 /* resolve load-base */
1721 if (note
.found
== note_correct
1722 && note
.desc
.load_base
!= (signed32
)-1)
1723 chirp
->load_base
= note
.desc
.load_base
;
1724 else if (tree_find_property(root
, "/options/load-base") != NULL
)
1725 chirp
->load_base
= tree_find_integer_property(root
, "/options/load-base");
1727 chirp
->load_base
= CHIRP_LOAD_BASE
;
1728 if (tree_find_property(root
, "/options/load-base") != NULL
) {
1729 if (chirp
->load_base
!= tree_find_integer_property(root
, "/options/load-base"))
1730 error("chirp: /options/load-base conflicts with note section\n");
1733 tree_parse(root
, "/options/load-base 0x%lx",
1734 (unsigned long)chirp
->load_base
);
1736 /* now adjust the preliminary firmware addresses to final values */
1737 chirp
->code_ra
= chirp
->code_offset
+ chirp
->real_base
;
1738 chirp
->stack_ra
= chirp
->stack_offset
+ chirp
->real_base
;
1739 chirp
->htab_ra
= chirp
->htab_offset
+ chirp
->real_base
;
1741 /* the virtual addresses. In real mode these are real addresses. */
1743 chirp
->code_va
= chirp
->code_offset
+ chirp
->virt_base
;
1744 chirp
->stack_va
= chirp
->stack_offset
+ chirp
->virt_base
;
1745 chirp
->htab_va
= chirp
->htab_offset
+ chirp
->virt_base
;
1747 chirp
->code_client_va
= chirp
->code_va
;
1748 chirp
->code_client_ra
= chirp
->code_ra
;
1750 chirp
->code_callback_va
= chirp
->code_client_va
+ 16;
1751 chirp
->code_callback_ra
= chirp
->code_client_ra
+ 16;
1753 chirp
->code_loop_va
= chirp
->code_callback_va
+ 16;
1754 chirp
->code_loop_ra
= chirp
->code_callback_ra
+ 16;
1756 /* initialization */
1758 tree_parse(root
, "/openprom/init");
1759 tree_parse(root
, "/openprom/init/register");
1760 tree_parse(root
, "/openprom/init/register/0.pc 0x%lx",
1761 (unsigned long)bfd_get_start_address(image
));
1762 tree_parse(root
, "/openprom/init/register/pc 0x%lx",
1763 (unsigned long)chirp
->code_loop_va
);
1764 tree_parse(root
, "/openprom/init/register/msr 0x%x",
1765 (msr_machine_check_enable
1768 : (msr_instruction_relocate
1769 | msr_data_relocate
))
1770 | (chirp
->little_endian
1771 ? (msr_little_endian_mode
1772 | msr_interrupt_little_endian_mode
)
1774 | (chirp
->floating_point_available
1775 ? msr_floating_point_available
1777 | (chirp
->interrupt_prefix
1778 ? msr_interrupt_prefix
1781 tree_parse(root
, "/openprom/init/register/sdr1 0x%lx",
1782 (unsigned long)(chirp
->htab_ra
1784 | ((chirp
->sizeof_htab
- 1) >> 16)));
1785 /* make certain that the segment registers map straight through */
1786 for (i
= 0; i
< 16; i
++) {
1787 tree_parse(root
, "/openprom/init/register/sr%d 0x%lx",
1788 i
, (unsigned long)i
);
1791 /* establish an initial state for all processors */
1794 /* the client interface address */
1795 tree_parse(root
, "/openprom/init/register/r5 0x%lx",
1796 (unsigned long)chirp
->code_client_va
);
1798 tree_parse(root
, "/openprom/init/register/sp 0x%lx",
1799 (unsigned long)(chirp
->stack_va
+ chirp
->sizeof_stack
- 16));
1800 /* in chrp mode any arguments end up being concatinated */
1801 tree_parse(root
, "/openprom/init/stack/stack-type chirp");
1804 /* client interface - emul-call followed by return instruction */
1807 node
= tree_parse(root
, "/openprom/init/data@0x%lx",
1808 (unsigned long)chirp
->code_client_ra
);
1809 tree_parse(node
, "./psim,description \"client-interface instruction");
1810 tree_parse(node
, "./real-address 0x%lx",
1811 (unsigned long)chirp
->code_client_ra
);
1812 tree_parse(node
, "./data 0x%lx",
1813 (unsigned long)emul_call_instruction
);
1815 node
= tree_parse(root
, "/openprom/init/data@0x%lx",
1816 (unsigned long)(chirp
->code_client_ra
+ 4));
1817 tree_parse(node
, "./psim,description \"client-interface return instruction");
1818 tree_parse(node
, "./real-address 0x%lx",
1819 (unsigned long)(chirp
->code_client_ra
+ 4));
1820 tree_parse(node
, "./data 0x%lx",
1821 (unsigned long)emul_blr_instruction
);
1824 /* return address for client callbacks - an emul-call instruction
1825 that is again followed by a return instruction */
1828 node
= tree_parse(root
, "/openprom/init/data@0x%lx",
1829 (unsigned long)chirp
->code_callback_ra
);
1830 tree_parse(node
, "./psim,description \"client-callback instruction");
1831 tree_parse(node
, "./real-address 0x%lx",
1832 (unsigned long)chirp
->code_callback_ra
);
1833 tree_parse(node
, "./data 0x%lx",
1834 (unsigned long)emul_call_instruction
);
1836 node
= tree_parse(root
, "/openprom/init/data@0x%lx",
1837 (unsigned long)(chirp
->code_callback_ra
+ 4));
1838 tree_parse(node
, "./psim,description \"client-callback return instruction");
1839 tree_parse(node
, "./real-address 0x%lx",
1840 (unsigned long)(chirp
->code_callback_ra
+ 4));
1841 tree_parse(node
, "./data 0x%lx",
1842 (unsigned long)emul_blr_instruction
);
1844 /* loop to keep other processors busy */
1846 node
= tree_parse(root
, "/openprom/init/data@0x%lx",
1847 (unsigned long)chirp
->code_loop_ra
);
1848 tree_parse(node
, "./psim,description \"processor busy loop");
1849 tree_parse(node
, "./real-address 0x%lx",
1850 (unsigned long)chirp
->code_loop_ra
);
1851 tree_parse(node
, "./data 0x%lx",
1852 (unsigned long)emul_loop_instruction
);
1856 /* create a hash table */
1858 if (!chirp
->real_mode
) {
1859 node
= tree_parse(root
, "/openprom/init/htab@0x%lx",
1860 (unsigned long)chirp
->htab_ra
);
1861 tree_parse(node
, "./claim 0");
1862 tree_parse(node
, "./real-address 0x%lx",
1863 (unsigned long)chirp
->htab_ra
);
1864 tree_parse(node
, "./nr-bytes 0x%lx",
1865 (unsigned long)chirp
->sizeof_htab
);
1868 /* map in the stack */
1870 if (!chirp
->real_mode
) {
1871 node
= tree_parse(root
, "/openprom/init/htab/pte@0x%lx",
1872 (unsigned long)chirp
->stack_ra
);
1873 tree_parse(node
, "./psim,description \"map in the stack");
1874 tree_parse(node
, "./claim 1");
1875 tree_parse(node
, "./virtual-address 0x%lx",
1876 (unsigned long)chirp
->stack_va
);
1877 tree_parse(node
, "./real-address 0x%lx",
1878 (unsigned long)chirp
->stack_ra
);
1879 tree_parse(node
, "./nr-bytes 0x%lx",
1880 (unsigned long)chirp
->sizeof_stack
);
1881 tree_parse(node
, "./wimg %d", 0x7);
1882 tree_parse(node
, "./pp %d", 0x2);
1885 /* map in the chrp openboot callback code */
1887 if (!chirp
->real_mode
) {
1888 node
= tree_parse(root
, "/openprom/init/htab/pte@0x%lx",
1889 (unsigned long)chirp
->code_ra
);
1890 tree_parse(node
, "./psim,description \"map in chrp openboot callback code");
1891 tree_parse(node
, "./claim 1");
1892 tree_parse(node
, "./virtual-address 0x%lx",
1893 (unsigned long)chirp
->code_va
);
1894 tree_parse(node
, "./real-address 0x%lx",
1895 (unsigned long)chirp
->code_ra
);
1896 tree_parse(node
, "./nr-bytes 0x%lx",
1897 (unsigned long)chirp
->sizeof_code
);
1898 tree_parse(node
, "./wimg %d", 0x7);
1899 tree_parse(node
, "./pp %d", 0x2);
1902 /* map in the program to run */
1904 if (chirp
->real_mode
) {
1905 node
= tree_parse(node
, "/openprom/init/load-binary");
1906 tree_parse(node
, "./psim,description \"load the binary");
1907 tree_parse(node
, "./file-name %s", bfd_get_filename(image
));
1908 tree_parse(node
, "./claim 1");
1911 node
= tree_parse(root
, "/openprom/init/htab/pte@0x%lx",
1912 (unsigned long)chirp
->load_base
);
1913 tree_parse(node
, "./psim,description \"load & map the binary");
1914 tree_parse(node
, "./claim 1");
1915 tree_parse(node
, "./file-name \"%s", bfd_get_filename(image
));
1916 tree_parse(node
, "./wimg %d", 0x7);
1917 tree_parse(node
, "./pp %d", 0x2);
1920 /* map in the interrupt vectors */
1922 if (!chirp
->real_mode
) {
1923 node
= tree_parse(root
, "/openprom/init/htab/pte@0x0");
1924 tree_parse(node
, "./psim,description \"map in interrupt vectors");
1925 tree_parse(node
, "./virtual-address 0x0");
1926 tree_parse(node
, "./real-address 0x0");
1927 tree_parse(node
, "./nr-bytes 0x3000");
1928 tree_parse(node
, "./wimg %d", 0x7);
1929 tree_parse(node
, "./pp %d", 0x2);
1936 emul_chirp_init(os_emul_data
*emul_data
,
1939 emul_data
->state
= serving
;
1943 emul_chirp_instruction_call(cpu
*processor
,
1946 os_emul_data
*emul_data
)
1948 unsigned_word service_name_addr
;
1949 unsigned_word result
;
1950 char service_buf
[32];
1952 chirp_services
*service
;
1954 switch (emul_data
->state
) {
1957 /* we are waiting on an OpenBoot request from the client program
1958 via the client interface */
1959 if (cia
!= emul_data
->code_client_va
)
1961 emul_data
->return_address
= LR
;
1962 emul_data
->arguments
= cpu_registers(processor
)->gpr
[3];
1963 /* try to determine what to do */
1964 service_name_addr
= emul_read_word(cpu_registers(processor
)->gpr
[3],
1966 service_name
= emul_read_string(service_buf
, service_name_addr
,
1967 sizeof(service_buf
), processor
, cia
);
1968 emul_data
->n_args
= emul_read_word(emul_data
->arguments
+ sizeof(unsigned_cell
),
1970 emul_data
->n_returns
= emul_read_word(emul_data
->arguments
+ 2 * sizeof(unsigned_cell
),
1972 /* verify what was passed */
1973 if (service_name_addr
== 0
1974 || service_name
== NULL
) {
1975 error("OpenFirmware called with invalid (NULL) service name from 0x%lx with args 0x%lx\n",
1976 (unsigned long)emul_data
->return_address
,
1977 (unsigned long)emul_data
->arguments
);
1979 if (emul_data
->n_args
> 6) { /* See iee1275 requirements on nr returns */
1980 error("OpenFirmware service %s called from 0x%lx with args 0x%lx, too many args (%d)\n",
1981 (unsigned long)emul_data
->return_address
,
1982 (unsigned long)emul_data
->arguments
,
1983 emul_data
->n_returns
);
1985 if (emul_data
->n_returns
> 6) {
1986 error("OpenFirmware service %s called from 0x%lx with args 0x%lx, with too many returns (%d)\n",
1987 (unsigned long)emul_data
->return_address
,
1988 (unsigned long)emul_data
->arguments
,
1992 TRACE(trace_os_emul
, ("%s called from 0x%lx with args 0x%lx\n",
1994 (unsigned long)emul_data
->return_address
,
1995 (unsigned long)emul_data
->arguments
));
1997 while (service
->name
!= NULL
&& strcmp(service
->name
, service_name
) != 0)
2000 if (service
->name
== NULL
) {
2001 error("OpenBoot service `%s' not found\n", service_name
);
2002 TRACE(trace_os_emul
, ("%s not found\n", service_name
));
2003 cpu_registers(processor
)->gpr
[3] = -1;
2006 emul_data
->service
= service
;
2008 result
= service
->handler(emul_data
, processor
, cia
);
2010 TRACE(trace_os_emul
, ("%s aborted with %ld\n", service_name
, (long)result
));
2011 cpu_registers(processor
)->gpr
[3] = result
;
2016 error("emul_chirp_instruction_call() unknown internal state\n");
2022 /* return to caller - instruction following this is a function return */
2026 const os_emul emul_chirp
= {
2030 NULL
, /*system_call*/
2031 emul_chirp_instruction_call
,