ia64/xen-unstable

view xen/tools/get-fields.sh @ 17062:0769835cf50f

x86 shadow: Reduce scope of shadow lock.

emulate_map_dest doesn't require holding lock, since
only shadow related operation possibly involved is to
remove shadow which is less frequent and can acquire
lock inside. Rest are either guest table walk or
per-vcpu monitor table manipulation

Signed-off-by Kevin Tian <kevin.tian@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Feb 14 10:33:12 2008 +0000 (2008-02-14)
parents 9d1d27fddc50
children 945394931d9e
line source
1 test -n "$1" -a -n "$2" -a -n "$3"
2 set -ef
4 SED=sed
5 test -x /usr/xpg4/bin/sed && SED=/usr/xpg4/bin/sed
7 get_fields ()
8 {
9 local level=1 aggr=0 name= fields=
10 for token in $2
11 do
12 case "$token" in
13 struct|union)
14 test $level != 1 || aggr=1 fields= name=
15 ;;
16 "{")
17 level=$(expr $level + 1)
18 ;;
19 "}")
20 level=$(expr $level - 1)
21 if [ $level = 1 -a $name = $1 ]
22 then
23 echo "$fields }"
24 return 0
25 fi
26 ;;
27 [a-zA-Z_]*)
28 test $aggr = 0 -o -n "$name" || name="$token"
29 ;;
30 esac
31 test $aggr = 0 || fields="$fields $token"
32 done
33 }
35 build_enums ()
36 {
37 local level=1 kind= fields= members= named= id= token
38 for token in $2
39 do
40 case "$token" in
41 struct|union)
42 test $level != 2 || fields=" "
43 kind="$token;$kind"
44 ;;
45 "{")
46 level=$(expr $level + 1)
47 ;;
48 "}")
49 level=$(expr $level - 1)
50 if [ $level = 1 ]
51 then
52 if [ "${kind%%;*}" = union ]
53 then
54 echo
55 echo "enum XLAT_$1 {"
56 for m in $members
57 do
58 echo " XLAT_${1}_$m,"
59 done
60 echo "};"
61 fi
62 return 0
63 elif [ $level = 2 ]
64 then
65 named='?'
66 fi
67 ;;
68 [a-zA-Z]*)
69 id=$token
70 if [ -n "$named" -a -n "${kind#*;}" ]
71 then
72 build_enums ${1}_$token "$fields"
73 named='!'
74 fi
75 ;;
76 ",")
77 test $level != 2 || members="$members $id"
78 ;;
79 ";")
80 test $level != 2 || members="$members $id"
81 test -z "$named" || kind=${kind#*;}
82 named=
83 ;;
84 esac
85 test -z "$fields" || fields="$fields $token"
86 done
87 }
89 handle_field ()
90 {
91 if [ -z "$5" ]
92 then
93 echo " \\"
94 if [ -z "$4" ]
95 then
96 echo -n "$1(_d_)->$3 = (_s_)->$3;"
97 else
98 echo -n "$1XLAT_${2}_HNDL_$(echo $3 | $SED 's,\.,_,g')(_d_, _s_);"
99 fi
100 elif [ -z "$(echo "$5" | $SED 's,[^{}],,g')" ]
101 then
102 local tag=$(echo "$5" | python -c '
103 import re,sys
104 for line in sys.stdin.readlines():
105 print re.subn(r"\s*(struct|union)\s+(compat_)?(\w+)\s.*", r"\3", line)[0].rstrip()
106 ')
107 echo " \\"
108 echo -n "${1}XLAT_$tag(&(_d_)->$3, &(_s_)->$3);"
109 else
110 local level=1 kind= fields= id= array= arrlvl=1 array_type= type= token
111 for token in $5
112 do
113 case "$token" in
114 struct|union)
115 test $level != 2 || fields=" "
116 if [ $level = 1 ]
117 then
118 kind=$token
119 if [ $kind = union ]
120 then
121 echo " \\"
122 echo -n "${1}switch ($(echo $3 | $SED 's,\.,_,g')) {"
123 fi
124 fi
125 ;;
126 "{")
127 level=$(expr $level + 1) id=
128 ;;
129 "}")
130 level=$(expr $level - 1) id=
131 if [ $level = 1 -a $kind = union ]
132 then
133 echo " \\"
134 echo -n "$1}"
135 fi
136 ;;
137 "[")
138 if [ $level != 2 -o $arrlvl != 1 ]
139 then
140 :
141 elif [ -z "$array" ]
142 then
143 array=" "
144 else
145 array="$array;"
146 fi
147 arrlvl=$(expr $arrlvl + 1)
148 ;;
149 "]")
150 arrlvl=$(expr $arrlvl - 1)
151 ;;
152 COMPAT_HANDLE\(*\))
153 if [ $level = 2 -a -z "$id" ]
154 then
155 type=${token#COMPAT_HANDLE?}
156 type=${type%?}
157 type=${type#compat_}
158 fi
159 ;;
160 compat_domain_handle_t)
161 if [ $level = 2 -a -z "$id" ]
162 then
163 array_type=$token
164 fi
165 ;;
166 [a-zA-Z]*)
167 id=$token
168 ;;
169 [\,\;])
170 if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
171 then
172 if [ $kind = union ]
173 then
174 echo " \\"
175 echo -n "${1}case XLAT_${2}_$(echo $3.$id | $SED 's,\.,_,g'):"
176 handle_field "$1 " $2 $3.$id "$type" "$fields"
177 elif [ -z "$array" -a -z "$array_type" ]
178 then
179 handle_field "$1" $2 $3.$id "$type" "$fields"
180 elif [ -z "$array" ]
181 then
182 copy_array " " $3.$id
183 else
184 handle_array "$1" $2 $3.$id "${array#*;}" "$type" "$fields"
185 fi
186 test "$token" != ";" || fields= id= type=
187 array=
188 if [ $kind = union ]
189 then
190 echo " \\"
191 echo -n "$1 break;"
192 fi
193 fi
194 ;;
195 *)
196 if [ -n "$array" ]
197 then
198 array="$array $token"
199 fi
200 ;;
201 esac
202 test -z "$fields" || fields="$fields $token"
203 done
204 fi
205 }
207 copy_array ()
208 {
209 echo " \\"
210 echo "${1}if ((_d_)->$2 != (_s_)->$2) \\"
211 echo -n "$1 memcpy((_d_)->$2, (_s_)->$2, sizeof((_d_)->$2));"
212 }
214 handle_array ()
215 {
216 local i="i$(echo $4 | $SED 's,[^;], ,g' | wc -w | $SED 's,[[:space:]]*,,g')"
217 echo " \\"
218 echo "$1{ \\"
219 echo "$1 unsigned int $i; \\"
220 echo -n "$1 for ($i = 0; $i < "${4%%;*}"; ++$i) {"
221 if [ "$4" = "${4#*;}" ]
222 then
223 handle_field "$1 " $2 $3[$i] "$5" "$6"
224 else
225 handle_array "$1 " $2 $3[$i] "${4#*;}" "$5" "$6"
226 fi
227 echo " \\"
228 echo "$1 } \\"
229 echo -n "$1}"
230 }
232 build_body ()
233 {
234 echo
235 echo -n "#define XLAT_$1(_d_, _s_) do {"
236 local level=1 fields= id= array= arrlvl=1 array_type= type= token
237 for token in $2
238 do
239 case "$token" in
240 struct|union)
241 test $level != 2 || fields=" "
242 ;;
243 "{")
244 level=$(expr $level + 1) id=
245 ;;
246 "}")
247 level=$(expr $level - 1) id=
248 ;;
249 "[")
250 if [ $level != 2 -o $arrlvl != 1 ]
251 then
252 :
253 elif [ -z "$array" ]
254 then
255 array=" "
256 else
257 array="$array;"
258 fi
259 arrlvl=$(expr $arrlvl + 1)
260 ;;
261 "]")
262 arrlvl=$(expr $arrlvl - 1)
263 ;;
264 COMPAT_HANDLE\(*\))
265 if [ $level = 2 -a -z "$id" ]
266 then
267 type=${token#COMPAT_HANDLE?}
268 type=${type%?}
269 type=${type#compat_}
270 fi
271 ;;
272 compat_domain_handle_t)
273 if [ $level = 2 -a -z "$id" ]
274 then
275 array_type=$token
276 fi
277 ;;
278 [a-zA-Z_]*)
279 if [ -n "$array" ]
280 then
281 array="$array $token"
282 else
283 id=$token
284 fi
285 ;;
286 [\,\;])
287 if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
288 then
289 if [ -z "$array" -a -z "$array_type" ]
290 then
291 handle_field " " $1 $id "$type" "$fields"
292 elif [ -z "$array" ]
293 then
294 copy_array " " $id
295 else
296 handle_array " " $1 $id "${array#*;}" "$type" "$fields"
297 fi
298 test "$token" != ";" || fields= id= type=
299 array=
300 fi
301 ;;
302 *)
303 if [ -n "$array" ]
304 then
305 array="$array $token"
306 fi
307 ;;
308 esac
309 test -z "$fields" || fields="$fields $token"
310 done
311 echo " \\"
312 echo "} while (0)"
313 echo ""
314 }
316 check_field ()
317 {
318 if [ -z "$(echo "$4" | $SED 's,[^{}],,g')" ]
319 then
320 echo "; \\"
321 local n=$(echo $3 | $SED 's,[^.], ,g' | wc -w | $SED 's,[[:space:]]*,,g')
322 if [ -n "$4" ]
323 then
324 for n in $4
325 do
326 case $n in
327 struct|union)
328 ;;
329 [a-zA-Z_]*)
330 echo -n " CHECK_$n"
331 break
332 ;;
333 *)
334 echo "Malformed compound declaration: '$n'" >&2
335 exit 1
336 ;;
337 esac
338 done
339 elif [ $n = 0 ]
340 then
341 echo -n " CHECK_FIELD_($1, $2, $3)"
342 else
343 echo -n " CHECK_SUBFIELD_${n}_($1, $2, $(echo $3 | $SED 's!\.!, !g'))"
344 fi
345 else
346 local level=1 fields= id= token
347 for token in $4
348 do
349 case "$token" in
350 struct|union)
351 test $level != 2 || fields=" "
352 ;;
353 "{")
354 level=$(expr $level + 1) id=
355 ;;
356 "}")
357 level=$(expr $level - 1) id=
358 ;;
359 [a-zA-Z]*)
360 id=$token
361 ;;
362 [\,\;])
363 if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
364 then
365 check_field $1 $2 $3.$id "$fields"
366 test "$token" != ";" || fields= id=
367 fi
368 ;;
369 esac
370 test -z "$fields" || fields="$fields $token"
371 done
372 fi
373 }
375 build_check ()
376 {
377 echo
378 echo "#define CHECK_$1 \\"
379 local level=1 fields= kind= id= arrlvl=1 token
380 for token in $2
381 do
382 case "$token" in
383 struct|union)
384 if [ $level = 1 ]
385 then
386 kind=$token
387 echo -n " CHECK_SIZE_($kind, $1)"
388 elif [ $level = 2 ]
389 then
390 fields=" "
391 fi
392 ;;
393 "{")
394 level=$(expr $level + 1) id=
395 ;;
396 "}")
397 level=$(expr $level - 1) id=
398 ;;
399 "[")
400 arrlvl=$(expr $arrlvl + 1)
401 ;;
402 "]")
403 arrlvl=$(expr $arrlvl - 1)
404 ;;
405 [a-zA-Z_]*)
406 test $level != 2 -o $arrlvl != 1 || id=$token
407 ;;
408 [\,\;])
409 if [ $level = 2 -a -n "$(echo $id | $SED 's,^_pad[[:digit:]]*,,')" ]
410 then
411 check_field $kind $1 $id "$fields"
412 test "$token" != ";" || fields= id=
413 fi
414 ;;
415 esac
416 test -z "$fields" || fields="$fields $token"
417 done
418 echo ""
419 }
421 fields="$(get_fields $(echo $2 | $SED 's,^compat_xen,compat_,') "$($SED -e 's,^[[:space:]]#.*,,' -e 's!\([]\[,;:{}]\)! \1 !g' $3)")"
422 if [ -z "$fields" ]
423 then
424 echo "Fields of '$2' not found in '$3'" >&2
425 exit 1
426 fi
427 name=${2#compat_}
428 name=${name#xen}
429 case "$1" in
430 "!")
431 build_enums $name "$fields"
432 build_body $name "$fields"
433 ;;
434 "?")
435 build_check $name "$fields"
436 ;;
437 *)
438 echo "Invalid translation indicator: '$1'" >&2
439 exit 1
440 ;;
441 esac