aboutsummaryrefslogtreecommitdiff
path: root/gdb/avr-tdep.c
diff options
context:
space:
mode:
authorPierre Langlois <pierre.langlois@embecosm.com>2014-07-25 14:45:03 +0100
committerPierre Langlois <pierre.langlois@embecosm.com>2014-07-25 15:03:29 +0100
commit7d0d9d2bee341b1e88c559c476f15fc24b6de346 (patch)
treef6781f9824890f6f6ccad55a60a2b8e257ca6ee8 /gdb/avr-tdep.c
parentc3f814a14336b9d395f3abad739592929e2faaa0 (diff)
downloadgdb-7d0d9d2bee341b1e88c559c476f15fc24b6de346.zip
gdb-7d0d9d2bee341b1e88c559c476f15fc24b6de346.tar.gz
gdb-7d0d9d2bee341b1e88c559c476f15fc24b6de346.tar.bz2
Clarify the address and pointer conversions on AVR.
This patch adds additional comments about the conversion of addresses to pointers and vice-versa on AVR. Special conversion needs to be done when dealing with an address in the flash address space, where both code and read-only data can be stored. Code and data pointers to flash are not addressed the same way: A code pointer is 16 bit addressed. A data pointer is 8 bit addressed, even if the data is in flash. 2014-07-25 Pierre Langlois <pierre.langlois@embecosm.com> * avr-tdep.c (avr_address_to_pointer): Clarify the conversion in the comments. (avr_pointer_to_address): Likewise.
Diffstat (limited to 'gdb/avr-tdep.c')
-rw-r--r--gdb/avr-tdep.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c
index be0b543..1f268f2 100644
--- a/gdb/avr-tdep.c
+++ b/gdb/avr-tdep.c
@@ -308,7 +308,7 @@ avr_address_to_pointer (struct gdbarch *gdbarch,
/* Is it a data address in flash? */
if (AVR_TYPE_ADDRESS_CLASS_FLASH (type))
{
- /* A data address in flash is always byte addressed. */
+ /* A data pointer in flash is byte addressed. */
store_unsigned_integer (buf, TYPE_LENGTH (type), byte_order,
avr_convert_iaddr_to_raw (addr));
}
@@ -316,8 +316,8 @@ avr_address_to_pointer (struct gdbarch *gdbarch,
else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC
|| TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
{
- /* A code address, either a function pointer or the program counter, is
- word (16 bits) addressed. */
+ /* A code pointer is word (16 bits) addressed. We shift the address down
+ by 1 bit to convert it to a pointer. */
store_unsigned_integer (buf, TYPE_LENGTH (type), byte_order,
avr_convert_iaddr_to_raw (addr >> 1));
}
@@ -339,12 +339,19 @@ avr_pointer_to_address (struct gdbarch *gdbarch,
/* Is it a data address in flash? */
if (AVR_TYPE_ADDRESS_CLASS_FLASH (type))
- return avr_make_iaddr (addr);
+ {
+ /* A data pointer in flash is already byte addressed. */
+ return avr_make_iaddr (addr);
+ }
/* Is it a code address? */
else 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)))
- return avr_make_iaddr (addr << 1);
+ {
+ /* A code pointer is word (16 bits) addressed so we shift it up
+ by 1 bit to convert it to an address. */
+ return avr_make_iaddr (addr << 1);
+ }
else
return avr_make_saddr (addr);
}