2 #ifndef ARM_SEMIHOSTING_H_
3 #define ARM_SEMIHOSTING_H_
5 // ----------------------------------------------------------------------------
7 // Semihosting operations.
11 SEMIHOSTING_EnterSVC = 0x17,
12 SEMIHOSTING_ReportException = 0x18,
13 SEMIHOSTING_SYS_CLOSE = 0x02,
14 SEMIHOSTING_SYS_CLOCK = 0x10,
15 SEMIHOSTING_SYS_ELAPSED = 0x30,
16 SEMIHOSTING_SYS_ERRNO = 0x13,
17 SEMIHOSTING_SYS_FLEN = 0x0C,
18 SEMIHOSTING_SYS_GET_CMDLINE = 0x15,
19 SEMIHOSTING_SYS_HEAPINFO = 0x16,
20 SEMIHOSTING_SYS_ISERROR = 0x08,
21 SEMIHOSTING_SYS_ISTTY = 0x09,
22 SEMIHOSTING_SYS_OPEN = 0x01,
23 SEMIHOSTING_SYS_READ = 0x06,
24 SEMIHOSTING_SYS_READC = 0x07,
25 SEMIHOSTING_SYS_REMOVE = 0x0E,
26 SEMIHOSTING_SYS_RENAME = 0x0F,
27 SEMIHOSTING_SYS_SEEK = 0x0A,
28 SEMIHOSTING_SYS_SYSTEM = 0x12,
29 SEMIHOSTING_SYS_TICKFREQ = 0x31,
30 SEMIHOSTING_SYS_TIME = 0x11,
31 SEMIHOSTING_SYS_TMPNAM = 0x0D,
32 SEMIHOSTING_SYS_WRITE = 0x05,
33 SEMIHOSTING_SYS_WRITEC = 0x03,
34 SEMIHOSTING_SYS_WRITE0 = 0x04,
36 // Codes returned by SEMIHOSTING_ReportException
37 ADP_Stopped_ApplicationExit = ((2 << 16) + 38),
38 ADP_Stopped_RunTimeError = ((2 << 16) + 35),
42 // ----------------------------------------------------------------------------
44 // SWI numbers and reason codes for RDI (Angel) monitors.
45 #define AngelSWI_ARM 0x123456
49 #define AngelSWI AngelSWI_ARM
51 // For thumb only architectures use the BKPT instruction instead of SWI.
52 #if defined(__ARM_ARCH_7M__) \
53 || defined(__ARM_ARCH_7EM__) \
54 || defined(__ARM_ARCH_6M__) \
55 || defined(__ARM_ARCH_8M_BASE__)
56 #define AngelSWIInsn "bkpt"
57 #define AngelSWIAsm bkpt
59 #define AngelSWIInsn "swi"
60 #define AngelSWIAsm swi
63 #if defined(OS_DEBUG_SEMIHOSTING_FAULTS)
64 // Testing the local semihosting handler cannot use another BKPT, since this
65 // configuration cannot trigger HaedFault exceptions while the debugger is
66 // connected, so we use an illegal op code, that will trigger an
67 // UsageFault exception.
68 #define AngelSWITestFault "setend be"
69 #define AngelSWITestFaultOpCode (0xB658)
73 __attribute__ ((always_inline))
74 call_host (int reason, void* arg)
81 #if defined(OS_DEBUG_SEMIHOSTING_FAULTS)
82 " " AngelSWITestFault " \n"
84 " " AngelSWIInsn " %[swi] \n"
88 : [val] "=r" (value) /* Outputs */
89 : [rsn] "r" (reason), [arg] "r" (arg), [swi] "i" (AngelSWI) /* Inputs */
90 : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc"
91 // Clobbers r0 and r1, and lr if in supervisor mode
94 // Accordingly to page 13-77 of ARM DUI 0040D other registers
95 // can also be clobbered. Some memory positions may also be
96 // changed by a system call, so they should not be kept in
97 // registers. Note: we are assuming the manual is right and
98 // Angel is respecting the APCS.
102 // ----------------------------------------------------------------------------
104 // Function used in _exit() to return the status code as Angel exception.
106 __attribute__ ((always_inline,noreturn))
107 report_exception (int reason)
109 call_host (SEMIHOSTING_ReportException, (void*) reason);
115 // ----------------------------------------------------------------------------
117 #endif // ARM_SEMIHOSTING_H_