1 /* GNU/Linux/Xtensa specific low level interface, for the remote server for GDB.
2 Copyright 2007-2012 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "linux-low.h"
23 /* Defined in auto-generated file reg-xtensa.c. */
24 void init_registers_xtensa (void);
26 #include <sys/ptrace.h>
27 #include <xtensa-config.h>
29 #include "xtensa-xtregs.c"
33 R_LBEG
, R_LEND
, R_LCOUNT
,
40 xtensa_fill_gregset (struct regcache
*regcache
, void *buf
)
42 elf_greg_t
* rset
= (elf_greg_t
*)buf
;
47 /* Take care of AR registers. */
49 ar0_regnum
= find_regno ("ar0");
50 ptr
= (char*)&rset
[R_A0
];
52 for (i
= ar0_regnum
; i
< ar0_regnum
+ XCHAL_NUM_AREGS
; i
++)
54 collect_register (regcache
, i
, ptr
);
55 ptr
+= register_size(i
);
58 /* Loop registers, if hardware has it. */
61 collect_register_by_name (regcache
, "lbeg", (char*)&rset
[R_LBEG
]);
62 collect_register_by_name (regcache
, "lend", (char*)&rset
[R_LEND
]);
63 collect_register_by_name (regcache
, "lcount", (char*)&rset
[R_LCOUNT
]);
66 collect_register_by_name (regcache
, "sar", (char*)&rset
[R_SAR
]);
67 collect_register_by_name (regcache
, "pc", (char*)&rset
[R_PC
]);
68 collect_register_by_name (regcache
, "ps", (char*)&rset
[R_PS
]);
69 collect_register_by_name (regcache
, "windowbase", (char*)&rset
[R_WB
]);
70 collect_register_by_name (regcache
, "windowstart", (char*)&rset
[R_WS
]);
74 xtensa_store_gregset (struct regcache
*regcache
, const void *buf
)
76 const elf_greg_t
* rset
= (const elf_greg_t
*)buf
;
81 /* Take care of AR registers. */
83 ar0_regnum
= find_regno ("ar0");
84 ptr
= (char *)&rset
[R_A0
];
86 for (i
= ar0_regnum
; i
< ar0_regnum
+ XCHAL_NUM_AREGS
; i
++)
88 supply_register (regcache
, i
, ptr
);
89 ptr
+= register_size(i
);
92 /* Loop registers, if hardware has it. */
95 supply_register_by_name (regcache
, "lbeg", (char*)&rset
[R_LBEG
]);
96 supply_register_by_name (regcache
, "lend", (char*)&rset
[R_LEND
]);
97 supply_register_by_name (regcache
, "lcount", (char*)&rset
[R_LCOUNT
]);
100 supply_register_by_name (regcache
, "sar", (char*)&rset
[R_SAR
]);
101 supply_register_by_name (regcache
, "pc", (char*)&rset
[R_PC
]);
102 supply_register_by_name (regcache
, "ps", (char*)&rset
[R_PS
]);
103 supply_register_by_name (regcache
, "windowbase", (char*)&rset
[R_WB
]);
104 supply_register_by_name (regcache
, "windowstart", (char*)&rset
[R_WS
]);
107 /* Xtensa GNU/Linux PTRACE interface includes extended register set. */
110 xtensa_fill_xtregset (struct regcache
*regcache
, void *buf
)
112 const xtensa_regtable_t
*ptr
;
114 for (ptr
= xtensa_regmap_table
; ptr
->name
; ptr
++)
116 collect_register_by_name (regcache
, ptr
->name
,
117 (char*)buf
+ ptr
->ptrace_offset
);
122 xtensa_store_xtregset (struct regcache
*regcache
, const void *buf
)
124 const xtensa_regtable_t
*ptr
;
126 for (ptr
= xtensa_regmap_table
; ptr
->name
; ptr
++)
128 supply_register_by_name (regcache
, ptr
->name
,
129 (char*)buf
+ ptr
->ptrace_offset
);
133 struct regset_info target_regsets
[] = {
134 { PTRACE_GETREGS
, PTRACE_SETREGS
, 0, sizeof (elf_gregset_t
),
136 xtensa_fill_gregset
, xtensa_store_gregset
},
137 { PTRACE_GETXTREGS
, PTRACE_SETXTREGS
, 0, XTENSA_ELF_XTREG_SIZE
,
139 xtensa_fill_xtregset
, xtensa_store_xtregset
},
140 { 0, 0, 0, -1, -1, NULL
, NULL
}
144 #define XTENSA_BREAKPOINT {0xd2,0x0f}
146 #define XTENSA_BREAKPOINT {0x2d,0xf0}
149 static const unsigned char xtensa_breakpoint
[] = XTENSA_BREAKPOINT
;
150 #define xtensa_breakpoint_len 2
153 xtensa_get_pc (struct regcache
*regcache
)
157 collect_register_by_name (regcache
, "pc", &pc
);
162 xtensa_set_pc (struct regcache
*regcache
, CORE_ADDR pc
)
164 unsigned long newpc
= pc
;
165 supply_register_by_name (regcache
, "pc", &newpc
);
169 xtensa_breakpoint_at (CORE_ADDR where
)
173 (*the_target
->read_memory
) (where
, (unsigned char *) &insn
,
174 xtensa_breakpoint_len
);
175 return memcmp((char *) &insn
,
176 xtensa_breakpoint
, xtensa_breakpoint_len
) == 0;
179 struct linux_target_ops the_low_target
= {
180 init_registers_xtensa
,
186 NULL
, /* fetch_register */
190 xtensa_breakpoint_len
,
193 xtensa_breakpoint_at
,