VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h@ 58675

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

bs3kit: Converted a bit more stuff and decided to got with syscalls for screen output, at least for now.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 KB
Line 
1/* $Id: bs3kit.h 58675 2015-11-12 15:47:57Z vboxsync $ */
2/** @file
3 * BS3Kit - structures, symbols, macros and stuff.
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#ifndef ___bs3kit_h
28#define ___bs3kit_h
29
30#ifndef DOXYGEN_RUNNING
31# define IN_RING0
32#endif
33#include <iprt/cdefs.h>
34#include <iprt/types.h>
35#ifndef DOXYGEN_RUNNING
36# undef IN_RING0
37#endif
38
39
40/** @defgroup grp_bs3kit BS3Kit
41 * @{ */
42
43/** @def BS3_FAR
44 * For inidicating far pointers in 16-bit code.
45 * Does nothing in 32-bit and 64-bit code. */
46/** @def BS3_NEAR
47 * For inidicating near pointers in 16-bit code.
48 * Does nothing in 32-bit and 64-bit code. */
49#ifdef M_I86
50# define BS3_FAR __far
51# define BS3_NEAR __near
52#else
53# define BS3_FAR
54# define BS3_NEAR
55#endif
56
57/** @def BS3_CALL
58 * The calling convension used by BS3 functions. */
59#if ARCH_BITS != 64
60# define BS3_CALL __cdecl
61#elif !defined(_MSC_VER)
62# define BS3_CALL __attribute__((__ms_abi__))
63#else
64# define BS3_CALL
65#endif
66
67/** @def IN_BS3KIT
68 * Indicates that we're in the same link job as the BS3Kit code. */
69#ifdef DOXYGEN_RUNNING
70# define IN_BS3KIT
71#endif
72
73/** @def BS3_DECL
74 * Declares a BS3Kit function.
75 * @param a_Type The return type. */
76#ifdef IN_BS3KIT
77# define BS3_DECL(a_Type) DECLEXPORT(a_Type) BS3_CALL
78#else
79# define BS3_DECL(a_Type) DECLIMPORT(a_Type) BS3_CALL
80#endif
81
82/**
83 * Constructs a common name.
84 *
85 * Example: BS3_CMN_NM(Bs3Shutdown)
86 *
87 * @param a_Name The name of the function or global variable.
88 */
89#define BS3_CMN_NM(a_Name) RT_CONCAT3(a_Name,_c,ARCH_BITS)
90
91/**
92 * Template for createing a pointer union type.
93 * @param a_BaseName The base type name.
94 * @param a_Modifier The type modifier.
95 */
96#define BS3_PTR_UNION_TEMPLATE(a_BaseName, a_Modifiers) \
97 typedef union a_BaseName \
98 { \
99 /** Pointer into the void. */ \
100 a_Modifiers void BS3_FAR *pv; \
101 /** As a signed integer. */ \
102 intptr_t i; \
103 /** As an unsigned integer. */ \
104 uintptr_t u; \
105 /** Pointer to char value. */ \
106 a_Modifiers char BS3_FAR *pch; \
107 /** Pointer to char value. */ \
108 a_Modifiers unsigned char BS3_FAR *puch; \
109 /** Pointer to a int value. */ \
110 a_Modifiers int BS3_FAR *pi; \
111 /** Pointer to a unsigned int value. */ \
112 a_Modifiers unsigned int BS3_FAR *pu; \
113 /** Pointer to a long value. */ \
114 a_Modifiers long BS3_FAR *pl; \
115 /** Pointer to a long value. */ \
116 a_Modifiers unsigned long BS3_FAR *pul; \
117 /** Pointer to a memory size value. */ \
118 a_Modifiers size_t BS3_FAR *pcb; \
119 /** Pointer to a byte value. */ \
120 a_Modifiers uint8_t BS3_FAR *pb; \
121 /** Pointer to a 8-bit unsigned value. */ \
122 a_Modifiers uint8_t BS3_FAR *pu8; \
123 /** Pointer to a 16-bit unsigned value. */ \
124 a_Modifiers uint16_t BS3_FAR *pu16; \
125 /** Pointer to a 32-bit unsigned value. */ \
126 a_Modifiers uint32_t BS3_FAR *pu32; \
127 /** Pointer to a 64-bit unsigned value. */ \
128 a_Modifiers uint64_t BS3_FAR *pu64; \
129 /** Pointer to a UTF-16 character. */ \
130 a_Modifiers RTUTF16 BS3_FAR *pwc; \
131 /** Pointer to a UUID character. */ \
132 a_Modifiers RTUUID BS3_FAR *pUuid; \
133 } a_BaseName; \
134 /** Pointer to a pointer union. */ \
135 typedef a_BaseName *RT_CONCAT(P,a_BaseName)
136BS3_PTR_UNION_TEMPLATE(BS3PTRUNION, RT_NOTHING);
137BS3_PTR_UNION_TEMPLATE(BS3CPTRUNION, const);
138BS3_PTR_UNION_TEMPLATE(BS3VPTRUNION, volatile);
139BS3_PTR_UNION_TEMPLATE(BS3CVPTRUNION, const volatile);
140
141
142/** @defgroup grp_bs3kit_cmn Common Functions and Data
143 *
144 * The common functions comes in three variations: 16-bit, 32-bit and 64-bit.
145 * Templated code uses the #BS3_CMN_NM macro to mangle the name according to the
146 * desired
147 *
148 * @{
149 */
150
151/**
152 * Panic, never return.
153 *
154 * The current implementation will only halt the CPU.
155 */
156BS3_DECL(void) Bs3Panic_c16(void);
157BS3_DECL(void) Bs3Panic_c32(void); /**< @copydoc Bs3Panic_c16 */
158BS3_DECL(void) Bs3Panic_c64(void); /**< @copydoc Bs3Panic_c16 */
159#define Bs3Panic BS3_CMN_NM(Bs3Panic) /**< Selects #Bs3Panic_c16, #Bs3Panic_c32 or #Bs3Panic_c64. */
160
161/**
162 * Shutdown the system, never returns.
163 *
164 * This currently only works for VMs. When running on real systems it will
165 * just halt the CPU.
166 */
167BS3_DECL(void) Bs3Shutdown_c16(void);
168BS3_DECL(void) Bs3Shutdown_c32(void); /**< @copydoc Bs3Shutdown_c16 */
169BS3_DECL(void) Bs3Shutdown_c64(void); /**< @copydoc Bs3Shutdown_c16 */
170#define Bs3Shutdown BS3_CMN_NM(Bs3Shutdown) /**< Selects #Bs3Shutdown_c16, #Bs3Shutdown_c32 or #Bs3Shutdown_c64. */
171
172/**
173 * Prints a 32-bit unsigned value as hex to the screen.
174 *
175 * @param uValue The 32-bit value.
176 */
177BS3_DECL(void) Bs3PrintU32_c16(uint32_t uValue);
178BS3_DECL(void) Bs3PrintU32_c32(uint32_t uValue); /**< @copydoc Bs3PrintU32_c16 */
179BS3_DECL(void) Bs3PrintU32_c64(uint32_t uValue); /**< @copydoc Bs3PrintU32_c16 */
180#define Bs3PrintU32 BS3_CMN_NM(Bs3PrintU32) /**< Selects #Bs3PrintU32_c16, #Bs3PrintU32_c32 or #Bs3PrintU32_c64. */
181
182/**
183 * Prints a string to the screen.
184 *
185 * @param pszString The string to print.
186 */
187BS3_DECL(void) Bs3PrintStr_c16(const char BS3_FAR *pszString);
188BS3_DECL(void) Bs3PrintStr_c32(const char BS3_FAR *pszString); /**< @copydoc Bs3PrintStr_c16 */
189BS3_DECL(void) Bs3PrintStr_c64(const char BS3_FAR *pszString); /**< @copydoc Bs3PrintStr_c16 */
190#define Bs3PrintStr BS3_CMN_NM(Bs3PrintStr) /**< Selects #Bs3PrintStr_c16, #Bs3PrintStr_c32 or #Bs3PrintStr_c64. */
191
192/**
193 * Prints a char to the screen.
194 *
195 * @param ch The character to print.
196 */
197BS3_DECL(void) Bs3PrintChr_c16(char ch);
198BS3_DECL(void) Bs3PrintChr_c32(char ch); /**< @copydoc Bs3PrintChr_c16 */
199BS3_DECL(void) Bs3PrintChr_c64(char ch); /**< @copydoc Bs3PrintChr_c16 */
200#define Bs3PrintChr BS3_CMN_NM(Bs3PrintChr) /**< Selects #Bs3PrintChr_c16, #Bs3PrintChr_c32 or #Bs3PrintChr_c64. */
201
202
203/**
204 * Finds the length of a zero terminated string.
205 *
206 * @returns String length in chars/bytes.
207 * @param pszString The string to examine.
208 */
209BS3_DECL(size_t) Bs3StrLen_c16(const char BS3_FAR *pszString);
210BS3_DECL(size_t) Bs3StrLen_c32(const char BS3_FAR *pszString); /** @copydoc Bs3StrLen_c16 */
211BS3_DECL(size_t) Bs3StrLen_c64(const char BS3_FAR *pszString); /** @copydoc Bs3StrLen_c16 */
212#define Bs3StrLen BS3_CMN_NM(Bs3StrLen) /**< Selects #Bs3StrLen_c16, #Bs3StrLen_c32 or #Bs3StrLen_c64. */
213
214/**
215 * Finds the length of a zero terminated string, but with a max length.
216 *
217 * @returns String length in chars/bytes, or @a cchMax if no zero-terminator
218 * was found before we reached the limit.
219 * @param pszString The string to examine.
220 * @param cchMax The max length to examine.
221 */
222BS3_DECL(size_t) Bs3StrNLen_c16(const char BS3_FAR *pszString, size_t cchMax);
223BS3_DECL(size_t) Bs3StrNLen_c32(const char BS3_FAR *pszString, size_t cchMax); /** @copydoc Bs3StrNLen_c16 */
224BS3_DECL(size_t) Bs3StrNLen_c64(const char BS3_FAR *pszString, size_t cchMax); /** @copydoc Bs3StrNLen_c16 */
225#define Bs3StrNLen BS3_CMN_NM(Bs3StrNLen) /**< Selects #Bs3StrNLen_c16, #Bs3StrNLen_c32 or #Bs3StrNLen_c64. */
226
227/**
228 * CRT style unsafe strcpy.
229 *
230 * @returns pszDst.
231 * @param pszDst The destination buffer. Must be large enough to
232 * hold the source string.
233 * @param pszSrc The source string.
234 */
235BS3_DECL(char BS3_FAR *) Bs3StrCpy_c16(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc);
236BS3_DECL(char BS3_FAR *) Bs3StrCpy_c32(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc); /** @copydoc Bs3StrCpy_c16 */
237BS3_DECL(char BS3_FAR *) Bs3StrCpy_c64(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc); /** @copydoc Bs3StrCpy_c16 */
238#define Bs3StrCpy BS3_CMN_NM(Bs3StrCpy) /**< Selects #Bs3StrCpy_c16, #Bs3StrCpy_c32 or #Bs3StrCpy_c64. */
239
240/**
241 * CRT style memcpy.
242 *
243 * @returns pvDst
244 * @param pvDst The destination buffer.
245 * @param pvSrc The source buffer.
246 * @param cbCopy The number of bytes to copy.
247 */
248BS3_DECL(void BS3_FAR *) Bs3MemCpy_c16(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy);
249BS3_DECL(void BS3_FAR *) Bs3MemCpy_c32(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemCpy_c16 */
250BS3_DECL(void BS3_FAR *) Bs3MemCpy_c64(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemCpy_c16 */
251#define Bs3MemCpy BS3_CMN_NM(Bs3MemCpy) /**< Selects #Bs3MemCpy_c16, #Bs3MemCpy_c32 or #Bs3MemCpy_c64. */
252
253/**
254 * GNU (?) style mempcpy.
255 *
256 * @returns pvDst + cbCopy
257 * @param pvDst The destination buffer.
258 * @param pvSrc The source buffer.
259 * @param cbCopy The number of bytes to copy.
260 */
261BS3_DECL(void BS3_FAR *) Bs3MemPCpy_c16(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy);
262BS3_DECL(void BS3_FAR *) Bs3MemPCpy_c32(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemPCpy_c16 */
263BS3_DECL(void BS3_FAR *) Bs3MemPCpy_c64(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemPCpy_c16 */
264#define Bs3MemPCpy BS3_CMN_NM(Bs3MemPCpy) /**< Selects #Bs3MemPCpy_c16, #Bs3MemPCpy_c32 or #Bs3MemPCpy_c64. */
265
266/**
267 * CRT style memmove (overlapping buffers is fine).
268 *
269 * @returns pvDst
270 * @param pvDst The destination buffer.
271 * @param pvSrc The source buffer.
272 * @param cbCopy The number of bytes to copy.
273 */
274BS3_DECL(void BS3_FAR *) Bs3MemMove_c16(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy);
275BS3_DECL(void BS3_FAR *) Bs3MemMove_c32(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemMove_c16 */
276BS3_DECL(void BS3_FAR *) Bs3MemMove_c64(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemMove_c16 */
277#define Bs3MemMove BS3_CMN_NM(Bs3MemMove) /**< Selects #Bs3MemMove_c16, #Bs3MemMove_c32 or #Bs3MemMove_c64. */
278
279
280
281/**
282 * Equivalent to RTTestCreate + RTTestBanner.
283 *
284 * @param pszTest The test name.
285 */
286BS3_DECL(void) Bs3TestInit_c16(const char BS3_FAR *pszTest);
287BS3_DECL(void) Bs3TestInit_c32(const char BS3_FAR *pszTest); /**< @copydoc Bs3TestInit_c16 */
288BS3_DECL(void) Bs3TestInit_c64(const char BS3_FAR *pszTest); /**< @copydoc Bs3TestInit_c16 */
289#define Bs3TestInit BS3_CMN_NM(Bs3TestInit) /**< Selects #Bs3TestInit_c16, #Bs3TestInit_c32 or #Bs3TestInit_c64. */
290
291
292/** @} */
293
294
295
296/** @defgroup grp_bs3kit_mode Mode Specific Functions and Data
297 *
298 * The mode specific functions come in bit count variations and CPU mode
299 * variations. The bs3kit-template-header.h/mac defines the BS3_NM macro to
300 * mangle a function or variable name according to the target CPU mode. In
301 * non-templated code, it's common to spell the name out in full.
302 *
303 * @{
304 */
305
306
307/** @} */
308
309#endif
310
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