1 | ; $Id: bs3-cmn-SwitchTo16BitV86.asm 59894 2016-03-02 10:03:21Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - Bs3SwitchTo16BitV86
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2007-2016 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 | TMPL_BEGIN_TEXT
|
---|
34 |
|
---|
35 |
|
---|
36 | ;;
|
---|
37 | ; @cproto BS3_DECL(void) Bs3SwitchTo16BitV86(void);
|
---|
38 | ;
|
---|
39 | BS3_PROC_BEGIN_CMN Bs3SwitchTo16BitV86
|
---|
40 | ; Construct basic v8086 return frame.
|
---|
41 | BS3_ONLY_16BIT_STMT push gs
|
---|
42 | BS3_ONLY_16BIT_STMT movzx esp, sp
|
---|
43 | push dword fs
|
---|
44 | push dword BS3_SEL_DATA16 ; ES
|
---|
45 | push dword BS3_SEL_DATA16 ; DS
|
---|
46 | push dword ss
|
---|
47 | push dword 0 ; return ESP, later.
|
---|
48 | pushfd
|
---|
49 | or dword [esp], X86_EFL_VM ; Set the VM flag in EFLAGS.
|
---|
50 | push dword BS3_SEL_TEXT16
|
---|
51 | push word 0
|
---|
52 | %if TMPL_BITS == 16
|
---|
53 | push word [esp + 2 + 7 * 4 + 2]
|
---|
54 | %else
|
---|
55 | push word [esp + 2 + 7 * 4]
|
---|
56 | %endif
|
---|
57 | ; Save registers and stuff.
|
---|
58 | push eax
|
---|
59 | %if TMPL_BITS == 16
|
---|
60 | push ds
|
---|
61 |
|
---|
62 | ; Check g_bBs3CurrentMode whether we're in v8086 mode or not.
|
---|
63 | mov ax, seg g_bBs3CurrentMode
|
---|
64 | mov ds, ax
|
---|
65 | mov al, [g_bBs3CurrentMode]
|
---|
66 | and al, BS3_MODE_CODE_MASK
|
---|
67 | cmp al, BS3_MODE_CODE_V86
|
---|
68 | jne .not_v8086
|
---|
69 |
|
---|
70 | pop ds
|
---|
71 | pop eax
|
---|
72 | add xSP, (9-1)*4
|
---|
73 | ret
|
---|
74 |
|
---|
75 | .not_v8086:
|
---|
76 | pop ax ; Drop the push ds so the stacks are identical. Keep DS = BS3DATA16 though.
|
---|
77 | %endif
|
---|
78 |
|
---|
79 | ; Ensure that we're in ring-0.
|
---|
80 | mov ax, ss
|
---|
81 | test ax, 3
|
---|
82 | jz .is_ring0
|
---|
83 | call Bs3SwitchToRing0
|
---|
84 | .is_ring0:
|
---|
85 |
|
---|
86 | ; Update globals.
|
---|
87 | and byte [g_bBs3CurrentMode], ~BS3_MODE_CODE_MASK
|
---|
88 | or byte [g_bBs3CurrentMode], BS3_MODE_CODE_16
|
---|
89 |
|
---|
90 | %if TMPL_BITS != 16
|
---|
91 | ; Set GS.
|
---|
92 | mov ax, gs
|
---|
93 | mov [xSP + 4 + 20h], ax
|
---|
94 | %endif
|
---|
95 |
|
---|
96 | ; Thunk SS:ESP, first step: calc flat address.
|
---|
97 | lea eax, [esp + 4 + 24h]
|
---|
98 | push eax
|
---|
99 | push ss
|
---|
100 | ; call Bs3SelFar32ToFlat32
|
---|
101 |
|
---|
102 | ; Second step: Calc realmode segment and offset.
|
---|
103 |
|
---|
104 |
|
---|
105 | ; Return to v8086 mode.
|
---|
106 | pop eax
|
---|
107 | iretd
|
---|
108 | BS3_PROC_END_CMN Bs3SwitchTo16Bit
|
---|
109 |
|
---|
110 |
|
---|
111 |
|
---|
112 | %endif ; ! 64-bit
|
---|
113 |
|
---|