VirtualBox

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

Last change on this file since 60676 was 60676, checked in by vboxsync, 9 years ago

bs3kit: updates

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