1 | ; $Id: bs3-cmn-SelFlatCodeToRealMode.asm 60539 2016-04-18 14:09:39Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - Bs3SelFlatCodeToRealMode.
|
---|
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 |
|
---|
28 | ;*********************************************************************************************************************************
|
---|
29 | ;* Header Files *
|
---|
30 | ;*********************************************************************************************************************************
|
---|
31 | %include "bs3kit-template-header.mac"
|
---|
32 |
|
---|
33 |
|
---|
34 | ;*********************************************************************************************************************************
|
---|
35 | ;* Global Variables *
|
---|
36 | ;*********************************************************************************************************************************
|
---|
37 | extern Bs3X0Text16_EndOfSegment
|
---|
38 | extern Bs3X1Text16_EndOfSegment
|
---|
39 |
|
---|
40 |
|
---|
41 | ;
|
---|
42 | ; Make sure we can get at all the segments.
|
---|
43 | ;
|
---|
44 | BS3_BEGIN_TEXT16
|
---|
45 | BS3_BEGIN_X0TEXT16
|
---|
46 | BS3_BEGIN_X1TEXT16
|
---|
47 | TMPL_BEGIN_TEXT
|
---|
48 |
|
---|
49 |
|
---|
50 | ;;
|
---|
51 | ; @cproto BS3_CMN_PROTO(uint32_t, Bs3SelRealModeCodeToProtMode,(uint32_t uFlatAddr), false);
|
---|
52 | ;
|
---|
53 | ; @uses Only return registers (ax:dx, eax, eax)
|
---|
54 | ;
|
---|
55 | BS3_PROC_BEGIN_CMN Bs3SelFlatCodeToRealMode, BS3_PBC_NEAR
|
---|
56 | BS3_CALL_CONV_PROLOG 1
|
---|
57 | push xBP
|
---|
58 | mov xBP, xSP
|
---|
59 | push xCX
|
---|
60 | push xBX
|
---|
61 | %if TMPL_BITS != 16
|
---|
62 | push xDX
|
---|
63 | %endif
|
---|
64 |
|
---|
65 | ;
|
---|
66 | ; Load the real mode frame number into DX so we can compare with the
|
---|
67 | ; segment frame numbers fixed up by the linker.
|
---|
68 | ;
|
---|
69 | ; Imagine: FlatAddr = 0x054321
|
---|
70 | ;
|
---|
71 | mov dx, [xBP + xCB + cbCurRetAddr + 1] ; dx = 0x0543
|
---|
72 | mov al, [xBP + xCB + cbCurRetAddr + 0] ; al = 0x21
|
---|
73 | mov cl,4
|
---|
74 | shl dx, 4 ; dx = 0x5430
|
---|
75 | shr al, 4 ; al = 0x02
|
---|
76 | or dl, al ; dx = 0x5432
|
---|
77 |
|
---|
78 | mov ax, dx
|
---|
79 | sub ax, BS3TEXT16
|
---|
80 | cmp ax, 1000h
|
---|
81 | jb .bs3text16
|
---|
82 |
|
---|
83 | mov ax, dx
|
---|
84 | sub ax, BS3X0TEXT16
|
---|
85 | mov bx, Bs3X0Text16_EndOfSegment wrt BS3GROUPX0TEXT16
|
---|
86 | add bx, 15
|
---|
87 | shr bx, cl
|
---|
88 | cmp ax, bx
|
---|
89 | jb .bs3x0text16
|
---|
90 |
|
---|
91 | mov ax, dx
|
---|
92 | sub ax, BS3X1TEXT16
|
---|
93 | mov bx, Bs3X1Text16_EndOfSegment wrt BS3GROUPX1TEXT16
|
---|
94 | add bx, 15
|
---|
95 | shr bx, cl
|
---|
96 | cmp ax, bx
|
---|
97 | jb .bs3x1text16
|
---|
98 |
|
---|
99 | extern BS3_CMN_NM(Bs3Panic)
|
---|
100 | call BS3_CMN_NM(Bs3Panic)
|
---|
101 |
|
---|
102 | ;
|
---|
103 | ; Load the real-mode frame into DX and calc the offset in AX.
|
---|
104 | ;
|
---|
105 | .bs3x1text16:
|
---|
106 | mov dx, BS3X1TEXT16
|
---|
107 | jmp .calc_return
|
---|
108 | .bs3x0text16:
|
---|
109 | mov dx, BS3X0TEXT16
|
---|
110 | jmp .calc_return
|
---|
111 | .bs3text16:
|
---|
112 | mov dx, BS3X0TEXT16
|
---|
113 | .calc_return:
|
---|
114 | ; Convert the real-mode frame into the low 16-bit base (BX).
|
---|
115 | mov bx, dx
|
---|
116 | shl bx, cl
|
---|
117 | ; Subtract the 16-bit base from the flat address. (No need to consider
|
---|
118 | ; the top half on either side.)
|
---|
119 | mov ax, [xBP + xCB + cbCurRetAddr + 0]
|
---|
120 | sub ax, bx
|
---|
121 | %if TMPL_BITS != 16
|
---|
122 | ; Got a single 32-bit return register here.
|
---|
123 | shl edx, 16
|
---|
124 | mov dx, ax
|
---|
125 | mov eax, edx
|
---|
126 | pop xDX
|
---|
127 | %endif
|
---|
128 | pop xBX
|
---|
129 | pop xCX
|
---|
130 | pop xBP
|
---|
131 | BS3_CALL_CONV_EPILOG 1
|
---|
132 | BS3_HYBRID_RET
|
---|
133 | BS3_PROC_END_CMN Bs3SelFlatCodeToRealMode
|
---|
134 |
|
---|
135 | ;
|
---|
136 | ; We may be using the near code in some critical code paths, so don't
|
---|
137 | ; penalize it.
|
---|
138 | ;
|
---|
139 | BS3_CMN_FAR_STUB Bs3SelFlatCodeToRealMode, 4
|
---|
140 |
|
---|
141 |
|
---|