1 |
2 |
alfik |
/*
|
2 |
|
|
* Copyright (c) 2014, Aleksander Osman
|
3 |
|
|
* All rights reserved.
|
4 |
|
|
*
|
5 |
|
|
* Redistribution and use in source and binary forms, with or without
|
6 |
|
|
* modification, are permitted provided that the following conditions are met:
|
7 |
|
|
*
|
8 |
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
9 |
|
|
* list of conditions and the following disclaimer.
|
10 |
|
|
*
|
11 |
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
12 |
|
|
* this list of conditions and the following disclaimer in the documentation
|
13 |
|
|
* and/or other materials provided with the distribution.
|
14 |
|
|
*
|
15 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16 |
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18 |
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21 |
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22 |
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23 |
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24 |
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25 |
|
|
*/
|
26 |
|
|
|
27 |
|
|
`include "defines.v"
|
28 |
|
|
|
29 |
|
|
module execute_offset(
|
30 |
|
|
|
31 |
|
|
input exe_operand_16bit,
|
32 |
|
|
input [39:0] exe_decoder,
|
33 |
|
|
|
34 |
|
|
input [31:0] ebp,
|
35 |
|
|
input [31:0] esp,
|
36 |
|
|
input [63:0] ss_cache,
|
37 |
|
|
|
38 |
|
|
input [63:0] glob_descriptor,
|
39 |
|
|
|
40 |
|
|
input [31:0] glob_param_1,
|
41 |
|
|
input [31:0] glob_param_3,
|
42 |
|
|
input [31:0] glob_param_4,
|
43 |
|
|
|
44 |
|
|
input [31:0] exe_address_effective,
|
45 |
|
|
|
46 |
|
|
input [31:0] wr_stack_offset,
|
47 |
|
|
|
48 |
|
|
//offset control
|
49 |
|
|
input offset_ret_far_se,
|
50 |
|
|
input offset_new_stack,
|
51 |
|
|
input offset_new_stack_minus,
|
52 |
|
|
input offset_new_stack_continue,
|
53 |
|
|
input offset_leave,
|
54 |
|
|
input offset_pop,
|
55 |
|
|
input offset_enter_last,
|
56 |
|
|
input offset_ret,
|
57 |
|
|
input offset_iret_glob_param_4,
|
58 |
|
|
input offset_iret,
|
59 |
|
|
input offset_ret_imm,
|
60 |
|
|
input offset_esp,
|
61 |
|
|
input offset_call,
|
62 |
|
|
input offset_call_keep,
|
63 |
|
|
input offset_call_int_same_first,
|
64 |
|
|
input offset_call_int_same_next,
|
65 |
|
|
input offset_int_real,
|
66 |
|
|
input offset_int_real_next,
|
67 |
|
|
input offset_task,
|
68 |
|
|
|
69 |
|
|
//output
|
70 |
|
|
output [31:0] exe_stack_offset,
|
71 |
|
|
|
72 |
|
|
output [31:0] exe_enter_offset
|
73 |
|
|
);
|
74 |
|
|
|
75 |
|
|
//------------------------------------------------------------------------------
|
76 |
|
|
|
77 |
|
|
wire [31:0] e_pop_offset;
|
78 |
|
|
wire [31:0] e_push_offset;
|
79 |
|
|
wire [31:0] e_task_switch_error_push;
|
80 |
|
|
wire [31:0] e_push_real_int_offset;
|
81 |
|
|
wire [31:0] e_leave_offset;
|
82 |
|
|
wire [31:0] e_ret_offset;
|
83 |
|
|
wire [31:0] e_iret_offset;
|
84 |
|
|
wire [31:0] e_push_offset_for_call_int;
|
85 |
|
|
wire [31:0] e_temp_esp_real_int;
|
86 |
|
|
wire [31:0] e_temp_esp;
|
87 |
|
|
wire [31:0] e_push_offset_for_call_2_int;
|
88 |
|
|
|
89 |
|
|
wire [31:0] e_final_offset;
|
90 |
|
|
wire [31:0] e_new_stack_final_offset;
|
91 |
|
|
|
92 |
|
|
//------------------------------------------------------------------------------
|
93 |
|
|
|
94 |
|
|
assign e_pop_offset =
|
95 |
|
|
(exe_operand_16bit)? esp + 32'd2 :
|
96 |
|
|
esp + 32'd4;
|
97 |
|
|
assign e_push_offset =
|
98 |
|
|
(exe_operand_16bit)? esp - 32'd2 :
|
99 |
|
|
esp - 32'd4;
|
100 |
|
|
|
101 |
|
|
assign e_task_switch_error_push =
|
102 |
|
|
(~(glob_param_3[17]))? esp - 32'd2 :
|
103 |
|
|
esp - 32'd4;
|
104 |
|
|
|
105 |
|
|
assign e_push_real_int_offset = esp - 32'd2;
|
106 |
|
|
|
107 |
|
|
assign e_leave_offset =
|
108 |
|
|
(exe_operand_16bit)? ebp + 32'd2 :
|
109 |
|
|
ebp + 32'd4;
|
110 |
|
|
assign e_ret_offset =
|
111 |
|
|
(exe_operand_16bit)? esp + 32'd2 + { {16{exe_decoder[23] & offset_ret_far_se}}, exe_decoder[23:8] } :
|
112 |
|
|
esp + 32'd4 + { 16'd0, exe_decoder[23:8] };
|
113 |
|
|
assign e_iret_offset =
|
114 |
|
|
(exe_operand_16bit)? esp + 32'd6 :
|
115 |
|
|
esp + 32'd12;
|
116 |
|
|
|
117 |
|
|
assign e_push_offset_for_call_int =
|
118 |
|
|
(~(glob_param_1[19]))? esp - 32'd2 :
|
119 |
|
|
esp - 32'd4;
|
120 |
|
|
|
121 |
|
|
assign e_temp_esp_real_int = wr_stack_offset - 32'd2;
|
122 |
|
|
|
123 |
|
|
assign e_temp_esp =
|
124 |
|
|
(exe_operand_16bit)? wr_stack_offset - 32'd2 :
|
125 |
|
|
wr_stack_offset - 32'd4;
|
126 |
|
|
|
127 |
|
|
assign e_push_offset_for_call_2_int =
|
128 |
|
|
(~(glob_param_1[19]))? wr_stack_offset - 32'd2 :
|
129 |
|
|
wr_stack_offset - 32'd4;
|
130 |
|
|
|
131 |
|
|
assign e_final_offset =
|
132 |
|
|
(offset_leave)? e_leave_offset :
|
133 |
|
|
(offset_pop)? e_pop_offset :
|
134 |
|
|
(offset_enter_last)? exe_address_effective :
|
135 |
|
|
(offset_ret)? e_ret_offset :
|
136 |
|
|
(offset_iret)? e_iret_offset :
|
137 |
|
|
(offset_iret_glob_param_4)? glob_param_4 :
|
138 |
|
|
(offset_ret_imm)? glob_param_4 + { 16'd0, exe_decoder[23:8] } :
|
139 |
|
|
(offset_esp)? esp :
|
140 |
|
|
(offset_call)? e_temp_esp :
|
141 |
|
|
(offset_call_keep)? wr_stack_offset :
|
142 |
|
|
(offset_call_int_same_first)? e_push_offset_for_call_int :
|
143 |
|
|
(offset_call_int_same_next)? e_push_offset_for_call_2_int :
|
144 |
|
|
(offset_int_real)? e_push_real_int_offset :
|
145 |
|
|
(offset_int_real_next)? e_temp_esp_real_int :
|
146 |
|
|
(offset_task)? e_task_switch_error_push :
|
147 |
|
|
e_push_offset; // task_switch, call
|
148 |
|
|
|
149 |
|
|
assign e_new_stack_final_offset =
|
150 |
|
|
(offset_new_stack)? glob_param_4 :
|
151 |
|
|
(offset_new_stack_minus && ~(glob_param_3[19]))? glob_param_4 - 32'd2 :
|
152 |
|
|
(offset_new_stack_minus)? glob_param_4 - 32'd4 :
|
153 |
|
|
(~(glob_param_3[19]))? wr_stack_offset - 32'd2 :
|
154 |
|
|
wr_stack_offset - 32'd4;
|
155 |
|
|
assign exe_stack_offset =
|
156 |
|
|
((offset_new_stack || offset_new_stack_minus || offset_new_stack_continue) && glob_descriptor[`DESC_BIT_D_B])? e_new_stack_final_offset :
|
157 |
|
|
((offset_new_stack || offset_new_stack_minus || offset_new_stack_continue))? { 16'd0, e_new_stack_final_offset[15:0] } :
|
158 |
|
|
(ss_cache[`DESC_BIT_D_B])? e_final_offset :
|
159 |
|
|
{ 16'd0, e_final_offset[15:0] };
|
160 |
|
|
assign exe_enter_offset = (ss_cache[`DESC_BIT_D_B])? e_push_offset : { esp[31:16], e_push_offset[15:0] };
|
161 |
|
|
|
162 |
|
|
//------------------------------------------------------------------------------
|
163 |
|
|
|
164 |
|
|
// synthesis translate_off
|
165 |
|
|
wire _unused_ok = &{ 1'b0, exe_decoder[39:24], exe_decoder[7:0], ss_cache[63:55], ss_cache[53:0], glob_descriptor[63:55], glob_descriptor[53:0],
|
166 |
|
|
glob_param_1[31:20], glob_param_1[18:0], glob_param_3[31:20], glob_param_3[18], glob_param_3[16:0], 1'b0 };
|
167 |
|
|
// synthesis translate_on
|
168 |
|
|
|
169 |
|
|
//------------------------------------------------------------------------------
|
170 |
|
|
|
171 |
|
|
endmodule
|
172 |
|
|
|