NUC472_NUC442_BSP V3.03.005
The Board Support Package for NUC472/NUC442
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.
9{
10 // Regular operations
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
71static 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.
104static 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_
#define AngelSWIInsn
Definition: semihosting.h:58
OperationNumber
Definition: semihosting.h:9
@ SEMIHOSTING_SYS_TICKFREQ
Definition: semihosting.h:29
@ ADP_Stopped_RunTimeError
Definition: semihosting.h:38
@ SEMIHOSTING_ReportException
Definition: semihosting.h:12
@ SEMIHOSTING_SYS_ISERROR
Definition: semihosting.h:20
@ SEMIHOSTING_EnterSVC
Definition: semihosting.h:11
@ SEMIHOSTING_SYS_WRITE
Definition: semihosting.h:32
@ SEMIHOSTING_SYS_FLEN
Definition: semihosting.h:17
@ SEMIHOSTING_SYS_GET_CMDLINE
Definition: semihosting.h:18
@ SEMIHOSTING_SYS_REMOVE
Definition: semihosting.h:25
@ SEMIHOSTING_SYS_SEEK
Definition: semihosting.h:27
@ SEMIHOSTING_SYS_TMPNAM
Definition: semihosting.h:31
@ ADP_Stopped_ApplicationExit
Definition: semihosting.h:37
@ SEMIHOSTING_SYS_TIME
Definition: semihosting.h:30
@ SEMIHOSTING_SYS_CLOCK
Definition: semihosting.h:14
@ SEMIHOSTING_SYS_WRITEC
Definition: semihosting.h:33
@ SEMIHOSTING_SYS_ERRNO
Definition: semihosting.h:16
@ SEMIHOSTING_SYS_ISTTY
Definition: semihosting.h:21
@ SEMIHOSTING_SYS_HEAPINFO
Definition: semihosting.h:19
@ SEMIHOSTING_SYS_WRITE0
Definition: semihosting.h:34
@ SEMIHOSTING_SYS_ELAPSED
Definition: semihosting.h:15
@ SEMIHOSTING_SYS_READ
Definition: semihosting.h:23
@ SEMIHOSTING_SYS_SYSTEM
Definition: semihosting.h:28
@ SEMIHOSTING_SYS_CLOSE
Definition: semihosting.h:13
@ SEMIHOSTING_SYS_READC
Definition: semihosting.h:24
@ SEMIHOSTING_SYS_OPEN
Definition: semihosting.h:22
@ SEMIHOSTING_SYS_RENAME
Definition: semihosting.h:26
static int void * arg
Definition: semihosting.h:74
#define AngelSWI
Definition: semihosting.h:49
static int __attribute__((always_inline)) call_host(int reason
return value
Definition: semihosting.h:98