Complete patch w/arm926ejs example implementation.


-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 ARM11 XScale Cortex
JTAG debugger and flash programmer
diff --git a/src/target/arm926ejs.c b/src/target/arm926ejs.c
index 9c9628a..f4984a5 100644
--- a/src/target/arm926ejs.c
+++ b/src/target/arm926ejs.c
@@ -2,7 +2,7 @@
  *   Copyright (C) 2007 by Dominic Rath                                    *
  *   dominic.r...@gmx.de                                                   *
  *                                                                         *
- *   Copyright (C) 2009 by Øyvind Harboe                                   *
+ *   Copyright (C) 2007,2008,2009 by Øyvind Harboe                         *
  *   oyvind.har...@zylin.com                                               *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -52,6 +52,29 @@ int arm926ejs_write_phys_memory(struct target_s *target, 
uint32_t address, uint3
 static int arm926ejs_virt2phys(struct target_s *target, uint32_t virtual, 
uint32_t *physical);
 static int arm926ejs_mmu(struct target_s *target, int *enabled);
 
+int arm926ejs_cp15_read(target_t *target, uint32_t op1, uint32_t op2, uint32_t 
CRn, uint32_t CRm, uint32_t *value);
+int arm926ejs_cp15_write(target_t *target, uint32_t op1, uint32_t op2, 
uint32_t CRn, uint32_t CRm, uint32_t value);
+
+static int arm926ejs_mrc(target_t *target, int cpnum, uint32_t op1, uint32_t 
op2, uint32_t CRn, uint32_t CRm, uint32_t *value)
+{
+       if (cpnum!=15)
+       {
+               LOG_ERROR("Only cp15 is supported");
+               return ERROR_FAIL;
+       }
+       return arm926ejs_cp15_read(target, op1, op2, CRn, CRm, value);
+}
+
+static int arm926ejs_mcr(target_t *target, int cpnum, uint32_t op1, uint32_t 
op2, uint32_t CRn, uint32_t CRm, uint32_t value)
+{
+       if (cpnum!=15)
+       {
+               LOG_ERROR("Only cp15 is supported");
+               return ERROR_FAIL;
+       }
+       return arm926ejs_cp15_write(target, op1, op2, CRn, CRm, value);
+}
+
 target_type_t arm926ejs_target =
 {
        .name = "arm926ejs",
@@ -94,6 +117,8 @@ target_type_t arm926ejs_target =
 
        .read_phys_memory = arm926ejs_read_phys_memory,
        .write_phys_memory = arm926ejs_write_phys_memory,
+       .mrc = arm926ejs_mrc,
+       .mcr = arm926ejs_mcr,
 };
 
 int arm926ejs_catch_broken_irscan(uint8_t *captured, void *priv, scan_field_t 
*field)
diff --git a/src/target/target.c b/src/target/target.c
index 4516207..bed1633 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -687,6 +687,60 @@ void target_reset_examined(struct target_s *target)
 }
 
 
+
+static int default_mrc(struct target_s *target, int cpnum, uint32_t op1, 
uint32_t op2, uint32_t CRn, uint32_t CRm, uint32_t *value)
+{
+       LOG_ERROR("Not implemented");
+       return ERROR_FAIL;
+}
+
+static int default_mcr(struct target_s *target, int cpnum, uint32_t op1, 
uint32_t op2, uint32_t CRn, uint32_t CRm, uint32_t value)
+{
+       LOG_ERROR("Not implemented");
+       return ERROR_FAIL;
+}
+
+static int arm_cp_check(struct target_s *target, int cpnum, uint32_t op1, 
uint32_t op2, uint32_t CRn, uint32_t CRm)
+{
+       /* basic check */
+       if (!target_was_examined(target))
+       {
+               LOG_ERROR("Target not examined yet");
+               return ERROR_FAIL;
+       }
+
+       if ((cpnum <0) || (cpnum > 15))
+       {
+               LOG_ERROR("Illegal co-processor %d", cpnum);
+               return ERROR_FAIL;
+       }
+
+       return ERROR_OK;
+}
+
+int target_mrc(struct target_s *target, int cpnum, uint32_t op1, uint32_t op2, 
uint32_t CRn, uint32_t CRm, uint32_t *value)
+{
+       int retval;
+
+       retval = arm_cp_check(target, cpnum, op1, op2, CRn, CRm);
+       if (retval != ERROR_OK)
+               return retval;
+
+       return target->type->mrc(target, cpnum, op1, op2, CRn, CRm, value);
+}
+
+int target_mcr(struct target_s *target, int cpnum, uint32_t op1, uint32_t op2, 
uint32_t CRn, uint32_t CRm, uint32_t value)
+{
+       int retval;
+
+       retval = arm_cp_check(target, cpnum, op1, op2, CRn, CRm);
+       if (retval != ERROR_OK)
+               return retval;
+
+       return target->type->mcr(target, cpnum, op1, op2, CRn, CRm, value);
+}
+
+
 int target_init(struct command_context_s *cmd_ctx)
 {
        target_t *target = all_targets;
@@ -722,6 +776,17 @@ int target_init(struct command_context_s *cmd_ctx)
                        target->type->write_phys_memory = 
target->type->write_memory;
                }
 
+               if (target->type->mcr == NULL)
+               {
+                       target->type->mcr = default_mcr;
+               }
+
+               if (target->type->mrc == NULL)
+               {
+                       target->type->mrc = default_mrc;
+               }
+
+
                /* a non-invasive way(in terms of patches) to add some code that
                 * runs before the type->write/read_memory implementation
                 */
diff --git a/src/target/target.h b/src/target/target.h
index 19d8013..ef57837 100644
--- a/src/target/target.h
+++ b/src/target/target.h
@@ -2,7 +2,7 @@
  *   Copyright (C) 2005 by Dominic Rath                                    *
  *   dominic.r...@gmx.de                                                   *
  *                                                                         *
- *   Copyright (C) 2007,2008 Øyvind Harboe                                 *
+ *   Copyright (C) 2007,2008,2009 Øyvind Harboe                            *
  *   oyvind.har...@zylin.com                                               *
  *                                                                         *
  *   Copyright (C) 2008 by Spencer Oliver                                  *
diff --git a/src/target/target_type.h b/src/target/target_type.h
index aab4321..83baa25 100644
--- a/src/target/target_type.h
+++ b/src/target/target_type.h
@@ -2,7 +2,7 @@
  *   Copyright (C) 2005 by Dominic Rath                                    *
  *   dominic.r...@gmx.de                                                   *
  *                                                                         *
- *   Copyright (C) 2007,2008 Øyvind Harboe                                 *
+ *   Copyright (C) 2007,2008,2009 Øyvind Harboe                            *
  *   oyvind.har...@zylin.com                                               *
  *                                                                         *
  *   Copyright (C) 2008 by Spencer Oliver                                  *
@@ -202,6 +202,11 @@ struct target_type_s
 
        int (*mmu)(struct target_s *target, int *enabled);
 
+       /* Read coprocessor - arm specific. Default implementation returns 
error. */
+       int (*mrc)(struct target_s *target, int cpnum, uint32_t op1, uint32_t 
op2, uint32_t CRn, uint32_t CRm, uint32_t *value);
+
+       /* Write coprocessor. Default implementation returns error.  */
+       int (*mcr)(struct target_s *target, int cpnum, uint32_t op1, uint32_t 
op2, uint32_t CRn, uint32_t CRm, uint32_t value);
 };
 
 #endif // TARGET_TYPE_H
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to