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