File: RegisterInfoPOSIX_loongarch64.cpp

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (158 lines) | stat: -rw-r--r-- 6,655 bytes parent folder | download | duplicates (11)
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
//===-- RegisterInfoPOSIX_loongarch64.cpp --------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===---------------------------------------------------------------------===//

#include <cassert>
#include <lldb/Utility/Flags.h>
#include <stddef.h>

#include "lldb/lldb-defines.h"
#include "llvm/Support/Compiler.h"

#include "RegisterInfoPOSIX_loongarch64.h"

#define GPR_OFFSET(idx) ((idx)*8 + 0)
#define FPR_OFFSET(idx) ((idx)*8 + sizeof(RegisterInfoPOSIX_loongarch64::GPR))
#define FCC_OFFSET(idx) ((idx)*1 + 32 * 8 + sizeof(RegisterInfoPOSIX_loongarch64::GPR))
#define FCSR_OFFSET (8 * 1 + 32 * 8 + sizeof(RegisterInfoPOSIX_loongarch64::GPR))

#define REG_CONTEXT_SIZE                                                       \
  (sizeof(RegisterInfoPOSIX_loongarch64::GPR) +                                \
   sizeof(RegisterInfoPOSIX_loongarch64::FPR))

#define DECLARE_REGISTER_INFOS_LOONGARCH64_STRUCT
#include "RegisterInfos_loongarch64.h"
#undef DECLARE_REGISTER_INFOS_LOONGARCH64_STRUCT

const lldb_private::RegisterInfo *
RegisterInfoPOSIX_loongarch64::GetRegisterInfoPtr(
    const lldb_private::ArchSpec &target_arch) {
  switch (target_arch.GetMachine()) {
  case llvm::Triple::loongarch64:
    return g_register_infos_loongarch64;
  default:
    assert(false && "Unhandled target architecture.");
    return nullptr;
  }
}

uint32_t RegisterInfoPOSIX_loongarch64::GetRegisterInfoCount(
    const lldb_private::ArchSpec &target_arch) {
  switch (target_arch.GetMachine()) {
  case llvm::Triple::loongarch64:
    return static_cast<uint32_t>(sizeof(g_register_infos_loongarch64) /
                                 sizeof(g_register_infos_loongarch64[0]));
  default:
    assert(false && "Unhandled target architecture.");
    return 0;
  }
}

// Number of register sets provided by this context.
enum {
  k_num_gpr_registers = gpr_last_loongarch - gpr_first_loongarch + 1,
  k_num_fpr_registers = fpr_last_loongarch - fpr_first_loongarch + 1,
  k_num_register_sets = 2
};

// LoongArch64 general purpose registers.
static const uint32_t g_gpr_regnums_loongarch64[] = {
    gpr_r0_loongarch,        gpr_r1_loongarch,        gpr_r2_loongarch,
    gpr_r3_loongarch,        gpr_r4_loongarch,        gpr_r5_loongarch,
    gpr_r6_loongarch,        gpr_r7_loongarch,        gpr_r8_loongarch,
    gpr_r9_loongarch,        gpr_r10_loongarch,       gpr_r11_loongarch,
    gpr_r12_loongarch,       gpr_r13_loongarch,       gpr_r14_loongarch,
    gpr_r15_loongarch,       gpr_r16_loongarch,       gpr_r17_loongarch,
    gpr_r18_loongarch,       gpr_r19_loongarch,       gpr_r20_loongarch,
    gpr_r21_loongarch,       gpr_r22_loongarch,       gpr_r23_loongarch,
    gpr_r24_loongarch,       gpr_r25_loongarch,       gpr_r26_loongarch,
    gpr_r27_loongarch,       gpr_r28_loongarch,       gpr_r29_loongarch,
    gpr_r30_loongarch,       gpr_r31_loongarch,       gpr_orig_a0_loongarch,
    gpr_pc_loongarch,        gpr_badv_loongarch,      gpr_reserved0_loongarch,
    gpr_reserved1_loongarch, gpr_reserved2_loongarch, gpr_reserved3_loongarch,
    gpr_reserved4_loongarch, gpr_reserved5_loongarch, gpr_reserved6_loongarch,
    gpr_reserved7_loongarch, gpr_reserved8_loongarch, gpr_reserved9_loongarch,
    LLDB_INVALID_REGNUM};

