VirtualBox

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

Last change on this file since 65847 was 65507, checked in by vboxsync, 8 years ago

bs3-cpu-instr-2: Simple cmpxchg16b testcase.

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