summaryrefslogtreecommitdiff
path: root/src/target
diff options
context:
space:
mode:
authordrath <drath@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2006-06-23 07:54:01 +0000
committerdrath <drath@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2006-06-23 07:54:01 +0000
commitef139a3a5e41fbcbabdf4be0ecbbb5591448ad2e (patch)
treee9723f6723c0ed5b77b0edf85cb0ce2db6d35d66 /src/target
parent1f76f6999974a3a1765aaa96fecc3f2433e7b5b6 (diff)
downloadopenocd+libswd-ef139a3a5e41fbcbabdf4be0ecbbb5591448ad2e.tar.gz
openocd+libswd-ef139a3a5e41fbcbabdf4be0ecbbb5591448ad2e.tar.bz2
openocd+libswd-ef139a3a5e41fbcbabdf4be0ecbbb5591448ad2e.tar.xz
openocd+libswd-ef139a3a5e41fbcbabdf4be0ecbbb5591448ad2e.zip
- added support for AT91SAM7A3 flash (patch from andre renaud, thanks)
- fix trunk build for mac os x (patch from Lauri Leukkunen, thanks) - added check for host endianness, defines WORDS_BIGENDIAN on a big-endian host (e.g. mac os-x) - fixed bug where endianness of memory accesses could be swapped on BE hosts - added space for zero termination of ftd2xx_layout string (from Magnus Ludin, tahnks) git-svn-id: svn://svn.berlios.de/openocd/trunk@73 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/target')
-rw-r--r--src/target/arm7_9_common.c30
-rw-r--r--src/target/target.c36
-rw-r--r--src/target/target.h5
3 files changed, 52 insertions, 19 deletions
diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c
index d167041f..e0ccd7a5 100644
--- a/src/target/arm7_9_common.c
+++ b/src/target/arm7_9_common.c
@@ -1610,9 +1610,6 @@ int arm7_9_read_memory(struct target_s *target, u32 address, u32 size, u32 count
u32 *reg_p[16];
int num_accesses = 0;
int thisrun_accesses;
- u32 *buf32;
- u16 *buf16;
- u8 *buf8;
int i;
u32 cpsr;
int retval;
@@ -1645,7 +1642,6 @@ int arm7_9_read_memory(struct target_s *target, u32 address, u32 size, u32 count
switch (size)
{
case 4:
- buf32 = (u32*)buffer;
while (num_accesses < count)
{
u32 reg_list;
@@ -1662,13 +1658,13 @@ int arm7_9_read_memory(struct target_s *target, u32 address, u32 size, u32 count
{
if (i > last_reg)
last_reg = i;
- *(buf32++) = reg[i];
+ target_buffer_set_u32(target, buffer, reg[i]);
+ buffer += 4;
}
num_accesses += thisrun_accesses;
}
break;
case 2:
- buf16 = (u16*)buffer;
while (num_accesses < count)
{
u32 reg_list;
@@ -1688,13 +1684,13 @@ int arm7_9_read_memory(struct target_s *target, u32 address, u32 size, u32 count
for (i = 1; i <= thisrun_accesses; i++)
{
- *(buf16++) = reg[i] & 0xffff;
+ target_buffer_set_u16(target, buffer, reg[i]);
+ buffer += 2;
}
num_accesses += thisrun_accesses;
}
break;
case 1:
- buf8 = buffer;
while (num_accesses < count)
{
u32 reg_list;
@@ -1714,7 +1710,7 @@ int arm7_9_read_memory(struct target_s *target, u32 address, u32 size, u32 count
for (i = 1; i <= thisrun_accesses; i++)
{
- *(buf8++) = reg[i] & 0xff;
+ *(buffer++) = reg[i] & 0xff;
}
num_accesses += thisrun_accesses;
}
@@ -1755,9 +1751,6 @@ int arm7_9_write_memory(struct target_s *target, u32 address, u32 size, u32 coun
u32 reg[16];
int num_accesses = 0;
int thisrun_accesses;
- u32 *buf32;
- u16 *buf16;
- u8 *buf8;
int i;
u32 cpsr;
int retval;
@@ -1785,7 +1778,6 @@ int arm7_9_write_memory(struct target_s *target, u32 address, u32 size, u32 coun
switch (size)
{
case 4:
- buf32 = (u32*)buffer;
while (num_accesses < count)
{
u32 reg_list;
@@ -1796,7 +1788,8 @@ int arm7_9_write_memory(struct target_s *target, u32 address, u32 size, u32 coun
{
if (i > last_reg)
last_reg = i;
- reg[i] = *buf32++;
+ reg[i] = target_buffer_get_u32(target, buffer);
+ buffer += 4;
}
arm7_9->write_core_regs(target, reg_list, reg);
@@ -1815,7 +1808,6 @@ int arm7_9_write_memory(struct target_s *target, u32 address, u32 size, u32 coun
}
break;
case 2:
- buf16 = (u16*)buffer;
while (num_accesses < count)
{
u32 reg_list;
@@ -1826,7 +1818,8 @@ int arm7_9_write_memory(struct target_s *target, u32 address, u32 size, u32 coun
{
if (i > last_reg)
last_reg = i;
- reg[i] = *buf16++ & 0xffff;
+ reg[i] = target_buffer_get_u16(target, buffer) & 0xffff;
+ buffer += 2;
}
arm7_9->write_core_regs(target, reg_list, reg);
@@ -1848,7 +1841,6 @@ int arm7_9_write_memory(struct target_s *target, u32 address, u32 size, u32 coun
}
break;
case 1:
- buf8 = buffer;
while (num_accesses < count)
{
u32 reg_list;
@@ -1859,7 +1851,7 @@ int arm7_9_write_memory(struct target_s *target, u32 address, u32 size, u32 coun
{
if (i > last_reg)
last_reg = i;
- reg[i] = *buf8++ & 0xff;
+ reg[i] = *buffer++ & 0xff;
}
arm7_9->write_core_regs(target, reg_list, reg);
@@ -1955,7 +1947,7 @@ int arm7_9_bulk_write_memory(target_t *target, u32 address, u32 count, u8 *buffe
for (i = 0; i < count; i++)
{
- embeddedice_write_reg(&arm7_9->eice_cache->reg_list[EICE_COMMS_DATA], buf_get_u32(buffer, 0, 32));
+ embeddedice_write_reg(&arm7_9->eice_cache->reg_list[EICE_COMMS_DATA], target_buffer_get_u32(target, buffer));
buffer += 4;
}
diff --git a/src/target/target.c b/src/target/target.c
index 98407afb..34dc60a7 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -111,6 +111,42 @@ enum daemon_startup_mode startup_mode = DAEMON_ATTACH;
static int target_continous_poll = 1;
+/* read a u32 from a buffer in target memory endianness */
+u32 target_buffer_get_u32(target_t *target, u8 *buffer)
+{
+ if (target->endianness == TARGET_LITTLE_ENDIAN)
+ return le_to_h_u32(buffer);
+ else
+ return be_to_h_u32(buffer);
+}
+
+/* read a u16 from a buffer in target memory endianness */
+u16 target_buffer_get_u16(target_t *target, u8 *buffer)
+{
+ if (target->endianness == TARGET_LITTLE_ENDIAN)
+ return le_to_h_u16(buffer);
+ else
+ return be_to_h_u16(buffer);
+}
+
+/* write a u32 to a buffer in target memory endianness */
+void target_buffer_set_u32(target_t *target, u8 *buffer, u32 value)
+{
+ if (target->endianness == TARGET_LITTLE_ENDIAN)
+ h_u32_to_le(buffer, value);
+ else
+ h_u32_to_be(buffer, value);
+}
+
+/* write a u16 to a buffer in target memory endianness */
+void target_buffer_set_u16(target_t *target, u8 *buffer, u16 value)
+{
+ if (target->endianness == TARGET_LITTLE_ENDIAN)
+ h_u16_to_le(buffer, value);
+ else
+ h_u16_to_be(buffer, value);
+}
+
/* returns a pointer to the n-th configured target */
target_t* get_target_by_num(int num)
{
diff --git a/src/target/target.h b/src/target/target.h
index 6d3b6d17..dc6d8ce1 100644
--- a/src/target/target.h
+++ b/src/target/target.h
@@ -217,6 +217,11 @@ extern target_t *targets;
extern target_event_callback_t *target_event_callbacks;
extern target_timer_callback_t *target_timer_callbacks;
+extern u32 target_buffer_get_u32(target_t *target, u8 *buffer);
+extern u16 target_buffer_get_u16(target_t *target, u8 *buffer);
+extern void target_buffer_set_u32(target_t *target, u8 *buffer, u32 value);
+extern void target_buffer_set_u16(target_t *target, u8 *buffer, u16 value);
+
#define ERROR_TARGET_INVALID (-300)
#define ERROR_TARGET_INIT_FAILED (-301)
#define ERROR_TARGET_TIMEOUT (-302)