[PATCH 1/2]support64: Add functions into types and target 00/1700/4
authorDongxue Zhang <elta.era@gmail.com>
Fri, 15 Nov 2013 08:55:34 +0000 (16:55 +0800)
committerAndreas Fritiofson <andreas.fritiofson@gmail.com>
Sun, 1 Dec 2013 12:39:36 +0000 (12:39 +0000)
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>
src/helper/types.h
src/target/target.c
src/target/target.h

index 7a845284e4467cd8f4db5fad568eebfe02f50828..210d3c3e92fd3d2f1354e8eb0066a41da9a703cd 100644 (file)
@@ -110,6 +110,17 @@ typedef bool _Bool;
  * Again, note that the "buf" pointer in memory is probably unaligned.
  */
 
  * Again, note that the "buf" pointer in memory is probably unaligned.
  */
 
+static inline uint64_t le_to_h_u64(const uint8_t *buf)
+{
+       return (uint64_t)((uint64_t)buf[0] |
+                         (uint64_t)buf[1] << 8 |
+                         (uint64_t)buf[2] << 16 |
+                         (uint64_t)buf[3] << 24 |
+                         (uint64_t)buf[4] << 32 |
+                         (uint64_t)buf[5] << 40 |
+                         (uint64_t)buf[6] << 48 |
+                         (uint64_t)buf[7] << 56);
+}
 
 static inline uint32_t le_to_h_u32(const uint8_t* buf)
 {
 
 static inline uint32_t le_to_h_u32(const uint8_t* buf)
 {
@@ -126,6 +137,18 @@ static inline uint16_t le_to_h_u16(const uint8_t* buf)
        return (uint16_t)(buf[0] | buf[1] << 8);
 }
 
        return (uint16_t)(buf[0] | buf[1] << 8);
 }
 
+static inline uint64_t be_to_h_u64(const uint8_t *buf)
+{
+       return (uint64_t)((uint64_t)buf[7] |
+                         (uint64_t)buf[6] << 8 |
+                         (uint64_t)buf[5] << 16 |
+                         (uint64_t)buf[4] << 24 |
+                         (uint64_t)buf[3] << 32 |
+                         (uint64_t)buf[2] << 40 |
+                         (uint64_t)buf[1] << 48 |
+                         (uint64_t)buf[0] << 56);
+}
+
 static inline uint32_t be_to_h_u32(const uint8_t* buf)
 {
        return (uint32_t)(buf[3] | buf[2] << 8 | buf[1] << 16 | buf[0] << 24);
 static inline uint32_t be_to_h_u32(const uint8_t* buf)
 {
        return (uint32_t)(buf[3] | buf[2] << 8 | buf[1] << 16 | buf[0] << 24);
@@ -141,6 +164,30 @@ static inline uint16_t be_to_h_u16(const uint8_t* buf)
        return (uint16_t)(buf[1] | buf[0] << 8);
 }
 
        return (uint16_t)(buf[1] | buf[0] << 8);
 }
 
