VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchTo16BitV86.asm@ 106560

Last change on this file since 106560 was 106061, checked in by vboxsync, 4 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1; $Id: bs3-cmn-SwitchTo16BitV86.asm 106061 2024-09-16 14:03:52Z vboxsync $
2;; @file
3; BS3Kit - Bs3SwitchTo16BitV86
4;
5
6;
7; Copyright (C) 2007-2024 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%include "bs3kit-template-header.mac"
38
39%if TMPL_BITS != 64
40
41BS3_EXTERN_DATA16 g_bBs3CurrentMode
42BS3_EXTERN_CMN Bs3SwitchToRing0
43BS3_EXTERN_CMN Bs3SelProtFar32ToFlat32
44TMPL_BEGIN_TEXT
45
46
47;;
48; @cproto BS3_DECL(void) Bs3SwitchTo16BitV86(void);
49; @uses No general registers modified. Regment registers loaded with specific
50; values and the stack register converted to real mode (not ebp).
51;
52BS3_PROC_BEGIN_CMN Bs3SwitchTo16BitV86, BS3_PBC_NEAR
53 ; Construct basic v8086 return frame.
54BONLY16 movzx esp, sp
55 push dword 0 ; +0x20: GS
56 push dword 0 ; +0x1c: FS
57 push dword BS3_SEL_DATA16 ; +0x18: ES
58 push dword BS3_SEL_DATA16 ; +0x14: DS
59 push dword 0 ; +0x10: SS - later
60 push dword 0 ; +0x0c: return ESP, later.
61 pushfd
62 or dword [esp], X86_EFL_VM | X86_EFL_IOPL ; +0x08: Set IOPL=3 and the VM flag (EFLAGS).
63 push dword BS3_SEL_TEXT16 ; +0x04
64 push word 0
65 push word [esp + 24h - 2] ; +0x00
66 ; Save registers and stuff.
67 push eax
68 push edx
69 push ecx
70 push ebx
71 %if TMPL_BITS == 16
72 push ds
73
74 ; Check g_bBs3CurrentMode whether we're in v8086 mode or not.
75 mov ax, seg g_bBs3CurrentMode
76 mov ds, ax
77 mov al, [BS3_DATA16_WRT(g_bBs3CurrentMode)]
78 test al, BS3_MODE_CODE_V86
79 jz .not_v8086
80
81 pop ds
82 pop ebx
83 pop ecx
84 pop edx
85 pop eax
86 add xSP, 0x24
87 ret
88
89.not_v8086:
90 pop ax ; Drop the push ds so the stacks are identical. Keep DS = BS3KIT_GRPNM_DATA16 though.
91 %endif
92
93 ; Ensure that we're in ring-0.
94 mov ax, ss
95 test ax, 3
96 jz .is_ring0
97 call Bs3SwitchToRing0
98 %if TMPL_BITS == 16
99 mov ax, seg g_bBs3CurrentMode
100 mov ds, ax ; parnoia
101 %endif
102.is_ring0:
103
104 ; Update globals.
105 and byte [BS3_DATA16_WRT(g_bBs3CurrentMode)], ~BS3_MODE_CODE_MASK
106 or byte [BS3_DATA16_WRT(g_bBs3CurrentMode)], BS3_MODE_CODE_V86
107
108 ; Thunk return SS:ESP to real-mode address via 32-bit flat.
109 lea eax, [esp + 4*4 + 24h + xCB]
110 push ss
111 push eax
112 BS3_CALL Bs3SelProtFar32ToFlat32, 2
113 add esp, sCB + xCB
114 mov [esp + 4*4 + 0ch], ax ; high word is already zero
115 %if TMPL_BITS == 16
116 mov [esp + 4*4 + 10h], dx
117 %else
118 shr eax, 16
119 mov [esp + 4*4 + 10h], ax
120 %endif
121
122 ; Return to v8086 mode.
123 pop ebx
124 pop ecx
125 pop edx
126 pop eax
127 iretd
128BS3_PROC_END_CMN Bs3SwitchTo16BitV86
129
130;; @todo far 16-bit variant.
131
132%endif ; ! 64-bit
133
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette