Commit | Line | Data |
---|---|---|
27fd2f50 Q |
1 | /* Target-dependent code for the S+core architecture, for GDB, |
2 | the GNU Debugger. | |
3 | ||
3666a048 | 4 | Copyright (C) 2006-2021 Free Software Foundation, Inc. |
27fd2f50 Q |
5 | |
6 | Contributed by Qinwei (qinwei@sunnorth.com.cn) | |
7 | Contributed by Ching-Peng Lin (cplin@sunplus.com) | |
8 | ||
9 | This file is part of GDB. | |
10 | ||
11 | This program is free software; you can redistribute it and/or modify | |
12 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 13 | the Free Software Foundation; either version 3 of the License, or |
27fd2f50 Q |
14 | (at your option) any later version. |
15 | ||
16 | This program is distributed in the hope that it will be useful, | |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
20 | ||
21 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 22 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
27fd2f50 Q |
23 | |
24 | #include "defs.h" | |
27fd2f50 Q |
25 | #include "inferior.h" |
26 | #include "symtab.h" | |
27 | #include "objfiles.h" | |
28 | #include "gdbcore.h" | |
29 | #include "target.h" | |
30 | #include "arch-utils.h" | |
31 | #include "regcache.h" | |
5f814c3b | 32 | #include "regset.h" |
27fd2f50 Q |
33 | #include "dis-asm.h" |
34 | #include "frame-unwind.h" | |
35 | #include "frame-base.h" | |
36 | #include "trad-frame.h" | |
82ca8957 | 37 | #include "dwarf2/frame.h" |
27fd2f50 Q |
38 | #include "score-tdep.h" |
39 | ||
5f814c3b DL |
40 | #define G_FLD(_i,_ms,_ls) \ |
41 | ((unsigned)((_i) << (31 - (_ms))) >> (31 - (_ms) + (_ls))) | |
27fd2f50 Q |
42 | |
43 | typedef struct{ | |
c378eb4e MS |
44 | unsigned long long v; |
45 | unsigned long long raw; | |
46 | unsigned int len; | |
27fd2f50 Q |
47 | }inst_t; |
48 | ||
49 | struct score_frame_cache | |
50 | { | |
51 | CORE_ADDR base; | |
5e29c264 | 52 | CORE_ADDR fp; |
098caef4 | 53 | trad_frame_saved_reg *saved_regs; |
27fd2f50 Q |
54 | }; |
55 | ||
5f814c3b | 56 | static int target_mach = bfd_mach_score7; |
5e29c264 | 57 | |
27fd2f50 Q |
58 | static struct type * |
59 | score_register_type (struct gdbarch *gdbarch, int regnum) | |
60 | { | |
5f814c3b | 61 | gdb_assert (regnum >= 0 |
dda83cd7 | 62 | && regnum < ((target_mach == bfd_mach_score7) |
c378eb4e | 63 | ? SCORE7_NUM_REGS : SCORE3_NUM_REGS)); |
df4df182 | 64 | return builtin_type (gdbarch)->builtin_uint32; |
27fd2f50 Q |
65 | } |
66 | ||
5f814c3b DL |
67 | static const char * |
68 | score7_register_name (struct gdbarch *gdbarch, int regnum) | |
27fd2f50 | 69 | { |
5f814c3b DL |
70 | const char *score_register_names[] = { |
71 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | |
72 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
73 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", | |
74 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", | |
75 | ||
76 | "PSR", "COND", "ECR", "EXCPVEC", "CCR", | |
77 | "EPC", "EMA", "TLBLOCK", "TLBPT", "PEADDR", | |
78 | "TLBRPT", "PEVN", "PECTX", "LIMPFN", "LDMPFN", | |
79 | "PREV", "DREG", "PC", "DSAVE", "COUNTER", | |
80 | "LDCR", "STCR", "CEH", "CEL", | |
81 | }; | |
82 | ||
83 | gdb_assert (regnum >= 0 && regnum < SCORE7_NUM_REGS); | |
84 | return score_register_names[regnum]; | |
27fd2f50 Q |
85 | } |
86 | ||
87 | static const char * | |
5f814c3b | 88 | score3_register_name (struct gdbarch *gdbarch, int regnum) |
27fd2f50 Q |
89 | { |
90 | const char *score_register_names[] = { | |
91 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | |
92 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
93 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", | |
94 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", | |
95 | ||
5f814c3b DL |
96 | "PSR", "COND", "ECR", "EXCPVEC", "CCR", |
97 | "EPC", "EMA", "PREV", "DREG", "DSAVE", | |
98 | "COUNTER", "LDCR", "STCR", "CEH", "CEL", | |
99 | "", "", "PC", | |
27fd2f50 Q |
100 | }; |
101 | ||
5f814c3b | 102 | gdb_assert (regnum >= 0 && regnum < SCORE3_NUM_REGS); |
27fd2f50 Q |
103 | return score_register_names[regnum]; |
104 | } | |
105 | ||
5f814c3b | 106 | #if WITH_SIM |
27fd2f50 | 107 | static int |
e7faf938 | 108 | score_register_sim_regno (struct gdbarch *gdbarch, int regnum) |
27fd2f50 | 109 | { |
5f814c3b | 110 | gdb_assert (regnum >= 0 |
dda83cd7 | 111 | && regnum < ((target_mach == bfd_mach_score7) |
c378eb4e | 112 | ? SCORE7_NUM_REGS : SCORE3_NUM_REGS)); |
27fd2f50 Q |
113 | return regnum; |
114 | } | |
5f814c3b | 115 | #endif |
27fd2f50 | 116 | |
5f814c3b | 117 | static inst_t * |
e362b510 | 118 | score7_fetch_inst (struct gdbarch *gdbarch, CORE_ADDR addr, gdb_byte *memblock) |
5f814c3b DL |
119 | { |
120 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
121 | static inst_t inst = { 0, 0, 0 }; | |
e362b510 | 122 | gdb_byte buf[SCORE_INSTLEN] = { 0 }; |
5f814c3b DL |
123 | int big; |
124 | int ret; | |
125 | ||
55f6301a | 126 | if (target_has_execution () && memblock != NULL) |
5f814c3b DL |
127 | { |
128 | /* Fetch instruction from local MEMBLOCK. */ | |
129 | memcpy (buf, memblock, SCORE_INSTLEN); | |
130 | } | |
131 | else | |
132 | { | |
133 | /* Fetch instruction from target. */ | |
134 | ret = target_read_memory (addr & ~0x3, buf, SCORE_INSTLEN); | |
135 | if (ret) | |
dda83cd7 SM |
136 | { |
137 | error (_("Error: target_read_memory in file:%s, line:%d!"), | |
138 | __FILE__, __LINE__); | |
139 | return 0; | |
140 | } | |
5f814c3b DL |
141 | } |
142 | ||
143 | inst.raw = extract_unsigned_integer (buf, SCORE_INSTLEN, byte_order); | |
144 | inst.len = (inst.raw & 0x80008000) ? 4 : 2; | |
145 | inst.v = ((inst.raw >> 16 & 0x7FFF) << 15) | (inst.raw & 0x7FFF); | |
146 | big = (byte_order == BFD_ENDIAN_BIG); | |
147 | if (inst.len == 2) | |
148 | { | |
149 | if (big ^ ((addr & 0x2) == 2)) | |
dda83cd7 | 150 | inst.v = G_FLD (inst.v, 29, 15); |
5f814c3b | 151 | else |
dda83cd7 | 152 | inst.v = G_FLD (inst.v, 14, 0); |
5f814c3b DL |
153 | } |
154 | return &inst; | |
155 | } | |
156 | ||
157 | static inst_t * | |
158 | score3_adjust_pc_and_fetch_inst (CORE_ADDR *pcptr, int *lenptr, | |
159 | enum bfd_endian byte_order) | |
160 | { | |
161 | static inst_t inst = { 0, 0, 0 }; | |
162 | ||
163 | struct breakplace | |
164 | { | |
165 | int break_offset; | |
166 | int inst_len; | |
167 | }; | |
168 | /* raw table 1 (column 2, 3, 4) | |
169 | * 0 1 0 * # 2 | |
170 | * 0 1 1 0 # 3 | |
171 | 0 1 1 0 * # 6 | |
dda83cd7 | 172 | table 2 (column 1, 2, 3) |
5f814c3b DL |
173 | * 0 0 * * # 0, 4 |
174 | 0 1 0 * * # 2 | |
175 | 1 1 0 * * # 6 | |
176 | */ | |
177 | ||
178 | static const struct breakplace bk_table[16] = | |
179 | { | |
180 | /* table 1 */ | |
181 | {0, 0}, | |
182 | {0, 0}, | |
183 | {0, 4}, | |
184 | {0, 6}, | |
185 | {0, 0}, | |
186 | {0, 0}, | |
187 | {-2, 6}, | |
188 | {0, 0}, | |
189 | /* table 2 */ | |
190 | {0, 2}, | |
191 | {0, 0}, | |
192 | {-2, 4}, | |
193 | {0, 0}, | |
194 | {0, 2}, | |
195 | {0, 0}, | |
196 | {-4, 6}, | |
197 | {0, 0} | |
198 | }; | |
199 | ||
200 | #define EXTRACT_LEN 2 | |
201 | CORE_ADDR adjust_pc = *pcptr & ~0x1; | |
5f814c3b DL |
202 | gdb_byte buf[5][EXTRACT_LEN] = |
203 | { | |
204 | {'\0', '\0'}, | |
205 | {'\0', '\0'}, | |
206 | {'\0', '\0'}, | |
207 | {'\0', '\0'}, | |
208 | {'\0', '\0'} | |
209 | }; | |
210 | int ret; | |
211 | unsigned int raw; | |
212 | unsigned int cbits = 0; | |
213 | int bk_index; | |
214 | int i, count; | |
215 | ||
216 | inst.v = 0; | |
217 | inst.raw = 0; | |
218 | inst.len = 0; | |
219 | ||
220 | adjust_pc -= 4; | |
221 | for (i = 0; i < 5; i++) | |
222 | { | |
223 | ret = target_read_memory (adjust_pc + 2 * i, buf[i], EXTRACT_LEN); | |
224 | if (ret != 0) | |
dda83cd7 SM |
225 | { |
226 | buf[i][0] = '\0'; | |
227 | buf[i][1] = '\0'; | |
5f814c3b | 228 | if (i == 2) |
dda83cd7 | 229 | error (_("Error: target_read_memory in file:%s, line:%d!"), |
5f814c3b | 230 | __FILE__, __LINE__); |
dda83cd7 | 231 | } |
5f814c3b DL |
232 | |
233 | raw = extract_unsigned_integer (buf[i], EXTRACT_LEN, byte_order); | |
234 | cbits = (cbits << 1) | (raw >> 15); | |
235 | } | |
236 | adjust_pc += 4; | |
237 | ||
238 | if (cbits & 0x4) | |
239 | { | |
240 | /* table 1 */ | |
241 | cbits = (cbits >> 1) & 0x7; | |
242 | bk_index = cbits; | |
243 | } | |
244 | else | |
245 | { | |
246 | /* table 2 */ | |
247 | cbits = (cbits >> 2) & 0x7; | |
248 | bk_index = cbits + 8; | |
249 | } | |
250 | ||
251 | gdb_assert (!((bk_table[bk_index].break_offset == 0) | |
252 | && (bk_table[bk_index].inst_len == 0))); | |
253 | ||
254 | inst.len = bk_table[bk_index].inst_len; | |
255 | ||
256 | i = (bk_table[bk_index].break_offset + 4) / 2; | |
257 | count = inst.len / 2; | |
258 | for (; count > 0; i++, count--) | |
259 | { | |
260 | inst.raw = (inst.raw << 16) | |
dda83cd7 | 261 | | extract_unsigned_integer (buf[i], EXTRACT_LEN, byte_order); |
5f814c3b DL |
262 | } |
263 | ||
264 | switch (inst.len) | |
265 | { | |
266 | case 2: | |
267 | inst.v = inst.raw & 0x7FFF; | |
268 | break; | |
269 | case 4: | |
270 | inst.v = ((inst.raw >> 16 & 0x7FFF) << 15) | (inst.raw & 0x7FFF); | |
271 | break; | |
272 | case 6: | |
273 | inst.v = ((inst.raw >> 32 & 0x7FFF) << 30) | |
274 | | ((inst.raw >> 16 & 0x7FFF) << 15) | (inst.raw & 0x7FFF); | |
275 | break; | |
276 | } | |
277 | ||
278 | if (pcptr) | |
279 | *pcptr = adjust_pc + bk_table[bk_index].break_offset; | |
280 | if (lenptr) | |
281 | *lenptr = bk_table[bk_index].inst_len; | |
282 | ||
283 | #undef EXTRACT_LEN | |
284 | ||
285 | return &inst; | |
286 | } | |
287 | ||
cd6c3b4f YQ |
288 | /* Implement the breakpoint_kind_from_pc gdbarch method. */ |
289 | ||
d19280ad YQ |
290 | static int |
291 | score7_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr) | |
27fd2f50 | 292 | { |
27fd2f50 Q |
293 | int ret; |
294 | unsigned int raw; | |
d19280ad YQ |
295 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
296 | gdb_byte buf[SCORE_INSTLEN] = { 0 }; | |
27fd2f50 Q |
297 | |
298 | if ((ret = target_read_memory (*pcptr & ~0x3, buf, SCORE_INSTLEN)) != 0) | |
299 | { | |
a73c6dcd | 300 | error (_("Error: target_read_memory in file:%s, line:%d!"), |
d19280ad | 301 | __FILE__, __LINE__); |
27fd2f50 | 302 | } |
e17a4113 | 303 | raw = extract_unsigned_integer (buf, SCORE_INSTLEN, byte_order); |
27fd2f50 | 304 | |
d19280ad | 305 | if (!(raw & 0x80008000)) |
27fd2f50 | 306 | { |
d19280ad YQ |
307 | /* 16bits instruction. */ |
308 | *pcptr &= ~0x1; | |
309 | return 2; | |
310 | } | |
311 | else | |
312 | { | |
313 | /* 32bits instruction. */ | |
314 | *pcptr &= ~0x3; | |
315 | return 4; | |
316 | } | |
317 | } | |
318 | ||
cd6c3b4f YQ |
319 | /* Implement the sw_breakpoint_from_kind gdbarch method. */ |
320 | ||
d19280ad YQ |
321 | static const gdb_byte * |
322 | score7_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size) | |
323 | { | |
324 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
325 | ||
326 | *size = kind; | |
327 | ||
328 | if (kind == 4) | |
329 | { | |
330 | static gdb_byte big_breakpoint32[] = { 0x80, 0x00, 0x80, 0x06 }; | |
331 | static gdb_byte little_breakpoint32[] = { 0x06, 0x80, 0x00, 0x80 }; | |
332 | ||
333 | if (byte_order == BFD_ENDIAN_BIG) | |
334 | return big_breakpoint32; | |
27fd2f50 | 335 | else |
d19280ad | 336 | return little_breakpoint32; |
27fd2f50 Q |
337 | } |
338 | else | |
339 | { | |
d19280ad YQ |
340 | static gdb_byte big_breakpoint16[] = { 0x60, 0x02 }; |
341 | static gdb_byte little_breakpoint16[] = { 0x02, 0x60 }; | |
342 | ||
343 | if (byte_order == BFD_ENDIAN_BIG) | |
344 | return big_breakpoint16; | |
27fd2f50 | 345 | else |
d19280ad | 346 | return little_breakpoint16; |
27fd2f50 Q |
347 | } |
348 | } | |
349 | ||
cd6c3b4f YQ |
350 | /* Implement the breakpoint_kind_from_pc gdbarch method. */ |
351 | ||
d19280ad YQ |
352 | static int |
353 | score3_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr) | |
5f814c3b DL |
354 | { |
355 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
5f814c3b | 356 | int len; |
d19280ad YQ |
357 | |
358 | score3_adjust_pc_and_fetch_inst (pcptr, &len, byte_order); | |
359 | ||
360 | return len; | |
361 | } | |
362 | ||
cd6c3b4f YQ |
363 | /* Implement the sw_breakpoint_from_kind gdbarch method. */ |
364 | ||
d19280ad YQ |
365 | static const gdb_byte * |
366 | score3_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size) | |
367 | { | |
368 | int index = 0; | |
369 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
5f814c3b DL |
370 | static gdb_byte score_break_insns[6][6] = { |
371 | /* The following three instructions are big endian. */ | |
372 | { 0x00, 0x20 }, | |
373 | { 0x80, 0x00, 0x00, 0x06 }, | |
374 | { 0x80, 0x00, 0x80, 0x00, 0x00, 0x00 }, | |
375 | /* The following three instructions are little endian. */ | |
376 | { 0x20, 0x00 }, | |
377 | { 0x00, 0x80, 0x06, 0x00 }, | |
378 | { 0x00, 0x80, 0x00, 0x80, 0x00, 0x00 }}; | |
379 | ||
d19280ad | 380 | *size = kind; |
5f814c3b | 381 | |
d19280ad YQ |
382 | index = ((byte_order == BFD_ENDIAN_BIG) ? 0 : 3) + (kind / 2 - 1); |
383 | return score_break_insns[index]; | |
5f814c3b DL |
384 | } |
385 | ||
386 | static CORE_ADDR | |
387 | score_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr) | |
388 | { | |
389 | CORE_ADDR adjust_pc = bpaddr; | |
390 | ||
391 | if (target_mach == bfd_mach_score3) | |
392 | score3_adjust_pc_and_fetch_inst (&adjust_pc, NULL, | |
393 | gdbarch_byte_order (gdbarch)); | |
394 | else | |
395 | adjust_pc = align_down (adjust_pc, 2); | |
396 | ||
397 | return adjust_pc; | |
398 | } | |
399 | ||
27fd2f50 Q |
400 | static CORE_ADDR |
401 | score_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) | |
402 | { | |
403 | return align_down (addr, 16); | |
404 | } | |
405 | ||
406 | static void | |
407 | score_xfer_register (struct regcache *regcache, int regnum, int length, | |
dda83cd7 SM |
408 | enum bfd_endian endian, gdb_byte *readbuf, |
409 | const gdb_byte *writebuf, int buf_offset) | |
27fd2f50 Q |
410 | { |
411 | int reg_offset = 0; | |
5f814c3b | 412 | gdb_assert (regnum >= 0 |
dda83cd7 | 413 | && regnum < ((target_mach == bfd_mach_score7) |
c378eb4e | 414 | ? SCORE7_NUM_REGS : SCORE3_NUM_REGS)); |
27fd2f50 Q |
415 | |
416 | switch (endian) | |
417 | { | |
418 | case BFD_ENDIAN_BIG: | |
419 | reg_offset = SCORE_REGSIZE - length; | |
420 | break; | |
421 | case BFD_ENDIAN_LITTLE: | |
422 | reg_offset = 0; | |
423 | break; | |
424 | case BFD_ENDIAN_UNKNOWN: | |
425 | reg_offset = 0; | |
426 | break; | |
427 | default: | |
a73c6dcd | 428 | error (_("Error: score_xfer_register in file:%s, line:%d!"), |
dda83cd7 | 429 | __FILE__, __LINE__); |
27fd2f50 Q |
430 | } |
431 | ||
432 | if (readbuf != NULL) | |
73bb0000 SM |
433 | regcache->cooked_read_part (regnum, reg_offset, length, |
434 | readbuf + buf_offset); | |
27fd2f50 | 435 | if (writebuf != NULL) |
e4c4a59b SM |
436 | regcache->cooked_write_part (regnum, reg_offset, length, |
437 | writebuf + buf_offset); | |
27fd2f50 Q |
438 | } |
439 | ||
440 | static enum return_value_convention | |
6a3a010b | 441 | score_return_value (struct gdbarch *gdbarch, struct value *function, |
dda83cd7 SM |
442 | struct type *type, struct regcache *regcache, |
443 | gdb_byte * readbuf, const gdb_byte * writebuf) | |
27fd2f50 | 444 | { |
78134374 SM |
445 | if (type->code () == TYPE_CODE_STRUCT |
446 | || type->code () == TYPE_CODE_UNION | |
447 | || type->code () == TYPE_CODE_ARRAY) | |
27fd2f50 Q |
448 | return RETURN_VALUE_STRUCT_CONVENTION; |
449 | else | |
450 | { | |
451 | int offset; | |
452 | int regnum; | |
453 | for (offset = 0, regnum = SCORE_A0_REGNUM; | |
dda83cd7 SM |
454 | offset < TYPE_LENGTH (type); |
455 | offset += SCORE_REGSIZE, regnum++) | |
456 | { | |
457 | int xfer = SCORE_REGSIZE; | |
458 | ||
459 | if (offset + xfer > TYPE_LENGTH (type)) | |
460 | xfer = TYPE_LENGTH (type) - offset; | |
461 | score_xfer_register (regcache, regnum, xfer, | |
5f814c3b | 462 | gdbarch_byte_order(gdbarch), |
dda83cd7 SM |
463 | readbuf, writebuf, offset); |
464 | } | |
27fd2f50 Q |
465 | return RETURN_VALUE_REGISTER_CONVENTION; |
466 | } | |
467 | } | |
468 | ||
27fd2f50 Q |
469 | static int |
470 | score_type_needs_double_align (struct type *type) | |
471 | { | |
78134374 | 472 | enum type_code typecode = type->code (); |
27fd2f50 | 473 | |
5e29c264 Q |
474 | if ((typecode == TYPE_CODE_INT && TYPE_LENGTH (type) == 8) |
475 | || (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)) | |
27fd2f50 Q |
476 | return 1; |
477 | else if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION) | |
478 | { | |
479 | int i, n; | |
480 | ||
1f704f76 | 481 | n = type->num_fields (); |
27fd2f50 | 482 | for (i = 0; i < n; i++) |
dda83cd7 SM |
483 | if (score_type_needs_double_align (type->field (i).type ())) |
484 | return 1; | |
27fd2f50 Q |
485 | return 0; |
486 | } | |
487 | return 0; | |
488 | } | |
489 | ||
490 | static CORE_ADDR | |
491 | score_push_dummy_call (struct gdbarch *gdbarch, struct value *function, | |
dda83cd7 SM |
492 | struct regcache *regcache, CORE_ADDR bp_addr, |
493 | int nargs, struct value **args, CORE_ADDR sp, | |
cf84fa6b AH |
494 | function_call_return_method return_method, |
495 | CORE_ADDR struct_addr) | |
27fd2f50 | 496 | { |
e17a4113 | 497 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
27fd2f50 Q |
498 | int argnum; |
499 | int argreg; | |
500 | int arglen = 0; | |
501 | CORE_ADDR stack_offset = 0; | |
502 | CORE_ADDR addr = 0; | |
503 | ||
504 | /* Step 1, Save RA. */ | |
505 | regcache_cooked_write_unsigned (regcache, SCORE_RA_REGNUM, bp_addr); | |
506 | ||
507 | /* Step 2, Make space on the stack for the args. */ | |
508 | struct_addr = align_down (struct_addr, 16); | |
509 | sp = align_down (sp, 16); | |
510 | for (argnum = 0; argnum < nargs; argnum++) | |
511 | arglen += align_up (TYPE_LENGTH (value_type (args[argnum])), | |
dda83cd7 | 512 | SCORE_REGSIZE); |
27fd2f50 Q |
513 | sp -= align_up (arglen, 16); |
514 | ||
515 | argreg = SCORE_BEGIN_ARG_REGNUM; | |
516 | ||
5e29c264 Q |
517 | /* Step 3, Check if struct return then save the struct address to |
518 | r4 and increase the stack_offset by 4. */ | |
cf84fa6b | 519 | if (return_method == return_method_struct) |
27fd2f50 Q |
520 | { |
521 | regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); | |
522 | stack_offset += SCORE_REGSIZE; | |
523 | } | |
524 | ||
525 | /* Step 4, Load arguments: | |
5e29c264 Q |
526 | If arg length is too long (> 4 bytes), then split the arg and |
527 | save every parts. */ | |
27fd2f50 Q |
528 | for (argnum = 0; argnum < nargs; argnum++) |
529 | { | |
530 | struct value *arg = args[argnum]; | |
531 | struct type *arg_type = check_typedef (value_type (arg)); | |
78134374 | 532 | enum type_code typecode = arg_type->code (); |
27fd2f50 Q |
533 | const gdb_byte *val = value_contents (arg); |
534 | int downward_offset = 0; | |
1cfd2c3e | 535 | int arg_last_part_p = 0; |
27fd2f50 | 536 | |
1cfd2c3e | 537 | arglen = TYPE_LENGTH (arg_type); |
27fd2f50 Q |
538 | |
539 | /* If a arg should be aligned to 8 bytes (long long or double), | |
dda83cd7 | 540 | the value should be put to even register numbers. */ |
27fd2f50 | 541 | if (score_type_needs_double_align (arg_type)) |
dda83cd7 SM |
542 | { |
543 | if (argreg & 1) | |
544 | argreg++; | |
545 | } | |
27fd2f50 Q |
546 | |
547 | /* If sizeof a block < SCORE_REGSIZE, then Score GCC will chose | |
dda83cd7 | 548 | the default "downward"/"upward" method: |
27fd2f50 | 549 | |
dda83cd7 | 550 | Example: |
27fd2f50 | 551 | |
dda83cd7 SM |
552 | struct struc |
553 | { | |
554 | char a; char b; char c; | |
555 | } s = {'a', 'b', 'c'}; | |
27fd2f50 | 556 | |
dda83cd7 SM |
557 | Big endian: s = {X, 'a', 'b', 'c'} |
558 | Little endian: s = {'a', 'b', 'c', X} | |
27fd2f50 | 559 | |
dda83cd7 | 560 | Where X is a hole. */ |
27fd2f50 | 561 | |
5f814c3b | 562 | if (gdbarch_byte_order(gdbarch) == BFD_ENDIAN_BIG |
dda83cd7 SM |
563 | && (typecode == TYPE_CODE_STRUCT |
564 | || typecode == TYPE_CODE_UNION) | |
565 | && argreg > SCORE_LAST_ARG_REGNUM | |
566 | && arglen < SCORE_REGSIZE) | |
567 | downward_offset += (SCORE_REGSIZE - arglen); | |
27fd2f50 Q |
568 | |
569 | while (arglen > 0) | |
dda83cd7 SM |
570 | { |
571 | int partial_len = arglen < SCORE_REGSIZE ? arglen : SCORE_REGSIZE; | |
572 | ULONGEST regval = extract_unsigned_integer (val, partial_len, | |
5f814c3b | 573 | byte_order); |
27fd2f50 | 574 | |
dda83cd7 SM |
575 | /* The last part of a arg should shift left when |
576 | gdbarch_byte_order is BFD_ENDIAN_BIG. */ | |
577 | if (byte_order == BFD_ENDIAN_BIG | |
578 | && arg_last_part_p == 1 | |
579 | && (typecode == TYPE_CODE_STRUCT | |
580 | || typecode == TYPE_CODE_UNION)) | |
581 | regval <<= ((SCORE_REGSIZE - partial_len) * TARGET_CHAR_BIT); | |
582 | ||
583 | /* Always increase the stack_offset and save args to stack. */ | |
584 | addr = sp + stack_offset + downward_offset; | |
585 | write_memory (addr, val, partial_len); | |
586 | ||
587 | if (argreg <= SCORE_LAST_ARG_REGNUM) | |
588 | { | |
589 | regcache_cooked_write_unsigned (regcache, argreg++, regval); | |
590 | if (arglen > SCORE_REGSIZE && arglen < SCORE_REGSIZE * 2) | |
591 | arg_last_part_p = 1; | |
592 | } | |
593 | ||
594 | val += partial_len; | |
595 | arglen -= partial_len; | |
596 | stack_offset += align_up (partial_len, SCORE_REGSIZE); | |
597 | } | |
27fd2f50 Q |
598 | } |
599 | ||
600 | /* Step 5, Save SP. */ | |
601 | regcache_cooked_write_unsigned (regcache, SCORE_SP_REGNUM, sp); | |
602 | ||
603 | return sp; | |
604 | } | |
605 | ||
27fd2f50 | 606 | static CORE_ADDR |
5f814c3b | 607 | score7_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) |
27fd2f50 Q |
608 | { |
609 | CORE_ADDR cpc = pc; | |
610 | int iscan = 32, stack_sub = 0; | |
611 | while (iscan-- > 0) | |
612 | { | |
5f814c3b | 613 | inst_t *inst = score7_fetch_inst (gdbarch, cpc, NULL); |
27fd2f50 | 614 | if (!inst) |
dda83cd7 | 615 | break; |
5f814c3b | 616 | if ((inst->len == 4) && !stack_sub |
dda83cd7 SM |
617 | && (G_FLD (inst->v, 29, 25) == 0x1 |
618 | && G_FLD (inst->v, 24, 20) == 0x0)) | |
619 | { | |
620 | /* addi r0, offset */ | |
621 | stack_sub = cpc + SCORE_INSTLEN; | |
622 | pc = cpc + SCORE_INSTLEN; | |
623 | } | |
5f814c3b | 624 | else if ((inst->len == 4) |
dda83cd7 SM |
625 | && (G_FLD (inst->v, 29, 25) == 0x0) |
626 | && (G_FLD (inst->v, 24, 20) == 0x2) | |
627 | && (G_FLD (inst->v, 19, 15) == 0x0) | |
628 | && (G_FLD (inst->v, 14, 10) == 0xF) | |
629 | && (G_FLD (inst->v, 9, 0) == 0x56)) | |
630 | { | |
631 | /* mv r2, r0 */ | |
632 | pc = cpc + SCORE_INSTLEN; | |
633 | break; | |
634 | } | |
5f814c3b | 635 | else if ((inst->len == 2) |
dda83cd7 SM |
636 | && (G_FLD (inst->v, 14, 12) == 0x0) |
637 | && (G_FLD (inst->v, 11, 8) == 0x2) | |
638 | && (G_FLD (inst->v, 7, 4) == 0x0) | |
639 | && (G_FLD (inst->v, 3, 0) == 0x3)) | |
640 | { | |
641 | /* mv! r2, r0 */ | |
642 | pc = cpc + SCORE16_INSTLEN; | |
643 | break; | |
644 | } | |
5f814c3b | 645 | else if ((inst->len == 2) |
dda83cd7 SM |
646 | && ((G_FLD (inst->v, 14, 12) == 3) /* j15 form */ |
647 | || (G_FLD (inst->v, 14, 12) == 4) /* b15 form */ | |
648 | || (G_FLD (inst->v, 14, 12) == 0x0 | |
649 | && G_FLD (inst->v, 3, 0) == 0x4))) /* br! */ | |
650 | break; | |
5f814c3b | 651 | else if ((inst->len == 4) |
dda83cd7 SM |
652 | && ((G_FLD (inst->v, 29, 25) == 2) /* j32 form */ |
653 | || (G_FLD (inst->v, 29, 25) == 4) /* b32 form */ | |
654 | || (G_FLD (inst->v, 29, 25) == 0x0 | |
655 | && G_FLD (inst->v, 6, 1) == 0x4))) /* br */ | |
656 | break; | |
27fd2f50 | 657 | |
5f814c3b | 658 | cpc += (inst->len == 2) ? SCORE16_INSTLEN : SCORE_INSTLEN; |
27fd2f50 Q |
659 | } |
660 | return pc; | |
661 | } | |
662 | ||
5f814c3b DL |
663 | static CORE_ADDR |
664 | score3_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) | |
27fd2f50 | 665 | { |
5f814c3b DL |
666 | CORE_ADDR cpc = pc; |
667 | int iscan = 32, stack_sub = 0; | |
668 | while (iscan-- > 0) | |
669 | { | |
670 | inst_t *inst | |
c378eb4e MS |
671 | = score3_adjust_pc_and_fetch_inst (&cpc, NULL, |
672 | gdbarch_byte_order (gdbarch)); | |
27fd2f50 | 673 | |
5f814c3b | 674 | if (!inst) |
dda83cd7 | 675 | break; |
5f814c3b | 676 | if (inst->len == 4 && !stack_sub |
dda83cd7 SM |
677 | && (G_FLD (inst->v, 29, 25) == 0x1) |
678 | && (G_FLD (inst->v, 19, 17) == 0x0) | |
5f814c3b | 679 | && (G_FLD (inst->v, 24, 20) == 0x0)) |
dda83cd7 SM |
680 | { |
681 | /* addi r0, offset */ | |
682 | stack_sub = cpc + inst->len; | |
683 | pc = cpc + inst->len; | |
684 | } | |
5f814c3b | 685 | else if (inst->len == 4 |
dda83cd7 | 686 | && (G_FLD (inst->v, 29, 25) == 0x0) |
5f814c3b DL |
687 | && (G_FLD (inst->v, 24, 20) == 0x2) |
688 | && (G_FLD (inst->v, 19, 15) == 0x0) | |
689 | && (G_FLD (inst->v, 14, 10) == 0xF) | |
690 | && (G_FLD (inst->v, 9, 0) == 0x56)) | |
dda83cd7 SM |
691 | { |
692 | /* mv r2, r0 */ | |
693 | pc = cpc + inst->len; | |
694 | break; | |
695 | } | |
5f814c3b | 696 | else if ((inst->len == 2) |
dda83cd7 SM |
697 | && (G_FLD (inst->v, 14, 10) == 0x10) |
698 | && (G_FLD (inst->v, 9, 5) == 0x2) | |
5f814c3b | 699 | && (G_FLD (inst->v, 4, 0) == 0x0)) |
dda83cd7 SM |
700 | { |
701 | /* mv! r2, r0 */ | |
702 | pc = cpc + inst->len; | |
703 | break; | |
704 | } | |
5f814c3b | 705 | else if (inst->len == 2 |
dda83cd7 SM |
706 | && ((G_FLD (inst->v, 14, 12) == 3) /* b15 form */ |
707 | || (G_FLD (inst->v, 14, 12) == 0x0 | |
708 | && G_FLD (inst->v, 11, 5) == 0x4))) /* br! */ | |
709 | break; | |
5f814c3b | 710 | else if (inst->len == 4 |
dda83cd7 SM |
711 | && ((G_FLD (inst->v, 29, 25) == 2) /* j32 form */ |
712 | || (G_FLD (inst->v, 29, 25) == 4))) /* b32 form */ | |
713 | break; | |
5f814c3b DL |
714 | |
715 | cpc += inst->len; | |
716 | } | |
717 | return pc; | |
718 | } | |
719 | ||
c9cf6e20 MG |
720 | /* Implement the stack_frame_destroyed_p gdbarch method. */ |
721 | ||
5f814c3b | 722 | static int |
c9cf6e20 | 723 | score7_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR cur_pc) |
5f814c3b DL |
724 | { |
725 | inst_t *inst = score7_fetch_inst (gdbarch, cur_pc, NULL); | |
726 | ||
727 | if (inst->v == 0x23) | |
728 | return 1; /* mv! r0, r2 */ | |
729 | else if (G_FLD (inst->v, 14, 12) == 0x2 | |
dda83cd7 | 730 | && G_FLD (inst->v, 3, 0) == 0xa) |
5f814c3b | 731 | return 1; /* pop! */ |
27fd2f50 | 732 | else if (G_FLD (inst->v, 14, 12) == 0x0 |
dda83cd7 | 733 | && G_FLD (inst->v, 7, 0) == 0x34) |
27fd2f50 Q |
734 | return 1; /* br! r3 */ |
735 | else if (G_FLD (inst->v, 29, 15) == 0x2 | |
dda83cd7 | 736 | && G_FLD (inst->v, 6, 1) == 0x2b) |
27fd2f50 Q |
737 | return 1; /* mv r0, r2 */ |
738 | else if (G_FLD (inst->v, 29, 25) == 0x0 | |
dda83cd7 SM |
739 | && G_FLD (inst->v, 6, 1) == 0x4 |
740 | && G_FLD (inst->v, 19, 15) == 0x3) | |
27fd2f50 Q |
741 | return 1; /* br r3 */ |
742 | else | |
743 | return 0; | |
744 | } | |
745 | ||
c9cf6e20 MG |
746 | /* Implement the stack_frame_destroyed_p gdbarch method. */ |
747 | ||
5f814c3b | 748 | static int |
c9cf6e20 | 749 | score3_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR cur_pc) |
5f814c3b DL |
750 | { |
751 | CORE_ADDR pc = cur_pc; | |
752 | inst_t *inst | |
c378eb4e MS |
753 | = score3_adjust_pc_and_fetch_inst (&pc, NULL, |
754 | gdbarch_byte_order (gdbarch)); | |
5f814c3b DL |
755 | |
756 | if (inst->len == 2 | |
757 | && (G_FLD (inst->v, 14, 10) == 0x10) | |
758 | && (G_FLD (inst->v, 9, 5) == 0x0) | |
759 | && (G_FLD (inst->v, 4, 0) == 0x2)) | |
760 | return 1; /* mv! r0, r2 */ | |
761 | else if (inst->len == 4 | |
dda83cd7 SM |
762 | && (G_FLD (inst->v, 29, 25) == 0x0) |
763 | && (G_FLD (inst->v, 24, 20) == 0x2) | |
764 | && (G_FLD (inst->v, 19, 15) == 0x0) | |
5f814c3b DL |
765 | && (G_FLD (inst->v, 14, 10) == 0xF) |
766 | && (G_FLD (inst->v, 9, 0) == 0x56)) | |
767 | return 1; /* mv r0, r2 */ | |
768 | else if (inst->len == 2 | |
dda83cd7 SM |
769 | && (G_FLD (inst->v, 14, 12) == 0x0) |
770 | && (G_FLD (inst->v, 11, 5) == 0x2)) | |
5f814c3b DL |
771 | return 1; /* pop! */ |
772 | else if (inst->len == 2 | |
dda83cd7 SM |
773 | && (G_FLD (inst->v, 14, 12) == 0x0) |
774 | && (G_FLD (inst->v, 11, 7) == 0x0) | |
775 | && (G_FLD (inst->v, 6, 5) == 0x2)) | |
5f814c3b DL |
776 | return 1; /* rpop! */ |
777 | else if (inst->len == 2 | |
dda83cd7 SM |
778 | && (G_FLD (inst->v, 14, 12) == 0x0) |
779 | && (G_FLD (inst->v, 11, 5) == 0x4) | |
780 | && (G_FLD (inst->v, 4, 0) == 0x3)) | |
5f814c3b DL |
781 | return 1; /* br! r3 */ |
782 | else if (inst->len == 4 | |
dda83cd7 SM |
783 | && (G_FLD (inst->v, 29, 25) == 0x0) |
784 | && (G_FLD (inst->v, 24, 20) == 0x0) | |
785 | && (G_FLD (inst->v, 19, 15) == 0x3) | |
786 | && (G_FLD (inst->v, 14, 10) == 0xF) | |
787 | && (G_FLD (inst->v, 9, 0) == 0x8)) | |
5f814c3b DL |
788 | return 1; /* br r3 */ |
789 | else | |
790 | return 0; | |
791 | } | |
792 | ||
e362b510 | 793 | static gdb_byte * |
5f814c3b DL |
794 | score7_malloc_and_get_memblock (CORE_ADDR addr, CORE_ADDR size) |
795 | { | |
796 | int ret; | |
e362b510 | 797 | gdb_byte *memblock = NULL; |
5f814c3b | 798 | |
d66ff635 | 799 | if (size == 0) |
5f814c3b DL |
800 | return NULL; |
801 | ||
224c3ddb | 802 | memblock = (gdb_byte *) xmalloc (size); |
5f814c3b DL |
803 | memset (memblock, 0, size); |
804 | ret = target_read_memory (addr & ~0x3, memblock, size); | |
805 | if (ret) | |
806 | { | |
a73c6dcd | 807 | error (_("Error: target_read_memory in file:%s, line:%d!"), |
dda83cd7 | 808 | __FILE__, __LINE__); |
5f814c3b DL |
809 | return NULL; |
810 | } | |
811 | return memblock; | |
812 | } | |
813 | ||
27fd2f50 | 814 | static void |
948f8e3d | 815 | score7_free_memblock (gdb_byte *memblock) |
5f814c3b DL |
816 | { |
817 | xfree (memblock); | |
818 | } | |
819 | ||
820 | static void | |
e362b510 | 821 | score7_adjust_memblock_ptr (gdb_byte **memblock, CORE_ADDR prev_pc, |
dda83cd7 | 822 | CORE_ADDR cur_pc) |
5f814c3b DL |
823 | { |
824 | if (prev_pc == -1) | |
825 | { | |
826 | /* First time call this function, do nothing. */ | |
827 | } | |
828 | else if (cur_pc - prev_pc == 2 && (cur_pc & 0x3) == 0) | |
829 | { | |
830 | /* First 16-bit instruction, then 32-bit instruction. */ | |
831 | *memblock += SCORE_INSTLEN; | |
832 | } | |
833 | else if (cur_pc - prev_pc == 4) | |
834 | { | |
835 | /* Is 32-bit instruction, increase MEMBLOCK by 4. */ | |
836 | *memblock += SCORE_INSTLEN; | |
837 | } | |
838 | } | |
839 | ||
840 | static void | |
841 | score7_analyze_prologue (CORE_ADDR startaddr, CORE_ADDR pc, | |
dda83cd7 SM |
842 | struct frame_info *this_frame, |
843 | struct score_frame_cache *this_cache) | |
27fd2f50 | 844 | { |
94afd7a6 | 845 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
27fd2f50 | 846 | CORE_ADDR sp; |
5e29c264 | 847 | CORE_ADDR fp; |
27fd2f50 Q |
848 | CORE_ADDR cur_pc = startaddr; |
849 | ||
850 | int sp_offset = 0; | |
851 | int ra_offset = 0; | |
852 | int fp_offset = 0; | |
853 | int ra_offset_p = 0; | |
854 | int fp_offset_p = 0; | |
855 | int inst_len = 0; | |
856 | ||
e362b510 PA |
857 | gdb_byte *memblock = NULL; |
858 | gdb_byte *memblock_ptr = NULL; | |
5e29c264 Q |
859 | CORE_ADDR prev_pc = -1; |
860 | ||
861 | /* Allocate MEMBLOCK if PC - STARTADDR > 0. */ | |
862 | memblock_ptr = memblock = | |
5f814c3b | 863 | score7_malloc_and_get_memblock (startaddr, pc - startaddr); |
5e29c264 | 864 | |
94afd7a6 UW |
865 | sp = get_frame_register_unsigned (this_frame, SCORE_SP_REGNUM); |
866 | fp = get_frame_register_unsigned (this_frame, SCORE_FP_REGNUM); | |
27fd2f50 | 867 | |
5e29c264 | 868 | for (; cur_pc < pc; prev_pc = cur_pc, cur_pc += inst_len) |
27fd2f50 | 869 | { |
5e29c264 Q |
870 | inst_t *inst = NULL; |
871 | if (memblock != NULL) | |
dda83cd7 SM |
872 | { |
873 | /* Reading memory block from target successfully and got all | |
874 | the instructions(from STARTADDR to PC) needed. */ | |
875 | score7_adjust_memblock_ptr (&memblock, prev_pc, cur_pc); | |
876 | inst = score7_fetch_inst (gdbarch, cur_pc, memblock); | |
877 | } | |
5e29c264 | 878 | else |
dda83cd7 SM |
879 | { |
880 | /* Otherwise, we fetch 4 bytes from target, and GDB also | |
881 | work correctly. */ | |
882 | inst = score7_fetch_inst (gdbarch, cur_pc, NULL); | |
883 | } | |
5e29c264 | 884 | |
c378eb4e | 885 | /* FIXME: make a full-power prologue analyzer. */ |
5f814c3b | 886 | if (inst->len == 2) |
dda83cd7 SM |
887 | { |
888 | inst_len = SCORE16_INSTLEN; | |
889 | ||
890 | if (G_FLD (inst->v, 14, 12) == 0x2 | |
891 | && G_FLD (inst->v, 3, 0) == 0xe) | |
892 | { | |
893 | /* push! */ | |
894 | sp_offset += 4; | |
895 | ||
896 | if (G_FLD (inst->v, 11, 7) == 0x6 | |
897 | && ra_offset_p == 0) | |
898 | { | |
899 | /* push! r3, [r0] */ | |
900 | ra_offset = sp_offset; | |
901 | ra_offset_p = 1; | |
902 | } | |
903 | else if (G_FLD (inst->v, 11, 7) == 0x4 | |
904 | && fp_offset_p == 0) | |
905 | { | |
906 | /* push! r2, [r0] */ | |
907 | fp_offset = sp_offset; | |
908 | fp_offset_p = 1; | |
909 | } | |
910 | } | |
911 | else if (G_FLD (inst->v, 14, 12) == 0x2 | |
912 | && G_FLD (inst->v, 3, 0) == 0xa) | |
913 | { | |
914 | /* pop! */ | |
915 | sp_offset -= 4; | |
916 | } | |
917 | else if (G_FLD (inst->v, 14, 7) == 0xc1 | |
918 | && G_FLD (inst->v, 2, 0) == 0x0) | |
919 | { | |
920 | /* subei! r0, n */ | |
921 | sp_offset += (int) pow (2.0, G_FLD (inst->v, 6, 3)); | |
922 | } | |
923 | else if (G_FLD (inst->v, 14, 7) == 0xc0 | |
924 | && G_FLD (inst->v, 2, 0) == 0x0) | |
925 | { | |
926 | /* addei! r0, n */ | |
d411762c CB |
927 | /* Solaris 11+gcc 5.5 has ambiguous overloads of pow, so we |
928 | pass 2.0 instead of 2 to get the right one. */ | |
dda83cd7 SM |
929 | sp_offset -= (int) pow (2.0, G_FLD (inst->v, 6, 3)); |
930 | } | |
931 | } | |
27fd2f50 | 932 | else |
dda83cd7 SM |
933 | { |
934 | inst_len = SCORE_INSTLEN; | |
935 | ||
936 | if (G_FLD(inst->v, 29, 25) == 0x3 | |
937 | && G_FLD(inst->v, 2, 0) == 0x4 | |
938 | && G_FLD(inst->v, 19, 15) == 0) | |
939 | { | |
940 | /* sw rD, [r0, offset]+ */ | |
941 | sp_offset += SCORE_INSTLEN; | |
942 | ||
943 | if (G_FLD(inst->v, 24, 20) == 0x3) | |
944 | { | |
945 | /* rD = r3 */ | |
946 | if (ra_offset_p == 0) | |
947 | { | |
948 | ra_offset = sp_offset; | |
949 | ra_offset_p = 1; | |
950 | } | |
951 | } | |
952 | else if (G_FLD(inst->v, 24, 20) == 0x2) | |
953 | { | |
954 | /* rD = r2 */ | |
955 | if (fp_offset_p == 0) | |
956 | { | |
957 | fp_offset = sp_offset; | |
958 | fp_offset_p = 1; | |
959 | } | |
960 | } | |
961 | } | |
962 | else if (G_FLD(inst->v, 29, 25) == 0x14 | |
963 | && G_FLD(inst->v, 19,15) == 0) | |
964 | { | |
965 | /* sw rD, [r0, offset] */ | |
966 | if (G_FLD(inst->v, 24, 20) == 0x3) | |
967 | { | |
968 | /* rD = r3 */ | |
969 | ra_offset = sp_offset - G_FLD(inst->v, 14, 0); | |
970 | ra_offset_p = 1; | |
971 | } | |
972 | else if (G_FLD(inst->v, 24, 20) == 0x2) | |
973 | { | |
974 | /* rD = r2 */ | |
975 | fp_offset = sp_offset - G_FLD(inst->v, 14, 0); | |
976 | fp_offset_p = 1; | |
977 | } | |
978 | } | |
979 | else if (G_FLD (inst->v, 29, 15) == 0x1c60 | |
980 | && G_FLD (inst->v, 2, 0) == 0x0) | |
981 | { | |
982 | /* lw r3, [r0]+, 4 */ | |
983 | sp_offset -= SCORE_INSTLEN; | |
984 | ra_offset_p = 1; | |
985 | } | |
986 | else if (G_FLD (inst->v, 29, 15) == 0x1c40 | |
987 | && G_FLD (inst->v, 2, 0) == 0x0) | |
988 | { | |
989 | /* lw r2, [r0]+, 4 */ | |
990 | sp_offset -= SCORE_INSTLEN; | |
991 | fp_offset_p = 1; | |
992 | } | |
993 | ||
994 | else if (G_FLD (inst->v, 29, 17) == 0x100 | |
995 | && G_FLD (inst->v, 0, 0) == 0x0) | |
996 | { | |
997 | /* addi r0, -offset */ | |
998 | sp_offset += 65536 - G_FLD (inst->v, 16, 1); | |
999 | } | |
1000 | else if (G_FLD (inst->v, 29, 17) == 0x110 | |
1001 | && G_FLD (inst->v, 0, 0) == 0x0) | |
1002 | { | |
1003 | /* addi r2, offset */ | |
1004 | if (pc - cur_pc > 4) | |
1005 | { | |
1006 | unsigned int save_v = inst->v; | |
1007 | inst_t *inst2 = | |
1008 | score7_fetch_inst (gdbarch, cur_pc + SCORE_INSTLEN, NULL); | |
1009 | if (inst2->v == 0x23) | |
1010 | { | |
1011 | /* mv! r0, r2 */ | |
1012 | sp_offset -= G_FLD (save_v, 16, 1); | |
1013 | } | |
1014 | } | |
1015 | } | |
1016 | } | |
27fd2f50 Q |
1017 | } |
1018 | ||
1019 | /* Save RA. */ | |
1020 | if (ra_offset_p == 1) | |
1021 | { | |
a9a87d35 LM |
1022 | if (this_cache->saved_regs[SCORE_PC_REGNUM].is_realreg () |
1023 | && this_cache->saved_regs[SCORE_PC_REGNUM].realreg () | |
1024 | == SCORE_PC_REGNUM) | |
098caef4 LM |
1025 | this_cache->saved_regs[SCORE_PC_REGNUM].set_addr (sp + sp_offset |
1026 | - ra_offset); | |
27fd2f50 Q |
1027 | } |
1028 | else | |
1029 | { | |
1030 | this_cache->saved_regs[SCORE_PC_REGNUM] = | |
dda83cd7 | 1031 | this_cache->saved_regs[SCORE_RA_REGNUM]; |
27fd2f50 Q |
1032 | } |
1033 | ||
1034 | /* Save FP. */ | |
1035 | if (fp_offset_p == 1) | |
1036 | { | |
a9a87d35 LM |
1037 | if (this_cache->saved_regs[SCORE_FP_REGNUM].is_realreg () |
1038 | && this_cache->saved_regs[SCORE_FP_REGNUM].realreg () | |
1039 | == SCORE_FP_REGNUM) | |
098caef4 LM |
1040 | this_cache->saved_regs[SCORE_FP_REGNUM].set_addr (sp + sp_offset |
1041 | - fp_offset); | |
27fd2f50 Q |
1042 | } |
1043 | ||
5e29c264 Q |
1044 | /* Save SP and FP. */ |
1045 | this_cache->base = sp + sp_offset; | |
1046 | this_cache->fp = fp; | |
1047 | ||
1048 | /* Don't forget to free MEMBLOCK if we allocated it. */ | |
1049 | if (memblock_ptr != NULL) | |
5f814c3b DL |
1050 | score7_free_memblock (memblock_ptr); |
1051 | } | |
1052 | ||
1053 | static void | |
1054 | score3_analyze_prologue (CORE_ADDR startaddr, CORE_ADDR pc, | |
dda83cd7 SM |
1055 | struct frame_info *this_frame, |
1056 | struct score_frame_cache *this_cache) | |
5f814c3b DL |
1057 | { |
1058 | CORE_ADDR sp; | |
1059 | CORE_ADDR fp; | |
1060 | CORE_ADDR cur_pc = startaddr; | |
c378eb4e MS |
1061 | enum bfd_endian byte_order |
1062 | = gdbarch_byte_order (get_frame_arch (this_frame)); | |
5f814c3b DL |
1063 | |
1064 | int sp_offset = 0; | |
1065 | int ra_offset = 0; | |
1066 | int fp_offset = 0; | |
1067 | int ra_offset_p = 0; | |
1068 | int fp_offset_p = 0; | |
1069 | int inst_len = 0; | |
1070 | ||
5f814c3b DL |
1071 | sp = get_frame_register_unsigned (this_frame, SCORE_SP_REGNUM); |
1072 | fp = get_frame_register_unsigned (this_frame, SCORE_FP_REGNUM); | |
1073 | ||
870f88f7 | 1074 | for (; cur_pc < pc; cur_pc += inst_len) |
5f814c3b DL |
1075 | { |
1076 | inst_t *inst = NULL; | |
1077 | ||
1078 | inst = score3_adjust_pc_and_fetch_inst (&cur_pc, &inst_len, byte_order); | |
1079 | ||
c378eb4e | 1080 | /* FIXME: make a full-power prologue analyzer. */ |
5f814c3b | 1081 | if (inst->len == 2) |
dda83cd7 SM |
1082 | { |
1083 | if (G_FLD (inst->v, 14, 12) == 0x0 | |
1084 | && G_FLD (inst->v, 11, 7) == 0x0 | |
1085 | && G_FLD (inst->v, 6, 5) == 0x3) | |
1086 | { | |
1087 | /* push! */ | |
1088 | sp_offset += 4; | |
1089 | ||
1090 | if (G_FLD (inst->v, 4, 0) == 0x3 | |
1091 | && ra_offset_p == 0) | |
1092 | { | |
1093 | /* push! r3, [r0] */ | |
1094 | ra_offset = sp_offset; | |
1095 | ra_offset_p = 1; | |
1096 | } | |
1097 | else if (G_FLD (inst->v, 4, 0) == 0x2 | |
1098 | && fp_offset_p == 0) | |
1099 | { | |
1100 | /* push! r2, [r0] */ | |
1101 | fp_offset = sp_offset; | |
1102 | fp_offset_p = 1; | |
1103 | } | |
1104 | } | |
1105 | else if (G_FLD (inst->v, 14, 12) == 0x6 | |
1106 | && G_FLD (inst->v, 11, 10) == 0x3) | |
1107 | { | |
1108 | /* rpush! */ | |
1109 | int start_r = G_FLD (inst->v, 9, 5); | |
1110 | int cnt = G_FLD (inst->v, 4, 0); | |
5f814c3b | 1111 | |
dda83cd7 | 1112 | if ((ra_offset_p == 0) |
5f814c3b | 1113 | && (start_r <= SCORE_RA_REGNUM) |
dda83cd7 SM |
1114 | && (SCORE_RA_REGNUM < start_r + cnt)) |
1115 | { | |
1116 | /* rpush! contains r3 */ | |
1117 | ra_offset_p = 1; | |
1118 | ra_offset = sp_offset + 4 * (SCORE_RA_REGNUM - start_r) + 4; | |
1119 | } | |
1120 | ||
1121 | if ((fp_offset_p == 0) | |
5f814c3b | 1122 | && (start_r <= SCORE_FP_REGNUM) |
dda83cd7 SM |
1123 | && (SCORE_FP_REGNUM < start_r + cnt)) |
1124 | { | |
1125 | /* rpush! contains r2 */ | |
1126 | fp_offset_p = 1; | |
1127 | fp_offset = sp_offset + 4 * (SCORE_FP_REGNUM - start_r) + 4; | |
1128 | } | |
1129 | ||
1130 | sp_offset += 4 * cnt; | |
1131 | } | |
1132 | else if (G_FLD (inst->v, 14, 12) == 0x0 | |
1133 | && G_FLD (inst->v, 11, 7) == 0x0 | |
1134 | && G_FLD (inst->v, 6, 5) == 0x2) | |
1135 | { | |
1136 | /* pop! */ | |
1137 | sp_offset -= 4; | |
1138 | } | |
1139 | else if (G_FLD (inst->v, 14, 12) == 0x6 | |
1140 | && G_FLD (inst->v, 11, 10) == 0x2) | |
1141 | { | |
1142 | /* rpop! */ | |
1143 | sp_offset -= 4 * G_FLD (inst->v, 4, 0); | |
1144 | } | |
1145 | else if (G_FLD (inst->v, 14, 12) == 0x5 | |
1146 | && G_FLD (inst->v, 11, 10) == 0x3 | |
1147 | && G_FLD (inst->v, 9, 6) == 0x0) | |
1148 | { | |
1149 | /* addi! r0, -offset */ | |
1150 | int imm = G_FLD (inst->v, 5, 0); | |
5f814c3b DL |
1151 | if (imm >> 5) |
1152 | imm = -(0x3F - imm + 1); | |
1153 | sp_offset -= imm; | |
dda83cd7 SM |
1154 | } |
1155 | else if (G_FLD (inst->v, 14, 12) == 0x5 | |
1156 | && G_FLD (inst->v, 11, 10) == 0x3 | |
1157 | && G_FLD (inst->v, 9, 6) == 0x2) | |
1158 | { | |
1159 | /* addi! r2, offset */ | |
1160 | if (pc - cur_pc >= 2) | |
1161 | { | |
5f814c3b DL |
1162 | inst_t *inst2; |
1163 | ||
1164 | cur_pc += inst->len; | |
c378eb4e MS |
1165 | inst2 = score3_adjust_pc_and_fetch_inst (&cur_pc, NULL, |
1166 | byte_order); | |
5f814c3b | 1167 | |
dda83cd7 SM |
1168 | if (inst2->len == 2 |
1169 | && G_FLD (inst2->v, 14, 10) == 0x10 | |
1170 | && G_FLD (inst2->v, 9, 5) == 0x0 | |
1171 | && G_FLD (inst2->v, 4, 0) == 0x2) | |
1172 | { | |
1173 | /* mv! r0, r2 */ | |
1174 | int imm = G_FLD (inst->v, 5, 0); | |
1175 | if (imm >> 5) | |
1176 | imm = -(0x3F - imm + 1); | |
1177 | sp_offset -= imm; | |
1178 | } | |
1179 | } | |
5f814c3b | 1180 | } |
dda83cd7 | 1181 | } |
5f814c3b | 1182 | else if (inst->len == 4) |
dda83cd7 SM |
1183 | { |
1184 | if (G_FLD (inst->v, 29, 25) == 0x3 | |
1185 | && G_FLD (inst->v, 2, 0) == 0x4 | |
1186 | && G_FLD (inst->v, 24, 20) == 0x3 | |
1187 | && G_FLD (inst->v, 19, 15) == 0x0) | |
1188 | { | |
1189 | /* sw r3, [r0, offset]+ */ | |
1190 | sp_offset += inst->len; | |
1191 | if (ra_offset_p == 0) | |
1192 | { | |
1193 | ra_offset = sp_offset; | |
1194 | ra_offset_p = 1; | |
1195 | } | |
1196 | } | |
1197 | else if (G_FLD (inst->v, 29, 25) == 0x3 | |
1198 | && G_FLD (inst->v, 2, 0) == 0x4 | |
1199 | && G_FLD (inst->v, 24, 20) == 0x2 | |
1200 | && G_FLD (inst->v, 19, 15) == 0x0) | |
1201 | { | |
1202 | /* sw r2, [r0, offset]+ */ | |
1203 | sp_offset += inst->len; | |
1204 | if (fp_offset_p == 0) | |
1205 | { | |
1206 | fp_offset = sp_offset; | |
1207 | fp_offset_p = 1; | |
1208 | } | |
1209 | } | |
1210 | else if (G_FLD (inst->v, 29, 25) == 0x7 | |
1211 | && G_FLD (inst->v, 2, 0) == 0x0 | |
1212 | && G_FLD (inst->v, 24, 20) == 0x3 | |
1213 | && G_FLD (inst->v, 19, 15) == 0x0) | |
1214 | { | |
1215 | /* lw r3, [r0]+, 4 */ | |
1216 | sp_offset -= inst->len; | |
1217 | ra_offset_p = 1; | |
1218 | } | |
1219 | else if (G_FLD (inst->v, 29, 25) == 0x7 | |
1220 | && G_FLD (inst->v, 2, 0) == 0x0 | |
1221 | && G_FLD (inst->v, 24, 20) == 0x2 | |
1222 | && G_FLD (inst->v, 19, 15) == 0x0) | |
1223 | { | |
1224 | /* lw r2, [r0]+, 4 */ | |
1225 | sp_offset -= inst->len; | |
1226 | fp_offset_p = 1; | |
1227 | } | |
1228 | else if (G_FLD (inst->v, 29, 25) == 0x1 | |
1229 | && G_FLD (inst->v, 19, 17) == 0x0 | |
1230 | && G_FLD (inst->v, 24, 20) == 0x0 | |
1231 | && G_FLD (inst->v, 0, 0) == 0x0) | |
1232 | { | |
1233 | /* addi r0, -offset */ | |
1234 | int imm = G_FLD (inst->v, 16, 1); | |
5f814c3b DL |
1235 | if (imm >> 15) |
1236 | imm = -(0xFFFF - imm + 1); | |
dda83cd7 SM |
1237 | sp_offset -= imm; |
1238 | } | |
1239 | else if (G_FLD (inst->v, 29, 25) == 0x1 | |
1240 | && G_FLD (inst->v, 19, 17) == 0x0 | |
1241 | && G_FLD (inst->v, 24, 20) == 0x2 | |
1242 | && G_FLD (inst->v, 0, 0) == 0x0) | |
1243 | { | |
1244 | /* addi r2, offset */ | |
1245 | if (pc - cur_pc >= 2) | |
1246 | { | |
5f814c3b DL |
1247 | inst_t *inst2; |
1248 | ||
1249 | cur_pc += inst->len; | |
c378eb4e MS |
1250 | inst2 = score3_adjust_pc_and_fetch_inst (&cur_pc, NULL, |
1251 | byte_order); | |
5f814c3b | 1252 | |
dda83cd7 SM |
1253 | if (inst2->len == 2 |
1254 | && G_FLD (inst2->v, 14, 10) == 0x10 | |
1255 | && G_FLD (inst2->v, 9, 5) == 0x0 | |
1256 | && G_FLD (inst2->v, 4, 0) == 0x2) | |
1257 | { | |
1258 | /* mv! r0, r2 */ | |
1259 | int imm = G_FLD (inst->v, 16, 1); | |
1260 | if (imm >> 15) | |
1261 | imm = -(0xFFFF - imm + 1); | |
1262 | sp_offset -= imm; | |
1263 | } | |
1264 | } | |
1265 | } | |
1266 | } | |
5f814c3b DL |
1267 | } |
1268 | ||
1269 | /* Save RA. */ | |
1270 | if (ra_offset_p == 1) | |
1271 | { | |
a9a87d35 LM |
1272 | if (this_cache->saved_regs[SCORE_PC_REGNUM].is_realreg () |
1273 | && this_cache->saved_regs[SCORE_PC_REGNUM].realreg () | |
1274 | == SCORE_PC_REGNUM) | |
098caef4 LM |
1275 | this_cache->saved_regs[SCORE_PC_REGNUM].set_addr (sp + sp_offset |
1276 | - ra_offset); | |
5f814c3b DL |
1277 | } |
1278 | else | |
1279 | { | |
1280 | this_cache->saved_regs[SCORE_PC_REGNUM] = | |
dda83cd7 | 1281 | this_cache->saved_regs[SCORE_RA_REGNUM]; |
5f814c3b DL |
1282 | } |
1283 | ||
1284 | /* Save FP. */ | |
1285 | if (fp_offset_p == 1) | |
1286 | { | |
a9a87d35 LM |
1287 | if (this_cache->saved_regs[SCORE_FP_REGNUM].is_realreg () |
1288 | && this_cache->saved_regs[SCORE_FP_REGNUM].realreg () | |
1289 | == SCORE_FP_REGNUM) | |
098caef4 LM |
1290 | this_cache->saved_regs[SCORE_FP_REGNUM].set_addr (sp + sp_offset |
1291 | - fp_offset); | |
5f814c3b DL |
1292 | } |
1293 | ||
1294 | /* Save SP and FP. */ | |
1295 | this_cache->base = sp + sp_offset; | |
1296 | this_cache->fp = fp; | |
27fd2f50 Q |
1297 | } |
1298 | ||
1299 | static struct score_frame_cache * | |
94afd7a6 | 1300 | score_make_prologue_cache (struct frame_info *this_frame, void **this_cache) |
27fd2f50 Q |
1301 | { |
1302 | struct score_frame_cache *cache; | |
1303 | ||
1304 | if ((*this_cache) != NULL) | |
19ba03f4 | 1305 | return (struct score_frame_cache *) (*this_cache); |
27fd2f50 Q |
1306 | |
1307 | cache = FRAME_OBSTACK_ZALLOC (struct score_frame_cache); | |
1308 | (*this_cache) = cache; | |
94afd7a6 | 1309 | cache->saved_regs = trad_frame_alloc_saved_regs (this_frame); |
27fd2f50 Q |
1310 | |
1311 | /* Analyze the prologue. */ | |
1312 | { | |
94afd7a6 | 1313 | const CORE_ADDR pc = get_frame_pc (this_frame); |
27fd2f50 Q |
1314 | CORE_ADDR start_addr; |
1315 | ||
1316 | find_pc_partial_function (pc, NULL, &start_addr, NULL); | |
1317 | if (start_addr == 0) | |
1318 | return cache; | |
5f814c3b DL |
1319 | |
1320 | if (target_mach == bfd_mach_score3) | |
19ba03f4 SM |
1321 | score3_analyze_prologue (start_addr, pc, this_frame, |
1322 | (struct score_frame_cache *) *this_cache); | |
5f814c3b | 1323 | else |
19ba03f4 SM |
1324 | score7_analyze_prologue (start_addr, pc, this_frame, |
1325 | (struct score_frame_cache *) *this_cache); | |
27fd2f50 Q |
1326 | } |
1327 | ||
1328 | /* Save SP. */ | |
a9a87d35 | 1329 | cache->saved_regs[SCORE_SP_REGNUM].set_value (cache->base); |
27fd2f50 | 1330 | |
19ba03f4 | 1331 | return (struct score_frame_cache *) (*this_cache); |
27fd2f50 Q |
1332 | } |
1333 | ||
1334 | static void | |
94afd7a6 | 1335 | score_prologue_this_id (struct frame_info *this_frame, void **this_cache, |
dda83cd7 | 1336 | struct frame_id *this_id) |
27fd2f50 | 1337 | { |
94afd7a6 | 1338 | struct score_frame_cache *info = score_make_prologue_cache (this_frame, |
dda83cd7 | 1339 | this_cache); |
94afd7a6 | 1340 | (*this_id) = frame_id_build (info->base, get_frame_func (this_frame)); |
27fd2f50 Q |
1341 | } |
1342 | ||
94afd7a6 UW |
1343 | static struct value * |
1344 | score_prologue_prev_register (struct frame_info *this_frame, | |
dda83cd7 | 1345 | void **this_cache, int regnum) |
27fd2f50 | 1346 | { |
94afd7a6 | 1347 | struct score_frame_cache *info = score_make_prologue_cache (this_frame, |
dda83cd7 | 1348 | this_cache); |
94afd7a6 | 1349 | return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum); |
27fd2f50 Q |
1350 | } |
1351 | ||
1352 | static const struct frame_unwind score_prologue_unwind = | |
1353 | { | |
a154d838 | 1354 | "score prologue", |
27fd2f50 | 1355 | NORMAL_FRAME, |
8fbca658 | 1356 | default_frame_unwind_stop_reason, |
27fd2f50 | 1357 | score_prologue_this_id, |
94afd7a6 UW |
1358 | score_prologue_prev_register, |
1359 | NULL, | |
5f814c3b DL |
1360 | default_frame_sniffer, |
1361 | NULL | |
27fd2f50 Q |
1362 | }; |
1363 | ||
27fd2f50 | 1364 | static CORE_ADDR |
94afd7a6 | 1365 | score_prologue_frame_base_address (struct frame_info *this_frame, |
dda83cd7 | 1366 | void **this_cache) |
27fd2f50 Q |
1367 | { |
1368 | struct score_frame_cache *info = | |
94afd7a6 | 1369 | score_make_prologue_cache (this_frame, this_cache); |
5e29c264 | 1370 | return info->fp; |
27fd2f50 Q |
1371 | } |
1372 | ||
1373 | static const struct frame_base score_prologue_frame_base = | |
1374 | { | |
1375 | &score_prologue_unwind, | |
1376 | score_prologue_frame_base_address, | |
1377 | score_prologue_frame_base_address, | |
1378 | score_prologue_frame_base_address, | |
1379 | }; | |
1380 | ||
1381 | static const struct frame_base * | |
94afd7a6 | 1382 | score_prologue_frame_base_sniffer (struct frame_info *this_frame) |
27fd2f50 Q |
1383 | { |
1384 | return &score_prologue_frame_base; | |
1385 | } | |
1386 | ||
c5741217 AA |
1387 | /* Core file support. */ |
1388 | ||
1389 | static const struct regcache_map_entry score7_linux_gregmap[] = | |
1390 | { | |
1391 | /* FIXME: According to the current Linux kernel, r0 is preceded by | |
1392 | 9 rather than 7 words. */ | |
1393 | { 7, REGCACHE_MAP_SKIP, 4 }, | |
1394 | { 32, 0, 4 }, /* r0 ... r31 */ | |
1395 | { 1, 55, 4 }, /* CEL */ | |
1396 | { 1, 54, 4 }, /* CEH */ | |
1397 | { 1, 53, 4 }, /* sr0, i.e. cnt or COUNTER */ | |
1398 | { 1, 52, 4 }, /* sr1, i.e. lcr or LDCR */ | |
1399 | { 1, 51, 4 }, /* sr2, i.e. scr or STCR */ | |
1400 | { 1, 49, 4 }, /* PC (same slot as EPC) */ | |
1401 | { 1, 38, 4 }, /* EMA */ | |
1402 | { 1, 32, 4 }, /* PSR */ | |
1403 | { 1, 34, 4 }, /* ECR */ | |
1404 | { 1, 33, 4 }, /* COND */ | |
1405 | { 0 } | |
1406 | }; | |
1407 | ||
1408 | #define SCORE7_LINUX_EPC_OFFSET (44 * 4) | |
1409 | #define SCORE7_LINUX_SIZEOF_GREGSET (49 * 4) | |
5f814c3b DL |
1410 | |
1411 | static void | |
1412 | score7_linux_supply_gregset(const struct regset *regset, | |
c5741217 AA |
1413 | struct regcache *regcache, |
1414 | int regnum, const void *buf, | |
1415 | size_t size) | |
5f814c3b | 1416 | { |
c5741217 AA |
1417 | regcache_supply_regset (regset, regcache, regnum, buf, size); |
1418 | ||
1419 | /* Supply the EPC from the same slot as the PC. Note that the | |
1420 | collect function will store the PC in that slot. */ | |
1421 | if ((regnum == -1 || regnum == SCORE_EPC_REGNUM) | |
1422 | && size >= SCORE7_LINUX_EPC_OFFSET + 4) | |
73e1c03f SM |
1423 | regcache->raw_supply |
1424 | (SCORE_EPC_REGNUM, (const gdb_byte *) buf + SCORE7_LINUX_EPC_OFFSET); | |
5f814c3b DL |
1425 | } |
1426 | ||
8fea3224 AA |
1427 | static const struct regset score7_linux_gregset = |
1428 | { | |
c5741217 AA |
1429 | score7_linux_gregmap, |
1430 | score7_linux_supply_gregset, | |
1431 | regcache_collect_regset | |
8fea3224 AA |
1432 | }; |
1433 | ||
9845a0b5 | 1434 | /* Iterate over core file register note sections. */ |
5f814c3b | 1435 | |
9845a0b5 AA |
1436 | static void |
1437 | score7_linux_iterate_over_regset_sections (struct gdbarch *gdbarch, | |
1438 | iterate_over_regset_sections_cb *cb, | |
1439 | void *cb_data, | |
1440 | const struct regcache *regcache) | |
5f814c3b | 1441 | { |
a616bb94 AH |
1442 | cb (".reg", SCORE7_LINUX_SIZEOF_GREGSET, SCORE7_LINUX_SIZEOF_GREGSET, |
1443 | &score7_linux_gregset, NULL, cb_data); | |
5f814c3b DL |
1444 | } |
1445 | ||
27fd2f50 Q |
1446 | static struct gdbarch * |
1447 | score_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | |
1448 | { | |
1449 | struct gdbarch *gdbarch; | |
5f814c3b | 1450 | target_mach = info.bfd_arch_info->mach; |
27fd2f50 Q |
1451 | |
1452 | arches = gdbarch_list_lookup_by_info (arches, &info); | |
1453 | if (arches != NULL) | |
1454 | { | |
1455 | return (arches->gdbarch); | |
1456 | } | |
8fea3224 | 1457 | gdbarch = gdbarch_alloc (&info, NULL); |
27fd2f50 Q |
1458 | |
1459 | set_gdbarch_short_bit (gdbarch, 16); | |
1460 | set_gdbarch_int_bit (gdbarch, 32); | |
1461 | set_gdbarch_float_bit (gdbarch, 32); | |
1462 | set_gdbarch_double_bit (gdbarch, 64); | |
1463 | set_gdbarch_long_double_bit (gdbarch, 64); | |
5f814c3b | 1464 | #if WITH_SIM |
27fd2f50 | 1465 | set_gdbarch_register_sim_regno (gdbarch, score_register_sim_regno); |
5f814c3b | 1466 | #endif |
27fd2f50 Q |
1467 | set_gdbarch_pc_regnum (gdbarch, SCORE_PC_REGNUM); |
1468 | set_gdbarch_sp_regnum (gdbarch, SCORE_SP_REGNUM); | |
c378eb4e MS |
1469 | set_gdbarch_adjust_breakpoint_address (gdbarch, |
1470 | score_adjust_breakpoint_address); | |
27fd2f50 Q |
1471 | set_gdbarch_register_type (gdbarch, score_register_type); |
1472 | set_gdbarch_frame_align (gdbarch, score_frame_align); | |
1473 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
5f814c3b DL |
1474 | |
1475 | switch (target_mach) | |
1476 | { | |
1477 | case bfd_mach_score7: | |
04180708 YQ |
1478 | set_gdbarch_breakpoint_kind_from_pc (gdbarch, |
1479 | score7_breakpoint_kind_from_pc); | |
1480 | set_gdbarch_sw_breakpoint_from_kind (gdbarch, | |
1481 | score7_sw_breakpoint_from_kind); | |
5f814c3b | 1482 | set_gdbarch_skip_prologue (gdbarch, score7_skip_prologue); |
c9cf6e20 MG |
1483 | set_gdbarch_stack_frame_destroyed_p (gdbarch, |
1484 | score7_stack_frame_destroyed_p); | |
5f814c3b DL |
1485 | set_gdbarch_register_name (gdbarch, score7_register_name); |
1486 | set_gdbarch_num_regs (gdbarch, SCORE7_NUM_REGS); | |
c378eb4e | 1487 | /* Core file support. */ |
9845a0b5 AA |
1488 | set_gdbarch_iterate_over_regset_sections |
1489 | (gdbarch, score7_linux_iterate_over_regset_sections); | |
5f814c3b DL |
1490 | break; |
1491 | ||
1492 | case bfd_mach_score3: | |
04180708 YQ |
1493 | set_gdbarch_breakpoint_kind_from_pc (gdbarch, |
1494 | score3_breakpoint_kind_from_pc); | |
1495 | set_gdbarch_sw_breakpoint_from_kind (gdbarch, | |
1496 | score3_sw_breakpoint_from_kind); | |
5f814c3b | 1497 | set_gdbarch_skip_prologue (gdbarch, score3_skip_prologue); |
c9cf6e20 MG |
1498 | set_gdbarch_stack_frame_destroyed_p (gdbarch, |
1499 | score3_stack_frame_destroyed_p); | |
5f814c3b DL |
1500 | set_gdbarch_register_name (gdbarch, score3_register_name); |
1501 | set_gdbarch_num_regs (gdbarch, SCORE3_NUM_REGS); | |
1502 | break; | |
1503 | } | |
5e29c264 Q |
1504 | |
1505 | /* Watchpoint hooks. */ | |
1506 | set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1); | |
1507 | ||
1508 | /* Dummy frame hooks. */ | |
27fd2f50 | 1509 | set_gdbarch_return_value (gdbarch, score_return_value); |
5e29c264 | 1510 | set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT); |
27fd2f50 Q |
1511 | set_gdbarch_push_dummy_call (gdbarch, score_push_dummy_call); |
1512 | ||
5e29c264 | 1513 | /* Normal frame hooks. */ |
94afd7a6 | 1514 | dwarf2_append_unwinders (gdbarch); |
27fd2f50 | 1515 | frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer); |
94afd7a6 | 1516 | frame_unwind_append_unwinder (gdbarch, &score_prologue_unwind); |
27fd2f50 Q |
1517 | frame_base_append_sniffer (gdbarch, score_prologue_frame_base_sniffer); |
1518 | ||
1519 | return gdbarch; | |
1520 | } | |
1521 | ||
6c265988 | 1522 | void _initialize_score_tdep (); |
27fd2f50 | 1523 | void |
6c265988 | 1524 | _initialize_score_tdep () |
27fd2f50 Q |
1525 | { |
1526 | gdbarch_register (bfd_arch_score, score_gdbarch_init, NULL); | |
1527 | } |