VirtualBox

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

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

ValidationKit/Bs3Kit: Doxygen

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 140.4 KB
Line 
1/* $Id: bs3kit.h 64367 2016-10-22 17:25:58Z 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/**
1852 * Slab control structure list head.
1853 *
1854 * The slabs on the list must all have the same chunk size.
1855 */
1856typedef struct BS3SLABHEAD
1857{
1858 /** Pointer to the first slab. */
1859 BS3_XPTR_MEMBER(struct BS3SLABCTL, pFirst);
1860 /** The allocation chunk size. */
1861 uint16_t cbChunk;
1862 /** Number of slabs in the list. */
1863 uint16_t cSlabs;
1864 /** Number of chunks in the list. */
1865 uint32_t cChunks;
1866 /** Number of free chunks. */
1867 uint32_t cFreeChunks;
1868} BS3SLABHEAD;
1869AssertCompileSize(BS3SLABHEAD, 16);
1870/** Pointer to a slab list head. */
1871typedef BS3SLABHEAD BS3_FAR *PBS3SLABHEAD;
1872
1873/**
1874 * Allocation slab control structure.
1875 *
1876 * This may live at the start of the slab for 4KB slabs, while in a separate
1877 * static location for the larger ones.
1878 */
1879typedef struct BS3SLABCTL
1880{
1881 /** Pointer to the next slab control structure in this list. */
1882 BS3_XPTR_MEMBER(struct BS3SLABCTL, pNext);
1883 /** Pointer to the slab list head. */
1884 BS3_XPTR_MEMBER(BS3SLABHEAD, pHead);
1885 /** The base address of the slab. */
1886 BS3_XPTR_MEMBER(uint8_t, pbStart);
1887 /** Number of chunks in this slab. */
1888 uint16_t cChunks;
1889 /** Number of currently free chunks. */
1890 uint16_t cFreeChunks;
1891 /** The chunk size. */
1892 uint16_t cbChunk;
1893 /** The shift count corresponding to cbChunk.
1894 * This is for turning a chunk number into a byte offset and vice versa. */
1895 uint16_t cChunkShift;
1896 /** Bitmap where set bits indicates allocated blocks (variable size,
1897 * multiple of 4). */
1898 uint8_t bmAllocated[4];
1899} BS3SLABCTL;
1900/** Pointer to a bs3kit slab control structure. */
1901typedef BS3SLABCTL BS3_FAR *PBS3SLABCTL;
1902
1903/** The chunks must all be in the same 16-bit segment tile. */
1904#define BS3_SLAB_ALLOC_F_SAME_TILE UINT16_C(0x0001)
1905
1906/**
1907 * Initializes a slab.
1908 *
1909 * @param pSlabCtl The slab control structure to initialize.
1910 * @param cbSlabCtl The size of the slab control structure.
1911 * @param uFlatSlabPtr The base address of the slab.
1912 * @param cbSlab The size of the slab.
1913 * @param cbChunk The chunk size.
1914 */
1915BS3_CMN_PROTO_STUB(void, Bs3SlabInit,(PBS3SLABCTL pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr,
1916 uint32_t cbSlab, uint16_t cbChunk));
1917
1918/**
1919 * Allocates one chunk from a slab.
1920 *
1921 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
1922 * @param pSlabCtl The slab constrol structure to allocate from.
1923 */
1924BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3SlabAlloc,(PBS3SLABCTL pSlabCtl));
1925
1926/**
1927 * Allocates one or more chunks rom a slab.
1928 *
1929 * @returns Pointer to the request number of chunks on success, NULL if we're
1930 * out of chunks.
1931 * @param pSlabCtl The slab constrol structure to allocate from.
1932 * @param cChunks The number of contiguous chunks we want.
1933 * @param fFlags Flags, see BS3_SLAB_ALLOC_F_XXX
1934 */
1935BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3SlabAllocEx,(PBS3SLABCTL pSlabCtl, uint16_t cChunks, uint16_t fFlags));
1936
1937/**
1938 * Frees one or more chunks from a slab.
1939 *
1940 * @returns Number of chunks actually freed. When correctly used, this will
1941 * match the @a cChunks parameter, of course.
1942 * @param pSlabCtl The slab constrol structure to free from.
1943 * @param uFlatChunkPtr The flat address of the chunks to free.
1944 * @param cChunks The number of contiguous chunks to free.
1945 */
1946BS3_CMN_PROTO_STUB(uint16_t, Bs3SlabFree,(PBS3SLABCTL pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks));
1947
1948
1949/**
1950 * Initializes the given slab list head.
1951 *
1952 * @param pHead The slab list head.
1953 * @param cbChunk The chunk size.
1954 */
1955BS3_CMN_PROTO_STUB(void, Bs3SlabListInit,(PBS3SLABHEAD pHead, uint16_t cbChunk));
1956
1957/**
1958 * Adds an initialized slab control structure to the list.
1959 *
1960 * @param pHead The slab list head to add it to.
1961 * @param pSlabCtl The slab control structure to add.
1962 */
1963BS3_CMN_PROTO_STUB(void, Bs3SlabListAdd,(PBS3SLABHEAD pHead, PBS3SLABCTL pSlabCtl));
1964
1965/**
1966 * Allocates one chunk.
1967 *
1968 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
1969 * @param pHead The slab list to allocate from.
1970 */
1971BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3SlabListAlloc,(PBS3SLABHEAD pHead));
1972
1973/**
1974 * Allocates one or more chunks.
1975 *
1976 * @returns Pointer to the request number of chunks on success, NULL if we're
1977 * out of chunks.
1978 * @param pHead The slab list to allocate from.
1979 * @param cChunks The number of contiguous chunks we want.
1980 * @param fFlags Flags, see BS3_SLAB_ALLOC_F_XXX
1981 */
1982BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3SlabListAllocEx,(PBS3SLABHEAD pHead, uint16_t cChunks, uint16_t fFlags));
1983
1984/**
1985 * Frees one or more chunks from a slab list.
1986 *
1987 * @param pHead The slab list to allocate from.
1988 * @param pvChunks Pointer to the first chunk to free.
1989 * @param cChunks The number of contiguous chunks to free.
1990 */
1991BS3_CMN_PROTO_STUB(void, Bs3SlabListFree,(PBS3SLABHEAD pHead, void BS3_FAR *pvChunks, uint16_t cChunks));
1992
1993/**
1994 * Allocation addressing constraints.
1995 */
1996typedef enum BS3MEMKIND
1997{
1998 /** Invalid zero type. */
1999 BS3MEMKIND_INVALID = 0,
2000 /** Real mode addressable memory. */
2001 BS3MEMKIND_REAL,
2002 /** Memory addressable using the 16-bit protected mode tiling. */
2003 BS3MEMKIND_TILED,
2004 /** Memory addressable using 32-bit flat addressing. */
2005 BS3MEMKIND_FLAT32,
2006 /** Memory addressable using 64-bit flat addressing. */
2007 BS3MEMKIND_FLAT64,
2008 /** End of valid types. */
2009 BS3MEMKIND_END,
2010} BS3MEMKIND;
2011
2012/**
2013 * Allocates low memory.
2014 *
2015 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
2016 * @param enmKind The kind of addressing constraints imposed on the
2017 * allocation.
2018 * @param cb How much to allocate. Must be 4KB or less.
2019 */
2020BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemAlloc,(BS3MEMKIND enmKind, size_t cb));
2021
2022/**
2023 * Allocates zero'ed memory.
2024 *
2025 * @param enmKind The kind of addressing constraints imposed on the
2026 * allocation.
2027 * @param cb How much to allocate. Must be 4KB or less.
2028 */
2029BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemAllocZ,(BS3MEMKIND enmKind, size_t cb));
2030
2031/**
2032 * Frees memory.
2033 *
2034 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
2035 * @param pv The memory to free (returned by #Bs3MemAlloc).
2036 * @param cb The size of the allocation.
2037 */
2038BS3_CMN_PROTO_STUB(void, Bs3MemFree,(void BS3_FAR *pv, size_t cb));
2039
2040/**
2041 * Allocates a page with non-present pages on each side.
2042 *
2043 * @returns Pointer to the usable page. NULL on failure. Use
2044 * Bs3MemGuardedTestPageFree to free the allocation.
2045 * @param enmKind The kind of addressing constraints imposed on the
2046 * allocation.
2047 */
2048BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemGuardedTestPageAlloc,(BS3MEMKIND enmKind));
2049
2050/**
2051 * Allocates a page with pages on each side to the @a fPte specification.
2052 *
2053 * @returns Pointer to the usable page. NULL on failure. Use
2054 * Bs3MemGuardedTestPageFree to free the allocation.
2055 * @param enmKind The kind of addressing constraints imposed on the
2056 * allocation.
2057 * @param fPte The page table entry specification for the guard pages.
2058 */
2059BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemGuardedTestPageAllocEx,(BS3MEMKIND enmKind, uint64_t fPte));
2060
2061/**
2062 * Frees guarded page allocated by Bs3MemGuardedTestPageAlloc or
2063 * Bs3MemGuardedTestPageAllocEx.
2064 *
2065 * @param pvGuardedPage Pointer returned by Bs3MemGuardedTestPageAlloc or
2066 * Bs3MemGuardedTestPageAllocEx. NULL is ignored.
2067 */
2068BS3_CMN_PROTO_STUB(void, Bs3MemGuardedTestPageFree,(void BS3_FAR *pvGuardedPage));
2069
2070/** Highes RAM byte below 4G. */
2071extern uint32_t g_uBs3EndOfRamBelow4G;
2072
2073
2074/**
2075 * Enables the A20 gate.
2076 */
2077BS3_CMN_PROTO_NOSB(void, Bs3A20Enable,(void));
2078
2079/**
2080 * Enables the A20 gate via the keyboard controller
2081 */
2082BS3_CMN_PROTO_NOSB(void, Bs3A20EnableViaKbd,(void));
2083
2084/**
2085 * Enables the A20 gate via the PS/2 control port A.
2086 */
2087BS3_CMN_PROTO_NOSB(void, Bs3A20EnableViaPortA,(void));
2088
2089/**
2090 * Disables the A20 gate.
2091 */
2092BS3_CMN_PROTO_NOSB(void, Bs3A20Disable,(void));
2093
2094/**
2095 * Disables the A20 gate via the keyboard controller
2096 */
2097BS3_CMN_PROTO_NOSB(void, Bs3A20DisableViaKbd,(void));
2098
2099/**
2100 * Disables the A20 gate via the PS/2 control port A.
2101 */
2102BS3_CMN_PROTO_NOSB(void, Bs3A20DisableViaPortA,(void));
2103
2104
2105/**
2106 * Initializes root page tables for page protected mode (PP16, PP32).
2107 *
2108 * @returns IPRT status code.
2109 * @remarks Must not be called in real-mode!
2110 */
2111BS3_CMN_PROTO_STUB(int, Bs3PagingInitRootForPP,(void));
2112
2113/**
2114 * Initializes root page tables for PAE page protected mode (PAE16, PAE32).
2115 *
2116 * @returns IPRT status code.
2117 * @remarks The default long mode page tables depends on the PAE ones.
2118 * @remarks Must not be called in real-mode!
2119 */
2120BS3_CMN_PROTO_STUB(int, Bs3PagingInitRootForPAE,(void));
2121
2122/**
2123 * Initializes root page tables for long mode (LM16, LM32, LM64).
2124 *
2125 * @returns IPRT status code.
2126 * @remarks The default long mode page tables depends on the PAE ones.
2127 * @remarks Must not be called in real-mode!
2128 */
2129BS3_CMN_PROTO_STUB(int, Bs3PagingInitRootForLM,(void));
2130
2131/**
2132 * Modifies the page table protection of an address range.
2133 *
2134 * This only works on the lowest level of the page tables in the current mode.
2135 *
2136 * Since we generally use the largest pages available when setting up the
2137 * initial page tables, this function will usually have to allocate and create
2138 * more tables. This may fail if we're low on memory.
2139 *
2140 * @returns IPRT status code.
2141 * @param uFlat The flat address of the first page in the range (rounded
2142 * down nearest page boundrary).
2143 * @param cb The range size from @a pv (rounded up to nearest page boundrary).
2144 * @param fSet Mask of zero or more X86_PTE_XXX values to set for the range.
2145 * @param fClear Mask of zero or more X86_PTE_XXX values to clear for the range.
2146 */
2147BS3_CMN_PROTO_STUB(int, Bs3PagingProtect,(uint64_t uFlat, uint64_t cb, uint64_t fSet, uint64_t fClear));
2148
2149/**
2150 * Modifies the page table protection of an address range.
2151 *
2152 * This only works on the lowest level of the page tables in the current mode.
2153 *
2154 * Since we generally use the largest pages available when setting up the
2155 * initial page tables, this function will usually have to allocate and create
2156 * more tables. This may fail if we're low on memory.
2157 *
2158 * @returns IPRT status code.
2159 * @param pv The address of the first page in the range (rounded
2160 * down nearest page boundrary).
2161 * @param cb The range size from @a pv (rounded up to nearest page boundrary).
2162 * @param fSet Mask of zero or more X86_PTE_XXX values to set for the range.
2163 * @param fClear Mask of zero or more X86_PTE_XXX values to clear for the range.
2164 */
2165BS3_CMN_PROTO_STUB(int, Bs3PagingProtectPtr,(void BS3_FAR *pv, size_t cb, uint64_t fSet, uint64_t fClear));
2166
2167/**
2168 * Aliases (maps) one or more contiguous physical pages to a virtual range.
2169 *
2170 * @returns VBox status code.
2171 * @retval VERR_INVALID_PARAMETER if we're in legacy paging mode and @a uDst or
2172 * @a uPhysToAlias are not compatible with legacy paging.
2173 * @retval VERR_OUT_OF_RANGE if we cannot traverse the page tables in this mode
2174 * (typically real mode or v86, maybe 16-bit PE).
2175 * @retval VERR_NO_MEMORY if we cannot allocate page tables for splitting up
2176 * the necessary large pages. No aliasing was performed.
2177 *
2178 * @param uDst The virtual address to map it at. Rounded down
2179 * to the nearest page (@a cbHowMuch is adjusted
2180 * up).
2181 * @param uPhysToAlias The physical address of the first page in the
2182 * (contiguous) range to map. Chopped down to
2183 * nearest page boundrary (@a cbHowMuch is not
2184 * adjusted).
2185 * @param cbHowMuch How much to map. Rounded up to nearest page.
2186 * @param fPte The PTE flags.
2187 */
2188BS3_CMN_PROTO_STUB(int, Bs3PagingAlias,(uint64_t uDst, uint64_t uPhysToAlias, uint32_t cbHowMuch, uint64_t fPte));
2189
2190/**
2191 * Unaliases memory, i.e. restores the 1:1 mapping.
2192 *
2193 * @returns VBox status code. Cannot fail if @a uDst and @a cbHowMuch specify
2194 * the range of a successful Bs3PagingAlias call, however it may run
2195 * out of memory if it's breaking new ground.
2196 *
2197 * @param uDst The virtual address to restore to 1:1 mapping.
2198 * Rounded down to the nearest page (@a cbHowMuch
2199 * is adjusted up).
2200 * @param cbHowMuch How much to restore. Rounded up to nearest page.
2201 */
2202BS3_CMN_PROTO_STUB(int, Bs3PagingUnalias,(uint64_t uDst, uint32_t cbHowMuch));
2203
2204
2205/** The physical / flat address of the buffer backing the canonical traps.
2206 * This buffer is spread equally on each side of the 64-bit non-canonical
2207 * address divide. Non-64-bit code can use this to setup trick shots and
2208 * inspect their results. */
2209extern uint32_t g_uBs3PagingCanonicalTrapsAddr;
2210/** The size of the buffer at g_uPagingCanonicalTraps (both sides). */
2211extern uint16_t g_cbBs3PagingCanonicalTraps;
2212/** The size of one trap buffer (low or high).
2213 * This is g_cbBs3PagingCanonicalTraps divided by two. */
2214extern uint16_t g_cbBs3PagingOneCanonicalTrap;
2215
2216/**
2217 * Sets up the 64-bit canonical address space trap buffers, if neceessary.
2218 *
2219 * @returns Pointer to the buffers (i.e. the first page of the low one) on
2220 * success. NULL on failure.
2221 */
2222BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3PagingSetupCanonicalTraps,(void));
2223
2224/**
2225 * Waits for the keyboard controller to become ready.
2226 */
2227BS3_CMN_PROTO_NOSB(void, Bs3KbdWait,(void));
2228
2229/**
2230 * Sends a read command to the keyboard controller and gets the result.
2231 *
2232 * The caller is responsible for making sure the keyboard controller is ready
2233 * for a command (call #Bs3KbdWait if unsure).
2234 *
2235 * @returns The value read is returned (in al).
2236 * @param bCmd The read command.
2237 */
2238BS3_CMN_PROTO_NOSB(uint8_t, Bs3KbdRead,(uint8_t bCmd));
2239
2240/**
2241 * Sends a write command to the keyboard controller and then sends the data.
2242 *
2243 * The caller is responsible for making sure the keyboard controller is ready
2244 * for a command (call #Bs3KbdWait if unsure).
2245 *
2246 * @param bCmd The write command.
2247 * @param bData The data to write.
2248 */
2249BS3_CMN_PROTO_NOSB(void, Bs3KbdWrite,(uint8_t bCmd, uint8_t bData));
2250
2251
2252/**
2253 * Configures the PIC, once only.
2254 *
2255 * Subsequent calls to this function will not do anything.
2256 *
2257 * The PIC will be programmed to use IDT/IVT vectors 0x70 thru 0x7f, auto
2258 * end-of-interrupt, and all IRQs masked. The individual PIC users will have to
2259 * use #Bs3PicUpdateMask unmask their IRQ once they've got all the handlers
2260 * installed.
2261 */
2262BS3_CMN_PROTO_STUB(void, Bs3PicSetup,(void));
2263
2264/**
2265 * Updates the PIC masks.
2266 *
2267 * @returns The new mask - master in low, slave in high byte.
2268 * @param fAndMask Things to keep as-is. Master in low, slave in high byte.
2269 * @param fOrMask Things to start masking. Ditto wrt bytes.
2270 */
2271BS3_CMN_PROTO_STUB(uint16_t, Bs3PicUpdateMask,(uint16_t fAndMask, uint16_t fOrMask));
2272
2273/**
2274 * Disables all IRQs on the PIC.
2275 */
2276BS3_CMN_PROTO_STUB(void, Bs3PicMaskAll,(void));
2277
2278
2279/**
2280 * Sets up the PIT for periodic callback.
2281 *
2282 * @param cHzDesired The desired Hz. Zero means max interval length
2283 * (18.2Hz). Plase check the various PIT globals for
2284 * the actual interval length.
2285 */
2286BS3_CMN_PROTO_STUB(void, Bs3PitSetupAndEnablePeriodTimer,(uint16_t cHzDesired));
2287
2288/**
2289 * Disables the PIT if active.
2290 */
2291BS3_CMN_PROTO_STUB(void, Bs3PitDisable,(void));
2292
2293/** Nano seconds (approx) since last the PIT timer was started. */
2294extern uint64_t volatile g_cBs3PitNs;
2295/** Milliseconds seconds (very approx) since last the PIT timer was started. */
2296extern uint64_t volatile g_cBs3PitMs;
2297/** Number of ticks since last the PIT timer was started. */
2298extern uint32_t volatile g_cBs3PitTicks;
2299/** The current interval in nanon seconds. */
2300extern uint32_t g_cBs3PitIntervalNs;
2301/** The current interval in milliseconds (approximately).
2302 * This is 0 if not yet started (used for checking the state internally). */
2303extern uint16_t volatile g_cBs3PitIntervalMs;
2304/** The current PIT frequency (approximately). 0 if not yet started. */
2305extern uint16_t g_cBs3PitIntervalHz;
2306
2307
2308/**
2309 * Call 16-bit prot mode function from v8086 mode.
2310 *
2311 * This switches from v8086 mode to 16-bit protected mode (code) and executed
2312 * @a fpfnCall with @a cbParams bytes of parameters pushed on the stack.
2313 * Afterwards it switches back to v8086 mode and returns a 16-bit status code.
2314 *
2315 * @returns 16-bit status code if the function returned anything.
2316 * @param fpfnCall Far real mode pointer to the function to call.
2317 * @param cbParams The size of the parameter list, in bytes.
2318 * @param ... The parameters.
2319 */
2320BS3_CMN_PROTO_STUB(int, Bs3SwitchFromV86To16BitAndCallC,(FPFNBS3FAR fpfnCall, unsigned cbParams, ...));
2321
2322
2323/**
2324 * BS3 integer register.
2325 */
2326typedef union BS3REG
2327{
2328 /** 8-bit unsigned integer. */
2329 uint8_t u8;
2330 /** 16-bit unsigned integer. */
2331 uint16_t u16;
2332 /** 32-bit unsigned integer. */
2333 uint32_t u32;
2334 /** 64-bit unsigned integer. */
2335 uint64_t u64;
2336 /** Full unsigned integer. */
2337 uint64_t u;
2338 /** High/low byte view. */
2339 struct
2340 {
2341 uint8_t bLo;
2342 uint8_t bHi;
2343 } b;
2344 /** 8-bit view. */
2345 uint8_t au8[8];
2346 /** 16-bit view. */
2347 uint16_t au16[4];
2348 /** 32-bit view. */
2349 uint32_t au32[2];
2350} BS3REG;
2351/** Pointer to an integer register. */
2352typedef BS3REG BS3_FAR *PBS3REG;
2353/** Pointer to a const integer register. */
2354typedef BS3REG const BS3_FAR *PCBS3REG;
2355
2356/**
2357 * Register context (without FPU).
2358 */
2359typedef struct BS3REGCTX
2360{
2361 BS3REG rax; /**< 0x00 */
2362 BS3REG rcx; /**< 0x08 */
2363 BS3REG rdx; /**< 0x10 */
2364 BS3REG rbx; /**< 0x18 */
2365 BS3REG rsp; /**< 0x20 */
2366 BS3REG rbp; /**< 0x28 */
2367 BS3REG rsi; /**< 0x30 */
2368 BS3REG rdi; /**< 0x38 */
2369 BS3REG r8; /**< 0x40 */
2370 BS3REG r9; /**< 0x48 */
2371 BS3REG r10; /**< 0x50 */
2372 BS3REG r11; /**< 0x58 */
2373 BS3REG r12; /**< 0x60 */
2374 BS3REG r13; /**< 0x68 */
2375 BS3REG r14; /**< 0x70 */
2376 BS3REG r15; /**< 0x78 */
2377 BS3REG rflags; /**< 0x80 */
2378 BS3REG rip; /**< 0x88 */
2379 uint16_t cs; /**< 0x90 */
2380 uint16_t ds; /**< 0x92 */
2381 uint16_t es; /**< 0x94 */
2382 uint16_t fs; /**< 0x96 */
2383 uint16_t gs; /**< 0x98 */
2384 uint16_t ss; /**< 0x9a */
2385 uint16_t tr; /**< 0x9c */
2386 uint16_t ldtr; /**< 0x9e */
2387 uint8_t bMode; /**< 0xa0: BS3_MODE_XXX. */
2388 uint8_t bCpl; /**< 0xa1: 0-3, 0 is used for real mode. */
2389 uint8_t fbFlags; /**< 0xa2: BS3REG_CTX_F_XXX */
2390 uint8_t abPadding[5]; /**< 0xa3 */
2391 BS3REG cr0; /**< 0xa8 */
2392 BS3REG cr2; /**< 0xb0 */
2393 BS3REG cr3; /**< 0xb8 */
2394 BS3REG cr4; /**< 0xc0 */
2395 uint64_t uUnused; /**< 0xc8 */
2396} BS3REGCTX;
2397AssertCompileSize(BS3REGCTX, 0xd0);
2398/** Pointer to a register context. */
2399typedef BS3REGCTX BS3_FAR *PBS3REGCTX;
2400/** Pointer to a const register context. */
2401typedef BS3REGCTX const BS3_FAR *PCBS3REGCTX;
2402
2403/** @name BS3REG_CTX_F_XXX - BS3REGCTX::fbFlags masks.
2404 * @{ */
2405/** The CR0 is MSW (only low 16-bit). */
2406#define BS3REG_CTX_F_NO_CR0_IS_MSW UINT8_C(0x01)
2407/** No CR2 and CR3 values. Not in CPL 0 or CPU too old for CR2 & CR3. */
2408#define BS3REG_CTX_F_NO_CR2_CR3 UINT8_C(0x02)
2409/** No CR4 value. The CPU is too old for CR4. */
2410#define BS3REG_CTX_F_NO_CR4 UINT8_C(0x04)
2411/** No TR and LDTR values. Context gathered in real mode or v8086 mode. */
2412#define BS3REG_CTX_F_NO_TR_LDTR UINT8_C(0x08)
2413/** The context doesn't have valid values for AMD64 GPR extensions. */
2414#define BS3REG_CTX_F_NO_AMD64 UINT8_C(0x10)
2415/** @} */
2416
2417/**
2418 * Saves the current register context.
2419 *
2420 * @param pRegCtx Where to store the register context.
2421 */
2422BS3_CMN_PROTO_NOSB(void, Bs3RegCtxSave,(PBS3REGCTX pRegCtx));
2423
2424/**
2425 * Switch to the specified CPU bitcount, reserve additional stack and save the
2426 * CPU context.
2427 *
2428 * This is for writing more flexible test drivers that can test more than the
2429 * CPU bitcount (16-bit, 32-bit, 64-bit, and virtual 8086) of the driver itself.
2430 * For instance a 32-bit driver can do V86 and 16-bit testing, thus saving more
2431 * precious and problematic 16-bit code.
2432 *
2433 * @param pRegCtx Where to store the register context.
2434 * @param bBitMode Bit mode to switch to, BS3_MODE_CODE_XXX. Only
2435 * BS3_MODE_CODE_MASK is used, other bits are ignored
2436 * to make it possible to pass a full mode value.
2437 * @param cbExtraStack Number of bytes of additional stack to allocate.
2438 */
2439BS3_CMN_PROTO_FARSTUB(8, void, Bs3RegCtxSaveEx,(PBS3REGCTX pRegCtx, uint8_t bBitMode, uint16_t cbExtraStack));
2440
2441/**
2442 * Transforms a register context to a different ring.
2443 *
2444 * @param pRegCtx The register context.
2445 * @param bRing The target ring (0..3).
2446 */
2447BS3_CMN_PROTO_STUB(void, Bs3RegCtxConvertToRingX,(PBS3REGCTX pRegCtx, uint8_t bRing));
2448
2449/**
2450 * Restores a register context.
2451 *
2452 * @param pRegCtx The register context to be restored and resumed.
2453 * @param fFlags BS3REGCTXRESTORE_F_XXX.
2454 *
2455 * @remarks Will switch to ring-0.
2456 * @remarks Does not return.
2457 */
2458BS3_CMN_PROTO_NOSB(DECL_NO_RETURN(void), Bs3RegCtxRestore,(PCBS3REGCTX pRegCtx, uint16_t fFlags));
2459#if !defined(BS3_KIT_WITH_NO_RETURN) && defined(__WATCOMC__)
2460# pragma aux Bs3RegCtxRestore_c16 "_Bs3RegCtxRestore_aborts_c16" __aborts
2461# pragma aux Bs3RegCtxRestore_f16 "_Bs3RegCtxRestore_aborts_f16" __aborts
2462# pragma aux Bs3RegCtxRestore_c32 "_Bs3RegCtxRestore_aborts_c32" __aborts
2463#endif
2464
2465/** Skip restoring the CRx registers. */
2466#define BS3REGCTXRESTORE_F_SKIP_CRX UINT16_C(0x0001)
2467
2468/**
2469 * Prints the register context.
2470 *
2471 * @param pRegCtx The register context to be printed.
2472 */
2473BS3_CMN_PROTO_STUB(void, Bs3RegCtxPrint,(PCBS3REGCTX pRegCtx));
2474
2475/**
2476 * Sets a GPR and segment register to point at the same location as @a uFlat.
2477 *
2478 * @param pRegCtx The register context.
2479 * @param pGpr The general purpose register to set (points within
2480 * @a pRegCtx).
2481 * @param pSel The selector register (points within @a pRegCtx).
2482 * @param uFlat Flat location address.
2483 */
2484BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetGrpSegFromFlat,(PBS3REGCTX pRegCtx, PBS3REG pGpr, PRTSEL pSel, RTCCUINTXREG uFlat));
2485
2486/**
2487 * Sets a GPR and segment register to point at the same location as @a ovPtr.
2488 *
2489 * @param pRegCtx The register context.
2490 * @param pGpr The general purpose register to set (points within
2491 * @a pRegCtx).
2492 * @param pSel The selector register (points within @a pRegCtx).
2493 * @param pvPtr Current context pointer.
2494 */
2495BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetGrpSegFromCurPtr,(PBS3REGCTX pRegCtx, PBS3REG pGpr, PRTSEL pSel, void BS3_FAR *pvPtr));
2496
2497/**
2498 * Sets a GPR and DS to point at the same location as @a ovPtr.
2499 *
2500 * @param pRegCtx The register context.
2501 * @param pGpr The general purpose register to set (points within
2502 * @a pRegCtx).
2503 * @param pvPtr Current context pointer.
2504 */
2505BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetGrpDsFromCurPtr,(PBS3REGCTX pRegCtx, PBS3REG pGpr, void BS3_FAR *pvPtr));
2506
2507/**
2508 * Sets CS:RIP to point at the same piece of code as @a uFlatCode.
2509 *
2510 * @param pRegCtx The register context.
2511 * @param uFlatCode Flat code pointer
2512 * @sa Bs3RegCtxSetRipCsFromLnkPtr, Bs3RegCtxSetRipCsFromCurPtr
2513 */
2514BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetRipCsFromFlat,(PBS3REGCTX pRegCtx, RTCCUINTXREG uFlatCode));
2515
2516/**
2517 * Sets CS:RIP to point at the same piece of code as @a pfnCode.
2518 *
2519 * The 16-bit edition of this function expects a far 16:16 address as written by
2520 * the linker (i.e. real mode).
2521 *
2522 * @param pRegCtx The register context.
2523 * @param pfnCode Pointer to the code. In 32-bit and 64-bit mode this is a
2524 * flat address, while in 16-bit it's a far 16:16 address
2525 * as fixed up by the linker (real mode selector). This
2526 * address is converted to match the mode of the context.
2527 * @sa Bs3RegCtxSetRipCsFromCurPtr, Bs3RegCtxSetRipCsFromFlat
2528 */
2529BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetRipCsFromLnkPtr,(PBS3REGCTX pRegCtx, FPFNBS3FAR pfnCode));
2530
2531/**
2532 * Sets CS:RIP to point at the same piece of code as @a pfnCode.
2533 *
2534 * @param pRegCtx The register context.
2535 * @param pfnCode Pointer to the code. Current mode pointer.
2536 * @sa Bs3RegCtxSetRipCsFromLnkPtr, Bs3RegCtxSetRipCsFromFlat
2537 */
2538BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetRipCsFromCurPtr,(PBS3REGCTX pRegCtx, FPFNBS3FAR pfnCode));
2539
2540
2541/**
2542 * Trap frame.
2543 */
2544typedef struct BS3TRAPFRAME
2545{
2546 /** 0x00: Exception/interrupt number. */
2547 uint8_t bXcpt;
2548 /** 0x01: The size of the IRET frame. */
2549 uint8_t cbIretFrame;
2550 /** 0x02: The handler CS. */
2551 uint16_t uHandlerCs;
2552 /** 0x04: The handler SS. */
2553 uint16_t uHandlerSs;
2554 /** 0x06: Explicit alignment. */
2555 uint16_t usAlignment;
2556 /** 0x08: The handler RSP (pointer to the iret frame, skipping ErrCd). */
2557 uint64_t uHandlerRsp;
2558 /** 0x10: The handler RFLAGS value. */
2559 uint64_t fHandlerRfl;
2560 /** 0x18: The error code (if applicable). */
2561 uint64_t uErrCd;
2562 /** 0x20: The register context. */
2563 BS3REGCTX Ctx;
2564} BS3TRAPFRAME;
2565AssertCompileSize(BS3TRAPFRAME, 0x20 + 0xd0);
2566/** Pointer to a trap frame. */
2567typedef BS3TRAPFRAME BS3_FAR *PBS3TRAPFRAME;
2568/** Pointer to a const trap frame. */
2569typedef BS3TRAPFRAME const BS3_FAR *PCBS3TRAPFRAME;
2570
2571
2572/**
2573 * Re-initializes the trap handling for the current mode.
2574 *
2575 * Useful after a test that messes with the IDT/IVT.
2576 *
2577 * @sa Bs3TrapInit
2578 */
2579BS3_CMN_PROTO_STUB(void, Bs3TrapReInit,(void));
2580
2581/**
2582 * Initializes real mode and v8086 trap handling.
2583 *
2584 * @remarks Does not install RM/V86 trap handling, just initializes the
2585 * structures.
2586 */
2587BS3_CMN_PROTO_STUB(void, Bs3TrapRmV86Init,(void));
2588
2589/**
2590 * Initializes real mode and v8086 trap handling, extended version.
2591 *
2592 * @param f386Plus Set if the CPU is 80386 or later and
2593 * extended registers should be saved. Once initialized
2594 * with this parameter set to @a true, the effect cannot be
2595 * reversed.
2596 *
2597 * @remarks Does not install RM/V86 trap handling, just initializes the
2598 * structures.
2599 */
2600BS3_CMN_PROTO_STUB(void, Bs3TrapRmV86InitEx,(bool f386Plus));
2601
2602/**
2603 * Initializes 16-bit (protected mode) trap handling.
2604 *
2605 * @remarks Does not install 16-bit trap handling, just initializes the
2606 * structures.
2607 */
2608BS3_CMN_PROTO_STUB(void, Bs3Trap16Init,(void));
2609
2610/**
2611 * Initializes 16-bit (protected mode) trap handling, extended version.
2612 *
2613 * @param f386Plus Set if the CPU is 80386 or later and
2614 * extended registers should be saved. Once initialized
2615 * with this parameter set to @a true, the effect cannot be
2616 * reversed.
2617 *
2618 * @remarks Does not install 16-bit trap handling, just initializes the
2619 * structures.
2620 */
2621BS3_CMN_PROTO_STUB(void, Bs3Trap16InitEx,(bool f386Plus));
2622
2623/**
2624 * Initializes 32-bit trap handling.
2625 *
2626 * @remarks Does not install 32-bit trap handling, just initializes the
2627 * structures.
2628 */
2629BS3_CMN_PROTO_STUB(void, Bs3Trap32Init,(void));
2630
2631/**
2632 * Initializes 64-bit trap handling
2633 *
2634 * @remarks Does not install 64-bit trap handling, just initializes the
2635 * structures.
2636 */
2637BS3_CMN_PROTO_STUB(void, Bs3Trap64Init,(void));
2638
2639/**
2640 * Modifies the real-mode / V86 IVT entry specified by @a iIvt.
2641 *
2642 * @param iIvt The index of the IDT entry to set.
2643 * @param uSeg The handler real-mode segment.
2644 * @param off The handler offset.
2645 */
2646BS3_CMN_PROTO_STUB(void, Bs3TrapRmV86SetGate,(uint8_t iIvt, uint16_t uSeg, uint16_t off));
2647
2648/**
2649 * Modifies the 16-bit IDT entry (protected mode) specified by @a iIdt.
2650 *
2651 * @param iIdt The index of the IDT entry to set.
2652 * @param bType The gate type (X86_SEL_TYPE_SYS_XXX).
2653 * @param bDpl The DPL.
2654 * @param uSel The handler selector.
2655 * @param off The handler offset (if applicable).
2656 * @param cParams The parameter count (for call gates).
2657 */
2658BS3_CMN_PROTO_STUB(void, Bs3Trap16SetGate,(uint8_t iIdt, uint8_t bType, uint8_t bDpl,
2659 uint16_t uSel, uint16_t off, uint8_t cParams));
2660
2661/** The address of Bs3Trap16GenericEntries.
2662 * Bs3Trap16GenericEntries is an array of interrupt/trap/whatever entry
2663 * points, 8 bytes each, that will create a register frame and call the generic
2664 * C compatible trap handlers. */
2665extern uint32_t g_Bs3Trap16GenericEntriesFlatAddr;
2666
2667/**
2668 * Modifies the 32-bit IDT entry specified by @a iIdt.
2669 *
2670 * @param iIdt The index of the IDT entry to set.
2671 * @param bType The gate type (X86_SEL_TYPE_SYS_XXX).
2672 * @param bDpl The DPL.
2673 * @param uSel The handler selector.
2674 * @param off The handler offset (if applicable).
2675 * @param cParams The parameter count (for call gates).
2676 */
2677BS3_CMN_PROTO_STUB(void, Bs3Trap32SetGate,(uint8_t iIdt, uint8_t bType, uint8_t bDpl,
2678 uint16_t uSel, uint32_t off, uint8_t cParams));
2679
2680/** The address of Bs3Trap32GenericEntries.
2681 * Bs3Trap32GenericEntries is an array of interrupt/trap/whatever entry
2682 * points, 10 bytes each, that will create a register frame and call the generic
2683 * C compatible trap handlers. */
2684extern uint32_t g_Bs3Trap32GenericEntriesFlatAddr;
2685
2686/**
2687 * Modifies the 64-bit IDT entry specified by @a iIdt.
2688 *
2689 * @param iIdt The index of the IDT entry to set.
2690 * @param bType The gate type (X86_SEL_TYPE_SYS_XXX).
2691 * @param bDpl The DPL.
2692 * @param uSel The handler selector.
2693 * @param off The handler offset (if applicable).
2694 * @param bIst The interrupt stack to use.
2695 */
2696BS3_CMN_PROTO_STUB(void, Bs3Trap64SetGate,(uint8_t iIdt, uint8_t bType, uint8_t bDpl, uint16_t uSel, uint64_t off, uint8_t bIst));
2697
2698/** The address of Bs3Trap64GenericEntries.
2699 * Bs3Trap64GenericEntries is an array of interrupt/trap/whatever entry
2700 * points, 8 bytes each, that will create a register frame and call the generic
2701 * C compatible trap handlers. */
2702extern uint32_t g_Bs3Trap64GenericEntriesFlatAddr;
2703
2704/**
2705 * C-style trap handler.
2706 *
2707 * The caller will resume the context in @a pTrapFrame upon return.
2708 *
2709 * @param pTrapFrame The trap frame. Registers can be modified.
2710 * @note The 16-bit versions must be in CGROUP16!
2711 */
2712typedef BS3_DECL_NEAR_CALLBACK(void) FNBS3TRAPHANDLER(PBS3TRAPFRAME pTrapFrame);
2713/** Pointer to a trap handler (current template context). */
2714typedef FNBS3TRAPHANDLER *PFNBS3TRAPHANDLER;
2715
2716#if ARCH_BITS == 16
2717/** @copydoc FNBS3TRAPHANDLER */
2718typedef FNBS3FAR FNBS3TRAPHANDLER32;
2719/** @copydoc FNBS3TRAPHANDLER */
2720typedef FNBS3FAR FNBS3TRAPHANDLER64;
2721#else
2722/** @copydoc FNBS3TRAPHANDLER */
2723typedef FNBS3TRAPHANDLER FNBS3TRAPHANDLER32;
2724/** @copydoc FNBS3TRAPHANDLER */
2725typedef FNBS3TRAPHANDLER FNBS3TRAPHANDLER64;
2726#endif
2727/** @copydoc PFNBS3TRAPHANDLER */
2728typedef FNBS3TRAPHANDLER32 *PFNBS3TRAPHANDLER32;
2729/** @copydoc PFNBS3TRAPHANDLER */
2730typedef FNBS3TRAPHANDLER64 *PFNBS3TRAPHANDLER64;
2731
2732
2733/**
2734 * C-style trap handler, near 16-bit (CGROUP16).
2735 *
2736 * The caller will resume the context in @a pTrapFrame upon return.
2737 *
2738 * @param pTrapFrame The trap frame. Registers can be modified.
2739 */
2740typedef BS3_DECL_NEAR_CALLBACK(void) FNBS3TRAPHANDLER16(PBS3TRAPFRAME pTrapFrame);
2741/** Pointer to a trap handler (current template context). */
2742typedef FNBS3TRAPHANDLER16 *PFNBS3TRAPHANDLER16;
2743
2744/**
2745 * C-style trap handler, near 16-bit (CGROUP16).
2746 *
2747 * The caller will resume the context in @a pTrapFrame upon return.
2748 *
2749 * @param pTrapFrame The trap frame. Registers can be modified.
2750 */
2751typedef BS3_DECL_CALLBACK(void) FNBS3TRAPHANDLER3264(PBS3TRAPFRAME pTrapFrame);
2752/** Pointer to a trap handler (current template context). */
2753typedef FNBS3TRAPHANDLER3264 *FPFNBS3TRAPHANDLER3264;
2754
2755
2756/**
2757 * Sets a trap handler (C/C++/assembly) for the current bitcount.
2758 *
2759 * @returns Previous handler.
2760 * @param iIdt The index of the IDT entry to set.
2761 * @param pfnHandler Pointer to the handler.
2762 * @sa Bs3TrapSetHandlerEx
2763 */
2764BS3_CMN_PROTO_STUB(PFNBS3TRAPHANDLER, Bs3TrapSetHandler,(uint8_t iIdt, PFNBS3TRAPHANDLER pfnHandler));
2765
2766/**
2767 * Sets a trap handler (C/C++/assembly) for all the bitcounts.
2768 *
2769 * @param iIdt The index of the IDT and IVT entry to set.
2770 * @param pfnHandler16 Pointer to the 16-bit handler. (Assumes linker addresses.)
2771 * @param pfnHandler32 Pointer to the 32-bit handler. (Assumes linker addresses.)
2772 * @param pfnHandler64 Pointer to the 64-bit handler. (Assumes linker addresses.)
2773 * @sa Bs3TrapSetHandler
2774 */
2775BS3_CMN_PROTO_STUB(void, Bs3TrapSetHandlerEx,(uint8_t iIdt, PFNBS3TRAPHANDLER16 pfnHandler16,
2776 PFNBS3TRAPHANDLER32 pfnHandler32, PFNBS3TRAPHANDLER64 pfnHandler64));
2777
2778/**
2779 * Default C/C++ trap handler.
2780 *
2781 * This will check trap record and panic if no match was found.
2782 *
2783 * @param pTrapFrame Trap frame of the trap to handle.
2784 */
2785BS3_CMN_PROTO_STUB(void, Bs3TrapDefaultHandler,(PBS3TRAPFRAME pTrapFrame));
2786
2787/**
2788 * Prints the trap frame (to screen).
2789 * @param pTrapFrame Trap frame to print.
2790 */
2791BS3_CMN_PROTO_STUB(void, Bs3TrapPrintFrame,(PCBS3TRAPFRAME pTrapFrame));
2792
2793/**
2794 * Sets up a long jump from a trap handler.
2795 *
2796 * The long jump will only be performed onced, but will catch any kind of trap,
2797 * fault, interrupt or irq.
2798 *
2799 * @retval true on the initial call.
2800 * @retval false on trap return.
2801 * @param pTrapFrame Where to store the trap information when
2802 * returning @c false.
2803 * @sa #Bs3TrapUnsetJmp
2804 */
2805BS3_CMN_PROTO_NOSB(DECL_RETURNS_TWICE(bool),Bs3TrapSetJmp,(PBS3TRAPFRAME pTrapFrame));
2806
2807/**
2808 * Combination of #Bs3TrapSetJmp and #Bs3RegCtxRestore.
2809 *
2810 * @param pCtxRestore The context to restore.
2811 * @param pTrapFrame Where to store the trap information.
2812 */
2813BS3_CMN_PROTO_STUB(void, Bs3TrapSetJmpAndRestore,(PCBS3REGCTX pCtxRestore, PBS3TRAPFRAME pTrapFrame));
2814
2815/**
2816 * Disables a previous #Bs3TrapSetJmp call.
2817 */
2818BS3_CMN_PROTO_STUB(void, Bs3TrapUnsetJmp,(void));
2819
2820
2821/**
2822 * The current test step.
2823 */
2824extern uint16_t g_usBs3TestStep;
2825
2826/**
2827 * Equivalent to RTTestCreate + RTTestBanner.
2828 *
2829 * @param pszTest The test name.
2830 */
2831BS3_CMN_PROTO_STUB(void, Bs3TestInit,(const char BS3_FAR *pszTest));
2832
2833
2834/**
2835 * Equivalent to RTTestSummaryAndDestroy.
2836 */
2837BS3_CMN_PROTO_STUB(void, Bs3TestTerm,(void));
2838
2839/**
2840 * Equivalent to RTTestISub.
2841 */
2842BS3_CMN_PROTO_STUB(void, Bs3TestSub,(const char BS3_FAR *pszSubTest));
2843
2844/**
2845 * Equivalent to RTTestIFailedF.
2846 */
2847BS3_CMN_PROTO_STUB(void, Bs3TestSubF,(const char BS3_FAR *pszFormat, ...));
2848
2849/**
2850 * Equivalent to RTTestISubV.
2851 */
2852BS3_CMN_PROTO_STUB(void, Bs3TestSubV,(const char BS3_FAR *pszFormat, va_list va));
2853
2854/**
2855 * Equivalent to RTTestISubDone.
2856 */
2857BS3_CMN_PROTO_STUB(void, Bs3TestSubDone,(void));
2858
2859/**
2860 * Equivalent to RTTestSubErrorCount.
2861 */
2862BS3_CMN_PROTO_STUB(uint16_t, Bs3TestSubErrorCount,(void));
2863
2864/**
2865 * Equivalent to RTTestIPrintf with RTTESTLVL_ALWAYS.
2866 *
2867 * @param pszFormat What to print, format string. Explicit newline char.
2868 * @param ... String format arguments.
2869 */
2870BS3_CMN_PROTO_STUB(void, Bs3TestPrintf,(const char BS3_FAR *pszFormat, ...));
2871
2872/**
2873 * Equivalent to RTTestIPrintfV with RTTESTLVL_ALWAYS.
2874 *
2875 * @param pszFormat What to print, format string. Explicit newline char.
2876 * @param va String format arguments.
2877 */
2878BS3_CMN_PROTO_STUB(void, Bs3TestPrintfV,(const char BS3_FAR *pszFormat, va_list va));
2879
2880/**
2881 * Equivalent to RTTestIFailed.
2882 */
2883BS3_CMN_PROTO_STUB(void, Bs3TestFailed,(const char BS3_FAR *pszMessage));
2884
2885/**
2886 * Equivalent to RTTestIFailedF.
2887 */
2888BS3_CMN_PROTO_STUB(void, Bs3TestFailedF,(const char BS3_FAR *pszFormat, ...));
2889
2890/**
2891 * Equivalent to RTTestIFailedV.
2892 */
2893BS3_CMN_PROTO_STUB(void, Bs3TestFailedV,(const char BS3_FAR *pszFormat, va_list va));
2894
2895/**
2896 * Equivalent to RTTestISkipped.
2897 *
2898 * @param pszWhy Optional reason why it's being skipped.
2899 */
2900BS3_CMN_PROTO_STUB(void, Bs3TestSkipped,(const char BS3_FAR *pszWhy));
2901
2902/**
2903 * Equivalent to RTTestISkippedF.
2904 *
2905 * @param pszFormat Optional reason why it's being skipped.
2906 * @param ... Format arguments.
2907 */
2908BS3_CMN_PROTO_STUB(void, Bs3TestSkippedF,(const char BS3_FAR *pszFormat, ...));
2909
2910/**
2911 * Equivalent to RTTestISkippedV.
2912 *
2913 * @param pszFormat Optional reason why it's being skipped.
2914 * @param va Format arguments.
2915 */
2916BS3_CMN_PROTO_STUB(void, Bs3TestSkippedV,(const char BS3_FAR *pszFormat, va_list va));
2917
2918/**
2919 * Compares two register contexts, with PC and SP adjustments.
2920 *
2921 * Differences will be reported as test failures.
2922 *
2923 * @returns true if equal, false if not.
2924 * @param pActualCtx The actual register context.
2925 * @param pExpectedCtx Expected register context.
2926 * @param cbPcAdjust Program counter adjustment (applied to @a pExpectedCtx).
2927 * @param cbSpAdjust Stack pointer adjustment (applied to @a pExpectedCtx).
2928 * @param fExtraEfl Extra EFLAGS to OR into @a pExepctedCtx.
2929 * @param pszMode CPU mode or some other helpful text.
2930 * @param idTestStep Test step identifier.
2931 */
2932BS3_CMN_PROTO_STUB(bool, Bs3TestCheckRegCtxEx,(PCBS3REGCTX pActualCtx, PCBS3REGCTX pExpectedCtx, uint16_t cbPcAdjust,
2933 int16_t cbSpAdjust, uint32_t fExtraEfl, const char *pszMode, uint16_t idTestStep));
2934
2935/**
2936 * Performs the testing for the given mode.
2937 *
2938 * This is called with the CPU already switch to that mode.
2939 *
2940 * @returns 0 on success or directly Bs3TestFailed calls, non-zero to indicate
2941 * where the test when wrong. Special value BS3TESTDOMODE_SKIPPED
2942 * should be returned to indicate that the test has been skipped.
2943 * @param bMode The current CPU mode.
2944 */
2945typedef BS3_DECL_CALLBACK(uint8_t) FNBS3TESTDOMODE(uint8_t bMode);
2946/** Pointer (far) to a test (for 32-bit and 64-bit code, will be flatten). */
2947typedef FNBS3TESTDOMODE *PFNBS3TESTDOMODE;
2948
2949/** Special FNBS3TESTDOMODE return code for indicating a skipped mode test. */
2950#define BS3TESTDOMODE_SKIPPED UINT8_MAX
2951
2952/**
2953 * Mode sub-test entry.
2954 *
2955 * This can only be passed around to functions with the same bit count, as it
2956 * contains function pointers. In 16-bit mode, the 16-bit pointers are near and
2957 * implies BS3TEXT16, whereas the 32-bit and 64-bit pointers are far real mode
2958 * addresses that will be converted to flat address prior to calling them.
2959 * Similarly, in 32-bit and 64-bit the addresses are all flat and the 16-bit
2960 * ones will be converted to BS3TEXT16 based addresses prior to calling.
2961 */
2962typedef struct BS3TESTMODEENTRY
2963{
2964 const char * BS3_FAR pszSubTest;
2965
2966 PFNBS3TESTDOMODE pfnDoRM;
2967
2968 PFNBS3TESTDOMODE pfnDoPE16;
2969 PFNBS3TESTDOMODE pfnDoPE16_32;
2970 PFNBS3TESTDOMODE pfnDoPE16_V86;
2971 PFNBS3TESTDOMODE pfnDoPE32;
2972 PFNBS3TESTDOMODE pfnDoPE32_16;
2973 PFNBS3TESTDOMODE pfnDoPEV86;
2974
2975 PFNBS3TESTDOMODE pfnDoPP16;
2976 PFNBS3TESTDOMODE pfnDoPP16_32;
2977 PFNBS3TESTDOMODE pfnDoPP16_V86;
2978 PFNBS3TESTDOMODE pfnDoPP32;
2979 PFNBS3TESTDOMODE pfnDoPP32_16;
2980 PFNBS3TESTDOMODE pfnDoPPV86;
2981
2982 PFNBS3TESTDOMODE pfnDoPAE16;
2983 PFNBS3TESTDOMODE pfnDoPAE16_32;
2984 PFNBS3TESTDOMODE pfnDoPAE16_V86;
2985 PFNBS3TESTDOMODE pfnDoPAE32;
2986 PFNBS3TESTDOMODE pfnDoPAE32_16;
2987 PFNBS3TESTDOMODE pfnDoPAEV86;
2988
2989 PFNBS3TESTDOMODE pfnDoLM16;
2990 PFNBS3TESTDOMODE pfnDoLM32;
2991 PFNBS3TESTDOMODE pfnDoLM64;
2992
2993} BS3TESTMODEENTRY;
2994/** Pointer to a mode sub-test entry. */
2995typedef BS3TESTMODEENTRY const *PCBS3TESTMODEENTRY;
2996
2997/** @def BS3TESTMODEENTRY_CMN
2998 * Produces a BS3TESTMODEENTRY initializer for common (c16,c32,c64) test
2999 * functions. */
3000#define BS3TESTMODEENTRY_CMN(a_szTest, a_BaseNm) \
3001 { /*pszSubTest =*/ a_szTest, \
3002 /*RM*/ RT_CONCAT(a_BaseNm, _c16), \
3003 /*PE16*/ RT_CONCAT(a_BaseNm, _c16), \
3004 /*PE16_32*/ RT_CONCAT(a_BaseNm, _c32), \
3005 /*PE16_V86*/ RT_CONCAT(a_BaseNm, _c16), \
3006 /*PE32*/ RT_CONCAT(a_BaseNm, _c32), \
3007 /*PE32_16*/ RT_CONCAT(a_BaseNm, _c16), \
3008 /*PEV86*/ RT_CONCAT(a_BaseNm, _c16), \
3009 /*PP16*/ RT_CONCAT(a_BaseNm, _c16), \
3010 /*PP16_32*/ RT_CONCAT(a_BaseNm, _c32), \
3011 /*PP16_V86*/ RT_CONCAT(a_BaseNm, _c16), \
3012 /*PP32*/ RT_CONCAT(a_BaseNm, _c32), \
3013 /*PP32_16*/ RT_CONCAT(a_BaseNm, _c16), \
3014 /*PPV86*/ RT_CONCAT(a_BaseNm, _c16), \
3015 /*PAE16*/ RT_CONCAT(a_BaseNm, _c16), \
3016 /*PAE16_32*/ RT_CONCAT(a_BaseNm, _c32), \
3017 /*PAE16_V86*/ RT_CONCAT(a_BaseNm, _c16), \
3018 /*PAE32*/ RT_CONCAT(a_BaseNm, _c32), \
3019 /*PAE32_16*/ RT_CONCAT(a_BaseNm, _c16), \
3020 /*PAEV86*/ RT_CONCAT(a_BaseNm, _c16), \
3021 /*LM16*/ RT_CONCAT(a_BaseNm, _c16), \
3022 /*LM32*/ RT_CONCAT(a_BaseNm, _c32), \
3023 /*LM64*/ RT_CONCAT(a_BaseNm, _c64), \
3024 }
3025
3026/** @def BS3TESTMODE_PROTOTYPES_CMN
3027 * A set of standard protypes to go with #BS3TESTMODEENTRY_CMN. */
3028#define BS3TESTMODE_PROTOTYPES_CMN(a_BaseNm) \
3029 FNBS3TESTDOMODE /*BS3_FAR_CODE*/ RT_CONCAT(a_BaseNm, _c16); \
3030 FNBS3TESTDOMODE /*BS3_FAR_CODE*/ RT_CONCAT(a_BaseNm, _c32); \
3031 FNBS3TESTDOMODE /*BS3_FAR_CODE*/ RT_CONCAT(a_BaseNm, _c64)
3032
3033/** @def BS3TESTMODEENTRY_MODE
3034 * Produces a BS3TESTMODEENTRY initializer for a full set of mode test
3035 * functions. */
3036#define BS3TESTMODEENTRY_MODE(a_szTest, a_BaseNm) \
3037 { /*pszSubTest =*/ a_szTest, \
3038 /*RM*/ RT_CONCAT(a_BaseNm, _rm), \
3039 /*PE16*/ RT_CONCAT(a_BaseNm, _pe16), \
3040 /*PE16_32*/ RT_CONCAT(a_BaseNm, _pe16_32), \
3041 /*PE16_V86*/ RT_CONCAT(a_BaseNm, _pe16_v86), \
3042 /*PE32*/ RT_CONCAT(a_BaseNm, _pe32), \
3043 /*PE32_16*/ RT_CONCAT(a_BaseNm, _pe32_16), \
3044 /*PEV86*/ RT_CONCAT(a_BaseNm, _pev86), \
3045 /*PP16*/ RT_CONCAT(a_BaseNm, _pp16), \
3046 /*PP16_32*/ RT_CONCAT(a_BaseNm, _pp16_32), \
3047 /*PP16_V86*/ RT_CONCAT(a_BaseNm, _pp16_v86), \
3048 /*PP32*/ RT_CONCAT(a_BaseNm, _pp32), \
3049 /*PP32_16*/ RT_CONCAT(a_BaseNm, _pp32_16), \
3050 /*PPV86*/ RT_CONCAT(a_BaseNm, _ppv86), \
3051 /*PAE16*/ RT_CONCAT(a_BaseNm, _pae16), \
3052 /*PAE16_32*/ RT_CONCAT(a_BaseNm, _pae16_32), \
3053 /*PAE16_V86*/ RT_CONCAT(a_BaseNm, _pae16_v86), \
3054 /*PAE32*/ RT_CONCAT(a_BaseNm, _pae32), \
3055 /*PAE32_16*/ RT_CONCAT(a_BaseNm, _pae32_16), \
3056 /*PAEV86*/ RT_CONCAT(a_BaseNm, _paev86), \
3057 /*LM16*/ RT_CONCAT(a_BaseNm, _lm16), \
3058 /*LM32*/ RT_CONCAT(a_BaseNm, _lm32), \
3059 /*LM64*/ RT_CONCAT(a_BaseNm, _lm64), \
3060 }
3061
3062/** @def BS3TESTMODE_PROTOTYPES_MODE
3063 * A set of standard protypes to go with #BS3TESTMODEENTRY_MODE. */
3064#define BS3TESTMODE_PROTOTYPES_MODE(a_BaseNm) \
3065 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _rm); \
3066 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe16); \
3067 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe16_32); \
3068 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe16_v86); \
3069 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe32); \
3070 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe32_16); \
3071 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pev86); \
3072 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp16); \
3073 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp16_32); \
3074 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp16_v86); \
3075 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp32); \
3076 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp32_16); \
3077 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _ppv86); \
3078 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae16); \
3079 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae16_32); \
3080 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae16_v86); \
3081 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae32); \
3082 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae32_16); \
3083 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _paev86); \
3084 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _lm16); \
3085 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _lm32); \
3086 FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _lm64)
3087
3088
3089/**
3090 * One worker drives all modes.
3091 *
3092 * This is an alternative to BS3TESTMODEENTRY where one worker, typically
3093 * 16-bit, does all the test driver work. It's called repeatedly from all
3094 * the modes being tested.
3095 */
3096typedef struct BS3TESTMODEBYONEENTRY
3097{
3098 const char * BS3_FAR pszSubTest;
3099 PFNBS3TESTDOMODE pfnWorker;
3100 uint32_t u32Reserved;
3101} BS3TESTMODEBYONEENTRY;
3102/** Pointer to a mode-by-one sub-test entry. */
3103typedef BS3TESTMODEBYONEENTRY const *PCBS3TESTMODEBYONEENTRY;
3104
3105
3106/**
3107 * Sets the full GDTR register.
3108 *
3109 * @param cbLimit The limit.
3110 * @param uBase The base address - 24, 32 or 64 bit depending on the
3111 * CPU mode.
3112 */
3113BS3_CMN_PROTO_NOSB(void, Bs3UtilSetFullGdtr,(uint16_t cbLimit, uint64_t uBase));
3114
3115/**
3116 * Sets the full IDTR register.
3117 *
3118 * @param cbLimit The limit.
3119 * @param uBase The base address - 24, 32 or 64 bit depending on the
3120 * CPU mode.
3121 */
3122BS3_CMN_PROTO_NOSB(void, Bs3UtilSetFullIdtr,(uint16_t cbLimit, uint64_t uBase));
3123
3124
3125/** @} */
3126
3127
3128/**
3129 * Initializes all of boot sector kit \#3.
3130 */
3131BS3_DECL(void) Bs3InitAll_rm(void);
3132
3133/**
3134 * Initializes the REAL and TILED memory pools.
3135 *
3136 * For proper operation on OLDer CPUs, call #Bs3CpuDetect_mmm first.
3137 */
3138BS3_DECL_FAR(void) Bs3InitMemory_rm_far(void);
3139
3140/**
3141 * Initialized the X0TEXT16 and X1TEXT16 GDT entries.
3142 */
3143BS3_DECL_FAR(void) Bs3InitGdt_rm_far(void);
3144
3145
3146
3147/** @defgroup grp_bs3kit_mode Mode Specific Functions and Data
3148 *
3149 * The mode specific functions come in bit count variations and CPU mode
3150 * variations. The bs3kit-template-header.h/mac defines the BS3_NM macro to
3151 * mangle a function or variable name according to the target CPU mode. In
3152 * non-templated code, it's common to spell the name out in full.
3153 *
3154 * @{
3155 */
3156
3157
3158/** @def BS3_MODE_PROTO_INT
3159 * Internal macro for emitting prototypes for mode functions.
3160 *
3161 * @param a_RetType The return type.
3162 * @param a_Name The function basename.
3163 * @param a_Params The parameter list (in parentheses).
3164 * @sa BS3_MODE_PROTO_STUB, BS3_MODE_PROTO_NOSB
3165 */
3166#define BS3_MODE_PROTO_INT(a_RetType, a_Name, a_Params) \
3167 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_rm) a_Params; \
3168 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe16) a_Params; \
3169 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe16_32) a_Params; \
3170 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe16_v86) a_Params; \
3171 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe32) a_Params; \
3172 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe32_16) a_Params; \
3173 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pev86) a_Params; \
3174 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp16) a_Params; \
3175 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp16_32) a_Params; \
3176 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp16_v86) a_Params; \
3177 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp32) a_Params; \
3178 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp32_16) a_Params; \
3179 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_ppv86) a_Params; \
3180 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae16) a_Params; \
3181 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae16_32) a_Params; \
3182 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae16_v86) a_Params; \
3183 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae32) a_Params; \
3184 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae32_16) a_Params; \
3185 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_paev86) a_Params; \
3186 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_lm16) a_Params; \
3187 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_lm32) a_Params; \
3188 BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_lm64) a_Params; \
3189 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_rm_far) a_Params; \
3190 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pe16_far) a_Params; \
3191 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pe16_v86_far) a_Params; \
3192 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pe32_16_far) a_Params; \
3193 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pev86_far) a_Params; \
3194 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pp16_far) a_Params; \
3195 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pp16_v86_far) a_Params; \
3196 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pp32_16_far) a_Params; \
3197 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_ppv86_far) a_Params; \
3198 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pae16_far) a_Params; \
3199 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pae16_v86_far)a_Params; \
3200 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pae32_16_far) a_Params; \
3201 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_paev86_far) a_Params; \
3202 BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_lm16_far) a_Params
3203
3204/** @def BS3_MODE_PROTO_STUB
3205 * Macro for prototyping all the variations of a mod function with automatic
3206 * near -> far stub.
3207 *
3208 * @param a_RetType The return type.
3209 * @param a_Name The function basename.
3210 * @param a_Params The parameter list (in parentheses).
3211 * @sa BS3_MODE_PROTO_STUB, BS3_MODE_PROTO_NOSB
3212 */
3213#define BS3_MODE_PROTO_STUB(a_RetType, a_Name, a_Params) BS3_MODE_PROTO_INT(a_RetType, a_Name, a_Params)
3214
3215/** @def BS3_MODE_PROTO_STUB
3216 * Macro for prototyping all the variations of a mod function without any
3217 * near -> far stub.
3218 *
3219 * @param a_RetType The return type.
3220 * @param a_Name The function basename.
3221 * @param a_Params The parameter list (in parentheses).
3222 * @sa BS3_MODE_PROTO_STUB, BS3_MODE_PROTO_NOSB
3223 */
3224#define BS3_MODE_PROTO_NOSB(a_RetType, a_Name, a_Params) BS3_MODE_PROTO_INT(a_RetType, a_Name, a_Params)
3225
3226
3227/**
3228 * Macro for reducing typing.
3229 *
3230 * Doxygen knows how to expand this, well, kind of.
3231 *
3232 * @remarks Variables instantiated in assembly code should define two labels,
3233 * with and without leading underscore. Variables instantiated from
3234 * C/C++ code doesn't need to as the object file convert does this for
3235 * 64-bit object files.
3236 */
3237#define BS3_MODE_EXPAND_EXTERN_DATA16(a_VarType, a_VarName, a_Suffix) \
3238 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_rm) a_Suffix; \
3239 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pe16) a_Suffix; \
3240 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pe16_32) a_Suffix; \
3241 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pe16_v86) a_Suffix; \
3242 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pe32) a_Suffix; \
3243 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pe32_16) a_Suffix; \
3244 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pev86) a_Suffix; \
3245 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pp16) a_Suffix; \
3246 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pp16_32) a_Suffix; \
3247 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pp16_v86) a_Suffix; \
3248 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pp32) a_Suffix; \
3249 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pp32_16) a_Suffix; \
3250 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_ppv86) a_Suffix; \
3251 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pae16) a_Suffix; \
3252 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pae16_32) a_Suffix; \
3253 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pae16_v86)a_Suffix; \
3254 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pae32) a_Suffix; \
3255 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pae32_16) a_Suffix; \
3256 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_paev86) a_Suffix; \
3257 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_lm16) a_Suffix; \
3258 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_lm32) a_Suffix; \
3259 extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_lm64) a_Suffix
3260
3261
3262/** The TMPL_MODE_STR value for each mode.
3263 * These are all in DATA16 so they can be accessed from any code. */
3264BS3_MODE_EXPAND_EXTERN_DATA16(const char, g_szBs3ModeName, []);
3265
3266/**
3267 * Basic CPU detection.
3268 *
3269 * This sets the #g_uBs3CpuDetected global variable to the return value.
3270 *
3271 * @returns BS3CPU_XXX value with the BS3CPU_F_CPUID flag set depending on
3272 * capabilities.
3273 */
3274BS3_MODE_PROTO_NOSB(uint8_t, Bs3CpuDetect,(void));
3275
3276/** @name BS3CPU_XXX - CPU detected by BS3CpuDetect_c16() and friends.
3277 * @{ */
3278#define BS3CPU_8086 UINT16_C(0x0001) /**< Both 8086 and 8088. */
3279#define BS3CPU_V20 UINT16_C(0x0002) /**< Both NEC V20, V30 and relatives. */
3280#define BS3CPU_80186 UINT16_C(0x0003) /**< Both 80186 and 80188. */
3281#define BS3CPU_80286 UINT16_C(0x0004)
3282#define BS3CPU_80386 UINT16_C(0x0005)
3283#define BS3CPU_80486 UINT16_C(0x0006)
3284#define BS3CPU_Pentium UINT16_C(0x0007)
3285#define BS3CPU_PPro UINT16_C(0x0008)
3286#define BS3CPU_PProOrNewer UINT16_C(0x0009)
3287/** CPU type mask. This is a full byte so it's possible to use byte access
3288 * without and AND'ing to get the type value. */
3289#define BS3CPU_TYPE_MASK UINT16_C(0x00ff)
3290/** Flag indicating that the CPUID instruction is supported by the CPU. */
3291#define BS3CPU_F_CPUID UINT16_C(0x0100)
3292/** Flag indicating that extend CPUID leaves are available (at least two). */
3293#define BS3CPU_F_CPUID_EXT_LEAVES UINT16_C(0x0200)
3294/** Flag indicating that the CPU supports PAE. */
3295#define BS3CPU_F_PAE UINT16_C(0x0400)
3296/** Flag indicating that the CPU supports the page size extension (4MB pages). */
3297#define BS3CPU_F_PSE UINT16_C(0x0800)
3298/** Flag indicating that the CPU supports long mode. */
3299#define BS3CPU_F_LONG_MODE UINT16_C(0x1000)
3300/** @} */
3301
3302/** The return value of #Bs3CpuDetect_mmm. (Initial value is BS3CPU_TYPE_MASK.) */
3303extern uint16_t g_uBs3CpuDetected;
3304
3305/**
3306 * Initializes trap handling for the current system.
3307 *
3308 * Calls the appropriate Bs3Trap16Init, Bs3Trap32Init or Bs3Trap64Init function.
3309 */
3310BS3_MODE_PROTO_STUB(void, Bs3TrapInit,(void));
3311
3312/**
3313 * Executes the array of tests in every possibly mode.
3314 *
3315 * @param paEntries The mode sub-test entries.
3316 * @param cEntries The number of sub-test entries.
3317 */
3318BS3_MODE_PROTO_NOSB(void, Bs3TestDoModes,(PCBS3TESTMODEENTRY paEntries, size_t cEntries));
3319
3320/**
3321 * Executes the array of tests in every possibly mode, unitifed driver.
3322 *
3323 * This requires much less code space than Bs3TestDoModes as there is only one
3324 * instace of each sub-test driver code, instead of 3 (cmn) or 22 (per-mode)
3325 * copies.
3326 *
3327 * @param paEntries The mode sub-test-by-one entries.
3328 * @param cEntries The number of sub-test-by-one entries.
3329 * @param fFlags Reserved for the future, MBZ.
3330 */
3331BS3_MODE_PROTO_NOSB(void, Bs3TestDoModesByOne,(PCBS3TESTMODEBYONEENTRY paEntries, size_t cEntries, uint32_t fFlags));
3332
3333
3334/** @} */
3335
3336/** @} */
3337
3338RT_C_DECLS_END
3339
3340
3341/*
3342 * Include default function symbol mangling.
3343 */
3344#include "bs3kit-mangling-code.h"
3345
3346/*
3347 * Change 16-bit text segment if requested.
3348 */
3349#if defined(BS3_USE_ALT_16BIT_TEXT_SEG) && ARCH_BITS == 16 && !defined(BS3_DONT_CHANGE_TEXT_SEG)
3350# if (defined(BS3_USE_RM_TEXT_SEG) + defined(BS3_USE_X0_TEXT_SEG) + defined(BS3_USE_X1_TEXT_SEG)) != 1
3351# error "Cannot set more than one alternative 16-bit text segment!"
3352# elif defined(BS3_USE_RM_TEXT_SEG)
3353# pragma code_seg("BS3RMTEXT16", "BS3CLASS16RMCODE")
3354# elif defined(BS3_USE_X0_TEXT_SEG)
3355# pragma code_seg("BS3X0TEXT16", "BS3CLASS16X0CODE")
3356# elif defined(BS3_USE_X1_TEXT_SEG)
3357# pragma code_seg("BS3X1TEXT16", "BS3CLASS16X1CODE")
3358# else
3359# error "Huh? Which alternative text segment did you want again?"
3360# endif
3361#endif
3362
3363#endif
3364
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