HPCToolkit
x86-push.c
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 /******************************************************************************
48  * include files
49  *****************************************************************************/
50 
52 #include "x86-decoder.h"
53 #include "x86-interval-arg.h"
54 
55 #include <assert.h>
56 
58 
59 /******************************************************************************
60  * interface operations
61  *****************************************************************************/
62 
64 process_push(xed_decoded_inst_t *xptr, const xed_inst_t *xi, interval_arg_t *iarg)
65 {
66  unwind_interval *next;
67 
68  const xed_operand_t *op0 = xed_inst_operand(xi, 0);
69  xed_operand_enum_t op0_name = xed_operand_name(op0);
70  x86recipe_t *xr = UWI_RECIPE(iarg->current);
71  x86registers_t reg = xr->reg;
72  bp_loc bp_status = reg.bp_status;
73  int size;
74 
75  switch(iclass(xptr)) {
76  case XED_ICLASS_PUSH: size = sizeof(void*); break;
77  case XED_ICLASS_PUSHFQ: size = 8; break;
78  case XED_ICLASS_PUSHFD: size = 4; break;
79  case XED_ICLASS_PUSHF: size = 2; break;
80  default: assert(0);
81  }
82 
83  reg.sp_ra_pos += size;
84  reg.sp_bp_pos += size;
85  if (op0_name == XED_OPERAND_REG0) {
86  xed_reg_enum_t regname = xed_decoded_inst_get_reg(xptr, op0_name);
87  if (x86_isReg_BP(regname) && bp_status == BP_UNCHANGED) {
88  reg.bp_status = BP_SAVED;
89  reg.sp_bp_pos = 0;
90  }
91  }
92 
93  next = new_ui(nextInsn(iarg, xptr), xr->ra_status, &reg);
94 
95  return next;
96 }
97 
98 
100 process_pop(xed_decoded_inst_t *xptr, const xed_inst_t *xi, interval_arg_t *iarg)
101 {
102  unwind_interval *next;
103 
104  const xed_operand_t *op0 = xed_inst_operand(xi, 0);
105  xed_operand_enum_t op0_name = xed_operand_name(op0);
106  x86recipe_t *xr = UWI_RECIPE(iarg->current);
107  x86registers_t reg = xr->reg;
108  int size;
109 
110  switch(iclass(xptr)) {
111  case XED_ICLASS_POP: size = -((int)sizeof(void*)); break;
112  case XED_ICLASS_POPFQ: size = -8; break;
113  case XED_ICLASS_POPFD: size = -4; break;
114  case XED_ICLASS_POPF: size = -2; break;
115  default: assert(0);
116  }
117 
118  reg.sp_ra_pos += size;
119  reg.sp_bp_pos += size;
120  if (op0_name == XED_OPERAND_REG0) {
121  xed_reg_enum_t regname = xed_decoded_inst_get_reg(xptr, op0_name);
122  if (x86_isReg_BP(regname)) reg.bp_status = BP_UNCHANGED;
123  }
124 
125  next = new_ui(nextInsn(iarg, xptr), xr->ra_status, &reg);
126  return next;
127 }
unwind_interval * process_push(xed_decoded_inst_t *xptr, const xed_inst_t *xi, interval_arg_t *iarg)
Definition: x86-push.c:64
bitree_uwi_t * current
#define UWI_RECIPE(btuwi)
x86registers_t reg
static char * nextInsn(uint32_t *insn)
#define iclass(xptr)
Definition: x86-decoder.h:69
unwind_interval * new_ui(char *startaddr, sp_ty_t sp_ty, ra_ty_t ra_ty, int sp_arg, int ra_arg)
unwind_interval * process_pop(xed_decoded_inst_t *xptr, const xed_inst_t *xi, interval_arg_t *iarg)
Definition: x86-push.c:100
bitree_uwi_t unwind_interval