VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE32.asm@ 58814

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

bs3kit: Solved the FLAT fixup issue for OMF files, while for COFF/ELF (64-bit only) we cannot do absolute fixups in places we care about (like just won't do what we want it to). Made the object converter check for COFF relocation we don't want, found 4 in one file and convinced the compiler to use RIP relative addressing instead of image relative addressing. (There's an alternative I've been avoiding, which is linking LX and using RTLdr to do the final linking.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1; $Id: bs3-mode-SwitchToPE32.asm 58814 2015-11-22 06:50:50Z vboxsync $
2;; @file
3; BS3Kit - Bs3SwitchToPE32
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;;
31; Switch to 32-bit unpaged protected mode from any other mode.
32;
33; @cproto BS3_DECL(void) Bs3SwitchToPE32(void);
34;
35; @uses Nothing (except high 32-bit register parts), upper part of ESP is
36; cleared if caller is in 16-bit mode.
37;
38; @remarks Obviously returns to 32-bit mode, even if the caller was
39; in 16-bit or 64-bit mode.
40;
41BS3_PROC_BEGIN_MODE Bs3SwitchToPE32
42%ifdef TMPL_PE32
43 ret
44
45%else
46 ;
47 ; Switch to real mode.
48 ;
49 %if TMPL_BITS != 32
50 %if TMPL_BITS > 32
51 shl xPRE [xSP + xCB], 32 ; Adjust the return address from 64-bit to 32-bit.
52 add rsp, xCB - 4
53 %else
54 push word 0 ; Reserve space to expand the return address.
55 %endif
56 ; Must be in 16-bit segment when calling Bs3SwitchTo16Bit.
57 jmp .sixteen_bit_segment
58BS3_BEGIN_TEXT16
59 BS3_SET_BITS TMPL_BITS
60.sixteen_bit_segment:
61 %endif
62
63 ;
64 ; Switch to real mode.
65 ;
66 extern TMPL_NM(Bs3SwitchToRM)
67 call TMPL_NM(Bs3SwitchToRM)
68 BS3_SET_BITS 16
69
70 push eax
71 pushfd
72 cli
73
74 ;
75 ; Load the GDT and enable PE32.
76 ;
77BS3_EXTERN_SYSTEM16 Bs3Lgdt_Gdt
78BS3_BEGIN_TEXT16
79 mov ax, BS3SYSTEM16
80 mov ds, ax
81 lgdt [Bs3Lgdt_Gdt]
82
83 mov eax, cr0
84 or eax, X86_CR0_PE
85 mov cr0, eax
86 jmp BS3_SEL_R0_CS32:dword .thirty_two_bit wrt FLAT
87BS3_BEGIN_TEXT32
88.thirty_two_bit:
89
90 ;
91 ; Call rountine for doing mode specific setups.
92 ;
93 extern NAME(Bs3EnteredMode_pe32)
94 call NAME(Bs3EnteredMode_pe32)
95
96 ;
97 ; Restore eax and flags (IF).
98 ;
99 %if TMPL_BITS < 32
100 and esp, 0ffffh ; Make sure the high word is zero.
101 movzx eax, word [esp + 8 + 2] ; Load return address.
102 add eax, BS3_ADDR_BS3TEXT16 ; Convert it to a flat address.
103 mov [esp + 8], eax ; Store it in the place right for 32-bit returns.
104 %endif
105 popfd
106 pop eax
107 ret
108
109 %if TMPL_BITS != 32
110TMPL_BEGIN_TEXT
111 %endif
112%endif
113BS3_PROC_END_MODE Bs3SwitchToPE32
114
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