µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
semihosting.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2015-2023 Liviu Ionescu. All rights reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose is hereby granted, under the terms of the MIT license.
8 *
9 * If a copy of the license was not distributed with this file, it can
10 * be obtained from https://opensource.org/licenses/mit/.
11 */
12
13#ifndef CMSIS_PLUS_ARM_SEMIHOSTING_H_
14#define CMSIS_PLUS_ARM_SEMIHOSTING_H_
15
16// ----------------------------------------------------------------------------
17
18#if defined(OS_USE_OS_APP_CONFIG_H)
19#include <cmsis-plus/os-app-config.h>
20#endif
21
22// ----------------------------------------------------------------------------
23
24#if defined(__cplusplus)
25extern "C"
26{
27#endif // defined(__cplusplus)
28
29// ----------------------------------------------------------------------------
30
31// Semihosting operations.
33{
34 // Regular operations
59
60 // Codes returned by SEMIHOSTING_ReportException
61 ADP_Stopped_ApplicationExit = ((2 << 16) + 38),
62 ADP_Stopped_RunTimeError = ((2 << 16) + 35),
63
64};
65
66// ----------------------------------------------------------------------------
67
68// SWI numbers and reason codes for RDI (Angel) monitors.
69#define AngelSWI_ARM 0x123456
70#ifdef __thumb__
71#define AngelSWI 0xAB
72#else
73#define AngelSWI AngelSWI_ARM
74#endif
75// For thumb only architectures use the BKPT instruction instead of SWI.
76#if defined(__ARM_ARCH_7M__) \
77 || defined(__ARM_ARCH_7EM__) \
78 || defined(__ARM_ARCH_6M__)
79#define AngelSWIInsn "bkpt"
80#define AngelSWIAsm bkpt
81#else
82#define AngelSWIInsn "swi"
83#define AngelSWIAsm swi
84#endif
85
86#if defined(OS_DEBUG_SEMIHOSTING_FAULTS)
87// Testing the local semihosting handler cannot use another BKPT, since this
88// configuration cannot trigger HaedFault exceptions while the debugger is
89// connected, so we use an illegal op code, that will trigger an
90// UsageFault exception.
91#define AngelSWITestFault "setend be"
92#define AngelSWITestFaultOpCode (0xB658)
93#endif
94
95#pragma GCC diagnostic push
96#pragma GCC diagnostic ignored "-Wunused-parameter"
97
98static inline int
99__attribute__ ((always_inline))
100call_host (int reason, void* arg)
101{
102 int value;
103 __asm__ volatile (
104
105 " mov r0, %[rsn] \n"
106 " mov r1, %[arg] \n"
107#if defined(OS_DEBUG_SEMIHOSTING_FAULTS)
108 " " AngelSWITestFault " \n"
109#else
110 " " AngelSWIInsn " %[swi] \n"
111#endif
112 " mov %[val], r0"
113
114 : [val] "=r" (value) /* Outputs */
115 : [rsn] "r" (reason), [arg] "r" (arg), [swi] "i" (AngelSWI) /* Inputs */
116 : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc"
117 // Clobbers r0 and r1, and lr if in supervisor mode
118 );
119
120 // Accordingly to page 13-77 of ARM DUI 0040D other registers
121 // can also be clobbered. Some memory positions may also be
122 // changed by a system call, so they should not be kept in
123 // registers. Note: we are assuming the manual is right and
124 // Angel is respecting the APCS.
125 return value;
126}
127
128#pragma GCC diagnostic pop
129
130// ----------------------------------------------------------------------------
131
132// Function used in _exit() to return the status code as Angel exception.
133static inline void
134__attribute__ ((always_inline,noreturn))
136{
137 call_host (SEMIHOSTING_ReportException, (void*) reason);
138
139 for (;;)
140 ;
141}
142
143// ----------------------------------------------------------------------------
144
145#if defined(__cplusplus)
146}
147#endif // defined(__cplusplus)
148
149// ----------------------------------------------------------------------------
150
151#endif /* CMSIS_PLUS_ARM_SEMIHOSTING_H_ */
#define AngelSWIInsn
Definition semihosting.h:82
static void report_exception(int reason)
OperationNumber
Definition semihosting.h:33
@ SEMIHOSTING_SYS_TICKFREQ
Definition semihosting.h:53
@ ADP_Stopped_RunTimeError
Definition semihosting.h:62
@ SEMIHOSTING_ReportException
Definition semihosting.h:36
@ SEMIHOSTING_SYS_ISERROR
Definition semihosting.h:44
@ SEMIHOSTING_EnterSVC
Definition semihosting.h:35
@ SEMIHOSTING_SYS_WRITE
Definition semihosting.h:56
@ SEMIHOSTING_SYS_FLEN
Definition semihosting.h:41
@ SEMIHOSTING_SYS_GET_CMDLINE
Definition semihosting.h:42
@ SEMIHOSTING_SYS_REMOVE
Definition semihosting.h:49
@ SEMIHOSTING_SYS_SEEK
Definition semihosting.h:51
@ SEMIHOSTING_SYS_TMPNAM
Definition semihosting.h:55
@ ADP_Stopped_ApplicationExit
Definition semihosting.h:61
@ SEMIHOSTING_SYS_TIME
Definition semihosting.h:54
@ SEMIHOSTING_SYS_CLOCK
Definition semihosting.h:38
@ SEMIHOSTING_SYS_WRITEC
Definition semihosting.h:57
@ SEMIHOSTING_SYS_ERRNO
Definition semihosting.h:40
@ SEMIHOSTING_SYS_ISTTY
Definition semihosting.h:45
@ SEMIHOSTING_SYS_HEAPINFO
Definition semihosting.h:43
@ SEMIHOSTING_SYS_WRITE0
Definition semihosting.h:58
@ SEMIHOSTING_SYS_ELAPSED
Definition semihosting.h:39
@ SEMIHOSTING_SYS_READ
Definition semihosting.h:47
@ SEMIHOSTING_SYS_SYSTEM
Definition semihosting.h:52
@ SEMIHOSTING_SYS_CLOSE
Definition semihosting.h:37
@ SEMIHOSTING_SYS_READC
Definition semihosting.h:48
@ SEMIHOSTING_SYS_OPEN
Definition semihosting.h:46
@ SEMIHOSTING_SYS_RENAME
Definition semihosting.h:50
#define AngelSWI
Definition semihosting.h:73
static int call_host(int reason, void *arg)