reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    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
//===-- RegisterContextLinux_mips64.cpp ------------------------*- C++ -*-===//
//
// 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 <stddef.h>
#include <vector>

// For eh_frame and DWARF Register numbers
#include "RegisterContextLinux_mips64.h"

// For GP and FP buffers
#include "RegisterContext_mips.h"

// Internal codes for all mips32 and mips64 registers
#include "lldb-mips-linux-register-enums.h"

using namespace lldb;
using namespace lldb_private;

// Include RegisterInfos_mips64 to declare our g_register_infos_mips64
// structure.
#define DECLARE_REGISTER_INFOS_MIPS64_STRUCT
#define LINUX_MIPS64
#include "RegisterInfos_mips64.h"
#undef LINUX_MIPS64
#undef DECLARE_REGISTER_INFOS_MIPS64_STRUCT

// Include RegisterInfos_mips to declare our g_register_infos_mips structure.
#define DECLARE_REGISTER_INFOS_MIPS_STRUCT
#include "RegisterInfos_mips.h"
#undef DECLARE_REGISTER_INFOS_MIPS_STRUCT

// mips64 general purpose registers.
const uint32_t g_gp_regnums_mips64[] = {
    gpr_zero_mips64,    gpr_r1_mips64,    gpr_r2_mips64,
    gpr_r3_mips64,      gpr_r4_mips64,    gpr_r5_mips64,
    gpr_r6_mips64,      gpr_r7_mips64,    gpr_r8_mips64,
    gpr_r9_mips64,      gpr_r10_mips64,   gpr_r11_mips64,
    gpr_r12_mips64,     gpr_r13_mips64,   gpr_r14_mips64,
    gpr_r15_mips64,     gpr_r16_mips64,   gpr_r17_mips64,
    gpr_r18_mips64,     gpr_r19_mips64,   gpr_r20_mips64,
    gpr_r21_mips64,     gpr_r22_mips64,   gpr_r23_mips64,
    gpr_r24_mips64,     gpr_r25_mips64,   gpr_r26_mips64,
    gpr_r27_mips64,     gpr_gp_mips64,    gpr_sp_mips64,
    gpr_r30_mips64,     gpr_ra_mips64,    gpr_sr_mips64,
    gpr_mullo_mips64,   gpr_mulhi_mips64, gpr_badvaddr_mips64,
    gpr_cause_mips64,   gpr_pc_mips64,    gpr_config5_mips64,
    LLDB_INVALID_REGNUM // register sets need to end with this flag
};

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

// mips64 floating point registers.
const uint32_t g_fp_regnums_mips64[] = {
    fpr_f0_mips64,      fpr_f1_mips64,  fpr_f2_mips64,      fpr_f3_mips64,
    fpr_f4_mips64,      fpr_f5_mips64,  fpr_f6_mips64,      fpr_f7_mips64,
    fpr_f8_mips64,      fpr_f9_mips64,  fpr_f10_mips64,     fpr_f11_mips64,
    fpr_f12_mips64,     fpr_f13_mips64, fpr_f14_mips64,     fpr_f15_mips64,
    fpr_f16_mips64,     fpr_f17_mips64, fpr_f18_mips64,     fpr_f19_mips64,
    fpr_f20_mips64,     fpr_f21_mips64, fpr_f22_mips64,     fpr_f23_mips64,
    fpr_f24_mips64,     fpr_f25_mips64, fpr_f26_mips64,     fpr_f27_mips64,
    fpr_f28_mips64,     fpr_f29_mips64, fpr_f30_mips64,     fpr_f31_mips64,
    fpr_fcsr_mips64,    fpr_fir_mips64, fpr_config5_mips64,
    LLDB_INVALID_REGNUM // register sets need to end with this flag
};

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