+static inline void h_u64_to_le(uint8_t *buf, int64_t val)
+{
+       buf[7] = (uint8_t) (val >> 56);
+       buf[6] = (uint8_t) (val >> 48);
+       buf[5] = (uint8_t) (val >> 40);
+       buf[4] = (uint8_t) (val >> 32);
+       buf[3] = (uint8_t) (val >> 24);
+       buf[2] = (uint8_t) (val >> 16);
+       buf[1] = (uint8_t) (val >> 8);
+       buf[0] = (uint8_t) (val >> 0);
+}
+
+static inline void h_u64_to_be(uint8_t *buf, int64_t val)
+{
+       buf[0] = (uint8_t) (val >> 56);
+       buf[1] = (uint8_t) (val >> 48);
+       buf[2] = (uint8_t) (val >> 40);
+       buf[3] = (uint8_t) (val >> 32);
+       buf[4] = (uint8_t) (val >> 24);
+       buf[5] = (uint8_t) (val >> 16);
+       buf[6] = (uint8_t) (val >> 8);
+       buf[7] = (uint8_t) (val >> 0);
+}
+
 static inline void h_u32_to_le(uint8_t* buf, int val)
 {
        buf[3] = (uint8_t) (val >> 24);
 static inline void h_u32_to_le(uint8_t* buf, int val)
 {
        buf[3] = (uint8_t) (val >> 24);
index 3042d5d6cf0a43ab698175c55897739435574d1b..cb54ced5e5733ac42044b37371f498d4a55103c9 100644 (file)
@@ -294,6 +294,15 @@ static int new_target_number(void)
        return x + 1;
 }
 
        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)
 {
 /* 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;
 }
 
        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)
 {
 /* 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;
 }
 
        *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)
 {
 /* 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]);
 }
 
                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)
 {
 /* 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;
 }
 
        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];
 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;
 }
 
        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;
 int target_write_u32(struct target *target, uint32_t address, uint32_t value)
 {
        int retval;
index 124dc9b709b4af0bef06f8c82216d88f8216132b..21b94eea8a583fd5f84d8c8159a60542ab180bf8 100644 (file)
@@ -593,21 +593,27 @@ uint32_t target_get_working_area_avail(struct target *target);
 
 extern struct target *all_targets;
 
 
 extern struct target *all_targets;
 
+uint64_t target_buffer_get_u64(struct target *target, const uint8_t *buffer);
 uint32_t target_buffer_get_u32(struct target *target, const uint8_t *buffer);
 uint32_t target_buffer_get_u24(struct target *target, const uint8_t *buffer);
 uint16_t target_buffer_get_u16(struct target *target, const uint8_t *buffer);
 uint32_t target_buffer_get_u32(struct target *target, const uint8_t *buffer);
 uint32_t target_buffer_get_u24(struct target *target, const uint8_t *buffer);
 uint16_t target_buffer_get_u16(struct target *target, const uint8_t *buffer);
+void target_buffer_set_u64(struct target *target, uint8_t *buffer, uint64_t value);
 void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value);
 void target_buffer_set_u24(struct target *target, uint8_t *buffer, uint32_t value);
 void target_buffer_set_u16(struct target *target, uint8_t *buffer, uint16_t value);
 
 void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value);
 void target_buffer_set_u24(struct target *target, uint8_t *buffer, uint32_t value);
 void target_buffer_set_u16(struct target *target, uint8_t *buffer, uint16_t value);
 
+void target_buffer_get_u64_array(struct target *target, const uint8_t *buffer, uint32_t count, uint64_t *dstbuf);
 void target_buffer_get_u32_array(struct target *target, const uint8_t *buffer, uint32_t count, uint32_t *dstbuf);
 void target_buffer_get_u16_array(struct target *target, const uint8_t *buffer, uint32_t count, uint16_t *dstbuf);
 void target_buffer_get_u32_array(struct target *target, const uint8_t *buffer, uint32_t count, uint32_t *dstbuf);
 void target_buffer_get_u16_array(struct target *target, const uint8_t *buffer, uint32_t count, uint16_t *dstbuf);
+void target_buffer_set_u64_array(struct target *target, uint8_t *buffer, uint32_t count, const uint64_t *srcbuf);
 void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_t count, const uint32_t *srcbuf);
 void target_buffer_set_u16_array(struct target *target, uint8_t *buffer, uint32_t count, const uint16_t *srcbuf);
 
 void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_t count, const uint32_t *srcbuf);
 void target_buffer_set_u16_array(struct target *target, uint8_t *buffer, uint32_t count, const uint16_t *srcbuf);
 
+int target_read_u64(struct target *target, uint64_t address, uint64_t *value);
 int target_read_u32(struct target *target, uint32_t address, uint32_t *value);
 int target_read_u16(struct target *target, uint32_t address, uint16_t *value);
 int target_read_u8(struct target *target, uint32_t address, uint8_t *value);
 int target_read_u32(struct target *target, uint32_t address, uint32_t *value);
 int target_read_u16(struct target *target, uint32_t address, uint16_t *value);
 int target_read_u8(struct target *target, uint32_t address, uint8_t *value);
+int target_write_u64(struct target *target, uint64_t address, uint64_t value);
 int target_write_u32(struct target *target, uint32_t address, uint32_t value);
 int target_write_u16(struct target *target, uint32_t address, uint16_t value);
 int target_write_u8(struct target *target, uint32_t address, uint8_t value);
 int target_write_u32(struct target *target, uint32_t address, uint32_t value);
 int target_write_u16(struct target *target, uint32_t address, uint16_t value);
 int target_write_u8(struct target *target, uint32_t address, uint8_t value);

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)