OpenOCD
rtos.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /***************************************************************************
4  * Copyright (C) 2011 by Broadcom Corporation *
5  * Evan Hunter - ehunter@broadcom.com *
6  ***************************************************************************/
7 
8 #ifndef OPENOCD_RTOS_RTOS_H
9 #define OPENOCD_RTOS_RTOS_H
10 
11 #include "server/server.h"
12 #include "target/breakpoints.h"
13 #include "target/target.h"
14 
15 typedef int64_t threadid_t;
16 typedef int64_t symbol_address_t;
17 
18 struct reg;
19 
24  const char *symbol_name;
26  bool optional;
27 };
28 
29 struct thread_detail {
31  bool exists;
34 };
35 
36 struct rtos {
37  const struct rtos_type *type;
38 
40  struct target *target;
41  /* add a context variable instead of global variable */
42  /* The thread currently selected by gdb. */
44  /* The currently selected thread according to the target. */
48  int (*gdb_thread_packet)(struct connection *connection, char const *packet, int packet_size);
49  int (*gdb_target_for_threadid)(struct connection *connection, int64_t thread_id, struct target **p_target);
51 };
52 
53 struct rtos_reg {
54  uint32_t number;
55  uint32_t size;
56  uint8_t value[16];
57 };
58 
59 struct rtos_type {
60  const char *name;
61  bool (*detect_rtos)(struct target *target);
62  int (*create)(struct target *target);
63  int (*smp_init)(struct target *target);
64  int (*update_threads)(struct rtos *rtos);
66  int (*get_thread_reg_list)(struct rtos *rtos, int64_t thread_id,
67  struct rtos_reg **reg_list, int *num_regs);
70  int (*get_thread_reg_value)(struct rtos *rtos, threadid_t thread_id,
71  uint32_t reg_num, uint32_t *size, uint8_t **value);
72  int (*get_symbol_list_to_lookup)(struct symbol_table_elem *symbol_list[]);
73  int (*clean)(struct target *target);
74  char * (*ps_command)(struct target *target);
75  int (*set_reg)(struct rtos *rtos, uint32_t reg_num, uint8_t *reg_value);
76  /* Implement these if different threads in the RTOS can see memory
77  * differently (for instance because address translation might be different
78  * for each thread). */
79  int (*read_buffer)(struct rtos *rtos, target_addr_t address, uint32_t size,
80  uint8_t *buffer);
81  int (*write_buffer)(struct rtos *rtos, target_addr_t address, uint32_t size,
82  const uint8_t *buffer);
89  bool (*needs_fake_step)(struct target *target, int64_t thread_id);
90  /* When a software breakpoint is set, it is set on only one target,
91  * because we assume memory is shared across them. By default this is the
92  * first target in the SMP group. Override this function to have
93  * breakpoint_add() use a different target. */
94  struct target * (*swbp_target)(struct rtos *rtos, target_addr_t address,
95  uint32_t length, enum breakpoint_type type);
96 };
97 
99  unsigned short number; /* register number */
100  signed short offset; /* offset in bytes from stack head, or -1 to indicate
101  * register is not stacked, or -2 to indicate this is the
102  * stack pointer register */
103  unsigned short width_bits;
104 };
105 
107  unsigned char stack_registers_size;
109  unsigned char num_output_registers;
110  /* Some targets require evaluating the stack to determine the
111  * actual stack pointer for a process. If this field is NULL,
112  * just use stacking->stack_registers_size * stack_growth_direction
113  * to calculate adjustment.
114  */
116  const uint8_t *stack_data,
117  const struct rtos_register_stacking *stacking,
118  target_addr_t stack_ptr);
120  /* Optional field for targets which may have to implement their own stack read function.
121  * Because stack format can be weird or stack data needed to be edited before passing to the gdb.
122  */
123  int (*read_stack)(struct target *target,
124  int64_t stack_ptr,
125  const struct rtos_register_stacking *stacking,
126  uint8_t *stack_data);
127 };
128 
129 #define GDB_THREAD_PACKET_NOT_CONSUMED (-40)
130 
131 int rtos_create(struct command_invocation *cmd, struct target *target,
132  const char *rtos_name);
133 void rtos_destroy(struct target *target);
134 int rtos_set_reg(struct connection *connection, int reg_num,
135  uint8_t *reg_value);
137  const struct rtos_register_stacking *stacking,
138  int64_t stack_ptr,
139  struct rtos_reg **reg_list,
140  int *num_regs);
141 int gdb_thread_packet(struct connection *connection, char const *packet, int packet_size);
142 int rtos_thread_packet(struct connection *connection, const char *packet, int packet_size);
143 int rtos_get_gdb_reg(struct connection *connection, int reg_num);
145 int rtos_update_threads(struct target *target);
146 void rtos_free_threadlist(struct rtos *rtos);
147 int rtos_smp_init(struct target *target);
148 /* function for handling symbol access */
149 int rtos_qsymbol(struct connection *connection, char const *packet, int packet_size);
151  uint32_t size, uint8_t *buffer);
153  uint32_t size, const uint8_t *buffer);
154 bool rtos_needs_fake_step(struct target *target, int64_t thread_id);
156  uint32_t length, enum breakpoint_type type);
161 struct rtos *rtos_from_target(struct target *target);
162 
163 // Keep in alphabetic order this list of rtos
164 extern const struct rtos_type chibios_rtos;
165 extern const struct rtos_type chromium_ec_rtos;
166 extern const struct rtos_type ecos_rtos;
167 extern const struct rtos_type embkernel_rtos;
168 extern const struct rtos_type freertos_rtos;
169 extern const struct rtos_type hwthread_rtos;
170 extern const struct rtos_type linux_rtos;
171 extern const struct rtos_type mqx_rtos;
172 extern const struct rtos_type nuttx_rtos;
173 extern const struct rtos_type riot_rtos;
174 extern const struct rtos_type rtkernel_rtos;
175 extern const struct rtos_type threadx_rtos;
176 extern const struct rtos_type ucos_iii_rtos;
177 extern const struct rtos_type zephyr_rtos;
178 
179 #endif /* OPENOCD_RTOS_RTOS_H */
breakpoint_type
Definition: breakpoints.h:17
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint32_t size
Size of dw_spi_transaction::buffer.
Definition: dw-spi-helper.h:4
uint32_t address
Starting address. Sector aligned.
Definition: dw-spi-helper.h:0
uint8_t type
Definition: esp_usb_jtag.c:0
uint8_t length
Definition: esp_usb_jtag.c:1
const struct rtos_type embkernel_rtos
Definition: embkernel.c:29
int rtos_generic_stack_read(struct target *target, const struct rtos_register_stacking *stacking, int64_t stack_ptr, struct rtos_reg **reg_list, int *num_regs)
Definition: rtos.c:655
struct target * rtos_swbp_target(struct target *target, target_addr_t address, uint32_t length, enum breakpoint_type type)
Definition: rtos.c:781
int rtos_thread_packet(struct connection *connection, const char *packet, int packet_size)
Definition: rtos.c:355
int64_t symbol_address_t
Definition: rtos.h:16
int gdb_thread_packet(struct connection *connection, char const *packet, int packet_size)
Definition: rtos.c:150
const struct rtos_type chromium_ec_rtos
Definition: chromium-ec.c:383
const struct rtos_type zephyr_rtos
Definition: zephyr.c:788
int rtos_create(struct command_invocation *cmd, struct target *target, const char *rtos_name)
Definition: rtos.c:100
const struct rtos_type ecos_rtos
Definition: ecos.c:455
const struct rtos_type threadx_rtos
Definition: threadx.c:193
const struct rtos_type hwthread_rtos
Definition: hwthread.c:53
const struct rtos_type freertos_rtos
Definition: freertos.c:82
int rtos_set_reg(struct connection *connection, int reg_num, uint8_t *reg_value)
Definition: rtos.c:641
const struct rtos_type nuttx_rtos
Definition: nuttx.c:396
int rtos_get_gdb_reg_list(struct connection *connection)
Return a list of general registers.
Definition: rtos.c:608
void rtos_destroy(struct target *target)
Definition: rtos.c:145
const struct rtos_type linux_rtos
Definition: linux.c:250
int rtos_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
Definition: rtos.c:766
const struct rtos_type chibios_rtos
Definition: chibios.c:99
int rtos_update_threads(struct target *target)
Definition: rtos.c:732
int rtos_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
Definition: rtos.c:758
int rtos_smp_init(struct target *target)
Definition: rtos.c:40
int64_t threadid_t
Definition: rtos.h:15
const struct rtos_type ucos_iii_rtos
Definition: ucos_iii.c:501
const struct rtos_type riot_rtos
Definition: riot.c:97
bool rtos_needs_fake_step(struct target *target, int64_t thread_id)
Definition: rtos.c:774
const struct rtos_type rtkernel_rtos
Definition: rtkernel.c:375
int rtos_qsymbol(struct connection *connection, char const *packet, int packet_size)
Definition: rtos.c:235
void rtos_free_threadlist(struct rtos *rtos)
Definition: rtos.c:740
struct rtos * rtos_from_target(struct target *target)
Get the RTOS from the target itself, or from one of the targets in the same SMP node,...
Definition: rtos.c:719
int rtos_get_gdb_reg(struct connection *connection, int reg_num)
Look through all registers to find this register.
Definition: rtos.c:551
const struct rtos_type mqx_rtos
Definition: mqx.c:499
struct target * target
Definition: rtt/rtt.c:26
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Definition: command.h:76
Definition: register.h:111
Definition: rtos.h:53
uint32_t number
Definition: rtos.h:54
uint8_t value[16]
Definition: rtos.h:56
uint32_t size
Definition: rtos.h:55
const struct stack_register_offset * register_offsets
Definition: rtos.h:119
unsigned char num_output_registers
Definition: rtos.h:109
target_addr_t(* calculate_process_stack)(struct target *target, const uint8_t *stack_data, const struct rtos_register_stacking *stacking, target_addr_t stack_ptr)
Definition: rtos.h:115
unsigned char stack_registers_size
Definition: rtos.h:107
int(* read_stack)(struct target *target, int64_t stack_ptr, const struct rtos_register_stacking *stacking, uint8_t *stack_data)
Definition: rtos.h:123
signed char stack_growth_direction
Definition: rtos.h:108
Definition: rtos.h:59
int(* create)(struct target *target)
Definition: rtos.h:62
bool(* needs_fake_step)(struct target *target, int64_t thread_id)
Possibly work around an annoying gdb behaviour: when the current thread is changed in gdb,...
Definition: rtos.h:89
int(* get_thread_reg_value)(struct rtos *rtos, threadid_t thread_id, uint32_t reg_num, uint32_t *size, uint8_t **value)
Return the size and value of the specified reg_num.
Definition: rtos.h:70
int(* smp_init)(struct target *target)
Definition: rtos.h:63
int(* update_threads)(struct rtos *rtos)
Definition: rtos.h:64
int(* get_symbol_list_to_lookup)(struct symbol_table_elem *symbol_list[])
Definition: rtos.h:72
const char * name
Definition: rtos.h:60
int(* write_buffer)(struct rtos *rtos, target_addr_t address, uint32_t size, const uint8_t *buffer)
Definition: rtos.h:81
int(* clean)(struct target *target)
Definition: rtos.h:73
int(* read_buffer)(struct rtos *rtos, target_addr_t address, uint32_t size, uint8_t *buffer)
Definition: rtos.h:79
bool(* detect_rtos)(struct target *target)
Definition: rtos.h:61
int(* get_thread_reg_list)(struct rtos *rtos, int64_t thread_id, struct rtos_reg **reg_list, int *num_regs)
Return a list of general registers, with their values filled out.
Definition: rtos.h:66
int(* set_reg)(struct rtos *rtos, uint32_t reg_num, uint8_t *reg_value)
Definition: rtos.h:75
Definition: rtos.h:36
const struct rtos_type * type
Definition: rtos.h:37
int thread_count
Definition: rtos.h:47
int(* gdb_thread_packet)(struct connection *connection, char const *packet, int packet_size)
Definition: rtos.h:48
struct thread_detail * thread_details
Definition: rtos.h:46
struct symbol_table_elem * symbols
Definition: rtos.h:39
struct target * target
Definition: rtos.h:40
void * rtos_specific_params
Definition: rtos.h:50
int(* gdb_target_for_threadid)(struct connection *connection, int64_t thread_id, struct target **p_target)
Definition: rtos.h:49
threadid_t current_thread
Definition: rtos.h:45
int64_t current_threadid
Definition: rtos.h:43
unsigned short width_bits
Definition: rtos.h:103
unsigned short number
Definition: rtos.h:99
signed short offset
Definition: rtos.h:100
Table should be terminated by an element with NULL in symbol_name.
Definition: rtos.h:23
symbol_address_t address
Definition: rtos.h:25
bool optional
Definition: rtos.h:26
const char * symbol_name
Definition: rtos.h:24
Definition: target.h:119
char * extra_info_str
Definition: rtos.h:33
char * thread_name_str
Definition: rtos.h:32
bool exists
Definition: rtos.h:31
threadid_t threadid
Definition: rtos.h:30
uint64_t target_addr_t
Definition: types.h:279
uint8_t cmd
Definition: vdebug.c:1