VirtualBox

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

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

bs3kit: Added missing bs3-mode-SwitchTo*_Weird.asm files and some fixes to the other switching stuff.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 3.4 KB
 
1; $Id: bs3-cmn-SwitchTo16Bit.asm 59934 2016-03-04 20:32:23Z vboxsync $
2;; @file
3; BS3Kit - Bs3SwitchTo16Bit
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
29BS3_EXTERN_DATA16 g_bBs3CurrentMode
30TMPL_BEGIN_TEXT
31
32
33;;
34; @cproto BS3_DECL(void) Bs3SwitchTo16Bit(void);
35; @remarks Does not require 20h of parameter scratch space in 64-bit mode.
36;
37BS3_PROC_BEGIN_CMN Bs3SwitchTo16Bit
38%if TMPL_BITS == 16
39 push ax
40 push ds
41
42 ; Check g_bBs3CurrentMode whether we're in v8086 mode or not.
43 mov ax, seg g_bBs3CurrentMode
44 mov ds, ax
45 mov al, [g_bBs3CurrentMode]
46 and al, BS3_MODE_CODE_MASK
47 cmp al, BS3_MODE_CODE_V86
48 jne .ret_16bit
49
50 ; Switch to ring-0 if v8086 mode.
51 mov ax, BS3_SYSCALL_TO_RING0
52 int BS3_TRAP_SYSCALL
53
54.ret_16bit:
55 pop ds
56 pop ax
57 ret
58
59%else
60 push xAX
61 push xBX
62 xPUSHF
63 cli
64
65 ; Calc new CS.
66 mov ax, cs
67 and xAX, 3
68 shl xAX, BS3_SEL_RING_SHIFT ; ring addend.
69 add xAX, BS3_SEL_R0_CS16
70
71 ; Construct a far return for switching to 16-bit code.
72 push xAX
73 push .sixteen_bit
74 xRETF
75
76BS3_BEGIN_TEXT16
77.sixteen_bit:
78
79 ; Load 16-bit segment registers.
80 add ax, BS3_SEL_R0_SS16 - BS3_SEL_R0_CS16
81 mov ss, ax
82
83 add ax, BS3_SEL_R0_DS16 - BS3_SEL_R0_SS16
84 mov ds, ax
85 mov es, ax
86
87 ; Thunk the stack if necessary.
88 mov ebx, esp
89 shr ebx, 16
90 jz .stack_ok
91int3 ; This is for later, just remove this int3 once needed.
92 test ax, X86_SEL_RPL
93 jnz .stack_rpl_must_be_0_for_custom_stacks
94 shl bx, X86_SEL_SHIFT
95 add bx, BS3_SEL_TILED
96 mov ss, bx
97 movzx esp, sp
98.stack_ok:
99
100 ; Update globals.
101 and byte [g_bBs3CurrentMode], ~BS3_MODE_CODE_MASK
102 or byte [g_bBs3CurrentMode], BS3_MODE_CODE_16
103
104 popfd
105 %if TMPL_BITS == 64
106 add sp, 4
107 %endif
108 pop ebx
109 %if TMPL_BITS == 64
110 add sp, 4
111 %endif
112 pop eax
113 %if TMPL_BITS == 64
114 add sp, 4
115 %endif
116 ret (TMPL_BITS - 16) / 8 ; Return and pop 2 or 6 bytes of "parameters" (unused return value)
117
118.stack_rpl_must_be_0_for_custom_stacks:
119 int3
120 jmp .stack_rpl_must_be_0_for_custom_stacks
121TMPL_BEGIN_TEXT
122%endif
123BS3_PROC_END_CMN Bs3SwitchTo16Bit
124
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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