aboutsummaryrefslogtreecommitdiff
path: root/src/target/target.c
diff options
context:
space:
mode:
authorDongxue Zhang <elta.era@gmail.com>2013-11-15 16:55:34 +0800
committerAndreas Fritiofson <andreas.fritiofson@gmail.com>2013-12-01 12:39:36 +0000
commit4516eebabac0df24f00f40ff97ff570fdd39b2db (patch)
tree2a9cca5cf2e4d47d87acccdee4ab2f3c698c68e8 /src/target/target.c
parent3b020c5bb3c332ad7518de388695cc8a98e388f2 (diff)
[PATCH 1/2]support64: Add functions into types and target
Add functions into types.h, target.c, target.h to operate 64bits data. Prepare for 64bits mips target. Change-Id: I668a8a5ac12ba754ae310fa6e92cfc91af850b1c Signed-off-by: Dongxue Zhang <elta.era@gmail.com> Reviewed-on: http://openocd.zylin.com/1700 Tested-by: jenkins Reviewed-by: Mathias Küster <kesmtp@freenet.de> Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Diffstat (limited to 'src/target/target.c')
-rw-r--r--src/target/target.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/target/target.c b/src/target/target.c
index 3042d5d6..cb54ced5 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -294,6 +294,15 @@ static int new_target_number(void)
return x + 1;
}
+/* read a uint64_t from a buffer in target memory endianness */
+uint64_t target_buffer_get_u64(struct target *target, const uint8_t *buffer)
+{
+ if (target->endianness == TARGET_LITTLE_ENDIAN)
+ return le_to_h_u64(buffer);
+ else
+ return be_to_h_u64(buffer);
+}
+
/* read a uint32_t from a buffer in target memory endianness */
uint32_t target_buffer_get_u32(struct target *target, const uint8_t *buffer)
{
@@ -327,6 +336,15 @@ static uint8_t target_buffer_get_u8(struct target *target, const uint8_t *buffer
return *buffer & 0x0ff;
}
+/* write a uint64_t to a buffer in target memory endianness */
+void target_buffer_set_u64(struct target *target, uint8_t *buffer, uint64_t value)
+{
+ if (target->endianness == TARGET_LITTLE_ENDIAN)
+ h_u64_to_le(buffer, value);
+ else
+ h_u64_to_be(buffer, value);
+}
+
/* write a uint32_t to a buffer in target memory endianness */
void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value)
{
@@ -360,6 +378,14 @@ static void target_buffer_set_u8(struct target *target, uint8_t *buffer, uint8_t
*buffer = value;
}
+/* write a uint64_t array to a buffer in target memory endianness */
+void target_buffer_get_u64_array(struct target *target, const uint8_t *buffer, uint32_t count, uint64_t *dstbuf)
+{
+ uint32_t i;
+ for (i = 0; i < count; i++)
+ dstbuf[i] = target_buffer_get_u64(target, &buffer[i * 8]);
+}
+
/* write a uint32_t array to a buffer in target memory endianness */
void target_buffer_get_u32_array(struct target *target, const uint8_t *buffer, uint32_t count, uint32_t *dstbuf)
{
@@ -376,6 +402,14 @@ void target_buffer_get_u16_array(struct target *target, const uint8_t *buffer, u
dstbuf[i] = target_buffer_get_u16(target, &buffer[i * 2]);
}
+/* write a uint64_t array to a buffer in target memory endianness */
+void target_buffer_set_u64_array(struct target *target, uint8_t *buffer, uint32_t count, const uint64_t *srcbuf)
+{
+ uint32_t i;
+ for (i = 0; i < count; i++)
+ target_buffer_set_u64(target, &buffer[i * 8], srcbuf[i]);
+}
+
/* write a uint32_t array to a buffer in target memory endianness */
void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_t count, const uint32_t *srcbuf)
{
@@ -1983,6 +2017,30 @@ int target_blank_check_memory(struct target *target, uint32_t address, uint32_t
return retval;
}
+int target_read_u64(struct target *target, uint64_t address, uint64_t *value)
+{
+ uint8_t value_buf[8];
+ if (!target_was_examined(target)) {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
+
+ int retval = target_read_memory(target, address, 8, 1, value_buf);
+
+ if (retval == ERROR_OK) {
+ *value = target_buffer_get_u64(target, value_buf);
+ LOG_DEBUG("address: 0x%" PRIx64 ", value: 0x%16.16" PRIx64 "",
+ address,
+ *value);
+ } else {
+ *value = 0x0;
+ LOG_DEBUG("address: 0x%" PRIx64 " failed",
+ address);
+ }
+
+ return retval;
+}
+
int target_read_u32(struct target *target, uint32_t address, uint32_t *value)
{
uint8_t value_buf[4];
@@ -2053,6 +2111,27 @@ int target_read_u8(struct target *target, uint32_t address, uint8_t *value)
return retval;
}
+int target_write_u64(struct target *target, uint64_t address, uint64_t value)
+{
+ int retval;
+ uint8_t value_buf[8];
+ if (!target_was_examined(target)) {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
+
+ LOG_DEBUG("address: 0x%" PRIx64 ", value: 0x%16.16" PRIx64 "",
+ address,
+ value);
+
+ target_buffer_set_u64(target, value_buf, value);
+ retval = target_write_memory(target, address, 8, 1, value_buf);
+ if (retval != ERROR_OK)
+ LOG_DEBUG("failed: %i", retval);
+
+ return retval;
+}
+
int target_write_u32(struct target *target, uint32_t address, uint32_t value)
{
int retval;