1 | ; $Id: bootsector2-common-routines-template-2.mac 96407 2022-08-22 17:43:14Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; bootsector2 common routines - template containing code specific to each mode.
|
---|
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 "bootsector2-template-header.mac"
|
---|
38 | ALIGNCODE(32)
|
---|
39 | GLOBALNAME TMPL_NM(g_szMode)
|
---|
40 | db TMPL_MODE_STR, 0
|
---|
41 |
|
---|
42 |
|
---|
43 | ;;
|
---|
44 | ; Prints a string on the screen.
|
---|
45 | ;
|
---|
46 | ; @param ds:ax The string to print (null terminated).
|
---|
47 | ;
|
---|
48 | ; @uses nothing
|
---|
49 | ;
|
---|
50 | BEGINPROC TMPL_NM(PrintStr)
|
---|
51 | push xBP
|
---|
52 | mov xBP, xSP
|
---|
53 | push xAX
|
---|
54 | push xBX
|
---|
55 | push xSI
|
---|
56 |
|
---|
57 | mov xSI, xAX
|
---|
58 | .next:
|
---|
59 | lodsb
|
---|
60 | test al, al
|
---|
61 | jz .done
|
---|
62 | %ifdef TMPL_HAVE_BIOS
|
---|
63 | mov bx, 0ff00h
|
---|
64 | mov ah, 0eh
|
---|
65 | int 10h
|
---|
66 | %else
|
---|
67 | call TMPL_NM(PrintChr)
|
---|
68 | %endif
|
---|
69 | jmp .next
|
---|
70 |
|
---|
71 | .done:
|
---|
72 | pop xSI
|
---|
73 | pop xBX
|
---|
74 | pop xAX
|
---|
75 | leave
|
---|
76 | ret
|
---|
77 | ENDPROC TMPL_NM(PrintStr)
|
---|
78 |
|
---|
79 |
|
---|
80 | ;;
|
---|
81 | ; Prints a string on the screen.
|
---|
82 | ;
|
---|
83 | ; @param al The character to print.
|
---|
84 | ;
|
---|
85 | ; @uses nothing
|
---|
86 | ;
|
---|
87 | BEGINCODELOW
|
---|
88 | BEGINPROC TMPL_NM(PrintChr)
|
---|
89 | push xBP
|
---|
90 | mov xBP, xSP
|
---|
91 | push xAX
|
---|
92 | push xBX
|
---|
93 |
|
---|
94 | %ifndef TMPL_HAVE_BIOS
|
---|
95 | %ifdef BS2_WITH_TRAPS
|
---|
96 | mov bx, cs
|
---|
97 | and xBX, 0x3
|
---|
98 | push xBX
|
---|
99 | jz .ring_ok
|
---|
100 | call TMPL_NM_CMN(Bs2ToRing0)
|
---|
101 | .ring_ok:
|
---|
102 | %endif
|
---|
103 |
|
---|
104 | mov bl, al
|
---|
105 | call TMPL_NM(LeaveCpuMode)
|
---|
106 | mov al, bl
|
---|
107 | BITS 16
|
---|
108 | %endif
|
---|
109 |
|
---|
110 | mov bx, 0ff00h
|
---|
111 | mov ah, 0eh
|
---|
112 | int 10h
|
---|
113 |
|
---|
114 | %ifndef TMPL_HAVE_BIOS
|
---|
115 | call TMPL_NM(EnterCpuMode)
|
---|
116 | BITS TMPL_BITS
|
---|
117 | %ifdef BS2_WITH_TRAPS
|
---|
118 | pop xAX
|
---|
119 | test al, al
|
---|
120 | jz .ring_restored
|
---|
121 | call TMPL_NM_CMN(Bs2ToRingN)
|
---|
122 | .ring_restored:
|
---|
123 | %endif
|
---|
124 | %endif
|
---|
125 |
|
---|
126 | pop xBX
|
---|
127 | pop xAX
|
---|
128 | leave
|
---|
129 | ret
|
---|
130 | ENDPROC TMPL_NM(PrintChr)
|
---|
131 | TMPL_BEGINCODE
|
---|
132 |
|
---|
133 |
|
---|
134 | %ifndef TMPL_HAVE_BIOS
|
---|
135 |
|
---|
136 | ;;
|
---|
137 | ; Leaves the current CPU mode and returns to real mode.
|
---|
138 | ;
|
---|
139 | ; @uses nothing
|
---|
140 | ;
|
---|
141 | BEGINPROC TMPL_NM(LeaveCpuMode)
|
---|
142 | jmp TMPL_NM(Bs2ExitMode)
|
---|
143 | ENDPROC TMPL_NM(LeaveCpuMode)
|
---|
144 |
|
---|
145 |
|
---|
146 | ;;
|
---|
147 | ; Undo what LeaveCpuMode did.
|
---|
148 | ;
|
---|
149 | ; @uses nothing
|
---|
150 | ;
|
---|
151 | BEGINCODELOW
|
---|
152 | BITS 16
|
---|
153 | BEGINPROC TMPL_NM(EnterCpuMode)
|
---|
154 | jmp TMPL_NM(Bs2EnterMode_rm)
|
---|
155 | ENDPROC TMPL_NM(EnterCpuMode)
|
---|
156 | TMPL_BEGINCODE
|
---|
157 | BITS TMPL_BITS
|
---|
158 |
|
---|
159 | %endif ; TMPL_HAVE_BIOS
|
---|
160 |
|
---|
161 |
|
---|
162 | ;;
|
---|
163 | ; Sets the global variable for the current CPU mode.
|
---|
164 | ;
|
---|
165 | ; @uses nothing.
|
---|
166 | ;
|
---|
167 | BEGINPROC TMPL_NM(SetCpuModeGlobals)
|
---|
168 | %ifdef TMPL_CMN_PE
|
---|
169 | %ifdef BS2_INC_PE16
|
---|
170 | mov word [g_pfnPrintStrInternal_p16], PrintStr_pe16
|
---|
171 | mov word [g_pfnPrintChrInternal_p16], PrintChr_pe16
|
---|
172 | %endif
|
---|
173 | %ifdef BS2_INC_PE32
|
---|
174 | mov dword [g_pfnPrintStrInternal_p32], PrintStr_pe32
|
---|
175 | mov dword [g_pfnPrintChrInternal_p32], PrintChr_pe32
|
---|
176 | %endif
|
---|
177 |
|
---|
178 | %elifdef TMPL_CMN_PP
|
---|
179 | %ifdef BS2_INC_PP16
|
---|
180 | mov word [g_pfnPrintStrInternal_p16], PrintStr_pp16
|
---|
181 | mov word [g_pfnPrintChrInternal_p16], PrintChr_pp16
|
---|
182 | %endif
|
---|
183 | %ifdef BS2_INC_PP32
|
---|
184 | mov dword [g_pfnPrintStrInternal_p32], PrintStr_pp32
|
---|
185 | mov dword [g_pfnPrintChrInternal_p32], PrintChr_pp32
|
---|
186 | %endif
|
---|
187 |
|
---|
188 | %elifdef TMPL_CMN_PAE
|
---|
189 | %ifdef BS2_INC_PAE16
|
---|
190 | mov word [g_pfnPrintStrInternal_p16], PrintStr_pae16
|
---|
191 | mov word [g_pfnPrintChrInternal_p16], PrintChr_pae16
|
---|
192 | %endif
|
---|
193 | %ifdef BS2_INC_PAE32
|
---|
194 | mov dword [g_pfnPrintStrInternal_p32], PrintStr_pae32
|
---|
195 | mov dword [g_pfnPrintChrInternal_p32], PrintChr_pae32
|
---|
196 | %endif
|
---|
197 |
|
---|
198 | %elifdef TMPL_CMN_LM
|
---|
199 | %ifdef BS2_INC_LM16
|
---|
200 | mov word [g_pfnPrintStrInternal_p16], PrintStr_lm16
|
---|
201 | mov word [g_pfnPrintChrInternal_p16], PrintChr_lm16
|
---|
202 | %endif
|
---|
203 | %ifdef BS2_INC_LM32
|
---|
204 | mov dword [g_pfnPrintStrInternal_p32], PrintStr_lm32
|
---|
205 | mov dword [g_pfnPrintChrInternal_p32], PrintChr_lm32
|
---|
206 | %endif
|
---|
207 | %ifdef BS2_INC_LM64
|
---|
208 | mov dword [g_pfnPrintStrInternal_p64], PrintStr_lm64
|
---|
209 | mov dword [g_pfnPrintChrInternal_p64], PrintChr_lm64
|
---|
210 | %endif
|
---|
211 |
|
---|
212 | %elifdef TMPL_16BIT
|
---|
213 | mov word [TMPL_NM_CMN(g_pfnPrintStrInternal)], TMPL_NM(PrintStr)
|
---|
214 | mov word [TMPL_NM_CMN(g_pfnPrintChrInternal)], TMPL_NM(PrintChr)
|
---|
215 | %else
|
---|
216 | %error "missing case"
|
---|
217 | %endif
|
---|
218 | ret
|
---|
219 | ENDPROC TMPL_NM(SetCpuModeGlobals)
|
---|
220 |
|
---|
221 |
|
---|
222 |
|
---|
223 | %include "bootsector2-template-footer.mac"
|
---|
224 |
|
---|