1 | ; $Id: bs3-cmn-SwitchTo32Bit.asm 59934 2016-03-04 20:32:23Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - Bs3SwitchTo32Bit
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2007-2015 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 |
|
---|
30 | %if TMPL_BITS == 16
|
---|
31 | BS3_EXTERN_CMN Bs3SelProtFar32ToFlat32
|
---|
32 | %endif
|
---|
33 | %if TMPL_BITS != 32
|
---|
34 | BS3_EXTERN_DATA16 g_bBs3CurrentMode
|
---|
35 | TMPL_BEGIN_TEXT
|
---|
36 | %endif
|
---|
37 |
|
---|
38 |
|
---|
39 | ;;
|
---|
40 | ; @cproto BS3_DECL(void) Bs3SwitchTo32Bit(void);
|
---|
41 | ;
|
---|
42 | ; @remarks Does not require 20h of parameter scratch space in 64-bit mode.
|
---|
43 | ;
|
---|
44 | BS3_PROC_BEGIN_CMN Bs3SwitchTo32Bit
|
---|
45 | %if TMPL_BITS == 32
|
---|
46 | ret
|
---|
47 | %else
|
---|
48 | %if TMPL_BITS == 16
|
---|
49 | push ax ; Reserve space for larger return value (adjusted in 32-bit code).
|
---|
50 | push eax
|
---|
51 | pushfd
|
---|
52 | push edx
|
---|
53 | %else
|
---|
54 | pushfq
|
---|
55 | mov [rsp + 4], eax
|
---|
56 | %endif
|
---|
57 | cli
|
---|
58 |
|
---|
59 | %if TMPL_BITS == 16
|
---|
60 | ; Check for v8086 mode, we need to exit it to enter 32-bit mode.
|
---|
61 | mov ax, seg g_bBs3CurrentMode
|
---|
62 | mov ds, ax
|
---|
63 | mov al, [g_bBs3CurrentMode]
|
---|
64 | and al, BS3_MODE_CODE_MASK
|
---|
65 | cmp al, BS3_MODE_CODE_V86
|
---|
66 | jne .not_v8086
|
---|
67 |
|
---|
68 | ; Calc flat stack into edx.
|
---|
69 | mov dx, ss
|
---|
70 | movzx edx, dx
|
---|
71 | shl edx, 4
|
---|
72 | add dx, sp
|
---|
73 | adc edx, 0 ; edx = flat stack address corresponding to ss:sp
|
---|
74 |
|
---|
75 | ; Switch to 16-bit ring0 and go on to do the far jump to 32-bit code.
|
---|
76 | mov ax, BS3_SYSCALL_TO_RING0
|
---|
77 | int BS3_TRAP_SYSCALL
|
---|
78 |
|
---|
79 | mov xAX, BS3_SEL_R0_CS32
|
---|
80 | jmp .do_far_jump
|
---|
81 | %endif
|
---|
82 |
|
---|
83 | .not_v8086:
|
---|
84 | %if TMPL_BITS == 16
|
---|
85 | ; Calc flat stack into edx.
|
---|
86 | push ecx
|
---|
87 | push ebx
|
---|
88 | push ss
|
---|
89 | push word 0
|
---|
90 | push sp
|
---|
91 | call Bs3SelProtFar32ToFlat32
|
---|
92 | add sp, 6
|
---|
93 | shl edx, 16
|
---|
94 | mov dx, ax ; edx = flat stack address corresponding to ss:sp
|
---|
95 | pop ebx
|
---|
96 | pop ecx
|
---|
97 | %endif
|
---|
98 |
|
---|
99 | ; Calc ring addend.
|
---|
100 | mov ax, cs
|
---|
101 | and xAX, 3
|
---|
102 | shl xAX, BS3_SEL_RING_SHIFT
|
---|
103 | add xAX, BS3_SEL_R0_CS32
|
---|
104 |
|
---|
105 | ; Create far return for switching to 32-bit mode.
|
---|
106 | .do_far_jump:
|
---|
107 | push sAX
|
---|
108 | %if TMPL_BITS == 16
|
---|
109 | push dword .thirty_two_bit wrt FLAT
|
---|
110 | o32 retf
|
---|
111 | %else
|
---|
112 | push .thirty_two_bit
|
---|
113 | o64 retf
|
---|
114 | %endif
|
---|
115 |
|
---|
116 | BS3_SET_BITS 32
|
---|
117 | .thirty_two_bit:
|
---|
118 | ; Load 32-bit segment registers.
|
---|
119 | add eax, BS3_SEL_R0_SS32 - BS3_SEL_R0_CS32
|
---|
120 | mov ss, ax
|
---|
121 | %if TMPL_BITS == 16
|
---|
122 | mov esp, edx ; Load flat stack address.
|
---|
123 | %endif
|
---|
124 |
|
---|
125 | add eax, BS3_SEL_R0_DS32 - BS3_SEL_R0_SS32
|
---|
126 | mov ds, ax
|
---|
127 | mov es, ax
|
---|
128 |
|
---|
129 | ; Update globals.
|
---|
130 | and byte [g_bBs3CurrentMode], ~BS3_MODE_CODE_MASK
|
---|
131 | or byte [g_bBs3CurrentMode], BS3_MODE_CODE_32
|
---|
132 |
|
---|
133 | %if TMPL_BITS == 16
|
---|
134 | ; Adjust the return address.
|
---|
135 | movsx eax, word [esp + 4*3 + 2]
|
---|
136 | add eax, BS3_ADDR_BS3TEXT16
|
---|
137 | mov [esp + 4*3], eax
|
---|
138 | %endif
|
---|
139 |
|
---|
140 | ; Restore and return.
|
---|
141 | BS3_ONLY_16BIT_STMT pop edx
|
---|
142 | popfd
|
---|
143 | pop eax
|
---|
144 | ret
|
---|
145 | %endif
|
---|
146 | BS3_PROC_END_CMN Bs3SwitchTo32Bit
|
---|
147 |
|
---|