LLDB mainline
ABISysV_mips64.cpp
Go to the documentation of this file.
1//===-- ABISysV_mips64.cpp ------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "ABISysV_mips64.h"
10
11#include "llvm/ADT/STLExtras.h"
12#include "llvm/TargetParser/Triple.h"
13
14#include "lldb/Core/Module.h"
16#include "lldb/Core/Value.h"
18#include "lldb/Target/Process.h"
21#include "lldb/Target/Target.h"
22#include "lldb/Target/Thread.h"
26#include "lldb/Utility/Log.h"
28#include "lldb/Utility/Status.h"
32#include <optional>
33
34using namespace lldb;
35using namespace lldb_private;
36
38
78};
79
81 {"r0",
82 "zero",
83 8,
84 0,
89 nullptr,
90 nullptr,
91 nullptr,
92 },
93 {"r1",
94 "AT",
95 8,
96 0,
101 nullptr,
102 nullptr,
103 nullptr,
104
105 },
106 {"r2",
107 "v0",
108 8,
109 0,
114 nullptr,
115 nullptr,
116 nullptr,
117 },
118 {"r3",
119 "v1",
120 8,
121 0,
126 nullptr,
127 nullptr,
128 nullptr,
129 },
130 {"r4",
131 nullptr,
132 8,
133 0,
138 nullptr,
139 nullptr,
140 nullptr,
141 },
142 {"r5",
143 nullptr,
144 8,
145 0,
150 nullptr,
151 nullptr,
152 nullptr,
153 },
154 {"r6",
155 nullptr,
156 8,
157 0,
162 nullptr,
163 nullptr,
164 nullptr,
165 },
166 {"r7",
167 nullptr,
168 8,
169 0,
174 nullptr,
175 nullptr,
176 nullptr,
177 },
178 {"r8",
179 nullptr,
180 8,
181 0,
186 nullptr,
187 nullptr,
188 nullptr,
189 },
190 {"r9",
191 nullptr,
192 8,
193 0,
198 nullptr,
199 nullptr,
200 nullptr,
201 },
202 {"r10",
203 nullptr,
204 8,
205 0,
210 nullptr,
211 nullptr,
212 nullptr,
213 },
214 {"r11",
215 nullptr,
216 8,
217 0,
222 nullptr,
223 nullptr,
224 nullptr,
225 },
226 {"r12",
227 nullptr,
228 8,
229 0,
234 nullptr,
235 nullptr,
236 nullptr,
237 },
238 {"r13",
239 nullptr,
240 8,
241 0,
246 nullptr,
247 nullptr,
248 nullptr,
249 },
250 {"r14",
251 nullptr,
252 8,
253 0,
258 nullptr,
259 nullptr,
260 nullptr,
261 },
262 {"r15",
263 nullptr,
264 8,
265 0,
270 nullptr,
271 nullptr,
272 nullptr,
273 },
274 {"r16",
275 nullptr,
276 8,
277 0,
282 nullptr,
283 nullptr,
284 nullptr,
285 },
286 {"r17",
287 nullptr,
288 8,
289 0,
294 nullptr,
295 nullptr,
296 nullptr,
297 },
298 {"r18",
299 nullptr,
300 8,
301 0,
306 nullptr,
307 nullptr,
308 nullptr,
309 },
310 {"r19",
311 nullptr,
312 8,
313 0,
318 nullptr,
319 nullptr,
320 nullptr,
321 },
322 {"r20",
323 nullptr,
324 8,
325 0,
330 nullptr,
331 nullptr,
332 nullptr,
333 },
334 {"r21",
335 nullptr,
336 8,
337 0,
342 nullptr,
343 nullptr,
344 nullptr,
345 },
346 {"r22",
347 nullptr,
348 8,
349 0,
354 nullptr,
355 nullptr,
356 nullptr,
357 },
358 {"r23",
359 nullptr,
360 8,
361 0,
366 nullptr,
367 nullptr,
368 nullptr,
369 },
370 {"r24",
371 nullptr,
372 8,
373 0,
378 nullptr,
379 nullptr,
380 nullptr,
381 },
382 {"r25",
383 nullptr,
384 8,
385 0,
390 nullptr,
391 nullptr,
392 nullptr,
393 },
394 {"r26",
395 nullptr,
396 8,
397 0,
402 nullptr,
403 nullptr,
404 nullptr,
405 },
406 {"r27",
407 nullptr,
408 8,
409 0,
414 nullptr,
415 nullptr,
416 nullptr,
417 },
418 {"r28",
419 "gp",
420 8,
421 0,
426 nullptr,
427 nullptr,
428 nullptr,
429 },
430 {"r29",
431 nullptr,
432 8,
433 0,
438 nullptr,
439 nullptr,
440 nullptr,
441 },
442 {"r30",
443 nullptr,
444 8,
445 0,
450 nullptr,
451 nullptr,
452 nullptr,
453 },
454 {"r31",
455 nullptr,
456 8,
457 0,
462 nullptr,
463 nullptr,
464 nullptr,
465 },
466 {"sr",
467 nullptr,
468 4,
469 0,
474 nullptr,
475 nullptr,
476 nullptr,
477 },
478 {"lo",
479 nullptr,
480 8,
481 0,
486 nullptr,
487 nullptr,
488 nullptr,
489 },
490 {"hi",
491 nullptr,
492 8,
493 0,
498 nullptr,
499 nullptr,
500 nullptr,
501 },
502 {"bad",
503 nullptr,
504 8,
505 0,
510 nullptr,
511 nullptr,
512 nullptr,
513 },
514 {"cause",
515 nullptr,
516 8,
517 0,
522 nullptr,
523 nullptr,
524 nullptr,
525 },
526 {"pc",
527 nullptr,
528 8,
529 0,
534 nullptr,
535 nullptr,
536 nullptr,
537 },
538};
539
540static const uint32_t k_num_register_infos = std::size(g_register_infos_mips64);
541
544 count = k_num_register_infos;
546}
547
548size_t ABISysV_mips64::GetRedZoneSize() const { return 0; }
549
550// Static Functions
551
552ABISP
554 if (arch.GetTriple().isMIPS64())
555 return ABISP(
556 new ABISysV_mips64(std::move(process_sp), MakeMCRegisterInfo(arch)));
557 return ABISP();
558}
559
561 addr_t func_addr, addr_t return_addr,
562 llvm::ArrayRef<addr_t> args) const {
563 Log *log = GetLog(LLDBLog::Expressions);
564
565 if (log) {
566 StreamString s;
567 s.Printf("ABISysV_mips64::PrepareTrivialCall (tid = 0x%" PRIx64
568 ", sp = 0x%" PRIx64 ", func_addr = 0x%" PRIx64
569 ", return_addr = 0x%" PRIx64,
570 thread.GetID(), (uint64_t)sp, (uint64_t)func_addr,
571 (uint64_t)return_addr);
572
573 for (size_t i = 0; i < args.size(); ++i)
574 s.Printf(", arg%zd = 0x%" PRIx64, i + 1, args[i]);
575 s.PutCString(")");
576 log->PutString(s.GetString());
577 }
578
579 RegisterContext *reg_ctx = thread.GetRegisterContext().get();
580 if (!reg_ctx)
581 return false;
582
583 const RegisterInfo *reg_info = nullptr;
584
585 if (args.size() > 8) // TODO handle more than 8 arguments
586 return false;
587
588 for (size_t i = 0; i < args.size(); ++i) {
589 reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric,
591 LLDB_LOGF(log, "About to write arg%zd (0x%" PRIx64 ") into %s", i + 1,
592 args[i], reg_info->name);
593 if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, args[i]))
594 return false;
595 }
596
597 // First, align the SP
598
599 LLDB_LOGF(log, "16-byte aligning SP: 0x%" PRIx64 " to 0x%" PRIx64,
600 (uint64_t)sp, (uint64_t)(sp & ~0xfull));
601
602 sp &= ~(0xfull); // 16-byte alignment
603
605 const RegisterInfo *pc_reg_info =
607 const RegisterInfo *sp_reg_info =
609 const RegisterInfo *ra_reg_info =
611 const RegisterInfo *r25_info = reg_ctx->GetRegisterInfoByName("r25", 0);
612 const RegisterInfo *r0_info = reg_ctx->GetRegisterInfoByName("zero", 0);
613
614 LLDB_LOGF(log, "Writing R0: 0x%" PRIx64, (uint64_t)0);
615
616 /* Write r0 with 0, in case we are stopped in syscall,
617 * such setting prevents automatic decrement of the PC.
618 * This clears the bug 23659 for MIPS.
619 */
620 if (!reg_ctx->WriteRegisterFromUnsigned(r0_info, (uint64_t)0))
621 return false;
622
623 LLDB_LOGF(log, "Writing SP: 0x%" PRIx64, (uint64_t)sp);
624
625 // Set "sp" to the requested value
626 if (!reg_ctx->WriteRegisterFromUnsigned(sp_reg_info, sp))
627 return false;
628
629 LLDB_LOGF(log, "Writing RA: 0x%" PRIx64, (uint64_t)return_addr);
630
631 // Set "ra" to the return address
632 if (!reg_ctx->WriteRegisterFromUnsigned(ra_reg_info, return_addr))
633 return false;
634
635 LLDB_LOGF(log, "Writing PC: 0x%" PRIx64, (uint64_t)func_addr);
636
637 // Set pc to the address of the called function.
638 if (!reg_ctx->WriteRegisterFromUnsigned(pc_reg_info, func_addr))
639 return false;
640
641 LLDB_LOGF(log, "Writing r25: 0x%" PRIx64, (uint64_t)func_addr);
642
643 // All callers of position independent functions must place the address of
644 // the called function in t9 (r25)
645 if (!reg_ctx->WriteRegisterFromUnsigned(r25_info, func_addr))
646 return false;
647
648 return true;
649}
650
652 ValueList &values) const {
653 return false;
654}
655
657 lldb::ValueObjectSP &new_value_sp) {
659 if (!new_value_sp) {
660 error = Status::FromErrorString("Empty value object for return value.");
661 return error;
662 }
663
664 CompilerType compiler_type = new_value_sp->GetCompilerType();
665 if (!compiler_type) {
666 error = Status::FromErrorString("Null clang type for return value.");
667 return error;
668 }
669
670 Thread *thread = frame_sp->GetThread().get();
671
672 RegisterContext *reg_ctx = thread->GetRegisterContext().get();
673
674 if (!reg_ctx)
675 error = Status::FromErrorString("no registers are available");
676
677 DataExtractor data;
678 Status data_error;
679 size_t num_bytes = new_value_sp->GetData(data, data_error);
680 if (data_error.Fail()) {
682 "Couldn't convert return value to raw data: %s",
683 data_error.AsCString());
684 return error;
685 }
686
687 const uint32_t type_flags = compiler_type.GetTypeInfo(nullptr);
688
689 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
690 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
691 lldb::offset_t offset = 0;
692
693 if (num_bytes <= 16) {
694 const RegisterInfo *r2_info = reg_ctx->GetRegisterInfoByName("r2", 0);
695 if (num_bytes <= 8) {
696 uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
697
698 if (!reg_ctx->WriteRegisterFromUnsigned(r2_info, raw_value))
699 error = Status::FromErrorString("failed to write register r2");
700 } else {
701 uint64_t raw_value = data.GetMaxU64(&offset, 8);
702 if (reg_ctx->WriteRegisterFromUnsigned(r2_info, raw_value)) {
703 const RegisterInfo *r3_info =
704 reg_ctx->GetRegisterInfoByName("r3", 0);
705 raw_value = data.GetMaxU64(&offset, num_bytes - offset);
706
707 if (!reg_ctx->WriteRegisterFromUnsigned(r3_info, raw_value))
708 error = Status::FromErrorString("failed to write register r3");
709 } else
710 error = Status::FromErrorString("failed to write register r2");
711 }
712 } else {
714 "We don't support returning longer than 128 bit "
715 "integer values at present.");
716 }
717 } else if (type_flags & eTypeIsFloat) {
718 error = Status::FromErrorString("TODO: Handle Float Types.");
719 }
720 } else if (type_flags & eTypeIsVector) {
721 error =
722 Status::FromErrorString("returning vector values are not supported");
723 }
724
725 return error;
726}
727
729 Thread &thread, CompilerType &return_compiler_type) const {
730 ValueObjectSP return_valobj_sp;
731 return return_valobj_sp;
732}
733
735 Thread &thread, CompilerType &return_compiler_type) const {
736 ValueObjectSP return_valobj_sp;
737 Value value;
739
740 ExecutionContext exe_ctx(thread.shared_from_this());
741 if (exe_ctx.GetTargetPtr() == nullptr || exe_ctx.GetProcessPtr() == nullptr)
742 return return_valobj_sp;
743
744 value.SetCompilerType(return_compiler_type);
745
746 RegisterContext *reg_ctx = thread.GetRegisterContext().get();
747 if (!reg_ctx)
748 return return_valobj_sp;
749
750 Target *target = exe_ctx.GetTargetPtr();
751 const ArchSpec target_arch = target->GetArchitecture();
752 ByteOrder target_byte_order = target_arch.GetByteOrder();
753 std::optional<uint64_t> byte_size = return_compiler_type.GetByteSize(&thread);
754 if (!byte_size)
755 return return_valobj_sp;
756 const uint32_t type_flags = return_compiler_type.GetTypeInfo(nullptr);
757 uint32_t fp_flag =
759
760 const RegisterInfo *r2_info = reg_ctx->GetRegisterInfoByName("r2", 0);
761 const RegisterInfo *r3_info = reg_ctx->GetRegisterInfoByName("r3", 0);
762 assert(r2_info && r3_info && "Basic registers should always be present.");
763
764 if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) {
765 value.SetValueType(Value::ValueType::Scalar);
766
767 bool success = false;
768 if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) {
769 // Extract the register context so we can read arguments from registers
770 // In MIPS register "r2" (v0) holds the integer function return values
771
772 uint64_t raw_value = reg_ctx->ReadRegisterAsUnsigned(r2_info, 0);
773
774 const bool is_signed = (type_flags & eTypeIsSigned) != 0;
775 switch (*byte_size) {
776 default:
777 break;
778
779 case sizeof(uint64_t):
780 if (is_signed)
781 value.GetScalar() = (int64_t)(raw_value);
782 else
783 value.GetScalar() = (uint64_t)(raw_value);
784 success = true;
785 break;
786
787 case sizeof(uint32_t):
788 if (is_signed)
789 value.GetScalar() = (int32_t)(raw_value & UINT32_MAX);
790 else
791 value.GetScalar() = (uint32_t)(raw_value & UINT32_MAX);
792 success = true;
793 break;
794
795 case sizeof(uint16_t):
796 if (is_signed)
797 value.GetScalar() = (int16_t)(raw_value & UINT16_MAX);
798 else
799 value.GetScalar() = (uint16_t)(raw_value & UINT16_MAX);
800 success = true;
801 break;
802
803 case sizeof(uint8_t):
804 if (is_signed)
805 value.GetScalar() = (int8_t)(raw_value & UINT8_MAX);
806 else
807 value.GetScalar() = (uint8_t)(raw_value & UINT8_MAX);
808 success = true;
809 break;
810 }
811 } else if (type_flags & eTypeIsFloat) {
812 if (type_flags & eTypeIsComplex) {
813 // Don't handle complex yet.
814 } else if (IsSoftFloat(fp_flag)) {
815 uint64_t raw_value = reg_ctx->ReadRegisterAsUnsigned(r2_info, 0);
816 switch (*byte_size) {
817 case 4:
818 value.GetScalar() = *((float *)(&raw_value));
819 success = true;
820 break;
821 case 8:
822 value.GetScalar() = *((double *)(&raw_value));
823 success = true;
824 break;
825 case 16:
826 uint64_t result[2];
827 if (target_byte_order == eByteOrderLittle) {
828 result[0] = raw_value;
829 result[1] = reg_ctx->ReadRegisterAsUnsigned(r3_info, 0);
830 value.GetScalar() = *((long double *)(result));
831 } else {
832 result[0] = reg_ctx->ReadRegisterAsUnsigned(r3_info, 0);
833 result[1] = raw_value;
834 value.GetScalar() = *((long double *)(result));
835 }
836 success = true;
837 break;
838 }
839
840 } else {
841 if (*byte_size <= sizeof(long double)) {
842 const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0);
843
844 RegisterValue f0_value;
845 DataExtractor f0_data;
846
847 reg_ctx->ReadRegister(f0_info, f0_value);
848
849 f0_value.GetData(f0_data);
850
851 lldb::offset_t offset = 0;
852 if (*byte_size == sizeof(float)) {
853 value.GetScalar() = (float)f0_data.GetFloat(&offset);
854 success = true;
855 } else if (*byte_size == sizeof(double)) {
856 value.GetScalar() = (double)f0_data.GetDouble(&offset);
857 success = true;
858 } else if (*byte_size == sizeof(long double)) {
859 const RegisterInfo *f2_info =
860 reg_ctx->GetRegisterInfoByName("f2", 0);
861 RegisterValue f2_value;
862 DataExtractor f2_data;
863 reg_ctx->ReadRegister(f2_info, f2_value);
864 DataExtractor *copy_from_extractor = nullptr;
865 WritableDataBufferSP data_sp(new DataBufferHeap(16, 0));
866 DataExtractor return_ext(
867 data_sp, target_byte_order,
869
870 if (target_byte_order == eByteOrderLittle) {
871 copy_from_extractor = &f0_data;
872 copy_from_extractor->CopyByteOrderedData(
873 0, 8, data_sp->GetBytes(), *byte_size - 8, target_byte_order);
874 f2_value.GetData(f2_data);
875 copy_from_extractor = &f2_data;
876 copy_from_extractor->CopyByteOrderedData(
877 0, 8, data_sp->GetBytes() + 8, *byte_size - 8,
878 target_byte_order);
879 } else {
880 copy_from_extractor = &f0_data;
881 copy_from_extractor->CopyByteOrderedData(
882 0, 8, data_sp->GetBytes() + 8, *byte_size - 8,
883 target_byte_order);
884 f2_value.GetData(f2_data);
885 copy_from_extractor = &f2_data;
886 copy_from_extractor->CopyByteOrderedData(
887 0, 8, data_sp->GetBytes(), *byte_size - 8, target_byte_order);
888 }
889
890 return_valobj_sp = ValueObjectConstResult::Create(
891 &thread, return_compiler_type, ConstString(""), return_ext);
892 return return_valobj_sp;
893 }
894 }
895 }
896 }
897
898 if (success)
899 return_valobj_sp = ValueObjectConstResult::Create(
900 thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));
901 } else if (type_flags & eTypeIsStructUnion || type_flags & eTypeIsClass ||
902 type_flags & eTypeIsVector) {
903 // Any structure of up to 16 bytes in size is returned in the registers.
904 if (*byte_size <= 16) {
905 WritableDataBufferSP data_sp(new DataBufferHeap(16, 0));
906 DataExtractor return_ext(data_sp, target_byte_order,
908
909 RegisterValue r2_value, r3_value, f0_value, f1_value, f2_value;
910 // Tracks how much bytes of r2 and r3 registers we've consumed so far
911 uint32_t integer_bytes = 0;
912
913 // True if return values are in FP return registers.
914 bool use_fp_regs = false;
915 // True if we found any non floating point field in structure.
916 bool found_non_fp_field = false;
917 // True if return values are in r2 register.
918 bool use_r2 = false;
919 // True if return values are in r3 register.
920 bool use_r3 = false;
921 // True if the result is copied into our data buffer
922 bool sucess = false;
923 std::string name;
924 bool is_complex;
925 uint32_t count;
926 const uint32_t num_children = return_compiler_type.GetNumFields();
927
928 // A structure consisting of one or two FP values (and nothing else) will
929 // be returned in the two FP return-value registers i.e fp0 and fp2.
930 if (num_children <= 2) {
931 uint64_t field_bit_offset = 0;
932
933 // Check if this structure contains only floating point fields
934 for (uint32_t idx = 0; idx < num_children; idx++) {
935 CompilerType field_compiler_type =
936 return_compiler_type.GetFieldAtIndex(idx, name, &field_bit_offset,
937 nullptr, nullptr);
938
939 if (field_compiler_type.IsFloatingPointType(count, is_complex))
940 use_fp_regs = true;
941 else
942 found_non_fp_field = true;
943 }
944
945 if (use_fp_regs && !found_non_fp_field) {
946 // We have one or two FP-only values in this structure. Get it from
947 // f0/f2 registers.
948 DataExtractor f0_data, f1_data, f2_data;
949 const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0);
950 const RegisterInfo *f1_info = reg_ctx->GetRegisterInfoByName("f1", 0);
951 const RegisterInfo *f2_info = reg_ctx->GetRegisterInfoByName("f2", 0);
952
953 reg_ctx->ReadRegister(f0_info, f0_value);
954 reg_ctx->ReadRegister(f2_info, f2_value);
955
956 f0_value.GetData(f0_data);
957
958 for (uint32_t idx = 0; idx < num_children; idx++) {
959 CompilerType field_compiler_type =
960 return_compiler_type.GetFieldAtIndex(
961 idx, name, &field_bit_offset, nullptr, nullptr);
962 std::optional<uint64_t> field_byte_width =
963 field_compiler_type.GetByteSize(&thread);
964 if (!field_byte_width)
965 return return_valobj_sp;
966
967 DataExtractor *copy_from_extractor = nullptr;
968 uint64_t return_value[2];
969 offset_t offset = 0;
970
971 if (idx == 0) {
972 // This case is for long double type.
973 if (*field_byte_width == 16) {
974
975 // If structure contains long double type, then it is returned
976 // in fp0/fp1 registers.
977 if (target_byte_order == eByteOrderLittle) {
978 return_value[0] = f0_data.GetU64(&offset);
979 reg_ctx->ReadRegister(f1_info, f1_value);
980 f1_value.GetData(f1_data);
981 offset = 0;
982 return_value[1] = f1_data.GetU64(&offset);
983 } else {
984 return_value[1] = f0_data.GetU64(&offset);
985 reg_ctx->ReadRegister(f1_info, f1_value);
986 f1_value.GetData(f1_data);
987 offset = 0;
988 return_value[0] = f1_data.GetU64(&offset);
989 }
990
991 f0_data.SetData(return_value, *field_byte_width,
992 target_byte_order);
993 }
994 copy_from_extractor = &f0_data; // This is in f0, copy from
995 // register to our result
996 // structure
997 } else {
998 f2_value.GetData(f2_data);
999 // This is in f2, copy from register to our result structure
1000 copy_from_extractor = &f2_data;
1001 }
1002
1003 // Sanity check to avoid crash
1004 if (!copy_from_extractor ||
1005 *field_byte_width > copy_from_extractor->GetByteSize())
1006 return return_valobj_sp;
1007
1008 // copy the register contents into our data buffer
1009 copy_from_extractor->CopyByteOrderedData(
1010 0, *field_byte_width,
1011 data_sp->GetBytes() + (field_bit_offset / 8), *field_byte_width,
1012 target_byte_order);
1013 }
1014
1015 // The result is in our data buffer. Create a variable object out of
1016 // it
1017 return_valobj_sp = ValueObjectConstResult::Create(
1018 &thread, return_compiler_type, ConstString(""), return_ext);
1019
1020 return return_valobj_sp;
1021 }
1022 }
1023
1024 // If we reach here, it means this structure either contains more than
1025 // two fields or it contains at least one non floating point type. In
1026 // that case, all fields are returned in GP return registers.
1027 for (uint32_t idx = 0; idx < num_children; idx++) {
1028 uint64_t field_bit_offset = 0;
1029 bool is_signed;
1030 uint32_t padding;
1031
1032 CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex(
1033 idx, name, &field_bit_offset, nullptr, nullptr);
1034 std::optional<uint64_t> field_byte_width =
1035 field_compiler_type.GetByteSize(&thread);
1036
1037 // if we don't know the size of the field (e.g. invalid type), just
1038 // bail out
1039 if (!field_byte_width || *field_byte_width == 0)
1040 break;
1041
1042 uint32_t field_byte_offset = field_bit_offset / 8;
1043
1044 if (field_compiler_type.IsIntegerOrEnumerationType(is_signed) ||
1045 field_compiler_type.IsPointerType() ||
1046 field_compiler_type.IsFloatingPointType(count, is_complex)) {
1047 padding = field_byte_offset - integer_bytes;
1048
1049 if (integer_bytes < 8) {
1050 // We have not yet consumed r2 completely.
1051 if (integer_bytes + *field_byte_width + padding <= 8) {
1052 // This field fits in r2, copy its value from r2 to our result
1053 // structure
1054 integer_bytes = integer_bytes + *field_byte_width +
1055 padding; // Increase the consumed bytes.
1056 use_r2 = true;
1057 } else {
1058 // There isn't enough space left in r2 for this field, so this
1059 // will be in r3.
1060 integer_bytes = integer_bytes + *field_byte_width +
1061 padding; // Increase the consumed bytes.
1062 use_r3 = true;
1063 }
1064 }
1065 // We already have consumed at-least 8 bytes that means r2 is done,
1066 // and this field will be in r3. Check if this field can fit in r3.
1067 else if (integer_bytes + *field_byte_width + padding <= 16) {
1068 integer_bytes = integer_bytes + *field_byte_width + padding;
1069 use_r3 = true;
1070 } else {
1071 // There isn't any space left for this field, this should not
1072 // happen as we have already checked the overall size is not
1073 // greater than 16 bytes. For now, return a nullptr return value
1074 // object.
1075 return return_valobj_sp;
1076 }
1077 }
1078 }
1079 // Vector types up to 16 bytes are returned in GP return registers
1080 if (type_flags & eTypeIsVector) {
1081 if (*byte_size <= 8)
1082 use_r2 = true;
1083 else {
1084 use_r2 = true;
1085 use_r3 = true;
1086 }
1087 }
1088
1089 if (use_r2) {
1090 reg_ctx->ReadRegister(r2_info, r2_value);
1091
1092 const size_t bytes_copied = r2_value.GetAsMemoryData(
1093 *r2_info, data_sp->GetBytes(), r2_info->byte_size,
1094 target_byte_order, error);
1095 if (bytes_copied != r2_info->byte_size)
1096 return return_valobj_sp;
1097 sucess = true;
1098 }
1099 if (use_r3) {
1100 reg_ctx->ReadRegister(r3_info, r3_value);
1101 const size_t bytes_copied = r3_value.GetAsMemoryData(
1102 *r3_info, data_sp->GetBytes() + r2_info->byte_size,
1103 r3_info->byte_size, target_byte_order, error);
1104
1105 if (bytes_copied != r3_info->byte_size)
1106 return return_valobj_sp;
1107 sucess = true;
1108 }
1109 if (sucess) {
1110 // The result is in our data buffer. Create a variable object out of
1111 // it
1112 return_valobj_sp = ValueObjectConstResult::Create(
1113 &thread, return_compiler_type, ConstString(""), return_ext);
1114 }
1115 return return_valobj_sp;
1116 }
1117
1118 // Any structure/vector greater than 16 bytes in size is returned in
1119 // memory. The pointer to that memory is returned in r2.
1120 uint64_t mem_address = reg_ctx->ReadRegisterAsUnsigned(
1121 reg_ctx->GetRegisterInfoByName("r2", 0), 0);
1122
1123 // We have got the address. Create a memory object out of it
1124 return_valobj_sp = ValueObjectMemory::Create(
1125 &thread, "", Address(mem_address, nullptr), return_compiler_type);
1126 }
1127 return return_valobj_sp;
1128}
1129
1131 unwind_plan.Clear();
1133
1135
1136 // Our Call Frame Address is the stack pointer value
1137 row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_r29, 0);
1138
1139 // The previous PC is in the RA
1140 row->SetRegisterLocationToRegister(dwarf_pc, dwarf_r31, true);
1141 unwind_plan.AppendRow(row);
1142
1143 // All other registers are the same.
1144
1145 unwind_plan.SetSourceName("mips64 at-func-entry default");
1148 return true;
1149}
1150
1152 unwind_plan.Clear();
1154
1156
1157 row->SetUnspecifiedRegistersAreUndefined(true);
1158 row->GetCFAValue().SetIsRegisterPlusOffset(dwarf_r29, 0);
1159
1160 row->SetRegisterLocationToRegister(dwarf_pc, dwarf_r31, true);
1161
1162 unwind_plan.AppendRow(row);
1163 unwind_plan.SetSourceName("mips64 default unwind plan");
1167 return true;
1168}
1169
1171 return !RegisterIsCalleeSaved(reg_info);
1172}
1173
1174bool ABISysV_mips64::IsSoftFloat(uint32_t fp_flag) const {
1176}
1177
1179 if (reg_info) {
1180 // Preserved registers are :
1181 // r16-r23, r28, r29, r30, r31
1182
1183 int reg = ((reg_info->byte_offset) / 8);
1184
1185 bool save = (reg >= 16) && (reg <= 23);
1186 save |= (reg >= 28) && (reg <= 31);
1187
1188 return save;
1189 }
1190 return false;
1191}
1192
1195 GetPluginNameStatic(), "System V ABI for mips64 targets", CreateInstance);
1196}
1197
1200}
static const uint32_t k_num_register_infos
@ dwarf_r7
@ dwarf_r21
@ dwarf_r24
@ dwarf_r12
@ dwarf_hi
@ dwarf_r3
@ dwarf_r13
@ dwarf_r2
@ dwarf_r8
@ dwarf_r28
@ dwarf_bad
@ dwarf_r11
@ dwarf_r31
@ dwarf_sr
@ dwarf_r19
@ dwarf_r1
@ dwarf_r26
@ dwarf_r9
@ dwarf_pc
@ dwarf_r29
@ dwarf_r16
@ dwarf_r18
@ dwarf_r17
@ dwarf_r15
@ dwarf_lo
@ dwarf_r23
@ dwarf_r10
@ dwarf_cause
@ dwarf_r14
@ dwarf_r6
@ dwarf_r25
@ dwarf_r30
@ dwarf_r0
@ dwarf_r5
@ dwarf_r20
@ dwarf_r27
@ dwarf_r4
@ dwarf_r22
static const uint32_t k_num_register_infos
static const RegisterInfo g_register_infos_mips64[]
dwarf_regnums
@ dwarf_r31
@ dwarf_pc
@ dwarf_r29
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition: Log.h:376
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:32
static llvm::StringRef GetPluginNameStatic()
bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info)
bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp, lldb::addr_t functionAddress, lldb::addr_t returnAddress, llvm::ArrayRef< lldb::addr_t > args) const override
lldb_private::Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value) override
bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override
static void Initialize()
const lldb_private::RegisterInfo * GetRegisterInfoArray(uint32_t &count) override
static void Terminate()
lldb::ValueObjectSP GetReturnValueObjectSimple(lldb_private::Thread &thread, lldb_private::CompilerType &ast_type) const
bool GetArgumentValues(lldb_private::Thread &thread, lldb_private::ValueList &values) const override
lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread, lldb_private::CompilerType &type) const override
bool IsSoftFloat(uint32_t fp_flag) const
bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
size_t GetRedZoneSize() const override
static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch)
bool CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override
static std::unique_ptr< llvm::MCRegisterInfo > MakeMCRegisterInfo(const ArchSpec &arch)
Utility function to construct a MCRegisterInfo using the ArchSpec triple.
Definition: ABI.cpp:234
A section + offset based address class.
Definition: Address.h:62
An architecture specification class.
Definition: ArchSpec.h:31
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition: ArchSpec.cpp:709
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:461
uint32_t GetFlags() const
Definition: ArchSpec.h:532
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
Definition: ArchSpec.cpp:756
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
CompilerType GetFieldAtIndex(size_t idx, std::string &name, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) const
bool IsFloatingPointType(uint32_t &count, bool &is_complex) const
uint32_t GetNumFields() const
bool IsIntegerOrEnumerationType(bool &is_signed) const
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
bool IsPointerType(CompilerType *pointee_type=nullptr) const
A uniqued constant string class.
Definition: ConstString.h:40
A subclass of DataBuffer that stores a data buffer on the heap.
An data extractor class.
Definition: DataExtractor.h:48
float GetFloat(lldb::offset_t *offset_ptr) const
Extract a float from *offset_ptr.
uint64_t GetU64(lldb::offset_t *offset_ptr) const
Extract a uint64_t value from *offset_ptr.
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
uint64_t GetMaxU64(lldb::offset_t *offset_ptr, size_t byte_size) const
Extract an unsigned integer of size byte_size from *offset_ptr.
lldb::offset_t CopyByteOrderedData(lldb::offset_t src_offset, lldb::offset_t src_len, void *dst, lldb::offset_t dst_len, lldb::ByteOrder dst_byte_order) const
Copy dst_len bytes from *offset_ptr and ensure the copied data is treated as a value that can be swap...
double GetDouble(lldb::offset_t *offset_ptr) const
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
Target * GetTargetPtr() const
Returns a pointer to the target object.
Process * GetProcessPtr() const
Returns a pointer to the process object.
void PutString(llvm::StringRef str)
Definition: Log.cpp:147
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value)
const RegisterInfo * GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num)
bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval)
const RegisterInfo * GetRegisterInfoByName(llvm::StringRef reg_name, uint32_t start_idx=0)
virtual bool ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value)=0
bool GetData(DataExtractor &data) const
uint32_t GetAsMemoryData(const RegisterInfo &reg_info, void *dst, uint32_t dst_len, lldb::ByteOrder dst_byte_order, Status &error) const
An error handling class.
Definition: Status.h:115
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition: Status.cpp:106
static Status FromErrorString(const char *str)
Definition: Status.h:138
bool Fail() const
Test for error condition.
Definition: Status.cpp:270
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:195
llvm::StringRef GetString() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:65
const ArchSpec & GetArchitecture() const
Definition: Target.h:1039
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition: Thread.h:408
virtual lldb::RegisterContextSP GetRegisterContext()=0
void SetUnwindPlanForSignalTrap(lldb_private::LazyBool is_for_signal_trap)
Definition: UnwindPlan.h:536
void SetRegisterKind(lldb::RegisterKind kind)
Definition: UnwindPlan.h:471
void SetReturnAddressRegister(uint32_t regnum)
Definition: UnwindPlan.h:473
void AppendRow(const RowSP &row_sp)
Definition: UnwindPlan.cpp:392
std::shared_ptr< Row > RowSP
Definition: UnwindPlan.h:429
void SetSourcedFromCompiler(lldb_private::LazyBool from_compiler)
Definition: UnwindPlan.h:512
void SetSourceName(const char *)
Definition: UnwindPlan.cpp:594
void SetUnwindPlanValidAtAllInstructions(lldb_private::LazyBool valid_at_all_insn)
Definition: UnwindPlan.h:524
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size, lldb::addr_t address=LLDB_INVALID_ADDRESS)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, llvm::StringRef name, const Address &address, lldb::TypeSP &type_sp)
const Scalar & GetScalar() const
Definition: Value.h:112
void SetCompilerType(const CompilerType &compiler_type)
Definition: Value.cpp:268
void SetValueType(ValueType value_type)
Definition: Value.h:89
#define LLDB_REGNUM_GENERIC_RA
Definition: lldb-defines.h:59
#define LLDB_REGNUM_GENERIC_ARG8
Definition: lldb-defines.h:75
#define LLDB_REGNUM_GENERIC_ARG6
Definition: lldb-defines.h:71
#define LLDB_REGNUM_GENERIC_SP
Definition: lldb-defines.h:57
#define LLDB_REGNUM_GENERIC_ARG4
Definition: lldb-defines.h:67
#define LLDB_REGNUM_GENERIC_ARG3
Definition: lldb-defines.h:65
#define LLDB_REGNUM_GENERIC_ARG1
Definition: lldb-defines.h:61
#define LLDB_REGNUM_GENERIC_ARG7
Definition: lldb-defines.h:73
#define LLDB_REGNUM_GENERIC_FLAGS
Definition: lldb-defines.h:60
#define UINT32_MAX
Definition: lldb-defines.h:19
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:87
#define LLDB_REGNUM_GENERIC_ARG2
Definition: lldb-defines.h:63
#define LLDB_REGNUM_GENERIC_PC
Definition: lldb-defines.h:56
#define LLDB_REGNUM_GENERIC_FP
Definition: lldb-defines.h:58
#define LLDB_REGNUM_GENERIC_ARG5
Definition: lldb-defines.h:69
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:332
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ABI > ABISP
Definition: lldb-forward.h:317
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
Definition: lldb-forward.h:424
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:484
uint64_t offset_t
Definition: lldb-types.h:85
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:389
@ eEncodingUint
unsigned integer
ByteOrder
Byte ordering definitions.
@ eByteOrderLittle
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
Definition: lldb-forward.h:337
uint64_t addr_t
Definition: lldb-types.h:80
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
@ eRegisterKindDWARF
the register numbers seen DWARF
Every register is described in detail including its name, alternate name (optional),...
uint32_t byte_offset
The byte offset in the register context data where this register's value is found.
uint32_t byte_size
Size in bytes of the register.
const char * name
Name of this register, can't be NULL.
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47