VirtualBox

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

Last change on this file since 60009 was 59984, checked in by vboxsync, 9 years ago

bs3kit: Updates.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1; $Id: bs3-cmn-SwitchTo16BitV86.asm 59984 2016-03-11 00:56:10Z 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
31BS3_EXTERN_DATA16 g_bBs3CurrentMode
32BS3_EXTERN_CMN Bs3SwitchToRing0
33BS3_EXTERN_CMN Bs3SelProtFar32ToFlat32
34TMPL_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;
42BS3_PROC_BEGIN_CMN Bs3SwitchTo16BitV86
43 ; Construct basic v8086 return frame.
44 BS3_ONLY_16BIT_STMT 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 and al, BS3_MODE_CODE_MASK
69 cmp al, BS3_MODE_CODE_V86
70 jne .not_v8086
71
72 pop ds
73 pop ebx
74 pop ecx
75 pop edx
76 pop eax
77 add xSP, 0x24
78 ret
79
80.not_v8086:
81 pop ax ; Drop the push ds so the stacks are identical. Keep DS = BS3DATA16 though.
82 %endif
83
84 ; Ensure that we're in ring-0.
85 mov ax, ss
86 test ax, 3
87 jz .is_ring0
88 call Bs3SwitchToRing0
89 %if TMPL_BITS == 16
90 mov ax, seg g_bBs3CurrentMode
91 mov ds, ax ; parnoia
92 %endif
93.is_ring0:
94
95 ; Update globals.
96 and byte [BS3_DATA16_WRT(g_bBs3CurrentMode)], ~BS3_MODE_CODE_MASK
97 or byte [BS3_DATA16_WRT(g_bBs3CurrentMode)], BS3_MODE_CODE_V86
98
99 %if TMPL_BITS != 16
100 ; Set GS.
101 mov ax, gs
102 mov [xSP + 4*4 + 20h], ax
103 %endif
104
105 ; Thunk return SS:ESP to real-mode address via 32-bit flat.
106 lea eax, [esp + 4*4 + 24h]
107 push ss
108 push eax
109 BS3_CALL Bs3SelProtFar32ToFlat32, 2
110 add esp, sCB + xCB
111 mov [esp + 4*4 + 0ch], ax ; high word is already zero
112 %if TMPL_BITS == 16
113 mov [esp + 4*4 + 10h], dx
114 %else
115 shr eax, 16
116 mov [esp + 4*4 + 10h], ax
117 %endif
118
119 ; Return to v8086 mode.
120 pop ebx
121 pop ecx
122 pop edx
123 pop eax
124 iretd
125BS3_PROC_END_CMN Bs3SwitchTo16BitV86
126
127%endif ; ! 64-bit
128
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