+static int mem_ap_reg_get(struct reg *reg)
+{
+ return ERROR_OK;
+}
+
+static int mem_ap_reg_set(struct reg *reg, uint8_t *buf)
+{
+ return ERROR_OK;
+}
+
+static struct reg_arch_type mem_ap_reg_arch_type = {
+ .get = mem_ap_reg_get,
+ .set = mem_ap_reg_set,
+};
+
+const char *mem_ap_get_gdb_arch(struct target *target)
+{
+ return "arm";
+}
+
+/*
+ * Dummy ARM register emulation:
+ * reg[0..15]: 32 bits, r0~r12, sp, lr, pc
+ * reg[16..23]: 96 bits, f0~f7
+ * reg[24]: 32 bits, fps
+ * reg[25]: 32 bits, cpsr
+ *
+ * Set 'exist' only to reg[0..15], so initial response to GDB is correct
+ */
+#define NUM_REGS 26
+#define MAX_REG_SIZE 96
+#define REG_EXIST(n) ((n) < 16)
+#define REG_SIZE(n) ((((n) >= 16) && ((n) < 24)) ? 96 : 32)
+
+struct mem_ap_alloc_reg_list {
+ /* reg_list must be the first field */
+ struct reg *reg_list[NUM_REGS];
+ struct reg regs[NUM_REGS];
+ uint8_t regs_value[MAX_REG_SIZE / 8];
+};
+
+static int mem_ap_get_gdb_reg_list(struct target *target, struct reg **reg_list[],
+ int *reg_list_size, enum target_register_class reg_class)
+{
+ struct mem_ap_alloc_reg_list *mem_ap_alloc = calloc(1, sizeof(struct mem_ap_alloc_reg_list));
+ if (!mem_ap_alloc) {
+ LOG_ERROR("Out of memory");
+ return ERROR_FAIL;
+ }
+
+ *reg_list = mem_ap_alloc->reg_list;
+ *reg_list_size = NUM_REGS;
+ struct reg *regs = mem_ap_alloc->regs;
+
+ for (int i = 0; i < NUM_REGS; i++) {
+ regs[i].number = i;
+ regs[i].value = mem_ap_alloc->regs_value;
+ regs[i].size = REG_SIZE(i);
+ regs[i].exist = REG_EXIST(i);
+ regs[i].type = &mem_ap_reg_arch_type;
+ (*reg_list)[i] = ®s[i];
+ }
+
+ return ERROR_OK;
+}
+