VirtualBox

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

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

bs3kit: v8086, long, fixes, updates.

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