1 /*
2  * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 // This module implements debug/trace stubs. The stub is a piece of special code which can invoked by OpenOCD
8 // Currently one stub is used for GCOV functionality
9 //
10 
11 #include "esp_cpu.h"
12 #include "esp_log.h"
13 #include "riscv/semihosting.h"
14 
15 const static char *TAG = "esp_dbg_stubs";
16 
17 
18 /* Advertises apptrace control block address to host */
esp_dbg_stubs_advertise_table(void * stub_table_addr)19 static int esp_dbg_stubs_advertise_table(void *stub_table_addr)
20 {
21     if (!esp_cpu_dbgr_is_attached()) {
22         return 0;
23     }
24     return (int) semihosting_call_noerrno(ESP_SEMIHOSTING_SYS_DBG_STUBS_INIT, (long*)stub_table_addr);
25 }
26 
esp_dbg_stubs_ll_init(void * stub_table_addr)27 void esp_dbg_stubs_ll_init(void *stub_table_addr)
28 {
29     // notify host about control block address
30     int res = esp_dbg_stubs_advertise_table(stub_table_addr);
31     assert(res == 0 && "Failed to send debug stubs table address to host!");
32     ESP_LOGV(TAG, "%s stubs %p", __func__, stub_table_addr);
33 }
34