VirtualBox

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

最後變更 在這個檔案從59895是 59895,由 vboxsync 提交於 9 年 前

bs3kit: Updates

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 109.3 KB
 
1/* $Id: bs3kit.h 59895 2016-03-02 12:40:59Z vboxsync $ */
2/** @file
3 * BS3Kit - structures, symbols, macros and stuff.
4 */
5
6/*
7 * Copyright (C) 2007-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef ___bs3kit_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 * We may want to reuse some IPRT code in the common name space, so we
41 * redefine the RT_MANGLER to work like BS3_CMN_NM. (We cannot use
42 * BS3_CMN_NM yet, as we need to include IPRT headers with function
43 * declarations before we can define it. Thus the duplciate effort.)
44 */
45#define RT_MANGLER(a_Name) RT_CONCAT3(a_Name,_c,ARCH_BITS)
46#include <iprt/mangling.h>
47#include <iprt/x86.h>
48#include <iprt/err.h>
49
50
51
52RT_C_DECLS_BEGIN
53
54/** @defgroup grp_bs3kit BS3Kit
55 * @{ */
56
57/** @name Execution modes.
58 * @{ */
59#define BS3_MODE_INVALID UINT8_C(0x00)
60#define BS3_MODE_RM UINT8_C(0x01) /**< real mode. */
61#define BS3_MODE_PE16 UINT8_C(0x11) /**< 16-bit protected mode kernel+tss, running 16-bit code, unpaged. */
62#define BS3_MODE_PE16_32 UINT8_C(0x12) /**< 16-bit protected mode kernel+tss, running 32-bit code, unpaged. */
63#define BS3_MODE_PE16_V86 UINT8_C(0x13) /**< 16-bit protected mode kernel+tss, running virtual 8086 mode code, unpaged. */
64#define BS3_MODE_PE32 UINT8_C(0x22) /**< 32-bit protected mode kernel+tss, running 32-bit code, unpaged. */
65#define BS3_MODE_PE32_16 UINT8_C(0x21) /**< 32-bit protected mode kernel+tss, running 16-bit code, unpaged. */
66#define BS3_MODE_PEV86 UINT8_C(0x23) /**< 32-bit protected mode kernel+tss, running virtual 8086 mode code, unpaged. */
67#define BS3_MODE_PP16 UINT8_C(0x31) /**< 16-bit protected mode kernel+tss, running 16-bit code, paged. */
68#define BS3_MODE_PP16_32 UINT8_C(0x32) /**< 16-bit protected mode kernel+tss, running 32-bit code, paged. */
69#define BS3_MODE_PP16_V86 UINT8_C(0x33) /**< 16-bit protected mode kernel+tss, running virtual 8086 mode code, paged. */
70#define BS3_MODE_PP32 UINT8_C(0x42) /**< 32-bit protected mode kernel+tss, running 32-bit code, paged. */
71#define BS3_MODE_PP32_16 UINT8_C(0x41) /**< 32-bit protected mode kernel+tss, running 16-bit code, paged. */
72#define BS3_MODE_PPV86 UINT8_C(0x43) /**< 32-bit protected mode kernel+tss, running virtual 8086 mode code, paged. */
73#define BS3_MODE_PAE16 UINT8_C(0x51) /**< 16-bit protected mode kernel+tss, running 16-bit code, PAE paging. */
74#define BS3_MODE_PAE16_32 UINT8_C(0x52) /**< 16-bit protected mode kernel+tss, running 32-bit code, PAE paging. */
75#define BS3_MODE_PAE16_V86 UINT8_C(0x53) /**< 16-bit protected mode kernel+tss, running virtual 8086 mode, PAE paging. */
76#define BS3_MODE_PAE32 UINT8_C(0x62) /**< 32-bit protected mode kernel+tss, running 32-bit code, PAE paging. */
77#define BS3_MODE_PAE32_16 UINT8_C(0x61) /**< 32-bit protected mode kernel+tss, running 16-bit code, PAE paging. */
78#define BS3_MODE_PAEV86 UINT8_C(0x63) /**< 32-bit protected mode kernel+tss, running virtual 8086 mode, PAE paging. */
79#define BS3_MODE_LM16 UINT8_C(0x71) /**< 16-bit long mode (paged), kernel+tss always 64-bit. */
80#define BS3_MODE_LM32 UINT8_C(0x72) /**< 32-bit long mode (paged), kernel+tss always 64-bit. */
81#define BS3_MODE_LM64 UINT8_C(0x74) /**< 64-bit long mode (paged), kernel+tss always 64-bit. */
82
83#define BS3_MODE_CODE_MASK UINT8_C(0x0f) /**< Running code mask. */
84#define BS3_MODE_CODE_16 UINT8_C(0x01) /**< Running 16-bit code. */
85#define BS3_MODE_CODE_32 UINT8_C(0x02) /**< Running 32-bit code. */
86#define BS3_MODE_CODE_V86 UINT8_C(0x03) /**< Running 16-bit virtual 8086 code. */
87#define BS3_MODE_CODE_64 UINT8_C(0x04) /**< Running 64-bit code. */
88
89#define BS3_MODE_SYS_MASK UINT8_C(0xf0) /**< kernel+tss mask. */
90#define BS3_MODE_SYS_RM UINT8_C(0x00) /**< Real mode kernel+tss. */
91#define BS3_MODE_SYS_PE16 UINT8_C(0x10) /**< 16-bit protected mode kernel+tss. */
92#define BS3_MODE_SYS_PE32 UINT8_C(0x20) /**< 32-bit protected mode kernel+tss. */
93#define BS3_MODE_SYS_PP16 UINT8_C(0x30) /**< 16-bit paged protected mode kernel+tss. */
94#define BS3_MODE_SYS_PP32 UINT8_C(0x40) /**< 32-bit paged protected mode kernel+tss. */
95#define BS3_MODE_SYS_PAE16 UINT8_C(0x50) /**< 16-bit PAE paged protected mode kernel+tss. */
96#define BS3_MODE_SYS_PAE32 UINT8_C(0x60) /**< 32-bit PAE paged protected mode kernel+tss. */
97#define BS3_MODE_SYS_LM UINT8_C(0x70) /**< 64-bit (paged) long mode protected mode kernel+tss. */
98
99/** Whether the mode has paging enabled. */
100#define BS3_MODE_IS_PAGED(a_fMode) ((a_fMode) >= BS3_MODE_PP16)
101
102/** Whether the mode is running v8086 code. */
103#define BS3_MODE_IS_V86(a_fMode) (((a_fMode) & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_V86)
104/** Whether the we're executing in real mode or v8086 mode. */
105#define BS3_MODE_IS_RM_OR_V86(a_fMode) ((a_fMode) == BS3_MODE_RM || BS3_MODE_IS_V86(a_fMode))
106/** Whether the mode is running 16-bit code, except v8086. */
107#define BS3_MODE_IS_16BIT_CODE_NO_V86(a_fMode) (((a_fMode) & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_16)
108/** Whether the mode is running 16-bit code (includes v8086). */
109#define BS3_MODE_IS_16BIT_CODE(a_fMode) (BS3_MODE_IS_16BIT_CODE_NO_V86(a_fMode) || BS3_MODE_IS_V86(a_fMode))
110/** Whether the mode is running 32-bit code. */
111#define BS3_MODE_IS_32BIT_CODE(a_fMode) (((a_fMode) & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_32)
112/** Whether the mode is running 64-bit code. */
113#define BS3_MODE_IS_64BIT_CODE(a_fMode) (((a_fMode) & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_64)
114
115/** Whether the system is in real mode. */
116#define BS3_MODE_IS_RM_SYS(a_fMode) (((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_RM)
117/** Whether the system is some 16-bit mode that isn't real mode. */
118#define BS3_MODE_IS_16BIT_SYS_NO_RM(a_fMode) ( ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PE16 \
119 || ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PP16 \
120 || ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PAE16)
121/** Whether the system is some 16-bit mode (includes real mode). */
122#define BS3_MODE_IS_16BIT_SYS(a_fMode) (BS3_MODE_IS_16BIT_SYS_NO_RM(a_fMode) || BS3_MODE_IS_RM_SYS(a_fMode))
123/** Whether the system is some 32-bit mode. */
124#define BS3_MODE_IS_32BIT_SYS(a_fMode) ( ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PE32 \
125 || ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PP32 \
126 || ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PAE32)
127/** Whether the system is long mode. */
128#define BS3_MODE_IS_64BIT_SYS(a_fMode) (((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_LM)
129
130/** @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? */
131/** @} */
132
133
134/** @name BS3_ADDR_XXX - Static Memory Allocation
135 * @{ */
136/** The flat load address for the code after the bootsector. */
137#define BS3_ADDR_LOAD 0x10000
138/** Where we save the boot registers during init.
139 * Located right before the code. */
140#define BS3_ADDR_REG_SAVE (BS3_ADDR_LOAD - sizeof(BS3REGS) - 8)
141/** Where the stack starts (initial RSP value).
142 * Located 16 bytes (assumed by boot sector) before the saved registers.
143 * SS.BASE=0. The size is a little short of 32KB */
144#define BS3_ADDR_STACK (BS3_ADDR_REG_SAVE - 16)
145/** The ring-0 stack (8KB) for ring transitions. */
146#define BS3_ADDR_STACK_R0 0x06000
147/** The ring-1 stack (8KB) for ring transitions. */
148#define BS3_ADDR_STACK_R1 0x04000
149/** The ring-2 stack (8KB) for ring transitions. */
150#define BS3_ADDR_STACK_R2 0x02000
151/** IST1 ring-0 stack for long mode (4KB), used for double faults elsewhere. */
152#define BS3_ADDR_STACK_R0_IST1 0x09000
153/** IST2 ring-0 stack for long mode (3KB), used for spare 0 stack elsewhere. */
154#define BS3_ADDR_STACK_R0_IST2 0x08000
155/** IST3 ring-0 stack for long mode (1KB). */
156#define BS3_ADDR_STACK_R0_IST3 0x07400
157/** IST4 ring-0 stack for long mode (1KB), used for spare 1 stack elsewhere. */
158#define BS3_ADDR_STACK_R0_IST4 0x07000
159/** IST5 ring-0 stack for long mode (1KB). */
160#define BS3_ADDR_STACK_R0_IST5 0x06c00
161/** IST6 ring-0 stack for long mode (1KB). */
162#define BS3_ADDR_STACK_R0_IST6 0x06800
163/** IST7 ring-0 stack for long mode (1KB). */
164#define BS3_ADDR_STACK_R0_IST7 0x06400
165
166/** The base address of the BS3TEXT16 segment (same as BS3_LOAD_ADDR).
167 * @sa BS3_SEL_TEXT16 */
168#define BS3_ADDR_BS3TEXT16 0x10000
169/** The base address of the BS3SYSTEM16 segment.
170 * @sa BS3_SEL_SYSTEM16 */
171#define BS3_ADDR_BS3SYSTEM16 0x20000
172/** The base address of the BS3DATA16 segment.
173 * @sa BS3_SEL_DATA16 */
174#define BS3_ADDR_BS3DATA16 0x27000
175/** @} */
176
177/** @name BS3_SEL_XXX - GDT selector assignments.
178 *
179 * The real mode segment numbers for BS16TEXT, BS16DATA and BS16SYSTEM are
180 * present in the GDT, this allows the 16-bit C/C++ and assembly code to
181 * continue using the real mode segment values in ring-0 protected mode.
182 *
183 * The three segments have fixed locations:
184 * | segment | flat address | real mode segment |
185 * | ----------- | ------------ | ----------------- |
186 * | BS3TEXT16 | 0x00010000 | 1000h |
187 * | BS3SYSTEM16 | 0x00020000 | 2000h |
188 * | BS3DATA16 | 0x00027000 | 2700h |
189 *
190 * This means that we've got a lot of GDT space to play around with.
191 *
192 * @{ */
193#define BS3_SEL_LDT 0x0010 /**< The LDT selector for Bs3Ldt. */
194#define BS3_SEL_TSS16 0x0020 /**< The 16-bit TSS selector. */
195#define BS3_SEL_TSS16_DF 0x0028 /**< The 16-bit TSS selector for double faults. */
196#define BS3_SEL_TSS16_SPARE0 0x0030 /**< The 16-bit TSS selector for testing. */
197#define BS3_SEL_TSS16_SPARE1 0x0038 /**< The 16-bit TSS selector for testing. */
198#define BS3_SEL_TSS32 0x0040 /**< The 32-bit TSS selector. */
199#define BS3_SEL_TSS32_DF 0x0048 /**< The 32-bit TSS selector for double faults. */
200#define BS3_SEL_TSS32_SPARE0 0x0050 /**< The 32-bit TSS selector for testing. */
201#define BS3_SEL_TSS32_SPARE1 0x0058 /**< The 32-bit TSS selector for testing. */
202#define BS3_SEL_TSS32_IOBP_IRB 0x0060 /**< The 32-bit TSS selector with I/O permission and interrupt redirection bitmaps. */
203#define BS3_SEL_TSS32_IRB 0x0068 /**< The 32-bit TSS selector with only interrupt redirection bitmap (IOPB stripped by limit). */
204#define BS3_SEL_TSS64 0x0070 /**< The 64-bit TSS selector. */
205#define BS3_SEL_TSS64_SPARE0 0x0080 /**< The 64-bit TSS selector. */
206#define BS3_SEL_TSS64_SPARE1 0x0090 /**< The 64-bit TSS selector. */
207#define BS3_SEL_TSS64_IOBP 0x00a0 /**< The 64-bit TSS selector. */
208
209#define BS3_SEL_VMMDEV_MMIO16 0x00f8 /**< Selector for accessing the VMMDev MMIO segment at 0100000h from 16-bit code. */
210
211#define BS3_SEL_RING_SHIFT 8 /**< For the formula: BS3_SEL_R0_XXX + ((cs & 3) << BS3_SEL_RING_SHIFT) */
212
213#define BS3_SEL_R0_FIRST 0x0100 /**< The first selector in the ring-0 block. */
214#define BS3_SEL_R0_CS16 0x0100 /**< ring-0: 16-bit code selector, base 0x10000. */
215#define BS3_SEL_R0_DS16 0x0108 /**< ring-0: 16-bit data selector, base 0x23000. */
216#define BS3_SEL_R0_SS16 0x0110 /**< ring-0: 16-bit stack selector, base 0x00000. */
217#define BS3_SEL_R0_CS32 0x0118 /**< ring-0: 32-bit flat code selector. */
218#define BS3_SEL_R0_DS32 0x0120 /**< ring-0: 32-bit flat data selector. */
219#define BS3_SEL_R0_SS32 0x0128 /**< ring-0: 32-bit flat stack selector. */
220#define BS3_SEL_R0_CS64 0x0130 /**< ring-0: 64-bit flat code selector. */
221#define BS3_SEL_R0_DS64 0x0138 /**< ring-0: 64-bit flat data & stack selector. */
222#define BS3_SEL_R0_CS16_EO 0x0140 /**< ring-0: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base. */
223#define BS3_SEL_R0_CS16_CNF 0x0148 /**< ring-0: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base. */
224#define BS3_SEL_R0_CS16_CNF_EO 0x0150 /**< ring-0: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base. */
225#define BS3_SEL_R0_CS32_EO 0x0158 /**< ring-0: 32-bit execute-only code selector, not accessed, flat. */
226#define BS3_SEL_R0_CS32_CNF 0x0160 /**< ring-0: 32-bit conforming code selector, not accessed, flat. */
227#define BS3_SEL_R0_CS32_CNF_EO 0x0168 /**< ring-0: 32-bit execute-only conforming code selector, not accessed, flat. */
228#define BS3_SEL_R0_CS64_EO 0x0170 /**< ring-0: 64-bit execute-only code selector, not accessed, flat. */
229#define BS3_SEL_R0_CS64_CNF 0x0178 /**< ring-0: 64-bit conforming code selector, not accessed, flat. */
230#define BS3_SEL_R0_CS64_CNF_EO 0x0180 /**< ring-0: 64-bit execute-only conforming code selector, not accessed, flat. */
231
232#define BS3_SEL_R1_FIRST 0x0200 /**< The first selector in the ring-1 block. */
233#define BS3_SEL_R1_CS16 0x0200 /**< ring-1: 16-bit code selector, base 0x10000. */
234#define BS3_SEL_R1_DS16 0x0208 /**< ring-1: 16-bit data selector, base 0x23000. */
235#define BS3_SEL_R1_SS16 0x0210 /**< ring-1: 16-bit stack selector, base 0x00000. */
236#define BS3_SEL_R1_CS32 0x0218 /**< ring-1: 32-bit flat code selector. */
237#define BS3_SEL_R1_DS32 0x0220 /**< ring-1: 32-bit flat data selector. */
238#define BS3_SEL_R1_SS32 0x0228 /**< ring-1: 32-bit flat stack selector. */
239#define BS3_SEL_R1_CS64 0x0230 /**< ring-1: 64-bit flat code selector. */
240#define BS3_SEL_R1_DS64 0x0238 /**< ring-1: 64-bit flat data & stack selector. */
241#define BS3_SEL_R1_CS16_EO 0x0240 /**< ring-1: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base. */
242#define BS3_SEL_R1_CS16_CNF 0x0248 /**< ring-1: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base. */
243#define BS3_SEL_R1_CS16_CNF_EO 0x0250 /**< ring-1: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base. */
244#define BS3_SEL_R1_CS32_EO 0x0258 /**< ring-1: 32-bit execute-only code selector, not accessed, flat. */
245#define BS3_SEL_R1_CS32_CNF 0x0260 /**< ring-1: 32-bit conforming code selector, not accessed, flat. */
246#define BS3_SEL_R1_CS32_CNF_EO 0x0268 /**< ring-1: 32-bit execute-only conforming code selector, not accessed, flat. */
247#define BS3_SEL_R1_CS64_EO 0x0270 /**< ring-1: 64-bit execute-only code selector, not accessed, flat. */
248#define BS3_SEL_R1_CS64_CNF 0x0278 /**< ring-1: 64-bit conforming code selector, not accessed, flat. */
249#define BS3_SEL_R1_CS64_CNF_EO 0x0280 /**< ring-1: 64-bit execute-only conforming code selector, not accessed, flat. */
250
251#define BS3_SEL_R2_FIRST 0x0300 /**< The first selector in the ring-2 block. */
252#define BS3_SEL_R2_CS16 0x0300 /**< ring-2: 16-bit code selector, base 0x10000. */
253#define BS3_SEL_R2_DS16 0x0308 /**< ring-2: 16-bit data selector, base 0x23000. */
254#define BS3_SEL_R2_SS16 0x0310 /**< ring-2: 16-bit stack selector, base 0x00000. */
255#define BS3_SEL_R2_CS32 0x0318 /**< ring-2: 32-bit flat code selector. */
256#define BS3_SEL_R2_DS32 0x0320 /**< ring-2: 32-bit flat data selector. */
257#define BS3_SEL_R2_SS32 0x0328 /**< ring-2: 32-bit flat stack selector. */
258#define BS3_SEL_R2_CS64 0x0330 /**< ring-2: 64-bit flat code selector. */
259#define BS3_SEL_R2_DS64 0x0338 /**< ring-2: 64-bit flat data & stack selector. */
260#define BS3_SEL_R2_CS16_EO 0x0340 /**< ring-2: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base. */
261#define BS3_SEL_R2_CS16_CNF 0x0348 /**< ring-2: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base. */
262#define BS3_SEL_R2_CS16_CNF_EO 0x0350 /**< ring-2: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base. */
263#define BS3_SEL_R2_CS32_EO 0x0358 /**< ring-2: 32-bit execute-only code selector, not accessed, flat. */
264#define BS3_SEL_R2_CS32_CNF 0x0360 /**< ring-2: 32-bit conforming code selector, not accessed, flat. */
265#define BS3_SEL_R2_CS32_CNF_EO 0x0368 /**< ring-2: 32-bit execute-only conforming code selector, not accessed, flat. */
266#define BS3_SEL_R2_CS64_EO 0x0370 /**< ring-2: 64-bit execute-only code selector, not accessed, flat. */
267#define BS3_SEL_R2_CS64_CNF 0x0378 /**< ring-2: 64-bit conforming code selector, not accessed, flat. */
268#define BS3_SEL_R2_CS64_CNF_EO 0x0380 /**< ring-2: 64-bit execute-only conforming code selector, not accessed, flat. */
269
270#define BS3_SEL_R3_FIRST 0x0400 /**< The first selector in the ring-3 block. */
271#define BS3_SEL_R3_CS16 0x0400 /**< ring-3: 16-bit code selector, base 0x10000. */
272#define BS3_SEL_R3_DS16 0x0408 /**< ring-3: 16-bit data selector, base 0x23000. */
273#define BS3_SEL_R3_SS16 0x0410 /**< ring-3: 16-bit stack selector, base 0x00000. */
274#define BS3_SEL_R3_CS32 0x0418 /**< ring-3: 32-bit flat code selector. */
275#define BS3_SEL_R3_DS32 0x0420 /**< ring-3: 32-bit flat data selector. */
276#define BS3_SEL_R3_SS32 0x0428 /**< ring-3: 32-bit flat stack selector. */
277#define BS3_SEL_R3_CS64 0x0430 /**< ring-3: 64-bit flat code selector. */
278#define BS3_SEL_R3_DS64 0x0438 /**< ring-3: 64-bit flat data & stack selector. */
279#define BS3_SEL_R3_CS16_EO 0x0440 /**< ring-3: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base. */
280#define BS3_SEL_R3_CS16_CNF 0x0448 /**< ring-3: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base. */
281#define BS3_SEL_R3_CS16_CNF_EO 0x0450 /**< ring-3: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base. */
282#define BS3_SEL_R3_CS32_EO 0x0458 /**< ring-3: 32-bit execute-only code selector, not accessed, flat. */
283#define BS3_SEL_R3_CS32_CNF 0x0460 /**< ring-3: 32-bit conforming code selector, not accessed, flat. */
284#define BS3_SEL_R3_CS32_CNF_EO 0x0468 /**< ring-3: 32-bit execute-only conforming code selector, not accessed, flat. */
285#define BS3_SEL_R3_CS64_EO 0x0470 /**< ring-3: 64-bit execute-only code selector, not accessed, flat. */
286#define BS3_SEL_R3_CS64_CNF 0x0478 /**< ring-3: 64-bit conforming code selector, not accessed, flat. */
287#define BS3_SEL_R3_CS64_CNF_EO 0x0480 /**< ring-3: 64-bit execute-only conforming code selector, not accessed, flat. */
288
289#define BS3_SEL_SPARE_FIRST 0x0500 /**< The first selector in the spare block */
290#define BS3_SEL_SPARE_00 0x0500 /**< Spare selector number 00h. */
291#define BS3_SEL_SPARE_01 0x0508 /**< Spare selector number 01h. */
292#define BS3_SEL_SPARE_02 0x0510 /**< Spare selector number 02h. */
293#define BS3_SEL_SPARE_03 0x0518 /**< Spare selector number 03h. */
294#define BS3_SEL_SPARE_04 0x0520 /**< Spare selector number 04h. */
295#define BS3_SEL_SPARE_05 0x0528 /**< Spare selector number 05h. */
296#define BS3_SEL_SPARE_06 0x0530 /**< Spare selector number 06h. */
297#define BS3_SEL_SPARE_07 0x0538 /**< Spare selector number 07h. */
298#define BS3_SEL_SPARE_08 0x0540 /**< Spare selector number 08h. */
299#define BS3_SEL_SPARE_09 0x0548 /**< Spare selector number 09h. */
300#define BS3_SEL_SPARE_0a 0x0550 /**< Spare selector number 0ah. */
301#define BS3_SEL_SPARE_0b 0x0558 /**< Spare selector number 0bh. */
302#define BS3_SEL_SPARE_0c 0x0560 /**< Spare selector number 0ch. */
303#define BS3_SEL_SPARE_0d 0x0568 /**< Spare selector number 0dh. */
304#define BS3_SEL_SPARE_0e 0x0570 /**< Spare selector number 0eh. */
305#define BS3_SEL_SPARE_0f 0x0578 /**< Spare selector number 0fh. */
306#define BS3_SEL_SPARE_10 0x0580 /**< Spare selector number 10h. */
307#define BS3_SEL_SPARE_11 0x0588 /**< Spare selector number 11h. */
308#define BS3_SEL_SPARE_12 0x0590 /**< Spare selector number 12h. */
309#define BS3_SEL_SPARE_13 0x0598 /**< Spare selector number 13h. */
310#define BS3_SEL_SPARE_14 0x05a0 /**< Spare selector number 14h. */
311#define BS3_SEL_SPARE_15 0x05a8 /**< Spare selector number 15h. */
312#define BS3_SEL_SPARE_16 0x05b0 /**< Spare selector number 16h. */
313#define BS3_SEL_SPARE_17 0x05b8 /**< Spare selector number 17h. */
314#define BS3_SEL_SPARE_18 0x05c0 /**< Spare selector number 18h. */
315#define BS3_SEL_SPARE_19 0x05c8 /**< Spare selector number 19h. */
316#define BS3_SEL_SPARE_1a 0x05d0 /**< Spare selector number 1ah. */
317#define BS3_SEL_SPARE_1b 0x05d8 /**< Spare selector number 1bh. */
318#define BS3_SEL_SPARE_1c 0x05e0 /**< Spare selector number 1ch. */
319#define BS3_SEL_SPARE_1d 0x05e8 /**< Spare selector number 1dh. */
320#define BS3_SEL_SPARE_1e 0x05f0 /**< Spare selector number 1eh. */
321#define BS3_SEL_SPARE_1f 0x05f8 /**< Spare selector number 1fh. */
322
323#define BS3_SEL_TILED 0x0600 /**< 16-bit data tiling: First - base=0x00000000, limit=64KB. */
324#define BS3_SEL_TILED_LAST 0x0df8 /**< 16-bit data tiling: Last - base=0x00ff0000, limit=64KB. */
325#define BS3_SEL_TILED_AREA_SIZE 0x001000000 /**< 16-bit data tiling: Size of addressable area, in bytes. (16 MB) */
326
327#define BS3_SEL_FREE_PART1 0x0e00 /**< Free selector space - part \#1. */
328#define BS3_SEL_FREE_PART1_LAST 0x0ff8 /**< Free selector space - part \#1, last entry. */
329
330#define BS3_SEL_TEXT16 0x1000 /**< The BS3TEXT16 selector. */
331
332#define BS3_SEL_FREE_PART2 0x1008 /**< Free selector space - part \#2. */
333#define BS3_SEL_FREE_PART2_LAST 0x1ff8 /**< Free selector space - part \#2, last entry. */
334
335#define BS3_SEL_SYSTEM16 0x2000 /**< The BS3SYSTEM16 selector. */
336
337#define BS3_SEL_FREE_PART3 0x2008 /**< Free selector space - part \#3. */
338#define BS3_SEL_FREE_PART3_LAST 0x26f8 /**< Free selector space - part \#3, last entry. */
339
340#define BS3_SEL_DATA16 0x2700 /**< The BS3DATA16 selector. */
341
342#define BS3_SEL_GDT_LIMIT 0x2707 /**< The GDT limit. */
343/** @} */
344
345
346/** @def BS3_FAR
347 * For indicating far pointers in 16-bit code.
348 * Does nothing in 32-bit and 64-bit code. */
349/** @def BS3_NEAR
350 * For indicating near pointers in 16-bit code.
351 * Does nothing in 32-bit and 64-bit code. */
352/** @def BS3_FAR_CODE
353 * For indicating far 16-bit functions.
354 * Does nothing in 32-bit and 64-bit code. */
355/** @def BS3_NEAR_CODE
356 * For indicating near 16-bit functions.
357 * Does nothing in 32-bit and 64-bit code. */
358/** @def BS3_FAR_DATA
359 * For indicating far 16-bit external data, i.e. in a segment other than DATA16.
360 * Does nothing in 32-bit and 64-bit code. */
361#ifdef M_I86
362# define BS3_FAR __far
363# define BS3_NEAR __near
364# define BS3_FAR_CODE __far
365# define BS3_NEAR_CODE __near
366# define BS3_FAR_DATA __far
367#else
368# define BS3_FAR
369# define BS3_NEAR
370# define BS3_FAR_CODE
371# define BS3_NEAR_CODE
372# define BS3_FAR_DATA
373#endif
374
375#if ARCH_BITS == 16 || defined(DOXYGEN_RUNNING)
376/** @def BS3_FP_SEG
377 * Get the selector (segment) part of a far pointer.
378 * @returns selector.
379 * @param a_pv Far pointer.
380 */
381# define BS3_FP_SEG(a_pv) ((uint16_t)(__segment)(void BS3_FAR *)(a_pv))
382/** @def BS3_FP_OFF
383 * Get the segment offset part of a far pointer.
384 * @returns offset.
385 * @param a_pv Far pointer.
386 */
387# define BS3_FP_OFF(a_pv) ((uint16_t)(void __near *)(a_pv))
388/** @def BS3_FP_MAKE
389 * Create a far pointer.
390 * @returns selector.
391 * @param a_pv Far pointer.
392 */
393# define BS3_FP_MAKE(a_uSeg, a_off) (((__segment)(a_uSeg)) :> ((void __near *)(a_off)))
394#endif
395
396/** @def BS3_CALL
397 * The calling convension used by BS3 functions. */
398#if ARCH_BITS != 64
399# define BS3_CALL __cdecl
400#elif !defined(_MSC_VER)
401# define BS3_CALL __attribute__((__ms_abi__))
402#else
403# define BS3_CALL
404#endif
405
406/** @def IN_BS3KIT
407 * Indicates that we're in the same link job as the BS3Kit code. */
408#ifdef DOXYGEN_RUNNING
409# define IN_BS3KIT
410#endif
411
412/** @def BS3_DECL
413 * Declares a BS3Kit function.
414 *
415 * Until we outgrow BS3TEXT16, we use all near functions in 16-bit.
416 *
417 * @param a_Type The return type. */
418#ifdef IN_BS3KIT
419# define BS3_DECL(a_Type) DECLEXPORT(a_Type) BS3_NEAR_CODE BS3_CALL
420#else
421# define BS3_DECL(a_Type) DECLIMPORT(a_Type) BS3_NEAR_CODE BS3_CALL
422#endif
423
424/** @def BS3_DECL_CALLBACK
425 * Declares a BS3Kit callback function (typically static).
426 *
427 * Until we outgrow BS3TEXT16, we use all near functions in 16-bit.
428 *
429 * @param a_Type The return type. */
430#ifdef IN_BS3KIT
431# define BS3_DECL_CALLBACK(a_Type) a_Type BS3_NEAR_CODE BS3_CALL
432#else
433# define BS3_DECL_CALLBACK(a_Type) a_Type BS3_NEAR_CODE BS3_CALL
434#endif
435
436/**
437 * Constructs a common name.
438 *
439 * Example: BS3_CMN_NM(Bs3Shutdown)
440 *
441 * @param a_Name The name of the function or global variable.
442 */
443#define BS3_CMN_NM(a_Name) RT_CONCAT3(a_Name,_c,ARCH_BITS)
444
445/**
446 * Constructs a data name.
447 *
448 * Example: extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdt)
449 *
450 * @param a_Name The name of the global variable.
451 */
452#if ARCH_BITS == 64
453# define BS3_DATA_NM(a_Name) RT_CONCAT(_,a_Name)
454#else
455# define BS3_DATA_NM(a_Name) a_Name
456#endif
457
458/** @def BS3_MSC64_FIXUP_HACK
459 * Used to avoid IMAGE_REL_AMD64_ADDR32NB fixups where the compiler tries to
460 * make use of __ImageBase as a base pointer instead of emitting rip relative
461 * accesses. Happens when there are a bunch of global data accesses in the same
462 * function, probably to save space.
463 *
464 * The volatile variable in the lambda fixes it.
465 */
466#if _MSC_VER && ARCH_BITS == 64
467# define BS3_MSC64_FIXUP_HACK(a_BaseType, a_Data) \
468 ([]() -> a_BaseType * \
469 { \
470 a_BaseType * volatile x = a_Data; \
471 return x; \
472 }())
473
474#else
475# define BS3_MSC64_FIXUP_HACK(a_BaseType, a_Data) (a_Data)
476#endif
477
478
479/**
480 * Template for createing a pointer union type.
481 * @param a_BaseName The base type name.
482 * @param a_Modifier The type modifier.
483 */
484#define BS3_PTR_UNION_TEMPLATE(a_BaseName, a_Modifiers) \
485 typedef union a_BaseName \
486 { \
487 /** Pointer into the void. */ \
488 a_Modifiers void BS3_FAR *pv; \
489 /** As a signed integer. */ \
490 intptr_t i; \
491 /** As an unsigned integer. */ \
492 uintptr_t u; \
493 /** Pointer to char value. */ \
494 a_Modifiers char BS3_FAR *pch; \
495 /** Pointer to char value. */ \
496 a_Modifiers unsigned char BS3_FAR *puch; \
497 /** Pointer to a int value. */ \
498 a_Modifiers int BS3_FAR *pi; \
499 /** Pointer to a unsigned int value. */ \
500 a_Modifiers unsigned int BS3_FAR *pu; \
501 /** Pointer to a long value. */ \
502 a_Modifiers long BS3_FAR *pl; \
503 /** Pointer to a long value. */ \
504 a_Modifiers unsigned long BS3_FAR *pul; \
505 /** Pointer to a memory size value. */ \
506 a_Modifiers size_t BS3_FAR *pcb; \
507 /** Pointer to a byte value. */ \
508 a_Modifiers uint8_t BS3_FAR *pb; \
509 /** Pointer to a 8-bit unsigned value. */ \
510 a_Modifiers uint8_t BS3_FAR *pu8; \
511 /** Pointer to a 16-bit unsigned value. */ \
512 a_Modifiers uint16_t BS3_FAR *pu16; \
513 /** Pointer to a 32-bit unsigned value. */ \
514 a_Modifiers uint32_t BS3_FAR *pu32; \
515 /** Pointer to a 64-bit unsigned value. */ \
516 a_Modifiers uint64_t BS3_FAR *pu64; \
517 /** Pointer to a UTF-16 character. */ \
518 a_Modifiers RTUTF16 BS3_FAR *pwc; \
519 /** Pointer to a UUID character. */ \
520 a_Modifiers RTUUID BS3_FAR *pUuid; \
521 } a_BaseName; \
522 /** Pointer to a pointer union. */ \
523 typedef a_BaseName *RT_CONCAT(P,a_BaseName)
524BS3_PTR_UNION_TEMPLATE(BS3PTRUNION, RT_NOTHING);
525BS3_PTR_UNION_TEMPLATE(BS3CPTRUNION, const);
526BS3_PTR_UNION_TEMPLATE(BS3VPTRUNION, volatile);
527BS3_PTR_UNION_TEMPLATE(BS3CVPTRUNION, const volatile);
528
529
530/** The system call vector. */
531#define BS3_TRAP_SYSCALL UINT8_C(0x20)
532
533/** @name System call numbers (ax).
534 * Paramenters are generally passed in registers specific to each system call.
535 * @{ */
536/** Print char (cl). */
537#define BS3_SYSCALL_PRINT_CHR UINT16_C(0x0001)
538/** Print string (pointer in ds:[e]si, length in cx). */
539#define BS3_SYSCALL_PRINT_STR UINT16_C(0x0002)
540/** Switch to ring-0. */
541#define BS3_SYSCALL_TO_RING0 UINT16_C(0x0003)
542/** Switch to ring-1. */
543#define BS3_SYSCALL_TO_RING1 UINT16_C(0x0004)
544/** Switch to ring-2. */
545#define BS3_SYSCALL_TO_RING2 UINT16_C(0x0005)
546/** Switch to ring-3. */
547#define BS3_SYSCALL_TO_RING3 UINT16_C(0x0006)
548/** @} */
549
550
551
552/** @defgroup grp_bs3kit_system System structures
553 * @{ */
554/** The GDT, indexed by BS3_SEL_XXX shifted by 3. */
555extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdt)[(BS3_SEL_GDT_LIMIT + 1) / 8];
556
557extern X86DESC64 BS3_FAR_DATA BS3_DATA_NM(Bs3Gdt_Ldt); /**< @see BS3_SEL_LDT */
558extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss16); /**< @see BS3_SEL_TSS16 */
559extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss16DoubleFault); /**< @see BS3_SEL_TSS16_DF */
560extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss16Spare0); /**< @see BS3_SEL_TSS16_SPARE0 */
561extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss16Spare1); /**< @see BS3_SEL_TSS16_SPARE1 */
562extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss32); /**< @see BS3_SEL_TSS32 */
563extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss32DoubleFault); /**< @see BS3_SEL_TSS32_DF */
564extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss32Spare0); /**< @see BS3_SEL_TSS32_SPARE0 */
565extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss32Spare1); /**< @see BS3_SEL_TSS32_SPARE1 */
566extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss32IobpIntRedirBm); /**< @see BS3_SEL_TSS32_IOBP_IRB */
567extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss32IntRedirBm); /**< @see BS3_SEL_TSS32_IRB */
568extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss64); /**< @see BS3_SEL_TSS64 */
569extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss64Spare0); /**< @see BS3_SEL_TSS64_SPARE0 */
570extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss64Spare1); /**< @see BS3_SEL_TSS64_SPARE1 */
571extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss64Iobp); /**< @see BS3_SEL_TSS64_IOBP */
572extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_MMIO16); /**< @see BS3_SEL_VMMDEV_MMIO16 */
573
574extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_First); /**< @see BS3_SEL_R0_FIRST */
575extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS16); /**< @see BS3_SEL_R0_CS16 */
576extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_DS16); /**< @see BS3_SEL_R0_DS16 */
577extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_SS16); /**< @see BS3_SEL_R0_SS16 */
578extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS32); /**< @see BS3_SEL_R0_CS32 */
579extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_DS32); /**< @see BS3_SEL_R0_DS32 */
580extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_SS32); /**< @see BS3_SEL_R0_SS32 */
581extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS64); /**< @see BS3_SEL_R0_CS64 */
582extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_DS64); /**< @see BS3_SEL_R0_DS64 */
583extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS16_EO); /**< @see BS3_SEL_R0_CS16_EO */
584extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS16_CNF); /**< @see BS3_SEL_R0_CS16_CNF */
585extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS16_CND_EO); /**< @see BS3_SEL_R0_CS16_CNF_EO */
586extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS32_EO); /**< @see BS3_SEL_R0_CS32_EO */
587extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS32_CNF); /**< @see BS3_SEL_R0_CS32_CNF */
588extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS32_CNF_EO); /**< @see BS3_SEL_R0_CS32_CNF_EO */
589extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS64_EO); /**< @see BS3_SEL_R0_CS64_EO */
590extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS64_CNF); /**< @see BS3_SEL_R0_CS64_CNF */
591extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS64_CNF_EO); /**< @see BS3_SEL_R0_CS64_CNF_EO */
592
593extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_First); /**< @see BS3_SEL_R1_FIRST */
594extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS16); /**< @see BS3_SEL_R1_CS16 */
595extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_DS16); /**< @see BS3_SEL_R1_DS16 */
596extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_SS16); /**< @see BS3_SEL_R1_SS16 */
597extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS32); /**< @see BS3_SEL_R1_CS32 */
598extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_DS32); /**< @see BS3_SEL_R1_DS32 */
599extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_SS32); /**< @see BS3_SEL_R1_SS32 */
600extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS64); /**< @see BS3_SEL_R1_CS64 */
601extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_DS64); /**< @see BS3_SEL_R1_DS64 */
602extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS16_EO); /**< @see BS3_SEL_R1_CS16_EO */
603extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS16_CNF); /**< @see BS3_SEL_R1_CS16_CNF */
604extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS16_CND_EO); /**< @see BS3_SEL_R1_CS16_CNF_EO */
605extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS32_EO); /**< @see BS3_SEL_R1_CS32_EO */
606extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS32_CNF); /**< @see BS3_SEL_R1_CS32_CNF */
607extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS32_CNF_EO); /**< @see BS3_SEL_R1_CS32_CNF_EO */
608extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS64_EO); /**< @see BS3_SEL_R1_CS64_EO */
609extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS64_CNF); /**< @see BS3_SEL_R1_CS64_CNF */
610extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS64_CNF_EO); /**< @see BS3_SEL_R1_CS64_CNF_EO */
611
612extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_First); /**< @see BS3_SEL_R2_FIRST */
613extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS16); /**< @see BS3_SEL_R2_CS16 */
614extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_DS16); /**< @see BS3_SEL_R2_DS16 */
615extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_SS16); /**< @see BS3_SEL_R2_SS16 */
616extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS32); /**< @see BS3_SEL_R2_CS32 */
617extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_DS32); /**< @see BS3_SEL_R2_DS32 */
618extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_SS32); /**< @see BS3_SEL_R2_SS32 */
619extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS64); /**< @see BS3_SEL_R2_CS64 */
620extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_DS64); /**< @see BS3_SEL_R2_DS64 */
621extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS16_EO); /**< @see BS3_SEL_R2_CS16_EO */
622extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS16_CNF); /**< @see BS3_SEL_R2_CS16_CNF */
623extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS16_CND_EO); /**< @see BS3_SEL_R2_CS16_CNF_EO */
624extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS32_EO); /**< @see BS3_SEL_R2_CS32_EO */
625extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS32_CNF); /**< @see BS3_SEL_R2_CS32_CNF */
626extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS32_CNF_EO); /**< @see BS3_SEL_R2_CS32_CNF_EO */
627extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS64_EO); /**< @see BS3_SEL_R2_CS64_EO */
628extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS64_CNF); /**< @see BS3_SEL_R2_CS64_CNF */
629extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS64_CNF_EO); /**< @see BS3_SEL_R2_CS64_CNF_EO */
630
631extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_First); /**< @see BS3_SEL_R3_FIRST */
632extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS16); /**< @see BS3_SEL_R3_CS16 */
633extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_DS16); /**< @see BS3_SEL_R3_DS16 */
634extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_SS16); /**< @see BS3_SEL_R3_SS16 */
635extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS32); /**< @see BS3_SEL_R3_CS32 */
636extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_DS32); /**< @see BS3_SEL_R3_DS32 */
637extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_SS32); /**< @see BS3_SEL_R3_SS32 */
638extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS64); /**< @see BS3_SEL_R3_CS64 */
639extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_DS64); /**< @see BS3_SEL_R3_DS64 */
640extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS16_EO); /**< @see BS3_SEL_R3_CS16_EO */
641extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS16_CNF); /**< @see BS3_SEL_R3_CS16_CNF */
642extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS16_CND_EO); /**< @see BS3_SEL_R3_CS16_CNF_EO */
643extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS32_EO); /**< @see BS3_SEL_R3_CS32_EO */
644extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS32_CNF); /**< @see BS3_SEL_R3_CS32_CNF */
645extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS32_CNF_EO); /**< @see BS3_SEL_R3_CS32_CNF_EO */
646extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS64_EO); /**< @see BS3_SEL_R3_CS64_EO */
647extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS64_CNF); /**< @see BS3_SEL_R3_CS64_CNF */
648extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS64_CNF_EO); /**< @see BS3_SEL_R3_CS64_CNF_EO */
649
650extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare00); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_00 */
651extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare01); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_01 */
652extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare02); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_02 */
653extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare03); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_03 */
654extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare04); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_04 */
655extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare05); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_05 */
656extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare06); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_06 */
657extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare07); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_07 */
658extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare08); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_08 */
659extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare09); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_09 */
660extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare0a); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0a */
661extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare0b); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0b */
662extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare0c); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0c */
663extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare0d); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0d */
664extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare0e); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0e */
665extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare0f); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0f */
666extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare10); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_10 */
667extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare11); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_11 */
668extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare12); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_12 */
669extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare13); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_13 */
670extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare14); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_14 */
671extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare15); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_15 */
672extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare16); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_16 */
673extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare17); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_17 */
674extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare18); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_18 */
675extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare19); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_19 */
676extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare1a); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1a */
677extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare1b); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1b */
678extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare1c); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1c */
679extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare1d); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1d */
680extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare1e); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1e */
681extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare1f); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1f */
682
683/** GDTs setting up the tiled 16-bit access to the first 16 MBs of memory.
684 * @see BS3_SEL_TILED, BS3_SEL_TILED_LAST, BS3_SEL_TILED_AREA_SIZE */
685extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteTiled)[256];
686/** Free GDTes, part \#1. */
687extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteFreePart1)[64];
688/** The BS3CODE16 GDT entry. @see BS3_SEL_TEXT16 */
689extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_CODE16);
690/** Free GDTes, part \#2. */
691extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteFreePart2)[511];
692/** The BS3SYSTEM16 GDT entry. */
693extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_SYSTEM16);
694/** Free GDTes, part \#3. */
695extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteFreePart3)[223];
696/** The BS3DATA16 GDT entry. */
697extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_DATA16);
698/** The end of the GDT (exclusive). */
699extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdtEnd);
700
701/** The default 16-bit TSS. */
702extern X86TSS16 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss16);
703extern X86TSS16 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss16DoubleFault);
704extern X86TSS16 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss16Spare0);
705extern X86TSS16 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss16Spare1);
706/** The default 32-bit TSS. */
707extern X86TSS32 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss32);
708extern X86TSS32 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss32DoubleFault);
709extern X86TSS32 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss32Spare0);
710extern X86TSS32 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss32Spare1);
711/** The default 64-bit TSS. */
712extern X86TSS64 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss64);
713extern X86TSS64 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss64Spare0);
714extern X86TSS64 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss64Spare1);
715extern X86TSS64 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss64WithIopb);
716extern X86TSS32 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss32WithIopb);
717/** Interrupt redirection bitmap used by Bs3Tss32WithIopb. */
718extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3SharedIntRedirBm)[32];
719/** I/O permission bitmap used by Bs3Tss32WithIopb and Bs3Tss64WithIopb. */
720extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3SharedIobp)[8192+2];
721/** End of the I/O permission bitmap (exclusive). */
722extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3SharedIobpEnd);
723/** 16-bit IDT. */
724extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Idt16)[256];
725/** 32-bit IDT. */
726extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Idt32)[256];
727/** 64-bit IDT. */
728extern X86DESC64 BS3_FAR_DATA BS3_DATA_NM(Bs3Idt64)[256];
729/** Structure for the LIDT instruction for loading the 16-bit IDT. */
730extern X86XDTR64 BS3_FAR_DATA BS3_DATA_NM(Bs3Lidt_Idt16);
731/** Structure for the LIDT instruction for loading the 32-bit IDT. */
732extern X86XDTR64 BS3_FAR_DATA BS3_DATA_NM(Bs3Lidt_Idt32);
733/** Structure for the LIDT instruction for loading the 64-bit IDT. */
734extern X86XDTR64 BS3_FAR_DATA BS3_DATA_NM(Bs3Lidt_Idt64);
735/** Structure for the LIDT instruction for loading the real mode interrupt
736 * vector table.. */
737extern X86XDTR64 BS3_FAR_DATA BS3_DATA_NM(Bs3Lidt_Ivt);
738/** Structure for the LGDT instruction for loading the GDT. */
739extern X86XDTR64 BS3_FAR_DATA BS3_DATA_NM(Bs3Lgdt_Gdt);
740/** The LDT (all entries are empty, fill in for testing). */
741extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Ldt)[118];
742/** The end of the LDT (exclusive). */
743extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3LdtEnd);
744
745/** @} */
746
747
748/** @name Segment start and end markers, sizes.
749 * @{ */
750/** Start of the BS3TEXT16 segment. */
751extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Text16_StartOfSegment);
752/** End of the BS3TEXT16 segment. */
753extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Text16_EndOfSegment);
754/** The size of the BS3TEXT16 segment. */
755extern uint16_t BS3_FAR_DATA BS3_DATA_NM(Bs3Text16_Size);
756
757/** Start of the BS3SYSTEM16 segment. */
758extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3System16_StartOfSegment);
759/** End of the BS3SYSTEM16 segment. */
760extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3System16_EndOfSegment);
761
762/** Start of the BS3DATA16 segment. */
763extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Data16_StartOfSegment);
764/** End of the BS3DATA16 segment. */
765extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Data16_EndOfSegment);
766
767/** Start of the BS3TEXT32 segment. */
768extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Text32_StartOfSegment);
769/** Start of the BS3TEXT32 segment. */
770extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Text32_EndOfSegment);
771
772/** Start of the BS3DATA32 segment. */
773extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Data32_StartOfSegment);
774/** Start of the BS3DATA32 segment. */
775extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Data32_EndOfSegment);
776
777/** Start of the BS3TEXT64 segment. */
778extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Text64_StartOfSegment);
779/** Start of the BS3TEXT64 segment. */
780extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Text64_EndOfSegment);
781
782/** Start of the BS3DATA64 segment. */
783extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Data64_StartOfSegment);
784/** Start of the BS3DATA64 segment. */
785extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Data64_EndOfSegment);
786
787/** The size of the Data16, Text32, Text64, Data32 and Data64 blob. */
788extern uint32_t BS3_FAR_DATA BS3_DATA_NM(Bs3Data16Thru64Text32And64_TotalSize);
789/** The total image size (from Text16 thu Data64). */
790extern uint32_t BS3_FAR_DATA BS3_DATA_NM(Bs3TotalImageSize);
791/** @} */
792
793
794/** Lower case hex digits. */
795extern char const BS3_DATA_NM(g_achBs3HexDigits)[16+1];
796/** Upper case hex digits. */
797extern char const BS3_DATA_NM(g_achBs3HexDigitsUpper)[16+1];
798
799
800/** The current mode (BS3_MODE_XXX) of CPU \#0. */
801extern uint8_t BS3_FAR_DATA BS3_DATA_NM(g_bBs3CurrentMode);
802
803
804#ifdef __WATCOMC__
805/**
806 * Executes the SMSW instruction and returns the value.
807 *
808 * @returns Machine status word.
809 */
810uint16_t Bs3AsmSmsw(void);
811# pragma aux Bs3AsmSmsw = \
812 ".286" \
813 "smsw ax" \
814 value [ax] modify exact [ax] nomemory;
815#endif
816
817
818/** @def BS3_IS_PROTECTED_MODE
819 * @returns true if protected mode, false if not. */
820#if ARCH_BITS != 16
821# define BS3_IS_PROTECTED_MODE() (true)
822#else
823# if 1
824# define BS3_IS_PROTECTED_MODE() (!BS3_MODE_IS_RM_SYS(BS3_DATA_NM(g_bBs3CurrentMode)))
825# else
826# define BS3_IS_PROTECTED_MODE() (Bs3AsmSmsw() & 1 /*PE*/)
827# endif
828#endif
829
830
831/** @defgroup bs3kit_cross_ptr Cross context pointer type
832 *
833 * The cross context pointer type is
834 *
835 * @{ */
836
837/**
838 * Cross context pointer base type.
839 */
840#pragma pack(4)
841typedef union BS3XPTR
842{
843 /** The flat pointer. */
844 uint32_t uFlat;
845 /** 16-bit view. */
846 struct
847 {
848 uint16_t uLow;
849 uint16_t uHigh;
850 } u;
851#if ARCH_BITS == 16
852 /** 16-bit near pointer. */
853 void __near *pvNear;
854#elif ARCH_BITS == 32
855 /** 32-bit pointer. */
856 void *pvRaw;
857#endif
858} BS3XPTR;
859#pragma pack()
860
861
862/** @def BS3_XPTR_DEF_INTERNAL
863 * Internal worker.
864 *
865 * @param a_Scope RT_NOTHING if structure or global, static or extern
866 * otherwise.
867 * @param a_Type The type we're pointing to.
868 * @param a_Name The member or variable name.
869 * @internal
870 */
871#if ARCH_BITS == 16
872# define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \
873 a_Scope union \
874 { \
875 BS3XPTR XPtr; \
876 a_Type __near *pNearTyped; \
877 } a_Name
878#elif ARCH_BITS == 32
879# define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \
880 a_Scope union \
881 { \
882 BS3XPTR XPtr; \
883 a_Type *pTyped; \
884 } a_Name
885#elif ARCH_BITS == 64
886# define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \
887 a_Scope union \
888 { \
889 BS3XPTR XPtr; \
890 a_Type *pTyped; \
891 } a_Name
892#else
893# error "ARCH_BITS"
894#endif
895
896/** @def BS3_XPTR_DEF_MEMBER
897 * Defines a pointer member that can be shared by all CPU modes.
898 *
899 * @param a_Type The type we're pointing to.
900 * @param a_Name The member or variable name.
901 */
902#define BS3_XPTR_MEMBER(a_Type, a_Name) BS3_XPTR_DEF_INTERNAL(RT_NOTHING, a_Type, a_Name)
903
904/** @def BS3_XPTR_DEF_AUTO
905 * Defines a pointer static variable for working with an XPTR.
906 *
907 * This is typically used to convert flat pointers into context specific
908 * pointers.
909 *
910 * @param a_Type The type we're pointing to.
911 * @param a_Name The member or variable name.
912 */
913#define BS3_XPTR_AUTO(a_Type, a_Name) BS3_XPTR_DEF_INTERNAL(RT_NOTHING, a_Type, a_Name)
914
915/** @def BS3_XPTR_SET
916 * Sets a cross context pointer.
917 *
918 * @param a_Type The type we're pointing to.
919 * @param a_Name The member or variable name.
920 * @param a_uFlatPtr The flat pointer value to assign. If the x-pointer is
921 * used in real mode, this must be less than 1MB.
922 * Otherwise the limit is 16MB (due to selector tiling).
923 */
924#define BS3_XPTR_SET_FLAT(a_Type, a_Name, a_uFlatPtr) \
925 do { a_Name.XPtr.uFlat = (a_uFlatPtr); } while (0)
926
927/** @def BS3_XPTR_GET_FLAT
928 * Gets the flat address of a cross context pointer.
929 *
930 * @returns 32-bit flat pointer.
931 * @param a_Type The type we're pointing to.
932 * @param a_Name The member or variable name.
933 */
934#define BS3_XPTR_GET_FLAT(a_Type, a_Name) (a_Name.XPtr.uFlat)
935
936/** @def BS3_XPTR_GET_FLAT_LOW
937 * Gets the low 16 bits of the flat address.
938 *
939 * @returns Low 16 bits of the flat pointer.
940 * @param a_Type The type we're pointing to.
941 * @param a_Name The member or variable name.
942 */
943#define BS3_XPTR_GET_FLAT_LOW(a_Type, a_Name) (a_Name.XPtr.u.uLow)
944
945
946#if ARCH_BITS == 16
947
948/**
949 * Gets the current ring number.
950 * @returns Ring number.
951 */
952DECLINLINE(uint16_t) Bs3Sel16GetCurRing(void);
953# pragma aux Bs3Sel16GetCurRing = \
954 "mov ax, ss" \
955 "and ax, 3" \
956 value [ax] modify exact [ax] nomemory;
957
958/**
959 * Converts the high word of a flat pointer into a 16-bit selector.
960 *
961 * This makes use of the tiled area. It also handles real mode.
962 *
963 * @returns Segment selector value.
964 * @param uHigh The high part of flat pointer.
965 * @sa BS3_XPTR_GET, BS3_XPTR_SET
966 */
967DECLINLINE(__segment) Bs3Sel16HighFlatPtrToSelector(uint16_t uHigh)
968{
969 if (BS3_IS_PROTECTED_MODE())
970 return (__segment)(((uHigh << 3) + BS3_SEL_TILED) | Bs3Sel16GetCurRing());
971 return (__segment)(uHigh << 12);
972}
973
974#endif /* ARCH_BITS == 16*/
975
976/** @def BS3_XPTR_GET
977 * Gets the current context pointer value.
978 *
979 * @returns Usable pointer.
980 * @param a_Type The type we're pointing to.
981 * @param a_Name The member or variable name.
982 */
983#if ARCH_BITS == 16
984# define BS3_XPTR_GET(a_Type, a_Name) \
985 ((a_Type BS3_FAR *)BS3_FP_MAKE(Bs3Sel16HighFlatPtrToSelector((a_Name).XPtr.u.uHigh), (a_Name).pNearTyped))
986#elif ARCH_BITS == 32
987# define BS3_XPTR_GET(a_Type, a_Name) ((a_Name).pTyped)
988#elif ARCH_BITS == 64
989# define BS3_XPTR_GET(a_Type, a_Name) ((a_Type *)(uintptr_t)(a_Name).XPtr.uFlat)
990#else
991# error "ARCH_BITS"
992#endif
993
994/** @def BS3_XPTR_SET
995 * Gets the current context pointer value.
996 *
997 * @returns Usable pointer.
998 * @param a_Type The type we're pointing to.
999 * @param a_Name The member or variable name.
1000 * @param a_pValue The new pointer value, current context pointer.
1001 */
1002#if ARCH_BITS == 16
1003# define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \
1004 do { \
1005 a_Type BS3_FAR *pTypeCheck = (a_pValue); \
1006 if (BS3_IS_PROTECTED_MODE()) \
1007 { \
1008 (a_Name).XPtr.u.uLow = BS3_FP_OFF(pTypeCheck); \
1009 (a_Name).XPtr.u.uHigh = ((BS3_FP_SEG(pTypeCheck) & UINT16_C(0xfff8)) - BS3_SEL_TILED) >> 3; \
1010 } \
1011 else \
1012 (a_Name).XPtr.uFlat = BS3_FP_OFF(pTypeCheck) + ((uint32_t)BS3_FP_SEG(pTypeCheck) << 4); \
1013 } while (0)
1014#elif ARCH_BITS == 32
1015# define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \
1016 do { (a_Name).pTyped = (a_pValue); } while (0)
1017#elif ARCH_BITS == 64
1018# define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \
1019 do { \
1020 a_Type *pTypeCheck = (a_pValue); \
1021 (a_Name).XPtr.uFlat = (uint32_t)(uintptr_t)pTypeCheck; \
1022 } while (0)
1023#else
1024# error "ARCH_BITS"
1025#endif
1026
1027
1028/** @def BS3_XPTR_IS_NULL
1029 * Checks if the cross context pointer is NULL.
1030 *
1031 * @returns true if NULL, false if not.
1032 * @param a_Type The type we're pointing to.
1033 * @param a_Name The member or variable name.
1034 */
1035#define BS3_XPTR_IS_NULL(a_Type, a_Name) ((a_Name).XPtr.uFlat == 0)
1036/** @} */
1037
1038
1039
1040/** @defgroup grp_bs3kit_cmn Common Functions and Data
1041 *
1042 * The common functions comes in three variations: 16-bit, 32-bit and 64-bit.
1043 * Templated code uses the #BS3_CMN_NM macro to mangle the name according to the
1044 * desired
1045 *
1046 * @{
1047 */
1048
1049#ifdef BS3_STRICT
1050# define BS3_ASSERT(a_Expr) do { if (!!(a_Expr)) { /* likely */ } else { Bs3Panic(); } } while (0) /**< @todo later */
1051#else
1052# define BS3_ASSERT(a_Expr) do { } while (0)
1053#endif
1054
1055/**
1056 * Panic, never return.
1057 *
1058 * The current implementation will only halt the CPU.
1059 */
1060BS3_DECL(void) Bs3Panic_c16(void);
1061BS3_DECL(void) Bs3Panic_c32(void); /**< @copydoc Bs3Panic_c16 */
1062BS3_DECL(void) Bs3Panic_c64(void); /**< @copydoc Bs3Panic_c16 */
1063#define Bs3Panic BS3_CMN_NM(Bs3Panic) /**< Selects #Bs3Panic_c16, #Bs3Panic_c32 or #Bs3Panic_c64. */
1064
1065/**
1066 * Shutdown the system, never returns.
1067 *
1068 * This currently only works for VMs. When running on real systems it will
1069 * just halt the CPU.
1070 */
1071BS3_DECL(void) Bs3Shutdown_c16(void);
1072BS3_DECL(void) Bs3Shutdown_c32(void); /**< @copydoc Bs3Shutdown_c16 */
1073BS3_DECL(void) Bs3Shutdown_c64(void); /**< @copydoc Bs3Shutdown_c16 */
1074#define Bs3Shutdown BS3_CMN_NM(Bs3Shutdown) /**< Selects #Bs3Shutdown_c16, #Bs3Shutdown_c32 or #Bs3Shutdown_c64. */
1075
1076/**
1077 * Prints a 32-bit unsigned value as decimal to the screen.
1078 *
1079 * @param uValue The 32-bit value.
1080 */
1081BS3_DECL(void) Bs3PrintU32_c16(uint32_t uValue);
1082BS3_DECL(void) Bs3PrintU32_c32(uint32_t uValue); /**< @copydoc Bs3PrintU32_c16 */
1083BS3_DECL(void) Bs3PrintU32_c64(uint32_t uValue); /**< @copydoc Bs3PrintU32_c16 */
1084#define Bs3PrintU32 BS3_CMN_NM(Bs3PrintU32) /**< Selects #Bs3PrintU32_c16, #Bs3PrintU32_c32 or #Bs3PrintU32_c64. */
1085
1086/**
1087 * Prints a 32-bit unsigned value as hex to the screen.
1088 *
1089 * @param uValue The 32-bit value.
1090 */
1091BS3_DECL(void) Bs3PrintX32_c16(uint32_t uValue);
1092BS3_DECL(void) Bs3PrintX32_c32(uint32_t uValue); /**< @copydoc Bs3PrintX32_c16 */
1093BS3_DECL(void) Bs3PrintX32_c64(uint32_t uValue); /**< @copydoc Bs3PrintX32_c16 */
1094#define Bs3PrintX32 BS3_CMN_NM(Bs3PrintX32) /**< Selects #Bs3PrintX32_c16, #Bs3PrintX32_c32 or #Bs3PrintX32_c64. */
1095
1096/**
1097 * Formats and prints a string to the screen.
1098 *
1099 * See #Bs3StrFormatV_c16 for supported format types.
1100 *
1101 * @param pszFormat The format string.
1102 * @param ... Format arguments.
1103 */
1104BS3_DECL(size_t) Bs3Printf_c16(const char BS3_FAR *pszFormat, ...);
1105BS3_DECL(size_t) Bs3Printf_c32(const char BS3_FAR *pszFormat, ...); /**< @copydoc Bs3Printf_c16 */
1106BS3_DECL(size_t) Bs3Printf_c64(const char BS3_FAR *pszFormat, ...); /**< @copydoc Bs3Printf_c16 */
1107#define Bs3Printf BS3_CMN_NM(Bs3Printf) /**< Selects #Bs3Printf_c16, #Bs3Printf_c32 or #Bs3Printf_c64. */
1108
1109/**
1110 * Formats and prints a string to the screen, va_list version.
1111 *
1112 * See #Bs3Format_c16 for supported format types.
1113 *
1114 * @param pszFormat The format string.
1115 * @param va Format arguments.
1116 */
1117BS3_DECL(size_t) Bs3PrintfV_c16(const char BS3_FAR *pszFormat, va_list va);
1118BS3_DECL(size_t) Bs3PrintfV_c32(const char BS3_FAR *pszFormat, va_list va); /**< @copydoc Bs3PrintfV_c16 */
1119BS3_DECL(size_t) Bs3PrintfV_c64(const char BS3_FAR *pszFormat, va_list va); /**< @copydoc Bs3PrintfV_c16 */
1120#define Bs3PrintfV BS3_CMN_NM(Bs3PrintfV) /**< Selects #Bs3PrintfV_c16, #Bs3PrintfV_c32 or #Bs3PrintfV_c64. */
1121
1122/**
1123 * Prints a string to the screen.
1124 *
1125 * @param pszString The string to print.
1126 */
1127BS3_DECL(void) Bs3PrintStr_c16(const char BS3_FAR *pszString);
1128BS3_DECL(void) Bs3PrintStr_c32(const char BS3_FAR *pszString); /**< @copydoc Bs3PrintStr_c16 */
1129BS3_DECL(void) Bs3PrintStr_c64(const char BS3_FAR *pszString); /**< @copydoc Bs3PrintStr_c16 */
1130#define Bs3PrintStr BS3_CMN_NM(Bs3PrintStr) /**< Selects #Bs3PrintStr_c16, #Bs3PrintStr_c32 or #Bs3PrintStr_c64. */
1131
1132/**
1133 * Prints a char to the screen.
1134 *
1135 * @param ch The character to print.
1136 */
1137BS3_DECL(void) Bs3PrintChr_c16(char ch);
1138BS3_DECL(void) Bs3PrintChr_c32(char ch); /**< @copydoc Bs3PrintChr_c16 */
1139BS3_DECL(void) Bs3PrintChr_c64(char ch); /**< @copydoc Bs3PrintChr_c16 */
1140#define Bs3PrintChr BS3_CMN_NM(Bs3PrintChr) /**< Selects #Bs3PrintChr_c16, #Bs3PrintChr_c32 or #Bs3PrintChr_c64. */
1141
1142
1143/**
1144 * An output function for #Bs3StrFormatV.
1145 *
1146 * @returns Number of characters written.
1147 * @param ch The character to write. Zero in the final call.
1148 * @param pvUser User argument supplied to #Bs3StrFormatV.
1149 */
1150typedef BS3_DECL_CALLBACK(size_t) FNBS3STRFORMATOUTPUT(char ch, void BS3_FAR *pvUser);
1151/** Pointer to an output function for #Bs3StrFormatV. */
1152typedef FNBS3STRFORMATOUTPUT *PFNBS3STRFORMATOUTPUT;
1153
1154/**
1155 * Formats a string, sending the output to @a pfnOutput.
1156 *
1157 * Supported types:
1158 * - %RI8, %RI16, %RI32, %RI64
1159 * - %RU8, %RU16, %RU32, %RU64
1160 * - %RX8, %RX16, %RX32, %RX64
1161 * - %i, %d
1162 * - %u
1163 * - %x
1164 * - %c
1165 * - %p (far pointer)
1166 * - %s (far pointer)
1167 *
1168 * @returns Sum of @a pfnOutput return values.
1169 * @param pszFormat The format string.
1170 * @param va Format arguments.
1171 * @param pfnOutput The output function.
1172 * @param pvUser The user argument for the output function.
1173 */
1174BS3_DECL(size_t) Bs3StrFormatV_c16(const char BS3_FAR *pszFormat, va_list va,
1175 PFNBS3STRFORMATOUTPUT pfnOutput, void BS3_FAR *pvUser);
1176/** @copydoc Bs3StrFormatV_c16 */
1177BS3_DECL(size_t) Bs3StrFormatV_c32(const char BS3_FAR *pszFormat, va_list va,
1178 PFNBS3STRFORMATOUTPUT pfnOutput, void BS3_FAR *pvUser);
1179/** @copydoc Bs3StrFormatV_c16 */
1180BS3_DECL(size_t) Bs3StrFormatV_c64(const char BS3_FAR *pszFormat, va_list va,
1181 PFNBS3STRFORMATOUTPUT pfnOutput, void BS3_FAR *pvUser);
1182#define Bs3StrFormatV BS3_CMN_NM(Bs3StrFormatV) /**< Selects #Bs3StrFormatV_c16, #Bs3StrFormatV_c32 or #Bs3StrFormatV_c64. */
1183
1184/**
1185 * Formats a string into a buffer.
1186 *
1187 * See #Bs3Format_c16 for supported format types.
1188 *
1189 * @returns The length of the formatted string (excluding terminator).
1190 * This will be higher or equal to @c cbBuf in case of an overflow.
1191 * @param pszBuf The output buffer.
1192 * @param cbBuf The size of the output buffer.
1193 * @param pszFormat The format string.
1194 * @param va Format arguments.
1195 */
1196BS3_DECL(size_t) Bs3StrPrintfV_c16(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, va_list va);
1197/** @copydoc Bs3StrPrintfV_c16 */
1198BS3_DECL(size_t) Bs3StrPrintfV_c32(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, va_list va);
1199/** @copydoc Bs3StrPrintfV_c16 */
1200BS3_DECL(size_t) Bs3StrPrintfV_c64(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, va_list va);
1201#define Bs3StrPrintfV BS3_CMN_NM(Bs3StrPrintfV) /**< Selects #Bs3StrPrintfV_c16, #Bs3StrPrintfV_c32 or #Bs3StrPrintfV_c64. */
1202
1203/**
1204 * Formats a string into a buffer.
1205 *
1206 * See #Bs3Format_c16 for supported format types.
1207 *
1208 * @returns The length of the formatted string (excluding terminator).
1209 * This will be higher or equal to @c cbBuf in case of an overflow.
1210 * @param pszBuf The output buffer.
1211 * @param cbBuf The size of the output buffer.
1212 * @param pszFormat The format string.
1213 * @param ... Format arguments.
1214 */
1215BS3_DECL(size_t) Bs3StrPrintf_c16(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, ...);
1216/** @copydoc Bs3StrPrintf_c16 */
1217BS3_DECL(size_t) Bs3StrPrintf_c32(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, ...);
1218/** @copydoc Bs3StrPrintf_c16 */
1219BS3_DECL(size_t) Bs3StrPrintf_c64(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, ...);
1220#define Bs3StrPrintf BS3_CMN_NM(Bs3StrPrintf) /**< Selects #Bs3StrPrintf_c16, #Bs3StrPrintf_c32 or #Bs3StrPrintf_c64. */
1221
1222
1223/**
1224 * Finds the length of a zero terminated string.
1225 *
1226 * @returns String length in chars/bytes.
1227 * @param pszString The string to examine.
1228 */
1229BS3_DECL(size_t) Bs3StrLen_c16(const char BS3_FAR *pszString);
1230BS3_DECL(size_t) Bs3StrLen_c32(const char BS3_FAR *pszString); /** @copydoc Bs3StrLen_c16 */
1231BS3_DECL(size_t) Bs3StrLen_c64(const char BS3_FAR *pszString); /** @copydoc Bs3StrLen_c16 */
1232#define Bs3StrLen BS3_CMN_NM(Bs3StrLen) /**< Selects #Bs3StrLen_c16, #Bs3StrLen_c32 or #Bs3StrLen_c64. */
1233
1234/**
1235 * Finds the length of a zero terminated string, but with a max length.
1236 *
1237 * @returns String length in chars/bytes, or @a cchMax if no zero-terminator
1238 * was found before we reached the limit.
1239 * @param pszString The string to examine.
1240 * @param cchMax The max length to examine.
1241 */
1242BS3_DECL(size_t) Bs3StrNLen_c16(const char BS3_FAR *pszString, size_t cchMax);
1243BS3_DECL(size_t) Bs3StrNLen_c32(const char BS3_FAR *pszString, size_t cchMax); /** @copydoc Bs3StrNLen_c16 */
1244BS3_DECL(size_t) Bs3StrNLen_c64(const char BS3_FAR *pszString, size_t cchMax); /** @copydoc Bs3StrNLen_c16 */
1245#define Bs3StrNLen BS3_CMN_NM(Bs3StrNLen) /**< Selects #Bs3StrNLen_c16, #Bs3StrNLen_c32 or #Bs3StrNLen_c64. */
1246
1247/**
1248 * CRT style unsafe strcpy.
1249 *
1250 * @returns pszDst.
1251 * @param pszDst The destination buffer. Must be large enough to
1252 * hold the source string.
1253 * @param pszSrc The source string.
1254 */
1255BS3_DECL(char BS3_FAR *) Bs3StrCpy_c16(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc);
1256BS3_DECL(char BS3_FAR *) Bs3StrCpy_c32(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc); /** @copydoc Bs3StrCpy_c16 */
1257BS3_DECL(char BS3_FAR *) Bs3StrCpy_c64(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc); /** @copydoc Bs3StrCpy_c16 */
1258#define Bs3StrCpy BS3_CMN_NM(Bs3StrCpy) /**< Selects #Bs3StrCpy_c16, #Bs3StrCpy_c32 or #Bs3StrCpy_c64. */
1259
1260/**
1261 * CRT style memcpy.
1262 *
1263 * @returns pvDst
1264 * @param pvDst The destination buffer.
1265 * @param pvSrc The source buffer.
1266 * @param cbCopy The number of bytes to copy.
1267 */
1268BS3_DECL(void BS3_FAR *) Bs3MemCpy_c16(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy);
1269BS3_DECL(void BS3_FAR *) Bs3MemCpy_c32(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemCpy_c16 */
1270BS3_DECL(void BS3_FAR *) Bs3MemCpy_c64(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemCpy_c16 */
1271#define Bs3MemCpy BS3_CMN_NM(Bs3MemCpy) /**< Selects #Bs3MemCpy_c16, #Bs3MemCpy_c32 or #Bs3MemCpy_c64. */
1272
1273/**
1274 * GNU (?) style mempcpy.
1275 *
1276 * @returns pvDst + cbCopy
1277 * @param pvDst The destination buffer.
1278 * @param pvSrc The source buffer.
1279 * @param cbCopy The number of bytes to copy.
1280 */
1281BS3_DECL(void BS3_FAR *) Bs3MemPCpy_c16(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy);
1282BS3_DECL(void BS3_FAR *) Bs3MemPCpy_c32(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemPCpy_c16 */
1283BS3_DECL(void BS3_FAR *) Bs3MemPCpy_c64(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemPCpy_c16 */
1284#define Bs3MemPCpy BS3_CMN_NM(Bs3MemPCpy) /**< Selects #Bs3MemPCpy_c16, #Bs3MemPCpy_c32 or #Bs3MemPCpy_c64. */
1285
1286/**
1287 * CRT style memmove (overlapping buffers is fine).
1288 *
1289 * @returns pvDst
1290 * @param pvDst The destination buffer.
1291 * @param pvSrc The source buffer.
1292 * @param cbCopy The number of bytes to copy.
1293 */
1294BS3_DECL(void BS3_FAR *) Bs3MemMove_c16(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy);
1295BS3_DECL(void BS3_FAR *) Bs3MemMove_c32(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemMove_c16 */
1296BS3_DECL(void BS3_FAR *) Bs3MemMove_c64(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemMove_c16 */
1297#define Bs3MemMove BS3_CMN_NM(Bs3MemMove) /**< Selects #Bs3MemMove_c16, #Bs3MemMove_c32 or #Bs3MemMove_c64. */
1298
1299/**
1300 * BSD style bzero.
1301 *
1302 * @param pvDst The buffer to be zeroed.
1303 * @param cbDst The number of bytes to zero.
1304 */
1305BS3_DECL(void) Bs3MemZero_c16(void BS3_FAR *pvDst, size_t cbDst);
1306BS3_DECL(void) Bs3MemZero_c32(void BS3_FAR *pvDst, size_t cbDst); /** @copydoc Bs3MemZero_c16 */
1307BS3_DECL(void) Bs3MemZero_c64(void BS3_FAR *pvDst, size_t cbDst); /** @copydoc Bs3MemZero_c16 */
1308#define Bs3MemZero BS3_CMN_NM(Bs3MemZero) /**< Selects #Bs3MemZero_c16, #Bs3MemZero_c32 or #Bs3MemZero_c64. */
1309
1310
1311/**
1312 * Converts a protected mode 32-bit far pointer to a 32-bit flat address.
1313 *
1314 * @returns 32-bit flat address.
1315 * @param off The segment offset.
1316 * @param uSel The protected mode segment selector.
1317 */
1318BS3_DECL(uint32_t) Bs3SelProtFar32ToFlat32_c16(uint32_t off, uint16_t uSel);
1319BS3_DECL(uint32_t) Bs3SelProtFar32ToFlat32_c32(uint32_t off, uint16_t uSel); /**< @copydoc Bs3SelProtFar32ToFlat32_c16 */
1320BS3_DECL(uint32_t) Bs3SelProtFar32ToFlat32_c64(uint32_t off, uint16_t uSel); /**< @copydoc Bs3SelProtFar32ToFlat32_c16 */
1321#define Bs3SelProtFar32ToFlat32 BS3_CMN_NM(Bs3SelProtFar32ToFlat32) /**< Selects #Bs3SelProtFar32ToFlat32_c16, #Bs3SelProtFar32ToFlat32_c32 or #Bs3SelProtFar32ToFlat32_c64. */
1322
1323
1324/**
1325 * Equivalent to RTTestCreate + RTTestBanner.
1326 *
1327 * @param pszTest The test name.
1328 */
1329BS3_DECL(void) Bs3TestInit_c16(const char BS3_FAR *pszTest);
1330BS3_DECL(void) Bs3TestInit_c32(const char BS3_FAR *pszTest); /**< @copydoc Bs3TestInit_c16 */
1331BS3_DECL(void) Bs3TestInit_c64(const char BS3_FAR *pszTest); /**< @copydoc Bs3TestInit_c16 */
1332#define Bs3TestInit BS3_CMN_NM(Bs3TestInit) /**< Selects #Bs3TestInit_c16, #Bs3TestInit_c32 or #Bs3TestInit_c64. */
1333
1334
1335/**
1336 * Equivalent to RTTestSummaryAndDestroy.
1337 */
1338BS3_DECL(void) Bs3TestTerm_c16(void);
1339BS3_DECL(void) Bs3TestTerm_c32(void); /**< @copydoc Bs3TestTerm_c16 */
1340BS3_DECL(void) Bs3TestTerm_c64(void); /**< @copydoc Bs3TestTerm_c16 */
1341#define Bs3TestTerm BS3_CMN_NM(Bs3TestTerm) /**< Selects #Bs3TestTerm_c16, #Bs3TestTerm_c32 or #Bs3TestTerm_c64. */
1342
1343/**
1344 * Equivalent to RTTestISub.
1345 */
1346BS3_DECL(void) Bs3TestSub_c16(const char BS3_FAR *pszSubTest);
1347BS3_DECL(void) Bs3TestSub_c32(const char BS3_FAR *pszSubTest); /**< @copydoc Bs3TestSub_c16 */
1348BS3_DECL(void) Bs3TestSub_c64(const char BS3_FAR *pszSubTest); /**< @copydoc Bs3TestSub_c16 */
1349#define Bs3TestSub BS3_CMN_NM(Bs3TestSub) /**< Selects #Bs3TestSub_c16, #Bs3TestSub_c32 or #Bs3TestSub_c64. */
1350
1351/**
1352 * Equivalent to RTTestIFailedF.
1353 */
1354BS3_DECL(void) Bs3TestSubF_c16(const char BS3_FAR *pszFormat, ...);
1355BS3_DECL(void) Bs3TestSubF_c32(const char BS3_FAR *pszFormat, ...); /**< @copydoc Bs3TestSubF_c16 */
1356BS3_DECL(void) Bs3TestSubF_c64(const char BS3_FAR *pszFormat, ...); /**< @copydoc Bs3TestSubF_c16 */
1357#define Bs3TestSubF BS3_CMN_NM(Bs3TestSubF) /**< Selects #Bs3TestSubF_c16, #Bs3TestSubF_c32 or #Bs3TestSubF_c64. */
1358
1359/**
1360 * Equivalent to RTTestISubV.
1361 */
1362BS3_DECL(void) Bs3TestSubV_c16(const char BS3_FAR *pszFormat, va_list va);
1363BS3_DECL(void) Bs3TestSubV_c32(const char BS3_FAR *pszFormat, va_list va); /**< @copydoc Bs3TestSubV_c16 */
1364BS3_DECL(void) Bs3TestSubV_c64(const char BS3_FAR *pszFormat, va_list va); /**< @copydoc Bs3TestSubV_c16 */
1365#define Bs3TestSubV BS3_CMN_NM(Bs3TestSubV) /**< Selects #Bs3TestSubV_c16, #Bs3TestSubV_c32 or #Bs3TestSubV_c64. */
1366
1367/**
1368 * Equivalent to RTTestISubDone.
1369 */
1370BS3_DECL(void) Bs3TestSubDone_c16(void);
1371BS3_DECL(void) Bs3TestSubDone_c32(void); /**< @copydoc Bs3TestSubDone_c16 */
1372BS3_DECL(void) Bs3TestSubDone_c64(void); /**< @copydoc Bs3TestSubDone_c16 */
1373#define Bs3TestSubDone BS3_CMN_NM(Bs3TestSubDone) /**< Selects #Bs3TestSubDone_c16, #Bs3TestSubDone_c32 or #Bs3TestSubDone_c64. */
1374
1375/**
1376 * Equivalent to RTTestSubErrorCount.
1377 */
1378BS3_DECL(uint16_t) Bs3TestSubErrorCount_c16(void);
1379BS3_DECL(uint16_t) Bs3TestSubErrorCount_c32(void); /**< @copydoc Bs3TestSubErrorCount_c16 */
1380BS3_DECL(uint16_t) Bs3TestSubErrorCount_c64(void); /**< @copydoc Bs3TestSubErrorCount_c16 */
1381#define Bs3TestSubErrorCount BS3_CMN_NM(Bs3TestSubErrorCount) /**< Selects #Bs3TestSubErrorCount_c16, #Bs3TestSubErrorCount_c32 or #Bs3TestSubErrorCount_c64. */
1382
1383/**
1384 * Equivalent to RTTestIFailed.
1385 */
1386BS3_DECL(void) Bs3TestFailed_c16(const char BS3_FAR *pszMessage);
1387BS3_DECL(void) Bs3TestFailed_c32(const char BS3_FAR *pszMessage); /**< @copydoc Bs3TestFailed_c16 */
1388BS3_DECL(void) Bs3TestFailed_c64(const char BS3_FAR *pszMessage); /**< @copydoc Bs3TestFailed_c16 */
1389#define Bs3TestFailed BS3_CMN_NM(Bs3TestFailed) /**< Selects #Bs3TestFailed_c16, #Bs3TestFailed_c32 or #Bs3TestFailed_c64. */
1390
1391/**
1392 * Equivalent to RTTestIFailedF.
1393 */
1394BS3_DECL(void) Bs3TestFailedF_c16(const char BS3_FAR *pszFormat, ...);
1395BS3_DECL(void) Bs3TestFailedF_c32(const char BS3_FAR *pszFormat, ...); /**< @copydoc Bs3TestFailedF_c16 */
1396BS3_DECL(void) Bs3TestFailedF_c64(const char BS3_FAR *pszFormat, ...); /**< @copydoc Bs3TestFailedF_c16 */
1397#define Bs3TestFailedF BS3_CMN_NM(Bs3TestFailedF) /**< Selects #Bs3TestFailedF_c16, #Bs3TestFailedF_c32 or #Bs3TestFailedF_c64. */
1398
1399/**
1400 * Equivalent to RTTestIFailedV.
1401 */
1402BS3_DECL(void) Bs3TestFailedV_c16(const char BS3_FAR *pszFormat, va_list va);
1403BS3_DECL(void) Bs3TestFailedV_c32(const char BS3_FAR *pszFormat, va_list va); /**< @copydoc Bs3TestFailedV_c16 */
1404BS3_DECL(void) Bs3TestFailedV_c64(const char BS3_FAR *pszFormat, va_list va); /**< @copydoc Bs3TestFailedV_c16 */
1405#define Bs3TestFailedV BS3_CMN_NM(Bs3TestFailedV) /**< Selects #Bs3TestFailedV_c16, #Bs3TestFailedV_c32 or #Bs3TestFailedV_c64. */
1406
1407/**
1408 * Equivalent to RTTestISkipped.
1409 *
1410 * @param pszWhy Optional reason why it's being skipped.
1411 */
1412BS3_DECL(void) Bs3TestSkipped_c16(const char BS3_FAR *pszWhy);
1413BS3_DECL(void) Bs3TestSkipped_c32(const char BS3_FAR *pszWhy); /**< @copydoc Bs3TestSkipped_c16 */
1414BS3_DECL(void) Bs3TestSkipped_c64(const char BS3_FAR *pszWhy); /**< @copydoc Bs3TestSkipped_c16 */
1415#define Bs3TestSkipped BS3_CMN_NM(Bs3TestSkipped) /**< Selects #Bs3TestSkipped_c16, #Bs3TestSkipped_c32 or #Bs3TestSkipped_c64. */
1416
1417/**
1418 * Equivalent to RTTestISkippedF.
1419 *
1420 * @param pszFormat Optional reason why it's being skipped.
1421 * @param ... Format arguments.
1422 */
1423BS3_DECL(void) Bs3TestSkippedF_c16(const char BS3_FAR *pszFormat, ...);
1424BS3_DECL(void) Bs3TestSkippedF_c32(const char BS3_FAR *pszFormat, ...); /**< @copydoc Bs3TestSkippedF_c16 */
1425BS3_DECL(void) Bs3TestSkippedF_c64(const char BS3_FAR *pszFormat, ...); /**< @copydoc Bs3TestSkippedF_c16 */
1426#define Bs3TestSkippedF BS3_CMN_NM(Bs3TestSkippedF) /**< Selects #Bs3TestSkippedF_c16, #Bs3TestSkippedF_c32 or #Bs3TestSkippedF_c64. */
1427
1428/**
1429 * Equivalent to RTTestISkippedV.
1430 *
1431 * @param pszFormat Optional reason why it's being skipped.
1432 * @param va Format arguments.
1433 */
1434BS3_DECL(void) Bs3TestSkippedV_c16(const char BS3_FAR *pszFormat, va_list va);
1435BS3_DECL(void) Bs3TestSkippedV_c32(const char BS3_FAR *pszFormat, va_list va); /**< @copydoc Bs3TestSkippedV_c16 */
1436BS3_DECL(void) Bs3TestSkippedV_c64(const char BS3_FAR *pszFormat, va_list va); /**< @copydoc Bs3TestSkippedV_c16 */
1437#define Bs3TestSkippedV BS3_CMN_NM(Bs3TestSkippedV) /**< Selects #Bs3TestSkippedV_c16, #Bs3TestSkippedV_c32 or #Bs3TestSkippedV_c64. */
1438
1439
1440/**
1441 * Performs the testing for the given mode.
1442 *
1443 * This is called with the CPU already switch to that mode.
1444 *
1445 * @returns 0 on success or directly Bs3TestFailed calls, non-zero to indicate
1446 * where the test when wrong.
1447 * @param bMode The current CPU mode.
1448 */
1449typedef BS3_DECL_CALLBACK(uint8_t) FNBS3TESTDOMODE(uint8_t bMode);
1450/** Near pointer to a test (for 16-bit code). */
1451typedef FNBS3TESTDOMODE *PFNBS3TESTDOMODE;
1452/** Far pointer to a test (for 32-bit and 64-bit code, will be flatten). */
1453typedef FNBS3TESTDOMODE BS3_FAR_CODE *FPFNBS3TESTDOMODE;
1454
1455/**
1456 * Mode sub-test entry.
1457 *
1458 * This can only be passed around to functions with the same bit count, as it
1459 * contains function pointers. In 16-bit mode, the 16-bit pointers are near and
1460 * implies BS3TEXT16, whereas the 32-bit and 64-bit pointers are far real mode
1461 * addresses that will be converted to flat address prior to calling them.
1462 * Similarly, in 32-bit and 64-bit the addresses are all flat and the 16-bit
1463 * ones will be converted to BS3TEXT16 based addresses prior to calling.
1464 */
1465typedef struct BS3TESTMODEENTRY
1466{
1467 const char * BS3_FAR pszSubTest;
1468
1469 PFNBS3TESTDOMODE pfnDoRM;
1470
1471 PFNBS3TESTDOMODE pfnDoPE16;
1472 FPFNBS3TESTDOMODE pfnDoPE16_32;
1473 PFNBS3TESTDOMODE pfnDoPE16_V86;
1474 FPFNBS3TESTDOMODE pfnDoPE32;
1475 PFNBS3TESTDOMODE pfnDoPE32_16;
1476 PFNBS3TESTDOMODE pfnDoPEV86;
1477
1478 PFNBS3TESTDOMODE pfnDoPP16;
1479 FPFNBS3TESTDOMODE pfnDoPP16_32;
1480 PFNBS3TESTDOMODE pfnDoPP16_V86;
1481 FPFNBS3TESTDOMODE pfnDoPP32;
1482 PFNBS3TESTDOMODE pfnDoPP32_16;
1483 PFNBS3TESTDOMODE pfnDoPPV86;
1484
1485 PFNBS3TESTDOMODE pfnDoPAE16;
1486 FPFNBS3TESTDOMODE pfnDoPAE16_32;
1487 PFNBS3TESTDOMODE pfnDoPAE16_V86;
1488 FPFNBS3TESTDOMODE pfnDoPAE32;
1489 PFNBS3TESTDOMODE pfnDoPAE32_16;
1490 PFNBS3TESTDOMODE pfnDoPAEV86;
1491
1492 PFNBS3TESTDOMODE pfnDoLM16;
1493 FPFNBS3TESTDOMODE pfnDoLM32;
1494 FPFNBS3TESTDOMODE pfnDoLM64;
1495
1496} BS3TESTMODEENTRY;
1497/** Pointer to a mode sub-test entry. */
1498typedef BS3TESTMODEENTRY const *PCBS3TESTMODEENTRY;
1499
1500
1501/**
1502 * Slab control structure list head.
1503 *
1504 * The slabs on the list must all have the same chunk size.
1505 */
1506typedef struct BS3SLABHEAD
1507{
1508 /** Pointer to the first slab. */
1509 BS3_XPTR_MEMBER(struct BS3SLABCTL, pFirst);
1510 /** The allocation chunk size. */
1511 uint16_t cbChunk;
1512 /** Number of slabs in the list. */
1513 uint16_t cSlabs;
1514 /** Number of chunks in the list. */
1515 uint32_t cChunks;
1516 /** Number of free chunks. */
1517 uint32_t cFreeChunks;
1518} BS3SLABHEAD;
1519/** Pointer to a slab list head. */
1520typedef BS3SLABHEAD BS3_FAR *PBS3SLABHEAD;
1521
1522/**
1523 * Allocation slab control structure.
1524 *
1525 * This may live at the start of the slab for 4KB slabs, while in a separate
1526 * static location for the larger ones.
1527 */
1528typedef struct BS3SLABCTL
1529{
1530 /** Pointer to the next slab control structure in this list. */
1531 BS3_XPTR_MEMBER(struct BS3SLABCTL, pNext);
1532 /** Pointer to the slab list head. */
1533 BS3_XPTR_MEMBER(BS3SLABHEAD, pHead);
1534 /** The base address of the slab. */
1535 BS3_XPTR_MEMBER(uint8_t, pbStart);
1536 /** Number of chunks in this slab. */
1537 uint16_t cChunks;
1538 /** Number of currently free chunks. */
1539 uint16_t cFreeChunks;
1540 /** The chunk size. */
1541 uint16_t cbChunk;
1542 /** The shift count corresponding to cbChunk.
1543 * This is for turning a chunk number into a byte offset and vice versa. */
1544 uint16_t cChunkShift;
1545 /** Bitmap where set bits indicates allocated blocks (variable size,
1546 * multiple of 4). */
1547 uint8_t bmAllocated[4];
1548} BS3SLABCTL;
1549/** Pointer to a bs3kit slab control structure. */
1550typedef BS3SLABCTL BS3_FAR *PBS3SLABCTL;
1551
1552/** The chunks must all be in the same 16-bit segment tile. */
1553#define BS3_SLAB_ALLOC_F_SAME_TILE UINT16_C(0x0001)
1554
1555/**
1556 * Initializes a slab.
1557 *
1558 * @param pSlabCtl The slab control structure to initialize.
1559 * @param cbSlabCtl The size of the slab control structure.
1560 * @param uFlatSlabPtr The base address of the slab.
1561 * @param cbSlab The size of the slab.
1562 * @param cbChunk The chunk size.
1563 */
1564BS3_DECL(void) Bs3SlabInit_c16(PBS3SLABCTL pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk);
1565/** @copydoc Bs3SlabInit_c16 */
1566BS3_DECL(void) Bs3SlabInit_c32(PBS3SLABCTL pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk);
1567/** @copydoc Bs3SlabInit_c16 */
1568BS3_DECL(void) Bs3SlabInit_c64(PBS3SLABCTL pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk);
1569#define Bs3SlabInit BS3_CMN_NM(Bs3SlabInit) /**< Selects #Bs3SlabInit_c16, #Bs3SlabInit_c32 or #Bs3SlabInit_c64. */
1570
1571/**
1572 * Allocates one chunk from a slab.
1573 *
1574 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
1575 * @param pSlabCtl The slab constrol structure to allocate from.
1576 */
1577BS3_DECL(void BS3_FAR *) Bs3SlabAlloc_c16(PBS3SLABCTL pSlabCtl);
1578BS3_DECL(void BS3_FAR *) Bs3SlabAlloc_c32(PBS3SLABCTL pSlabCtl); /**< @copydoc Bs3SlabAlloc_c16 */
1579BS3_DECL(void BS3_FAR *) Bs3SlabAlloc_c64(PBS3SLABCTL pSlabCtl); /**< @copydoc Bs3SlabAlloc_c16 */
1580#define Bs3SlabAlloc BS3_CMN_NM(Bs3SlabAlloc) /**< Selects #Bs3SlabAlloc_c16, #Bs3SlabAlloc_c32 or #Bs3SlabAlloc_c64. */
1581
1582/**
1583 * Allocates one or more chunks rom a slab.
1584 *
1585 * @returns Pointer to the request number of chunks on success, NULL if we're
1586 * out of chunks.
1587 * @param pSlabCtl The slab constrol structure to allocate from.
1588 * @param cChunks The number of contiguous chunks we want.
1589 * @param fFlags Flags, see BS3_SLAB_ALLOC_F_XXX
1590 */
1591BS3_DECL(void BS3_FAR *) Bs3SlabAllocEx_c16(PBS3SLABCTL pSlabCtl, uint16_t cChunks, uint16_t fFlags);
1592BS3_DECL(void BS3_FAR *) Bs3SlabAllocEx_c32(PBS3SLABCTL pSlabCtl, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabAllocEx_c16 */
1593BS3_DECL(void BS3_FAR *) Bs3SlabAllocEx_c64(PBS3SLABCTL pSlabCtl, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabAllocEx_c16 */
1594#define Bs3SlabAllocEx BS3_CMN_NM(Bs3SlabAllocEx) /**< Selects #Bs3SlabAllocEx_c16, #Bs3SlabAllocEx_c32 or #Bs3SlabAllocEx_c64. */
1595
1596/**
1597 * Frees one or more chunks from a slab.
1598 *
1599 * @returns Number of chunks actually freed. When correctly used, this will
1600 * match the @a cChunks parameter, of course.
1601 * @param pSlabCtl The slab constrol structure to free from.
1602 * @param uFlatChunkPtr The flat address of the chunks to free.
1603 * @param cChunks The number of contiguous chunks to free.
1604 */
1605BS3_DECL(uint16_t) Bs3SlabFree_c16(PBS3SLABCTL pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks);
1606BS3_DECL(uint16_t) Bs3SlabFree_c32(PBS3SLABCTL pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks); /**< @copydoc Bs3SlabFree_c16 */
1607BS3_DECL(uint16_t) Bs3SlabFree_c64(PBS3SLABCTL pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks); /**< @copydoc Bs3SlabFree_c16 */
1608#define Bs3SlabFree BS3_CMN_NM(Bs3SlabFree) /**< Selects #Bs3SlabFree_c16, #Bs3SlabFree_c32 or #Bs3SlabFree_c64. */
1609
1610
1611/**
1612 * Initializes the given slab list head.
1613 *
1614 * @param pHead The slab list head.
1615 * @param cbChunk The chunk size.
1616 */
1617BS3_DECL(void) Bs3SlabListInit_c16(PBS3SLABHEAD pHead, uint16_t cbChunk);
1618BS3_DECL(void) Bs3SlabListInit_c32(PBS3SLABHEAD pHead, uint16_t cbChunk); /**< @copydoc Bs3SlabListInit_c16 */
1619BS3_DECL(void) Bs3SlabListInit_c64(PBS3SLABHEAD pHead, uint16_t cbChunk); /**< @copydoc Bs3SlabListInit_c16 */
1620#define Bs3SlabListInit BS3_CMN_NM(Bs3SlabListInit) /**< Selects #Bs3SlabListInit_c16, #Bs3SlabListInit_c32 or #Bs3SlabListInit_c64. */
1621
1622/**
1623 * Adds an initialized slab control structure to the list.
1624 *
1625 * @param pHead The slab list head to add it to.
1626 * @param pSlabCtl The slab control structure to add.
1627 */
1628BS3_DECL(void) Bs3SlabListAdd_c16(PBS3SLABHEAD pHead, PBS3SLABCTL pSlabCtl);
1629/** @copydoc Bs3SlabListAdd_c16 */
1630BS3_DECL(void) Bs3SlabListAdd_c32(PBS3SLABHEAD pHead, PBS3SLABCTL pSlabCtl);
1631/** @copydoc Bs3SlabListAdd_c16 */
1632BS3_DECL(void) Bs3SlabListAdd_c64(PBS3SLABHEAD pHead, PBS3SLABCTL pSlabCtl);
1633#define Bs3SlabListAdd BS3_CMN_NM(Bs3SlabListAdd) /**< Selects #Bs3SlabListAdd_c16, #Bs3SlabListAdd_c32 or #Bs3SlabListAdd_c64. */
1634
1635/**
1636 * Allocates one chunk.
1637 *
1638 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
1639 * @param pHead The slab list to allocate from.
1640 */
1641BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c16(PBS3SLABHEAD pHead);
1642BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c32(PBS3SLABHEAD pHead); /**< @copydoc Bs3SlabListAlloc_c16 */
1643BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c64(PBS3SLABHEAD pHead); /**< @copydoc Bs3SlabListAlloc_c16 */
1644#define Bs3SlabListAlloc BS3_CMN_NM(Bs3SlabListAlloc) /**< Selects #Bs3SlabListAlloc_c16, #Bs3SlabListAlloc_c32 or #Bs3SlabListAlloc_c64. */
1645
1646/**
1647 * Allocates one or more chunks.
1648 *
1649 * @returns Pointer to the request number of chunks on success, NULL if we're
1650 * out of chunks.
1651 * @param pHead The slab list to allocate from.
1652 * @param cChunks The number of contiguous chunks we want.
1653 * @param fFlags Flags, see BS3_SLAB_ALLOC_F_XXX
1654 */
1655BS3_DECL(void BS3_FAR *) Bs3SlabListAllocEx_c16(PBS3SLABHEAD pHead, uint16_t cChunks, uint16_t fFlags);
1656BS3_DECL(void BS3_FAR *) Bs3SlabListAllocEx_c32(PBS3SLABHEAD pHead, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabListAllocEx_c16 */
1657BS3_DECL(void BS3_FAR *) Bs3SlabListAllocEx_c64(PBS3SLABHEAD pHead, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabListAllocEx_c16 */
1658#define Bs3SlabListAllocEx BS3_CMN_NM(Bs3SlabListAllocEx) /**< Selects #Bs3SlabListAllocEx_c16, #Bs3SlabListAllocEx_c32 or #Bs3SlabListAllocEx_c64. */
1659
1660/**
1661 * Frees one or more chunks from a slab list.
1662 *
1663 * @param pHead The slab list to allocate from.
1664 * @param pvChunks Pointer to the first chunk to free.
1665 * @param cChunks The number of contiguous chunks to free.
1666 */
1667BS3_DECL(void) Bs3SlabListFree_c16(PBS3SLABHEAD pHead, void BS3_FAR *pvChunks, uint16_t cChunks);
1668BS3_DECL(void) Bs3SlabListFree_c32(PBS3SLABHEAD pHead, void BS3_FAR *pvChunks, uint16_t cChunks); /**< @copydoc Bs3SlabListFree_c16 */
1669BS3_DECL(void) Bs3SlabListFree_c64(PBS3SLABHEAD pHead, void BS3_FAR *pvChunks, uint16_t cChunks); /**< @copydoc Bs3SlabListFree_c16 */
1670#define Bs3SlabListFree BS3_CMN_NM(Bs3SlabListFree) /**< Selects #Bs3SlabListFree_c16, #Bs3SlabListFree_c32 or #Bs3SlabListFree_c64. */
1671
1672/**
1673 * Allocation addressing constraints.
1674 */
1675typedef enum BS3MEMKIND
1676{
1677 /** Invalid zero type. */
1678 BS3MEMKIND_INVALID = 0,
1679 /** Real mode addressable memory. */
1680 BS3MEMKIND_REAL,
1681 /** Memory addressable using the 16-bit protected mode tiling. */
1682 BS3MEMKIND_TILED,
1683 /** Memory addressable using 32-bit flat addressing. */
1684 BS3MEMKIND_FLAT32,
1685 /** Memory addressable using 64-bit flat addressing. */
1686 BS3MEMKIND_FLAT64,
1687 /** End of valid types. */
1688 BS3MEMKIND_END,
1689} BS3MEMKIND;
1690
1691/**
1692 * Allocates low memory.
1693 *
1694 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
1695 * @param enmKind The kind of addressing constraints imposed on the
1696 * allocation.
1697 * @param cb How much to allocate. Must be 4KB or less.
1698 */
1699BS3_DECL(void BS3_FAR *) Bs3MemAlloc_c16(BS3MEMKIND enmKind, size_t cb);
1700BS3_DECL(void BS3_FAR *) Bs3MemAlloc_c32(BS3MEMKIND enmKind, size_t cb); /**< @copydoc Bs3MemAlloc_c16 */
1701BS3_DECL(void BS3_FAR *) Bs3MemAlloc_c64(BS3MEMKIND enmKind, size_t cb); /**< @copydoc Bs3MemAlloc_c16 */
1702#define Bs3MemAlloc BS3_CMN_NM(Bs3MemAlloc) /**< Selects #Bs3MemAlloc_c16, #Bs3MemAlloc_c32 or #Bs3MemAlloc_c64. */
1703
1704/**
1705 * Allocates zero'ed memory.
1706 *
1707 * @param enmKind The kind of addressing constraints imposed on the
1708 * allocation.
1709 * @param cb How much to allocate. Must be 4KB or less.
1710 */
1711BS3_DECL(void BS3_FAR *) Bs3MemAllocZ_c16(BS3MEMKIND enmKind, size_t cb);
1712BS3_DECL(void BS3_FAR *) Bs3MemAllocZ_c32(BS3MEMKIND enmKind, size_t cb); /**< @copydoc Bs3MemAllocZ_c16 */
1713BS3_DECL(void BS3_FAR *) Bs3MemAllocZ_c64(BS3MEMKIND enmKind, size_t cb); /**< @copydoc Bs3MemAllocZ_c16 */
1714#define Bs3MemAllocZ BS3_CMN_NM(Bs3MemAllocZ) /**< Selects #Bs3MemAllocZ_c16, #Bs3MemAllocZ_c32 or #Bs3MemAllocZ_c64. */
1715
1716/**
1717 * Frees memory.
1718 *
1719 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
1720 * @param pv The memory to free (returned by #Bs3MemAlloc).
1721 * @param cb The size of the allocation.
1722 */
1723BS3_DECL(void) Bs3MemFree_c16(void BS3_FAR *pv, size_t cb);
1724BS3_DECL(void) Bs3MemFree_c32(void BS3_FAR *pv, size_t cb); /**< @copydoc Bs3MemFree_c16 */
1725BS3_DECL(void) Bs3MemFree_c64(void BS3_FAR *pv, size_t cb); /**< @copydoc Bs3MemFree_c16 */
1726#define Bs3MemFree BS3_CMN_NM(Bs3MemFree) /**< Selects #Bs3MemFree_c16, #Bs3MemFree_c32 or #Bs3MemFree_c64. */
1727
1728
1729/**
1730 * Enables the A20 gate.
1731 */
1732BS3_DECL(void) Bs3A20Enable_c16(void);
1733BS3_DECL(void) Bs3A20Enable_c32(void); /**< @copydoc Bs3A20Enable_c16 */
1734BS3_DECL(void) Bs3A20Enable_c64(void); /**< @copydoc Bs3A20Enable_c16 */
1735#define Bs3A20Enable BS3_CMN_NM(Bs3A20Enable) /**< Selects #Bs3A20Enable_c16, #Bs3A20Enable_c32 or #Bs3A20Enable_c64. */
1736
1737/**
1738 * Enables the A20 gate via the keyboard controller
1739 */
1740BS3_DECL(void) Bs3A20EnableViaKbd_c16(void);
1741BS3_DECL(void) Bs3A20EnableViaKbd_c32(void); /**< @copydoc Bs3A20EnableViaKbd_c16 */
1742BS3_DECL(void) Bs3A20EnableViaKbd_c64(void); /**< @copydoc Bs3A20EnableViaKbd_c16 */
1743#define Bs3A20EnableViaKbd BS3_CMN_NM(Bs3A20EnableViaKbd) /**< Selects #Bs3A20EnableViaKbd_c16, #Bs3A20EnableViaKbd_c32 or #Bs3A20EnableViaKbd_c64. */
1744
1745/**
1746 * Enables the A20 gate via the PS/2 control port A.
1747 */
1748BS3_DECL(void) Bs3A20EnableViaPortA_c16(void);
1749BS3_DECL(void) Bs3A20EnableViaPortA_c32(void); /**< @copydoc Bs3A20EnableViaPortA_c16 */
1750BS3_DECL(void) Bs3A20EnableViaPortA_c64(void); /**< @copydoc Bs3A20EnableViaPortA_c16 */
1751#define Bs3A20EnableViaPortA BS3_CMN_NM(Bs3A20EnableViaPortA) /**< Selects #Bs3A20EnableViaPortA_c16, #Bs3A20EnableViaPortA_c32 or #Bs3A20EnableViaPortA_c64. */
1752
1753/**
1754 * Disables the A20 gate.
1755 */
1756BS3_DECL(void) Bs3A20Disable_c16(void);
1757BS3_DECL(void) Bs3A20Disable_c32(void); /**< @copydoc Bs3A20Disable_c16 */
1758BS3_DECL(void) Bs3A20Disable_c64(void); /**< @copydoc Bs3A20Disable_c16 */
1759#define Bs3A20Disable BS3_CMN_NM(Bs3A20Disable) /**< Selects #Bs3A20Disable_c16, #Bs3A20Disable_c32 or #Bs3A20Disable_c64. */
1760
1761/**
1762 * Disables the A20 gate via the keyboard controller
1763 */
1764BS3_DECL(void) Bs3A20DisableViaKbd_c16(void);
1765BS3_DECL(void) Bs3A20DisableViaKbd_c32(void); /**< @copydoc Bs3A20DisableViaKbd_c16 */
1766BS3_DECL(void) Bs3A20DisableViaKbd_c64(void); /**< @copydoc Bs3A20DisableViaKbd_c16 */
1767#define Bs3A20DisableViaKbd BS3_CMN_NM(Bs3A20DisableViaKbd) /**< Selects #Bs3A20DisableViaKbd_c16, #Bs3A20DisableViaKbd_c32 or #Bs3A20DisableViaKbd_c64. */
1768
1769/**
1770 * Disables the A20 gate via the PS/2 control port A.
1771 */
1772BS3_DECL(void) Bs3A20DisableViaPortA_c16(void);
1773BS3_DECL(void) Bs3A20DisableViaPortA_c32(void); /**< @copydoc Bs3A20DisableViaPortA_c16 */
1774BS3_DECL(void) Bs3A20DisableViaPortA_c64(void); /**< @copydoc Bs3A20DisableViaPortA_c16 */
1775#define Bs3A20DisableViaPortA BS3_CMN_NM(Bs3A20DisableViaPortA) /**< Selects #Bs3A20DisableViaPortA_c16, #Bs3A20DisableViaPortA_c32 or #Bs3A20DisableViaPortA_c64. */
1776
1777
1778/**
1779 * Initializes root page tables for page protected mode (PP16, PP32).
1780 *
1781 * @returns IPRT status code.
1782 * @remarks Must not be called in real-mode!
1783 */
1784BS3_DECL(int) Bs3PagingInitRootForPP_c16(void);
1785BS3_DECL(int) Bs3PagingInitRootForPP_c32(void); /**< @copydoc Bs3PagingInitRootForPP_c16 */
1786BS3_DECL(int) Bs3PagingInitRootForPP_c64(void); /**< @copydoc Bs3PagingInitRootForPP_c16 */
1787#define Bs3PagingInitRootForPP BS3_CMN_NM(Bs3PagingInitRootForPP) /**< Selects #Bs3PagingInitRootForPP_c16, #Bs3PagingInitRootForPP_c32 or #Bs3PagingInitRootForPP_c64. */
1788
1789/**
1790 * Initializes root page tables for PAE page protected mode (PAE16, PAE32).
1791 *
1792 * @returns IPRT status code.
1793 * @remarks The default long mode page tables depends on the PAE ones.
1794 * @remarks Must not be called in real-mode!
1795 */
1796BS3_DECL(int) Bs3PagingInitRootForPAE_c16(void);
1797BS3_DECL(int) Bs3PagingInitRootForPAE_c32(void); /**< @copydoc Bs3PagingInitRootForPAE_c16 */
1798BS3_DECL(int) Bs3PagingInitRootForPAE_c64(void); /**< @copydoc Bs3PagingInitRootForPAE_c16 */
1799#define Bs3PagingInitRootForPAE BS3_CMN_NM(Bs3PagingInitRootForPAE) /**< Selects #Bs3PagingInitRootForPAE_c16, #Bs3PagingInitRootForPAE_c32 or #Bs3PagingInitRootForPAE_c64. */
1800
1801/**
1802 * Initializes root page tables for long mode (LM16, LM32, LM64).
1803 *
1804 * @returns IPRT status code.
1805 * @remarks The default long mode page tables depends on the PAE ones.
1806 * @remarks Must not be called in real-mode!
1807 */
1808BS3_DECL(int) Bs3PagingInitRootForLM_c16(void);
1809BS3_DECL(int) Bs3PagingInitRootForLM_c32(void); /**< @copydoc Bs3PagingInitRootForLM_c16 */
1810BS3_DECL(int) Bs3PagingInitRootForLM_c64(void); /**< @copydoc Bs3PagingInitRootForLM_c16 */
1811#define Bs3PagingInitRootForLM BS3_CMN_NM(Bs3PagingInitRootForLM) /**< Selects #Bs3PagingInitRootForLM_c16, #Bs3PagingInitRootForLM_c32 or #Bs3PagingInitRootForLM_c64. */
1812
1813
1814/**
1815 * Waits for the keyboard controller to become ready.
1816 */
1817BS3_DECL(void) Bs3KbdWait_c16(void);
1818BS3_DECL(void) Bs3KbdWait_c32(void); /**< @copydoc Bs3KbdWait_c16 */
1819BS3_DECL(void) Bs3KbdWait_c64(void); /**< @copydoc Bs3KbdWait_c16 */
1820#define Bs3KbdWait BS3_CMN_NM(Bs3KbdWait) /**< Selects #Bs3KbdWait_c16, #Bs3KbdWait_c32 or #Bs3KbdWait_c64. */
1821
1822/**
1823 * Sends a read command to the keyboard controller and gets the result.
1824 *
1825 * The caller is responsible for making sure the keyboard controller is ready
1826 * for a command (call #Bs3KbdWait if unsure).
1827 *
1828 * @returns The value read is returned (in al).
1829 * @param bCmd The read command.
1830 */
1831BS3_DECL(uint8_t) Bs3KbdRead_c16(uint8_t bCmd);
1832BS3_DECL(uint8_t) Bs3KbdRead_c32(uint8_t bCmd); /**< @copydoc Bs3KbdRead_c16 */
1833BS3_DECL(uint8_t) Bs3KbdRead_c64(uint8_t bCmd); /**< @copydoc Bs3KbdRead_c16 */
1834#define Bs3KbdRead BS3_CMN_NM(Bs3KbdRead) /**< Selects #Bs3KbdRead_c16, #Bs3KbdRead_c32 or #Bs3KbdRead_c64. */
1835
1836/**
1837 * Sends a write command to the keyboard controller and then sends the data.
1838 *
1839 * The caller is responsible for making sure the keyboard controller is ready
1840 * for a command (call #Bs3KbdWait if unsure).
1841 *
1842 * @param bCmd The write command.
1843 * @param bData The data to write.
1844 */
1845BS3_DECL(void) Bs3KbdWrite_c16(uint8_t bCmd, uint8_t bData);
1846BS3_DECL(void) Bs3KbdWrite_c32(uint8_t bCmd, uint8_t bData); /**< @copydoc Bs3KbdWrite_c16 */
1847BS3_DECL(void) Bs3KbdWrite_c64(uint8_t bCmd, uint8_t bData); /**< @copydoc Bs3KbdWrite_c16 */
1848#define Bs3KbdWrite BS3_CMN_NM(Bs3KbdWrite) /**< Selects #Bs3KbdWrite_c16, #Bs3KbdWrite_c32 or #Bs3KbdWrite_c64. */
1849
1850
1851/**
1852 * BS3 integer register.
1853 */
1854typedef union BS3REG
1855{
1856 /** 8-bit unsigned integer. */
1857 uint8_t u8;
1858 /** 16-bit unsigned integer. */
1859 uint16_t u16;
1860 /** 32-bit unsigned integer. */
1861 uint32_t u32;
1862 /** 64-bit unsigned integer. */
1863 uint64_t u64;
1864 /** Full unsigned integer. */
1865 uint64_t u;
1866 /** High/low byte view. */
1867 struct
1868 {
1869 uint8_t bLo;
1870 uint8_t bHi;
1871 } b;
1872 /** 8-bit view. */
1873 uint8_t au8[8];
1874 /** 16-bit view. */
1875 uint16_t au16[4];
1876 /** 32-bit view. */
1877 uint32_t au32[2];
1878} BS3REG;
1879/** Pointer to an integer register. */
1880typedef BS3REG BS3_FAR *PBS3REG;
1881/** Pointer to a const integer register. */
1882typedef BS3REG const BS3_FAR *PCBS3REG;
1883
1884/**
1885 * Register context (without FPU).
1886 */
1887typedef struct BS3REGCTX
1888{
1889 BS3REG rax;
1890 BS3REG rcx;
1891 BS3REG rdx;
1892 BS3REG rbx;
1893 BS3REG rsp;
1894 BS3REG rbp;
1895 BS3REG rsi;
1896 BS3REG rdi;
1897 BS3REG r8;
1898 BS3REG r9;
1899 BS3REG r10;
1900 BS3REG r11;
1901 BS3REG r12;
1902 BS3REG r13;
1903 BS3REG r14;
1904 BS3REG r15;
1905 BS3REG rflags;
1906 BS3REG rip;
1907 uint16_t cs;
1908 uint16_t ds;
1909 uint16_t es;
1910 uint16_t fs;
1911 uint16_t gs;
1912 uint16_t ss;
1913 uint16_t tr;
1914 uint16_t ldtr;
1915 uint8_t cBits;
1916 uint8_t abPadding[7];
1917 BS3REG cr0;
1918 BS3REG cr2;
1919 BS3REG cr3;
1920 BS3REG cr4;
1921} BS3REGCTX;
1922/** Pointer to a register context. */
1923typedef BS3REGCTX BS3_FAR *PBS3REGCTX;
1924/** Pointer to a const register context. */
1925typedef BS3REGCTX const BS3_FAR *PCBS3REGCTX;
1926
1927
1928/**
1929 * Trap frame.
1930 */
1931typedef struct BS3TRAPFRAME
1932{
1933 /** Exception/interrupt number. */
1934 uint8_t bXcpt;
1935 /** Explicit alignment. */
1936 uint8_t bAlignment;
1937 /** The handler CS. */
1938 uint16_t uHandlerCc;
1939 /** The handler SS. */
1940 uint16_t uHandlerSs;
1941 /** The handler RSP (top of iret frame). */
1942 uint64_t uHandlerRsp;
1943 /** The handler RFLAGS value. */
1944 uint64_t fHandlerRfl;
1945 /** The error code (if applicable). */
1946 uint64_t uErrCd;
1947 /** The register context. */
1948 BS3REGCTX Ctx;
1949} BS3TRAPFRAME;
1950/** Pointer to a trap frame. */
1951typedef BS3TRAPFRAME BS3_FAR *PBS3TRAPFRAME;
1952/** Pointer to a const trap frame. */
1953typedef BS3TRAPFRAME const BS3_FAR *PCBS3TRAPFRAME;
1954
1955/**
1956 * Resumes execution of a 32-bit trap frame.
1957 *
1958 * @param pTrapFrame Trap frame to resume.
1959 * @param fFlags Flags, BS3TRAPRESUME_F_XXX.
1960 */
1961BS3_DECL(void) Bs3Trap32ResumeFrame_c32(BS3TRAPFRAME BS3_FAR *pTrapFrame, uint16_t fFlags);
1962#define Bs3Trap32ResumeFrame BS3_CMN_NM(Bs3Trap32ResumeFrame) /**< Selects Bs3Trap32ResumeFrame_c16 (not implemented), #Bs3Trap32ResumeFrame_c32 or Bs3Trap32ResumeFrame_c64 (not implemented). */
1963
1964/** Skip restoring the CRx registers. */
1965#define BS3TRAPRESUME_F_SKIP_CRX UINT16_C(0x0001)
1966
1967/**
1968 * Initializes 16-bit (protected mode) trap handling.
1969 *
1970 * @remarks Does not install 16-bit trap handling, just initializes the
1971 * structures.
1972 */
1973BS3_DECL(void) Bs3Trap16Init_c16(void);
1974BS3_DECL(void) Bs3Trap16Init_c32(void); /**< @copydoc Bs3Trap16Init_c16 */
1975BS3_DECL(void) Bs3Trap16Init_c64(void); /**< @copydoc Bs3Trap16Init_c16 */
1976#define Bs3Trap16Init BS3_CMN_NM(Bs3Trap16Init) /**< Selects #Bs3Trap16Init_c16, #Bs3Trap16Init_c32 or #Bs3Trap16Init_c64. */
1977
1978/**
1979 * Initializes 32-bit trap handling.
1980 *
1981 * @remarks Does not install 32-bit trap handling, just initializes the
1982 * structures.
1983 */
1984BS3_DECL(void) Bs3Trap32Init_c16(void);
1985BS3_DECL(void) Bs3Trap32Init_c32(void); /**< @copydoc Bs3Trap32Init_c16 */
1986BS3_DECL(void) Bs3Trap32Init_c64(void); /**< @copydoc Bs3Trap32Init_c16 */
1987#define Bs3Trap32Init BS3_CMN_NM(Bs3Trap32Init) /**< Selects #Bs3Trap32Init_c16, #Bs3Trap32Init_c32 or #Bs3Trap32Init_c64. */
1988
1989/**
1990 * Initializes 64-bit trap handling
1991 *
1992 * @remarks Does not install 64-bit trap handling, just initializes the
1993 * structures.
1994 */
1995BS3_DECL(void) Bs3Trap64Init_c16(void);
1996BS3_DECL(void) Bs3Trap64Init_c32(void); /**< @copydoc Bs3Trap64Init_c16 */
1997BS3_DECL(void) Bs3Trap64Init_c64(void); /**< @copydoc Bs3Trap64Init_c16 */
1998#define Bs3Trap64Init BS3_CMN_NM(Bs3Trap64Init) /**< Selects #Bs3Trap64Init_c16, #Bs3Trap64Init_c32 or #Bs3Trap64Init_c64. */
1999
2000/**
2001 * Modifies the 16-bit IDT entry (protected mode) specified by @a iIdt.
2002 *
2003 * @param iIdt The index of the IDT entry to set.
2004 * @param bType The gate type (X86_SEL_TYPE_SYS_XXX).
2005 * @param bDpl The DPL.
2006 * @param uSel The handler selector.
2007 * @param off The handler offset (if applicable).
2008 * @param cParams The parameter count (for call gates).
2009 */
2010BS3_DECL(void) Bs3Trap16SetGate_c16(uint8_t iIdt, uint8_t bType, uint8_t bDpl, uint16_t uSel, uint16_t off, uint8_t cParams);
2011BS3_DECL(void) Bs3Trap16SetGate_c32(uint8_t iIdt, uint8_t bType, uint8_t bDpl, uint16_t uSel, uint16_t off, uint8_t cParams); /**< @copydoc Bs3Trap16SetGate_c16 */
2012BS3_DECL(void) Bs3Trap16SetGate_c64(uint8_t iIdt, uint8_t bType, uint8_t bDpl, uint16_t uSel, uint16_t off, uint8_t cParams); /**< @copydoc Bs3Trap16SetGate_c16 */
2013#define Bs3Trap16SetGate BS3_CMN_NM(Bs3Trap16SetGate) /**< Selects #Bs3Trap16SetGate_c16, #Bs3Trap16SetGate_c32 or #Bs3Trap16SetGate_c64. */
2014
2015/** The address of Bs3Trap16GenericEntries.
2016 * Bs3Trap16GenericEntries is an array of interrupt/trap/whatever entry
2017 * points, 8 bytes each, that will create a register frame and call the generic
2018 * C compatible trap handlers. */
2019extern uint32_t BS3_DATA_NM(g_Bs3Trap16GenericEntriesFlatAddr);
2020
2021/**
2022 * Modifies the 32-bit IDT entry specified by @a iIdt.
2023 *
2024 * @param iIdt The index of the IDT entry to set.
2025 * @param bType The gate type (X86_SEL_TYPE_SYS_XXX).
2026 * @param bDpl The DPL.
2027 * @param uSel The handler selector.
2028 * @param off The handler offset (if applicable).
2029 * @param cParams The parameter count (for call gates).
2030 */
2031BS3_DECL(void) Bs3Trap32SetGate_c16(uint8_t iIdt, uint8_t bType, uint8_t bDpl, uint16_t uSel, uint32_t off, uint8_t cParams);
2032BS3_DECL(void) Bs3Trap32SetGate_c32(uint8_t iIdt, uint8_t bType, uint8_t bDpl, uint16_t uSel, uint32_t off, uint8_t cParams); /**< @copydoc Bs3Trap32SetGate_c16 */
2033BS3_DECL(void) Bs3Trap32SetGate_c64(uint8_t iIdt, uint8_t bType, uint8_t bDpl, uint16_t uSel, uint32_t off, uint8_t cParams); /**< @copydoc Bs3Trap32SetGate_c16 */
2034#define Bs3Trap32SetGate BS3_CMN_NM(Bs3Trap32SetGate) /**< Selects #Bs3Trap32SetGate_c16, #Bs3Trap32SetGate_c32 or #Bs3Trap32SetGate_c64. */
2035
2036/** The address of Bs3Trap32GenericEntries.
2037 * Bs3Trap32GenericEntries is an array of interrupt/trap/whatever entry
2038 * points, 8 bytes each, that will create a register frame and call the generic
2039 * C compatible trap handlers. */
2040extern uint32_t BS3_DATA_NM(g_Bs3Trap32GenericEntriesFlatAddr);
2041
2042/**
2043 * Modifies the 64-bit IDT entry specified by @a iIdt.
2044 *
2045 * @param iIdt The index of the IDT entry to set.
2046 * @param bType The gate type (X86_SEL_TYPE_SYS_XXX).
2047 * @param bDpl The DPL.
2048 * @param uSel The handler selector.
2049 * @param off The handler offset (if applicable).
2050 * @param bIst The interrupt stack to use.
2051 */
2052BS3_DECL(void) Bs3Trap64SetGate_c16(uint8_t iIdt, uint8_t bType, uint8_t bDpl, uint16_t uSel, uint64_t off, uint8_t bIst);
2053BS3_DECL(void) Bs3Trap64SetGate_c32(uint8_t iIdt, uint8_t bType, uint8_t bDpl, uint16_t uSel, uint64_t off, uint8_t bIst); /**< @copydoc Bs3Trap64SetGate_c16 */
2054BS3_DECL(void) Bs3Trap64SetGate_c64(uint8_t iIdt, uint8_t bType, uint8_t bDpl, uint16_t uSel, uint64_t off, uint8_t bIst); /**< @copydoc Bs3Trap64SetGate_c16 */
2055#define Bs3Trap64SetGate BS3_CMN_NM(Bs3Trap64SetGate) /**< Selects #Bs3Trap64SetGate_c16, #Bs3Trap64SetGate_c32 or #Bs3Trap64SetGate_c64. */
2056
2057/** The address of Bs3Trap64GenericEntries.
2058 * Bs3Trap64GenericEntries is an array of interrupt/trap/whatever entry
2059 * points, 8 bytes each, that will create a register frame and call the generic
2060 * C compatible trap handlers. */
2061extern uint32_t BS3_DATA_NM(g_Bs3Trap64GenericEntriesFlatAddr);
2062
2063/**
2064 * C-style trap handler.
2065 *
2066 * Upon return Bs3Trap16ResumeFrame_c16, #Bs3Trap32ResumeFrame_c32, or
2067 * Bs3Trap64ResumeFrame_c64 will be called depending on the current template
2068 * context.
2069 *
2070 * @param pTrapFrame The trap frame. Registers can be modified.
2071 */
2072typedef BS3_DECL_CALLBACK(void) FNBS3TRAPHANDLER(PBS3TRAPFRAME pTrapFrame);
2073/** Pointer to a trap handler (current template context). */
2074typedef FNBS3TRAPHANDLER *PFNBS3TRAPHANDLER;
2075
2076/**
2077 * Sets a trap handler (C/C++/assembly) for the current bitness.
2078 *
2079 * When using a 32-bit IDT, only #Bs3TrapSetHandler_c32 will have any effect.
2080 * Likewise, when using a 16-bit IDT, only Bs3TrapSetHandler_c16 will make any
2081 * difference. Ditto 64-bit.
2082 *
2083 * Rational: It's mainly a C API, can't easily mix function pointers from other
2084 * bit counts in C. Use assembly helpers or something if that is necessary.
2085 * Besides, most of the real trap handling goes thru the default handler with
2086 * help of trap records.
2087 *
2088 * @returns Previous handler.
2089 * @param iIdt The index of the IDT entry to set.
2090 * @param pfnHandler Pointer to the handler.
2091 */
2092BS3_DECL(PFNBS3TRAPHANDLER) Bs3TrapSetHandler_c16(uint8_t iIdt, PFNBS3TRAPHANDLER pfnHandler);
2093BS3_DECL(PFNBS3TRAPHANDLER) Bs3TrapSetHandler_c32(uint8_t iIdt, PFNBS3TRAPHANDLER pfnHandler); /**< @copydoc Bs3Trap32SetHandler_c16 */
2094BS3_DECL(PFNBS3TRAPHANDLER) Bs3TrapSetHandler_c64(uint8_t iIdt, PFNBS3TRAPHANDLER pfnHandler); /**< @copydoc Bs3Trap32SetHandler_c16 */
2095#define Bs3Trap32SetHandler BS3_CMN_NM(Bs3Trap32SetHandler) /**< Selects #Bs3Trap32SetHandler_c16, #Bs3Trap32SetHandler_c32 or #Bs3Trap32SetHandler_c64. */
2096
2097/**
2098 * Default C/C++ trap handler.
2099 *
2100 * This will check trap record and panic if no match was found.
2101 *
2102 * @param pTrapFrame Trap frame of the trap to handle.
2103 */
2104BS3_DECL(void) Bs3TrapDefaultHandler_c16(PBS3TRAPFRAME pTrapFrame);
2105BS3_DECL(void) Bs3TrapDefaultHandler_c32(PBS3TRAPFRAME pTrapFrame); /**< @copydoc Bs3TrapDefaultHandler_c16 */
2106BS3_DECL(void) Bs3TrapDefaultHandler_c64(PBS3TRAPFRAME pTrapFrame); /**< @copydoc Bs3TrapDefaultHandler_c16 */
2107#define Bs3TrapDefaultHandler BS3_CMN_NM(Bs3TrapDefaultHandler) /**< Selects #Bs3TrapDefaultHandler_c16, #Bs3TrapDefaultHandler_c32 or #Bs3TrapDefaultHandler_c64. */
2108
2109/**
2110 * Prints the trap frame (to screen).
2111 * @param pTrapFrame Trap frame to print.
2112 */
2113BS3_DECL(void) Bs3TrapPrintFrame_c16(PCBS3TRAPFRAME pTrapFrame);
2114BS3_DECL(void) Bs3TrapPrintFrame_c32(PCBS3TRAPFRAME pTrapFrame); /**< @copydoc Bs3TrapPrintFrame_c16 */
2115BS3_DECL(void) Bs3TrapPrintFrame_c64(PCBS3TRAPFRAME pTrapFrame); /**< @copydoc Bs3TrapPrintFrame_c16 */
2116#define Bs3TrapPrintFrame BS3_CMN_NM(Bs3TrapPrintFrame) /**< Selects #Bs3TrapPrintFrame_c16, #Bs3TrapPrintFrame_c32 or #Bs3TrapPrintFrame_c64. */
2117
2118/** @} */
2119
2120
2121/**
2122 * Initializes all of boot sector kit \#3.
2123 */
2124BS3_DECL(void) Bs3InitAll_rm(void);
2125
2126/**
2127 * Initializes the REAL and TILED memory pools.
2128 *
2129 * For proper operation on OLDer CPUs, call #Bs3CpuDetect_mmm first.
2130 */
2131BS3_DECL(void) Bs3InitMemory_rm(void);
2132
2133
2134
2135/** @defgroup grp_bs3kit_mode Mode Specific Functions and Data
2136 *
2137 * The mode specific functions come in bit count variations and CPU mode
2138 * variations. The bs3kit-template-header.h/mac defines the BS3_NM macro to
2139 * mangle a function or variable name according to the target CPU mode. In
2140 * non-templated code, it's common to spell the name out in full.
2141 *
2142 * @{
2143 */
2144
2145
2146/**
2147 * Macro for reducing typing.
2148 *
2149 * Doxygen knows how to expand this, well, kind of.
2150 */
2151#define BS3_MODE_EXPAND_PROTOTYPES(a_RetType, a_BaseFnNm, a_Parameters) \
2152 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_rm) a_Parameters; \
2153 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pe16) a_Parameters; \
2154 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pe16_32) a_Parameters; \
2155 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pe16_v86) a_Parameters; \
2156 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pe32) a_Parameters; \
2157 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pe32_16) a_Parameters; \
2158 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pev86) a_Parameters; \
2159 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pp16) a_Parameters; \
2160 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pp16_32) a_Parameters; \
2161 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pp16_v86) a_Parameters; \
2162 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pp32) a_Parameters; \
2163 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pp32_16) a_Parameters; \
2164 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_ppv86) a_Parameters; \
2165 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pae16) a_Parameters; \
2166 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pae16_16) a_Parameters; \
2167 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pae16_v86)a_Parameters; \
2168 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pae32) a_Parameters; \
2169 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pae32_16) a_Parameters; \
2170 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_paev86) a_Parameters; \
2171 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_lm16) a_Parameters; \
2172 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_lm32) a_Parameters; \
2173 BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_lm64) a_Parameters
2174
2175/**
2176 * Macro for reducing typing.
2177 *
2178 * Doxygen knows how to expand this, well, kind of.
2179 */
2180#define BS3_MODE_EXPAND_EXTERN_DATA16(a_VarType, a_VarName, a_Suffix) \
2181 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_rm)) a_Suffix; \
2182 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_pe16)) a_Suffix; \
2183 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_pe16_32)) a_Suffix; \
2184 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_pe16_v86)) a_Suffix; \
2185 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_pe32)) a_Suffix; \
2186 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_pe32_16)) a_Suffix; \
2187 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_pev86)) a_Suffix; \
2188 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_pp16)) a_Suffix; \
2189 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_pp16_32)) a_Suffix; \
2190 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_pp16_v86)) a_Suffix; \
2191 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_pp32)) a_Suffix; \
2192 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_pp32_16)) a_Suffix; \
2193 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_ppv86)) a_Suffix; \
2194 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_pae16)) a_Suffix; \
2195 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_pae16_32)) a_Suffix; \
2196 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_pae16_v86))a_Suffix; \
2197 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_pae32)) a_Suffix; \
2198 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_pae32_16)) a_Suffix; \
2199 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_paev86)) a_Suffix; \
2200 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_lm16)) a_Suffix; \
2201 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_lm32)) a_Suffix; \
2202 extern a_VarType BS3_FAR_DATA BS3_DATA_NM(RT_CONCAT(a_VarName,_lm64)) a_Suffix
2203
2204
2205/** The TMPL_MODE_STR value for each mode.
2206 * These are all in DATA16 so they can be accessed from any code. */
2207BS3_MODE_EXPAND_EXTERN_DATA16(const char *, g_szBs3ModeName, []);
2208
2209/**
2210 * Basic CPU detection.
2211 *
2212 * This sets the #g_bBs3CpuDetected global variable to the return value.
2213 *
2214 * @returns BS3CPU_XXX value with the BS3CPU_F_CPUID flag set depending on
2215 * capabilities.
2216 */
2217BS3_MODE_EXPAND_PROTOTYPES(uint8_t, Bs3CpuDetect,(void));
2218
2219/** @name BS3CPU_XXX - CPU detected by BS3CpuDetect_c16() and friends.
2220 * @{ */
2221#define BS3CPU_8086 UINT16_C(0x0001) /**< Both 8086 and 8088. */
2222#define BS3CPU_V20 UINT16_C(0x0002) /**< Both NEC V20, V30 and relatives. */
2223#define BS3CPU_80186 UINT16_C(0x0003) /**< Both 80186 and 80188. */
2224#define BS3CPU_80286 UINT16_C(0x0004)
2225#define BS3CPU_80386 UINT16_C(0x0005)
2226#define BS3CPU_80486 UINT16_C(0x0006)
2227#define BS3CPU_Pentium UINT16_C(0x0007)
2228#define BS3CPU_PPro UINT16_C(0x0008)
2229#define BS3CPU_PProOrNewer UINT16_C(0x0009)
2230/** CPU type mask. This is a full byte so it's possible to use byte access
2231 * without and AND'ing to get the type value. */
2232#define BS3CPU_TYPE_MASK UINT16_C(0x00ff)
2233/** Flag indicating that the CPUID instruction is supported by the CPU. */
2234#define BS3CPU_F_CPUID UINT16_C(0x0100)
2235/** Flag indicating that extend CPUID leaves are available (at least two). */
2236#define BS3CPU_F_CPUID_EXT_LEAVES UINT16_C(0x0200)
2237/** Flag indicating that the CPU supports PAE. */
2238#define BS3CPU_F_PAE UINT16_C(0x0400)
2239/** Flag indicating that the CPU supports long mode. */
2240#define BS3CPU_F_LONG_MODE UINT16_C(0x0800)
2241/** @} */
2242
2243/** The return value of #Bs3CpuDetect_mmm. (Initial value is BS3CPU_TYPE_MASK.) */
2244extern uint16_t BS3_DATA_NM(g_uBs3CpuDetected);
2245
2246
2247/**
2248 * Executes the array of tests in every possibly mode.
2249 *
2250 * @param paEntries The mode sub-test entries.
2251 * @param cEntries The number of sub-test entries.
2252 */
2253BS3_MODE_EXPAND_PROTOTYPES(void, Bs3TestDoModes, (BS3TESTMODEENTRY paEntries, unsigned cEntries));
2254
2255/** @} */
2256
2257RT_C_DECLS_END
2258
2259
2260#endif
2261
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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