µ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 Liviu Ionescu.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28#ifndef CMSIS_PLUS_ARM_SEMIHOSTING_H_
29#define CMSIS_PLUS_ARM_SEMIHOSTING_H_
30
31// ----------------------------------------------------------------------------
32
33// Semihosting operations.
35{
36 // Regular operations
61
62 // Codes returned by SEMIHOSTING_ReportException
63 ADP_Stopped_ApplicationExit = ((2 << 16) + 38),
64 ADP_Stopped_RunTimeError = ((2 << 16) + 35),
65
66};
67
68// ----------------------------------------------------------------------------
69
70// SWI numbers and reason codes for RDI (Angel) monitors.
71#define AngelSWI_ARM 0x123456
72#ifdef __thumb__
73#define AngelSWI 0xAB
74#else
75#define AngelSWI AngelSWI_ARM
76#endif
77// For thumb only architectures use the BKPT instruction instead of SWI.
78#if defined(__ARM_ARCH_7M__) \
79 || defined(__ARM_ARCH_7EM__) \
80 || defined(__ARM_ARCH_6M__)
81#define AngelSWIInsn "bkpt"
82#define AngelSWIAsm bkpt
83#else
84#define AngelSWIInsn "swi"
85#define AngelSWIAsm swi
86#endif
87
88#if defined(OS_DEBUG_SEMIHOSTING_FAULTS)
89// Testing the local semihosting handler cannot use another BKPT, since this
90// configuration cannot trigger HaedFault exceptions while the debugger is
91// connected, so we use an illegal op code, that will trigger an
92// UsageFault exception.
93#define AngelSWITestFault "setend be"
94#define AngelSWITestFaultOpCode (0xB658)
95#endif
96
97static inline int
98__attribute__ ((always_inline))
99call_host (int reason, void* arg)
100{
101 int value;
102 asm volatile (
103
104 " mov r0, %[rsn] \n"
105 " mov r1, %[arg] \n"
106#if defined(OS_DEBUG_SEMIHOSTING_FAULTS)
107 " " AngelSWITestFault " \n"
108#else
109 " " AngelSWIInsn " %[swi] \n"
110#endif
111 " mov %[val], r0"
112
113 : [val] "=r" (value) /* Outputs */
114 : [rsn] "r" (reason), [arg] "r" (arg), [swi] "i" (AngelSWI) /* Inputs */
115 : "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc"
116 // Clobbers r0 and r1, and lr if in supervisor mode
117 );
118
119 // Accordingly to page 13-77 of ARM DUI 0040D other registers
120 // can also be clobbered. Some memory positions may also be
121 // changed by a system call, so they should not be kept in
122 // registers. Note: we are assuming the manual is right and
123 // Angel is respecting the APCS.
124 return value;
125}
126
127// ----------------------------------------------------------------------------
128
129// Function used in _exit() to return the status code as Angel exception.
130static inline void
131__attribute__ ((always_inline,noreturn))
133{
134 call_host (SEMIHOSTING_ReportException, (void*) reason);
135
136 for (;;)
137 ;
138}
139
140// ----------------------------------------------------------------------------
141
142#endif /* CMSIS_PLUS_ARM_SEMIHOSTING_H_ */
#define AngelSWIInsn
Definition semihosting.h:84
static void report_exception(int reason)
OperationNumber
Definition semihosting.h:35
@ SEMIHOSTING_SYS_TICKFREQ
Definition semihosting.h:55
@ ADP_Stopped_RunTimeError
Definition semihosting.h:64
@ SEMIHOSTING_ReportException
Definition semihosting.h:38
@ SEMIHOSTING_SYS_ISERROR
Definition semihosting.h:46
@ SEMIHOSTING_EnterSVC
Definition semihosting.h:37
@ SEMIHOSTING_SYS_WRITE
Definition semihosting.h:58
@ SEMIHOSTING_SYS_FLEN
Definition semihosting.h:43
@ SEMIHOSTING_SYS_GET_CMDLINE
Definition semihosting.h:44
@ SEMIHOSTING_SYS_REMOVE
Definition semihosting.h:51
@ SEMIHOSTING_SYS_SEEK
Definition semihosting.h:53
@ SEMIHOSTING_SYS_TMPNAM
Definition semihosting.h:57
@ ADP_Stopped_ApplicationExit
Definition semihosting.h:63
@ SEMIHOSTING_SYS_TIME
Definition semihosting.h:56
@ SEMIHOSTING_SYS_CLOCK
Definition semihosting.h:40
@ SEMIHOSTING_SYS_WRITEC
Definition semihosting.h:59
@ SEMIHOSTING_SYS_ERRNO
Definition semihosting.h:42
@ SEMIHOSTING_SYS_ISTTY
Definition semihosting.h:47
@ SEMIHOSTING_SYS_HEAPINFO
Definition semihosting.h:45
@ SEMIHOSTING_SYS_WRITE0
Definition semihosting.h:60
@ SEMIHOSTING_SYS_ELAPSED
Definition semihosting.h:41
@ SEMIHOSTING_SYS_READ
Definition semihosting.h:49
@ SEMIHOSTING_SYS_SYSTEM
Definition semihosting.h:54
@ SEMIHOSTING_SYS_CLOSE
Definition semihosting.h:39
@ SEMIHOSTING_SYS_READC
Definition semihosting.h:50
@ SEMIHOSTING_SYS_OPEN
Definition semihosting.h:48
@ SEMIHOSTING_SYS_RENAME
Definition semihosting.h:52
#define AngelSWI
Definition semihosting.h:75
static int call_host(int reason, void *arg)
Definition semihosting.h:99