VirtualBox

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

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

bs3kit: Updates

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

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