VirtualBox

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

Last change on this file since 77922 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

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