This is an automated email from Gerrit. Peter Mamonov ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/2321
-- gerrit commit e09de7987c614f43a8903edb763387b4267b62aa Author: Peter Mamonov <[email protected]> Date: Tue Sep 23 12:46:02 2014 +0400 mips: Add MIPS64 support The patch adds support for processors implementing MIPS64 instruction set. Change-Id: I79a983dfdead81553457a0f3e9e739a9785afaac Signed-off-by: Konstantin Kostyukhin <[email protected]> Signed-off-by: Andrey Sidorov <[email protected]> Signed-off-by: Aleksey Kuleshov <[email protected]> Signed-off-by: Antony Pavlov <[email protected]> Signed-off-by: Peter Mamonov <[email protected]> CC: Dongxue Zhang <[email protected]> CC: Oleksij Rempel <[email protected]> CC: Paul Fertser <[email protected]> CC: Salvador Arroyo <[email protected]> CC: Spencer Oliver <[email protected]> diff --git a/src/helper/command.h b/src/helper/command.h index 0f0edbb..3dd6871 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -359,6 +359,7 @@ DECLARE_PARSE_WRAPPER(_u16, uint16_t); DECLARE_PARSE_WRAPPER(_u8, uint8_t); DECLARE_PARSE_WRAPPER(_int, int); +DECLARE_PARSE_WRAPPER(_s64, int64_t); DECLARE_PARSE_WRAPPER(_s32, int32_t); DECLARE_PARSE_WRAPPER(_s16, int16_t); DECLARE_PARSE_WRAPPER(_s8, int8_t); diff --git a/src/helper/types.h b/src/helper/types.h index 210d3c3..61683a1 100644 --- a/src/helper/types.h +++ b/src/helper/types.h @@ -286,6 +286,9 @@ static inline void buf_bswap32(uint8_t *dst, const uint8_t *src, size_t len) #define PRId8 PRId32 #define SCNx64 "llx" #define PRIx64 "llx" +#define PRId64 "lld" +#define PRIi64 "lli" +#define PRIu64 "llu" typedef CYG_ADDRWORD intptr_t; typedef int64_t intmax_t; diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 2912c74..3b93e51 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -1342,7 +1342,7 @@ static int gdb_read_memory_packet(struct connection *connection, { struct target *target = get_target_from_connection(connection); char *separator; - uint32_t addr = 0; + uint64_t addr = 0; uint32_t len = 0; uint8_t *buffer; @@ -1353,7 +1353,7 @@ static int gdb_read_memory_packet(struct connection *connection, /* skip command character */ packet++; - addr = strtoul(packet, &separator, 16); + addr = strtoull(packet, &separator, 16); if (*separator != ',') { LOG_ERROR("incomplete read memory packet received, dropping connection"); @@ -1370,7 +1370,7 @@ static int gdb_read_memory_packet(struct connection *connection, buffer = malloc(len); - LOG_DEBUG("addr: 0x%8.8" PRIx32 ", len: 0x%8.8" PRIx32 "", addr, len); + LOG_DEBUG("addr: 0x%16.16" PRIx64 ", len: 0x%8.8" PRIx32 "", addr, len); retval = target_read_buffer(target, addr, len, buffer); @@ -1547,7 +1547,7 @@ static int gdb_breakpoint_watchpoint_packet(struct connection *connection, int type; enum breakpoint_type bp_type = BKPT_SOFT /* dummy init to avoid warning */; enum watchpoint_rw wp_type = WPT_READ /* dummy init to avoid warning */; - uint32_t address; + uint64_t address; uint32_t size; char *separator; int retval; @@ -1579,7 +1579,7 @@ static int gdb_breakpoint_watchpoint_packet(struct connection *connection, return ERROR_SERVER_REMOTE_CLOSED; } - address = strtoul(separator + 1, &separator, 16); + address = strtoull(separator + 1, &separator, 16); if (*separator != ',') { LOG_ERROR("incomplete breakpoint/watchpoint packet received, dropping connection"); diff --git a/src/target/Makefile.am b/src/target/Makefile.am index 08d0db4..290a84b 100644 --- a/src/target/Makefile.am +++ b/src/target/Makefile.am @@ -36,6 +36,7 @@ libtarget_la_SOURCES = \ $(MIPS32_SRC) \ $(NDS32_SRC) \ $(INTEL_IA32_SRC) \ + $(MIPS64_SRC)\ avrt.c \ dsp563xx.c \ dsp563xx_once.c \ @@ -130,6 +131,14 @@ INTEL_IA32_SRC = \ lakemont.c \ x86_32_common.c +MIPS64_SRC = \ + mips64.c \ + mips32_pracc.c \ + mips64_pracc.c \ + trace.c \ + mips_ejtag.c + + noinst_HEADERS = \ algorithm.h \ arm.h \ @@ -198,7 +207,9 @@ noinst_HEADERS = \ nds32_v3m.h \ nds32_aice.h \ lakemont.h \ - x86_32_common.h + x86_32_common.h \ + mips64.h \ + mips64_pracc.h ocddatadir = $(pkglibdir) nobase_dist_ocddata_DATA = diff --git a/src/target/breakpoints.c b/src/target/breakpoints.c index 5143afb..7ed44c9 100644 --- a/src/target/breakpoints.c +++ b/src/target/breakpoints.c @@ -44,7 +44,7 @@ static char *watchpoint_rw_strings[] = { static int bpwp_unique_id; int breakpoint_add_internal(struct target *target, - uint32_t address, + uint64_t address, uint32_t length, enum breakpoint_type type) { @@ -62,7 +62,7 @@ int breakpoint_add_internal(struct target *target, * breakpoint" ... check all the parameters before * succeeding. */ - LOG_DEBUG("Duplicate Breakpoint address: 0x%08" PRIx32 " (BP %" PRIu32 ")", + LOG_DEBUG("Duplicate Breakpoint address: 0x%16" PRIx64 " (BP %" PRIu32 ")", address, breakpoint->unique_id); return ERROR_OK; } @@ -152,7 +152,7 @@ int context_breakpoint_add_internal(struct target *target, return retval; } - LOG_DEBUG("added %s Context breakpoint at 0x%8.8" PRIx32 " of length 0x%8.8x, (BPID: %" PRIu32 ")", + LOG_DEBUG("added %s Context breakpoint at 0x%16.16" PRIx64 " of length 0x%8.8x, (BPID: %" PRIu32 ")", breakpoint_type_strings[(*breakpoint_p)->type], (*breakpoint_p)->asid, (*breakpoint_p)->length, (*breakpoint_p)->unique_id); @@ -161,7 +161,7 @@ int context_breakpoint_add_internal(struct target *target, } int hybrid_breakpoint_add_internal(struct target *target, - uint32_t address, + uint64_t address, uint32_t asid, uint32_t length, enum breakpoint_type type) @@ -220,7 +220,7 @@ int hybrid_breakpoint_add_internal(struct target *target, } int breakpoint_add(struct target *target, - uint32_t address, + uint64_t address, uint32_t length, enum breakpoint_type type) { @@ -265,7 +265,7 @@ int context_breakpoint_add(struct target *target, return context_breakpoint_add_internal(target, asid, length, type); } int hybrid_breakpoint_add(struct target *target, - uint32_t address, + uint64_t address, uint32_t asid, uint32_t length, enum breakpoint_type type) @@ -312,7 +312,7 @@ static void breakpoint_free(struct target *target, struct breakpoint *breakpoint free(breakpoint); } -int breakpoint_remove_internal(struct target *target, uint32_t address) +int breakpoint_remove_internal(struct target *target, uint64_t address) { struct breakpoint *breakpoint = target->breakpoints; @@ -331,11 +331,11 @@ int breakpoint_remove_internal(struct target *target, uint32_t address) return 1; } else { if (!target->smp) - LOG_ERROR("no breakpoint at address 0x%8.8" PRIx32 " found", address); + LOG_ERROR("no breakpoint at address 0x%16.16" PRIx64 " found", address); return 0; } } -void breakpoint_remove(struct target *target, uint32_t address) +void breakpoint_remove(struct target *target, uint64_t address) { int found = 0; if (target->smp) { @@ -348,7 +348,7 @@ void breakpoint_remove(struct target *target, uint32_t address) head = head->next; } if (found == 0) - LOG_ERROR("no breakpoint at address 0x%8.8" PRIx32 " found", address); + LOG_ERROR("no breakpoint at address 0x%16.16" PRIx64 " found", address); } else breakpoint_remove_internal(target, address); } @@ -377,7 +377,7 @@ void breakpoint_clear_target(struct target *target) } -struct breakpoint *breakpoint_find(struct target *target, uint32_t address) +struct breakpoint *breakpoint_find(struct target *target, uint64_t address) { struct breakpoint *breakpoint = target->breakpoints; @@ -390,8 +390,8 @@ struct breakpoint *breakpoint_find(struct target *target, uint32_t address) return NULL; } -int watchpoint_add(struct target *target, uint32_t address, uint32_t length, - enum watchpoint_rw rw, uint32_t value, uint32_t mask) +int watchpoint_add(struct target *target, uint64_t address, uint32_t length, + enum watchpoint_rw rw, uint64_t value, uint64_t mask) { struct watchpoint *watchpoint = target->watchpoints; struct watchpoint **watchpoint_p = &target->watchpoints; @@ -404,7 +404,7 @@ int watchpoint_add(struct target *target, uint32_t address, uint32_t length, || watchpoint->value != value || watchpoint->mask != mask || watchpoint->rw != rw) { - LOG_ERROR("address 0x%8.8" PRIx32 + LOG_ERROR("address 0x%16.16" PRIx64 "already has watchpoint %d", address, watchpoint->unique_id); return ERROR_FAIL; @@ -438,7 +438,7 @@ int watchpoint_add(struct target *target, uint32_t address, uint32_t length, default: reason = "unrecognized error"; bye: - LOG_ERROR("can't add %s watchpoint at 0x%8.8" PRIx32 ", %s", + LOG_ERROR("can't add %s watchpoint at 0x%16.16" PRIx64 ", %s", watchpoint_rw_strings[(*watchpoint_p)->rw], address, reason); free(*watchpoint_p); @@ -446,7 +446,7 @@ bye: return retval; } - LOG_DEBUG("added %s watchpoint at 0x%8.8" PRIx32 + LOG_DEBUG("added %s watchpoint at 0x%16.16" PRIx64 " of length 0x%8.8" PRIx32 " (WPID: %d)", watchpoint_rw_strings[(*watchpoint_p)->rw], (*watchpoint_p)->address, @@ -477,7 +477,7 @@ static void watchpoint_free(struct target *target, struct watchpoint *watchpoint free(watchpoint); } -void watchpoint_remove(struct target *target, uint32_t address) +void watchpoint_remove(struct target *target, uint64_t address) { struct watchpoint *watchpoint = target->watchpoints; @@ -490,7 +490,7 @@ void watchpoint_remove(struct target *target, uint32_t address) if (watchpoint) watchpoint_free(target, watchpoint); else - LOG_ERROR("no watchpoint at address 0x%8.8" PRIx32 " found", address); + LOG_ERROR("no watchpoint at address 0x%16.16" PRIx64 " found", address); } void watchpoint_clear_target(struct target *target) diff --git a/src/target/breakpoints.h b/src/target/breakpoints.h index 0246acd..fd841ff 100644 --- a/src/target/breakpoints.h +++ b/src/target/breakpoints.h @@ -33,7 +33,7 @@ enum watchpoint_rw { }; struct breakpoint { - uint32_t address; + uint64_t address; uint32_t asid; int length; enum breakpoint_type type; @@ -45,10 +45,10 @@ struct breakpoint { }; struct watchpoint { - uint32_t address; + uint64_t address; uint32_t length; - uint32_t mask; - uint32_t value; + uint64_t mask; + uint64_t value; enum watchpoint_rw rw; int set; struct watchpoint *next; @@ -57,20 +57,20 @@ struct watchpoint { void breakpoint_clear_target(struct target *target); int breakpoint_add(struct target *target, - uint32_t address, uint32_t length, enum breakpoint_type type); + uint64_t address, uint32_t length, enum breakpoint_type type); int context_breakpoint_add(struct target *target, uint32_t asid, uint32_t length, enum breakpoint_type type); int hybrid_breakpoint_add(struct target *target, - uint32_t address, uint32_t asid, uint32_t length, enum breakpoint_type type); -void breakpoint_remove(struct target *target, uint32_t address); + uint64_t address, uint32_t asid, uint32_t length, enum breakpoint_type type); +void breakpoint_remove(struct target *target, uint64_t address); -struct breakpoint *breakpoint_find(struct target *target, uint32_t address); +struct breakpoint *breakpoint_find(struct target *target, uint64_t address); void watchpoint_clear_target(struct target *target); int watchpoint_add(struct target *target, - uint32_t address, uint32_t length, - enum watchpoint_rw rw, uint32_t value, uint32_t mask); -void watchpoint_remove(struct target *target, uint32_t address); + uint64_t address, uint32_t length, + enum watchpoint_rw rw, uint64_t value, uint64_t mask); +void watchpoint_remove(struct target *target, uint64_t address); /* report type and address of just hit watchpoint */ int watchpoint_hit(struct target *target, enum watchpoint_rw *rw, uint32_t *address); diff --git a/src/target/image.c b/src/target/image.c index 07420b1..c7847b8 100644 --- a/src/target/image.c +++ b/src/target/image.c @@ -123,7 +123,7 @@ static int image_ihex_buffer_complete_inner(struct image *image, { struct image_ihex *ihex = image->type_private; struct fileio *fileio = &ihex->fileio; - uint32_t full_address = 0x0; + uint64_t full_address = 0x0; uint32_t cooked_bytes; int i; @@ -146,7 +146,7 @@ static int image_ihex_buffer_complete_inner(struct image *image, while (fileio_fgets(fileio, 1023, lpszLine) == ERROR_OK) { uint32_t count; - uint32_t address; + uint64_t address; uint32_t record_type; uint32_t checksum; uint8_t cal_checksum = 0; @@ -155,7 +155,7 @@ static int image_ihex_buffer_complete_inner(struct image *image, if (lpszLine[0] == '#') continue; - if (sscanf(&lpszLine[bytes_read], ":%2" SCNx32 "%4" SCNx32 "%2" SCNx32, &count, + if (sscanf(&lpszLine[bytes_read], ":%2" SCNx32 "%4" SCNx64 "%2" SCNx32, &count, &address, &record_type) != 3) return ERROR_IMAGE_FORMAT_ERROR; bytes_read += 9; @@ -281,9 +281,13 @@ static int image_ihex_buffer_complete_inner(struct image *image, full_address = (full_address & 0xffff) | (upper_address << 16); } } else if (record_type == 5) { /* Start Linear Address Record */ - uint32_t start_address; + uint64_t start_address; - sscanf(&lpszLine[bytes_read], "%8" SCNx32, &start_address); + sscanf(&lpszLine[bytes_read], "%4" SCNx64, &start_address); + cal_checksum += (uint8_t)(start_address >> 56); + cal_checksum += (uint8_t)(start_address >> 48); + cal_checksum += (uint8_t)(start_address >> 40); + cal_checksum += (uint8_t)(start_address >> 32); cal_checksum += (uint8_t)(start_address >> 24); cal_checksum += (uint8_t)(start_address >> 16); cal_checksum += (uint8_t)(start_address >> 8); @@ -291,7 +295,7 @@ static int image_ihex_buffer_complete_inner(struct image *image, bytes_read += 8; image->start_address_set = 1; - image->start_address = be_to_h_u32((uint8_t *)&start_address); + image->start_address = be_to_h_u64((uint8_t *)&start_address); } else { LOG_ERROR("unhandled IHEX record type: %i", (int)record_type); return ERROR_IMAGE_FORMAT_ERROR; @@ -512,7 +516,7 @@ static int image_mot_buffer_complete_inner(struct image *image, { struct image_mot *mot = image->type_private; struct fileio *fileio = &mot->fileio; - uint32_t full_address = 0x0; + uint64_t full_address = 0x0; uint32_t cooked_bytes; int i; @@ -535,7 +539,7 @@ static int image_mot_buffer_complete_inner(struct image *image, while (fileio_fgets(fileio, 1023, lpszLine) == ERROR_OK) { uint32_t count; - uint32_t address; + uint64_t address; uint32_t record_type; uint32_t checksum; uint8_t cal_checksum = 0; @@ -565,7 +569,7 @@ static int image_mot_buffer_complete_inner(struct image *image, switch (record_type) { case 1: /* S1 - 16 bit address data record */ - sscanf(&lpszLine[bytes_read], "%4" SCNx32, &address); + sscanf(&lpszLine[bytes_read], "%4" SCNx64, &address); cal_checksum += (uint8_t)(address >> 8); cal_checksum += (uint8_t)address; bytes_read += 4; @@ -574,7 +578,7 @@ static int image_mot_buffer_complete_inner(struct image *image, case 2: /* S2 - 24 bit address data record */ - sscanf(&lpszLine[bytes_read], "%6" SCNx32, &address); + sscanf(&lpszLine[bytes_read], "%6" SCNx64, &address); cal_checksum += (uint8_t)(address >> 16); cal_checksum += (uint8_t)(address >> 8); cal_checksum += (uint8_t)address; @@ -584,7 +588,7 @@ static int image_mot_buffer_complete_inner(struct image *image, case 3: /* S3 - 32 bit address data record */ - sscanf(&lpszLine[bytes_read], "%8" SCNx32, &address); + sscanf(&lpszLine[bytes_read], "%8" SCNx64, &address); cal_checksum += (uint8_t)(address >> 24); cal_checksum += (uint8_t)(address >> 16); cal_checksum += (uint8_t)(address >> 8); @@ -851,7 +855,7 @@ int image_read_section(struct image *image, return image_elf_read_section(image, section, offset, size, buffer, size_read); else if (image->type == IMAGE_MEMORY) { struct image_memory *image_memory = image->type_private; - uint32_t address = image->sections[section].base_address + offset; + uint64_t address = image->sections[section].base_address + offset; *size_read = 0; @@ -902,7 +906,7 @@ int image_read_section(struct image *image, return ERROR_OK; } -int image_add_section(struct image *image, uint32_t base, uint32_t size, int flags, uint8_t const *data) +int image_add_section(struct image *image, uint64_t base, uint32_t size, int flags, uint8_t const *data) { struct imagesection *section; diff --git a/src/target/image.h b/src/target/image.h index 5aeba2f..59aa1a8 100644 --- a/src/target/image.h +++ b/src/target/image.h @@ -48,7 +48,7 @@ enum image_type { }; struct imagesection { - uint32_t base_address; + uint64_t base_address; uint32_t size; int flags; void *private; /* private data */ @@ -60,9 +60,9 @@ struct image { int num_sections; /* number of sections contained in the image */ struct imagesection *sections; /* array of sections */ int base_address_set; /* whether the image has a base address set (for relocation purposes) */ - long long base_address; /* base address, if one is set */ + uint64_t base_address; /* base address, if one is set */ int start_address_set; /* whether the image has a start address (entry point) associated */ - uint32_t start_address; /* start address, if one is set */ + uint64_t start_address; /* start address, if one is set */ }; struct image_binary { @@ -77,7 +77,7 @@ struct image_ihex { struct image_memory { struct target *target; uint8_t *cache; - uint32_t cache_address; + uint64_t cache_address; }; struct image_elf { @@ -98,7 +98,7 @@ int image_read_section(struct image *image, int section, uint32_t offset, uint32_t size, uint8_t *buffer, size_t *size_read); void image_close(struct image *image); -int image_add_section(struct image *image, uint32_t base, uint32_t size, +int image_add_section(struct image *image, uint64_t base, uint32_t size, int flags, uint8_t const *data); int image_calculate_checksum(uint8_t *buffer, uint32_t nbytes, diff --git a/src/target/mips32_pracc.c b/src/target/mips32_pracc.c index da9a2b7..c9aca77 100644 --- a/src/target/mips32_pracc.c +++ b/src/target/mips32_pracc.c @@ -1029,7 +1029,7 @@ int mips32_pracc_fastdata_xfer(struct mips_ejtag *ejtag_info, struct working_are ejtag_info->fast_access_save = write_t; } - LOG_DEBUG("%s using 0x%.8" PRIx32 " for write handler", __func__, source->address); + LOG_DEBUG("%s using 0x%.16" PRIx64 " for write handler", __func__, source->address); jmp_code[1] |= UPPER16(source->address); jmp_code[2] |= LOWER16(source->address); diff --git a/src/target/mips64.c b/src/target/mips64.c new file mode 100644 index 0000000..7ad5fcc --- /dev/null +++ b/src/target/mips64.c @@ -0,0 +1,511 @@ +/*************************************************************************** + * Support for processors implementing MIPS64 instruction set * + * * + * Copyright (C) 2014 by Andrey Sidorov <[email protected]> * + * Copyright (C) 2014 by Aleksey Kuleshov <[email protected]> * + * Copyright (C) 2014 by Antony Pavlov <[email protected]> * + * Copyright (C) 2014 by Peter Mamonov <[email protected]> * + * * + * Based on the work of: * + * Copyright (C) 2008 by Spencer Oliver * + * Copyright (C) 2008 by David T.L. Wong * + * Copyright (C) 2010 by Konstantin Kostyukhin, Nikolay Shmyrev * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "mips64.h" + +#define MIPS32_GDB_DUMMY_FP_REG 1 + +static const struct { + unsigned id; + const char *name; + enum reg_type type; + const char *group; + const char *feature; + int flag; +} mips64_regs[] = { + { 0, "r0", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 1, "r1", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 2, "r2", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 3, "r3", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 4, "r4", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 5, "r5", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 6, "r6", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 7, "r7", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 8, "r8", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 9, "r9", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 10, "r10", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 11, "r11", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 12, "r12", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 13, "r13", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 14, "r14", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 15, "r15", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 16, "r16", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 17, "r17", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 18, "r18", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 19, "r19", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 20, "r20", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 21, "r21", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 22, "r22", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 23, "r23", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 24, "r24", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 25, "r25", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 26, "r26", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 27, "r27", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 28, "r28", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 29, "r29", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 30, "r30", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 31, "r31", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 32, "status", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cp0", 0 }, + { 33, "lo", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 34, "hi", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + { 35, "badvaddr", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cp0", 0 }, + { 36, "cause", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cp0", 0 }, + { 37, "pc", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 }, + + { 38, "f0", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 39, "f1", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 40, "f2", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 41, "f3", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 42, "f4", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 43, "f5", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 44, "f6", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 45, "f7", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 46, "f8", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 47, "f9", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 48, "f10", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 49, "f11", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 50, "f12", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 51, "f13", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 52, "f14", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 53, "f15", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 54, "f16", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 55, "f17", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 56, "f18", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 57, "f19", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 58, "f20", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 59, "f21", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 60, "f22", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 61, "f23", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 62, "f24", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 63, "f25", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 64, "f26", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 65, "f27", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 66, "f28", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 67, "f29", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 68, "f30", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 69, "f31", REG_TYPE_IEEE_SINGLE, NULL, + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 70, "fcsr", REG_TYPE_INT, "float", + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG }, + { 71, "fir", REG_TYPE_INT, "float", + "org.gnu.gdb.mips.fpu", MIPS32_GDB_DUMMY_FP_REG } +}; + +static uint8_t mips32_gdb_dummy_fp_value[] = {0, 0, 0, 0}; + +int mips64_get_core_reg(struct reg *reg) +{ + int retval; + mips64_core_reg_t *mips64_reg = reg->arch_info; + struct target *target = mips64_reg->target; + mips64_common_t *mips64_target = target->arch_info; + + if (target->state != TARGET_HALTED) + return ERROR_TARGET_NOT_HALTED; + + retval = mips64_target->read_core_reg(target, mips64_reg->num); + + return retval; +} + +int mips64_set_core_reg(struct reg *reg, uint8_t *buf) +{ + mips64_core_reg_t *mips64_reg = reg->arch_info; + struct target *target = mips64_reg->target; + uint64_t value = buf_get_u64(buf, 0, 64); + + if (target->state != TARGET_HALTED) + return ERROR_TARGET_NOT_HALTED; + + buf_set_u64(reg->value, 0, 64, value); + reg->dirty = 1; + reg->valid = 1; + + return ERROR_OK; +} + +int mips64_read_core_reg(struct target *target, int num) +{ + uint64_t reg_value; + + /* get pointers to arch-specific information */ + mips64_common_t *mips64 = target->arch_info; + + if ((num < 0) || (num >= MIPS64NUMCOREREGS)) + return ERROR_COMMAND_ARGUMENT_INVALID; + + reg_value = mips64->core_regs[num]; + buf_set_u64(mips64->core_cache->reg_list[num].value, 0, 64, reg_value); + mips64->core_cache->reg_list[num].valid = 1; + mips64->core_cache->reg_list[num].dirty = 0; + + return ERROR_OK; +} + +int mips64_write_core_reg(struct target *target, int num) +{ + uint64_t reg_value; + + /* get pointers to arch-specific information */ + mips64_common_t *mips64 = target->arch_info; + + if ((num < 0) || (num >= MIPS64NUMCOREREGS)) + return ERROR_COMMAND_ARGUMENT_INVALID; + + reg_value = buf_get_u64(mips64->core_cache->reg_list[num].value, 0, 64); + mips64->core_regs[num] = reg_value; + LOG_DEBUG("write core reg %i value 0x%" PRIx64 "", num , reg_value); + mips64->core_cache->reg_list[num].valid = 1; + mips64->core_cache->reg_list[num].dirty = 0; + + return ERROR_OK; +} + +int mips64_invalidate_core_regs(struct target *target) +{ + /* get pointers to arch-specific information */ + mips64_common_t *mips64 = target->arch_info; + unsigned int i; + + for (i = 0; i < mips64->core_cache->num_regs; i++) { + mips64->core_cache->reg_list[i].valid = 0; + mips64->core_cache->reg_list[i].dirty = 0; + } + + return ERROR_OK; +} + + +int mips64_get_gdb_reg_list(struct target *target, struct reg **reg_list[], + int *reg_list_size, enum target_register_class reg_class) +{ + /* get pointers to arch-specific information */ + mips64_common_t *mips64 = target->arch_info; + register int i; + + /* include floating point registers */ + *reg_list_size = MIPS64NUMCOREREGS; + *reg_list = malloc(sizeof(struct reg *) * (*reg_list_size)); + + for (i = 0; i < MIPS64NUMCOREREGS; i++) + (*reg_list)[i] = &mips64->core_cache->reg_list[i]; + + return ERROR_OK; +} + +int mips64_save_context(struct target *target) +{ + int i, retval; + + /* get pointers to arch-specific information */ + mips64_common_t *mips64 = target->arch_info; + struct mips_ejtag *ejtag_info = &mips64->ejtag_info; + + /* read core registers */ + retval = mips64_pracc_read_regs(ejtag_info, mips64->core_regs); + if (retval != ERROR_OK) + return retval; + + for (i = 0; i < MIPS64NUMCOREREGS; i++) { + retval = mips64->read_core_reg(target, i); + } + + return retval; +} + +int mips64_restore_context(struct target *target) +{ + int i; + + /* get pointers to arch-specific information */ + mips64_common_t *mips64 = target->arch_info; + struct mips_ejtag *ejtag_info = &mips64->ejtag_info; + + for (i = 0; i < MIPS64NUMCOREREGS; i++) { + if (mips64->core_cache->reg_list[i].dirty) + mips64->write_core_reg(target, i); + } + + /* write core regs */ + return mips64_pracc_write_regs(ejtag_info, mips64->core_regs); +} + +int mips64_arch_state(struct target *target) +{ + mips64_common_t *mips64 = target->arch_info; + + if (mips64->common_magic != MIPS64_COMMON_MAGIC) { + LOG_ERROR("BUG: called for a non-MIPS64 target"); + exit(-1); + } + + LOG_USER("target halted due to %s, pc: 0x%" PRIx64 "", + debug_reason_name(target), + buf_get_u64(mips64->core_cache->reg_list[MIPS64_PC].value, 0, 64)); + + return ERROR_OK; +} + +static const struct reg_arch_type mips64_reg_type = { + .get = mips64_get_core_reg, + .set = mips64_set_core_reg, +}; + +struct reg_cache *mips64_build_reg_cache(struct target *target) +{ + /* get pointers to arch-specific information */ + mips64_common_t *mips64 = target->arch_info; + + int num_regs = MIPS64NUMCOREREGS; + struct reg_cache **cache_p = register_get_last_cache_p(&target->reg_cache); + struct reg_cache *cache = malloc(sizeof(struct reg_cache)); + struct reg *reg_list = malloc(sizeof(struct reg) * num_regs); + mips64_core_reg_t *arch_info = malloc(sizeof(mips64_core_reg_t) * num_regs); + struct reg_feature *feature; + int i; + + /* Build the process context cache */ + cache->name = "mips64 registers"; + cache->next = NULL; + cache->reg_list = reg_list; + cache->num_regs = num_regs; + (*cache_p) = cache; + mips64->core_cache = cache; + + for (i = 0; i < num_regs; i++) { + arch_info[i].num = mips64_regs[i].id; + arch_info[i].target = target; + arch_info[i].mips64_common = mips64; + reg_list[i].name = mips64_regs[i].name; + reg_list[i].size = 64; + reg_list[i].value = calloc(1, 8); + + if (mips64_regs[i].flag == MIPS32_GDB_DUMMY_FP_REG) { + reg_list[i].value = mips32_gdb_dummy_fp_value; + reg_list[i].valid = 1; + reg_list[i].arch_info = NULL; + register_init_dummy(®_list[i]); + } else { + reg_list[i].value = calloc(1, 4); + reg_list[i].valid = 0; + reg_list[i].type = &mips64_reg_type; + reg_list[i].arch_info = &arch_info[i]; + + reg_list[i].reg_data_type = calloc(1, sizeof(struct reg_data_type)); + if (reg_list[i].reg_data_type) + reg_list[i].reg_data_type->type = mips64_regs[i].type; + else + LOG_ERROR("unable to allocate reg type list"); + } + + reg_list[i].dirty = 0; + + reg_list[i].group = mips64_regs[i].group; + reg_list[i].number = i; + reg_list[i].exist = true; + reg_list[i].caller_save = true; /* gdb defaults to true */ + + feature = calloc(1, sizeof(struct reg_feature)); + if (feature) { + feature->name = mips64_regs[i].feature; + reg_list[i].feature = feature; + } else + LOG_ERROR("unable to allocate feature list"); + } + + return cache; +} + +int mips64_init_arch_info(struct target *target, mips64_common_t *mips64, struct jtag_tap *tap) +{ + target->arch_info = mips64; + mips64->common_magic = MIPS64_COMMON_MAGIC; + + /* has breakpoint/watchpint unit been scanned */ + mips64->bp_scanned = 0; + mips64->data_break_list = NULL; + + mips64->ejtag_info.tap = tap; + mips64->read_core_reg = mips64_read_core_reg; + mips64->write_core_reg = mips64_write_core_reg; + + return ERROR_OK; +} + +int mips64_run_algorithm(struct target *target, int num_mem_params, + struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, + uint32_t entry_point, uint32_t exit_point, int timeout_ms, void *arch_info) +{ + /*TODO*/ + return ERROR_OK; +} + +int mips64_examine(struct target *target) +{ + mips64_common_t *mips64 = target->arch_info; + + if (!target_was_examined(target)) { + target_set_examined(target); + + /* we will configure later */ + mips64->bp_scanned = 0; + mips64->num_inst_bpoints = 0; + mips64->num_data_bpoints = 0; + mips64->num_inst_bpoints_avail = 0; + mips64->num_data_bpoints_avail = 0; + } + + return ERROR_OK; +} + +int mips64_configure_break_unit(struct target *target) +{ + /* get pointers to arch-specific information */ + mips64_common_t *mips64 = target->arch_info; + int retval; + uint64_t dcr; + uint64_t bpinfo; + int i; + + if (mips64->bp_scanned) + return ERROR_OK; + + /* get info about breakpoint support */ + retval = target_read_u64(target, EJTAG64_DCR, &dcr); + if (retval != ERROR_OK) + return retval; + + if (dcr & (1 << 16)) { + /* get number of inst breakpoints */ + retval = target_read_u64(target, EJTAG64_V25_IBS, &bpinfo); + if (retval != ERROR_OK) + return retval; + + mips64->num_inst_bpoints = (bpinfo >> 24) & 0x0F; + mips64->num_inst_bpoints_avail = mips64->num_inst_bpoints; + mips64->inst_break_list = calloc(mips64->num_inst_bpoints, sizeof(mips64_comparator_t)); + for (i = 0; i < mips64->num_inst_bpoints; i++) + mips64->inst_break_list[i].reg_address = EJTAG64_V25_IBA0 + (0x100 * i); + + /* clear IBIS reg */ + retval = target_write_u64(target, EJTAG64_V25_IBS, 0); + if (retval != ERROR_OK) + return retval; + } + + if (dcr & (1 << 17)) { + /* get number of data breakpoints */ + retval = target_read_u64(target, EJTAG64_V25_DBS, &bpinfo); + if (retval != ERROR_OK) + return retval; + + mips64->num_data_bpoints = (bpinfo >> 24) & 0x0F; + mips64->num_data_bpoints_avail = mips64->num_data_bpoints; + mips64->data_break_list = calloc(mips64->num_data_bpoints, sizeof(mips64_comparator_t)); + for (i = 0; i < mips64->num_data_bpoints; i++) + mips64->data_break_list[i].reg_address = EJTAG64_V25_DBA0 + (0x100 * i); + + /* clear DBIS reg */ + retval = target_write_u64(target, EJTAG64_V25_DBS, 0); + if (retval != ERROR_OK) + return retval; + } + + LOG_DEBUG("DCR 0x%" PRIx64 " numinst %i numdata %i", dcr, mips64->num_inst_bpoints, mips64->num_data_bpoints); + + mips64->bp_scanned = 1; + + return ERROR_OK; +} + +int mips64_enable_interrupts(struct target *target, int enable) +{ + int retval; + int update = 0; + uint64_t dcr; + + /* read debug control register */ + retval = target_read_u64(target, EJTAG64_DCR, &dcr); + if (retval != ERROR_OK) + return retval; + + if (enable) { + if (!(dcr & (1 << 4))) { + /* enable interrupts */ + dcr |= (1 << 4); + update = 1; + } + } else { + if (dcr & (1 << 4)) { + /* disable interrupts */ + dcr &= ~(1 << 4); + update = 1; + } + } + + if (update) { + retval = target_write_u64(target, EJTAG64_DCR, dcr); + if (retval != ERROR_OK) + return retval; + } + + return ERROR_OK; +} diff --git a/src/target/mips64.h b/src/target/mips64.h new file mode 100644 index 0000000..0d7be51 --- /dev/null +++ b/src/target/mips64.h @@ -0,0 +1,172 @@ +/*************************************************************************** + * Support for processors implementing MIPS64 instruction set * + * * + * Copyright (C) 2014 by Andrey Sidorov <[email protected]> * + * Copyright (C) 2014 by Aleksey Kuleshov <[email protected]> * + * Copyright (C) 2014 by Peter Mamonov <[email protected]> * + * * + * Based on the work of: * + * Copyright (C) 2008 by Spencer Oliver * + * Copyright (C) 2008 by David T.L. Wong * + * Copyright (C) 2010 by Konstantin Kostyukhin, Nikolay Shmyrev * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef MIPS64_H +#define MIPS64_H + +#include "target.h" +#include "register.h" +#include "mips64_pracc.h" + + +#define MIPS64_COMMON_MAGIC 0xB640B640 + +/* offsets into mips64 core register cache */ +enum { + MIPS64_PC = 37, + MIPS32_FIR = 71, + MIPS64NUMCOREREGS +}; + +typedef struct mips64_comparator_s { + int used; + uint64_t bp_value; + uint64_t reg_address; +} mips64_comparator_t; + +typedef struct mips64_common_s { + uint32_t common_magic; + void *arch_info; + struct reg_cache *core_cache; + struct mips_ejtag ejtag_info; + uint64_t core_regs[MIPS64NUMCOREREGS]; + + int bp_scanned; + int num_inst_bpoints; + int num_data_bpoints; + int num_inst_bpoints_avail; + int num_data_bpoints_avail; + mips64_comparator_t *inst_break_list; + mips64_comparator_t *data_break_list; + + /* register cache to processor synchronization */ + int (*read_core_reg)(struct target *target, int num); + int (*write_core_reg)(struct target *target, int num); +} mips64_common_t; + +typedef struct mips64_core_reg_s { + uint32_t num; + struct target *target; + mips64_common_t *mips64_common; +} mips64_core_reg_t; + +#define MIPS64_OP_BEQ 0x04 +#define MIPS64_OP_BNE 0x05 +#define MIPS64_OP_ADDI 0x08 +#define MIPS64_OP_AND 0x24 +#define MIPS64_OP_LUI 0x0F +#define MIPS64_OP_LW 0x23 +#define MIPS64_OP_LD 0x37 +#define MIPS64_OP_LBU 0x24 +#define MIPS64_OP_LHU 0x25 +#define MIPS64_OP_MFHI 0x10 +#define MIPS64_OP_MTHI 0x11 +#define MIPS64_OP_MFLO 0x12 +#define MIPS64_OP_MTLO 0x13 +#define MIPS64_OP_SB 0x28 +#define MIPS64_OP_SH 0x29 +#define MIPS64_OP_SW 0x2B +#define MIPS64_OP_SD 0x3F +#define MIPS64_OP_ORI 0x0D + +#define MIPS64_OP_COP0 0x10 +#define MIPS64_OP_COP1 0x11 +#define MIPS64_OP_COP2 0x12 + +#define MIPS64_COP_MF 0x00 +#define MIPS64_COP_DMF 0x01 +#define MIPS64_COP_MT 0x04 +#define MIPS64_COP_DMT 0x05 +#define MIPS64_COP_CF 0x02 +#define MIPS64_COP_CT 0x06 + +#define MIPS64_R_INST(opcode, rs, rt, rd, shamt, funct) (((opcode) << 26) | ((rs) << 21) | ((rt) << 16) | ((rd) << 11) | ((shamt) << 6) | (funct)) +#define MIPS64_I_INST(opcode, rs, rt, immd) (((opcode) << 26) | ((rs) << 21) | ((rt) << 16) | (immd)) +#define MIPS64_J_INST(opcode, addr) (((opcode) << 26) | (addr)) + +#define MIPS64_NOP 0 +#define MIPS64_ADDI(tar, src, val) MIPS64_I_INST(MIPS64_OP_ADDI, src, tar, val) +#define MIPS64_AND(reg, off, val) MIPS64_R_INST(0, off, val, reg, 0, MIPS64_OP_AND) +#define MIPS64_B(off) MIPS64_BEQ(0, 0, off) +#define MIPS64_BEQ(src, tar, off) MIPS64_I_INST(MIPS64_OP_BEQ, src, tar, off) +#define MIPS64_BNE(src, tar, off) MIPS64_I_INST(MIPS64_OP_BNE, src, tar, off) +#define MIPS64_MFC0(gpr, cpr, sel) MIPS64_R_INST(MIPS64_OP_COP0, MIPS64_COP_MF, gpr, cpr, 0, sel) +#define MIPS64_DMFC0(gpr, cpr, sel) MIPS64_R_INST(MIPS64_OP_COP0, MIPS64_COP_DMF, gpr, cpr, 0, sel) +#define MIPS64_MTC0(gpr, cpr, sel) MIPS64_R_INST(MIPS64_OP_COP0, MIPS64_COP_MT, gpr, cpr, 0, sel) +#define MIPS64_DMTC0(gpr, cpr, sel) MIPS64_R_INST(MIPS64_OP_COP0, MIPS64_COP_DMT, gpr, cpr, 0, sel) +#define MIPS64_MFC1(gpr, cpr, sel) MIPS64_R_INST(MIPS64_OP_COP1, MIPS64_COP_MF, gpr, cpr, 0, 0) +#define MIPS64_MTC1(gpr, cpr, sel) MIPS64_R_INST(MIPS64_OP_COP1, MIPS64_COP_MT, gpr, cpr, 0, 0) +#define MIPS64_MFC2(gpr, cpr, sel) MIPS64_R_INST(MIPS64_OP_COP2, MIPS64_COP_MF, gpr, cpr, 0, sel) +#define MIPS64_MTC2(gpr, cpr, sel) MIPS64_R_INST(MIPS64_OP_COP2, MIPS64_COP_MT, gpr, cpr, 0, sel) +#define MIPS64_CFC1(gpr, cpr, sel) MIPS64_R_INST(MIPS64_OP_COP1, MIPS64_COP_CF, gpr, cpr, 0, 0) +#define MIPS64_CTC1(gpr, cpr, sel) MIPS64_R_INST(MIPS64_OP_COP1, MIPS64_COP_CT, gpr, cpr, 0, 0) +#define MIPS64_CFC2(gpr, cpr, sel) MIPS64_R_INST(MIPS64_OP_COP2, MIPS64_COP_CF, gpr, cpr, 0, sel) +#define MIPS64_CTC2(gpr, cpr, sel) MIPS64_R_INST(MIPS64_OP_COP2, MIPS64_COP_CT, gpr, cpr, 0, sel) +#define MIPS64_LBU(reg, off, base) MIPS64_I_INST(MIPS64_OP_LBU, base, reg, off) +#define MIPS64_LHU(reg, off, base) MIPS64_I_INST(MIPS64_OP_LHU, base, reg, off) +#define MIPS64_LUI(reg, val) MIPS64_I_INST(MIPS64_OP_LUI, 0, reg, val) +#define MIPS64_LW(reg, off, base) MIPS64_I_INST(MIPS64_OP_LW, base, reg, off) +#define MIPS64_LD(reg, off, base) MIPS64_I_INST(MIPS64_OP_LD, base, reg, off) +#define MIPS64_MFLO(reg) MIPS64_R_INST(0, 0, 0, reg, 0, MIPS64_OP_MFLO) +#define MIPS64_MFHI(reg) MIPS64_R_INST(0, 0, 0, reg, 0, MIPS64_OP_MFHI) +#define MIPS64_MTLO(reg) MIPS64_R_INST(0, reg, 0, 0, 0, MIPS64_OP_MTLO) +#define MIPS64_MTHI(reg) MIPS64_R_INST(0, reg, 0, 0, 0, MIPS64_OP_MTHI) +#define MIPS64_ORI(src, tar, val) MIPS64_I_INST(MIPS64_OP_ORI, src, tar, val) +#define MIPS64_SB(reg, off, base) MIPS64_I_INST(MIPS64_OP_SB, base, reg, off) +#define MIPS64_SH(reg, off, base) MIPS64_I_INST(MIPS64_OP_SH, base, reg, off) +#define MIPS64_SW(reg, off, base) MIPS64_I_INST(MIPS64_OP_SW, base, reg, off) +#define MIPS64_SD(reg, off, base) MIPS64_I_INST(MIPS64_OP_SD, base, reg, off) +#define MIPS64_CACHE(op, reg, off) (47 << 26 | (reg) << 21 | (op) << 16 | (off)) +#define MIPS64_SYNCI(reg, off) (1 << 26 | (reg) << 21 | 0x1f << 16 | (off)) + +/* ejtag specific instructions */ +#define MIPS64_DRET 0x4200001F +#define MIPS64_SDBBP 0x7000003F +#define MIPS64_SDBBP_LE 0x3f000007 +#define MIPS16_SDBBP 0xE801 + +#define MIPS64_SYNC 0x0000000F + +extern int mips64_arch_state(struct target *target); +extern int mips64_init_arch_info(struct target *target, mips64_common_t *mips64, struct jtag_tap *tap); +extern int mips64_restore_context(struct target *target); +extern int mips64_save_context(struct target *target); +extern struct reg_cache *mips64_build_reg_cache(struct target *target); +extern int mips64_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, + int num_reg_params, struct reg_param *reg_params, + uint32_t entry_point, uint32_t exit_point, + int timeout_ms, void *arch_info); +extern int mips64_configure_break_unit(struct target *target); +extern int mips64_enable_interrupts(struct target *target, int enable); +extern int mips64_examine(struct target *target); + +extern int mips64_register_commands(struct command_context *cmd_ctx); +extern int mips64_invalidate_core_regs(struct target *target); +extern int mips64_get_gdb_reg_list(struct target *target, + struct reg **reg_list[], int *reg_list_size, + enum target_register_class reg_class); + +#endif /*MIPS64_H*/ diff --git a/src/target/mips64_pracc.c b/src/target/mips64_pracc.c new file mode 100644 index 0000000..7e8b05d --- /dev/null +++ b/src/target/mips64_pracc.c @@ -0,0 +1,982 @@ +/*************************************************************************** + * Support for processors implementing MIPS64 instruction set * + * * + * Copyright (C) 2014 by Andrey Sidorov <[email protected]> * + * Copyright (C) 2014 by Aleksey Kuleshov <[email protected]> * + * Copyright (C) 2014 by Peter Mamonov <[email protected]> * + * * + * Based on the work of: * + * Copyright (C) 2008 by Spencer Oliver * + * Copyright (C) 2008 by David T.L. Wong * + * Copyright (C) 2010 by Konstantin Kostyukhin, Nikolay Shmyrev * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +/* +This version has optimized assembly routines for 32 bit operations: +- read word +- write word +- write array of words + +One thing to be aware of is that the MIPS64 cpu will execute the +instruction after a branch instruction (one delay slot). + +For example: + + + LW $2, ($5 +10) + B foo + LW $1, ($2 +100) + +The LW $1, ($2 +100) instruction is also executed. If this is +not wanted a NOP can be inserted: + + LW $2, ($5 +10) + B foo + NOP + LW $1, ($2 +100) + +or the code can be changed to: + + B foo + LW $2, ($5 +10) + LW $1, ($2 +100) + +The original code contained NOPs. I have removed these and moved +the branches. + +I also moved the PRACC_STACK to 0xFF204000. This allows +the use of 16 bits offsets to get pointers to the input +and output area relative to the stack. Note that the stack +isn't really a stack (the stack pointer is not 'moving') +but a FIFO simulated in software. + +These changes result in a 35% speed increase when programming an +external flash. + +More improvement could be gained if the registers do no need +to be preserved but in that case the routines should be aware +OpenOCD is used as a flash programmer or as a debug tool. + +Nico Coesel +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "mips64.h" +#include "mips64_pracc.h" + +#include "time_support.h" + +typedef struct { + uint64_t *local_iparam; + int num_iparam; + uint64_t *local_oparam; + int num_oparam; + uint32_t *code; + int code_len; + uint64_t stack[32]; + int stack_offset; + struct mips_ejtag *ejtag_info; +} mips64_pracc_context; + +static int wait_for_pracc_rw(struct mips_ejtag *ejtag_info, uint32_t *ctrl) +{ + uint32_t ejtag_ctrl; + + int nt = 5; + while (1) { + mips_ejtag_set_instr(ejtag_info, EJTAG_INST_CONTROL); + ejtag_ctrl = ejtag_info->ejtag_ctrl; + mips_ejtag_drscan_32(ejtag_info, &ejtag_ctrl); + + if (ejtag_ctrl & EJTAG_CTRL_PRACC) + break; + LOG_DEBUG("DEBUGMODULE: No memory access in progress!\n"); + if (nt == 0) + return ERROR_JTAG_DEVICE_ERROR; + nt--; + } + + *ctrl = ejtag_ctrl; + return ERROR_OK; +} + +static int mips64_pracc_exec_read(mips64_pracc_context *ctx, uint64_t address) +{ + struct mips_ejtag *ejtag_info = ctx->ejtag_info; + int offset; + uint32_t ejtag_ctrl; + uint64_t data; + static uint64_t prev_text_address = MIPS64_PRACC_TEXT; + + if ((address >= MIPS64_PRACC_PARAM_IN) + && (address <= MIPS64_PRACC_PARAM_IN + ctx->num_iparam * MIPS64_PRACC_DATA_STEP)) { + offset = (address - MIPS64_PRACC_PARAM_IN) / MIPS64_PRACC_DATA_STEP; + + if (offset >= MIPS64_PRACC_PARAM_IN_SIZE) { + printf("Error: iparam size exceeds MIPS64_PRACC_PARAM_IN_SIZE"); + return ERROR_JTAG_DEVICE_ERROR; + } + + if (ctx->local_iparam == NULL) { + printf("Error: unexpected reading of input parameter\n"); + return ERROR_JTAG_DEVICE_ERROR; + } + data = ctx->local_iparam[offset]; + LOG_DEBUG("Reading %llx at %llx\n", (unsigned long long) data, (unsigned long long) address); + + } else if ((address >= MIPS64_PRACC_PARAM_OUT) + && (address <= MIPS64_PRACC_PARAM_OUT + ctx->num_oparam * MIPS64_PRACC_DATA_STEP)) { + offset = (address - MIPS64_PRACC_PARAM_OUT) / MIPS64_PRACC_DATA_STEP; + if (ctx->local_oparam == NULL) { + printf("Error: unexpected reading of output parameter\n"); + return ERROR_JTAG_DEVICE_ERROR; + } + data = ctx->local_oparam[offset]; + LOG_DEBUG("Reading %llx at %llx\n", (unsigned long long) data, (unsigned long long) address); + } else if ((address >= MIPS64_PRACC_TEXT) + && (address <= MIPS64_PRACC_TEXT + ctx->code_len * MIPS64_PRACC_ADDR_STEP)) { + /* Check for correct text address incrementation */ + if ((address != MIPS64_PRACC_TEXT) && + (address != prev_text_address + MIPS64_PRACC_ADDR_STEP * 2)) { + LOG_DEBUG("Warning: probably reading unexpected text address or there was jump due to branch from %llx\n", + (unsigned long long) prev_text_address); + } + + offset = (address - MIPS64_PRACC_TEXT) / MIPS64_PRACC_ADDR_STEP; + + data = (uint64_t)ctx->code[offset] << (8 * (4 - (address & 7))); + + prev_text_address = address; + LOG_DEBUG("Running commands %llx at address %llx\n", + (unsigned long long) data, (unsigned long long) address); + } else if ((address & ~7llu) == MIPS64_PRACC_STACK) { + /* load from our debug stack */ + if (ctx->stack_offset == 0) { + printf("Error reading from stack: stack is empty\n"); + return ERROR_JTAG_DEVICE_ERROR; + } + data = ctx->stack[--ctx->stack_offset]; + LOG_DEBUG("Reading %llx at %llx\n", (unsigned long long) data, (unsigned long long) address); + } else { + /* TODO: send JMP 0xFF200000 instruction. Hopefully processor jump back + * to start of debug vector */ + + data = 0; + printf("Error reading unexpected address %llx\n", (unsigned long long) address); + return ERROR_JTAG_DEVICE_ERROR; + } + + /* Send the data out */ + mips_ejtag_set_instr(ctx->ejtag_info, EJTAG_INST_DATA); + mips_ejtag_drscan_64(ctx->ejtag_info, &data); + + /* Clear the access pending bit (let the processor eat!) */ + + ejtag_ctrl = ejtag_info->ejtag_ctrl & ~EJTAG_CTRL_PRACC; + mips_ejtag_set_instr(ctx->ejtag_info, EJTAG_INST_CONTROL); + mips_ejtag_drscan_32(ctx->ejtag_info, &ejtag_ctrl); + + jtag_add_clocks(5); + + jtag_execute_queue(); + + return ERROR_OK; +} + +static int mips64_pracc_exec_write(mips64_pracc_context *ctx, uint64_t address) +{ + uint32_t ejtag_ctrl; + uint64_t data; + int offset; + struct mips_ejtag *ejtag_info = ctx->ejtag_info; + + LOG_DEBUG("!"); + + mips_ejtag_set_instr(ctx->ejtag_info, EJTAG_INST_DATA); + mips_ejtag_drscan_64(ctx->ejtag_info, &data); + + /* Clear access pending bit */ + ejtag_ctrl = ejtag_info->ejtag_ctrl & ~EJTAG_CTRL_PRACC; + mips_ejtag_set_instr(ctx->ejtag_info, EJTAG_INST_CONTROL); + mips_ejtag_drscan_32(ctx->ejtag_info, &ejtag_ctrl); + + jtag_add_clocks(5); + jtag_execute_queue(); + + LOG_DEBUG("Writing %llx at %llx\n", (unsigned long long) data, (unsigned long long) address); + + if ((address >= MIPS64_PRACC_PARAM_IN) + && (address <= MIPS64_PRACC_PARAM_IN + ctx->num_iparam * MIPS64_PRACC_DATA_STEP)) { + offset = (address - MIPS64_PRACC_PARAM_IN) / MIPS64_PRACC_DATA_STEP; + if (ctx->local_iparam == NULL) { + printf("Error: unexpected writing of input parameter\n"); + return ERROR_JTAG_DEVICE_ERROR; + } + ctx->local_iparam[offset] = data; + } else if ((address >= MIPS64_PRACC_PARAM_OUT) + && (address <= MIPS64_PRACC_PARAM_OUT + ctx->num_oparam * MIPS64_PRACC_DATA_STEP)) { + offset = (address - MIPS64_PRACC_PARAM_OUT) / MIPS64_PRACC_DATA_STEP; + if (ctx->local_oparam == NULL) { + printf("Error: unexpected writing of output parameter\n"); + return ERROR_JTAG_DEVICE_ERROR; + } + ctx->local_oparam[offset] = data; + } else if ((address&~7llu) == MIPS64_PRACC_STACK) { + /* save data onto our stack */ + ctx->stack[ctx->stack_offset++] = data; + } else { + LOG_ERROR("Error writing unexpected address 0x%" PRIx64 "", address); + return ERROR_JTAG_DEVICE_ERROR; + } + + return ERROR_OK; +} + +int mips64_pracc_exec(struct mips_ejtag *ejtag_info, int code_len, uint32_t *code, + int num_param_in, uint64_t *param_in, int num_param_out, uint64_t *param_out, int cycle) +{ + uint32_t ejtag_ctrl; + uint64_t address, data; + mips64_pracc_context ctx; + int retval; + int pass = 0; + int first_time_call = 1; + int i; + + for (i = 0; i < code_len; i++) + LOG_DEBUG("%08x", code[i]); + + ctx.local_iparam = param_in; + ctx.local_oparam = param_out; + ctx.num_iparam = num_param_in; + ctx.num_oparam = num_param_out; + ctx.code = code; + ctx.code_len = code_len; + ctx.ejtag_info = ejtag_info; + ctx.stack_offset = 0; + + while (1) { + retval = wait_for_pracc_rw(ejtag_info, &ejtag_ctrl); + if (retval != ERROR_OK) { + printf("ERROR wait_for_pracc_rw\n"); + return retval; + } + address = data = 0; + + mips_ejtag_set_instr(ejtag_info, EJTAG_INST_ADDRESS); + mips_ejtag_drscan_32(ejtag_info, &address); + address |= 0xffffffffff200000ull; + LOG_DEBUG("-> %016llx", address); + + if (first_time_call && address != MIPS64_PRACC_TEXT) { + printf("Error reading address %llx (%x expected)\n", + (unsigned long long) address, MIPS64_PRACC_TEXT); + return ERROR_JTAG_DEVICE_ERROR; + } + + first_time_call = 0; + + /* Check for read or write */ + if (ejtag_ctrl & EJTAG_CTRL_PRNW) { + retval = mips64_pracc_exec_write(&ctx, address); + if (retval != ERROR_OK) { + printf("ERROR mips64_pracc_exec_write\n"); + return retval; + } + } else { + /* Check to see if its reading at the debug vector. The first pass through + * the module is always read at the vector, so the first one we allow. When + * the second read from the vector occurs we are done and just exit. */ + if ((address == MIPS64_PRACC_TEXT) && (pass++)) { + LOG_DEBUG("@MIPS64_PRACC_TEXT"); + break; + if (ejtag_info->after_reset) + ejtag_info->after_reset = 0; + else + break; + } + retval = mips64_pracc_exec_read(&ctx, address); + if (retval != ERROR_OK) { + printf("ERROR mips64_pracc_exec_read\n"); + return retval; + } + + } + + if (cycle == 0) + break; + } + + /* stack sanity check */ + if (ctx.stack_offset != 0) + LOG_DEBUG("Pracc Stack not zero"); + + return ERROR_OK; +} + +int mips64_pracc_read_mem(struct mips_ejtag *ejtag_info, uint64_t addr, int size, int count, void *buf) +{ + switch (size) { + case 1: + return mips64_pracc_read_mem8(ejtag_info, addr, count, buf); + case 2: + return mips64_pracc_read_mem16(ejtag_info, addr, count, buf); + case 4: + return mips64_pracc_read_mem32(ejtag_info, addr, count, buf); + case 8: + return mips64_pracc_read_mem64(ejtag_info, addr, count, buf); + } + return ERROR_FAIL; +} + +int mips64_pracc_read_mem64(struct mips_ejtag *ejtag_info, uint64_t addr, int count, uint64_t *buf) +{ + int i, retval; + for (i = 0; i < count; i++) { + retval = mips64_pracc_read_u64(ejtag_info, addr + 8*i, &buf[i]); + if (retval != ERROR_OK) + return retval; + } + return retval; +} + +int mips64_pracc_read_u64(struct mips_ejtag *ejtag_info, uint64_t addr, uint64_t *buf) +{ + uint32_t code[] = { + MIPS64_DMTC0(15, 31, 0), /* move $15 to COP0 DeSave */ + MIPS64_LUI(15, UPPER16(MIPS64_PRACC_STACK)), /* $15 = MIPS64_PRACC_STACK */ + MIPS64_ORI(15, 15, LOWER16(MIPS64_PRACC_STACK)), + MIPS64_SD(8, 0, 15), /* sd $8, ($15) */ + MIPS64_LD(8, NEG16(MIPS64_PRACC_STACK-MIPS64_PRACC_PARAM_IN), 15), /* load R8 @ param_in[0] = address */ + MIPS64_LD(8, 0, 8), /* ld $8, 0($8), Load $8 with the word @mem[$8] */ + MIPS64_SD(8, NEG16(MIPS64_PRACC_STACK-MIPS64_PRACC_PARAM_OUT), 15), /* sd $8, 0($15) */ + MIPS64_LD(8, 0, 15), /* ld $8, ($15) */ + MIPS64_SYNC, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_B(NEG16(18)), /* b start */ + MIPS64_DMFC0(15, 31, 0), /* move COP0 DeSave to $15 */ + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + }; + + uint64_t param_in[1]; + param_in[0] = addr; + + return mips64_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, + ARRAY_SIZE(param_in), param_in, 1, (uint64_t *) buf, 1); +} + +int mips64_pracc_read_mem32(struct mips_ejtag *ejtag_info, uint64_t addr, int count, uint32_t *buf) +{ + int i, retval; + for (i = 0; i < count; i++) { + retval = mips64_pracc_read_u32(ejtag_info, addr + 4 * i, &buf[i]); + if (retval != ERROR_OK) + return retval; + } + return retval; +} + +int mips64_pracc_read_u32(struct mips_ejtag *ejtag_info, uint64_t addr, uint32_t *buf) +{ + uint32_t code[] = { + MIPS64_DMTC0(15, 31, 0), /* move $15 to COP0 DeSave */ + MIPS64_LUI(15, UPPER16(MIPS64_PRACC_STACK)), /* $15 = MIPS64_PRACC_STACK */ + MIPS64_ORI(15, 15, LOWER16(MIPS64_PRACC_STACK)), + MIPS64_SD(8, 0, 15), /* sd $8, ($15) */ + MIPS64_LD(8, NEG16(MIPS64_PRACC_STACK-MIPS64_PRACC_PARAM_IN), 15), /* load R8 @ param_in[0] = address */ + MIPS64_LW(8, 0, 8), /* lw $8, 0($8), Load $8 with the word @mem[$8] */ + MIPS64_SD(8, NEG16(MIPS64_PRACC_STACK-MIPS64_PRACC_PARAM_OUT), 15), /* sd $8, 0($9) */ + MIPS64_LD(8, 0, 15), /* ld $8, ($15) */ + MIPS64_SYNC, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_B(NEG16(17)), /* b start */ + MIPS64_DMFC0(15, 31, 0), /* move COP0 DeSave to $15 */ + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + }; + + int retval = ERROR_OK; + uint64_t param_in[1]; + uint64_t param_out[1]; + + param_in[0] = addr; + + retval = mips64_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, + 1, param_in, 1, param_out, 1); + buf[0] = (uint32_t) param_out[0]; + return retval; +} + +int mips64_pracc_read_mem16(struct mips_ejtag *ejtag_info, uint64_t addr, int count, uint16_t *buf) +{ + int i, retval; + for (i = 0; i < count; i++) { + retval = mips64_pracc_read_u16(ejtag_info, addr + 2*i, &buf[i]); + if (retval != ERROR_OK) + return retval; + } + return retval; +} + +int mips64_pracc_read_u16(struct mips_ejtag *ejtag_info, uint64_t addr, uint16_t *buf) +{ + uint32_t code[] = { + MIPS64_DMTC0(15, 31, 0), /* move $15 to COP0 DeSave */ + MIPS64_LUI(15, UPPER16(MIPS64_PRACC_STACK)), /* $15 = MIPS64_PRACC_STACK */ + MIPS64_ORI(15, 15, LOWER16(MIPS64_PRACC_STACK)), + MIPS64_SD(8, 0, 15), /* sd $8, ($15) */ + MIPS64_LD(8, NEG16(MIPS64_PRACC_STACK-MIPS64_PRACC_PARAM_IN), 15), /* load R8 @ param_in[0] = address */ + MIPS64_LHU(8, 0, 8), /* lw $8, 0($8), Load $8 with the word @mem[$8] */ + MIPS64_SD(8, NEG16(MIPS64_PRACC_STACK-MIPS64_PRACC_PARAM_OUT), 15), /* sd $8, 0($9) */ + MIPS64_LD(8, 0, 15), /* ld $8, ($15) */ + MIPS64_SYNC, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_B(NEG16(17)), /* b start */ + MIPS64_DMFC0(15, 31, 0), /* move COP0 DeSave to $15 */ + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + }; + + int retval; + uint64_t param_in[1]; + uint64_t param_out[1]; + + param_in[0] = addr; + + retval = mips64_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, + 1, param_in, 1, param_out, 1); + buf[0] = (uint16_t)param_out[0]; + return retval; +} + +int mips64_pracc_read_mem8(struct mips_ejtag *ejtag_info, uint64_t addr, int count, uint8_t *buf) +{ + int i, retval; + for (i = 0; i < count; i++) { + retval = mips64_pracc_read_u8(ejtag_info, addr + i, &buf[i]); + if (retval != ERROR_OK) + return retval; + } + return retval; +} + +int mips64_pracc_read_u8(struct mips_ejtag *ejtag_info, uint64_t addr, uint8_t *buf) +{ + uint32_t code[] = { + MIPS64_DMTC0(15, 31, 0), /* move $15 to COP0 DeSave */ + MIPS64_LUI(15, UPPER16(MIPS64_PRACC_STACK)), /* $15 = MIPS64_PRACC_STACK */ + MIPS64_ORI(15, 15, LOWER16(MIPS64_PRACC_STACK)), + MIPS64_SD(8, 0, 15), /* sd $8, ($15) */ + MIPS64_LD(8, NEG16(MIPS64_PRACC_STACK-MIPS64_PRACC_PARAM_IN), 15), /* load R8 @ param_in[0] = address */ + MIPS64_LBU(8, 0, 8), /* lw $8, 0($8), Load $8 with the word @mem[$8] */ + MIPS64_SD(8, NEG16(MIPS64_PRACC_STACK-MIPS64_PRACC_PARAM_OUT), 15), /* sd $8, 0($9) */ + MIPS64_LD(8, 0, 15), /* ld $8, ($15) */ + MIPS64_SYNC, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_B(NEG16(17)), /* b start */ + MIPS64_DMFC0(15, 31, 0), /* move COP0 DeSave to $15 */ + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + }; + + int retval; + uint64_t param_in[1]; + uint64_t param_out[1]; + + param_in[0] = addr; + + retval = mips64_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, + 1, param_in, 1, param_out, 1); + buf[0] = (uint8_t)param_out[0]; + return retval; +} + +int mips64_pracc_write_mem(struct mips_ejtag *ejtag_info, uint64_t addr, int size, int count, void *buf) +{ + switch (size) { + case 1: + return mips64_pracc_write_mem8(ejtag_info, addr, count, buf); + case 2: + return mips64_pracc_write_mem16(ejtag_info, addr, count, buf); + case 4: + return mips64_pracc_write_mem32(ejtag_info, addr, count, buf); + case 8: + return mips64_pracc_write_mem64(ejtag_info, addr, count, buf); + } + return ERROR_FAIL; +} + +int mips64_pracc_write_mem64(struct mips_ejtag *ejtag_info, uint64_t addr, int count, uint64_t *buf) +{ + int i, retval; + + for (i = 0; i < count; i++) { + retval = mips64_pracc_write_u64(ejtag_info, addr + 8*i, &buf[i]); + if (retval != ERROR_OK) + return retval; + } + return retval; +} + +int mips64_pracc_write_u64(struct mips_ejtag *ejtag_info, uint64_t addr, uint64_t *buf) +{ + uint32_t code[] = { + /* start: */ + MIPS64_DMTC0(15, 31, 0), /* move $15 to COP0 DeSave */ + MIPS64_LUI(15, UPPER16(MIPS64_PRACC_STACK)), /* $15 = MIPS64_PRACC_STACK */ + MIPS64_ORI(15, 15, LOWER16(MIPS64_PRACC_STACK)), + MIPS64_SD(8, 0, 15), /* sd $8, ($15) */ + MIPS64_SD(9, 0, 15), /* sd $9, ($15) */ + + MIPS64_LD(8, NEG16((MIPS64_PRACC_STACK-MIPS64_PRACC_PARAM_IN)-8), 15), /* load R8 @ param_in[1] = data */ + MIPS64_LD(9, NEG16(MIPS64_PRACC_STACK-MIPS64_PRACC_PARAM_IN), 15), /* load R9 @ param_in[0] = address */ + MIPS64_SD(8, 0, 9), /* sd $8, 0($9) */ + MIPS64_SYNC, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_SYNCI(9, 0), + MIPS64_NOP, + MIPS64_NOP, + + MIPS64_LD(9, 0, 15), /* ld $9, ($15) */ + MIPS64_LD(8, 0, 15), /* ld $8, ($15) */ + MIPS64_SYNC, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_B(NEG16(26)), /* b start */ + MIPS64_DMFC0(15, 31, 0), /* move COP0 DeSave to $15 */ + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + }; + + /* TODO remove array */ + uint64_t param_in[2]; + param_in[0] = addr; + param_in[1] = *buf; + + return mips64_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, + ARRAY_SIZE(param_in), param_in, 0, NULL, 1); +} + +int mips64_pracc_write_mem32(struct mips_ejtag *ejtag_info, uint64_t addr, int count, uint32_t *buf) +{ + int i, retval; + + for (i = 0; i < count; i++) { + retval = mips64_pracc_write_u32(ejtag_info, addr + 4*i, &buf[i]); + if (retval != ERROR_OK) + return retval; + } + return retval; +} + +int mips64_pracc_write_u32(struct mips_ejtag *ejtag_info, uint64_t addr, uint32_t *buf) +{ + uint32_t code[] = { + /* start: */ + MIPS64_DMTC0(15, 31, 0), /* move $15 to COP0 DeSave */ + MIPS64_LUI(15, UPPER16(MIPS64_PRACC_STACK)), /* $15 = MIPS64_PRACC_STACK */ + MIPS64_ORI(15, 15, LOWER16(MIPS64_PRACC_STACK)), + MIPS64_SD(8, 0, 15), /* sd $8, ($15) */ + MIPS64_SD(9, 0, 15), /* sd $9, ($15) */ + MIPS64_LD(8, NEG16((MIPS64_PRACC_STACK-MIPS64_PRACC_PARAM_IN)-8), 15), /* load R8 @ param_in[1] = data */ + MIPS64_LD(9, NEG16(MIPS64_PRACC_STACK-MIPS64_PRACC_PARAM_IN), 15), /* load R9 @ param_in[0] = address */ + MIPS64_SW(8, 0, 9), /* sw $8, 0($9) */ + MIPS64_SYNC, + MIPS64_NOP, + MIPS64_NOP, + /*MIPS64_CACHE(1 << 3 | 5, 9, 0), /* D cache Hit invalidate */ + /*MIPS64_CACHE(3 << 3 | 5, 9, 0), /* L2 cache Hit invalidate */ + /*MIPS64_CACHE(2 << 3 | 5, 9, 0), /* L3 cache Hit invalidate */ + /*MIPS64_CACHE(0 << 3 | 4, 9, 0), /* I cache fill */ + MIPS64_SYNCI(9, 0), + MIPS64_NOP, + MIPS64_NOP, + MIPS64_LD(9, 0, 15), /* ld $9, ($15) */ + MIPS64_LD(8, 0, 15), /* ld $8, ($15) */ + MIPS64_SYNC, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_B(NEG16(20)), /* b start */ + MIPS64_DMFC0(15, 31, 0), /* move COP0 DeSave to $15 */ + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + }; + + /* TODO remove array */ + uint64_t param_in[1 + 1]; + param_in[0] = addr; + param_in[1] = *buf; + + return mips64_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, + ARRAY_SIZE(param_in), param_in, 0, NULL, 1); +} + +int mips64_pracc_write_mem16(struct mips_ejtag *ejtag_info, uint64_t addr, int count, uint16_t *buf) +{ + int i, retval; + + for (i = 0; i < count; i++) { + retval = mips64_pracc_write_u16(ejtag_info, addr + 2*i, &buf[i]); + if (retval != ERROR_OK) + return retval; + } + return retval; +} + +int mips64_pracc_write_u16(struct mips_ejtag *ejtag_info, uint64_t addr, uint16_t *buf) +{ + uint32_t code[] = { + MIPS64_DMTC0(15, 31, 0), /* move $15 to COP0 DeSave */ + MIPS64_LUI(15, UPPER16(MIPS64_PRACC_STACK)), /* $15 = MIPS64_PRACC_STACK */ + MIPS64_ORI(15, 15, LOWER16(MIPS64_PRACC_STACK)), + MIPS64_SD(8, 0, 15), /* sd $8, ($15) */ + MIPS64_SD(9, 0, 15), /* sd $9, ($15) */ + MIPS64_LD(8, NEG16((MIPS64_PRACC_STACK-MIPS64_PRACC_PARAM_IN)-8), 15), /* load R8 @ param_in[1] = data */ + MIPS64_LD(9, NEG16(MIPS64_PRACC_STACK-MIPS64_PRACC_PARAM_IN), 15), /* load R9 @ param_in[0] = address */ + MIPS64_SH(8, 0, 9), /* sh $8, 0($9) */ + + MIPS64_LD(9, 0, 15), /* ld $9, ($15) */ + MIPS64_LD(8, 0, 15), /* ld $8, ($15) */ + MIPS64_SYNC, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_B(NEG16(14)), /* b start */ + MIPS64_DMFC0(15, 31, 0), /* move COP0 DeSave to $15 */ + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + }; + + uint64_t param_in[2]; + param_in[0] = addr; + param_in[1] = *buf; + + return mips64_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, + ARRAY_SIZE(param_in), param_in, 0, NULL, 1); +} + +int mips64_pracc_write_mem8(struct mips_ejtag *ejtag_info, uint64_t addr, int count, uint8_t *buf) +{ + int i, retval; + + for (i = 0; i < count; i++) { + retval = mips64_pracc_write_u8(ejtag_info, addr + i, &buf[i]); + if (retval != ERROR_OK) + return retval; + } + return retval; +} + +int mips64_pracc_write_u8(struct mips_ejtag *ejtag_info, uint64_t addr, uint8_t *buf) +{ + uint32_t code[] = { + MIPS64_DMTC0(15, 31, 0), /* move $15 to COP0 DeSave */ + MIPS64_LUI(15, UPPER16(MIPS64_PRACC_STACK)), /* $15 = MIPS64_PRACC_STACK */ + MIPS64_ORI(15, 15, LOWER16(MIPS64_PRACC_STACK)), + MIPS64_SD(8, 0, 15), /* sd $8, ($15) */ + MIPS64_SD(9, 0, 15), /* sd $9, ($15) */ + MIPS64_LD(8, NEG16((MIPS64_PRACC_STACK-MIPS64_PRACC_PARAM_IN)-8), 15), /* load R8 @ param_in[1] = data */ + MIPS64_LD(9, NEG16(MIPS64_PRACC_STACK-MIPS64_PRACC_PARAM_IN), 15), /* load R9 @ param_in[0] = address */ + MIPS64_SB(8, 0, 9), /* sh $8, 0($9) */ + + MIPS64_LD(9, 0, 15), /* ld $9, ($15) */ + MIPS64_LD(8, 0, 15), /* ld $8, ($15) */ + MIPS64_SYNC, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_B(NEG16(14)), /* b start */ + MIPS64_DMFC0(15, 31, 0), /* move COP0 DeSave to $15 */ + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + }; + + /* TODO remove array */ + uint64_t param_in[2]; + param_in[0] = addr; + param_in[1] = *buf; + + return mips64_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, + ARRAY_SIZE(param_in), param_in, 0, NULL, 1); +} + +int mips64_pracc_write_regs(struct mips_ejtag *ejtag_info, uint64_t *regs) +{ + uint32_t code[] = { + MIPS64_DMTC0(2, 31, 0), /* move $2 to COP0 DeSave */ + MIPS64_LUI(2, UPPER16(MIPS64_PRACC_PARAM_IN)), /* $15 = MIPS64_PRACC_STACK */ + MIPS64_ORI(2, 2, LOWER16(MIPS64_PRACC_PARAM_IN)), + MIPS64_LD(1, 1*8, 2), /* sd $0, 0*8($2) */ + MIPS64_LD(15, 15*8, 2), /* sd $1, 1*8($2) */ + MIPS64_DMFC0(2, 31, 0), /* sd $11, ($15) */ + MIPS64_DMTC0(15, 31, 0), + MIPS64_LUI(15, UPPER16(MIPS64_PRACC_STACK)), + + MIPS64_ORI(15, 15, LOWER16(MIPS64_PRACC_STACK)), + MIPS64_SD(1, 0, 15), + MIPS64_LUI(1, UPPER16(MIPS64_PRACC_PARAM_IN)), /* $11 = MIPS64_PRACC_PARAM_OUT */ + MIPS64_ORI(1, 1, LOWER16(MIPS64_PRACC_PARAM_IN)), + MIPS64_LD(3, 3*8, 1), + MIPS64_LD(4, 4*8, 1), + MIPS64_LD(5, 5*8, 1), + MIPS64_LD(6, 6*8, 1), + + MIPS64_LD(7, 7*8, 1), + MIPS64_LD(8, 8*8, 1), + MIPS64_LD(9, 9*8, 1), + MIPS64_LD(10, 10*8, 1), + MIPS64_LD(11, 11*8, 1), + MIPS64_LD(12, 12*8, 1), + MIPS64_LD(13, 13*8, 1), + MIPS64_LD(14, 14*8, 1), + + MIPS64_LD(16, 16*8, 1), + MIPS64_LD(17, 17*8, 1), + MIPS64_LD(18, 18*8, 1), + MIPS64_LD(19, 19*8, 1), + MIPS64_LD(20, 20*8, 1), + MIPS64_LD(21, 21*8, 1), + MIPS64_LD(22, 22*8, 1), + MIPS64_LD(23, 23*8, 1), + + MIPS64_LD(24, 24*8, 1), + MIPS64_LD(25, 25*8, 1), + MIPS64_LD(26, 26*8, 1), + MIPS64_LD(27, 27*8, 1), + MIPS64_LD(28, 28*8, 1), + MIPS64_LD(29, 29*8, 1), + MIPS64_LD(30, 30*8, 1), + MIPS64_LD(31, 31*8, 1), + + MIPS64_LD(2, 32*8, 1), + MIPS64_DMTC0(2, 12, 0), + MIPS64_LD(2, 33*8, 1), + MIPS64_MTLO(2), + MIPS64_LD(2, 34*8, 1), + MIPS64_MTHI(2), + MIPS64_LD(2, 35*8, 1), + MIPS64_DMTC0(2, 8, 0), + + MIPS64_LD(2, 36*8, 1), + MIPS64_DMTC0(2, 13, 0), + MIPS64_LD(2, 37*8, 1), + MIPS64_DMTC0(2, 24, 0), + MIPS64_LD(2, 2*8, 1), + MIPS64_LD(1, 0, 15), + MIPS64_NOP, + MIPS64_SYNC, + + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_B(NEG16(65)), /* b start */ + MIPS64_DMFC0(15, 31, 0), /* move COP0 DeSave to $15 */ + + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP + }; + + return mips64_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, + MIPS64NUMCOREREGS, regs, 0, NULL, 1); +} + +int mips64_pracc_read_regs(struct mips_ejtag *ejtag_info, uint64_t *regs) +{ + LOG_DEBUG("!"); + uint32_t code[] = { + /* start: */ + MIPS64_DMTC0(2, 31, 0), /* move $2 to COP0 DeSave */ + MIPS64_LUI(2, UPPER16(MIPS64_PRACC_PARAM_OUT)), /* $2 = MIPS64_PRACC_PARAM_OUT */ + MIPS64_ORI(2, 2, LOWER16(MIPS64_PRACC_PARAM_OUT)), + MIPS64_SD(0, 0*8, 2), /* sd $0, 0*8($2) */ + MIPS64_SD(1, 1*8, 2), /* sd $1, 1*8($2) */ + MIPS64_SD(15, 15*8, 2), /* sd $15, 15*8($2) */ + MIPS64_DMFC0(2, 31, 0), /* move COP0 DeSave to $2 */ + MIPS64_DMTC0(15, 31, 0), /* move $15 to COP0 DeSave */ + + MIPS64_LUI(15, UPPER16(MIPS64_PRACC_STACK)), /* $15 = MIPS64_PRACC_STACK */ + MIPS64_ORI(15, 15, LOWER16(MIPS64_PRACC_STACK)), + MIPS64_SD(1, 0, 15), /* sd $1, ($15) */ + MIPS64_SD(2, 0, 15), /* sd $2, ($15) */ + MIPS64_LUI(1, UPPER16(MIPS64_PRACC_PARAM_OUT)), /* $1 = MIPS64_PRACC_PARAM_OUT */ + MIPS64_ORI(1, 1, LOWER16(MIPS64_PRACC_PARAM_OUT)), + MIPS64_SD(2, 2*8, 1), /* sd $2, 2*8($1) */ + MIPS64_SD(3, 3*8, 1), /* sd $3, 3*8($1) */ + + MIPS64_SD(4, 4*8, 1), /* sd $4, 4*8($1) */ + MIPS64_SD(5, 5*8, 1), /* sd $5, 5*8($1) */ + MIPS64_SD(6, 6*8, 1), /* sd $6, 6*8($1) */ + MIPS64_SD(7, 7*8, 1), /* sd $7, 7*8($1) */ + MIPS64_SD(8, 8*8, 1), /* sd $8, 8*8($1) */ + MIPS64_SD(9, 9*8, 1), /* sd $9, 9*8($1) */ + MIPS64_SD(10, 10*8, 1), /* sd $10, 10*8($1) */ + MIPS64_SD(11, 11*8, 1), /* sd $11, 11*8($1) */ + + MIPS64_SD(12, 12*8, 1), /* sd $12, 12*8($1) */ + MIPS64_SD(13, 13*8, 1), /* sd $13, 13*8($1) */ + MIPS64_SD(14, 14*8, 1), /* sd $14, 14*8($1) */ + MIPS64_SD(16, 16*8, 1), /* sd $16, 16*8($1) */ + MIPS64_SD(17, 17*8, 1), /* sd $17, 17*8($1) */ + MIPS64_SD(18, 18*8, 1), /* sd $18, 18*8($1) */ + MIPS64_SD(19, 19*8, 1), /* sd $19, 19*8($1) */ + MIPS64_SD(20, 20*8, 1), /* sd $20, 20*8($1) */ + + MIPS64_SD(21, 21*8, 1), /* sd $21, 21*8($1) */ + MIPS64_SD(22, 22*8, 1), /* sd $22, 22*8($1) */ + MIPS64_SD(23, 23*8, 1), /* sd $23, 23*8($1) */ + MIPS64_SD(24, 24*8, 1), /* sd $24, 24*8($1) */ + MIPS64_SD(25, 25*8, 1), /* sd $25, 25*8($1) */ + MIPS64_SD(26, 26*8, 1), /* sd $26, 26*8($1) */ + MIPS64_SD(27, 27*8, 1), /* sd $27, 27*8($1) */ + MIPS64_SD(28, 28*8, 1), /* sd $28, 28*8($1) */ + MIPS64_SD(29, 29*8, 1), /* sd $29, 29*8($1) */ + MIPS64_SD(30, 30*8, 1), /* sd $30, 30*8($1) */ + MIPS64_SD(31, 31*8, 1), /* sd $31, 31*8($1) */ + + MIPS64_DMFC0(2, 12, 0), /* (32)cpu.cpu_core.cop0.status_reg */ + MIPS64_SD(2, 32*8, 1), + MIPS64_MFLO(2), /* (33)cpu.int_mult_div.lo_reg */ + MIPS64_SD(2, 33*8, 1), + MIPS64_MFHI(2), /* (34)cpu.int_mul_div.hi_reg */ + + MIPS64_SD(2, 34*8, 1), + MIPS64_DMFC0(2, 8, 0), /* (35)cpu.cpu_core.cop0.BadVAddr */ + MIPS64_SD(2, 35*8, 1), + MIPS64_DMFC0(2, 13, 0), /* (36)cpu.cpu_core.cop0.cause */ + MIPS64_SD(2, 36*8, 1), + MIPS64_DMFC0(2, 24, 0), /* (37)cpu.cpu_core.cop0.DEPC */ + MIPS64_SD(2, 37*8, 1), + MIPS64_LD(2, 0, 15), + + MIPS64_LD(1, 0, 15), + MIPS64_SYNC, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_B(NEG16(67)), /* b start */ + MIPS64_DMFC0(15, 31, 0), /* move COP0 DeSave to $15 */ + + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP +}; + + return mips64_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, + 0, NULL, MIPS64NUMCOREREGS, regs, 1); +} diff --git a/src/target/mips64_pracc.h b/src/target/mips64_pracc.h new file mode 100644 index 0000000..14a9361 --- /dev/null +++ b/src/target/mips64_pracc.h @@ -0,0 +1,74 @@ +/*************************************************************************** + * Support for processors implementing MIPS64 instruction set * + * * + * Copyright (C) 2014 by Andrey Sidorov <[email protected]> * + * Copyright (C) 2014 by Aleksey Kuleshov <[email protected]> * + * Copyright (C) 2014 by Peter Mamonov <[email protected]> * + * * + * Based on the work of: * + * Copyright (C) 2008 by Spencer Oliver * + * Copyright (C) 2008 by David T.L. Wong * + * Copyright (C) 2010 by Konstantin Kostyukhin, Nikolay Shmyrev * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ +#ifndef MIPS64_PRACC_H +#define MIPS64_PRACC_H + +#include "mips_ejtag.h" + +#define MIPS64_PRACC_TEXT 0xffffffffFF200200ull + +#define MIPS64_PRACC_STACK 0xffffffffFF204000ull +#define MIPS64_PRACC_PARAM_IN 0xffffffffFF201000ull +#define MIPS64_PRACC_PARAM_IN_SIZE 0x1000 +#define MIPS64_PRACC_PARAM_OUT (MIPS64_PRACC_PARAM_IN + MIPS64_PRACC_PARAM_IN_SIZE) +#define MIPS64_PRACC_PARAM_OUT_SIZE 0x1000 + +#define UPPER16(uint32_t) ((uint32_t >> 16) & 0xFFFF) +#define LOWER16(uint32_t) (uint32_t & 0xFFFF) + +/* FIXME: 16-bit NEG */ +#define NEG16(v) (((~(v)) + 1) & 0xFFFF) + +#define MIPS64_PRACC_ADDR_STEP 4 +#define MIPS64_PRACC_DATA_STEP 8 + +extern int mips64_pracc_read_mem(struct mips_ejtag *ejtag_info, uint64_t addr, int size, int count, void *buf); +extern int mips64_pracc_write_mem(struct mips_ejtag *ejtag_info, uint64_t addr, int size, int count, void *buf); + +extern int mips64_pracc_read_mem8(struct mips_ejtag *ejtag_info, uint64_t addr, int count, uint8_t *buf); +extern int mips64_pracc_read_u8(struct mips_ejtag *ejtag_info, uint64_t addr, uint8_t *buf); +extern int mips64_pracc_read_mem16(struct mips_ejtag *ejtag_info, uint64_t addr, int count, uint16_t *buf); +extern int mips64_pracc_read_u16(struct mips_ejtag *ejtag_info, uint64_t addr, uint16_t *buf); +extern int mips64_pracc_read_mem32(struct mips_ejtag *ejtag_info, uint64_t addr, int count, uint32_t *buf); +extern int mips64_pracc_read_u32(struct mips_ejtag *ejtag_info, uint64_t addr, uint32_t *buf); +extern int mips64_pracc_read_mem64(struct mips_ejtag *ejtag_info, uint64_t addr, int count, uint64_t *buf); +extern int mips64_pracc_read_u64(struct mips_ejtag *ejtag_info, uint64_t addr, uint64_t *buf); + +extern int mips64_pracc_write_mem8(struct mips_ejtag *ejtag_info, uint64_t addr, int count, uint8_t *buf); +extern int mips64_pracc_write_u8(struct mips_ejtag *ejtag_info, uint64_t addr, uint8_t *buf); +extern int mips64_pracc_write_mem16(struct mips_ejtag *ejtag_info, uint64_t addr, int count, uint16_t *buf); +extern int mips64_pracc_write_u16(struct mips_ejtag *ejtag_info, uint64_t addr, uint16_t *buf); +extern int mips64_pracc_write_mem32(struct mips_ejtag *ejtag_info, uint64_t addr, int count, uint32_t *buf); +extern int mips64_pracc_write_u32(struct mips_ejtag *ejtag_info, uint64_t addr, uint32_t *buf); +extern int mips64_pracc_write_mem64(struct mips_ejtag *ejtag_info, uint64_t addr, int count, uint64_t *buf); +extern int mips64_pracc_write_u64(struct mips_ejtag *ejtag_info, uint64_t addr, uint64_t *buf); + +extern int mips64_pracc_read_regs(struct mips_ejtag *ejtag_info, uint64_t *regs); +extern int mips64_pracc_write_regs(struct mips_ejtag *ejtag_info, uint64_t *regs); + +extern int mips64_pracc_exec(struct mips_ejtag *ejtag_info, int code_len, uint32_t *code, + int num_param_in, uint64_t *param_in, int num_param_out, uint64_t *param_out, int cycle); +#endif diff --git a/src/target/mips_ejtag.c b/src/target/mips_ejtag.c index c24cea3..a03be30 100644 --- a/src/target/mips_ejtag.c +++ b/src/target/mips_ejtag.c @@ -6,6 +6,12 @@ * * * Copyright (C) 2009 by David N. Claffey <[email protected]> * * * + * Copyright (C) 2010 by Konstantin Kostyukhin, Nikolay Shmyrev * + * * + * Copyright (C) 2014 by Andrey Sidorov <[email protected]> * + * Copyright (C) 2014 by Aleksey Kuleshov <[email protected]> * + * Copyright (C) 2014 by Peter Mamonov <[email protected]> * + * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * @@ -27,6 +33,7 @@ #endif #include "mips32.h" +#include "mips64.h" #include "mips_ejtag.h" #include "mips32_dmaacc.h" @@ -123,6 +130,87 @@ void mips_ejtag_add_scan_96(struct mips_ejtag *ejtag_info, uint32_t ctrl, uint32 keep_alive(); } +int mips_ejtag_drscan_64(struct mips_ejtag *ejtag_info, uint64_t *data) +{ + struct jtag_tap *tap; + tap = ejtag_info->tap; + + if (tap == NULL) + return ERROR_FAIL; + struct scan_field field; + uint8_t t[8], r[8]; + int retval; + + field.num_bits = 64; + field.out_value = t; + buf_set_u64(t, 0, field.num_bits, *data); + field.in_value = r; + + jtag_add_dr_scan(tap, 1, &field, TAP_IDLE); + retval = jtag_execute_queue(); + if (retval != ERROR_OK) { + LOG_ERROR("register read failed"); + return retval; + } + + *data = buf_get_u64(field.in_value, 0, 64); + + keep_alive(); + + return ERROR_OK; +} + +int mips_ejtag_drscan_36(struct mips_ejtag *ejtag_info, uint64_t *data) +{ + struct jtag_tap *tap; + tap = ejtag_info->tap; + + if (tap == NULL) + return ERROR_FAIL; + struct scan_field field; + uint8_t t[8], r[8]; + int retval; + + field.num_bits = 36; + field.out_value = t; + buf_set_u64(t, 0, field.num_bits, *data); + field.in_value = r; + + jtag_add_dr_scan(tap, 1, &field, TAP_IDLE); + + retval = jtag_execute_queue(); + if (retval != ERROR_OK) { + LOG_ERROR("register read failed"); + return retval; + } + + *data = buf_get_u64(field.in_value, 0, 64); + + *data |= 0xfffffff000000000; + + keep_alive(); + + return ERROR_OK; +} + +void mips_ejtag_drscan_64_out(struct mips_ejtag *ejtag_info, uint64_t data) +{ + uint8_t t[8]; + struct jtag_tap *tap; + tap = ejtag_info->tap; + assert(tap != NULL); + + struct scan_field field; + + field.num_bits = 64; + field.out_value = t; + buf_set_u64(t, 0, field.num_bits, data); + + field.in_value = NULL; + + jtag_add_dr_scan(tap, 1, &field, TAP_IDLE); +} + int mips_ejtag_drscan_32(struct mips_ejtag *ejtag_info, uint32_t *data) { struct jtag_tap *tap; @@ -217,6 +305,76 @@ void mips_ejtag_drscan_8_out(struct mips_ejtag *ejtag_info, uint8_t data) /* Set (to enable) or clear (to disable stepping) the SSt bit (bit 8) in Cp0 Debug reg (reg 23, sel 0) */ int mips_ejtag_config_step(struct mips_ejtag *ejtag_info, int enable_step) { + /* MIPS64 */ + if (ejtag_info->impcode & 1) { + uint32_t code_enable[] = { + MIPS64_MTC0(1, 31, 0), /* move $1 to COP0 DeSave */ + MIPS64_MFC0(1, 23, 0), /* move COP0 Debug to $1 */ + MIPS64_ORI(1, 1, 0x0100), /* set SSt bit in debug reg */ + MIPS64_MTC0(1, 23, 0), /* move $1 to COP0 Debug */ + MIPS64_MFC0(1, 31, 0), /* move COP0 DeSave to $1 */ + MIPS64_SYNC, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_B(NEG16(15)), + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + }; + + uint32_t code_disable[] = { + MIPS64_MTC0(15, 31, 0), /* move $15 to COP0 DeSave */ + MIPS64_LUI(15, UPPER16(MIPS64_PRACC_STACK)), /* $15 = MIPS64_PRACC_STACK */ + MIPS64_ORI(15, 15, LOWER16(MIPS64_PRACC_STACK)), + MIPS64_SD(1, 0, 15), /* sw $1,($15) */ + MIPS64_SD(2, 0, 15), /* sw $2,($15) */ + MIPS64_MFC0(1, 23, 0), /* move COP0 Debug to $1 */ + MIPS64_LUI(2, 0xFFFF), /* $2 = 0xfffffeff */ + MIPS64_ORI(2, 2, 0xFEFF), + MIPS64_AND(1, 1, 2), + MIPS64_MTC0(1, 23, 0), /* move $1 to COP0 Debug */ + MIPS64_LD(2, 0, 15), + MIPS64_LD(1, 0, 15), + MIPS64_NOP, + MIPS64_SYNC, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_B(NEG16(23)), + MIPS64_MFC0(15, 31, 0), /* move COP0 DeSave to $15 */ + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + }; + uint32_t *code = enable_step ? code_enable : code_disable; + mips64_pracc_exec(ejtag_info,\ + enable_step ? ARRAY_SIZE(code_enable) : ARRAY_SIZE(code_disable),\ + code,\ + 0, NULL, 0, NULL, 1); + return ERROR_OK; + } + struct pracc_queue_info ctx = {.max_code = 7}; pracc_queue_init(&ctx); if (ctx.retval != ERROR_OK) @@ -248,6 +406,43 @@ static int disable_dcr_mp(struct mips_ejtag *ejtag_info) { uint32_t dcr; int retval; + /* MIPS64 */ + if (ejtag_info->impcode & 1) { + uint32_t code[] = { + MIPS64_MTC0(15, 31, 0), /* move $15 to COP0 DeSave */ + MIPS64_LUI(15, UPPER16(MIPS64_PRACC_STACK)), /* $15 = MIPS64_PRACC_STACK */ + MIPS64_ORI(15, 15, LOWER16(MIPS64_PRACC_STACK)), + MIPS64_SD(1, 0, 15), /* sw $1,($15) */ + MIPS64_SD(2, 0, 15), /* sw $2,($15) */ + MIPS64_MFC0(1, 23, 0), /* move COP0 Debug to $1 */ + MIPS64_LUI(2, 0xFFFF), /* $2 = 0xfffffeff */ + MIPS64_ORI(2, 2, 0xFEFF), + + + MIPS64_AND(1, 1, 2), + MIPS64_MTC0(1, 23, 0), /* move $1 to COP0 Debug */ + MIPS64_LD(2, 0, 15), + MIPS64_LD(1, 0, 15), + MIPS64_NOP, + MIPS64_SYNC, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_B(NEG16(17)), + MIPS64_MFC0(15, 31, 0), /* move COP0 DeSave to $15 */ + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + }; + + mips64_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, \ + 0, NULL, 0, NULL, 1); + return ERROR_OK; + } retval = mips32_dmaacc_read_mem(ejtag_info, EJTAG_DCR, 4, 1, &dcr); if (retval != ERROR_OK) @@ -277,7 +472,12 @@ int mips_ejtag_enter_debug(struct mips_ejtag *ejtag_info) ejtag_ctrl = ejtag_info->ejtag_ctrl | EJTAG_CTRL_JTAGBRK; mips_ejtag_drscan_32(ejtag_info, &ejtag_ctrl); - /* break bit will be cleared by hardware */ + /* break bit will not be cleared by hardware */ + ejtag_ctrl = ejtag_info->ejtag_ctrl & ~EJTAG_CTRL_JTAGBRK; + mips_ejtag_drscan_32(ejtag_info, &ejtag_ctrl); + + jtag_add_sleep(1000); + ejtag_ctrl = ejtag_info->ejtag_ctrl; mips_ejtag_drscan_32(ejtag_info, &ejtag_ctrl); LOG_DEBUG("ejtag_ctrl: 0x%8.8" PRIx32 "", ejtag_ctrl); @@ -294,6 +494,22 @@ int mips_ejtag_exit_debug(struct mips_ejtag *ejtag_info) { uint32_t instr = MIPS32_DRET; struct pracc_queue_info ctx = {.max_code = 1, .pracc_list = &instr, .code_count = 1, .store_count = 0}; + if (ejtag_info->impcode & 1) { + /* MIPS64 */ + uint32_t code[] = { + MIPS64_DRET, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + MIPS64_NOP, + }; + mips64_pracc_exec(ejtag_info, ARRAY_SIZE(code), code, + 0, NULL, 0, NULL, 1); + return ERROR_OK; + } /* execute our dret instruction */ ctx.retval = mips32_pracc_queue_exec(ejtag_info, &ctx, NULL); diff --git a/src/target/mips_ejtag.h b/src/target/mips_ejtag.h index db20e9d..829c1af 100644 --- a/src/target/mips_ejtag.h +++ b/src/target/mips_ejtag.h @@ -106,6 +106,7 @@ /* Debug Control Register DCR */ #define EJTAG_DCR 0xFF300000 +#define EJTAG64_DCR 0xFFFFFFFFFF300000ull #define EJTAG_DCR_ENM (1 << 29) #define EJTAG_DCR_DB (1 << 17) #define EJTAG_DCR_IB (1 << 16) @@ -128,13 +129,17 @@ #define EJTAG_V20_DBAn_STEP 0x10 #define EJTAG_V25_IBS 0xFF301000 +#define EJTAG64_V25_IBS 0xFFFFFFFFFF301000ull #define EJTAG_V25_IBA0 0xFF301100 +#define EJTAG64_V25_IBA0 0xFFFFFFFFFF301100ull #define EJTAG_V25_IBM_OFFS 0x8 #define EJTAG_V25_IBASID_OFFS 0x10 #define EJTAG_V25_IBC_OFFS 0x18 #define EJTAG_V25_IBAn_STEP 0x100 #define EJTAG_V25_DBS 0xFF302000 +#define EJTAG64_V25_DBS 0xFFFFFFFFFF302000ull #define EJTAG_V25_DBA0 0xFF302100 +#define EJTAG64_V25_DBA0 0xFFFFFFFFFF302100ull #define EJTAG_V25_DBM_OFFS 0x8 #define EJTAG_V25_DBASID_OFFS 0x10 #define EJTAG_V25_DBC_OFFS 0x18 @@ -184,6 +189,9 @@ struct mips_ejtag { uint32_t ejtag_iba_step_size; uint32_t ejtag_dba_step_size; /* siez of step till next * *DBAn register. */ + + /* FIXME: hack for step after reset */ + uint32_t after_reset; }; void mips_ejtag_set_instr(struct mips_ejtag *ejtag_info, @@ -193,6 +201,9 @@ int mips_ejtag_exit_debug(struct mips_ejtag *ejtag_info); int mips_ejtag_get_idcode(struct mips_ejtag *ejtag_info, uint32_t *idcode); void mips_ejtag_add_scan_96(struct mips_ejtag *ejtag_info, uint32_t ctrl, uint32_t data, uint8_t *in_scan_buf); +void mips_ejtag_drscan_64_out(struct mips_ejtag *ejtag_info, uint64_t data); +int mips_ejtag_drscan_64(struct mips_ejtag *ejtag_info, uint64_t *data); +int mips_ejtag_drscan_36(struct mips_ejtag *ejtag_info, uint64_t *data); void mips_ejtag_drscan_32_out(struct mips_ejtag *ejtag_info, uint32_t data); int mips_ejtag_drscan_32(struct mips_ejtag *ejtag_info, uint32_t *data); void mips_ejtag_drscan_8_out(struct mips_ejtag *ejtag_info, uint8_t data); diff --git a/src/target/target.c b/src/target/target.c index 32ab117..f352235 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -23,6 +23,8 @@ * Copyright (C) 2011 Andreas Fritiofson * * [email protected] * * * + * Copyright (C) 2011 by Konstantin Kostyukhin, Nikolay Shmyrev * + * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * @@ -59,9 +61,9 @@ /* default halt wait timeout (ms) */ #define DEFAULT_HALT_TIMEOUT 5000 -static int target_read_buffer_default(struct target *target, uint32_t address, +static int target_read_buffer_default(struct target *target, uint64_t address, uint32_t count, uint8_t *buffer); -static int target_write_buffer_default(struct target *target, uint32_t address, +static int target_write_buffer_default(struct target *target, uint64_t address, uint32_t count, const uint8_t *buffer); static int target_array2mem(Jim_Interp *interp, struct target *target, int argc, Jim_Obj * const *argv); @@ -564,7 +566,7 @@ int target_halt(struct target *target) * hand the infrastructure for running such helpers might use this * procedure but rely on hardware breakpoint to detect termination.) */ -int target_resume(struct target *target, int current, uint32_t address, int handle_breakpoints, int debug_execution) +int target_resume(struct target *target, int current, uint64_t address, int handle_breakpoints, int debug_execution) { int retval; @@ -632,7 +634,7 @@ static int target_process_reset(struct command_context *cmd_ctx, enum target_res } static int identity_virt2phys(struct target *target, - uint32_t virtual, uint32_t *physical) + uint64_t virtual, uint64_t *physical) { *physical = virtual; return ERROR_OK; @@ -987,7 +989,7 @@ int target_run_flash_async_algorithm(struct target *target, } int target_read_memory(struct target *target, - uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer) + uint64_t address, uint32_t size, uint32_t count, uint8_t *buffer) { if (!target_was_examined(target)) { LOG_ERROR("Target not examined yet"); @@ -997,7 +999,7 @@ int target_read_memory(struct target *target, } int target_read_phys_memory(struct target *target, - uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer) + uint64_t address, uint32_t size, uint32_t count, uint8_t *buffer) { if (!target_was_examined(target)) { LOG_ERROR("Target not examined yet"); @@ -1007,7 +1009,7 @@ int target_read_phys_memory(struct target *target, } int target_write_memory(struct target *target, - uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer) + uint64_t address, uint32_t size, uint32_t count, const uint8_t *buffer) { if (!target_was_examined(target)) { LOG_ERROR("Target not examined yet"); @@ -1017,7 +1019,7 @@ int target_write_memory(struct target *target, } int target_write_phys_memory(struct target *target, - uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer) + uint64_t address, uint32_t size, uint32_t count, const uint8_t *buffer) { if (!target_was_examined(target)) { LOG_ERROR("Target not examined yet"); @@ -1101,7 +1103,7 @@ int target_get_gdb_reg_list(struct target *target, return target->type->get_gdb_reg_list(target, reg_list, reg_list_size, reg_class); } int target_step(struct target *target, - int current, uint32_t address, int handle_breakpoints) + int current, uint64_t address, int handle_breakpoints) { return target->type->step(target, current, address, handle_breakpoints); } @@ -1144,14 +1146,14 @@ static void target_reset_examined(struct target *target) target->examined = false; } -static int err_read_phys_memory(struct target *target, uint32_t address, +static int err_read_phys_memory(struct target *target, uint64_t address, uint32_t size, uint32_t count, uint8_t *buffer) { LOG_ERROR("Not implemented: %s", __func__); return ERROR_FAIL; } -static int err_write_phys_memory(struct target *target, uint32_t address, +static int err_write_phys_memory(struct target *target, uint64_t address, uint32_t size, uint32_t count, const uint8_t *buffer) { LOG_ERROR("Not implemented: %s", __func__); @@ -1849,9 +1851,9 @@ static int target_profiling_default(struct target *target, uint32_t *samples, * mode respectively, otherwise data is handled as quickly as * possible */ -int target_write_buffer(struct target *target, uint32_t address, uint32_t size, const uint8_t *buffer) +int target_write_buffer(struct target *target, uint64_t address, uint32_t size, const uint8_t *buffer) { - LOG_DEBUG("writing buffer of %i byte at 0x%8.8x", + LOG_DEBUG("writing buffer of %i byte at 0x%16.16llx", (int)size, (unsigned)address); if (!target_was_examined(target)) { @@ -1864,8 +1866,8 @@ int target_write_buffer(struct target *target, uint32_t address, uint32_t size, if ((address + size - 1) < address) { /* GDB can request this when e.g. PC is 0xfffffffc*/ - LOG_ERROR("address + size wrapped(0x%08x, 0x%08x)", - (unsigned)address, + LOG_ERROR("address + size wrapped(0x%16llx, 0x%08x)", + address, (unsigned)size); return ERROR_FAIL; } @@ -1873,7 +1875,7 @@ int target_write_buffer(struct target *target, uint32_t address, uint32_t size, return target->type->write_buffer(target, address, size, buffer); } -static int target_write_buffer_default(struct target *target, uint32_t address, uint32_t count, const uint8_t *buffer) +static int target_write_buffer_default(struct target *target, uint64_t address, uint32_t count, const uint8_t *buffer) { uint32_t size; @@ -1910,10 +1912,10 @@ static int target_write_buffer_default(struct target *target, uint32_t address, * mode respectively, otherwise data is handled as quickly as * possible */ -int target_read_buffer(struct target *target, uint32_t address, uint32_t size, uint8_t *buffer) +int target_read_buffer(struct target *target, uint64_t address, uint32_t size, uint8_t *buffer) { - LOG_DEBUG("reading buffer of %i byte at 0x%8.8x", - (int)size, (unsigned)address); + LOG_DEBUG("reading buffer of %i byte at 0x%16.16llx", + (int)size, address); if (!target_was_examined(target)) { LOG_ERROR("Target not examined yet"); @@ -1925,7 +1927,7 @@ int target_read_buffer(struct target *target, uint32_t address, uint32_t size, u if ((address + size - 1) < address) { /* GDB can request this when e.g. PC is 0xfffffffc*/ - LOG_ERROR("address + size wrapped(0x%08" PRIx32 ", 0x%08" PRIx32 ")", + LOG_ERROR("address + size wrapped(0x%16" PRIx64 ", 0x%08" PRIx32 ")", address, size); return ERROR_FAIL; @@ -1934,7 +1936,7 @@ int target_read_buffer(struct target *target, uint32_t address, uint32_t size, u return target->type->read_buffer(target, address, size, buffer); } -static int target_read_buffer_default(struct target *target, uint32_t address, uint32_t count, uint8_t *buffer) +static int target_read_buffer_default(struct target *target, uint64_t address, uint32_t count, uint8_t *buffer) { uint32_t size; @@ -1967,7 +1969,7 @@ static int target_read_buffer_default(struct target *target, uint32_t address, u return ERROR_OK; } -int target_checksum_memory(struct target *target, uint32_t address, uint32_t size, uint32_t* crc) +int target_checksum_memory(struct target *target, uint64_t address, uint32_t size, uint32_t* crc) { uint8_t *buffer; int retval; @@ -1993,7 +1995,7 @@ int target_checksum_memory(struct target *target, uint32_t address, uint32_t siz /* convert to target endianness */ for (i = 0; i < (size/sizeof(uint32_t)); i++) { - uint32_t target_data; + uint64_t target_data; target_data = target_buffer_get_u32(target, &buffer[i*sizeof(uint32_t)]); target_buffer_set_u32(target, &buffer[i*sizeof(uint32_t)], target_data); } @@ -2007,7 +2009,7 @@ int target_checksum_memory(struct target *target, uint32_t address, uint32_t siz return retval; } -int target_blank_check_memory(struct target *target, uint32_t address, uint32_t size, uint32_t* blank) +int target_blank_check_memory(struct target *target, uint64_t address, uint32_t size, uint32_t* blank) { int retval; if (!target_was_examined(target)) { @@ -2047,7 +2049,7 @@ int target_read_u64(struct target *target, uint64_t address, uint64_t *value) return retval; } -int target_read_u32(struct target *target, uint32_t address, uint32_t *value) +int target_read_u32(struct target *target, uint64_t address, uint32_t *value) { uint8_t value_buf[4]; if (!target_was_examined(target)) { @@ -2059,19 +2061,19 @@ int target_read_u32(struct target *target, uint32_t address, uint32_t *value) if (retval == ERROR_OK) { *value = target_buffer_get_u32(target, value_buf); - LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%8.8" PRIx32 "", + LOG_DEBUG("address: 0x%16.16" PRIx64 ", value: 0x%8.8" PRIx32 "", address, *value); } else { *value = 0x0; - LOG_DEBUG("address: 0x%8.8" PRIx32 " failed", + LOG_DEBUG("address: 0x%16.16" PRIx64 " failed", address); } return retval; } -int target_read_u16(struct target *target, uint32_t address, uint16_t *value) +int target_read_u16(struct target *target, uint64_t address, uint16_t *value) { uint8_t value_buf[2]; if (!target_was_examined(target)) { @@ -2083,19 +2085,19 @@ int target_read_u16(struct target *target, uint32_t address, uint16_t *value) if (retval == ERROR_OK) { *value = target_buffer_get_u16(target, value_buf); - LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%4.4x", + LOG_DEBUG("address: 0x%16.16" PRIx64 ", value: 0x%4.4x", address, *value); } else { *value = 0x0; - LOG_DEBUG("address: 0x%8.8" PRIx32 " failed", + LOG_DEBUG("address: 0x%16.16" PRIx64 " failed", address); } return retval; } -int target_read_u8(struct target *target, uint32_t address, uint8_t *value) +int target_read_u8(struct target *target, uint64_t address, uint8_t *value) { if (!target_was_examined(target)) { LOG_ERROR("Target not examined yet"); @@ -2105,12 +2107,12 @@ int target_read_u8(struct target *target, uint32_t address, uint8_t *value) int retval = target_read_memory(target, address, 1, 1, value); if (retval == ERROR_OK) { - LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%2.2x", + LOG_DEBUG("address: 0x%16.16" PRIx64 ", value: 0x%2.2x", address, *value); } else { *value = 0x0; - LOG_DEBUG("address: 0x%8.8" PRIx32 " failed", + LOG_DEBUG("address: 0x%16.16" PRIx64 " failed", address); } @@ -2138,7 +2140,7 @@ int target_write_u64(struct target *target, uint64_t address, uint64_t value) return retval; } -int target_write_u32(struct target *target, uint32_t address, uint32_t value) +int target_write_u32(struct target *target, uint64_t address, uint32_t value) { int retval; uint8_t value_buf[4]; @@ -2147,7 +2149,7 @@ int target_write_u32(struct target *target, uint32_t address, uint32_t value) return ERROR_FAIL; } - LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%8.8" PRIx32 "", + LOG_DEBUG("address: 0x%16.16" PRIx64 ", value: 0x%8.8" PRIx32 "", address, value); @@ -2159,7 +2161,7 @@ int target_write_u32(struct target *target, uint32_t address, uint32_t value) return retval; } -int target_write_u16(struct target *target, uint32_t address, uint16_t value) +int target_write_u16(struct target *target, uint64_t address, uint16_t value) { int retval; uint8_t value_buf[2]; @@ -2168,7 +2170,7 @@ int target_write_u16(struct target *target, uint32_t address, uint16_t value) return ERROR_FAIL; } - LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%8.8x", + LOG_DEBUG("address: 0x%16.16" PRIx64 ", value: 0x%8.8x", address, value); @@ -2180,7 +2182,7 @@ int target_write_u16(struct target *target, uint32_t address, uint16_t value) return retval; } -int target_write_u8(struct target *target, uint32_t address, uint8_t value) +int target_write_u8(struct target *target, uint64_t address, uint8_t value) { int retval; if (!target_was_examined(target)) { @@ -2188,7 +2190,7 @@ int target_write_u8(struct target *target, uint32_t address, uint8_t value) return ERROR_FAIL; } - LOG_DEBUG("address: 0x%8.8" PRIx32 ", value: 0x%2.2x", + LOG_DEBUG("address: 0x%16.16" PRIx64 ", value: 0x%2.2x", address, value); retval = target_write_memory(target, address, 1, 1, &value); @@ -2693,9 +2695,9 @@ COMMAND_HANDLER(handle_resume_command) /* with no CMD_ARGV, resume from current pc, addr = 0, * with one arguments, addr = CMD_ARGV[0], * handle breakpoints, not debugging */ - uint32_t addr = 0; + uint64_t addr = 0; if (CMD_ARGC == 1) { - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], addr); + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], addr); current = 0; } @@ -2712,10 +2714,10 @@ COMMAND_HANDLER(handle_step_command) /* with no CMD_ARGV, step from current pc, addr = 0, * with one argument addr = CMD_ARGV[0], * handle breakpoints, debugging */ - uint32_t addr = 0; + uint64_t addr = 0; int current_pc = 1; if (CMD_ARGC == 1) { - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], addr); + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], addr); current_pc = 0; } @@ -2725,7 +2727,7 @@ COMMAND_HANDLER(handle_step_command) } static void handle_md_output(struct command_context *cmd_ctx, - struct target *target, uint32_t address, unsigned size, + struct target *target, uint64_t address, unsigned size, unsigned count, const uint8_t *buffer) { const unsigned line_bytecnt = 32; @@ -2736,6 +2738,9 @@ static void handle_md_output(struct command_context *cmd_ctx, const char *value_fmt; switch (size) { + case 8: + value_fmt = "%16.16llx "; + break; case 4: value_fmt = "%8.8x "; break; @@ -2755,13 +2760,16 @@ static void handle_md_output(struct command_context *cmd_ctx, if (i % line_modulo == 0) { output_len += snprintf(output + output_len, sizeof(output) - output_len, - "0x%8.8x: ", - (unsigned)(address + (i*size))); + "0x%16.16llx: ", + (uint64_t)(address + (i*size))); } - uint32_t value = 0; + uint64_t value = 0; const uint8_t *value_ptr = buffer + i * size; switch (size) { + case 8: + value = target_buffer_get_u64(target, value_ptr); + break; case 4: value = target_buffer_get_u32(target, value_ptr); break; @@ -2789,6 +2797,9 @@ COMMAND_HANDLER(handle_md_command) unsigned size = 0; switch (CMD_NAME[2]) { + case 'd': + size = 8; + break; case 'w': size = 4; break; @@ -2804,7 +2815,7 @@ COMMAND_HANDLER(handle_md_command) bool physical = strcmp(CMD_ARGV[0], "phys") == 0; int (*fn)(struct target *target, - uint32_t address, uint32_t size_value, uint32_t count, uint8_t *buffer); + uint64_t address, uint32_t size_value, uint32_t count, uint8_t *buffer); if (physical) { CMD_ARGC--; CMD_ARGV++; @@ -2814,8 +2825,8 @@ COMMAND_HANDLER(handle_md_command) if ((CMD_ARGC < 1) || (CMD_ARGC > 2)) return ERROR_COMMAND_SYNTAX_ERROR; - uint32_t address; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address); + uint64_t address; + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], address); unsigned count = 1; if (CMD_ARGC == 2) @@ -2834,14 +2845,14 @@ COMMAND_HANDLER(handle_md_command) } typedef int (*target_write_fn)(struct target *target, - uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer); + uint64_t address, uint32_t size, uint32_t count, const uint8_t *buffer); static int target_fill_mem(struct target *target, - uint32_t address, + uint64_t address, target_write_fn fn, unsigned data_size, /* value */ - uint32_t b, + uint64_t b, /* count */ unsigned c) { @@ -2856,6 +2867,9 @@ static int target_fill_mem(struct target *target, for (unsigned i = 0; i < chunk_size; i++) { switch (data_size) { + case 8: + target_buffer_set_u64(target, target_buf + i*data_size, b); + break; case 4: target_buffer_set_u32(target, target_buf + i * data_size, b); break; @@ -2904,11 +2918,11 @@ COMMAND_HANDLER(handle_mw_command) if ((CMD_ARGC < 2) || (CMD_ARGC > 3)) return ERROR_COMMAND_SYNTAX_ERROR; - uint32_t address; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address); + uint64_t address; + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], address); - uint32_t value; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value); + uint64_t value; + COMMAND_PARSE_NUMBER(ullong, CMD_ARGV[1], value); unsigned count = 1; if (CMD_ARGC == 3) @@ -2917,6 +2931,9 @@ COMMAND_HANDLER(handle_mw_command) struct target *target = get_current_target(CMD_CTX); unsigned wordsize; switch (CMD_NAME[2]) { + case 'd': + wordsize = 8; + break; case 'w': wordsize = 4; break; @@ -2934,7 +2951,7 @@ COMMAND_HANDLER(handle_mw_command) } static COMMAND_HELPER(parse_load_image_command_CMD_ARGV, struct image *image, - uint32_t *min_address, uint32_t *max_address) + uint64_t *min_address, uint64_t *max_address) { if (CMD_ARGC < 1 || CMD_ARGC > 5) return ERROR_COMMAND_SYNTAX_ERROR; @@ -2942,8 +2959,8 @@ static COMMAND_HELPER(parse_load_image_command_CMD_ARGV, struct image *image, /* a base address isn't always necessary, * default to 0x0 (i.e. don't relocate) */ if (CMD_ARGC >= 2) { - uint32_t addr; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], addr); + uint64_t addr; + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[1], addr); image->base_address = addr; image->base_address_set = 1; } else @@ -2952,9 +2969,9 @@ static COMMAND_HELPER(parse_load_image_command_CMD_ARGV, struct image *image, image->start_address_set = 0; if (CMD_ARGC >= 4) - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[3], *min_address); + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[3], *min_address); if (CMD_ARGC == 5) { - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[4], *max_address); + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[4], *max_address); /* use size (given) to find max (required) */ *max_address += *min_address; } @@ -2970,8 +2987,8 @@ COMMAND_HANDLER(handle_load_image_command) uint8_t *buffer; size_t buf_cnt; uint32_t image_size; - uint32_t min_address = 0; - uint32_t max_address = 0xffffffff; + uint64_t min_address = 0; + uint64_t max_address = 0xffffffffffffffff; int i; struct image image; @@ -3029,7 +3046,7 @@ COMMAND_HANDLER(handle_load_image_command) break; } image_size += length; - command_print(CMD_CTX, "%u bytes written at address 0x%8.8" PRIx32 "", + command_print(CMD_CTX, "%u bytes written at address 0x%16.16" PRIx64 "", (unsigned int)length, image.sections[i].base_address + offset); } @@ -3054,14 +3071,15 @@ COMMAND_HANDLER(handle_dump_image_command) struct fileio fileio; uint8_t *buffer; int retval, retvaltemp; - uint32_t address, size; + uint64_t address; + uint32_t size; struct duration bench; struct target *target = get_current_target(CMD_CTX); if (CMD_ARGC != 3) return ERROR_COMMAND_SYNTAX_ERROR; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], address); + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[1], address); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], size); uint32_t buf_size = (size > 4096) ? 4096 : size; @@ -3137,8 +3155,8 @@ static COMMAND_HELPER(handle_verify_image_command_internal, int verify) duration_start(&bench); if (CMD_ARGC >= 2) { - uint32_t addr; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], addr); + uint64_t addr; + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[1], addr); image.base_address = addr; image.base_address_set = 1; } else { @@ -3205,9 +3223,9 @@ static COMMAND_HELPER(handle_verify_image_command_internal, int verify) for (t = 0; t < buf_cnt; t++) { if (data[t] != buffer[t]) { command_print(CMD_CTX, - "diff %d address 0x%08x. Was 0x%02x instead of 0x%02x", + "diff %d address 0x%16llx. Was 0x%02x instead of 0x%02x", diffs, - (unsigned)(t + image.sections[i].base_address), + (t + image.sections[i].base_address), data[t], buffer[t]); if (diffs++ >= 127) { @@ -3223,7 +3241,7 @@ static COMMAND_HELPER(handle_verify_image_command_internal, int verify) free(data); } } else { - command_print(CMD_CTX, "address 0x%08" PRIx32 " length 0x%08zx", + command_print(CMD_CTX, "address 0x%16" PRIx64 " length 0x%08zx", image.sections[i].base_address, buf_cnt); } @@ -3265,24 +3283,24 @@ static int handle_bp_command_list(struct command_context *cmd_ctx) if (breakpoint->type == BKPT_SOFT) { char *buf = buf_to_str(breakpoint->orig_instr, breakpoint->length, 16); - command_print(cmd_ctx, "IVA breakpoint: 0x%8.8" PRIx32 ", 0x%x, %i, 0x%s", + command_print(cmd_ctx, "IVA breakpoint: 0x%16.16" PRIx64 ", 0x%x, %i, 0x%s", breakpoint->address, breakpoint->length, breakpoint->set, buf); free(buf); } else { if ((breakpoint->address == 0) && (breakpoint->asid != 0)) - command_print(cmd_ctx, "Context breakpoint: 0x%8.8" PRIx32 ", 0x%x, %i", + command_print(cmd_ctx, "Context breakpoint: 0x%16.16" PRIx64 ", 0x%x, %i", breakpoint->asid, breakpoint->length, breakpoint->set); else if ((breakpoint->address != 0) && (breakpoint->asid != 0)) { - command_print(cmd_ctx, "Hybrid breakpoint(IVA): 0x%8.8" PRIx32 ", 0x%x, %i", + command_print(cmd_ctx, "Hybrid breakpoint(IVA): 0x%16.16" PRIx64 ", 0x%x, %i", breakpoint->address, breakpoint->length, breakpoint->set); - command_print(cmd_ctx, "\t|--->linked with ContextID: 0x%8.8" PRIx32, + command_print(cmd_ctx, "\t|--->linked with ContextID: 0x%16.16" PRIx64, breakpoint->asid); } else - command_print(cmd_ctx, "Breakpoint(IVA): 0x%8.8" PRIx32 ", 0x%x, %i", + command_print(cmd_ctx, "Breakpoint(IVA): 0x%16.16" PRIx64 ", 0x%x, %i", breakpoint->address, breakpoint->length, breakpoint->set); } @@ -3293,14 +3311,14 @@ static int handle_bp_command_list(struct command_context *cmd_ctx) } static int handle_bp_command_set(struct command_context *cmd_ctx, - uint32_t addr, uint32_t asid, uint32_t length, int hw) + uint64_t addr, uint32_t asid, uint32_t length, int hw) { struct target *target = get_current_target(cmd_ctx); if (asid == 0) { int retval = breakpoint_add(target, addr, length, hw); if (ERROR_OK == retval) - command_print(cmd_ctx, "breakpoint set at 0x%8.8" PRIx32 "", addr); + command_print(cmd_ctx, "breakpoint set at 0x%16.16" PRIx64 "", addr); else { LOG_ERROR("Failure setting breakpoint, the same address(IVA) is already used"); return retval; @@ -3308,7 +3326,7 @@ static int handle_bp_command_set(struct command_context *cmd_ctx, } else if (addr == 0) { int retval = context_breakpoint_add(target, asid, length, hw); if (ERROR_OK == retval) - command_print(cmd_ctx, "Context breakpoint set at 0x%8.8" PRIx32 "", asid); + command_print(cmd_ctx, "Context breakpoint set at 0x%16.16" PRIx64 "", asid); else { LOG_ERROR("Failure setting breakpoint, the same address(CONTEXTID) is already used"); return retval; @@ -3316,7 +3334,7 @@ static int handle_bp_command_set(struct command_context *cmd_ctx, } else { int retval = hybrid_breakpoint_add(target, addr, asid, length, hw); if (ERROR_OK == retval) - command_print(cmd_ctx, "Hybrid breakpoint set at 0x%8.8" PRIx32 "", asid); + command_print(cmd_ctx, "Hybrid breakpoint set at 0x%16.16" PRIx64 "", asid); else { LOG_ERROR("Failure setting breakpoint, the same address is already used"); return retval; @@ -3327,7 +3345,7 @@ static int handle_bp_command_set(struct command_context *cmd_ctx, COMMAND_HANDLER(handle_bp_command) { - uint32_t addr; + uint64_t addr; uint32_t asid; uint32_t length; int hw = BKPT_SOFT; @@ -3338,14 +3356,14 @@ COMMAND_HANDLER(handle_bp_command) case 2: asid = 0; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], addr); + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], addr); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], length); return handle_bp_command_set(CMD_CTX, addr, asid, length, hw); case 3: if (strcmp(CMD_ARGV[2], "hw") == 0) { hw = BKPT_HARD; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], addr); + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], addr); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], length); @@ -3361,7 +3379,7 @@ COMMAND_HANDLER(handle_bp_command) case 4: hw = BKPT_HARD; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], addr); + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], addr); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], asid); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], length); return handle_bp_command_set(CMD_CTX, addr, asid, length, hw); @@ -3376,8 +3394,8 @@ COMMAND_HANDLER(handle_rbp_command) if (CMD_ARGC != 1) return ERROR_COMMAND_SYNTAX_ERROR; - uint32_t addr; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], addr); + uint64_t addr; + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], addr); struct target *target = get_current_target(CMD_CTX); breakpoint_remove(target, addr); @@ -3393,10 +3411,10 @@ COMMAND_HANDLER(handle_wp_command) struct watchpoint *watchpoint = target->watchpoints; while (watchpoint) { - command_print(CMD_CTX, "address: 0x%8.8" PRIx32 + command_print(CMD_CTX, "address: 0x%16.16" PRIx64 ", len: 0x%8.8" PRIx32 - ", r/w/a: %i, value: 0x%8.8" PRIx32 - ", mask: 0x%8.8" PRIx32, + ", r/w/a: %i, value: 0x%16.16" PRIx64 + ", mask: 0x%16.16" PRIx64, watchpoint->address, watchpoint->length, (int)watchpoint->rw, @@ -3408,17 +3426,17 @@ COMMAND_HANDLER(handle_wp_command) } enum watchpoint_rw type = WPT_ACCESS; - uint32_t addr = 0; + uint64_t addr = 0; uint32_t length = 0; - uint32_t data_value = 0x0; - uint32_t data_mask = 0xffffffff; + uint64_t data_value = 0x0; + uint64_t data_mask = 0xffffffffffffffff; switch (CMD_ARGC) { case 5: - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[4], data_mask); + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[4], data_mask); /* fall through */ case 4: - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[3], data_value); + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[3], data_value); /* fall through */ case 3: switch (CMD_ARGV[2][0]) { @@ -3438,7 +3456,7 @@ COMMAND_HANDLER(handle_wp_command) /* fall through */ case 2: COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], length); - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], addr); + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], addr); break; default: @@ -3458,8 +3476,8 @@ COMMAND_HANDLER(handle_rwp_command) if (CMD_ARGC != 1) return ERROR_COMMAND_SYNTAX_ERROR; - uint32_t addr; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], addr); + uint64_t addr; + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], addr); struct target *target = get_current_target(CMD_CTX); watchpoint_remove(target, addr); @@ -3478,14 +3496,14 @@ COMMAND_HANDLER(handle_virt2phys_command) if (CMD_ARGC != 1) return ERROR_COMMAND_SYNTAX_ERROR; - uint32_t va; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], va); - uint32_t pa; + uint64_t va; + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], va); + uint64_t pa; struct target *target = get_current_target(CMD_CTX); int retval = target->type->virt2phys(target, va, &pa); if (retval == ERROR_OK) - command_print(CMD_CTX, "Physical address 0x%08" PRIx32 "", pa); + command_print(CMD_CTX, "Physical address 0x%16" PRIx64 "", pa); return retval; } @@ -3515,8 +3533,8 @@ static void writeString(FILE *f, char *s) typedef unsigned char UNIT[2]; /* unit of profiling */ /* Dump a gmon.out histogram file. */ -static void write_gmon(uint32_t *samples, uint32_t sampleNum, const char *filename, - bool with_range, uint32_t start_address, uint32_t end_address) +static void write_gmon(uint64_t *samples, uint32_t sampleNum, const char *filename, + bool with_range, uint64_t start_address, uint64_t end_address) { uint32_t i; FILE *f = fopen(filename, "w"); @@ -3532,8 +3550,8 @@ static void write_gmon(uint32_t *samples, uint32_t sampleNum, const char *filena writeData(f, &zero, 1); /* figure out bucket size */ - uint32_t min; - uint32_t max; + uint64_t min; + uint64_t max; if (with_range) { min = start_address; max = end_address; @@ -3552,23 +3570,23 @@ static void write_gmon(uint32_t *samples, uint32_t sampleNum, const char *filena max++; } - int addressSpace = max - min; + uint64_t addressSpace = max - min; assert(addressSpace >= 2); /* FIXME: What is the reasonable number of buckets? * The profiling result will be more accurate if there are enough buckets. */ - static const uint32_t maxBuckets = 128 * 1024; /* maximum buckets. */ - uint32_t numBuckets = addressSpace / sizeof(UNIT); + static const uint64_t maxBuckets = 128 * 1024; /* maximum buckets. */ + uint64_t numBuckets = addressSpace / sizeof(UNIT); if (numBuckets > maxBuckets) numBuckets = maxBuckets; - int *buckets = malloc(sizeof(int) * numBuckets); + uint64_t *buckets = malloc(sizeof(uint64_t) * numBuckets); if (buckets == NULL) { fclose(f); return; } - memset(buckets, 0, sizeof(int) * numBuckets); + memset(buckets, 0, sizeof(uint64_t) * numBuckets); for (i = 0; i < sampleNum; i++) { - uint32_t address = samples[i]; + uint64_t address = samples[i]; if ((address < min) || (max <= address)) continue; @@ -3627,7 +3645,7 @@ COMMAND_HANDLER(handle_profile_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], offset); - uint32_t *samples = malloc(sizeof(uint32_t) * MAX_PROFILE_SAMPLE_NUM); + uint64_t *samples = malloc(sizeof(uint64_t) * MAX_PROFILE_SAMPLE_NUM); if (samples == NULL) { LOG_ERROR("No memory to store samples."); return ERROR_FAIL; @@ -3666,13 +3684,13 @@ COMMAND_HANDLER(handle_profile_command) return retval; } - uint32_t start_address = 0; - uint32_t end_address = 0; + uint64_t start_address = 0; + uint64_t end_address = 0; bool with_range = false; if (CMD_ARGC == 4) { with_range = true; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], start_address); - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[3], end_address); + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[2], start_address); + COMMAND_PARSE_NUMBER(u64, CMD_ARGV[3], end_address); } write_gmon(samples, num_of_samples, CMD_ARGV[1], @@ -3730,9 +3748,9 @@ static int jim_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *argv) static int target_mem2array(Jim_Interp *interp, struct target *target, int argc, Jim_Obj *const *argv) { long l; - uint32_t width; + uint64_t width; int len; - uint32_t addr; + uint64_t addr; uint32_t count; uint32_t v; const char *varname; @@ -3774,9 +3792,12 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc, case 32: width = 4; break; + case 64: + width = 8; + break; default: Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - Jim_AppendStrings(interp, Jim_GetResult(interp), "Invalid width param, must be 8/16/32", NULL); + Jim_AppendStrings(interp, Jim_GetResult(interp), "Invalid width param, must be 8/16/32/64", NULL); return JIM_ERR; } if (len == 0) { @@ -3798,14 +3819,15 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc, if ((width == 1) || ((width == 2) && ((addr & 1) == 0)) || - ((width == 4) && ((addr & 3) == 0))) { + ((width == 4) && ((addr & 3) == 0)) || + ((width == 8) && ((addr & 7) == 0))) { /* all is well */ } else { char buf[100]; Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - sprintf(buf, "mem2array address: 0x%08" PRIx32 " is not aligned for %" PRId32 " byte reads", + sprintf(buf, "mem2array address: 0x%16" PRIx64 " is not aligned for %" PRId32 " byte reads", addr, - width); + (unsigned)width); Jim_AppendStrings(interp, Jim_GetResult(interp), buf , NULL); return JIM_ERR; } @@ -3832,8 +3854,8 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc, retval = target_read_memory(target, addr, width, count, buffer); if (retval != ERROR_OK) { /* BOO !*/ - LOG_ERROR("mem2array: Read @ 0x%08x, w=%d, cnt=%d, failed", - (unsigned int)addr, + LOG_ERROR("mem2array: Read @ 0x%16llx, w=%d, cnt=%d, failed", + addr, (int)width, (int)count); Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); @@ -3844,6 +3866,9 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc, v = 0; /* shut up gcc */ for (i = 0; i < count ; i++, n++) { switch (width) { + case 8: + v = target_buffer_get_u64(target, &buffer[i*width]); + break; case 4: v = target_buffer_get_u32(target, &buffer[i*width]); break; @@ -3919,10 +3944,10 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, int argc, Jim_Obj *const *argv) { long l; - uint32_t width; + uint64_t width; int len; - uint32_t addr; - uint32_t count; + uint64_t addr; + uint64_t count; uint32_t v; const char *varname; int n, e, retval; @@ -3963,6 +3988,9 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, case 32: width = 4; break; + case 64: + width = 8; + break; default: Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); Jim_AppendStrings(interp, Jim_GetResult(interp), @@ -3991,13 +4019,14 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, if ((width == 1) || ((width == 2) && ((addr & 1) == 0)) || - ((width == 4) && ((addr & 3) == 0))) { + ((width == 4) && ((addr & 3) == 0)) || + ((width == 8) && ((addr & 7) == 0))) { /* all is well */ } else { char buf[100]; Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - sprintf(buf, "array2mem address: 0x%08x is not aligned for %d byte reads", - (unsigned int)addr, + sprintf(buf, "array2mem address: 0x%16llx is not aligned for %d byte reads", + addr, (int)width); Jim_AppendStrings(interp, Jim_GetResult(interp), buf , NULL); return JIM_ERR; @@ -4026,6 +4055,9 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, for (i = 0; i < count; i++, n++) { get_int_array_element(interp, varname, n, &v); switch (width) { + case 8: + target_buffer_set_u64(target, &buffer[i*width], v); + break; case 4: target_buffer_set_u32(target, &buffer[i * width], v); break; @@ -4042,8 +4074,8 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, retval = target_write_memory(target, addr, width, count, buffer); if (retval != ERROR_OK) { /* BOO !*/ - LOG_ERROR("array2mem: Write @ 0x%08x, w=%d, cnt=%d, failed", - (unsigned int)addr, + LOG_ERROR("array2mem: Write @ 0x%16llx, w=%d, cnt=%d, failed", + addr, (int)width, (int)count); Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); @@ -4499,7 +4531,9 @@ static int jim_target_mw(Jim_Interp *interp, int argc, Jim_Obj *const *argv) struct target *target = Jim_CmdPrivData(goi.interp); unsigned data_size; - if (strcasecmp(cmd_name, "mww") == 0) + if (strcasecmp(cmd_name, "mwd") == 0) + data_size = 8; + else if (strcasecmp(cmd_name, "mww") == 0) data_size = 4; else if (strcasecmp(cmd_name, "mwh") == 0) data_size = 2; @@ -4555,7 +4589,7 @@ static int jim_target_md(Jim_Interp *interp, int argc, Jim_Obj *const *argv) } int (*fn)(struct target *target, - uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer); + uint64_t address, uint32_t size, uint32_t count, uint8_t *buffer); fn = target_read_memory; int e; @@ -4589,7 +4623,9 @@ static int jim_target_md(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return JIM_ERR; jim_wide dwidth = 1; /* shut up gcc */ - if (strcasecmp(cmd_name, "mdw") == 0) + if (strcasecmp(cmd_name, "mdd") == 0) + dwidth = 8; + else if (strcasecmp(cmd_name, "mdw") == 0) dwidth = 4; else if (strcasecmp(cmd_name, "mdh") == 0) dwidth = 2; @@ -4604,7 +4640,7 @@ static int jim_target_md(Jim_Interp *interp, int argc, Jim_Obj *const *argv) int bytes = count * dwidth; struct target *target = Jim_CmdPrivData(goi.interp); - uint8_t target_buf[32]; + uint8_t target_buf[64]; jim_wide x, y, z; while (bytes > 0) { y = (bytes < 16) ? bytes : 16; /* y = min(bytes, 16); */ @@ -4619,6 +4655,14 @@ static int jim_target_md(Jim_Interp *interp, int argc, Jim_Obj *const *argv) command_print_sameline(NULL, "0x%08x ", (int)(addr)); switch (dwidth) { + case 8: + for (x = 0 ; (x < 16) && (x < y) ; x += 8) { + z = target_buffer_get_u64(target, &(target_buf[x])); + command_print_sameline(NULL, "%16llx ", (z)); + } + for (; (x < 16) ; x += 8) + command_print_sameline(NULL, " "); + break; case 4: for (x = 0; x < 16 && x < y; x += 4) { z = target_buffer_get_u32(target, &(target_buf[x])); @@ -4913,6 +4957,13 @@ static const struct command_registration target_instance_command_handlers[] = { .usage = "target_attribute", }, { + .name = "mwd", + .mode = COMMAND_EXEC, + .jim_handler = jim_target_mw, + .help = "Write 64-bit word(s) to target memory", + .usage = "address data [count]", + }, + { .name = "mww", .mode = COMMAND_EXEC, .jim_handler = jim_target_mw, @@ -4934,6 +4985,13 @@ static const struct command_registration target_instance_command_handlers[] = { .usage = "address data [count]", }, { + .name = "mdd", + .mode = COMMAND_EXEC, + .jim_handler = jim_target_md, + .help = "Displaytargetmemoryas64-bitwords", + .usage = "address[count]", + }, + { .name = "mdw", .mode = COMMAND_EXEC, .jim_handler = jim_target_md, @@ -5440,7 +5498,7 @@ static const struct command_registration target_subcommand_handlers[] = { }; struct FastLoad { - uint32_t address; + uint64_t address; uint8_t *data; int length; @@ -5467,8 +5525,8 @@ COMMAND_HANDLER(handle_fast_load_image_command) uint8_t *buffer; size_t buf_cnt; uint32_t image_size; - uint32_t min_address = 0; - uint32_t max_address = 0xffffffff; + uint64_t min_address = 0; + uint64_t max_address = 0xffffffffffffffff; int i; struct image image; @@ -5579,8 +5637,8 @@ COMMAND_HANDLER(handle_fast_load_command) int retval = ERROR_OK; for (i = 0; i < fastload_num; i++) { struct target *target = get_current_target(CMD_CTX); - command_print(CMD_CTX, "Write to 0x%08x, length 0x%08x", - (unsigned int)(fastload[i].address), + command_print(CMD_CTX, "Write to 0x%16llx, length 0x%08x", + fastload[i].address, (unsigned int)(fastload[i].length)); retval = target_write_buffer(target, fastload[i].address, fastload[i].length, fastload[i].data); if (retval != ERROR_OK) @@ -5939,6 +5997,13 @@ static const struct command_registration target_exec_command_handlers[] = { .usage = "[address]", }, { + .name = "mdd", + .handler = handle_md_command, + .mode = COMMAND_EXEC, + .help = "displaymemorydoublewords", + .usage = "['phys']address[count]", + }, + { .name = "mdw", .handler = handle_md_command, .mode = COMMAND_EXEC, @@ -5960,6 +6025,13 @@ static const struct command_registration target_exec_command_handlers[] = { .usage = "['phys'] address [count]", }, { + .name = "mwd", + .handler = handle_mw_command, + .mode = COMMAND_EXEC, + .help = "writememorydoubleword", + .usage = "['phys']addressvalue[count]", + }, + { .name = "mww", .handler = handle_mw_command, .mode = COMMAND_EXEC, diff --git a/src/target/target.h b/src/target/target.h index 8e1c8f9..6170604 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -93,7 +93,7 @@ enum target_endianness { }; struct working_area { - uint32_t address; + uint64_t address; uint32_t size; bool free; uint8_t *backup; @@ -154,9 +154,9 @@ struct target { uint32_t working_area; /* working area (initialised RAM). Evaluated * upon first allocation from virtual/physical address. */ bool working_area_virt_spec; /* virtual address specified? */ - uint32_t working_area_virt; /* virtual address */ + uint64_t working_area_virt; /* virtual address */ bool working_area_phys_spec; /* virtual address specified? */ - uint32_t working_area_phys; /* physical address */ + uint64_t working_area_phys; /* physical address */ uint32_t working_area_size; /* size in bytes */ uint32_t backup_working_area; /* whether the content of the working area has to be preserved */ struct working_area *working_areas;/* list of allocated working areas */ @@ -317,7 +317,7 @@ int target_unregister_event_callback( * yet it is possible to detect error conditions. */ int target_poll(struct target *target); -int target_resume(struct target *target, int current, uint32_t address, +int target_resume(struct target *target, int current, uint64_t address, int handle_breakpoints, int debug_execution); int target_halt(struct target *target); int target_call_event_callbacks(struct target *target, enum target_event event); @@ -435,7 +435,7 @@ int target_get_gdb_reg_list(struct target *target, * This routine is a wrapper for target->type->step. */ int target_step(struct target *target, - int current, uint32_t address, int handle_breakpoints); + int current, uint64_t address, int handle_breakpoints); /** * Run an algorithm on the @a target given. * @@ -488,9 +488,9 @@ int target_run_flash_async_algorithm(struct target *target, * This routine is a wrapper for target->type->read_memory. */ int target_read_memory(struct target *target, - uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer); + uint64_t address, uint32_t size, uint32_t count, uint8_t *buffer); int target_read_phys_memory(struct target *target, - uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer); + uint64_t address, uint32_t size, uint32_t count, uint8_t *buffer); /** * Write @a count items of @a size bytes to the memory of @a target at * the @a address given. @a address must be aligned to @a size @@ -509,9 +509,9 @@ int target_read_phys_memory(struct target *target, * This routine is wrapper for target->type->write_memory. */ int target_write_memory(struct target *target, - uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer); + uint64_t address, uint32_t size, uint32_t count, const uint8_t *buffer); int target_write_phys_memory(struct target *target, - uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer); + uint64_t address, uint32_t size, uint32_t count, const uint8_t *buffer); /* * Write to target memory using the virtual address. @@ -538,13 +538,13 @@ int target_write_phys_memory(struct target *target, * peripheral registers which do not support byte operations. */ int target_write_buffer(struct target *target, - uint32_t address, uint32_t size, const uint8_t *buffer); + uint64_t address, uint32_t size, const uint8_t *buffer); int target_read_buffer(struct target *target, - uint32_t address, uint32_t size, uint8_t *buffer); + uint64_t address, uint32_t size, uint8_t *buffer); int target_checksum_memory(struct target *target, - uint32_t address, uint32_t size, uint32_t *crc); + uint64_t address, uint32_t size, uint32_t *crc); int target_blank_check_memory(struct target *target, - uint32_t address, uint32_t size, uint32_t *blank); + uint64_t address, uint32_t size, uint32_t *blank); int target_wait_state(struct target *target, enum target_state state, int ms); /** @@ -610,13 +610,13 @@ void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_ 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, uint64_t address, uint32_t *value); +int target_read_u16(struct target *target, uint64_t address, uint16_t *value); +int target_read_u8(struct target *target, uint64_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, uint64_t address, uint32_t value); +int target_write_u16(struct target *target, uint64_t address, uint16_t value); +int target_write_u8(struct target *target, uint64_t address, uint8_t value); /* Issues USER() statements with target state information */ int target_arch_state(struct target *target); diff --git a/src/target/target_type.h b/src/target/target_type.h index cf3c864..7d258e1 100644 --- a/src/target/target_type.h +++ b/src/target/target_type.h @@ -55,9 +55,9 @@ struct target_type { /* halt will log a warning, but return ERROR_OK if the target is already halted. */ int (*halt)(struct target *target); - int (*resume)(struct target *target, int current, uint32_t address, + int (*resume)(struct target *target, int current, uint64_t address, int handle_breakpoints, int debug_execution); - int (*step)(struct target *target, int current, uint32_t address, + int (*step)(struct target *target, int current, uint64_t address, int handle_breakpoints); /* target reset control. assert reset can be invoked when OpenOCD and @@ -113,26 +113,26 @@ struct target_type { * Target memory read callback. Do @b not call this function * directly, use target_read_memory() instead. */ - int (*read_memory)(struct target *target, uint32_t address, + int (*read_memory)(struct target *target, uint64_t address, uint32_t size, uint32_t count, uint8_t *buffer); /** * Target memory write callback. Do @b not call this function * directly, use target_write_memory() instead. */ - int (*write_memory)(struct target *target, uint32_t address, + int (*write_memory)(struct target *target, uint64_t address, uint32_t size, uint32_t count, const uint8_t *buffer); /* Default implementation will do some fancy alignment to improve performance, target can override */ - int (*read_buffer)(struct target *target, uint32_t address, + int (*read_buffer)(struct target *target, uint64_t address, uint32_t size, uint8_t *buffer); /* Default implementation will do some fancy alignment to improve performance, target can override */ - int (*write_buffer)(struct target *target, uint32_t address, + int (*write_buffer)(struct target *target, uint64_t address, uint32_t size, const uint8_t *buffer); - int (*checksum_memory)(struct target *target, uint32_t address, + int (*checksum_memory)(struct target *target, uint64_t address, uint32_t count, uint32_t *checksum); - int (*blank_check_memory)(struct target *target, uint32_t address, + int (*blank_check_memory)(struct target *target, uint64_t address, uint32_t count, uint32_t *blank); /* @@ -228,7 +228,7 @@ struct target_type { /* translate from virtual to physical address. Default implementation is successful * no-op(i.e. virtual==physical). */ - int (*virt2phys)(struct target *target, uint32_t address, uint32_t *physical); + int (*virt2phys)(struct target *target, uint64_t address, uint64_t *physical); /* read directly from physical memory. caches are bypassed and untouched. * @@ -238,13 +238,13 @@ struct target_type { * * Default implementation is to call read_memory. */ - int (*read_phys_memory)(struct target *target, uint32_t phys_address, + int (*read_phys_memory)(struct target *target, uint64_t phys_address, uint32_t size, uint32_t count, uint8_t *buffer); /* * same as read_phys_memory, except that it writes... */ - int (*write_phys_memory)(struct target *target, uint32_t phys_address, + int (*write_phys_memory)(struct target *target, uint64_t phys_address, uint32_t size, uint32_t count, const uint8_t *buffer); int (*mmu)(struct target *target, int *enabled); -- ------------------------------------------------------------------------------ Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk _______________________________________________ OpenOCD-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openocd-devel
