1 /*
2 * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #pragma once
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13
14 /* ESP custom semihosting calls numbers */
15
16 /**
17 * @brief Initialize apptrace data at host side
18 *
19 * @param addr address of apptrace control data block
20 * @return return 0 on sucess or non-zero error code
21 */
22 #define ESP_SEMIHOSTING_SYS_APPTRACE_INIT 0x101
23
24 /**
25 * @brief Initialize debug stubs table at host side
26 *
27 * @param addr address of debug stubs table
28 * @return return 0 on sucess or non-zero error code
29 */
30 #define ESP_SEMIHOSTING_SYS_DBG_STUBS_INIT 0x102
31
32 /**
33 * @brief Set/clear breakpoint
34 *
35 * @param set if true set breakpoint, otherwise clear it
36 * @param id breakpoint ID
37 * @param addr address to set breakpoint at. Ignored if `set` is false.
38 * @return return 0 on sucess or non-zero error code
39 */
40 #define ESP_SEMIHOSTING_SYS_BREAKPOINT_SET 0x103
41
42 /**
43 * @brief Set/clear watchpoint
44 *
45 * @param set if true set watchpoint, otherwise clear it
46 * @param id watchpoint ID
47 * @param addr address to set watchpoint at. Ignored if `set` is false.
48 * @param size size of watchpoint. Ignored if `set` is false.
49 * @param flags watchpoint flags, see description below. Ignored if `set` is false.
50 * @return return 0 on sucess or non-zero error code
51 */
52 #define ESP_SEMIHOSTING_SYS_WATCHPOINT_SET 0x104
53
54 /* bit values for `flags` argument of ESP_SEMIHOSTING_SYS_WATCHPOINT_SET call. Can be ORed. */
55 /* watch for 'reads' at `addr` */
56 #define ESP_SEMIHOSTING_WP_FLG_RD (1UL << 0)
57 /* watch for 'writes' at `addr` */
58 #define ESP_SEMIHOSTING_WP_FLG_WR (1UL << 1)
59
60 /**
61 * @brief Perform semihosting call
62 *
63 * See https://github.com/riscv/riscv-semihosting-spec/ and the linked
64 * ARM semihosting spec for details.
65 *
66 * @param id semihosting call number
67 * @param data data block to pass to the host; number of items and their
68 * meaning depends on the semihosting call. See the spec for
69 * details.
70 *
71 * @return return value from the host
72 */
semihosting_call_noerrno(long id,long * data)73 static inline long semihosting_call_noerrno(long id, long *data)
74 {
75 register long a0 asm ("a0") = id;
76 register long a1 asm ("a1") = (long) data;
77 __asm__ __volatile__ (
78 ".option push\n"
79 ".option norvc\n"
80 "slli zero, zero, 0x1f\n"
81 "ebreak\n"
82 "srai zero, zero, 0x7\n"
83 ".option pop\n"
84 : "+r"(a0) : "r"(a1) : "memory");
85 return a0;
86 }
87
88 #ifdef __cplusplus
89 }
90 #endif
91