1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *  * Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 *  * Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in
12 *    the documentation and/or other materials provided with the
13 *    distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29    .text
30    .balign 0
31
32    .global asm_test_jacket
33
34    // Set the register and flag values
35    // Calls the asm function
36    // Reads the register/flag values to output register
37
38    // Parameters
39    // X0 - Function to jump
40    // X1 - register values array
41    // X2 - flag values array
42asm_test_jacket:
43    // Save registers to stack
44    stp    x29, x30, [sp,#-16]!
45    stp    x27, x28, [sp,#-16]!
46
47    mov x30, x0
48    mov x28, x1
49    mov x27, x2
50
51    //Set the flags based on flag array
52    //EQ
53    ldr w0, [x27,#0]
54    cmp w0, #1
55    b.ne bt_aeq
56    cmp w0,#1
57    b bt_end
58bt_aeq:
59
60    //NE
61    ldr w0, [x27,#4]
62    cmp w0, #1
63    b.ne bt_ane
64    cmp w0,#2
65    b bt_end
66bt_ane:
67
68    //CS
69    ldr w0, [x27,#8]
70    cmp w0, #1
71    b.ne bt_acs
72    cmp w0,#0
73    b bt_end
74bt_acs:
75
76    //CC
77    ldr w0, [x27,#12]
78    cmp w0, #1
79    b.ne bt_acc
80    cmp w0,#2
81    b bt_end
82bt_acc:
83
84    //MI
85    ldr w0, [x27,#16]
86    cmp w0, #1
87    b.ne bt_ami
88    subs w0,w0,#2
89    b bt_end
90bt_ami:
91
92    //PL
93    ldr w0, [x27,#20]
94    cmp w0, #1
95    b.ne bt_apl
96    subs w0,w0,#0
97    b bt_end
98bt_apl:
99    //HI - (C==1) && (Z==0)
100    ldr w0, [x27,#32]
101    cmp w0, #1
102    b.ne bt_ahi
103    cmp w0,#0
104    b bt_end
105bt_ahi:
106
107    //LS - (C==0) || (Z==1)
108    ldr w0, [x27,#36]
109    cmp w0, #1
110    b.ne bt_als
111    cmp w0,#1
112    b bt_end
113bt_als:
114
115    //GE
116    ldr w0, [x27,#40]
117    cmp w0, #1
118    b.ne bt_age
119    cmp w0,#0
120    b bt_end
121bt_age:
122
123    //LT
124    ldr w0, [x27,#44]
125    cmp w0, #1
126    b.ne bt_alt
127    cmp w0,#2
128    b bt_end
129bt_alt:
130
131    //GT
132    ldr w0, [x27,#48]
133    cmp w0, #1
134    b.ne bt_agt
135    cmp w0,#0
136    b bt_end
137bt_agt:
138
139    //LE
140    ldr w0, [x27,#52]
141    cmp w0, #1
142    b.ne bt_ale
143    cmp w0,#2
144    b bt_end
145bt_ale:
146
147
148bt_end:
149
150    // Load the registers from reg array
151    ldr x0, [x28,#0]
152    ldr x1, [x28,#8]
153    ldr x2, [x28,#16]
154    ldr x3, [x28,#24]
155    ldr x4, [x28,#32]
156    ldr x5, [x28,#40]
157    ldr x6, [x28,#48]
158    ldr x7, [x28,#56]
159    ldr x8, [x28,#64]
160    ldr x9, [x28,#72]
161    ldr x10, [x28,#80]
162    ldr x11, [x28,#88]
163    ldr x12, [x28,#96]
164    ldr x14, [x28,#112]
165
166    // Call the function
167    blr X30
168
169    // Save the registers to reg array
170    str x0, [x28,#0]
171    str x1, [x28,#8]
172    str x2, [x28,#16]
173    str x3, [x28,#24]
174    str x4, [x28,#32]
175    str x5, [x28,#40]
176    str x6, [x28,#48]
177    str x7, [x28,#56]
178    str x8, [x28,#64]
179    str x9, [x28,#72]
180    str x10, [x28,#80]
181    str x11, [x28,#88]
182    str x12, [x28,#96]
183    str x14, [x28,#112]
184
185    //Set the flags array based on result flags
186    movz w0, #0
187    movz w1, #1
188    csel w2, w1, w0, EQ
189    str w2, [x27,#0]
190    csel w2, w1, w0, NE
191    str w2, [x27,#4]
192    csel w2, w1, w0, CS
193    str w2, [x27,#8]
194    csel w2, w1, w0, CC
195    str w2, [x27,#12]
196    csel w2, w1, w0, MI
197    str w2, [x27,#16]
198    csel w2, w1, w0, PL
199    str w2, [x27,#20]
200    csel w2, w1, w0, VS
201    str w2, [x27,#24]
202    csel w2, w1, w0, VC
203    str w2, [x27,#28]
204    csel w2, w1, w0, HI
205    str w2, [x27,#32]
206    csel w2, w1, w0, LS
207    str w2, [x27,#36]
208    csel w2, w1, w0, GE
209    str w2, [x27,#40]
210    csel w2, w1, w0, LT
211    str w2, [x27,#44]
212    csel w2, w1, w0, GT
213    str w2, [x27,#48]
214    csel w2, w1, w0, LE
215    str w2, [x27,#52]
216
217    // Restore registers from stack
218    ldp    x27, x28, [sp],#16
219    ldp    x29, x30, [sp],#16
220    ret
221
222