VirtualBox

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

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

Bs3MemMove

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.5 KB
Line 
1/* $Id: bs3kit.h 58667 2015-11-12 00:22:18Z 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); /**< @copydoc Bs3PrintU32_c16 */
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 * Finds the length of a zero terminated string.
184 *
185 * @returns String length in chars/bytes.
186 * @param pszString The string to examine.
187 */
188BS3_DECL(size_t) Bs3StrLen_c16(const char BS3_FAR *pszString);
189BS3_DECL(size_t) Bs3StrLen_c32(const char BS3_FAR *pszString); /** @copydoc Bs3StrLen_c16 */
190BS3_DECL(size_t) Bs3StrLen_c64(const char BS3_FAR *pszString); /** @copydoc Bs3StrLen_c16 */
191#define Bs3StrLen BS3_CMN_NM(Bs3StrLen) /**< Selects #Bs3StrLen_c16, #Bs3StrLen_c32 or #Bs3StrLen_c64. */
192
193/**
194 * Finds the length of a zero terminated string, but with a max length.
195 *
196 * @returns String length in chars/bytes, or @a cchMax if no zero-terminator
197 * was found before we reached the limit.
198 * @param pszString The string to examine.
199 * @param cchMax The max length to examine.
200 */
201BS3_DECL(size_t) Bs3StrNLen_c16(const char BS3_FAR *pszString, size_t cchMax);
202BS3_DECL(size_t) Bs3StrNLen_c32(const char BS3_FAR *pszString, size_t cchMax); /** @copydoc Bs3StrNLen_c16 */
203BS3_DECL(size_t) Bs3StrNLen_c64(const char BS3_FAR *pszString, size_t cchMax); /** @copydoc Bs3StrNLen_c16 */
204#define Bs3StrNLen BS3_CMN_NM(Bs3StrNLen) /**< Selects #Bs3StrNLen_c16, #Bs3StrNLen_c32 or #Bs3StrNLen_c64. */
205
206/**
207 * CRT style unsafe strcpy.
208 *
209 * @returns pszDst.
210 * @param pszDst The destination buffer. Must be large enough to
211 * hold the source string.
212 * @param pszSrc The source string.
213 */
214BS3_DECL(char BS3_FAR *) Bs3StrCpy_c16(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc);
215BS3_DECL(char BS3_FAR *) Bs3StrCpy_c32(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc); /** @copydoc Bs3StrCpy_c16 */
216BS3_DECL(char BS3_FAR *) Bs3StrCpy_c64(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc); /** @copydoc Bs3StrCpy_c16 */
217#define Bs3StrCpy BS3_CMN_NM(Bs3StrCpy) /**< Selects #Bs3StrCpy_c16, #Bs3StrCpy_c32 or #Bs3StrCpy_c64. */
218
219/**
220 * CRT style memcpy.
221 *
222 * @returns pvDst
223 * @param pvDst The destination buffer.
224 * @param pvSrc The source buffer.
225 * @param cbCopy The number of bytes to copy.
226 */
227BS3_DECL(void BS3_FAR *) Bs3MemCpy_c16(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy);
228BS3_DECL(void BS3_FAR *) Bs3MemCpy_c32(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemCpy_c16 */
229BS3_DECL(void BS3_FAR *) Bs3MemCpy_c64(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemCpy_c16 */
230#define Bs3MemCpy BS3_CMN_NM(Bs3MemCpy) /**< Selects #Bs3MemCpy_c16, #Bs3MemCpy_c32 or #Bs3MemCpy_c64. */
231
232/**
233 * GNU (?) style mempcpy.
234 *
235 * @returns pvDst + cbCopy
236 * @param pvDst The destination buffer.
237 * @param pvSrc The source buffer.
238 * @param cbCopy The number of bytes to copy.
239 */
240BS3_DECL(void BS3_FAR *) Bs3MemPCpy_c16(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy);
241BS3_DECL(void BS3_FAR *) Bs3MemPCpy_c32(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemPCpy_c16 */
242BS3_DECL(void BS3_FAR *) Bs3MemPCpy_c64(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemPCpy_c16 */
243#define Bs3MemPCpy BS3_CMN_NM(Bs3MemPCpy) /**< Selects #Bs3MemPCpy_c16, #Bs3MemPCpy_c32 or #Bs3MemPCpy_c64. */
244
245/**
246 * CRT style memmove (overlapping buffers is fine).
247 *
248 * @returns pvDst
249 * @param pvDst The destination buffer.
250 * @param pvSrc The source buffer.
251 * @param cbCopy The number of bytes to copy.
252 */
253BS3_DECL(void BS3_FAR *) Bs3MemMove_c16(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy);
254BS3_DECL(void BS3_FAR *) Bs3MemMove_c32(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemMove_c16 */
255BS3_DECL(void BS3_FAR *) Bs3MemMove_c64(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemMove_c16 */
256#define Bs3MemMove BS3_CMN_NM(Bs3MemMove) /**< Selects #Bs3MemMove_c16, #Bs3MemMove_c32 or #Bs3MemMove_c64. */
257
258
259/** @} */
260
261
262
263/** @defgroup grp_bs3kit_mode Mode Specific Functions and Data
264 *
265 * The mode specific functions come in bit count variations and CPU mode
266 * variations. The bs3kit-template-header.h/mac defines the BS3_NM macro to
267 * mangle a function or variable name according to the target CPU mode. In
268 * non-templated code, it's common to spell the name out in full.
269 *
270 * @{
271 */
272
273
274/** @} */
275
276#endif
277
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