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/target.h"
13 
14 typedef int64_t threadid_t;
15 typedef int64_t symbol_address_t;
16 
17 struct reg;
18 
23  const char *symbol_name;
25  bool optional;
26 };
27 
28 struct thread_detail {
30  bool exists;
33 };
34 
35 struct rtos {
36  const struct rtos_type *type;
37 
39  struct target *target;
40  /* add a context variable instead of global variable */
41  /* The thread currently selected by gdb. */
43  /* The currently selected thread according to the target. */
47  int (*gdb_thread_packet)(struct connection *connection, char const *packet, int packet_size);
48  int (*gdb_target_for_threadid)(struct connection *connection, int64_t thread_id, struct target **p_target);
50 };
51 
52 struct rtos_reg {
53  uint32_t number;
54  uint32_t size;
55  uint8_t value[16];
56 };
57 
58 struct rtos_type {
59  const char *name;
60  bool (*detect_rtos)(struct target *target);
61  int (*create)(struct target *target);
62  int (*smp_init)(struct target *target);
63  int (*update_threads)(struct rtos *rtos);
65  int (*get_thread_reg_list)(struct rtos *rtos, int64_t thread_id,
66  struct rtos_reg **reg_list, int *num_regs);
69  int (*get_thread_reg_value)(struct rtos *rtos, threadid_t thread_id,
70  uint32_t reg_num, uint32_t *size, uint8_t **value);
71  int (*get_symbol_list_to_lookup)(struct symbol_table_elem *symbol_list[]);
72  int (*clean)(struct target *target);
73  char * (*ps_command)(struct target *target);
74  int (*set_reg)(struct rtos *rtos, uint32_t reg_num, uint8_t *reg_value);
75  /* Implement these if different threads in the RTOS can see memory
76  * differently (for instance because address translation might be different
77  * for each thread). */
78  int (*read_buffer)(struct rtos *rtos, target_addr_t address, uint32_t size,
79  uint8_t *buffer);
80  int (*write_buffer)(struct rtos *rtos, target_addr_t address, uint32_t size,
81  const uint8_t *buffer);
88  bool (*needs_fake_step)(struct target *target, int64_t thread_id);
89 };
90 
92  unsigned short number; /* register number */
93  signed short offset; /* offset in bytes from stack head, or -1 to indicate
94  * register is not stacked, or -2 to indicate this is the
95  * stack pointer register */
96  unsigned short width_bits;
97 };
98 
100  unsigned char stack_registers_size;
102  unsigned char num_output_registers;
103  /* Some targets require evaluating the stack to determine the
104  * actual stack pointer for a process. If this field is NULL,
105  * just use stacking->stack_registers_size * stack_growth_direction
106  * to calculate adjustment.
107  */
109  const uint8_t *stack_data,
110  const struct rtos_register_stacking *stacking,
111  target_addr_t stack_ptr);
113  /* Optional field for targets which may have to implement their own stack read function.
114  * Because stack format can be weird or stack data needed to be edited before passing to the gdb.
115  */
116  int (*read_stack)(struct target *target,
117  int64_t stack_ptr,
118  const struct rtos_register_stacking *stacking,
119  uint8_t *stack_data);
120 };
121 
122 #define GDB_THREAD_PACKET_NOT_CONSUMED (-40)
123 
124 int rtos_create(struct command_invocation *cmd, struct target *target,
125  const char *rtos_name);
126 void rtos_destroy(struct target *target);
127 int rtos_set_reg(struct connection *connection, int reg_num,
128  uint8_t *reg_value);
130  const struct rtos_register_stacking *stacking,
131  int64_t stack_ptr,
132  struct rtos_reg **reg_list,
133  int *num_regs);
134 int gdb_thread_packet(struct connection *connection, char const *packet, int packet_size);
135 int rtos_thread_packet(struct connection *connection, const char *packet, int packet_size);
136 int rtos_get_gdb_reg(struct connection *connection, int reg_num);
138 int rtos_update_threads(struct target *target);
139 void rtos_free_threadlist(struct rtos *rtos);
140 int rtos_smp_init(struct target *target);
141 /* function for handling symbol access */
142 int rtos_qsymbol(struct connection *connection, char const *packet, int packet_size);
144  uint32_t size, uint8_t *buffer);
146  uint32_t size, const uint8_t *buffer);
147 bool rtos_needs_fake_step(struct target *target, int64_t thread_id);
148 
149 // Keep in alphabetic order this list of rtos
150 extern const struct rtos_type chibios_rtos;
151 extern const struct rtos_type chromium_ec_rtos;
152 extern const struct rtos_type ecos_rtos;
153 extern const struct rtos_type embkernel_rtos;
154 extern const struct rtos_type freertos_rtos;
155 extern const struct rtos_type hwthread_rtos;
156 extern const struct rtos_type linux_rtos;
157 extern const struct rtos_type mqx_rtos;
158 extern const struct rtos_type nuttx_rtos;
159 extern const struct rtos_type riot_rtos;
160 extern const struct rtos_type rtkernel_rtos;
161 extern const struct rtos_type threadx_rtos;
162 extern const struct rtos_type ucos_iii_rtos;
163 extern const struct rtos_type zephyr_rtos;
164 
165 #endif /* OPENOCD_RTOS_RTOS_H */
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
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:654
int rtos_thread_packet(struct connection *connection, const char *packet, int packet_size)
Definition: rtos.c:354
int64_t symbol_address_t
Definition: rtos.h:15
int gdb_thread_packet(struct connection *connection, char const *packet, int packet_size)
Definition: rtos.c:149
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:99
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:51
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:640
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:607
void rtos_destroy(struct target *target)
Definition: rtos.c:144
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:751
const struct rtos_type chibios_rtos
Definition: chibios.c:99
int rtos_update_threads(struct target *target)
Definition: rtos.c:718
int rtos_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
Definition: rtos.c:743
int rtos_smp_init(struct target *target)
Definition: rtos.c:39
int64_t threadid_t
Definition: rtos.h:14
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:759
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:234
void rtos_free_threadlist(struct rtos *rtos)
Definition: rtos.c:725
int rtos_get_gdb_reg(struct connection *connection, int reg_num)
Look through all registers to find this register.
Definition: rtos.c:550
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:52
uint32_t number
Definition: rtos.h:53
uint8_t value[16]
Definition: rtos.h:55
uint32_t size
Definition: rtos.h:54
const struct stack_register_offset * register_offsets
Definition: rtos.h:112
unsigned char num_output_registers
Definition: rtos.h:102
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:108
unsigned char stack_registers_size
Definition: rtos.h:100
int(* read_stack)(struct target *target, int64_t stack_ptr, const struct rtos_register_stacking *stacking, uint8_t *stack_data)
Definition: rtos.h:116
signed char stack_growth_direction
Definition: rtos.h:101
Definition: rtos.h:58
int(* create)(struct target *target)
Definition: rtos.h:61
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:88
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:69
int(* smp_init)(struct target *target)
Definition: rtos.h:62
int(* update_threads)(struct rtos *rtos)
Definition: rtos.h:63
int(* get_symbol_list_to_lookup)(struct symbol_table_elem *symbol_list[])
Definition: rtos.h:71
const char * name
Definition: rtos.h:59
int(* write_buffer)(struct rtos *rtos, target_addr_t address, uint32_t size, const uint8_t *buffer)
Definition: rtos.h:80
int(* clean)(struct target *target)
Definition: rtos.h:72
int(* read_buffer)(struct rtos *rtos, target_addr_t address, uint32_t size, uint8_t *buffer)
Definition: rtos.h:78
bool(* detect_rtos)(struct target *target)
Definition: rtos.h:60
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:65
int(* set_reg)(struct rtos *rtos, uint32_t reg_num, uint8_t *reg_value)
Definition: rtos.h:74
Definition: rtos.h:35
const struct rtos_type * type
Definition: rtos.h:36
int thread_count
Definition: rtos.h:46
int(* gdb_thread_packet)(struct connection *connection, char const *packet, int packet_size)
Definition: rtos.h:47
struct thread_detail * thread_details
Definition: rtos.h:45
struct symbol_table_elem * symbols
Definition: rtos.h:38
struct target * target
Definition: rtos.h:39
void * rtos_specific_params
Definition: rtos.h:49
int(* gdb_target_for_threadid)(struct connection *connection, int64_t thread_id, struct target **p_target)
Definition: rtos.h:48
threadid_t current_thread
Definition: rtos.h:44
int64_t current_threadid
Definition: rtos.h:42
unsigned short width_bits
Definition: rtos.h:96
unsigned short number
Definition: rtos.h:92
signed short offset
Definition: rtos.h:93
Table should be terminated by an element with NULL in symbol_name.
Definition: rtos.h:22
symbol_address_t address
Definition: rtos.h:24
bool optional
Definition: rtos.h:25
const char * symbol_name
Definition: rtos.h:23
Definition: target.h:119
char * extra_info_str
Definition: rtos.h:32
char * thread_name_str
Definition: rtos.h:31
bool exists
Definition: rtos.h:30
threadid_t threadid
Definition: rtos.h:29
uint64_t target_addr_t
Definition: types.h:279
uint8_t cmd
Definition: vdebug.c:1