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