Mistake on this page?
Report an issue in GitHub or email us
mbed_semihost_api.h
1 
2 /* mbed Microcontroller Library
3  * Copyright (c) 2006-2013 ARM Limited
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #ifndef MBED_SEMIHOST_H
19 #define MBED_SEMIHOST_H
20 
21 #include "device.h"
22 #include "platform/mbed_toolchain.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #if DEVICE_SEMIHOST
29 
30 #if !defined(__CC_ARM) && !defined(__ARMCC_VERSION)
31 
32 #if defined(__ICCARM__)
33 static inline int __semihost(int reason, const void *arg)
34 {
35  return __semihosting(reason, (void *)arg);
36 }
37 #else
38 
39 #ifdef __thumb__
40 # define AngelSWI 0xAB
41 # define AngelSWIInsn "bkpt"
42 # define AngelSWIAsm bkpt
43 #else
44 # define AngelSWI 0x123456
45 # define AngelSWIInsn "swi"
46 # define AngelSWIAsm swi
47 #endif
48 
49 static inline int __semihost(int reason, const void *arg)
50 {
51  int value;
52 
53  asm volatile(
54  "mov r0, %1" "\n\t"
55  "mov r1, %2" "\n\t"
56  AngelSWIInsn " %a3" "\n\t"
57  "mov %0, r0"
58  : "=r"(value) /* output operands */
59  : "r"(reason), "r"(arg), "i"(AngelSWI) /* input operands */
60  : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc" /* list of clobbered registers */
61  );
62 
63  return value;
64 }
65 #endif
66 #endif
67 
68 #if DEVICE_LOCALFILESYSTEM
69 FILEHANDLE semihost_open(const char *name, int openmode);
70 int semihost_close(FILEHANDLE fh);
71 int semihost_read(FILEHANDLE fh, unsigned char *buffer, unsigned int length, int mode);
72 int semihost_write(FILEHANDLE fh, const unsigned char *buffer, unsigned int length, int mode);
73 int semihost_ensure(FILEHANDLE fh);
74 long semihost_flen(FILEHANDLE fh);
75 int semihost_seek(FILEHANDLE fh, long position);
76 int semihost_istty(FILEHANDLE fh);
77 
78 int semihost_remove(const char *name);
79 int semihost_rename(const char *old_name, const char *new_name);
80 #endif
81 
82 int semihost_uid(char *uid);
83 int semihost_reset(void);
84 int semihost_vbus(void);
85 int semihost_powerdown(void);
86 int semihost_exit(void);
87 
88 int semihost_connected(void);
89 int semihost_disabledebug(void);
90 
91 #endif
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
97 #endif
98 
99 
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.