VirtualBox

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

最後變更 在這個檔案從97575是 97430,由 vboxsync 提交於 2 年 前

ValKit/bs3kit: Added Bs3SelLnkPtrToFlat. bugref:9898

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 179.9 KB
 
1/* $Id: bs3kit.h 97430 2022-11-07 13:51:44Z vboxsync $ */
2/** @file
3 * BS3Kit - structures, symbols, macros and stuff.
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.alldomusa.eu.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#ifndef BS3KIT_INCLUDED_bs3kit_h
38#define BS3KIT_INCLUDED_bs3kit_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43#ifndef DOXYGEN_RUNNING
44# undef IN_RING0
45# define IN_RING0
46#endif
47
48#define RT_NO_STRICT /* Don't drag in IPRT assertion code in inline code we may use (asm.h). */
49#include <iprt/cdefs.h>
50#include <iprt/types.h>
51
52#ifndef DOXYGEN_RUNNING
53# undef IN_RING0
54#endif
55
56/*
57 * Make asm.h and friend compatible with our 64-bit assembly config (ASM_CALL64_MSC).
58 */
59#if defined(__GNUC__) && ARCH_BITS == 64
60# undef DECLASM
61# ifdef __cplusplus
62# define DECLASM(type) extern "C" type BS3_CALL
63# else
64# define DECLASM(type) type BS3_CALL
65# endif
66#endif
67
68
69/*
70 * Work around ms_abi trouble in the gcc camp (gcc bugzilla #50818).
71 * ASSUMES all va_lists are in functions with
72 */
73#if defined(__GNUC__) && ARCH_BITS == 64
74# undef va_list
75# undef va_start
76# undef va_end
77# undef va_copy
78# define va_list __builtin_ms_va_list
79# define va_start(a_Va, a_Arg) __builtin_ms_va_start(a_Va, a_Arg)
80# define va_end(a_Va) __builtin_ms_va_end(a_Va)
81# define va_copy(a_DstVa, a_SrcVa) __builtin_ms_va_copy(a_DstVa, a_SrcVa)
82#endif
83
84
85/** @def BS3_USE_ALT_16BIT_TEXT_SEG
86 * @ingroup grp_bs3kit
87 * Combines the BS3_USE_RM_TEXT_SEG, BS3_USE_X0_TEXT_SEG, and
88 * BS3_USE_X1_TEXT_SEG indicators into a single one.
89 */
90#if defined(BS3_USE_RM_TEXT_SEG) || defined(BS3_USE_X0_TEXT_SEG) || defined(BS3_USE_X1_TEXT_SEG) || defined(DOXYGEN_RUNNING)
91# define BS3_USE_ALT_16BIT_TEXT_SEG
92#else
93# undef BS3_USE_ALT_16BIT_TEXT_SEG
94#endif
95
96/** @def BS3_USE_X0_TEXT_SEG
97 * @ingroup grp_bs3kit
98 * Emit 16-bit code to the BS3X0TEXT16 segment - ignored for 32-bit and 64-bit.
99 *
100 * Calling directly into the BS3X0TEXT16 segment is only possible in real-mode
101 * and v8086 mode. In protected mode the real far pointer have to be converted
102 * to a protected mode pointer that uses BS3_SEL_X0TEXT16_CS, Bs3TestDoModes and
103 * associates does this automatically.
104 */
105#ifdef DOXYGEN_RUNNING
106# define BS3_USE_X0_TEXT_SEG
107#endif
108
109/** @def BS3_USE_X1_TEXT_SEG
110 * @ingroup grp_bs3kit
111 * Emit 16-bit code to the BS3X1TEXT16 segment - ignored for 32-bit and 64-bit.
112 *
113 * Calling directly into the BS3X1TEXT16 segment is only possible in real-mode
114 * and v8086 mode. In protected mode the real far pointer have to be converted
115 * to a protected mode pointer that uses BS3_SEL_X1TEXT16_CS, Bs3TestDoModes and
116 * associates does this automatically.
117 */
118#ifdef DOXYGEN_RUNNING
119# define BS3_USE_X1_TEXT_SEG
120#endif
121
122/** @def BS3_USE_RM_TEXT_SEG
123 * @ingroup grp_bs3kit
124 * Emit 16-bit code to the BS3RMTEXT16 segment - ignored for 32-bit and 64-bit.
125 *
126 * This segment is normally used for real-mode only code, though
127 * BS3_SEL_RMTEXT16_CS can be used to call it from protected mode. Unlike the
128 * BS3X0TEXT16 and BS3X1TEXT16 segments which are empty by default, this segment
129 * is used by common BS3Kit code.
130 */
131#ifdef DOXYGEN_RUNNING
132# define BS3_USE_X0_TEXT_SEG
133#endif
134
135/** @def BS3_MODEL_FAR_CODE
136 * @ingroup grp_bs3kit
137 * Default compiler model indicates far code.
138 */
139#ifdef DOXYGEN_RUNNING
140# define BS3_MODEL_FAR_CODE
141#elif !defined(BS3_MODEL_FAR_CODE) && (defined(__LARGE__) || defined(__MEDIUM__) || defined(__HUGE__)) && ARCH_BITS == 16
142# define BS3_MODEL_FAR_CODE
143#endif
144
145
146/*
147 * We normally don't want the noreturn / aborts attributes as they mess up stack traces.
148 *
149 * Note! pragma aux <fnname> aborts can only be used with functions
150 * implemented in C and functions that does not have parameters.
151 */
152#define BS3_KIT_WITH_NO_RETURN
153#ifndef BS3_KIT_WITH_NO_RETURN
154# undef DECL_NO_RETURN
155# define DECL_NO_RETURN(type) type
156#endif
157
158
159/*
160 * We may want to reuse some IPRT code in the common name space, so we
161 * redefine the RT_MANGLER to work like BS3_CMN_NM. (We cannot use
162 * BS3_CMN_NM yet, as we need to include IPRT headers with function
163 * declarations before we can define it. Thus the duplciate effort.)
164 */
165#if ARCH_BITS == 16
166# undef RTCALL
167# if defined(BS3_USE_ALT_16BIT_TEXT_SEG)
168# define RTCALL __cdecl __far
169# define RT_MANGLER(a_Name) RT_CONCAT(a_Name,_f16)
170# else
171# define RTCALL __cdecl __near
172# define RT_MANGLER(a_Name) RT_CONCAT(a_Name,_c16)
173# endif
174#else
175# define RT_MANGLER(a_Name) RT_CONCAT3(a_Name,_c,ARCH_BITS)
176#endif
177#include <iprt/mangling.h>
178#include <iprt/x86.h>
179#include <iprt/err.h>
180
181/*
182 * Include data symbol mangling (function mangling/mapping must be done
183 * after the protypes).
184 */
185#include "bs3kit-mangling-data.h"
186
187
188
189RT_C_DECLS_BEGIN
190
191/** @defgroup grp_bs3kit BS3Kit - Boot Sector Kit \#3
192 *
193 * The BS3Kit is a framework for bare metal floppy/usb image tests,
194 * see the @ref pg_bs3kit "doc page" for more.
195 *
196 * @{ */
197
198/** @name Execution modes.
199 * @{ */
200#define BS3_MODE_INVALID UINT8_C(0x00)
201#define BS3_MODE_RM UINT8_C(0x01) /**< real mode. */
202#define BS3_MODE_PE16 UINT8_C(0x11) /**< 16-bit protected mode kernel+tss, running 16-bit code, unpaged. */
203#define BS3_MODE_PE16_32 UINT8_C(0x12) /**< 16-bit protected mode kernel+tss, running 32-bit code, unpaged. */
204#define BS3_MODE_PE16_V86 UINT8_C(0x18) /**< 16-bit protected mode kernel+tss, running virtual 8086 mode code, unpaged. */
205#define BS3_MODE_PE32 UINT8_C(0x22) /**< 32-bit protected mode kernel+tss, running 32-bit code, unpaged. */
206#define BS3_MODE_PE32_16 UINT8_C(0x21) /**< 32-bit protected mode kernel+tss, running 16-bit code, unpaged. */
207#define BS3_MODE_PEV86 UINT8_C(0x28) /**< 32-bit protected mode kernel+tss, running virtual 8086 mode code, unpaged. */
208#define BS3_MODE_PP16 UINT8_C(0x31) /**< 16-bit protected mode kernel+tss, running 16-bit code, paged. */
209#define BS3_MODE_PP16_32 UINT8_C(0x32) /**< 16-bit protected mode kernel+tss, running 32-bit code, paged. */
210#define BS3_MODE_PP16_V86 UINT8_C(0x38) /**< 16-bit protected mode kernel+tss, running virtual 8086 mode code, paged. */
211#define BS3_MODE_PP32 UINT8_C(0x42) /**< 32-bit protected mode kernel+tss, running 32-bit code, paged. */
212#define BS3_MODE_PP32_16 UINT8_C(0x41) /**< 32-bit protected mode kernel+tss, running 16-bit code, paged. */
213#define BS3_MODE_PPV86 UINT8_C(0x48) /**< 32-bit protected mode kernel+tss, running virtual 8086 mode code, paged. */
214#define BS3_MODE_PAE16 UINT8_C(0x51) /**< 16-bit protected mode kernel+tss, running 16-bit code, PAE paging. */
215#define BS3_MODE_PAE16_32 UINT8_C(0x52) /**< 16-bit protected mode kernel+tss, running 32-bit code, PAE paging. */
216#define BS3_MODE_PAE16_V86 UINT8_C(0x58) /**< 16-bit protected mode kernel+tss, running virtual 8086 mode, PAE paging. */
217#define BS3_MODE_PAE32 UINT8_C(0x62) /**< 32-bit protected mode kernel+tss, running 32-bit code, PAE paging. */
218#define BS3_MODE_PAE32_16 UINT8_C(0x61) /**< 32-bit protected mode kernel+tss, running 16-bit code, PAE paging. */
219#define BS3_MODE_PAEV86 UINT8_C(0x68) /**< 32-bit protected mode kernel+tss, running virtual 8086 mode, PAE paging. */
220#define BS3_MODE_LM16 UINT8_C(0x71) /**< 16-bit long mode (paged), kernel+tss always 64-bit. */
221#define BS3_MODE_LM32 UINT8_C(0x72) /**< 32-bit long mode (paged), kernel+tss always 64-bit. */
222#define BS3_MODE_LM64 UINT8_C(0x74) /**< 64-bit long mode (paged), kernel+tss always 64-bit. */
223
224#define BS3_MODE_CODE_MASK UINT8_C(0x0f) /**< Running code mask. */
225#define BS3_MODE_CODE_16 UINT8_C(0x01) /**< Running 16-bit code. */
226#define BS3_MODE_CODE_32 UINT8_C(0x02) /**< Running 32-bit code. */
227#define BS3_MODE_CODE_64 UINT8_C(0x04) /**< Running 64-bit code. */
228#define BS3_MODE_CODE_V86 UINT8_C(0x08) /**< Running 16-bit virtual 8086 code. */
229
230#define BS3_MODE_SYS_MASK UINT8_C(0xf0) /**< kernel+tss mask. */
231#define BS3_MODE_SYS_RM UINT8_C(0x00) /**< Real mode kernel+tss. */
232#define BS3_MODE_SYS_PE16 UINT8_C(0x10) /**< 16-bit protected mode kernel+tss. */
233#define BS3_MODE_SYS_PE32 UINT8_C(0x20) /**< 32-bit protected mode kernel+tss. */
234#define BS3_MODE_SYS_PP16 UINT8_C(0x30) /**< 16-bit paged protected mode kernel+tss. */
235#define BS3_MODE_SYS_PP32 UINT8_C(0x40) /**< 32-bit paged protected mode kernel+tss. */
236#define BS3_MODE_SYS_PAE16 UINT8_C(0x50) /**< 16-bit PAE paged protected mode kernel+tss. */
237#define BS3_MODE_SYS_PAE32 UINT8_C(0x60) /**< 32-bit PAE paged protected mode kernel+tss. */
238#define BS3_MODE_SYS_LM UINT8_C(0x70) /**< 64-bit (paged) long mode protected mode kernel+tss. */
239
240/** Whether the mode has paging enabled. */
241#define BS3_MODE_IS_PAGED(a_fMode) ((a_fMode) >= BS3_MODE_PP16)
242/** Whether the mode has legacy paging enabled (legacy as opposed to PAE or
243 * long mode). */
244#define BS3_MODE_IS_LEGACY_PAGING(a_fMode) ((a_fMode) >= BS3_MODE_PP16 && (a_fMode) < BS3_MODE_PAE16)
245
246/** Whether the mode is running v8086 code. */
247#define BS3_MODE_IS_V86(a_fMode) (((a_fMode) & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_V86)
248/** Whether the we're executing in real mode or v8086 mode. */
249#define BS3_MODE_IS_RM_OR_V86(a_fMode) ((a_fMode) == BS3_MODE_RM || BS3_MODE_IS_V86(a_fMode))
250/** Whether the mode is running 16-bit code, except v8086. */
251#define BS3_MODE_IS_16BIT_CODE_NO_V86(a_fMode) (((a_fMode) & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_16)
252/** Whether the mode is running 16-bit code (includes v8086). */
253#define BS3_MODE_IS_16BIT_CODE(a_fMode) (BS3_MODE_IS_16BIT_CODE_NO_V86(a_fMode) || BS3_MODE_IS_V86(a_fMode))
254/** Whether the mode is running 32-bit code. */
255#define BS3_MODE_IS_32BIT_CODE(a_fMode) (((a_fMode) & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_32)
256/** Whether the mode is running 64-bit code. */
257#define BS3_MODE_IS_64BIT_CODE(a_fMode) (((a_fMode) & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_64)
258
259/** Whether the system is in real mode. */
260#define BS3_MODE_IS_RM_SYS(a_fMode) (((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_RM)
261/** Whether the system is some 16-bit mode that isn't real mode. */
262#define BS3_MODE_IS_16BIT_SYS_NO_RM(a_fMode) ( ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PE16 \
263 || ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PP16 \
264 || ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PAE16)
265/** Whether the system is some 16-bit mode (includes real mode). */
266#define BS3_MODE_IS_16BIT_SYS(a_fMode) (BS3_MODE_IS_16BIT_SYS_NO_RM(a_fMode) || BS3_MODE_IS_RM_SYS(a_fMode))
267/** Whether the system is some 32-bit mode. */
268#define BS3_MODE_IS_32BIT_SYS(a_fMode) ( ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PE32 \
269 || ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PP32 \
270 || ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PAE32)
271/** Whether the system is long mode. */
272#define BS3_MODE_IS_64BIT_SYS(a_fMode) (((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_LM)
273
274/** Whether the system is in protected mode (with or without paging).
275 * @note Long mode is not included. */
276#define BS3_MODE_IS_PM_SYS(a_fMode) ((a_fMode) >= BS3_MODE_SYS_PE16 && (a_fMode) < BS3_MODE_SYS_LM)
277
278/** @todo testcase: How would long-mode handle a 16-bit TSS loaded prior to the switch? (mainly stack switching wise) Hopefully, it will tripple fault, right? */
279/** @} */
280
281
282/** @name BS3_ADDR_XXX - Static Memory Allocation
283 * @{ */
284/** The flat load address for the code after the bootsector. */
285#define BS3_ADDR_LOAD 0x10000
286/** Where we save the boot registers during init.
287 * Located right before the code. */
288#define BS3_ADDR_REG_SAVE (BS3_ADDR_LOAD - sizeof(BS3REGCTX) - 8)
289/** Where the stack starts (initial RSP value).
290 * Located 16 bytes (assumed by boot sector) before the saved registers.
291 * SS.BASE=0. The size is a little short of 32KB */
292#define BS3_ADDR_STACK (BS3_ADDR_REG_SAVE - 16)
293/** The ring-0 stack (8KB) for ring transitions. */
294#define BS3_ADDR_STACK_R0 0x06000
295/** The ring-1 stack (8KB) for ring transitions. */
296#define BS3_ADDR_STACK_R1 0x04000
297/** The ring-2 stack (8KB) for ring transitions. */
298#define BS3_ADDR_STACK_R2 0x02000
299/** IST1 ring-0 stack for long mode (4KB), used for double faults elsewhere. */
300#define BS3_ADDR_STACK_R0_IST1 0x09000
301/** IST2 ring-0 stack for long mode (3KB), used for spare 0 stack elsewhere. */
302#define BS3_ADDR_STACK_R0_IST2 0x08000
303/** IST3 ring-0 stack for long mode (1KB). */
304#define BS3_ADDR_STACK_R0_IST3 0x07400
305/** IST4 ring-0 stack for long mode (1KB), used for spare 1 stack elsewhere. */
306#define BS3_ADDR_STACK_R0_IST4 0x07000
307/** IST5 ring-0 stack for long mode (1KB). */
308#define BS3_ADDR_STACK_R0_IST5 0x06c00
309/** IST6 ring-0 stack for long mode (1KB). */
310#define BS3_ADDR_STACK_R0_IST6 0x06800
311/** IST7 ring-0 stack for long mode (1KB). */
312#define BS3_ADDR_STACK_R0_IST7 0x06400
313
314/** The base address of the BS3TEXT16 segment (same as BS3_LOAD_ADDR).
315 * @sa BS3_SEL_TEXT16 */
316#define BS3_ADDR_BS3TEXT16 0x10000
317/** The base address of the BS3SYSTEM16 segment.
318 * @sa BS3_SEL_SYSTEM16 */
319#define BS3_ADDR_BS3SYSTEM16 0x20000
320/** The base address of the BS3DATA16/BS3KIT_GRPNM_DATA16 segment.
321 * @sa BS3_SEL_DATA16 */
322#define BS3_ADDR_BS3DATA16 0x29000
323/** @} */
324
325/** @name BS3_SEL_XXX - GDT selector assignments.
326 *
327 * The real mode segment numbers for BS16TEXT, BS16DATA and BS16SYSTEM are
328 * present in the GDT, this allows the 16-bit C/C++ and assembly code to
329 * continue using the real mode segment values in ring-0 protected mode.
330 *
331 * The three segments have fixed locations:
332 * | segment | flat address | real mode segment |
333 * | ----------- | ------------ | ----------------- |
334 * | BS3TEXT16 | 0x00010000 | 1000h |
335 * | BS3SYSTEM16 | 0x00020000 | 2000h |
336 * | BS3DATA16 | 0x00029000 | 2900h |
337 *
338 * This means that we've got a lot of GDT space to play around with.
339 *
340 * @{ */
341#define BS3_SEL_LDT 0x0010 /**< The LDT selector for Bs3Ldt. */
342#define BS3_SEL_TSS16 0x0020 /**< The 16-bit TSS selector. */
343#define BS3_SEL_TSS16_DF 0x0028 /**< The 16-bit TSS selector for double faults. */
344#define BS3_SEL_TSS16_SPARE0 0x0030 /**< The 16-bit TSS selector for testing. */
345#define BS3_SEL_TSS16_SPARE1 0x0038 /**< The 16-bit TSS selector for testing. */
346#define BS3_SEL_TSS32 0x0040 /**< The 32-bit TSS selector. */
347#define BS3_SEL_TSS32_DF 0x0048 /**< The 32-bit TSS selector for double faults. */
348#define BS3_SEL_TSS32_SPARE0 0x0050 /**< The 32-bit TSS selector for testing. */
349#define BS3_SEL_TSS32_SPARE1 0x0058 /**< The 32-bit TSS selector for testing. */
350#define BS3_SEL_TSS32_IOBP_IRB 0x0060 /**< The 32-bit TSS selector with I/O permission and interrupt redirection bitmaps. */
351#define BS3_SEL_TSS32_IRB 0x0068 /**< The 32-bit TSS selector with only interrupt redirection bitmap (IOPB stripped by limit). */
352#define BS3_SEL_TSS64 0x0070 /**< The 64-bit TSS selector. */
353#define BS3_SEL_TSS64_SPARE0 0x0080 /**< The 64-bit TSS selector. */
354#define BS3_SEL_TSS64_SPARE1 0x0090 /**< The 64-bit TSS selector. */
355#define BS3_SEL_TSS64_IOBP 0x00a0 /**< The 64-bit TSS selector. */
356
357#define BS3_SEL_RMTEXT16_CS 0x00e0 /**< Conforming code selector for accessing the BS3RMTEXT16 segment. Runtime config. */
358#define BS3_SEL_X0TEXT16_CS 0x00e8 /**< Conforming code selector for accessing the BS3X0TEXT16 segment. Runtime config. */
359#define BS3_SEL_X1TEXT16_CS 0x00f0 /**< Conforming code selector for accessing the BS3X1TEXT16 segment. Runtime config. */
360#define BS3_SEL_VMMDEV_MMIO16 0x00f8 /**< Selector for accessing the VMMDev MMIO segment at 00df000h from 16-bit code. */
361
362/** Checks if @a uSel is in the BS3_SEL_RX_XXX range. */
363#define BS3_SEL_IS_IN_RING_RANGE(uSel) ( (unsigned)(uSel - BS3_SEL_R0_FIRST) < (unsigned)(4 << BS3_SEL_RING_SHIFT) )
364#define BS3_SEL_RING_SHIFT 8 /**< For the formula: BS3_SEL_R0_XXX + ((cs & 3) << BS3_SEL_RING_SHIFT) */
365#define BS3_SEL_RING_SUB_MASK 0x00f8 /**< Mask for getting the sub-selector. For use with BS3_SEL_R*_FIRST. */
366
367/** Checks if @a uSel is in the BS3_SEL_R0_XXX range. */
368#define BS3_SEL_IS_IN_R0_RANGE(uSel) ( (unsigned)(uSel - BS3_SEL_R0_FIRST) < (unsigned)(1 << BS3_SEL_RING_SHIFT) )
369#define BS3_SEL_R0_FIRST 0x0100 /**< The first selector in the ring-0 block. */
370#define BS3_SEL_R0_CS16 0x0100 /**< ring-0: 16-bit code selector, base 0x10000. */
371#define BS3_SEL_R0_DS16 0x0108 /**< ring-0: 16-bit data selector, base 0x23000. */
372#define BS3_SEL_R0_SS16 0x0110 /**< ring-0: 16-bit stack selector, base 0x00000. */
373#define BS3_SEL_R0_CS32 0x0118 /**< ring-0: 32-bit flat code selector. */
374#define BS3_SEL_R0_DS32 0x0120 /**< ring-0: 32-bit flat data selector. */
375#define BS3_SEL_R0_SS32 0x0128 /**< ring-0: 32-bit flat stack selector. */
376#define BS3_SEL_R0_CS64 0x0130 /**< ring-0: 64-bit flat code selector. */
377#define BS3_SEL_R0_DS64 0x0138 /**< ring-0: 64-bit flat data & stack selector. */
378#define BS3_SEL_R0_CS16_EO 0x0140 /**< ring-0: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base. */
379#define BS3_SEL_R0_CS16_CNF 0x0148 /**< ring-0: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base. */
380#define BS3_SEL_R0_CS16_CNF_EO 0x0150 /**< ring-0: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base. */
381#define BS3_SEL_R0_CS32_EO 0x0158 /**< ring-0: 32-bit execute-only code selector, not accessed, flat. */
382#define BS3_SEL_R0_CS32_CNF 0x0160 /**< ring-0: 32-bit conforming code selector, not accessed, flat. */
383#define BS3_SEL_R0_CS32_CNF_EO 0x0168 /**< ring-0: 32-bit execute-only conforming code selector, not accessed, flat. */
384#define BS3_SEL_R0_CS64_EO 0x0170 /**< ring-0: 64-bit execute-only code selector, not accessed, flat. */
385#define BS3_SEL_R0_CS64_CNF 0x0178 /**< ring-0: 64-bit conforming code selector, not accessed, flat. */
386#define BS3_SEL_R0_CS64_CNF_EO 0x0180 /**< ring-0: 64-bit execute-only conforming code selector, not accessed, flat. */
387
388#define BS3_SEL_R1_FIRST 0x0200 /**< The first selector in the ring-1 block. */
389#define BS3_SEL_R1_CS16 0x0200 /**< ring-1: 16-bit code selector, base 0x10000. */
390#define BS3_SEL_R1_DS16 0x0208 /**< ring-1: 16-bit data selector, base 0x23000. */
391#define BS3_SEL_R1_SS16 0x0210 /**< ring-1: 16-bit stack selector, base 0x00000. */
392#define BS3_SEL_R1_CS32 0x0218 /**< ring-1: 32-bit flat code selector. */
393#define BS3_SEL_R1_DS32 0x0220 /**< ring-1: 32-bit flat data selector. */
394#define BS3_SEL_R1_SS32 0x0228 /**< ring-1: 32-bit flat stack selector. */
395#define BS3_SEL_R1_CS64 0x0230 /**< ring-1: 64-bit flat code selector. */
396#define BS3_SEL_R1_DS64 0x0238 /**< ring-1: 64-bit flat data & stack selector. */
397#define BS3_SEL_R1_CS16_EO 0x0240 /**< ring-1: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base. */
398#define BS3_SEL_R1_CS16_CNF 0x0248 /**< ring-1: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base. */
399#define BS3_SEL_R1_CS16_CNF_EO 0x0250 /**< ring-1: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base. */
400#define BS3_SEL_R1_CS32_EO 0x0258 /**< ring-1: 32-bit execute-only code selector, not accessed, flat. */
401#define BS3_SEL_R1_CS32_CNF 0x0260 /**< ring-1: 32-bit conforming code selector, not accessed, flat. */
402#define BS3_SEL_R1_CS32_CNF_EO 0x0268 /**< ring-1: 32-bit execute-only conforming code selector, not accessed, flat. */
403#define BS3_SEL_R1_CS64_EO 0x0270 /**< ring-1: 64-bit execute-only code selector, not accessed, flat. */
404#define BS3_SEL_R1_CS64_CNF 0x0278 /**< ring-1: 64-bit conforming code selector, not accessed, flat. */
405#define BS3_SEL_R1_CS64_CNF_EO 0x0280 /**< ring-1: 64-bit execute-only conforming code selector, not accessed, flat. */
406
407#define BS3_SEL_R2_FIRST 0x0300 /**< The first selector in the ring-2 block. */
408#define BS3_SEL_R2_CS16 0x0300 /**< ring-2: 16-bit code selector, base 0x10000. */
409#define BS3_SEL_R2_DS16 0x0308 /**< ring-2: 16-bit data selector, base 0x23000. */
410#define BS3_SEL_R2_SS16 0x0310 /**< ring-2: 16-bit stack selector, base 0x00000. */
411#define BS3_SEL_R2_CS32 0x0318 /**< ring-2: 32-bit flat code selector. */
412#define BS3_SEL_R2_DS32 0x0320 /**< ring-2: 32-bit flat data selector. */
413#define BS3_SEL_R2_SS32 0x0328 /**< ring-2: 32-bit flat stack selector. */
414#define BS3_SEL_R2_CS64 0x0330 /**< ring-2: 64-bit flat code selector. */
415#define BS3_SEL_R2_DS64 0x0338 /**< ring-2: 64-bit flat data & stack selector. */
416#define BS3_SEL_R2_CS16_EO 0x0340 /**< ring-2: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base. */
417#define BS3_SEL_R2_CS16_CNF 0x0348 /**< ring-2: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base. */
418#define BS3_SEL_R2_CS16_CNF_EO 0x0350 /**< ring-2: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base. */
419#define BS3_SEL_R2_CS32_EO 0x0358 /**< ring-2: 32-bit execute-only code selector, not accessed, flat. */
420#define BS3_SEL_R2_CS32_CNF 0x0360 /**< ring-2: 32-bit conforming code selector, not accessed, flat. */
421#define BS3_SEL_R2_CS32_CNF_EO 0x0368 /**< ring-2: 32-bit execute-only conforming code selector, not accessed, flat. */
422#define BS3_SEL_R2_CS64_EO 0x0370 /**< ring-2: 64-bit execute-only code selector, not accessed, flat. */
423#define BS3_SEL_R2_CS64_CNF 0x0378 /**< ring-2: 64-bit conforming code selector, not accessed, flat. */
424#define BS3_SEL_R2_CS64_CNF_EO 0x0380 /**< ring-2: 64-bit execute-only conforming code selector, not accessed, flat. */
425
426#define BS3_SEL_R3_FIRST 0x0400 /**< The first selector in the ring-3 block. */
427#define BS3_SEL_R3_CS16 0x0400 /**< ring-3: 16-bit code selector, base 0x10000. */
428#define BS3_SEL_R3_DS16 0x0408 /**< ring-3: 16-bit data selector, base 0x23000. */
429#define BS3_SEL_R3_SS16 0x0410 /**< ring-3: 16-bit stack selector, base 0x00000. */
430#define BS3_SEL_R3_CS32 0x0418 /**< ring-3: 32-bit flat code selector. */
431#define BS3_SEL_R3_DS32 0x0420 /**< ring-3: 32-bit flat data selector. */
432#define BS3_SEL_R3_SS32 0x0428 /**< ring-3: 32-bit flat stack selector. */
433#define BS3_SEL_R3_CS64 0x0430 /**< ring-3: 64-bit flat code selector. */
434#define BS3_SEL_R3_DS64 0x0438 /**< ring-3: 64-bit flat data & stack selector. */
435#define BS3_SEL_R3_CS16_EO 0x0440 /**< ring-3: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base. */
436#define BS3_SEL_R3_CS16_CNF 0x0448 /**< ring-3: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base. */
437#define BS3_SEL_R3_CS16_CNF_EO 0x0450 /**< ring-3: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base. */
438#define BS3_SEL_R3_CS32_EO 0x0458 /**< ring-3: 32-bit execute-only code selector, not accessed, flat. */
439#define BS3_SEL_R3_CS32_CNF 0x0460 /**< ring-3: 32-bit conforming code selector, not accessed, flat. */
440#define BS3_SEL_R3_CS32_CNF_EO 0x0468 /**< ring-3: 32-bit execute-only conforming code selector, not accessed, flat. */
441#define BS3_SEL_R3_CS64_EO 0x0470 /**< ring-3: 64-bit execute-only code selector, not accessed, flat. */
442#define BS3_SEL_R3_CS64_CNF 0x0478 /**< ring-3: 64-bit conforming code selector, not accessed, flat. */
443#define BS3_SEL_R3_CS64_CNF_EO 0x0480 /**< ring-3: 64-bit execute-only conforming code selector, not accessed, flat. */
444
445#define BS3_SEL_R3_LAST 0x04f8 /**< ring-3: Last of the BS3_SEL_RX_XXX range. */
446
447#define BS3_SEL_SPARE_FIRST 0x0500 /**< The first selector in the spare block */
448#define BS3_SEL_SPARE_00 0x0500 /**< Spare selector number 00h. */
449#define BS3_SEL_SPARE_01 0x0508 /**< Spare selector number 01h. */
450#define BS3_SEL_SPARE_02 0x0510 /**< Spare selector number 02h. */
451#define BS3_SEL_SPARE_03 0x0518 /**< Spare selector number 03h. */
452#define BS3_SEL_SPARE_04 0x0520 /**< Spare selector number 04h. */
453#define BS3_SEL_SPARE_05 0x0528 /**< Spare selector number 05h. */
454#define BS3_SEL_SPARE_06 0x0530 /**< Spare selector number 06h. */
455#define BS3_SEL_SPARE_07 0x0538 /**< Spare selector number 07h. */
456#define BS3_SEL_SPARE_08 0x0540 /**< Spare selector number 08h. */
457#define BS3_SEL_SPARE_09 0x0548 /**< Spare selector number 09h. */
458#define BS3_SEL_SPARE_0a 0x0550 /**< Spare selector number 0ah. */
459#define BS3_SEL_SPARE_0b 0x0558 /**< Spare selector number 0bh. */
460#define BS3_SEL_SPARE_0c 0x0560 /**< Spare selector number 0ch. */
461#define BS3_SEL_SPARE_0d 0x0568 /**< Spare selector number 0dh. */
462#define BS3_SEL_SPARE_0e 0x0570 /**< Spare selector number 0eh. */
463#define BS3_SEL_SPARE_0f 0x0578 /**< Spare selector number 0fh. */
464#define BS3_SEL_SPARE_10 0x0580 /**< Spare selector number 10h. */
465#define BS3_SEL_SPARE_11 0x0588 /**< Spare selector number 11h. */
466#define BS3_SEL_SPARE_12 0x0590 /**< Spare selector number 12h. */
467#define BS3_SEL_SPARE_13 0x0598 /**< Spare selector number 13h. */
468#define BS3_SEL_SPARE_14 0x05a0 /**< Spare selector number 14h. */
469#define BS3_SEL_SPARE_15 0x05a8 /**< Spare selector number 15h. */
470#define BS3_SEL_SPARE_16 0x05b0 /**< Spare selector number 16h. */
471#define BS3_SEL_SPARE_17 0x05b8 /**< Spare selector number 17h. */
472#define BS3_SEL_SPARE_18 0x05c0 /**< Spare selector number 18h. */
473#define BS3_SEL_SPARE_19 0x05c8 /**< Spare selector number 19h. */
474#define BS3_SEL_SPARE_1a 0x05d0 /**< Spare selector number 1ah. */
475#define BS3_SEL_SPARE_1b 0x05d8 /**< Spare selector number 1bh. */
476#define BS3_SEL_SPARE_1c 0x05e0 /**< Spare selector number 1ch. */
477#define BS3_SEL_SPARE_1d 0x05e8 /**< Spare selector number 1dh. */
478#define BS3_SEL_SPARE_1e 0x05f0 /**< Spare selector number 1eh. */
479#define BS3_SEL_SPARE_1f 0x05f8 /**< Spare selector number 1fh. */
480
481#define BS3_SEL_TILED 0x0600 /**< 16-bit data tiling: First - base=0x00000000, limit=64KB, DPL=3. */
482#define BS3_SEL_TILED_LAST 0x0df8 /**< 16-bit data tiling: Last - base=0x00ff0000, limit=64KB, DPL=3. */
483#define BS3_SEL_TILED_AREA_SIZE 0x001000000 /**< 16-bit data tiling: Size of addressable area, in bytes. (16 MB) */
484
485#define BS3_SEL_FREE_PART1 0x0e00 /**< Free selector space - part \#1. */
486#define BS3_SEL_FREE_PART1_LAST 0x0ff8 /**< Free selector space - part \#1, last entry. */
487
488#define BS3_SEL_TEXT16 0x1000 /**< The BS3TEXT16 selector. */
489
490#define BS3_SEL_FREE_PART2 0x1008 /**< Free selector space - part \#2. */
491#define BS3_SEL_FREE_PART2_LAST 0x17f8 /**< Free selector space - part \#2, last entry. */
492
493#define BS3_SEL_TILED_R0 0x1800 /**< 16-bit data/stack tiling: First - base=0x00000000, limit=64KB, DPL=0. */
494#define BS3_SEL_TILED_R0_LAST 0x1ff8 /**< 16-bit data/stack tiling: Last - base=0x00ff0000, limit=64KB, DPL=0. */
495
496#define BS3_SEL_SYSTEM16 0x2000 /**< The BS3SYSTEM16 selector. */
497
498#define BS3_SEL_FREE_PART3 0x2008 /**< Free selector space - part \#3. */
499#define BS3_SEL_FREE_PART3_LAST 0x28f8 /**< Free selector space - part \#3, last entry. */
500
501#define BS3_SEL_DATA16 0x2900 /**< The BS3DATA16/BS3KIT_GRPNM_DATA16 selector. */
502
503#define BS3_SEL_FREE_PART4 0x2908 /**< Free selector space - part \#4. */
504#define BS3_SEL_FREE_PART4_LAST 0x2f98 /**< Free selector space - part \#4, last entry. */
505
506#define BS3_SEL_PRE_TEST_PAGE_08 0x2fa0 /**< Selector located 8 selectors before the test page. */
507#define BS3_SEL_PRE_TEST_PAGE_07 0x2fa8 /**< Selector located 7 selectors before the test page. */
508#define BS3_SEL_PRE_TEST_PAGE_06 0x2fb0 /**< Selector located 6 selectors before the test page. */
509#define BS3_SEL_PRE_TEST_PAGE_05 0x2fb8 /**< Selector located 5 selectors before the test page. */
510#define BS3_SEL_PRE_TEST_PAGE_04 0x2fc0 /**< Selector located 4 selectors before the test page. */
511#define BS3_SEL_PRE_TEST_PAGE_03 0x2fc8 /**< Selector located 3 selectors before the test page. */
512#define BS3_SEL_PRE_TEST_PAGE_02 0x2fd0 /**< Selector located 2 selectors before the test page. */
513#define BS3_SEL_PRE_TEST_PAGE_01 0x2fd8 /**< Selector located 1 selector before the test page. */
514#define BS3_SEL_TEST_PAGE 0x2fe0 /**< Start of the test page intended for playing around with paging and GDT. */
515#define BS3_SEL_TEST_PAGE_00 0x2fe0 /**< Test page selector number 00h (convenience). */
516#define BS3_SEL_TEST_PAGE_01 0x2fe8 /**< Test page selector number 01h (convenience). */
517#define BS3_SEL_TEST_PAGE_02 0x2ff0 /**< Test page selector number 02h (convenience). */
518#define BS3_SEL_TEST_PAGE_03 0x2ff8 /**< Test page selector number 03h (convenience). */
519#define BS3_SEL_TEST_PAGE_04 0x3000 /**< Test page selector number 04h (convenience). */
520#define BS3_SEL_TEST_PAGE_05 0x3008 /**< Test page selector number 05h (convenience). */
521#define BS3_SEL_TEST_PAGE_06 0x3010 /**< Test page selector number 06h (convenience). */
522#define BS3_SEL_TEST_PAGE_07 0x3018 /**< Test page selector number 07h (convenience). */
523#define BS3_SEL_TEST_PAGE_LAST 0x3fd0 /**< The last selector in the spare page. */
524
525#define BS3_SEL_GDT_LIMIT 0x3fd8 /**< The GDT limit. */
526/** @} */
527
528
529/** @def BS3_FAR
530 * For indicating far pointers in 16-bit code.
531 * Does nothing in 32-bit and 64-bit code. */
532/** @def BS3_NEAR
533 * For indicating near pointers in 16-bit code.
534 * Does nothing in 32-bit and 64-bit code. */
535/** @def BS3_FAR_CODE
536 * For indicating far 16-bit functions.
537 * Does nothing in 32-bit and 64-bit code. */
538/** @def BS3_NEAR_CODE
539 * For indicating near 16-bit functions.
540 * Does nothing in 32-bit and 64-bit code. */
541/** @def BS3_FAR_DATA
542 * For indicating far 16-bit external data, i.e. in a segment other than DATA16.
543 * Does nothing in 32-bit and 64-bit code. */
544#ifdef M_I86
545# define BS3_FAR __far
546# define BS3_NEAR __near
547# define BS3_FAR_CODE __far
548# define BS3_NEAR_CODE __near
549# define BS3_FAR_DATA __far
550#else
551# define BS3_FAR
552# define BS3_NEAR
553# define BS3_FAR_CODE
554# define BS3_NEAR_CODE
555# define BS3_FAR_DATA
556#endif
557
558#if ARCH_BITS == 16 || defined(DOXYGEN_RUNNING)
559/** @def BS3_FP_SEG
560 * Get the selector (segment) part of a far pointer.
561 *
562 * @returns selector.
563 * @param a_pv Far pointer.
564 */
565# define BS3_FP_SEG(a_pv) ((uint16_t)(__segment)(void BS3_FAR *)(a_pv))
566/** @def BS3_FP_OFF
567 * Get the segment offset part of a far pointer.
568 *
569 * For sake of convenience, this works like a uintptr_t cast in 32-bit and
570 * 64-bit code.
571 *
572 * @returns offset.
573 * @param a_pv Far pointer.
574 */
575# define BS3_FP_OFF(a_pv) ((uint16_t)(void __near *)(a_pv))
576/** @def BS3_FP_MAKE
577 * Create a far pointer.
578 *
579 * @returns Far pointer.
580 * @param a_uSeg The selector/segment.
581 * @param a_off The offset into the segment.
582 */
583# define BS3_FP_MAKE(a_uSeg, a_off) (((__segment)(a_uSeg)) :> ((void __near *)(a_off)))
584#else
585# define BS3_FP_OFF(a_pv) ((uintptr_t)(a_pv))
586#endif
587
588/** @def BS3_MAKE_PROT_R0PTR_FROM_FLAT
589 * Creates a protected mode pointer from a flat address.
590 *
591 * For sake of convenience, this macro also works in 32-bit and 64-bit mode,
592 * only there it doesn't return a far pointer but a flat point.
593 *
594 * @returns far void pointer if 16-bit code, near/flat void pointer in 32-bit
595 * and 64-bit.
596 * @param a_uFlat Flat address in the first 16MB. */
597#if ARCH_BITS == 16
598# define BS3_MAKE_PROT_R0PTR_FROM_FLAT(a_uFlat) \
599 BS3_FP_MAKE(((uint16_t)(a_uFlat >> 16) << 3) + BS3_SEL_TILED, (uint16_t)(a_uFlat))
600#else
601# define BS3_MAKE_PROT_R0PTR_FROM_FLAT(a_uFlat) ((void *)(uintptr_t)(a_uFlat))
602#endif
603
604/** @def BS3_MAKE_PROT_R0PTR_FROM_REAL
605 * Creates a protected mode pointer from a far real mode address.
606 *
607 * For sake of convenience, this macro also works in 32-bit and 64-bit mode,
608 * only there it doesn't return a far pointer but a flat point.
609 *
610 * @returns far void pointer if 16-bit code, near/flat void pointer in 32-bit
611 * and 64-bit.
612 * @param a_uSeg The selector/segment.
613 * @param a_off The offset into the segment.
614 */
615#if ARCH_BITS == 16
616# define BS3_MAKE_PROT_R0PTR_FROM_REAL(a_uSeg, a_off) BS3_MAKE_PROT_R0PTR_FROM_FLAT(((uint32_t)(a_uSeg) << 4) + (uint16_t)(a_off))
617#else
618# define BS3_MAKE_PROT_R0PTR_FROM_REAL(a_uSeg, a_off) ( (void *)(uintptr_t)(((uint32_t)(a_uSeg) << 4) + (uint16_t)(a_off)) )
619#endif
620
621
622/** @def BS3_CALL
623 * The calling convension used by BS3 functions. */
624#if ARCH_BITS != 64
625# define BS3_CALL __cdecl
626#elif !defined(_MSC_VER)
627# define BS3_CALL __attribute__((__ms_abi__))
628#else
629# define BS3_CALL
630#endif
631
632/** @def IN_BS3KIT
633 * Indicates that we're in the same link job as the BS3Kit code. */
634#ifdef DOXYGEN_RUNNING
635# define IN_BS3KIT
636#endif
637
638/** @def BS3_DECL
639 * Declares a BS3Kit function with default far/near.
640 *
641 * Until we outgrow BS3TEXT16, we use all near functions in 16-bit.
642 *
643 * @param a_Type The return type. */
644#if ARCH_BITS != 16 || !defined(BS3_USE_ALT_16BIT_TEXT_SEG)
645# define BS3_DECL(a_Type) BS3_DECL_NEAR(a_Type)
646#else
647# define BS3_DECL(a_Type) BS3_DECL_FAR(a_Type)
648#endif
649
650/** @def BS3_DECL_NEAR
651 * Declares a BS3Kit function, always near everywhere.
652 *
653 * Until we outgrow BS3TEXT16, we use all near functions in 16-bit.
654 *
655 * @param a_Type The return type. */
656#ifdef IN_BS3KIT
657# define BS3_DECL_NEAR(a_Type) DECLEXPORT(a_Type) BS3_NEAR_CODE BS3_CALL
658#else
659# define BS3_DECL_NEAR(a_Type) DECLIMPORT(a_Type) BS3_NEAR_CODE BS3_CALL
660#endif
661
662/** @def BS3_DECL_FAR
663 * Declares a BS3Kit function, far 16-bit, otherwise near.
664 *
665 * Until we outgrow BS3TEXT16, we use all near functions in 16-bit.
666 *
667 * @param a_Type The return type. */
668#ifdef IN_BS3KIT
669# define BS3_DECL_FAR(a_Type) DECLEXPORT(a_Type) BS3_FAR_CODE BS3_CALL
670#else
671# define BS3_DECL_FAR(a_Type) DECLIMPORT(a_Type) BS3_FAR_CODE BS3_CALL
672#endif
673
674/** @def BS3_DECL_CALLBACK
675 * Declares a BS3Kit callback function (typically static).
676 *
677 * @param a_Type The return type. */
678#ifdef IN_BS3KIT
679# define BS3_DECL_CALLBACK(a_Type) a_Type BS3_FAR_CODE BS3_CALL
680#else
681# define BS3_DECL_CALLBACK(a_Type) a_Type BS3_FAR_CODE BS3_CALL
682#endif
683
684/** @def BS3_DECL_NEAR_CALLBACK
685 * Declares a near BS3Kit callback function (typically static).
686 *
687 * 16-bit users must be in CGROUP16!
688 *
689 * @param a_Type The return type. */
690#ifdef IN_BS3KIT
691# define BS3_DECL_NEAR_CALLBACK(a_Type) a_Type BS3_NEAR_CODE BS3_CALL
692#else
693# define BS3_DECL_NEAR_CALLBACK(a_Type) a_Type BS3_NEAR_CODE BS3_CALL
694#endif
695
696/**
697 * Constructs a common name.
698 *
699 * Example: BS3_CMN_NM(Bs3Shutdown)
700 *
701 * @param a_Name The name of the function or global variable.
702 */
703#define BS3_CMN_NM(a_Name) RT_CONCAT3(a_Name,_c,ARCH_BITS)
704
705/**
706 * Constructs a common function name, far in 16-bit code.
707 *
708 * Example: BS3_CMN_FAR_NM(Bs3Shutdown)
709 *
710 * @param a_Name The name of the function.
711 */
712#if ARCH_BITS == 16
713# define BS3_CMN_FAR_NM(a_Name) RT_CONCAT(a_Name,_f16)
714#else
715# define BS3_CMN_FAR_NM(a_Name) RT_CONCAT3(a_Name,_c,ARCH_BITS)
716#endif
717
718/**
719 * Constructs a common function name, far or near as defined by the source.
720 *
721 * Which to use in 16-bit mode is defined by BS3_USE_ALT_16BIT_TEXT_SEG. In
722 * 32-bit and 64-bit mode there are no far symbols, only near ones.
723 *
724 * Example: BS3_CMN_FN_NM(Bs3Shutdown)
725 *
726 * @param a_Name The name of the function.
727 */
728#if ARCH_BITS != 16 || !defined(BS3_USE_ALT_16BIT_TEXT_SEG)
729# define BS3_CMN_FN_NM(a_Name) BS3_CMN_NM(a_Name)
730#else
731# define BS3_CMN_FN_NM(a_Name) BS3_CMN_FAR_NM(a_Name)
732#endif
733
734
735/**
736 * Constructs a data name.
737 *
738 * This glosses over the underscore prefix usage of our 16-bit, 32-bit and
739 * 64-bit compilers.
740 *
741 * Example: @code{.c}
742 * \#define Bs3Gdt BS3_DATA_NM(Bs3Gdt)
743 * extern X86DESC BS3_FAR_DATA Bs3Gdt
744 * @endcode
745 *
746 * @param a_Name The name of the global variable.
747 * @remarks Mainly used in bs3kit-mangling.h, internal headers and templates.
748 */
749//converter does this now//#if ARCH_BITS == 64
750//converter does this now//# define BS3_DATA_NM(a_Name) RT_CONCAT(_,a_Name)
751//converter does this now//#else
752# define BS3_DATA_NM(a_Name) a_Name
753//converter does this now//#endif
754
755/**
756 * Template for creating a pointer union type.
757 * @param a_BaseName The base type name.
758 * @param a_Modifiers The type modifier.
759 */
760#define BS3_PTR_UNION_TEMPLATE(a_BaseName, a_Modifiers) \
761 typedef union a_BaseName \
762 { \
763 /** Pointer into the void. */ \
764 a_Modifiers void BS3_FAR *pv; \
765 /** As a signed integer. */ \
766 intptr_t i; \
767 /** As an unsigned integer. */ \
768 uintptr_t u; \
769 /** Pointer to char value. */ \
770 a_Modifiers char BS3_FAR *pch; \
771 /** Pointer to char value. */ \
772 a_Modifiers unsigned char BS3_FAR *puch; \
773 /** Pointer to a int value. */ \
774 a_Modifiers int BS3_FAR *pi; \
775 /** Pointer to a unsigned int value. */ \
776 a_Modifiers unsigned int BS3_FAR *pu; \
777 /** Pointer to a long value. */ \
778 a_Modifiers long BS3_FAR *pl; \
779 /** Pointer to a long value. */ \
780 a_Modifiers unsigned long BS3_FAR *pul; \
781 /** Pointer to a memory size value. */ \
782 a_Modifiers size_t BS3_FAR *pcb; \
783 /** Pointer to a byte value. */ \
784 a_Modifiers uint8_t BS3_FAR *pb; \
785 /** Pointer to a 8-bit unsigned value. */ \
786 a_Modifiers uint8_t BS3_FAR *pu8; \
787 /** Pointer to a 16-bit unsigned value. */ \
788 a_Modifiers uint16_t BS3_FAR *pu16; \
789 /** Pointer to a 32-bit unsigned value. */ \
790 a_Modifiers uint32_t BS3_FAR *pu32; \
791 /** Pointer to a 64-bit unsigned value. */ \
792 a_Modifiers uint64_t BS3_FAR *pu64; \
793 /** Pointer to a UTF-16 character. */ \
794 a_Modifiers RTUTF16 BS3_FAR *pwc; \
795 /** Pointer to a UUID character. */ \
796 a_Modifiers RTUUID BS3_FAR *pUuid; \
797 } a_BaseName; \
798 /** Pointer to a pointer union. */ \
799 typedef a_BaseName *RT_CONCAT(P,a_BaseName)
800BS3_PTR_UNION_TEMPLATE(BS3PTRUNION, RT_NOTHING);
801BS3_PTR_UNION_TEMPLATE(BS3CPTRUNION, const);
802BS3_PTR_UNION_TEMPLATE(BS3VPTRUNION, volatile);
803BS3_PTR_UNION_TEMPLATE(BS3CVPTRUNION, const volatile);
804
805/** Generic far function type. */
806typedef BS3_DECL_FAR(void) FNBS3FAR(void);
807/** Generic far function pointer type. */
808typedef FNBS3FAR *FPFNBS3FAR;
809
810/** Generic near function type. */
811typedef BS3_DECL_NEAR(void) FNBS3NEAR(void);
812/** Generic near function pointer type. */
813typedef FNBS3NEAR *PFNBS3NEAR;
814
815/** Generic far 16:16 function pointer type for address conversion functions. */
816#if ARCH_BITS == 16
817typedef FPFNBS3FAR PFNBS3FARADDRCONV;
818#else
819typedef uint32_t PFNBS3FARADDRCONV;
820#endif
821
822/** The system call vector. */
823#define BS3_TRAP_SYSCALL UINT8_C(0x20)
824
825/** @name System call numbers (ax).
826 * Paramenters are generally passed in registers specific to each system call,
827 * however cx:xSI is used for passing a pointer parameter.
828 * @{ */
829/** Print char (cl). */
830#define BS3_SYSCALL_PRINT_CHR UINT16_C(0x0001)
831/** Print string (pointer in cx:xSI, length in dx). */
832#define BS3_SYSCALL_PRINT_STR UINT16_C(0x0002)
833/** Switch to ring-0. */
834#define BS3_SYSCALL_TO_RING0 UINT16_C(0x0003)
835/** Switch to ring-1. */
836#define BS3_SYSCALL_TO_RING1 UINT16_C(0x0004)
837/** Switch to ring-2. */
838#define BS3_SYSCALL_TO_RING2 UINT16_C(0x0005)
839/** Switch to ring-3. */
840#define BS3_SYSCALL_TO_RING3 UINT16_C(0x0006)
841/** Restore context (pointer in cx:xSI, flags in dx). */
842#define BS3_SYSCALL_RESTORE_CTX UINT16_C(0x0007)
843/** Set DRx register (value in ESI, register number in dl). */
844#define BS3_SYSCALL_SET_DRX UINT16_C(0x0008)
845/** Get DRx register (register number in dl, value returned in ax:dx). */
846#define BS3_SYSCALL_GET_DRX UINT16_C(0x0009)
847/** Set CRx register (value in ESI, register number in dl). */
848#define BS3_SYSCALL_SET_CRX UINT16_C(0x000a)
849/** Get CRx register (register number in dl, value returned in ax:dx). */
850#define BS3_SYSCALL_GET_CRX UINT16_C(0x000b)
851/** Set the task register (value in ESI). */
852#define BS3_SYSCALL_SET_TR UINT16_C(0x000c)
853/** Get the task register (value returned in ax). */
854#define BS3_SYSCALL_GET_TR UINT16_C(0x000d)
855/** Set the LDT register (value in ESI). */
856#define BS3_SYSCALL_SET_LDTR UINT16_C(0x000e)
857/** Get the LDT register (value returned in ax). */
858#define BS3_SYSCALL_GET_LDTR UINT16_C(0x000f)
859/** Set XCR0 register (value in edx:esi). */
860#define BS3_SYSCALL_SET_XCR0 UINT16_C(0x0010)
861/** Get XCR0 register (value returned in edx:eax). */
862#define BS3_SYSCALL_GET_XCR0 UINT16_C(0x0011)
863/** The last system call value. */
864#define BS3_SYSCALL_LAST BS3_SYSCALL_GET_XCR0
865/** @} */
866
867
868
869/** @defgroup grp_bs3kit_system System Structures
870 * @{ */
871/** The GDT, indexed by BS3_SEL_XXX shifted by 3. */
872extern X86DESC BS3_FAR_DATA Bs3Gdt[(BS3_SEL_GDT_LIMIT + 1) / 8];
873
874extern X86DESC64 BS3_FAR_DATA Bs3Gdt_Ldt; /**< @see BS3_SEL_LDT */
875extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss16; /**< @see BS3_SEL_TSS16 */
876extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss16DoubleFault; /**< @see BS3_SEL_TSS16_DF */
877extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss16Spare0; /**< @see BS3_SEL_TSS16_SPARE0 */
878extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss16Spare1; /**< @see BS3_SEL_TSS16_SPARE1 */
879extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss32; /**< @see BS3_SEL_TSS32 */
880extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss32DoubleFault; /**< @see BS3_SEL_TSS32_DF */
881extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss32Spare0; /**< @see BS3_SEL_TSS32_SPARE0 */
882extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss32Spare1; /**< @see BS3_SEL_TSS32_SPARE1 */
883extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss32IobpIntRedirBm; /**< @see BS3_SEL_TSS32_IOBP_IRB */
884extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss32IntRedirBm; /**< @see BS3_SEL_TSS32_IRB */
885extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss64; /**< @see BS3_SEL_TSS64 */
886extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss64Spare0; /**< @see BS3_SEL_TSS64_SPARE0 */
887extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss64Spare1; /**< @see BS3_SEL_TSS64_SPARE1 */
888extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss64Iobp; /**< @see BS3_SEL_TSS64_IOBP */
889extern X86DESC BS3_FAR_DATA Bs3Gdte_RMTEXT16_CS; /**< @see BS3_SEL_RMTEXT16_CS */
890extern X86DESC BS3_FAR_DATA Bs3Gdte_X0TEXT16_CS; /**< @see BS3_SEL_X0TEXT16_CS */
891extern X86DESC BS3_FAR_DATA Bs3Gdte_X1TEXT16_CS; /**< @see BS3_SEL_X1TEXT16_CS */
892extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_MMIO16; /**< @see BS3_SEL_VMMDEV_MMIO16 */
893
894extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_First; /**< @see BS3_SEL_R0_FIRST */
895extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS16; /**< @see BS3_SEL_R0_CS16 */
896extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_DS16; /**< @see BS3_SEL_R0_DS16 */
897extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_SS16; /**< @see BS3_SEL_R0_SS16 */
898extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS32; /**< @see BS3_SEL_R0_CS32 */
899extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_DS32; /**< @see BS3_SEL_R0_DS32 */
900extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_SS32; /**< @see BS3_SEL_R0_SS32 */
901extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS64; /**< @see BS3_SEL_R0_CS64 */
902extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_DS64; /**< @see BS3_SEL_R0_DS64 */
903extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS16_EO; /**< @see BS3_SEL_R0_CS16_EO */
904extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS16_CNF; /**< @see BS3_SEL_R0_CS16_CNF */
905extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS16_CND_EO; /**< @see BS3_SEL_R0_CS16_CNF_EO */
906extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS32_EO; /**< @see BS3_SEL_R0_CS32_EO */
907extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS32_CNF; /**< @see BS3_SEL_R0_CS32_CNF */
908extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS32_CNF_EO; /**< @see BS3_SEL_R0_CS32_CNF_EO */
909extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS64_EO; /**< @see BS3_SEL_R0_CS64_EO */
910extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS64_CNF; /**< @see BS3_SEL_R0_CS64_CNF */
911extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS64_CNF_EO; /**< @see BS3_SEL_R0_CS64_CNF_EO */
912
913extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_First; /**< @see BS3_SEL_R1_FIRST */
914extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS16; /**< @see BS3_SEL_R1_CS16 */
915extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_DS16; /**< @see BS3_SEL_R1_DS16 */
916extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_SS16; /**< @see BS3_SEL_R1_SS16 */
917extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS32; /**< @see BS3_SEL_R1_CS32 */
918extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_DS32; /**< @see BS3_SEL_R1_DS32 */
919extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_SS32; /**< @see BS3_SEL_R1_SS32 */
920extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS64; /**< @see BS3_SEL_R1_CS64 */
921extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_DS64; /**< @see BS3_SEL_R1_DS64 */
922extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS16_EO; /**< @see BS3_SEL_R1_CS16_EO */
923extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS16_CNF; /**< @see BS3_SEL_R1_CS16_CNF */
924extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS16_CND_EO; /**< @see BS3_SEL_R1_CS16_CNF_EO */
925extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS32_EO; /**< @see BS3_SEL_R1_CS32_EO */
926extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS32_CNF; /**< @see BS3_SEL_R1_CS32_CNF */
927extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS32_CNF_EO; /**< @see BS3_SEL_R1_CS32_CNF_EO */
928extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS64_EO; /**< @see BS3_SEL_R1_CS64_EO */
929extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS64_CNF; /**< @see BS3_SEL_R1_CS64_CNF */
930extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS64_CNF_EO; /**< @see BS3_SEL_R1_CS64_CNF_EO */
931
932extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_First; /**< @see BS3_SEL_R2_FIRST */
933extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS16; /**< @see BS3_SEL_R2_CS16 */
934extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_DS16; /**< @see BS3_SEL_R2_DS16 */
935extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_SS16; /**< @see BS3_SEL_R2_SS16 */
936extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS32; /**< @see BS3_SEL_R2_CS32 */
937extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_DS32; /**< @see BS3_SEL_R2_DS32 */
938extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_SS32; /**< @see BS3_SEL_R2_SS32 */
939extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS64; /**< @see BS3_SEL_R2_CS64 */
940extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_DS64; /**< @see BS3_SEL_R2_DS64 */
941extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS16_EO; /**< @see BS3_SEL_R2_CS16_EO */
942extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS16_CNF; /**< @see BS3_SEL_R2_CS16_CNF */
943extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS16_CND_EO; /**< @see BS3_SEL_R2_CS16_CNF_EO */
944extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS32_EO; /**< @see BS3_SEL_R2_CS32_EO */
945extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS32_CNF; /**< @see BS3_SEL_R2_CS32_CNF */
946extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS32_CNF_EO; /**< @see BS3_SEL_R2_CS32_CNF_EO */
947extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS64_EO; /**< @see BS3_SEL_R2_CS64_EO */
948extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS64_CNF; /**< @see BS3_SEL_R2_CS64_CNF */
949extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS64_CNF_EO; /**< @see BS3_SEL_R2_CS64_CNF_EO */
950
951extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_First; /**< @see BS3_SEL_R3_FIRST */
952extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS16; /**< @see BS3_SEL_R3_CS16 */
953extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_DS16; /**< @see BS3_SEL_R3_DS16 */
954extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_SS16; /**< @see BS3_SEL_R3_SS16 */
955extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS32; /**< @see BS3_SEL_R3_CS32 */
956extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_DS32; /**< @see BS3_SEL_R3_DS32 */
957extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_SS32; /**< @see BS3_SEL_R3_SS32 */
958extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS64; /**< @see BS3_SEL_R3_CS64 */
959extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_DS64; /**< @see BS3_SEL_R3_DS64 */
960extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS16_EO; /**< @see BS3_SEL_R3_CS16_EO */
961extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS16_CNF; /**< @see BS3_SEL_R3_CS16_CNF */
962extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS16_CND_EO; /**< @see BS3_SEL_R3_CS16_CNF_EO */
963extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS32_EO; /**< @see BS3_SEL_R3_CS32_EO */
964extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS32_CNF; /**< @see BS3_SEL_R3_CS32_CNF */
965extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS32_CNF_EO; /**< @see BS3_SEL_R3_CS32_CNF_EO */
966extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS64_EO; /**< @see BS3_SEL_R3_CS64_EO */
967extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS64_CNF; /**< @see BS3_SEL_R3_CS64_CNF */
968extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS64_CNF_EO; /**< @see BS3_SEL_R3_CS64_CNF_EO */
969
970extern X86DESC BS3_FAR_DATA Bs3GdteSpare00; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_00 */
971extern X86DESC BS3_FAR_DATA Bs3GdteSpare01; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_01 */
972extern X86DESC BS3_FAR_DATA Bs3GdteSpare02; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_02 */
973extern X86DESC BS3_FAR_DATA Bs3GdteSpare03; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_03 */
974extern X86DESC BS3_FAR_DATA Bs3GdteSpare04; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_04 */
975extern X86DESC BS3_FAR_DATA Bs3GdteSpare05; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_05 */
976extern X86DESC BS3_FAR_DATA Bs3GdteSpare06; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_06 */
977extern X86DESC BS3_FAR_DATA Bs3GdteSpare07; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_07 */
978extern X86DESC BS3_FAR_DATA Bs3GdteSpare08; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_08 */
979extern X86DESC BS3_FAR_DATA Bs3GdteSpare09; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_09 */
980extern X86DESC BS3_FAR_DATA Bs3GdteSpare0a; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0a */
981extern X86DESC BS3_FAR_DATA Bs3GdteSpare0b; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0b */
982extern X86DESC BS3_FAR_DATA Bs3GdteSpare0c; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0c */
983extern X86DESC BS3_FAR_DATA Bs3GdteSpare0d; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0d */
984extern X86DESC BS3_FAR_DATA Bs3GdteSpare0e; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0e */
985extern X86DESC BS3_FAR_DATA Bs3GdteSpare0f; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0f */
986extern X86DESC BS3_FAR_DATA Bs3GdteSpare10; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_10 */
987extern X86DESC BS3_FAR_DATA Bs3GdteSpare11; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_11 */
988extern X86DESC BS3_FAR_DATA Bs3GdteSpare12; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_12 */
989extern X86DESC BS3_FAR_DATA Bs3GdteSpare13; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_13 */
990extern X86DESC BS3_FAR_DATA Bs3GdteSpare14; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_14 */
991extern X86DESC BS3_FAR_DATA Bs3GdteSpare15; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_15 */
992extern X86DESC BS3_FAR_DATA Bs3GdteSpare16; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_16 */
993extern X86DESC BS3_FAR_DATA Bs3GdteSpare17; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_17 */
994extern X86DESC BS3_FAR_DATA Bs3GdteSpare18; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_18 */
995extern X86DESC BS3_FAR_DATA Bs3GdteSpare19; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_19 */
996extern X86DESC BS3_FAR_DATA Bs3GdteSpare1a; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1a */
997extern X86DESC BS3_FAR_DATA Bs3GdteSpare1b; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1b */
998extern X86DESC BS3_FAR_DATA Bs3GdteSpare1c; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1c */
999extern X86DESC BS3_FAR_DATA Bs3GdteSpare1d; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1d */
1000extern X86DESC BS3_FAR_DATA Bs3GdteSpare1e; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1e */
1001extern X86DESC BS3_FAR_DATA Bs3GdteSpare1f; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1f */
1002
1003/** GDTs setting up the tiled 16-bit access to the first 16 MBs of memory.
1004 * @see BS3_SEL_TILED, BS3_SEL_TILED_LAST, BS3_SEL_TILED_AREA_SIZE */
1005extern X86DESC BS3_FAR_DATA Bs3GdteTiled[256];
1006/** Free GDTes, part \#1. */
1007extern X86DESC BS3_FAR_DATA Bs3GdteFreePart1[64];
1008/** The BS3TEXT16/BS3CLASS16CODE GDT entry. @see BS3_SEL_TEXT16 */
1009extern X86DESC BS3_FAR_DATA Bs3Gdte_CODE16;
1010/** Free GDTes, part \#2. */
1011extern X86DESC BS3_FAR_DATA Bs3GdteFreePart2[511];
1012/** The BS3SYSTEM16 GDT entry. */
1013extern X86DESC BS3_FAR_DATA Bs3Gdte_SYSTEM16;
1014/** Free GDTes, part \#3. */
1015extern X86DESC BS3_FAR_DATA Bs3GdteFreePart3[223];
1016/** The BS3DATA16/BS3KIT_GRPNM_DATA16 GDT entry. */
1017extern X86DESC BS3_FAR_DATA Bs3Gdte_DATA16;
1018
1019/** Free GDTes, part \#4. */
1020extern X86DESC BS3_FAR_DATA Bs3GdteFreePart4[211];
1021
1022extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage08; /**< GDT entry 8 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_08 */
1023extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage07; /**< GDT entry 7 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_07 */
1024extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage06; /**< GDT entry 6 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_06 */
1025extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage05; /**< GDT entry 5 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_05 */
1026extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage04; /**< GDT entry 4 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_04 */
1027extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage03; /**< GDT entry 3 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_03 */
1028extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage02; /**< GDT entry 2 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_02 */
1029extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage01; /**< GDT entry 1 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_01 */
1030/** Array of GDT entries starting on a page boundrary and filling (almost) the
1031 * whole page. This is for playing with paging and GDT usage.
1032 * @see BS3_SEL_TEST_PAGE */
1033extern X86DESC BS3_FAR_DATA Bs3GdteTestPage[2043];
1034extern X86DESC BS3_FAR_DATA Bs3GdteTestPage00; /**< GDT entry 0 on the test page (convenience). @see BS3_SEL_TEST_PAGE_00 */
1035extern X86DESC BS3_FAR_DATA Bs3GdteTestPage01; /**< GDT entry 1 on the test page (convenience). @see BS3_SEL_TEST_PAGE_01 */
1036extern X86DESC BS3_FAR_DATA Bs3GdteTestPage02; /**< GDT entry 2 on the test page (convenience). @see BS3_SEL_TEST_PAGE_02 */
1037extern X86DESC BS3_FAR_DATA Bs3GdteTestPage03; /**< GDT entry 3 on the test page (convenience). @see BS3_SEL_TEST_PAGE_03 */
1038extern X86DESC BS3_FAR_DATA Bs3GdteTestPage04; /**< GDT entry 4 on the test page (convenience). @see BS3_SEL_TEST_PAGE_04 */
1039extern X86DESC BS3_FAR_DATA Bs3GdteTestPage05; /**< GDT entry 5 on the test page (convenience). @see BS3_SEL_TEST_PAGE_05 */
1040extern X86DESC BS3_FAR_DATA Bs3GdteTestPage06; /**< GDT entry 6 on the test page (convenience). @see BS3_SEL_TEST_PAGE_06 */
1041extern X86DESC BS3_FAR_DATA Bs3GdteTestPage07; /**< GDT entry 7 on the test page (convenience). @see BS3_SEL_TEST_PAGE_07 */
1042
1043/** The end of the GDT (exclusive - contains eye-catcher string). */
1044extern X86DESC BS3_FAR_DATA Bs3GdtEnd;
1045
1046/** The default 16-bit TSS. */
1047extern X86TSS16 BS3_FAR_DATA Bs3Tss16;
1048extern X86TSS16 BS3_FAR_DATA Bs3Tss16DoubleFault;
1049extern X86TSS16 BS3_FAR_DATA Bs3Tss16Spare0;
1050extern X86TSS16 BS3_FAR_DATA Bs3Tss16Spare1;
1051/** The default 32-bit TSS. */
1052extern X86TSS32 BS3_FAR_DATA Bs3Tss32;
1053extern X86TSS32 BS3_FAR_DATA Bs3Tss32DoubleFault;
1054extern X86TSS32 BS3_FAR_DATA Bs3Tss32Spare0;
1055extern X86TSS32 BS3_FAR_DATA Bs3Tss32Spare1;
1056/** The default 64-bit TSS. */
1057extern X86TSS64 BS3_FAR_DATA Bs3Tss64;
1058extern X86TSS64 BS3_FAR_DATA Bs3Tss64Spare0;
1059extern X86TSS64 BS3_FAR_DATA Bs3Tss64Spare1;
1060extern X86TSS64 BS3_FAR_DATA Bs3Tss64WithIopb;
1061extern X86TSS32 BS3_FAR_DATA Bs3Tss32WithIopb;
1062/** Interrupt redirection bitmap used by Bs3Tss32WithIopb. */
1063extern uint8_t BS3_FAR_DATA Bs3SharedIntRedirBm[32];
1064/** I/O permission bitmap used by Bs3Tss32WithIopb and Bs3Tss64WithIopb. */
1065extern uint8_t BS3_FAR_DATA Bs3SharedIobp[8192+2];
1066/** End of the I/O permission bitmap (exclusive). */
1067extern uint8_t BS3_FAR_DATA Bs3SharedIobpEnd;
1068/** 16-bit IDT. */
1069extern X86DESC BS3_FAR_DATA Bs3Idt16[256];
1070/** 32-bit IDT. */
1071extern X86DESC BS3_FAR_DATA Bs3Idt32[256];
1072/** 64-bit IDT. */
1073extern X86DESC64 BS3_FAR_DATA Bs3Idt64[256];
1074/** Structure for the LIDT instruction for loading the 16-bit IDT. */
1075extern X86XDTR64 BS3_FAR_DATA Bs3Lidt_Idt16;
1076/** Structure for the LIDT instruction for loading the 32-bit IDT. */
1077extern X86XDTR64 BS3_FAR_DATA Bs3Lidt_Idt32;
1078/** Structure for the LIDT instruction for loading the 64-bit IDT. */
1079extern X86XDTR64 BS3_FAR_DATA Bs3Lidt_Idt64;
1080/** Structure for the LIDT instruction for loading the real mode interrupt
1081 * vector table. */
1082extern X86XDTR64 BS3_FAR_DATA Bs3Lidt_Ivt;
1083/** Structure for the LGDT instruction for loading the current GDT. */
1084extern X86XDTR64 BS3_FAR_DATA Bs3Lgdt_Gdt;
1085/** Structure for the LGDT instruction for loading the default GDT. */
1086extern X86XDTR64 BS3_FAR_DATA Bs3LgdtDef_Gdt;
1087/** The LDT (all entries are empty, fill in for testing). */
1088extern X86DESC BS3_FAR_DATA Bs3Ldt[116];
1089/** The end of the LDT (exclusive). */
1090extern X86DESC BS3_FAR_DATA Bs3LdtEnd;
1091
1092/** @} */
1093
1094
1095/** @name Segment start and end markers, sizes.
1096 * @{ */
1097/** Start of the BS3TEXT16 segment. */
1098extern uint8_t BS3_FAR_DATA Bs3Text16_StartOfSegment;
1099/** End of the BS3TEXT16 segment. */
1100extern uint8_t BS3_FAR_DATA Bs3Text16_EndOfSegment;
1101/** The size of the BS3TEXT16 segment. */
1102extern uint16_t BS3_FAR_DATA Bs3Text16_Size;
1103
1104/** Start of the BS3SYSTEM16 segment. */
1105extern uint8_t BS3_FAR_DATA Bs3System16_StartOfSegment;
1106/** End of the BS3SYSTEM16 segment. */
1107extern uint8_t BS3_FAR_DATA Bs3System16_EndOfSegment;
1108
1109/** Start of the BS3DATA16/BS3KIT_GRPNM_DATA16 segment. */
1110extern uint8_t BS3_FAR_DATA Bs3Data16_StartOfSegment;
1111/** End of the BS3DATA16/BS3KIT_GRPNM_DATA16 segment. */
1112extern uint8_t BS3_FAR_DATA Bs3Data16_EndOfSegment;
1113
1114/** Start of the BS3RMTEXT16 segment. */
1115extern uint8_t BS3_FAR_DATA Bs3RmText16_StartOfSegment;
1116/** End of the BS3RMTEXT16 segment. */
1117extern uint8_t BS3_FAR_DATA Bs3RmText16_EndOfSegment;
1118/** The size of the BS3RMTEXT16 segment. */
1119extern uint16_t BS3_FAR_DATA Bs3RmText16_Size;
1120/** The flat start address of the BS3X0TEXT16 segment. */
1121extern uint32_t BS3_FAR_DATA Bs3RmText16_FlatAddr;
1122
1123/** Start of the BS3X0TEXT16 segment. */
1124extern uint8_t BS3_FAR_DATA Bs3X0Text16_StartOfSegment;
1125/** End of the BS3X0TEXT16 segment. */
1126extern uint8_t BS3_FAR_DATA Bs3X0Text16_EndOfSegment;
1127/** The size of the BS3X0TEXT16 segment. */
1128extern uint16_t BS3_FAR_DATA Bs3X0Text16_Size;
1129/** The flat start address of the BS3X0TEXT16 segment. */
1130extern uint32_t BS3_FAR_DATA Bs3X0Text16_FlatAddr;
1131
1132/** Start of the BS3X1TEXT16 segment. */
1133extern uint8_t BS3_FAR_DATA Bs3X1Text16_StartOfSegment;
1134/** End of the BS3X1TEXT16 segment. */
1135extern uint8_t BS3_FAR_DATA Bs3X1Text16_EndOfSegment;
1136/** The size of the BS3X1TEXT16 segment. */
1137extern uint16_t BS3_FAR_DATA Bs3X1Text16_Size;
1138/** The flat start address of the BS3X1TEXT16 segment. */
1139extern uint32_t BS3_FAR_DATA Bs3X1Text16_FlatAddr;
1140
1141/** Start of the BS3TEXT32 segment. */
1142extern uint8_t BS3_FAR_DATA Bs3Text32_StartOfSegment;
1143/** Start of the BS3TEXT32 segment. */
1144extern uint8_t BS3_FAR_DATA Bs3Text32_EndOfSegment;
1145
1146/** Start of the BS3DATA32 segment. */
1147extern uint8_t BS3_FAR_DATA Bs3Data32_StartOfSegment;
1148/** Start of the BS3DATA32 segment. */
1149extern uint8_t BS3_FAR_DATA Bs3Data32_EndOfSegment;
1150
1151/** Start of the BS3TEXT64 segment. */
1152extern uint8_t BS3_FAR_DATA Bs3Text64_StartOfSegment;
1153/** Start of the BS3TEXT64 segment. */
1154extern uint8_t BS3_FAR_DATA Bs3Text64_EndOfSegment;
1155
1156/** Start of the BS3DATA64 segment. */
1157extern uint8_t BS3_FAR_DATA Bs3Data64_StartOfSegment;
1158/** Start of the BS3DATA64 segment. */
1159extern uint8_t BS3_FAR_DATA Bs3Data64_EndOfSegment;
1160
1161/** The size of the Data16, Text32, Text64, Data32 and Data64 blob. */
1162extern uint32_t BS3_FAR_DATA Bs3Data16Thru64Text32And64_TotalSize;
1163/** The total image size (from Text16 thu Data64). */
1164extern uint32_t BS3_FAR_DATA Bs3TotalImageSize;
1165/** @} */
1166
1167
1168/** Lower case hex digits. */
1169extern char const g_achBs3HexDigits[16+1];
1170/** Upper case hex digits. */
1171extern char const g_achBs3HexDigitsUpper[16+1];
1172
1173
1174/** The current mode (BS3_MODE_XXX) of CPU \#0. */
1175extern uint8_t g_bBs3CurrentMode;
1176
1177/** Hint for 16-bit trap handlers regarding the high word of EIP. */
1178extern uint32_t g_uBs3TrapEipHint;
1179
1180/** Set to disable special V8086 \#GP and \#UD handling in Bs3TrapDefaultHandler.
1181 * This is useful for getting */
1182extern bool volatile g_fBs3TrapNoV86Assist;
1183
1184/** Copy of the original real-mode interrupt vector table. */
1185extern RTFAR16 g_aBs3RmIvtOriginal[256];
1186
1187
1188#ifdef __WATCOMC__
1189/**
1190 * Executes the SMSW instruction and returns the value.
1191 *
1192 * @returns Machine status word.
1193 */
1194uint16_t Bs3AsmSmsw(void);
1195# pragma aux Bs3AsmSmsw = \
1196 ".286" \
1197 "smsw ax" \
1198 value [ax] modify exact [ax] nomemory;
1199#endif
1200
1201
1202/** @defgroup bs3kit_cross_ptr Cross Context Pointer Type
1203 *
1204 * The cross context pointer type is
1205 *
1206 * @{ */
1207
1208/**
1209 * Cross context pointer base type.
1210 */
1211typedef union BS3XPTR
1212{
1213 /** The flat pointer. */
1214 uint32_t uFlat;
1215 /** 16-bit view. */
1216 struct
1217 {
1218 uint16_t uLow;
1219 uint16_t uHigh;
1220 } u;
1221#if ARCH_BITS == 16
1222 /** 16-bit near pointer. */
1223 void __near *pvNear;
1224#elif ARCH_BITS == 32
1225 /** 32-bit pointer. */
1226 void *pvRaw;
1227#endif
1228} BS3XPTR;
1229AssertCompileSize(BS3XPTR, 4);
1230
1231
1232/** @def BS3_XPTR_DEF_INTERNAL
1233 * Internal worker.
1234 *
1235 * @param a_Scope RT_NOTHING if structure or global, static or extern
1236 * otherwise.
1237 * @param a_Type The type we're pointing to.
1238 * @param a_Name The member or variable name.
1239 * @internal
1240 */
1241#if ARCH_BITS == 16
1242# define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \
1243 a_Scope union \
1244 { \
1245 BS3XPTR XPtr; \
1246 a_Type __near *pNearTyped; \
1247 } a_Name
1248#elif ARCH_BITS == 32
1249# define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \
1250 a_Scope union \
1251 { \
1252 BS3XPTR XPtr; \
1253 a_Type *pTyped; \
1254 } a_Name
1255#elif ARCH_BITS == 64
1256# define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \
1257 a_Scope union \
1258 { \
1259 BS3XPTR XPtr; \
1260 } a_Name
1261#else
1262# error "ARCH_BITS"
1263#endif
1264
1265/** @def BS3_XPTR_MEMBER
1266 * Defines a pointer member that can be shared by all CPU modes.
1267 *
1268 * @param a_Type The type we're pointing to.
1269 * @param a_Name The member or variable name.
1270 */
1271#define BS3_XPTR_MEMBER(a_Type, a_Name) BS3_XPTR_DEF_INTERNAL(RT_NOTHING, a_Type, a_Name)
1272
1273/** @def BS3_XPTR_AUTO
1274 * Defines a pointer static variable for working with an XPTR.
1275 *
1276 * This is typically used to convert flat pointers into context specific
1277 * pointers.
1278 *
1279 * @param a_Type The type we're pointing to.
1280 * @param a_Name The member or variable name.
1281 */
1282#define BS3_XPTR_AUTO(a_Type, a_Name) BS3_XPTR_DEF_INTERNAL(RT_NOTHING, a_Type, a_Name)
1283
1284/** @def BS3_XPTR_SET_FLAT
1285 * Sets a cross context pointer.
1286 *
1287 * @param a_Type The type we're pointing to.
1288 * @param a_Name The member or variable name.
1289 * @param a_uFlatPtr The flat pointer value to assign. If the x-pointer is
1290 * used in real mode, this must be less than 1MB.
1291 * Otherwise the limit is 16MB (due to selector tiling).
1292 */
1293#define BS3_XPTR_SET_FLAT(a_Type, a_Name, a_uFlatPtr) \
1294 do { a_Name.XPtr.uFlat = (a_uFlatPtr); } while (0)
1295
1296/** @def BS3_XPTR_GET_FLAT
1297 * Gets the flat address of a cross context pointer.
1298 *
1299 * @returns 32-bit flat pointer.
1300 * @param a_Type The type we're pointing to.
1301 * @param a_Name The member or variable name.
1302 */
1303#define BS3_XPTR_GET_FLAT(a_Type, a_Name) (a_Name.XPtr.uFlat)
1304
1305/** @def BS3_XPTR_GET_FLAT_LOW
1306 * Gets the low 16 bits of the flat address.
1307 *
1308 * @returns Low 16 bits of the flat pointer.
1309 * @param a_Type The type we're pointing to.
1310 * @param a_Name The member or variable name.
1311 */
1312#define BS3_XPTR_GET_FLAT_LOW(a_Type, a_Name) (a_Name.XPtr.u.uLow)
1313
1314
1315#if ARCH_BITS == 16
1316
1317/**
1318 * Gets the current ring number.
1319 * @returns Ring number.
1320 */
1321DECLINLINE(uint16_t) Bs3Sel16GetCurRing(void);
1322# pragma aux Bs3Sel16GetCurRing = \
1323 "mov ax, ss" \
1324 "and ax, 3" \
1325 value [ax] modify exact [ax] nomemory;
1326
1327/**
1328 * Converts the high word of a flat pointer into a 16-bit selector.
1329 *
1330 * This makes use of the tiled area. It also handles real mode.
1331 *
1332 * @returns Segment selector value.
1333 * @param uHigh The high part of flat pointer.
1334 * @sa BS3_XPTR_GET, BS3_XPTR_SET
1335 */
1336DECLINLINE(__segment) Bs3Sel16HighFlatPtrToSelector(uint16_t uHigh)
1337{
1338 if (!BS3_MODE_IS_RM_OR_V86(g_bBs3CurrentMode))
1339 return (__segment)(((uHigh << 3) + BS3_SEL_TILED) | Bs3Sel16GetCurRing());
1340 return (__segment)(uHigh << 12);
1341}
1342
1343#endif /* ARCH_BITS == 16 */
1344
1345/** @def BS3_XPTR_GET
1346 * Gets the current context pointer value.
1347 *
1348 * @returns Usable pointer.
1349 * @param a_Type The type we're pointing to.
1350 * @param a_Name The member or variable name.
1351 */
1352#if ARCH_BITS == 16
1353# define BS3_XPTR_GET(a_Type, a_Name) \
1354 ((a_Type BS3_FAR *)BS3_FP_MAKE(Bs3Sel16HighFlatPtrToSelector((a_Name).XPtr.u.uHigh), (a_Name).pNearTyped))
1355#elif ARCH_BITS == 32
1356# define BS3_XPTR_GET(a_Type, a_Name) ((a_Name).pTyped)
1357#elif ARCH_BITS == 64
1358# define BS3_XPTR_GET(a_Type, a_Name) ((a_Type *)(uintptr_t)(a_Name).XPtr.uFlat)
1359#else
1360# error "ARCH_BITS"
1361#endif
1362
1363/** @def BS3_XPTR_SET
1364 * Gets the current context pointer value.
1365 *
1366 * @returns Usable pointer.
1367 * @param a_Type The type we're pointing to.
1368 * @param a_Name The member or variable name.
1369 * @param a_pValue The new pointer value, current context pointer.
1370 */
1371#if ARCH_BITS == 16
1372# define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \
1373 do { \
1374 a_Type BS3_FAR *pTypeCheck = (a_pValue); \
1375 if (BS3_MODE_IS_RM_OR_V86(g_bBs3CurrentMode)) \
1376 (a_Name).XPtr.uFlat = BS3_FP_OFF(pTypeCheck) + ((uint32_t)BS3_FP_SEG(pTypeCheck) << 4); \
1377 else \
1378 { \
1379 (a_Name).XPtr.u.uLow = BS3_FP_OFF(pTypeCheck); \
1380 (a_Name).XPtr.u.uHigh = ((BS3_FP_SEG(pTypeCheck) & UINT16_C(0xfff8)) - BS3_SEL_TILED) >> 3; \
1381 } \
1382 } while (0)
1383#elif ARCH_BITS == 32
1384# define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \
1385 do { (a_Name).pTyped = (a_pValue); } while (0)
1386#elif ARCH_BITS == 64
1387# define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \
1388 do { \
1389 a_Type *pTypeCheck = (a_pValue); \
1390 (a_Name).XPtr.uFlat = (uint32_t)(uintptr_t)pTypeCheck; \
1391 } while (0)
1392#else
1393# error "ARCH_BITS"
1394#endif
1395
1396
1397/** @def BS3_XPTR_IS_NULL
1398 * Checks if the cross context pointer is NULL.
1399 *
1400 * @returns true if NULL, false if not.
1401 * @param a_Type The type we're pointing to.
1402 * @param a_Name The member or variable name.
1403 */
1404#define BS3_XPTR_IS_NULL(a_Type, a_Name) ((a_Name).XPtr.uFlat == 0)
1405
1406/**
1407 * Gets a working pointer from a flat address.
1408 *
1409 * @returns Current context pointer.
1410 * @param uFlatPtr The flat address to convert (32-bit or 64-bit).
1411 */
1412DECLINLINE(void BS3_FAR *) Bs3XptrFlatToCurrent(RTCCUINTXREG uFlatPtr)
1413{
1414 BS3_XPTR_AUTO(void, pTmp);
1415 BS3_XPTR_SET_FLAT(void, pTmp, uFlatPtr);
1416 return BS3_XPTR_GET(void, pTmp);
1417}
1418
1419/** @} */
1420
1421
1422
1423/** @defgroup grp_bs3kit_cmn Common Functions and Data
1424 *
1425 * The common functions comes in three variations: 16-bit, 32-bit and 64-bit.
1426 * Templated code uses the #BS3_CMN_NM macro to mangle the name according to the
1427 * desired
1428 *
1429 * @{
1430 */
1431
1432/** @def BS3_CMN_PROTO_INT
1433 * Internal macro for prototyping all the variations of a common function.
1434 * @param a_RetType The return type.
1435 * @param a_Name The function basename.
1436 * @param a_Params The parameter list (in parentheses).
1437 * @sa BS3_CMN_PROTO_STUB, BS3_CMN_PROTO_NOSB
1438 */
1439#if ARCH_BITS == 16
1440# ifndef BS3_USE_ALT_16BIT_TEXT_SEG
1441# define BS3_CMN_PROTO_INT(a_RetType, a_Name, a_Params) \
1442 BS3_DECL_NEAR(a_RetType) BS3_CMN_NM(a_Name) a_Params; \
1443 BS3_DECL_FAR(a_RetType) BS3_CMN_FAR_NM(a_Name) a_Params
1444# else
1445# define BS3_CMN_PROTO_INT(a_RetType, a_Name, a_Params) \
1446 BS3_DECL_FAR(a_RetType) BS3_CMN_FAR_NM(a_Name) a_Params
1447# endif
1448#else
1449# define BS3_CMN_PROTO_INT(a_RetType, a_Name, a_Params) \
1450 BS3_DECL_NEAR(a_RetType) BS3_CMN_NM(a_Name) a_Params
1451#endif
1452
1453/** @def BS3_CMN_PROTO_STUB
1454 * Macro for prototyping all the variations of a common function with automatic
1455 * near -> far stub.
1456 *
1457 * @param a_RetType The return type.
1458 * @param a_Name The function basename.
1459 * @param a_Params The parameter list (in parentheses).
1460 * @sa BS3_CMN_PROTO_NOSB
1461 */
1462#define BS3_CMN_PROTO_STUB(a_RetType, a_Name, a_Params) BS3_CMN_PROTO_INT(a_RetType, a_Name, a_Params)
1463
1464/** @def BS3_CMN_PROTO_NOSB
1465 * Macro for prototyping all the variations of a common function without any
1466 * near > far stub.
1467 *
1468 * @param a_RetType The return type.
1469 * @param a_Name The function basename.
1470 * @param a_Params The parameter list (in parentheses).
1471 * @sa BS3_CMN_PROTO_STUB
1472 */
1473#define BS3_CMN_PROTO_NOSB(a_RetType, a_Name, a_Params) BS3_CMN_PROTO_INT(a_RetType, a_Name, a_Params)
1474
1475/** @def BS3_CMN_PROTO_FARSTUB
1476 * Macro for prototyping all the variations of a common function with automatic
1477 * far -> near stub.
1478 *
1479 * @param a_cbParam16 The size of the 16-bit parameter list in bytes.
1480 * @param a_RetType The return type.
1481 * @param a_Name The function basename.
1482 * @param a_Params The parameter list (in parentheses).
1483 * @sa BS3_CMN_PROTO_STUB
1484 */
1485#define BS3_CMN_PROTO_FARSTUB(a_cbParam16, a_RetType, a_Name, a_Params) BS3_CMN_PROTO_INT(a_RetType, a_Name, a_Params)
1486
1487
1488/** @def BS3_CMN_DEF
1489 * Macro for defining a common function.
1490 *
1491 * This makes 16-bit common function far, while 32-bit and 64-bit are near.
1492 *
1493 * @param a_RetType The return type.
1494 * @param a_Name The function basename.
1495 * @param a_Params The parameter list (in parentheses).
1496 */
1497#if ARCH_BITS == 16
1498# define BS3_CMN_DEF(a_RetType, a_Name, a_Params) \
1499 BS3_DECL_FAR(a_RetType) BS3_CMN_FAR_NM(a_Name) a_Params
1500#else
1501# define BS3_CMN_DEF(a_RetType, a_Name, a_Params) \
1502 BS3_DECL_NEAR(a_RetType) BS3_CMN_NM(a_Name) a_Params
1503#endif
1504
1505/** @def BS3_ASSERT
1506 * Assert that an expression is true.
1507 *
1508 * Calls Bs3Panic if false and it's a strict build. Does nothing in
1509 * non-strict builds. */
1510#ifdef BS3_STRICT
1511# define BS3_ASSERT(a_Expr) do { if (!!(a_Expr)) { /* likely */ } else { Bs3Panic(); } } while (0) /**< @todo later */
1512#else
1513# define BS3_ASSERT(a_Expr) do { } while (0)
1514#endif
1515
1516/**
1517 * Panic, never return.
1518 *
1519 * The current implementation will only halt the CPU.
1520 */
1521BS3_CMN_PROTO_NOSB(DECL_NO_RETURN(void), Bs3Panic,(void));
1522#if !defined(BS3_KIT_WITH_NO_RETURN) && defined(__WATCOMC__)
1523# pragma aux Bs3Panic_c16 __aborts
1524# pragma aux Bs3Panic_f16 __aborts
1525# pragma aux Bs3Panic_c32 __aborts
1526#endif
1527
1528
1529/**
1530 * Translate a mode into a string.
1531 *
1532 * @returns Pointer to read-only mode name string.
1533 * @param bMode The mode value (BS3_MODE_XXX).
1534 */
1535BS3_CMN_PROTO_STUB(const char BS3_FAR *, Bs3GetModeName,(uint8_t bMode));
1536
1537/**
1538 * Translate a mode into a short lower case string.
1539 *
1540 * @returns Pointer to read-only short mode name string.
1541 * @param bMode The mode value (BS3_MODE_XXX).
1542 */
1543BS3_CMN_PROTO_STUB(const char BS3_FAR *, Bs3GetModeNameShortLower,(uint8_t bMode));
1544
1545/** CPU vendors. */
1546typedef enum BS3CPUVENDOR
1547{
1548 BS3CPUVENDOR_INVALID = 0,
1549 BS3CPUVENDOR_INTEL,
1550 BS3CPUVENDOR_AMD,
1551 BS3CPUVENDOR_VIA,
1552 BS3CPUVENDOR_CYRIX,
1553 BS3CPUVENDOR_SHANGHAI,
1554 BS3CPUVENDOR_HYGON,
1555 BS3CPUVENDOR_UNKNOWN,
1556 BS3CPUVENDOR_END
1557} BS3CPUVENDOR;
1558
1559/**
1560 * Tries to detect the CPU vendor.
1561 *
1562 * @returns CPU vendor.
1563 */
1564BS3_CMN_PROTO_STUB(BS3CPUVENDOR, Bs3GetCpuVendor,(void));
1565
1566/**
1567 * Shutdown the system, never returns.
1568 *
1569 * This currently only works for VMs. When running on real systems it will
1570 * just halt the CPU.
1571 */
1572BS3_CMN_PROTO_NOSB(void, Bs3Shutdown,(void));
1573
1574/**
1575 * Prints a 32-bit unsigned value as decimal to the screen.
1576 *
1577 * @param uValue The 32-bit value.
1578 */
1579BS3_CMN_PROTO_NOSB(void, Bs3PrintU32,(uint32_t uValue));
1580
1581/**
1582 * Prints a 32-bit unsigned value as hex to the screen.
1583 *
1584 * @param uValue The 32-bit value.
1585 */
1586BS3_CMN_PROTO_NOSB(void, Bs3PrintX32,(uint32_t uValue));
1587
1588/**
1589 * Formats and prints a string to the screen.
1590 *
1591 * See #Bs3StrFormatV for supported format types.
1592 *
1593 * @param pszFormat The format string.
1594 * @param ... Format arguments.
1595 */
1596BS3_CMN_PROTO_STUB(size_t, Bs3Printf,(const char BS3_FAR *pszFormat, ...));
1597
1598/**
1599 * Formats and prints a string to the screen, va_list version.
1600 *
1601 * See #Bs3StrFormatV for supported format types.
1602 *
1603 * @param pszFormat The format string.
1604 * @param va Format arguments.
1605 */
1606BS3_CMN_PROTO_STUB(size_t, Bs3PrintfV,(const char BS3_FAR *pszFormat, va_list BS3_FAR va));
1607
1608/**
1609 * Prints a string to the screen.
1610 *
1611 * @param pszString The string to print.
1612 */
1613BS3_CMN_PROTO_STUB(void, Bs3PrintStr,(const char BS3_FAR *pszString));
1614
1615/**
1616 * Prints a string to the screen.
1617 *
1618 * @param pszString The string to print. Any terminator charss will be printed.
1619 * @param cchString The exact number of characters to print.
1620 */
1621BS3_CMN_PROTO_NOSB(void, Bs3PrintStrN,(const char BS3_FAR *pszString, size_t cchString));
1622
1623/**
1624 * Prints a char to the screen.
1625 *
1626 * @param ch The character to print.
1627 */
1628BS3_CMN_PROTO_NOSB(void, Bs3PrintChr,(char ch));
1629
1630
1631/**
1632 * An output function for #Bs3StrFormatV.
1633 *
1634 * @returns Number of characters written.
1635 * @param ch The character to write. Zero in the final call.
1636 * @param pvUser User argument supplied to #Bs3StrFormatV.
1637 */
1638typedef BS3_DECL_CALLBACK(size_t) FNBS3STRFORMATOUTPUT(char ch, void BS3_FAR *pvUser);
1639/** Pointer to an output function for #Bs3StrFormatV. */
1640typedef FNBS3STRFORMATOUTPUT *PFNBS3STRFORMATOUTPUT;
1641
1642/**
1643 * Formats a string, sending the output to @a pfnOutput.
1644 *
1645 * Supported types:
1646 * - %RI8, %RI16, %RI32, %RI64
1647 * - %RU8, %RU16, %RU32, %RU64
1648 * - %RX8, %RX16, %RX32, %RX64
1649 * - %i, %d
1650 * - %u
1651 * - %x
1652 * - %c
1653 * - %p (far pointer)
1654 * - %s (far pointer)
1655 *
1656 * @returns Sum of @a pfnOutput return values.
1657 * @param pszFormat The format string.
1658 * @param va Format arguments.
1659 * @param pfnOutput The output function.
1660 * @param pvUser The user argument for the output function.
1661 */
1662BS3_CMN_PROTO_STUB(size_t, Bs3StrFormatV,(const char BS3_FAR *pszFormat, va_list BS3_FAR va,
1663 PFNBS3STRFORMATOUTPUT pfnOutput, void BS3_FAR *pvUser));
1664
1665/**
1666 * Formats a string into a buffer.
1667 *
1668 * See #Bs3StrFormatV for supported format types.
1669 *
1670 * @returns The length of the formatted string (excluding terminator).
1671 * This will be higher or equal to @c cbBuf in case of an overflow.
1672 * @param pszBuf The output buffer.
1673 * @param cbBuf The size of the output buffer.
1674 * @param pszFormat The format string.
1675 * @param va Format arguments.
1676 */
1677BS3_CMN_PROTO_STUB(size_t, Bs3StrPrintfV,(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, va_list BS3_FAR va));
1678
1679/**
1680 * Formats a string into a buffer.
1681 *
1682 * See #Bs3StrFormatV for supported format types.
1683 *
1684 * @returns The length of the formatted string (excluding terminator).
1685 * This will be higher or equal to @c cbBuf in case of an overflow.
1686 * @param pszBuf The output buffer.
1687 * @param cbBuf The size of the output buffer.
1688 * @param pszFormat The format string.
1689 * @param ... Format arguments.
1690 */
1691BS3_CMN_PROTO_STUB(size_t, Bs3StrPrintf,(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, ...));
1692
1693
1694/**
1695 * Finds the length of a zero terminated string.
1696 *
1697 * @returns String length in chars/bytes.
1698 * @param pszString The string to examine.
1699 */
1700BS3_CMN_PROTO_STUB(size_t, Bs3StrLen,(const char BS3_FAR *pszString));
1701
1702/**
1703 * Finds the length of a zero terminated string, but with a max length.
1704 *
1705 * @returns String length in chars/bytes, or @a cchMax if no zero-terminator
1706 * was found before we reached the limit.
1707 * @param pszString The string to examine.
1708 * @param cchMax The max length to examine.
1709 */
1710BS3_CMN_PROTO_STUB(size_t, Bs3StrNLen,(const char BS3_FAR *pszString, size_t cchMax));
1711
1712/**
1713 * CRT style unsafe strcpy.
1714 *
1715 * @returns pszDst.
1716 * @param pszDst The destination buffer. Must be large enough to
1717 * hold the source string.
1718 * @param pszSrc The source string.
1719 */
1720BS3_CMN_PROTO_STUB(char BS3_FAR *, Bs3StrCpy,(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc));
1721
1722/**
1723 * CRT style memcpy.
1724 *
1725 * @returns pvDst
1726 * @param pvDst The destination buffer.
1727 * @param pvSrc The source buffer.
1728 * @param cbToCopy The number of bytes to copy.
1729 */
1730BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemCpy,(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy));
1731
1732/**
1733 * GNU (?) style mempcpy.
1734 *
1735 * @returns pvDst + cbCopy
1736 * @param pvDst The destination buffer.
1737 * @param pvSrc The source buffer.
1738 * @param cbToCopy The number of bytes to copy.
1739 */
1740BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemPCpy,(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy));
1741
1742/**
1743 * CRT style memmove (overlapping buffers is fine).
1744 *
1745 * @returns pvDst
1746 * @param pvDst The destination buffer.
1747 * @param pvSrc The source buffer.
1748 * @param cbToCopy The number of bytes to copy.
1749 */
1750BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemMove,(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy));
1751
1752/**
1753 * BSD style bzero.
1754 *
1755 * @param pvDst The buffer to be zeroed.
1756 * @param cbDst The number of bytes to zero.
1757 */
1758BS3_CMN_PROTO_NOSB(void, Bs3MemZero,(void BS3_FAR *pvDst, size_t cbDst));
1759
1760/**
1761 * CRT style memset.
1762 *
1763 * @param pvDst The buffer to be fill.
1764 * @param bFiller The filler byte.
1765 * @param cbDst The number of bytes to fill.
1766 */
1767BS3_CMN_PROTO_NOSB(void, Bs3MemSet,(void BS3_FAR *pvDst, uint8_t bFiller, size_t cbDst));
1768
1769/**
1770 * CRT style memchr.
1771 *
1772 * @param pvHaystack The memory to scan for @a bNeedle.
1773 * @param bNeedle The byte to search for.
1774 * @param cbHaystack The amount of memory to search.
1775 */
1776BS3_CMN_PROTO_NOSB(void BS3_FAR *, Bs3MemChr,(void const BS3_FAR *pvHaystack, uint8_t bNeedle, size_t cbHaystack));
1777
1778/**
1779 * CRT style memcmp.
1780 *
1781 * @returns 0 if equal. Negative if the left side is 'smaller' than the right
1782 * side, and positive in the other case.
1783 * @param pv1 The left hand memory.
1784 * @param pv2 The right hand memory.
1785 * @param cb The number of bytes to compare.
1786 */
1787BS3_CMN_PROTO_NOSB(int, Bs3MemCmp,(void const BS3_FAR *pv1, void const BS3_FAR *pv2, size_t cb));
1788
1789BS3_CMN_PROTO_STUB(void, Bs3UInt64Div,(RTUINT64U uDividend, RTUINT64U uDivisor, RTUINT64U BS3_FAR *paQuotientReminder));
1790BS3_CMN_PROTO_STUB(void, Bs3UInt32Div,(RTUINT32U uDividend, RTUINT32U uDivisor, RTUINT32U BS3_FAR *paQuotientReminder));
1791
1792
1793/**
1794 * Converts a protected mode 32-bit far pointer to a 32-bit flat address.
1795 *
1796 * @returns 32-bit flat address.
1797 * @param off The segment offset.
1798 * @param uSel The protected mode segment selector.
1799 */
1800BS3_CMN_PROTO_STUB(uint32_t, Bs3SelProtFar32ToFlat32,(uint32_t off, uint16_t uSel));
1801
1802/**
1803 * Converts a current mode 32-bit far pointer to a 32-bit flat address.
1804 *
1805 * @returns 32-bit flat address.
1806 * @param off The segment offset.
1807 * @param uSel The current mode segment selector.
1808 */
1809BS3_CMN_PROTO_STUB(uint32_t, Bs3SelFar32ToFlat32,(uint32_t off, uint16_t uSel));
1810
1811/**
1812 * Wrapper around Bs3SelFar32ToFlat32 that makes it easier to use in tight
1813 * assembly spots.
1814 *
1815 * @returns 32-bit flat address.
1816 * @param off The segment offset.
1817 * @param uSel The current mode segment selector.
1818 * @remarks All register are preserved, except return.
1819 * @remarks No 20h scratch space required in 64-bit mode.
1820 */
1821BS3_CMN_PROTO_FARSTUB(6, uint32_t, Bs3SelFar32ToFlat32NoClobber,(uint32_t off, uint16_t uSel));
1822
1823/**
1824 * Converts a real mode code segment to a protected mode code segment selector.
1825 *
1826 * @returns protected mode segment selector.
1827 * @param uRealSeg Real mode code segment.
1828 * @remarks All register are preserved, except return and parameter.
1829 */
1830BS3_CMN_PROTO_NOSB(uint16_t, Bs3SelRealModeCodeToProtMode,(uint16_t uRealSeg));
1831
1832/**
1833 * Converts a real mode code segment to a protected mode code segment selector.
1834 *
1835 * @returns protected mode segment selector.
1836 * @param uProtSel Real mode code segment.
1837 * @remarks All register are preserved, except return and parameter.
1838 */
1839BS3_CMN_PROTO_NOSB(uint16_t, Bs3SelProtModeCodeToRealMode,(uint16_t uProtSel));
1840
1841/**
1842 * Converts a flat code address to a real mode segment and offset.
1843 *
1844 * @returns Far real mode address (high 16-bit is segment, low is offset).
1845 * @param uFlatAddr Flat code address.
1846 * @remarks All register are preserved, except return and parameter.
1847 */
1848BS3_CMN_PROTO_NOSB(uint32_t, Bs3SelFlatCodeToRealMode,(uint32_t uFlatAddr));
1849
1850/**
1851 * Converts a flat code address to a protected mode 16-bit far pointer (ring-0).
1852 *
1853 * @returns Far 16-bit protected mode address (high 16-bit is segment selector,
1854 * low is segment offset).
1855 * @param uFlatAddr Flat code address.
1856 * @remarks All register are preserved, except return and parameter.
1857 */
1858BS3_CMN_PROTO_NOSB(uint32_t, Bs3SelFlatCodeToProtFar16,(uint32_t uFlatAddr));
1859
1860/**
1861 * Converts a far 16:16 real mode (code) address to a flat address.
1862 *
1863 * @returns 32-bit flat address.
1864 * @param uFar1616 Far real mode address (high 16-bit is segment, low
1865 * is offset).
1866 * @remarks All register are preserved, except return.
1867 * @remarks No 20h scratch space required in 64-bit mode.
1868 * @remarks Exactly the same as Bs3SelRealModeDataToFlat, except for param.
1869 */
1870BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelRealModeCodeToFlat,(PFNBS3FARADDRCONV uFar1616));
1871
1872/**
1873 * Converts a flat data address to a real mode segment and offset.
1874 *
1875 * @returns Far real mode address (high 16-bit is segment, low is offset)
1876 * @param uFlatAddr Flat code address.
1877 * @remarks All register are preserved, except return.
1878 * @remarks No 20h scratch space required in 64-bit mode.
1879 */
1880BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelFlatDataToRealMode,(uint32_t uFlatAddr));
1881
1882/**
1883 * Converts a flat data address to a real mode segment and offset.
1884 *
1885 * @returns Far 16-bit protected mode address (high 16-bit is segment selector,
1886 * low is segment offset).
1887 * @param uFlatAddr Flat code address.
1888 * @remarks All register are preserved, except return.
1889 * @remarks No 20h scratch space required in 64-bit mode.
1890 */
1891BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelFlatDataToProtFar16,(uint32_t uFlatAddr));
1892
1893/**
1894 * Converts a far 16:16 data address to a real mode segment and offset.
1895 *
1896 * @returns Far real mode address (high 16-bit is segment, low is offset)
1897 * @param uFar1616 Far 16-bit protected mode address (high 16-bit is
1898 * segment selector, low is segment offset).
1899 * @remarks All register are preserved, except return.
1900 * @remarks No 20h scratch space required in 64-bit mode.
1901 */
1902BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelProtFar16DataToRealMode,(uint32_t uFar1616));
1903
1904/**
1905 * Converts a far 16:16 real mode address to a 16-bit protected mode address.
1906 *
1907 * @returns Far real mode address (high 16-bit is segment, low is offset)
1908 * @param uFar1616 Far real mode address (high 16-bit is segment, low
1909 * is offset).
1910 * @remarks All register are preserved, except return.
1911 * @remarks No 20h scratch space required in 64-bit mode.
1912 */
1913BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelRealModeDataToProtFar16,(uint32_t uFar1616));
1914
1915/**
1916 * Converts a far 16:16 data address to a flat 32-bit address.
1917 *
1918 * @returns 32-bit flat address.
1919 * @param uFar1616 Far 16-bit protected mode address (high 16-bit is
1920 * segment selector, low is segment offset).
1921 * @remarks All register are preserved, except return.
1922 * @remarks No 20h scratch space required in 64-bit mode.
1923 */
1924BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelProtFar16DataToFlat,(uint32_t uFar1616));
1925
1926/**
1927 * Converts a far 16:16 real mode address to a flat address.
1928 *
1929 * @returns 32-bit flat address.
1930 * @param uFar1616 Far real mode address (high 16-bit is segment, low
1931 * is offset).
1932 * @remarks All register are preserved, except return.
1933 * @remarks No 20h scratch space required in 64-bit mode.
1934 */
1935BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelRealModeDataToFlat,(uint32_t uFar1616));
1936
1937/**
1938 * Converts a link-time pointer to a current context pointer.
1939 *
1940 * @returns Converted pointer.
1941 * @param pvLnkPtr The pointer the linker produced.
1942 */
1943BS3_CMN_PROTO_FARSTUB(4, void BS3_FAR *, Bs3SelLnkPtrToCurPtr,(void BS3_FAR *pvLnkPtr));
1944
1945/**
1946 * Converts a link-time pointer to a flat address.
1947 *
1948 * @returns 32-bit flag address.
1949 * @param pvLnkPtr The pointer the linker produced.
1950 */
1951BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelLnkPtrToFlat,(void BS3_FAR *pvLnkPtr));
1952
1953/**
1954 * Gets a flat address from a working poitner.
1955 *
1956 * @returns flat address (32-bit or 64-bit).
1957 * @param pv Current context pointer.
1958 */
1959DECLINLINE(RTCCUINTXREG) Bs3SelPtrToFlat(void BS3_FAR *pv)
1960{
1961#if ARCH_BITS == 16
1962 return BS3_CMN_FN_NM(Bs3SelFar32ToFlat32)(BS3_FP_OFF(pv), BS3_FP_SEG(pv));
1963#else
1964 return (uintptr_t)pv;
1965#endif
1966}
1967
1968/**
1969 * Sets up a 16-bit read-write data selector with ring-3 access and 64KB limit.
1970 *
1971 * @param pDesc Pointer to the descriptor table entry.
1972 * @param uBaseAddr The base address of the descriptor.
1973 */
1974BS3_CMN_PROTO_STUB(void, Bs3SelSetup16BitData,(X86DESC BS3_FAR *pDesc, uint32_t uBaseAddr));
1975
1976/**
1977 * Sets up a 16-bit execute-read selector with a 64KB limit.
1978 *
1979 * @param pDesc Pointer to the descriptor table entry.
1980 * @param uBaseAddr The base address of the descriptor.
1981 * @param bDpl The descriptor privilege level.
1982 */
1983BS3_CMN_PROTO_STUB(void, Bs3SelSetup16BitCode,(X86DESC BS3_FAR *pDesc, uint32_t uBaseAddr, uint8_t bDpl));
1984
1985/**
1986 * Sets up a 32-bit execute-read selector with a user specified limit.
1987 *
1988 * @param pDesc Pointer to the descriptor table entry.
1989 * @param uBaseAddr The base address of the descriptor.
1990 * @param uLimit The limit. (This is included here and not in the 16-bit
1991 * functions because we're more likely to want to set it
1992 * than for 16-bit selectors.)
1993 * @param bDpl The descriptor privilege level.
1994 */
1995BS3_CMN_PROTO_STUB(void, Bs3SelSetup32BitCode,(X86DESC BS3_FAR *pDesc, uint32_t uBaseAddr, uint32_t uLimit, uint8_t bDpl));
1996
1997
1998/**
1999 * Slab control structure list head.
2000 *
2001 * The slabs on the list must all have the same chunk size.
2002 */
2003typedef struct BS3SLABHEAD
2004{
2005 /** Pointer to the first slab. */
2006 BS3_XPTR_MEMBER(struct BS3SLABCTL, pFirst);
2007 /** The allocation chunk size. */
2008 uint16_t cbChunk;
2009 /** Number of slabs in the list. */
2010 uint16_t cSlabs;
2011 /** Number of chunks in the list. */
2012 uint32_t cChunks;
2013 /** Number of free chunks. */
2014 uint32_t cFreeChunks;
2015} BS3SLABHEAD;
2016AssertCompileSize(BS3SLABHEAD, 16);
2017/** Pointer to a slab list head. */
2018typedef BS3SLABHEAD BS3_FAR *PBS3SLABHEAD;
2019
2020/**
2021 * Allocation slab control structure.
2022 *
2023 * This may live at the start of the slab for 4KB slabs, while in a separate
2024 * static location for the larger ones.
2025 */
2026typedef struct BS3SLABCTL
2027{
2028 /** Pointer to the next slab control structure in this list. */
2029 BS3_XPTR_MEMBER(struct BS3SLABCTL, pNext);
2030 /** Pointer to the slab list head. */
2031 BS3_XPTR_MEMBER(BS3SLABHEAD, pHead);
2032 /** The base address of the slab. */
2033 BS3_XPTR_MEMBER(uint8_t, pbStart);
2034 /** Number of chunks in this slab. */
2035 uint16_t cChunks;
2036 /** Number of currently free chunks. */
2037 uint16_t cFreeChunks;
2038 /** The chunk size. */
2039 uint16_t cbChunk;
2040 /** The shift count corresponding to cbChunk.
2041 * This is for turning a chunk number into a byte offset and vice versa. */
2042 uint16_t cChunkShift;
2043 /** Bitmap where set bits indicates allocated blocks (variable size,
2044 * multiple of 4). */
2045 uint8_t bmAllocated[4];
2046} BS3SLABCTL;
2047/** Pointer to a bs3kit slab control structure. */
2048typedef BS3SLABCTL BS3_FAR *PBS3SLABCTL;
2049
2050/** The chunks must all be in the same 16-bit segment tile. */
2051#define BS3_SLAB_ALLOC_F_SAME_TILE UINT16_C(0x0001)
2052
2053/**
2054 * Initializes a slab.
2055 *
2056 * @param pSlabCtl The slab control structure to initialize.
2057 * @param cbSlabCtl The size of the slab control structure.
2058 * @param uFlatSlabPtr The base address of the slab.
2059 * @param cbSlab The size of the slab.
2060 * @param cbChunk The chunk size.
2061 */
2062BS3_CMN_PROTO_STUB(void, Bs3SlabInit,(PBS3SLABCTL pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr,
2063 uint32_t cbSlab, uint16_t cbChunk));
2064
2065/**
2066 * Allocates one chunk from a slab.
2067 *
2068 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
2069 * @param pSlabCtl The slab control structure to allocate from.
2070 */
2071BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3SlabAlloc,(PBS3SLABCTL pSlabCtl));
2072
2073/**
2074 * Allocates one or more chunks rom a slab.
2075 *
2076 * @returns Pointer to the request number of chunks on success, NULL if we're
2077 * out of chunks.
2078 * @param pSlabCtl The slab control structure to allocate from.
2079 * @param cChunks The number of contiguous chunks we want.
2080 * @param fFlags Flags, see BS3_SLAB_ALLOC_F_XXX
2081 */
2082BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3SlabAllocEx,(PBS3SLABCTL pSlabCtl, uint16_t cChunks, uint16_t fFlags));
2083
2084/**
2085 * Frees one or more chunks from a slab.
2086 *
2087 * @returns Number of chunks actually freed. When correctly used, this will
2088 * match the @a cChunks parameter, of course.
2089 * @param pSlabCtl The slab control structure to free from.
2090 * @param uFlatChunkPtr The flat address of the chunks to free.
2091 * @param cChunks The number of contiguous chunks to free.
2092 */
2093BS3_CMN_PROTO_STUB(uint16_t, Bs3SlabFree,(PBS3SLABCTL pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks));
2094
2095
2096/**
2097 * Initializes the given slab list head.
2098 *
2099 * @param pHead The slab list head.
2100 * @param cbChunk The chunk size.
2101 */
2102BS3_CMN_PROTO_STUB(void, Bs3SlabListInit,(PBS3SLABHEAD pHead, uint16_t cbChunk));
2103
2104/**
2105 * Adds an initialized slab control structure to the list.
2106 *
2107 * @param pHead The slab list head to add it to.
2108 * @param pSlabCtl The slab control structure to add.
2109 */
2110BS3_CMN_PROTO_STUB(void, Bs3SlabListAdd,(PBS3SLABHEAD pHead, PBS3SLABCTL pSlabCtl));
2111
2112/**
2113 * Allocates one chunk.
2114 *
2115 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
2116 * @param pHead The slab list to allocate from.
2117 */
2118BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3SlabListAlloc,(PBS3SLABHEAD pHead));
2119
2120/**
2121 * Allocates one or more chunks.
2122 *
2123 * @returns Pointer to the request number of chunks on success, NULL if we're
2124 * out of chunks.
2125 * @param pHead The slab list to allocate from.
2126 * @param cChunks The number of contiguous chunks we want.
2127 * @param fFlags Flags, see BS3_SLAB_ALLOC_F_XXX
2128 */
2129BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3SlabListAllocEx,(PBS3SLABHEAD pHead, uint16_t cChunks, uint16_t fFlags));
2130
2131/**
2132 * Frees one or more chunks from a slab list.
2133 *
2134 * @param pHead The slab list to allocate from.
2135 * @param pvChunks Pointer to the first chunk to free.
2136 * @param cChunks The number of contiguous chunks to free.
2137 */
2138BS3_CMN_PROTO_STUB(void, Bs3SlabListFree,(PBS3SLABHEAD pHead, void BS3_FAR *pvChunks, uint16_t cChunks));
2139
2140/**
2141 * Allocation addressing constraints.
2142 */
2143typedef enum BS3MEMKIND
2144{
2145 /** Invalid zero type. */
2146 BS3MEMKIND_INVALID = 0,
2147 /** Real mode addressable memory. */
2148 BS3MEMKIND_REAL,
2149 /** Memory addressable using the 16-bit protected mode tiling. */
2150 BS3MEMKIND_TILED,
2151 /** Memory addressable using 32-bit flat addressing. */
2152 BS3MEMKIND_FLAT32,
2153 /** Memory addressable using 64-bit flat addressing. */
2154 BS3MEMKIND_FLAT64,
2155 /** End of valid types. */
2156 BS3MEMKIND_END,
2157} BS3MEMKIND;
2158
2159/**
2160 * Allocates low memory.
2161 *
2162 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
2163 * @param enmKind The kind of addressing constraints imposed on the
2164 * allocation.
2165 * @param cb How much to allocate. Must be 4KB or less.
2166 */
2167BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemAlloc,(BS3MEMKIND enmKind, size_t cb));
2168
2169/**
2170 * Allocates zero'ed memory.
2171 *
2172 * @param enmKind The kind of addressing constraints imposed on the
2173 * allocation.
2174 * @param cb How much to allocate. Must be 4KB or less.
2175 */
2176BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemAllocZ,(BS3MEMKIND enmKind, size_t cb));
2177
2178/**
2179 * Frees memory.
2180 *
2181 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
2182 * @param pv The memory to free (returned by #Bs3MemAlloc).
2183 * @param cb The size of the allocation.
2184 */
2185BS3_CMN_PROTO_STUB(void, Bs3MemFree,(void BS3_FAR *pv, size_t cb));
2186
2187/**
2188 * Allocates a page with non-present pages on each side.
2189 *
2190 * @returns Pointer to the usable page. NULL on failure. Use
2191 * Bs3MemGuardedTestPageFree to free the allocation.
2192 * @param enmKind The kind of addressing constraints imposed on the
2193 * allocation.
2194 */
2195BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemGuardedTestPageAlloc,(BS3MEMKIND enmKind));
2196
2197/**
2198 * Allocates a page with pages on each side to the @a fPte specification.
2199 *
2200 * @returns Pointer to the usable page. NULL on failure. Use
2201 * Bs3MemGuardedTestPageFree to free the allocation.
2202 * @param enmKind The kind of addressing constraints imposed on the
2203 * allocation.
2204 * @param fPte The page table entry specification for the guard pages.
2205 */
2206BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemGuardedTestPageAllocEx,(BS3MEMKIND enmKind, uint64_t fPte));
2207
2208/**
2209 * Frees guarded page allocated by Bs3MemGuardedTestPageAlloc or
2210 * Bs3MemGuardedTestPageAllocEx.
2211 *
2212 * @param pvGuardedPage Pointer returned by Bs3MemGuardedTestPageAlloc or
2213 * Bs3MemGuardedTestPageAllocEx. NULL is ignored.
2214 */
2215BS3_CMN_PROTO_STUB(void, Bs3MemGuardedTestPageFree,(void BS3_FAR *pvGuardedPage));
2216
2217/**
2218 * Print all heap info.
2219 */
2220BS3_CMN_PROTO_STUB(void, Bs3MemPrintInfo, (void));
2221
2222/** The end RAM address below 4GB (approximately). */
2223extern uint32_t g_uBs3EndOfRamBelow4G;
2224/** The end RAM address above 4GB, zero if no memory above 4GB. */
2225extern uint64_t g_uBs3EndOfRamAbove4G;
2226
2227
2228/**
2229 * Enables the A20 gate.
2230 */
2231BS3_CMN_PROTO_NOSB(void, Bs3A20Enable,(void));
2232
2233/**
2234 * Enables the A20 gate via the keyboard controller
2235 */
2236BS3_CMN_PROTO_NOSB(void, Bs3A20EnableViaKbd,(void));
2237
2238/**
2239 * Enables the A20 gate via the PS/2 control port A.
2240 */
2241BS3_CMN_PROTO_NOSB(void, Bs3A20EnableViaPortA,(void));
2242
2243/**
2244 * Disables the A20 gate.
2245 */
2246BS3_CMN_PROTO_NOSB(void, Bs3A20Disable,(void));
2247
2248/**
2249 * Disables the A20 gate via the keyboard controller
2250 */
2251BS3_CMN_PROTO_NOSB(void, Bs3A20DisableViaKbd,(void));
2252
2253/**
2254 * Disables the A20 gate via the PS/2 control port A.
2255 */
2256BS3_CMN_PROTO_NOSB(void, Bs3A20DisableViaPortA,(void));
2257
2258
2259/**
2260 * Initializes root page tables for page protected mode (PP16, PP32).
2261 *
2262 * @returns IPRT status code.
2263 * @remarks Must not be called in real-mode!
2264 */
2265BS3_CMN_PROTO_STUB(int, Bs3PagingInitRootForPP,(void));
2266
2267/**
2268 * Initializes root page tables for PAE page protected mode (PAE16, PAE32).
2269 *
2270 * @returns IPRT status code.
2271 * @remarks The default long mode page tables depends on the PAE ones.
2272 * @remarks Must not be called in real-mode!
2273 */
2274BS3_CMN_PROTO_STUB(int, Bs3PagingInitRootForPAE,(void));
2275
2276/**
2277 * Initializes root page tables for long mode (LM16, LM32, LM64).
2278 *
2279 * @returns IPRT status code.
2280 * @remarks The default long mode page tables depends on the PAE ones.
2281 * @remarks Must not be called in real-mode!
2282 */
2283BS3_CMN_PROTO_STUB(int, Bs3PagingInitRootForLM,(void));
2284
2285/**
2286 * Maps all RAM above 4GB into the long mode page tables.
2287 *
2288 * This requires Bs3PagingInitRootForLM to have been called first.
2289 *
2290 * @returns IPRT status code.
2291 * @retval VERR_WRONG_ORDER if Bs3PagingInitRootForLM wasn't called.
2292 * @retval VINF_ALREADY_INITIALIZED if already called or someone mapped
2293 * something else above 4GiB already.
2294 * @retval VERR_OUT_OF_RANGE if too much RAM (more than 2^47 bytes).
2295 * @retval VERR_NO_MEMORY if no more memory for paging structures.
2296 * @retval VERR_UNSUPPORTED_ALIGNMENT if the bs3kit allocator malfunctioned and
2297 * didn't give us page aligned memory as it should.
2298 *
2299 * @param puFailurePoint Where to return the address where we encountered
2300 * a failure. Optional.
2301 *
2302 * @remarks Must be called in 32-bit or 64-bit mode as paging structures will be
2303 * allocated using BS3MEMKIND_FLAT32, as there might not be sufficient
2304 * BS3MEMKIND_TILED memory around. (Also, too it's simply too much of
2305 * a bother to deal with 16-bit for something that's long-mode only.)
2306 */
2307BS3_CMN_PROTO_STUB(int, Bs3PagingMapRamAbove4GForLM,(uint64_t *puFailurePoint));
2308
2309/**
2310 * Modifies the page table protection of an address range.
2311 *
2312 * This only works on the lowest level of the page tables in the current mode.
2313 *
2314 * Since we generally use the largest pages available when setting up the
2315 * initial page tables, this function will usually have to allocate and create
2316 * more tables. This may fail if we're low on memory.
2317 *
2318 * @returns IPRT status code.
2319 * @param uFlat The flat address of the first page in the range (rounded
2320 * down nearest page boundrary).
2321 * @param cb The range size from @a pv (rounded up to nearest page boundrary).
2322 * @param fSet Mask of zero or more X86_PTE_XXX values to set for the range.
2323 * @param fClear Mask of zero or more X86_PTE_XXX values to clear for the range.
2324 */
2325BS3_CMN_PROTO_STUB(int, Bs3PagingProtect,(uint64_t uFlat, uint64_t cb, uint64_t fSet, uint64_t fClear));
2326
2327/**
2328 * Modifies the page table protection of an address range.
2329 *
2330 * This only works on the lowest level of the page tables in the current mode.
2331 *
2332 * Since we generally use the largest pages available when setting up the
2333 * initial page tables, this function will usually have to allocate and create
2334 * more tables. This may fail if we're low on memory.
2335 *
2336 * @returns IPRT status code.
2337 * @param pv The address of the first page in the range (rounded
2338 * down nearest page boundrary).
2339 * @param cb The range size from @a pv (rounded up to nearest page boundrary).
2340 * @param fSet Mask of zero or more X86_PTE_XXX values to set for the range.
2341 * @param fClear Mask of zero or more X86_PTE_XXX values to clear for the range.
2342 */
2343BS3_CMN_PROTO_STUB(int, Bs3PagingProtectPtr,(void BS3_FAR *pv, size_t cb, uint64_t fSet, uint64_t fClear));
2344
2345/**
2346 * Aliases (maps) one or more contiguous physical pages to a virtual range.
2347 *
2348 * @returns VBox status code.
2349 * @retval VERR_INVALID_PARAMETER if we're in legacy paging mode and @a uDst or
2350 * @a uPhysToAlias are not compatible with legacy paging.
2351 * @retval VERR_OUT_OF_RANGE if we cannot traverse the page tables in this mode
2352 * (typically real mode or v86, maybe 16-bit PE).
2353 * @retval VERR_NO_MEMORY if we cannot allocate page tables for splitting up
2354 * the necessary large pages. No aliasing was performed.
2355 *
2356 * @param uDst The virtual address to map it at. Rounded down
2357 * to the nearest page (@a cbHowMuch is adjusted
2358 * up).
2359 * @param uPhysToAlias The physical address of the first page in the
2360 * (contiguous) range to map. Chopped down to
2361 * nearest page boundrary (@a cbHowMuch is not
2362 * adjusted).
2363 * @param cbHowMuch How much to map. Rounded up to nearest page.
2364 * @param fPte The PTE flags.
2365 */
2366BS3_CMN_PROTO_STUB(int, Bs3PagingAlias,(uint64_t uDst, uint64_t uPhysToAlias, uint32_t cbHowMuch, uint64_t fPte));
2367
2368/**
2369 * Unaliases memory, i.e. restores the 1:1 mapping.
2370 *
2371 * @returns VBox status code. Cannot fail if @a uDst and @a cbHowMuch specify
2372 * the range of a successful Bs3PagingAlias call, however it may run
2373 * out of memory if it's breaking new ground.
2374 *
2375 * @param uDst The virtual address to restore to 1:1 mapping.
2376 * Rounded down to the nearest page (@a cbHowMuch
2377 * is adjusted up).
2378 * @param cbHowMuch How much to restore. Rounded up to nearest page.
2379 */
2380BS3_CMN_PROTO_STUB(int, Bs3PagingUnalias,(uint64_t uDst, uint32_t cbHowMuch));
2381
2382/**
2383 * Get the pointer to the PTE for the given address.
2384 *
2385 * @returns Pointer to the PTE.
2386 * @param uFlat The flat address of the page which PTE we want.
2387 * @param prc Where to return additional error info. Optional.
2388 */
2389BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3PagingGetPte,(uint64_t uFlat, int *prc));
2390
2391/**
2392 * Paging information for an address.
2393 */
2394typedef struct BS3PAGINGINFO4ADDR
2395{
2396 /** The depth of the system's paging mode.
2397 * This is always 2 for legacy, 3 for PAE and 4 for long mode. */
2398 uint8_t cEntries;
2399 /** The size of the page structures (the entires). */
2400 uint8_t cbEntry;
2401 /** Flags defined for future fun, currently zero. */
2402 uint16_t fFlags;
2403 /** Union display different view on the entry pointers. */
2404 union
2405 {
2406 /** Pointer to the page structure entries, starting with the PTE as 0.
2407 * If large pages are involved, the first entry will be NULL (first two if 1GB
2408 * page). Same if the address is invalid on a higher level. */
2409 uint8_t BS3_FAR *apbEntries[4];
2410 /** Alternative view for legacy mode. */
2411 struct
2412 {
2413 X86PTE BS3_FAR *pPte;
2414 X86PDE BS3_FAR *pPde;
2415 void *pvUnused2;
2416 void *pvUnused3;
2417 } Legacy;
2418 /** Alternative view for PAE and Long mode. */
2419 struct
2420 {
2421 X86PTEPAE BS3_FAR *pPte;
2422 X86PDEPAE BS3_FAR *pPde;
2423 X86PDPE BS3_FAR *pPdpe;
2424 X86PML4E BS3_FAR *pPml4e;
2425 } Pae;
2426 } u;
2427} BS3PAGINGINFO4ADDR;
2428/** Pointer to paging information for and address. */
2429typedef BS3PAGINGINFO4ADDR BS3_FAR *PBS3PAGINGINFO4ADDR;
2430
2431/**
2432 * Queries paging information about the given virtual address.
2433 *
2434 * @returns VBox status code.
2435 * @param uFlat The flat address to query information about.
2436 * @param pPgInfo Where to return the information.
2437 */
2438BS3_CMN_PROTO_STUB(int, Bs3PagingQueryAddressInfo,(uint64_t uFlat, PBS3PAGINGINFO4ADDR pPgInfo));
2439
2440
2441/** The physical / flat address of the buffer backing the canonical traps.
2442 * This buffer is spread equally on each side of the 64-bit non-canonical
2443 * address divide. Non-64-bit code can use this to setup trick shots and
2444 * inspect their results. */
2445extern uint32_t g_uBs3PagingCanonicalTrapsAddr;
2446/** The size of the buffer at g_uPagingCanonicalTraps (both sides). */
2447extern uint16_t g_cbBs3PagingCanonicalTraps;
2448/** The size of one trap buffer (low or high).
2449 * This is g_cbBs3PagingCanonicalTraps divided by two. */
2450extern uint16_t g_cbBs3PagingOneCanonicalTrap;
2451
2452/**
2453 * Sets up the 64-bit canonical address space trap buffers, if neceessary.
2454 *
2455 * @returns Pointer to the buffers (i.e. the first page of the low one) on
2456 * success. NULL on failure.
2457 */
2458BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3PagingSetupCanonicalTraps,(void));
2459
2460/**
2461 * Waits for the keyboard controller to become ready.
2462 */
2463BS3_CMN_PROTO_NOSB(void, Bs3KbdWait,(void));
2464
2465/**
2466 * Sends a read command to the keyboard controller and gets the result.
2467 *
2468 * The caller is responsible for making sure the keyboard controller is ready
2469 * for a command (call #Bs3KbdWait if unsure).
2470 *
2471 * @returns The value read is returned (in al).
2472 * @param bCmd The read command.
2473 */
2474BS3_CMN_PROTO_NOSB(uint8_t, Bs3KbdRead,(uint8_t bCmd));
2475
2476/**
2477 * Sends a write command to the keyboard controller and then sends the data.
2478 *
2479 * The caller is responsible for making sure the keyboard controller is ready
2480 * for a command (call #Bs3KbdWait if unsure).
2481 *
2482 * @param bCmd The write command.
2483 * @param bData The data to write.
2484 */
2485BS3_CMN_PROTO_NOSB(void, Bs3KbdWrite,(uint8_t bCmd, uint8_t bData));
2486
2487
2488/**
2489 * Configures the PIC, once only.
2490 *
2491 * Subsequent calls to this function will not do anything.
2492 *
2493 * The PIC will be programmed to use IDT/IVT vectors 0x70 thru 0x7f, auto
2494 * end-of-interrupt, and all IRQs masked. The individual PIC users will have to
2495 * use #Bs3PicUpdateMask unmask their IRQ once they've got all the handlers
2496 * installed.
2497 *
2498 * @param fForcedReInit Force a reinitialization.
2499 */
2500BS3_CMN_PROTO_STUB(void, Bs3PicSetup,(bool fForcedReInit));
2501
2502/**
2503 * Updates the PIC masks.
2504 *
2505 * @returns The new mask - master in low, slave in high byte.
2506 * @param fAndMask Things to keep as-is. Master in low, slave in high byte.
2507 * @param fOrMask Things to start masking. Ditto wrt bytes.
2508 */
2509BS3_CMN_PROTO_STUB(uint16_t, Bs3PicUpdateMask,(uint16_t fAndMask, uint16_t fOrMask));
2510
2511/**
2512 * Disables all IRQs on the PIC.
2513 */
2514BS3_CMN_PROTO_STUB(void, Bs3PicMaskAll,(void));
2515
2516
2517/**
2518 * Sets up the PIT for periodic callback.
2519 *
2520 * @param cHzDesired The desired Hz. Zero means max interval length
2521 * (18.2Hz). Plase check the various PIT globals for
2522 * the actual interval length.
2523 */
2524BS3_CMN_PROTO_STUB(void, Bs3PitSetupAndEnablePeriodTimer,(uint16_t cHzDesired));
2525
2526/**
2527 * Disables the PIT if active.
2528 */
2529BS3_CMN_PROTO_STUB(void, Bs3PitDisable,(void));
2530
2531/** Nanoseconds (approx) since last the PIT timer was started. */
2532extern uint64_t volatile g_cBs3PitNs;
2533/** Milliseconds seconds (very approx) since last the PIT timer was started. */
2534extern uint64_t volatile g_cBs3PitMs;
2535/** Number of ticks since last the PIT timer was started. */
2536extern uint32_t volatile g_cBs3PitTicks;
2537/** The current interval in nanoseconds.
2538 * This is 0 if not yet started (cleared by Bs3PitDisable). */
2539extern uint32_t g_cBs3PitIntervalNs;
2540/** The current interval in milliseconds (approximately).
2541 * This is 0 if not yet started (cleared by Bs3PitDisable). */
2542extern uint16_t g_cBs3PitIntervalMs;
2543/** The current PIT frequency (approximately).
2544 * 0 if not yet started (cleared by Bs3PitDisable; used for checking the
2545 * state internally). */
2546extern uint16_t volatile g_cBs3PitIntervalHz;
2547
2548
2549/**
2550 * Call 16-bit prot mode function from v8086 mode.
2551 *
2552 * This switches from v8086 mode to 16-bit protected mode (code) and executed
2553 * @a fpfnCall with @a cbParams bytes of parameters pushed on the stack.
2554 * Afterwards it switches back to v8086 mode and returns a 16-bit status code.
2555 *
2556 * @returns 16-bit status code if the function returned anything.
2557 * @param fpfnCall Far real mode pointer to the function to call.
2558 * @param cbParams The size of the parameter list, in bytes.
2559 * @param ... The parameters.
2560 * @sa Bs3SwitchTo32BitAndCallC
2561 */
2562BS3_CMN_PROTO_STUB(int, Bs3SwitchFromV86To16BitAndCallC,(FPFNBS3FAR fpfnCall, unsigned cbParams, ...));
2563
2564
2565/**
2566 * BS3 integer register.
2567 */
2568typedef union BS3REG
2569{
2570 /** 8-bit unsigned integer. */
2571 uint8_t u8;
2572 /** 16-bit unsigned integer. */
2573 uint16_t u16;
2574 /** 32-bit unsigned integer. */
2575 uint32_t u32;
2576 /** 64-bit unsigned integer. */
2577 uint64_t u64;
2578 /** Full unsigned integer. */
2579 uint64_t u;
2580 /** High/low byte view. */
2581 struct
2582 {
2583 uint8_t bLo;
2584 uint8_t bHi;
2585 } b;
2586 /** 8-bit view. */
2587 uint8_t au8[8];
2588 /** 16-bit view. */
2589 uint16_t au16[4];
2590 /** 32-bit view. */
2591 uint32_t au32[2];
2592 /** Unsigned integer, depending on compiler context.
2593 * This generally follows ARCH_BITS. */
2594 RTCCUINTREG uCcReg;
2595 /** Extended unsigned integer, depending on compiler context.
2596 * This is 32-bit in 16-bit and 32-bit compiler contexts, and 64-bit in
2597 * 64-bit. */
2598 RTCCUINTXREG uCcXReg;
2599} BS3REG;
2600/** Pointer to an integer register. */
2601typedef BS3REG BS3_FAR *PBS3REG;
2602/** Pointer to a const integer register. */
2603typedef BS3REG const BS3_FAR *PCBS3REG;
2604
2605/**
2606 * Register context (without FPU).
2607 */
2608typedef struct BS3REGCTX
2609{
2610 BS3REG rax; /**< 0x00 */
2611 BS3REG rcx; /**< 0x08 */
2612 BS3REG rdx; /**< 0x10 */
2613 BS3REG rbx; /**< 0x18 */
2614 BS3REG rsp; /**< 0x20 */
2615 BS3REG rbp; /**< 0x28 */
2616 BS3REG rsi; /**< 0x30 */
2617 BS3REG rdi; /**< 0x38 */
2618 BS3REG r8; /**< 0x40 */
2619 BS3REG r9; /**< 0x48 */
2620 BS3REG r10; /**< 0x50 */
2621 BS3REG r11; /**< 0x58 */
2622 BS3REG r12; /**< 0x60 */
2623 BS3REG r13; /**< 0x68 */
2624 BS3REG r14; /**< 0x70 */
2625 BS3REG r15; /**< 0x78 */
2626 BS3REG rflags; /**< 0x80 */
2627 BS3REG rip; /**< 0x88 */
2628 uint16_t cs; /**< 0x90 */
2629 uint16_t ds; /**< 0x92 */
2630 uint16_t es; /**< 0x94 */
2631 uint16_t fs; /**< 0x96 */
2632 uint16_t gs; /**< 0x98 */
2633 uint16_t ss; /**< 0x9a */
2634 uint16_t tr; /**< 0x9c */
2635 uint16_t ldtr; /**< 0x9e */
2636 uint8_t bMode; /**< 0xa0: BS3_MODE_XXX. */
2637 uint8_t bCpl; /**< 0xa1: 0-3, 0 is used for real mode. */
2638 uint8_t fbFlags; /**< 0xa2: BS3REG_CTX_F_XXX */
2639 uint8_t abPadding[5]; /**< 0xa3 */
2640 BS3REG cr0; /**< 0xa8 */
2641 BS3REG cr2; /**< 0xb0 */
2642 BS3REG cr3; /**< 0xb8 */
2643 BS3REG cr4; /**< 0xc0 */
2644 uint64_t uUnused; /**< 0xc8 */
2645} BS3REGCTX;
2646AssertCompileSize(BS3REGCTX, 0xd0);
2647/** Pointer to a register context. */
2648typedef BS3REGCTX BS3_FAR *PBS3REGCTX;
2649/** Pointer to a const register context. */
2650typedef BS3REGCTX const BS3_FAR *PCBS3REGCTX;
2651
2652/** @name BS3REG_CTX_F_XXX - BS3REGCTX::fbFlags masks.
2653 * @{ */
2654/** The CR0 is MSW (only low 16-bit). */
2655#define BS3REG_CTX_F_NO_CR0_IS_MSW UINT8_C(0x01)
2656/** No CR2 and CR3 values. Not in CPL 0 or CPU too old for CR2 & CR3. */
2657#define BS3REG_CTX_F_NO_CR2_CR3 UINT8_C(0x02)
2658/** No CR4 value. The CPU is too old for CR4. */
2659#define BS3REG_CTX_F_NO_CR4 UINT8_C(0x04)
2660/** No TR and LDTR values. Context gathered in real mode or v8086 mode. */
2661#define BS3REG_CTX_F_NO_TR_LDTR UINT8_C(0x08)
2662/** The context doesn't have valid values for AMD64 GPR extensions. */
2663#define BS3REG_CTX_F_NO_AMD64 UINT8_C(0x10)
2664/** @} */
2665
2666/**
2667 * Saves the current register context.
2668 *
2669 * @param pRegCtx Where to store the register context.
2670 */
2671BS3_CMN_PROTO_NOSB(void, Bs3RegCtxSave,(PBS3REGCTX pRegCtx));
2672
2673/**
2674 * Switch to the specified CPU bitcount, reserve additional stack and save the
2675 * CPU context.
2676 *
2677 * This is for writing more flexible test drivers that can test more than the
2678 * CPU bitcount (16-bit, 32-bit, 64-bit, and virtual 8086) of the driver itself.
2679 * For instance a 32-bit driver can do V86 and 16-bit testing, thus saving space
2680 * by avoiding duplicate 16-bit driver code.
2681 *
2682 * @param pRegCtx Where to store the register context.
2683 * @param bBitMode Bit mode to switch to, BS3_MODE_CODE_XXX. Only
2684 * BS3_MODE_CODE_MASK is used, other bits are ignored
2685 * to make it possible to pass a full mode value.
2686 * @param cbExtraStack Number of bytes of additional stack to allocate.
2687 */
2688BS3_CMN_PROTO_FARSTUB(8, void, Bs3RegCtxSaveEx,(PBS3REGCTX pRegCtx, uint8_t bBitMode, uint16_t cbExtraStack));
2689
2690/**
2691 * This is Bs3RegCtxSaveEx with automatic Bs3RegCtxConvertV86ToRm thrown in.
2692 *
2693 * This is for simplifying writing 32-bit test drivers that covers real-mode as
2694 * well as virtual 8086, 16-bit, 32-bit, and 64-bit modes.
2695 *
2696 * @param pRegCtx Where to store the register context.
2697 * @param bMode The mode to get a context for. If this isn't
2698 * BS3_MODE_RM, the BS3_MODE_SYS_MASK has to match the
2699 * one of the current mode.
2700 * @param cbExtraStack Number of bytes of additional stack to allocate.
2701 */
2702BS3_CMN_PROTO_STUB(void, Bs3RegCtxSaveForMode,(PBS3REGCTX pRegCtx, uint8_t bMode, uint16_t cbExtraStack));
2703
2704/**
2705 * Transforms a register context to a different ring.
2706 *
2707 * @param pRegCtx The register context.
2708 * @param bRing The target ring (0..3).
2709 *
2710 * @note Do _NOT_ call this for creating real mode or v8086 contexts, because
2711 * it will always output a protected mode context!
2712 */
2713BS3_CMN_PROTO_STUB(void, Bs3RegCtxConvertToRingX,(PBS3REGCTX pRegCtx, uint8_t bRing));
2714
2715/**
2716 * Transforms a V8086 register context to a real mode one.
2717 *
2718 * @param pRegCtx The register context.
2719 *
2720 * @note Will assert if called on a non-V8086 context.
2721 */
2722BS3_CMN_PROTO_STUB(void, Bs3RegCtxConvertV86ToRm,(PBS3REGCTX pRegCtx));
2723
2724/**
2725 * Restores a register context.
2726 *
2727 * @param pRegCtx The register context to be restored and resumed.
2728 * @param fFlags BS3REGCTXRESTORE_F_XXX.
2729 *
2730 * @remarks Will switch to ring-0.
2731 * @remarks Does not return.
2732 */
2733BS3_CMN_PROTO_NOSB(DECL_NO_RETURN(void), Bs3RegCtxRestore,(PCBS3REGCTX pRegCtx, uint16_t fFlags));
2734#if !defined(BS3_KIT_WITH_NO_RETURN) && defined(__WATCOMC__)
2735# pragma aux Bs3RegCtxRestore_c16 "_Bs3RegCtxRestore_aborts_c16" __aborts
2736# pragma aux Bs3RegCtxRestore_f16 "_Bs3RegCtxRestore_aborts_f16" __aborts
2737# pragma aux Bs3RegCtxRestore_c32 "_Bs3RegCtxRestore_aborts_c32" __aborts
2738#endif
2739
2740/** @name Flags for Bs3RegCtxRestore
2741 * @{ */
2742/** Skip restoring the CRx registers. */
2743#define BS3REGCTXRESTORE_F_SKIP_CRX UINT16_C(0x0001)
2744/** Sets g_fBs3TrapNoV86Assist. */
2745#define BS3REGCTXRESTORE_F_NO_V86_ASSIST UINT16_C(0x0002)
2746/** @} */
2747
2748/**
2749 * Prints the register context.
2750 *
2751 * @param pRegCtx The register context to be printed.
2752 */
2753BS3_CMN_PROTO_STUB(void, Bs3RegCtxPrint,(PCBS3REGCTX pRegCtx));
2754
2755/**
2756 * Sets a GPR and segment register to point at the same location as @a uFlat.
2757 *
2758 * @param pRegCtx The register context.
2759 * @param pGpr The general purpose register to set (points within
2760 * @a pRegCtx).
2761 * @param pSel The selector register (points within @a pRegCtx).
2762 * @param uFlat Flat location address.
2763 */
2764BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetGrpSegFromFlat,(PBS3REGCTX pRegCtx, PBS3REG pGpr, PRTSEL pSel, RTCCUINTXREG uFlat));
2765
2766/**
2767 * Sets a GPR and segment register to point at the same location as @a ovPtr.
2768 *
2769 * @param pRegCtx The register context.
2770 * @param pGpr The general purpose register to set (points within
2771 * @a pRegCtx).
2772 * @param pSel The selector register (points within @a pRegCtx).
2773 * @param pvPtr Current context pointer.
2774 */
2775BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetGrpSegFromCurPtr,(PBS3REGCTX pRegCtx, PBS3REG pGpr, PRTSEL pSel, void BS3_FAR *pvPtr));
2776
2777/**
2778 * Sets a GPR and DS to point at the same location as @a pvPtr.
2779 *
2780 * @param pRegCtx The register context.
2781 * @param pGpr The general purpose register to set (points within
2782 * @a pRegCtx).
2783 * @param pvPtr Current context pointer.
2784 */
2785BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetGrpDsFromCurPtr,(PBS3REGCTX pRegCtx, PBS3REG pGpr, void BS3_FAR *pvPtr));
2786
2787/**
2788 * Sets CS:RIP to point at the same piece of code as @a uFlatCode.
2789 *
2790 * @param pRegCtx The register context.
2791 * @param uFlatCode Flat code pointer
2792 * @sa Bs3RegCtxSetRipCsFromLnkPtr, Bs3RegCtxSetRipCsFromCurPtr
2793 */
2794BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetRipCsFromFlat,(PBS3REGCTX pRegCtx, RTCCUINTXREG uFlatCode));
2795
2796/**
2797 * Sets CS:RIP to point at the same piece of code as @a pfnCode.
2798 *
2799 * The 16-bit edition of this function expects a far 16:16 address as written by
2800 * the linker (i.e. real mode).
2801 *
2802 * @param pRegCtx The register context.
2803 * @param pfnCode Pointer to the code. In 32-bit and 64-bit mode this is a
2804 * flat address, while in 16-bit it's a far 16:16 address
2805 * as fixed up by the linker (real mode selector). This
2806 * address is converted to match the mode of the context.
2807 * @sa Bs3RegCtxSetRipCsFromCurPtr, Bs3RegCtxSetRipCsFromFlat
2808 */
2809BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetRipCsFromLnkPtr,(PBS3REGCTX pRegCtx, FPFNBS3FAR pfnCode));
2810
2811/**
2812 * Sets CS:RIP to point at the same piece of code as @a pfnCode.
2813 *
2814 * @param pRegCtx The register context.
2815 * @param pfnCode Pointer to the code. Current mode pointer.
2816 * @sa Bs3RegCtxSetRipCsFromLnkPtr, Bs3RegCtxSetRipCsFromFlat
2817 */
2818BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetRipCsFromCurPtr,(PBS3REGCTX pRegCtx, FPFNBS3FAR pfnCode));
2819
2820/**
2821 * Sets a GPR by number.
2822 *
2823 * @return true if @a iGpr is valid, false if not.
2824 * @param pRegCtx The register context.
2825 * @param iGpr The GPR number.
2826 * @param uValue The new value.
2827 * @param cbValue The size of the value: 1, 2, 4 or 8.
2828 */
2829BS3_CMN_PROTO_STUB(bool, Bs3RegCtxSetGpr,(PBS3REGCTX pRegCtx, uint8_t iGpr, uint64_t uValue, uint8_t cb));
2830
2831
2832/**
2833 * The method to be used to save and restore the extended context.
2834 */
2835typedef enum BS3EXTCTXMETHOD
2836{
2837 BS3EXTCTXMETHOD_INVALID = 0,
2838 BS3EXTCTXMETHOD_ANCIENT, /**< Ancient fnsave/frstor format. */
2839 BS3EXTCTXMETHOD_FXSAVE, /**< fxsave/fxrstor format. */
2840 BS3EXTCTXMETHOD_XSAVE, /**< xsave/xrstor format. */
2841 BS3EXTCTXMETHOD_END,
2842} BS3EXTCTXMETHOD;
2843
2844
2845/**
2846 * Extended CPU context (FPU, SSE, AVX, ++).
2847 *
2848 * @remarks Also in bs3kit.inc
2849 */
2850typedef struct BS3EXTCTX
2851{
2852 /** Dummy/magic value. */
2853 uint16_t u16Magic;
2854 /** The size of the structure. */
2855 uint16_t cb;
2856 /** The method used to save and restore the context (BS3EXTCTXMETHOD). */
2857 uint8_t enmMethod;
2858 uint8_t abPadding0[3];
2859 /** Nominal XSAVE_C_XXX. */
2860 uint64_t fXcr0Nominal;
2861 /** The saved XCR0 mask (restored after xrstor). */
2862 uint64_t fXcr0Saved;
2863
2864 /** Explicit alignment padding. */
2865 uint8_t abPadding[64 - 2 - 2 - 1 - 3 - 8 - 8];
2866
2867 /** The context, variable size (see above).
2868 * This must be aligned on a 64 byte boundrary. */
2869 union
2870 {
2871 /** fnsave/frstor. */
2872 X86FPUSTATE Ancient;
2873 /** fxsave/fxrstor */
2874 X86FXSTATE x87;
2875 /** xsave/xrstor */
2876 X86XSAVEAREA x;
2877 /** Byte array view. */
2878 uint8_t ab[sizeof(X86XSAVEAREA)];
2879 } Ctx;
2880} BS3EXTCTX;
2881AssertCompileMemberAlignment(BS3EXTCTX, Ctx, 64);
2882/** Pointer to an extended CPU context. */
2883typedef BS3EXTCTX BS3_FAR *PBS3EXTCTX;
2884/** Pointer to a const extended CPU context. */
2885typedef BS3EXTCTX const BS3_FAR *PCBS3EXTCTX;
2886
2887/** Magic value for BS3EXTCTX. */
2888#define BS3EXTCTX_MAGIC UINT16_C(0x1980)
2889
2890/**
2891 * Allocates and initializes the extended CPU context structure.
2892 *
2893 * @returns The new extended CPU context structure.
2894 * @param enmKind The kind of allocation to make.
2895 */
2896BS3_CMN_PROTO_STUB(PBS3EXTCTX, Bs3ExtCtxAlloc,(BS3MEMKIND enmKind));
2897
2898/**
2899 * Frees an extended CPU context structure.
2900 *
2901 * @param pExtCtx The extended CPU context (returned by
2902 * Bs3ExtCtxAlloc).
2903 */
2904BS3_CMN_PROTO_STUB(void, Bs3ExtCtxFree,(PBS3EXTCTX pExtCtx));
2905
2906/**
2907 * Get the size required for a BS3EXTCTX structure.
2908 *
2909 * @returns size in bytes of the whole structure.
2910 * @param pfFlags Where to return flags for Bs3ExtCtxInit.
2911 * @note Use Bs3ExtCtxAlloc when possible.
2912 */
2913BS3_CMN_PROTO_STUB(uint16_t, Bs3ExtCtxGetSize,(uint64_t *pfFlags));
2914
2915/**
2916 * Initializes the extended CPU context structure.
2917 * @returns pExtCtx
2918 * @param pExtCtx The extended CPU context.
2919 * @param cbExtCtx The size of the @a pExtCtx allocation.
2920 * @param fFlags XSAVE_C_XXX flags.
2921 */
2922BS3_CMN_PROTO_STUB(PBS3EXTCTX, Bs3ExtCtxInit,(PBS3EXTCTX pExtCtx, uint16_t cbExtCtx, uint64_t fFlags));
2923
2924/**
2925 * Saves the extended CPU state to the given structure.
2926 *
2927 * @param pExtCtx The extended CPU context.
2928 * @remarks All GPRs preserved.
2929 */
2930BS3_CMN_PROTO_FARSTUB(4, void, Bs3ExtCtxSave,(PBS3EXTCTX pExtCtx));
2931
2932/**
2933 * Saves the extended CPU state to the given structure, when in long mode this
2934 * is done from 64-bit mode to capture YMM8 thru YMM15.
2935 *
2936 * This is for testing 64-bit code from a 32-bit test driver.
2937 *
2938 * @param pExtCtx The extended CPU context.
2939 * @note Only safe to call from ring-0 at present.
2940 * @remarks All GPRs preserved.
2941 * @sa Bs3ExtCtxRestoreEx
2942 */
2943BS3_CMN_PROTO_FARSTUB(4, void, Bs3ExtCtxSaveEx,(PBS3EXTCTX pExtCtx));
2944
2945/**
2946 * Restores the extended CPU state from the given structure.
2947 *
2948 * @param pExtCtx The extended CPU context.
2949 * @remarks All GPRs preserved.
2950 */
2951BS3_CMN_PROTO_FARSTUB(4, void, Bs3ExtCtxRestore,(PCBS3EXTCTX pExtCtx));
2952
2953/**
2954 * Restores the extended CPU state from the given structure and in long mode
2955 * switch to 64-bit mode to do this so YMM8-YMM15 are also loaded.
2956 *
2957 * This is for testing 64-bit code from a 32-bit test driver.
2958 *
2959 * @param pExtCtx The extended CPU context.
2960 * @note Only safe to call from ring-0 at present.
2961 * @remarks All GPRs preserved.
2962 * @sa Bs3ExtCtxSaveEx
2963 */
2964BS3_CMN_PROTO_FARSTUB(4, void, Bs3ExtCtxRestoreEx,(PCBS3EXTCTX pExtCtx));
2965
2966/**
2967 * Copies the state from one context to another.
2968 *
2969 * @returns pDst
2970 * @param pDst The destination extended CPU context.
2971 * @param pSrc The source extended CPU context.
2972 */
2973BS3_CMN_PROTO_STUB(PBS3EXTCTX, Bs3ExtCtxCopy,(PBS3EXTCTX pDst, PCBS3EXTCTX pSrc));
2974
2975/**
2976 * Gets the FCW register value from @a pExtCtx.
2977 *
2978 * @returns FCW value.
2979 * @param pExtCtx The extended CPU context.
2980 */
2981BS3_CMN_PROTO_STUB(uint16_t, Bs3ExtCtxGetFcw,(PCBS3EXTCTX pExtCtx));
2982
2983/**
2984 * Sets the FCW register value in @a pExtCtx.
2985 *
2986 * @param pExtCtx The extended CPU context.
2987 * @param uValue The new FCW value.
2988 */
2989BS3_CMN_PROTO_STUB(void, Bs3ExtCtxSetFcw,(PBS3EXTCTX pExtCtx, uint16_t uValue));
2990
2991/**
2992 * Gets the FSW register value from @a pExtCtx.
2993 *
2994 * @returns FSW value.
2995 * @param pExtCtx The extended CPU context.
2996 */
2997BS3_CMN_PROTO_STUB(uint16_t, Bs3ExtCtxGetFsw,(PCBS3EXTCTX pExtCtx));
2998
2999/**
3000 * Sets the FSW register value in @a pExtCtx.
3001 *
3002 * @param pExtCtx The extended CPU context.
3003 * @param uValue The new FSW value.
3004 */
3005BS3_CMN_PROTO_STUB(void, Bs3ExtCtxSetFsw,(PBS3EXTCTX pExtCtx, uint16_t uValue));
3006
3007/**
3008 * Gets the abridged FTW register value from @a pExtCtx.
3009 *
3010 * @returns FTW value.
3011 * @param pExtCtx The extended CPU context.
3012 */
3013BS3_CMN_PROTO_STUB(uint16_t, Bs3ExtCtxGetAbridgedFtw,(PCBS3EXTCTX pExtCtx));
3014
3015/**
3016 * Sets the abridged FTW register value in @a pExtCtx.
3017 *
3018 * Currently this requires that the state stores teh abridged FTW, no conversion
3019 * to the two-bit variant will be attempted.
3020 *
3021 * @returns true if set successfully, false if not.
3022 * @param pExtCtx The extended CPU context.
3023 * @param uValue The new FTW value.
3024 */
3025BS3_CMN_PROTO_STUB(bool, Bs3ExtCtxSetAbridgedFtw,(PBS3EXTCTX pExtCtx, uint16_t uValue));
3026
3027/**
3028 * Gets the MXCSR register value from @a pExtCtx.
3029 *
3030 * @returns MXCSR value, 0 if not part of context.
3031 * @param pExtCtx The extended CPU context.
3032 */
3033BS3_CMN_PROTO_STUB(uint32_t, Bs3ExtCtxGetMxCsr,(PCBS3EXTCTX pExtCtx));
3034
3035/**
3036 * Sets the MXCSR register value in @a pExtCtx.
3037 *
3038 * @returns true if set, false if not supported by the format.
3039 * @param pExtCtx The extended CPU context.
3040 * @param uValue The new MXCSR value.
3041 */
3042BS3_CMN_PROTO_STUB(bool, Bs3ExtCtxSetMxCsr,(PBS3EXTCTX pExtCtx, uint32_t uValue));
3043
3044/**
3045 * Gets the MXCSR MASK value from @a pExtCtx.
3046 *
3047 * @returns MXCSR MASK value, 0 if not part of context.
3048 * @param pExtCtx The extended CPU context.
3049 */
3050BS3_CMN_PROTO_STUB(uint32_t, Bs3ExtCtxGetMxCsrMask,(PCBS3EXTCTX pExtCtx));
3051
3052/**
3053 * Sets the MXCSR MASK value in @a pExtCtx.
3054 *
3055 * @returns true if set, false if not supported by the format.
3056 * @param pExtCtx The extended CPU context.
3057 * @param uValue The new MXCSR MASK value.
3058 */
3059BS3_CMN_PROTO_STUB(bool, Bs3ExtCtxSetMxCsrMask,(PBS3EXTCTX pExtCtx, uint32_t uValue));
3060
3061/**
3062 * Gets the value of MM register number @a iReg from @a pExtCtx.
3063 *
3064 * @returns The MM register value.
3065 * @param pExtCtx The extended CPU context.
3066 * @param iReg The register to get (0 thru 7).
3067 */
3068BS3_CMN_PROTO_STUB(uint64_t, Bs3ExtCtxGetMm,(PCBS3EXTCTX pExtCtx, uint8_t iReg));
3069
3070/** What to do about the 16-bit above the MM QWORD. */
3071typedef enum BS3EXTCTXTOPMM
3072{
3073 /** Invalid zero value. */
3074 BS3EXTCTXTOPMM_INVALID = 0,
3075 /** Set to 0FFFFh like real CPUs typically does when updating an MM register. */
3076 BS3EXTCTXTOPMM_SET,
3077 /** Set to zero. */
3078 BS3EXTCTXTOPMM_ZERO,
3079 /** Don't change the value, leaving it as-is. */
3080 BS3EXTCTXTOPMM_AS_IS,
3081 /** End of valid values. */
3082 BS3EXTCTXTOPMM_END
3083} BS3EXTCTXTOPMM;
3084
3085/**
3086 * Sets the value of YMM register number @a iReg in @a pExtCtx to @a pValue.
3087 *
3088 * @returns True if set, false if not.
3089 * @param pExtCtx The extended CPU context.
3090 * @param iReg The register to set.
3091 * @param uValue The new register value.
3092 * @param enmTop What to do about the 16-bit value above the MM
3093 * QWord.
3094 */
3095BS3_CMN_PROTO_STUB(bool, Bs3ExtCtxSetMm,(PBS3EXTCTX pExtCtx, uint8_t iReg, uint64_t uValue, BS3EXTCTXTOPMM enmTop));
3096
3097/**
3098 * Gets the value of XMM register number @a iReg from @a pExtCtx.
3099 *
3100 * @returns pValue
3101 * @param pExtCtx The extended CPU context.
3102 * @param iReg The register to get.
3103 * @param pValue Where to return the value. Zeroed if the state
3104 * doesn't support SSE or if @a iReg is invalid.
3105 */
3106BS3_CMN_PROTO_STUB(PRTUINT128U, Bs3ExtCtxGetXmm,(PCBS3EXTCTX pExtCtx, uint8_t iReg, PRTUINT128U pValue));
3107
3108/**
3109 * Sets the value of XMM register number @a iReg in @a pExtCtx to @a pValue.
3110 *
3111 * @returns True if set, false if not set (not supported by state format or
3112 * invalid iReg).
3113 * @param pExtCtx The extended CPU context.
3114 * @param iReg The register to set.
3115 * @param pValue The new register value.
3116 */
3117BS3_CMN_PROTO_STUB(bool, Bs3ExtCtxSetXmm,(PBS3EXTCTX pExtCtx, uint8_t iReg, PCRTUINT128U pValue));
3118
3119/**
3120 * Gets the value of YMM register number @a iReg from @a pExtCtx.
3121 *
3122 * @returns pValue
3123 * @param pExtCtx The extended CPU context.
3124 * @param iReg The register to get.
3125 * @param pValue Where to return the value. Parts not in the
3126 * extended state are zeroed. For absent or invalid
3127 * @a iReg values this is set to zero.
3128 */
3129BS3_CMN_PROTO_STUB(PRTUINT256U, Bs3ExtCtxGetYmm,(PCBS3EXTCTX pExtCtx, uint8_t iReg, PRTUINT256U pValue));
3130
3131/**
3132 * Sets the value of YMM register number @a iReg in @a pExtCtx to @a pValue.
3133 *
3134 * @returns true if set (even if only partially). False if not set (not
3135 * supported by state format, unsupported/invalid iReg).
3136 * @param pExtCtx The extended CPU context.
3137 * @param iReg The register to set.
3138 * @param pValue The new register value.
3139 * @param cbValue Number of bytes to take from @a pValue, either 16 or
3140 * 32. If 16, the high part will be zeroed when present
3141 * in the state.
3142 */
3143BS3_CMN_PROTO_STUB(bool, Bs3ExtCtxSetYmm,(PBS3EXTCTX pExtCtx, uint8_t iReg, PCRTUINT256U pValue, uint8_t cbValue));
3144
3145
3146/** @name Debug register accessors for V8086 mode (works everwhere).
3147 * @{ */
3148BS3_CMN_PROTO_NOSB(RTCCUINTXREG, Bs3RegGetDr0,(void));
3149BS3_CMN_PROTO_NOSB(RTCCUINTXREG, Bs3RegGetDr1,(void));
3150BS3_CMN_PROTO_NOSB(RTCCUINTXREG, Bs3RegGetDr2,(void));
3151BS3_CMN_PROTO_NOSB(RTCCUINTXREG, Bs3RegGetDr3,(void));
3152BS3_CMN_PROTO_NOSB(RTCCUINTXREG, Bs3RegGetDr6,(void));
3153BS3_CMN_PROTO_NOSB(RTCCUINTXREG, Bs3RegGetDr7,(void));
3154
3155BS3_CMN_PROTO_NOSB(void, Bs3RegSetDr0,(RTCCUINTXREG uValue));
3156BS3_CMN_PROTO_NOSB(void, Bs3RegSetDr1,(RTCCUINTXREG uValue));
3157BS3_CMN_PROTO_NOSB(void, Bs3RegSetDr2,(RTCCUINTXREG uValue));
3158BS3_CMN_PROTO_NOSB(void, Bs3RegSetDr3,(RTCCUINTXREG uValue));
3159BS3_CMN_PROTO_NOSB(void, Bs3RegSetDr6,(RTCCUINTXREG uValue));
3160BS3_CMN_PROTO_NOSB(void, Bs3RegSetDr7,(RTCCUINTXREG uValue));
3161
3162BS3_CMN_PROTO_NOSB(RTCCUINTXREG, Bs3RegGetDrX,(uint8_t iReg));
3163BS3_CMN_PROTO_NOSB(void, Bs3RegSetDrX,(uint8_t iReg, RTCCUINTXREG uValue));
3164/** @} */
3165
3166
3167/** @name Control register accessors for V8086 mode (works everwhere).
3168 * @{ */
3169BS3_CMN_PROTO_NOSB(RTCCUINTXREG, Bs3RegGetCr0,(void));
3170BS3_CMN_PROTO_NOSB(RTCCUINTXREG, Bs3RegGetCr2,(void));
3171BS3_CMN_PROTO_NOSB(RTCCUINTXREG, Bs3RegGetCr3,(void));
3172BS3_CMN_PROTO_NOSB(RTCCUINTXREG, Bs3RegGetCr4,(void));
3173BS3_CMN_PROTO_NOSB(uint16_t, Bs3RegGetTr,(void));
3174BS3_CMN_PROTO_NOSB(uint16_t, Bs3RegGetLdtr,(void));
3175BS3_CMN_PROTO_NOSB(uint64_t, Bs3RegGetXcr0,(void));
3176
3177BS3_CMN_PROTO_NOSB(void, Bs3RegSetCr0,(RTCCUINTXREG uValue));
3178BS3_CMN_PROTO_NOSB(void, Bs3RegSetCr2,(RTCCUINTXREG uValue));
3179BS3_CMN_PROTO_NOSB(void, Bs3RegSetCr3,(RTCCUINTXREG uValue));
3180BS3_CMN_PROTO_NOSB(void, Bs3RegSetCr4,(RTCCUINTXREG uValue));
3181BS3_CMN_PROTO_NOSB(void, Bs3RegSetTr,(uint16_t uValue));
3182BS3_CMN_PROTO_NOSB(void, Bs3RegSetLdtr,(uint16_t uValue));
3183BS3_CMN_PROTO_NOSB(void, Bs3RegSetXcr0,(uint64_t uValue));
3184/** @} */
3185
3186
3187/**
3188 * Trap frame.
3189 */
3190typedef struct BS3TRAPFRAME
3191{
3192 /** 0x00: Exception/interrupt number. */
3193 uint8_t bXcpt;
3194 /** 0x01: The size of the IRET frame. */
3195 uint8_t cbIretFrame;
3196 /** 0x02: The handler CS. */
3197 uint16_t uHandlerCs;
3198 /** 0x04: The handler SS. */
3199 uint16_t uHandlerSs;
3200 /** 0x06: Explicit alignment. */
3201 uint16_t usAlignment;
3202 /** 0x08: The handler RSP (pointer to the iret frame, skipping ErrCd). */
3203 uint64_t uHandlerRsp;
3204 /** 0x10: The handler RFLAGS value. */
3205 uint64_t fHandlerRfl;
3206 /** 0x18: The error code (if applicable). */
3207 uint64_t uErrCd;
3208 /** 0x20: The register context. */
3209 BS3REGCTX Ctx;
3210} BS3TRAPFRAME;
3211AssertCompileSize(BS3TRAPFRAME, 0x20 + 0xd0);
3212/** Pointer to a trap frame. */
3213typedef BS3TRAPFRAME BS3_FAR *PBS3TRAPFRAME;
3214/** Pointer to a const trap frame. */
3215typedef BS3TRAPFRAME const BS3_FAR *PCBS3TRAPFRAME;
3216
3217
3218/**
3219 * Re-initializes the trap handling for the current mode.
3220 *
3221 * Useful after a test that messes with the IDT/IVT.
3222 *
3223 * @sa Bs3TrapInit
3224 */
3225BS3_CMN_PROTO_STUB(void, Bs3TrapReInit,(void));
3226
3227/**
3228 * Initializes real mode and v8086 trap handling.
3229 *
3230 * @remarks Does not install RM/V86 trap handling, just initializes the
3231 * structures.
3232 */
3233BS3_CMN_PROTO_STUB(void, Bs3TrapRmV86Init,(void));
3234
3235/**
3236 * Initializes real mode and v8086 trap handling, extended version.
3237 *
3238 * @param f386Plus Set if the CPU is 80386 or later and
3239 * extended registers should be saved. Once initialized
3240 * with this parameter set to @a true, the effect cannot be
3241 * reversed.
3242 *
3243 * @remarks Does not install RM/V86 trap handling, just initializes the
3244 * structures.
3245 */
3246BS3_CMN_PROTO_STUB(void, Bs3TrapRmV86InitEx,(bool f386Plus));
3247
3248/**
3249 * Initializes 16-bit (protected mode) trap handling.
3250 *
3251 * @remarks Does not install 16-bit trap handling, just initializes the
3252 * structures.
3253 */
3254BS3_CMN_PROTO_STUB(void, Bs3Trap16Init,(void));
3255
3256/**
3257 * Initializes 16-bit (protected mode) trap handling, extended version.
3258 *
3259 * @param f386Plus Set if the CPU is 80386 or later and
3260 * extended registers should be saved. Once initialized
3261 * with this parameter set to @a true, the effect cannot be
3262 * reversed.
3263 *
3264 * @remarks Does not install 16-bit trap handling, just initializes the
3265 * structures.
3266 */
3267BS3_CMN_PROTO_STUB(void, Bs3Trap16InitEx,(bool f386Plus));
3268
3269/**
3270 * Initializes 32-bit trap handling.
3271 *
3272 * @remarks Does not install 32-bit trap handling, just initializes the
3273 * structures.
3274 */
3275BS3_CMN_PROTO_STUB(void, Bs3Trap32Init,(void));
3276
3277/**
3278 * Initializes 64-bit trap handling
3279 *
3280 * @remarks Does not install 64-bit trap handling, just initializes the
3281 * structures.
3282 */
3283BS3_CMN_PROTO_STUB(void, Bs3Trap64Init,(void));
3284
3285/**
3286 * Modifies the real-mode / V86 IVT entry specified by @a iIvt.
3287 *
3288 * @param iIvt The index of the IDT entry to set.
3289 * @param uSeg The handler real-mode segment.
3290 * @param off The handler offset.
3291 */
3292BS3_CMN_PROTO_STUB(void, Bs3TrapRmV86SetGate,(uint8_t iIvt, uint16_t uSeg, uint16_t off));
3293
3294/**
3295 * Modifies the 16-bit IDT entry (protected mode) specified by @a iIdt.
3296 *
3297 * @param iIdt The index of the IDT entry to set.
3298 * @param bType The gate type (X86_SEL_TYPE_SYS_XXX).
3299 * @param bDpl The DPL.
3300 * @param uSel The handler selector.
3301 * @param off The handler offset (if applicable).
3302 * @param cParams The parameter count (for call gates).
3303 */
3304BS3_CMN_PROTO_STUB(void, Bs3Trap16SetGate,(uint8_t iIdt, uint8_t bType, uint8_t bDpl,
3305 uint16_t uSel, uint16_t off, uint8_t cParams));
3306
3307/** The address of Bs3Trap16GenericEntries.
3308 * Bs3Trap16GenericEntries is an array of interrupt/trap/whatever entry
3309 * points, 8 bytes each, that will create a register frame and call the generic
3310 * C compatible trap handlers. */
3311extern uint32_t g_Bs3Trap16GenericEntriesFlatAddr;
3312
3313/**
3314 * Modifies the 32-bit IDT entry specified by @a iIdt.
3315 *
3316 * @param iIdt The index of the IDT entry to set.
3317 * @param bType The gate type (X86_SEL_TYPE_SYS_XXX).
3318 * @param bDpl The DPL.
3319 * @param uSel The handler selector.
3320 * @param off The handler offset (if applicable).
3321 * @param cParams The parameter count (for call gates).
3322 */
3323BS3_CMN_PROTO_STUB(void, Bs3Trap32SetGate,(uint8_t iIdt, uint8_t bType, uint8_t bDpl,
3324 uint16_t uSel, uint32_t off, uint8_t cParams));
3325
3326/** The address of Bs3Trap32GenericEntries.
3327 * Bs3Trap32GenericEntries is an array of interrupt/trap/whatever entry
3328 * points, 10 bytes each, that will create a register frame and call the generic
3329 * C compatible trap handlers. */
3330extern uint32_t g_Bs3Trap32GenericEntriesFlatAddr;
3331
3332/**
3333 * Modifies the 64-bit IDT entry specified by @a iIdt.
3334 *
3335 * @param iIdt The index of the IDT entry to set.
3336 * @param bType The gate type (X86_SEL_TYPE_SYS_XXX).
3337 * @param bDpl The DPL.
3338 * @param uSel The handler selector.
3339 * @param off The handler offset (if applicable).
3340 * @param bIst The interrupt stack to use.
3341 */
3342BS3_CMN_PROTO_STUB(void, Bs3Trap64SetGate,(uint8_t iIdt, uint8_t bType, uint8_t bDpl, uint16_t uSel, uint64_t off, uint8_t bIst));
3343
3344/** The address of Bs3Trap64GenericEntries.
3345 * Bs3Trap64GenericEntries is an array of interrupt/trap/whatever entry
3346 * points, 8 bytes each, that will create a register frame and call the generic
3347 * C compatible trap handlers. */
3348extern uint32_t g_Bs3Trap64GenericEntriesFlatAddr;
3349
3350/**
3351 * Adjusts the DPL the IDT entry specified by @a iIdt.
3352 *
3353 * The change is applied to the 16-bit, 32-bit and 64-bit IDTs.
3354 *
3355 * @returns Old DPL (from 64-bit IDT).
3356 * @param iIdt The index of the IDT and IVT entry to set.
3357 * @param bDpl The DPL.
3358 */
3359BS3_CMN_PROTO_STUB(uint8_t, Bs3TrapSetDpl,(uint8_t iIdt, uint8_t bDpl));
3360
3361/**
3362 * C-style trap handler.
3363 *
3364 * The caller will resume the context in @a pTrapFrame upon return.
3365 *
3366 * @param pTrapFrame The trap frame. Registers can be modified.
3367 * @note The 16-bit versions must be in CGROUP16!
3368 */
3369typedef BS3_DECL_NEAR_CALLBACK(void) FNBS3TRAPHANDLER(PBS3TRAPFRAME pTrapFrame);
3370/** Pointer to a trap handler (current template context). */
3371typedef FNBS3TRAPHANDLER *PFNBS3TRAPHANDLER;
3372
3373#if ARCH_BITS == 16
3374/** @copydoc FNBS3TRAPHANDLER */
3375typedef FNBS3FAR FNBS3TRAPHANDLER32;
3376/** @copydoc FNBS3TRAPHANDLER */
3377typedef FNBS3FAR FNBS3TRAPHANDLER64;
3378#else
3379/** @copydoc FNBS3TRAPHANDLER */
3380typedef FNBS3TRAPHANDLER FNBS3TRAPHANDLER32;
3381/** @copydoc FNBS3TRAPHANDLER */
3382typedef FNBS3TRAPHANDLER FNBS3TRAPHANDLER64;
3383#endif
3384/** @copydoc PFNBS3TRAPHANDLER */
3385typedef FNBS3TRAPHANDLER32 *PFNBS3TRAPHANDLER32;
3386/** @copydoc PFNBS3TRAPHANDLER */
3387typedef FNBS3TRAPHANDLER64 *PFNBS3TRAPHANDLER64;
3388
3389
3390/**
3391 * C-style trap handler, near 16-bit (CGROUP16).
3392 *
3393 * The caller will resume the context in @a pTrapFrame upon return.
3394 *
3395 * @param pTrapFrame The trap frame. Registers can be modified.
3396 */
3397typedef BS3_DECL_NEAR_CALLBACK(void) FNBS3TRAPHANDLER16(PBS3TRAPFRAME pTrapFrame);
3398/** Pointer to a trap handler (current template context). */
3399typedef FNBS3TRAPHANDLER16 *PFNBS3TRAPHANDLER16;
3400
3401/**
3402 * C-style trap handler, near 16-bit (CGROUP16).
3403 *
3404 * The caller will resume the context in @a pTrapFrame upon return.
3405 *
3406 * @param pTrapFrame The trap frame. Registers can be modified.
3407 */
3408typedef BS3_DECL_CALLBACK(void) FNBS3TRAPHANDLER3264(PBS3TRAPFRAME pTrapFrame);
3409/** Pointer to a trap handler (current template context). */
3410typedef FNBS3TRAPHANDLER3264 *FPFNBS3TRAPHANDLER3264;
3411
3412
3413/**
3414 * Sets a trap handler (C/C++/assembly) for the current bitcount.
3415 *
3416 * @returns Previous handler.
3417 * @param iIdt The index of the IDT entry to set.
3418 * @param pfnHandler Pointer to the handler.
3419 * @sa Bs3TrapSetHandlerEx
3420 */
3421BS3_CMN_PROTO_STUB(PFNBS3TRAPHANDLER, Bs3TrapSetHandler,(uint8_t iIdt, PFNBS3TRAPHANDLER pfnHandler));
3422
3423/**
3424 * Sets a trap handler (C/C++/assembly) for all the bitcounts.
3425 *
3426 * @param iIdt The index of the IDT and IVT entry to set.
3427 * @param pfnHandler16 Pointer to the 16-bit handler. (Assumes linker addresses.)
3428 * @param pfnHandler32 Pointer to the 32-bit handler. (Assumes linker addresses.)
3429 * @param pfnHandler64 Pointer to the 64-bit handler. (Assumes linker addresses.)
3430 * @sa Bs3TrapSetHandler
3431 */
3432BS3_CMN_PROTO_STUB(void, Bs3TrapSetHandlerEx,(uint8_t iIdt, PFNBS3TRAPHANDLER16 pfnHandler16,
3433 PFNBS3TRAPHANDLER32 pfnHandler32, PFNBS3TRAPHANDLER64 pfnHandler64));
3434
3435/**
3436 * Default C/C++ trap handler.
3437 *
3438 * This will check trap record and panic if no match was found.
3439 *
3440 * @param pTrapFrame Trap frame of the trap to handle.
3441 */
3442BS3_CMN_PROTO_STUB(void, Bs3TrapDefaultHandler,(PBS3TRAPFRAME pTrapFrame));
3443
3444/**
3445 * Prints the trap frame (to screen).
3446 * @param pTrapFrame Trap frame to print.
3447 */
3448BS3_CMN_PROTO_STUB(void, Bs3TrapPrintFrame,(PCBS3TRAPFRAME pTrapFrame));
3449
3450/**
3451 * Sets up a long jump from a trap handler.
3452 *
3453 * The long jump will only be performed once, but will catch any kind of trap,
3454 * fault, interrupt or irq.
3455 *
3456 * @retval true on the initial call.
3457 * @retval false on trap return.
3458 * @param pTrapFrame Where to store the trap information when
3459 * returning @c false.
3460 * @sa #Bs3TrapUnsetJmp
3461 */
3462BS3_CMN_PROTO_NOSB(DECL_RETURNS_TWICE(bool),Bs3TrapSetJmp,(PBS3TRAPFRAME pTrapFrame));
3463
3464/**
3465 * Combination of #Bs3TrapSetJmp and #Bs3RegCtxRestore.
3466 *
3467 * @param pCtxRestore The context to restore.
3468 * @param pTrapFrame Where to store the trap information.
3469 */
3470BS3_CMN_PROTO_STUB(void, Bs3TrapSetJmpAndRestore,(PCBS3REGCTX pCtxRestore, PBS3TRAPFRAME pTrapFrame));
3471
3472/**
3473 * Variation of Bs3TrapSetJmpAndRestore that includes
3474 * #Bs3TrapSetJmpAndRestoreInRm and calls is if pCtxRestore is a real mode
3475 * context and we're not in real mode.
3476 *
3477 * This is useful for 32-bit test drivers running via #Bs3TestDoModesByOne using
3478 * BS3TESTMODEBYONEENTRY_F_REAL_MODE_READY to allow them to test real-mode too.
3479 *
3480 * @param pCtxRestore The context to restore.
3481 * @param pTrapFrame Where to store the trap information.
3482 */
3483BS3_CMN_PROTO_STUB(void, Bs3TrapSetJmpAndRestoreWithRm,(PCBS3REGCTX pCtxRestore, PBS3TRAPFRAME pTrapFrame));
3484
3485/**
3486 * Combination of #Bs3ExtCtxRestoreEx, #Bs3TrapSetJmp, #Bs3RegCtxRestore and
3487 * #Bs3ExtCtxSaveEx.
3488 *
3489 * @param pCtxRestore The context to restore.
3490 * @param pExtCtxRestore The extended context to restore.
3491 * @param pTrapFrame Where to store the trap information.
3492 * @param pExtCtxTrap Where to store the extended context after the trap.
3493 * Note, the saving isn't done from the trap handler,
3494 * but after #Bs3TrapSetJmp returns zero (i.e. for the
3495 * 2nd time).
3496 */
3497BS3_CMN_PROTO_STUB(void, Bs3TrapSetJmpAndRestoreWithExtCtx,(PCBS3REGCTX pCtxRestore, PCBS3EXTCTX pExtCtxRestore,
3498 PBS3TRAPFRAME pTrapFrame, PBS3EXTCTX pExtCtxTrap));
3499
3500/**
3501 * Variation of Bs3TrapSetJmpAndRestoreWithExtCtx that includes
3502 * #Bs3TrapSetJmpAndRestoreInRm and calls is if pCtxRestore is a real mode
3503 * context and we're not in real mode.
3504 *
3505 * This is useful for 32-bit test drivers running via #Bs3TestDoModesByOne using
3506 * BS3TESTMODEBYONEENTRY_F_REAL_MODE_READY to allow them to test real-mode too.
3507 *
3508 * @param pCtxRestore The context to restore.
3509 * @param pExtCtxRestore The extended context to restore.
3510 * @param pTrapFrame Where to store the trap information.
3511 * @param pExtCtxTrap Where to store the extended context after the trap.
3512 * Note, the saving isn't done from the trap handler,
3513 * but after #Bs3TrapSetJmp returns zero (i.e. for the
3514 * 2nd time).
3515 */
3516BS3_CMN_PROTO_STUB(void, Bs3TrapSetJmpAndRestoreWithExtCtxAndRm,(PCBS3REGCTX pCtxRestore, PCBS3EXTCTX pExtCtxRestore,
3517 PBS3TRAPFRAME pTrapFrame, PBS3EXTCTX pExtCtxTrap));
3518
3519/**
3520 * Combination of Bs3SwitchToRM, #Bs3TrapSetJmp and #Bs3RegCtxRestore.
3521 *
3522 * @param pCtxRestore The context to restore. Must be real-mode
3523 * addressable.
3524 * @param pTrapFrame Where to store the trap information. Must be
3525 * real-mode addressable.
3526 */
3527BS3_CMN_PROTO_STUB(void, Bs3TrapSetJmpAndRestoreInRm,(PCBS3REGCTX pCtxRestore, PBS3TRAPFRAME pTrapFrame));
3528
3529/**
3530 * Disables a previous #Bs3TrapSetJmp call.
3531 */
3532BS3_CMN_PROTO_STUB(void, Bs3TrapUnsetJmp,(void));
3533
3534
3535/**
3536 * The current test step.
3537 */
3538extern uint16_t g_usBs3TestStep;
3539
3540/**
3541 * Equivalent to RTTestCreate + RTTestBanner.
3542 *
3543 * @param pszTest The test name.
3544 */
3545BS3_CMN_PROTO_STUB(void, Bs3TestInit,(const char BS3_FAR *pszTest));
3546
3547
3548/**
3549 * Equivalent to RTTestSummaryAndDestroy.
3550 */
3551BS3_CMN_PROTO_STUB(void, Bs3TestTerm,(void));
3552
3553/**
3554 * Equivalent to RTTestISub.
3555 */
3556BS3_CMN_PROTO_STUB(void, Bs3TestSub,(const char BS3_FAR *pszSubTest));
3557
3558/**
3559 * Equivalent to RTTestIFailedF.
3560 */
3561BS3_CMN_PROTO_STUB(void, Bs3TestSubF,(const char BS3_FAR *pszFormat, ...));
3562
3563/**
3564 * Equivalent to RTTestISubV.
3565 */
3566BS3_CMN_PROTO_STUB(void, Bs3TestSubV,(const char BS3_FAR *pszFormat, va_list BS3_FAR va));
3567
3568/**
3569 * Equivalent to RTTestISubDone.
3570 */
3571BS3_CMN_PROTO_STUB(void, Bs3TestSubDone,(void));
3572
3573/**
3574 * Equivalent to RTTestIValue.
3575 */
3576BS3_CMN_PROTO_STUB(void, Bs3TestValue,(const char BS3_FAR *pszName, uint64_t u64Value, uint8_t bUnit));
3577
3578/**
3579 * Equivalent to RTTestSubErrorCount.
3580 */
3581BS3_CMN_PROTO_STUB(uint16_t, Bs3TestSubErrorCount,(void));
3582
3583/**
3584 * Get nanosecond host timestamp.
3585 *
3586 * This only works when testing is enabled and will not work in VMs configured
3587 * with a 286, 186 or 8086/8088 CPU profile.
3588 */
3589BS3_CMN_PROTO_STUB(uint64_t, Bs3TestNow,(void));
3590
3591
3592/**
3593 * Queries an unsigned 8-bit configuration value.
3594 *
3595 * @returns Value.
3596 * @param uCfg A VMMDEV_TESTING_CFG_XXX value.
3597 */
3598BS3_CMN_PROTO_STUB(uint8_t, Bs3TestQueryCfgU8,(uint16_t uCfg));
3599
3600/**
3601 * Queries an unsigned 8-bit configuration value.
3602 *
3603 * @returns Value.
3604 * @param uCfg A VMMDEV_TESTING_CFG_XXX value.
3605 */
3606BS3_CMN_PROTO_STUB(bool, Bs3TestQueryCfgBool,(uint16_t uCfg));
3607
3608/**
3609 * Queries an unsigned 32-bit configuration value.
3610 *
3611 * @returns Value.
3612 * @param uCfg A VMMDEV_TESTING_CFG_XXX value.
3613 */
3614BS3_CMN_PROTO_STUB(uint32_t, Bs3TestQueryCfgU32,(uint16_t uCfg));
3615
3616/**
3617 * Equivalent to RTTestIPrintf with RTTESTLVL_ALWAYS.
3618 *
3619 * @param pszFormat What to print, format string. Explicit newline char.
3620 * @param ... String format arguments.
3621 */
3622BS3_CMN_PROTO_STUB(void, Bs3TestPrintf,(const char BS3_FAR *pszFormat, ...));
3623
3624/**
3625 * Equivalent to RTTestIPrintfV with RTTESTLVL_ALWAYS.
3626 *
3627 * @param pszFormat What to print, format string. Explicit newline char.
3628 * @param va String format arguments.
3629 */
3630BS3_CMN_PROTO_STUB(void, Bs3TestPrintfV,(const char BS3_FAR *pszFormat, va_list BS3_FAR va));
3631
3632/**
3633 * Same as Bs3TestPrintf, except no guest screen echo.
3634 *
3635 * @param pszFormat What to print, format string. Explicit newline char.
3636 * @param ... String format arguments.
3637 */
3638BS3_CMN_PROTO_STUB(void, Bs3TestHostPrintf,(const char BS3_FAR *pszFormat, ...));
3639
3640/**
3641 * Same as Bs3TestPrintfV, except no guest screen echo.
3642 *
3643 * @param pszFormat What to print, format string. Explicit newline char.
3644 * @param va String format arguments.
3645 */
3646BS3_CMN_PROTO_STUB(void, Bs3TestHostPrintfV,(const char BS3_FAR *pszFormat, va_list BS3_FAR va));
3647
3648/**
3649 * Equivalent to RTTestIFailed.
3650 * @returns false.
3651 */
3652BS3_CMN_PROTO_STUB(bool, Bs3TestFailed,(const char BS3_FAR *pszMessage));
3653
3654/**
3655 * Equivalent to RTTestIFailedF.
3656 * @returns false.
3657 */
3658BS3_CMN_PROTO_STUB(bool, Bs3TestFailedF,(const char BS3_FAR *pszFormat, ...));
3659
3660/**
3661 * Equivalent to RTTestIFailedV.
3662 * @returns false.
3663 */
3664BS3_CMN_PROTO_STUB(bool, Bs3TestFailedV,(const char BS3_FAR *pszFormat, va_list BS3_FAR va));
3665
3666/**
3667 * Equivalent to RTTestISkipped.
3668 *
3669 * @param pszWhy Optional reason why it's being skipped.
3670 */
3671BS3_CMN_PROTO_STUB(void, Bs3TestSkipped,(const char BS3_FAR *pszWhy));
3672
3673/**
3674 * Equivalent to RTTestISkippedF.
3675 *
3676 * @param pszFormat Optional reason why it's being skipped.
3677 * @param ... Format arguments.
3678 */
3679BS3_CMN_PROTO_STUB(void, Bs3TestSkippedF,(const char BS3_FAR *pszFormat, ...));
3680
3681/**
3682 * Equivalent to RTTestISkippedV.
3683 *
3684 * @param pszFormat Optional reason why it's being skipped.
3685 * @param va Format arguments.
3686 */
3687BS3_CMN_PROTO_STUB(void, Bs3TestSkippedV,(const char BS3_FAR *pszFormat, va_list BS3_FAR va));
3688
3689/**
3690 * Compares two register contexts, with PC and SP adjustments.
3691 *
3692 * Differences will be reported as test failures.
3693 *
3694 * @returns true if equal, false if not.
3695 * @param pActualCtx The actual register context.
3696 * @param pExpectedCtx Expected register context.
3697 * @param cbPcAdjust Program counter adjustment (applied to @a pExpectedCtx).
3698 * @param cbSpAdjust Stack pointer adjustment (applied to @a pExpectedCtx).
3699 * @param fExtraEfl Extra EFLAGS to OR into @a pExepctedCtx.
3700 * @param pszMode CPU mode or some other helpful text.
3701 * @param idTestStep Test step identifier.
3702 */
3703BS3_CMN_PROTO_STUB(bool, Bs3TestCheckRegCtxEx,(PCBS3REGCTX pActualCtx, PCBS3REGCTX pExpectedCtx, uint16_t cbPcAdjust,
3704 int16_t cbSpAdjust, uint32_t fExtraEfl,
3705 const char BS3_FAR *pszMode, uint16_t idTestStep));
3706
3707/**
3708 * Compares two extended register contexts.
3709 *
3710 * Differences will be reported as test failures.
3711 *
3712 * @returns true if equal, false if not.
3713 * @param pActualExtCtx The actual register context.
3714 * @param pExpectedExtCtx Expected register context.
3715 * @param fFlags Reserved, pass 0.
3716 * @param pszMode CPU mode or some other helpful text.
3717 * @param idTestStep Test step identifier.
3718 */
3719BS3_CMN_PROTO_STUB(bool, Bs3TestCheckExtCtx,(PCBS3EXTCTX pActualExtCtx, PCBS3EXTCTX pExpectedExtCtx, uint16_t fFlags,
3720 const char BS3_FAR *pszMode, uint16_t idTestStep));
3721
3722/**
3723 * Performs the testing for the given mode.
3724 *
3725 * This is called with the CPU already switch to that mode.
3726 *
3727 * @returns 0 on success or directly Bs3TestFailed calls, non-zero to indicate
3728 * where the test when wrong. Special value BS3TESTDOMODE_SKIPPED
3729 * should be returned to indicate that the test has been skipped.
3730 * @param bMode The current CPU mode.
3731 */
3732typedef BS3_DECL_CALLBACK(uint8_t) FNBS3TESTDOMODE(uint8_t bMode);
3733/** Pointer (far) to a test (for 32-bit and 64-bit code, will be flatten). */
3734typedef FNBS3TESTDOMODE *PFNBS3TESTDOMODE;
3735
3736/** Special FNBS3TESTDOMODE return code for indicating a skipped mode test. */
3737#define BS3TESTDOMODE_SKIPPED UINT8_MAX
3738
3739/**
3740 * Mode sub-test entry.
3741 *
3742 * This can only be passed around to functions with the same bit count, as it
3743 * contains function pointers. In 16-bit mode, the 16-bit pointers are near and
3744 * implies BS3TEXT16, whereas the 32-bit and 64-bit pointers are far real mode
3745 * addresses that will be converted to flat address prior to calling them.
3746 * Similarly, in 32-bit and 64-bit the addresses are all flat and the 16-bit
3747 * ones will be converted to BS3TEXT16 based addresses prior to calling.
3748 */
3749typedef struct BS3TESTMODEENTRY
3750{
3751 /** The sub-test name to be passed to Bs3TestSub if not NULL. */
3752 const char * BS3_FAR pszSubTest;
3753
3754 PFNBS3TESTDOMODE pfnDoRM;
3755
3756 PFNBS3TESTDOMODE pfnDoPE16;
3757 PFNBS3TESTDOMODE pfnDoPE16_32;
3758 PFNBS3TESTDOMODE pfnDoPE16_V86;
3759 PFNBS3TESTDOMODE pfnDoPE32;
3760 PFNBS3TESTDOMODE pfnDoPE32_16;
3761 PFNBS3TESTDOMODE pfnDoPEV86;
3762
3763 PFNBS3TESTDOMODE pfnDoPP16;
3764 PFNBS3TESTDOMODE pfnDoPP16_32;
3765 PFNBS3TESTDOMODE pfnDoPP16_V86;
3766 PFNBS3TESTDOMODE pfnDoPP32;
3767 PFNBS3TESTDOMODE pfnDoPP32_16;
3768 PFNBS3TESTDOMODE pfnDoPPV86;
3769
3770 PFNBS3TESTDOMODE pfnDoPAE16;
3771 PFNBS3TESTDOMODE pfnDoPAE16_32;
3772 PFNBS3TESTDOMODE pfnDoPAE16_V86;
3773 PFNBS3TESTDOMODE pfnDoPAE32;
3774 PFNBS3TESTDOMODE pfnDoPAE32_16;
3775 PFNBS3TESTDOMODE pfnDoPAEV86;
3776
3777 PFNBS3TESTDOMODE pfnDoLM16;
3778 PFNBS3TESTDOMODE pfnDoLM32;
3779 PFNBS3TESTDOMODE pfnDoLM64;
3780
3781} BS3TESTMODEENTRY;
3782/** Pointer to a mode sub-test entry. */
3783typedef BS3TESTMODEENTRY const *PCBS3TESTMODEENTRY;
3784
3785/** @def BS3TESTMODEENTRY_CMN
3786 * Produces a BS3TESTMODEENTRY initializer for common (c16,c32,c64) test
3787 * functions. */
3788#define BS3TESTMODEENTRY_CMN(a_szTest, a_BaseNm) \
3789 { /*pszSubTest =*/ a_szTest, \
3790 /*RM*/ RT_CONCAT(a_BaseNm, _c16), \
3791 /*PE16*/ RT_CONCAT(a_BaseNm, _c16), \
3792 /*PE16_32*/ RT_CONCAT(a_BaseNm, _c32), \
3793 /*PE16_V86*/ RT_CONCAT(a_BaseNm, _c16), \
3794 /*PE32*/ RT_CONCAT(a_BaseNm, _c32), \
3795 /*PE32_16*/ RT_CONCAT(a_BaseNm, _c16), \
3796 /*PEV86*/ RT_CONCAT(a_BaseNm, _c16), \
3797 /*PP16*/ RT_CONCAT(a_BaseNm, _c16), \
3798 /*PP16_32*/ RT_CONCAT(a_BaseNm, _c32), \
3799 /*PP16_V86*/ RT_CONCAT(a_BaseNm, _c16), \
3800 /*PP32*/ RT_CONCAT(a_BaseNm, _c32), \
3801 /*PP32_16*/ RT_CONCAT(a_BaseNm, _c16), \
3802 /*PPV86*/ RT_CONCAT(a_BaseNm, _c16), \
3803 /*PAE16*/ RT_CONCAT(a_BaseNm, _c16), \
3804 /*PAE16_32*/ RT_CONCAT(a_BaseNm, _c32), \
3805 /*PAE16_V86*/ RT_CONCAT(a_BaseNm, _c16), \
3806 /*PAE32*/ RT_CONCAT(a_BaseNm, _c32), \
3807 /*PAE32_16*/ RT_CONCAT(a_BaseNm, _c16), \
3808 /*PAEV86*/ RT_CONCAT(a_BaseNm, _c16), \
3809 /*LM16*/ RT_CONCAT(a_BaseNm, _c16), \
3810 /*LM32*/ RT_CONCAT(a_BaseNm, _c32), \
3811 /*LM64*/ RT_CONCAT(a_BaseNm, _c64), \
3812 }
3813
3814/** @def BS3TESTMODE_PROTOTYPES_CMN
3815 * A set of standard protypes to go with #BS3TESTMODEENTRY_CMN. */
3816#define BS3TESTMODE_PROTOTYPES_CMN(a_BaseNm) \
3817 FNBS3TESTDOMODE /*BS3_FAR_CODE*/ RT_CONCAT(a_BaseNm, _c16); \
3818 FNBS3TESTDOMODE /*BS3_FAR_CODE*/ RT_CONCAT(a_BaseNm, _c32); \
3819 FNBS3TESTDOMODE /*BS3_FAR_CODE*/ RT_CONCAT(a_BaseNm, _c64)
3820
3821/** @def BS3TESTMODEENTRY_CMN_64
3822 * Produces a BS3TESTMODEENTRY initializer for common 64-bit test functions. */
3823#define BS3TESTMODEENTRY_CMN_64(a_szTest, a_BaseNm) \
3824 { /*pszSubTest =*/ a_szTest, \
3825 /*RM*/ NULL, \
3826 /*PE16*/ NULL, \
3827 /*PE16_32*/ NULL, \
3828 /*PE16_V86*/ NULL, \
3829 /*PE32*/ NULL, \
3830 /*PE32_16*/ NULL, \
3831 /*PEV86*/ NULL, \
3832 /*PP16*/ NULL, \
3833 /*PP16_32*/ NULL, \
3834 /*PP16_V86*/ NULL, \
3835 /*PP32*/ NULL, \
3836 /*PP32_16*/ NULL, \
3837 /*PPV86*/ NULL, \
3838 /*PAE16*/ NULL, \
3839 /*PAE16_32*/ NULL, \
3840 /*PAE16_V86*/ NULL, \
3841 /*PAE32*/ NULL, \
3842 /*PAE32_16*/ NULL, \
3843 /*PAEV86*/ NULL, \
3844 /*LM16*/ NULL, \
3845 /*LM32*/ NULL, \
3846 /*LM64*/ RT_CONCAT(a_BaseNm, _c64), \
3847 }
3848
3849/** @def BS3TESTMODE_PROTOTYPES_CMN
3850 * Standard protype to go with #BS3TESTMODEENTRY_CMN_64. */
3851#define BS3TESTMODE_PROTOTYPES_CMN_64(a_BaseNm) \
3852 FNBS3TESTDOMODE /*BS3_FAR_CODE*/ RT_CONCAT(a_BaseNm, _c64)
3853
3854/** @def BS3TESTMODEENTRY_MODE
3855 * Produces a BS3TESTMODEENTRY initializer for a full set of mode test
3856 * functions. */
3857#define BS3TESTMODEENTRY_MODE(a_szTest, a_BaseNm) \
3858 { /*pszSubTest =*/ a_szTest, \
3859 /*RM*/ RT_CONCAT(a_BaseNm, _rm), \
3860 /*PE16*/ RT_CONCAT(a_BaseNm, _pe16), \
3861 /*PE16_32*/ RT_CONCAT(a_BaseNm, _pe16_32), \
3862 /*PE16_V86*/ RT_CONCAT(a_BaseNm, _pe16_v86), \
3863 /*PE32*/ RT_CONCAT(a_BaseNm, _pe32), \
3864 /*PE32_16*/ RT_CONCAT(a_BaseNm, _pe32_16), \
3865 /*PEV86*/ RT_CONCAT(a_BaseNm, _pev86), \
3866 /*PP16*/ RT_CONCAT(a_BaseNm, _pp16), \
3867 /*PP16_32*/ RT_CONCAT(a_BaseNm, _pp16_32), \
3868 /*PP16_V86*/ RT_CONCAT(a_BaseNm, _pp16_v86), \
3869 /*PP32*/ RT_CONCAT(a_BaseNm, _pp32), \
3870 /*PP32_16*/ RT_CONCAT(a_BaseNm, _pp32_16), \
3871 /*PPV86*/ RT_CONCAT(a_BaseNm, _ppv86), \
3872 /*PAE16*/ RT_CONCAT(a_BaseNm, _pae16), \
3873 /*PAE16_32*/ RT_CONCAT(a_BaseNm, _pae16_32), \
3874 /*PAE16_V86*/ RT_CONCAT(a_BaseNm, _pae16_v86), \
3875 /*PAE32*/ RT_CONCAT(a_BaseNm, _pae32), \
3876 /*PAE32_16*/ RT_CONCAT(a_BaseNm, _pae32_16), \
3877 /*PAEV86*/ RT_CONCAT(a_BaseNm, _paev86), \
3878 /*LM16*/ RT_CONCAT(a_BaseNm, _lm16), \
3879 /*LM32*/ RT_CONCAT(a_BaseNm, _lm32), \
3880 /*LM64*/ RT_CONCAT(a_BaseNm, _lm64), \
3881 }
3882
3883/** @def BS3TESTMODE_PROTOTYPES_MODE
3884 * A set of standard protypes to go with #BS3TESTMODEENTRY_MODE. */
3885#define BS3TESTMODE_PROTOTYPES_MODE(a_BaseNm) \
3886 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _rm); \
3887 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe16); \
3888 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe16_32); \
3889 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe16_v86); \
3890 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe32); \
3891 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe32_16); \
3892 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pev86); \
3893 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp16); \
3894 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp16_32); \
3895 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp16_v86); \
3896 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp32); \
3897 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp32_16); \
3898 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _ppv86); \
3899 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae16); \
3900 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae16_32); \
3901 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae16_v86); \
3902 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae32); \
3903 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae32_16); \
3904 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _paev86); \
3905 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _lm16); \
3906 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _lm32); \
3907 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _lm64)
3908
3909
3910/**
3911 * Mode sub-test entry, max bit-count driven
3912 *
3913 * This is an alternative to BS3TESTMODEENTRY where a few workers (test drivers)
3914 * does all the work, using faster 32-bit and 64-bit code where possible. This
3915 * avoids executing workers in V8086 mode. It allows for modifying and checking
3916 * 64-bit register content when testing LM16 and LM32.
3917 *
3918 * The 16-bit workers are only used for real mode and 16-bit protected mode.
3919 * So, the 16-bit version of the code template can be stripped of anything
3920 * related to paging and/or v8086, saving code space.
3921 */
3922typedef struct BS3TESTMODEBYMAXENTRY
3923{
3924 /** The sub-test name to be passed to Bs3TestSub if not NULL. */
3925 const char * BS3_FAR pszSubTest;
3926
3927 PFNBS3TESTDOMODE pfnDoRM;
3928 PFNBS3TESTDOMODE pfnDoPE16;
3929 PFNBS3TESTDOMODE pfnDoPE16_32;
3930 PFNBS3TESTDOMODE pfnDoPE32;
3931 PFNBS3TESTDOMODE pfnDoPP16_32;
3932 PFNBS3TESTDOMODE pfnDoPP32;
3933 PFNBS3TESTDOMODE pfnDoPAE16_32;
3934 PFNBS3TESTDOMODE pfnDoPAE32;
3935 PFNBS3TESTDOMODE pfnDoLM64;
3936
3937 bool fDoRM : 1;
3938
3939 bool fDoPE16 : 1;
3940 bool fDoPE16_32 : 1;
3941 bool fDoPE16_V86 : 1;
3942 bool fDoPE32 : 1;
3943 bool fDoPE32_16 : 1;
3944 bool fDoPEV86 : 1;
3945
3946 bool fDoPP16 : 1;
3947 bool fDoPP16_32 : 1;
3948 bool fDoPP16_V86 : 1;
3949 bool fDoPP32 : 1;
3950 bool fDoPP32_16 : 1;
3951 bool fDoPPV86 : 1;
3952
3953 bool fDoPAE16 : 1;
3954 bool fDoPAE16_32 : 1;
3955 bool fDoPAE16_V86 : 1;
3956 bool fDoPAE32 : 1;
3957 bool fDoPAE32_16 : 1;
3958 bool fDoPAEV86 : 1;
3959
3960 bool fDoLM16 : 1;
3961 bool fDoLM32 : 1;
3962 bool fDoLM64 : 1;
3963
3964} BS3TESTMODEBYMAXENTRY;
3965/** Pointer to a mode-by-max sub-test entry. */
3966typedef BS3TESTMODEBYMAXENTRY const *PCBS3TESTMODEBYMAXENTRY;
3967
3968/** @def BS3TESTMODEBYMAXENTRY_CMN
3969 * Produces a BS3TESTMODEBYMAXENTRY initializer for common (c16,c32,c64) test
3970 * functions. */
3971#define BS3TESTMODEBYMAXENTRY_CMN(a_szTest, a_BaseNm) \
3972 { /*pszSubTest =*/ a_szTest, \
3973 /*RM*/ RT_CONCAT(a_BaseNm, _c16), \
3974 /*PE16*/ RT_CONCAT(a_BaseNm, _c16), \
3975 /*PE16_32*/ RT_CONCAT(a_BaseNm, _c32), \
3976 /*PE32*/ RT_CONCAT(a_BaseNm, _c32), \
3977 /*PP16_32*/ RT_CONCAT(a_BaseNm, _c32), \
3978 /*PP32*/ RT_CONCAT(a_BaseNm, _c32), \
3979 /*PAE16_32*/ RT_CONCAT(a_BaseNm, _c32), \
3980 /*PAE32*/ RT_CONCAT(a_BaseNm, _c32), \
3981 /*LM64*/ RT_CONCAT(a_BaseNm, _c64), \
3982 /*fDoRM*/ true, \
3983 /*fDoPE16*/ true, \
3984 /*fDoPE16_32*/ true, \
3985 /*fDoPE16_V86*/ true, \
3986 /*fDoPE32*/ true, \
3987 /*fDoPE32_16*/ true, \
3988 /*fDoPEV86*/ true, \
3989 /*fDoPP16*/ true, \
3990 /*fDoPP16_32*/ true, \
3991 /*fDoPP16_V86*/ true, \
3992 /*fDoPP32*/ true, \
3993 /*fDoPP32_16*/ true, \
3994 /*fDoPPV86*/ true, \
3995 /*fDoPAE16*/ true, \
3996 /*fDoPAE16_32*/ true, \
3997 /*fDoPAE16_V86*/ true, \
3998 /*fDoPAE32*/ true, \
3999 /*fDoPAE32_16*/ true, \
4000 /*fDoPAEV86*/ true, \
4001 /*fDoLM16*/ true, \
4002 /*fDoLM32*/ true, \
4003 /*fDoLM64*/ true, \
4004 }
4005
4006/** @def BS3TESTMODEBYMAX_PROTOTYPES_CMN
4007 * A set of standard protypes to go with #BS3TESTMODEBYMAXENTRY_CMN. */
4008#define BS3TESTMODEBYMAX_PROTOTYPES_CMN(a_BaseNm) \
4009 FNBS3TESTDOMODE /*BS3_FAR_CODE*/ RT_CONCAT(a_BaseNm, _c16); \
4010 FNBS3TESTDOMODE /*BS3_FAR_CODE*/ RT_CONCAT(a_BaseNm, _c32); \
4011 FNBS3TESTDOMODE /*BS3_FAR_CODE*/ RT_CONCAT(a_BaseNm, _c64)
4012
4013
4014/** @def BS3TESTMODEBYMAXENTRY_MODE
4015 * Produces a BS3TESTMODEBYMAXENTRY initializer for a full set of mode test
4016 * functions. */
4017#define BS3TESTMODEBYMAXENTRY_MODE(a_szTest, a_BaseNm) \
4018 { /*pszSubTest =*/ a_szTest, \
4019 /*RM*/ RT_CONCAT(a_BaseNm, _rm), \
4020 /*PE16*/ RT_CONCAT(a_BaseNm, _pe16), \
4021 /*PE16_32*/ RT_CONCAT(a_BaseNm, _pe16_32), \
4022 /*PE32*/ RT_CONCAT(a_BaseNm, _pe32), \
4023 /*PP16_32*/ RT_CONCAT(a_BaseNm, _pp16_32), \
4024 /*PP32*/ RT_CONCAT(a_BaseNm, _pp32), \
4025 /*PAE16_32*/ RT_CONCAT(a_BaseNm, _pae16_32), \
4026 /*PAE32*/ RT_CONCAT(a_BaseNm, _pae32), \
4027 /*LM64*/ RT_CONCAT(a_BaseNm, _lm64), \
4028 /*fDoRM*/ true, \
4029 /*fDoPE16*/ true, \
4030 /*fDoPE16_32*/ true, \
4031 /*fDoPE16_V86*/ true, \
4032 /*fDoPE32*/ true, \
4033 /*fDoPE32_16*/ true, \
4034 /*fDoPEV86*/ true, \
4035 /*fDoPP16*/ true, \
4036 /*fDoPP16_32*/ true, \
4037 /*fDoPP16_V86*/ true, \
4038 /*fDoPP32*/ true, \
4039 /*fDoPP32_16*/ true, \
4040 /*fDoPPV86*/ true, \
4041 /*fDoPAE16*/ true, \
4042 /*fDoPAE16_32*/ true, \
4043 /*fDoPAE16_V86*/ true, \
4044 /*fDoPAE32*/ true, \
4045 /*fDoPAE32_16*/ true, \
4046 /*fDoPAEV86*/ true, \
4047 /*fDoLM16*/ true, \
4048 /*fDoLM32*/ true, \
4049 /*fDoLM64*/ true, \
4050 }
4051
4052/** @def BS3TESTMODEBYMAX_PROTOTYPES_MODE
4053 * A set of standard protypes to go with #BS3TESTMODEBYMAXENTRY_MODE. */
4054#define BS3TESTMODEBYMAX_PROTOTYPES_MODE(a_BaseNm) \
4055 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _rm); \
4056 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe16); \
4057 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe16_32); \
4058 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe32); \
4059 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp16_32); \
4060 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp32); \
4061 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae16_32); \
4062 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae32); \
4063 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _lm64)
4064
4065
4066/**
4067 * One worker drives all modes.
4068 *
4069 * This is an alternative to BS3TESTMODEENTRY where one worker, typically
4070 * 16-bit, does all the test driver work. It's called repeatedly from all
4071 * the modes being tested.
4072 */
4073typedef struct BS3TESTMODEBYONEENTRY
4074{
4075 const char * BS3_FAR pszSubTest;
4076 PFNBS3TESTDOMODE pfnWorker;
4077 /** BS3TESTMODEBYONEENTRY_F_XXX. */
4078 uint32_t fFlags;
4079} BS3TESTMODEBYONEENTRY;
4080/** Pointer to a mode-by-one sub-test entry. */
4081typedef BS3TESTMODEBYONEENTRY const *PCBS3TESTMODEBYONEENTRY;
4082
4083/** @name BS3TESTMODEBYONEENTRY_F_XXX - flags.
4084 * @{ */
4085/** Only test modes that has paging enabled. */
4086#define BS3TESTMODEBYONEENTRY_F_ONLY_PAGING RT_BIT_32(0)
4087/** Minimal mode selection. */
4088#define BS3TESTMODEBYONEENTRY_F_MINIMAL RT_BIT_32(1)
4089/** The 32-bit worker is ready to handle real-mode by mode switching. */
4090#define BS3TESTMODEBYONEENTRY_F_REAL_MODE_READY RT_BIT_32(2)
4091/** @} */
4092
4093
4094/**
4095 * Sets the full GDTR register.
4096 *
4097 * @param cbLimit The limit.
4098 * @param uBase The base address - 24, 32 or 64 bit depending on the
4099 * CPU mode.
4100 */
4101BS3_CMN_PROTO_NOSB(void, Bs3UtilSetFullGdtr,(uint16_t cbLimit, uint64_t uBase));
4102
4103/**
4104 * Sets the full IDTR register.
4105 *
4106 * @param cbLimit The limit.
4107 * @param uBase The base address - 24, 32 or 64 bit depending on the
4108 * CPU mode.
4109 */
4110BS3_CMN_PROTO_NOSB(void, Bs3UtilSetFullIdtr,(uint16_t cbLimit, uint64_t uBase));
4111
4112
4113/** @} */
4114
4115
4116/**
4117 * Initializes all of boot sector kit \#3.
4118 */
4119BS3_DECL(void) Bs3InitAll_rm(void);
4120
4121/**
4122 * Initializes the REAL and TILED memory pools.
4123 *
4124 * For proper operation on OLDer CPUs, call #Bs3CpuDetect_mmm first.
4125 */
4126BS3_DECL_FAR(void) Bs3InitMemory_rm_far(void);
4127
4128/**
4129 * Initializes the X0TEXT16 and X1TEXT16 GDT entries.
4130 */
4131BS3_DECL_FAR(void) Bs3InitGdt_rm_far(void);
4132
4133
4134
4135/** @defgroup grp_bs3kit_mode Mode Specific Functions and Data
4136 *
4137 * The mode specific functions come in bit count variations and CPU mode
4138 * variations. The bs3kit-template-header.h/mac defines the BS3_NM macro to
4139 * mangle a function or variable name according to the target CPU mode. In
4140 * non-templated code, it's common to spell the name out in full.
4141 *
4142 * @{
4143 */
4144
4145
4146/** @def BS3_MODE_PROTO_INT
4147 * Internal macro for emitting prototypes for mode functions.
4148 *
4149 * @param a_RetType The return type.
4150 * @param a_Name The function basename.
4151 * @param a_Params The parameter list (in parentheses).
4152 * @sa BS3_MODE_PROTO_STUB, BS3_MODE_PROTO_NOSB
4153 */
4154#define BS3_MODE_PROTO_INT(a_RetType, a_Name, a_Params) \
4155 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_rm) a_Params; \
4156 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe16) a_Params; \
4157 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe16_32) a_Params; \
4158 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe16_v86) a_Params; \
4159 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe32) a_Params; \
4160 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe32_16) a_Params; \
4161 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pev86) a_Params; \
4162 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp16) a_Params; \
4163 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp16_32) a_Params; \
4164 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp16_v86) a_Params; \
4165 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp32) a_Params; \
4166 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp32_16) a_Params; \
4167 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_ppv86) a_Params; \
4168 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae16) a_Params; \
4169 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae16_32) a_Params; \
4170 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae16_v86) a_Params; \
4171 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae32) a_Params; \
4172 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae32_16) a_Params; \
4173 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_paev86) a_Params; \
4174 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_lm16) a_Params; \
4175 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_lm32) a_Params; \
4176 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_lm64) a_Params; \
4177 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_rm_far) a_Params; \
4178 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pe16_far) a_Params; \
4179 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pe16_v86_far) a_Params; \
4180 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pe32_16_far) a_Params; \
4181 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pev86_far) a_Params; \
4182 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pp16_far) a_Params; \
4183 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pp16_v86_far) a_Params; \
4184 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pp32_16_far) a_Params; \
4185 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_ppv86_far) a_Params; \
4186 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pae16_far) a_Params; \
4187 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pae16_v86_far)a_Params; \
4188 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pae32_16_far) a_Params; \
4189 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_paev86_far) a_Params; \
4190 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_lm16_far) a_Params
4191
4192/** @def BS3_MODE_PROTO_STUB
4193 * Macro for prototyping all the variations of a mod function with automatic
4194 * near -> far stub.
4195 *
4196 * @param a_RetType The return type.
4197 * @param a_Name The function basename.
4198 * @param a_Params The parameter list (in parentheses).
4199 * @sa BS3_MODE_PROTO_STUB, BS3_MODE_PROTO_NOSB
4200 */
4201#define BS3_MODE_PROTO_STUB(a_RetType, a_Name, a_Params) BS3_MODE_PROTO_INT(a_RetType, a_Name, a_Params)
4202
4203/** @def BS3_MODE_PROTO_STUB
4204 * Macro for prototyping all the variations of a mod function without any
4205 * near -> far stub.
4206 *
4207 * @param a_RetType The return type.
4208 * @param a_Name The function basename.
4209 * @param a_Params The parameter list (in parentheses).
4210 * @sa BS3_MODE_PROTO_STUB, BS3_MODE_PROTO_NOSB
4211 */
4212#define BS3_MODE_PROTO_NOSB(a_RetType, a_Name, a_Params) BS3_MODE_PROTO_INT(a_RetType, a_Name, a_Params)
4213
4214
4215/**
4216 * Macro for reducing typing.
4217 *
4218 * Doxygen knows how to expand this, well, kind of.
4219 *
4220 * @remarks Variables instantiated in assembly code should define two labels,
4221 * with and without leading underscore. Variables instantiated from
4222 * C/C++ code doesn't need to as the object file convert does this for
4223 * 64-bit object files.
4224 */
4225#define BS3_MODE_EXPAND_EXTERN_DATA16(a_VarType, a_VarName, a_Suffix) \
4226 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_rm) a_Suffix; \
4227 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pe16) a_Suffix; \
4228 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pe16_32) a_Suffix; \
4229 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pe16_v86) a_Suffix; \
4230 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pe32) a_Suffix; \
4231 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pe32_16) a_Suffix; \
4232 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pev86) a_Suffix; \
4233 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pp16) a_Suffix; \
4234 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pp16_32) a_Suffix; \
4235 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pp16_v86) a_Suffix; \
4236 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pp32) a_Suffix; \
4237 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pp32_16) a_Suffix; \
4238 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_ppv86) a_Suffix; \
4239 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pae16) a_Suffix; \
4240 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pae16_32) a_Suffix; \
4241 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pae16_v86)a_Suffix; \
4242 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pae32) a_Suffix; \
4243 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pae32_16) a_Suffix; \
4244 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_paev86) a_Suffix; \
4245 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_lm16) a_Suffix; \
4246 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_lm32) a_Suffix; \
4247 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_lm64) a_Suffix
4248
4249
4250/** The TMPL_MODE_STR value for each mode.
4251 * These are all in DATA16 so they can be accessed from any code. */
4252BS3_MODE_EXPAND_EXTERN_DATA16(const char, g_szBs3ModeName, []);
4253/** The TMPL_MODE_LNAME value for each mode.
4254 * These are all in DATA16 so they can be accessed from any code. */
4255BS3_MODE_EXPAND_EXTERN_DATA16(const char, g_szBs3ModeNameShortLower, []);
4256
4257
4258/**
4259 * Basic CPU detection.
4260 *
4261 * This sets the #g_uBs3CpuDetected global variable to the return value.
4262 *
4263 * @returns BS3CPU_XXX value with the BS3CPU_F_CPUID flag set depending on
4264 * capabilities.
4265 */
4266BS3_MODE_PROTO_NOSB(uint8_t, Bs3CpuDetect,(void));
4267
4268/** @name BS3CPU_XXX - CPU detected by BS3CpuDetect_c16() and friends.
4269 * @{ */
4270#define BS3CPU_8086 UINT16_C(0x0001) /**< Both 8086 and 8088. */
4271#define BS3CPU_V20 UINT16_C(0x0002) /**< Both NEC V20, V30 and relatives. */
4272#define BS3CPU_80186 UINT16_C(0x0003) /**< Both 80186 and 80188. */
4273#define BS3CPU_80286 UINT16_C(0x0004)
4274#define BS3CPU_80386 UINT16_C(0x0005)
4275#define BS3CPU_80486 UINT16_C(0x0006)
4276#define BS3CPU_Pentium UINT16_C(0x0007)
4277#define BS3CPU_PPro UINT16_C(0x0008)
4278#define BS3CPU_PProOrNewer UINT16_C(0x0009)
4279/** CPU type mask. This is a full byte so it's possible to use byte access
4280 * without and AND'ing to get the type value. */
4281#define BS3CPU_TYPE_MASK UINT16_C(0x00ff)
4282/** Flag indicating that the CPUID instruction is supported by the CPU. */
4283#define BS3CPU_F_CPUID UINT16_C(0x0100)
4284/** Flag indicating that extend CPUID leaves are available (at least two). */
4285#define BS3CPU_F_CPUID_EXT_LEAVES UINT16_C(0x0200)
4286/** Flag indicating that the CPU supports PAE. */
4287#define BS3CPU_F_PAE UINT16_C(0x0400)
4288/** Flag indicating that the CPU supports the page size extension (4MB pages). */
4289#define BS3CPU_F_PSE UINT16_C(0x0800)
4290/** Flag indicating that the CPU supports long mode. */
4291#define BS3CPU_F_LONG_MODE UINT16_C(0x1000)
4292/** Flag indicating that the CPU supports NX. */
4293#define BS3CPU_F_NX UINT16_C(0x2000)
4294/** @} */
4295
4296/** The return value of #Bs3CpuDetect_mmm. (Initial value is BS3CPU_TYPE_MASK.) */
4297extern uint16_t g_uBs3CpuDetected;
4298
4299/**
4300 * Call 32-bit prot mode C function.
4301 *
4302 * This switches to 32-bit mode and calls the 32-bit @a fpfnCall C code with @a
4303 * cbParams on the stack, then returns in the original mode. When called in
4304 * real mode, this will switch to PE32.
4305 *
4306 * @returns 32-bit status code if the function returned anything.
4307 * @param fpfnCall Address of the 32-bit C function to call. When
4308 * called from 16-bit code, this is a far real mode
4309 * function pointer, i.e. as fixed up by the linker.
4310 * In 32-bit and 64-bit code, this is a flat address.
4311 * @param cbParams The size of the parameter list, in bytes.
4312 * @param ... The parameters.
4313 * @sa Bs3SwitchFromV86To16BitAndCallC
4314 *
4315 * @remarks WARNING! This probably doesn't work in 64-bit mode yet.
4316 * Only tested for 16-bit real mode.
4317 */
4318BS3_MODE_PROTO_STUB(int32_t, Bs3SwitchTo32BitAndCallC,(FPFNBS3FAR fpfnCall, unsigned cbParams, ...));
4319
4320/**
4321 * Initializes trap handling for the current system.
4322 *
4323 * Calls the appropriate Bs3Trap16Init, Bs3Trap32Init or Bs3Trap64Init function.
4324 */
4325BS3_MODE_PROTO_STUB(void, Bs3TrapInit,(void));
4326
4327/**
4328 * Executes the array of tests in every possibly mode.
4329 *
4330 * @param paEntries The mode sub-test entries.
4331 * @param cEntries The number of sub-test entries.
4332 */
4333BS3_MODE_PROTO_NOSB(void, Bs3TestDoModes,(PCBS3TESTMODEENTRY paEntries, size_t cEntries));
4334
4335/**
4336 * Executes the array of tests in every possibly mode, unified driver.
4337 *
4338 * This requires much less code space than Bs3TestDoModes as there is only one
4339 * instace of each sub-test driver code, instead of 3 (cmn) or 22 (per-mode)
4340 * copies.
4341 *
4342 * @param paEntries The mode sub-test-by-one entries.
4343 * @param cEntries The number of sub-test-by-one entries.
4344 * @param fFlags BS3TESTMODEBYONEENTRY_F_XXX.
4345 */
4346BS3_MODE_PROTO_NOSB(void, Bs3TestDoModesByOne,(PCBS3TESTMODEBYONEENTRY paEntries, size_t cEntries, uint32_t fFlags));
4347
4348/**
4349 * Executes the array of tests in every possibly mode, using the max bit-count
4350 * worker for each.
4351 *
4352 * @param paEntries The mode sub-test entries.
4353 * @param cEntries The number of sub-test entries.
4354 */
4355BS3_MODE_PROTO_NOSB(void, Bs3TestDoModesByMax,(PCBS3TESTMODEBYMAXENTRY paEntries, size_t cEntries));
4356
4357/** @} */
4358
4359
4360/** @defgroup grp_bs3kit_bios_int15 BIOS - int 15h
4361 * @{ */
4362
4363/** An INT15E820 data entry. */
4364typedef struct INT15E820ENTRY
4365{
4366 uint64_t uBaseAddr;
4367 uint64_t cbRange;
4368 /** Memory type this entry describes, see INT15E820_TYPE_XXX. */
4369 uint32_t uType;
4370 /** Optional. */
4371 uint32_t fAcpi3;
4372} INT15E820ENTRY;
4373AssertCompileSize(INT15E820ENTRY,24);
4374
4375
4376/** @name INT15E820_TYPE_XXX - Memory types returned by int 15h function 0xe820.
4377 * @{ */
4378#define INT15E820_TYPE_USABLE 1 /**< Usable RAM. */
4379#define INT15E820_TYPE_RESERVED 2 /**< Reserved by the system, unusable. */
4380#define INT15E820_TYPE_ACPI_RECLAIMABLE 3 /**< ACPI reclaimable memory, whatever that means. */
4381#define INT15E820_TYPE_ACPI_NVS 4 /**< ACPI non-volatile storage? */
4382#define INT15E820_TYPE_BAD 5 /**< Bad memory, unusable. */
4383/** @} */
4384
4385
4386/**
4387 * Performs an int 15h function 0xe820 call.
4388 *
4389 * @returns Success indicator.
4390 * @param pEntry The return buffer.
4391 * @param pcbEntry Input: The size of the buffer (min 20 bytes);
4392 * Output: The size of the returned data.
4393 * @param puContinuationValue Where to get and return the continuation value (EBX)
4394 * Set to zero the for the first call. Returned as zero
4395 * after the last entry.
4396 */
4397BS3_MODE_PROTO_STUB(bool, Bs3BiosInt15hE820,(INT15E820ENTRY BS3_FAR *pEntry, uint32_t BS3_FAR *pcbEntry,
4398 uint32_t BS3_FAR *puContinuationValue));
4399
4400/**
4401 * Performs an int 15h function 0x88 call.
4402 *
4403 * @returns UINT32_MAX on failure, number of KBs above 1MB otherwise.
4404 */
4405#if ARCH_BITS != 16 || !defined(BS3_BIOS_INLINE_RM)
4406BS3_MODE_PROTO_STUB(uint32_t, Bs3BiosInt15h88,(void));
4407#else
4408BS3_DECL(uint32_t) Bs3BiosInt15h88(void);
4409# pragma aux Bs3BiosInt15h88 = \
4410 ".286" \
4411 "clc" \
4412 "mov ax, 08800h" \
4413 "int 15h" \
4414 "jc failed" \
4415 "xor dx, dx" \
4416 "jmp done" \
4417 "failed:" \
4418 "xor ax, ax" \
4419 "dec ax" \
4420 "mov dx, ax" \
4421 "done:" \
4422 value [ax dx] \
4423 modify exact [ax bx cx dx es];
4424#endif
4425
4426/** @} */
4427
4428
4429/** @} */
4430
4431RT_C_DECLS_END
4432
4433
4434/*
4435 * Include default function symbol mangling.
4436 */
4437#include "bs3kit-mangling-code.h"
4438
4439/*
4440 * Change 16-bit text segment if requested.
4441 */
4442#if defined(BS3_USE_ALT_16BIT_TEXT_SEG) && ARCH_BITS == 16 && !defined(BS3_DONT_CHANGE_TEXT_SEG)
4443# if (defined(BS3_USE_RM_TEXT_SEG) + defined(BS3_USE_X0_TEXT_SEG) + defined(BS3_USE_X1_TEXT_SEG)) != 1
4444# error "Cannot set more than one alternative 16-bit text segment!"
4445# elif defined(BS3_USE_RM_TEXT_SEG)
4446# pragma code_seg("BS3RMTEXT16", "BS3CLASS16RMCODE")
4447# elif defined(BS3_USE_X0_TEXT_SEG)
4448# pragma code_seg("BS3X0TEXT16", "BS3CLASS16X0CODE")
4449# elif defined(BS3_USE_X1_TEXT_SEG)
4450# pragma code_seg("BS3X1TEXT16", "BS3CLASS16X1CODE")
4451# else
4452# error "Huh? Which alternative text segment did you want again?"
4453# endif
4454#endif
4455
4456#endif /* !BS3KIT_INCLUDED_bs3kit_h */
4457
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette