1 /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd.  All rights reserved.
2 
3  Redistribution and use in source and binary forms, with or without
4  modification, are permitted provided that the following conditions
5  are met:
6  1. Redistributions of source code must retain the above copyright
7     notice, this list of conditions and the following disclaimer.
8  2. Redistributions in binary form must reproduce the above copyright
9     notice, this list of conditions and the following disclaimer in the
10     documentation and/or other materials provided with the distribution.
11  3. The name of the company may not be used to endorse or promote
12     products derived from this software without specific prior written
13     permission.
14 
15  THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
16  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
20  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
25 
26 /* Now the SWI numbers and reason codes for RDI (Angel) monitors.  */
27 #define AngelSVC			0xF000
28 #define AngelSVCInsn			"hlt"
29 #define AngelSVCAsm			hlt
30 
31 /* The reason codes:  */
32 #define AngelSVC_Reason_Open		0x01
33 #define AngelSVC_Reason_Close		0x02
34 #define AngelSVC_Reason_WriteC		0x03
35 #define AngelSVC_Reason_Write0		0x04
36 #define AngelSVC_Reason_Write		0x05
37 #define AngelSVC_Reason_Read		0x06
38 #define AngelSVC_Reason_ReadC		0x07
39 #define AngelSVC_Reason_IsTTY		0x09
40 #define AngelSVC_Reason_Seek		0x0A
41 #define AngelSVC_Reason_FLen		0x0C
42 #define AngelSVC_Reason_TmpNam		0x0D
43 #define AngelSVC_Reason_Remove		0x0E
44 #define AngelSVC_Reason_Rename		0x0F
45 #define AngelSVC_Reason_Clock		0x10
46 #define AngelSVC_Reason_Time		0x11
47 #define AngelSVC_Reason_System		0x12
48 #define AngelSVC_Reason_Errno		0x13
49 #define AngelSVC_Reason_GetCmdLine	0x15
50 #define AngelSVC_Reason_HeapInfo	0x16
51 #define AngelSVC_Reason_EnterSVC	0x17
52 #define AngelSVC_Reason_ReportException 0x18
53 #define AngelSVC_Reason_SyncCacheRange	0x19
54 #define AngelSVC_Reason_Elapsed         0x30
55 #define ADP_Stopped_ApplicationExit	((2 << 16) + 38)
56 #define ADP_Stopped_RunTimeError	((2 << 16) + 35)
57 
58 #if defined(ARM_RDI_MONITOR) && !defined(__ASSEMBLER__)
59 
60 /* Type of each entry in a parameter block.  */
61 typedef long long param_block_t;
62 
63 static inline long long
do_AngelSVC(int reason,param_block_t * arg)64 do_AngelSVC (int reason, param_block_t * arg)
65 {
66   long long value;
67   asm volatile ("mov w0, %w1; mov x1, %2; " AngelSVCInsn " %3; mov %0, x0"
68 		: "=r" (value) /* Outputs */
69 		: "r" (reason), "r" (arg), "n" (AngelSVC) /* Inputs */
70 		: "x0", "x1", "x2", "x3", "x17", "x30", "memory", "cc"
71 		  /* Clobbers x0 and x1, and lr if in supervisor mode */);
72   return value;
73 }
74 
75 #endif
76