30
30
#include "target/target_type.h"
31
31
#include "target/armv7m.h"
32
32
33
+ #define UNIMPLEMENTED 0xFFFFFFFFU
34
+
33
35
struct Zephyr_thread {
34
36
uint32_t ptr , next_ptr ;
35
37
uint32_t entry ;
@@ -49,13 +51,18 @@ enum Zephyr_offsets {
49
51
OFFSET_T_USER_OPTIONS ,
50
52
OFFSET_T_PRIO ,
51
53
OFFSET_T_STACK_POINTER ,
54
+ OFFSET_T_NAME ,
55
+ OFFSET_T_ARCH ,
56
+ OFFSET_T_PREEMPT_FLOAT ,
57
+ OFFSET_T_COOP_FLOAT ,
52
58
OFFSET_MAX
53
59
};
54
60
55
61
struct Zephyr_params {
56
62
const char * target_name ;
57
63
uint8_t size_width ;
58
64
uint8_t pointer_width ;
65
+ uint32_t num_offsets ;
59
66
uint32_t offsets [OFFSET_MAX ];
60
67
const struct rtos_register_stacking * callee_saved_stacking ;
61
68
const struct rtos_register_stacking * cpu_saved_nofp_stacking ;
@@ -161,13 +168,15 @@ enum Zephyr_symbol_values {
161
168
Zephyr_VAL__kernel ,
162
169
Zephyr_VAL__kernel_openocd_offsets ,
163
170
Zephyr_VAL__kernel_openocd_size_t_size ,
171
+ Zephyr_VAL__kernel_openocd_num_offsets ,
164
172
Zephyr_VAL_COUNT
165
173
};
166
174
167
175
static const symbol_table_elem_t Zephyr_symbol_list [] = {
168
176
{ .symbol_name = "_kernel" , .optional = false },
169
177
{ .symbol_name = "_kernel_openocd_offsets" , .optional = false },
170
178
{ .symbol_name = "_kernel_openocd_size_t_size" , .optional = false },
179
+ { .symbol_name = "_kernel_openocd_num_offsets" , .optional = true },
171
180
{ }
172
181
};
173
182
@@ -369,20 +378,49 @@ static int Zephyr_update_threads(struct rtos *rtos)
369
378
return ERROR_FAIL ;
370
379
}
371
380
381
+ if (rtos -> symbols [Zephyr_VAL__kernel_openocd_num_offsets ].address ) {
382
+ retval = target_read_u32 (rtos -> target ,
383
+ rtos -> symbols [Zephyr_VAL__kernel_openocd_num_offsets ].address ,
384
+ & param -> num_offsets );
385
+ if (retval != ERROR_OK ) {
386
+ LOG_ERROR ("Couldn't not fetch number of offsets from Zephyr" );
387
+ return retval ;
388
+ }
389
+ if (param -> num_offsets <= OFFSET_T_STACK_POINTER ) {
390
+ LOG_ERROR ("Number of offsets too small" );
391
+ return ERROR_FAIL ;
392
+ }
393
+ } else {
394
+ param -> num_offsets = OFFSET_VERSION + 1 ;
395
+ }
372
396
/* We can fetch the whole array for version 0, as they're supposed
373
397
* to grow only */
374
398
uint32_t address ;
375
399
address = rtos -> symbols [Zephyr_VAL__kernel_openocd_offsets ].address ;
376
400
for (size_t i = 0 ; i < OFFSET_MAX ; i ++ , address += param -> size_width ) {
401
+ if (i >= param -> num_offsets ) {
402
+ param -> offsets [i ] = UNIMPLEMENTED ;
403
+ continue ;
404
+ }
377
405
retval = target_read_u32 (rtos -> target , address , & param -> offsets [i ]);
378
406
if (retval != ERROR_OK ) {
379
407
LOG_ERROR ("Could not fetch offsets from Zephyr" );
380
408
return ERROR_FAIL ;
381
409
}
410
+ if (param -> num_offsets == OFFSET_VERSION + 1 && i == OFFSET_VERSION ) {
411
+ switch (param -> offsets [OFFSET_VERSION ]) {
412
+ case 0 :
413
+ param -> num_offsets = OFFSET_T_STACK_POINTER + 1 ;
414
+ break ;
415
+ case 1 :
416
+ param -> num_offsets = OFFSET_T_COOP_FLOAT + 1 ;
417
+ break ;
418
+ }
419
+ }
382
420
}
383
- if (param -> offsets [OFFSET_VERSION ] != 0 ) {
384
- LOG_ERROR ("Expecting OpenOCD support version 0, got % " PRId32
385
- " instead" , param -> offsets [OFFSET_VERSION ]);
421
+ if (param -> offsets [OFFSET_VERSION ] > 1 ) {
422
+ LOG_ERROR ("Unexpected OpenOCD support version %" PRIu32 ,
423
+ param -> offsets [OFFSET_VERSION ]);
386
424
return ERROR_FAIL ;
387
425
}
388
426
0 commit comments