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