kfsw-platform/src/semihost_target.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <errno.h> | ||
| 2 | #include <zephyr/kernel.h> | ||
| 3 | #include <zephyr/sys/util.h> | ||
| 4 | |||
| 5 | #include "semihost_internal.h" | ||
| 6 | |||
| 7 | #if CONFIG_CPU_CORTEX_M && CONFIG_ARMV7_M_ARMV8_M_MAINLINE && !CONFIG_ARMV8_M_SE | ||
| 8 | #include <cmsis_core.h> | ||
| 9 | #include <zephyr/arch/common/semihost.h> | ||
| 10 | |||
| 11 | #define SEMIHOST_STDOUT 1L | ||
| 12 | |||
| 13 | int kfsw_semihost_context(void) | ||
| 14 | { | ||
| 15 | if (k_is_in_isr() || (__get_IPSR() != 0U) || (__get_PRIMASK() != 0U) || | ||
| 16 | ((__get_CONTROL() & CONTROL_nPRIV_Msk) != 0U)) { | ||
| 17 | return -EWOULDBLOCK; | ||
| 18 | } | ||
| 19 | if ((__get_BASEPRI() != 0U) || (__get_FAULTMASK() != 0U)) { | ||
| 20 | return -EWOULDBLOCK; | ||
| 21 | } | ||
| 22 | return (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) != 0U ? 0 : -ENODEV; | ||
| 23 | } | ||
| 24 | |||
| 25 | long kfsw_semihost_target_write(const char *text, size_t size) | ||
| 26 | { | ||
| 27 | int result = kfsw_semihost_context(); | ||
| 28 | |||
| 29 | if (result != 0) { | ||
| 30 | return result; | ||
| 31 | } | ||
| 32 | /* Zephyr passes SYS_WRITE's count of unwritten bytes through unchanged. */ | ||
| 33 | return semihost_write(SEMIHOST_STDOUT, text, (long)size); | ||
| 34 | } | ||
| 35 | #else | ||
| 36 | 4 | int kfsw_semihost_context(void) | |
| 37 | { | ||
| 38 | 4 | return -ENOTSUP; | |
| 39 | } | ||
| 40 | |||
| 41 | 4 | long kfsw_semihost_target_write(const char *text, size_t size) | |
| 42 | { | ||
| 43 | ARG_UNUSED(text); | ||
| 44 | ARG_UNUSED(size); | ||
| 45 | 4 | return -ENOTSUP; | |
| 46 | } | ||
| 47 | #endif | ||
| 48 |