-/* Fetch (and possibly build) an appropriate link_map_offsets
- structure for native GNU/Linux CRIS targets using the struct
- offsets defined in link.h (but without actual reference to that
- file).
-
- This makes it possible to access GNU/Linux CRIS shared libraries
- from a GDB that was not built on an GNU/Linux CRIS host (for cross
- debugging).
-
- See gdb/solib-svr4.h for an explanation of these fields. */
-
-static struct link_map_offsets *
-cris_linux_svr4_fetch_link_map_offsets (void)
-{
- static struct link_map_offsets lmo;
- static struct link_map_offsets *lmp = NULL;
-
- if (lmp == NULL)
- {
- lmp = &lmo;
-
- lmo.r_debug_size = 8; /* The actual size is 20 bytes, but
- this is all we need. */
- lmo.r_map_offset = 4;
- lmo.r_map_size = 4;
-
- lmo.link_map_size = 20;
-
- lmo.l_addr_offset = 0;
- lmo.l_addr_size = 4;
-
- lmo.l_name_offset = 4;
- lmo.l_name_size = 4;
-
- lmo.l_next_offset = 12;
- lmo.l_next_size = 4;
-
- lmo.l_prev_offset = 16;
- lmo.l_prev_size = 4;
- }
-
- return lmp;
-}
-
-static void
-cris_fpless_backtrace (char *noargs, int from_tty)
-{
- /* Points at the instruction after the jsr (except when in innermost frame
- where it points at the original pc). */
- CORE_ADDR pc = 0;
-
- /* Temporary variable, used for parsing from the start of the function that
- the pc is in, up to the pc. */
- CORE_ADDR tmp_pc = 0;
- CORE_ADDR sp = 0;
-
- /* Information about current frame. */
- struct symtab_and_line sal;
- char* func_name;
-
- /* Present instruction. */
- unsigned short insn;
-
- /* Next instruction, lookahead. */
- unsigned short insn_next;
-
- /* This is to store the offset between sp at start of function and until we
- reach push srp (if any). */
- int sp_add_later = 0;
- int push_srp_found = 0;
-
- int val = 0;
-
- /* Frame counter. */
- int frame = 0;
-
- /* For the innermost frame, we want to look at srp in case it's a leaf
- function (since there's no push srp in that case). */
- int innermost_frame = 1;
-
- deprecated_read_register_gen (PC_REGNUM, (char *) &pc);
- deprecated_read_register_gen (SP_REGNUM, (char *) &sp);
-
- /* We make an explicit return when we can't find an outer frame. */
- while (1)
- {
- /* Get file name and line number. */
- sal = find_pc_line (pc, 0);
-
- /* Get function name. */
- find_pc_partial_function (pc, &func_name, (CORE_ADDR *) NULL,
- (CORE_ADDR *) NULL);
-
- /* Print information about current frame. */
- printf_unfiltered ("#%i 0x%08lx in %s", frame++, pc, func_name);
- if (sal.symtab)
- {
- printf_unfiltered (" at %s:%i", sal.symtab->filename, sal.line);
- }
- printf_unfiltered ("\n");
-
- /* Get the start address of this function. */
- tmp_pc = get_pc_function_start (pc);
-
- /* Mini parser, only meant to find push sp and sub ...,sp from the start
- of the function, up to the pc. */
- while (tmp_pc < pc)
- {
- insn = read_memory_unsigned_integer (tmp_pc, sizeof (short));
- tmp_pc += sizeof (short);
- if (insn == 0xE1FC)
- {
- /* push <reg> 32 bit instruction */
- insn_next = read_memory_unsigned_integer (tmp_pc,
- sizeof (short));
- tmp_pc += sizeof (short);
-
- /* Recognize srp. */
- if (insn_next == 0xBE7E)
- {
- /* For subsequent (not this one though) push or sub which
- affects sp, adjust sp immediately. */
- push_srp_found = 1;
-
- /* Note: this will break if we ever encounter a
- push vr (1 byte) or push ccr (2 bytes). */
- sp_add_later += 4;
- }
- else
- {
- /* Some other register was pushed. */
- if (push_srp_found)
- {
- sp += 4;
- }
- else
- {
- sp_add_later += 4;
- }
- }
- }
- else if (cris_get_operand2 (insn) == SP_REGNUM
- && cris_get_mode (insn) == 0x0000
- && cris_get_opcode (insn) == 0x000A)
- {
- /* subq <val>,sp */
- val = cris_get_quick_value (insn);
-
- if (push_srp_found)
- {
- sp += val;
- }
- else
- {
- sp_add_later += val;
- }
-
- }
- else if (cris_get_operand2 (insn) == SP_REGNUM
- /* Autoincrement addressing mode. */
- && cris_get_mode (insn) == 0x0003
- /* Opcode. */
- && ((insn) & 0x03E0) >> 5 == 0x0004)
- {
- /* subu <val>,sp */
- val = get_data_from_address (&insn, tmp_pc);
-
- if (push_srp_found)
- {
- sp += val;
- }
- else
- {
- sp_add_later += val;
- }
- }
- else if (cris_get_operand2 (insn) == SP_REGNUM
- && ((insn & 0x0F00) >> 8) == 0x0001
- && (cris_get_signed_offset (insn) < 0))
- {
- /* Immediate byte offset addressing prefix word with sp as base
- register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
- is between 64 and 128.
- movem r<regsave>,[sp=sp-<val>] */
- val = -cris_get_signed_offset (insn);
- insn_next = read_memory_unsigned_integer (tmp_pc,
- sizeof (short));
- tmp_pc += sizeof (short);
-
- if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
- && cris_get_opcode (insn_next) == 0x000F
- && cris_get_size (insn_next) == 0x0003
- && cris_get_operand1 (insn_next) == SP_REGNUM)
- {
- if (push_srp_found)
- {
- sp += val;
- }
- else
- {
- sp_add_later += val;
- }
- }
- }
- }
-
- if (push_srp_found)
- {
- /* Reset flag. */
- push_srp_found = 0;
-
- /* sp should now point at where srp is stored on the stack. Update
- the pc to the srp. */
- pc = read_memory_unsigned_integer (sp, 4);
- }
- else if (innermost_frame)
- {
- /* We couldn't find a push srp in the prologue, so this must be
- a leaf function, and thus we use the srp register directly.
- This should happen at most once, for the innermost function. */
- deprecated_read_register_gen (SRP_REGNUM, (char *) &pc);
- }
- else
- {
- /* Couldn't find an outer frame. */
- return;
- }
-
- /* Reset flag. (In case the innermost frame wasn't a leaf, we don't
- want to look at the srp register later either). */
- innermost_frame = 0;
-
- /* Now, add the offset for everything up to, and including push srp,
- that was held back during the prologue parsing. */
- sp += sp_add_later;
- sp_add_later = 0;
- }
-}
-