* avr-tdep.c: Ran through gdb_indent.sh.

This commit is contained in:
Theodore A. Roth 2002-04-25 21:22:12 +00:00
parent e33ce51979
commit 2e5ff58c05
2 changed files with 348 additions and 339 deletions

View File

@ -1,3 +1,7 @@
2002-04-25 Theodore A. Roth <troth@verinet.com>
* avr-tdep.c: Ran through gdb_indent.sh.
2002-04-25 Theodore A. Roth <troth@verinet.com>
* MAINTAINERS: Add myself as AVR maintainer.

View File

@ -72,7 +72,7 @@
/* Constants: prefixed with AVR_ to avoid name space clashes */
enum
{
{
AVR_REG_W = 24,
AVR_REG_X = 26,
AVR_REG_Y = 28,
@ -127,7 +127,7 @@ enum
AVR_EMEM_START = 0x00810000, /* EEPROM memory */
AVR_MEM_MASK = 0x00ff0000, /* mask to determine memory space */
#endif
};
};
/* Any function with a frame looks like this
....... <-SP POINTS HERE
@ -141,28 +141,27 @@ enum
SECOND ARG */
struct frame_extra_info
{
{
CORE_ADDR return_pc;
CORE_ADDR args_pointer;
int locals_size;
int framereg;
int framesize;
int is_main;
};
};
struct gdbarch_tdep
{
{
/* FIXME: TRoth: is there anything to put here? */
int foo;
};
};
/* Lookup the name of a register given it's number. */
static char *
avr_register_name (int regnum)
{
static char *register_names[] =
{
static char *register_names[] = {
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
"r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
@ -326,17 +325,18 @@ avr_pointer_to_address (struct type *type, void *buf)
{
CORE_ADDR addr = extract_address (buf, TYPE_LENGTH (type));
if ( TYPE_CODE_SPACE (TYPE_TARGET_TYPE (type)) )
if (TYPE_CODE_SPACE (TYPE_TARGET_TYPE (type)))
{
fprintf_unfiltered (gdb_stderr, "CODE_SPACE ---->> ptr->addr: 0x%lx\n", addr);
fprintf_unfiltered (gdb_stderr, "+++ If you see this, please send me an email <troth@verinet.com>\n");
fprintf_unfiltered (gdb_stderr, "CODE_SPACE ---->> ptr->addr: 0x%lx\n",
addr);
fprintf_unfiltered (gdb_stderr,
"+++ If you see this, please send me an email <troth@verinet.com>\n");
}
/* Is it a code address? */
if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC
|| TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD
|| TYPE_CODE_SPACE (TYPE_TARGET_TYPE (type))
)
|| TYPE_CODE_SPACE (TYPE_TARGET_TYPE (type)))
return avr_make_iaddr (addr);
else
return avr_make_saddr (addr);
@ -461,7 +461,7 @@ avr_scan_prologue (struct frame_info *fi)
int i;
unsigned short insn;
int regno;
int scan_stage=0;
int scan_stage = 0;
char *name;
struct minimal_symbol *msymbol;
int prologue_len;
@ -470,7 +470,8 @@ avr_scan_prologue (struct frame_info *fi)
fi->extra_info->framereg = AVR_SP_REGNUM;
if (find_pc_partial_function (fi->pc, &name, &prologue_start, &prologue_end))
if (find_pc_partial_function
(fi->pc, &name, &prologue_start, &prologue_end))
{
struct symtab_and_line sal = find_pc_line (prologue_start, 0);
@ -502,10 +503,9 @@ avr_scan_prologue (struct frame_info *fi)
if (name && strcmp ("main", name) == 0 && prologue_len == 8)
{
CORE_ADDR locals;
unsigned char img[] =
{
0xde,0xbf, /* out __SP_H__,r29 */
0xcd,0xbf /* out __SP_L__,r28 */
unsigned char img[] = {
0xde, 0xbf, /* out __SP_H__,r29 */
0xcd, 0xbf /* out __SP_L__,r28 */
};
fi->extra_info->framereg = AVR_FP_REGNUM;
@ -514,7 +514,7 @@ avr_scan_prologue (struct frame_info *fi)
if ((insn & 0xf0f0) == 0xe0c0)
{
locals = (insn & 0xf) | ((insn & 0x0f00) >> 4);
insn = EXTRACT_INSN (&prologue[vpc+2]);
insn = EXTRACT_INSN (&prologue[vpc + 2]);
/* ldi r29,hi8(<RAM_ADDR> - <LOCALS_SIZE>) */
if ((insn & 0xf0f0) == 0xe0d0)
{
@ -593,7 +593,7 @@ avr_scan_prologue (struct frame_info *fi)
if (num_pushes)
{
int from;
fi->saved_regs[AVR_FP_REGNUM+1] = num_pushes;
fi->saved_regs[AVR_FP_REGNUM + 1] = num_pushes;
if (num_pushes >= 2)
fi->saved_regs[AVR_FP_REGNUM] = num_pushes - 1;
i = 0;
@ -611,14 +611,13 @@ avr_scan_prologue (struct frame_info *fi)
if (prologue_len >= 12)
{
unsigned char img[] =
{
0x78,0x94, /* sei */
0x1f,0x92, /* push r1 */
0x0f,0x92, /* push r0 */
0x0f,0xb6, /* in r0,0x3f SREG */
0x0f,0x92, /* push r0 */
0x11,0x24 /* clr r1 */
unsigned char img[] = {
0x78, 0x94, /* sei */
0x1f, 0x92, /* push r1 */
0x0f, 0x92, /* push r0 */
0x0f, 0xb6, /* in r0,0x3f SREG */
0x0f, 0x92, /* push r0 */
0x11, 0x24 /* clr r1 */
};
if (memcmp (prologue, img, sizeof (img)) == 0)
{
@ -661,10 +660,9 @@ avr_scan_prologue (struct frame_info *fi)
if (scan_stage == 1 && vpc + 4 <= prologue_len)
{
unsigned char img[] =
{
0xcd,0xb7, /* in r28,__SP_L__ */
0xde,0xb7 /* in r29,__SP_H__ */
unsigned char img[] = {
0xcd, 0xb7, /* in r28,__SP_L__ */
0xde, 0xb7 /* in r29,__SP_H__ */
};
unsigned short insn1;
@ -689,25 +687,22 @@ avr_scan_prologue (struct frame_info *fi)
if (scan_stage == 2 && vpc + 12 <= prologue_len)
{
int locals_size = 0;
unsigned char img[] =
{
0x0f,0xb6, /* in r0,0x3f */
0xf8,0x94, /* cli */
0xcd,0xbf, /* out 0x3d,r28 ; SPL */
0x0f,0xbe, /* out 0x3f,r0 ; SREG*/
0xde,0xbf /* out 0x3e,r29 ; SPH */
unsigned char img[] = {
0x0f, 0xb6, /* in r0,0x3f */
0xf8, 0x94, /* cli */
0xcd, 0xbf, /* out 0x3d,r28 ; SPL */
0x0f, 0xbe, /* out 0x3f,r0 ; SREG */
0xde, 0xbf /* out 0x3e,r29 ; SPH */
};
unsigned char img_sig[] =
{
0xcd,0xbf, /* out 0x3d,r28 ; SPL */
0xde,0xbf /* out 0x3e,r29 ; SPH */
unsigned char img_sig[] = {
0xcd, 0xbf, /* out 0x3d,r28 ; SPL */
0xde, 0xbf /* out 0x3e,r29 ; SPH */
};
unsigned char img_int[] =
{
0xf8,0x94, /* cli */
0xcd,0xbf, /* out 0x3d,r28 ; SPL */
0x78,0x94, /* sei */
0xde,0xbf /* out 0x3e,r29 ; SPH */
unsigned char img_int[] = {
0xf8, 0x94, /* cli */
0xcd, 0xbf, /* out 0x3d,r28 ; SPL */
0x78, 0x94, /* sei */
0xde, 0xbf /* out 0x3e,r29 ; SPH */
};
insn = EXTRACT_INSN (&prologue[vpc]);
@ -759,17 +754,17 @@ avr_init_extra_frame_info (int fromleaf, struct frame_info *fi)
{
/* We need to setup fi->frame here because run_stack_dummy gets it wrong
by assuming it's always FP. */
fi->frame = generic_read_register_dummy (fi->pc, fi->frame,
fi->frame);
fi->frame = generic_read_register_dummy (fi->pc, fi->frame, fi->frame);
}
else if (!fi->next) /* this is the innermost frame? */
fi->frame = read_register (fi->extra_info->framereg);
else if (fi->extra_info->is_main != 1) /* not the innermost frame, not `main' */
/* If we have an next frame, the callee saved it. */
{
struct frame_info * next_fi = fi->next;
struct frame_info *next_fi = fi->next;
if (fi->extra_info->framereg == AVR_SP_REGNUM)
fi->frame = next_fi->frame + 2 /* ret addr */ + next_fi->extra_info->framesize;
fi->frame =
next_fi->frame + 2 /* ret addr */ + next_fi->extra_info->framesize;
/* FIXME: I don't analyse va_args functions */
else
{
@ -789,8 +784,9 @@ avr_init_extra_frame_info (int fromleaf, struct frame_info *fi)
}
fp_low = (fp ? read_memory_unsigned_integer (avr_make_saddr (fp), 1)
: read_register (AVR_FP_REGNUM)) & 0xff;
fp_high = (fp1 ? read_memory_unsigned_integer (avr_make_saddr (fp1), 1)
: read_register (AVR_FP_REGNUM + 1)) & 0xff;
fp_high =
(fp1 ? read_memory_unsigned_integer (avr_make_saddr (fp1), 1) :
read_register (AVR_FP_REGNUM + 1)) & 0xff;
fi->frame = fp_low | (fp_high << 8);
}
}
@ -836,9 +832,9 @@ avr_pop_frame (void)
CORE_ADDR saddr;
struct frame_info *frame = get_current_frame ();
if (PC_IN_CALL_DUMMY(frame->pc, frame->frame, frame->frame))
if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
{
generic_pop_dummy_frame();
generic_pop_dummy_frame ();
}
else
{
@ -851,7 +847,8 @@ avr_pop_frame (void)
if (frame->saved_regs[regnum] && regnum != AVR_SP_REGNUM)
{
saddr = avr_make_saddr (frame->saved_regs[regnum]);
write_register (regnum, read_memory_unsigned_integer (saddr, 1));
write_register (regnum,
read_memory_unsigned_integer (saddr, 1));
}
else if (frame->saved_regs[regnum] && regnum == AVR_SP_REGNUM)
write_register (regnum, frame->frame + 2);
@ -868,8 +865,9 @@ avr_pop_frame (void)
static CORE_ADDR
avr_frame_saved_pc (struct frame_info *frame)
{
if (PC_IN_CALL_DUMMY(frame->pc, frame->frame, frame->frame))
return generic_read_register_dummy (frame->pc, frame->frame, AVR_PC_REGNUM);
if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
return generic_read_register_dummy (frame->pc, frame->frame,
AVR_PC_REGNUM);
else
return frame->extra_info->return_pc;
}
@ -894,15 +892,16 @@ avr_extract_return_value (struct type *type, char *regbuf, char *valbuf)
wordsize = 2;
len = TYPE_LENGTH(type);
len = TYPE_LENGTH (type);
switch (len) {
switch (len)
{
case 1: /* (char) */
case 2: /* (short), (int) */
memcpy (valbuf, regbuf + REGISTER_BYTE(24), 2);
memcpy (valbuf, regbuf + REGISTER_BYTE (24), 2);
break;
case 4: /* (long), (float) */
memcpy (valbuf, regbuf + REGISTER_BYTE(22), 4);
memcpy (valbuf, regbuf + REGISTER_BYTE (22), 4);
break;
case 8: /* (double) (doesn't seem to happen, which is good,
because this almost certainly isn't right. */
@ -929,15 +928,16 @@ avr_store_return_value (struct type *type, char *valbuf)
wordsize = 2;
len = TYPE_LENGTH(type);
switch (len) {
len = TYPE_LENGTH (type);
switch (len)
{
case 1: /* char */
case 2: /* short, int */
regval = extract_address(valbuf, len);
regval = extract_address (valbuf, len);
write_register (0, regval);
break;
case 4: /* long, float */
regval = extract_address(valbuf, len);
regval = extract_address (valbuf, len);
write_register (0, regval >> 16);
write_register (1, regval & 0xffff);
break;
@ -1026,12 +1026,13 @@ avr_frame_chain (struct frame_info *frame)
{
/* initialize the return_pc now */
frame->extra_info->return_pc = generic_read_register_dummy (frame->pc,
frame->frame,
frame->
frame,
AVR_PC_REGNUM);
return frame->frame;
}
return (frame->extra_info->is_main ? 0
: frame->frame + frame->extra_info->framesize + 2 /* ret addr */);
: frame->frame + frame->extra_info->framesize + 2 /* ret addr */ );
}
/* Store the address of the place in which to copy the structure the
@ -1054,8 +1055,7 @@ static CORE_ADDR
avr_extract_struct_value_address (char *regbuf)
{
return (extract_address ((regbuf) + REGISTER_BYTE (0),
REGISTER_RAW_SIZE (0))
| AVR_SMEM_START);
REGISTER_RAW_SIZE (0)) | AVR_SMEM_START);
}
/* Setup the function arguments for calling a function in the inferior.
@ -1103,9 +1103,8 @@ avr_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
wordsize = 1;
#if 0
/* Now make sure there's space on the stack */
for (argnum = 0, stack_alloc = 0;
argnum < nargs; argnum++)
stack_alloc += TYPE_LENGTH(VALUE_TYPE(args[argnum]));
for (argnum = 0, stack_alloc = 0; argnum < nargs; argnum++)
stack_alloc += TYPE_LENGTH (VALUE_TYPE (args[argnum]));
sp -= stack_alloc; /* make room on stack for args */
/* we may over-allocate a little here, but that won't hurt anything */
#endif
@ -1140,12 +1139,13 @@ avr_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
/* Initialize the gdbarch structure for the AVR's. */
static struct gdbarch *
avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches){
avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
{
/* FIXME: TRoth/2002-02-18: I have no idea if avr_call_dummy_words[] should
be bigger or not. Initial testing seems to show that `call my_func()`
works and backtrace from a breakpoint within the call looks correct.
Admittedly, I haven't tested with more than a very simple program. */
static LONGEST avr_call_dummy_words[] = {0};
static LONGEST avr_call_dummy_words[] = { 0 };
struct gdbarch *gdbarch;
struct gdbarch_tdep *tdep;
@ -1240,7 +1240,8 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches){
set_gdbarch_use_struct_convention (gdbarch, generic_use_struct_convention);
set_gdbarch_store_struct_return (gdbarch, avr_store_struct_return);
set_gdbarch_extract_struct_value_address (gdbarch, avr_extract_struct_value_address);
set_gdbarch_extract_struct_value_address (gdbarch,
avr_extract_struct_value_address);
set_gdbarch_frame_init_saved_regs (gdbarch, avr_scan_prologue);
set_gdbarch_init_extra_frame_info (gdbarch, avr_init_extra_frame_info);
@ -1251,7 +1252,8 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches){
set_gdbarch_decr_pc_after_break (gdbarch, 0);
set_gdbarch_function_start_offset (gdbarch, 0);
set_gdbarch_remote_translate_xfer_address (gdbarch, avr_remote_translate_xfer_address);
set_gdbarch_remote_translate_xfer_address (gdbarch,
avr_remote_translate_xfer_address);
set_gdbarch_frame_args_skip (gdbarch, 0);
set_gdbarch_frameless_function_invocation (gdbarch, frameless_look_for_prologue); /* ??? */
set_gdbarch_frame_chain (gdbarch, avr_frame_chain);
@ -1262,7 +1264,8 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches){
set_gdbarch_saved_pc_after_call (gdbarch, avr_saved_pc_after_call);
set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
set_gdbarch_convert_from_func_ptr_addr (gdbarch, avr_convert_from_func_ptr_addr);
set_gdbarch_convert_from_func_ptr_addr (gdbarch,
avr_convert_from_func_ptr_addr);
return gdbarch;
}
@ -1294,49 +1297,52 @@ avr_io_reg_read_command (char *args, int from_tty)
/* fprintf_unfiltered (gdb_stderr, "DEBUG: avr_io_reg_read_command (\"%s\", %d)\n", */
/* args, from_tty); */
if (! current_target.to_query)
if (!current_target.to_query)
{
fprintf_unfiltered (gdb_stderr, "ERR: info io_registers NOT supported by current target\n");
fprintf_unfiltered (gdb_stderr,
"ERR: info io_registers NOT supported by current target\n");
return;
}
/* Just get the maximum buffer size. */
target_query ((int) 'R', 0, 0, &bufsiz);
if (bufsiz > sizeof(buf))
bufsiz = sizeof(buf);
if (bufsiz > sizeof (buf))
bufsiz = sizeof (buf);
/* Find out how many io registers the target has. */
strcpy (query, "avr.io_reg");
target_query( (int) 'R', query, buf, &bufsiz );
target_query ((int) 'R', query, buf, &bufsiz);
if (strncmp (buf, "", bufsiz) == 0)
{
fprintf_unfiltered (gdb_stderr, "info io_registers NOT supported by target\n");
fprintf_unfiltered (gdb_stderr,
"info io_registers NOT supported by target\n");
return;
}
if ( sscanf (buf, "%x", &nreg) != 1 )
if (sscanf (buf, "%x", &nreg) != 1)
{
fprintf_unfiltered (gdb_stderr, "Error fetching number of io registers\n");
fprintf_unfiltered (gdb_stderr,
"Error fetching number of io registers\n");
return;
}
reinitialize_more_filter();
reinitialize_more_filter ();
printf_unfiltered ("Target has %u io registers:\n\n", nreg);
/* only fetch up to 8 registers at a time to keep the buffer small */
step = 8;
for (i=0; i<nreg; i+=step)
for (i = 0; i < nreg; i += step)
{
j = step - (nreg % step); /* how many registers this round? */
snprintf (query, sizeof(query)-1, "avr.io_reg:%x,%x", i, j);
snprintf (query, sizeof (query) - 1, "avr.io_reg:%x,%x", i, j);
target_query ((int) 'R', query, buf, &bufsiz);
p = buf;
for (k=i; k<(i+j); k++)
for (k = i; k < (i + j); k++)
{
if (sscanf (p, "%[^,],%x;", query, &val) == 2)
{
@ -1364,6 +1370,5 @@ _initialize_avr_tdep (void)
io_registers' to signify it is not available on other platforms. */
add_cmd ("io_registers", class_info, avr_io_reg_read_command,
"query remote avr target for io space register values",
&infolist);
"query remote avr target for io space register values", &infolist);
}