2 /*---------------------------------------------------------------*/
3 /*--- begin guest_ppc_helpers.c ---*/
4 /*---------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2004-2010 OpenWorks LLP
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 The GNU General Public License is contained in the file COPYING.
30 Neither the names of the U.S. Department of Energy nor the
31 University of California nor the names of its contributors may be
32 used to endorse or promote products derived from this software
33 without prior written permission.
36 #include "libvex_basictypes.h"
37 #include "libvex_emwarn.h"
38 #include "libvex_guest_ppc32.h"
39 #include "libvex_guest_ppc64.h"
40 #include "libvex_ir.h"
43 #include "main_util.h"
44 #include "guest_generic_bb_to_IR.h"
45 #include "guest_ppc_defs.h"
48 /* This file contains helper functions for ppc32 and ppc64 guest code.
49 Calls to these functions are generated by the back end. These
50 calls are of course in the host machine code and this file will be
51 compiled to host machine code, so that all makes sense.
53 Only change the signatures of these helper functions very
54 carefully. If you change the signature here, you'll have to change
55 the parameters passed to it in the IR calls constructed by
60 /*---------------------------------------------------------------*/
61 /*--- Misc integer helpers. ---*/
62 /*---------------------------------------------------------------*/
64 /* CALLED FROM GENERATED CODE */
65 /* DIRTY HELPER (non-referentially-transparent) */
66 /* Horrible hack. On non-ppc platforms, return 1. */
67 /* Reads a complete, consistent 64-bit TB value. */
68 ULong ppcg_dirtyhelper_MFTB ( void )
70 # if defined(__powerpc__) || defined(_AIX)
74 __asm__ __volatile__ ("\n"
78 : "=r" (hi1), "=r" (lo), "=r" (hi2)
80 if (hi1 == hi2) break;
82 res = ((ULong)hi1) << 32;
91 /* CALLED FROM GENERATED CODE */
92 /* DIRTY HELPER (non-referentially transparent) */
93 UInt ppc32g_dirtyhelper_MFSPR_268_269 ( UInt r269 )
95 # if defined(__powerpc__) || defined(_AIX)
98 __asm__ __volatile__("mfspr %0,269" : "=b"(spr));
100 __asm__ __volatile__("mfspr %0,268" : "=b"(spr));
109 /* CALLED FROM GENERATED CODE */
110 /* DIRTY HELPER (I'm not really sure what the side effects are) */
111 UInt ppc32g_dirtyhelper_MFSPR_287 ( void )
113 # if defined(__powerpc__) || defined(_AIX)
115 __asm__ __volatile__("mfspr %0,287" : "=b"(spr));
123 /* CALLED FROM GENERATED CODE */
124 /* DIRTY HELPER (reads guest state, writes guest mem) */
125 void ppc32g_dirtyhelper_LVS ( VexGuestPPC32State* gst,
126 UInt vD_off, UInt sh, UInt shift_right )
129 UChar ref[32] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
130 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
131 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
132 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F };
136 vassert( vD_off <= sizeof(VexGuestPPC32State)-8 );
138 vassert( shift_right <= 1 );
141 /* else shift left */
143 pU128_src = (U128*)&ref[sh];
144 pU128_dst = (U128*)( ((UChar*)gst) + vD_off );
146 (*pU128_dst)[0] = (*pU128_src)[0];
147 (*pU128_dst)[1] = (*pU128_src)[1];
148 (*pU128_dst)[2] = (*pU128_src)[2];
149 (*pU128_dst)[3] = (*pU128_src)[3];
152 /* CALLED FROM GENERATED CODE */
153 /* DIRTY HELPER (reads guest state, writes guest mem) */
154 void ppc64g_dirtyhelper_LVS ( VexGuestPPC64State* gst,
155 UInt vD_off, UInt sh, UInt shift_right )
159 /* ref[] used to be a static const array, but this doesn't work on
160 ppc64 because VEX doesn't load the TOC pointer for the call here,
161 and so we wind up picking up some totally random other data.
162 (It's a wonder we don't segfault.) So, just to be clear, this
163 "fix" (vex r2073) is really a kludgearound for the fact that
164 VEX's 64-bit ppc code generation doesn't provide a valid TOC
165 pointer for helper function calls. Ick. (Bug 250038) */
166 for (i = 0; i < 32; i++) ref[i] = i;
171 vassert( vD_off <= sizeof(VexGuestPPC64State)-8 );
173 vassert( shift_right <= 1 );
176 /* else shift left */
178 pU128_src = (U128*)&ref[sh];
179 pU128_dst = (U128*)( ((UChar*)gst) + vD_off );
181 (*pU128_dst)[0] = (*pU128_src)[0];
182 (*pU128_dst)[1] = (*pU128_src)[1];
183 (*pU128_dst)[2] = (*pU128_src)[2];
184 (*pU128_dst)[3] = (*pU128_src)[3];
188 /* Helper-function specialiser. */
190 IRExpr* guest_ppc32_spechelper ( HChar* function_name,
192 IRStmt** precedingStmts,
193 Int n_precedingStmts )
198 IRExpr* guest_ppc64_spechelper ( HChar* function_name,
200 IRStmt** precedingStmts,
201 Int n_precedingStmts )
207 /*----------------------------------------------*/
208 /*--- The exported fns .. ---*/
209 /*----------------------------------------------*/
211 /* VISIBLE TO LIBVEX CLIENT */
212 UInt LibVEX_GuestPPC32_get_CR ( /*IN*/VexGuestPPC32State* vex_state )
216 ( (vex_state->guest_CR##_n##_321 & (7<<1)) \
217 | (vex_state->guest_CR##_n##_0 & 1) \
224 FIELD(0) | FIELD(1) | FIELD(2) | FIELD(3)
225 | FIELD(4) | FIELD(5) | FIELD(6) | FIELD(7);
231 /* VISIBLE TO LIBVEX CLIENT */
232 /* Note: %CR is 32 bits even for ppc64 */
233 UInt LibVEX_GuestPPC64_get_CR ( /*IN*/VexGuestPPC64State* vex_state )
237 ( (vex_state->guest_CR##_n##_321 & (7<<1)) \
238 | (vex_state->guest_CR##_n##_0 & 1) \
245 FIELD(0) | FIELD(1) | FIELD(2) | FIELD(3)
246 | FIELD(4) | FIELD(5) | FIELD(6) | FIELD(7);
252 /* VISIBLE TO LIBVEX CLIENT */
253 void LibVEX_GuestPPC32_put_CR ( UInt cr_native,
254 /*OUT*/VexGuestPPC32State* vex_state )
260 t = cr_native >> (4*(7-(_n))); \
261 vex_state->guest_CR##_n##_0 = toUChar(t & 1); \
262 vex_state->guest_CR##_n##_321 = toUChar(t & (7<<1)); \
278 /* VISIBLE TO LIBVEX CLIENT */
279 /* Note: %CR is 32 bits even for ppc64 */
280 void LibVEX_GuestPPC64_put_CR ( UInt cr_native,
281 /*OUT*/VexGuestPPC64State* vex_state )
287 t = cr_native >> (4*(7-(_n))); \
288 vex_state->guest_CR##_n##_0 = toUChar(t & 1); \
289 vex_state->guest_CR##_n##_321 = toUChar(t & (7<<1)); \
305 /* VISIBLE TO LIBVEX CLIENT */
306 UInt LibVEX_GuestPPC32_get_XER ( /*IN*/VexGuestPPC32State* vex_state )
309 w |= ( ((UInt)vex_state->guest_XER_BC) & 0xFF );
310 w |= ( (((UInt)vex_state->guest_XER_SO) & 0x1) << 31 );
311 w |= ( (((UInt)vex_state->guest_XER_OV) & 0x1) << 30 );
312 w |= ( (((UInt)vex_state->guest_XER_CA) & 0x1) << 29 );
317 /* VISIBLE TO LIBVEX CLIENT */
318 /* Note: %XER is 32 bits even for ppc64 */
319 UInt LibVEX_GuestPPC64_get_XER ( /*IN*/VexGuestPPC64State* vex_state )
322 w |= ( ((UInt)vex_state->guest_XER_BC) & 0xFF );
323 w |= ( (((UInt)vex_state->guest_XER_SO) & 0x1) << 31 );
324 w |= ( (((UInt)vex_state->guest_XER_OV) & 0x1) << 30 );
325 w |= ( (((UInt)vex_state->guest_XER_CA) & 0x1) << 29 );
330 /* VISIBLE TO LIBVEX CLIENT */
331 void LibVEX_GuestPPC32_put_XER ( UInt xer_native,
332 /*OUT*/VexGuestPPC32State* vex_state )
334 vex_state->guest_XER_BC = toUChar(xer_native & 0xFF);
335 vex_state->guest_XER_SO = toUChar((xer_native >> 31) & 0x1);
336 vex_state->guest_XER_OV = toUChar((xer_native >> 30) & 0x1);
337 vex_state->guest_XER_CA = toUChar((xer_native >> 29) & 0x1);
340 /* VISIBLE TO LIBVEX CLIENT */
341 /* Note: %XER is 32 bits even for ppc64 */
342 void LibVEX_GuestPPC64_put_XER ( UInt xer_native,
343 /*OUT*/VexGuestPPC64State* vex_state )
345 vex_state->guest_XER_BC = toUChar(xer_native & 0xFF);
346 vex_state->guest_XER_SO = toUChar((xer_native >> 31) & 0x1);
347 vex_state->guest_XER_OV = toUChar((xer_native >> 30) & 0x1);
348 vex_state->guest_XER_CA = toUChar((xer_native >> 29) & 0x1);
351 /* VISIBLE TO LIBVEX CLIENT */
352 void LibVEX_GuestPPC32_initialise ( /*OUT*/VexGuestPPC32State* vex_state )
355 vex_state->guest_GPR0 = 0;
356 vex_state->guest_GPR1 = 0;
357 vex_state->guest_GPR2 = 0;
358 vex_state->guest_GPR3 = 0;
359 vex_state->guest_GPR4 = 0;
360 vex_state->guest_GPR5 = 0;
361 vex_state->guest_GPR6 = 0;
362 vex_state->guest_GPR7 = 0;
363 vex_state->guest_GPR8 = 0;
364 vex_state->guest_GPR9 = 0;
365 vex_state->guest_GPR10 = 0;
366 vex_state->guest_GPR11 = 0;
367 vex_state->guest_GPR12 = 0;
368 vex_state->guest_GPR13 = 0;
369 vex_state->guest_GPR14 = 0;
370 vex_state->guest_GPR15 = 0;
371 vex_state->guest_GPR16 = 0;
372 vex_state->guest_GPR17 = 0;
373 vex_state->guest_GPR18 = 0;
374 vex_state->guest_GPR19 = 0;
375 vex_state->guest_GPR20 = 0;
376 vex_state->guest_GPR21 = 0;
377 vex_state->guest_GPR22 = 0;
378 vex_state->guest_GPR23 = 0;
379 vex_state->guest_GPR24 = 0;
380 vex_state->guest_GPR25 = 0;
381 vex_state->guest_GPR26 = 0;
382 vex_state->guest_GPR27 = 0;
383 vex_state->guest_GPR28 = 0;
384 vex_state->guest_GPR29 = 0;
385 vex_state->guest_GPR30 = 0;
386 vex_state->guest_GPR31 = 0;
389 /* Initialise the vector state. */
390 # define VECZERO(_vr) _vr[0]=_vr[1]=_vr[2]=_vr[3] = 0;
392 VECZERO(vex_state->guest_VSR0 );
393 VECZERO(vex_state->guest_VSR1 );
394 VECZERO(vex_state->guest_VSR2 );
395 VECZERO(vex_state->guest_VSR3 );
396 VECZERO(vex_state->guest_VSR4 );
397 VECZERO(vex_state->guest_VSR5 );
398 VECZERO(vex_state->guest_VSR6 );
399 VECZERO(vex_state->guest_VSR7 );
400 VECZERO(vex_state->guest_VSR8 );
401 VECZERO(vex_state->guest_VSR9 );
402 VECZERO(vex_state->guest_VSR10);
403 VECZERO(vex_state->guest_VSR11);
404 VECZERO(vex_state->guest_VSR12);
405 VECZERO(vex_state->guest_VSR13);
406 VECZERO(vex_state->guest_VSR14);
407 VECZERO(vex_state->guest_VSR15);
408 VECZERO(vex_state->guest_VSR16);
409 VECZERO(vex_state->guest_VSR17);
410 VECZERO(vex_state->guest_VSR18);
411 VECZERO(vex_state->guest_VSR19);
412 VECZERO(vex_state->guest_VSR20);
413 VECZERO(vex_state->guest_VSR21);
414 VECZERO(vex_state->guest_VSR22);
415 VECZERO(vex_state->guest_VSR23);
416 VECZERO(vex_state->guest_VSR24);
417 VECZERO(vex_state->guest_VSR25);
418 VECZERO(vex_state->guest_VSR26);
419 VECZERO(vex_state->guest_VSR27);
420 VECZERO(vex_state->guest_VSR28);
421 VECZERO(vex_state->guest_VSR29);
422 VECZERO(vex_state->guest_VSR30);
423 VECZERO(vex_state->guest_VSR31);
424 VECZERO(vex_state->guest_VSR32);
425 VECZERO(vex_state->guest_VSR33);
426 VECZERO(vex_state->guest_VSR34);
427 VECZERO(vex_state->guest_VSR35);
428 VECZERO(vex_state->guest_VSR36);
429 VECZERO(vex_state->guest_VSR37);
430 VECZERO(vex_state->guest_VSR38);
431 VECZERO(vex_state->guest_VSR39);
432 VECZERO(vex_state->guest_VSR40);
433 VECZERO(vex_state->guest_VSR41);
434 VECZERO(vex_state->guest_VSR42);
435 VECZERO(vex_state->guest_VSR43);
436 VECZERO(vex_state->guest_VSR44);
437 VECZERO(vex_state->guest_VSR45);
438 VECZERO(vex_state->guest_VSR46);
439 VECZERO(vex_state->guest_VSR47);
440 VECZERO(vex_state->guest_VSR48);
441 VECZERO(vex_state->guest_VSR49);
442 VECZERO(vex_state->guest_VSR50);
443 VECZERO(vex_state->guest_VSR51);
444 VECZERO(vex_state->guest_VSR52);
445 VECZERO(vex_state->guest_VSR53);
446 VECZERO(vex_state->guest_VSR54);
447 VECZERO(vex_state->guest_VSR55);
448 VECZERO(vex_state->guest_VSR56);
449 VECZERO(vex_state->guest_VSR57);
450 VECZERO(vex_state->guest_VSR58);
451 VECZERO(vex_state->guest_VSR59);
452 VECZERO(vex_state->guest_VSR60);
453 VECZERO(vex_state->guest_VSR61);
454 VECZERO(vex_state->guest_VSR62);
455 VECZERO(vex_state->guest_VSR63);
459 vex_state->guest_CIA = 0;
460 vex_state->guest_LR = 0;
461 vex_state->guest_CTR = 0;
463 vex_state->guest_XER_SO = 0;
464 vex_state->guest_XER_OV = 0;
465 vex_state->guest_XER_CA = 0;
466 vex_state->guest_XER_BC = 0;
468 vex_state->guest_CR0_321 = 0;
469 vex_state->guest_CR0_0 = 0;
470 vex_state->guest_CR1_321 = 0;
471 vex_state->guest_CR1_0 = 0;
472 vex_state->guest_CR2_321 = 0;
473 vex_state->guest_CR2_0 = 0;
474 vex_state->guest_CR3_321 = 0;
475 vex_state->guest_CR3_0 = 0;
476 vex_state->guest_CR4_321 = 0;
477 vex_state->guest_CR4_0 = 0;
478 vex_state->guest_CR5_321 = 0;
479 vex_state->guest_CR5_0 = 0;
480 vex_state->guest_CR6_321 = 0;
481 vex_state->guest_CR6_0 = 0;
482 vex_state->guest_CR7_321 = 0;
483 vex_state->guest_CR7_0 = 0;
485 vex_state->guest_FPROUND = (UInt)PPCrm_NEAREST;
487 vex_state->guest_VRSAVE = 0;
489 vex_state->guest_VSCR = 0x0; // Non-Java mode = 0
491 vex_state->guest_EMWARN = EmWarn_NONE;
493 vex_state->guest_TISTART = 0;
494 vex_state->guest_TILEN = 0;
496 vex_state->guest_NRADDR = 0;
497 vex_state->guest_NRADDR_GPR2 = 0;
499 vex_state->guest_REDIR_SP = -1;
500 for (i = 0; i < VEX_GUEST_PPC32_REDIR_STACK_SIZE; i++)
501 vex_state->guest_REDIR_STACK[i] = 0;
503 vex_state->guest_IP_AT_SYSCALL = 0;
504 vex_state->guest_SPRG3_RO = 0;
508 /* VISIBLE TO LIBVEX CLIENT */
509 void LibVEX_GuestPPC64_initialise ( /*OUT*/VexGuestPPC64State* vex_state )
512 vex_state->guest_GPR0 = 0;
513 vex_state->guest_GPR1 = 0;
514 vex_state->guest_GPR2 = 0;
515 vex_state->guest_GPR3 = 0;
516 vex_state->guest_GPR4 = 0;
517 vex_state->guest_GPR5 = 0;
518 vex_state->guest_GPR6 = 0;
519 vex_state->guest_GPR7 = 0;
520 vex_state->guest_GPR8 = 0;
521 vex_state->guest_GPR9 = 0;
522 vex_state->guest_GPR10 = 0;
523 vex_state->guest_GPR11 = 0;
524 vex_state->guest_GPR12 = 0;
525 vex_state->guest_GPR13 = 0;
526 vex_state->guest_GPR14 = 0;
527 vex_state->guest_GPR15 = 0;
528 vex_state->guest_GPR16 = 0;
529 vex_state->guest_GPR17 = 0;
530 vex_state->guest_GPR18 = 0;
531 vex_state->guest_GPR19 = 0;
532 vex_state->guest_GPR20 = 0;
533 vex_state->guest_GPR21 = 0;
534 vex_state->guest_GPR22 = 0;
535 vex_state->guest_GPR23 = 0;
536 vex_state->guest_GPR24 = 0;
537 vex_state->guest_GPR25 = 0;
538 vex_state->guest_GPR26 = 0;
539 vex_state->guest_GPR27 = 0;
540 vex_state->guest_GPR28 = 0;
541 vex_state->guest_GPR29 = 0;
542 vex_state->guest_GPR30 = 0;
543 vex_state->guest_GPR31 = 0;
545 /* Initialise the vector state. */
546 # define VECZERO(_vr) _vr[0]=_vr[1]=_vr[2]=_vr[3] = 0;
548 VECZERO(vex_state->guest_VSR0 );
549 VECZERO(vex_state->guest_VSR1 );
550 VECZERO(vex_state->guest_VSR2 );
551 VECZERO(vex_state->guest_VSR3 );
552 VECZERO(vex_state->guest_VSR4 );
553 VECZERO(vex_state->guest_VSR5 );
554 VECZERO(vex_state->guest_VSR6 );
555 VECZERO(vex_state->guest_VSR7 );
556 VECZERO(vex_state->guest_VSR8 );
557 VECZERO(vex_state->guest_VSR9 );
558 VECZERO(vex_state->guest_VSR10);
559 VECZERO(vex_state->guest_VSR11);
560 VECZERO(vex_state->guest_VSR12);
561 VECZERO(vex_state->guest_VSR13);
562 VECZERO(vex_state->guest_VSR14);
563 VECZERO(vex_state->guest_VSR15);
564 VECZERO(vex_state->guest_VSR16);
565 VECZERO(vex_state->guest_VSR17);
566 VECZERO(vex_state->guest_VSR18);
567 VECZERO(vex_state->guest_VSR19);
568 VECZERO(vex_state->guest_VSR20);
569 VECZERO(vex_state->guest_VSR21);
570 VECZERO(vex_state->guest_VSR22);
571 VECZERO(vex_state->guest_VSR23);
572 VECZERO(vex_state->guest_VSR24);
573 VECZERO(vex_state->guest_VSR25);
574 VECZERO(vex_state->guest_VSR26);
575 VECZERO(vex_state->guest_VSR27);
576 VECZERO(vex_state->guest_VSR28);
577 VECZERO(vex_state->guest_VSR29);
578 VECZERO(vex_state->guest_VSR30);
579 VECZERO(vex_state->guest_VSR31);
580 VECZERO(vex_state->guest_VSR32);
581 VECZERO(vex_state->guest_VSR33);
582 VECZERO(vex_state->guest_VSR34);
583 VECZERO(vex_state->guest_VSR35);
584 VECZERO(vex_state->guest_VSR36);
585 VECZERO(vex_state->guest_VSR37);
586 VECZERO(vex_state->guest_VSR38);
587 VECZERO(vex_state->guest_VSR39);
588 VECZERO(vex_state->guest_VSR40);
589 VECZERO(vex_state->guest_VSR41);
590 VECZERO(vex_state->guest_VSR42);
591 VECZERO(vex_state->guest_VSR43);
592 VECZERO(vex_state->guest_VSR44);
593 VECZERO(vex_state->guest_VSR45);
594 VECZERO(vex_state->guest_VSR46);
595 VECZERO(vex_state->guest_VSR47);
596 VECZERO(vex_state->guest_VSR48);
597 VECZERO(vex_state->guest_VSR49);
598 VECZERO(vex_state->guest_VSR50);
599 VECZERO(vex_state->guest_VSR51);
600 VECZERO(vex_state->guest_VSR52);
601 VECZERO(vex_state->guest_VSR53);
602 VECZERO(vex_state->guest_VSR54);
603 VECZERO(vex_state->guest_VSR55);
604 VECZERO(vex_state->guest_VSR56);
605 VECZERO(vex_state->guest_VSR57);
606 VECZERO(vex_state->guest_VSR58);
607 VECZERO(vex_state->guest_VSR59);
608 VECZERO(vex_state->guest_VSR60);
609 VECZERO(vex_state->guest_VSR61);
610 VECZERO(vex_state->guest_VSR62);
611 VECZERO(vex_state->guest_VSR63);
615 vex_state->guest_CIA = 0;
616 vex_state->guest_LR = 0;
617 vex_state->guest_CTR = 0;
619 vex_state->guest_XER_SO = 0;
620 vex_state->guest_XER_OV = 0;
621 vex_state->guest_XER_CA = 0;
622 vex_state->guest_XER_BC = 0;
624 vex_state->guest_CR0_321 = 0;
625 vex_state->guest_CR0_0 = 0;
626 vex_state->guest_CR1_321 = 0;
627 vex_state->guest_CR1_0 = 0;
628 vex_state->guest_CR2_321 = 0;
629 vex_state->guest_CR2_0 = 0;
630 vex_state->guest_CR3_321 = 0;
631 vex_state->guest_CR3_0 = 0;
632 vex_state->guest_CR4_321 = 0;
633 vex_state->guest_CR4_0 = 0;
634 vex_state->guest_CR5_321 = 0;
635 vex_state->guest_CR5_0 = 0;
636 vex_state->guest_CR6_321 = 0;
637 vex_state->guest_CR6_0 = 0;
638 vex_state->guest_CR7_321 = 0;
639 vex_state->guest_CR7_0 = 0;
641 vex_state->guest_FPROUND = (UInt)PPCrm_NEAREST;
643 vex_state->guest_VRSAVE = 0;
645 vex_state->guest_VSCR = 0x0; // Non-Java mode = 0
647 vex_state->guest_EMWARN = EmWarn_NONE;
649 vex_state->padding = 0;
651 vex_state->guest_TISTART = 0;
652 vex_state->guest_TILEN = 0;
654 vex_state->guest_NRADDR = 0;
655 vex_state->guest_NRADDR_GPR2 = 0;
657 vex_state->guest_REDIR_SP = -1;
658 for (i = 0; i < VEX_GUEST_PPC64_REDIR_STACK_SIZE; i++)
659 vex_state->guest_REDIR_STACK[i] = 0;
661 vex_state->guest_IP_AT_SYSCALL = 0;
662 vex_state->guest_SPRG3_RO = 0;
664 vex_state->padding2 = 0;
668 /*-----------------------------------------------------------*/
669 /*--- Describing the ppc guest state, for the benefit ---*/
670 /*--- of iropt and instrumenters. ---*/
671 /*-----------------------------------------------------------*/
673 /* Figure out if any part of the guest state contained in minoff
674 .. maxoff requires precise memory exceptions. If in doubt return
675 True (but this is generates significantly slower code).
677 By default we enforce precise exns for guest R1 (stack pointer),
678 CIA (current insn address) and LR (link register). These are the
679 minimum needed to extract correct stack backtraces from ppc
680 code. [[NB: not sure if keeping LR up to date is actually
683 Bool guest_ppc32_state_requires_precise_mem_exns ( Int minoff,
686 Int lr_min = offsetof(VexGuestPPC32State, guest_LR);
687 Int lr_max = lr_min + 4 - 1;
688 Int r1_min = offsetof(VexGuestPPC32State, guest_GPR1);
689 Int r1_max = r1_min + 4 - 1;
690 Int cia_min = offsetof(VexGuestPPC32State, guest_CIA);
691 Int cia_max = cia_min + 4 - 1;
693 if (maxoff < lr_min || minoff > lr_max) {
694 /* no overlap with LR */
699 if (maxoff < r1_min || minoff > r1_max) {
700 /* no overlap with R1 */
705 if (maxoff < cia_min || minoff > cia_max) {
706 /* no overlap with CIA */
714 Bool guest_ppc64_state_requires_precise_mem_exns ( Int minoff,
717 /* Given that R2 is a Big Deal in the ELF ppc64 ABI, it seems
718 prudent to be conservative with it, even though thus far there
719 is no evidence to suggest that it actually needs to be kept up
720 to date wrt possible exceptions. */
721 Int lr_min = offsetof(VexGuestPPC64State, guest_LR);
722 Int lr_max = lr_min + 8 - 1;
723 Int r1_min = offsetof(VexGuestPPC64State, guest_GPR1);
724 Int r1_max = r1_min + 8 - 1;
725 Int r2_min = offsetof(VexGuestPPC64State, guest_GPR2);
726 Int r2_max = r2_min + 8 - 1;
727 Int cia_min = offsetof(VexGuestPPC64State, guest_CIA);
728 Int cia_max = cia_min + 8 - 1;
730 if (maxoff < lr_min || minoff > lr_max) {
731 /* no overlap with LR */
736 if (maxoff < r1_min || minoff > r1_max) {
737 /* no overlap with R1 */
742 if (maxoff < r2_min || minoff > r2_max) {
743 /* no overlap with R2 */
748 if (maxoff < cia_min || minoff > cia_max) {
749 /* no overlap with CIA */
758 #define ALWAYSDEFD32(field) \
759 { offsetof(VexGuestPPC32State, field), \
760 (sizeof ((VexGuestPPC32State*)0)->field) }
765 /* Total size of the guest state, in bytes. */
766 .total_sizeB = sizeof(VexGuestPPC32State),
768 /* Describe the stack pointer. */
769 .offset_SP = offsetof(VexGuestPPC32State,guest_GPR1),
772 /* Describe the frame pointer. */
773 .offset_FP = offsetof(VexGuestPPC32State,guest_GPR1),
776 /* Describe the instruction pointer. */
777 .offset_IP = offsetof(VexGuestPPC32State,guest_CIA),
780 /* Describe any sections to be regarded by Memcheck as
785 = { /* 0 */ ALWAYSDEFD32(guest_CIA),
786 /* 1 */ ALWAYSDEFD32(guest_EMWARN),
787 /* 2 */ ALWAYSDEFD32(guest_TISTART),
788 /* 3 */ ALWAYSDEFD32(guest_TILEN),
789 /* 4 */ ALWAYSDEFD32(guest_VSCR),
790 /* 5 */ ALWAYSDEFD32(guest_FPROUND),
791 /* 6 */ ALWAYSDEFD32(guest_NRADDR),
792 /* 7 */ ALWAYSDEFD32(guest_NRADDR_GPR2),
793 /* 8 */ ALWAYSDEFD32(guest_REDIR_SP),
794 /* 9 */ ALWAYSDEFD32(guest_REDIR_STACK),
795 /* 10 */ ALWAYSDEFD32(guest_IP_AT_SYSCALL)
799 #define ALWAYSDEFD64(field) \
800 { offsetof(VexGuestPPC64State, field), \
801 (sizeof ((VexGuestPPC64State*)0)->field) }
806 /* Total size of the guest state, in bytes. */
807 .total_sizeB = sizeof(VexGuestPPC64State),
809 /* Describe the stack pointer. */
810 .offset_SP = offsetof(VexGuestPPC64State,guest_GPR1),
813 /* Describe the frame pointer. */
814 .offset_FP = offsetof(VexGuestPPC64State,guest_GPR1),
817 /* Describe the instruction pointer. */
818 .offset_IP = offsetof(VexGuestPPC64State,guest_CIA),
821 /* Describe any sections to be regarded by Memcheck as
826 = { /* 0 */ ALWAYSDEFD64(guest_CIA),
827 /* 1 */ ALWAYSDEFD64(guest_EMWARN),
828 /* 2 */ ALWAYSDEFD64(guest_TISTART),
829 /* 3 */ ALWAYSDEFD64(guest_TILEN),
830 /* 4 */ ALWAYSDEFD64(guest_VSCR),
831 /* 5 */ ALWAYSDEFD64(guest_FPROUND),
832 /* 6 */ ALWAYSDEFD64(guest_NRADDR),
833 /* 7 */ ALWAYSDEFD64(guest_NRADDR_GPR2),
834 /* 8 */ ALWAYSDEFD64(guest_REDIR_SP),
835 /* 9 */ ALWAYSDEFD64(guest_REDIR_STACK),
836 /* 10 */ ALWAYSDEFD64(guest_IP_AT_SYSCALL)
840 /*---------------------------------------------------------------*/
841 /*--- end guest_ppc_helpers.c ---*/
842 /*---------------------------------------------------------------*/