]>
Commit | Line | Data |
---|---|---|
01127f1e CB |
1 | /* |
2 | * Copyright 2015, Cyril Bur, IBM Corp. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public License | |
6 | * as published by the Free Software Foundation; either version | |
7 | * 2 of the License, or (at your option) any later version. | |
8 | */ | |
9 | ||
10 | #include "../basic_asm.h" | |
11 | ||
12 | #define PUSH_VMX(pos,reg) \ | |
13 | li reg,pos; \ | |
14 | stvx v20,reg,sp; \ | |
15 | addi reg,reg,16; \ | |
16 | stvx v21,reg,sp; \ | |
17 | addi reg,reg,16; \ | |
18 | stvx v22,reg,sp; \ | |
19 | addi reg,reg,16; \ | |
20 | stvx v23,reg,sp; \ | |
21 | addi reg,reg,16; \ | |
22 | stvx v24,reg,sp; \ | |
23 | addi reg,reg,16; \ | |
24 | stvx v25,reg,sp; \ | |
25 | addi reg,reg,16; \ | |
26 | stvx v26,reg,sp; \ | |
27 | addi reg,reg,16; \ | |
28 | stvx v27,reg,sp; \ | |
29 | addi reg,reg,16; \ | |
30 | stvx v28,reg,sp; \ | |
31 | addi reg,reg,16; \ | |
32 | stvx v29,reg,sp; \ | |
33 | addi reg,reg,16; \ | |
34 | stvx v30,reg,sp; \ | |
35 | addi reg,reg,16; \ | |
36 | stvx v31,reg,sp; | |
37 | ||
38 | #define POP_VMX(pos,reg) \ | |
39 | li reg,pos; \ | |
40 | lvx v20,reg,sp; \ | |
41 | addi reg,reg,16; \ | |
42 | lvx v21,reg,sp; \ | |
43 | addi reg,reg,16; \ | |
44 | lvx v22,reg,sp; \ | |
45 | addi reg,reg,16; \ | |
46 | lvx v23,reg,sp; \ | |
47 | addi reg,reg,16; \ | |
48 | lvx v24,reg,sp; \ | |
49 | addi reg,reg,16; \ | |
50 | lvx v25,reg,sp; \ | |
51 | addi reg,reg,16; \ | |
52 | lvx v26,reg,sp; \ | |
53 | addi reg,reg,16; \ | |
54 | lvx v27,reg,sp; \ | |
55 | addi reg,reg,16; \ | |
56 | lvx v28,reg,sp; \ | |
57 | addi reg,reg,16; \ | |
58 | lvx v29,reg,sp; \ | |
59 | addi reg,reg,16; \ | |
60 | lvx v30,reg,sp; \ | |
61 | addi reg,reg,16; \ | |
62 | lvx v31,reg,sp; | |
63 | ||
64 | # Carefull this will 'clobber' vmx (by design) | |
65 | # Don't call this from C | |
66 | FUNC_START(load_vmx) | |
67 | li r5,0 | |
68 | lvx v20,r5,r3 | |
69 | addi r5,r5,16 | |
70 | lvx v21,r5,r3 | |
71 | addi r5,r5,16 | |
72 | lvx v22,r5,r3 | |
73 | addi r5,r5,16 | |
74 | lvx v23,r5,r3 | |
75 | addi r5,r5,16 | |
76 | lvx v24,r5,r3 | |
77 | addi r5,r5,16 | |
78 | lvx v25,r5,r3 | |
79 | addi r5,r5,16 | |
80 | lvx v26,r5,r3 | |
81 | addi r5,r5,16 | |
82 | lvx v27,r5,r3 | |
83 | addi r5,r5,16 | |
84 | lvx v28,r5,r3 | |
85 | addi r5,r5,16 | |
86 | lvx v29,r5,r3 | |
87 | addi r5,r5,16 | |
88 | lvx v30,r5,r3 | |
89 | addi r5,r5,16 | |
90 | lvx v31,r5,r3 | |
91 | blr | |
92 | FUNC_END(load_vmx) | |
93 | ||
94 | # Should be safe from C, only touches r4, r5 and v0,v1,v2 | |
95 | FUNC_START(check_vmx) | |
96 | PUSH_BASIC_STACK(16) | |
97 | mr r4,r3 | |
98 | li r3,1 # assume a bad result | |
99 | li r5,0 | |
100 | lvx v0,r5,r4 | |
101 | vcmpequd. v1,v0,v20 | |
102 | vmr v2,v1 | |
103 | ||
104 | addi r5,r5,16 | |
105 | lvx v0,r5,r4 | |
106 | vcmpequd. v1,v0,v21 | |
107 | vand v2,v2,v1 | |
108 | ||
109 | addi r5,r5,16 | |
110 | lvx v0,r5,r4 | |
111 | vcmpequd. v1,v0,v22 | |
112 | vand v2,v2,v1 | |
113 | ||
114 | addi r5,r5,16 | |
115 | lvx v0,r5,r4 | |
116 | vcmpequd. v1,v0,v23 | |
117 | vand v2,v2,v1 | |
118 | ||
119 | addi r5,r5,16 | |
120 | lvx v0,r5,r4 | |
121 | vcmpequd. v1,v0,v24 | |
122 | vand v2,v2,v1 | |
123 | ||
124 | addi r5,r5,16 | |
125 | lvx v0,r5,r4 | |
126 | vcmpequd. v1,v0,v25 | |
127 | vand v2,v2,v1 | |
128 | ||
129 | addi r5,r5,16 | |
130 | lvx v0,r5,r4 | |
131 | vcmpequd. v1,v0,v26 | |
132 | vand v2,v2,v1 | |
133 | ||
134 | addi r5,r5,16 | |
135 | lvx v0,r5,r4 | |
136 | vcmpequd. v1,v0,v27 | |
137 | vand v2,v2,v1 | |
138 | ||
139 | addi r5,r5,16 | |
140 | lvx v0,r5,r4 | |
141 | vcmpequd. v1,v0,v28 | |
142 | vand v2,v2,v1 | |
143 | ||
144 | addi r5,r5,16 | |
145 | lvx v0,r5,r4 | |
146 | vcmpequd. v1,v0,v29 | |
147 | vand v2,v2,v1 | |
148 | ||
149 | addi r5,r5,16 | |
150 | lvx v0,r5,r4 | |
151 | vcmpequd. v1,v0,v30 | |
152 | vand v2,v2,v1 | |
153 | ||
154 | addi r5,r5,16 | |
155 | lvx v0,r5,r4 | |
156 | vcmpequd. v1,v0,v31 | |
157 | vand v2,v2,v1 | |
158 | ||
159 | li r5,STACK_FRAME_LOCAL(0,0) | |
160 | stvx v2,r5,sp | |
161 | ldx r0,r5,sp | |
162 | cmpdi r0,0xffffffffffffffff | |
163 | bne 1f | |
164 | li r3,0 | |
165 | 1: POP_BASIC_STACK(16) | |
166 | blr | |
167 | FUNC_END(check_vmx) | |
168 | ||
169 | # Safe from C | |
170 | FUNC_START(test_vmx) | |
171 | # r3 holds pointer to where to put the result of fork | |
172 | # r4 holds pointer to the pid | |
173 | # v20-v31 are non-volatile | |
174 | PUSH_BASIC_STACK(512) | |
175 | std r3,STACK_FRAME_PARAM(0)(sp) # Address of varray | |
176 | std r4,STACK_FRAME_PARAM(1)(sp) # address of pid | |
177 | PUSH_VMX(STACK_FRAME_LOCAL(2,0),r4) | |
178 | ||
179 | bl load_vmx | |
180 | nop | |
181 | ||
182 | li r0,__NR_fork | |
183 | sc | |
184 | # Pass the result of fork back to the caller | |
185 | ld r9,STACK_FRAME_PARAM(1)(sp) | |
186 | std r3,0(r9) | |
187 | ||
188 | ld r3,STACK_FRAME_PARAM(0)(sp) | |
189 | bl check_vmx | |
190 | nop | |
191 | ||
192 | POP_VMX(STACK_FRAME_LOCAL(2,0),r4) | |
193 | POP_BASIC_STACK(512) | |
194 | blr | |
195 | FUNC_END(test_vmx) |