GDB (xrefs)
Loading...
Searching...
No Matches
loongarch.c
Go to the documentation of this file.
1/* Copyright (C) 2022-2023 Free Software Foundation, Inc.
2
3 This file is part of GDB.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18#include "gdbsupport/common-defs.h"
19#include "loongarch.h"
20#include <stdlib.h>
21#include <unordered_map>
22
23/* Target description features. */
24
28
29#ifndef GDBSERVER
30#define STATIC_IN_GDB static
31#else
32#define STATIC_IN_GDB
33#endif
34
35STATIC_IN_GDB target_desc_up
37{
38 /* Now we should create a new target description. */
39 target_desc_up tdesc = allocate_target_description ();
40
41 std::string arch_name = "loongarch";
42
43 if (features.xlen == 4)
44 arch_name.append ("32");
45 else if (features.xlen == 8)
46 arch_name.append ("64");
47
48 if (features.fputype == SINGLE_FLOAT)
49 arch_name.append ("f");
50 else if (features.fputype == DOUBLE_FLOAT)
51 arch_name.append ("d");
52
53 set_tdesc_architecture (tdesc.get (), arch_name.c_str ());
54
55 long regnum = 0;
56
57 /* For now we only support creating 32-bit or 64-bit x-registers. */
58 if (features.xlen == 4)
60 else if (features.xlen == 8)
62
63 /* For now we only support creating single float and double float. */
65
66 return tdesc;
67}
68
69#ifndef GDBSERVER
70
71/* Wrapper used by std::unordered_map to generate hash for feature set. */
73{
74 std::size_t
75 operator() (const loongarch_gdbarch_features &features) const noexcept
76 {
77 return features.hash ();
78 }
79};
80
81/* Cache of previously seen target descriptions, indexed by the feature set
82 that created them. */
83static std::unordered_map<loongarch_gdbarch_features,
84 const target_desc_up,
86
87const target_desc *
89{
90 /* Lookup in the cache. If we find it then return the pointer out of
91 the target_desc_up (which is a unique_ptr). This is safe as the
92 loongarch_tdesc_cache will exist until GDB exits. */
93 const auto it = loongarch_tdesc_cache.find (features);
94 if (it != loongarch_tdesc_cache.end ())
95 return it->second.get ();
96
97 target_desc_up tdesc (loongarch_create_target_description (features));
98
99 /* Add to the cache, and return a pointer borrowed from the
100 target_desc_up. This is safe as the cache (and the pointers
101 contained within it) are not deleted until GDB exits. */
102 target_desc *ptr = tdesc.get ();
103 loongarch_tdesc_cache.emplace (features, std::move (tdesc));
104 return ptr;
105}
106
107#endif /* !GDBSERVER */
int regnum
static int create_feature_loongarch_base32(struct target_desc *result, long regnum)
Definition base32.c:7
static int create_feature_loongarch_base64(struct target_desc *result, long regnum)
Definition base64.c:7
static int create_feature_loongarch_fpu(struct target_desc *result, long regnum)
Definition fpu.c:7
static std::unordered_map< loongarch_gdbarch_features, const target_desc_up, loongarch_gdbarch_features_hasher > loongarch_tdesc_cache
Definition loongarch.c:85
const target_desc * loongarch_lookup_target_description(const struct loongarch_gdbarch_features features)
Definition loongarch.c:88
STATIC_IN_GDB target_desc_up loongarch_create_target_description(const struct loongarch_gdbarch_features features)
Definition loongarch.c:36
#define STATIC_IN_GDB
Definition loongarch.c:30
@ DOUBLE_FLOAT
Definition loongarch.h:49
@ SINGLE_FLOAT
Definition loongarch.h:48
std::size_t operator()(const loongarch_gdbarch_features &features) const noexcept
Definition loongarch.c:75
void set_tdesc_architecture(struct target_desc *target_desc, const char *name)
target_desc_up allocate_target_description(void)