VirtualBox

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

Last change on this file since 97320 was 97320, checked in by vboxsync, 2 years ago

ValKit/bs3kit: Added a Bs3SelSetup32BitCode function for quickly setting up a 32-bit code segment.

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

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