1 /*BEGIN_LEGAL
2 
3 Copyright (c) 2018 Intel Corporation
4 
5   Licensed under the Apache License, Version 2.0 (the "License");
6   you may not use this file except in compliance with the License.
7   You may obtain a copy of the License at
8 
9       http://www.apache.org/licenses/LICENSE-2.0
10 
11   Unless required by applicable law or agreed to in writing, software
12   distributed under the License is distributed on an "AS IS" BASIS,
13   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   See the License for the specific language governing permissions and
15   limitations under the License.
16 
17 END_LEGAL */
18 
19 #include "xed-internal-header.h"
20 #include "xed-encoder-hl.h"
21 #include "xed-patch.h"
22 
23 xed_bool_t
xed_patch_disp(xed_decoded_inst_t * xedd,xed_uint8_t * itext,xed_enc_displacement_t disp)24 xed_patch_disp(xed_decoded_inst_t* xedd,
25                xed_uint8_t* itext,
26                xed_enc_displacement_t disp)
27 {
28     xed_uint_t disp_width = xed3_operand_get_disp_width(xedd);
29     xed_uint_t disp_pos   = xed3_operand_get_pos_disp(xedd);
30     xed_uint_t i;
31 
32     if (disp_pos == 0)
33         return 0;
34     if (disp_width != disp.displacement_bits)
35         return 0;
36     for (i=0;i<disp_width/8;i++)
37         itext[disp_pos+i] = (disp.displacement >> (i*8)) & 0xff;
38     return 1;
39 }
40 
41 
42 xed_bool_t
xed_patch_relbr(xed_decoded_inst_t * xedd,xed_uint8_t * itext,xed_encoder_operand_t disp)43 xed_patch_relbr(xed_decoded_inst_t* xedd,
44                 xed_uint8_t* itext,
45                 xed_encoder_operand_t disp)
46 {
47     xed_uint_t disp_width = xed3_operand_get_disp_width(xedd);
48     xed_uint_t disp_pos   = xed3_operand_get_pos_disp(xedd);
49     xed_uint_t i;
50 
51     if (disp_pos == 0)
52         return 0;
53     if (disp_width != disp.width_bits)
54         return 0;
55     for (i=0;i<disp_width/8;i++)
56         itext[disp_pos+i] = (disp.u.brdisp >> (i*8)) & 0xff;
57     return 1;
58 }
59 
60 xed_bool_t
xed_patch_imm0(xed_decoded_inst_t * xedd,xed_uint8_t * itext,xed_encoder_operand_t imm0)61 xed_patch_imm0(xed_decoded_inst_t* xedd,
62                xed_uint8_t* itext,
63                xed_encoder_operand_t imm0)
64 {
65     xed_uint_t imm_width = xed3_operand_get_imm_width(xedd);
66     xed_uint_t imm_pos   = xed3_operand_get_pos_imm(xedd);
67     xed_uint_t i;
68 
69     if (imm_pos == 0)
70         return 0;
71     if (imm_width != imm0.width_bits)
72         return 0;
73     for (i=0;i<imm_width/8;i++)
74         itext[imm_pos+i] = (imm0.u.imm0 >> (i*8)) & 0xff;
75     return 1;
76 }
77 
78 
79 
80