]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/ABI/SysV-hexagon/ABISysV_hexagon.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / ABI / SysV-hexagon / ABISysV_hexagon.cpp
1 //===-- ABISysV_hexagon.cpp -------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "ABISysV_hexagon.h"
11
12 #include "llvm/ADT/Triple.h"
13 #include "llvm/IR/DerivedTypes.h"
14
15 #include "lldb/Core/Module.h"
16 #include "lldb/Core/PluginManager.h"
17 #include "lldb/Core/Value.h"
18 #include "lldb/Core/ValueObjectConstResult.h"
19 #include "lldb/Core/ValueObjectMemory.h"
20 #include "lldb/Core/ValueObjectRegister.h"
21 #include "lldb/Symbol/UnwindPlan.h"
22 #include "lldb/Target/Process.h"
23 #include "lldb/Target/RegisterContext.h"
24 #include "lldb/Target/StackFrame.h"
25 #include "lldb/Target/Target.h"
26 #include "lldb/Target/Thread.h"
27 #include "lldb/Utility/ConstString.h"
28 #include "lldb/Utility/DataExtractor.h"
29 #include "lldb/Utility/Log.h"
30 #include "lldb/Utility/RegisterValue.h"
31 #include "lldb/Utility/Status.h"
32
33 using namespace lldb;
34 using namespace lldb_private;
35
36 static RegisterInfo g_register_infos[] = {
37     // hexagon-core.xml
38     {"r00",
39      "",
40      4,
41      0,
42      eEncodingUint,
43      eFormatAddressInfo,
44      {0, 0, LLDB_INVALID_REGNUM, 0, 0},
45      nullptr,
46      nullptr,
47      nullptr,
48      0},
49     {"r01",
50      "",
51      4,
52      0,
53      eEncodingUint,
54      eFormatAddressInfo,
55      {1, 1, LLDB_INVALID_REGNUM, 1, 1},
56      nullptr,
57      nullptr,
58      nullptr,
59      0},
60     {"r02",
61      "",
62      4,
63      0,
64      eEncodingUint,
65      eFormatAddressInfo,
66      {2, 2, LLDB_INVALID_REGNUM, 2, 2},
67      nullptr,
68      nullptr,
69      nullptr,
70      0},
71     {"r03",
72      "",
73      4,
74      0,
75      eEncodingUint,
76      eFormatAddressInfo,
77      {3, 3, LLDB_INVALID_REGNUM, 3, 3},
78      nullptr,
79      nullptr,
80      nullptr,
81      0},
82     {"r04",
83      "",
84      4,
85      0,
86      eEncodingUint,
87      eFormatAddressInfo,
88      {4, 4, LLDB_INVALID_REGNUM, 4, 4},
89      nullptr,
90      nullptr,
91      nullptr,
92      0},
93     {"r05",
94      "",
95      4,
96      0,
97      eEncodingUint,
98      eFormatAddressInfo,
99      {5, 5, LLDB_INVALID_REGNUM, 5, 5},
100      nullptr,
101      nullptr,
102      nullptr,
103      0},
104     {"r06",
105      "",
106      4,
107      0,
108      eEncodingUint,
109      eFormatAddressInfo,
110      {6, 6, LLDB_INVALID_REGNUM, 6, 6},
111      nullptr,
112      nullptr,
113      nullptr,
114      0},
115     {"r07",
116      "",
117      4,
118      0,
119      eEncodingUint,
120      eFormatAddressInfo,
121      {7, 7, LLDB_INVALID_REGNUM, 7, 7},
122      nullptr,
123      nullptr,
124      nullptr,
125      0},
126     {"r08",
127      "",
128      4,
129      0,
130      eEncodingUint,
131      eFormatAddressInfo,
132      {8, 8, LLDB_INVALID_REGNUM, 8, 8},
133      nullptr,
134      nullptr,
135      nullptr,
136      0},
137     {"r09",
138      "",
139      4,
140      0,
141      eEncodingUint,
142      eFormatAddressInfo,
143      {9, 9, LLDB_INVALID_REGNUM, 9, 9},
144      nullptr,
145      nullptr,
146      nullptr,
147      0},
148     {"r10",
149      "",
150      4,
151      0,
152      eEncodingUint,
153      eFormatAddressInfo,
154      {10, 10, LLDB_INVALID_REGNUM, 10, 10},
155      nullptr,
156      nullptr,
157      nullptr,
158      0},
159     {"r11",
160      "",
161      4,
162      0,
163      eEncodingUint,
164      eFormatAddressInfo,
165      {11, 11, LLDB_INVALID_REGNUM, 11, 11},
166      nullptr,
167      nullptr,
168      nullptr,
169      0},
170     {"r12",
171      "",
172      4,
173      0,
174      eEncodingUint,
175      eFormatAddressInfo,
176      {12, 12, LLDB_INVALID_REGNUM, 12, 12},
177      nullptr,
178      nullptr,
179      nullptr,
180      0},
181     {"r13",
182      "",
183      4,
184      0,
185      eEncodingUint,
186      eFormatAddressInfo,
187      {13, 13, LLDB_INVALID_REGNUM, 13, 13},
188      nullptr,
189      nullptr,
190      nullptr,
191      0},
192     {"r14",
193      "",
194      4,
195      0,
196      eEncodingUint,
197      eFormatAddressInfo,
198      {14, 14, LLDB_INVALID_REGNUM, 14, 14},
199      nullptr,
200      nullptr,
201      nullptr,
202      0},
203     {"r15",
204      "",
205      4,
206      0,
207      eEncodingUint,
208      eFormatAddressInfo,
209      {15, 15, LLDB_INVALID_REGNUM, 15, 15},
210      nullptr,
211      nullptr,
212      nullptr,
213      0},
214     {"r16",
215      "",
216      4,
217      0,
218      eEncodingUint,
219      eFormatAddressInfo,
220      {16, 16, LLDB_INVALID_REGNUM, 16, 16},
221      nullptr,
222      nullptr,
223      nullptr,
224      0},
225     {"r17",
226      "",
227      4,
228      0,
229      eEncodingUint,
230      eFormatAddressInfo,
231      {17, 17, LLDB_INVALID_REGNUM, 17, 17},
232      nullptr,
233      nullptr,
234      nullptr,
235      0},
236     {"r18",
237      "",
238      4,
239      0,
240      eEncodingUint,
241      eFormatAddressInfo,
242      {18, 18, LLDB_INVALID_REGNUM, 18, 18},
243      nullptr,
244      nullptr,
245      nullptr,
246      0},
247     {"r19",
248      "",
249      4,
250      0,
251      eEncodingUint,
252      eFormatAddressInfo,
253      {19, 19, LLDB_INVALID_REGNUM, 19, 19},
254      nullptr,
255      nullptr,
256      nullptr,
257      0},
258     {"r20",
259      "",
260      4,
261      0,
262      eEncodingUint,
263      eFormatAddressInfo,
264      {20, 20, LLDB_INVALID_REGNUM, 20, 20},
265      nullptr,
266      nullptr,
267      nullptr,
268      0},
269     {"r21",
270      "",
271      4,
272      0,
273      eEncodingUint,
274      eFormatAddressInfo,
275      {21, 21, LLDB_INVALID_REGNUM, 21, 21},
276      nullptr,
277      nullptr,
278      nullptr,
279      0},
280     {"r22",
281      "",
282      4,
283      0,
284      eEncodingUint,
285      eFormatAddressInfo,
286      {22, 22, LLDB_INVALID_REGNUM, 22, 22},
287      nullptr,
288      nullptr,
289      nullptr,
290      0},
291     {"r23",
292      "",
293      4,
294      0,
295      eEncodingUint,
296      eFormatAddressInfo,
297      {23, 23, LLDB_INVALID_REGNUM, 23, 23},
298      nullptr,
299      nullptr,
300      nullptr,
301      0},
302     {"r24",
303      "",
304      4,
305      0,
306      eEncodingUint,
307      eFormatAddressInfo,
308      {24, 24, LLDB_INVALID_REGNUM, 24, 24},
309      nullptr,
310      nullptr,
311      nullptr,
312      0},
313     {"r25",
314      "",
315      4,
316      0,
317      eEncodingUint,
318      eFormatAddressInfo,
319      {25, 25, LLDB_INVALID_REGNUM, 25, 25},
320      nullptr,
321      nullptr,
322      nullptr,
323      0},
324     {"r26",
325      "",
326      4,
327      0,
328      eEncodingUint,
329      eFormatAddressInfo,
330      {26, 26, LLDB_INVALID_REGNUM, 26, 26},
331      nullptr,
332      nullptr,
333      nullptr,
334      0},
335     {"r27",
336      "",
337      4,
338      0,
339      eEncodingUint,
340      eFormatAddressInfo,
341      {27, 27, LLDB_INVALID_REGNUM, 27, 27},
342      nullptr,
343      nullptr,
344      nullptr,
345      0},
346     {"r28",
347      "",
348      4,
349      0,
350      eEncodingUint,
351      eFormatAddressInfo,
352      {28, 28, LLDB_INVALID_REGNUM, 28, 28},
353      nullptr,
354      nullptr,
355      nullptr,
356      0},
357     {"sp",
358      "r29",
359      4,
360      0,
361      eEncodingUint,
362      eFormatAddressInfo,
363      {29, 29, LLDB_REGNUM_GENERIC_SP, 29, 29},
364      nullptr,
365      nullptr,
366      nullptr,
367      0},
368     {"fp",
369      "r30",
370      4,
371      0,
372      eEncodingUint,
373      eFormatAddressInfo,
374      {30, 30, LLDB_REGNUM_GENERIC_FP, 30, 30},
375      nullptr,
376      nullptr,
377      nullptr,
378      0},
379     {"lr",
380      "r31",
381      4,
382      0,
383      eEncodingUint,
384      eFormatAddressInfo,
385      {31, 31, LLDB_REGNUM_GENERIC_RA, 31, 31},
386      nullptr,
387      nullptr,
388      nullptr,
389      0},
390     {"sa0",
391      "",
392      4,
393      0,
394      eEncodingUint,
395      eFormatAddressInfo,
396      {32, 32, LLDB_INVALID_REGNUM, 32, 32},
397      nullptr,
398      nullptr,
399      nullptr,
400      0},
401     {"lc0",
402      "",
403      4,
404      0,
405      eEncodingUint,
406      eFormatAddressInfo,
407      {33, 33, LLDB_INVALID_REGNUM, 33, 33},
408      nullptr,
409      nullptr,
410      nullptr,
411      0},
412     {"sa1",
413      "",
414      4,
415      0,
416      eEncodingUint,
417      eFormatAddressInfo,
418      {34, 34, LLDB_INVALID_REGNUM, 34, 34},
419      nullptr,
420      nullptr,
421      nullptr,
422      0},
423     {"lc1",
424      "",
425      4,
426      0,
427      eEncodingUint,
428      eFormatAddressInfo,
429      {35, 35, LLDB_INVALID_REGNUM, 35, 35},
430      nullptr,
431      nullptr,
432      nullptr,
433      0},
434     // --> hexagon-v4/5/55/56-sim.xml
435     {"p3_0",
436      "",
437      4,
438      0,
439      eEncodingUint,
440      eFormatAddressInfo,
441      {36, 36, LLDB_INVALID_REGNUM, 36, 36},
442      nullptr,
443      nullptr,
444      nullptr,
445      0},
446     // PADDING {
447     {"p00",
448      "",
449      4,
450      0,
451      eEncodingInvalid,
452      eFormatInvalid,
453      {37, 37, LLDB_INVALID_REGNUM, 37, 37},
454      nullptr,
455      nullptr,
456      nullptr,
457      0},
458     // }
459     {"m0",
460      "",
461      4,
462      0,
463      eEncodingUint,
464      eFormatAddressInfo,
465      {38, 38, LLDB_INVALID_REGNUM, 38, 38},
466      nullptr,
467      nullptr,
468      nullptr,
469      0},
470     {"m1",
471      "",
472      4,
473      0,
474      eEncodingUint,
475      eFormatAddressInfo,
476      {39, 39, LLDB_INVALID_REGNUM, 39, 39},
477      nullptr,
478      nullptr,
479      nullptr,
480      0},
481     {"usr",
482      "",
483      4,
484      0,
485      eEncodingUint,
486      eFormatAddressInfo,
487      {40, 40, LLDB_INVALID_REGNUM, 40, 40},
488      nullptr,
489      nullptr,
490      nullptr,
491      0},
492     {"pc",
493      "",
494      4,
495      0,
496      eEncodingUint,
497      eFormatAddressInfo,
498      {41, 41, LLDB_REGNUM_GENERIC_PC, 41, 41},
499      nullptr,
500      nullptr,
501      nullptr,
502      0},
503     {"ugp",
504      "",
505      4,
506      0,
507      eEncodingUint,
508      eFormatAddressInfo,
509      {42, 42, LLDB_INVALID_REGNUM, 42, 42},
510      nullptr,
511      nullptr,
512      nullptr,
513      0},
514     {"gp",
515      "",
516      4,
517      0,
518      eEncodingUint,
519      eFormatAddressInfo,
520      {43, 43, LLDB_INVALID_REGNUM, 43, 43},
521      nullptr,
522      nullptr,
523      nullptr,
524      0},
525     {"cs0",
526      "",
527      4,
528      0,
529      eEncodingUint,
530      eFormatAddressInfo,
531      {44, 44, LLDB_INVALID_REGNUM, 44, 44},
532      nullptr,
533      nullptr,
534      nullptr,
535      0},
536     {"cs1",
537      "",
538      4,
539      0,
540      eEncodingUint,
541      eFormatAddressInfo,
542      {45, 45, LLDB_INVALID_REGNUM, 45, 45},
543      nullptr,
544      nullptr,
545      nullptr,
546      0},
547     // PADDING {
548     {"p01",
549      "",
550      4,
551      0,
552      eEncodingInvalid,
553      eFormatInvalid,
554      {46, 46, LLDB_INVALID_REGNUM, 46, 46},
555      nullptr,
556      nullptr,
557      nullptr,
558      0},
559     {"p02",
560      "",
561      4,
562      0,
563      eEncodingInvalid,
564      eFormatInvalid,
565      {47, 47, LLDB_INVALID_REGNUM, 47, 47},
566      nullptr,
567      nullptr,
568      nullptr,
569      0},
570     {"p03",
571      "",
572      4,
573      0,
574      eEncodingInvalid,
575      eFormatInvalid,
576      {48, 48, LLDB_INVALID_REGNUM, 48, 48},
577      nullptr,
578      nullptr,
579      nullptr,
580      0},
581     {"p04",
582      "",
583      4,
584      0,
585      eEncodingInvalid,
586      eFormatInvalid,
587      {49, 49, LLDB_INVALID_REGNUM, 49, 49},
588      nullptr,
589      nullptr,
590      nullptr,
591      0},
592     {"p05",
593      "",
594      4,
595      0,
596      eEncodingInvalid,
597      eFormatInvalid,
598      {50, 50, LLDB_INVALID_REGNUM, 50, 50},
599      nullptr,
600      nullptr,
601      nullptr,
602      0},
603     {"p06",
604      "",
605      4,
606      0,
607      eEncodingInvalid,
608      eFormatInvalid,
609      {51, 51, LLDB_INVALID_REGNUM, 51, 51},
610      nullptr,
611      nullptr,
612      nullptr,
613      0},
614     {"p07",
615      "",
616      4,
617      0,
618      eEncodingInvalid,
619      eFormatInvalid,
620      {52, 52, LLDB_INVALID_REGNUM, 52, 52},
621      nullptr,
622      nullptr,
623      nullptr,
624      0},
625     {"p08",
626      "",
627      4,
628      0,
629      eEncodingInvalid,
630      eFormatInvalid,
631      {53, 53, LLDB_INVALID_REGNUM, 53, 53},
632      nullptr,
633      nullptr,
634      nullptr,
635      0},
636     {"p09",
637      "",
638      4,
639      0,
640      eEncodingInvalid,
641      eFormatInvalid,
642      {54, 54, LLDB_INVALID_REGNUM, 54, 54},
643      nullptr,
644      nullptr,
645      nullptr,
646      0},
647     {"p10",
648      "",
649      4,
650      0,
651      eEncodingInvalid,
652      eFormatInvalid,
653      {55, 55, LLDB_INVALID_REGNUM, 55, 55},
654      nullptr,
655      nullptr,
656      nullptr,
657      0},
658     {"p11",
659      "",
660      4,
661      0,
662      eEncodingInvalid,
663      eFormatInvalid,
664      {56, 56, LLDB_INVALID_REGNUM, 56, 56},
665      nullptr,
666      nullptr,
667      nullptr,
668      0},
669     {"p12",
670      "",
671      4,
672      0,
673      eEncodingInvalid,
674      eFormatInvalid,
675      {57, 57, LLDB_INVALID_REGNUM, 57, 57},
676      nullptr,
677      nullptr,
678      nullptr,
679      0},
680     {"p13",
681      "",
682      4,
683      0,
684      eEncodingInvalid,
685      eFormatInvalid,
686      {58, 58, LLDB_INVALID_REGNUM, 58, 58},
687      nullptr,
688      nullptr,
689      nullptr,
690      0},
691     {"p14",
692      "",
693      4,
694      0,
695      eEncodingInvalid,
696      eFormatInvalid,
697      {59, 59, LLDB_INVALID_REGNUM, 59, 59},
698      nullptr,
699      nullptr,
700      nullptr,
701      0},
702     {"p15",
703      "",
704      4,
705      0,
706      eEncodingInvalid,
707      eFormatInvalid,
708      {60, 60, LLDB_INVALID_REGNUM, 60, 60},
709      nullptr,
710      nullptr,
711      nullptr,
712      0},
713     {"p16",
714      "",
715      4,
716      0,
717      eEncodingInvalid,
718      eFormatInvalid,
719      {61, 61, LLDB_INVALID_REGNUM, 61, 61},
720      nullptr,
721      nullptr,
722      nullptr,
723      0},
724     {"p17",
725      "",
726      4,
727      0,
728      eEncodingInvalid,
729      eFormatInvalid,
730      {62, 62, LLDB_INVALID_REGNUM, 62, 62},
731      nullptr,
732      nullptr,
733      nullptr,
734      0},
735     {"p18",
736      "",
737      4,
738      0,
739      eEncodingInvalid,
740      eFormatInvalid,
741      {63, 63, LLDB_INVALID_REGNUM, 63, 63},
742      nullptr,
743      nullptr,
744      nullptr,
745      0},
746     // }
747     {"sgp0",
748      "",
749      4,
750      0,
751      eEncodingUint,
752      eFormatAddressInfo,
753      {64, 64, LLDB_INVALID_REGNUM, 64, 64},
754      nullptr,
755      nullptr,
756      nullptr,
757      0},
758     // PADDING {
759     {"p19",
760      "",
761      4,
762      0,
763      eEncodingInvalid,
764      eFormatInvalid,
765      {65, 65, LLDB_INVALID_REGNUM, 65, 65},
766      nullptr,
767      nullptr,
768      nullptr,
769      0},
770     // }
771     {"stid",
772      "",
773      4,
774      0,
775      eEncodingUint,
776      eFormatAddressInfo,
777      {66, 66, LLDB_INVALID_REGNUM, 66, 66},
778      nullptr,
779      nullptr,
780      nullptr,
781      0},
782     {"elr",
783      "",
784      4,
785      0,
786      eEncodingUint,
787      eFormatAddressInfo,
788      {67, 67, LLDB_INVALID_REGNUM, 67, 67},
789      nullptr,
790      nullptr,
791      nullptr,
792      0},
793     {"badva0",
794      "",
795      4,
796      0,
797      eEncodingUint,
798      eFormatAddressInfo,
799      {68, 68, LLDB_INVALID_REGNUM, 68, 68},
800      nullptr,
801      nullptr,
802      nullptr,
803      0},
804     {"badva1",
805      "",
806      4,
807      0,
808      eEncodingUint,
809      eFormatAddressInfo,
810      {69, 69, LLDB_INVALID_REGNUM, 69, 69},
811      nullptr,
812      nullptr,
813      nullptr,
814      0},
815     {"ssr",
816      "",
817      4,
818      0,
819      eEncodingUint,
820      eFormatAddressInfo,
821      {70, 70, LLDB_INVALID_REGNUM, 70, 70},
822      nullptr,
823      nullptr,
824      nullptr,
825      0},
826     {"ccr",
827      "",
828      4,
829      0,
830      eEncodingUint,
831      eFormatAddressInfo,
832      {71, 71, LLDB_INVALID_REGNUM, 71, 71},
833      nullptr,
834      nullptr,
835      nullptr,
836      0},
837     {"htid",
838      "",
839      4,
840      0,
841      eEncodingUint,
842      eFormatAddressInfo,
843      {72, 72, LLDB_INVALID_REGNUM, 72, 72},
844      nullptr,
845      nullptr,
846      nullptr,
847      0},
848     // PADDING {
849     {"p20",
850      "",
851      4,
852      0,
853      eEncodingInvalid,
854      eFormatInvalid,
855      {73, 73, LLDB_INVALID_REGNUM, 73, 73},
856      nullptr,
857      nullptr,
858      nullptr,
859      0},
860     // }
861     {"imask",
862      "",
863      4,
864      0,
865      eEncodingUint,
866      eFormatAddressInfo,
867      {74, 74, LLDB_INVALID_REGNUM, 74, 74},
868      nullptr,
869      nullptr,
870      nullptr,
871      0},
872     // PADDING {
873     {"p21",
874      "",
875      4,
876      0,
877      eEncodingInvalid,
878      eFormatInvalid,
879      {75, 75, LLDB_INVALID_REGNUM, 75, 75},
880      nullptr,
881      nullptr,
882      nullptr,
883      0},
884     {"p22",
885      "",
886      4,
887      0,
888      eEncodingInvalid,
889      eFormatInvalid,
890      {76, 76, LLDB_INVALID_REGNUM, 76, 76},
891      nullptr,
892      nullptr,
893      nullptr,
894      0},
895     {"p23",
896      "",
897      4,
898      0,
899      eEncodingInvalid,
900      eFormatInvalid,
901      {77, 77, LLDB_INVALID_REGNUM, 77, 77},
902      nullptr,
903      nullptr,
904      nullptr,
905      0},
906     {"p24",
907      "",
908      4,
909      0,
910      eEncodingInvalid,
911      eFormatInvalid,
912      {78, 78, LLDB_INVALID_REGNUM, 78, 78},
913      nullptr,
914      nullptr,
915      nullptr,
916      0},
917     {"p25",
918      "",
919      4,
920      0,
921      eEncodingInvalid,
922      eFormatInvalid,
923      {79, 79, LLDB_INVALID_REGNUM, 79, 79},
924      nullptr,
925      nullptr,
926      nullptr,
927      0},
928     // }
929     {"g0",
930      "",
931      4,
932      0,
933      eEncodingUint,
934      eFormatAddressInfo,
935      {80, 80, LLDB_INVALID_REGNUM, 80, 80},
936      nullptr,
937      nullptr,
938      nullptr,
939      0},
940     {"g1",
941      "",
942      4,
943      0,
944      eEncodingUint,
945      eFormatAddressInfo,
946      {81, 81, LLDB_INVALID_REGNUM, 81, 81},
947      nullptr,
948      nullptr,
949      nullptr,
950      0},
951     {"g2",
952      "",
953      4,
954      0,
955      eEncodingUint,
956      eFormatAddressInfo,
957      {82, 82, LLDB_INVALID_REGNUM, 82, 82},
958      nullptr,
959      nullptr,
960      nullptr,
961      0},
962     {"g3",
963      "",
964      4,
965      0,
966      eEncodingUint,
967      eFormatAddressInfo,
968      {83, 83, LLDB_INVALID_REGNUM, 83, 83},
969      nullptr,
970      nullptr,
971      nullptr,
972      0}};
973
974 static const uint32_t k_num_register_infos =
975     sizeof(g_register_infos) / sizeof(RegisterInfo);
976 static bool g_register_info_names_constified = false;
977
978 const lldb_private::RegisterInfo *
979 ABISysV_hexagon::GetRegisterInfoArray(uint32_t &count) {
980   // Make the C-string names and alt_names for the register infos into const
981   // C-string values by having the ConstString unique the names in the global
982   // constant C-string pool.
983   if (!g_register_info_names_constified) {
984     g_register_info_names_constified = true;
985     for (uint32_t i = 0; i < k_num_register_infos; ++i) {
986       if (g_register_infos[i].name)
987         g_register_infos[i].name =
988             ConstString(g_register_infos[i].name).GetCString();
989       if (g_register_infos[i].alt_name)
990         g_register_infos[i].alt_name =
991             ConstString(g_register_infos[i].alt_name).GetCString();
992     }
993   }
994   count = k_num_register_infos;
995   return g_register_infos;
996 }
997
998 /*
999     http://en.wikipedia.org/wiki/Red_zone_%28computing%29
1000
1001     In computing, a red zone is a fixed size area in memory beyond the stack
1002    pointer that has not been
1003     "allocated". This region of memory is not to be modified by
1004    interrupt/exception/signal handlers.
1005     This allows the space to be used for temporary data without the extra
1006    overhead of modifying the
1007     stack pointer. The x86-64 ABI mandates a 128 byte red zone.[1] The OpenRISC
1008    toolchain assumes a
1009     128 byte red zone though it is not documented.
1010 */
1011 size_t ABISysV_hexagon::GetRedZoneSize() const { return 0; }
1012
1013 //------------------------------------------------------------------
1014 // Static Functions
1015 //------------------------------------------------------------------
1016
1017 ABISP
1018 ABISysV_hexagon::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) {
1019   if (arch.GetTriple().getArch() == llvm::Triple::hexagon) {
1020     return ABISP(new ABISysV_hexagon(process_sp));
1021   }
1022   return ABISP();
1023 }
1024
1025 bool ABISysV_hexagon::PrepareTrivialCall(Thread &thread, lldb::addr_t sp,
1026                                          lldb::addr_t pc, lldb::addr_t ra,
1027                                          llvm::ArrayRef<addr_t> args) const {
1028   // we don't use the traditional trivial call specialized for jit
1029   return false;
1030 }
1031
1032 /*
1033
1034 // AD:
1035 //  . safeguard the current stack
1036 //  . how can we know that the called function will create its own frame
1037 properly?
1038 //  . we could manually make a new stack first:
1039 //      2. push RA
1040 //      3. push FP
1041 //      4. FP = SP
1042 //      5. SP = SP ( since no locals in our temp frame )
1043
1044 // AD 6/05/2014
1045 //  . variable argument list parameters are not passed via registers, they are
1046 passed on
1047 //    the stack.  This presents us with a problem, since we need to know when
1048 the valist
1049 //    starts.  Currently I can find out if a function is varg, but not how many
1050 //    real parameters it takes.  Thus I don't know when to start spilling the
1051 vargs.  For
1052 //    the time being, to progress, I will assume that it takes on real parameter
1053 before
1054 //    the vargs list starts.
1055
1056 // AD 06/05/2014
1057 //  . how do we adhere to the stack alignment requirements
1058
1059 // AD 06/05/2014
1060 //  . handle 64bit values and their register / stack requirements
1061
1062 */
1063 #define HEX_ABI_DEBUG 0
1064 bool ABISysV_hexagon::PrepareTrivialCall(
1065     Thread &thread, lldb::addr_t sp, lldb::addr_t pc, lldb::addr_t ra,
1066     llvm::Type &prototype, llvm::ArrayRef<ABI::CallArgument> args) const {
1067   // default number of register passed arguments for varg functions
1068   const int nVArgRegParams = 1;
1069   Status error;
1070
1071   // grab the process so we have access to the memory for spilling
1072   lldb::ProcessSP proc = thread.GetProcess();
1073
1074   // get the register context for modifying all of the registers
1075   RegisterContext *reg_ctx = thread.GetRegisterContext().get();
1076   if (!reg_ctx)
1077     return false;
1078
1079   uint32_t pc_reg = reg_ctx->ConvertRegisterKindToRegisterNumber(
1080       eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC);
1081   if (pc_reg == LLDB_INVALID_REGNUM)
1082     return false;
1083
1084   uint32_t ra_reg = reg_ctx->ConvertRegisterKindToRegisterNumber(
1085       eRegisterKindGeneric, LLDB_REGNUM_GENERIC_RA);
1086   if (ra_reg == LLDB_INVALID_REGNUM)
1087     return false;
1088
1089   uint32_t sp_reg = reg_ctx->ConvertRegisterKindToRegisterNumber(
1090       eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);
1091   if (sp_reg == LLDB_INVALID_REGNUM)
1092     return false;
1093
1094   // push host data onto target
1095   for (size_t i = 0; i < args.size(); i++) {
1096     const ABI::CallArgument &arg = args[i];
1097     // skip over target values
1098     if (arg.type == ABI::CallArgument::TargetValue)
1099       continue;
1100     // round up to 8 byte multiple
1101     size_t argSize = (arg.size | 0x7) + 1;
1102
1103     // create space on the stack for this data
1104     sp -= argSize;
1105
1106     // write this argument onto the stack of the host process
1107     proc->WriteMemory(sp, arg.data_ap.get(), arg.size, error);
1108     if (error.Fail())
1109       return false;
1110
1111     // update the argument with the target pointer
1112     // XXX: This is a gross hack for getting around the const
1113     *const_cast<lldb::addr_t *>(&arg.value) = sp;
1114   }
1115
1116 #if HEX_ABI_DEBUG
1117   // print the original stack pointer
1118   printf("sp : %04" PRIx64 " \n", sp);
1119 #endif
1120
1121   // make sure number of parameters matches prototype
1122   assert(prototype.getFunctionNumParams() == args.size());
1123
1124   // check if this is a variable argument function
1125   bool isVArg = prototype.isFunctionVarArg();
1126
1127   // number of arguments passed by register
1128   int nRegArgs = nVArgRegParams;
1129   if (!isVArg) {
1130     // number of arguments is limited by [R0 : R5] space
1131     nRegArgs = args.size();
1132     if (nRegArgs > 6)
1133       nRegArgs = 6;
1134   }
1135
1136   // pass arguments that are passed via registers
1137   for (int i = 0; i < nRegArgs; i++) {
1138     // get the parameter as a u32
1139     uint32_t param = (uint32_t)args[i].value;
1140     // write argument into register
1141     if (!reg_ctx->WriteRegisterFromUnsigned(i, param))
1142       return false;
1143   }
1144
1145   // number of arguments to spill onto stack
1146   int nSpillArgs = args.size() - nRegArgs;
1147   // make space on the stack for arguments
1148   sp -= 4 * nSpillArgs;
1149   // align stack on an 8 byte boundary
1150   if (sp & 7)
1151     sp -= 4;
1152
1153   // arguments that are passed on the stack
1154   for (size_t i = nRegArgs, offs = 0; i < args.size(); i++) {
1155     // get the parameter as a u32
1156     uint32_t param = (uint32_t)args[i].value;
1157     // write argument to stack
1158     proc->WriteMemory(sp + offs, (void *)&param, sizeof(param), error);
1159     if (!error.Success())
1160       return false;
1161     //
1162     offs += 4;
1163   }
1164
1165   // update registers with current function call state
1166   reg_ctx->WriteRegisterFromUnsigned(pc_reg, pc);
1167   reg_ctx->WriteRegisterFromUnsigned(ra_reg, ra);
1168   reg_ctx->WriteRegisterFromUnsigned(sp_reg, sp);
1169
1170 #if HEX_ABI_DEBUG
1171   // quick and dirty stack dumper for debugging
1172   for (int i = -8; i < 8; i++) {
1173     uint32_t data = 0;
1174     lldb::addr_t addr = sp + i * 4;
1175     proc->ReadMemory(addr, (void *)&data, sizeof(data), error);
1176     printf("\n0x%04" PRIx64 " 0x%08x ", addr, data);
1177     if (i == 0)
1178       printf("<<-- sp");
1179   }
1180   printf("\n");
1181 #endif
1182
1183   return true;
1184 }
1185
1186 bool ABISysV_hexagon::GetArgumentValues(Thread &thread,
1187                                         ValueList &values) const {
1188   return false;
1189 }
1190
1191 Status
1192 ABISysV_hexagon::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
1193                                       lldb::ValueObjectSP &new_value_sp) {
1194   Status error;
1195   return error;
1196 }
1197
1198 ValueObjectSP ABISysV_hexagon::GetReturnValueObjectSimple(
1199     Thread &thread, CompilerType &return_compiler_type) const {
1200   ValueObjectSP return_valobj_sp;
1201   return return_valobj_sp;
1202 }
1203
1204 ValueObjectSP ABISysV_hexagon::GetReturnValueObjectImpl(
1205     Thread &thread, CompilerType &return_compiler_type) const {
1206   ValueObjectSP return_valobj_sp;
1207   return return_valobj_sp;
1208 }
1209
1210 // called when we are on the first instruction of a new function for hexagon
1211 // the return address is in RA (R31)
1212 bool ABISysV_hexagon::CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan) {
1213   unwind_plan.Clear();
1214   unwind_plan.SetRegisterKind(eRegisterKindGeneric);
1215   unwind_plan.SetReturnAddressRegister(LLDB_REGNUM_GENERIC_RA);
1216
1217   UnwindPlan::RowSP row(new UnwindPlan::Row);
1218
1219   // Our Call Frame Address is the stack pointer value
1220   row->GetCFAValue().SetIsRegisterPlusOffset(LLDB_REGNUM_GENERIC_SP, 4);
1221   row->SetOffset(0);
1222
1223   // The previous PC is in the LR
1224   row->SetRegisterLocationToRegister(LLDB_REGNUM_GENERIC_PC,
1225                                      LLDB_REGNUM_GENERIC_RA, true);
1226   unwind_plan.AppendRow(row);
1227
1228   unwind_plan.SetSourceName("hexagon at-func-entry default");
1229   unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
1230   return true;
1231 }
1232
1233 bool ABISysV_hexagon::CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) {
1234   unwind_plan.Clear();
1235   unwind_plan.SetRegisterKind(eRegisterKindGeneric);
1236
1237   uint32_t fp_reg_num = LLDB_REGNUM_GENERIC_FP;
1238   uint32_t sp_reg_num = LLDB_REGNUM_GENERIC_SP;
1239   uint32_t pc_reg_num = LLDB_REGNUM_GENERIC_PC;
1240
1241   UnwindPlan::RowSP row(new UnwindPlan::Row);
1242
1243   row->GetCFAValue().SetIsRegisterPlusOffset(LLDB_REGNUM_GENERIC_FP, 8);
1244
1245   row->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, -8, true);
1246   row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, -4, true);
1247   row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true);
1248
1249   unwind_plan.AppendRow(row);
1250   unwind_plan.SetSourceName("hexagon default unwind plan");
1251   unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
1252   unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);
1253   return true;
1254 }
1255
1256 /*
1257     Register            Usage                                   Saved By
1258
1259     R0  - R5            parameters(a)                   -
1260     R6  - R15           Scratch(b)                              Caller
1261     R16 - R27           Scratch                                 Callee
1262     R28                         Scratch(b)                              Caller
1263     R29 - R31           Stack Frames                    Callee(c)
1264     P3:0                        Processor State                 Caller
1265
1266     a = the caller can change parameter values
1267     b = R14 - R15 and R28 are used by the procedure linkage table
1268     c = R29 - R31 are saved and restored by allocframe() and deallocframe()
1269 */
1270 bool ABISysV_hexagon::RegisterIsVolatile(const RegisterInfo *reg_info) {
1271   return !RegisterIsCalleeSaved(reg_info);
1272 }
1273
1274 bool ABISysV_hexagon::RegisterIsCalleeSaved(const RegisterInfo *reg_info) {
1275   int reg = ((reg_info->byte_offset) / 4);
1276
1277   bool save = (reg >= 16) && (reg <= 27);
1278   save |= (reg >= 29) && (reg <= 32);
1279
1280   return save;
1281 }
1282
1283 void ABISysV_hexagon::Initialize() {
1284   PluginManager::RegisterPlugin(GetPluginNameStatic(),
1285                                 "System V ABI for hexagon targets",
1286                                 CreateInstance);
1287 }
1288
1289 void ABISysV_hexagon::Terminate() {
1290   PluginManager::UnregisterPlugin(CreateInstance);
1291 }
1292
1293 lldb_private::ConstString ABISysV_hexagon::GetPluginNameStatic() {
1294   static ConstString g_name("sysv-hexagon");
1295   return g_name;
1296 }
1297
1298 //------------------------------------------------------------------
1299 // PluginInterface protocol
1300 //------------------------------------------------------------------
1301
1302 lldb_private::ConstString ABISysV_hexagon::GetPluginName() {
1303   return GetPluginNameStatic();
1304 }
1305
1306 uint32_t ABISysV_hexagon::GetPluginVersion() { return 1; }
1307
1308 // get value object specialized to work with llvm IR types
1309 lldb::ValueObjectSP
1310 ABISysV_hexagon::GetReturnValueObjectImpl(lldb_private::Thread &thread,
1311                                           llvm::Type &retType) const {
1312   Value value;
1313   ValueObjectSP vObjSP;
1314
1315   // get the current register context
1316   RegisterContext *reg_ctx = thread.GetRegisterContext().get();
1317   if (!reg_ctx)
1318     return vObjSP;
1319
1320   // for now just pop R0 to find the return value
1321   const lldb_private::RegisterInfo *r0_info =
1322       reg_ctx->GetRegisterInfoAtIndex(0);
1323   if (r0_info == nullptr)
1324     return vObjSP;
1325
1326   // void return type
1327   if (retType.isVoidTy()) {
1328     value.GetScalar() = 0;
1329   }
1330   // integer / pointer return type
1331   else if (retType.isIntegerTy() || retType.isPointerTy()) {
1332     // read r0 register value
1333     lldb_private::RegisterValue r0_value;
1334     if (!reg_ctx->ReadRegister(r0_info, r0_value))
1335       return vObjSP;
1336
1337     // push r0 into value
1338     uint32_t r0_u32 = r0_value.GetAsUInt32();
1339
1340     // account for integer size
1341     if (retType.isIntegerTy() && retType.isSized()) {
1342       uint64_t size = retType.getScalarSizeInBits();
1343       uint64_t mask = (1ull << size) - 1;
1344       // mask out higher order bits then the type we expect
1345       r0_u32 &= mask;
1346     }
1347
1348     value.GetScalar() = r0_u32;
1349   }
1350   // unsupported return type
1351   else
1352     return vObjSP;
1353
1354   // pack the value into a ValueObjectSP
1355   vObjSP = ValueObjectConstResult::Create(thread.GetStackFrameAtIndex(0).get(),
1356                                           value, ConstString(""));
1357   return vObjSP;
1358 }