1 | ; $Id: bs3-cmn-SwitchTo16BitV86.asm 82968 2020-02-04 10:35:17Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - Bs3SwitchTo16BitV86
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2007-2020 Oracle Corporation
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
11 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | ; General Public License (GPL) as published by the Free Software
|
---|
13 | ; Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | ;
|
---|
17 | ; The contents of this file may alternatively be used under the terms
|
---|
18 | ; of the Common Development and Distribution License Version 1.0
|
---|
19 | ; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | ; VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | ; CDDL are applicable instead of those of the GPL.
|
---|
22 | ;
|
---|
23 | ; You may elect to license modified versions of this file under the
|
---|
24 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | ;
|
---|
26 |
|
---|
27 | %include "bs3kit-template-header.mac"
|
---|
28 |
|
---|
29 | %if TMPL_BITS != 64
|
---|
30 |
|
---|
31 | BS3_EXTERN_DATA16 g_bBs3CurrentMode
|
---|
32 | BS3_EXTERN_CMN Bs3SwitchToRing0
|
---|
33 | BS3_EXTERN_CMN Bs3SelProtFar32ToFlat32
|
---|
34 | TMPL_BEGIN_TEXT
|
---|
35 |
|
---|
36 |
|
---|
37 | ;;
|
---|
38 | ; @cproto BS3_DECL(void) Bs3SwitchTo16BitV86(void);
|
---|
39 | ; @uses No general registers modified. Regment registers loaded with specific
|
---|
40 | ; values and the stack register converted to real mode (not ebp).
|
---|
41 | ;
|
---|
42 | BS3_PROC_BEGIN_CMN Bs3SwitchTo16BitV86, BS3_PBC_NEAR
|
---|
43 | ; Construct basic v8086 return frame.
|
---|
44 | BONLY16 movzx esp, sp
|
---|
45 | push dword 0 ; +0x20: GS
|
---|
46 | push dword 0 ; +0x1c: FS
|
---|
47 | push dword BS3_SEL_DATA16 ; +0x18: ES
|
---|
48 | push dword BS3_SEL_DATA16 ; +0x14: DS
|
---|
49 | push dword 0 ; +0x10: SS - later
|
---|
50 | push dword 0 ; +0x0c: return ESP, later.
|
---|
51 | pushfd
|
---|
52 | or dword [esp], X86_EFL_VM | X86_EFL_IOPL ; +0x08: Set IOPL=3 and the VM flag (EFLAGS).
|
---|
53 | push dword BS3_SEL_TEXT16 ; +0x04
|
---|
54 | push word 0
|
---|
55 | push word [esp + 24h - 2] ; +0x00
|
---|
56 | ; Save registers and stuff.
|
---|
57 | push eax
|
---|
58 | push edx
|
---|
59 | push ecx
|
---|
60 | push ebx
|
---|
61 | %if TMPL_BITS == 16
|
---|
62 | push ds
|
---|
63 |
|
---|
64 | ; Check g_bBs3CurrentMode whether we're in v8086 mode or not.
|
---|
65 | mov ax, seg g_bBs3CurrentMode
|
---|
66 | mov ds, ax
|
---|
67 | mov al, [BS3_DATA16_WRT(g_bBs3CurrentMode)]
|
---|
68 | test al, BS3_MODE_CODE_V86
|
---|
69 | jz .not_v8086
|
---|
70 |
|
---|
71 | pop ds
|
---|
72 | pop ebx
|
---|
73 | pop ecx
|
---|
74 | pop edx
|
---|
75 | pop eax
|
---|
76 | add xSP, 0x24
|
---|
77 | ret
|
---|
78 |
|
---|
79 | .not_v8086:
|
---|
80 | pop ax ; Drop the push ds so the stacks are identical. Keep DS = BS3KIT_GRPNM_DATA16 though.
|
---|
81 | %endif
|
---|
82 |
|
---|
83 | ; Ensure that we're in ring-0.
|
---|
84 | mov ax, ss
|
---|
85 | test ax, 3
|
---|
86 | jz .is_ring0
|
---|
87 | call Bs3SwitchToRing0
|
---|
88 | %if TMPL_BITS == 16
|
---|
89 | mov ax, seg g_bBs3CurrentMode
|
---|
90 | mov ds, ax ; parnoia
|
---|
91 | %endif
|
---|
92 | .is_ring0:
|
---|
93 |
|
---|
94 | ; Update globals.
|
---|
95 | and byte [BS3_DATA16_WRT(g_bBs3CurrentMode)], ~BS3_MODE_CODE_MASK
|
---|
96 | or byte [BS3_DATA16_WRT(g_bBs3CurrentMode)], BS3_MODE_CODE_V86
|
---|
97 |
|
---|
98 | ; Thunk return SS:ESP to real-mode address via 32-bit flat.
|
---|
99 | lea eax, [esp + 4*4 + 24h + xCB]
|
---|
100 | push ss
|
---|
101 | push eax
|
---|
102 | BS3_CALL Bs3SelProtFar32ToFlat32, 2
|
---|
103 | add esp, sCB + xCB
|
---|
104 | mov [esp + 4*4 + 0ch], ax ; high word is already zero
|
---|
105 | %if TMPL_BITS == 16
|
---|
106 | mov [esp + 4*4 + 10h], dx
|
---|
107 | %else
|
---|
108 | shr eax, 16
|
---|
109 | mov [esp + 4*4 + 10h], ax
|
---|
110 | %endif
|
---|
111 |
|
---|
112 | ; Return to v8086 mode.
|
---|
113 | pop ebx
|
---|
114 | pop ecx
|
---|
115 | pop edx
|
---|
116 | pop eax
|
---|
117 | iretd
|
---|
118 | BS3_PROC_END_CMN Bs3SwitchTo16BitV86
|
---|
119 |
|
---|
120 | ;; @todo far 16-bit variant.
|
---|
121 |
|
---|
122 | %endif ; ! 64-bit
|
---|
123 |
|
---|