mbed_semihost_api.h 2.6 KB

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