VirtualBox

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

最後變更 在這個檔案從59934是 59287,由 vboxsync 提交於 9 年 前

bs3kit: Working 16 and 64 bit PrintChr system call, fixed/documented 64-bit calls.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 3.5 KB
 
1; $Id: bs3-mode-SwitchToPE32.asm 59287 2016-01-08 10:08:40Z 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.alldomusa.eu.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;
41; @remarks Does not require 20h of parameter scratch space in 64-bit mode.
42;
43BS3_PROC_BEGIN_MODE Bs3SwitchToPE32
44%ifdef TMPL_PE32
45 ret
46
47%else
48 ;
49 ; Switch to real mode.
50 ;
51 %if TMPL_BITS != 32
52 %if TMPL_BITS > 32
53 shl xPRE [xSP + xCB], 32 ; Adjust the return address from 64-bit to 32-bit.
54 add rsp, xCB - 4
55 %else
56 push word 0 ; Reserve space to expand the return address.
57 %endif
58 ; Must be in 16-bit segment when calling Bs3SwitchTo16Bit.
59 jmp .sixteen_bit_segment
60BS3_BEGIN_TEXT16
61 BS3_SET_BITS TMPL_BITS
62.sixteen_bit_segment:
63 %endif
64
65 ;
66 ; Switch to real mode.
67 ;
68 extern TMPL_NM(Bs3SwitchToRM)
69 call TMPL_NM(Bs3SwitchToRM)
70 BS3_SET_BITS 16
71
72 push eax
73 pushfd
74 cli
75
76 ;
77 ; Load the GDT and enable PE32.
78 ;
79BS3_EXTERN_SYSTEM16 Bs3Lgdt_Gdt
80BS3_BEGIN_TEXT16
81 mov ax, BS3SYSTEM16
82 mov ds, ax
83 lgdt [Bs3Lgdt_Gdt]
84
85 mov eax, cr0
86 or eax, X86_CR0_PE
87 mov cr0, eax
88 jmp BS3_SEL_R0_CS32:dword .thirty_two_bit wrt FLAT
89BS3_BEGIN_TEXT32
90.thirty_two_bit:
91
92 ;
93 ; Convert the (now) real mode stack pointer to 32-bit flat.
94 ;
95 xor eax, eax
96 mov ax, ss
97 shl eax, 4
98 and esp, 0ffffh
99 add esp, eax
100
101 mov ax, BS3_SEL_R0_SS32
102 mov ss, ax
103
104 ;
105 ; Call rountine for doing mode specific setups.
106 ;
107 extern NAME(Bs3EnteredMode_pe32)
108 call NAME(Bs3EnteredMode_pe32)
109
110 ;
111 ; Restore eax and flags (IF).
112 ;
113 %if TMPL_BITS < 32
114 and esp, 0ffffh ; Make sure the high word is zero.
115 movzx eax, word [esp + 8 + 2] ; Load return address.
116 add eax, BS3_ADDR_BS3TEXT16 ; Convert it to a flat address.
117 mov [esp + 8], eax ; Store it in the place right for 32-bit returns.
118 %endif
119 popfd
120 pop eax
121 ret
122
123 %if TMPL_BITS != 32
124TMPL_BEGIN_TEXT
125 %endif
126%endif
127BS3_PROC_END_MODE Bs3SwitchToPE32
128
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette