EVE 1.0
semihosting.h
Go to the documentation of this file.
1 #ifndef SEMIHOSTING_H_INCLUDED
2 #define SEMIHOSTING_H_INCLUDED
3 /**********************************************************************/
4 /*
5  * Copyright (c) 2015-2016, Jetro AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONRIBUTORS ``AS IS'' AND ANY EXPRESS
20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the EVE platform.
31  */
32 
33  /**
34  * \file
35  * \brief Semihosting interface
36  *
37  * \author DT, Jetro AS
38  */ /******************************************************************/
39 
40 /**
41  * \addtogroup debug
42  * @{
43  *
44  * Semihosting is a mechanism that enables code running on an ARM target
45  * to communicate and use the Input/Output facilities on a host computer
46  * that is running a debugger.
47  *
48  * Examples of these facilities include keyboard input, screen output,
49  * and disk I/O. For example, you can use this mechanism to enable functions
50  * in the C library, such as printf() and scanf(), to use the screen and keyboard
51  * of the host instead of having a screen and keyboard on the target system.
52  *
53  * This is useful because development hardware often does not have all the input
54  * and output facilities of the final system. Semihosting enables the host
55  * computer to provide these facilities.
56  *
57  * Semihosting is implemented by a set of defined software instructions,
58  * that generate exceptions from program control. The application invokes
59  * the appropriate semihosting call and the debug agent then handles the
60  * exception. The debug agent provides the required communication with the host.
61  *
62  * For more details please check http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0471g/Bgbjjgij.html
63  ***********************************************************************/
64 
65 /**
66  * Semihosting opcodes, please check ARM documentation for more details
67  */
68 enum
69 {
70  angel_SWIreason_EnterSVC = 0x17,
71  angel_SWIreason_ReportException = 0x18,
72  SYS_CLOSE = 0x02,
73  SYS_CLOCK = 0x10,
74  SYS_ELAPSED = 0x30,
75  SYS_ERRNO = 0x13,
76  SYS_FLEN = 0x0C,
77  SYS_GET_CMDLINE = 0x15,
78  SYS_HEAPINFO = 0x16,
79  SYS_ISERROR = 0x08,
80  SYS_ISTTY = 0x09,
81  SYS_OPEN = 0x01,
82  SYS_READ = 0x06,
83  SYS_READC = 0x07,
84  SYS_REMOVE = 0x0E,
85  SYS_SEEK = 0x0A,
86  SYS_SYSTEM = 0x12,
87  SYS_TICKFREQ = 0x31,
88  SYS_TIME = 0x11,
89  SYS_TMPNAM = 0x0D,
90  SYS_WRITE = 0x05,
91  SYS_WRITEC = 0x03,
92  SYS_WRITE0 = 0x04,
93 };
94 
95 /**
96  * angel_SWIreason_ReportException reason codes.
97  */
98 enum
99 {
100  ADP_Stopped_BranchThroughZero = 0x20000,
101  ADP_Stopped_UndefinedInstr = 0x20001,
102  ADP_Stopped_SoftwareInterrupt = 0x20002,
103  ADP_Stopped_PrefetchAbort = 0x20003,
104  ADP_Stopped_DataAbort = 0x20004,
105  ADP_Stopped_AddressException = 0x20005,
106  ADP_Stopped_IRQ = 0x20006,
107  ADP_Stopped_FIQ = 0x20007,
108 
109  ADP_Stopped_BreakPoint = 0x20020,
110  ADP_Stopped_WatchPoint = 0x20021,
111  ADP_Stopped_StepComplete = 0x20022,
112  ADP_Stopped_RunTimeErrorUnknown = 0x20023,
113  ADP_Stopped_InternalError = 0x20024,
114  ADP_Stopped_UserInterruption = 0x20025,
115  ADP_Stopped_ApplicationExit = 0x20026,
116  ADP_Stopped_StackOverflow = 0x20027,
117  ADP_Stopped_DivisionByZero = 0x20028,
118  ADP_Stopped_OSSpecific = 0x20029,
119 };
120 
121 /**
122  * Performs a semihosting call
123  *
124  * @param cmd The semihosting command
125  * @param msg The semihosting message
126  * @return Return value of the executed command
127  */
128 static inline int32_t call_semihost(uint32_t cmd, const void *msg)
129 {
130  register uint32_t rcmd __ASM("r0") = cmd;
131  register const void *rmsg __ASM("r1") = msg;
132  register int32_t result __ASM("r0");
133 
134  __DSB();
135  __ASM volatile ("BKPT #0xAB" : "=r" (result) : "r" (rcmd), "r" (rmsg));
136 
137  return result;
138 }
139 
140 /** @} */ /* debug */
141 
142 #endif /* SEMIHOSTING_H_INCLUDED */
static int32_t call_semihost(uint32_t cmd, const void *msg)
Definition: semihosting.h:128