// mips64 MSA registers.
const uint32_t g_msa_regnums_mips64[] = {
    msa_w0_mips64,      msa_w1_mips64,  msa_w2_mips64,   msa_w3_mips64,
    msa_w4_mips64,      msa_w5_mips64,  msa_w6_mips64,   msa_w7_mips64,
    msa_w8_mips64,      msa_w9_mips64,  msa_w10_mips64,  msa_w11_mips64,
    msa_w12_mips64,     msa_w13_mips64, msa_w14_mips64,  msa_w15_mips64,
    msa_w16_mips64,     msa_w17_mips64, msa_w18_mips64,  msa_w19_mips64,
    msa_w20_mips64,     msa_w21_mips64, msa_w22_mips64,  msa_w23_mips64,
    msa_w24_mips64,     msa_w25_mips64, msa_w26_mips64,  msa_w27_mips64,
    msa_w28_mips64,     msa_w29_mips64, msa_w30_mips64,  msa_w31_mips64,
    msa_fcsr_mips64,    msa_fir_mips64, msa_mcsr_mips64, msa_mir_mips64,
    msa_config5_mips64,
    LLDB_INVALID_REGNUM // register sets need to end with this flag
};

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

// Number of register sets provided by this context.
constexpr size_t k_num_register_sets = 3;

// Register sets for mips64.
static const RegisterSet g_reg_sets_mips64[k_num_register_sets] = {
    {"General Purpose Registers", "gpr", k_num_gpr_registers_mips64,
     g_gp_regnums_mips64},
    {"Floating Point Registers", "fpu", k_num_fpr_registers_mips64,
     g_fp_regnums_mips64},
    {"MSA Registers", "msa", k_num_msa_registers_mips64, g_msa_regnums_mips64},
};

const RegisterSet *
RegisterContextLinux_mips64::GetRegisterSet(size_t set) const {
  if (set >= k_num_register_sets)
    return nullptr;

  switch (m_target_arch.GetMachine()) {
  case llvm::Triple::mips64:
  case llvm::Triple::mips64el:
    return &g_reg_sets_mips64[set];
  default:
    assert(false && "Unhandled target architecture.");
    return nullptr;
  }
  return nullptr;
}

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

static const RegisterInfo *GetRegisterInfoPtr(const ArchSpec &target_arch) {
  switch (target_arch.GetMachine()) {
  case llvm::Triple::mips64:
  case llvm::Triple::mips64el:
    return g_register_infos_mips64;
  case llvm::Triple::mips:
  case llvm::Triple::mipsel:
    return g_register_infos_mips;
  default:
    assert(false && "Unhandled target architecture.");
    return nullptr;
  }
}

static uint32_t GetRegisterInfoCount(const ArchSpec &target_arch) {
  switch (target_arch.GetMachine()) {
  case llvm::Triple::mips64:
  case llvm::Triple::mips64el:
    return static_cast<uint32_t>(sizeof(g_register_infos_mips64) /
                                 sizeof(g_register_infos_mips64[0]));
  case llvm::Triple::mips:
  case llvm::Triple::mipsel:
    return static_cast<uint32_t>(sizeof(g_register_infos_mips) /
                                 sizeof(g_register_infos_mips[0]));
  default:
    assert(false && "Unhandled target architecture.");
    return 0;
  }
}

uint32_t GetUserRegisterInfoCount(const ArchSpec &target_arch,
                                  bool msa_present) {
  switch (target_arch.GetMachine()) {
  case llvm::Triple::mips:
  case llvm::Triple::mipsel:
    if (msa_present)
      return static_cast<uint32_t>(k_num_user_registers_mips);
    return static_cast<uint32_t>(k_num_user_registers_mips -
                                 k_num_msa_registers_mips);
  case llvm::Triple::mips64el:
  case llvm::Triple::mips64:
    if (msa_present)
      return static_cast<uint32_t>(k_num_user_registers_mips64);
    return static_cast<uint32_t>(k_num_user_registers_mips64 -
                                 k_num_msa_registers_mips64);
  default:
    assert(false && "Unhandled target architecture.");
    return 0;
  }
}

RegisterContextLinux_mips64::RegisterContextLinux_mips64(
    const ArchSpec &target_arch, bool msa_present)
    : lldb_private::RegisterInfoInterface(target_arch),
      m_register_info_p(GetRegisterInfoPtr(target_arch)),
      m_register_info_count(GetRegisterInfoCount(target_arch)),
      m_user_register_count(
          GetUserRegisterInfoCount(target_arch, msa_present)) {}

size_t RegisterContextLinux_mips64::GetGPRSize() const {
  return sizeof(GPR_linux_mips);
}

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

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

uint32_t RegisterContextLinux_mips64::GetUserRegisterCount() const {
  return m_user_register_count;
}