1 | ; $Id: bootsector2-cpu-ac-loop.asm 106061 2024-09-16 14:03:52Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; Bootsector test for debug exceptions.
|
---|
4 | ;
|
---|
5 | ; Recommended (but not necessary):
|
---|
6 | ; VBoxManage setextradata bs-cpu-xcpt-2 VBoxInternal/Devices/VMMDev/0/Config/TestingEnabled 1
|
---|
7 | ;
|
---|
8 |
|
---|
9 | ;
|
---|
10 | ; Copyright (C) 2007-2024 Oracle and/or its affiliates.
|
---|
11 | ;
|
---|
12 | ; This file is part of VirtualBox base platform packages, as
|
---|
13 | ; available from https://www.virtualbox.org.
|
---|
14 | ;
|
---|
15 | ; This program is free software; you can redistribute it and/or
|
---|
16 | ; modify it under the terms of the GNU General Public License
|
---|
17 | ; as published by the Free Software Foundation, in version 3 of the
|
---|
18 | ; License.
|
---|
19 | ;
|
---|
20 | ; This program is distributed in the hope that it will be useful, but
|
---|
21 | ; WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
22 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
23 | ; General Public License for more details.
|
---|
24 | ;
|
---|
25 | ; You should have received a copy of the GNU General Public License
|
---|
26 | ; along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
27 | ;
|
---|
28 | ; The contents of this file may alternatively be used under the terms
|
---|
29 | ; of the Common Development and Distribution License Version 1.0
|
---|
30 | ; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
31 | ; in the VirtualBox distribution, in which case the provisions of the
|
---|
32 | ; CDDL are applicable instead of those of the GPL.
|
---|
33 | ;
|
---|
34 | ; You may elect to license modified versions of this file under the
|
---|
35 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
36 | ;
|
---|
37 | ; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
38 | ;
|
---|
39 |
|
---|
40 |
|
---|
41 | ;*******************************************************************************
|
---|
42 | ;* Header Files *
|
---|
43 | ;*******************************************************************************
|
---|
44 | %include "iprt/asmdefs.mac"
|
---|
45 | %include "iprt/x86.mac"
|
---|
46 | %include "VBox/VMMDevTesting.mac"
|
---|
47 |
|
---|
48 |
|
---|
49 | ;
|
---|
50 | ; Include and execute the init code.
|
---|
51 | ;
|
---|
52 | %define BS2_INIT_PE32
|
---|
53 | %define BS2_WITH_TRAPS
|
---|
54 | %define BS2_WITH_TRAPRECS
|
---|
55 | %define BS2_INC_PE32
|
---|
56 | %define BS2_INC_RM ; for SetCpuModeGlobals_rm
|
---|
57 | %include "bootsector2-common-init-code.mac"
|
---|
58 |
|
---|
59 |
|
---|
60 | ;
|
---|
61 | ; The main() function.
|
---|
62 | ;
|
---|
63 | BEGINPROC main
|
---|
64 | BITS 32
|
---|
65 | ;
|
---|
66 | ; Test prologue.
|
---|
67 | ;
|
---|
68 | mov ax, .s_szTstName
|
---|
69 | call TestInit_p32
|
---|
70 | call Bs2EnableA20_p32
|
---|
71 | cli ; raw-mode hack
|
---|
72 |
|
---|
73 | ;
|
---|
74 | ; Execute the tests
|
---|
75 | ;
|
---|
76 | sub esp, 20h
|
---|
77 |
|
---|
78 | ; Get the address of the #AC IDT entry.
|
---|
79 | sidt [esp]
|
---|
80 | mov eax, [esp + 2]
|
---|
81 | add eax, 8 * X86_XCPT_AC
|
---|
82 |
|
---|
83 | ; Make it execute in ring-3.
|
---|
84 | mov word [eax + 2], BS2_SEL_R3_CS32 ; u16Sel
|
---|
85 | or byte [eax + 5], 3 << 5 ; u2Dpl = 3
|
---|
86 |
|
---|
87 | ; Enable AC.
|
---|
88 | mov eax, cr0
|
---|
89 | or eax, X86_CR0_AM
|
---|
90 | mov cr0, eax
|
---|
91 |
|
---|
92 | ; Switch to ring-3
|
---|
93 | call Bs2ToRing3_p32
|
---|
94 |
|
---|
95 | ; Enable AC.
|
---|
96 | pushfd
|
---|
97 | or dword [esp], X86_EFL_AC
|
---|
98 | popfd
|
---|
99 |
|
---|
100 | ;; Test it. - won't work as the handle touches CR2, which traps in ring-3.
|
---|
101 | ;BS2_TRAP_INSTR X86_XCPT_AC, 0, mov dword [esp + 3], 0
|
---|
102 |
|
---|
103 | ; Misalign the stack and use it.
|
---|
104 | or esp, 3
|
---|
105 | push esp ; this will loop forever on real intel hardware.
|
---|
106 | and esp, ~3h
|
---|
107 |
|
---|
108 | add esp, 20h
|
---|
109 |
|
---|
110 | ;
|
---|
111 | ; We're done.
|
---|
112 | ;
|
---|
113 | call TestTerm_p32
|
---|
114 | ret
|
---|
115 |
|
---|
116 | .s_szTstName:
|
---|
117 | db 'tstCpuAcLoop', 0
|
---|
118 | ENDPROC main
|
---|
119 |
|
---|
120 |
|
---|
121 | ;
|
---|
122 | ; End sections and image.
|
---|
123 | ;
|
---|
124 | %include "bootsector2-common-end.mac"
|
---|
125 |
|
---|