1 | ; $Id: bs3-cmn-SelFlatCodeToProtFar16.asm 62484 2016-07-22 18:35:33Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - Bs3SelFlatCodeToProtFar16.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2007-2016 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 |
|
---|
28 | ;*********************************************************************************************************************************
|
---|
29 | ;* Header Files *
|
---|
30 | ;*********************************************************************************************************************************
|
---|
31 | %include "bs3kit-template-header.mac"
|
---|
32 |
|
---|
33 |
|
---|
34 | ;*********************************************************************************************************************************
|
---|
35 | ;* External Symbols *
|
---|
36 | ;*********************************************************************************************************************************
|
---|
37 | BS3_EXTERN_CMN Bs3SelFlatCodeToRealMode
|
---|
38 | BS3_EXTERN_CMN Bs3SelRealModeCodeToProtMode
|
---|
39 | TMPL_BEGIN_TEXT
|
---|
40 |
|
---|
41 |
|
---|
42 | ;;
|
---|
43 | ; @cproto BS3_CMN_PROTO(uint32_t, Bs3SelRealModeCodeToProtMode,(uint32_t uFlatAddr), false);
|
---|
44 | ;
|
---|
45 | ; @uses Only return registers (ax:dx, eax, eax)
|
---|
46 | ;
|
---|
47 | BS3_PROC_BEGIN_CMN Bs3SelFlatCodeToProtFar16, BS3_PBC_NEAR
|
---|
48 | BS3_CALL_CONV_PROLOG 1
|
---|
49 | push xBP
|
---|
50 | mov xBP, xSP
|
---|
51 |
|
---|
52 | ;
|
---|
53 | ; Call Bs3SelFlatCodeToRealMode and then Bs3SelRealModeCodeToProtMode.
|
---|
54 | ; This avoid some code duplication.
|
---|
55 | ;
|
---|
56 | %if TMPL_BITS == 16
|
---|
57 | push word [xBP + xCB + cbCurRetAddr + 2]
|
---|
58 | push word [xBP + xCB + cbCurRetAddr]
|
---|
59 | call Bs3SelFlatCodeToRealMode
|
---|
60 | add sp, 4h
|
---|
61 |
|
---|
62 | push ax ; save the offset as it will be the same.
|
---|
63 |
|
---|
64 | push dx
|
---|
65 | call Bs3SelRealModeCodeToProtMode
|
---|
66 | add sp, 2h
|
---|
67 |
|
---|
68 | mov dx, ax ; The protected mode selector.
|
---|
69 | pop ax ; The offset.
|
---|
70 |
|
---|
71 | %elif TMPL_BITS == 32
|
---|
72 | push dword [xBP + xCB + cbCurRetAddr]
|
---|
73 | call Bs3SelFlatCodeToRealMode
|
---|
74 | add esp, 4h
|
---|
75 |
|
---|
76 | push eax ; save the result.
|
---|
77 |
|
---|
78 | shr eax, 16
|
---|
79 | push eax
|
---|
80 | call Bs3SelRealModeCodeToProtMode
|
---|
81 | add esp, 4h
|
---|
82 |
|
---|
83 | mov [esp + 2], ax ; Update the selector before popping the result.
|
---|
84 | pop eax
|
---|
85 |
|
---|
86 | %elif TMPL_BITS == 64
|
---|
87 | push xCX ; Preserve RCX to make the behaviour uniform.
|
---|
88 | sub xSP, 28h ; 20h bytes of calling convention scratch and 8 byte for saving the result.
|
---|
89 |
|
---|
90 | mov ecx, [xBP + xCB + cbCurRetAddr] ; move straight to parameter 0 register.
|
---|
91 | call Bs3SelFlatCodeToRealMode
|
---|
92 |
|
---|
93 | mov [xBP - xCB*2], eax ; Save the result.
|
---|
94 |
|
---|
95 | shr eax, 16
|
---|
96 | mov ecx, eax ; Move straight to parameter 0 register.
|
---|
97 | call Bs3SelRealModeCodeToProtMode
|
---|
98 |
|
---|
99 | shl eax, 16 ; Shift prot mode selector into result position.
|
---|
100 | mov ax, [xBP - xCB*2] ; The segment offset from the previous call.
|
---|
101 |
|
---|
102 | add xSP, 28h
|
---|
103 | pop xCX
|
---|
104 | %else
|
---|
105 | %error "TMPL_BITS=" TMPL_BITS "!"
|
---|
106 | %endif
|
---|
107 | pop xBP
|
---|
108 | BS3_CALL_CONV_EPILOG 1
|
---|
109 | BS3_HYBRID_RET
|
---|
110 | BS3_PROC_END_CMN Bs3SelFlatCodeToProtFar16
|
---|
111 |
|
---|
112 |
|
---|
113 | ;
|
---|
114 | ; We may be using the near code in some critical code paths, so don't
|
---|
115 | ; penalize it.
|
---|
116 | ;
|
---|
117 | BS3_CMN_FAR_STUB Bs3SelFlatCodeToProtFar16, 4
|
---|
118 |
|
---|
119 |
|
---|
120 |
|
---|