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 |
|
|
|
28 |
|
|
`define TRUE 1'b1
|
29 |
|
|
`define FALSE 1'b0
|
30 |
|
|
|
31 |
|
|
//------------------------------------------------------------------------------
|
32 |
|
|
|
33 |
|
|
//divide by zero
|
34 |
|
|
`define EXCEPTION_DE 8'd0
|
35 |
|
|
//debug
|
36 |
|
|
`define EXCEPTION_DB 8'd1
|
37 |
|
|
//breakpoint
|
38 |
|
|
`define EXCEPTION_BP 8'd3
|
39 |
|
|
//overflow
|
40 |
|
|
`define EXCEPTION_OF 8'd4
|
41 |
|
|
//bounds
|
42 |
|
|
`define EXCEPTION_BR 8'd5
|
43 |
|
|
`define EXCEPTION_UD 8'd6
|
44 |
|
|
`define EXCEPTION_NM 8'd7
|
45 |
|
|
`define EXCEPTION_DF 8'd8
|
46 |
|
|
`define EXCEPTION_TS 8'd10
|
47 |
|
|
`define EXCEPTION_NP 8'd11
|
48 |
|
|
`define EXCEPTION_SS 8'd12
|
49 |
|
|
`define EXCEPTION_GP 8'd13
|
50 |
|
|
`define EXCEPTION_PF 8'd14
|
51 |
|
|
`define EXCEPTION_AC 8'd17
|
52 |
|
|
`define EXCEPTION_MC 8'd18
|
53 |
|
|
|
54 |
|
|
//------------------------------------------------------------------------------
|
55 |
|
|
|
56 |
|
|
`define PREFETCH_GP_FAULT 4'd15
|
57 |
|
|
`define PREFETCH_PF_FAULT 4'd14
|
58 |
|
|
`define PREFETCH_MIN_FAULT 4'd9
|
59 |
|
|
|
60 |
|
|
//------------------------------------------------------------------------------
|
61 |
|
|
|
62 |
|
|
`define CMD_NULL 7'd0
|
63 |
|
|
|
64 |
|
|
`define CMDEX_NULL 4'd0
|
65 |
|
|
|
66 |
|
|
//------------------------------------------------------------------------------
|
67 |
|
|
//------------------------------------------------------------------------------
|
68 |
|
|
//------------------------------------------------------------------------------
|
69 |
|
|
|
70 |
|
|
`define CPUID_MODEL_FAMILY_STEPPING 32'h0000045B
|
71 |
|
|
|
72 |
|
|
`define MC_PARAM_1_FLAG_NO_WRITE 13'd1
|
73 |
|
|
`define MC_PARAM_1_FLAG_NO_WRITE_BIT 19
|
74 |
|
|
// no write and cpl from param 3
|
75 |
|
|
`define MC_PARAM_1_FLAG_CPL_FROM_PARAM_3 13'd3
|
76 |
|
|
`define MC_PARAM_1_FLAG_CPL_FROM_PARAM_3_BIT 20
|
77 |
|
|
`define MC_PARAM_1_FLAG_NP_NOT_SS 13'd7
|
78 |
|
|
`define MC_PARAM_1_FLAG_NP_NOT_SS_BIT 21
|
79 |
|
|
|
80 |
|
|
`define EFLAGS_BIT_VM 17
|
81 |
|
|
|
82 |
|
|
`define DESC_BIT_G 55
|
83 |
|
|
`define DESC_BIT_D_B 54
|
84 |
|
|
`define DESC_BIT_P 47
|
85 |
|
|
`define DESC_BIT_SEG 44
|
86 |
|
|
`define DESC_BITS_TYPE 43:40
|
87 |
|
|
`define DESC_BITS_DPL 46:45
|
88 |
|
|
`define DESC_BIT_TYPE_BIT_0 40
|
89 |
|
|
|
90 |
|
|
`define DESC_IS_CODE(val) val[43]
|
91 |
|
|
`define DESC_IS_DATA(val) ~(val[43])
|
92 |
|
|
`define DESC_IS_DATA_RO(val) (~val[43] && ~val[41])
|
93 |
|
|
`define DESC_IS_DATA_RW(val) (~val[43] && val[41])
|
94 |
|
|
`define DESC_IS_CODE_EO(val) (val[43] && ~val[41])
|
95 |
|
|
`define DESC_IS_CODE_NON_CONFORMING(val) (val[43] && ~val[42])
|
96 |
|
|
`define DESC_IS_NOT_ACCESSED(val) ~(val[40])
|
97 |
|
|
`define DESC_IS_ACCESSED(val) val[40]
|
98 |
|
|
`define DESC_IS_CODE_CONFORMING(val) (val[43] && val[42])
|
99 |
|
|
|
100 |
|
|
`define SELECTOR_BITS_RPL 1:0
|
101 |
|
|
`define SELECTOR_BIT_TI 2
|
102 |
|
|
`define SELECTOR_FOR_CODE(val) { val[15:2], 2'b00 }
|
103 |
|
|
|
104 |
|
|
`define DR7_BIT_GD 13
|
105 |
|
|
|
106 |
|
|
`define SEGMENT_ES 3'd0
|
107 |
|
|
`define SEGMENT_CS 3'd1
|
108 |
|
|
`define SEGMENT_SS 3'd2
|
109 |
|
|
`define SEGMENT_DS 3'd3
|
110 |
|
|
`define SEGMENT_FS 3'd4
|
111 |
|
|
`define SEGMENT_GS 3'd5
|
112 |
|
|
`define SEGMENT_LDT 3'd6
|
113 |
|
|
`define SEGMENT_TR 3'd7
|
114 |
|
|
|
115 |
|
|
`define DESC_TSS_AVAIL_386 4'h9
|
116 |
|
|
`define DESC_TSS_BUSY_386 4'hB
|
117 |
|
|
`define DESC_TSS_AVAIL_286 4'h1
|
118 |
|
|
`define DESC_TSS_BUSY_286 4'h3
|
119 |
|
|
`define DESC_INTERRUPT_GATE_386 4'hE
|
120 |
|
|
`define DESC_INTERRUPT_GATE_286 4'h6
|
121 |
|
|
`define DESC_TRAP_GATE_386 4'hF
|
122 |
|
|
`define DESC_TRAP_GATE_286 4'h7
|
123 |
|
|
`define DESC_CALL_GATE_386 4'hC
|
124 |
|
|
`define DESC_CALL_GATE_286 4'h4
|
125 |
|
|
`define DESC_LDT 4'h2
|
126 |
|
|
`define DESC_TASK_GATE 4'h5
|
127 |
|
|
|
128 |
|
|
`define DESC_MASK_G 64'h0080000000000000
|
129 |
|
|
`define DESC_MASK_D_B 64'h0040000000000000
|
130 |
|
|
`define DESC_MASK_L 64'h0020000000000000
|
131 |
|
|
`define DESC_MASK_AVL 64'h0010000000000000
|
132 |
|
|
`define DESC_MASK_LIMIT 64'h000F00000000FFFF
|
133 |
|
|
`define DESC_MASK_P 64'h0000800000000000
|
134 |
|
|
`define DESC_MASK_DPL 64'h0000600000000000
|
135 |
|
|
`define DESC_MASK_SEG 64'h0000100000000000
|
136 |
|
|
`define DESC_MASK_TYPE 64'h00000F0000000000
|
137 |
|
|
`define DESC_MASK_DATA_RWA 64'h0000030000000000
|
138 |
|
|
|
139 |
|
|
`define MUTEX_EAX_BIT 0
|
140 |
|
|
`define MUTEX_ECX_BIT 1
|
141 |
|
|
`define MUTEX_EDX_BIT 2
|
142 |
|
|
`define MUTEX_EBX_BIT 3
|
143 |
|
|
`define MUTEX_ESP_BIT 4
|
144 |
|
|
`define MUTEX_EBP_BIT 5
|
145 |
|
|
`define MUTEX_ESI_BIT 6
|
146 |
|
|
`define MUTEX_EDI_BIT 7
|
147 |
|
|
`define MUTEX_EFLAGS_BIT 8
|
148 |
|
|
`define MUTEX_MEMORY_BIT 9
|
149 |
|
|
`define MUTEX_ACTIVE_BIT 10
|
150 |
|
|
`define MUTEX_IO_BIT 11
|
151 |
|
|
|
152 |
|
|
`define ARITH_VALID 4'd8
|
153 |
|
|
|
154 |
|
|
`define ARITH_ADD 4'd0
|
155 |
|
|
`define ARITH_OR 4'd1
|
156 |
|
|
`define ARITH_ADC 4'd2
|
157 |
|
|
`define ARITH_SBB 4'd3
|
158 |
|
|
`define ARITH_AND 4'd4
|
159 |
|
|
`define ARITH_SUB 4'd5
|
160 |
|
|
`define ARITH_XOR 4'd6
|
161 |
|
|
`define ARITH_CMP 4'd7
|
162 |
|
|
|
163 |
|
|
//------------------------------------------------------------------------------
|
164 |
|
|
|
165 |
|
|
`include "startup_default.v"
|
166 |
|
|
|
167 |
|
|
//------------------------------------------------------------------------------
|
168 |
|
|
|
169 |
|
|
`include "autogen/defines.v"
|
170 |
|
|
|
171 |
|
|
//------------------------------------------------------------------------------
|