target/arc: introduce arc_read/write_instruction functions
[fw/openocd] / src / target / arc.h
index 311648e15e93d9f5eee377ba6380e9e4a56c3704..55a1ead21f9646a6946b9afa6906a33f47e604c8 100644 (file)
 #define AUX_PC_REG                      0x6
 #define AUX_STATUS32_REG                0xA
 
+
 #define SET_CORE_FORCE_HALT             BIT(1)
 #define SET_CORE_HALT_BIT               BIT(0)      /* STATUS32[0] = H field */
-#define SET_CORE_ENABLE_INTERRUPTS                     BIT(31)
+#define SET_CORE_ENABLE_INTERRUPTS      BIT(31)
+/* STATUS32[5] or AE bit indicates if the processor is in exception state */
+#define SET_CORE_AE_BIT                 BIT(5)
+/* Single instruction step bit in Debug register */
+#define SET_CORE_SINGLE_INSTR_STEP      BIT(11)
 
 #define AUX_STATUS32_REG_HALT_BIT       BIT(0)
 #define AUX_STATUS32_REG_IE_BIT         BIT(31)    /* STATUS32[31] = IE field */
@@ -61,6 +66,10 @@ struct arc_reg_data_type {
        struct reg_data_type_struct data_type_struct;
        char data_type_id[REG_TYPE_MAX_NAME_LENGTH];
        struct arc_reg_bitfield *bitfields;
+       union {
+               struct reg_data_type_struct_field *reg_type_struct_field;
+               struct reg_data_type_flags_field *reg_type_flags_field;
+       };
 };
 
 
@@ -151,6 +160,29 @@ static inline struct arc_common *target_to_arc(struct target *target)
        return target->arch_info;
 }
 
+/* ----- Inlined functions ------------------------------------------------- */
+
+/**
+ * Convert data in host endianness to the middle endian. This is required to
+ * write 4-byte instructions.
+ */
+static inline void arc_h_u32_to_me(uint8_t *buf, int val)
+{
+       buf[1] = (uint8_t) (val >> 24);
+       buf[0] = (uint8_t) (val >> 16);
+       buf[3] = (uint8_t) (val >> 8);
+       buf[2] = (uint8_t) (val >> 0);
+}
+
+/**
+ * Convert data in middle endian to host endian. This is required to read 32-bit
+ * instruction from little endian ARCs.
+ */
+static inline uint32_t arc_me_to_h_u32(const uint8_t *buf)
+{
+       return (uint32_t)(buf[2] | buf[3] << 8 | buf[0] << 16 | buf[1] << 24);
+}
+
 
 /* ARC Register description */
 struct arc_reg_desc {