8
8
9
9
#include "esp_vfs_semihost.h"
10
10
11
+ #if CONFIG_IDF_TARGET_ARCH_XTENSA
12
+ #include "xtensa/semihosting.h"
13
+ #else
14
+ #include "riscv/semihosting.h"
15
+ #endif
16
+
11
17
#include "esp_log.h"
12
18
const static char * TAG = "semihost_test" ;
13
19
@@ -16,8 +22,6 @@ const static char *TAG = "semihost_test";
16
22
#define ESP_ENOTSUP_UNIX 95
17
23
#define ESP_ENOTSUP_DARWIN 45
18
24
19
- #define SYSCALL_INSTR "break 1,14\n"
20
-
21
25
#define SYS_OPEN 0x01
22
26
#define SYS_CLOSE 0x02
23
27
#define SYS_WRITE 0x05
@@ -71,16 +75,6 @@ static inline bool esp_cpu_in_ocd_debug_mode(void) //check
71
75
return esp_cpu_dbgr_is_attached ();
72
76
}
73
77
74
- static inline long semihosting_call_noerrno_generic (long id , long * data )
75
- {
76
- register long a2 asm ("a2" ) = id ;
77
- register long a3 asm ("a3" ) = (long )data ;
78
- __asm__ __volatile__ (
79
- "break 1, 14\n"
80
- : "+r" (a2 ) : "r" (a3 )
81
- : "memory" );
82
- return a2 ;
83
- }
84
78
static inline int generic_syscall (int sys_nr , int arg1 , int arg2 , int arg3 , int arg4 ,
85
79
int * ret_errno )
86
80
{
@@ -94,10 +88,10 @@ static inline int generic_syscall(int sys_nr, int arg1, int arg2, int arg3, int
94
88
long data [] = {arg1 , arg2 , arg3 , arg4 };
95
89
ESP_LOGI (TAG , "CPU[%d]: -> syscall 0x%x, args: 0x%x, 0x%x, 0x%x, 0x%x" , core_id , sys_nr , arg1 , arg2 , arg3 , arg4 );
96
90
97
- long ret = semihosting_call_noerrno_generic (sys_nr , data );
91
+ long ret = semihosting_call_noerrno (sys_nr , data );
98
92
if (ret == -1 ) {
99
93
const int semihosting_sys_errno = SYS_ERRNO ;
100
- * ret_errno = (int ) semihosting_call_noerrno_generic (semihosting_sys_errno , NULL );
94
+ * ret_errno = (int ) semihosting_call_noerrno (semihosting_sys_errno , NULL );
101
95
}
102
96
ESP_LOGI (TAG , "CPU[%d]: -> syscall 0x%x, args: 0x%x, 0x%x, 0x%x, 0x%x, ret: 0x%x, errno: 0x%x" , core_id , sys_nr , arg1 , arg2 , arg3 , arg4 , (int )ret , (int )* ret_errno );
103
97
return ret ;
@@ -112,10 +106,13 @@ static inline int semihosting_wrong_args(int wrong_arg)
112
106
char fname [32 ];
113
107
snprintf (fname , sizeof (fname ) - 1 , "/test_read.%d" , core_id );
114
108
109
+ #if CONFIG_IDF_TARGET_ARCH_XTENSA
110
+ /* Invalid opcode halts the execution for RISC-V targets OCD-1113 */
115
111
ESP_LOGI (TAG , "CPU[%d]:------ wrong SYSCALL -------" , core_id );
116
112
syscall_ret = generic_syscall (wrong_arg , 0 , 0 , 0 , 0 , & test_errno );
117
113
assert (syscall_ret == -1 );
118
114
assert ((test_errno == ESP_ENOTSUP_WIN ) || (test_errno == ESP_ENOTSUP_UNIX ) || (test_errno == ESP_ENOTSUP_DARWIN ));
115
+ #endif
119
116
120
117
/**** SYS_DRVINFO ****/
121
118
ESP_LOGI (TAG , "CPU[%d]:------ SYS_DRVINFO test -------" , core_id );
@@ -794,7 +791,6 @@ static void semihost_task(void *pvParameter)
794
791
done ();
795
792
}
796
793
797
- #if CONFIG_IDF_TARGET_ARCH_XTENSA
798
794
TEST_DECL (semihost_args , "test_semihost.SemihostTests*.test_semihost_args" )
799
795
{
800
796
int ret ;
@@ -839,7 +835,6 @@ TEST_DECL(semihost_args, "test_semihost.SemihostTests*.test_semihost_args")
839
835
}
840
836
done ();
841
837
}
842
- #endif /* CONFIG_IDF_TARGET_ARCH_XTENSA */
843
838
844
839
TEST_DECL (semihost_rw , "test_semihost.SemihostTests*.test_semihost_rw" )
845
840
{
@@ -959,7 +954,6 @@ ut_result_t semihost_test_do(int test_num)
959
954
xTaskCreatePinnedToCore (TEST_ENTRY (gdb_consoleio ), "gdb_consoleio_task" , 4096 , NULL , 5 , NULL , 0 );
960
955
} else if (TEST_ID_MATCH (TEST_ID_PATTERN (semihost_rw ), test_num )) {
961
956
xTaskCreatePinnedToCore (TEST_ENTRY (semihost_rw ), "semihost_task" , 4096 , NULL , 5 , NULL , 0 );
962
- #if CONFIG_IDF_TARGET_ARCH_XTENSA
963
957
} else if (TEST_ID_MATCH (TEST_ID_PATTERN (semihost_args ), test_num )) {
964
958
/*
965
959
* *** About the test ***
@@ -981,7 +975,6 @@ ut_result_t semihost_test_do(int test_num)
981
975
* - Close the file
982
976
*/
983
977
xTaskCreatePinnedToCore (TEST_ENTRY (semihost_args ), "semihost_args_task0" , 8000 , NULL , 5 , NULL , 0 );
984
- #endif /* CONFIG_IDF_TARGET_ARCH_XTENSA */
985
978
/*
986
979
* *** About the tests ***
987
980
*
0 commit comments