initial

Dependencies:   mbed

Committer:
yihui
Date:
Mon Jan 11 02:32:24 2016 +0000
Revision:
0:638edba3adf6
initial

Who changed what in which revision?

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