1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2016 by Matthias Welwarsky <matthias.welwarsky@sysgo.com>
12 #include "target_type.h"
13 #include "arm_adi_v5.h"
16 #include <jtag/jtag.h>
18 #define MEM_AP_COMMON_MAGIC 0x4DE4DA50
22 struct adiv5_dap
*dap
;
27 static int mem_ap_target_create(struct target
*target
, Jim_Interp
*interp
)
29 struct mem_ap
*mem_ap
;
30 struct adiv5_private_config
*pc
;
32 pc
= (struct adiv5_private_config
*)target
->private_config
;
36 if (pc
->ap_num
== DP_APSEL_INVALID
) {
37 LOG_ERROR("AP number not specified");
41 mem_ap
= calloc(1, sizeof(struct mem_ap
));
43 LOG_ERROR("Out of memory");
47 mem_ap
->ap_num
= pc
->ap_num
;
48 mem_ap
->common_magic
= MEM_AP_COMMON_MAGIC
;
49 mem_ap
->dap
= pc
->dap
;
51 target
->arch_info
= mem_ap
;
53 if (!target
->gdb_port_override
)
54 target
->gdb_port_override
= strdup("disabled");
59 static int mem_ap_init_target(struct command_context
*cmd_ctx
, struct target
*target
)
61 LOG_DEBUG("%s", __func__
);
62 target
->state
= TARGET_UNKNOWN
;
63 target
->debug_reason
= DBG_REASON_UNDEFINED
;
67 static void mem_ap_deinit_target(struct target
*target
)
69 struct mem_ap
*mem_ap
= target
->arch_info
;
71 LOG_DEBUG("%s", __func__
);
74 dap_put_ap(mem_ap
->ap
);
76 free(target
->private_config
);
77 free(target
->arch_info
);
81 static int mem_ap_arch_state(struct target
*target
)
83 LOG_DEBUG("%s", __func__
);
87 static int mem_ap_poll(struct target
*target
)
89 if (target
->state
== TARGET_UNKNOWN
) {
90 target
->state
= TARGET_RUNNING
;
91 target
->debug_reason
= DBG_REASON_NOTHALTED
;
97 static int mem_ap_halt(struct target
*target
)
99 LOG_DEBUG("%s", __func__
);
100 target
->state
= TARGET_HALTED
;
101 target
->debug_reason
= DBG_REASON_DBGRQ
;
102 target_call_event_callbacks(target
, TARGET_EVENT_HALTED
);
106 static int mem_ap_resume(struct target
*target
, int current
, target_addr_t address
,
107 int handle_breakpoints
, int debug_execution
)
109 LOG_DEBUG("%s", __func__
);
110 target
->state
= TARGET_RUNNING
;
111 target
->debug_reason
= DBG_REASON_NOTHALTED
;
115 static int mem_ap_step(struct target
*target
, int current
, target_addr_t address
,
116 int handle_breakpoints
)
118 LOG_DEBUG("%s", __func__
);
119 target
->state
= TARGET_HALTED
;
120 target
->debug_reason
= DBG_REASON_DBGRQ
;
121 target_call_event_callbacks(target
, TARGET_EVENT_HALTED
);
125 static int mem_ap_assert_reset(struct target
*target
)
127 target
->state
= TARGET_RESET
;
128 target
->debug_reason
= DBG_REASON_UNDEFINED
;
130 LOG_DEBUG("%s", __func__
);
134 static int mem_ap_examine(struct target
*target
)
136 struct mem_ap
*mem_ap
= target
->arch_info
;
138 if (!target_was_examined(target
)) {
140 mem_ap
->ap
= dap_get_ap(mem_ap
->dap
, mem_ap
->ap_num
);
142 LOG_ERROR("Cannot get AP");
146 target_set_examined(target
);
147 target
->state
= TARGET_UNKNOWN
;
148 target
->debug_reason
= DBG_REASON_UNDEFINED
;
149 return mem_ap_init(mem_ap
->ap
);
155 static int mem_ap_deassert_reset(struct target
*target
)
157 if (target
->reset_halt
) {
158 target
->state
= TARGET_HALTED
;
159 target
->debug_reason
= DBG_REASON_DBGRQ
;
160 target_call_event_callbacks(target
, TARGET_EVENT_HALTED
);
162 target
->state
= TARGET_RUNNING
;
163 target
->debug_reason
= DBG_REASON_NOTHALTED
;
166 LOG_DEBUG("%s", __func__
);
170 static int mem_ap_reg_get(struct reg
*reg
)
175 static int mem_ap_reg_set(struct reg
*reg
, uint8_t *buf
)
180 static struct reg_arch_type mem_ap_reg_arch_type
= {
181 .get
= mem_ap_reg_get
,
182 .set
= mem_ap_reg_set
,
185 static const char *mem_ap_get_gdb_arch(const struct target
*target
)
191 * Dummy ARM register emulation:
192 * reg[0..15]: 32 bits, r0~r12, sp, lr, pc
193 * reg[16..23]: 96 bits, f0~f7
194 * reg[24]: 32 bits, fps
195 * reg[25]: 32 bits, cpsr
197 * GDB requires only reg[0..15]
200 #define NUM_GDB_REGS 16
201 #define MAX_REG_SIZE 96
202 #define REG_SIZE(n) ((((n) >= 16) && ((n) < 24)) ? 96 : 32)
204 struct mem_ap_alloc_reg_list
{
205 /* reg_list must be the first field */
206 struct reg
*reg_list
[NUM_REGS
];
207 struct reg regs
[NUM_REGS
];
208 uint8_t regs_value
[MAX_REG_SIZE
/ 8];
211 static int mem_ap_get_gdb_reg_list(struct target
*target
, struct reg
**reg_list
[],
212 int *reg_list_size
, enum target_register_class reg_class
)
214 struct mem_ap_alloc_reg_list
*mem_ap_alloc
= calloc(1, sizeof(struct mem_ap_alloc_reg_list
));
216 LOG_ERROR("Out of memory");
220 *reg_list
= mem_ap_alloc
->reg_list
;
221 *reg_list_size
= (reg_class
== REG_CLASS_ALL
) ? NUM_REGS
: NUM_GDB_REGS
;
222 struct reg
*regs
= mem_ap_alloc
->regs
;
224 for (int i
= 0; i
< NUM_REGS
; i
++) {
226 regs
[i
].value
= mem_ap_alloc
->regs_value
;
227 regs
[i
].size
= REG_SIZE(i
);
228 regs
[i
].exist
= true;
229 regs
[i
].type
= &mem_ap_reg_arch_type
;
230 (*reg_list
)[i
] = ®s
[i
];
236 static int mem_ap_read_memory(struct target
*target
, target_addr_t address
,
237 uint32_t size
, uint32_t count
, uint8_t *buffer
)
239 struct mem_ap
*mem_ap
= target
->arch_info
;
241 LOG_DEBUG("Reading memory at physical address " TARGET_ADDR_FMT
242 "; size %" PRIu32
"; count %" PRIu32
, address
, size
, count
);
244 if (count
== 0 || !buffer
)
245 return ERROR_COMMAND_SYNTAX_ERROR
;
247 return mem_ap_read_buf(mem_ap
->ap
, buffer
, size
, count
, address
);
250 static int mem_ap_write_memory(struct target
*target
, target_addr_t address
,
251 uint32_t size
, uint32_t count
,
252 const uint8_t *buffer
)
254 struct mem_ap
*mem_ap
= target
->arch_info
;
256 LOG_DEBUG("Writing memory at physical address " TARGET_ADDR_FMT
257 "; size %" PRIu32
"; count %" PRIu32
, address
, size
, count
);
259 if (count
== 0 || !buffer
)
260 return ERROR_COMMAND_SYNTAX_ERROR
;
262 return mem_ap_write_buf(mem_ap
->ap
, buffer
, size
, count
, address
);
265 struct target_type mem_ap_target
= {
268 .target_create
= mem_ap_target_create
,
269 .init_target
= mem_ap_init_target
,
270 .deinit_target
= mem_ap_deinit_target
,
271 .examine
= mem_ap_examine
,
272 .target_jim_configure
= adiv5_jim_configure
,
275 .arch_state
= mem_ap_arch_state
,
278 .resume
= mem_ap_resume
,
281 .assert_reset
= mem_ap_assert_reset
,
282 .deassert_reset
= mem_ap_deassert_reset
,
284 .get_gdb_arch
= mem_ap_get_gdb_arch
,
285 .get_gdb_reg_list
= mem_ap_get_gdb_reg_list
,
287 .read_memory
= mem_ap_read_memory
,
288 .write_memory
= mem_ap_write_memory
,
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)