1 | ; $Id: bs3-cmn-SwitchToRingX.asm 96407 2022-08-22 17:43:14Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - Bs3SwitchToRingX
|
---|
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 |
|
---|
39 |
|
---|
40 | BS3_EXTERN_CMN Bs3Syscall
|
---|
41 | %if TMPL_BITS == 16
|
---|
42 | BS3_EXTERN_DATA16 g_bBs3CurrentMode
|
---|
43 | %endif
|
---|
44 | TMPL_BEGIN_TEXT
|
---|
45 |
|
---|
46 |
|
---|
47 | ;;
|
---|
48 | ; @cproto BS3_DECL(void) Bs3SwitchToRingX(uint8_t bRing);
|
---|
49 | ;
|
---|
50 | ; @param bRing The target ring (0..3).
|
---|
51 | ; @remarks Does not require 20h of parameter scratch space in 64-bit mode.
|
---|
52 | ;
|
---|
53 | ; @uses No GPRs.
|
---|
54 | ;
|
---|
55 | BS3_PROC_BEGIN_CMN Bs3SwitchToRingX, BS3_PBC_HYBRID_SAFE
|
---|
56 | BS3_CALL_CONV_PROLOG 1
|
---|
57 | push xBP
|
---|
58 | mov xBP, xSP
|
---|
59 | push xAX
|
---|
60 |
|
---|
61 | %if TMPL_BITS == 16
|
---|
62 | ; Check the current mode.
|
---|
63 | mov al, [BS3_DATA16_WRT(g_bBs3CurrentMode)]
|
---|
64 |
|
---|
65 | ; If real mode: Nothing we can do, but we'll bitch if the request isn't for ring-0.
|
---|
66 | cmp al, BS3_MODE_RM
|
---|
67 | je .return_real_mode
|
---|
68 |
|
---|
69 | ; If V8086 mode: Always do syscall and add a lock prefix to make sure it gets to the VMM.
|
---|
70 | test al, BS3_MODE_CODE_V86
|
---|
71 | jnz .just_do_it
|
---|
72 | %endif
|
---|
73 |
|
---|
74 | ; In protected mode: Check the CPL we're currently at skip syscall if ring-0 already.
|
---|
75 | mov ax, cs
|
---|
76 | and al, 3
|
---|
77 | cmp al, byte [xBP + xCB + cbCurRetAddr]
|
---|
78 | je .return
|
---|
79 |
|
---|
80 | .just_do_it:
|
---|
81 | mov xAX, BS3_SYSCALL_TO_RING0
|
---|
82 | add al, [xBP + xCB + cbCurRetAddr]
|
---|
83 | call Bs3Syscall
|
---|
84 |
|
---|
85 | %ifndef BS3_STRICT
|
---|
86 | .return_real_mode:
|
---|
87 | %endif
|
---|
88 | .return:
|
---|
89 | pop xAX
|
---|
90 | pop xBP
|
---|
91 | BS3_CALL_CONV_EPILOG 1
|
---|
92 | BS3_HYBRID_RET
|
---|
93 |
|
---|
94 | %ifdef BS3_STRICT
|
---|
95 | ; In real mode, only ring-0 makes any sense.
|
---|
96 | .return_real_mode:
|
---|
97 | cmp byte [xBP + xCB + cbCurRetAddr], 0
|
---|
98 | je .return
|
---|
99 | int3
|
---|
100 | jmp .return
|
---|
101 | %endif
|
---|
102 | BS3_PROC_END_CMN Bs3SwitchToRingX
|
---|
103 |
|
---|