| NUC029FAE_BSP V3.02.000 The Board Support Package for NUC029FAE MCU

semihosting.h
Go to the documentation of this file.
1
2#ifndef ARM_SEMIHOSTING_H_
3#define ARM_SEMIHOSTING_H_
4
5// ----------------------------------------------------------------------------
6
7// Semihosting operations.
8 enum OperationNumber
9{
10 // Regular 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,
35
36 // Codes returned by SEMIHOSTING_ReportException
37 ADP_Stopped_ApplicationExit = ((2 << 16) + 38),
38 ADP_Stopped_RunTimeError = ((2 << 16) + 35),
39
40};
41
42// ----------------------------------------------------------------------------
43
44// SWI numbers and reason codes for RDI (Angel) monitors.
45#define AngelSWI_ARM 0x123456
46#ifdef __thumb__
47#define AngelSWI 0xAB
48#else
49#define AngelSWI AngelSWI_ARM
50#endif
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#define AngelSWIInsn "bkpt"
56#define AngelSWIAsm bkpt
57#else
58#define AngelSWIInsn "swi"
59#define AngelSWIAsm swi
60#endif
61
62#if defined(OS_DEBUG_SEMIHOSTING_FAULTS)
63// Testing the local semihosting handler cannot use another BKPT, since this
64// configuration cannot trigger HaedFault exceptions while the debugger is
65// connected, so we use an illegal op code, that will trigger an
66// UsageFault exception.
67#define AngelSWITestFault "setend be"
68#define AngelSWITestFaultOpCode (0xB658)
69#endif
70
71 static inline int
72__attribute__ ((always_inline))
73call_host (int reason, void* arg)
74{
75 int value;
76 asm volatile (
77
78 " mov r0, %[rsn] \n"
79 " mov r1, %[arg] \n"
80#if defined(OS_DEBUG_SEMIHOSTING_FAULTS)
81 " " AngelSWITestFault " \n"
82#else
83 " " AngelSWIInsn " %[swi] \n"
84#endif
85 " mov %[val], r0"
86
87 : [val] "=r" (value) /* Outputs */
88 : [rsn] "r" (reason), [arg] "r" (arg), [swi] "i" (AngelSWI) /* Inputs */
89 : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc"
90 // Clobbers r0 and r1, and lr if in supervisor mode
91 );
92
93 // Accordingly to page 13-77 of ARM DUI 0040D other registers
94 // can also be clobbered. Some memory positions may also be
95 // changed by a system call, so they should not be kept in
96 // registers. Note: we are assuming the manual is right and
97 // Angel is respecting the APCS.
98 return value;
99}
100
101// ----------------------------------------------------------------------------
102
103// Function used in _exit() to return the status code as Angel exception.
104 static inline void
105__attribute__ ((always_inline,noreturn))
106report_exception (int reason)
107{
108 call_host (SEMIHOSTING_ReportException, (void*) reason);
109
110 for (;;)
111 ;
112}
113
114// ----------------------------------------------------------------------------
115
116#endif // ARM_SEMIHOSTING_H_
AngelSWIInsn
#define AngelSWIInsn
Definition: semihosting.h:58
OperationNumber
OperationNumber
Definition: semihosting.h:9
SEMIHOSTING_SYS_TICKFREQ
@ SEMIHOSTING_SYS_TICKFREQ
Definition: semihosting.h:29
ADP_Stopped_RunTimeError
@ ADP_Stopped_RunTimeError
Definition: semihosting.h:38
SEMIHOSTING_ReportException
@ SEMIHOSTING_ReportException
Definition: semihosting.h:12
SEMIHOSTING_SYS_ISERROR
@ SEMIHOSTING_SYS_ISERROR
Definition: semihosting.h:20
SEMIHOSTING_EnterSVC
@ SEMIHOSTING_EnterSVC
Definition: semihosting.h:11
SEMIHOSTING_SYS_WRITE
@ SEMIHOSTING_SYS_WRITE
Definition: semihosting.h:32
SEMIHOSTING_SYS_FLEN
@ SEMIHOSTING_SYS_FLEN
Definition: semihosting.h:17
SEMIHOSTING_SYS_GET_CMDLINE
@ SEMIHOSTING_SYS_GET_CMDLINE
Definition: semihosting.h:18
SEMIHOSTING_SYS_REMOVE
@ SEMIHOSTING_SYS_REMOVE
Definition: semihosting.h:25
SEMIHOSTING_SYS_SEEK
@ SEMIHOSTING_SYS_SEEK
Definition: semihosting.h:27
SEMIHOSTING_SYS_TMPNAM
@ SEMIHOSTING_SYS_TMPNAM
Definition: semihosting.h:31
ADP_Stopped_ApplicationExit
@ ADP_Stopped_ApplicationExit
Definition: semihosting.h:37
SEMIHOSTING_SYS_TIME
@ SEMIHOSTING_SYS_TIME
Definition: semihosting.h:30
SEMIHOSTING_SYS_CLOCK
@ SEMIHOSTING_SYS_CLOCK
Definition: semihosting.h:14
SEMIHOSTING_SYS_WRITEC
@ SEMIHOSTING_SYS_WRITEC
Definition: semihosting.h:33
SEMIHOSTING_SYS_ERRNO
@ SEMIHOSTING_SYS_ERRNO
Definition: semihosting.h:16
SEMIHOSTING_SYS_ISTTY
@ SEMIHOSTING_SYS_ISTTY
Definition: semihosting.h:21
SEMIHOSTING_SYS_HEAPINFO
@ SEMIHOSTING_SYS_HEAPINFO
Definition: semihosting.h:19
SEMIHOSTING_SYS_WRITE0
@ SEMIHOSTING_SYS_WRITE0
Definition: semihosting.h:34
SEMIHOSTING_SYS_ELAPSED
@ SEMIHOSTING_SYS_ELAPSED
Definition: semihosting.h:15
SEMIHOSTING_SYS_READ
@ SEMIHOSTING_SYS_READ
Definition: semihosting.h:23
SEMIHOSTING_SYS_SYSTEM
@ SEMIHOSTING_SYS_SYSTEM
Definition: semihosting.h:28
SEMIHOSTING_SYS_CLOSE
@ SEMIHOSTING_SYS_CLOSE
Definition: semihosting.h:13
SEMIHOSTING_SYS_READC
@ SEMIHOSTING_SYS_READC
Definition: semihosting.h:24
SEMIHOSTING_SYS_OPEN
@ SEMIHOSTING_SYS_OPEN
Definition: semihosting.h:22
SEMIHOSTING_SYS_RENAME
@ SEMIHOSTING_SYS_RENAME
Definition: semihosting.h:26
arg
static int void * arg
Definition: semihosting.h:74
AngelSWI
#define AngelSWI
Definition: semihosting.h:49
__attribute__
static int __attribute__((always_inline)) call_host(int reason
value
return value
Definition: semihosting.h:98