mbed libraries for KL25Z
semihost_api.h@8:c14af7958ef5, 2012-11-09 (annotated)
- Committer:
- emilmont
- Date:
- Fri Nov 09 11:33:53 2012 +0000
- Revision:
- 8:c14af7958ef5
- Child:
- 9:663789d7729f
SPI driver; ADC driver; DAC driver; microlib support; general bugfixing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 8:c14af7958ef5 | 1 | /* mbed Microcontroller Library - semihost_api |
emilmont | 8:c14af7958ef5 | 2 | * Copyright (c) 2006-2009 ARM Limited. All rights reserved. |
emilmont | 8:c14af7958ef5 | 3 | */ |
emilmont | 8:c14af7958ef5 | 4 | #ifndef MBED_SEMIHOST_H |
emilmont | 8:c14af7958ef5 | 5 | #define MBED_SEMIHOST_H |
emilmont | 8:c14af7958ef5 | 6 | |
emilmont | 8:c14af7958ef5 | 7 | #include "device.h" |
emilmont | 8:c14af7958ef5 | 8 | #include "toolchain.h" |
emilmont | 8:c14af7958ef5 | 9 | |
emilmont | 8:c14af7958ef5 | 10 | #ifdef __cplusplus |
emilmont | 8:c14af7958ef5 | 11 | extern "C" { |
emilmont | 8:c14af7958ef5 | 12 | #endif |
emilmont | 8:c14af7958ef5 | 13 | |
emilmont | 8:c14af7958ef5 | 14 | /* __semihost intrinsic |
emilmont | 8:c14af7958ef5 | 15 | This intrinsic inserts an SVC or BKPT instruction into the instruction stream |
emilmont | 8:c14af7958ef5 | 16 | generated by the compiler. It enables you to make semihosting calls from C or |
emilmont | 8:c14af7958ef5 | 17 | C++ that are independent of the target architecture. |
emilmont | 8:c14af7958ef5 | 18 | */ |
emilmont | 8:c14af7958ef5 | 19 | #ifndef __CC_ARM |
emilmont | 8:c14af7958ef5 | 20 | /* Semihost implementation taken from: |
emilmont | 8:c14af7958ef5 | 21 | * git://github.com/elua/elua.git/src/semifs.c |
emilmont | 8:c14af7958ef5 | 22 | */ |
emilmont | 8:c14af7958ef5 | 23 | |
emilmont | 8:c14af7958ef5 | 24 | /* SWI numbers for RDI (Angel) monitors */ |
emilmont | 8:c14af7958ef5 | 25 | #ifdef __thumb__ |
emilmont | 8:c14af7958ef5 | 26 | #define AngelSWI 0xAB |
emilmont | 8:c14af7958ef5 | 27 | #else |
emilmont | 8:c14af7958ef5 | 28 | #define AngelSWI 0x123456 |
emilmont | 8:c14af7958ef5 | 29 | #endif |
emilmont | 8:c14af7958ef5 | 30 | /* For Thumb-2 code use the BKPT instruction instead of SWI */ |
emilmont | 8:c14af7958ef5 | 31 | #ifdef __thumb2__ |
emilmont | 8:c14af7958ef5 | 32 | #define AngelSWIInsn "bkpt" |
emilmont | 8:c14af7958ef5 | 33 | #define AngelSWIAsm bkpt |
emilmont | 8:c14af7958ef5 | 34 | #else |
emilmont | 8:c14af7958ef5 | 35 | #define AngelSWIInsn "swi" |
emilmont | 8:c14af7958ef5 | 36 | #define AngelSWIAsm swi |
emilmont | 8:c14af7958ef5 | 37 | #endif |
emilmont | 8:c14af7958ef5 | 38 | |
emilmont | 8:c14af7958ef5 | 39 | inline int __semihost(int reason, const void *arg) { |
emilmont | 8:c14af7958ef5 | 40 | int value; |
emilmont | 8:c14af7958ef5 | 41 | asm volatile ("mov r0, %1; mov r1, %2; " AngelSWIInsn " %a3; mov %0, r0" |
emilmont | 8:c14af7958ef5 | 42 | : "=r" (value) /* Outputs */ |
emilmont | 8:c14af7958ef5 | 43 | : "r" (reason), "r" (arg), "i" (AngelSWI) /* Inputs */ |
emilmont | 8:c14af7958ef5 | 44 | : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc" |
emilmont | 8:c14af7958ef5 | 45 | /* Clobbers r0 and r1, and lr if in supervisor mode */); |
emilmont | 8:c14af7958ef5 | 46 | /* Accordingly to page 13-77 of ARM DUI 0040D other registers |
emilmont | 8:c14af7958ef5 | 47 | can also be clobbered. Some memory positions may also be |
emilmont | 8:c14af7958ef5 | 48 | changed by a system call, so they should not be kept in |
emilmont | 8:c14af7958ef5 | 49 | registers. Note: we are assuming the manual is right and |
emilmont | 8:c14af7958ef5 | 50 | Angel is respecting the APCS. */ |
emilmont | 8:c14af7958ef5 | 51 | |
emilmont | 8:c14af7958ef5 | 52 | return value; |
emilmont | 8:c14af7958ef5 | 53 | } |
emilmont | 8:c14af7958ef5 | 54 | |
emilmont | 8:c14af7958ef5 | 55 | #endif |
emilmont | 8:c14af7958ef5 | 56 | |
emilmont | 8:c14af7958ef5 | 57 | #if DEVICE_LOCALFILESYSTEM |
emilmont | 8:c14af7958ef5 | 58 | FILEHANDLE semihost_open(const char* name, int openmode); |
emilmont | 8:c14af7958ef5 | 59 | int semihost_close(FILEHANDLE fh); |
emilmont | 8:c14af7958ef5 | 60 | int semihost_read(FILEHANDLE fh, unsigned char* buffer, unsigned int length, int mode); |
emilmont | 8:c14af7958ef5 | 61 | int semihost_write(FILEHANDLE fh, const unsigned char* buffer, unsigned int length, int mode); |
emilmont | 8:c14af7958ef5 | 62 | int semihost_ensure(FILEHANDLE fh); |
emilmont | 8:c14af7958ef5 | 63 | long semihost_flen(FILEHANDLE fh); |
emilmont | 8:c14af7958ef5 | 64 | int semihost_seek(FILEHANDLE fh, long position); |
emilmont | 8:c14af7958ef5 | 65 | int semihost_istty(FILEHANDLE fh); |
emilmont | 8:c14af7958ef5 | 66 | |
emilmont | 8:c14af7958ef5 | 67 | int semihost_remove(const char *name); |
emilmont | 8:c14af7958ef5 | 68 | int semihost_rename(const char *old_name, const char *new_name); |
emilmont | 8:c14af7958ef5 | 69 | #endif |
emilmont | 8:c14af7958ef5 | 70 | |
emilmont | 8:c14af7958ef5 | 71 | int semihost_uid(char *uid); |
emilmont | 8:c14af7958ef5 | 72 | int semihost_reset(void); |
emilmont | 8:c14af7958ef5 | 73 | int semihost_vbus(void); |
emilmont | 8:c14af7958ef5 | 74 | int semihost_powerdown(void); |
emilmont | 8:c14af7958ef5 | 75 | int semihost_exit(void); |
emilmont | 8:c14af7958ef5 | 76 | |
emilmont | 8:c14af7958ef5 | 77 | int semihost_connected(void); |
emilmont | 8:c14af7958ef5 | 78 | int semihost_disabledebug(void); |
emilmont | 8:c14af7958ef5 | 79 | |
emilmont | 8:c14af7958ef5 | 80 | #ifdef __cplusplus |
emilmont | 8:c14af7958ef5 | 81 | } |
emilmont | 8:c14af7958ef5 | 82 | #endif |
emilmont | 8:c14af7958ef5 | 83 | |
emilmont | 8:c14af7958ef5 | 84 | #endif |