static_assert(((sizeof g_gpr_regnums_loongarch64 /
                sizeof g_gpr_regnums_loongarch64[0]) -
               1) == k_num_gpr_registers,
              "g_gpr_regnums_loongarch64 has wrong number of register infos");

// LoongArch64 floating point registers.
static const uint32_t g_fpr_regnums_loongarch64[] = {
    fpr_f0_loongarch,   fpr_f1_loongarch,   fpr_f2_loongarch,
    fpr_f3_loongarch,   fpr_f4_loongarch,   fpr_f5_loongarch,
    fpr_f6_loongarch,   fpr_f7_loongarch,   fpr_f8_loongarch,
    fpr_f9_loongarch,   fpr_f10_loongarch,  fpr_f11_loongarch,
    fpr_f12_loongarch,  fpr_f13_loongarch,  fpr_f14_loongarch,
    fpr_f15_loongarch,  fpr_f16_loongarch,  fpr_f17_loongarch,
    fpr_f18_loongarch,  fpr_f19_loongarch,  fpr_f20_loongarch,
    fpr_f21_loongarch,  fpr_f22_loongarch,  fpr_f23_loongarch,
    fpr_f24_loongarch,  fpr_f25_loongarch,  fpr_f26_loongarch,
    fpr_f27_loongarch,  fpr_f28_loongarch,  fpr_f29_loongarch,
    fpr_f30_loongarch,  fpr_f31_loongarch,  fpr_fcc0_loongarch,
    fpr_fcc1_loongarch, fpr_fcc2_loongarch, fpr_fcc3_loongarch,
    fpr_fcc4_loongarch, fpr_fcc5_loongarch, fpr_fcc6_loongarch,
    fpr_fcc7_loongarch, fpr_fcsr_loongarch, LLDB_INVALID_REGNUM};

static_assert(((sizeof g_fpr_regnums_loongarch64 /
                sizeof g_fpr_regnums_loongarch64[0]) -
               1) == k_num_fpr_registers,
              "g_fpr_regnums_loongarch64 has wrong number of register infos");

// Register sets for LoongArch64.
static const lldb_private::RegisterSet
    g_reg_sets_loongarch64[k_num_register_sets] = {
        {"General Purpose Registers", "gpr", k_num_gpr_registers,
         g_gpr_regnums_loongarch64},
        {"Floating Point Registers", "fpr", k_num_fpr_registers,
         g_fpr_regnums_loongarch64}};

RegisterInfoPOSIX_loongarch64::RegisterInfoPOSIX_loongarch64(
    const lldb_private::ArchSpec &target_arch, lldb_private::Flags flags)
    : lldb_private::RegisterInfoAndSetInterface(target_arch),
      m_register_info_p(GetRegisterInfoPtr(target_arch)),
      m_register_info_count(GetRegisterInfoCount(target_arch)) {}

uint32_t RegisterInfoPOSIX_loongarch64::GetRegisterCount() const {
  return m_register_info_count;
}

size_t RegisterInfoPOSIX_loongarch64::GetGPRSize() const {
  return sizeof(struct RegisterInfoPOSIX_loongarch64::GPR);
}

size_t RegisterInfoPOSIX_loongarch64::GetFPRSize() const {
  return sizeof(struct RegisterInfoPOSIX_loongarch64::FPR);
}

const lldb_private::RegisterInfo *
RegisterInfoPOSIX_loongarch64::GetRegisterInfo() const {
  return m_register_info_p;
}

size_t RegisterInfoPOSIX_loongarch64::GetRegisterSetCount() const {
  return k_num_register_sets;
}

size_t RegisterInfoPOSIX_loongarch64::GetRegisterSetFromRegisterIndex(
    uint32_t reg_index) const {
  // coverity[unsigned_compare]
  if (reg_index >= gpr_first_loongarch && reg_index <= gpr_last_loongarch)
    return GPRegSet;
  if (reg_index >= fpr_first_loongarch && reg_index <= fpr_last_loongarch)
    return FPRegSet;
  return LLDB_INVALID_REGNUM;
}

const lldb_private::RegisterSet *
RegisterInfoPOSIX_loongarch64::GetRegisterSet(size_t set_index) const {
  if (set_index < GetRegisterSetCount())
    return &g_reg_sets_loongarch64[set_index];
  return nullptr;
}