1 | ; $Id: bs3-cmn-SelProtModeCodeToRealMode.asm 69111 2017-10-17 14:26:02Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - Bs3SelProtModeCodeToRealMode.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2007-2017 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 | ; Make sure we can get at all the segments.
|
---|
31 | ;
|
---|
32 | BS3_BEGIN_TEXT16
|
---|
33 | BS3_BEGIN_RMTEXT16
|
---|
34 | BS3_BEGIN_X0TEXT16
|
---|
35 | BS3_BEGIN_X1TEXT16
|
---|
36 | TMPL_BEGIN_TEXT
|
---|
37 |
|
---|
38 |
|
---|
39 | ;;
|
---|
40 | ; @cproto BS3_CMN_PROTO(uint16_t, Bs3SelProtModeCodeToRealMode,(uint16_t uRealSel), false);
|
---|
41 | ; @uses ax (return register)
|
---|
42 | ;
|
---|
43 | BS3_PROC_BEGIN_CMN Bs3SelProtModeCodeToRealMode, BS3_PBC_NEAR
|
---|
44 | BS3_CALL_CONV_PROLOG 1
|
---|
45 | push xBP
|
---|
46 | mov xBP, xSP
|
---|
47 |
|
---|
48 | ; Load it and mask off the RPL.
|
---|
49 | mov ax, [xBP + xCB + cbCurRetAddr]
|
---|
50 | and ax, X86_SEL_MASK_OFF_RPL
|
---|
51 |
|
---|
52 | ; We're allowed to use the real-mode segment value.
|
---|
53 | cmp ax, CGROUP16
|
---|
54 | je .bs3text16
|
---|
55 |
|
---|
56 | ; Check for typical code segments.
|
---|
57 | cmp ax, BS3_SEL_R0_CS16
|
---|
58 | je .bs3text16
|
---|
59 | cmp ax, BS3_SEL_RMTEXT16_CS
|
---|
60 | je .bs3rmtext16
|
---|
61 | cmp ax, BS3_SEL_X0TEXT16_CS
|
---|
62 | je .bs3x0text16
|
---|
63 | cmp ax, BS3_SEL_X1TEXT16_CS
|
---|
64 | je .bs3x1text16
|
---|
65 |
|
---|
66 | ; Check for less common BS3_SEL_R*_CS16_* values.
|
---|
67 | cmp ax, BS3_SEL_R0_FIRST
|
---|
68 | jb .panic
|
---|
69 | cmp ax, BS3_SEL_R3_FIRST + (1 << BS3_SEL_RING_SHIFT)
|
---|
70 | jae .panic
|
---|
71 |
|
---|
72 | ; Since the relevant bits now are the lower 8 ones, we skip the
|
---|
73 | ; AND AX, BS3_SEL_RING_SHIFT
|
---|
74 | ; ADD AX, BS3_SEL_R0_FIRST
|
---|
75 | ; bits and compare AL with lower 8-bit of the BS3_SEL_R0_CS16* values.
|
---|
76 | AssertCompile(BS3_SEL_RING_SHIFT == 8)
|
---|
77 | cmp al, BS3_SEL_R0_CS16 & 0xff
|
---|
78 | je .bs3text16
|
---|
79 | cmp al, BS3_SEL_R0_CS16_EO & 0xff
|
---|
80 | je .bs3text16
|
---|
81 | cmp ax, BS3_SEL_R0_CS16_CNF & 0xff
|
---|
82 | je .bs3text16
|
---|
83 | cmp ax, BS3_SEL_R0_CS16_CNF_EO & 0xff
|
---|
84 | je .bs3text16
|
---|
85 | .panic:
|
---|
86 | extern BS3_CMN_NM(Bs3Panic)
|
---|
87 | call BS3_CMN_NM(Bs3Panic)
|
---|
88 | jmp .return
|
---|
89 |
|
---|
90 | .bs3x1text16:
|
---|
91 | mov ax, BS3GROUPX1TEXT16
|
---|
92 | jmp .return
|
---|
93 | .bs3x0text16:
|
---|
94 | mov ax, BS3GROUPX0TEXT16
|
---|
95 | jmp .return
|
---|
96 | .bs3rmtext16:
|
---|
97 | mov ax, BS3GROUPRMTEXT16
|
---|
98 | jmp .return
|
---|
99 | .bs3text16:
|
---|
100 | mov ax, CGROUP16
|
---|
101 | .return:
|
---|
102 | pop xBP
|
---|
103 | BS3_CALL_CONV_EPILOG 1
|
---|
104 | BS3_HYBRID_RET
|
---|
105 | BS3_PROC_END_CMN Bs3SelProtModeCodeToRealMode
|
---|
106 |
|
---|
107 | ;
|
---|
108 | ; We may be using the near code in some critical code paths, so don't
|
---|
109 | ; penalize it.
|
---|
110 | ;
|
---|
111 | BS3_CMN_FAR_STUB Bs3SelProtModeCodeToRealMode, 2
|
---|
112 |
|
---|