[444] | 1 | #include "arm.h" |
---|
| 2 | #include <_ansi.h> |
---|
| 3 | |
---|
| 4 | /* SWI numbers for RDP (Demon) monitor. */ |
---|
| 5 | #define SWI_WriteC 0x0 |
---|
| 6 | #define SWI_Write0 0x2 |
---|
| 7 | #define SWI_ReadC 0x4 |
---|
| 8 | #define SWI_CLI 0x5 |
---|
| 9 | #define SWI_GetEnv 0x10 |
---|
| 10 | #define SWI_Exit 0x11 |
---|
| 11 | #define SWI_EnterOS 0x16 |
---|
| 12 | |
---|
| 13 | #define SWI_GetErrno 0x60 |
---|
| 14 | #define SWI_Clock 0x61 |
---|
| 15 | #define SWI_Time 0x63 |
---|
| 16 | #define SWI_Remove 0x64 |
---|
| 17 | #define SWI_Rename 0x65 |
---|
| 18 | #define SWI_Open 0x66 |
---|
| 19 | |
---|
| 20 | #define SWI_Close 0x68 |
---|
| 21 | #define SWI_Write 0x69 |
---|
| 22 | #define SWI_Read 0x6a |
---|
| 23 | #define SWI_Seek 0x6b |
---|
| 24 | #define SWI_Flen 0x6c |
---|
| 25 | |
---|
| 26 | #define SWI_IsTTY 0x6e |
---|
| 27 | #define SWI_TmpNam 0x6f |
---|
| 28 | #define SWI_InstallHandler 0x70 |
---|
| 29 | #define SWI_GenerateError 0x71 |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | /* Now the SWI numbers and reason codes for RDI (Angel) monitors. */ |
---|
| 33 | #if defined (SEMIHOST_V2) && defined (SEMIHOST_V2_MIXED_MODE) |
---|
| 34 | #define AngelSWI_ARM 0xF000 /* HLT A32. */ |
---|
| 35 | #ifdef __thumb__ |
---|
| 36 | #define AngelSWI 0x3C /* HLT T32. */ |
---|
| 37 | #else /* __thumb__. */ |
---|
| 38 | #define AngelSWI AngelSWI_ARM |
---|
| 39 | #endif /* __thumb__. */ |
---|
| 40 | #else /* SEMIHOST_V2. */ |
---|
| 41 | #define AngelSWI_ARM 0x123456 /* SVC A32. */ |
---|
| 42 | #ifdef __thumb__ |
---|
| 43 | #define AngelSWI 0xAB /* SVC T32. */ |
---|
| 44 | #else /* __thumb__. */ |
---|
| 45 | #define AngelSWI AngelSWI_ARM |
---|
| 46 | #endif /* __thumb__. */ |
---|
| 47 | #endif /* SEMIHOST_V2. */ |
---|
| 48 | |
---|
| 49 | /* For thumb only architectures use the BKPT instruction instead of SWI. */ |
---|
| 50 | #ifdef THUMB_VXM |
---|
| 51 | #define AngelSWIInsn "bkpt" |
---|
| 52 | #define AngelSWIAsm bkpt |
---|
| 53 | #else |
---|
| 54 | #define AngelSWIInsn "swi" |
---|
| 55 | #define AngelSWIAsm swi |
---|
| 56 | #endif |
---|
| 57 | |
---|
| 58 | /* The reason codes: */ |
---|
| 59 | #define AngelSWI_Reason_Open 0x01 |
---|
| 60 | #define AngelSWI_Reason_Close 0x02 |
---|
| 61 | #define AngelSWI_Reason_WriteC 0x03 |
---|
| 62 | #define AngelSWI_Reason_Write0 0x04 |
---|
| 63 | #define AngelSWI_Reason_Write 0x05 |
---|
| 64 | #define AngelSWI_Reason_Read 0x06 |
---|
| 65 | #define AngelSWI_Reason_ReadC 0x07 |
---|
| 66 | #define AngelSWI_Reason_IsError 0x08 |
---|
| 67 | #define AngelSWI_Reason_IsTTY 0x09 |
---|
| 68 | #define AngelSWI_Reason_Seek 0x0A |
---|
| 69 | #define AngelSWI_Reason_FLen 0x0C |
---|
| 70 | #define AngelSWI_Reason_TmpNam 0x0D |
---|
| 71 | #define AngelSWI_Reason_Remove 0x0E |
---|
| 72 | #define AngelSWI_Reason_Rename 0x0F |
---|
| 73 | #define AngelSWI_Reason_Clock 0x10 |
---|
| 74 | #define AngelSWI_Reason_Time 0x11 |
---|
| 75 | #define AngelSWI_Reason_System 0x12 |
---|
| 76 | #define AngelSWI_Reason_Errno 0x13 |
---|
| 77 | #define AngelSWI_Reason_GetCmdLine 0x15 |
---|
| 78 | #define AngelSWI_Reason_HeapInfo 0x16 |
---|
| 79 | #define AngelSWI_Reason_EnterSVC 0x17 |
---|
| 80 | #define AngelSWI_Reason_ReportException 0x18 |
---|
| 81 | #define AngelSWI_Reason_ReportExceptionExtended 0x20 |
---|
| 82 | #define AngelSWI_Reason_Elapsed 0x30 |
---|
| 83 | #define AngelSWI_Reason_TickFreq 0x31 |
---|
| 84 | #define ADP_Stopped_ApplicationExit ((2 << 16) + 38) |
---|
| 85 | #define ADP_Stopped_RunTimeError ((2 << 16) + 35) |
---|
| 86 | |
---|
| 87 | /* Semihosting feature magic numbers. */ |
---|
| 88 | #define NUM_SHFB_MAGIC 4 |
---|
| 89 | #define SHFB_MAGIC_0 0x53 |
---|
| 90 | #define SHFB_MAGIC_1 0x48 |
---|
| 91 | #define SHFB_MAGIC_2 0x46 |
---|
| 92 | #define SHFB_MAGIC_3 0x42 |
---|
| 93 | |
---|
| 94 | /* Semihosting extensions. */ |
---|
| 95 | #define SH_EXT_EXIT_EXTENDED_BITNUM 0x0 |
---|
| 96 | #define SH_EXT_STDOUT_STDERR_BITNUM 0x1 |
---|
| 97 | |
---|
| 98 | #if !defined (__ASSEMBLER__) |
---|
| 99 | extern int _get_semihosting_exts (char*, int, int); |
---|
| 100 | extern int _has_ext_exit_extended (void); |
---|
| 101 | extern int _has_ext_stdout_stderr (void); |
---|
| 102 | #endif |
---|
| 103 | |
---|
| 104 | #if defined(ARM_RDI_MONITOR) && !defined(__ASSEMBLER__) |
---|
| 105 | |
---|
| 106 | static inline int |
---|
| 107 | do_AngelSWI (int reason, void * arg) |
---|
| 108 | { |
---|
| 109 | int value; |
---|
| 110 | asm volatile ("mov r0, %1; mov r1, %2; " AngelSWIInsn " %a3; mov %0, r0" |
---|
| 111 | : "=r" (value) /* Outputs */ |
---|
| 112 | : "r" (reason), "r" (arg), "i" (AngelSWI) /* Inputs */ |
---|
| 113 | : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc" |
---|
| 114 | /* Clobbers r0 and r1, and lr if in supervisor mode */); |
---|
| 115 | /* Accordingly to page 13-77 of ARM DUI 0040D other registers |
---|
| 116 | can also be clobbered. Some memory positions may also be |
---|
| 117 | changed by a system call, so they should not be kept in |
---|
| 118 | registers. Note: we are assuming the manual is right and |
---|
| 119 | Angel is respecting the APCS. */ |
---|
| 120 | return value; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | #endif |
---|