1 | ; $Id: bs3-cpu-basic-2-asm.asm 102130 2023-11-16 23:51:25Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - bs3-cpu-basic-2
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2007-2023 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 | ; CPU mode agnostic test code snippets.
|
---|
54 | ;
|
---|
55 | BS3_BEGIN_TEXT16
|
---|
56 |
|
---|
57 | BS3_PROC_BEGIN _bs3CpuBasic2_ud2
|
---|
58 | .again:
|
---|
59 | ud2
|
---|
60 | jmp .again
|
---|
61 | BS3_PROC_END _bs3CpuBasic2_ud2
|
---|
62 |
|
---|
63 |
|
---|
64 | BS3_PROC_BEGIN _bs3CpuBasic2_salc_ud2
|
---|
65 | salc ; #UD in 64-bit mode
|
---|
66 | .again:
|
---|
67 | ud2
|
---|
68 | jmp .again
|
---|
69 | BS3_PROC_END _bs3CpuBasic2_salc_ud2
|
---|
70 |
|
---|
71 | BS3_PROC_BEGIN _bs3CpuBasic2_swapgs
|
---|
72 | .again:
|
---|
73 | db 00fh, 001h, 0f8h ; swapgs - #UD when not in 64-bit mode.
|
---|
74 | jmp .again
|
---|
75 | BS3_PROC_END _bs3CpuBasic2_swapgs
|
---|
76 |
|
---|
77 |
|
---|
78 | BS3_PROC_BEGIN _bs3CpuBasic2_Int80
|
---|
79 | int 80h
|
---|
80 | .again: ud2
|
---|
81 | jmp .again
|
---|
82 | BS3_PROC_END _bs3CpuBasic2_Int80
|
---|
83 |
|
---|
84 |
|
---|
85 | BS3_PROC_BEGIN _bs3CpuBasic2_Int81
|
---|
86 | int 81h
|
---|
87 | .again: ud2
|
---|
88 | jmp .again
|
---|
89 | BS3_PROC_END _bs3CpuBasic2_Int81
|
---|
90 |
|
---|
91 |
|
---|
92 | BS3_PROC_BEGIN _bs3CpuBasic2_Int82
|
---|
93 | int 82h
|
---|
94 | .again: ud2
|
---|
95 | jmp .again
|
---|
96 | BS3_PROC_END _bs3CpuBasic2_Int82
|
---|
97 |
|
---|
98 |
|
---|
99 | BS3_PROC_BEGIN _bs3CpuBasic2_Int83
|
---|
100 | int 83h
|
---|
101 | .again: ud2
|
---|
102 | jmp .again
|
---|
103 | BS3_PROC_END _bs3CpuBasic2_Int83
|
---|
104 |
|
---|
105 |
|
---|
106 | BS3_PROC_BEGIN _bs3CpuBasic2_iret
|
---|
107 | iret
|
---|
108 | BS3_PROC_END _bs3CpuBasic2_iret
|
---|
109 | AssertCompile(_bs3CpuBasic2_iret_EndProc - _bs3CpuBasic2_iret == 1)
|
---|
110 |
|
---|
111 |
|
---|
112 | BS3_PROC_BEGIN _bs3CpuBasic2_iret_opsize
|
---|
113 | iretd
|
---|
114 | BS3_PROC_END _bs3CpuBasic2_iret_opsize
|
---|
115 | AssertCompile(_bs3CpuBasic2_iret_opsize_EndProc - _bs3CpuBasic2_iret_opsize == 2)
|
---|
116 |
|
---|
117 |
|
---|
118 | BS3_PROC_BEGIN _bs3CpuBasic2_iret_rexw
|
---|
119 | BS3_SET_BITS 64
|
---|
120 | iretq
|
---|
121 | BS3_SET_BITS 16
|
---|
122 | BS3_PROC_END _bs3CpuBasic2_iret_rexw
|
---|
123 | AssertCompile(_bs3CpuBasic2_iret_rexw_EndProc - _bs3CpuBasic2_iret_rexw == 2)
|
---|
124 |
|
---|
125 |
|
---|
126 | ;
|
---|
127 | ; CPU mode agnostic test code snippets.
|
---|
128 | ;
|
---|
129 | BS3_BEGIN_TEXT32
|
---|
130 |
|
---|
131 | ;;
|
---|
132 | ; @param [xBP + xCB*2] puDst
|
---|
133 | ; @param [xBP + xCB*3] uNewValue
|
---|
134 | BS3_PROC_BEGIN_CMN bs3CpuBasic2_Store_mov, BS3_PBC_NEAR
|
---|
135 | push xBP
|
---|
136 | mov xBP, xSP
|
---|
137 | mov xCX, [xBP + xCB*2]
|
---|
138 | mov xAX, [xBP + xCB*3]
|
---|
139 | mov [xCX], xAX
|
---|
140 | leave
|
---|
141 | ret
|
---|
142 | BS3_PROC_END_CMN bs3CpuBasic2_Store_mov
|
---|
143 |
|
---|
144 | ;;
|
---|
145 | ; @param [xBP + xCB*2] puDst
|
---|
146 | ; @param [xBP + xCB*3] uNewValue
|
---|
147 | BS3_PROC_BEGIN_CMN bs3CpuBasic2_Store_xchg, BS3_PBC_NEAR
|
---|
148 | push xBP
|
---|
149 | mov xBP, xSP
|
---|
150 | mov xCX, [xBP + xCB*2]
|
---|
151 | mov xAX, [xBP + xCB*3]
|
---|
152 | xchg [xCX], xAX
|
---|
153 | leave
|
---|
154 | ret
|
---|
155 | BS3_PROC_END_CMN bs3CpuBasic2_Store_xchg
|
---|
156 |
|
---|
157 | ;;
|
---|
158 | ; @param [xBP + xCB*2] puDst
|
---|
159 | ; @param [xBP + xCB*3] uNewValue
|
---|
160 | ; @param [xBP + xCB*4] uOldValue
|
---|
161 | BS3_PROC_BEGIN_CMN bs3CpuBasic2_Store_cmpxchg, BS3_PBC_NEAR
|
---|
162 | push xBP
|
---|
163 | mov xBP, xSP
|
---|
164 | mov xCX, [xBP + xCB*2]
|
---|
165 | mov xDX, [xBP + xCB*3]
|
---|
166 | mov xAX, [xBP + xCB*4]
|
---|
167 | .again:
|
---|
168 | cmpxchg [xCX], xDX
|
---|
169 | jnz .again
|
---|
170 | leave
|
---|
171 | ret
|
---|
172 | BS3_PROC_END_CMN bs3CpuBasic2_Store_cmpxchg
|
---|
173 |
|
---|
174 |
|
---|
175 | ;
|
---|
176 | ; Jump code segment 64KB.
|
---|
177 | ;
|
---|
178 | ; There is no ORG directive in OMF mode of course. :-(
|
---|
179 | ;
|
---|
180 | section BS3JMPTEXT16 align=16 CLASS=BS3CLASS16JMPCODE PRIVATE USE16
|
---|
181 | GROUP BS3GROUPJMPTEXT16 BS3JMPTEXT16
|
---|
182 | BS3_SET_BITS 16
|
---|
183 |
|
---|
184 | ; 0000: Start with two int3 filler instructions.
|
---|
185 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmptext16_start), function, 2
|
---|
186 | int3
|
---|
187 | int3
|
---|
188 |
|
---|
189 | ; 0002: This is the target for forward wrap around jumps, should they succeed.
|
---|
190 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_target_wrap_forward), function, 2
|
---|
191 | ud2
|
---|
192 | align 8, int3
|
---|
193 |
|
---|
194 | ; 0008
|
---|
195 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_jb_wrap_backward__ud2), function, 2
|
---|
196 | db 0ebh, -012h ; jmp (0x0008 + 2 - 0x12 = 0xFFFFFFF8 (-8))
|
---|
197 | int3
|
---|
198 |
|
---|
199 | ; 000b
|
---|
200 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_jb_opsize_wrap_backward__ud2), function, 3
|
---|
201 | db 066h, 0ebh, -016h ; jmp (0x000b + 3 - 0x16 = 0xFFFFFFF8 (-8))
|
---|
202 | int3
|
---|
203 |
|
---|
204 | align 0x80, int3
|
---|
205 | ; 0080
|
---|
206 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_jv16_wrap_backward__ud2), function, 3
|
---|
207 | db 0e9h ; jmp (0x0080 + 3 - 0x8b = 0xFFFFFFF8 (-8))
|
---|
208 | dw -08bh
|
---|
209 | int3
|
---|
210 |
|
---|
211 | ; 0084
|
---|
212 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_jv16_opsize_wrap_backward__ud2), function, 6
|
---|
213 | db 066h, 0e9h ; jmp (0x0084 + 6 - 0x92 = 0xFFFFFFF8 (-8))
|
---|
214 | dd -092h
|
---|
215 | int3
|
---|
216 |
|
---|
217 | ; 008b
|
---|
218 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_call_jv16_wrap_backward__ud2), function, 3
|
---|
219 | db 0e8h ; call (0x008b + 3 - 0x96)
|
---|
220 | dw -096h
|
---|
221 | int3
|
---|
222 |
|
---|
223 | ; 008f
|
---|
224 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_call_jv16_opsize_wrap_backward__ud2), function, 6
|
---|
225 | db 066h, 0e8h ; call (0x008f + 6 - 0x9d = 0xFFFFFFF8 (-8))
|
---|
226 | dd -09dh
|
---|
227 | int3
|
---|
228 |
|
---|
229 |
|
---|
230 | align 0x100, int3 ; Note! Doesn't work correctly for higher values.
|
---|
231 | times (0xff6b - 0x100) int3
|
---|
232 |
|
---|
233 | ; ff6b
|
---|
234 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_call_jv16_wrap_forward__ud2), function, 4
|
---|
235 | db 0e8h ; call (0xff6b+3 + 0x94 = 0x10002 (65538))
|
---|
236 | dw 094h
|
---|
237 | int3
|
---|
238 |
|
---|
239 | ; ff6f
|
---|
240 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_call_jv16_opsize_wrap_forward__ud2), function, 7
|
---|
241 | db 066h, 0e8h ; o32 call (0xff6f+6 + 0x8d = 0x10002 (65538))
|
---|
242 | dd 08dh
|
---|
243 | int3
|
---|
244 |
|
---|
245 | ; ff76
|
---|
246 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_jv16_wrap_forward__ud2), function, 5
|
---|
247 | db 0e9h ; jmp (0xff76+4 + 0x88 = 0x10002 (65538))
|
---|
248 | dw 089h
|
---|
249 | int3
|
---|
250 |
|
---|
251 | ; ff7a
|
---|
252 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_jv16_opsize_wrap_forward__ud2), function, 7
|
---|
253 | db 066h, 0e9h ; o32 jmp (0xff7a+6 + 0x82 = 0x10002 (65538))
|
---|
254 | dd 082h
|
---|
255 | int3
|
---|
256 |
|
---|
257 | ; ff81
|
---|
258 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_jb_wrap_forward__ud2), function, 2
|
---|
259 | db 0ebh, 07fh ; jmp (0xff81+2 + 0x7f = 0x10002 (65538))
|
---|
260 | int3
|
---|
261 |
|
---|
262 | ; ff84
|
---|
263 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_jb_opsize_wrap_forward__ud2), function, 3
|
---|
264 | db 066h, 0ebh, 07bh ; o32 jmp (0xff84+3 + 0x7b = 0x10002 (65538))
|
---|
265 | ; ff87
|
---|
266 |
|
---|
267 | times (0xfff8 - 0xff87) int3
|
---|
268 |
|
---|
269 | ; fff8: This is the target for backward wrap around jumps, should they succeed.
|
---|
270 | BS3_GLOBAL_NAME_EX NAME(bs3CpuBasic2_jmp_target_wrap_backward), function, 2
|
---|
271 | ud2
|
---|
272 | times 6 int3
|
---|
273 | ; End of segment.
|
---|
274 |
|
---|
275 | BS3_BEGIN_TEXT16
|
---|
276 |
|
---|
277 | ;
|
---|
278 | ; Instantiate code templates.
|
---|
279 | ;
|
---|
280 | BS3_INSTANTIATE_COMMON_TEMPLATE "bs3-cpu-basic-2-template.mac"
|
---|
281 | BS3_INSTANTIATE_TEMPLATE_WITH_WEIRD_ONES "bs3-cpu-basic-2-template.mac"
|
---|
282 |
|
---|