OpenOCD
esp_algorithm.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /***************************************************************************
4  * Espressif chips common algorithm API for OpenOCD *
5  * Copyright (C) 2022 Espressif Systems Ltd. *
6  ***************************************************************************/
7 
8 #ifndef OPENOCD_TARGET_ESP_ALGORITHM_H
9 #define OPENOCD_TARGET_ESP_ALGORITHM_H
10 
11 #include "helper/log.h"
12 #include "helper/binarybuffer.h"
13 #include <helper/time_support.h>
14 #include <target/algorithm.h>
15 #include <target/image.h>
16 
119  struct image image;
121  uint32_t bss_size;
123  uint32_t iram_org;
125  uint32_t iram_len;
127  uint32_t dram_org;
129  uint32_t dram_len;
131  bool reverse;
132 };
133 
134 #define ESP_IMAGE_ELF_PHF_EXEC 0x1
135 
163  uint32_t log_buff_size;
165  void *ainfo;
166 };
167 
173  struct mem_param *params;
175  uint32_t count;
176 };
177 
183  struct reg_param *params;
185  uint32_t count;
189 };
190 
192 
202 typedef int (*esp_algorithm_func_t)(struct target *target, struct esp_algorithm_run_data *run, void *arg);
203 
214 typedef int (*esp_algorithm_usr_func_t)(struct target *target, void *usr_arg);
215 
229  struct esp_algorithm_run_data *run,
230  void *usr_arg);
231 
244  struct esp_algorithm_run_data *run,
245  void *usr_arg);
246 
248  int (*algo_init)(struct target *target, struct esp_algorithm_run_data *run, uint32_t num_args, va_list ap);
249  int (*algo_cleanup)(struct target *target, struct esp_algorithm_run_data *run);
250  const uint8_t *(*stub_tramp_get)(struct target *target, size_t *size);
251 };
252 
258  uint32_t timeout_ms;
260  uint32_t stack_size;
266  void *arch_info;
268  int32_t ret_code;
270  struct esp_algorithm_stub stub;
271  union {
272  struct {
274  uint32_t code_buf_size;
278  uint32_t min_stack_size;
282  struct esp_algorithm_image image;
283  };
295  const struct esp_algorithm_hw *hw;
296 };
297 
300 
302  struct esp_algorithm_run_data *run,
303  uint32_t num_args,
304  va_list ap);
305 
317  struct esp_algorithm_run_data *run,
318  uint32_t num_args,
319  va_list ap)
320 {
321  int ret = esp_algorithm_load_func_image(target, run);
322  if (ret != ERROR_OK)
323  return ret;
324  ret = esp_algorithm_exec_func_image_va(target, run, num_args, ap);
326  return ret != ERROR_OK ? ret : rc;
327 }
328 
329 static inline int esp_algorithm_run_func_image(struct target *target,
330  struct esp_algorithm_run_data *run,
331  uint32_t num_args,
332  ...)
333 {
334  va_list ap;
335  va_start(ap, num_args);
336  int retval = esp_algorithm_run_func_image_va(target, run, num_args, ap);
337  va_end(ap);
338  return retval;
339 }
340 
342  target_addr_t func_addr,
343  struct esp_algorithm_run_data *run);
346  struct esp_algorithm_run_data *run,
347  uint32_t num_args,
348  va_list ap);
349 
362  struct esp_algorithm_run_data *run,
363  target_addr_t func_addr,
364  uint32_t num_args,
365  va_list ap)
366 {
367  int ret = esp_algorithm_load_onboard_func(target, func_addr, run);
368  if (ret != ERROR_OK)
369  return ret;
370  ret = esp_algorithm_exec_onboard_func_va(target, run, num_args, ap);
371  if (ret != ERROR_OK)
372  return ret;
374 }
375 
376 static inline int esp_algorithm_run_onboard_func(struct target *target,
377  struct esp_algorithm_run_data *run,
378  target_addr_t func_addr,
379  uint32_t num_args,
380  ...)
381 {
382  va_list ap;
383  va_start(ap, num_args);
384  int retval = esp_algorithm_run_onboard_func_va(target, run, func_addr, num_args, ap);
385  va_end(ap);
386  return retval;
387 }
388 
393  int arg_num,
394  uint64_t val)
395 {
396  struct reg_param *param = &run->reg_args.params[run->reg_args.first_user_param + arg_num];
397 
398  assert(param->size <= 64);
399 
400  if (param->size <= 32)
401  buf_set_u32(param->value, 0, param->size, val);
402  else
403  buf_set_u64(param->value, 0, param->size, val);
404 }
405 
409 static inline uint64_t esp_algorithm_user_arg_get_uint(struct esp_algorithm_run_data *run, int arg_num)
410 {
411  struct reg_param *param = &run->reg_args.params[run->reg_args.first_user_param + arg_num];
412 
413  assert(param->size <= 64);
414 
415  if (param->size <= 32)
416  return buf_get_u32(param->value, 0, param->size);
417  return buf_get_u64(param->value, 0, param->size);
418 }
419 
420 #endif /* OPENOCD_TARGET_ESP_ALGORITHM_H */
Support functions to access arbitrary bits in a byte array.
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
Definition: binarybuffer.h:104
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:34
static uint64_t buf_get_u64(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 64-bit word.
Definition: binarybuffer.h:134
static void buf_set_u64(uint8_t *_buffer, unsigned int first, unsigned int num, uint64_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:65
static int esp_algorithm_run_onboard_func(struct target *target, struct esp_algorithm_run_data *run, target_addr_t func_addr, uint32_t num_args,...)
int esp_algorithm_exec_onboard_func_va(struct target *target, struct esp_algorithm_run_data *run, uint32_t num_args, va_list ap)
static uint64_t esp_algorithm_user_arg_get_uint(struct esp_algorithm_run_data *run, int arg_num)
Get the value of an argument passed via registers from the stub main function.
static int esp_algorithm_run_func_image_va(struct target *target, struct esp_algorithm_run_data *run, uint32_t num_args, va_list ap)
Loads and runs stub from specified image.
static int esp_algorithm_run_onboard_func_va(struct target *target, struct esp_algorithm_run_data *run, target_addr_t func_addr, uint32_t num_args, va_list ap)
Runs pre-compiled on-board function.
void(* esp_algorithm_usr_func_done_t)(struct target *target, struct esp_algorithm_run_data *run, void *usr_arg)
Algorithm's arguments cleanup function.
int esp_algorithm_load_func_image(struct target *target, struct esp_algorithm_run_data *run)
int(* esp_algorithm_usr_func_t)(struct target *target, void *usr_arg)
Host part of algorithm.
int esp_algorithm_unload_onboard_func(struct target *target, struct esp_algorithm_run_data *run)
int esp_algorithm_unload_func_image(struct target *target, struct esp_algorithm_run_data *run)
int(* esp_algorithm_func_t)(struct target *target, struct esp_algorithm_run_data *run, void *arg)
Algorithm run function.
int(* esp_algorithm_usr_func_init_t)(struct target *target, struct esp_algorithm_run_data *run, void *usr_arg)
Algorithm's arguments setup function.
static int esp_algorithm_run_func_image(struct target *target, struct esp_algorithm_run_data *run, uint32_t num_args,...)
int esp_algorithm_exec_func_image_va(struct target *target, struct esp_algorithm_run_data *run, uint32_t num_args, va_list ap)
int esp_algorithm_load_onboard_func(struct target *target, target_addr_t func_addr, struct esp_algorithm_run_data *run)
static void esp_algorithm_user_arg_set_uint(struct esp_algorithm_run_data *run, int arg_num, uint64_t val)
Set the value of an argument passed via registers to the stub main function.
#define ERROR_OK
Definition: log.h:164
struct target * target
Definition: rtt/rtt.c:26
size_t size
Size of the control block search area.
Definition: rtt/rtt.c:30
int(* algo_init)(struct target *target, struct esp_algorithm_run_data *run, uint32_t num_args, va_list ap)
int(* algo_cleanup)(struct target *target, struct esp_algorithm_run_data *run)
API defined below allows executing pieces of code on target without breaking the execution of the run...
uint32_t iram_len
Total reserved IRAM size.
bool reverse
IRAM DRAM address range reversed or not.
uint32_t bss_size
BSS section size.
uint32_t dram_len
Total reserved DRAM size.
uint32_t dram_org
DRAM start address in the linker script.
uint32_t iram_org
IRAM start address in the linker script.
Algorithm stub in-memory arguments.
uint32_t count
Number of memory params.
struct mem_param * params
Memory params.
Algorithm stub register arguments.
struct reg_param * params
Algorithm register params.
uint32_t first_user_param
The first several reg_params can be used by stub itself (e.g.
uint32_t count
Number of register params.
Algorithm run data.
struct esp_algorithm_run_data::@96::@98 on_board
target_addr_t min_stack_addr
Pre-compiled target buffer's addr for stack.
struct esp_algorithm_reg_args reg_args
Algorithm register arguments.
struct esp_algorithm_mem_args mem_args
Algorithm memory arguments.
esp_algorithm_usr_func_init_t usr_func_init
Host side algorithm function setup routine.
esp_algorithm_usr_func_t usr_func
Host side algorithm function.
void * usr_func_arg
Host side algorithm function argument.
void * arch_info
Algorithm arch-specific info.
uint32_t timeout_ms
Algorithm completion timeout in ms.
const struct esp_algorithm_hw * hw
HW specific API.
esp_algorithm_usr_func_done_t usr_func_done
Host side algorithm function cleanup routine.
struct esp_algorithm_stub stub
Stub.
uint32_t min_stack_size
Size of the pre-alocated on-board buffer for stub's stack.
uint32_t stack_size
Algorithm stack size.
int32_t ret_code
Algorithm return code.
target_addr_t code_buf_addr
Address of pre-compiled target buffer for stub trampoline.
esp_algorithm_func_t algo_func
Algorithm run function: see algorithm_run_xxx for example.
uint32_t code_buf_size
Size of the pre-alocated on-board buffer for stub's code.
Algorithm stub data.
target_addr_t stack_addr
Address of the target buffer for stack.
target_addr_t tramp_addr
Address of the target buffer for stub trampoline.
void * ainfo
Algorithm's arch-specific info.
uint32_t log_buff_size
Size of the log buffer.
struct working_area * padding
Working area for padding between code and data area.
target_addr_t tramp_mapped_addr
Tramp code area will be filled from dbus.
struct working_area * data
Working area for data segment.
struct working_area * tramp
Working area for trampoline.
target_addr_t log_buff_addr
Address of the log buffer.
struct working_area * stack
Working area for stack.
target_addr_t entry
Entry addr.
struct working_area * code
Working area for code segment.
Definition: image.h:48
uint32_t size
Definition: algorithm.h:29
uint8_t * value
Definition: algorithm.h:30
Definition: target.h:116
uint64_t target_addr_t
Definition: types.h:335