VirtualBox

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

最後變更 在這個檔案從95534是 95496,由 vboxsync 提交於 3 年 前

ValKit/bs3kit: Added some wrapper functions for better dealing with 32-bit test drivers needing to handle RM and general for restoring and saving extended state. bugref:9898

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

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