[PATCH 0/4] arc: Add GNU/Linux support

classic Classic list List threaded Threaded
52 messages Options
123
Reply | Threaded
Open this post in threaded view
|

[PATCH 0/4] arc: Add GNU/Linux support

Sourceware - gdb-patches mailing list
From: Shahab Vahedi <[hidden email]>

This is a series of changes to enable debugging ARC targets that are
running on a native ARC GNU/Linux system.  Most of these changes are
related to how registers are slightly handled differently compared
to a baremetal scenario.  Each commit illustrate further on those.

After this series, there will come patches that add support for
native ARC gdb/gdbserver.

Anton Kolesov (4):
  arc: Add XML target features for Linux targets
  arc: Recognize registers available on Linux targets
  arc: Add GNU/Linux support for ARC
  arc: Add arc-*-linux regformats

 gdb/Makefile.in                           |   1 +
 gdb/arc-linux-tdep.c                      | 284 ++++++++++++++++++++++
 gdb/arc-tdep.c                            |  84 +++++--
 gdb/arc-tdep.h                            |  22 +-
 gdb/arch/arc.c                            |  40 ++-
 gdb/arch/arc.h                            |  18 +-
 gdb/configure.tgt                         |   6 +
 gdb/doc/gdb.texinfo                       |   3 +-
 gdb/features/Makefile                     |   8 +-
 gdb/features/arc/aux-arcompact-linux.c    |  34 +++
 gdb/features/arc/aux-arcompact-linux.xml  |  31 +++
 gdb/features/arc/aux-v2-linux.c           |  38 +++
 gdb/features/arc/aux-v2-linux.xml         |  35 +++
 gdb/features/arc/core-arcompact-linux.c   |  45 ++++
 gdb/features/arc/core-arcompact-linux.xml |  56 +++++
 gdb/features/arc/core-v2-linux.c          |  48 ++++
 gdb/features/arc/core-v2-linux.xml        |  58 +++++
 gdb/regformats/arc-arcompact-linux.dat    |  42 ++++
 gdb/regformats/arc-v2-linux.dat           |  45 ++++
 19 files changed, 859 insertions(+), 39 deletions(-)
 create mode 100644 gdb/arc-linux-tdep.c
 create mode 100644 gdb/features/arc/aux-arcompact-linux.c
 create mode 100644 gdb/features/arc/aux-arcompact-linux.xml
 create mode 100644 gdb/features/arc/aux-v2-linux.c
 create mode 100644 gdb/features/arc/aux-v2-linux.xml
 create mode 100644 gdb/features/arc/core-arcompact-linux.c
 create mode 100644 gdb/features/arc/core-arcompact-linux.xml
 create mode 100644 gdb/features/arc/core-v2-linux.c
 create mode 100644 gdb/features/arc/core-v2-linux.xml
 create mode 100644 gdb/regformats/arc-arcompact-linux.dat
 create mode 100644 gdb/regformats/arc-v2-linux.dat

--
2.26.0

Reply | Threaded
Open this post in threaded view
|

[PATCH 1/4] arc: Add XML target features for Linux targets

Sourceware - gdb-patches mailing list
From: Anton Kolesov <[hidden email]>

Add XML target features for Linux targets.  Compared to default
Linux features:

- Explicitly specify CPU machine.
- Remove baremetal only ILINK{,1,2} registers.
- Add LP_START and LP_END registers for hardware loops - required to
  properly evaluate possible next instruction during software single
  instruction stepping.
- Add BTA register which contains branch target address - address of
  next instruction when processor is in the delay slot.
- ARC HS description also adds R30, R58 and R59 registers, specific to
  this architecture.

gdb/ChangeLog:
2020-03-26  Anton Kolesov  <[hidden email]>

        * arch/arc.h (arc_create_target_description): Support Linux targets.
        * arch/arc.c (arc_create_target_description): Likewise.
        * arc-tdep.c (arc_tdesc_init): Update invocation of
          arc_read_description.
        * features/Makefile (FEATURE_XMLFILES): Add new files.
        * features/arc/aux-arcompact-linux.xml: New file.
        * features/arc/aux-v2-linux.xml: Likewise.
        * features/arc/core-arcompact-linux.xml: Likewise.
        * features/arc/core-v2-linux.xml: Likewise.
        * features/arc/aux-arcompact-linux.c: Generate.
        * features/arc/aux-v2-linux.c: Likewise.
        * features/arc/core-arcompact-linux.c: Likewise.
        * features/arc/core-v2-linux.c: Likewise.
---
 gdb/arc-tdep.c                            |  4 +-
 gdb/arch/arc.c                            | 40 ++++++++++++----
 gdb/arch/arc.h                            | 18 ++++---
 gdb/features/Makefile                     |  4 ++
 gdb/features/arc/aux-arcompact-linux.c    | 34 +++++++++++++
 gdb/features/arc/aux-arcompact-linux.xml  | 31 ++++++++++++
 gdb/features/arc/aux-v2-linux.c           | 38 +++++++++++++++
 gdb/features/arc/aux-v2-linux.xml         | 35 ++++++++++++++
 gdb/features/arc/core-arcompact-linux.c   | 45 ++++++++++++++++++
 gdb/features/arc/core-arcompact-linux.xml | 56 ++++++++++++++++++++++
 gdb/features/arc/core-v2-linux.c          | 48 +++++++++++++++++++
 gdb/features/arc/core-v2-linux.xml        | 58 +++++++++++++++++++++++
 12 files changed, 394 insertions(+), 17 deletions(-)
 create mode 100644 gdb/features/arc/aux-arcompact-linux.c
 create mode 100644 gdb/features/arc/aux-arcompact-linux.xml
 create mode 100644 gdb/features/arc/aux-v2-linux.c
 create mode 100644 gdb/features/arc/aux-v2-linux.xml
 create mode 100644 gdb/features/arc/core-arcompact-linux.c
 create mode 100644 gdb/features/arc/core-arcompact-linux.xml
 create mode 100644 gdb/features/arc/core-v2-linux.c
 create mode 100644 gdb/features/arc/core-v2-linux.xml

diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index 3020099c335..a4f3f44b4fb 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -1756,9 +1756,9 @@ arc_tdesc_init (struct gdbarch_info info, const struct target_desc **tdesc,
   if (!tdesc_has_registers (tdesc_loc))
     {
       if (is_arcv2)
- tdesc_loc = arc_read_description (ARC_SYS_TYPE_ARCV2);
+ tdesc_loc = arc_read_description (ARC_SYS_TYPE_ARCV2_BMT);
       else
- tdesc_loc = arc_read_description (ARC_SYS_TYPE_ARCOMPACT);
+ tdesc_loc = arc_read_description (ARC_SYS_TYPE_ARCOMPACT_BMT);
     }
   else
     {
diff --git a/gdb/arch/arc.c b/gdb/arch/arc.c
index 9552b4aff97..0babbf8a36a 100644
--- a/gdb/arch/arc.c
+++ b/gdb/arch/arc.c
@@ -24,8 +24,12 @@
 /* Target description features.  */
 #include "features/arc/core-v2.c"
 #include "features/arc/aux-v2.c"
+#include "features/arc/core-v2-linux.c"
+#include "features/arc/aux-v2-linux.c"
 #include "features/arc/core-arcompact.c"
 #include "features/arc/aux-arcompact.c"
+#include "features/arc/core-arcompact-linux.c"
+#include "features/arc/aux-arcompact-linux.c"
 
 /* See arc.h.  */
 
@@ -37,21 +41,39 @@ arc_create_target_description (arc_sys_type sys_type)
   long regnum = 0;
 
 #ifndef IN_PROCESS_AGENT
-  if (sys_type == ARC_SYS_TYPE_ARCV2)
+  if (sys_type == ARC_SYS_TYPE_ARCV2_BMT)
     set_tdesc_architecture (tdesc, "arc:ARCv2");
+  else if (sys_type == ARC_SYS_TYPE_ARCV2_LNX)
+    /* If this is ARCv2 Linux, then it is ARC HS.  */
+    set_tdesc_architecture (tdesc, "arc:HS");
   else
     set_tdesc_architecture (tdesc, "arc:ARC700");
+
+  if (sys_type == ARC_SYS_TYPE_ARCOMPACT_LNX
+      || sys_type == ARC_SYS_TYPE_ARCV2_LNX)
+    set_tdesc_osabi (tdesc, "GNU/Linux");
 #endif
 
-  if (sys_type == ARC_SYS_TYPE_ARCV2)
-    {
-      regnum = create_feature_arc_core_v2 (tdesc, regnum);
-      regnum = create_feature_arc_aux_v2 (tdesc, regnum);
-    }
-  else
+  switch (sys_type)
     {
-      regnum = create_feature_arc_core_arcompact (tdesc, regnum);
-      regnum = create_feature_arc_aux_arcompact (tdesc, regnum);
+    case ARC_SYS_TYPE_ARCOMPACT_BMT:
+  regnum = create_feature_arc_core_arcompact (tdesc, regnum);
+  regnum = create_feature_arc_aux_arcompact (tdesc, regnum);
+  break;
+    case ARC_SYS_TYPE_ARCOMPACT_LNX:
+  regnum = create_feature_arc_core_arcompact_linux (tdesc, regnum);
+  regnum = create_feature_arc_aux_arcompact_linux (tdesc, regnum);
+  break;
+    case ARC_SYS_TYPE_ARCV2_BMT:
+  regnum = create_feature_arc_core_v2 (tdesc, regnum);
+  regnum = create_feature_arc_aux_v2 (tdesc, regnum);
+  break;
+    case ARC_SYS_TYPE_ARCV2_LNX:
+  regnum = create_feature_arc_core_v2_linux (tdesc, regnum);
+  regnum = create_feature_arc_aux_v2_linux (tdesc, regnum);
+  break;
+    default:
+  gdb_assert(!"Invalid arc_sys_type.");
     }
 
   return tdesc;
diff --git a/gdb/arch/arc.h b/gdb/arch/arc.h
index fd806ae7d34..3c19118b946 100644
--- a/gdb/arch/arc.h
+++ b/gdb/arch/arc.h
@@ -23,8 +23,10 @@
 /* Supported ARC system hardware types.  */
 enum arc_sys_type
 {
-  ARC_SYS_TYPE_ARCOMPACT = 0,  /* ARC600 or ARC700 */
-  ARC_SYS_TYPE_ARCV2,  /* ARC EM or ARC HS */
+  ARC_SYS_TYPE_ARCOMPACT_BMT = 0, /* ARC600 or ARC700 (baremetal) */
+  ARC_SYS_TYPE_ARCOMPACT_LNX,  /* ARC600 or ARC700 (linux) */
+  ARC_SYS_TYPE_ARCV2_BMT,  /* ARC EM or ARC HS (baremetal) */
+  ARC_SYS_TYPE_ARCV2_LNX,  /* ARC HS (linux) */
   ARC_SYS_TYPE_NUM
 };
 
@@ -33,10 +35,14 @@ arc_sys_type_to_str (const arc_sys_type type)
 {
   switch (type)
     {
-    case ARC_SYS_TYPE_ARCOMPACT:
-      return "ARC_SYS_TYPE_ARCOMPACT";
-    case ARC_SYS_TYPE_ARCV2:
-      return "ARC_SYS_TYPE_ARCV2";
+    case ARC_SYS_TYPE_ARCOMPACT_BMT:
+      return "ARC_SYS_TYPE_ARCOMPACT_BMT";
+    case ARC_SYS_TYPE_ARCOMPACT_LNX:
+      return "ARC_SYS_TYPE_ARCOMPACT_LNX";
+    case ARC_SYS_TYPE_ARCV2_BMT:
+      return "ARC_SYS_TYPE_ARCV2_BMT";
+    case ARC_SYS_TYPE_ARCV2_LNX:
+      return "ARC_SYS_TYPE_ARCV2_LNX";
     default:
       return "Invalid";
     }
diff --git a/gdb/features/Makefile b/gdb/features/Makefile
index cc65baa6eda..a95be667dc1 100644
--- a/gdb/features/Makefile
+++ b/gdb/features/Makefile
@@ -206,8 +206,12 @@ FEATURE_XMLFILES = aarch64-core.xml \
  aarch64-pauth.xml \
  arc/core-v2.xml \
  arc/aux-v2.xml \
+ arc/core-v2-linux.xml \
+ arc/aux-v2-linux.xml \
  arc/core-arcompact.xml \
  arc/aux-arcompact.xml \
+ arc/core-arcompact-linux.xml \
+ arc/aux-arcompact-linux.xml \
  arm/arm-core.xml \
  arm/arm-fpa.xml \
  arm/arm-m-profile.xml \
diff --git a/gdb/features/arc/aux-arcompact-linux.c b/gdb/features/arc/aux-arcompact-linux.c
new file mode 100644
index 00000000000..41f26c1e2ec
--- /dev/null
+++ b/gdb/features/arc/aux-arcompact-linux.c
@@ -0,0 +1,34 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: aux-arcompact-linux.xml */
+
+#include "gdbsupport/tdesc.h"
+
+static int
+create_feature_arc_aux_arcompact_linux (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.arc.aux-minimal");
+  tdesc_type_with_fields *type_with_fields;
+  type_with_fields = tdesc_create_flags (feature, "status32_type", 4);
+  tdesc_add_flag (type_with_fields, 0, "H");
+  tdesc_add_bitfield (type_with_fields, "E", 1, 2);
+  tdesc_add_bitfield (type_with_fields, "A", 3, 4);
+  tdesc_add_flag (type_with_fields, 5, "AE");
+  tdesc_add_flag (type_with_fields, 6, "DE");
+  tdesc_add_flag (type_with_fields, 7, "U");
+  tdesc_add_flag (type_with_fields, 8, "V");
+  tdesc_add_flag (type_with_fields, 9, "C");
+  tdesc_add_flag (type_with_fields, 10, "N");
+  tdesc_add_flag (type_with_fields, 11, "Z");
+  tdesc_add_flag (type_with_fields, 12, "L");
+  tdesc_add_flag (type_with_fields, 13, "R");
+  tdesc_add_flag (type_with_fields, 14, "SE");
+
+  tdesc_create_reg (feature, "pc", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "status32", regnum++, 1, NULL, 32, "status32_type");
+  tdesc_create_reg (feature, "lp_start", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "lp_end", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "bta", regnum++, 1, NULL, 32, "code_ptr");
+  return regnum;
+}
diff --git a/gdb/features/arc/aux-arcompact-linux.xml b/gdb/features/arc/aux-arcompact-linux.xml
new file mode 100644
index 00000000000..0d72373eda3
--- /dev/null
+++ b/gdb/features/arc/aux-arcompact-linux.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2020 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE target SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.arc.aux-minimal">
+  <flags id="status32_type" size="4">
+      <field name="H"   start="0" end="0"/>
+      <field name="E"   start="1" end="2"/>
+      <field name="A"   start="3" end="4"/>
+      <field name="AE"  start="5" end="5"/>
+      <field name="DE"  start="6" end="6"/>
+      <field name="U"   start="7" end="7"/>
+      <field name="V"   start="8" end="8"/>
+      <field name="C"   start="9" end="9"/>
+      <field name="N"   start="10" end="10"/>
+      <field name="Z"   start="11" end="11"/>
+      <field name="L"   start="12" end="12"/>
+      <field name="R"  start="13" end="13"/>
+      <field name="SE"  start="14" end="14"/>
+  </flags>
+
+  <reg name="pc"       bitsize="32" type="code_ptr"/>
+  <reg name="status32" bitsize="32" type="status32_type"/>
+  <reg name="lp_start" bitsize="32" type="code_ptr"/>
+  <reg name="lp_end"   bitsize="32" type="code_ptr"/>
+  <reg name="bta"      bitsize="32" type="code_ptr"/>
+</feature>
diff --git a/gdb/features/arc/aux-v2-linux.c b/gdb/features/arc/aux-v2-linux.c
new file mode 100644
index 00000000000..6e4d7c02efa
--- /dev/null
+++ b/gdb/features/arc/aux-v2-linux.c
@@ -0,0 +1,38 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: aux-v2-linux.xml */
+
+#include "gdbsupport/tdesc.h"
+
+static int
+create_feature_arc_aux_v2_linux (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.arc.aux-minimal");
+  tdesc_type_with_fields *type_with_fields;
+  type_with_fields = tdesc_create_flags (feature, "status32_type", 4);
+  tdesc_add_flag (type_with_fields, 0, "H");
+  tdesc_add_bitfield (type_with_fields, "E", 1, 4);
+  tdesc_add_flag (type_with_fields, 5, "AE");
+  tdesc_add_flag (type_with_fields, 6, "DE");
+  tdesc_add_flag (type_with_fields, 7, "U");
+  tdesc_add_flag (type_with_fields, 8, "V");
+  tdesc_add_flag (type_with_fields, 9, "C");
+  tdesc_add_flag (type_with_fields, 10, "N");
+  tdesc_add_flag (type_with_fields, 11, "Z");
+  tdesc_add_flag (type_with_fields, 12, "L");
+  tdesc_add_flag (type_with_fields, 13, "DZ");
+  tdesc_add_flag (type_with_fields, 14, "SC");
+  tdesc_add_flag (type_with_fields, 15, "ES");
+  tdesc_add_bitfield (type_with_fields, "RB", 16, 18);
+  tdesc_add_flag (type_with_fields, 19, "AD");
+  tdesc_add_flag (type_with_fields, 20, "US");
+  tdesc_add_flag (type_with_fields, 31, "IE");
+
+  tdesc_create_reg (feature, "pc", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "status32", regnum++, 1, NULL, 32, "status32_type");
+  tdesc_create_reg (feature, "lp_start", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "lp_end", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "bta", regnum++, 1, NULL, 32, "code_ptr");
+  return regnum;
+}
diff --git a/gdb/features/arc/aux-v2-linux.xml b/gdb/features/arc/aux-v2-linux.xml
new file mode 100644
index 00000000000..165ebb1d6d6
--- /dev/null
+++ b/gdb/features/arc/aux-v2-linux.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2020 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE target SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.arc.aux-minimal">
+  <flags id="status32_type" size="4">
+      <field name="H"   start="0" end="0"/>
+      <field name="E"   start="1" end="4"/>
+      <field name="AE"  start="5" end="5"/>
+      <field name="DE"  start="6" end="6"/>
+      <field name="U"   start="7" end="7"/>
+      <field name="V"   start="8" end="8"/>
+      <field name="C"   start="9" end="9"/>
+      <field name="N"   start="10" end="10"/>
+      <field name="Z"   start="11" end="11"/>
+      <field name="L"   start="12" end="12"/>
+      <field name="DZ"  start="13" end="13"/>
+      <field name="SC"  start="14" end="14"/>
+      <field name="ES"  start="15" end="15"/>
+      <field name="RB"  start="16" end="18"/>
+      <field name="AD"  start="19" end="19"/>
+      <field name="US"  start="20" end="20"/>
+      <field name="IE"  start="31" end="31"/>
+  </flags>
+
+  <reg name="pc"       bitsize="32" type="code_ptr"/>
+  <reg name="status32" bitsize="32" type="status32_type"/>
+  <reg name="lp_start" bitsize="32" type="code_ptr"/>
+  <reg name="lp_end"   bitsize="32" type="code_ptr"/>
+  <reg name="bta"      bitsize="32" type="code_ptr"/>
+</feature>
diff --git a/gdb/features/arc/core-arcompact-linux.c b/gdb/features/arc/core-arcompact-linux.c
new file mode 100644
index 00000000000..c870413e922
--- /dev/null
+++ b/gdb/features/arc/core-arcompact-linux.c
@@ -0,0 +1,45 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: core-arcompact-linux.xml */
+
+#include "gdbsupport/tdesc.h"
+
+static int
+create_feature_arc_core_arcompact_linux (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.arc.core.arcompact");
+  tdesc_create_reg (feature, "r0", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r1", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r2", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r3", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r4", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r5", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r6", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r7", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r8", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r9", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r10", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r11", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r12", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r13", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r14", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r15", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r16", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r17", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r18", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r19", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r20", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r21", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r22", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r23", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r24", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r25", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "gp", regnum++, 1, NULL, 32, "data_ptr");
+  tdesc_create_reg (feature, "fp", regnum++, 1, NULL, 32, "data_ptr");
+  tdesc_create_reg (feature, "sp", regnum++, 1, NULL, 32, "data_ptr");
+  tdesc_create_reg (feature, "blink", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "lp_count", regnum++, 1, NULL, 32, "uint32");
+  tdesc_create_reg (feature, "pcl", regnum++, 1, NULL, 32, "code_ptr");
+  return regnum;
+}
diff --git a/gdb/features/arc/core-arcompact-linux.xml b/gdb/features/arc/core-arcompact-linux.xml
new file mode 100644
index 00000000000..9b2865d32be
--- /dev/null
+++ b/gdb/features/arc/core-arcompact-linux.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2020 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE target SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.arc.core.arcompact">
+  <reg name="r0"  bitsize="32"/>
+  <reg name="r1"  bitsize="32"/>
+  <reg name="r2"  bitsize="32"/>
+  <reg name="r3"  bitsize="32"/>
+  <reg name="r4"  bitsize="32"/>
+  <reg name="r5"  bitsize="32"/>
+  <reg name="r6"  bitsize="32"/>
+  <reg name="r7"  bitsize="32"/>
+  <reg name="r8"  bitsize="32"/>
+  <reg name="r9"  bitsize="32"/>
+  <reg name="r10" bitsize="32"/>
+  <reg name="r11" bitsize="32"/>
+  <reg name="r12" bitsize="32"/>
+  <reg name="r13" bitsize="32"/>
+  <reg name="r14" bitsize="32"/>
+  <reg name="r15" bitsize="32"/>
+  <reg name="r16" bitsize="32"/>
+  <reg name="r17" bitsize="32"/>
+  <reg name="r18" bitsize="32"/>
+  <reg name="r19" bitsize="32"/>
+  <reg name="r20" bitsize="32"/>
+  <reg name="r21" bitsize="32"/>
+  <reg name="r22" bitsize="32"/>
+  <reg name="r23" bitsize="32"/>
+  <reg name="r24" bitsize="32"/>
+  <reg name="r25" bitsize="32"/>
+
+  <!-- ARC core data pointer registers.  -->
+  <reg name="gp"  bitsize="32" type="data_ptr"/>
+  <reg name="fp"  bitsize="32" type="data_ptr"/>
+  <reg name="sp"  bitsize="32" type="data_ptr"/>
+
+  <!-- Code pointers.  -->
+  <reg name="blink"  bitsize="32" type="code_ptr"/>
+
+  <!-- Here goes extension core registers: r32 - r59 -->
+
+  <!-- Loop counter.  -->
+  <reg name="lp_count" bitsize="32" type="uint32"/>
+
+  <!-- r61 is a reserved register address.  -->
+
+  <!-- r62 is a long immediate value, not a real register.  -->
+
+  <!-- 4-byte aligned read-only program counter.  -->
+  <reg name="pcl" bitsize="32" type="code_ptr" group=""/>
+</feature>
diff --git a/gdb/features/arc/core-v2-linux.c b/gdb/features/arc/core-v2-linux.c
new file mode 100644
index 00000000000..d3e563778ff
--- /dev/null
+++ b/gdb/features/arc/core-v2-linux.c
@@ -0,0 +1,48 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: core-v2-linux.xml */
+
+#include "gdbsupport/tdesc.h"
+
+static int
+create_feature_arc_core_v2_linux (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.arc.core.v2");
+  tdesc_create_reg (feature, "r0", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r1", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r2", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r3", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r4", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r5", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r6", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r7", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r8", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r9", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r10", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r11", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r12", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r13", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r14", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r15", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r16", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r17", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r18", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r19", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r20", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r21", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r22", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r23", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r24", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r25", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "gp", regnum++, 1, NULL, 32, "data_ptr");
+  tdesc_create_reg (feature, "fp", regnum++, 1, NULL, 32, "data_ptr");
+  tdesc_create_reg (feature, "sp", regnum++, 1, NULL, 32, "data_ptr");
+  tdesc_create_reg (feature, "r30", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "blink", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "r58", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r59", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "lp_count", regnum++, 1, NULL, 32, "uint32");
+  tdesc_create_reg (feature, "pcl", regnum++, 1, NULL, 32, "code_ptr");
+  return regnum;
+}
diff --git a/gdb/features/arc/core-v2-linux.xml b/gdb/features/arc/core-v2-linux.xml
new file mode 100644
index 00000000000..3ac4a86da56
--- /dev/null
+++ b/gdb/features/arc/core-v2-linux.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2020 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE target SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.arc.core.v2">
+  <reg name="r0"  bitsize="32"/>
+  <reg name="r1"  bitsize="32"/>
+  <reg name="r2"  bitsize="32"/>
+  <reg name="r3"  bitsize="32"/>
+  <reg name="r4"  bitsize="32"/>
+  <reg name="r5"  bitsize="32"/>
+  <reg name="r6"  bitsize="32"/>
+  <reg name="r7"  bitsize="32"/>
+  <reg name="r8"  bitsize="32"/>
+  <reg name="r9"  bitsize="32"/>
+  <reg name="r10" bitsize="32"/>
+  <reg name="r11" bitsize="32"/>
+  <reg name="r12" bitsize="32"/>
+  <reg name="r13" bitsize="32"/>
+  <reg name="r14" bitsize="32"/>
+  <reg name="r15" bitsize="32"/>
+  <reg name="r16" bitsize="32"/>
+  <reg name="r17" bitsize="32"/>
+  <reg name="r18" bitsize="32"/>
+  <reg name="r19" bitsize="32"/>
+  <reg name="r20" bitsize="32"/>
+  <reg name="r21" bitsize="32"/>
+  <reg name="r22" bitsize="32"/>
+  <reg name="r23" bitsize="32"/>
+  <reg name="r24" bitsize="32"/>
+  <reg name="r25" bitsize="32"/>
+
+  <!-- ARC core data pointer registers.  -->
+  <reg name="gp"  bitsize="32" type="data_ptr"/>
+  <reg name="fp"  bitsize="32" type="data_ptr"/>
+  <reg name="sp"  bitsize="32" type="data_ptr"/>
+
+  <reg name="r30"   bitsize="32" group=""/>
+  <reg name="blink" bitsize="32" type="code_ptr"/>
+
+  <!-- Here goes extension core registers: r32 - r57.  -->
+  <reg name="r58"   bitsize="32"/>
+  <reg name="r59"   bitsize="32"/>
+
+  <!-- Loop counter.  -->
+  <reg name="lp_count" bitsize="32" type="uint32"/>
+
+  <!-- r61 is a reserved register address.  -->
+
+  <!-- r62 is a long immediate value, not a real register.  -->
+
+  <!-- 4-byte aligned read-only program counter.  -->
+  <reg name="pcl" bitsize="32" type="code_ptr" group=""/>
+</feature>
--
2.26.0

Reply | Threaded
Open this post in threaded view
|

[PATCH 2/4] arc: Recognize registers available on Linux targets

Sourceware - gdb-patches mailing list
In reply to this post by Sourceware - gdb-patches mailing list
From: Anton Kolesov <[hidden email]>

For ARC there are registers that are not part of a required set in XML target
descriptions by default, but which are almost always present on ARC targets and
are universally exposed by the ptrace interface.  This patch adds those
registers to those recognized by GDB:

- R30 - core register available in user-space on ARC HS processors only (used
  to be a privileged only ILINK2 on ARC700).
- R58, R59 - accumulator register pair for a 64-multiplier and
  double-precision FPU - only on ARC HS.
- LP_START, LP_END - AUX registers, hardware loop start and end.  Formally
  optional, though it is hard to find ARC configuration that doesn't have
  them and is always present in processors that can run Linux.  GDB needs to
  know about those registers to implement proper software single stepping,
  since they affect what instruction will be next.
- BTA - AUX register that contains branch target address.  Value of this
  register makes sense only when execution halts at the delay slot
  instruction - in this case branch instruction is already committed,
  STATUS32.DE is set to 1 and BTA contains address of next PC.  GDB needs to
  understand this register to properly handle situations when breakpoint has
  been set in the delay slot (delay slot is stepped over when doing software
  single stepping).  Unfortunately, right now this doesn't work very well,
  because Linux doesn't allow modifications of STATUS32 via ptrace and Linux
  uses TRAP_S instruction to implement software breakpoints - this
  instruction commits when executed, therefore when TRAP_S is set in the
  delay slot and execution halts at it, PC is already advanced to BTA value
  and STATUS32.DE is reset.  BTA register will be more useful for debugger
  after support for SWI instruction will be added to ARC Linux - this
  breakpoint instruction doesn't commit, hence it doesn't change processor
  state.

gdb/ChangeLog:
2020-03-26  Anton Kolesov  <[hidden email]>

        * arc-tdep.c (core_v2_register_names): Fix names of R58 and R59.
        (aux_minimal_register_names): Add LP_START, LP_END and BTA.
        (arc_tdesc_init): Recognize those registers.
        * arc-tdep.h (arc_regnum): Add R58, R59, LP_START, LP_END and BTA.
        (gdbarch_tdep): New field has_hw_loops.

gdb/doc/ChangeLog:
2020-03-26  Anton Kolesov  <[hidden email]>

        * gdb.texinfo (Synopsys ARC): Document LP_START, LP_END and BTA.
---
 gdb/arc-tdep.c      | 77 +++++++++++++++++++++++++++++++++++----------
 gdb/arc-tdep.h      | 17 ++++++++--
 gdb/doc/gdb.texinfo |  3 +-
 3 files changed, 78 insertions(+), 19 deletions(-)

diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index a4f3f44b4fb..edcb8286b07 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -117,12 +117,12 @@ static const char *const core_v2_register_names[] = {
   "r44", "r45", "r46", "r47",
   "r48", "r49", "r50", "r51",
   "r52", "r53", "r54", "r55",
-  "r56", "r57", "accl", "acch",
-  "lp_count", "reserved", "limm", "pcl",
+  "r56", "r57", "r58", "r59",
+  "lp_count", "reserved", "limm", "pcl"
 };
 
 static const char *const aux_minimal_register_names[] = {
-  "pc", "status32",
+  "pc", "status32", "lp_start", "lp_end", "bta"
 };
 
 static const char *const core_arcompact_register_names[] = {
@@ -141,7 +141,7 @@ static const char *const core_arcompact_register_names[] = {
   "r48", "r49", "r50", "r51",
   "r52", "r53", "r54", "r55",
   "r56", "r57", "r58", "r59",
-  "lp_count", "reserved", "limm", "pcl",
+  "lp_count", "reserved", "limm", "pcl"
 };
 
 static char *arc_disassembler_options = NULL;
@@ -1724,7 +1724,7 @@ static const struct frame_base arc_normal_base = {
 
 static bool
 arc_tdesc_init (struct gdbarch_info info, const struct target_desc **tdesc,
- struct tdesc_arch_data **tdesc_data)
+ struct tdesc_arch_data **tdesc_data, struct gdbarch_tdep *tdep)
 {
   if (arc_debug)
     debug_printf ("arc: Target description initialization.\n");
@@ -1858,17 +1858,44 @@ arc_tdesc_init (struct gdbarch_info info, const struct target_desc **tdesc,
     || (i >= ARC_R16_REGNUM && i <= ARC_R25_REGNUM)))
  continue;
 
-      valid_p = tdesc_numbered_register (feature, tdesc_data_loc, i,
- core_regs[i]);
+      /* R58 and R59 can have special names: ACCL and ACCH, however which
+ one is which depends on target endianness - for little endian R58
+ is ACCL, R59 is ACCH; vice versa for big endian.  */
+
+      const char *const r58_names[] = {
+ core_regs[58],
+ (info.byte_order == BFD_ENDIAN_LITTLE ? "accl" : "acch"),
+ NULL
+      };
+      const char *const r59_names[] = {
+ core_regs[59],
+ (info.byte_order == BFD_ENDIAN_LITTLE ? "acch" : "accl"),
+ NULL
+      };
+
+      switch (i)
+ {
+ case ARC_R58_REGNUM:
+  valid_p = tdesc_numbered_register_choices (feature, tdesc_data_loc,
+     i, r58_names);
+  break;
+ case ARC_R59_REGNUM:
+  valid_p = tdesc_numbered_register_choices (feature, tdesc_data_loc,
+     i, r59_names);
+  break;
+ default:
+  valid_p = tdesc_numbered_register (feature, tdesc_data_loc, i,
+     core_regs[i]);
+ }
 
       /* - Ignore errors in extension registers - they are optional.
  - Ignore missing ILINK because it doesn't make sense for Linux.
- - Ignore missing ILINK2 when architecture is ARCompact, because it
- doesn't make sense for Linux targets.
+ - Ignore missing ILINK2 when architecture is ARCompact, because
+ it doesn't make sense for Linux targets.
 
- In theory those optional registers should be in separate features, but
- that would create numerous but tiny features, which looks like an
- overengineering of a rather simple task.  */
+ In theory those optional registers should be in separate
+ features, but that would create numerous but tiny features, which
+ looks like an overengineering of a rather simple task.  */
       if (!valid_p && (i <= ARC_SP_REGNUM || i == ARC_BLINK_REGNUM
        || i == ARC_LP_COUNT_REGNUM || i == ARC_PCL_REGNUM
        || (i == ARC_R30_REGNUM && is_arcv2)))
@@ -1895,7 +1922,9 @@ arc_tdesc_init (struct gdbarch_info info, const struct target_desc **tdesc,
     {
       const char *name = aux_minimal_register_names[i - ARC_FIRST_AUX_REGNUM];
       valid_p = tdesc_numbered_register (feature, tdesc_data_loc, i, name);
-      if (!valid_p)
+
+      /* Only STATUS32 and PC are mandatory.  */
+      if (!valid_p && (i == ARC_PC_REGNUM || i == ARC_STATUS32_REGNUM))
  {
   arc_print (_("Error: Cannot find required register `%s' "
        "in feature `%s'.\n"),
@@ -1903,6 +1932,11 @@ arc_tdesc_init (struct gdbarch_info info, const struct target_desc **tdesc,
   tdesc_data_cleanup (tdesc_data_loc);
   return false;
  }
+      /* Hardware loops present if both its registers are.  */
+      else if (ARC_LP_START_REGNUM == i)
+ tdep->has_hw_loops = valid_p;
+      else if (ARC_LP_END_REGNUM == i)
+ tdep->has_hw_loops &= valid_p;
     }
 
   *tdesc = tdesc_loc;
@@ -1950,13 +1984,17 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   if (arc_debug)
     debug_printf ("arc: Architecture initialization.\n");
 
-  if (!arc_tdesc_init (info, &tdesc, &tdesc_data))
-    return NULL;
-
   /* Allocate the ARC-private target-dependent information structure, and the
      GDB target-independent information structure.  */
   struct gdbarch_tdep *tdep = XCNEW (struct gdbarch_tdep);
   tdep->jb_pc = -1; /* No longjmp support by default.  */
+
+  if (!arc_tdesc_init (info, &tdesc, &tdesc_data, tdep))
+    {
+      XDELETE (tdep);
+      return NULL;
+    }
+
   struct gdbarch *gdbarch = gdbarch_alloc (&info, tdep);
 
   /* Data types.  */
@@ -1987,6 +2025,13 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_ps_regnum (gdbarch, ARC_STATUS32_REGNUM);
   set_gdbarch_fp0_regnum (gdbarch, -1); /* No FPU registers.  */
 
+  /* Confirm that register name lists have proper length.  */
+  gdb_static_assert (ARC_LAST_REGNUM + 1
+     == (ARRAY_SIZE (core_v2_register_names)
+ + ARRAY_SIZE (aux_minimal_register_names)));
+  gdb_static_assert (ARRAY_SIZE (core_v2_register_names)
+     == ARRAY_SIZE (core_arcompact_register_names));
+
   set_gdbarch_push_dummy_call (gdbarch, arc_push_dummy_call);
   set_gdbarch_push_dummy_code (gdbarch, arc_push_dummy_code);
 
diff --git a/gdb/arc-tdep.h b/gdb/arc-tdep.h
index d72332c7638..8fd8571457f 100644
--- a/gdb/arc-tdep.h
+++ b/gdb/arc-tdep.h
@@ -23,6 +23,7 @@
 
 /* Need disassemble_info.  */
 #include "dis-asm.h"
+#include "gdbarch.h"
 #include "arch/arc.h"
 
 /* To simplify GDB code this enum assumes that internal regnums should be same
@@ -54,6 +55,8 @@ enum arc_regnum
     ARC_R30_REGNUM,
     /* Return address from function.  */
     ARC_BLINK_REGNUM,
+    ARC_R58_REGNUM = 58,
+    ARC_R59_REGNUM,
     /* Zero-delay loop counter.  */
     ARC_LP_COUNT_REGNUM = 60,
     /* Reserved register number.  There should never be a register with such
@@ -69,14 +72,21 @@ enum arc_regnum
     /* Program counter, aligned to 4-bytes, read-only.  */
     ARC_PCL_REGNUM,
     ARC_LAST_CORE_REGNUM = ARC_PCL_REGNUM,
+
     /* AUX registers.  */
     /* Actual program counter.  */
     ARC_PC_REGNUM,
     ARC_FIRST_AUX_REGNUM = ARC_PC_REGNUM,
     /* Status register.  */
     ARC_STATUS32_REGNUM,
-    ARC_LAST_REGNUM = ARC_STATUS32_REGNUM,
-    ARC_LAST_AUX_REGNUM = ARC_STATUS32_REGNUM,
+    /* Zero-delay loop start instruction.  */
+    ARC_LP_START_REGNUM,
+    /* Zero-delay loop next-after-last instruction.  */
+    ARC_LP_END_REGNUM,
+    /* Branch target address.  */
+    ARC_BTA_REGNUM,
+    ARC_LAST_AUX_REGNUM = ARC_BTA_REGNUM,
+    ARC_LAST_REGNUM = ARC_LAST_AUX_REGNUM,
 
     /* Additional ABI constants.  */
     ARC_FIRST_ARG_REGNUM = ARC_R0_REGNUM,
@@ -101,6 +111,9 @@ struct gdbarch_tdep
   /* Offset to PC value in jump buffer.  If this is negative, longjmp
      support will be disabled.  */
   int jb_pc;
+
+  /* Whether target has hardware (aka zero-delay) loops.  */
+  bool has_hw_loops;
 };
 
 /* Utility functions used by other ARC-specific modules.  */
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 385c832f222..1671d44c6c8 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -45115,7 +45115,8 @@ difference with @samp{org.gnu.gdb.arc.core.v2} feature is in the names of
 ARC v2, but @samp{ilink2} is optional on ARCompact.
 
 The @samp{org.gnu.gdb.arc.aux-minimal} feature is required for all ARC
-targets.  It should contain registers @samp{pc} and @samp{status32}.
+targets.  It should contain registers @samp{pc} and @samp{status32}.  It may
+contain registers @samp{lp_start}, @samp{lp_end} and @samp{bta}.
 
 @node ARM Features
 @subsection ARM Features
--
2.26.0

Reply | Threaded
Open this post in threaded view
|

[PATCH 3/4] arc: Add GNU/Linux support for ARC

Sourceware - gdb-patches mailing list
In reply to this post by Sourceware - gdb-patches mailing list
From: Anton Kolesov <[hidden email]>

ARC Linux targets differences from baremetal:

- No support for hardware single instruction stepping.
- Different access rules to registers.
- Use of another instruction for breakpoints.

2020-03-26  Anton Kolesov  <[hidden email]>

        * configure.tgt: ARC support for GNU/Linux.
        * Makefile.in (ALL_TARGET_OBJS): Likewise.
        * arc-linux-tdep.c: New file.
        * arc-tdep.h (ARC_STATUS32_L_MASK, ARC_STATUS32_DE_MASK): Declare.
        * arc-tdep.c (arc_write_pc): Use it.
---
 gdb/Makefile.in      |   1 +
 gdb/arc-linux-tdep.c | 284 +++++++++++++++++++++++++++++++++++++++++++
 gdb/arc-tdep.c       |   3 +-
 gdb/arc-tdep.h       |   5 +
 gdb/configure.tgt    |   6 +
 5 files changed, 297 insertions(+), 2 deletions(-)
 create mode 100644 gdb/arc-linux-tdep.c

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 0c331af4bff..028992ab664 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -695,6 +695,7 @@ ALL_64_TARGET_OBS = \
 # All other target-dependent objects files (used with --enable-targets=all).
 ALL_TARGET_OBS = \
  aarch32-tdep.o \
+ arc-linux-tdep.o \
  arc-tdep.o \
  arch/aarch32.o \
  arch/arc.o \
diff --git a/gdb/arc-linux-tdep.c b/gdb/arc-linux-tdep.c
new file mode 100644
index 00000000000..ebb5d622988
--- /dev/null
+++ b/gdb/arc-linux-tdep.c
@@ -0,0 +1,284 @@
+/* Target dependent code for GNU/Linux ARC.
+
+   Copyright 2020 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* GDB header files.  */
+#include "defs.h"
+#include "linux-tdep.h"
+#include "objfiles.h"
+#include "opcode/arc.h"
+#include "osabi.h"
+#include "solib-svr4.h"
+
+/* ARC header files.  */
+#include "opcodes/arc-dis.h"
+#include "arc-tdep.h"
+
+/* Implement the "cannot_fetch_register" gdbarch method.  */
+
+static int
+arc_linux_cannot_fetch_register (struct gdbarch *gdbarch, int regnum)
+{
+  /* Assume that register is readable if it is unknown.  */
+  switch (regnum)
+    {
+    case ARC_ILINK_REGNUM:
+    case ARC_RESERVED_REGNUM:
+    case ARC_LIMM_REGNUM:
+      return TRUE;
+    case ARC_R30_REGNUM:
+    case ARC_R58_REGNUM:
+    case ARC_R59_REGNUM:
+      return !arc_mach_is_arcv2 (gdbarch);
+    }
+  if (regnum > ARC_BLINK_REGNUM && regnum < ARC_LP_COUNT_REGNUM)
+    return TRUE;
+  return FALSE;
+}
+
+/* Implement the "cannot_store_register" gdbarch method.  */
+
+static int
+arc_linux_cannot_store_register (struct gdbarch *gdbarch, int regnum)
+{
+  /* Assume that register is writable if it is unknown.  */
+  switch (regnum)
+    {
+    case ARC_ILINK_REGNUM:
+    case ARC_RESERVED_REGNUM:
+    case ARC_LIMM_REGNUM:
+    case ARC_PCL_REGNUM:
+      return TRUE;
+    case ARC_R30_REGNUM:
+    case ARC_R58_REGNUM:
+    case ARC_R59_REGNUM:
+      return !arc_mach_is_arcv2 (gdbarch);
+    }
+  if (regnum > ARC_BLINK_REGNUM && regnum < ARC_LP_COUNT_REGNUM)
+    return TRUE;
+  return FALSE;
+}
+
+/* For ARC Linux, breakpoint uses the 16-bit TRAP_S 1 instruction, which
+   is 0x3e78 (little endian) or 0x783e (big endian).  */
+
+static const gdb_byte arc_linux_trap_s_be[] = { 0x78, 0x3e };
+static const gdb_byte arc_linux_trap_s_le[] = { 0x3e, 0x78 };
+
+/* Implement the "breakpoint_kind_from_pc" gdbarch method.  */
+
+static int
+arc_linux_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  return 2;
+}
+
+/* Implement the "sw_breakpoint_from_kind" gdbarch method.  */
+
+static const gdb_byte *
+arc_linux_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
+{
+
+  *size = kind;
+  return ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
+  ? arc_linux_trap_s_be
+  : arc_linux_trap_s_le);
+}
+
+/* Implement the "software_single_step" gdbarch method.  */
+
+static std::vector<CORE_ADDR>
+arc_linux_software_single_step (struct regcache *regcache)
+{
+  struct gdbarch *gdbarch = regcache->arch ();
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  struct disassemble_info di = arc_disassemble_info (gdbarch);
+
+  /* Read current instruction.  */
+  struct arc_instruction curr_insn;
+  arc_insn_decode (regcache_read_pc (regcache), &di, arc_delayed_print_insn,
+   &curr_insn);
+  CORE_ADDR next_pc = arc_insn_get_linear_next_pc (curr_insn);
+
+  std::vector<CORE_ADDR> next_pcs;
+
+  /* For instructions with delay slots, the fall thru is not the
+     instruction immediately after the current instruction, but the one
+     after that.  */
+  if (curr_insn.has_delay_slot)
+    {
+      struct arc_instruction next_insn;
+      arc_insn_decode (next_pc, &di, arc_delayed_print_insn, &next_insn);
+      next_pcs.push_back (arc_insn_get_linear_next_pc (next_insn));
+    }
+  else
+    {
+      next_pcs.push_back (next_pc);
+    }
+
+  ULONGEST status32;
+  regcache_cooked_read_unsigned (regcache, gdbarch_ps_regnum (gdbarch),
+ &status32);
+
+  if (curr_insn.is_control_flow)
+    {
+      CORE_ADDR branch_pc = arc_insn_get_branch_target (curr_insn);
+      if (branch_pc != next_pc)
+ next_pcs.push_back (branch_pc);
+    }
+  /* Is current instruction the last in a loop body?  */
+  else if (tdep->has_hw_loops)
+    {
+      /* If STATUS32.L is 1, then ZD-loops are disabled.  */
+      if (!(status32 & ARC_STATUS32_L_MASK))
+ {
+  ULONGEST lp_end, lp_start, lp_count;
+  regcache_cooked_read_unsigned (regcache, ARC_LP_START_REGNUM,
+ &lp_start);
+  regcache_cooked_read_unsigned (regcache, ARC_LP_END_REGNUM, &lp_end);
+  regcache_cooked_read_unsigned (regcache, ARC_LP_COUNT_REGNUM,
+ &lp_count);
+
+  if (arc_debug)
+    {
+      debug_printf ("arc-linux: lp_start = %s, lp_end = %s, "
+    "lp_count = %s, next_pc = %s\n",
+    paddress (gdbarch, lp_start),
+    paddress (gdbarch, lp_end),
+    pulongest (lp_count),
+    paddress (gdbarch, next_pc));
+    }
+
+  if (next_pc == lp_end && lp_count > 1)
+    {
+      /* The instruction is in effect a jump back to the start of
+ the loop.  */
+      next_pcs.push_back (lp_start);
+    }
+
+ }
+    }
+
+  /* Is this a delay slot?  Then next PC is in BTA register.  */
+  if (status32 & ARC_STATUS32_DE_MASK)
+    {
+      ULONGEST bta;
+      regcache_cooked_read_unsigned (regcache, ARC_BTA_REGNUM, &bta);
+      next_pcs.push_back (bta);
+    }
+
+  return next_pcs;
+}
+
+/* Implement the "skip_solib_resolver" gdbarch method.
+
+   See glibc_skip_solib_resolver for details.  */
+
+static CORE_ADDR
+arc_linux_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
+{
+  /* For uClibc 0.9.26+.
+
+     An unresolved PLT entry points to "__dl_linux_resolve", which calls
+     "_dl_linux_resolver" to do the resolving and then eventually jumps to
+     the function.
+
+     So we look for the symbol `_dl_linux_resolver', and if we are there,
+     gdb sets a breakpoint at the return address, and continues.  */
+  struct bound_minimal_symbol resolver =
+    lookup_minimal_symbol ("_dl_linux_resolver", NULL, NULL);
+
+  if (arc_debug)
+    {
+      if (resolver.minsym)
+ {
+  CORE_ADDR res_addr = BMSYMBOL_VALUE_ADDRESS (resolver);
+  debug_printf ("arc-linux: skip_solib_resolver (): "
+ "pc = %s, resolver at %s\n",
+ print_core_address (gdbarch, pc),
+ print_core_address (gdbarch, res_addr));
+ }
+      else
+ {
+  debug_printf ("arc-linux: skip_solib_resolver (): "
+ "pc = %s, no resolver found\n",
+ print_core_address (gdbarch, pc));
+ }
+    }
+
+  if (resolver.minsym && BMSYMBOL_VALUE_ADDRESS (resolver) == pc)
+    {
+      /* Find the return address.  */
+      return frame_unwind_caller_pc (get_current_frame ());
+    }
+  else
+    {
+      /* No breakpoint required.  */
+      return 0;
+    }
+}
+
+/* Initialization specific to Linux environment.  */
+
+static void
+arc_linux_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  if (arc_debug)
+    debug_printf ("arc-linux: GNU/Linux OS/ABI initialization.\n");
+
+  /* If we are using Linux, we have in uClibc
+     (libc/sysdeps/linux/arc/bits/setjmp.h):
+
+     typedef int __jmp_buf[13+1+1+1];    //r13-r25, fp, sp, blink
+
+     Where "blink" is a stored PC of a caller function.
+   */
+  tdep->jb_pc = 15;
+
+  linux_init_abi (info, gdbarch);
+
+  /* Set up target dependent GDB architecture entries.  */
+  set_gdbarch_cannot_fetch_register (gdbarch, arc_linux_cannot_fetch_register);
+  set_gdbarch_cannot_store_register (gdbarch, arc_linux_cannot_store_register);
+  set_gdbarch_breakpoint_kind_from_pc (gdbarch,
+       arc_linux_breakpoint_kind_from_pc);
+  set_gdbarch_sw_breakpoint_from_kind (gdbarch,
+       arc_linux_sw_breakpoint_from_kind);
+  set_gdbarch_fetch_tls_load_module_address (gdbarch,
+     svr4_fetch_objfile_link_map);
+  set_gdbarch_software_single_step (gdbarch, arc_linux_software_single_step);
+  set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
+  set_gdbarch_skip_solib_resolver (gdbarch, arc_linux_skip_solib_resolver);
+
+  /* GNU/Linux uses SVR4-style shared libraries, with 32-bit ints, longs
+     and pointers (ILP32).  */
+  set_solib_svr4_fetch_link_map_offsets (gdbarch,
+ svr4_ilp32_fetch_link_map_offsets);
+}
+
+/* Suppress warning from -Wmissing-prototypes.  */
+extern initialize_file_ftype _initialize_arc_linux_tdep;
+
+void
+_initialize_arc_linux_tdep (void)
+{
+  gdbarch_register_osabi (bfd_arch_arc, 0, GDB_OSABI_LINUX,
+  arc_linux_init_osabi);
+}
diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index edcb8286b07..2ef3738ef5d 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -462,8 +462,7 @@ arc_write_pc (struct regcache *regcache, CORE_ADDR new_pc)
   regcache_cooked_read_unsigned (regcache, gdbarch_ps_regnum (gdbarch),
  &status32);
 
-  /* Mask for DE bit is 0x40.  */
-  if (status32 & 0x40)
+  if (status32 & ARC_STATUS32_DE_MASK)
     {
       if (arc_debug)
  {
diff --git a/gdb/arc-tdep.h b/gdb/arc-tdep.h
index 8fd8571457f..015ef3d4953 100644
--- a/gdb/arc-tdep.h
+++ b/gdb/arc-tdep.h
@@ -100,6 +100,11 @@ enum arc_regnum
    Longer registers are represented as pairs of 32-bit registers.  */
 #define ARC_REGISTER_SIZE  4
 
+/* STATUS32 register: hardware loops disabled bit.  */
+#define ARC_STATUS32_L_MASK (1 << 12)
+/* STATUS32 register: current instruction is a delay slot.  */
+#define ARC_STATUS32_DE_MASK (1 << 6)
+
 #define arc_print(fmt, args...) fprintf_unfiltered (gdb_stdlog, fmt, ##args)
 
 extern int arc_debug;
diff --git a/gdb/configure.tgt b/gdb/configure.tgt
index b3f31af763c..5c607320055 100644
--- a/gdb/configure.tgt
+++ b/gdb/configure.tgt
@@ -157,6 +157,12 @@ arc*-*-elf32)
  gdb_target_obs="arc-newlib-tdep.o"
  ;;
 
+arc*-*-linux*)
+ # Target: ARC machine running Linux
+ gdb_target_obs="arc-linux-tdep.o linux-tdep.o solib-svr4.o"
+ build_gdbserver=yes
+ ;;
+
 arm*-wince-pe | arm*-*-mingw32ce*)
  # Target: ARM based machine running Windows CE (win32)
  gdb_target_obs="arm-wince-tdep.o windows-tdep.o"
--
2.26.0

Reply | Threaded
Open this post in threaded view
|

[PATCH 4/4] arc: Add arc-*-linux regformats

Sourceware - gdb-patches mailing list
In reply to this post by Sourceware - gdb-patches mailing list
From: Anton Kolesov <[hidden email]>

gdb/ChangeLog:
2020-03-26  Anton Kolesov <[hidden email]>

        * features/Makefile: Add new files and expedite registers.
        * regformats/arc-arcompact-Linux.dat: New file.
        * regformats/arc-v2-Linux.dat: Likewise.
---
 gdb/features/Makefile                  |  4 ++-
 gdb/regformats/arc-arcompact-linux.dat | 42 ++++++++++++++++++++++++
 gdb/regformats/arc-v2-linux.dat        | 45 ++++++++++++++++++++++++++
 3 files changed, 90 insertions(+), 1 deletion(-)
 create mode 100644 gdb/regformats/arc-arcompact-linux.dat
 create mode 100644 gdb/regformats/arc-v2-linux.dat

diff --git a/gdb/features/Makefile b/gdb/features/Makefile
index a95be667dc1..312c4f53185 100644
--- a/gdb/features/Makefile
+++ b/gdb/features/Makefile
@@ -44,7 +44,8 @@
 #   make GDB=/path/to/gdb XMLTOC="xml files" FEATURE_XMLFILES="xml files" cfiles
 
 # List of .dat files to create in ../regformats/
-WHICH = arm/arm-with-iwmmxt arm/arm-with-vfpv2 arm/arm-with-vfpv3 \
+WHICH = arc-v2-linux arc-arcompact-linux \
+ arm/arm-with-iwmmxt arm/arm-with-vfpv2 arm/arm-with-vfpv3 \
  arm/arm-with-neon \
  mips-linux mips-dsp-linux \
  microblaze-with-stack-protect \
@@ -72,6 +73,7 @@ WHICH = arm/arm-with-iwmmxt arm/arm-with-vfpv2 arm/arm-with-vfpv3 \
 
 # Record which registers should be sent to GDB by default after stop.
 aarch64-expedite = x29,sp,pc
+arc-expedite = sp,pc
 arm-expedite = r11,sp,pc
 i386-expedite = ebp,esp,eip
 amd64-expedite = rbp,rsp,rip
diff --git a/gdb/regformats/arc-arcompact-linux.dat b/gdb/regformats/arc-arcompact-linux.dat
new file mode 100644
index 00000000000..1d35860af3d
--- /dev/null
+++ b/gdb/regformats/arc-arcompact-linux.dat
@@ -0,0 +1,42 @@
+# THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi :set ro:
+# Generated from: arc-arcompact-linux.xml
+name:arc_arcompact_linux
+xmltarget:arc-arcompact-linux.xml
+expedite:sp,pc
+32:r0
+32:r1
+32:r2
+32:r3
+32:r4
+32:r5
+32:r6
+32:r7
+32:r8
+32:r9
+32:r10
+32:r11
+32:r12
+32:r13
+32:r14
+32:r15
+32:r16
+32:r17
+32:r18
+32:r19
+32:r20
+32:r21
+32:r22
+32:r23
+32:r24
+32:r25
+32:gp
+32:fp
+32:sp
+32:blink
+32:lp_count
+32:pcl
+32:pc
+32:status32
+32:lp_start
+32:lp_end
+32:bta
diff --git a/gdb/regformats/arc-v2-linux.dat b/gdb/regformats/arc-v2-linux.dat
new file mode 100644
index 00000000000..7e5d1904664
--- /dev/null
+++ b/gdb/regformats/arc-v2-linux.dat
@@ -0,0 +1,45 @@
+# THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi :set ro:
+# Generated from: arc-v2-linux.xml
+name:arc_v2_linux
+xmltarget:arc-v2-linux.xml
+expedite:sp,pc
+32:r0
+32:r1
+32:r2
+32:r3
+32:r4
+32:r5
+32:r6
+32:r7
+32:r8
+32:r9
+32:r10
+32:r11
+32:r12
+32:r13
+32:r14
+32:r15
+32:r16
+32:r17
+32:r18
+32:r19
+32:r20
+32:r21
+32:r22
+32:r23
+32:r24
+32:r25
+32:gp
+32:fp
+32:sp
+32:r30
+32:blink
+32:r58
+32:r59
+32:lp_count
+32:pcl
+32:pc
+32:status32
+32:lp_start
+32:lp_end
+32:bta
--
2.26.0

Reply | Threaded
Open this post in threaded view
|

[PING][PATCH 0/4] arc: Add GNU/Linux support

Sourceware - gdb-patches mailing list
In reply to this post by Sourceware - gdb-patches mailing list
A friendly reminder for the patch series in:

https://sourceware.org/pipermail/gdb-patches/2020-March/167022.html

I appreciate taking the time to review it.


Cheers,
Shahab
Reply | Threaded
Open this post in threaded view
|

[PING^2][PATCH 0/4] arc: Add GNU/Linux support

Sourceware - gdb-patches mailing list
In reply to this post by Sourceware - gdb-patches mailing list
Second ping:
---
A friendly reminder for the patch series in:

https://sourceware.org/pipermail/gdb-patches/2020-March/167022.html

I appreciate taking the time to review it.


Cheers,
Shahab
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/4] arc: Add XML target features for Linux targets

Tom Tromey-2
In reply to this post by Sourceware - gdb-patches mailing list
>>>>> ">" == Shahab Vahedi via Gdb-patches <[hidden email]> writes:

>> From: Anton Kolesov <[hidden email]>
>> Add XML target features for Linux targets.  Compared to default
>> Linux features:

>> - Explicitly specify CPU machine.
>> - Remove baremetal only ILINK{,1,2} registers.
>> - Add LP_START and LP_END registers for hardware loops - required to
>>   properly evaluate possible next instruction during software single
>>   instruction stepping.
>> - Add BTA register which contains branch target address - address of
>>   next instruction when processor is in the delay slot.
>> - ARC HS description also adds R30, R58 and R59 registers, specific to
>>   this architecture.

>> gdb/ChangeLog:
>> 2020-03-26  Anton Kolesov  <[hidden email]>

>> * arch/arc.h (arc_create_target_description): Support Linux targets.
>> * arch/arc.c (arc_create_target_description): Likewise.
>> * arc-tdep.c (arc_tdesc_init): Update invocation of
>>  arc_read_description.
>> * features/Makefile (FEATURE_XMLFILES): Add new files.
>> * features/arc/aux-arcompact-linux.xml: New file.
>> * features/arc/aux-v2-linux.xml: Likewise.
>> * features/arc/core-arcompact-linux.xml: Likewise.
>> * features/arc/core-v2-linux.xml: Likewise.
>> * features/arc/aux-arcompact-linux.c: Generate.
>> * features/arc/aux-v2-linux.c: Likewise.
>> * features/arc/core-arcompact-linux.c: Likewise.
>> * features/arc/core-v2-linux.c: Likewise.

Thanks, and sorry about the delay.  This is ok.

Tom
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/4] arc: Recognize registers available on Linux targets

Tom Tromey-2
In reply to this post by Sourceware - gdb-patches mailing list
>>>>> ">" == Shahab Vahedi via Gdb-patches <[hidden email]> writes:

>> +      const char *const r58_names[] = {
>> + core_regs[58],

This should probably say ARC_R58_REGNUM?

>> + core_regs[59],

ARC_R59_REGNUM ?

>>    /* Allocate the ARC-private target-dependent information structure, and the
>>       GDB target-independent information structure.  */
>>    struct gdbarch_tdep *tdep = XCNEW (struct gdbarch_tdep);
>> tdep-> jb_pc = -1; /* No longjmp support by default.  */
>> +
>> +  if (!arc_tdesc_init (info, &tdesc, &tdesc_data, tdep))
>> +    {
>> +      XDELETE (tdep);
>> +      return NULL;
>> +    }

gdb doesn't use XDELETE, but rather "xfree".
You might as well "return nullptr;" while you're at it.

thanks,
Tom
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 3/4] arc: Add GNU/Linux support for ARC

Tom Tromey-2
In reply to this post by Sourceware - gdb-patches mailing list
>>>>> ">" == Shahab Vahedi via Gdb-patches <[hidden email]> writes:

Thank you for the patch.
I have a few nits to pick, but no serious issues.

>> +static int
>> +arc_linux_cannot_fetch_register (struct gdbarch *gdbarch, int regnum)
>> +{
>> +  /* Assume that register is readable if it is unknown.  */
>> +  switch (regnum)
>> +    {
>> +    case ARC_ILINK_REGNUM:
>> +    case ARC_RESERVED_REGNUM:
>> +    case ARC_LIMM_REGNUM:
>> +      return TRUE;

gdb doesn't generally use the TRUE / FALSE defines -- there are
exceptions, mostly for curses code, but on the whole these should be
avoided.  You can either use 1 / 0, or true / false.

These functions only return int nowadays because C++-ification is
incomplete and nobody has gone back to fix up gdbarch to use bool
here, so I guess I'd opt for true / false.

>> +/* Implement the "sw_breakpoint_from_kind" gdbarch method.  */
>> +
>> +static const gdb_byte *
>> +arc_linux_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)

This line is too long.

>> +{
>> +
>> +  *size = kind;
>> +  return ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)

Spurious blank line at the start of this function.

>> +  /* Is this a delay slot?  Then next PC is in BTA register.  */
>> +  if (status32 & ARC_STATUS32_DE_MASK)

Normally in gdb this kind of expression is written out more fully, like:

    if ((status32 & ARC_STATUS32_DE_MASK) != 0)

I thought GCC had a warning that prevented the form in the patch?
Maybe I'm confusing it with something else.

>> -  /* Mask for DE bit is 0x40.  */
>> -  if (status32 & 0x40)
>> +  if (status32 & ARC_STATUS32_DE_MASK)

As long as you're touching this, you might as well change it to the
"!= 0" form.

>> +arc*-*-linux*)
>> + # Target: ARC machine running Linux
>> + gdb_target_obs="arc-linux-tdep.o linux-tdep.o solib-svr4.o"
>> + build_gdbserver=yes

build_gdbserver is no longer needed in this file.  Since gdbserver was
moved to the top level, Whether or not gdbserver is built is now decided
entirely by gdbserver/configure.srv.

Tom
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 4/4] arc: Add arc-*-linux regformats

Tom Tromey-2
In reply to this post by Sourceware - gdb-patches mailing list
>>>>> ">" == Shahab Vahedi via Gdb-patches <[hidden email]> writes:

>> From: Anton Kolesov <[hidden email]>
>> gdb/ChangeLog:
>> 2020-03-26  Anton Kolesov <[hidden email]>

>> * features/Makefile: Add new files and expedite registers.
>> * regformats/arc-arcompact-Linux.dat: New file.
>> * regformats/arc-v2-Linux.dat: Likewise.

This is ok.  Thank you.

Tom
Reply | Threaded
Open this post in threaded view
|

[PATCH v2 0/4] arc: Add GNU/Linux support

Sourceware - gdb-patches mailing list
In reply to this post by Sourceware - gdb-patches mailing list
From: Shahab Vahedi <[hidden email]>

This is a series of changes to enable debugging ARC targets that are
running on a native ARC GNU/Linux system.  Most of these changes are
related to how registers are slightly handled differently compared
to a baremetal scenario.  Each commit illustrate further on those.

After this series, there will come patches that add support for
native ARC gdb/gdbserver.

v2: Changes after Tom's remarks:
 arc-tdep.c
  - arc_tdesc_init(): Use "ARC_{R58,R59}_REGNUM" to index "core_regs[]".
  - arc_gdbarch_init(): Use "xfree ()" instead of "XDELETE ()"
  - arc_gdbarch_init(): return "nullptr" instead of "NULL".
  - Use explicit number evaluation, e.g: if (a & b) -> if ((a & b) != 0)
 arc-linux-tdep.c
  - Use true/false instead of TRUE/FALSE.
  - arc_linux_sw_breakpoint_from_kind (): Break long lines into two.
  - arc_linux_sw_breakpoint_from_kind (): Remove starting blank line.
  - Use explicit number evaluation, e.g: if (a & b) -> if ((a & b) != 0)
 gdb/configure.tgt
  - arc*-*-linux*): Remove "build_gdbserver=yes".

Anton Kolesov (4):
  arc: Add XML target features for Linux targets
  arc: Recognize registers available on Linux targets
  arc: Add GNU/Linux support for ARC
  arc: Add arc-*-linux regformats

 gdb/Makefile.in                           |   1 +
 gdb/arc-linux-tdep.c                      | 284 ++++++++++++++++++++++
 gdb/arc-tdep.c                            |  84 +++++--
 gdb/arc-tdep.h                            |  22 +-
 gdb/arch/arc.c                            |  40 ++-
 gdb/arch/arc.h                            |  18 +-
 gdb/configure.tgt                         |   5 +
 gdb/doc/gdb.texinfo                       |   3 +-
 gdb/features/Makefile                     |   8 +-
 gdb/features/arc/aux-arcompact-linux.c    |  34 +++
 gdb/features/arc/aux-arcompact-linux.xml  |  31 +++
 gdb/features/arc/aux-v2-linux.c           |  38 +++
 gdb/features/arc/aux-v2-linux.xml         |  35 +++
 gdb/features/arc/core-arcompact-linux.c   |  45 ++++
 gdb/features/arc/core-arcompact-linux.xml |  56 +++++
 gdb/features/arc/core-v2-linux.c          |  48 ++++
 gdb/features/arc/core-v2-linux.xml        |  58 +++++
 gdb/regformats/arc-arcompact-linux.dat    |  42 ++++
 gdb/regformats/arc-v2-linux.dat           |  45 ++++
 19 files changed, 858 insertions(+), 39 deletions(-)
 create mode 100644 gdb/arc-linux-tdep.c
 create mode 100644 gdb/features/arc/aux-arcompact-linux.c
 create mode 100644 gdb/features/arc/aux-arcompact-linux.xml
 create mode 100644 gdb/features/arc/aux-v2-linux.c
 create mode 100644 gdb/features/arc/aux-v2-linux.xml
 create mode 100644 gdb/features/arc/core-arcompact-linux.c
 create mode 100644 gdb/features/arc/core-arcompact-linux.xml
 create mode 100644 gdb/features/arc/core-v2-linux.c
 create mode 100644 gdb/features/arc/core-v2-linux.xml
 create mode 100644 gdb/regformats/arc-arcompact-linux.dat
 create mode 100644 gdb/regformats/arc-v2-linux.dat

--
2.26.2

Reply | Threaded
Open this post in threaded view
|

[PATCH v2 1/4] arc: Add XML target features for Linux targets

Sourceware - gdb-patches mailing list
From: Anton Kolesov <[hidden email]>

Add XML target features for Linux targets.  Compared to default
Linux features:

- Explicitly specify CPU machine.
- Remove baremetal only ILINK{,1,2} registers.
- Add LP_START and LP_END registers for hardware loops - required to
  properly evaluate possible next instruction during software single
  instruction stepping.
- Add BTA register which contains branch target address - address of
  next instruction when processor is in the delay slot.
- ARC HS description also adds R30, R58 and R59 registers, specific to
  this architecture.

gdb/ChangeLog:
2020-04-28  Anton Kolesov  <[hidden email]>

        * arch/arc.h (arc_create_target_description): Support Linux targets.
        * arch/arc.c (arc_create_target_description): Likewise.
        * arc-tdep.c (arc_tdesc_init): Update invocation of
          arc_read_description.
        * features/Makefile (FEATURE_XMLFILES): Add new files.
        * features/arc/aux-arcompact-linux.xml: New file.
        * features/arc/aux-v2-linux.xml: Likewise.
        * features/arc/core-arcompact-linux.xml: Likewise.
        * features/arc/core-v2-linux.xml: Likewise.
        * features/arc/aux-arcompact-linux.c: Generate.
        * features/arc/aux-v2-linux.c: Likewise.
        * features/arc/core-arcompact-linux.c: Likewise.
        * features/arc/core-v2-linux.c: Likewise.
---
 gdb/arc-tdep.c                            |  4 +-
 gdb/arch/arc.c                            | 40 ++++++++++++----
 gdb/arch/arc.h                            | 18 ++++---
 gdb/features/Makefile                     |  4 ++
 gdb/features/arc/aux-arcompact-linux.c    | 34 +++++++++++++
 gdb/features/arc/aux-arcompact-linux.xml  | 31 ++++++++++++
 gdb/features/arc/aux-v2-linux.c           | 38 +++++++++++++++
 gdb/features/arc/aux-v2-linux.xml         | 35 ++++++++++++++
 gdb/features/arc/core-arcompact-linux.c   | 45 ++++++++++++++++++
 gdb/features/arc/core-arcompact-linux.xml | 56 ++++++++++++++++++++++
 gdb/features/arc/core-v2-linux.c          | 48 +++++++++++++++++++
 gdb/features/arc/core-v2-linux.xml        | 58 +++++++++++++++++++++++
 12 files changed, 394 insertions(+), 17 deletions(-)
 create mode 100644 gdb/features/arc/aux-arcompact-linux.c
 create mode 100644 gdb/features/arc/aux-arcompact-linux.xml
 create mode 100644 gdb/features/arc/aux-v2-linux.c
 create mode 100644 gdb/features/arc/aux-v2-linux.xml
 create mode 100644 gdb/features/arc/core-arcompact-linux.c
 create mode 100644 gdb/features/arc/core-arcompact-linux.xml
 create mode 100644 gdb/features/arc/core-v2-linux.c
 create mode 100644 gdb/features/arc/core-v2-linux.xml

diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index 3020099c335..a4f3f44b4fb 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -1756,9 +1756,9 @@ arc_tdesc_init (struct gdbarch_info info, const struct target_desc **tdesc,
   if (!tdesc_has_registers (tdesc_loc))
     {
       if (is_arcv2)
- tdesc_loc = arc_read_description (ARC_SYS_TYPE_ARCV2);
+ tdesc_loc = arc_read_description (ARC_SYS_TYPE_ARCV2_BMT);
       else
- tdesc_loc = arc_read_description (ARC_SYS_TYPE_ARCOMPACT);
+ tdesc_loc = arc_read_description (ARC_SYS_TYPE_ARCOMPACT_BMT);
     }
   else
     {
diff --git a/gdb/arch/arc.c b/gdb/arch/arc.c
index 9552b4aff97..0babbf8a36a 100644
--- a/gdb/arch/arc.c
+++ b/gdb/arch/arc.c
@@ -24,8 +24,12 @@
 /* Target description features.  */
 #include "features/arc/core-v2.c"
 #include "features/arc/aux-v2.c"
+#include "features/arc/core-v2-linux.c"
+#include "features/arc/aux-v2-linux.c"
 #include "features/arc/core-arcompact.c"
 #include "features/arc/aux-arcompact.c"
+#include "features/arc/core-arcompact-linux.c"
+#include "features/arc/aux-arcompact-linux.c"
 
 /* See arc.h.  */
 
@@ -37,21 +41,39 @@ arc_create_target_description (arc_sys_type sys_type)
   long regnum = 0;
 
 #ifndef IN_PROCESS_AGENT
-  if (sys_type == ARC_SYS_TYPE_ARCV2)
+  if (sys_type == ARC_SYS_TYPE_ARCV2_BMT)
     set_tdesc_architecture (tdesc, "arc:ARCv2");
+  else if (sys_type == ARC_SYS_TYPE_ARCV2_LNX)
+    /* If this is ARCv2 Linux, then it is ARC HS.  */
+    set_tdesc_architecture (tdesc, "arc:HS");
   else
     set_tdesc_architecture (tdesc, "arc:ARC700");
+
+  if (sys_type == ARC_SYS_TYPE_ARCOMPACT_LNX
+      || sys_type == ARC_SYS_TYPE_ARCV2_LNX)
+    set_tdesc_osabi (tdesc, "GNU/Linux");
 #endif
 
-  if (sys_type == ARC_SYS_TYPE_ARCV2)
-    {
-      regnum = create_feature_arc_core_v2 (tdesc, regnum);
-      regnum = create_feature_arc_aux_v2 (tdesc, regnum);
-    }
-  else
+  switch (sys_type)
     {
-      regnum = create_feature_arc_core_arcompact (tdesc, regnum);
-      regnum = create_feature_arc_aux_arcompact (tdesc, regnum);
+    case ARC_SYS_TYPE_ARCOMPACT_BMT:
+  regnum = create_feature_arc_core_arcompact (tdesc, regnum);
+  regnum = create_feature_arc_aux_arcompact (tdesc, regnum);
+  break;
+    case ARC_SYS_TYPE_ARCOMPACT_LNX:
+  regnum = create_feature_arc_core_arcompact_linux (tdesc, regnum);
+  regnum = create_feature_arc_aux_arcompact_linux (tdesc, regnum);
+  break;
+    case ARC_SYS_TYPE_ARCV2_BMT:
+  regnum = create_feature_arc_core_v2 (tdesc, regnum);
+  regnum = create_feature_arc_aux_v2 (tdesc, regnum);
+  break;
+    case ARC_SYS_TYPE_ARCV2_LNX:
+  regnum = create_feature_arc_core_v2_linux (tdesc, regnum);
+  regnum = create_feature_arc_aux_v2_linux (tdesc, regnum);
+  break;
+    default:
+  gdb_assert(!"Invalid arc_sys_type.");
     }
 
   return tdesc;
diff --git a/gdb/arch/arc.h b/gdb/arch/arc.h
index fd806ae7d34..3c19118b946 100644
--- a/gdb/arch/arc.h
+++ b/gdb/arch/arc.h
@@ -23,8 +23,10 @@
 /* Supported ARC system hardware types.  */
 enum arc_sys_type
 {
-  ARC_SYS_TYPE_ARCOMPACT = 0,  /* ARC600 or ARC700 */
-  ARC_SYS_TYPE_ARCV2,  /* ARC EM or ARC HS */
+  ARC_SYS_TYPE_ARCOMPACT_BMT = 0, /* ARC600 or ARC700 (baremetal) */
+  ARC_SYS_TYPE_ARCOMPACT_LNX,  /* ARC600 or ARC700 (linux) */
+  ARC_SYS_TYPE_ARCV2_BMT,  /* ARC EM or ARC HS (baremetal) */
+  ARC_SYS_TYPE_ARCV2_LNX,  /* ARC HS (linux) */
   ARC_SYS_TYPE_NUM
 };
 
@@ -33,10 +35,14 @@ arc_sys_type_to_str (const arc_sys_type type)
 {
   switch (type)
     {
-    case ARC_SYS_TYPE_ARCOMPACT:
-      return "ARC_SYS_TYPE_ARCOMPACT";
-    case ARC_SYS_TYPE_ARCV2:
-      return "ARC_SYS_TYPE_ARCV2";
+    case ARC_SYS_TYPE_ARCOMPACT_BMT:
+      return "ARC_SYS_TYPE_ARCOMPACT_BMT";
+    case ARC_SYS_TYPE_ARCOMPACT_LNX:
+      return "ARC_SYS_TYPE_ARCOMPACT_LNX";
+    case ARC_SYS_TYPE_ARCV2_BMT:
+      return "ARC_SYS_TYPE_ARCV2_BMT";
+    case ARC_SYS_TYPE_ARCV2_LNX:
+      return "ARC_SYS_TYPE_ARCV2_LNX";
     default:
       return "Invalid";
     }
diff --git a/gdb/features/Makefile b/gdb/features/Makefile
index cc65baa6eda..a95be667dc1 100644
--- a/gdb/features/Makefile
+++ b/gdb/features/Makefile
@@ -206,8 +206,12 @@ FEATURE_XMLFILES = aarch64-core.xml \
  aarch64-pauth.xml \
  arc/core-v2.xml \
  arc/aux-v2.xml \
+ arc/core-v2-linux.xml \
+ arc/aux-v2-linux.xml \
  arc/core-arcompact.xml \
  arc/aux-arcompact.xml \
+ arc/core-arcompact-linux.xml \
+ arc/aux-arcompact-linux.xml \
  arm/arm-core.xml \
  arm/arm-fpa.xml \
  arm/arm-m-profile.xml \
diff --git a/gdb/features/arc/aux-arcompact-linux.c b/gdb/features/arc/aux-arcompact-linux.c
new file mode 100644
index 00000000000..41f26c1e2ec
--- /dev/null
+++ b/gdb/features/arc/aux-arcompact-linux.c
@@ -0,0 +1,34 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: aux-arcompact-linux.xml */
+
+#include "gdbsupport/tdesc.h"
+
+static int
+create_feature_arc_aux_arcompact_linux (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.arc.aux-minimal");
+  tdesc_type_with_fields *type_with_fields;
+  type_with_fields = tdesc_create_flags (feature, "status32_type", 4);
+  tdesc_add_flag (type_with_fields, 0, "H");
+  tdesc_add_bitfield (type_with_fields, "E", 1, 2);
+  tdesc_add_bitfield (type_with_fields, "A", 3, 4);
+  tdesc_add_flag (type_with_fields, 5, "AE");
+  tdesc_add_flag (type_with_fields, 6, "DE");
+  tdesc_add_flag (type_with_fields, 7, "U");
+  tdesc_add_flag (type_with_fields, 8, "V");
+  tdesc_add_flag (type_with_fields, 9, "C");
+  tdesc_add_flag (type_with_fields, 10, "N");
+  tdesc_add_flag (type_with_fields, 11, "Z");
+  tdesc_add_flag (type_with_fields, 12, "L");
+  tdesc_add_flag (type_with_fields, 13, "R");
+  tdesc_add_flag (type_with_fields, 14, "SE");
+
+  tdesc_create_reg (feature, "pc", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "status32", regnum++, 1, NULL, 32, "status32_type");
+  tdesc_create_reg (feature, "lp_start", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "lp_end", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "bta", regnum++, 1, NULL, 32, "code_ptr");
+  return regnum;
+}
diff --git a/gdb/features/arc/aux-arcompact-linux.xml b/gdb/features/arc/aux-arcompact-linux.xml
new file mode 100644
index 00000000000..0d72373eda3
--- /dev/null
+++ b/gdb/features/arc/aux-arcompact-linux.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2020 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE target SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.arc.aux-minimal">
+  <flags id="status32_type" size="4">
+      <field name="H"   start="0" end="0"/>
+      <field name="E"   start="1" end="2"/>
+      <field name="A"   start="3" end="4"/>
+      <field name="AE"  start="5" end="5"/>
+      <field name="DE"  start="6" end="6"/>
+      <field name="U"   start="7" end="7"/>
+      <field name="V"   start="8" end="8"/>
+      <field name="C"   start="9" end="9"/>
+      <field name="N"   start="10" end="10"/>
+      <field name="Z"   start="11" end="11"/>
+      <field name="L"   start="12" end="12"/>
+      <field name="R"  start="13" end="13"/>
+      <field name="SE"  start="14" end="14"/>
+  </flags>
+
+  <reg name="pc"       bitsize="32" type="code_ptr"/>
+  <reg name="status32" bitsize="32" type="status32_type"/>
+  <reg name="lp_start" bitsize="32" type="code_ptr"/>
+  <reg name="lp_end"   bitsize="32" type="code_ptr"/>
+  <reg name="bta"      bitsize="32" type="code_ptr"/>
+</feature>
diff --git a/gdb/features/arc/aux-v2-linux.c b/gdb/features/arc/aux-v2-linux.c
new file mode 100644
index 00000000000..6e4d7c02efa
--- /dev/null
+++ b/gdb/features/arc/aux-v2-linux.c
@@ -0,0 +1,38 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: aux-v2-linux.xml */
+
+#include "gdbsupport/tdesc.h"
+
+static int
+create_feature_arc_aux_v2_linux (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.arc.aux-minimal");
+  tdesc_type_with_fields *type_with_fields;
+  type_with_fields = tdesc_create_flags (feature, "status32_type", 4);
+  tdesc_add_flag (type_with_fields, 0, "H");
+  tdesc_add_bitfield (type_with_fields, "E", 1, 4);
+  tdesc_add_flag (type_with_fields, 5, "AE");
+  tdesc_add_flag (type_with_fields, 6, "DE");
+  tdesc_add_flag (type_with_fields, 7, "U");
+  tdesc_add_flag (type_with_fields, 8, "V");
+  tdesc_add_flag (type_with_fields, 9, "C");
+  tdesc_add_flag (type_with_fields, 10, "N");
+  tdesc_add_flag (type_with_fields, 11, "Z");
+  tdesc_add_flag (type_with_fields, 12, "L");
+  tdesc_add_flag (type_with_fields, 13, "DZ");
+  tdesc_add_flag (type_with_fields, 14, "SC");
+  tdesc_add_flag (type_with_fields, 15, "ES");
+  tdesc_add_bitfield (type_with_fields, "RB", 16, 18);
+  tdesc_add_flag (type_with_fields, 19, "AD");
+  tdesc_add_flag (type_with_fields, 20, "US");
+  tdesc_add_flag (type_with_fields, 31, "IE");
+
+  tdesc_create_reg (feature, "pc", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "status32", regnum++, 1, NULL, 32, "status32_type");
+  tdesc_create_reg (feature, "lp_start", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "lp_end", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "bta", regnum++, 1, NULL, 32, "code_ptr");
+  return regnum;
+}
diff --git a/gdb/features/arc/aux-v2-linux.xml b/gdb/features/arc/aux-v2-linux.xml
new file mode 100644
index 00000000000..165ebb1d6d6
--- /dev/null
+++ b/gdb/features/arc/aux-v2-linux.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2020 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE target SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.arc.aux-minimal">
+  <flags id="status32_type" size="4">
+      <field name="H"   start="0" end="0"/>
+      <field name="E"   start="1" end="4"/>
+      <field name="AE"  start="5" end="5"/>
+      <field name="DE"  start="6" end="6"/>
+      <field name="U"   start="7" end="7"/>
+      <field name="V"   start="8" end="8"/>
+      <field name="C"   start="9" end="9"/>
+      <field name="N"   start="10" end="10"/>
+      <field name="Z"   start="11" end="11"/>
+      <field name="L"   start="12" end="12"/>
+      <field name="DZ"  start="13" end="13"/>
+      <field name="SC"  start="14" end="14"/>
+      <field name="ES"  start="15" end="15"/>
+      <field name="RB"  start="16" end="18"/>
+      <field name="AD"  start="19" end="19"/>
+      <field name="US"  start="20" end="20"/>
+      <field name="IE"  start="31" end="31"/>
+  </flags>
+
+  <reg name="pc"       bitsize="32" type="code_ptr"/>
+  <reg name="status32" bitsize="32" type="status32_type"/>
+  <reg name="lp_start" bitsize="32" type="code_ptr"/>
+  <reg name="lp_end"   bitsize="32" type="code_ptr"/>
+  <reg name="bta"      bitsize="32" type="code_ptr"/>
+</feature>
diff --git a/gdb/features/arc/core-arcompact-linux.c b/gdb/features/arc/core-arcompact-linux.c
new file mode 100644
index 00000000000..c870413e922
--- /dev/null
+++ b/gdb/features/arc/core-arcompact-linux.c
@@ -0,0 +1,45 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: core-arcompact-linux.xml */
+
+#include "gdbsupport/tdesc.h"
+
+static int
+create_feature_arc_core_arcompact_linux (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.arc.core.arcompact");
+  tdesc_create_reg (feature, "r0", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r1", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r2", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r3", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r4", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r5", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r6", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r7", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r8", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r9", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r10", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r11", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r12", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r13", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r14", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r15", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r16", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r17", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r18", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r19", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r20", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r21", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r22", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r23", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r24", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r25", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "gp", regnum++, 1, NULL, 32, "data_ptr");
+  tdesc_create_reg (feature, "fp", regnum++, 1, NULL, 32, "data_ptr");
+  tdesc_create_reg (feature, "sp", regnum++, 1, NULL, 32, "data_ptr");
+  tdesc_create_reg (feature, "blink", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "lp_count", regnum++, 1, NULL, 32, "uint32");
+  tdesc_create_reg (feature, "pcl", regnum++, 1, NULL, 32, "code_ptr");
+  return regnum;
+}
diff --git a/gdb/features/arc/core-arcompact-linux.xml b/gdb/features/arc/core-arcompact-linux.xml
new file mode 100644
index 00000000000..9b2865d32be
--- /dev/null
+++ b/gdb/features/arc/core-arcompact-linux.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2020 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE target SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.arc.core.arcompact">
+  <reg name="r0"  bitsize="32"/>
+  <reg name="r1"  bitsize="32"/>
+  <reg name="r2"  bitsize="32"/>
+  <reg name="r3"  bitsize="32"/>
+  <reg name="r4"  bitsize="32"/>
+  <reg name="r5"  bitsize="32"/>
+  <reg name="r6"  bitsize="32"/>
+  <reg name="r7"  bitsize="32"/>
+  <reg name="r8"  bitsize="32"/>
+  <reg name="r9"  bitsize="32"/>
+  <reg name="r10" bitsize="32"/>
+  <reg name="r11" bitsize="32"/>
+  <reg name="r12" bitsize="32"/>
+  <reg name="r13" bitsize="32"/>
+  <reg name="r14" bitsize="32"/>
+  <reg name="r15" bitsize="32"/>
+  <reg name="r16" bitsize="32"/>
+  <reg name="r17" bitsize="32"/>
+  <reg name="r18" bitsize="32"/>
+  <reg name="r19" bitsize="32"/>
+  <reg name="r20" bitsize="32"/>
+  <reg name="r21" bitsize="32"/>
+  <reg name="r22" bitsize="32"/>
+  <reg name="r23" bitsize="32"/>
+  <reg name="r24" bitsize="32"/>
+  <reg name="r25" bitsize="32"/>
+
+  <!-- ARC core data pointer registers.  -->
+  <reg name="gp"  bitsize="32" type="data_ptr"/>
+  <reg name="fp"  bitsize="32" type="data_ptr"/>
+  <reg name="sp"  bitsize="32" type="data_ptr"/>
+
+  <!-- Code pointers.  -->
+  <reg name="blink"  bitsize="32" type="code_ptr"/>
+
+  <!-- Here goes extension core registers: r32 - r59 -->
+
+  <!-- Loop counter.  -->
+  <reg name="lp_count" bitsize="32" type="uint32"/>
+
+  <!-- r61 is a reserved register address.  -->
+
+  <!-- r62 is a long immediate value, not a real register.  -->
+
+  <!-- 4-byte aligned read-only program counter.  -->
+  <reg name="pcl" bitsize="32" type="code_ptr" group=""/>
+</feature>
diff --git a/gdb/features/arc/core-v2-linux.c b/gdb/features/arc/core-v2-linux.c
new file mode 100644
index 00000000000..d3e563778ff
--- /dev/null
+++ b/gdb/features/arc/core-v2-linux.c
@@ -0,0 +1,48 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: core-v2-linux.xml */
+
+#include "gdbsupport/tdesc.h"
+
+static int
+create_feature_arc_core_v2_linux (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.arc.core.v2");
+  tdesc_create_reg (feature, "r0", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r1", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r2", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r3", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r4", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r5", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r6", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r7", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r8", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r9", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r10", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r11", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r12", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r13", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r14", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r15", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r16", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r17", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r18", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r19", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r20", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r21", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r22", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r23", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r24", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r25", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "gp", regnum++, 1, NULL, 32, "data_ptr");
+  tdesc_create_reg (feature, "fp", regnum++, 1, NULL, 32, "data_ptr");
+  tdesc_create_reg (feature, "sp", regnum++, 1, NULL, 32, "data_ptr");
+  tdesc_create_reg (feature, "r30", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "blink", regnum++, 1, NULL, 32, "code_ptr");
+  tdesc_create_reg (feature, "r58", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "r59", regnum++, 1, NULL, 32, "int");
+  tdesc_create_reg (feature, "lp_count", regnum++, 1, NULL, 32, "uint32");
+  tdesc_create_reg (feature, "pcl", regnum++, 1, NULL, 32, "code_ptr");
+  return regnum;
+}
diff --git a/gdb/features/arc/core-v2-linux.xml b/gdb/features/arc/core-v2-linux.xml
new file mode 100644
index 00000000000..3ac4a86da56
--- /dev/null
+++ b/gdb/features/arc/core-v2-linux.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2020 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE target SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.arc.core.v2">
+  <reg name="r0"  bitsize="32"/>
+  <reg name="r1"  bitsize="32"/>
+  <reg name="r2"  bitsize="32"/>
+  <reg name="r3"  bitsize="32"/>
+  <reg name="r4"  bitsize="32"/>
+  <reg name="r5"  bitsize="32"/>
+  <reg name="r6"  bitsize="32"/>
+  <reg name="r7"  bitsize="32"/>
+  <reg name="r8"  bitsize="32"/>
+  <reg name="r9"  bitsize="32"/>
+  <reg name="r10" bitsize="32"/>
+  <reg name="r11" bitsize="32"/>
+  <reg name="r12" bitsize="32"/>
+  <reg name="r13" bitsize="32"/>
+  <reg name="r14" bitsize="32"/>
+  <reg name="r15" bitsize="32"/>
+  <reg name="r16" bitsize="32"/>
+  <reg name="r17" bitsize="32"/>
+  <reg name="r18" bitsize="32"/>
+  <reg name="r19" bitsize="32"/>
+  <reg name="r20" bitsize="32"/>
+  <reg name="r21" bitsize="32"/>
+  <reg name="r22" bitsize="32"/>
+  <reg name="r23" bitsize="32"/>
+  <reg name="r24" bitsize="32"/>
+  <reg name="r25" bitsize="32"/>
+
+  <!-- ARC core data pointer registers.  -->
+  <reg name="gp"  bitsize="32" type="data_ptr"/>
+  <reg name="fp"  bitsize="32" type="data_ptr"/>
+  <reg name="sp"  bitsize="32" type="data_ptr"/>
+
+  <reg name="r30"   bitsize="32" group=""/>
+  <reg name="blink" bitsize="32" type="code_ptr"/>
+
+  <!-- Here goes extension core registers: r32 - r57.  -->
+  <reg name="r58"   bitsize="32"/>
+  <reg name="r59"   bitsize="32"/>
+
+  <!-- Loop counter.  -->
+  <reg name="lp_count" bitsize="32" type="uint32"/>
+
+  <!-- r61 is a reserved register address.  -->
+
+  <!-- r62 is a long immediate value, not a real register.  -->
+
+  <!-- 4-byte aligned read-only program counter.  -->
+  <reg name="pcl" bitsize="32" type="code_ptr" group=""/>
+</feature>
--
2.26.2

Reply | Threaded
Open this post in threaded view
|

[PATCH v2 2/4] arc: Recognize registers available on Linux targets

Sourceware - gdb-patches mailing list
In reply to this post by Sourceware - gdb-patches mailing list
From: Anton Kolesov <[hidden email]>

For ARC there are registers that are not part of a required set in XML target
descriptions by default, but which are almost always present on ARC targets and
are universally exposed by the ptrace interface.  This patch adds those
registers to those recognized by GDB:

- R30 - core register available in user-space on ARC HS processors only (used
  to be a privileged only ILINK2 on ARC700).
- R58, R59 - accumulator register pair for a 64-multiplier and
  double-precision FPU - only on ARC HS.
- LP_START, LP_END - AUX registers, hardware loop start and end.  Formally
  optional, though it is hard to find ARC configuration that doesn't have
  them and is always present in processors that can run Linux.  GDB needs to
  know about those registers to implement proper software single stepping,
  since they affect what instruction will be next.
- BTA - AUX register that contains branch target address.  Value of this
  register makes sense only when execution halts at the delay slot
  instruction - in this case branch instruction is already committed,
  STATUS32.DE is set to 1 and BTA contains address of next PC.  GDB needs to
  understand this register to properly handle situations when breakpoint has
  been set in the delay slot (delay slot is stepped over when doing software
  single stepping).  Unfortunately, right now this doesn't work very well,
  because Linux doesn't allow modifications of STATUS32 via ptrace and Linux
  uses TRAP_S instruction to implement software breakpoints - this
  instruction commits when executed, therefore when TRAP_S is set in the
  delay slot and execution halts at it, PC is already advanced to BTA value
  and STATUS32.DE is reset.  BTA register will be more useful for debugger
  after support for SWI instruction will be added to ARC Linux - this
  breakpoint instruction doesn't commit, hence it doesn't change processor
  state.

v2: Changes after Tom's remarks:
 arc-tdep.c
  - arc_tdesc_init(): Use "ARC_{R58,R59}_REGNUM" to index "core_regs[]".
  - arc_gdbarch_init(): Use "xfree ()" instead of "XDELETE ()"
  - arc_gdbarch_init(): return "nullptr" instead of "NULL".

gdb/ChangeLog:
2020-04-28  Anton Kolesov  <[hidden email]>

        * arc-tdep.c (core_v2_register_names): Fix names of R58 and R59.
        (aux_minimal_register_names): Add LP_START, LP_END and BTA.
        (arc_tdesc_init): Recognize those registers.
        * arc-tdep.h (arc_regnum): Add R58, R59, LP_START, LP_END and BTA.
        (gdbarch_tdep): New field has_hw_loops.

gdb/doc/ChangeLog:
2020-04-28  Anton Kolesov  <[hidden email]>

        * gdb.texinfo (Synopsys ARC): Document LP_START, LP_END and BTA.
---
 gdb/arc-tdep.c      | 77 +++++++++++++++++++++++++++++++++++----------
 gdb/arc-tdep.h      | 17 ++++++++--
 gdb/doc/gdb.texinfo |  3 +-
 3 files changed, 78 insertions(+), 19 deletions(-)

diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index a4f3f44b4fb..878728bc62c 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -117,12 +117,12 @@ static const char *const core_v2_register_names[] = {
   "r44", "r45", "r46", "r47",
   "r48", "r49", "r50", "r51",
   "r52", "r53", "r54", "r55",
-  "r56", "r57", "accl", "acch",
-  "lp_count", "reserved", "limm", "pcl",
+  "r56", "r57", "r58", "r59",
+  "lp_count", "reserved", "limm", "pcl"
 };
 
 static const char *const aux_minimal_register_names[] = {
-  "pc", "status32",
+  "pc", "status32", "lp_start", "lp_end", "bta"
 };
 
 static const char *const core_arcompact_register_names[] = {
@@ -141,7 +141,7 @@ static const char *const core_arcompact_register_names[] = {
   "r48", "r49", "r50", "r51",
   "r52", "r53", "r54", "r55",
   "r56", "r57", "r58", "r59",
-  "lp_count", "reserved", "limm", "pcl",
+  "lp_count", "reserved", "limm", "pcl"
 };
 
 static char *arc_disassembler_options = NULL;
@@ -1724,7 +1724,7 @@ static const struct frame_base arc_normal_base = {
 
 static bool
 arc_tdesc_init (struct gdbarch_info info, const struct target_desc **tdesc,
- struct tdesc_arch_data **tdesc_data)
+ struct tdesc_arch_data **tdesc_data, struct gdbarch_tdep *tdep)
 {
   if (arc_debug)
     debug_printf ("arc: Target description initialization.\n");
@@ -1858,17 +1858,44 @@ arc_tdesc_init (struct gdbarch_info info, const struct target_desc **tdesc,
     || (i >= ARC_R16_REGNUM && i <= ARC_R25_REGNUM)))
  continue;
 
-      valid_p = tdesc_numbered_register (feature, tdesc_data_loc, i,
- core_regs[i]);
+      /* R58 and R59 can have special names: ACCL and ACCH, however which
+ one is which depends on target endianness - for little endian R58
+ is ACCL, R59 is ACCH; vice versa for big endian.  */
+
+      const char *const r58_names[] = {
+ core_regs[ARC_R58_REGNUM],
+ (info.byte_order == BFD_ENDIAN_LITTLE ? "accl" : "acch"),
+ NULL
+      };
+      const char *const r59_names[] = {
+ core_regs[ARC_R59_REGNUM],
+ (info.byte_order == BFD_ENDIAN_LITTLE ? "acch" : "accl"),
+ NULL
+      };
+
+      switch (i)
+ {
+ case ARC_R58_REGNUM:
+  valid_p = tdesc_numbered_register_choices (feature, tdesc_data_loc,
+     i, r58_names);
+  break;
+ case ARC_R59_REGNUM:
+  valid_p = tdesc_numbered_register_choices (feature, tdesc_data_loc,
+     i, r59_names);
+  break;
+ default:
+  valid_p = tdesc_numbered_register (feature, tdesc_data_loc, i,
+     core_regs[i]);
+ }
 
       /* - Ignore errors in extension registers - they are optional.
  - Ignore missing ILINK because it doesn't make sense for Linux.
- - Ignore missing ILINK2 when architecture is ARCompact, because it
- doesn't make sense for Linux targets.
+ - Ignore missing ILINK2 when architecture is ARCompact, because
+ it doesn't make sense for Linux targets.
 
- In theory those optional registers should be in separate features, but
- that would create numerous but tiny features, which looks like an
- overengineering of a rather simple task.  */
+ In theory those optional registers should be in separate
+ features, but that would create numerous but tiny features, which
+ looks like an overengineering of a rather simple task.  */
       if (!valid_p && (i <= ARC_SP_REGNUM || i == ARC_BLINK_REGNUM
        || i == ARC_LP_COUNT_REGNUM || i == ARC_PCL_REGNUM
        || (i == ARC_R30_REGNUM && is_arcv2)))
@@ -1895,7 +1922,9 @@ arc_tdesc_init (struct gdbarch_info info, const struct target_desc **tdesc,
     {
       const char *name = aux_minimal_register_names[i - ARC_FIRST_AUX_REGNUM];
       valid_p = tdesc_numbered_register (feature, tdesc_data_loc, i, name);
-      if (!valid_p)
+
+      /* Only STATUS32 and PC are mandatory.  */
+      if (!valid_p && (i == ARC_PC_REGNUM || i == ARC_STATUS32_REGNUM))
  {
   arc_print (_("Error: Cannot find required register `%s' "
        "in feature `%s'.\n"),
@@ -1903,6 +1932,11 @@ arc_tdesc_init (struct gdbarch_info info, const struct target_desc **tdesc,
   tdesc_data_cleanup (tdesc_data_loc);
   return false;
  }
+      /* Hardware loops present if both its registers are.  */
+      else if (ARC_LP_START_REGNUM == i)
+ tdep->has_hw_loops = valid_p;
+      else if (ARC_LP_END_REGNUM == i)
+ tdep->has_hw_loops &= valid_p;
     }
 
   *tdesc = tdesc_loc;
@@ -1950,13 +1984,17 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   if (arc_debug)
     debug_printf ("arc: Architecture initialization.\n");
 
-  if (!arc_tdesc_init (info, &tdesc, &tdesc_data))
-    return NULL;
-
   /* Allocate the ARC-private target-dependent information structure, and the
      GDB target-independent information structure.  */
   struct gdbarch_tdep *tdep = XCNEW (struct gdbarch_tdep);
   tdep->jb_pc = -1; /* No longjmp support by default.  */
+
+  if (!arc_tdesc_init (info, &tdesc, &tdesc_data, tdep))
+    {
+      xfree (tdep);
+      return nullptr;
+    }
+
   struct gdbarch *gdbarch = gdbarch_alloc (&info, tdep);
 
   /* Data types.  */
@@ -1987,6 +2025,13 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_ps_regnum (gdbarch, ARC_STATUS32_REGNUM);
   set_gdbarch_fp0_regnum (gdbarch, -1); /* No FPU registers.  */
 
+  /* Confirm that register name lists have proper length.  */
+  gdb_static_assert (ARC_LAST_REGNUM + 1
+     == (ARRAY_SIZE (core_v2_register_names)
+ + ARRAY_SIZE (aux_minimal_register_names)));
+  gdb_static_assert (ARRAY_SIZE (core_v2_register_names)
+     == ARRAY_SIZE (core_arcompact_register_names));
+
   set_gdbarch_push_dummy_call (gdbarch, arc_push_dummy_call);
   set_gdbarch_push_dummy_code (gdbarch, arc_push_dummy_code);
 
diff --git a/gdb/arc-tdep.h b/gdb/arc-tdep.h
index d72332c7638..8fd8571457f 100644
--- a/gdb/arc-tdep.h
+++ b/gdb/arc-tdep.h
@@ -23,6 +23,7 @@
 
 /* Need disassemble_info.  */
 #include "dis-asm.h"
+#include "gdbarch.h"
 #include "arch/arc.h"
 
 /* To simplify GDB code this enum assumes that internal regnums should be same
@@ -54,6 +55,8 @@ enum arc_regnum
     ARC_R30_REGNUM,
     /* Return address from function.  */
     ARC_BLINK_REGNUM,
+    ARC_R58_REGNUM = 58,
+    ARC_R59_REGNUM,
     /* Zero-delay loop counter.  */
     ARC_LP_COUNT_REGNUM = 60,
     /* Reserved register number.  There should never be a register with such
@@ -69,14 +72,21 @@ enum arc_regnum
     /* Program counter, aligned to 4-bytes, read-only.  */
     ARC_PCL_REGNUM,
     ARC_LAST_CORE_REGNUM = ARC_PCL_REGNUM,
+
     /* AUX registers.  */
     /* Actual program counter.  */
     ARC_PC_REGNUM,
     ARC_FIRST_AUX_REGNUM = ARC_PC_REGNUM,
     /* Status register.  */
     ARC_STATUS32_REGNUM,
-    ARC_LAST_REGNUM = ARC_STATUS32_REGNUM,
-    ARC_LAST_AUX_REGNUM = ARC_STATUS32_REGNUM,
+    /* Zero-delay loop start instruction.  */
+    ARC_LP_START_REGNUM,
+    /* Zero-delay loop next-after-last instruction.  */
+    ARC_LP_END_REGNUM,
+    /* Branch target address.  */
+    ARC_BTA_REGNUM,
+    ARC_LAST_AUX_REGNUM = ARC_BTA_REGNUM,
+    ARC_LAST_REGNUM = ARC_LAST_AUX_REGNUM,
 
     /* Additional ABI constants.  */
     ARC_FIRST_ARG_REGNUM = ARC_R0_REGNUM,
@@ -101,6 +111,9 @@ struct gdbarch_tdep
   /* Offset to PC value in jump buffer.  If this is negative, longjmp
      support will be disabled.  */
   int jb_pc;
+
+  /* Whether target has hardware (aka zero-delay) loops.  */
+  bool has_hw_loops;
 };
 
 /* Utility functions used by other ARC-specific modules.  */
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 385c832f222..1671d44c6c8 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -45115,7 +45115,8 @@ difference with @samp{org.gnu.gdb.arc.core.v2} feature is in the names of
 ARC v2, but @samp{ilink2} is optional on ARCompact.
 
 The @samp{org.gnu.gdb.arc.aux-minimal} feature is required for all ARC
-targets.  It should contain registers @samp{pc} and @samp{status32}.
+targets.  It should contain registers @samp{pc} and @samp{status32}.  It may
+contain registers @samp{lp_start}, @samp{lp_end} and @samp{bta}.
 
 @node ARM Features
 @subsection ARM Features
--
2.26.2

Reply | Threaded
Open this post in threaded view
|

[PATCH v2 3/4] arc: Add GNU/Linux support for ARC

Sourceware - gdb-patches mailing list
In reply to this post by Sourceware - gdb-patches mailing list
From: Anton Kolesov <[hidden email]>

ARC Linux targets differences from baremetal:

- No support for hardware single instruction stepping.
- Different access rules to registers.
- Use of another instruction for breakpoints.

v2: Changes after Tom's remarks
 arc-linux-tdep.c
  - Use true/false instead of TRUE/FALSE.
  - arc_linux_sw_breakpoint_from_kind (): Break long lines into two.
  - arc_linux_sw_breakpoint_from_kind (): Remove starting blank line.
  - Use explicit number evaluation, e.g: if (a & b) -> if ((a & b) != 0)
 arc-tdep.c
  - Use explicit number evaluation, e.g: if (a & b) -> if ((a & b) != 0)
 gdb/configure.tgt
  - arc*-*-linux*): Remove "build_gdbserver=yes".

2020-04-28  Anton Kolesov  <[hidden email]>

        * configure.tgt: ARC support for GNU/Linux.
        * Makefile.in (ALL_TARGET_OBJS): Likewise.
        * arc-linux-tdep.c: New file.
        * arc-tdep.h (ARC_STATUS32_L_MASK, ARC_STATUS32_DE_MASK): Declare.
        * arc-tdep.c (arc_write_pc): Use it.
---
 gdb/Makefile.in      |   1 +
 gdb/arc-linux-tdep.c | 284 +++++++++++++++++++++++++++++++++++++++++++
 gdb/arc-tdep.c       |   3 +-
 gdb/arc-tdep.h       |   5 +
 gdb/configure.tgt    |   5 +
 5 files changed, 296 insertions(+), 2 deletions(-)
 create mode 100644 gdb/arc-linux-tdep.c

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 0c331af4bff..028992ab664 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -695,6 +695,7 @@ ALL_64_TARGET_OBS = \
 # All other target-dependent objects files (used with --enable-targets=all).
 ALL_TARGET_OBS = \
  aarch32-tdep.o \
+ arc-linux-tdep.o \
  arc-tdep.o \
  arch/aarch32.o \
  arch/arc.o \
diff --git a/gdb/arc-linux-tdep.c b/gdb/arc-linux-tdep.c
new file mode 100644
index 00000000000..91eac68ebb5
--- /dev/null
+++ b/gdb/arc-linux-tdep.c
@@ -0,0 +1,284 @@
+/* Target dependent code for GNU/Linux ARC.
+
+   Copyright 2020 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* GDB header files.  */
+#include "defs.h"
+#include "linux-tdep.h"
+#include "objfiles.h"
+#include "opcode/arc.h"
+#include "osabi.h"
+#include "solib-svr4.h"
+
+/* ARC header files.  */
+#include "opcodes/arc-dis.h"
+#include "arc-tdep.h"
+
+/* Implement the "cannot_fetch_register" gdbarch method.  */
+
+static int
+arc_linux_cannot_fetch_register (struct gdbarch *gdbarch, int regnum)
+{
+  /* Assume that register is readable if it is unknown.  */
+  switch (regnum)
+    {
+    case ARC_ILINK_REGNUM:
+    case ARC_RESERVED_REGNUM:
+    case ARC_LIMM_REGNUM:
+      return true;
+    case ARC_R30_REGNUM:
+    case ARC_R58_REGNUM:
+    case ARC_R59_REGNUM:
+      return !arc_mach_is_arcv2 (gdbarch);
+    }
+  if (regnum > ARC_BLINK_REGNUM && regnum < ARC_LP_COUNT_REGNUM)
+    return true;
+  return false;
+}
+
+/* Implement the "cannot_store_register" gdbarch method.  */
+
+static int
+arc_linux_cannot_store_register (struct gdbarch *gdbarch, int regnum)
+{
+  /* Assume that register is writable if it is unknown.  */
+  switch (regnum)
+    {
+    case ARC_ILINK_REGNUM:
+    case ARC_RESERVED_REGNUM:
+    case ARC_LIMM_REGNUM:
+    case ARC_PCL_REGNUM:
+      return true;
+    case ARC_R30_REGNUM:
+    case ARC_R58_REGNUM:
+    case ARC_R59_REGNUM:
+      return !arc_mach_is_arcv2 (gdbarch);
+    }
+  if (regnum > ARC_BLINK_REGNUM && regnum < ARC_LP_COUNT_REGNUM)
+    return true;
+  return false;
+}
+
+/* For ARC Linux, breakpoint uses the 16-bit TRAP_S 1 instruction, which
+   is 0x3e78 (little endian) or 0x783e (big endian).  */
+
+static const gdb_byte arc_linux_trap_s_be[] = { 0x78, 0x3e };
+static const gdb_byte arc_linux_trap_s_le[] = { 0x3e, 0x78 };
+
+/* Implement the "breakpoint_kind_from_pc" gdbarch method.  */
+
+static int
+arc_linux_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
+{
+  return 2;
+}
+
+/* Implement the "sw_breakpoint_from_kind" gdbarch method.  */
+
+static const gdb_byte *
+arc_linux_sw_breakpoint_from_kind (struct gdbarch *gdbarch,
+   int kind, int *size)
+{
+  *size = kind;
+  return ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
+  ? arc_linux_trap_s_be
+  : arc_linux_trap_s_le);
+}
+
+/* Implement the "software_single_step" gdbarch method.  */
+
+static std::vector<CORE_ADDR>
+arc_linux_software_single_step (struct regcache *regcache)
+{
+  struct gdbarch *gdbarch = regcache->arch ();
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  struct disassemble_info di = arc_disassemble_info (gdbarch);
+
+  /* Read current instruction.  */
+  struct arc_instruction curr_insn;
+  arc_insn_decode (regcache_read_pc (regcache), &di, arc_delayed_print_insn,
+   &curr_insn);
+  CORE_ADDR next_pc = arc_insn_get_linear_next_pc (curr_insn);
+
+  std::vector<CORE_ADDR> next_pcs;
+
+  /* For instructions with delay slots, the fall thru is not the
+     instruction immediately after the current instruction, but the one
+     after that.  */
+  if (curr_insn.has_delay_slot)
+    {
+      struct arc_instruction next_insn;
+      arc_insn_decode (next_pc, &di, arc_delayed_print_insn, &next_insn);
+      next_pcs.push_back (arc_insn_get_linear_next_pc (next_insn));
+    }
+  else
+    {
+      next_pcs.push_back (next_pc);
+    }
+
+  ULONGEST status32;
+  regcache_cooked_read_unsigned (regcache, gdbarch_ps_regnum (gdbarch),
+ &status32);
+
+  if (curr_insn.is_control_flow)
+    {
+      CORE_ADDR branch_pc = arc_insn_get_branch_target (curr_insn);
+      if (branch_pc != next_pc)
+ next_pcs.push_back (branch_pc);
+    }
+  /* Is current instruction the last in a loop body?  */
+  else if (tdep->has_hw_loops)
+    {
+      /* If STATUS32.L is 1, then ZD-loops are disabled.  */
+      if ((status32 & ARC_STATUS32_L_MASK) == 0)
+ {
+  ULONGEST lp_end, lp_start, lp_count;
+  regcache_cooked_read_unsigned (regcache, ARC_LP_START_REGNUM,
+ &lp_start);
+  regcache_cooked_read_unsigned (regcache, ARC_LP_END_REGNUM, &lp_end);
+  regcache_cooked_read_unsigned (regcache, ARC_LP_COUNT_REGNUM,
+ &lp_count);
+
+  if (arc_debug)
+    {
+      debug_printf ("arc-linux: lp_start = %s, lp_end = %s, "
+    "lp_count = %s, next_pc = %s\n",
+    paddress (gdbarch, lp_start),
+    paddress (gdbarch, lp_end),
+    pulongest (lp_count),
+    paddress (gdbarch, next_pc));
+    }
+
+  if (next_pc == lp_end && lp_count > 1)
+    {
+      /* The instruction is in effect a jump back to the start of
+ the loop.  */
+      next_pcs.push_back (lp_start);
+    }
+
+ }
+    }
+
+  /* Is this a delay slot?  Then next PC is in BTA register.  */
+  if ((status32 & ARC_STATUS32_DE_MASK) != 0)
+    {
+      ULONGEST bta;
+      regcache_cooked_read_unsigned (regcache, ARC_BTA_REGNUM, &bta);
+      next_pcs.push_back (bta);
+    }
+
+  return next_pcs;
+}
+
+/* Implement the "skip_solib_resolver" gdbarch method.
+
+   See glibc_skip_solib_resolver for details.  */
+
+static CORE_ADDR
+arc_linux_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
+{
+  /* For uClibc 0.9.26+.
+
+     An unresolved PLT entry points to "__dl_linux_resolve", which calls
+     "_dl_linux_resolver" to do the resolving and then eventually jumps to
+     the function.
+
+     So we look for the symbol `_dl_linux_resolver', and if we are there,
+     gdb sets a breakpoint at the return address, and continues.  */
+  struct bound_minimal_symbol resolver =
+    lookup_minimal_symbol ("_dl_linux_resolver", NULL, NULL);
+
+  if (arc_debug)
+    {
+      if (resolver.minsym)
+ {
+  CORE_ADDR res_addr = BMSYMBOL_VALUE_ADDRESS (resolver);
+  debug_printf ("arc-linux: skip_solib_resolver (): "
+ "pc = %s, resolver at %s\n",
+ print_core_address (gdbarch, pc),
+ print_core_address (gdbarch, res_addr));
+ }
+      else
+ {
+  debug_printf ("arc-linux: skip_solib_resolver (): "
+ "pc = %s, no resolver found\n",
+ print_core_address (gdbarch, pc));
+ }
+    }
+
+  if (resolver.minsym && BMSYMBOL_VALUE_ADDRESS (resolver) == pc)
+    {
+      /* Find the return address.  */
+      return frame_unwind_caller_pc (get_current_frame ());
+    }
+  else
+    {
+      /* No breakpoint required.  */
+      return 0;
+    }
+}
+
+/* Initialization specific to Linux environment.  */
+
+static void
+arc_linux_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  if (arc_debug)
+    debug_printf ("arc-linux: GNU/Linux OS/ABI initialization.\n");
+
+  /* If we are using Linux, we have in uClibc
+     (libc/sysdeps/linux/arc/bits/setjmp.h):
+
+     typedef int __jmp_buf[13+1+1+1];    //r13-r25, fp, sp, blink
+
+     Where "blink" is a stored PC of a caller function.
+   */
+  tdep->jb_pc = 15;
+
+  linux_init_abi (info, gdbarch);
+
+  /* Set up target dependent GDB architecture entries.  */
+  set_gdbarch_cannot_fetch_register (gdbarch, arc_linux_cannot_fetch_register);
+  set_gdbarch_cannot_store_register (gdbarch, arc_linux_cannot_store_register);
+  set_gdbarch_breakpoint_kind_from_pc (gdbarch,
+       arc_linux_breakpoint_kind_from_pc);
+  set_gdbarch_sw_breakpoint_from_kind (gdbarch,
+       arc_linux_sw_breakpoint_from_kind);
+  set_gdbarch_fetch_tls_load_module_address (gdbarch,
+     svr4_fetch_objfile_link_map);
+  set_gdbarch_software_single_step (gdbarch, arc_linux_software_single_step);
+  set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
+  set_gdbarch_skip_solib_resolver (gdbarch, arc_linux_skip_solib_resolver);
+
+  /* GNU/Linux uses SVR4-style shared libraries, with 32-bit ints, longs
+     and pointers (ILP32).  */
+  set_solib_svr4_fetch_link_map_offsets (gdbarch,
+ svr4_ilp32_fetch_link_map_offsets);
+}
+
+/* Suppress warning from -Wmissing-prototypes.  */
+extern initialize_file_ftype _initialize_arc_linux_tdep;
+
+void
+_initialize_arc_linux_tdep (void)
+{
+  gdbarch_register_osabi (bfd_arch_arc, 0, GDB_OSABI_LINUX,
+  arc_linux_init_osabi);
+}
diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index 878728bc62c..b3d1e192ceb 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -462,8 +462,7 @@ arc_write_pc (struct regcache *regcache, CORE_ADDR new_pc)
   regcache_cooked_read_unsigned (regcache, gdbarch_ps_regnum (gdbarch),
  &status32);
 
-  /* Mask for DE bit is 0x40.  */
-  if (status32 & 0x40)
+  if ((status32 & ARC_STATUS32_DE_MASK) != 0)
     {
       if (arc_debug)
  {
diff --git a/gdb/arc-tdep.h b/gdb/arc-tdep.h
index 8fd8571457f..015ef3d4953 100644
--- a/gdb/arc-tdep.h
+++ b/gdb/arc-tdep.h
@@ -100,6 +100,11 @@ enum arc_regnum
    Longer registers are represented as pairs of 32-bit registers.  */
 #define ARC_REGISTER_SIZE  4
 
+/* STATUS32 register: hardware loops disabled bit.  */
+#define ARC_STATUS32_L_MASK (1 << 12)
+/* STATUS32 register: current instruction is a delay slot.  */
+#define ARC_STATUS32_DE_MASK (1 << 6)
+
 #define arc_print(fmt, args...) fprintf_unfiltered (gdb_stdlog, fmt, ##args)
 
 extern int arc_debug;
diff --git a/gdb/configure.tgt b/gdb/configure.tgt
index b3f31af763c..1a5c3a351fd 100644
--- a/gdb/configure.tgt
+++ b/gdb/configure.tgt
@@ -157,6 +157,11 @@ arc*-*-elf32)
  gdb_target_obs="arc-newlib-tdep.o"
  ;;
 
+arc*-*-linux*)
+ # Target: ARC machine running Linux
+ gdb_target_obs="arc-linux-tdep.o linux-tdep.o solib-svr4.o"
+ ;;
+
 arm*-wince-pe | arm*-*-mingw32ce*)
  # Target: ARM based machine running Windows CE (win32)
  gdb_target_obs="arm-wince-tdep.o windows-tdep.o"
--
2.26.2

Reply | Threaded
Open this post in threaded view
|

[PATCH v2 4/4] arc: Add arc-*-linux regformats

Sourceware - gdb-patches mailing list
In reply to this post by Sourceware - gdb-patches mailing list
From: Anton Kolesov <[hidden email]>

gdb/ChangeLog:
2020-04-28  Anton Kolesov <[hidden email]>

        * features/Makefile: Add new files and expedite registers.
        * regformats/arc-arcompact-Linux.dat: New file.
        * regformats/arc-v2-Linux.dat: Likewise.
---
 gdb/features/Makefile                  |  4 ++-
 gdb/regformats/arc-arcompact-linux.dat | 42 ++++++++++++++++++++++++
 gdb/regformats/arc-v2-linux.dat        | 45 ++++++++++++++++++++++++++
 3 files changed, 90 insertions(+), 1 deletion(-)
 create mode 100644 gdb/regformats/arc-arcompact-linux.dat
 create mode 100644 gdb/regformats/arc-v2-linux.dat

diff --git a/gdb/features/Makefile b/gdb/features/Makefile
index a95be667dc1..312c4f53185 100644
--- a/gdb/features/Makefile
+++ b/gdb/features/Makefile
@@ -44,7 +44,8 @@
 #   make GDB=/path/to/gdb XMLTOC="xml files" FEATURE_XMLFILES="xml files" cfiles
 
 # List of .dat files to create in ../regformats/
-WHICH = arm/arm-with-iwmmxt arm/arm-with-vfpv2 arm/arm-with-vfpv3 \
+WHICH = arc-v2-linux arc-arcompact-linux \
+ arm/arm-with-iwmmxt arm/arm-with-vfpv2 arm/arm-with-vfpv3 \
  arm/arm-with-neon \
  mips-linux mips-dsp-linux \
  microblaze-with-stack-protect \
@@ -72,6 +73,7 @@ WHICH = arm/arm-with-iwmmxt arm/arm-with-vfpv2 arm/arm-with-vfpv3 \
 
 # Record which registers should be sent to GDB by default after stop.
 aarch64-expedite = x29,sp,pc
+arc-expedite = sp,pc
 arm-expedite = r11,sp,pc
 i386-expedite = ebp,esp,eip
 amd64-expedite = rbp,rsp,rip
diff --git a/gdb/regformats/arc-arcompact-linux.dat b/gdb/regformats/arc-arcompact-linux.dat
new file mode 100644
index 00000000000..1d35860af3d
--- /dev/null
+++ b/gdb/regformats/arc-arcompact-linux.dat
@@ -0,0 +1,42 @@
+# THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi :set ro:
+# Generated from: arc-arcompact-linux.xml
+name:arc_arcompact_linux
+xmltarget:arc-arcompact-linux.xml
+expedite:sp,pc
+32:r0
+32:r1
+32:r2
+32:r3
+32:r4
+32:r5
+32:r6
+32:r7
+32:r8
+32:r9
+32:r10
+32:r11
+32:r12
+32:r13
+32:r14
+32:r15
+32:r16
+32:r17
+32:r18
+32:r19
+32:r20
+32:r21
+32:r22
+32:r23
+32:r24
+32:r25
+32:gp
+32:fp
+32:sp
+32:blink
+32:lp_count
+32:pcl
+32:pc
+32:status32
+32:lp_start
+32:lp_end
+32:bta
diff --git a/gdb/regformats/arc-v2-linux.dat b/gdb/regformats/arc-v2-linux.dat
new file mode 100644
index 00000000000..7e5d1904664
--- /dev/null
+++ b/gdb/regformats/arc-v2-linux.dat
@@ -0,0 +1,45 @@
+# THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi :set ro:
+# Generated from: arc-v2-linux.xml
+name:arc_v2_linux
+xmltarget:arc-v2-linux.xml
+expedite:sp,pc
+32:r0
+32:r1
+32:r2
+32:r3
+32:r4
+32:r5
+32:r6
+32:r7
+32:r8
+32:r9
+32:r10
+32:r11
+32:r12
+32:r13
+32:r14
+32:r15
+32:r16
+32:r17
+32:r18
+32:r19
+32:r20
+32:r21
+32:r22
+32:r23
+32:r24
+32:r25
+32:gp
+32:fp
+32:sp
+32:r30
+32:blink
+32:r58
+32:r59
+32:lp_count
+32:pcl
+32:pc
+32:status32
+32:lp_start
+32:lp_end
+32:bta
--
2.26.2

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2 2/4] arc: Recognize registers available on Linux targets

Eli Zaretskii
In reply to this post by Sourceware - gdb-patches mailing list
> Date: Tue, 28 Apr 2020 18:04:35 +0200
> From: Shahab Vahedi via Gdb-patches <[hidden email]>
> Cc: Shahab Vahedi <[hidden email]>,
>  Shahab Vahedi <[hidden email]>,
>  Anton Kolesov <[hidden email]>, Tom Tromey <[hidden email]>,
>  Francois Bedard <[hidden email]>
>
> gdb/ChangeLog:
> 2020-04-28  Anton Kolesov  <[hidden email]>
>
> * arc-tdep.c (core_v2_register_names): Fix names of R58 and R59.
> (aux_minimal_register_names): Add LP_START, LP_END and BTA.
> (arc_tdesc_init): Recognize those registers.
> * arc-tdep.h (arc_regnum): Add R58, R59, LP_START, LP_END and BTA.
> (gdbarch_tdep): New field has_hw_loops.
>
> gdb/doc/ChangeLog:
> 2020-04-28  Anton Kolesov  <[hidden email]>
>
> * gdb.texinfo (Synopsys ARC): Document LP_START, LP_END and BTA.

OK for the gdb.texinfo part.

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2 0/4] arc: Add GNU/Linux support

Sourceware - gdb-patches mailing list
In reply to this post by Sourceware - gdb-patches mailing list
A gentle reminder for the _second_ version of the patch series in:

https://sourceware.org/pipermail/gdb-patches/2020-April/168003.html

I appreciate taking the time to review it.

--
Shahab
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2 1/4] arc: Add XML target features for Linux targets

Simon Marchi-4
In reply to this post by Sourceware - gdb-patches mailing list
On 2020-04-28 12:04 p.m., Shahab Vahedi via Gdb-patches wrote:

> From: Anton Kolesov <[hidden email]>
>
> Add XML target features for Linux targets.  Compared to default
> Linux features:
>
> - Explicitly specify CPU machine.
> - Remove baremetal only ILINK{,1,2} registers.
> - Add LP_START and LP_END registers for hardware loops - required to
>   properly evaluate possible next instruction during software single
>   instruction stepping.
> - Add BTA register which contains branch target address - address of
>   next instruction when processor is in the delay slot.
> - ARC HS description also adds R30, R58 and R59 registers, specific to
>   this architecture.
>
> gdb/ChangeLog:
> 2020-04-28  Anton Kolesov  <[hidden email]>
>
> * arch/arc.h (arc_create_target_description): Support Linux targets.
> * arch/arc.c (arc_create_target_description): Likewise.
> * arc-tdep.c (arc_tdesc_init): Update invocation of
>  arc_read_description.
> * features/Makefile (FEATURE_XMLFILES): Add new files.
> * features/arc/aux-arcompact-linux.xml: New file.
> * features/arc/aux-v2-linux.xml: Likewise.
> * features/arc/core-arcompact-linux.xml: Likewise.
> * features/arc/core-v2-linux.xml: Likewise.
> * features/arc/aux-arcompact-linux.c: Generate.
> * features/arc/aux-v2-linux.c: Likewise.
> * features/arc/core-arcompact-linux.c: Likewise.
> * features/arc/core-v2-linux.c: Likewise.

Hi Shahab,

Instead of having multiple almost identical features, it's now usual
to build small features and compose them into the full target description.

For example, instead of having both:

- core-arcompact.xml
- core-arcompact-linux.xml

I think you should have:

- core-arcompact.xml, containing everything that's common in the two above
- core-arcompact-baremetal.xml, containing only the registers that are only present
  in the baremetal version.

When building the target description, the pseudo code would look like:

  if (arcompact)
    create_core_arcompact_feature ();
  else
    create_core_v2_feature ();

  if (baremetal) // or if (!linux)
    {
      if (arcompact)
        create_core_arccompact_baremetal_feature ();
      else
        create_core_v2_baremetal_feature ();
    }

Same goes for aux.  The i386 and arm target descriptions have examples of how to do
that.

Note that I don't know if the order of the registers in the target description
matters...  if so it could make this more difficult.

> @@ -37,21 +41,39 @@ arc_create_target_description (arc_sys_type sys_type)
>    long regnum = 0;
>  
>  #ifndef IN_PROCESS_AGENT
> -  if (sys_type == ARC_SYS_TYPE_ARCV2)
> +  if (sys_type == ARC_SYS_TYPE_ARCV2_BMT)
>      set_tdesc_architecture (tdesc, "arc:ARCv2");
> +  else if (sys_type == ARC_SYS_TYPE_ARCV2_LNX)
> +    /* If this is ARCv2 Linux, then it is ARC HS.  */
> +    set_tdesc_architecture (tdesc, "arc:HS");
>    else
>      set_tdesc_architecture (tdesc, "arc:ARC700");
> +
> +  if (sys_type == ARC_SYS_TYPE_ARCOMPACT_LNX
> +      || sys_type == ARC_SYS_TYPE_ARCV2_LNX)
> +    set_tdesc_osabi (tdesc, "GNU/Linux");
>  #endif
>  
> -  if (sys_type == ARC_SYS_TYPE_ARCV2)
> -    {
> -      regnum = create_feature_arc_core_v2 (tdesc, regnum);
> -      regnum = create_feature_arc_aux_v2 (tdesc, regnum);
> -    }
> -  else
> +  switch (sys_type)
>      {
> -      regnum = create_feature_arc_core_arcompact (tdesc, regnum);
> -      regnum = create_feature_arc_aux_arcompact (tdesc, regnum);
> +    case ARC_SYS_TYPE_ARCOMPACT_BMT:
> +  regnum = create_feature_arc_core_arcompact (tdesc, regnum);
> +  regnum = create_feature_arc_aux_arcompact (tdesc, regnum);
> +  break;
> +    case ARC_SYS_TYPE_ARCOMPACT_LNX:
> +  regnum = create_feature_arc_core_arcompact_linux (tdesc, regnum);
> +  regnum = create_feature_arc_aux_arcompact_linux (tdesc, regnum);
> +  break;
> +    case ARC_SYS_TYPE_ARCV2_BMT:
> +  regnum = create_feature_arc_core_v2 (tdesc, regnum);
> +  regnum = create_feature_arc_aux_v2 (tdesc, regnum);
> +  break;
> +    case ARC_SYS_TYPE_ARCV2_LNX:
> +  regnum = create_feature_arc_core_v2_linux (tdesc, regnum);
> +  regnum = create_feature_arc_aux_v2_linux (tdesc, regnum);
> +  break;
> +    default:
> +  gdb_assert(!"Invalid arc_sys_type.");
>      }

The goal of having descriptions built at runtime with features is to avoid
this kind of combinatorial explosion.  Now, you have two axis of configuration
(arcompact vs arcv2, bare-metal vs linux).  If you had more, it would become
less and less practical.  That's why I would encourage you to consider what I
said above.

>  
>    return tdesc;
> diff --git a/gdb/arch/arc.h b/gdb/arch/arc.h
> index fd806ae7d34..3c19118b946 100644
> --- a/gdb/arch/arc.h
> +++ b/gdb/arch/arc.h
> @@ -23,8 +23,10 @@
>  /* Supported ARC system hardware types.  */
>  enum arc_sys_type
>  {
> -  ARC_SYS_TYPE_ARCOMPACT = 0,  /* ARC600 or ARC700 */
> -  ARC_SYS_TYPE_ARCV2,  /* ARC EM or ARC HS */
> +  ARC_SYS_TYPE_ARCOMPACT_BMT = 0, /* ARC600 or ARC700 (baremetal) */
> +  ARC_SYS_TYPE_ARCOMPACT_LNX,  /* ARC600 or ARC700 (linux) */
> +  ARC_SYS_TYPE_ARCV2_BMT,  /* ARC EM or ARC HS (baremetal) */
> +  ARC_SYS_TYPE_ARCV2_LNX,  /* ARC HS (linux) */
>    ARC_SYS_TYPE_NUM

That's also not expected.  The fact that the target system is running Linux
should be handled by the fact that the selected osabi will be Linux.  So
you shouldn't need any changes here.

Simon
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2 2/4] arc: Recognize registers available on Linux targets

Simon Marchi-4
In reply to this post by Sourceware - gdb-patches mailing list
Just some nits - I don't really know about the specific details of the ARC architecture.

On 2020-04-28 12:04 p.m., Shahab Vahedi via Gdb-patches wrote:

> @@ -1950,13 +1984,17 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>    if (arc_debug)
>      debug_printf ("arc: Architecture initialization.\n");
>  
> -  if (!arc_tdesc_init (info, &tdesc, &tdesc_data))
> -    return NULL;
> -
>    /* Allocate the ARC-private target-dependent information structure, and the
>       GDB target-independent information structure.  */
>    struct gdbarch_tdep *tdep = XCNEW (struct gdbarch_tdep);
>    tdep->jb_pc = -1; /* No longjmp support by default.  */
> +
> +  if (!arc_tdesc_init (info, &tdesc, &tdesc_data, tdep))
> +    {
> +      xfree (tdep);
> +      return nullptr;
> +    }
> +

I would suggest to do it in a bit more C++-y way, to even avoid the xfree:

  gdb::unique_xmalloc_ptr<gdbarch_tdep> tdep (XCNEW (struct gdbarch_tdep));
  tdep->jb_pc = -1; /* No longjmp support by default.  */

  if (!arc_tdesc_init (info, &tdesc, &tdesc_data, tdep.get ()))
    return nullptr;

  struct gdbarch *gdbarch = gdbarch_alloc (&info, tdep.release ());

This way it shows clearly that this function is giving ownership of the tdep
to gdbarch_alloc.

>    struct gdbarch *gdbarch = gdbarch_alloc (&info, tdep);
>  
>    /* Data types.  */
> @@ -1987,6 +2025,13 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>    set_gdbarch_ps_regnum (gdbarch, ARC_STATUS32_REGNUM);
>    set_gdbarch_fp0_regnum (gdbarch, -1); /* No FPU registers.  */
>  
> +  /* Confirm that register name lists have proper length.  */
> +  gdb_static_assert (ARC_LAST_REGNUM + 1
> +     == (ARRAY_SIZE (core_v2_register_names)
> + + ARRAY_SIZE (aux_minimal_register_names)));
> +  gdb_static_assert (ARRAY_SIZE (core_v2_register_names)
> +     == ARRAY_SIZE (core_arcompact_register_names));

Does this need to be here?  I would expect them to be near (just after) the definitions
of said arrays.

Simon

123