1 | | |
2 | | |
3 | | |
4 | | |
5 | | |
6 | | |
7 | | |
8 | | |
9 | | |
10 | | |
11 | | |
12 | | |
13 | | |
14 | | |
15 | | |
16 | | |
17 | | |
18 | | |
19 | | |
20 | | |
21 | | |
22 | | |
23 | | |
24 | | |
25 | | |
26 | | |
27 | | |
28 | | |
29 | | |
30 | | |
31 | | |
32 | | |
33 | | |
34 | | |
35 | | |
36 | | |
37 | | |
38 | | |
39 | | |
40 | | |
41 | | |
42 | | |
43 | | |
44 | | |
45 | | |
46 | | |
47 | | |
48 | | |
49 | | |
50 | | |
51 | | |
52 | | |
53 | | |
54 | | |
55 | | |
56 | | |
57 | | |
58 | | |
59 | | |
60 | | |
61 | | |
62 | | |
63 | | |
64 | | |
65 | | |
66 | | |
67 | | |
68 | | |
69 | | |
70 | | |
71 | | |
72 | | |
73 | | |
74 | | |
75 | | |
76 | | |
77 | | |
78 | | |
79 | | |
80 | | |
81 | | |
82 | | |
83 | | |
84 | | |
85 | | |
86 | | |
87 | | |
88 | | |
89 | | |
90 | | |
91 | | |
92 | | |
93 | | |
94 | | |
95 | | |
96 | | |
97 | | |
98 | | |
99 | | |
100 | | |
101 | | |
102 | | |
103 | | |
104 | | |
105 | | |
106 | | |
107 | | |
108 | | |
109 | | |
110 | | |
111 | | |
112 | | |
113 | | |
114 | | |
115 | | |
116 | | |
117 | | |
118 | | |
119 | | |
120 | | |
121 | | |
122 | | |
123 | | |
124 | | |
125 | | |
126 | | |
127 | | |
128 | | |
129 | | |
130 | | |
131 | | |
132 | | |
133 | | |
134 | | |
135 | | |
136 | | |
137 | | |
138 | | |
139 | | |
140 | | |
141 | | |
142 | | |
143 | | |
144 | | |
145 | | |
146 | | |
147 | | |
148 | | |
149 | | |
150 | | |
151 | | |
152 | | |
153 | | |
154 | | |
155 | | |
156 | | |
157 | | |
158 | | |
159 | | |
160 | | |
161 | | |
162 | | |
163 | | |
164 | | |
165 | | |
166 | | |
167 | | |
168 | | |
169 | | |
170 | | |
171 | | |
172 | | |
173 | | |
174 | | |
175 | | |
176 | | |
177 | | |
178 | | |
179 | | |
180 | | |
181 | | |
182 | | |
183 | | |
184 | | |
185 | | |
186 | | |
187 | | |
188 | | |
189 | | |
190 | | |
191 | | |
192 | | |
193 | | |
194 | | |
195 | | |
196 | | |
197 | | |
198 | | |
199 | | |
200 | | |
201 | | |
202 | | |
203 | | |
204 | | |
205 | | |
206 | | |
207 | | |
208 | | |
209 | | |
210 | | |
211 | | |
212 | | |
213 | | |
214 | | |
215 | | |
216 | | |
217 | | |
218 | | |
219 | | |
220 | | |
221 | | |
222 | | |
223 | | |
224 | | |
225 | | |
226 | | |
227 | | |
228 | | |
229 | | |
230 | | |
231 | | |
232 | | |
233 | | |
234 | | |
235 | | |
236 | | |
237 | | |
238 | | |
239 | | |
240 | | |
241 | | |
242 | | |
243 | | |
244 | | |
245 | | |
246 | | |
247 | | |
248 | | |
249 | | |
250 | | |
251 | | |
252 | | |
253 | | |
254 | | |
255 | | |
256 | | |
257 | | |
258 | | |
259 | | |
260 | | |
261 | | |
262 | | |
263 | | |
264 | | |
265 | | |
266 | | |
267 | | |
268 | | |
269 | | |
270 | | |
271 | | |
272 | | |
273 | | |
274 | | |
275 | | |
276 | | |
277 | | |
278 | | |
279 | | |
280 | | |
281 | | |
282 | | |
283 | | |
284 | | |
285 | | |
286 | | |
287 | | |
288 | | |
289 | | |
290 | | |
291 | | |
292 | | |
293 | | |
294 | | |
295 | | |
296 | | |
297 | | |
298 | | |
299 | | |
300 | | |
301 | | |
302 | | |
303 | | |
304 | | |
305 | | |
306 | | |
307 | | |
308 | | |
309 | | |
310 | | |
311 | | |
312 | | |
313 | | |
314 | | |
315 | | |
316 | | |
317 | | |
318 | | |
319 | | |
320 | | |
321 | | |
322 | | |
323 | | |
324 | | |
325 | | |
326 | | |
327 | | |
328 | | |
329 | | |
330 | | |
331 | | |
332 | | |
333 | | |
334 | | |
335 | | |
336 | | |
337 | | |
338 | | |
339 | | |
340 | | |
341 | | |
342 | | |
343 | | |
344 | | |
345 | | |
346 | | |
347 | | |
348 | | |
349 | | |
350 | | |
351 | | |
352 | | |
353 | | |
354 | | |
355 | | |
356 | | |
357 | | |
358 | | |
359 | | |
360 | | |
361 | | |
362 | | |
363 | | |
364 | | |
365 | | |
366 | | |
367 | | |
368 | | |
369 | | |
370 | | |
371 | | |
372 | | |
373 | | |
374 | | |
375 | | |
376 | | |
377 | | |
378 | | |
379 | | |
380 | | |
381 | | |
382 | | |
383 | | |
384 | | |
385 | | |
386 | | |
387 | | |
388 | | |
389 | | |
390 | | |
391 | | |
392 | | |
393 | | |
394 | | |
395 | | |
396 | | |
397 | | |
398 | | |
399 | | |
400 | | |
401 | | |
402 | | |
403 | | |
404 | | |
405 | | |
406 | | |
407 | | |
408 | | |
409 | | |
410 | | |
411 | | |
412 | | |
413 | | |
414 | | |
415 | | |
416 | | |
417 | | |
418 | | |
419 | | |
420 | | |
421 | | |
422 | | |
423 | | |
424 | | |
425 | | |
426 | | |
427 | | |
428 | | |
429 | | |
430 | | |
431 | | |
432 | | |
433 | | |
434 | | |
435 | | |
436 | | |
437 | | |
438 | | |
439 | | |
440 | | |
441 | | |
442 | | |
443 | | |
444 | | |
445 | | |
446 | | |
447 | | |
448 | | |
449 | | |
450 | | |
451 | | |
452 | | |
453 | | |
454 | | |
455 | | |
456 | | |
457 | | |
458 | | |
459 | | |
460 | | |
461 | | |
462 | | |
463 | | |
464 | | |
465 | | |
466 | | |
467 | | |
468 | | |
469 | | |
470 | | |
471 | | |
472 | | |
473 | | |
474 | | |
475 | | |
476 | | |
477 | | |
478 | | |
479 | | |
480 | | |
481 | | |
482 | | |
483 | | |
484 | | |
485 | | |
486 | | |
487 | | |
488 | | |
489 | | |
490 | | |
491 | | |
492 | | |
493 | | |
494 | | |
495 | | |
496 | | |
497 | | |
498 | | |
499 | | |
500 | | |
501 | | |
502 | | |
503 | | |
504 | | |
505 | | |
506 | | |
507 | | |
508 | | |
509 | | |
510 | | |
511 | | |
512 | | |
513 | | |
514 | | |
515 | | |
516 | | |
517 | | |
518 | | |
519 | | |
520 | | |
521 | | |
522 | | |
523 | | |
524 | | |
525 | | |
526 | | |
527 | | |
528 | | |
529 | | |
530 | | |
531 | | |
532 | | |
533 | | |
534 | | |
535 | | |
536 | | |
537 | | |
538 | | |
539 | | |
540 | | |
541 | | |
542 | | |
543 | | |
544 | | |
545 | | |
546 | | |
547 | | |
548 | | |
549 | | |
550 | | |
551 | | |
552 | | |
553 | | |
554 | | |
555 | | |
556 | | |
557 | | |
558 | | |
559 | | |
560 | | |
561 | | |
562 | | |
563 | | |
564 | | |
565 | | |
566 | | |
567 | | |
568 | | |
569 | | |
570 | | |
571 | | |
572 | | |
573 | | |
574 | | |
575 | | |
576 | | |
577 | | |
578 | | |
579 | | |
580 | | |
581 | | |
582 | | |
583 | | |
584 | | |
585 | | |
586 | | |
587 | | |
588 | | |
589 | | |
590 | | |
591 | | |
592 | | |
593 | | |
594 | | |
595 | | |
596 | | |
597 | | |
598 | | |
599 | | |
600 | | |
601 | | |
602 | | |
603 | | |
604 | | |
605 | | |
606 | | |
607 | | |
608 | | |
609 | | |
610 | | |
611 | | |
612 | | |
613 | | |
614 | | |
615 | | |
616 | | |
617 | | |
618 | | |
619 | | |
620 | | |
621 | | |
622 | | |
623 | | |
624 | | |
625 | | |
626 | | |
627 | | |
628 | | |
629 | | |
630 | | |
631 | | |
632 | | |
633 | | |
634 | | |
635 | | |
636 | | |
637 | | |
638 | | |
639 | | |
640 | | |
641 | | |
642 | | |
643 | | |
644 | | |
645 | | |
646 | | |
647 | | |
648 | | |
649 | | |
650 | | |
651 | | |
652 | | |
653 | | |
654 | | |
655 | | |
656 | | |
657 | | |
658 | | |
659 | | |
660 | | |
661 | | |
662 | | |
663 | | |
664 | | |
665 | | |
666 | | |
667 | | |
668 | | |
669 | | |
670 | | |
671 | | |
672 | | |
673 | | |
674 | | |
675 | | |
676 | | |
677 | | |
678 | | |
679 | | |
680 | | |
681 | | |
682 | | |
683 | | |
684 | | |
685 | | |
686 | | |
687 | | |
688 | | |
689 | | |
690 | | |
691 | | |
692 | | |
693 | | |
694 | | |
695 | | |
696 | | |
697 | | |
698 | | |
699 | | |
700 | | |
701 | | |
702 | | |
703 | | |
704 | | |
705 | | |
706 | | |
707 | | |
708 | | |
709 | | |
710 | | |
711 | | |
712 | | |
713 | | |
714 | | |
715 | | |
716 | | |
717 | | |
718 | | |
719 | | |
720 | | |
721 | | |
722 | | |
723 | | |
724 | | |
725 | | |
726 | | |
727 | | |
728 | | |
729 | | |
730 | | |
731 | | |
732 | | |
733 | | |
734 | | |
735 | | |
736 | | |
737 | | |
738 | | |
739 | | |
740 | | |
741 | | |
742 | | |
743 | | |
744 | | |
745 | | |
746 | | |
747 | | |
748 | | |
749 | | |
750 | | |
751 | | |
752 | | |
753 | | |
754 | | |
755 | | |
756 | | |
757 | | |
758 | | |
759 | | |
760 | | |
761 | | |
762 | | |
763 | | |
764 | | |
765 | | |
766 | | |
767 | | |
768 | | |
769 | | |
770 | | |
771 | | |
772 | | |
773 | | |
774 | | |
775 | | |
776 | | |
777 | | |
778 | | |
779 | | |
780 | | |
781 | | |
782 | | |
783 | | |
784 | | |
785 | | |
786 | | |
787 | | |
788 | | |
789 | | |
790 | | |
791 | | |
792 | | |
793 | | |
794 | | |
795 | | |
796 | | |
797 | | |
798 | | |
799 | | |
800 | | |
801 | | |
802 | | |
803 | | |
804 | | |
805 | | |
806 | | |
807 | | |
808 | | |
809 | | |
810 | | |
811 | | |
812 | | |
813 | | |
814 | | |
815 | | |
816 | | |
817 | | |
818 | | |
819 | | |
820 | | |
821 | | |
822 | | |
823 | | |
824 | | |
825 | | |
826 | | |
827 | | |
828 | | |
829 | | |
830 | | |
831 | | |
832 | | |
833 | | |
834 | | |
835 | | |
836 | | |
837 | | |
838 | | |
839 | | |
840 | | |
841 | | |
842 | | |
843 | | |
844 | | |
845 | | |
846 | | |
847 | | |
848 | | |
849 | | |
850 | | |
851 | | |
852 | | |
853 | | |
854 | | |
855 | | |
856 | | |
857 | | |
858 | | |
859 | | |
860 | | |
861 | | |
862 | | |
863 | | |
864 | | |
865 | | |
866 | | |
867 | | |
868 | | |
869 | | |
870 | | |
871 | | |
872 | | |
873 | | |
874 | | |
875 | | |
876 | | |
877 | | |
878 | | |
879 | | |
880 | | |
881 | | |
882 | | |
883 | | |
884 | | |
885 | | |
886 | | |
887 | | |
888 | | |
889 | | |
890 | | |
891 | | |
892 | | |
893 | | |
894 | | |
895 | | |
896 | | |
897 | | |
898 | | |
899 | | |
900 | | |
901 | | |
902 | | |
903 | | |
904 | | |
905 | | |
906 | | |
907 | | |
908 | | |
909 | | |
910 | | |
911 | | |
912 | | |
913 | | |
914 | | |
915 | | |
916 | | |
917 | | |
918 | | |
919 | | |
920 | | |
921 | | |
922 | | |
923 | | |
924 | | |
925 | | |
926 | | |
927 | | |
928 | | |
929 | | |
930 | | |
931 | | |
932 | | |
933 | | |
934 | | |
935 | | |
936 | | |
937 | | |
938 | | |
939 | | |
940 | | |
941 | | |
942 | | |
943 | | |
944 | | |
945 | | |
946 | | |
947 | | |
948 | | |
949 | | |
950 | | |
951 | | |
952 | | |
953 | | |
954 | | |
955 | | |
956 | | |
957 | | |
958 | | |
959 | | |
960 | | |
961 | | |
962 | | |
963 | | |
964 | | |
965 | | |
966 | | |
967 | | |
968 | | |
969 | | |
970 | | |
971 | | |
972 | | |
973 | | |
974 | | |
975 | | |
976 | | |
977 | | |
978 | | |
979 | | |
980 | | |
981 | | |
982 | | |
983 | | |
984 | | |
985 | | |
986 | | |
987 | | |
988 | | |
989 | | |
990 | | |
991 | | |
992 | | |
993 | | |
994 | | |
995 | | |
996 | | |
997 | | |
998 | | |
999 | | |
1000 | | |
1001 | | |
1002 | | |
1003 | | |
1004 | | |
1005 | | |
1006 | | |
1007 | | |
1008 | | |
1009 | | |
1010 | | |
1011 | | |
1012 | | |
1013 | | |
1014 | | |
1015 | | |
1016 | | |
1017 | | |
1018 | | |
1019 | | |
1020 | | |
1021 | | |
1022 | | |
1023 | | |
1024 | | |
1025 | | |
1026 | | |
1027 | | |
1028 | | |
1029 | | |
1030 | | |
1031 | | |
1032 | | |
1033 | | |
1034 | | |
1035 | | |
1036 | | |
1037 | | |
1038 | | |
1039 | | |
1040 | | |
1041 | | |
1042 | | |
1043 | | |
1044 | | |
1045 | | |
1046 | | |
1047 | | |
1048 | | |
1049 | | |
1050 | | |
1051 | | |
1052 | | |
1053 | | |
1054 | | |
1055 | | |
1056 | | |
1057 | | |
1058 | | |
1059 | | |
1060 | | |
1061 | | |
1062 | | |
1063 | | |
1064 | | |
1065 | | |
1066 | | |
1067 | | |
1068 | | |
1069 | | |
1070 | | |
1071 | | |
1072 | | |
1073 | | |
1074 | | |
1075 | | |
1076 | | |
1077 | | |
1078 | | |
1079 | | |
1080 | | |
1081 | | |
1082 | | |
1083 | | |
1084 | | |
1085 | | |
1086 | | |
1087 | | |
1088 | | |
1089 | | |
1090 | | |
1091 | | |
1092 | | |
1093 | | |
1094 | | |
1095 | | |
1096 | | |
1097 | | |
1098 | | |
1099 | | |
1100 | | |
1101 | | |
1102 | | |
1103 | | |
1104 | | |
1105 | | |
1106 | | |
1107 | | |
1108 | | |
1109 | | |
1110 | | |
1111 | | |
1112 | | |
1113 | | |
1114 | | |
1115 | | |
1116 | | |
1117 | | |
1118 | | |
1119 | | |
1120 | | |
1121 | | |
1122 | | |
1123 | | |
1124 | | |
1125 | | |
1126 | | |
1127 | | |
1128 | | |
1129 | | |
1130 | | |
1131 | | |
1132 | | |
1133 | | |
1134 | | |
1135 | | |
1136 | | |
1137 | | |
1138 | | |
1139 | | |
1140 | | |
1141 | | |
1142 | | |
1143 | | |
1144 | | |
1145 | | |
1146 | | |
1147 | | |
1148 | | |
1149 | | |
1150 | | |
1151 | | |
1152 | | |
1153 | | |
1154 | | |
1155 | | |
1156 | | |
1157 | | |
1158 | | |
1159 | | |
1160 | | |
1161 | | |
1162 | | |
1163 | | |
1164 | | |
1165 | | |
1166 | | |
1167 | | |
1168 | | |
1169 | | |
1170 | | |
1171 | | |
1172 | | |
1173 | | |
1174 | | |
1175 | | |
1176 | | |
1177 | | |
1178 | | |
1179 | | |
1180 | | |
1181 | | |
1182 | | |
1183 | | |
1184 | | |
1185 | | |
1186 | | |
1187 | | |
1188 | | |
1189 | | |
1190 | | |
1191 | | |
1192 | | |
1193 | | |
1194 | | |
1195 | | |
1196 | | |
1197 | | |
1198 | | |
1199 | | |
1200 | | |
1201 | | |
1202 | | |
1203 | | |
1204 | | |
1205 | | |
1206 | | |
1207 | | |
1208 | | |
1209 | | |
1210 | | |
1211 | | |
1212 | | |
1213 | | |
1214 | | |
1215 | | |
1216 | | |
1217 | | |
1218 | | |
1219 | | |
1220 | | |
1221 | | |
1222 | | |
1223 | | |
1224 | | |
1225 | | |
1226 | | |
1227 | | |
1228 | | |
1229 | | |
1230 | | |
1231 | | |
1232 | | |
1233 | | |
1234 | | |
1235 | | |
1236 | | |
1237 | | |
1238 | | |
1239 | | |
1240 | | |
1241 | | |
1242 | | |
1243 | | |
1244 | | |
1245 | | |
1246 | | |
1247 | | |
1248 | | |
1249 | | |
1250 | | |
1251 | | |
1252 | | |
1253 | | |
1254 | | |
1255 | | |
1256 | | |
1257 | | |
1258 | | |
1259 | | |
1260 | | |
1261 | | |
1262 | | |
1263 | | |
| | | | | | | | | | | | | #include "operators.h" | #include "constants.h" | #include "object.h" | #include "builtin_functions.h" | | | | #ifdef HAVE_CORESERVICES_CORESERVICES_H | #include <CoreServices/CoreServices.h> | #endif | | | #if PIKE_BYTEORDER == 1234 | #define MAKE_TYPE_WORD(t,st) ((t)|((st)<<16)) | #else | #define MAKE_TYPE_WORD(t,st) ((st)|((t)<<16)) | #endif | | #if _CALL_ELF == 2 | | #define ADD_CALL(X) do { \ | INT64 func_=(INT64)(void*)(X); \ | \ | SET_REG64(12, func_); \ | /* mtlr r12 */ \ | MTSPR(12, PPC_SPREG_LR); \ | /* blrl */ \ | BCLRL(20, 0); \ | } while(0) | | #else | | #define ADD_CALL(X) do { \ | INT64 func_=(INT64)(void*)(X); \ | \ | SET_REG64(11, (func_+32768)&~0xffff); \ | if ((func_ &= 0xffff) > 32767) \ | func_ -= 65536; \ | /* ldu r0,%lo(func)(r11) */ \ | LDU(0, 11, func_); \ | /* ld r2,%8(r11) */ \ | LD(2, 11, 8); \ | /* mtlr r0 */ \ | MTSPR(0, PPC_SPREG_LR); \ | /* blrl */ \ | BCLRL(20, 0); \ | } while(0) | | #endif | | int ppc64_codegen_state = 0, ppc64_codegen_last_pc = 0; | static int last_prog_id=-1; | | void ppc64_flush_code_generator_state() | { | if(ppc64_codegen_state & PPC_CODEGEN_SP_NEEDSSTORE) { | | STD(PPC_REG_PIKE_SP, PPC_REG_PIKE_INTERP, | OFFSETOF(Pike_interpreter_struct, stack_pointer)); | } | if(ppc64_codegen_state & PPC_CODEGEN_MARK_SP_NEEDSSTORE) { | | STD(PPC_REG_PIKE_MARK_SP, PPC_REG_PIKE_INTERP, | OFFSETOF(Pike_interpreter_struct, mark_stack_pointer)); | } | ppc64_codegen_state = 0; | last_prog_id=-1; | } | | INT32 ppc64_get_local_addr(int reg, INT32 arg) | { | INT32 offs = arg * sizeof(struct svalue); | | LOAD_FP_REG(); | | LD(reg, PPC_REG_PIKE_FP, OFFSETOF(pike_frame, locals)); | | if(offs > 32767) { | | ADDIS(reg, reg, (offs+32768)>>16); | if((offs &= 0xffff) > 32767) | offs -= 65536; | } | | return offs; | } | | void ppc64_push_svalue(int reg, INT32 offs, int force_reftype) | { | int e; | | LOAD_SP_REG(); | | if(offs > (INT32)(32768-sizeof(struct svalue))) { | | ADDI(reg, reg, offs); | offs = 0; | } | | if(sizeof(struct svalue) > 16) | { | for(e=8;e<(int)sizeof(struct svalue);e+=8) | { | if( e == OFFSETOF(svalue,u.refs)) continue; | | | LD(0, reg, e+offs); | | STD(0, PPC_REG_PIKE_SP, e); | } | } | | | LD(0, reg, offs); | | LD(11, reg, offs+OFFSETOF(svalue,u.refs)); | | STD(0, PPC_REG_PIKE_SP, 0); | if(!force_reftype) { | #if PIKE_BYTEORDER == 1234 | | RLDICL(0, 0, 61, 51); | #else | | RLDICL(0, 0, 13, 51); | #endif | } | | STD(11, PPC_REG_PIKE_SP, OFFSETOF(svalue,u.refs)); | if(!force_reftype) { | | CMPLI(0, 0, MIN_REF_TYPE>>3); | } | INCR_SP_REG(sizeof(struct svalue)); | if(!force_reftype) { | | BC(4, 2, 4); | } | | LWZ(0, 11, 0); | | ADDIC(0, 0, 1); | | STW(0, 11, 0); | | } | | void ppc64_push_constant(INT32 arg) | { | INT32 offs; | struct svalue *sval = &Pike_compiler->new_program->constants[arg].sval; | | | | | | if(!REFCOUNTED_TYPE(TYPEOF(*sval)) && !SUBTYPEOF(*sval)) { | int e; | INT64 last=0; | | LOAD_SP_REG(); | | for(e=0;e<(int)sizeof(struct svalue);e+=8) | { | if(e==0 || *(INT64 *)(((char *)sval)+e) != last) | SET_REG64(0, last = *(INT64 *)(((char *)sval)+e)); | | STD(0, PPC_REG_PIKE_SP, e); | } | | INCR_SP_REG(sizeof(struct svalue)); | | return; | } | | LOAD_FP_REG(); | | LD(PPC_REG_ARG1, PPC_REG_PIKE_FP, OFFSETOF(pike_frame, context)); | | LD(PPC_REG_ARG1, PPC_REG_ARG1, OFFSETOF(inherit, prog)); | | LD(PPC_REG_ARG1, PPC_REG_ARG1, OFFSETOF(program, constants)); | | offs = arg*sizeof(struct program_constant)+OFFSETOF(program_constant, sval); | | if(offs > 32767) { | | ADDIS(PPC_REG_ARG1, PPC_REG_ARG1, (offs+32768)>>16); | if((offs &= 0xffff) > 32767) | offs -= 65536; | } | | ppc64_push_svalue(PPC_REG_ARG1, offs, !!REFCOUNTED_TYPE(TYPEOF(*sval))); | } | | void ppc64_push_local(INT32 arg) | { | INT32 offs; | offs = ppc64_get_local_addr(PPC_REG_ARG1, arg); | ppc64_push_svalue(PPC_REG_ARG1, offs, 0); | } | | void ppc64_local_lvalue(INT32 arg) | { | INT32 offs; | int e; | | offs = ppc64_get_local_addr(PPC_REG_ARG1, arg); | LOAD_SP_REG(); | SET_REG32(0, 0); | STW(0, PPC_REG_PIKE_SP, 4); | STW(0, PPC_REG_PIKE_SP, sizeof(struct svalue)+4); | for(e=8;e<(int)(2*sizeof(struct svalue));e+=8) | { | if( e == OFFSETOF(svalue,u.lval) || e == sizeof(struct svalue) ) continue; | | STD(0, PPC_REG_PIKE_SP, e); | } | if(offs) { | | ADDI(PPC_REG_ARG1, PPC_REG_ARG1, offs); | } | | SET_REG32(0, MAKE_TYPE_WORD(T_SVALUE_PTR, 0)); | | STW(0, PPC_REG_PIKE_SP, 0); | | SET_REG32(0, MAKE_TYPE_WORD(T_VOID, 0)); | | STW(0, PPC_REG_PIKE_SP, sizeof(struct svalue)); | | STD(PPC_REG_ARG1, PPC_REG_PIKE_SP, OFFSETOF(svalue,u.lval)); | INCR_SP_REG(sizeof(struct svalue)*2); | } | | void ppc64_push_global(INT32 arg) | { | LOAD_FP_REG(); | | LD(PPC_REG_ARG3, PPC_REG_PIKE_FP, OFFSETOF(pike_frame, context)); | | LD(PPC_REG_ARG2, PPC_REG_PIKE_FP, | OFFSETOF(pike_frame, current_object)); | | LHA(PPC_REG_ARG3, PPC_REG_ARG3, OFFSETOF(inherit, identifier_level)); | if(arg > 32767) { | | ADDIS(PPC_REG_ARG3, PPC_REG_ARG3, (arg+32768)>>16); | if((arg &= 0xffff) > 32767) | arg -= 65536; | } | if(ppc64_codegen_state & PPC_CODEGEN_SP_ISSET) { | | ORI(PPC_REG_ARG1, PPC_REG_PIKE_SP, 0); | } else { | | LD(PPC_REG_ARG1, PPC_REG_PIKE_INTERP, | OFFSETOF(Pike_interpreter_struct, stack_pointer)); | } | if(arg) { | | ADDI(PPC_REG_ARG3, PPC_REG_ARG3, arg); | } | FLUSH_CODE_GENERATOR_STATE(); | ADD_CALL(low_object_index_no_free); | LOAD_SP_REG(); | INCR_SP_REG(sizeof(struct svalue)); | } | | void ppc64_push_int(INT64 x, int s) | { | LOAD_SP_REG(); | | SET_REG32(0, 0); | if(sizeof(struct svalue) > 16) | { | int e; | for(e=8;e<(int)sizeof(struct svalue);e+=8) | { | if( e == OFFSETOF(svalue,u.integer)) continue; | | STD(0, PPC_REG_PIKE_SP, e); | } | } | STW(0, PPC_REG_PIKE_SP, 4); | if(x != 0) | SET_REG64(0, x); | STD(0, PPC_REG_PIKE_SP, OFFSETOF(svalue,u.integer)); | if(x != MAKE_TYPE_WORD(PIKE_T_INT, s)) | SET_REG32(0, MAKE_TYPE_WORD(PIKE_T_INT, s)); | STW(0, PPC_REG_PIKE_SP, 0); | INCR_SP_REG(sizeof(struct svalue)); | } | | void ppc64_push_string(INT32 arg, int st) | { | INT32 offs; | | LOAD_FP_REG(); | LOAD_SP_REG(); | | | LD(11, PPC_REG_PIKE_FP, OFFSETOF(pike_frame, context)); | | LD(11, 11, OFFSETOF(inherit, prog)); | | LD(11, 11, OFFSETOF(program, strings)); | | offs = arg*sizeof(struct pike_string *); | | if(offs > 32767) { | | ADDIS(11, 11, (offs+32768)>>16); | if((offs &= 0xffff) > 32767) | offs -= 65536; | } | | | LD(11, 11, offs); | | SET_REG32(0, 0); | if(sizeof(struct svalue) > 16) | { | int e; | for(e=8;e<(int)sizeof(struct svalue);e+=8) | { | if( e == OFFSETOF(svalue,u.string)) continue; | | STD(0, PPC_REG_PIKE_SP, e); | } | } | STW(0, PPC_REG_PIKE_SP, 4); | STD(11, PPC_REG_PIKE_SP, OFFSETOF(svalue,u.string)); | if(st) | SET_REG32(0, MAKE_TYPE_WORD(PIKE_T_STRING, 1)); | else | SET_REG32(0, MAKE_TYPE_WORD(PIKE_T_STRING, 0)); | STW(0, PPC_REG_PIKE_SP, 0); | | | LWZ(0, 11, 0); | | ADDIC(0, 0, 1); | | STW(0, 11, 0); | | INCR_SP_REG(sizeof(struct svalue)); | } | | void ppc64_mark(void) | { | LOAD_SP_REG(); | LOAD_MARK_SP_REG(); | | STD(PPC_REG_PIKE_SP, PPC_REG_PIKE_MARK_SP, 0); | INCR_MARK_SP_REG(sizeof(struct svalue *)); | } | | static void ppc64_escape_catch(void) | { | LOAD_FP_REG(); | | LD(PPC_REG_ARG1, PPC_REG_PIKE_INTERP, | OFFSETOF(Pike_interpreter_struct, catch_ctx)); | | LD(PPC_REG_ARG2, PPC_REG_ARG1, | OFFSETOF(catch_context, recovery.previous)); | | STD(PPC_REG_ARG2, PPC_REG_PIKE_INTERP, | OFFSETOF(Pike_interpreter_struct, recoveries)); | | LD(PPC_REG_ARG2, PPC_REG_ARG1, | OFFSETOF(catch_context, prev)); | | STD(PPC_REG_ARG2, PPC_REG_PIKE_INTERP, | OFFSETOF(Pike_interpreter_struct, catch_ctx)); | | FLUSH_CODE_GENERATOR_STATE(); | ADD_CALL(really_free_catch_context); | } | | static void maybe_update_pc(void) | { | static unsigned int last_num_linenumbers=~0; | if(last_prog_id != Pike_compiler->new_program->id || | last_num_linenumbers != Pike_compiler->new_program->num_linenumbers) | { | last_prog_id=Pike_compiler->new_program->id; | last_num_linenumbers = Pike_compiler->new_program->num_linenumbers; | UPDATE_PC(); | } | } | | #ifdef OPCODE_INLINE_RETURN | void ppc64_ins_entry(void) | { | | STDU(1, 1, -128); | | MFSPR(0, PPC_SPREG_LR); | | STD(0, 1, 144); | | STD(2, 1, 120); | } | #endif /* OPCODE_INLINE_RETURN */ | | void ins_f_byte(unsigned int b) | { | void *addr; | INT32 rel_addr; | | b-=F_OFFSET; | #ifdef PIKE_DEBUG | if(b > MAX_SUPPORTED_INSTR) | Pike_error("Instruction too big %d\n",b); | #endif | maybe_update_pc(); | addr = instrs[b].address; | | #ifdef PIKE_DEBUG | if (d_flag < 3) | #endif | | switch(b) | { | case F_MARK2 - F_OFFSET: | ppc64_mark(); | case F_MARK - F_OFFSET: | ppc64_mark(); | return; | | case F_CONST0 - F_OFFSET: | ppc64_push_int(0, 0); | return; | | case F_CONST1 - F_OFFSET: | ppc64_push_int(1, 0); | return; | | case F_CONST_1 - F_OFFSET: | ppc64_push_int(-1, 0); | return; | | case F_MAKE_ITERATOR - F_OFFSET: | { | SET_REG32(PPC_REG_ARG1, 1); | addr = (void *)f_get_iterator; | } | break; | case F_ADD - F_OFFSET: | SET_REG32(PPC_REG_ARG1, 2); | addr = (void *)f_add; | break; | | case F_EXIT_CATCH - F_OFFSET: | ppc64_push_int(0, 1); | case F_ESCAPE_CATCH - F_OFFSET: | ppc64_escape_catch(); | return; | | #ifdef OPCODE_INLINE_RETURN | case F_CATCH - F_OFFSET: | | addr = inter_return_opcode_F_CATCH; | | BL(4); | | MFSPR(PPC_REG_ARG1, PPC_SPREG_LR); | rel_addr = PIKE_PC; | | ADDI(PPC_REG_ARG1, PPC_REG_ARG1, 4); | break; | case F_CATCH_AT - F_OFFSET: | | addr = inter_return_opcode_F_CATCH_AT; | | BL(4); | | MFSPR(PPC_REG_ARG1, PPC_SPREG_LR); | rel_addr = PIKE_PC; | | ADDI(PPC_REG_ARG1, PPC_REG_ARG1, 4); | break; | #endif | } | | FLUSH_CODE_GENERATOR_STATE(); | ADD_CALL(addr); | #ifdef OPCODE_INLINE_RETURN | if (instrs[b].flags & I_RETURN) { | | CMPI(1, PPC_REG_RET, -1); | | BC(4, 2, 6); | | LD(0, 1, 144); | | LD(2, 1, 120); | | ADDI(1, 1, 128); | | MTSPR(0, PPC_SPREG_LR); | | BCLR(20, 0); | | if ((b + F_OFFSET) == F_RETURN_IF_TRUE) { | | | | | MFSPR(0, PPC_SPREG_LR); | | SUBF(0, 0, PPC_REG_RET); | | CMPLI(1, 0, JUMP_EPILOGUE_SIZE*4); | | BC(12, 2, 3); | } | } | #endif | #ifdef OPCODE_RETURN_JUMPADDR | if (instrs[b].flags & I_JUMP) { | | | MTSPR(PPC_REG_RET, PPC_SPREG_LR); | | BCLR(20, 0); | | #ifdef OPCODE_INLINE_RETURN | if ((b == F_CATCH - F_OFFSET) || (b == F_CATCH_AT - F_OFFSET)) { | Pike_compiler->new_program->program[rel_addr] += (PIKE_PC - rel_addr)*4; | } | #endif | } | #endif | } | | void ins_f_byte_with_arg(unsigned int a, INT32 b) | { | maybe_update_pc(); | | #ifdef PIKE_DEBUG | if (d_flag < 3) | #endif | switch(a) | { | case F_MARK_AND_LOCAL: | ppc64_mark(); | | case F_LOCAL: | ppc64_push_local(b); | return; | | case F_LOCAL_LVALUE: | ppc64_local_lvalue(b); | return; | | case F_MARK_AND_GLOBAL: | ppc64_mark(); | | case F_GLOBAL: | ppc64_push_global(b); | return; | | case F_MARK_AND_STRING: | ppc64_mark(); | | case F_STRING: | ppc64_push_string(b, 0); | return; | | case F_ARROW_STRING: | ppc64_push_string(b, 1); | return; | | case F_NUMBER: | ppc64_push_int(b, 0); | return; | | case F_NEG_NUMBER: | ppc64_push_int(-(INT64)b, 0); | return; | | case F_CONSTANT: | ppc64_push_constant(b); | return; | | | | | | | case F_MARK_CALL_BUILTIN: | case F_CALL_BUILTIN1: | if(Pike_compiler->new_program->constants[b].sval.u.efun->internal_flags & CALLABLE_DYNAMIC) | break; | if(a == F_CALL_BUILTIN1) | SET_REG32(PPC_REG_ARG1, 1); | else | SET_REG32(PPC_REG_ARG1, 0); | FLUSH_CODE_GENERATOR_STATE(); | ADD_CALL(Pike_compiler->new_program->constants[b].sval.u.efun->function); | return; | } | SET_REG32(PPC_REG_ARG1, b); | ins_f_byte(a); | return; | } | | void ins_f_byte_with_2_args(unsigned int a, | INT32 b, | INT32 c) | { | maybe_update_pc(); | | #ifdef PIKE_DEBUG | if (d_flag < 3) | #endif | switch(a) | { | case F_2_LOCALS: | ppc64_push_local(b); | ppc64_push_local(c); | return; | } | SET_REG32(PPC_REG_ARG1, b); | SET_REG32(PPC_REG_ARG2, c); | ins_f_byte(a); | return; | } | | INT32 ppc64_ins_f_jump(unsigned int a, int backward_jump) | { | INT32 ret, pos_=0; | int (*test_func)(void); | if(a == F_BRANCH) | test_func = NULL; | else if(a == F_CATCH || a == F_CATCH_AT || a == F_RECUR || | a == F_RECUR_AND_POP || a == F_TAIL_RECUR) | return -1; | else | if(a<F_OFFSET || !(instrs[a-F_OFFSET].flags & I_BRANCH) || | !(test_func = instrs[a-F_OFFSET].address)) | Pike_fatal("ppc64_ins_f_jump: invalid branch op %d\n", a); | maybe_update_pc(); | FLUSH_CODE_GENERATOR_STATE(); | if(test_func) { | ADD_CALL(test_func); | | CMPLI(1, PPC_REG_RET, 0); | | BC(12, 2, 2); | pos_ = PIKE_PC; | } | if(backward_jump) { | ADD_CALL(branch_check_threads_etc); | if(pos_) | Pike_compiler->new_program->program[pos_-1] += 4*(PIKE_PC-pos_); | } | ret=(INT32) PIKE_PC; | | B(0); | return ret; | } | | INT32 ppc64_ins_f_jump_with_arg(unsigned int a, unsigned INT32 b, int backward_jump) | { | if(a == F_COND_RECUR) return -1; | SET_REG32(PPC_REG_ARG1, b); | return ppc64_ins_f_jump(a, backward_jump); | } | | INT32 ppc64_ins_f_jump_with_2_args(unsigned int a, unsigned INT32 b, | unsigned INT32 c, int backward_jump) | { | SET_REG32(PPC_REG_ARG1, b); | SET_REG32(PPC_REG_ARG2, c); | return ppc64_ins_f_jump(a, backward_jump); | } | | void ppc64_update_f_jump(INT32 offset, INT32 to_offset) | { | PIKE_OPCODE_T *op = &Pike_compiler->new_program->program[offset]; | | *op = (*op & 0xfc000003) | (((to_offset - offset)<<2)&0x03fffffc); | } | | INT32 ppc64_read_f_jump(INT32 offset) | { | INT32 delta = ((read_pointer(offset)&0x03fffffc)>>2); | if(delta >= 0x800000) | delta -= 0x1000000; | return offset + delta; | } | | void ppc64_flush_instruction_cache(void *addr, size_t len) | { | INT64 a; | | #ifdef HAVE_MAKEDATAEXECUTABLE | | MakeDataExecutable(addr, len); | return; | #endif | | #ifdef _POWER | #ifdef _AIX | __asm__(".machine \"pwr\""); | #endif | | * | * http://publibn.boulder.ibm.com/doc_link/en_US/a_doc_lib/aixassem/alangref/clf.htm | */ | len >>= 2; | for(a = (INT64)addr; len>0; --len) { | __asm__("clf 0,%0" : : "r" (a)); | a += 4; | } | __asm__("dcs"); | __asm__("ics"); | #else /* !_POWER */ | #ifdef _AIX | __asm__(".machine \"ppc\""); | #endif | len >>= 2; | for(a = (INT64)addr; len>0; --len) { | __asm__("icbi 0,%0" : : "r" (a)); | __asm__("dcbst 0,%0" : : "r" (a)); | a += 4; | } | __asm__("sync"); | __asm__("isync"); | #endif /* _POWER */ | } | | #if 0 | #define addstr(s, l) buffer_memcpy(buf, (s), (l)) | #define adddata2(s,l) addstr((char *)(s),(l) * sizeof((s)[0])); | | void ppc64_encode_program(struct program *p, struct byte_buffer *buf) | { | size_t prev = 0, rel; | | for (rel = 0; rel < p->num_relocations; rel++) | { | size_t off = p->relocations[rel]; | INT32 opcode; | #ifdef PIKE_DEBUG | if (off < prev) { | Pike_fatal("Relocations in bad order!\n"); | } | #endif /* PIKE_DEBUG */ | adddata2(p->program + prev, off - prev); | | #ifdef PIKE_DEBUG | if ((p->program[off] & 0xfc000002) != 0x48000000) | Pike_fatal("Bad relocation: %d, off:%d, opcode: 0x%08x\n", | rel, off, p->program[off]); | #endif /* PIKE_DEBUG */ | | opcode = p->program[off] & 0x03ffffff; | opcode += (INT32)(void *)(p->program+off); | adddata2(&opcode, 1); | prev = off+4; | } | adddata2(p->program + prev, p->num_program - prev); | } | | void ppc64_decode_program(struct program *p) | { | | PIKE_OPCODE_T *prog = p->program; | size_t rel = p->num_relocations; | while (rel--) { | PIKE_OPCODE_T *o = prog+p->relocations[rel]; | INT32 disp = *o - (INT32)(void*)o; | if(disp < -33554432 || disp > 33554431) | Pike_fatal("Relocation %d out of range!\n", disp); | *o = 0x48000000 | (disp & 0x03ffffff); | } | } | #endif | | void ppc64_disassemble_code(void *addr, size_t bytes) | { | | | | | | | | | | | | | | static const char *opname[] = { | NULL, NULL, "Dtdi", "Dtwi", NULL, NULL, NULL, "Dmulli", | "Dsubfic", NULL, "Dcmpli", "Dcmpi", "Daddic", "Daddic.", "Daddi", "Daddis", | NULL, "Ssc", NULL, NULL, "Mrlwimi", "Mrlwinm", NULL, "Mrlwnm", | "Dori", "Doris", "Dxori", "Dxoris", "Dandi.", "Dandis.", NULL, NULL, | "Dlwz", "Dlwzu", "Dlbz", "Dlbzu", "Dstw", "Dstwu", "Dstb", "Dstbu", | "Dlhz", "Dlhzu", "Dlha", "Dlhau", "Dsth", "Dsthu", "Dlmw", "Dstmw", | "Dlfs", "Dlfsu", "Dlfd", "Dlfdu", "Dstfs", "Dstfsu", "Dstfd", "Dstfdu", | }; | static const char *opname_bcx[] = { | "Bbc", "Bbcl", "Bbca", "Bbcla", | }; | static const char *opname_bx[] = { | "Ib", "Ibl", "Iba", "Ibla", | }; | static const char *opname_19[] = { | "Lcreqv", "Lcror", NULL, NULL, NULL, "Lmcrf", "Lrfid", "Lbcctr", | "Lbclr", NULL, "Lcrnor", "Lcrxor", "Lrfi", "Lcrand", "Lcrorc", NULL, | "Lisync", "Lcrnand", "Lcrandc", | }; | static short opxo_19[] = { | 289, 449, 0, 0, 0, 0, 18, 528, | 16, 0, 33, 193, 50, 257, 417, 0, | 150, 225, 129, | }; | static const char *opname_31_010[] = { | "Osubfc", "Omulhdu", "Oaddc", "Omulhwu", "Oneg", NULL, "Oadd", NULL, | NULL, "Omulhd", NULL, "Omulhw", "Osubfe", NULL, "Oadde", NULL, | "Osubfme", "Omulld", "Oaddme", "Omullw", "Osubfze", "Odivd", "Oaddze", "Odivw", | "Osubf", "Odivdu", NULL, "Odivwu", | }; | static short opxo_31_010[] = { | 8, 9, 10, 11, 104, 0, 266, 0, | 0, 73, 0, 75, 136, 0, 138, 0, | 232, 233, 234, 235, 200, 489, 202, 491, | 40, 457, 0, 459, | }; | static const char *opname_31_100[] = { | "Xmtmsrd", NULL, "Xslbmte", NULL, "Xtlbiel", NULL, "Xmtmsr", NULL, | "Fmtcrf", "Xmfcr", "Xslbia", "Xslbmfev", "Xtlbia", "Fmftb", "Xmtsrin", "Xmfsr", | NULL, "Fmtspr", NULL, "Fmfspr", "Xmtsr", "Xslbmfee", "Xslbie", "Xmfmsr", | "Xtlbie", "Xmfsrin", | }; | static short opxo_31_100[] = { | 178, 0, 402, 0, 274, 0, 146, 0, | 144, 19, 498, 851, 370, 371, 242, 595, | 0, 467, 0, 339, 210, 915, 434, 83, | 306, 659, | }; | static const char *opname_31_101[] = { | "Xdcba", NULL, "Xlfsx", "Xlwbrx", "Xlswx", "Xsthux", "Xecowx", NULL, | NULL, "Xdcbi", NULL, "Xlhaux", NULL, "Xlwaux", "Xstwx", "Xstwcx.", | "Xstdx", "Xlwzux", "Xdcbst", "Xldux", "Xlbzx", "Xdcbf", NULL, "Xldarx", | NULL, "Xstfiwx", "Xicbi", NULL, NULL, NULL, NULL, "Xstfsx", | "Xstwbrx", "Xstswx", "Xlfsux", "Xtlbsync", NULL, "Xlfdx", "Xsync", "Xlswi", | NULL, NULL, NULL, "Xlhzx", "Xdcbt", NULL, "Xstwux", NULL, | "Xstdux", "Xstbx", "Xstdcx.", NULL, "Xlbzux", NULL, NULL, NULL, | NULL, NULL, "Xdcbz", NULL, NULL, "Xlhbrx", NULL, "Xstfsux", | NULL, NULL, "Xstfdx", NULL, "Xstswi", "Xlfdux", NULL, NULL, | "Xsthx", NULL, NULL, "Xlhzux", "Xeciwx", NULL, "Xlhax", NULL, | "Xlwax", "Xstbux", "Xdcbtst", NULL, "Xlwzx", NULL, "Xldx", "Xlwarx", | NULL, NULL, "Xsthbrx", NULL, NULL, NULL, NULL, NULL, | "Xeieio", NULL, "Xstfdux", | }; | static short opxo_31_101[] = { | 758, 0, 535, 534, 533, 439, 438, 0, | 0, 470, 0, 375, 0, 373, 151, 150, | 149, 55, 54, 53, 87, 86, 0, 84, | 0, 983, 982, 0, 0, 0, 0, 663, | 662, 661, 567, 566, 0, 599, 598, 597, | 0, 0, 0, 279, 278, 0, 183, 0, | 181, 215, 214, 0, 119, 0, 0, 0, | 0, 0, 1014, 0, 0, 790, 0, 695, | 0, 0, 727, 0, 725, 631, 0, 0, | 407, 0, 0, 311, 310, 0, 343, 0, | 341, 247, 246, 0, 23, 0, 21, 20, | 0, 0, 918, 0, 0, 0, 0, 0, | 854, 0, 759, | }; | static const char *opname_31_110[] = { | NULL, NULL, "Xextsh", NULL, "Xextsb", NULL, "Xsld", "Xcntlzw", | "Xsrd", "Xslw", "Xsrad", "Xsrw", "Xsraw", "Xextsw", "Xsrawi", | }; | static short opxo_31_110[] = { | 0, 0, 922, 0, 954, 0, 27, 26, | 539, 24, 794, 536, 792, 986, 824, | }; | static const char *opname_31_111[] = { | "Xand", "Xandc", NULL, "Xnor", NULL, NULL, NULL, NULL, | "Xeqv", "Xxor", NULL, NULL, "Xorc", "Xor", "Xnand", NULL, | }; | static const char *opname_59[] = { | NULL, NULL, "Afdivs", NULL, "Afsubs", "Afadds", "Afsqrts", NULL, | "Afres", "Afmuls", NULL, NULL, "Afmsubs", "Afmadds", "Afnmsubs", "Afnmadds" | }; | static const char *opname_63_0[] = { | NULL, "Xfnabs", "Xfabs", NULL, NULL, "Xfcmpu", NULL, NULL, | "Xfcmpo", NULL, "Xmtfsb1", "Xmcrfs", NULL, "Xmtfsb0", "Xfctiwz", "Xfctiw", | "Xfneg", "Xfrsp", NULL, "Xfmr", NULL, NULL, "Gmtfsf", NULL, | NULL, NULL, NULL, NULL, "Xfctidz", "Xfctid", "Xmtfsfi", NULL, | "Xfcfid", NULL, "Xmffs", | }; | static short opxo_63_0[] = { | 0, 136, 264, 0, 0, 0, 0, 0, | 32, 0, 38, 64, 0, 70, 15, 14, | 40, 12, 0, 72, 0, 0, 711, 0, | 0, 0, 0, 0, 815, 814, 134, 0, | 846, 0, 583, | }; | static const char *opname_63_1[] = { | NULL, NULL, "Afdiv", NULL, "Afsub", "Afadd", "Afsqrt", "Afsel", | NULL, "Afmul", "Afrsqrte", NULL, "Afmsub", "Afmadd", "Afnmsub", "Afnmadd" | }; | unsigned INT32 *code = addr; | size_t len = (bytes+3)>>2; | | while(len--) { | int opcd, xo=0, form; | const char *instr_name; | unsigned INT32 instr = *code; | | fprintf(stderr, "%p %08x ", code++, instr); | | switch(opcd = ((instr>>26)&63)) { | case 16: | instr_name = opname_bcx[instr&3]; | break; | case 18: | instr_name = opname_bx[instr&3]; | break; | case 19: | { | int h; | xo = (instr>>1)&1023; | h = (xo^119)%19; | instr_name = (xo == opxo_19[h]? opname_19[h]:NULL); | } | break; | case 30: | xo = (instr>>2)&7; | switch(xo) { | case 0: instr_name = "Nrldicl"; break; | case 1: instr_name = "Nrldicr"; break; | case 2: instr_name = "Nrldic"; break; | case 3: instr_name = "Nrldimi"; break; | case 4: instr_name = ((instr&2)? "Wrldcr":"Wrldcl"); break; | default: instr_name = NULL; break; | } | break; | case 31: | xo = (instr>>1)&1023; | switch((xo>>2)&7) { | int h; | case 0: | switch(xo) { | case 0: instr_name = "Xcmp"; break; | case 32: instr_name = "Xcmpl"; break; | case 512: instr_name = "Xmcrxr"; break; | default: instr_name = NULL; break; | } | break; | case 1: | switch(xo) { | case 4: instr_name = "Xtw"; break; | case 58: instr_name = "Xcntlzd"; break; | case 68: instr_name = "Xtd"; break; | case 711: instr_name = "Zsradi"; break; | default: instr_name = NULL; break; | } | break; | case 2: | h = ((xo&0x1ff)^160)%28; | instr_name = ((xo&0x1ff) == opxo_31_010[h]? opname_31_010[h]:NULL); | break; | case 4: | h = (xo^98)%26; | instr_name = (xo == opxo_31_100[h]? opname_31_100[h]:NULL); | if(instr & (1<<20)) { | if(xo == 144) | instr_name = "Fmtocrf"; | else if(xo == 19) | instr_name = "Fmfocrf"; | } | break; | case 5: | h = (xo^67)%99; | instr_name = (xo == opxo_31_101[h]? opname_31_101[h]:NULL); | break; | case 6: | h = (xo^195)%15; | instr_name = (xo == opxo_31_110[h]? opname_31_110[h]:NULL); | break; | case 7: | instr_name = ((xo & 0x21f)==0x1c? opname_31_111[(xo>>5)&15]:NULL); | break; | default: | instr_name = NULL; | break; | } | break; | case 58: | xo = instr&3; | switch(xo) { | case 0: instr_name = "Eld"; break; | case 1: instr_name = "Eldu"; break; | case 2: instr_name = "Elwa"; break; | default: instr_name = NULL; break; | } | break; | case 59: | xo = (instr>>1)&0x1f; | instr_name = ((xo&0x10)? opname_59[xo&15] : NULL); | break; | case 62: | xo = instr&3; | switch(xo) { | case 0: instr_name = "Estd"; break; | case 1: instr_name = "Estdu"; break; | default: instr_name = NULL; break; | } | break; | case 63: | if(instr&0x20) { | xo = (instr>>1)&0x1f; | instr_name = opname_63_1[xo&15]; | } else { | int h; | xo = (instr>>1)&0x3ff; | h = (xo^355)%35; | instr_name = (xo == opxo_63_0[h]? opname_63_0[h]:NULL); | } | break; | default: | instr_name = (opcd < 56? opname[opcd] : NULL); | break; | } | form = (instr_name? *instr_name++ : '?'); | switch(form) { | case 'I': | fprintf(stderr, "%s 0x%lx\n", instr_name, | (instr&0x03fffffc)+((instr&2)? 0:(INT64)(code-1))); | break; | case 'B': | | fprintf(stderr, "%s %d,%d,0x%lx\n", instr_name, | (instr>>21)&31, (instr>>16)&31, | (instr&0x0000fffc)+((instr&2)? 0:(INT64)(code-1))); | break; | case 'S': | fprintf(stderr, "%s\n", instr_name); | break; | case 'D': | case 'E': | { | INT32 imm = instr & 0xffff; | char immtext[8]; | if(form == 'E') | imm &= ~3; | if((imm & 0x8000) && opcd != 10 && (opcd < 24 || opcd > 29)) | imm -= 0x10000; | if(imm<0) | sprintf(immtext, "-0x%x", -imm); | else | sprintf(immtext, "0x%x", imm); | if(opcd == 2 || opcd == 3) | fprintf(stderr, "%s %d,r%d,%s\n", instr_name, | (instr>>21)&31, (instr>>16)&31, immtext); | else if(opcd == 10 || opcd == 11) | fprintf(stderr, "%s cr%d,%d,r%d,%s\n", instr_name, | (instr>>23)&7, (instr>>21)&1, (instr>>16)&31, immtext); | else if(opcd >= 48 && opcd < 56) | fprintf(stderr, "%s fr%d,%s(r%d)\n", instr_name, | (instr>>21)&31, immtext, (instr>>16)&31); | else if(opcd >= 32) | fprintf(stderr, "%s r%d,%s(r%d)\n", instr_name, | (instr>>21)&31, immtext, (instr>>16)&31); | else if(opcd >= 24 && opcd <= 29) | fprintf(stderr, "%s r%d,r%d,%s\n", instr_name, | (instr>>16)&31, (instr>>21)&31, immtext); | else | fprintf(stderr, "%s r%d,r%d,%s\n", instr_name, | (instr>>21)&31, (instr>>16)&31, immtext); | } | break; | case 'X': | if(opcd == 63) { | if(xo & 8) | fprintf(stderr, "%s%s fr%d,fr%d\n", instr_name, ((instr&1)? ".":""), | (instr>>21)&31, (instr>>11)&31); | else if(xo & 512) | fprintf(stderr, "%s%s fr%d\n", instr_name, ((instr&1)? ".":""), | (instr>>21)&31); | else if(xo & 128) | fprintf(stderr, "%s%s crf%d,%d\n", instr_name, ((instr&1)? ".":""), | (instr>>23)&7, (instr>>12)&15); | else if(xo & 2) | fprintf(stderr, "%s%s crb%d\n", instr_name, ((instr&1)? ".":""), | (instr>>21)&31); | else if(xo & 64) | fprintf(stderr, "%s crf%d,crf%d\n", instr_name, | (instr>>23)&7, (instr>>18)&7); | else | fprintf(stderr, "%s crf%d,fr%d,fr%d\n", instr_name, | (instr>>23)&7, (instr>>16)&31, (instr>>11)&31); | } else if((xo & 543)==535) { | fprintf(stderr, "%s fr%d,r%d,r%d\n", instr_name, | (instr>>21)&31, (instr>>16)&31, (instr>>11)&31); | } else { | if (xo == 824) | fprintf(stderr, "%s%s r%d,r%d,%d\n", instr_name, ((instr&1)? ".":""), | (instr>>16)&31, (instr>>21)&31, (instr>>11)&31); | else if(!(xo & 991)) | fprintf(stderr, "%s crf%d,%d,r%d,r%d\n", instr_name, (instr>>23)&7, | (instr>>21)&1, (instr>>16)&31, (instr>>11)&31); | else if((xo & 27)==24 || ((xo>>8)|(xo&255))==27) | fprintf(stderr, "%s%s r%d,r%d,r%d\n", instr_name, | ((instr&1)? ".":""), (instr>>16)&31, (instr>>21)&31, | (instr>>11)&31); | else if(!(xo & 24)) { | if(xo&4) | fprintf(stderr, "%s %d,r%d,r%d\n", instr_name, | (instr>>21)&31, (instr>>16)&31, (instr>>11)&31); | else | fprintf(stderr, "%s crf%d\n", instr_name, (instr>>23)&7); | } else if(xo & 8) | fprintf(stderr, "%s%s r%d,r%d\n", instr_name, ((instr&1)? ".":""), | (instr>>16)&31, (instr>>21)&31); | else if(!(xo & 772)) { | if((xo & 96)==96) | fprintf(stderr, "%s r%d,r%d\n", instr_name, | (instr>>21)&31, (instr>>11)&31); | else if((xo & 192)==192) | fprintf(stderr, "%s %d,r%d\n", instr_name, | (instr>>16)&15, (instr>>21)&31); | else if(xo & 128) | fprintf(stderr, "%s r%d,%d\n", instr_name, | (instr>>21)&31, (instr>>16)&1); | else | fprintf(stderr, "%s r%d\n", instr_name, (instr>>21)&31); | } else if((xo & 639)==597) | fprintf(stderr, "%s r%d,r%d,%d\n", instr_name, | (instr>>21)&31, (instr>>16)&31, (instr>>11)&31); | else if(xo == 370 || xo == 498 || xo == 566 || xo == 598 || xo == 854) | fprintf(stderr, "%s\n", instr_name); | else if(!(xo & 4)) { | if((xo & 479)==274) | fprintf(stderr, "%s r%d,%d\n", instr_name, | (instr>>11)&31, (instr>>21)&1); | else if(xo & 32) | fprintf(stderr, "%s r%d\n", instr_name, (instr>>11)&31); | else if(xo == 595) | fprintf(stderr, "%s r%d,%d\n", instr_name, | (instr>>21)&31, (instr>>16)&15); | else | fprintf(stderr, "%s r%d,r%d\n", instr_name, | (instr>>21)&31, (instr>>11)&31); | } else if(instr_name[0]=='d' || instr_name[0]=='i') { | if(xo == 278) | fprintf(stderr, "%s r%d,r%d,%d\n", instr_name, | (instr>>16)&31, (instr>>11)&31, (instr>>21)&3); | else | fprintf(stderr, "%s r%d,r%d\n", instr_name, | (instr>>16)&31, (instr>>11)&31); | } else | fprintf(stderr, "%s r%d,r%d,r%d\n", instr_name, | (instr>>21)&31, (instr>>16)&31, (instr>>11)&31); | } | break; | case 'L': | if(!xo) | fprintf(stderr, "%s cr%d,cr%d\n", instr_name, | (instr>>23)&7, (instr>>18)&7); | else if((xo & 511) == 16) | | fprintf(stderr, "%s%s %d,%d,%d\n", instr_name, ((instr&1)? "l":""), | (instr>>21)&31, (instr>>16)&31, (instr>>11)&3); | else if(xo&1) | fprintf(stderr, "%s crb%d,crb%d,crb%d\n", instr_name, | (instr>>21)&31, (instr>>16)&31, (instr>>11)&31); | else | fprintf(stderr, "%s\n", instr_name); | break; | case 'F': | { | int arg = (!(xo & 256)? (instr>>12)&255 : | ((instr>>6)&0x3e0)|((instr>>16)&31)); | if(xo&128) | fprintf(stderr, "%s %d,r%d\n", instr_name, arg, (instr>>21)&31); | else | fprintf(stderr, "%s r%d,%d\n", instr_name, (instr>>21)&31, arg); | } | break; | case 'G': | fprintf(stderr, "%s%s 0x%x,fr%d\n", instr_name, ((instr&1)? ".":""), | (instr>>17)&255, (instr>>11)&31); | break; | case 'O': | if((xo&0x41)==0x40) | fprintf(stderr, "%s%s%s r%d,r%d\n", instr_name, | ((instr&(1<<10))? "o":""), ((instr&1)? ".":""), | (instr>>21)&31, (instr>>16)&31); | else | fprintf(stderr, "%s%s%s r%d,r%d,r%d\n", instr_name, | ((instr&(1<<10))? "o":""), ((instr&1)? ".":""), | (instr>>21)&31, (instr>>16)&31, (instr>>11)&31); | break; | case 'Z': | fprintf(stderr, "%s%s r%d,r%d,%d\n", | instr_name, ((instr&1)? ".":""), (instr>>16)&31, (instr>>21)&31, | ((instr>>11)&31)|((instr&2)<<4)); | break; | case 'A': | if(xo<22) | fprintf(stderr, "%s%s fr%d,fr%d,fr%d\n", instr_name, | ((instr&1)? ".":""), | (instr>>21)&31, (instr>>16)&31, (instr>>11)&31); | else if(xo >= 28 || xo == 23) | fprintf(stderr, "%s%s fr%d,fr%d,fr%d,fr%d\n", instr_name, | ((instr&1)? ".":""), | (instr>>21)&31, (instr>>16)&31, (instr>>6)&31, (instr>>11)&31); | else if(xo & 1) | fprintf(stderr, "%s%s fr%d,fr%d,fr%d\n", instr_name, | ((instr&1)? ".":""), | (instr>>21)&31, (instr>>16)&31, (instr>>6)&31); | else | fprintf(stderr, "%s%s fr%d,fr%d\n", instr_name, ((instr&1)? ".":""), | (instr>>21)&31, (instr>>11)&31); | break; | case 'M': | fprintf(stderr, (opcd==23? "%s%s r%d,r%d,r%d,%d,%d\n" : | "%s%s r%d,r%d,%d,%d,%d\n"), | instr_name, ((instr&1)? ".":""), (instr>>16)&31, (instr>>21)&31, | (instr>>11)&31, (instr>>6)&31, (instr>>1)&31); | break; | case 'N': | fprintf(stderr, "%s%s r%d,r%d,%d,%d\n", | instr_name, ((instr&1)? ".":""), (instr>>16)&31, (instr>>21)&31, | ((instr>>11)&31)|((instr&2)<<4), ((instr>>6)&31)|(instr&32)); | break; | case 'W': | fprintf(stderr, "%s%s r%d,r%d,r%d,%d\n", | instr_name, ((instr&1)? ".":""), (instr>>16)&31, (instr>>21)&31, | (instr>>11)&31, ((instr>>6)&31)|(instr&32)); | break; | default: | fprintf(stderr, ".long 0x%x\n", instr); | break; | } | } | } | | |
|