summaryrefslogtreecommitdiff
path: root/gdb/gdbserver/linux-arc-low.c
blob: 28c7ead3deb432c640d991d0c1b17469f9ca79ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* GNU/Linux/ARC specific low level interface, for the remote server for GDB.
   Copyright 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004
   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 2 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, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */

#include "server.h"
#include "linux-low.h"

#include <linux/user.h>

#define OFFSET(member,structure) (int)(&( ((struct structure *)0)->member ))

#define arc_num_regs 39

/* arc_regmap[i] is the offset of Ri in Linux's user struct */
static int arc_regmap[] = {
    OFFSET(r0, user_regs_struct),
    OFFSET(r1, user_regs_struct),
    OFFSET(r2, user_regs_struct),
    OFFSET(r3, user_regs_struct),
    OFFSET(r4, user_regs_struct),
    OFFSET(r5, user_regs_struct),
    OFFSET(r6, user_regs_struct),
    OFFSET(r7, user_regs_struct),
    OFFSET(r8, user_regs_struct),
    OFFSET(r9, user_regs_struct),
    OFFSET(r10, user_regs_struct),
    OFFSET(r11, user_regs_struct),
    OFFSET(r12, user_regs_struct),
    OFFSET(r13, user_regs_struct),
    OFFSET(r14, user_regs_struct),
    OFFSET(r15, user_regs_struct),
    OFFSET(r16, user_regs_struct),
    OFFSET(r17, user_regs_struct),
    OFFSET(r18, user_regs_struct),
    OFFSET(r19, user_regs_struct),
    OFFSET(r20, user_regs_struct),
    OFFSET(r21, user_regs_struct),
    OFFSET(r22, user_regs_struct),
    OFFSET(r23, user_regs_struct),
    OFFSET(r24, user_regs_struct),
    OFFSET(r25, user_regs_struct),
    OFFSET(r26, user_regs_struct),
    OFFSET(bta, user_regs_struct),
    OFFSET(lp_start, user_regs_struct),
    OFFSET(lp_end, user_regs_struct),
    OFFSET(lp_count, user_regs_struct),
    OFFSET(status32, user_regs_struct),
    OFFSET(blink, user_regs_struct),
    OFFSET(fp, user_regs_struct),
    OFFSET(sp, user_regs_struct),
    OFFSET(efa, user_regs_struct),
    OFFSET(ret, user_regs_struct),
    OFFSET(orig_r8, user_regs_struct),
    OFFSET(stop_pc, user_regs_struct)
};

static int
arc_cannot_store_register (int regno)
{
  return (regno == 35 || regno >= arc_num_regs); /* FIXME, this is dirty */
}

static int
arc_cannot_fetch_register (int regno)
{
  return (regno >= arc_num_regs);
}

extern int debug_threads;

static CORE_ADDR
arc_get_pc ()
{
  unsigned long pc;
  collect_register_by_name ("stop_pc", &pc);
  if (debug_threads)
    fprintf (stderr, "stop pc is %08lx\n", pc);
  return pc;
}

static void
arc_set_pc (CORE_ADDR pc)
{
  unsigned long newpc = pc;
  supply_register_by_name ("ret", &newpc);
}


/* trap_s 1 */
/* FIXME: dependent on target endianness */
static const unsigned long arc_breakpoint = 0x783E;
#define arc_breakpoint_len 2

static int
arc_breakpoint_at (CORE_ADDR where)
{
  unsigned long insn;

  (*the_target->read_memory) (where, (char *) &insn, arc_breakpoint_len);
  if (insn == arc_breakpoint)
    return 1;

  /* If necessary, recognize more trap instructions here.  GDB only uses the
     one.  */
  return 0;
}


/* We only place breakpoints in empty marker functions, and thread locking
   is outside of the function.  So rather than importing software single-step,
   we can just run until exit.  */
static CORE_ADDR
arc_reinsert_addr ()
{
  unsigned long pc;
  collect_register_by_name ("blink", &pc);
  return pc;
}

struct linux_target_ops the_low_target = {
  arc_num_regs,
  arc_regmap,
  arc_cannot_fetch_register,
  arc_cannot_store_register,
  arc_get_pc,
  arc_set_pc,
  (const char *) &arc_breakpoint,
  arc_breakpoint_len,
  arc_reinsert_addr,
  0,
  arc_breakpoint_at,
};