1 | ; $Id: bs3-cpu-basic-2-asm.asm 97627 2022-11-21 14:00:58Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - bs3-cpu-basic-2
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2007-2022 Oracle and/or its affiliates.
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox base platform packages, as
|
---|
10 | ; available from https://www.virtualbox.org.
|
---|
11 | ;
|
---|
12 | ; This program is free software; you can redistribute it and/or
|
---|
13 | ; modify it under the terms of the GNU General Public License
|
---|
14 | ; as published by the Free Software Foundation, in version 3 of the
|
---|
15 | ; License.
|
---|
16 | ;
|
---|
17 | ; This program is distributed in the hope that it will be useful, but
|
---|
18 | ; WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | ; General Public License for more details.
|
---|
21 | ;
|
---|
22 | ; You should have received a copy of the GNU General Public License
|
---|
23 | ; along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | ;
|
---|
25 | ; The contents of this file may alternatively be used under the terms
|
---|
26 | ; of the Common Development and Distribution License Version 1.0
|
---|
27 | ; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | ; in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | ; CDDL are applicable instead of those of the GPL.
|
---|
30 | ;
|
---|
31 | ; You may elect to license modified versions of this file under the
|
---|
32 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | ;
|
---|
34 | ; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | ;
|
---|
36 |
|
---|
37 |
|
---|
38 | ;*********************************************************************************************************************************
|
---|
39 | ;* Header Files *
|
---|
40 | ;*********************************************************************************************************************************
|
---|
41 | %include "bs3kit.mac"
|
---|
42 |
|
---|
43 |
|
---|
44 | ;*********************************************************************************************************************************
|
---|
45 | ;* Global Variables *
|
---|
46 | ;*********************************************************************************************************************************
|
---|
47 | BS3_BEGIN_DATA16
|
---|
48 | BS3_GLOBAL_DATA g_bs3CpuBasic2_ud2_FlatAddr, 4
|
---|
49 | dd _bs3CpuBasic2_ud2 wrt FLAT
|
---|
50 |
|
---|
51 |
|
---|
52 |
|
---|
53 | ;
|
---|
54 | ; CPU mode agnostic test code snippets.
|
---|
55 | ;
|
---|
56 | BS3_BEGIN_TEXT16
|
---|
57 |
|
---|
58 | BS3_PROC_BEGIN _bs3CpuBasic2_ud2
|
---|
59 | .again:
|
---|
60 | ud2
|
---|
61 | jmp .again
|
---|
62 | BS3_PROC_END _bs3CpuBasic2_ud2
|
---|
63 |
|
---|
64 |
|
---|
65 | BS3_PROC_BEGIN _bs3CpuBasic2_salc_ud2
|
---|
66 | salc ; #UD in 64-bit mode
|
---|
67 | .again:
|
---|
68 | ud2
|
---|
69 | jmp .again
|
---|
70 | BS3_PROC_END _bs3CpuBasic2_salc_ud2
|
---|
71 |
|
---|
72 | BS3_PROC_BEGIN _bs3CpuBasic2_swapgs
|
---|
73 | .again:
|
---|
74 | db 00fh, 001h, 0f8h ; swapgs - #UD when not in 64-bit mode.
|
---|
75 | jmp .again
|
---|
76 | BS3_PROC_END _bs3CpuBasic2_swapgs
|
---|
77 |
|
---|
78 |
|
---|
79 | BS3_PROC_BEGIN _bs3CpuBasic2_Int80
|
---|
80 | int 80h
|
---|
81 | .again: ud2
|
---|
82 | jmp .again
|
---|
83 | BS3_PROC_END _bs3CpuBasic2_Int80
|
---|
84 |
|
---|
85 |
|
---|
86 | BS3_PROC_BEGIN _bs3CpuBasic2_Int81
|
---|
87 | int 81h
|
---|
88 | .again: ud2
|
---|
89 | jmp .again
|
---|
90 | BS3_PROC_END _bs3CpuBasic2_Int81
|
---|
91 |
|
---|
92 |
|
---|
93 | BS3_PROC_BEGIN _bs3CpuBasic2_Int82
|
---|
94 | int 82h
|
---|
95 | .again: ud2
|
---|
96 | jmp .again
|
---|
97 | BS3_PROC_END _bs3CpuBasic2_Int82
|
---|
98 |
|
---|
99 |
|
---|
100 | BS3_PROC_BEGIN _bs3CpuBasic2_Int83
|
---|
101 | int 83h
|
---|
102 | .again: ud2
|
---|
103 | jmp .again
|
---|
104 | BS3_PROC_END _bs3CpuBasic2_Int83
|
---|
105 |
|
---|
106 |
|
---|
107 | BS3_PROC_BEGIN _bs3CpuBasic2_iret
|
---|
108 | iret
|
---|
109 | BS3_PROC_END _bs3CpuBasic2_iret
|
---|
110 | AssertCompile(_bs3CpuBasic2_iret_EndProc - _bs3CpuBasic2_iret == 1)
|
---|
111 |
|
---|
112 |
|
---|
113 | BS3_PROC_BEGIN _bs3CpuBasic2_iret_opsize
|
---|
114 | iretd
|
---|
115 | BS3_PROC_END _bs3CpuBasic2_iret_opsize
|
---|
116 | AssertCompile(_bs3CpuBasic2_iret_opsize_EndProc - _bs3CpuBasic2_iret_opsize == 2)
|
---|
117 |
|
---|
118 |
|
---|
119 | BS3_PROC_BEGIN _bs3CpuBasic2_iret_rexw
|
---|
120 | BS3_SET_BITS 64
|
---|
121 | iretq
|
---|
122 | BS3_SET_BITS 16
|
---|
123 | BS3_PROC_END _bs3CpuBasic2_iret_rexw
|
---|
124 | AssertCompile(_bs3CpuBasic2_iret_rexw_EndProc - _bs3CpuBasic2_iret_rexw == 2)
|
---|
125 |
|
---|
126 |
|
---|
127 | ;
|
---|
128 | ; CPU mode agnostic test code snippets.
|
---|
129 | ;
|
---|
130 | BS3_BEGIN_TEXT32
|
---|
131 |
|
---|
132 | ;;
|
---|
133 | ; @param [xBP + xCB*2] puDst
|
---|
134 | ; @param [xBP + xCB*3] uNewValue
|
---|
135 | BS3_PROC_BEGIN_CMN bs3CpuBasic2_Store_mov, BS3_PBC_NEAR
|
---|
136 | push xBP
|
---|
137 | mov xBP, xSP
|
---|
138 | mov xCX, [xBP + xCB*2]
|
---|
139 | mov xAX, [xBP + xCB*3]
|
---|
140 | mov [xCX], xAX
|
---|
141 | leave
|
---|
142 | ret
|
---|
143 | BS3_PROC_END_CMN bs3CpuBasic2_Store_mov
|
---|
144 |
|
---|
145 | ;;
|
---|
146 | ; @param [xBP + xCB*2] puDst
|
---|
147 | ; @param [xBP + xCB*3] uNewValue
|
---|
148 | BS3_PROC_BEGIN_CMN bs3CpuBasic2_Store_xchg, BS3_PBC_NEAR
|
---|
149 | push xBP
|
---|
150 | mov xBP, xSP
|
---|
151 | mov xCX, [xBP + xCB*2]
|
---|
152 | mov xAX, [xBP + xCB*3]
|
---|
153 | xchg [xCX], xAX
|
---|
154 | leave
|
---|
155 | ret
|
---|
156 | BS3_PROC_END_CMN bs3CpuBasic2_Store_xchg
|
---|
157 |
|
---|
158 | ;;
|
---|
159 | ; @param [xBP + xCB*2] puDst
|
---|
160 | ; @param [xBP + xCB*3] uNewValue
|
---|
161 | ; @param [xBP + xCB*4] uOldValue
|
---|
162 | BS3_PROC_BEGIN_CMN bs3CpuBasic2_Store_cmpxchg, BS3_PBC_NEAR
|
---|
163 | push xBP
|
---|
164 | mov xBP, xSP
|
---|
165 | mov xCX, [xBP + xCB*2]
|
---|
166 | mov xDX, [xBP + xCB*3]
|
---|
167 | mov xAX, [xBP + xCB*4]
|
---|
168 | .again:
|
---|
169 | cmpxchg [xCX], xDX
|
---|
170 | jnz .again
|
---|
171 | leave
|
---|
172 | ret
|
---|
173 | BS3_PROC_END_CMN bs3CpuBasic2_Store_cmpxchg
|
---|
174 |
|
---|
175 |
|
---|
176 | ;
|
---|
177 | ; Jump code segment 64KB.
|
---|
178 | ;
|
---|
179 | ; There is no ORG directive in OMF mode of course. :-(
|
---|
180 | ;
|
---|
181 | section BS3JMPTEXT16 align=16 CLASS=BS3CLASS16JMPCODE PRIVATE USE16
|
---|
182 | GROUP BS3GROUPJMPTEXT16 BS3JMPTEXT16
|
---|
183 | BS3_SET_BITS 16
|
---|
184 |
|
---|
185 | ; 0000: Start with two int3 filler instructions.
|
---|
186 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmptext16_start), function, 2
|
---|
187 | int3
|
---|
188 | int3
|
---|
189 |
|
---|
190 | ; 0002: This is the target for forward wrap around jumps, should they succeed.
|
---|
191 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_target_wrap_forward), function, 2
|
---|
192 | ud2
|
---|
193 | align 8, int3
|
---|
194 |
|
---|
195 | ; 0008
|
---|
196 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_jb_wrap_backward__ud2), function, 2
|
---|
197 | db 0ebh, -012h ; jmp (0x0008 + 2 - 0x12 = 0xFFFFFFF8 (-8))
|
---|
198 | int3
|
---|
199 |
|
---|
200 | ; 000b
|
---|
201 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_jb_opsize_wrap_backward__ud2), function, 3
|
---|
202 | db 066h, 0ebh, -016h ; jmp (0x000b + 3 - 0x16 = 0xFFFFFFF8 (-8))
|
---|
203 | int3
|
---|
204 |
|
---|
205 | align 0x80, int3
|
---|
206 | ; 0080
|
---|
207 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_jv16_wrap_backward__ud2), function, 3
|
---|
208 | db 0e9h ; jmp (0x0080 + 3 - 0x8b = 0xFFFFFFF8 (-8))
|
---|
209 | dw -08bh
|
---|
210 | int3
|
---|
211 |
|
---|
212 | ; 0084
|
---|
213 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_jv16_opsize_wrap_backward__ud2), function, 6
|
---|
214 | db 066h, 0e9h ; jmp (0x0084 + 6 - 0x92 = 0xFFFFFFF8 (-8))
|
---|
215 | dd -092h
|
---|
216 | int3
|
---|
217 |
|
---|
218 | ; 008b
|
---|
219 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_call_jv16_wrap_backward__ud2), function, 3
|
---|
220 | db 0e8h ; call (0x008b + 3 - 0x96)
|
---|
221 | dw -096h
|
---|
222 | int3
|
---|
223 |
|
---|
224 | ; 008f
|
---|
225 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_call_jv16_opsize_wrap_backward__ud2), function, 6
|
---|
226 | db 066h, 0e8h ; call (0x008f + 6 - 0x9d = 0xFFFFFFF8 (-8))
|
---|
227 | dd -09dh
|
---|
228 | int3
|
---|
229 |
|
---|
230 |
|
---|
231 | align 0x100, int3 ; Note! Doesn't work correctly for higher values.
|
---|
232 | times (0xff6b - 0x100) int3
|
---|
233 |
|
---|
234 | ; ff6b
|
---|
235 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_call_jv16_wrap_forward__ud2), function, 4
|
---|
236 | db 0e8h ; call (0xff6b+3 + 0x94 = 0x10002 (65538))
|
---|
237 | dw 094h
|
---|
238 | int3
|
---|
239 |
|
---|
240 | ; ff6f
|
---|
241 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_call_jv16_opsize_wrap_forward__ud2), function, 7
|
---|
242 | db 066h, 0e8h ; o32 call (0xff6f+6 + 0x8d = 0x10002 (65538))
|
---|
243 | dd 08dh
|
---|
244 | int3
|
---|
245 |
|
---|
246 | ; ff76
|
---|
247 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_jv16_wrap_forward__ud2), function, 5
|
---|
248 | db 0e9h ; jmp (0xff76+4 + 0x88 = 0x10002 (65538))
|
---|
249 | dw 089h
|
---|
250 | int3
|
---|
251 |
|
---|
252 | ; ff7a
|
---|
253 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_jv16_opsize_wrap_forward__ud2), function, 7
|
---|
254 | db 066h, 0e9h ; o32 jmp (0xff7a+6 + 0x82 = 0x10002 (65538))
|
---|
255 | dd 082h
|
---|
256 | int3
|
---|
257 |
|
---|
258 | ; ff81
|
---|
259 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_jb_wrap_forward__ud2), function, 2
|
---|
260 | db 0ebh, 07fh ; jmp (0xff81+2 + 0x7f = 0x10002 (65538))
|
---|
261 | int3
|
---|
262 |
|
---|
263 | ; ff84
|
---|
264 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_jb_opsize_wrap_forward__ud2), function, 3
|
---|
265 | db 066h, 0ebh, 07bh ; o32 jmp (0xff84+3 + 0x7b = 0x10002 (65538))
|
---|
266 | ; ff87
|
---|
267 |
|
---|
268 | times (0xfff8 - 0xff87) int3
|
---|
269 |
|
---|
270 | ; fff8: This is the target for backward wrap around jumps, should they succeed.
|
---|
271 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_target_wrap_backward), function, 2
|
---|
272 | ud2
|
---|
273 | times 6 int3
|
---|
274 | ; End of segment.
|
---|
275 |
|
---|
276 | BS3_BEGIN_TEXT16
|
---|
277 |
|
---|
278 | ;
|
---|
279 | ; Instantiate code templates.
|
---|
280 | ;
|
---|
281 | BS3_INSTANTIATE_COMMON_TEMPLATE "bs3-cpu-basic-2-template.mac"
|
---|
282 | BS3_INSTANTIATE_TEMPLATE_WITH_WEIRD_ONES "bs3-cpu-basic-2-template.mac"
|
---|
283 |
|
---|