Hello,

this patch add the risc (default) and harvard architecture to the target 
structure. Currently
this patch only affect the memory read/write functions.



Regards,

Mathias

From dbfc2e3b9473a9cfb48c3e6e651be7152f32748b Mon Sep 17 00:00:00 2001
From: Mathias K. <[email protected]>
Date: Thu, 24 Feb 2011 09:31:37 +0100
Subject: [PATCH] target: add target architecture risc and harvard

This patch separate the target architecture into risc and
harvard (default risc). This will solve the alignmend problem
on memory read/write access. On harvard architecture this
should be done in the target implementation.
---
 src/target/target.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/target/target.h |    8 +++++++
 2 files changed, 62 insertions(+), 1 deletions(-)

diff --git a/src/target/target.c b/src/target/target.c
index 3a6c6bb..025a50d 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -220,6 +220,12 @@ static const Jim_Nvp nvp_target_endian[] = {
        { .name = NULL,     .value = -1 },
 };
 
+static const Jim_Nvp nvp_target_architecture[] = {
+       { .name = "risc",    .value = TARGET_ARCH_RISC },
+       { .name = "harvard", .value = TARGET_ARCH_HARVARD },
+       { .name = NULL,     .value = -1 },
+};
+
 static const Jim_Nvp nvp_reset_modes[] = {
        { .name = "unknown", .value = RESET_UNKNOWN },
        { .name = "run"    , .value = RESET_RUN },
@@ -1356,6 +1362,14 @@ int target_write_buffer(struct target *target, uint32_t 
address, uint32_t size,
                return ERROR_FAIL;
        }
 
+       /* on harvard architecture we handle all parameters
+        * on target implementation
+        */
+       if ( target->architecture == TARGET_ARCH_HARVARD )
+       {
+               return target_write_memory(target, address, 0, size, buffer);
+       }
+
        if (((address % 2) == 0) && (size == 2))
        {
                return target_write_memory(target, address, 2, 1, buffer);
@@ -1438,6 +1452,14 @@ int target_read_buffer(struct target *target, uint32_t 
address, uint32_t size, u
                return ERROR_FAIL;
        }
 
+       /* on harvard architecture we handle all parameters
+        * on target implementation
+        */
+       if ( target->architecture == TARGET_ARCH_HARVARD )
+       {
+               return target_read_memory(target, address, 0, size, buffer);
+       }
+
        if (((address % 2) == 0) && (size == 2))
        {
                return target_read_memory(target, address, 2, 1, buffer);
@@ -3682,6 +3704,7 @@ enum target_cfg_param {
        TCFG_VARIANT,
        TCFG_COREID,
        TCFG_CHAIN_POSITION,
+       TCFG_ARCH,
 };
 
 static Jim_Nvp nvp_config_opts[] = {
@@ -3695,7 +3718,7 @@ static Jim_Nvp nvp_config_opts[] = {
        { .name = "-variant",          .value = TCFG_VARIANT },
        { .name = "-coreid",           .value = TCFG_COREID },
        { .name = "-chain-position",   .value = TCFG_CHAIN_POSITION },
-
+       { .name = "-arch" ,            .value = TCFG_ARCH },
        { .name = NULL, .value = -1 }
 };
 
@@ -3986,6 +4009,28 @@ static int target_configure(Jim_GetOptInfo *goi, struct 
target *target)
                        Jim_SetResultString(goi->interp, 
target->tap->dotted_name, -1);
                        /* loop for more e*/
                        break;
+
+               case TCFG_ARCH:
+                       if (goi->isconfigure) {
+                               e = Jim_GetOpt_Nvp(goi, 
nvp_target_architecture, &n);
+                               if (e != JIM_OK) {
+                                       Jim_GetOpt_NvpUnknown(goi, 
nvp_target_architecture, 1);
+                                       return e;
+                               }
+                               target->architecture = n->value;
+                       } else {
+                               if (goi->argc != 0) {
+                                       goto no_params;
+                               }
+                       }
+                       n = Jim_Nvp_value2name_simple(nvp_target_architecture, 
target->architecture);
+                       if (n->name == NULL) {
+                               target->architecture = TARGET_ARCH_RISC;
+                               n = 
Jim_Nvp_value2name_simple(nvp_target_architecture, target->architecture);
+                       }
+                       Jim_SetResultString(goi->interp, n->name, -1);
+                       /* loop for more */
+                       break;
                }
        } /* while (goi->argc) */
 
@@ -4673,6 +4718,9 @@ static int target_create(Jim_GetOptInfo *goi)
        /* will be set by "-endian" */
        target->endianness = TARGET_ENDIAN_UNKNOWN;
 
+       /* can also be set by "-arch */
+       target->architecture = TARGET_ARCH_UNKNOWN;
+
        /* default to first core, override with -coreid */
        target->coreid = 0;
 
@@ -4729,6 +4777,11 @@ static int target_create(Jim_GetOptInfo *goi)
                target->endianness = TARGET_LITTLE_ENDIAN;
        }
 
+       if (target->architecture == TARGET_ARCH_UNKNOWN) {
+               /* default risc */
+               target->architecture = TARGET_ARCH_RISC;
+       }
+
        /* incase variant is not set */
        if (!target->variant)
                target->variant = strdup("");
diff --git a/src/target/target.h b/src/target/target.h
index 2bf9668..92d48db 100644
--- a/src/target/target.h
+++ b/src/target/target.h
@@ -90,6 +90,13 @@ enum target_endianess
        TARGET_BIG_ENDIAN = 1, TARGET_LITTLE_ENDIAN = 2
 };
 
+enum target_architecture
+{
+       TARGET_ARCH_UNKNOWN = 0,
+       TARGET_ARCH_RISC = 1,
+       TARGET_ARCH_HARVARD = 2
+};
+
 struct working_area
 {
        uint32_t address;
@@ -140,6 +147,7 @@ struct target
        struct working_area *working_areas;/* list of allocated working areas */
        enum target_debug_reason debug_reason;/* reason why the target entered 
debug state */
        enum target_endianess endianness;       /* target endianess */
+       enum target_architecture architecture;  /* target architecture */
        // also see: target_state_name()
        enum target_state state;                        /* the current 
backend-state (running, halted, ...) */
        struct reg_cache *reg_cache;            /* the first register cache of 
the target (core regs) */
-- 
1.7.3.4

_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to