This is an automated email from Gerrit. Franck Jullien ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/1090
-- gerrit commit 2e1ab243f4324f1302ea0fe7d51c82935337bd7b Author: Franck Jullien <[email protected]> Date: Sun Dec 23 22:29:07 2012 +0100 tdesc: add tdesc helper functions Thid patch adds functions to help the generation of target description file. It also adds a feature variable in the struct reg. With this new variable, we can assign a register to a feature section in the tdesc file. Those functions need fileio_fprintf which is also included in this patch. Change-Id: Id05dc5ca080f17d6aaf3488a95ef066947b80fd4 Signed-off-by: Franck Jullien <[email protected]> diff --git a/src/helper/fileio.c b/src/helper/fileio.c index b2d847e..50dfead 100644 --- a/src/helper/fileio.c +++ b/src/helper/fileio.c @@ -211,6 +211,22 @@ int fileio_fgets(struct fileio *fileio_p, size_t size, void *buffer) return fileio_local_fgets(fileio, size, buffer); } +int fileio_fprintf(struct fileio *fileio_p, char *format, ...) +{ + va_list argList; + + va_start(argList, format); + + if (vfprintf(fileio_p->fp->file, format, argList) < 0) { + va_end(argList); + return ERROR_FILEIO_OPERATION_FAILED; + } + + va_end(argList); + + return ERROR_OK; +} + static int fileio_local_write(struct fileio_internal *fileio, size_t size, const void *buffer, size_t *size_written) { diff --git a/src/helper/fileio.h b/src/helper/fileio.h index 9d8931d..16ab320 100644 --- a/src/helper/fileio.h +++ b/src/helper/fileio.h @@ -57,6 +57,7 @@ int fileio_close(struct fileio *fileio); int fileio_seek(struct fileio *fileio, size_t position); int fileio_fgets(struct fileio *fileio, size_t size, void *buffer); +int fileio_fprintf(struct fileio *fileio_p, char *format, ...); int fileio_read(struct fileio *fileio, size_t size, void *buffer, size_t *size_read); diff --git a/src/target/Makefile.am b/src/target/Makefile.am index 19100c7..4f97a8e 100644 --- a/src/target/Makefile.am +++ b/src/target/Makefile.am @@ -45,7 +45,8 @@ TARGET_CORE_SRC = \ target.c \ target_request.c \ testee.c \ - smp.c + smp.c \ + tdesc.c ARMV4_5_SRC = \ armv4_5.c \ diff --git a/src/target/register.h b/src/target/register.h index cf08e4a..3ac3637 100644 --- a/src/target/register.h +++ b/src/target/register.h @@ -28,6 +28,7 @@ struct target; struct reg { const char *name; + const char *feature; void *value; bool dirty; bool valid; diff --git a/src/target/tdesc.c b/src/target/tdesc.c new file mode 100644 index 0000000..63dfd38 --- /dev/null +++ b/src/target/tdesc.c @@ -0,0 +1,190 @@ +/*************************************************************************** + * Copyright (C) 2012 by Franck Jullien * + * [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 * + * (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, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "log.h" +#include "register.h" +#include "target.h" +#include "target_type.h" +#include "fileio.h" + +/* Get the target registers list and write a tdesc feature section with + * all registers matching feature_name. If feature_name is NULL or empty, + * create a "nogroup" feature with all registers without feature definition. + */ +int generate_feature_section(struct target *target, struct fileio *fileio, + const char *arch_name, const char *feature_name) +{ + struct reg **reg_list; + int reg_list_size; + int retval; + int i; + int nogroup = 0; + int add_reg_to_group = 0; + + retval = target_get_gdb_reg_list(target, ®_list, ®_list_size); + if (retval != ERROR_OK) + return retval; + + /* If the feature name passed to the function is NULL or empty + * it means we want to create a "nogroup" feature section. + */ + if ((feature_name != NULL && !strcmp(feature_name, "")) || feature_name == NULL) + nogroup = 1; + + if (nogroup) + fileio_fprintf(fileio," <feature name=\"org.gnu.gdb.%s.%s\">\n", + arch_name, "nogroup"); + else + fileio_fprintf(fileio," <feature name=\"org.gnu.gdb.%s.%s\">\n", + arch_name, feature_name); + + for (i = 0; i < reg_list_size; i++) { + if (nogroup) { + if ((reg_list[i]->feature != NULL && !strcmp(reg_list[i]->feature, "")) + || reg_list[i]->feature == NULL) { + add_reg_to_group = 1; + } + } else { + if (reg_list[i]->feature != NULL && strcmp(reg_list[i]->feature, "")) { + if (!strcmp(reg_list[i]->feature, feature_name)) { + add_reg_to_group = 1; + } + } + } + + if (add_reg_to_group) { + fileio_fprintf(fileio, " <reg name=\"%s\" " + " bitsize=\"%d\" regnum=\"%d\"/>\n", + reg_list[i]->name, reg_list[i]->size, i); + add_reg_to_group = 0; + } + } + + fileio_fprintf(fileio, " </feature>\n"); + + free(reg_list); + + return ERROR_OK; +} + +/* Get a list of available target registers features. feature_list must + * be freed by caller. + */ +int get_reg_features_list(struct target *target, char **feature_list[]) +{ + struct reg **reg_list; + int reg_list_size; + int retval; + int tbl_sz = 0; + int i,j; + + retval = target_get_gdb_reg_list(target, ®_list, ®_list_size); + if (retval != ERROR_OK) { + *feature_list = NULL; + return retval; + } + + /* Start with only one element */ + *feature_list = calloc(1, sizeof(char *)); + + for (i = 0; i < reg_list_size; i++) { + if (reg_list[i]->feature != NULL && strcmp(reg_list[i]->feature, "")) { + /* We found a feature, check if the feature is already in the + * table. If not, allocate a new entry for the table and + * put the new feature in it. + */ + for (j = 0; j < (tbl_sz + 1); j++) { + if (!((*feature_list)[j])) { + (*feature_list)[tbl_sz++] = strdup(reg_list[i]->feature); + *feature_list = realloc(*feature_list, sizeof(char *) * (tbl_sz + 1)); + (*feature_list)[tbl_sz] = NULL; + break; + } else { + if (!strcmp((*feature_list)[j], reg_list[i]->feature)) + break; + } + } + } + } + + free(reg_list); + + return tbl_sz; +} + +/* Returns how many registers don't have a feature specified */ +int count_reg_without_group(struct target *target) +{ + struct reg **reg_list; + int reg_list_size; + int retval; + int i; + int reg_without_group = 0; + + retval = target_get_gdb_reg_list(target, ®_list, ®_list_size); + if (retval != ERROR_OK) + return retval; + + for (i = 0; i < reg_list_size; i++) { + if ((reg_list[i]->feature != NULL && + !strcmp(reg_list[i]->feature, "")) || + reg_list[i]->feature == NULL) { + reg_without_group++; + } + } + + free(reg_list); + + return reg_without_group; +} + +/* Open a file for write, set the header of the file according to the + * gdb target description format and configure the architecture element with + * the given arch_name. + */ +int open_and_init_tdesc_file(struct fileio *fileio, const char *filename, + const char *arch_name) +{ + int retval; + + retval = fileio_open(fileio, filename, FILEIO_WRITE, FILEIO_TEXT); + if (retval != ERROR_OK) + return ERROR_FAIL; + + fileio_fprintf(fileio, "<?xml version=\"1.0\"?>\n"); + fileio_fprintf(fileio, "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">\n"); + fileio_fprintf(fileio, "<target>\n"); + fileio_fprintf(fileio, " <architecture>%s</architecture>\n\n", arch_name); + + return ERROR_OK; +} + +/* Close a target descriptor file */ +int close_tdesc_file(struct fileio *fileio) +{ + fileio_fprintf(fileio, "</target>\n"); + fileio_close(fileio); + + return ERROR_OK; +} diff --git a/src/target/tdesc.h b/src/target/tdesc.h new file mode 100644 index 0000000..52ad6f0 --- /dev/null +++ b/src/target/tdesc.h @@ -0,0 +1,41 @@ +/*************************************************************************** + * Copyright (C) 2012 by Franck Jullien * + * [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 * + * (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, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef TDESC_H +#define TDESC_H + +#include "register.h" +#include "target.h" +#include "target_type.h" +#include "fileio.h" + +int generate_feature_section(struct target *target, struct fileio *fileio, + const char *arch_name, const char *feature_name) + +int get_reg_features_list(struct target *target, char **feature_list[]); + +int count_reg_without_group(struct target *target); + +int open_and_init_tdesc_file(struct fileio *fileio, const char *filename, + const char *arch_name); + +int close_tdesc_file(struct fileio *fileio); + +#endif -- ------------------------------------------------------------------------------ LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial Remotely access PCs and mobile devices and provide instant support Improve your efficiency, and focus on delivering more value-add services Discover what IT Professionals Know. Rescue delivers http://p.sf.net/sfu/logmein_12329d2d _______________________________________________ OpenOCD-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openocd-devel
