VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-header.mac@ 102157

Last change on this file since 102157 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.2 KB
Line 
1; $Id: bs3kit-template-header.mac 98103 2023-01-17 14:15:46Z vboxsync $
2;; @file
3; BS3Kit header for multi-mode code templates.
4;
5
6;
7; Copyright (C) 2007-2023 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 "bs3kit.mac"
38
39;
40; Check and expand the mode defines.
41; One of the following must be defined:
42; - TMPL_RM - real mode.
43; - TMPL_PE16 - 16-bit protected mode, unpaged.
44; - TMPL_PE32 - 32-bit protected mode, unpaged.
45; - TMPL_PEV86 - virtual 8086 mode under protected mode, unpaged.
46; - TMPL_PP16 - 16-bit protected mode, paged.
47; - TMPL_PP32 - 32-bit protected mode, paged.
48; - TMPL_PPV86 - virtual 8086 mode under protected mode, paged.
49; - TMPL_PAE16 - 16-bit protected mode with PAE (paged).
50; - TMPL_PAE32 - 16-bit protected mode with PAE (paged).
51; - TMPL_PAEV86- virtual 8086 mode under protected mode with PAE (paged).
52; - TMPL_LM16 - 16-bit long mode (paged).
53; - TMPL_LM32 - 32-bit long mode (paged).
54; - TMPL_LM64 - 64-bit long mode (paged).
55;
56; Derived indicators:
57; - TMPL_CMN_PE = TMPL_PE16 | TMPL_PE32 | TMPL_PEV86
58; - TMPL_CMN_PP = TMPL_PP16 | TMPL_PP32 | TMPL_PPV86
59; - TMPL_CMN_PAE = TMPL_PAE16 | TMPL_PAE32 | TMPL_PAEV86
60; - TMPL_CMN_LM = TMPL_LM16 | TMPL_LM32 | TMPL_LM64
61; - TMPL_CMN_V86 = TMPL_PEV86 | TMPL_PPV86 | TMPL_PAEV86
62; - TMPL_CMN_R86 = TMPL_CMN_V86 | TMPL_RM
63; - TMPL_CMN_PAGING = TMPL_CMN_PP | TMPL_CMN_PAE | TMPL_CMN_LM
64;
65
66
67;
68; Convert TMPL_XXX to TMPL_MODE.
69;
70%ifndef TMPL_MODE
71 %ifdef TMPL_RM
72 %define TMPL_MODE BS3_MODE_RM
73 %elifdef TMPL_PE16
74 %define TMPL_MODE BS3_MODE_PE16
75 %elifdef TMPL_PE16_32
76 %define TMPL_MODE BS3_MODE_PE16_32
77 %elifdef TMPL_PE16_V86
78 %define TMPL_MODE BS3_MODE_PE16_V86
79 %elifdef TMPL_PE32
80 %define TMPL_MODE BS3_MODE_PE32
81 %elifdef TMPL_PE32_16
82 %define TMPL_MODE BS3_MODE_PE32_16
83 %elifdef TMPL_PEV86
84 %define TMPL_MODE BS3_MODE_PEV86
85 %elifdef TMPL_PP16
86 %define TMPL_MODE BS3_MODE_PP16
87 %elifdef TMPL_PP16_32
88 %define TMPL_MODE BS3_MODE_PP16_32
89 %elifdef TMPL_PP16_V86
90 %define TMPL_MODE BS3_MODE_PP16_V86
91 %elifdef TMPL_PP32
92 %define TMPL_MODE BS3_MODE_PP32
93 %elifdef TMPL_PP32_16
94 %define TMPL_MODE BS3_MODE_PP32_16
95 %elifdef TMPL_PPV86
96 %define TMPL_MODE BS3_MODE_PPV86
97 %elifdef TMPL_PAE16
98 %define TMPL_MODE BS3_MODE_PAE16
99 %elifdef TMPL_PAE16_32
100 %define TMPL_MODE BS3_MODE_PAE16_32
101 %elifdef TMPL_PAE16_V86
102 %define TMPL_MODE BS3_MODE_PAE16_V86
103 %elifdef TMPL_PAE32
104 %define TMPL_MODE BS3_MODE_PAE32
105 %elifdef TMPL_PAE32_16
106 %define TMPL_MODE BS3_MODE_PAE32_16
107 %elifdef TMPL_PAEV86
108 %define TMPL_MODE BS3_MODE_PAEV86
109 %elifdef TMPL_LM16
110 %define TMPL_MODE BS3_MODE_LM16
111 %elifdef TMPL_LM32
112 %define TMPL_MODE BS3_MODE_LM32
113 %elifdef TMPL_LM64
114 %define TMPL_MODE BS3_MODE_LM64
115 %else
116 %error "Unable to to figure out the template mode."
117 %endif
118%endif
119
120;
121; Check the code bitness and set TMPL_XXBITS, TMPL_BITS, BS3_CMN_NM
122;
123%if (TMPL_MODE & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_16
124 %define TMPL_16BIT
125 %define TMPL_BITS 16
126 %define TMPL_PTR_DEF dw
127 %define TMPL_UNDERSCORE _
128 %define BS3_CMN_NM(Name) _ %+ Name %+ _c16
129
130%elif (TMPL_MODE & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_32
131 %define TMPL_32BIT
132 %define TMPL_BITS 32
133 %define TMPL_PTR_DEF dd
134 %define TMPL_UNDERSCORE _
135 %define BS3_CMN_NM(Name) _ %+ Name %+ _c32
136
137%elif (TMPL_MODE & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_V86
138 %define TMPL_16BIT
139 %define TMPL_BITS 16
140 %define TMPL_UNDERSCORE _
141 %define BS3_CMN_NM(Name) _ %+ Name %+ _c16
142 %define TMPL_CMN_R86
143 %define TMPL_CMN_V86
144
145%elif (TMPL_MODE & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_64
146 %define TMPL_64BIT
147 %define TMPL_BITS 64
148 %define TMPL_PTR_DEF dq
149 %define TMPL_UNDERSCORE _
150 %define BS3_CMN_NM(Name) _ %+ Name %+ _c64
151
152%else
153 %error "Invalid TMPL_MODE value!"
154%endif
155
156;
157; Check the system specific mask and set derived values.
158;
159%if (TMPL_MODE & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_RM
160 %define TMPL_HAVE_BIOS
161 %define TMPL_CMN_R86
162
163%elif (TMPL_MODE & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PE16
164 %define TMPL_SYS_PE16
165 %define TMPL_CMN_PE
166
167%elif (TMPL_MODE & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PE32
168 %define TMPL_SYS_PE32
169 %define TMPL_CMN_PE
170
171%elif (TMPL_MODE & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PP16
172 %define TMPL_SYS_PP16
173 %define TMPL_CMN_PP
174 %define TMPL_CMN_PAGING
175
176%elif (TMPL_MODE & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PP32
177 %define TMPL_SYS_PP32
178 %define TMPL_CMN_PP
179 %define TMPL_CMN_PAGING
180
181%elif (TMPL_MODE & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PAE16
182 %define TMPL_SYS_PAE16
183 %define TMPL_CMN_PAE
184 %define TMPL_CMN_PAGING
185
186%elif (TMPL_MODE & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PAE32
187 %define TMPL_SYS_PAE32
188 %define TMPL_CMN_PAE
189 %define TMPL_CMN_PAGING
190
191%elif (TMPL_MODE & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_LM
192 %define TMPL_SYS_LM
193 %define TMPL_CMN_LM
194 %define TMPL_CMN_PAGING
195
196%else
197 %error "Invalid TMPL_MODE value!"
198%endif
199
200
201;
202; Mode specific stuff.
203;
204%if TMPL_MODE == BS3_MODE_RM
205 %define TMPL_RM
206 %define TMPL_MODE_STR "real mode"
207 %define TMPL_NM(Name) _ %+ Name %+ _rm
208 %define TMPL_MODE_LNAME rm
209 %define TMPL_MODE_UNAME RM
210
211
212%elif TMPL_MODE == BS3_MODE_PE16
213 %define TMPL_PE16
214 %define TMPL_MODE_STR "16-bit prot, 16-bit"
215 %define TMPL_NM(Name) _ %+ Name %+ _pe16
216 %define TMPL_MODE_LNAME pe16
217 %define TMPL_MODE_UNAME PE16
218
219%elif TMPL_MODE == BS3_MODE_PE16_32
220 %define TMPL_PE16_32
221 %define TMPL_MODE_STR "16-bit prot, 32-bit"
222 %define TMPL_NM(Name) _ %+ Name %+ _pe16_32
223 %define TMPL_MODE_LNAME pe16_32
224 %define TMPL_MODE_UNAME PE16_32
225 %define TMPL_CMN_WEIRD
226
227%elif TMPL_MODE == BS3_MODE_PE16_V86
228 %define TMPL_PE16_V86
229 %define TMPL_MODE_STR "16-bit prot, v8086"
230 %define TMPL_NM(Name) _ %+ Name %+ _pe16_v86
231 %define TMPL_MODE_LNAME pe16_v86
232 %define TMPL_MODE_UNAME PE16_v86
233 %define TMPL_CMN_WEIRD
234 %define TMPL_CMN_WEIRD_V86
235
236
237%elif TMPL_MODE == BS3_MODE_PE32
238 %define TMPL_PE32
239 %define TMPL_MODE_STR "32-bit prot, 32-bit"
240 %define TMPL_NM(Name) _ %+ Name %+ _pe32
241 %define TMPL_MODE_LNAME pe32
242 %define TMPL_MODE_UNAME PE32
243
244%elif TMPL_MODE == BS3_MODE_PE32_16
245 %define TMPL_PE32_16
246 %define TMPL_MODE_STR "32-bit prot, 16-bit"
247 %define TMPL_NM(Name) _ %+ Name %+ _pe32_16
248 %define TMPL_MODE_LNAME pe32_16
249 %define TMPL_MODE_UNAME PE32_16
250 %define TMPL_CMN_WEIRD
251
252%elif TMPL_MODE == BS3_MODE_PEV86
253 %define TMPL_PEV86
254 %define TMPL_MODE_STR "32-bit prot, v8086"
255 %define TMPL_NM(Name) _ %+ Name %+ _pev86
256 %define TMPL_MODE_LNAME pev86
257 %define TMPL_MODE_UNAME PEV86
258
259
260%elif TMPL_MODE == BS3_MODE_PP16
261 %define TMPL_PP16
262 %define TMPL_MODE_STR "16-bit paged, 16-bit"
263 %define TMPL_NM(Name) _ %+ Name %+ _pp16
264 %define TMPL_MODE_LNAME pp16
265 %define TMPL_MODE_UNAME PP16
266
267%elif TMPL_MODE == BS3_MODE_PP16_32
268 %define TMPL_PP16_32
269 %define TMPL_MODE_STR "16-bit paged, 32-bit"
270 %define TMPL_NM(Name) _ %+ Name %+ _pp16_32
271 %define TMPL_MODE_LNAME pp16_32
272 %define TMPL_MODE_UNAME PP16_32
273 %define TMPL_CMN_WEIRD
274
275%elif TMPL_MODE == BS3_MODE_PP16_V86
276 %define TMPL_PP16_V86
277 %define TMPL_MODE_STR "16-bit paged, v8086"
278 %define TMPL_NM(Name) _ %+ Name %+ _pp16_v86
279 %define TMPL_MODE_LNAME pp16_v86
280 %define TMPL_MODE_UNAME PP16_v86
281 %define TMPL_CMN_WEIRD
282 %define TMPL_CMN_WEIRD_V86
283
284
285%elif TMPL_MODE == BS3_MODE_PP32
286 %define TMPL_PP32
287 %define TMPL_MODE_STR "32-bit paged, 32-bit"
288 %define TMPL_NM(Name) _ %+ Name %+ _pp32
289 %define TMPL_MODE_LNAME pp32
290 %define TMPL_MODE_UNAME PP32
291
292%elif TMPL_MODE == BS3_MODE_PP32_16
293 %define TMPL_PP32_16
294 %define TMPL_MODE_STR "32-bit paged, 16-bit"
295 %define TMPL_NM(Name) _ %+ Name %+ _pp32_16
296 %define TMPL_MODE_LNAME pp32_16
297 %define TMPL_MODE_UNAME PP32_16
298 %define TMPL_CMN_WEIRD
299
300%elif TMPL_MODE == BS3_MODE_PPV86
301 %define TMPL_PPV86
302 %define TMPL_MODE_STR "32-bit paged, v8086"
303 %define TMPL_NM(Name) _ %+ Name %+ _ppv86
304 %define TMPL_MODE_LNAME ppv86
305 %define TMPL_MODE_UNAME PPV86
306
307
308%elif TMPL_MODE == BS3_MODE_PAE16
309 %define TMPL_PAE16
310 %define TMPL_MODE_STR "16-bit pae, 16-bit"
311 %define TMPL_NM(Name) _ %+ Name %+ _pae16
312 %define TMPL_MODE_LNAME pae16
313 %define TMPL_MODE_UNAME PAE16
314
315%elif TMPL_MODE == BS3_MODE_PAE16_32
316 %define TMPL_PAE16_32
317 %define TMPL_MODE_STR "16-bit pae, 32-bit"
318 %define TMPL_NM(Name) _ %+ Name %+ _pae16_32
319 %define TMPL_MODE_LNAME pae16_32
320 %define TMPL_MODE_UNAME PAE16_32
321 %define TMPL_CMN_WEIRD
322
323%elif TMPL_MODE == BS3_MODE_PAE16_V86
324 %define TMPL_PAE16_V86
325 %define TMPL_MODE_STR "16-bit pae, v8086"
326 %define TMPL_NM(Name) _ %+ Name %+ _pae16_v86
327 %define TMPL_MODE_LNAME pae16_v86
328 %define TMPL_MODE_UNAME PAE16_v86
329 %define TMPL_CMN_WEIRD
330 %define TMPL_CMN_WEIRD_V86
331
332
333%elif TMPL_MODE == BS3_MODE_PAE32
334 %define TMPL_PAE32
335 %define TMPL_MODE_STR "32-bit pae, 32-bit"
336 %define TMPL_NM(Name) _ %+ Name %+ _pae32
337 %define TMPL_MODE_LNAME pae32
338 %define TMPL_MODE_UNAME PAE32
339
340%elif TMPL_MODE == BS3_MODE_PAE32_16
341 %define TMPL_PAE32_16
342 %define TMPL_MODE_STR "32-bit pae, 16-bit"
343 %define TMPL_NM(Name) _ %+ Name %+ _pae32_16
344 %define TMPL_MODE_LNAME pae32_16
345 %define TMPL_MODE_UNAME PAE32_16
346 %define TMPL_CMN_WEIRD
347
348%elif TMPL_MODE == BS3_MODE_PAEV86
349 %define TMPL_PAEV86
350 %define TMPL_MODE_STR "32-bit pae, v8086 pae"
351 %define TMPL_NM(Name) _ %+ Name %+ _paev86
352 %define TMPL_MODE_LNAME paev86
353 %define TMPL_MODE_UNAME PAEV86
354
355
356%elif TMPL_MODE == BS3_MODE_LM16
357 %define TMPL_LM16
358 %define TMPL_MODE_STR "long, 16-bit"
359 %define TMPL_NM(Name) _ %+ Name %+ _lm16
360 %define TMPL_MODE_LNAME lm16
361 %define TMPL_MODE_UNAME LM16
362
363%elif TMPL_MODE == BS3_MODE_LM32
364 %define TMPL_LM32
365 %define TMPL_MODE_STR "long, 32-bit"
366 %define TMPL_NM(Name) _ %+ Name %+ _lm32
367 %define TMPL_MODE_LNAME lm32
368 %define TMPL_MODE_UNAME LM32
369
370%elif TMPL_MODE == BS3_MODE_LM64
371 %define TMPL_LM64
372 %define TMPL_MODE_STR "long, 64-bit"
373 %define TMPL_NM(Name) _ %+ Name %+ _lm64
374 %define TMPL_MODE_LNAME lm64
375 %define TMPL_MODE_UNAME LM64
376
377%else
378 %error "Invalid TMPL_MODE value!!"
379%endif
380
381%ifnidn TMPL_UNDERSCORE,_; RT_CONCAT3 doesn't work with TMPL_UNDERSCORE being empty. duh.
382 %ifidn RT_CONCAT(TestName_,TMPL_MODE_LNAME),TMPL_NM(TestName)
383 %else
384 %error internal error: RT_CONCAT(TestName_,TMPL_MODE_LNAME) vs TMPL_NM(TestName)
385 %endif
386%else
387 %ifidn RT_CONCAT3(TMPL_UNDERSCORE,TestName_,TMPL_MODE_LNAME),TMPL_NM(TestName)
388 %else
389 %error internal error: RT_CONCAT3(TMPL_UNDERSCORE,TestName_,TMPL_MODE_LNAME) vs TMPL_NM(TestName)
390 %endif
391%endif
392
393; TMPL_NM version with uppercased suffix and no underscore separating them.
394%define TMPL_NM_U(Name) TMPL_UNDERSCORE %+ Name %+ TMPL_MODE_UNAME
395
396; TMPL_FAR_NM
397%if TMPL_MODE & (BS3_MODE_CODE_16 | BS3_MODE_CODE_V86)
398 %define TMPL_FAR_NM(Name) TMPL_NM(Name) %+ _far
399%else
400 %define TMPL_FAR_NM(Name) TMPL_NM(Name)
401%endif
402
403
404;; @def TMPL_WRT_FLAT
405; WRT flat when not in 16-bit modes.
406;
407%ifdef TMPL_16BIT
408 %define TMPL_WRT_FLAT
409%else
410 %define TMPL_WRT_FLAT wrt FLAT
411%endif
412
413;; @def TMPL_WRT_DATA16_OR_FLAT
414; WRT DATA16 in 16-bit mode, WRT FLAT in 32- and 64-bit modes.
415; This is important when accessing global variables.
416;
417%ifdef TMPL_16BIT
418 %define TMPL_WRT_DATA16_OR_FLAT wrt BS3KIT_GRPNM_DATA16
419%else
420 %define TMPL_WRT_DATA16_OR_FLAT wrt FLAT
421%endif
422
423;; @def TMPL_DATA16_WRT
424; WRT DATA16 in 16-bit mode, WRT FLAT in 32- and 64-bit modes.
425; This is important when accessing global variables.
426;
427%if TMPL_BITS == 16
428 %define TMPL_DATA16_WRT(a_Var) a_Var wrt BS3KIT_GRPNM_DATA16
429%elif TMPL_BITS == 32
430 %define TMPL_DATA16_WRT(a_Var) a_Var wrt FLAT
431%elif TMPL_BITS == 64
432 %define TMPL_DATA16_WRT(a_Var) rel a_Var wrt FLAT
433%else
434 %error TMPL_BITS
435%endif
436
437;; @def TMPL_WRT_SYSTEM16_OR_FLAT
438; WRT BS3SYSTEM16 in 16-bit mode, WRT FLAT in 32- and 64-bit modes.
439; This is important when accessing global variables in the BS3SYSTEM16 segment.
440%ifdef TMPL_16BIT
441 %define TMPL_WRT_SYSTEM16_OR_FLAT wrt BS3SYSTEM16
442%else
443 %define TMPL_WRT_SYSTEM16_OR_FLAT wrt FLAT
444%endif
445
446;; @def TONLY16
447; Version of BONLY16 that follows the code template.
448; Like BONLY16 this normally goes in column 1.
449%if TMPL_BITS == 16
450 %macro TONLY16 1+
451 %1
452 %endmacro
453%else
454 %macro TONLY16 1+
455 %endmacro
456%endif
457
458;; @def TONLY32
459; Version of BONLY32 that follows the code template.
460; Like BONLY32 this normally goes in column 1.
461%if TMPL_BITS == 32
462 %macro TONLY32 1+
463 %1
464 %endmacro
465%else
466 %macro TONLY32 1+
467 %endmacro
468%endif
469
470;; @def TONLY64
471; Version of BONLY64 that follows the code template.
472; Like BONLY64 this normally goes in column 1.
473%if TMPL_BITS == 64
474 %macro TONLY64 1+
475 %1
476 %endmacro
477%else
478 %macro TONLY64 1+
479 %endmacro
480%endif
481
482;; @def TNOT16
483; Version of BNOT16 that follows the code template.
484; Like BNOT16 this normally goes in column 1.
485%if TMPL_BITS == 16
486 %macro TNOT16 1+
487 %endmacro
488%else
489 %macro TNOT16 1+
490 %1
491 %endmacro
492%endif
493
494;; @def TNOT32
495; Version of BNOT32 that follows the code template.
496; Like BNOT32 this normally goes in column 1.
497%if TMPL_BITS == 32
498 %macro TNOT32 1+
499 %endmacro
500%else
501 %macro TNOT32 1+
502 %1
503 %endmacro
504%endif
505
506;; @def TNOT64
507; Version of BNOT64 that follows the code template.
508; Like BNOT64 this normally goes in column 1.
509%if TMPL_BITS == 64
510 %macro TNOT64 1+
511 %endmacro
512%else
513 %macro TNOT64 1+
514 %1
515 %endmacro
516%endif
517
518
519;
520; Default code segment (changes BITS too).
521;
522%ifdef TMPL_64BIT
523 %define TMPL_BEGIN_TEXT BS3_BEGIN_TEXT64
524%elifdef TMPL_32BIT
525 %define TMPL_BEGIN_TEXT BS3_BEGIN_TEXT32
526%elifdef TMPL_16BIT
527 %define TMPL_BEGIN_TEXT BS3_BEGIN_TEXT16
528%else
529 %error "Missing TMPL_xxBIT!"
530%endif
531TMPL_BEGIN_TEXT
532
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