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