VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-header.h@ 60112

Last change on this file since 60112 was 59863, checked in by vboxsync, 9 years ago

bs3kit: Updates.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.4 KB
Line 
1/* $Id: bs3kit-template-header.h 59863 2016-02-26 20:59:52Z vboxsync $ */
2/** @file
3 * BS3Kit header for multi-mode code templates.
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.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#include "bs3kit.h"
28
29/** @defgroup grp_bs3kit_tmpl BS3Kit Multi-Mode Code Templates
30 * @ingroup grp_bs3kit
31 *
32 * Multi-mode code templates avoid duplicating code for each of the CPU modes.
33 * Instead the code is compiled multiple times, either via multiple inclusions
34 * into a source files with different mode selectors defined or by multiple
35 * compiler invocations.
36 *
37 * In C/C++ code we're restricted to the compiler target bit count, whereas in
38 * assembly we can do everything in assembler run (with some 64-bit
39 * restrictions, that is).
40 *
41 * Before \#defining the next mode selector and including
42 * bs3kit-template-header.h again, include bs3kit-template-footer.h to undefine
43 * all the previous mode selectors and the macros defined by the header.
44 *
45 * @{
46 */
47
48#ifdef DOXYGEN_RUNNING
49/** @name Template mode selectors.
50 *
51 * Exactly one of these are defined by the file including the
52 * bs3kit-template-header.h header file. When building the code libraries, the
53 * kBuild target defines this.
54 *
55 * @{ */
56# define TMPL_RM /**< real mode. */
57
58# define TMPL_PE16 /**< 16-bit protected mode kernel+tss, running 16-bit code, unpaged. */
59# define TMPL_PE16_32 /**< 16-bit protected mode kernel+tss, running 32-bit code, unpaged. */
60# define TMPL_PE16_V86 /**< 16-bit protected mode kernel+tss, running virtual 8086 mode code, unpaged. */
61# define TMPL_PE32 /**< 32-bit protected mode kernel+tss, running 32-bit code, unpaged. */
62# define TMPL_PE32_16 /**< 32-bit protected mode kernel+tss, running 16-bit code, unpaged. */
63# define TMPL_PEV86 /**< 32-bit protected mode kernel+tss, running virtual 8086 mode code, unpaged. */
64
65# define TMPL_PP16 /**< 16-bit protected mode kernel+tss, running 16-bit code, paged. */
66# define TMPL_PP16_32 /**< 16-bit protected mode kernel+tss, running 32-bit code, paged. */
67# define TMPL_PP16_V86 /**< 16-bit protected mode kernel+tss, running virtual 8086 mode code, paged. */
68# define TMPL_PP32 /**< 32-bit protected mode kernel+tss, running 32-bit code, paged. */
69# define TMPL_PP32_16 /**< 32-bit protected mode kernel+tss, running 16-bit code, paged. */
70# define TMPL_PPV86 /**< 32-bit protected mode kernel+tss, running virtual 8086 mode code, paged. */
71
72# define TMPL_PAE16 /**< 16-bit protected mode kernel+tss, running 16-bit code, PAE paging. */
73# define TMPL_PAE16_32 /**< 16-bit protected mode kernel+tss, running 32-bit code, PAE paging. */
74# define TMPL_PAE16_V86 /**< 16-bit protected mode kernel+tss, running virtual 8086 mode code, PAE paging. */
75# define TMPL_PAE32 /**< 32-bit protected mode kernel+tss, running 32-bit code, PAE paging. */
76# define TMPL_PAE32_16 /**< 32-bit protected mode kernel+tss, running 16-bit code, PAE paging. */
77# define TMPL_PAEV86 /**< 32-bit protected mode kernel+tss, running virtual 8086 mode code, PAE paging. */
78
79# define TMPL_LM16 /**< 16-bit long mode (paged), kernel+tss always 64-bit. */
80# define TMPL_LM32 /**< 32-bit long mode (paged), kernel+tss always 64-bit. */
81# define TMPL_LM64 /**< 64-bit long mode (paged), kernel+tss always 64-bit. */
82/** @} */
83
84/** @name Derived Indicators
85 * @{ */
86# define TMPL_CMN_PE /**< TMPL_PE16 | TMPL_PE16_32 | TMPL_PE16_V86 | TMPL_PE32 | TMPL_PE32_16 | TMPL_PEV86 */
87# define TMPL_SYS_PE16 /**< TMPL_PE16 | TMPL_PE16_32 | TMPL_PE16_V86 */
88# define TMPL_SYS_PE32 /**< TMPL_PE32 | TMPL_PE32_16 | TMPL_PEV86 */
89# define TMPL_CMN_PP /**< TMPL_PP16 | TMPL_PP16_32 | TMPL_PP16_V86 | TMPL_PP32 | TMPL_PP32_16 | TMPL_PPV86 */
90# define TMPL_SYS_PP16 /**< TMPL_PP16 | TMPL_PP16_32 | TMPL_PP16_V86 */
91# define TMPL_SYS_PP32 /**< TMPL_PP32 | TMPL_PP32_16 | TMPL_PPV86 */
92# define TMPL_CMN_PAE /**< TMPL_PAE16 | TMPL_PAE16_32 | TMPL_PAE16_V86 | TMPL_PAE32 | TMPL_PAE32_16 | TMPL_PAEV86 */
93# define TMPL_SYS_PAE16 /**< TMPL_PAE16 | TMPL_PAE16_32 | TMPL_PAE16_V86 */
94# define TMPL_SYS_PAE32 /**< TMPL_PAE32 | TMPL_PAE32_16 | TMPL_PAEV86 */
95# define TMPL_CMN_LM /**< TMPL_LM16 | TMPL_LM32 | TMPL_LM64 */
96# define TMPL_CMN_V86 /**< TMPL_PEV86 | TMPL_PE16_V86 | TMPL_PPV86 | TMPL_PP16_V86 | TMPL_PAEV86 | TMPL_PAE16_V86 */
97# define TMPL_CMN_R86 /**< TMPL_CMN_V86 | TMPL_RM */
98# define TMPL_CMN_PAGING /**< TMPL_CMN_PP | TMPL_CMN_PAE | TMPL_CMN_LM */
99# define TMPL_CMN_WEIRD /**< TMPL_PE16_32 | TMPL_PE32_16 | TMPL_PP16_32 | TMPL_PP32_16 | TMPL_PAE16_32 | TMPL_PAE32_16 | TMPL_CMN_WEIRD_V86 */
100# define TMPL_CMN_WEIRD_V86 /**< TMPL_PE16_V86 | TMPL_PP16_V86 | TMPL_PAE16_V86 */
101/** @} */
102
103/** @def TMPL_NM
104 * Name mangling macro for the current mode.
105 *
106 * Example: TMPL_NM(PrintChr)
107 *
108 * @param Name The function or variable name to mangle.
109 */
110# define TMPL_NM(Name) RT_CONCAT(Name,_mode)
111
112/** @def TMPL_MODE_STR
113 * Short mode description. */
114# define TMPL_MODE_STR
115
116/** @def TMPL_HAVE_BIOS
117 * Indicates that we have direct access to the BIOS (only in real mode). */
118# define TMPL_HAVE_BIOS
119
120
121/** @name For ASM compatability
122 * @{ */
123/** @def TMPL_16BIT
124 * For ASM compatibility - please use ARCH_BITS == 16. */
125# define TMPL_16BIT
126/** @def TMPL_32BIT
127 * For ASM compatibility - please use ARCH_BITS == 32. */
128# define TMPL_32BIT
129/** @def TMPL_64BIT
130 * For ASM compatibility - please use ARCH_BITS == 64. */
131# define TMPL_64BIT
132
133/** @def TMPL_BITS
134 * For ASM compatibility - please use ARCH_BITS instead. */
135# define TMPL_BITS ARCH_BITS
136/** @} */
137
138#else /* !DOXYGEN_RUNNING */
139
140#undef BS3_CMN_NM
141
142
143/*
144 * Convert TMPL_XXX to TMPL_MODE.
145 */
146#ifndef TMPL_MODE
147# ifdef TMPL_RM
148# define TMPL_MODE BS3_MODE_RM
149# elif defined(TMPL_PE16)
150# define TMPL_MODE BS3_MODE_PE16
151# elif defined(TMPL_PE16_32)
152# define TMPL_MODE BS3_MODE_PE16_32
153# elif defined(TMPL_PE16_V86)
154# define TMPL_MODE BS3_MODE_PE16_V86
155# elif defined(TMPL_PE32)
156# define TMPL_MODE BS3_MODE_PE32
157# elif defined(TMPL_PE32_16)
158# define TMPL_MODE BS3_MODE_PE32_16
159# elif defined(TMPL_PEV86)
160# define TMPL_MODE BS3_MODE_PEV86
161# elif defined(TMPL_PP16)
162# define TMPL_MODE BS3_MODE_PP16
163# elif defined(TMPL_PP16_32)
164# define TMPL_MODE BS3_MODE_PP16_32
165# elif defined(TMPL_PP16_V86)
166# define TMPL_MODE BS3_MODE_PP16_V86
167# elif defined(TMPL_PP32)
168# define TMPL_MODE BS3_MODE_PP32
169# elif defined(TMPL_PP32_16)
170# define TMPL_MODE BS3_MODE_PP32_16
171# elif defined(TMPL_PPV86)
172# define TMPL_MODE BS3_MODE_PPV86
173# elif defined(TMPL_PAE16)
174# define TMPL_MODE BS3_MODE_PAE16
175# elif defined(TMPL_PAE16_32)
176# define TMPL_MODE BS3_MODE_PAE16_32
177# elif defined(TMPL_PAE16_V86)
178# define TMPL_MODE BS3_MODE_PAE16_V86
179# elif defined(TMPL_PAE32)
180# define TMPL_MODE BS3_MODE_PAE32
181# elif defined(TMPL_PAE32_16)
182# define TMPL_MODE BS3_MODE_PAE32_16
183# elif defined(TMPL_PAEV86)
184# define TMPL_MODE BS3_MODE_PAEV86
185# elif defined(TMPL_LM16)
186# define TMPL_MODE BS3_MODE_LM16
187# elif defined(TMPL_LM32)
188# define TMPL_MODE BS3_MODE_LM32
189# elif defined(TMPL_LM64)
190# define TMPL_MODE BS3_MODE_LM64
191# else
192# error "Unable to to figure out the template mode."
193# endif
194#endif
195
196
197/*
198 * Check the code bitness and set derived defines.
199 */
200#if (TMPL_MODE & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_16
201# if ARCH_BITS != 16
202# error "BS3_MODE_CODE_16 requires ARCH_BITS to be 16."
203# endif
204# define TMPL_16BIT
205# define TMPL_BITS 16
206# define TMPL_UNDERSCORE _
207# define BS3_CMN_NM(Name) RT_CONCAT(Name,_c16)
208
209#elif (TMPL_MODE & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_32
210# if ARCH_BITS != 32
211# error "BS3_MODE_CODE_32 requires ARCH_BITS to be 32."
212# endif
213# define TMPL_32BIT
214# define TMPL_BITS 32
215# define TMPL_UNDERSCORE _
216# define BS3_CMN_NM(Name) RT_CONCAT(Name,_c32)
217
218#elif (TMPL_MODE & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_V86
219# if ARCH_BITS != 16
220# error "BS3_MODE_CODE_V86 requires ARCH_BITS to be 16."
221# endif
222# define TMPL_16BIT
223# define TMPL_BITS 16
224# define TMPL_UNDERSCORE _
225# define BS3_CMN_NM(Name) RT_CONCAT(Name,_c16)
226# define TMPL_CMN_R86
227# define TMPL_CMN_V86
228
229#elif (TMPL_MODE & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_64
230# if ARCH_BITS != 64
231# error "BS3_MODE_CODE_64 requires ARCH_BITS to be 64."
232# endif
233# define TMPL_64BIT
234# define TMPL_BITS 64
235# define TMPL_UNDERSCORE
236# define BS3_CMN_NM(Name) RT_CONCAT(Name,_c64)
237
238#else
239# error "Invalid TMPL_MODE value!"
240#endif
241
242
243/*
244 * Check the system specific mask and set derived values.
245 */
246#if (TMPL_MODE & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_RM
247# define TMPL_HAVE_BIOS
248# define TMPL_CMN_R86
249
250#elif (TMPL_MODE & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PE16
251# define TMPL_SYS_PE16
252# define TMPL_CMN_PE
253
254#elif (TMPL_MODE & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PE32
255# define TMPL_SYS_PE32
256# define TMPL_CMN_PE
257
258#elif (TMPL_MODE & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PP16
259# define TMPL_SYS_PP16
260# define TMPL_CMN_PP
261# define TMPL_CMN_PAGING
262
263#elif (TMPL_MODE & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PP32
264# define TMPL_SYS_PP32
265# define TMPL_CMN_PP
266# define TMPL_CMN_PAGING
267
268#elif (TMPL_MODE & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PAE16
269# define TMPL_SYS_PAE16
270# define TMPL_CMN_PAE
271# define TMPL_CMN_PAGING
272
273#elif (TMPL_MODE & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PAE32
274# define TMPL_SYS_PAE32
275# define TMPL_CMN_PAE
276# define TMPL_CMN_PAGING
277
278#elif (TMPL_MODE & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_LM
279# define TMPL_SYS_LM
280# define TMPL_CMN_LM
281# define TMPL_CMN_PAGING
282
283#else
284# error "Invalid TMPL_MODE value!"
285#endif
286
287
288/*
289 * Mode specific stuff.
290 */
291#if TMPL_MODE == BS3_MODE_RM
292# define TMPL_RM 1
293# define TMPL_MODE_STR "real mode"
294# define TMPL_NM(Name) RT_CONCAT(Name,_rm)
295# define TMPL_MODE_LNAME rm
296# define TMPL_MODE_UNAME RM
297
298
299#elif TMPL_MODE == BS3_MODE_PE16
300# define TMPL_PE16 1
301# define TMPL_MODE_STR "16-bit prot, 16-bit"
302# define TMPL_NM(Name) RT_CONCAT(Name,_pe16)
303# define TMPL_MODE_LNAME pe16
304# define TMPL_MODE_UNAME PE16
305
306#elif TMPL_MODE == BS3_MODE_PE16_32
307# define TMPL_PE16_32 1
308# define TMPL_MODE_STR "16-bit prot, 32-bit"
309# define TMPL_NM(Name) RT_CONCAT(Name,_pe16_32)
310# define TMPL_MODE_LNAME pe16_32
311# define TMPL_MODE_UNAME PE16_32
312# define TMPL_CMN_WEIRD
313
314#elif TMPL_MODE == BS3_MODE_PE16_V86
315# define TMPL_PE16_V86 1
316# define TMPL_MODE_STR "16-bit prot, v8086"
317# define TMPL_NM(Name) RT_CONCAT(Name,_pe16_v86)
318# define TMPL_MODE_LNAME pe16_v86
319# define TMPL_MODE_UNAME PE16_v86
320# define TMPL_CMN_WEIRD
321# define TMPL_CMN_WEIRD_V86
322
323
324#elif TMPL_MODE == BS3_MODE_PE32
325# define TMPL_PE32 1
326# define TMPL_MODE_STR "32-bit prot, 32-bit"
327# define TMPL_NM(Name) RT_CONCAT(Name,_pe32)
328# define TMPL_MODE_LNAME pe32
329# define TMPL_MODE_UNAME PE32
330
331#elif TMPL_MODE == BS3_MODE_PE32_16
332# define TMPL_PE32_16 1
333# define TMPL_MODE_STR "32-bit prot, 16-bit"
334# define TMPL_NM(Name) RT_CONCAT(Name,_pe32_16)
335# define TMPL_MODE_LNAME pe32_16
336# define TMPL_MODE_UNAME PE32_16
337# define TMPL_CMN_WEIRD
338
339#elif TMPL_MODE == BS3_MODE_PEV86
340# define TMPL_PEV86 1
341# define TMPL_MODE_STR "32-bit prot, v8086"
342# define TMPL_NM(Name) RT_CONCAT(Name,_pev86)
343# define TMPL_MODE_LNAME pev86
344# define TMPL_MODE_UNAME PEV86
345
346
347#elif TMPL_MODE == BS3_MODE_PP16
348# define TMPL_PP16 1
349# define TMPL_MODE_STR "16-bit paged, 16-bit"
350# define TMPL_NM(Name) RT_CONCAT(Name,_pp16)
351# define TMPL_MODE_LNAME pp16
352# define TMPL_MODE_UNAME PP16
353
354#elif TMPL_MODE == BS3_MODE_PP16_32
355# define TMPL_PP16_32 1
356# define TMPL_MODE_STR "16-bit paged, 32-bit"
357# define TMPL_NM(Name) RT_CONCAT(Name,_pp16_32)
358# define TMPL_MODE_LNAME pp16_32
359# define TMPL_MODE_UNAME PP16_32
360# define TMPL_CMN_WEIRD
361
362#elif TMPL_MODE == BS3_MODE_PP16_V86
363# define TMPL_PP16_V86 1
364# define TMPL_MODE_STR "16-bit paged, v8086"
365# define TMPL_NM(Name) RT_CONCAT(Name,_pp16_v86)
366# define TMPL_MODE_LNAME pp16_v86
367# define TMPL_MODE_UNAME PP16_v86
368# define TMPL_CMN_WEIRD
369# define TMPL_CMN_WEIRD_V86
370
371
372#elif TMPL_MODE == BS3_MODE_PP32
373# define TMPL_PP32 1
374# define TMPL_MODE_STR "32-bit paged, 32-bit"
375# define TMPL_NM(Name) RT_CONCAT(Name,_pp32)
376# define TMPL_MODE_LNAME pp32
377# define TMPL_MODE_UNAME PP32
378
379#elif TMPL_MODE == BS3_MODE_PP32_16
380# define TMPL_PP32_16 1
381# define TMPL_MODE_STR "32-bit paged, 16-bit"
382# define TMPL_NM(Name) RT_CONCAT(Name,_pp32_16)
383# define TMPL_MODE_LNAME pp32_16
384# define TMPL_MODE_UNAME PP32_16
385# define TMPL_CMN_WEIRD
386
387#elif TMPL_MODE == BS3_MODE_PPV86
388# define TMPL_PPV86 1
389# define TMPL_MODE_STR "32-bit paged, v8086"
390# define TMPL_NM(Name) RT_CONCAT(Name,_ppv86)
391# define TMPL_MODE_LNAME ppv86
392# define TMPL_MODE_UNAME PPV86
393
394
395#elif TMPL_MODE == BS3_MODE_PAE16
396# define TMPL_PAE16 1
397# define TMPL_MODE_STR "16-bit pae, 16-bit"
398# define TMPL_NM(Name) RT_CONCAT(Name,_pae16)
399# define TMPL_MODE_LNAME pae16
400# define TMPL_MODE_UNAME PAE16
401
402#elif TMPL_MODE == BS3_MODE_PAE16_32
403# define TMPL_PAE16_32 1
404# define TMPL_MODE_STR "16-bit pae, 32-bit"
405# define TMPL_NM(Name) RT_CONCAT(Name,_pae16_32)
406# define TMPL_MODE_LNAME pae16_32
407# define TMPL_MODE_UNAME PAE16_32
408# define TMPL_CMN_WEIRD
409
410#elif TMPL_MODE == BS3_MODE_PAE16_V86
411# define TMPL_PAE16_V86 1
412# define TMPL_MODE_STR "16-bit pae, v8086"
413# define TMPL_NM(Name) RT_CONCAT(Name,_pae16_v86)
414# define TMPL_MODE_LNAME pae16_v86
415# define TMPL_MODE_UNAME PAE16_v86
416# define TMPL_CMN_WEIRD
417# define TMPL_CMN_WEIRD_V86
418
419
420#elif TMPL_MODE == BS3_MODE_PAE32
421# define TMPL_PAE32 1
422# define TMPL_MODE_STR "32-bit pae, 32-bit"
423# define TMPL_NM(Name) RT_CONCAT(Name,_pae32)
424# define TMPL_MODE_LNAME pae32
425# define TMPL_MODE_UNAME PAE32
426
427#elif TMPL_MODE == BS3_MODE_PAE32_16
428# define TMPL_PAE32_16 1
429# define TMPL_MODE_STR "32-bit pae, 32-bit"
430# define TMPL_NM(Name) RT_CONCAT(Name,_pae32_16)
431# define TMPL_MODE_LNAME pae32_16
432# define TMPL_MODE_UNAME PAE32_16
433# define TMPL_CMN_WEIRD
434
435#elif TMPL_MODE == BS3_MODE_PAEV86
436# define TMPL_PAEV86 1
437# define TMPL_MODE_STR "32-bit pae, v8086 pae"
438# define TMPL_NM(Name) RT_CONCAT(Name,_paev86)
439# define TMPL_MODE_LNAME paev86
440# define TMPL_MODE_UNAME PAEV86
441
442
443#elif TMPL_MODE == BS3_MODE_LM16
444# define TMPL_LM16 1
445# define TMPL_MODE_STR "long, 16-bit"
446# define TMPL_NM(Name) RT_CONCAT(Name,_lm16)
447# define TMPL_MODE_LNAME lm16
448# define TMPL_MODE_UNAME LM16
449
450#elif TMPL_MODE == BS3_MODE_LM32
451# define TMPL_LM32 1
452# define TMPL_MODE_STR "long, 32-bit"
453# define TMPL_NM(Name) RT_CONCAT(Name,_lm32)
454# define TMPL_MODE_LNAME lm32
455# define TMPL_MODE_UNAME LM32
456
457#elif TMPL_MODE == BS3_MODE_LM64
458# define TMPL_LM64 1
459# define TMPL_MODE_STR "long, 64-bit"
460# define TMPL_NM(Name) RT_CONCAT(Name,_lm64)
461# define TMPL_MODE_LNAME lm64
462# define TMPL_MODE_UNAME LM64
463
464#else
465# error "Invalid TMPL_MODE value!!"
466#endif
467
468
469#ifndef TMPL_MODE_STR
470# error "internal error"
471#endif
472
473#endif /* !DOXYGEN_RUNNING */
474/** @} */
475
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