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