| OLD | NEW |
| 1 /* Target-dependent code for the Tilera TILE-Gx processor. | 1 /* Target-dependent code for the Tilera TILE-Gx processor. |
| 2 | 2 |
| 3 Copyright (C) 2012 Free Software Foundation, Inc. | 3 Copyright (C) 2012-2013 Free Software Foundation, Inc. |
| 4 | 4 |
| 5 This file is part of GDB. | 5 This file is part of GDB. |
| 6 | 6 |
| 7 This program is free software; you can redistribute it and/or modify | 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 | 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 | 9 the Free Software Foundation; either version 3 of the License, or |
| 10 (at your option) any later version. | 10 (at your option) any later version. |
| 11 | 11 |
| 12 This program is distributed in the hope that it will be useful, | 12 This program is distributed in the hope that it will be useful, |
| 13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
| 16 | 16 |
| 17 You should have received a copy of the GNU General Public License | 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/>. */ | 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 19 | 19 |
| 20 #include "defs.h" | 20 #include "defs.h" |
| 21 #include "frame.h" | 21 #include "frame.h" |
| 22 #include "frame-base.h" | 22 #include "frame-base.h" |
| 23 #include "frame-unwind.h" | 23 #include "frame-unwind.h" |
| 24 #include "dwarf2-frame.h" | 24 #include "dwarf2-frame.h" |
| 25 #include "trad-frame.h" | 25 #include "trad-frame.h" |
| 26 #include "symtab.h" | 26 #include "symtab.h" |
| 27 #include "gdbtypes.h" | 27 #include "gdbtypes.h" |
| 28 #include "gdbcmd.h" | 28 #include "gdbcmd.h" |
| 29 #include "gdbcore.h" | 29 #include "gdbcore.h" |
| 30 #include "value.h" | 30 #include "value.h" |
| 31 #include "dis-asm.h" | 31 #include "dis-asm.h" |
| 32 #include "inferior.h" | 32 #include "inferior.h" |
| 33 #include "gdb_string.h" | 33 #include <string.h> |
| 34 #include "gdb_assert.h" | 34 #include "gdb_assert.h" |
| 35 #include "arch-utils.h" | 35 #include "arch-utils.h" |
| 36 #include "floatformat.h" | 36 #include "floatformat.h" |
| 37 #include "regcache.h" | 37 #include "regcache.h" |
| 38 #include "regset.h" | 38 #include "regset.h" |
| 39 #include "doublest.h" | 39 #include "doublest.h" |
| 40 #include "osabi.h" | 40 #include "osabi.h" |
| 41 #include "linux-tdep.h" | 41 #include "linux-tdep.h" |
| 42 #include "objfiles.h" | 42 #include "objfiles.h" |
| 43 #include "solib-svr4.h" | 43 #include "solib-svr4.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 static const char *const register_names[TILEGX_NUM_REGS] = | 148 static const char *const register_names[TILEGX_NUM_REGS] = |
| 149 { | 149 { |
| 150 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | 150 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 151 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | 151 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 152 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", | 152 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", |
| 153 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", | 153 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", |
| 154 "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39", | 154 "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39", |
| 155 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47", | 155 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47", |
| 156 "r48", "r49", "r50", "r51", "r52", "tp", "sp", "lr", | 156 "r48", "r49", "r50", "r51", "r52", "tp", "sp", "lr", |
| 157 "sn", "idn0", "idn1", "udn0", "udn1", "udn2", "udn3", "zero", | 157 "sn", "idn0", "idn1", "udn0", "udn1", "udn2", "udn3", "zero", |
| 158 "pc" | 158 "pc", "faultnum", |
| 159 }; | 159 }; |
| 160 | 160 |
| 161 if (regnum < 0 || regnum >= TILEGX_NUM_REGS) | 161 if (regnum < 0 || regnum >= TILEGX_NUM_REGS) |
| 162 internal_error (__FILE__, __LINE__, | 162 internal_error (__FILE__, __LINE__, |
| 163 "tilegx_register_name: invalid register number %d", | 163 "tilegx_register_name: invalid register number %d", |
| 164 regnum); | 164 regnum); |
| 165 | 165 |
| 166 return register_names[regnum]; | 166 return register_names[regnum]; |
| 167 } | 167 } |
| 168 | 168 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 CORE_ADDR bp_addr, int nargs, | 285 CORE_ADDR bp_addr, int nargs, |
| 286 struct value **args, | 286 struct value **args, |
| 287 CORE_ADDR sp, int struct_return, | 287 CORE_ADDR sp, int struct_return, |
| 288 CORE_ADDR struct_addr) | 288 CORE_ADDR struct_addr) |
| 289 { | 289 { |
| 290 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | 290 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
| 291 CORE_ADDR stack_dest = sp; | 291 CORE_ADDR stack_dest = sp; |
| 292 int argreg = TILEGX_R0_REGNUM; | 292 int argreg = TILEGX_R0_REGNUM; |
| 293 int i, j; | 293 int i, j; |
| 294 int typelen, slacklen, alignlen; | 294 int typelen, slacklen, alignlen; |
| 295 static const gdb_byte two_zero_words[8] = { 0 }; | 295 static const gdb_byte four_zero_words[16] = { 0 }; |
| 296 | 296 |
| 297 /* If struct_return is 1, then the struct return address will | 297 /* If struct_return is 1, then the struct return address will |
| 298 consume one argument-passing register. */ | 298 consume one argument-passing register. */ |
| 299 if (struct_return) | 299 if (struct_return) |
| 300 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); | 300 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr); |
| 301 | 301 |
| 302 /* Arguments are passed in R0 - R9, and as soon as an argument | 302 /* Arguments are passed in R0 - R9, and as soon as an argument |
| 303 will not fit completely in the remaining registers, then it, | 303 will not fit completely in the remaining registers, then it, |
| 304 and all remaining arguments, are put on the stack. */ | 304 and all remaining arguments, are put on the stack. */ |
| 305 for (i = 0; i < nargs && argreg <= TILEGX_R9_REGNUM; i++) | 305 for (i = 0; i < nargs && argreg <= TILEGX_R9_REGNUM; i++) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 319 int n = (typelen - j == 1) ? 1 : tilegx_reg_size; | 319 int n = (typelen - j == 1) ? 1 : tilegx_reg_size; |
| 320 ULONGEST w = extract_unsigned_integer (val + j, n, byte_order); | 320 ULONGEST w = extract_unsigned_integer (val + j, n, byte_order); |
| 321 | 321 |
| 322 regcache_cooked_write_unsigned (regcache, argreg++, w); | 322 regcache_cooked_write_unsigned (regcache, argreg++, w); |
| 323 } | 323 } |
| 324 } | 324 } |
| 325 | 325 |
| 326 /* Align SP. */ | 326 /* Align SP. */ |
| 327 stack_dest = tilegx_frame_align (gdbarch, stack_dest); | 327 stack_dest = tilegx_frame_align (gdbarch, stack_dest); |
| 328 | 328 |
| 329 /* Loop backwards through arguments to determine stack alignment. */ | |
| 330 alignlen = 0; | |
| 331 | |
| 332 for (j = nargs - 1; j >= i; j--) | |
| 333 { | |
| 334 typelen = TYPE_LENGTH (value_enclosing_type (args[j])); | |
| 335 alignlen += (typelen + 3) & (~3); | |
| 336 } | |
| 337 | |
| 338 if (alignlen & 0x4) | |
| 339 stack_dest -= 4; | |
| 340 | |
| 341 /* Loop backwards through remaining arguments and push them on | 329 /* Loop backwards through remaining arguments and push them on |
| 342 the stack, word aligned. */ | 330 the stack, word aligned. */ |
| 343 for (j = nargs - 1; j >= i; j--) | 331 for (j = nargs - 1; j >= i; j--) |
| 344 { | 332 { |
| 345 gdb_byte *val; | 333 gdb_byte *val; |
| 334 struct cleanup *back_to; |
| 335 const gdb_byte *contents = value_contents (args[j]); |
| 346 | 336 |
| 347 typelen = TYPE_LENGTH (value_enclosing_type (args[j])); | 337 typelen = TYPE_LENGTH (value_enclosing_type (args[j])); |
| 348 slacklen = ((typelen + 3) & (~3)) - typelen; | 338 slacklen = align_up (typelen, 8) - typelen; |
| 349 val = alloca (typelen + slacklen); | 339 val = xmalloc (typelen + slacklen); |
| 350 memcpy (val, value_contents (args[j]), typelen); | 340 back_to = make_cleanup (xfree, val); |
| 341 memcpy (val, contents, typelen); |
| 351 memset (val + typelen, 0, slacklen); | 342 memset (val + typelen, 0, slacklen); |
| 352 | 343 |
| 353 /* Now write data to the stack. The stack grows downwards. */ | 344 /* Now write data to the stack. The stack grows downwards. */ |
| 354 stack_dest -= typelen + slacklen; | 345 stack_dest -= typelen + slacklen; |
| 355 write_memory (stack_dest, val, typelen + slacklen); | 346 write_memory (stack_dest, val, typelen + slacklen); |
| 347 do_cleanups (back_to); |
| 356 } | 348 } |
| 357 | 349 |
| 358 /* Add 2 words for linkage space to the stack. */ | 350 /* Add 16 bytes for linkage space to the stack. */ |
| 359 stack_dest = stack_dest - 8; | 351 stack_dest = stack_dest - 16; |
| 360 write_memory (stack_dest, two_zero_words, 8); | 352 write_memory (stack_dest, four_zero_words, 16); |
| 361 | 353 |
| 362 /* Update stack pointer. */ | 354 /* Update stack pointer. */ |
| 363 regcache_cooked_write_unsigned (regcache, TILEGX_SP_REGNUM, stack_dest); | 355 regcache_cooked_write_unsigned (regcache, TILEGX_SP_REGNUM, stack_dest); |
| 364 | 356 |
| 365 /* Set the return address register to point to the entry point of | 357 /* Set the return address register to point to the entry point of |
| 366 the program, where a breakpoint lies in wait. */ | 358 the program, where a breakpoint lies in wait. */ |
| 367 regcache_cooked_write_unsigned (regcache, TILEGX_LR_REGNUM, bp_addr); | 359 regcache_cooked_write_unsigned (regcache, TILEGX_LR_REGNUM, bp_addr); |
| 368 | 360 |
| 369 return stack_dest; | 361 return stack_dest; |
| 370 } | 362 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 394 unsigned int instbuf_size; | 386 unsigned int instbuf_size; |
| 395 int status; | 387 int status; |
| 396 bfd_uint64_t bundle; | 388 bfd_uint64_t bundle; |
| 397 struct tilegx_decoded_instruction | 389 struct tilegx_decoded_instruction |
| 398 decoded[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE]; | 390 decoded[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE]; |
| 399 int num_insns; | 391 int num_insns; |
| 400 struct tilegx_reverse_regs reverse_frame[TILEGX_NUM_PHYS_REGS]; | 392 struct tilegx_reverse_regs reverse_frame[TILEGX_NUM_PHYS_REGS]; |
| 401 struct tilegx_reverse_regs | 393 struct tilegx_reverse_regs |
| 402 new_reverse_frame[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE]; | 394 new_reverse_frame[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE]; |
| 403 int dest_regs[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE]; | 395 int dest_regs[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE]; |
| 404 int reverse_frame_valid, prolog_done, branch_seen; | 396 int reverse_frame_valid, prolog_done, branch_seen, lr_saved_on_stack_p; |
| 405 LONGEST prev_sp_value; | 397 LONGEST prev_sp_value; |
| 406 int i, j; | 398 int i, j; |
| 407 | 399 |
| 408 if (start_addr >= end_addr | 400 if (start_addr >= end_addr |
| 409 || (start_addr % TILEGX_BUNDLE_ALIGNMENT_IN_BYTES) != 0) | 401 || (start_addr % TILEGX_BUNDLE_ALIGNMENT_IN_BYTES) != 0) |
| 410 return end_addr; | 402 return end_addr; |
| 411 | 403 |
| 412 /* Initialize the reverse frame. This maps the CURRENT frame's | 404 /* Initialize the reverse frame. This maps the CURRENT frame's |
| 413 registers to the outer frame's registers (the frame on the | 405 registers to the outer frame's registers (the frame on the |
| 414 stack goes the other way). */ | 406 stack goes the other way). */ |
| 415 memcpy (&reverse_frame, &template_reverse_regs, sizeof (reverse_frame)); | 407 memcpy (&reverse_frame, &template_reverse_regs, sizeof (reverse_frame)); |
| 416 | 408 |
| 417 prolog_done = 0; | 409 prolog_done = 0; |
| 418 branch_seen = 0; | 410 branch_seen = 0; |
| 419 prev_sp_value = 0; | 411 prev_sp_value = 0; |
| 412 lr_saved_on_stack_p = 0; |
| 420 | 413 |
| 421 /* To cut down on round-trip overhead, we fetch multiple bundles | 414 /* To cut down on round-trip overhead, we fetch multiple bundles |
| 422 at once. These variables describe the range of memory we have | 415 at once. These variables describe the range of memory we have |
| 423 prefetched. */ | 416 prefetched. */ |
| 424 instbuf_start = 0; | 417 instbuf_start = 0; |
| 425 instbuf_size = 0; | 418 instbuf_size = 0; |
| 426 | 419 |
| 427 for (next_addr = start_addr; | 420 for (next_addr = start_addr; |
| 428 next_addr < end_addr; | 421 next_addr < end_addr; |
| 429 next_addr += TILEGX_BUNDLE_SIZE_IN_BYTES) | 422 next_addr += TILEGX_BUNDLE_SIZE_IN_BYTES) |
| 430 { | 423 { |
| 431 /* Retrieve the next instruction. */ | 424 /* Retrieve the next instruction. */ |
| 432 if (next_addr - instbuf_start >= instbuf_size) | 425 if (next_addr - instbuf_start >= instbuf_size) |
| 433 { | 426 { |
| 434 /* Figure out how many bytes to fetch. Don't span a page | 427 /* Figure out how many bytes to fetch. Don't span a page |
| 435 boundary since that might cause an unnecessary memory | 428 boundary since that might cause an unnecessary memory |
| 436 error. */ | 429 error. */ |
| 437 unsigned int size_on_same_page = 4096 - (next_addr & 4095); | 430 unsigned int size_on_same_page = 4096 - (next_addr & 4095); |
| 438 | 431 |
| 439 instbuf_size = sizeof instbuf; | 432 instbuf_size = sizeof instbuf; |
| 440 | 433 |
| 441 if (instbuf_size > size_on_same_page) | 434 if (instbuf_size > size_on_same_page) |
| 442 instbuf_size = size_on_same_page; | 435 instbuf_size = size_on_same_page; |
| 436 |
| 437 instbuf_size = min (instbuf_size, (end_addr - next_addr)); |
| 443 instbuf_start = next_addr; | 438 instbuf_start = next_addr; |
| 444 | 439 |
| 445 status = safe_frame_unwind_memory (next_frame, instbuf_start, | 440 status = safe_frame_unwind_memory (next_frame, instbuf_start, |
| 446 instbuf, instbuf_size); | 441 instbuf, instbuf_size); |
| 447 if (status == 0) | 442 if (status == 0) |
| 448 memory_error (status, next_addr); | 443 memory_error (status, next_addr); |
| 449 } | 444 } |
| 450 | 445 |
| 451 reverse_frame_valid = 0; | 446 reverse_frame_valid = 0; |
| 452 | 447 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 473 unsigned saved_register | 468 unsigned saved_register |
| 474 = (unsigned) reverse_frame[operands[1]].value; | 469 = (unsigned) reverse_frame[operands[1]].value; |
| 475 | 470 |
| 476 /* realreg >= 0 and addr != -1 indicates that the | 471 /* realreg >= 0 and addr != -1 indicates that the |
| 477 value of saved_register is in memory location | 472 value of saved_register is in memory location |
| 478 saved_address. The value of realreg is not | 473 saved_address. The value of realreg is not |
| 479 meaningful in this case but it must be >= 0. | 474 meaningful in this case but it must be >= 0. |
| 480 See trad-frame.h. */ | 475 See trad-frame.h. */ |
| 481 cache->saved_regs[saved_register].realreg = saved_register; | 476 cache->saved_regs[saved_register].realreg = saved_register; |
| 482 cache->saved_regs[saved_register].addr = saved_address; | 477 cache->saved_regs[saved_register].addr = saved_address; |
| 483 » » } | 478 » » } |
| 479 » else if (cache |
| 480 » » && (operands[0] == TILEGX_SP_REGNUM) |
| 481 » » && (operands[1] == TILEGX_LR_REGNUM)) |
| 482 » » lr_saved_on_stack_p = 1; |
| 484 break; | 483 break; |
| 485 case TILEGX_OPC_ADDI: | 484 case TILEGX_OPC_ADDI: |
| 486 case TILEGX_OPC_ADDLI: | 485 case TILEGX_OPC_ADDLI: |
| 487 if (cache | 486 if (cache |
| 488 && operands[0] == TILEGX_SP_REGNUM | 487 && operands[0] == TILEGX_SP_REGNUM |
| 489 && operands[1] == TILEGX_SP_REGNUM | 488 && operands[1] == TILEGX_SP_REGNUM |
| 490 && reverse_frame[operands[1]].state == REVERSE_STATE_REGISTER) | 489 && reverse_frame[operands[1]].state == REVERSE_STATE_REGISTER) |
| 491 { | 490 { |
| 492 /* Special case. We're fixing up the stack frame. */ | 491 /* Special case. We're fixing up the stack frame. */ |
| 493 uint64_t hopefully_sp | 492 uint64_t hopefully_sp |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 && reverse_frame[i].value != i) | 725 && reverse_frame[i].value != i) |
| 727 { | 726 { |
| 728 unsigned saved_register = (unsigned) reverse_frame[i].value; | 727 unsigned saved_register = (unsigned) reverse_frame[i].value; |
| 729 | 728 |
| 730 cache->saved_regs[saved_register].realreg = i; | 729 cache->saved_regs[saved_register].realreg = i; |
| 731 cache->saved_regs[saved_register].addr = (LONGEST) -1; | 730 cache->saved_regs[saved_register].addr = (LONGEST) -1; |
| 732 } | 731 } |
| 733 } | 732 } |
| 734 } | 733 } |
| 735 | 734 |
| 735 if (lr_saved_on_stack_p) |
| 736 { |
| 737 cache->saved_regs[TILEGX_LR_REGNUM].realreg = TILEGX_LR_REGNUM; |
| 738 cache->saved_regs[TILEGX_LR_REGNUM].addr = |
| 739 cache->saved_regs[TILEGX_SP_REGNUM].addr; |
| 740 } |
| 741 |
| 736 return prolog_end; | 742 return prolog_end; |
| 737 } | 743 } |
| 738 | 744 |
| 739 /* This is the implementation of gdbarch method skip_prologue. */ | 745 /* This is the implementation of gdbarch method skip_prologue. */ |
| 740 | 746 |
| 741 static CORE_ADDR | 747 static CORE_ADDR |
| 742 tilegx_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) | 748 tilegx_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc) |
| 743 { | 749 { |
| 744 struct symtab_and_line sal; | 750 CORE_ADDR func_start, end_pc; |
| 745 CORE_ADDR func_start, func_end; | 751 struct obj_section *s; |
| 746 | 752 |
| 747 /* This is the preferred method, find the end of the prologue by | 753 /* This is the preferred method, find the end of the prologue by |
| 748 using the debugging information. */ | 754 using the debugging information. */ |
| 749 if (find_pc_partial_function (pc, NULL, &func_start, &func_end)) | 755 if (find_pc_partial_function (start_pc, NULL, &func_start, NULL)) |
| 750 { | 756 { |
| 751 » sal = find_pc_line (func_start, 0); | 757 CORE_ADDR post_prologue_pc |
| 758 = skip_prologue_using_sal (gdbarch, func_start); |
| 752 | 759 |
| 753 » if (sal.end < func_end && pc <= sal.end) | 760 if (post_prologue_pc != 0) |
| 754 » return sal.end; | 761 return max (start_pc, post_prologue_pc); |
| 755 } | 762 } |
| 756 | 763 |
| 764 /* Don't straddle a section boundary. */ |
| 765 s = find_pc_section (start_pc); |
| 766 end_pc = start_pc + 8 * TILEGX_BUNDLE_SIZE_IN_BYTES; |
| 767 if (s != NULL) |
| 768 end_pc = min (end_pc, obj_section_endaddr (s)); |
| 769 |
| 757 /* Otherwise, try to skip prologue the hard way. */ | 770 /* Otherwise, try to skip prologue the hard way. */ |
| 758 return tilegx_analyze_prologue (gdbarch, | 771 return tilegx_analyze_prologue (gdbarch, |
| 759 » » » » pc, pc + 8 * TILEGX_BUNDLE_SIZE_IN_BYTES, | 772 » » » » start_pc, |
| 773 » » » » end_pc, |
| 760 NULL, NULL); | 774 NULL, NULL); |
| 761 } | 775 } |
| 762 | 776 |
| 763 /* This is the implementation of gdbarch method in_function_epilogue_p. */ | 777 /* This is the implementation of gdbarch method in_function_epilogue_p. */ |
| 764 | 778 |
| 765 static int | 779 static int |
| 766 tilegx_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) | 780 tilegx_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) |
| 767 { | 781 { |
| 768 CORE_ADDR func_addr = 0, func_end = 0; | 782 CORE_ADDR func_addr = 0, func_end = 0; |
| 769 | 783 |
| 770 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | 784 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end)) |
| 771 { | 785 { |
| 772 ULONGEST inst, inst2; | 786 ULONGEST inst, inst2; |
| 773 CORE_ADDR addr = func_end - TILEGX_BUNDLE_SIZE_IN_BYTES; | 787 CORE_ADDR addr = func_end - TILEGX_BUNDLE_SIZE_IN_BYTES; |
| 774 | 788 |
| 775 /* FIXME: Find the actual epilogue. */ | 789 /* FIXME: Find the actual epilogue. */ |
| 776 /* HACK: Just assume the final bundle is the "ret" instruction". */ | 790 /* HACK: Just assume the final bundle is the "ret" instruction". */ |
| 777 if (pc > addr) | 791 if (pc > addr) |
| 778 return 1; | 792 return 1; |
| 779 } | 793 } |
| 780 return 0; | 794 return 0; |
| 781 } | 795 } |
| 782 | 796 |
| 797 /* This is the implementation of gdbarch method get_longjmp_target. */ |
| 798 |
| 799 static int |
| 800 tilegx_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc) |
| 801 { |
| 802 struct gdbarch *gdbarch = get_frame_arch (frame); |
| 803 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
| 804 CORE_ADDR jb_addr; |
| 805 gdb_byte buf[8]; |
| 806 |
| 807 jb_addr = get_frame_register_unsigned (frame, TILEGX_R0_REGNUM); |
| 808 |
| 809 /* TileGX jmp_buf contains 32 elements of type __uint_reg_t which |
| 810 has a size of 8 bytes. The return address is stored in the 25th |
| 811 slot. */ |
| 812 if (target_read_memory (jb_addr + 25 * 8, buf, 8)) |
| 813 return 0; |
| 814 |
| 815 *pc = extract_unsigned_integer (buf, 8, byte_order); |
| 816 |
| 817 return 1; |
| 818 } |
| 819 |
| 820 /* by assigning the 'faultnum' reg in kernel pt_regs with this value, |
| 821 kernel do_signal will not check r0. see tilegx kernel/signal.c |
| 822 for details. */ |
| 823 #define INT_SWINT_1_SIGRETURN (~0) |
| 824 |
| 825 /* Implement the "write_pc" gdbarch method. */ |
| 826 |
| 827 static void |
| 828 tilegx_write_pc (struct regcache *regcache, CORE_ADDR pc) |
| 829 { |
| 830 regcache_cooked_write_unsigned (regcache, TILEGX_PC_REGNUM, pc); |
| 831 |
| 832 /* We must be careful with modifying the program counter. If we |
| 833 just interrupted a system call, the kernel might try to restart |
| 834 it when we resume the inferior. On restarting the system call, |
| 835 the kernel will try backing up the program counter even though it |
| 836 no longer points at the system call. This typically results in a |
| 837 SIGSEGV or SIGILL. We can prevent this by writing INT_SWINT_1_SIGRETURN |
| 838 in the "faultnum" pseudo-register. |
| 839 |
| 840 Note that "faultnum" is saved when setting up a dummy call frame. |
| 841 This means that it is properly restored when that frame is |
| 842 popped, and that the interrupted system call will be restarted |
| 843 when we resume the inferior on return from a function call from |
| 844 within GDB. In all other cases the system call will not be |
| 845 restarted. */ |
| 846 regcache_cooked_write_unsigned (regcache, TILEGX_FAULTNUM_REGNUM, |
| 847 INT_SWINT_1_SIGRETURN); |
| 848 } |
| 849 |
| 783 /* This is the implementation of gdbarch method breakpoint_from_pc. */ | 850 /* This is the implementation of gdbarch method breakpoint_from_pc. */ |
| 784 | 851 |
| 785 static const unsigned char * | 852 static const unsigned char * |
| 786 tilegx_breakpoint_from_pc (struct gdbarch *gdbarch, | 853 tilegx_breakpoint_from_pc (struct gdbarch *gdbarch, |
| 787 CORE_ADDR *pcptr, int *lenptr) | 854 CORE_ADDR *pcptr, int *lenptr) |
| 788 { | 855 { |
| 789 /* 64-bit pattern for a { bpt ; nop } bundle. */ | 856 /* 64-bit pattern for a { bpt ; nop } bundle. */ |
| 790 static const unsigned char breakpoint[] = | 857 static const unsigned char breakpoint[] = |
| 791 { 0x00, 0x50, 0x48, 0x51, 0xae, 0x44, 0x6a, 0x28 }; | 858 { 0x00, 0x50, 0x48, 0x51, 0xae, 0x44, 0x6a, 0x28 }; |
| 792 | 859 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 810 cache = FRAME_OBSTACK_ZALLOC (struct tilegx_frame_cache); | 877 cache = FRAME_OBSTACK_ZALLOC (struct tilegx_frame_cache); |
| 811 *this_cache = cache; | 878 *this_cache = cache; |
| 812 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame); | 879 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame); |
| 813 cache->base = 0; | 880 cache->base = 0; |
| 814 cache->start_pc = get_frame_func (this_frame); | 881 cache->start_pc = get_frame_func (this_frame); |
| 815 current_pc = get_frame_pc (this_frame); | 882 current_pc = get_frame_pc (this_frame); |
| 816 | 883 |
| 817 cache->base = get_frame_register_unsigned (this_frame, TILEGX_SP_REGNUM); | 884 cache->base = get_frame_register_unsigned (this_frame, TILEGX_SP_REGNUM); |
| 818 trad_frame_set_value (cache->saved_regs, TILEGX_SP_REGNUM, cache->base); | 885 trad_frame_set_value (cache->saved_regs, TILEGX_SP_REGNUM, cache->base); |
| 819 | 886 |
| 820 cache->saved_regs[TILEGX_PC_REGNUM] = cache->saved_regs[TILEGX_LR_REGNUM]; | |
| 821 if (cache->start_pc) | 887 if (cache->start_pc) |
| 822 tilegx_analyze_prologue (gdbarch, cache->start_pc, current_pc, | 888 tilegx_analyze_prologue (gdbarch, cache->start_pc, current_pc, |
| 823 cache, this_frame); | 889 cache, this_frame); |
| 824 | 890 |
| 891 cache->saved_regs[TILEGX_PC_REGNUM] = cache->saved_regs[TILEGX_LR_REGNUM]; |
| 892 |
| 825 return cache; | 893 return cache; |
| 826 } | 894 } |
| 827 | 895 |
| 828 /* Retrieve the value of REGNUM in FRAME. */ | 896 /* Retrieve the value of REGNUM in FRAME. */ |
| 829 | 897 |
| 830 static struct value* | 898 static struct value* |
| 831 tilegx_frame_prev_register (struct frame_info *this_frame, | 899 tilegx_frame_prev_register (struct frame_info *this_frame, |
| 832 void **this_cache, | 900 void **this_cache, |
| 833 int regnum) | 901 int regnum) |
| 834 { | 902 { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 } | 972 } |
| 905 | 973 |
| 906 | 974 |
| 907 /* We cannot read/write the "special" registers. */ | 975 /* We cannot read/write the "special" registers. */ |
| 908 | 976 |
| 909 static int | 977 static int |
| 910 tilegx_cannot_reference_register (struct gdbarch *gdbarch, int regno) | 978 tilegx_cannot_reference_register (struct gdbarch *gdbarch, int regno) |
| 911 { | 979 { |
| 912 if (regno >= 0 && regno < TILEGX_NUM_EASY_REGS) | 980 if (regno >= 0 && regno < TILEGX_NUM_EASY_REGS) |
| 913 return 0; | 981 return 0; |
| 914 else if (regno == TILEGX_PC_REGNUM) | 982 else if (regno == TILEGX_PC_REGNUM |
| 983 || regno == TILEGX_FAULTNUM_REGNUM) |
| 915 return 0; | 984 return 0; |
| 916 else | 985 else |
| 917 return 1; | 986 return 1; |
| 918 } | 987 } |
| 919 | 988 |
| 920 static struct gdbarch * | 989 static struct gdbarch * |
| 921 tilegx_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | 990 tilegx_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) |
| 922 { | 991 { |
| 923 struct gdbarch *gdbarch; | 992 struct gdbarch *gdbarch; |
| 924 int arch_size = 64; | 993 int arch_size = 64; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 949 that there are 65 registers, and no "pseudo registers". */ | 1018 that there are 65 registers, and no "pseudo registers". */ |
| 950 set_gdbarch_num_regs (gdbarch, TILEGX_NUM_REGS); | 1019 set_gdbarch_num_regs (gdbarch, TILEGX_NUM_REGS); |
| 951 set_gdbarch_num_pseudo_regs (gdbarch, 0); | 1020 set_gdbarch_num_pseudo_regs (gdbarch, 0); |
| 952 | 1021 |
| 953 set_gdbarch_sp_regnum (gdbarch, TILEGX_SP_REGNUM); | 1022 set_gdbarch_sp_regnum (gdbarch, TILEGX_SP_REGNUM); |
| 954 set_gdbarch_pc_regnum (gdbarch, TILEGX_PC_REGNUM); | 1023 set_gdbarch_pc_regnum (gdbarch, TILEGX_PC_REGNUM); |
| 955 | 1024 |
| 956 set_gdbarch_register_name (gdbarch, tilegx_register_name); | 1025 set_gdbarch_register_name (gdbarch, tilegx_register_name); |
| 957 set_gdbarch_register_type (gdbarch, tilegx_register_type); | 1026 set_gdbarch_register_type (gdbarch, tilegx_register_type); |
| 958 | 1027 |
| 959 set_gdbarch_char_signed (gdbarch, 0); | |
| 960 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT); | 1028 set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT); |
| 961 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT); | 1029 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT); |
| 962 set_gdbarch_long_bit (gdbarch, arch_size); | 1030 set_gdbarch_long_bit (gdbarch, arch_size); |
| 963 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT); | 1031 set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT); |
| 964 | 1032 |
| 965 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT); | 1033 set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT); |
| 966 set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT); | 1034 set_gdbarch_double_bit (gdbarch, 8 * TARGET_CHAR_BIT); |
| 967 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT); | 1035 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT); |
| 968 | 1036 |
| 969 set_gdbarch_ptr_bit (gdbarch, arch_size); | 1037 set_gdbarch_ptr_bit (gdbarch, arch_size); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 987 set_gdbarch_skip_prologue (gdbarch, tilegx_skip_prologue); | 1055 set_gdbarch_skip_prologue (gdbarch, tilegx_skip_prologue); |
| 988 | 1056 |
| 989 set_gdbarch_in_function_epilogue_p (gdbarch, | 1057 set_gdbarch_in_function_epilogue_p (gdbarch, |
| 990 tilegx_in_function_epilogue_p); | 1058 tilegx_in_function_epilogue_p); |
| 991 | 1059 |
| 992 /* Map debug registers into internal register numbers. */ | 1060 /* Map debug registers into internal register numbers. */ |
| 993 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, tilegx_dwarf2_reg_to_regnum); | 1061 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, tilegx_dwarf2_reg_to_regnum); |
| 994 | 1062 |
| 995 /* These values and methods are used when gdb calls a target function. */ | 1063 /* These values and methods are used when gdb calls a target function. */ |
| 996 set_gdbarch_push_dummy_call (gdbarch, tilegx_push_dummy_call); | 1064 set_gdbarch_push_dummy_call (gdbarch, tilegx_push_dummy_call); |
| 1065 set_gdbarch_get_longjmp_target (gdbarch, tilegx_get_longjmp_target); |
| 1066 set_gdbarch_write_pc (gdbarch, tilegx_write_pc); |
| 997 set_gdbarch_breakpoint_from_pc (gdbarch, tilegx_breakpoint_from_pc); | 1067 set_gdbarch_breakpoint_from_pc (gdbarch, tilegx_breakpoint_from_pc); |
| 998 set_gdbarch_return_value (gdbarch, tilegx_return_value); | 1068 set_gdbarch_return_value (gdbarch, tilegx_return_value); |
| 999 | 1069 |
| 1000 set_gdbarch_print_insn (gdbarch, print_insn_tilegx); | 1070 set_gdbarch_print_insn (gdbarch, print_insn_tilegx); |
| 1001 | 1071 |
| 1002 gdbarch_init_osabi (info, gdbarch); | 1072 gdbarch_init_osabi (info, gdbarch); |
| 1003 | 1073 |
| 1004 dwarf2_append_unwinders (gdbarch); | 1074 dwarf2_append_unwinders (gdbarch); |
| 1005 frame_unwind_append_unwinder (gdbarch, &tilegx_frame_unwind); | 1075 frame_unwind_append_unwinder (gdbarch, &tilegx_frame_unwind); |
| 1006 | 1076 |
| 1007 return gdbarch; | 1077 return gdbarch; |
| 1008 } | 1078 } |
| 1009 | 1079 |
| 1010 /* Provide a prototype to silence -Wmissing-prototypes. */ | 1080 /* Provide a prototype to silence -Wmissing-prototypes. */ |
| 1011 extern initialize_file_ftype _initialize_tilegx_tdep; | 1081 extern initialize_file_ftype _initialize_tilegx_tdep; |
| 1012 | 1082 |
| 1013 void | 1083 void |
| 1014 _initialize_tilegx_tdep (void) | 1084 _initialize_tilegx_tdep (void) |
| 1015 { | 1085 { |
| 1016 register_gdbarch_init (bfd_arch_tilegx, tilegx_gdbarch_init); | 1086 register_gdbarch_init (bfd_arch_tilegx, tilegx_gdbarch_init); |
| 1017 } | 1087 } |
| OLD | NEW |