VirtualBox

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

Last change on this file since 97613 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1; $Id: bs3-cmn-SwitchTo16Bit.asm 96407 2022-08-22 17:43:14Z vboxsync $
2;; @file
3; BS3Kit - Bs3SwitchTo16Bit
4;
5
6;
7; Copyright (C) 2007-2022 Oracle and/or its affiliates.
8;
9; This file is part of VirtualBox base platform packages, as
10; available from https://www.virtualbox.org.
11;
12; This program is free software; you can redistribute it and/or
13; modify it under the terms of the GNU General Public License
14; as published by the Free Software Foundation, in version 3 of the
15; License.
16;
17; This program is distributed in the hope that it will be useful, but
18; WITHOUT ANY WARRANTY; without even the implied warranty of
19; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20; General Public License for more details.
21;
22; You should have received a copy of the GNU General Public License
23; along with this program; if not, see <https://www.gnu.org/licenses>.
24;
25; The contents of this file may alternatively be used under the terms
26; of the Common Development and Distribution License Version 1.0
27; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28; in the VirtualBox distribution, in which case the provisions of the
29; CDDL are applicable instead of those of the GPL.
30;
31; You may elect to license modified versions of this file under the
32; terms and conditions of either the GPL or the CDDL or both.
33;
34; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35;
36
37%include "bs3kit-template-header.mac"
38
39BS3_EXTERN_DATA16 g_bBs3CurrentMode
40%if TMPL_BITS == 16
41BS3_EXTERN_CMN Bs3Syscall
42%endif
43TMPL_BEGIN_TEXT
44
45
46;;
47; @cproto BS3_DECL(void) Bs3SwitchTo16Bit(void);
48; @remarks Does not require 20h of parameter scratch space in 64-bit mode.
49;
50BS3_PROC_BEGIN_CMN Bs3SwitchTo16Bit, BS3_PBC_NEAR
51%if TMPL_BITS == 16
52 push ax
53 push ds
54
55 ; Check g_bBs3CurrentMode whether we're in v8086 mode or not.
56 mov al, [BS3_DATA16_WRT(g_bBs3CurrentMode)]
57 test al, BS3_MODE_CODE_V86
58 jz .ret_16bit
59
60 ; Switch to ring-0 if v8086 mode.
61 mov ax, BS3_SYSCALL_TO_RING0
62 call Bs3Syscall
63
64.ret_16bit:
65 pop ds
66 pop ax
67 ret
68
69%else
70 push xAX
71 push xBX
72 xPUSHF
73 cli
74
75 ; Calc new CS.
76 mov ax, cs
77 and xAX, 3
78 shl xAX, BS3_SEL_RING_SHIFT ; ring addend.
79 add xAX, BS3_SEL_R0_CS16
80
81 ; Construct a far return for switching to 16-bit code.
82 push xAX
83 push .sixteen_bit
84 xRETF
85
86BS3_BEGIN_TEXT16
87BS3_GLOBAL_LOCAL_LABEL .sixteen_bit
88
89 ; Load 16-bit segment registers.
90 add ax, BS3_SEL_R0_SS16 - BS3_SEL_R0_CS16
91 mov ss, ax
92
93 add ax, BS3_SEL_R0_DS16 - BS3_SEL_R0_SS16
94 mov ds, ax
95 mov es, ax
96
97 ; Thunk the stack if necessary.
98 mov ebx, esp
99 shr ebx, 16
100 jz .stack_ok
101int3 ; This is for later, just remove this int3 once needed.
102 test ax, X86_SEL_RPL
103 jnz .stack_rpl_must_be_0_for_custom_stacks
104 shl bx, X86_SEL_SHIFT
105 add bx, BS3_SEL_TILED
106 mov ss, bx
107 movzx esp, sp
108.stack_ok:
109
110 ; Update globals.
111 and byte [BS3_DATA16_WRT(g_bBs3CurrentMode)], ~BS3_MODE_CODE_MASK
112 or byte [BS3_DATA16_WRT(g_bBs3CurrentMode)], BS3_MODE_CODE_16
113
114 popfd
115TONLY64 pop ebx
116 pop ebx
117TONLY64 pop eax
118 pop eax
119TONLY64 add sp, 4
120 ret (TMPL_BITS - 16) / 8 ; Return and pop 2 or 6 bytes of "parameters" (unused return value)
121
122.stack_rpl_must_be_0_for_custom_stacks:
123 int3
124 jmp .stack_rpl_must_be_0_for_custom_stacks
125TMPL_BEGIN_TEXT
126%endif
127BS3_PROC_END_CMN Bs3SwitchTo16Bit
128
129;; @todo far 16-bit variant.
130
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