Commit | Line | Data |
---|---|---|
49d45b20 JB |
1 | /* Target-dependent code for FT32. |
2 | ||
618f726f | 3 | Copyright (C) 2009-2016 Free Software Foundation, Inc. |
49d45b20 JB |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "frame.h" | |
22 | #include "frame-unwind.h" | |
23 | #include "frame-base.h" | |
24 | #include "symtab.h" | |
25 | #include "gdbtypes.h" | |
26 | #include "gdbcmd.h" | |
27 | #include "gdbcore.h" | |
28 | #include "value.h" | |
29 | #include "inferior.h" | |
30 | #include "symfile.h" | |
31 | #include "objfiles.h" | |
32 | #include "osabi.h" | |
33 | #include "language.h" | |
34 | #include "arch-utils.h" | |
35 | #include "regcache.h" | |
36 | #include "trad-frame.h" | |
37 | #include "dis-asm.h" | |
38 | #include "record.h" | |
39 | ||
86feccb9 | 40 | #include "opcode/ft32.h" |
41 | ||
49d45b20 JB |
42 | #include "ft32-tdep.h" |
43 | #include "gdb/sim-ft32.h" | |
44 | ||
45 | #define RAM_BIAS 0x800000 /* Bias added to RAM addresses. */ | |
46 | ||
47 | /* Local functions. */ | |
48 | ||
49 | extern void _initialize_ft32_tdep (void); | |
50 | ||
51 | /* Use an invalid address -1 as 'not available' marker. */ | |
52 | enum { REG_UNAVAIL = (CORE_ADDR) (-1) }; | |
53 | ||
54 | struct ft32_frame_cache | |
55 | { | |
56 | /* Base address of the frame */ | |
57 | CORE_ADDR base; | |
58 | /* Function this frame belongs to */ | |
59 | CORE_ADDR pc; | |
60 | /* Total size of this frame */ | |
61 | LONGEST framesize; | |
62 | /* Saved registers in this frame */ | |
63 | CORE_ADDR saved_regs[FT32_NUM_REGS]; | |
64 | /* Saved SP in this frame */ | |
65 | CORE_ADDR saved_sp; | |
66 | /* Has the new frame been LINKed. */ | |
67 | bfd_boolean established; | |
68 | }; | |
69 | ||
70 | /* Implement the "frame_align" gdbarch method. */ | |
71 | ||
72 | static CORE_ADDR | |
73 | ft32_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp) | |
74 | { | |
75 | /* Align to the size of an instruction (so that they can safely be | |
76 | pushed onto the stack. */ | |
77 | return sp & ~1; | |
78 | } | |
79 | ||
80 | /* Implement the "breakpoint_from_pc" gdbarch method. */ | |
81 | ||
82 | static const unsigned char * | |
83 | ft32_breakpoint_from_pc (struct gdbarch *gdbarch, | |
84 | CORE_ADDR *pcptr, int *lenptr) | |
85 | { | |
86 | static const gdb_byte breakpoint[] = { 0x02, 0x00, 0x34, 0x00 }; | |
87 | ||
88 | *lenptr = sizeof (breakpoint); | |
89 | return breakpoint; | |
90 | } | |
91 | ||
92 | /* FT32 register names. */ | |
93 | ||
94 | static const char *const ft32_register_names[] = | |
95 | { | |
96 | "fp", "sp", | |
97 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | |
98 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
99 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", | |
100 | "r24", "r25", "r26", "r27", "r28", "cc", | |
101 | "pc" | |
102 | }; | |
103 | ||
104 | /* Implement the "register_name" gdbarch method. */ | |
105 | ||
106 | static const char * | |
107 | ft32_register_name (struct gdbarch *gdbarch, int reg_nr) | |
108 | { | |
109 | if (reg_nr < 0) | |
110 | return NULL; | |
111 | if (reg_nr >= FT32_NUM_REGS) | |
112 | return NULL; | |
113 | return ft32_register_names[reg_nr]; | |
114 | } | |
115 | ||
116 | /* Implement the "register_type" gdbarch method. */ | |
117 | ||
118 | static struct type * | |
119 | ft32_register_type (struct gdbarch *gdbarch, int reg_nr) | |
120 | { | |
121 | if (reg_nr == FT32_PC_REGNUM) | |
623fb775 | 122 | return gdbarch_tdep (gdbarch)->pc_type; |
49d45b20 JB |
123 | else if (reg_nr == FT32_SP_REGNUM || reg_nr == FT32_FP_REGNUM) |
124 | return builtin_type (gdbarch)->builtin_data_ptr; | |
125 | else | |
126 | return builtin_type (gdbarch)->builtin_int32; | |
127 | } | |
128 | ||
129 | /* Write into appropriate registers a function return value | |
130 | of type TYPE, given in virtual format. */ | |
131 | ||
132 | static void | |
133 | ft32_store_return_value (struct type *type, struct regcache *regcache, | |
134 | const gdb_byte *valbuf) | |
135 | { | |
136 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
137 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
138 | CORE_ADDR regval; | |
139 | int len = TYPE_LENGTH (type); | |
140 | ||
141 | /* Things always get returned in RET1_REGNUM, RET2_REGNUM. */ | |
142 | regval = extract_unsigned_integer (valbuf, len > 4 ? 4 : len, byte_order); | |
143 | regcache_cooked_write_unsigned (regcache, FT32_R0_REGNUM, regval); | |
144 | if (len > 4) | |
145 | { | |
146 | regval = extract_unsigned_integer (valbuf + 4, | |
147 | len - 4, byte_order); | |
148 | regcache_cooked_write_unsigned (regcache, FT32_R1_REGNUM, regval); | |
149 | } | |
150 | } | |
151 | ||
152 | /* Decode the instructions within the given address range. Decide | |
153 | when we must have reached the end of the function prologue. If a | |
154 | frame_info pointer is provided, fill in its saved_regs etc. | |
155 | ||
156 | Returns the address of the first instruction after the prologue. */ | |
157 | ||
49d45b20 JB |
158 | static CORE_ADDR |
159 | ft32_analyze_prologue (CORE_ADDR start_addr, CORE_ADDR end_addr, | |
160 | struct ft32_frame_cache *cache, | |
161 | struct gdbarch *gdbarch) | |
162 | { | |
163 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
164 | CORE_ADDR next_addr; | |
870f88f7 | 165 | ULONGEST inst; |
ae4e2501 | 166 | int regnum, pushreg; |
167 | struct bound_minimal_symbol msymbol; | |
168 | const int first_saved_reg = 13; /* The first saved register. */ | |
169 | /* PROLOGS are addresses of the subroutine prologs, PROLOGS[n] | |
170 | is the address of __prolog_$rN. | |
171 | __prolog_$rN pushes registers from 13 through n inclusive. | |
172 | So for example CALL __prolog_$r15 is equivalent to: | |
173 | PUSH $r13 | |
174 | PUSH $r14 | |
175 | PUSH $r15 | |
176 | Note that PROLOGS[0] through PROLOGS[12] are unused. */ | |
177 | CORE_ADDR prologs[32]; | |
49d45b20 JB |
178 | |
179 | cache->saved_regs[FT32_PC_REGNUM] = 0; | |
180 | cache->framesize = 0; | |
181 | ||
ae4e2501 | 182 | for (regnum = first_saved_reg; regnum < 32; regnum++) |
183 | { | |
184 | char prolog_symbol[32]; | |
185 | ||
186 | snprintf (prolog_symbol, sizeof (prolog_symbol), "__prolog_$r%02d", | |
187 | regnum); | |
188 | msymbol = lookup_minimal_symbol (prolog_symbol, NULL, NULL); | |
189 | if (msymbol.minsym) | |
190 | prologs[regnum] = BMSYMBOL_VALUE_ADDRESS (msymbol); | |
191 | else | |
192 | prologs[regnum] = 0; | |
193 | } | |
194 | ||
49d45b20 | 195 | if (start_addr >= end_addr) |
ae4e2501 | 196 | return end_addr; |
49d45b20 JB |
197 | |
198 | cache->established = 0; | |
ae4e2501 | 199 | for (next_addr = start_addr; next_addr < end_addr;) |
49d45b20 JB |
200 | { |
201 | inst = read_memory_unsigned_integer (next_addr, 4, byte_order); | |
202 | ||
86feccb9 | 203 | if (FT32_IS_PUSH (inst)) |
49d45b20 | 204 | { |
ae4e2501 | 205 | pushreg = FT32_PUSH_REG (inst); |
49d45b20 | 206 | cache->framesize += 4; |
ae4e2501 | 207 | cache->saved_regs[FT32_R0_REGNUM + pushreg] = cache->framesize; |
49d45b20 JB |
208 | next_addr += 4; |
209 | } | |
ae4e2501 | 210 | else if (FT32_IS_CALL (inst)) |
211 | { | |
212 | for (regnum = first_saved_reg; regnum < 32; regnum++) | |
213 | { | |
214 | if ((4 * (inst & 0x3ffff)) == prologs[regnum]) | |
215 | { | |
216 | for (pushreg = first_saved_reg; pushreg <= regnum; | |
217 | pushreg++) | |
218 | { | |
219 | cache->framesize += 4; | |
220 | cache->saved_regs[FT32_R0_REGNUM + pushreg] = | |
221 | cache->framesize; | |
222 | } | |
223 | next_addr += 4; | |
224 | } | |
225 | } | |
226 | break; | |
227 | } | |
49d45b20 JB |
228 | else |
229 | break; | |
230 | } | |
231 | for (regnum = FT32_R0_REGNUM; regnum < FT32_PC_REGNUM; regnum++) | |
232 | { | |
233 | if (cache->saved_regs[regnum] != REG_UNAVAIL) | |
ae4e2501 | 234 | cache->saved_regs[regnum] = |
235 | cache->framesize - cache->saved_regs[regnum]; | |
49d45b20 JB |
236 | } |
237 | cache->saved_regs[FT32_PC_REGNUM] = cache->framesize; | |
238 | ||
239 | /* It is a LINK? */ | |
240 | if (next_addr < end_addr) | |
241 | { | |
242 | inst = read_memory_unsigned_integer (next_addr, 4, byte_order); | |
86feccb9 | 243 | if (FT32_IS_LINK (inst)) |
49d45b20 JB |
244 | { |
245 | cache->established = 1; | |
246 | for (regnum = FT32_R0_REGNUM; regnum < FT32_PC_REGNUM; regnum++) | |
247 | { | |
248 | if (cache->saved_regs[regnum] != REG_UNAVAIL) | |
249 | cache->saved_regs[regnum] += 4; | |
250 | } | |
251 | cache->saved_regs[FT32_PC_REGNUM] = cache->framesize + 4; | |
252 | cache->saved_regs[FT32_FP_REGNUM] = 0; | |
86feccb9 | 253 | cache->framesize += FT32_LINK_SIZE (inst); |
49d45b20 JB |
254 | next_addr += 4; |
255 | } | |
256 | } | |
257 | ||
258 | return next_addr; | |
259 | } | |
260 | ||
261 | /* Find the end of function prologue. */ | |
262 | ||
263 | static CORE_ADDR | |
264 | ft32_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) | |
265 | { | |
266 | CORE_ADDR func_addr = 0, func_end = 0; | |
267 | const char *func_name; | |
268 | ||
269 | /* See if we can determine the end of the prologue via the symbol table. | |
270 | If so, then return either PC, or the PC after the prologue, whichever | |
271 | is greater. */ | |
272 | if (find_pc_partial_function (pc, &func_name, &func_addr, &func_end)) | |
273 | { | |
274 | CORE_ADDR post_prologue_pc | |
275 | = skip_prologue_using_sal (gdbarch, func_addr); | |
276 | if (post_prologue_pc != 0) | |
277 | return max (pc, post_prologue_pc); | |
278 | else | |
279 | { | |
280 | /* Can't determine prologue from the symbol table, need to examine | |
281 | instructions. */ | |
282 | struct symtab_and_line sal; | |
283 | struct symbol *sym; | |
284 | struct ft32_frame_cache cache; | |
285 | CORE_ADDR plg_end; | |
286 | ||
287 | memset (&cache, 0, sizeof cache); | |
288 | ||
289 | plg_end = ft32_analyze_prologue (func_addr, | |
290 | func_end, &cache, gdbarch); | |
291 | /* Found a function. */ | |
835a09d9 | 292 | sym = lookup_symbol (func_name, NULL, VAR_DOMAIN, NULL).symbol; |
49d45b20 JB |
293 | /* Don't use line number debug info for assembly source files. */ |
294 | if ((sym != NULL) && SYMBOL_LANGUAGE (sym) != language_asm) | |
295 | { | |
296 | sal = find_pc_line (func_addr, 0); | |
297 | if (sal.end && sal.end < func_end) | |
298 | { | |
299 | /* Found a line number, use it as end of prologue. */ | |
300 | return sal.end; | |
301 | } | |
302 | } | |
303 | /* No useable line symbol. Use result of prologue parsing method. */ | |
304 | return plg_end; | |
305 | } | |
306 | } | |
307 | ||
308 | /* No function symbol -- just return the PC. */ | |
309 | return pc; | |
310 | } | |
311 | ||
623fb775 | 312 | /* Implementation of `pointer_to_address' gdbarch method. |
313 | ||
314 | On FT32 address space zero is RAM, address space 1 is flash. | |
315 | RAM appears at address RAM_BIAS, flash at address 0. */ | |
316 | ||
317 | static CORE_ADDR | |
318 | ft32_pointer_to_address (struct gdbarch *gdbarch, | |
319 | struct type *type, const gdb_byte *buf) | |
320 | { | |
321 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
322 | CORE_ADDR addr | |
323 | = extract_unsigned_integer (buf, TYPE_LENGTH (type), byte_order); | |
324 | ||
325 | if (TYPE_ADDRESS_CLASS_1 (type)) | |
326 | return addr; | |
327 | else | |
328 | return addr | RAM_BIAS; | |
329 | } | |
330 | ||
331 | /* Implementation of `address_class_type_flags' gdbarch method. | |
332 | ||
333 | This method maps DW_AT_address_class attributes to a | |
334 | type_instance_flag_value. */ | |
335 | ||
336 | static int | |
337 | ft32_address_class_type_flags (int byte_size, int dwarf2_addr_class) | |
338 | { | |
339 | /* The value 1 of the DW_AT_address_class attribute corresponds to the | |
340 | __flash__ qualifier, meaning pointer to data in FT32 program memory. | |
341 | */ | |
342 | if (dwarf2_addr_class == 1) | |
343 | return TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1; | |
344 | return 0; | |
345 | } | |
346 | ||
347 | /* Implementation of `address_class_type_flags_to_name' gdbarch method. | |
348 | ||
349 | Convert a type_instance_flag_value to an address space qualifier. */ | |
350 | ||
351 | static const char* | |
352 | ft32_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags) | |
353 | { | |
354 | if (type_flags & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1) | |
355 | return "flash"; | |
356 | else | |
357 | return NULL; | |
358 | } | |
359 | ||
360 | /* Implementation of `address_class_name_to_type_flags' gdbarch method. | |
361 | ||
362 | Convert an address space qualifier to a type_instance_flag_value. */ | |
363 | ||
364 | static int | |
365 | ft32_address_class_name_to_type_flags (struct gdbarch *gdbarch, | |
366 | const char* name, | |
367 | int *type_flags_ptr) | |
368 | { | |
369 | if (strcmp (name, "flash") == 0) | |
370 | { | |
371 | *type_flags_ptr = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1; | |
372 | return 1; | |
373 | } | |
374 | else | |
375 | return 0; | |
376 | } | |
377 | ||
378 | ||
49d45b20 JB |
379 | /* Implement the "read_pc" gdbarch method. */ |
380 | ||
381 | static CORE_ADDR | |
382 | ft32_read_pc (struct regcache *regcache) | |
383 | { | |
384 | ULONGEST pc; | |
385 | ||
386 | regcache_cooked_read_unsigned (regcache, FT32_PC_REGNUM, &pc); | |
387 | return pc; | |
388 | } | |
389 | ||
390 | /* Implement the "write_pc" gdbarch method. */ | |
391 | ||
392 | static void | |
393 | ft32_write_pc (struct regcache *regcache, CORE_ADDR val) | |
394 | { | |
395 | regcache_cooked_write_unsigned (regcache, FT32_PC_REGNUM, val); | |
396 | } | |
397 | ||
398 | /* Implement the "unwind_sp" gdbarch method. */ | |
399 | ||
400 | static CORE_ADDR | |
401 | ft32_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
402 | { | |
403 | return frame_unwind_register_unsigned (next_frame, FT32_SP_REGNUM); | |
404 | } | |
405 | ||
406 | /* Given a return value in `regbuf' with a type `valtype', | |
407 | extract and copy its value into `valbuf'. */ | |
408 | ||
409 | static void | |
410 | ft32_extract_return_value (struct type *type, struct regcache *regcache, | |
411 | gdb_byte *dst) | |
412 | { | |
413 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
414 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
415 | bfd_byte *valbuf = dst; | |
416 | int len = TYPE_LENGTH (type); | |
417 | ULONGEST tmp; | |
418 | ||
419 | /* By using store_unsigned_integer we avoid having to do | |
420 | anything special for small big-endian values. */ | |
421 | regcache_cooked_read_unsigned (regcache, FT32_R0_REGNUM, &tmp); | |
422 | store_unsigned_integer (valbuf, (len > 4 ? len - 4 : len), byte_order, tmp); | |
423 | ||
424 | /* Ignore return values more than 8 bytes in size because the ft32 | |
425 | returns anything more than 8 bytes in the stack. */ | |
426 | if (len > 4) | |
427 | { | |
428 | regcache_cooked_read_unsigned (regcache, FT32_R1_REGNUM, &tmp); | |
429 | store_unsigned_integer (valbuf + len - 4, 4, byte_order, tmp); | |
430 | } | |
431 | } | |
432 | ||
433 | /* Implement the "return_value" gdbarch method. */ | |
434 | ||
435 | static enum return_value_convention | |
436 | ft32_return_value (struct gdbarch *gdbarch, struct value *function, | |
437 | struct type *valtype, struct regcache *regcache, | |
438 | gdb_byte *readbuf, const gdb_byte *writebuf) | |
439 | { | |
440 | if (TYPE_LENGTH (valtype) > 8) | |
441 | return RETURN_VALUE_STRUCT_CONVENTION; | |
442 | else | |
443 | { | |
444 | if (readbuf != NULL) | |
445 | ft32_extract_return_value (valtype, regcache, readbuf); | |
446 | if (writebuf != NULL) | |
447 | ft32_store_return_value (valtype, regcache, writebuf); | |
448 | return RETURN_VALUE_REGISTER_CONVENTION; | |
449 | } | |
450 | } | |
451 | ||
452 | /* Allocate and initialize a ft32_frame_cache object. */ | |
453 | ||
454 | static struct ft32_frame_cache * | |
455 | ft32_alloc_frame_cache (void) | |
456 | { | |
457 | struct ft32_frame_cache *cache; | |
458 | int i; | |
459 | ||
460 | cache = FRAME_OBSTACK_ZALLOC (struct ft32_frame_cache); | |
461 | ||
462 | for (i = 0; i < FT32_NUM_REGS; ++i) | |
463 | cache->saved_regs[i] = REG_UNAVAIL; | |
464 | ||
465 | return cache; | |
466 | } | |
467 | ||
468 | /* Populate a ft32_frame_cache object for this_frame. */ | |
469 | ||
470 | static struct ft32_frame_cache * | |
471 | ft32_frame_cache (struct frame_info *this_frame, void **this_cache) | |
472 | { | |
473 | struct ft32_frame_cache *cache; | |
474 | CORE_ADDR current_pc; | |
475 | int i; | |
476 | ||
477 | if (*this_cache) | |
9a3c8263 | 478 | return (struct ft32_frame_cache *) *this_cache; |
49d45b20 JB |
479 | |
480 | cache = ft32_alloc_frame_cache (); | |
481 | *this_cache = cache; | |
482 | ||
483 | cache->base = get_frame_register_unsigned (this_frame, FT32_FP_REGNUM); | |
484 | if (cache->base == 0) | |
485 | return cache; | |
486 | ||
487 | cache->pc = get_frame_func (this_frame); | |
488 | current_pc = get_frame_pc (this_frame); | |
489 | if (cache->pc) | |
490 | { | |
491 | struct gdbarch *gdbarch = get_frame_arch (this_frame); | |
492 | ||
493 | ft32_analyze_prologue (cache->pc, current_pc, cache, gdbarch); | |
494 | if (!cache->established) | |
495 | cache->base = get_frame_register_unsigned (this_frame, FT32_SP_REGNUM); | |
496 | } | |
497 | ||
498 | cache->saved_sp = cache->base - 4; | |
499 | ||
500 | for (i = 0; i < FT32_NUM_REGS; ++i) | |
501 | if (cache->saved_regs[i] != REG_UNAVAIL) | |
502 | cache->saved_regs[i] = cache->base + cache->saved_regs[i]; | |
503 | ||
504 | return cache; | |
505 | } | |
506 | ||
507 | /* Implement the "unwind_pc" gdbarch method. */ | |
508 | ||
509 | static CORE_ADDR | |
510 | ft32_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
511 | { | |
512 | return frame_unwind_register_unsigned (next_frame, FT32_PC_REGNUM); | |
513 | } | |
514 | ||
515 | /* Given a GDB frame, determine the address of the calling function's | |
516 | frame. This will be used to create a new GDB frame struct. */ | |
517 | ||
518 | static void | |
519 | ft32_frame_this_id (struct frame_info *this_frame, | |
520 | void **this_prologue_cache, struct frame_id *this_id) | |
521 | { | |
522 | struct ft32_frame_cache *cache = ft32_frame_cache (this_frame, | |
523 | this_prologue_cache); | |
524 | ||
525 | /* This marks the outermost frame. */ | |
526 | if (cache->base == 0) | |
527 | return; | |
528 | ||
529 | *this_id = frame_id_build (cache->saved_sp, cache->pc); | |
530 | } | |
531 | ||
532 | /* Get the value of register regnum in the previous stack frame. */ | |
533 | ||
534 | static struct value * | |
535 | ft32_frame_prev_register (struct frame_info *this_frame, | |
536 | void **this_prologue_cache, int regnum) | |
537 | { | |
538 | struct ft32_frame_cache *cache = ft32_frame_cache (this_frame, | |
539 | this_prologue_cache); | |
540 | ||
541 | gdb_assert (regnum >= 0); | |
542 | ||
543 | if (regnum == FT32_SP_REGNUM && cache->saved_sp) | |
544 | return frame_unwind_got_constant (this_frame, regnum, cache->saved_sp); | |
545 | ||
546 | if (regnum < FT32_NUM_REGS && cache->saved_regs[regnum] != REG_UNAVAIL) | |
547 | return frame_unwind_got_memory (this_frame, regnum, | |
548 | RAM_BIAS | cache->saved_regs[regnum]); | |
549 | ||
550 | return frame_unwind_got_register (this_frame, regnum, regnum); | |
551 | } | |
552 | ||
553 | static const struct frame_unwind ft32_frame_unwind = | |
554 | { | |
555 | NORMAL_FRAME, | |
556 | default_frame_unwind_stop_reason, | |
557 | ft32_frame_this_id, | |
558 | ft32_frame_prev_register, | |
559 | NULL, | |
560 | default_frame_sniffer | |
561 | }; | |
562 | ||
563 | /* Return the base address of this_frame. */ | |
564 | ||
565 | static CORE_ADDR | |
566 | ft32_frame_base_address (struct frame_info *this_frame, void **this_cache) | |
567 | { | |
568 | struct ft32_frame_cache *cache = ft32_frame_cache (this_frame, | |
569 | this_cache); | |
570 | ||
571 | return cache->base; | |
572 | } | |
573 | ||
574 | static const struct frame_base ft32_frame_base = | |
575 | { | |
576 | &ft32_frame_unwind, | |
577 | ft32_frame_base_address, | |
578 | ft32_frame_base_address, | |
579 | ft32_frame_base_address | |
580 | }; | |
581 | ||
582 | static struct frame_id | |
583 | ft32_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame) | |
584 | { | |
585 | CORE_ADDR sp = get_frame_register_unsigned (this_frame, FT32_SP_REGNUM); | |
586 | ||
587 | return frame_id_build (sp, get_frame_pc (this_frame)); | |
588 | } | |
589 | ||
590 | /* Allocate and initialize the ft32 gdbarch object. */ | |
591 | ||
592 | static struct gdbarch * | |
593 | ft32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | |
594 | { | |
595 | struct gdbarch *gdbarch; | |
596 | struct gdbarch_tdep *tdep; | |
623fb775 | 597 | struct type *void_type; |
598 | struct type *func_void_type; | |
49d45b20 JB |
599 | |
600 | /* If there is already a candidate, use it. */ | |
601 | arches = gdbarch_list_lookup_by_info (arches, &info); | |
602 | if (arches != NULL) | |
603 | return arches->gdbarch; | |
604 | ||
605 | /* Allocate space for the new architecture. */ | |
606 | tdep = XNEW (struct gdbarch_tdep); | |
607 | gdbarch = gdbarch_alloc (&info, tdep); | |
608 | ||
623fb775 | 609 | /* Create a type for PC. We can't use builtin types here, as they may not |
610 | be defined. */ | |
611 | void_type = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void"); | |
612 | func_void_type = make_function_type (void_type, NULL); | |
613 | tdep->pc_type = arch_type (gdbarch, TYPE_CODE_PTR, 4, NULL); | |
614 | TYPE_TARGET_TYPE (tdep->pc_type) = func_void_type; | |
615 | TYPE_UNSIGNED (tdep->pc_type) = 1; | |
616 | TYPE_INSTANCE_FLAGS (tdep->pc_type) |= TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1; | |
617 | ||
49d45b20 JB |
618 | set_gdbarch_read_pc (gdbarch, ft32_read_pc); |
619 | set_gdbarch_write_pc (gdbarch, ft32_write_pc); | |
620 | set_gdbarch_unwind_sp (gdbarch, ft32_unwind_sp); | |
621 | ||
622 | set_gdbarch_num_regs (gdbarch, FT32_NUM_REGS); | |
623 | set_gdbarch_sp_regnum (gdbarch, FT32_SP_REGNUM); | |
624 | set_gdbarch_pc_regnum (gdbarch, FT32_PC_REGNUM); | |
625 | set_gdbarch_register_name (gdbarch, ft32_register_name); | |
626 | set_gdbarch_register_type (gdbarch, ft32_register_type); | |
627 | ||
628 | set_gdbarch_return_value (gdbarch, ft32_return_value); | |
629 | ||
623fb775 | 630 | set_gdbarch_pointer_to_address (gdbarch, ft32_pointer_to_address); |
631 | ||
49d45b20 JB |
632 | set_gdbarch_skip_prologue (gdbarch, ft32_skip_prologue); |
633 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
634 | set_gdbarch_breakpoint_from_pc (gdbarch, ft32_breakpoint_from_pc); | |
635 | set_gdbarch_frame_align (gdbarch, ft32_frame_align); | |
636 | ||
637 | frame_base_set_default (gdbarch, &ft32_frame_base); | |
638 | ||
639 | /* Methods for saving / extracting a dummy frame's ID. The ID's | |
640 | stack address must match the SP value returned by | |
641 | PUSH_DUMMY_CALL, and saved by generic_save_dummy_frame_tos. */ | |
642 | set_gdbarch_dummy_id (gdbarch, ft32_dummy_id); | |
643 | ||
644 | set_gdbarch_unwind_pc (gdbarch, ft32_unwind_pc); | |
645 | ||
646 | set_gdbarch_print_insn (gdbarch, print_insn_ft32); | |
647 | ||
648 | /* Hook in ABI-specific overrides, if they have been registered. */ | |
649 | gdbarch_init_osabi (info, gdbarch); | |
650 | ||
651 | /* Hook in the default unwinders. */ | |
652 | frame_unwind_append_unwinder (gdbarch, &ft32_frame_unwind); | |
653 | ||
654 | /* Support simple overlay manager. */ | |
655 | set_gdbarch_overlay_update (gdbarch, simple_overlay_update); | |
656 | ||
623fb775 | 657 | set_gdbarch_address_class_type_flags (gdbarch, ft32_address_class_type_flags); |
658 | set_gdbarch_address_class_name_to_type_flags | |
659 | (gdbarch, ft32_address_class_name_to_type_flags); | |
660 | set_gdbarch_address_class_type_flags_to_name | |
661 | (gdbarch, ft32_address_class_type_flags_to_name); | |
662 | ||
49d45b20 JB |
663 | return gdbarch; |
664 | } | |
665 | ||
666 | /* Register this machine's init routine. */ | |
667 | ||
668 | void | |
669 | _initialize_ft32_tdep (void) | |
670 | { | |
671 | register_gdbarch_init (bfd_arch_ft32, ft32_gdbarch_init); | |
672 | } |