VirtualBox

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

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

bs3kit: Implemented switching to long mode.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 74.9 KB
Line 
1/* $Id: bs3kit.h 59245 2016-01-04 01:57:26Z 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 may want to reuse some IPRT code in the common name space, so we
41 * redefine the RT_MANGLER to work like BS3_CMN_NM. (We cannot use
42 * BS3_CMN_NM yet, as we need to include IPRT headers with function
43 * declarations before we can define it. Thus the duplciate effort.)
44 */
45#define RT_MANGLER(a_Name) RT_CONCAT3(a_Name,_c,ARCH_BITS)
46#include <iprt/mangling.h>
47#include <iprt/x86.h>
48#include <iprt/err.h>
49
50
51
52RT_C_DECLS_BEGIN
53
54/** @defgroup grp_bs3kit BS3Kit
55 * @{ */
56
57
58/** @name BS3_ADDR_XXX - Static Memory Allocation
59 * @{ */
60/** The flat load address for the code after the bootsector. */
61#define BS3_ADDR_LOAD 0x10000
62/** Where we save the boot registers during init.
63 * Located right before the code. */
64#define BS3_ADDR_REG_SAVE (BS3_ADDR_LOAD - sizeof(BS3REGS) - 8)
65/** Where the stack starts (initial RSP value).
66 * Located 16 bytes (assumed by boot sector) before the saved registers.
67 * SS.BASE=0. The size is a little short of 32KB */
68#define BS3_ADDR_STACK (BS3_ADDR_REG_SAVE - 16)
69/** The ring-0 stack (8KB) for ring transitions. */
70#define BS3_ADDR_STACK_R0 0x06000
71/** The ring-1 stack (8KB) for ring transitions. */
72#define BS3_ADDR_STACK_R1 0x04000
73/** The ring-2 stack (8KB) for ring transitions. */
74#define BS3_ADDR_STACK_R2 0x02000
75/** IST1 ring-0 stack for long mode (4KB), used for double faults elsewhere. */
76#define BS3_ADDR_STACK_R0_IST1 0x09000
77/** IST2 ring-0 stack for long mode (3KB), used for spare 0 stack elsewhere. */
78#define BS3_ADDR_STACK_R0_IST2 0x08000
79/** IST3 ring-0 stack for long mode (1KB). */
80#define BS3_ADDR_STACK_R0_IST3 0x07400
81/** IST4 ring-0 stack for long mode (1KB), used for spare 1 stack elsewhere. */
82#define BS3_ADDR_STACK_R0_IST4 0x07000
83/** IST5 ring-0 stack for long mode (1KB). */
84#define BS3_ADDR_STACK_R0_IST5 0x06c00
85/** IST6 ring-0 stack for long mode (1KB). */
86#define BS3_ADDR_STACK_R0_IST6 0x06800
87/** IST7 ring-0 stack for long mode (1KB). */
88#define BS3_ADDR_STACK_R0_IST7 0x06400
89
90/** The base address of the BS3TEXT16 segment (same as BS3_LOAD_ADDR).
91 * @sa BS3_SEL_TEXT16 */
92#define BS3_ADDR_BS3TEXT16 0x10000
93/** The base address of the BS3SYSTEM16 segment.
94 * @sa BS3_SEL_SYSTEM16 */
95#define BS3_ADDR_BS3SYSTEM16 0x20000
96/** The base address of the BS3DATA16 segment.
97 * @sa BS3_SEL_DATA16 */
98#define BS3_ADDR_BS3DATA16 0x27000
99/** @} */
100
101/** @name BS3_SEL_XXX - GDT selector assignments.
102 *
103 * The real mode segment numbers for BS16TEXT, BS16DATA and BS16SYSTEM are
104 * present in the GDT, this allows the 16-bit C/C++ and assembly code to
105 * continue using the real mode segment values in ring-0 protected mode.
106 *
107 * The three segments have fixed locations:
108 * | segment | flat address | real mode segment |
109 * | ----------- | ------------ | ----------------- |
110 * | BS3TEXT16 | 0x00010000 | 1000h |
111 * | BS3SYSTEM16 | 0x00020000 | 2000h |
112 * | BS3DATA16 | 0x00027000 | 2700h |
113 *
114 * This means that we've got a lot of GDT space to play around with.
115 *
116 * @{ */
117#define BS3_SEL_LDT 0x0010 /**< The LDT selector for Bs3Ldt. */
118#define BS3_SEL_TSS16 0x0020 /**< The 16-bit TSS selector. */
119#define BS3_SEL_TSS16_DF 0x0028 /**< The 16-bit TSS selector for double faults. */
120#define BS3_SEL_TSS16_SPARE0 0x0030 /**< The 16-bit TSS selector for testing. */
121#define BS3_SEL_TSS16_SPARE1 0x0038 /**< The 16-bit TSS selector for testing. */
122#define BS3_SEL_TSS32 0x0040 /**< The 32-bit TSS selector. */
123#define BS3_SEL_TSS32_DF 0x0048 /**< The 32-bit TSS selector for double faults. */
124#define BS3_SEL_TSS32_SPARE0 0x0050 /**< The 32-bit TSS selector for testing. */
125#define BS3_SEL_TSS32_SPARE1 0x0058 /**< The 32-bit TSS selector for testing. */
126#define BS3_SEL_TSS32_IOBP_IRB 0x0060 /**< The 32-bit TSS selector with I/O permission and interrupt redirection bitmaps. */
127#define BS3_SEL_TSS32_IRB 0x0068 /**< The 32-bit TSS selector with only interrupt redirection bitmap (IOPB stripped by limit). */
128#define BS3_SEL_TSS64 0x0070 /**< The 64-bit TSS selector. */
129#define BS3_SEL_TSS64_SPARE0 0x0080 /**< The 64-bit TSS selector. */
130#define BS3_SEL_TSS64_SPARE1 0x0090 /**< The 64-bit TSS selector. */
131#define BS3_SEL_TSS64_IOBP 0x00a0 /**< The 64-bit TSS selector. */
132
133#define BS3_SEL_VMMDEV_MMIO16 0x00f8 /**< Selector for accessing the VMMDev MMIO segment at 0100000h from 16-bit code. */
134
135#define BS3_SEL_RING_SHIFT 8 /**< For the formula: BS3_SEL_R0_XXX + ((cs & 3) << BS3_SEL_RING_SHIFT) */
136
137#define BS3_SEL_R0_FIRST 0x0100 /**< The first selector in the ring-0 block. */
138#define BS3_SEL_R0_CS16 0x0100 /**< ring-0: 16-bit code selector, base 0x10000. */
139#define BS3_SEL_R0_DS16 0x0108 /**< ring-0: 16-bit data selector, base 0x23000. */
140#define BS3_SEL_R0_SS16 0x0110 /**< ring-0: 16-bit stack selector, base 0x00000. */
141#define BS3_SEL_R0_CS32 0x0118 /**< ring-0: 32-bit flat code selector. */
142#define BS3_SEL_R0_DS32 0x0120 /**< ring-0: 32-bit flat data selector. */
143#define BS3_SEL_R0_SS32 0x0128 /**< ring-0: 32-bit flat stack selector. */
144#define BS3_SEL_R0_CS64 0x0130 /**< ring-0: 64-bit flat code selector. */
145#define BS3_SEL_R0_DS64 0x0138 /**< ring-0: 64-bit flat data & stack selector. */
146#define BS3_SEL_R0_CS16_EO 0x0140 /**< ring-0: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base. */
147#define BS3_SEL_R0_CS16_CNF 0x0148 /**< ring-0: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base. */
148#define BS3_SEL_R0_CS16_CNF_EO 0x0150 /**< ring-0: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base. */
149#define BS3_SEL_R0_CS32_EO 0x0158 /**< ring-0: 32-bit execute-only code selector, not accessed, flat. */
150#define BS3_SEL_R0_CS32_CNF 0x0160 /**< ring-0: 32-bit conforming code selector, not accessed, flat. */
151#define BS3_SEL_R0_CS32_CNF_EO 0x0168 /**< ring-0: 32-bit execute-only conforming code selector, not accessed, flat. */
152#define BS3_SEL_R0_CS64_EO 0x0170 /**< ring-0: 64-bit execute-only code selector, not accessed, flat. */
153#define BS3_SEL_R0_CS64_CNF 0x0178 /**< ring-0: 64-bit conforming code selector, not accessed, flat. */
154#define BS3_SEL_R0_CS64_CNF_EO 0x0180 /**< ring-0: 64-bit execute-only conforming code selector, not accessed, flat. */
155
156#define BS3_SEL_R1_FIRST 0x0200 /**< The first selector in the ring-1 block. */
157#define BS3_SEL_R1_CS16 0x0200 /**< ring-1: 16-bit code selector, base 0x10000. */
158#define BS3_SEL_R1_DS16 0x0208 /**< ring-1: 16-bit data selector, base 0x23000. */
159#define BS3_SEL_R1_SS16 0x0210 /**< ring-1: 16-bit stack selector, base 0x00000. */
160#define BS3_SEL_R1_CS32 0x0218 /**< ring-1: 32-bit flat code selector. */
161#define BS3_SEL_R1_DS32 0x0220 /**< ring-1: 32-bit flat data selector. */
162#define BS3_SEL_R1_SS32 0x0228 /**< ring-1: 32-bit flat stack selector. */
163#define BS3_SEL_R1_CS64 0x0230 /**< ring-1: 64-bit flat code selector. */
164#define BS3_SEL_R1_DS64 0x0238 /**< ring-1: 64-bit flat data & stack selector. */
165#define BS3_SEL_R1_CS16_EO 0x0240 /**< ring-1: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base. */
166#define BS3_SEL_R1_CS16_CNF 0x0248 /**< ring-1: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base. */
167#define BS3_SEL_R1_CS16_CNF_EO 0x0250 /**< ring-1: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base. */
168#define BS3_SEL_R1_CS32_EO 0x0258 /**< ring-1: 32-bit execute-only code selector, not accessed, flat. */
169#define BS3_SEL_R1_CS32_CNF 0x0260 /**< ring-1: 32-bit conforming code selector, not accessed, flat. */
170#define BS3_SEL_R1_CS32_CNF_EO 0x0268 /**< ring-1: 32-bit execute-only conforming code selector, not accessed, flat. */
171#define BS3_SEL_R1_CS64_EO 0x0270 /**< ring-1: 64-bit execute-only code selector, not accessed, flat. */
172#define BS3_SEL_R1_CS64_CNF 0x0278 /**< ring-1: 64-bit conforming code selector, not accessed, flat. */
173#define BS3_SEL_R1_CS64_CNF_EO 0x0280 /**< ring-1: 64-bit execute-only conforming code selector, not accessed, flat. */
174
175#define BS3_SEL_R2_FIRST 0x0300 /**< The first selector in the ring-2 block. */
176#define BS3_SEL_R2_CS16 0x0300 /**< ring-2: 16-bit code selector, base 0x10000. */
177#define BS3_SEL_R2_DS16 0x0308 /**< ring-2: 16-bit data selector, base 0x23000. */
178#define BS3_SEL_R2_SS16 0x0310 /**< ring-2: 16-bit stack selector, base 0x00000. */
179#define BS3_SEL_R2_CS32 0x0318 /**< ring-2: 32-bit flat code selector. */
180#define BS3_SEL_R2_DS32 0x0320 /**< ring-2: 32-bit flat data selector. */
181#define BS3_SEL_R2_SS32 0x0328 /**< ring-2: 32-bit flat stack selector. */
182#define BS3_SEL_R2_CS64 0x0330 /**< ring-2: 64-bit flat code selector. */
183#define BS3_SEL_R2_DS64 0x0338 /**< ring-2: 64-bit flat data & stack selector. */
184#define BS3_SEL_R2_CS16_EO 0x0340 /**< ring-2: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base. */
185#define BS3_SEL_R2_CS16_CNF 0x0348 /**< ring-2: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base. */
186#define BS3_SEL_R2_CS16_CNF_EO 0x0350 /**< ring-2: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base. */
187#define BS3_SEL_R2_CS32_EO 0x0358 /**< ring-2: 32-bit execute-only code selector, not accessed, flat. */
188#define BS3_SEL_R2_CS32_CNF 0x0360 /**< ring-2: 32-bit conforming code selector, not accessed, flat. */
189#define BS3_SEL_R2_CS32_CNF_EO 0x0368 /**< ring-2: 32-bit execute-only conforming code selector, not accessed, flat. */
190#define BS3_SEL_R2_CS64_EO 0x0370 /**< ring-2: 64-bit execute-only code selector, not accessed, flat. */
191#define BS3_SEL_R2_CS64_CNF 0x0378 /**< ring-2: 64-bit conforming code selector, not accessed, flat. */
192#define BS3_SEL_R2_CS64_CNF_EO 0x0380 /**< ring-2: 64-bit execute-only conforming code selector, not accessed, flat. */
193
194#define BS3_SEL_R3_FIRST 0x0400 /**< The first selector in the ring-3 block. */
195#define BS3_SEL_R3_CS16 0x0400 /**< ring-3: 16-bit code selector, base 0x10000. */
196#define BS3_SEL_R3_DS16 0x0408 /**< ring-3: 16-bit data selector, base 0x23000. */
197#define BS3_SEL_R3_SS16 0x0410 /**< ring-3: 16-bit stack selector, base 0x00000. */
198#define BS3_SEL_R3_CS32 0x0418 /**< ring-3: 32-bit flat code selector. */
199#define BS3_SEL_R3_DS32 0x0420 /**< ring-3: 32-bit flat data selector. */
200#define BS3_SEL_R3_SS32 0x0428 /**< ring-3: 32-bit flat stack selector. */
201#define BS3_SEL_R3_CS64 0x0430 /**< ring-3: 64-bit flat code selector. */
202#define BS3_SEL_R3_DS64 0x0438 /**< ring-3: 64-bit flat data & stack selector. */
203#define BS3_SEL_R3_CS16_EO 0x0440 /**< ring-3: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base. */
204#define BS3_SEL_R3_CS16_CNF 0x0448 /**< ring-3: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base. */
205#define BS3_SEL_R3_CS16_CNF_EO 0x0450 /**< ring-3: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base. */
206#define BS3_SEL_R3_CS32_EO 0x0458 /**< ring-3: 32-bit execute-only code selector, not accessed, flat. */
207#define BS3_SEL_R3_CS32_CNF 0x0460 /**< ring-3: 32-bit conforming code selector, not accessed, flat. */
208#define BS3_SEL_R3_CS32_CNF_EO 0x0468 /**< ring-3: 32-bit execute-only conforming code selector, not accessed, flat. */
209#define BS3_SEL_R3_CS64_EO 0x0470 /**< ring-3: 64-bit execute-only code selector, not accessed, flat. */
210#define BS3_SEL_R3_CS64_CNF 0x0478 /**< ring-3: 64-bit conforming code selector, not accessed, flat. */
211#define BS3_SEL_R3_CS64_CNF_EO 0x0480 /**< ring-3: 64-bit execute-only conforming code selector, not accessed, flat. */
212
213#define BS3_SEL_SPARE_FIRST 0x0500 /**< The first selector in the spare block */
214#define BS3_SEL_SPARE_00 0x0500 /**< Spare selector number 00h. */
215#define BS3_SEL_SPARE_01 0x0508 /**< Spare selector number 01h. */
216#define BS3_SEL_SPARE_02 0x0510 /**< Spare selector number 02h. */
217#define BS3_SEL_SPARE_03 0x0518 /**< Spare selector number 03h. */
218#define BS3_SEL_SPARE_04 0x0520 /**< Spare selector number 04h. */
219#define BS3_SEL_SPARE_05 0x0528 /**< Spare selector number 05h. */
220#define BS3_SEL_SPARE_06 0x0530 /**< Spare selector number 06h. */
221#define BS3_SEL_SPARE_07 0x0538 /**< Spare selector number 07h. */
222#define BS3_SEL_SPARE_08 0x0540 /**< Spare selector number 08h. */
223#define BS3_SEL_SPARE_09 0x0548 /**< Spare selector number 09h. */
224#define BS3_SEL_SPARE_0a 0x0550 /**< Spare selector number 0ah. */
225#define BS3_SEL_SPARE_0b 0x0558 /**< Spare selector number 0bh. */
226#define BS3_SEL_SPARE_0c 0x0560 /**< Spare selector number 0ch. */
227#define BS3_SEL_SPARE_0d 0x0568 /**< Spare selector number 0dh. */
228#define BS3_SEL_SPARE_0e 0x0570 /**< Spare selector number 0eh. */
229#define BS3_SEL_SPARE_0f 0x0578 /**< Spare selector number 0fh. */
230#define BS3_SEL_SPARE_10 0x0580 /**< Spare selector number 10h. */
231#define BS3_SEL_SPARE_11 0x0588 /**< Spare selector number 11h. */
232#define BS3_SEL_SPARE_12 0x0590 /**< Spare selector number 12h. */
233#define BS3_SEL_SPARE_13 0x0598 /**< Spare selector number 13h. */
234#define BS3_SEL_SPARE_14 0x05a0 /**< Spare selector number 14h. */
235#define BS3_SEL_SPARE_15 0x05a8 /**< Spare selector number 15h. */
236#define BS3_SEL_SPARE_16 0x05b0 /**< Spare selector number 16h. */
237#define BS3_SEL_SPARE_17 0x05b8 /**< Spare selector number 17h. */
238#define BS3_SEL_SPARE_18 0x05c0 /**< Spare selector number 18h. */
239#define BS3_SEL_SPARE_19 0x05c8 /**< Spare selector number 19h. */
240#define BS3_SEL_SPARE_1a 0x05d0 /**< Spare selector number 1ah. */
241#define BS3_SEL_SPARE_1b 0x05d8 /**< Spare selector number 1bh. */
242#define BS3_SEL_SPARE_1c 0x05e0 /**< Spare selector number 1ch. */
243#define BS3_SEL_SPARE_1d 0x05e8 /**< Spare selector number 1dh. */
244#define BS3_SEL_SPARE_1e 0x05f0 /**< Spare selector number 1eh. */
245#define BS3_SEL_SPARE_1f 0x05f8 /**< Spare selector number 1fh. */
246
247#define BS3_SEL_TILED 0x0600 /**< 16-bit data tiling: First - base=0x00000000, limit=64KB. */
248#define BS3_SEL_TILED_LAST 0x0df8 /**< 16-bit data tiling: Last - base=0x00ff0000, limit=64KB. */
249#define BS3_SEL_TILED_AREA_SIZE 0x001000000 /**< 16-bit data tiling: Size of addressable area, in bytes. (16 MB) */
250
251#define BS3_SEL_FREE_PART1 0x0e00 /**< Free selector space - part \#1. */
252#define BS3_SEL_FREE_PART1_LAST 0x0ff8 /**< Free selector space - part \#1, last entry. */
253
254#define BS3_SEL_TEXT16 0x1000 /**< The BS3TEXT16 selector. */
255
256#define BS3_SEL_FREE_PART2 0x1008 /**< Free selector space - part \#2. */
257#define BS3_SEL_FREE_PART2_LAST 0x1ff8 /**< Free selector space - part \#2, last entry. */
258
259#define BS3_SEL_SYSTEM16 0x2000 /**< The BS3SYSTEM16 selector. */
260
261#define BS3_SEL_FREE_PART3 0x2008 /**< Free selector space - part \#3. */
262#define BS3_SEL_FREE_PART3_LAST 0x26f8 /**< Free selector space - part \#3, last entry. */
263
264#define BS3_SEL_DATA16 0x2700 /**< The BS3DATA16 selector. */
265
266#define BS3_SEL_GDT_LIMIT 0x2707 /**< The GDT limit. */
267/** @} */
268
269
270/** @def BS3_FAR
271 * For indicating far pointers in 16-bit code.
272 * Does nothing in 32-bit and 64-bit code. */
273/** @def BS3_NEAR
274 * For indicating near pointers in 16-bit code.
275 * Does nothing in 32-bit and 64-bit code. */
276/** @def BS3_FAR_CODE
277 * For indicating far 16-bit functions.
278 * Does nothing in 32-bit and 64-bit code. */
279/** @def BS3_NEAR_CODE
280 * For indicating near 16-bit functions.
281 * Does nothing in 32-bit and 64-bit code. */
282#ifdef M_I86
283# define BS3_FAR __far
284# define BS3_NEAR __near
285# define BS3_FAR_CODE __far
286# define BS3_NEAR_CODE __near
287#else
288# define BS3_FAR
289# define BS3_NEAR
290# define BS3_FAR_CODE
291# define BS3_NEAR_CODE
292#endif
293
294#if ARCH_BITS == 16 || defined(DOXYGEN_RUNNING)
295/** @def BS3_FP_SEG
296 * Get the selector (segment) part of a far pointer.
297 * @returns selector.
298 * @param a_pv Far pointer.
299 */
300# define BS3_FP_SEG(a_pv) ((uint16_t)(__segment)(void BS3_FAR *)(a_pv))
301/** @def BS3_FP_OFF
302 * Get the segment offset part of a far pointer.
303 * @returns offset.
304 * @param a_pv Far pointer.
305 */
306# define BS3_FP_OFF(a_pv) ((uint16_t)(void __near *)(a_pv))
307/** @def BS3_FP_MAKE
308 * Create a far pointer.
309 * @returns selector.
310 * @param a_pv Far pointer.
311 */
312# define BS3_FP_MAKE(a_uSeg, a_off) (((__segment)(a_uSeg)) :> ((void __near *)(a_off)))
313#endif
314
315/** @def BS3_CALL
316 * The calling convension used by BS3 functions. */
317#if ARCH_BITS != 64
318# define BS3_CALL __cdecl
319#elif !defined(_MSC_VER)
320# define BS3_CALL __attribute__((__ms_abi__))
321#else
322# define BS3_CALL
323#endif
324
325/** @def IN_BS3KIT
326 * Indicates that we're in the same link job as the BS3Kit code. */
327#ifdef DOXYGEN_RUNNING
328# define IN_BS3KIT
329#endif
330
331/** @def BS3_DECL
332 * Declares a BS3Kit function.
333 *
334 * Until we outgrow BS3TEXT16, we use all near functions in 16-bit.
335 *
336 * @param a_Type The return type. */
337#ifdef IN_BS3KIT
338# define BS3_DECL(a_Type) DECLEXPORT(a_Type) BS3_NEAR_CODE BS3_CALL
339#else
340# define BS3_DECL(a_Type) DECLIMPORT(a_Type) BS3_NEAR_CODE BS3_CALL
341#endif
342
343/** @def BS3_DECL_CALLBACK
344 * Declares a BS3Kit callback function (typically static).
345 *
346 * Until we outgrow BS3TEXT16, we use all near functions in 16-bit.
347 *
348 * @param a_Type The return type. */
349#ifdef IN_BS3KIT
350# define BS3_DECL_CALLBACK(a_Type) a_Type BS3_NEAR_CODE BS3_CALL
351#else
352# define BS3_DECL_CALLBACK(a_Type) a_Type BS3_NEAR_CODE BS3_CALL
353#endif
354
355/**
356 * Constructs a common name.
357 *
358 * Example: BS3_CMN_NM(Bs3Shutdown)
359 *
360 * @param a_Name The name of the function or global variable.
361 */
362#define BS3_CMN_NM(a_Name) RT_CONCAT3(a_Name,_c,ARCH_BITS)
363
364/**
365 * Constructs a data name.
366 *
367 * Example: BS3_DATA_NM(Bs3Gdt)
368 *
369 * @param a_Name The name of the global variable.
370 */
371#if ARCH_BITS == 64
372# define BS3_DATA_NM(a_Name) RT_CONCAT(_,a_Name)
373#else
374# define BS3_DATA_NM(a_Name) a_Name
375#endif
376
377/** @def BS3_MSC64_FIXUP_HACK
378 * Used to avoid IMAGE_REL_AMD64_ADDR32NB fixups where the compiler tries to
379 * make use of __ImageBase as a base pointer instead of emitting rip relative
380 * accesses. Happens when there are a bunch of global data accesses in the same
381 * function, probably to save space.
382 *
383 * The volatile variable in the lambda fixes it.
384 */
385#if _MSC_VER && ARCH_BITS == 64
386# define BS3_MSC64_FIXUP_HACK(a_BaseType, a_Data) \
387 ([]() -> a_BaseType * \
388 { \
389 a_BaseType * volatile x = a_Data; \
390 return x; \
391 }())
392
393#else
394# define BS3_MSC64_FIXUP_HACK(a_BaseType, a_Data) (a_Data)
395#endif
396
397
398/**
399 * Template for createing a pointer union type.
400 * @param a_BaseName The base type name.
401 * @param a_Modifier The type modifier.
402 */
403#define BS3_PTR_UNION_TEMPLATE(a_BaseName, a_Modifiers) \
404 typedef union a_BaseName \
405 { \
406 /** Pointer into the void. */ \
407 a_Modifiers void BS3_FAR *pv; \
408 /** As a signed integer. */ \
409 intptr_t i; \
410 /** As an unsigned integer. */ \
411 uintptr_t u; \
412 /** Pointer to char value. */ \
413 a_Modifiers char BS3_FAR *pch; \
414 /** Pointer to char value. */ \
415 a_Modifiers unsigned char BS3_FAR *puch; \
416 /** Pointer to a int value. */ \
417 a_Modifiers int BS3_FAR *pi; \
418 /** Pointer to a unsigned int value. */ \
419 a_Modifiers unsigned int BS3_FAR *pu; \
420 /** Pointer to a long value. */ \
421 a_Modifiers long BS3_FAR *pl; \
422 /** Pointer to a long value. */ \
423 a_Modifiers unsigned long BS3_FAR *pul; \
424 /** Pointer to a memory size value. */ \
425 a_Modifiers size_t BS3_FAR *pcb; \
426 /** Pointer to a byte value. */ \
427 a_Modifiers uint8_t BS3_FAR *pb; \
428 /** Pointer to a 8-bit unsigned value. */ \
429 a_Modifiers uint8_t BS3_FAR *pu8; \
430 /** Pointer to a 16-bit unsigned value. */ \
431 a_Modifiers uint16_t BS3_FAR *pu16; \
432 /** Pointer to a 32-bit unsigned value. */ \
433 a_Modifiers uint32_t BS3_FAR *pu32; \
434 /** Pointer to a 64-bit unsigned value. */ \
435 a_Modifiers uint64_t BS3_FAR *pu64; \
436 /** Pointer to a UTF-16 character. */ \
437 a_Modifiers RTUTF16 BS3_FAR *pwc; \
438 /** Pointer to a UUID character. */ \
439 a_Modifiers RTUUID BS3_FAR *pUuid; \
440 } a_BaseName; \
441 /** Pointer to a pointer union. */ \
442 typedef a_BaseName *RT_CONCAT(P,a_BaseName)
443BS3_PTR_UNION_TEMPLATE(BS3PTRUNION, RT_NOTHING);
444BS3_PTR_UNION_TEMPLATE(BS3CPTRUNION, const);
445BS3_PTR_UNION_TEMPLATE(BS3VPTRUNION, volatile);
446BS3_PTR_UNION_TEMPLATE(BS3CVPTRUNION, const volatile);
447
448
449
450/** @defgroup grp_bs3kit_system System structures
451 * @{ */
452/** The GDT, indexed by BS3_SEL_XXX shifted by 3. */
453extern X86DESC BS3_DATA_NM(Bs3Gdt)[(BS3_SEL_GDT_LIMIT + 1) / 8];
454
455extern X86DESC64 BS3_DATA_NM(Bs3Gdt_Ldt); /**< @see BS3_SEL_LDT */
456extern X86DESC BS3_DATA_NM(Bs3Gdte_Tss16); /**< @see BS3_SEL_TSS16 */
457extern X86DESC BS3_DATA_NM(Bs3Gdte_Tss16DoubleFault); /**< @see BS3_SEL_TSS16_DF */
458extern X86DESC BS3_DATA_NM(Bs3Gdte_Tss16Spare0); /**< @see BS3_SEL_TSS16_SPARE0 */
459extern X86DESC BS3_DATA_NM(Bs3Gdte_Tss16Spare1); /**< @see BS3_SEL_TSS16_SPARE1 */
460extern X86DESC BS3_DATA_NM(Bs3Gdte_Tss32); /**< @see BS3_SEL_TSS32 */
461extern X86DESC BS3_DATA_NM(Bs3Gdte_Tss32DoubleFault); /**< @see BS3_SEL_TSS32_DF */
462extern X86DESC BS3_DATA_NM(Bs3Gdte_Tss32Spare0); /**< @see BS3_SEL_TSS32_SPARE0 */
463extern X86DESC BS3_DATA_NM(Bs3Gdte_Tss32Spare1); /**< @see BS3_SEL_TSS32_SPARE1 */
464extern X86DESC BS3_DATA_NM(Bs3Gdte_Tss32IobpIntRedirBm); /**< @see BS3_SEL_TSS32_IOBP_IRB */
465extern X86DESC BS3_DATA_NM(Bs3Gdte_Tss32IntRedirBm); /**< @see BS3_SEL_TSS32_IRB */
466extern X86DESC BS3_DATA_NM(Bs3Gdte_Tss64); /**< @see BS3_SEL_TSS64 */
467extern X86DESC BS3_DATA_NM(Bs3Gdte_Tss64Spare0); /**< @see BS3_SEL_TSS64_SPARE0 */
468extern X86DESC BS3_DATA_NM(Bs3Gdte_Tss64Spare1); /**< @see BS3_SEL_TSS64_SPARE1 */
469extern X86DESC BS3_DATA_NM(Bs3Gdte_Tss64Iobp); /**< @see BS3_SEL_TSS64_IOBP */
470extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_MMIO16); /**< @see BS3_SEL_VMMDEV_MMIO16 */
471
472extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_First); /**< @see BS3_SEL_R0_FIRST */
473extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_CS16); /**< @see BS3_SEL_R0_CS16 */
474extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_DS16); /**< @see BS3_SEL_R0_DS16 */
475extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_SS16); /**< @see BS3_SEL_R0_SS16 */
476extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_CS32); /**< @see BS3_SEL_R0_CS32 */
477extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_DS32); /**< @see BS3_SEL_R0_DS32 */
478extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_SS32); /**< @see BS3_SEL_R0_SS32 */
479extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_CS64); /**< @see BS3_SEL_R0_CS64 */
480extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_DS64); /**< @see BS3_SEL_R0_DS64 */
481extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_CS16_EO); /**< @see BS3_SEL_R0_CS16_EO */
482extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_CS16_CNF); /**< @see BS3_SEL_R0_CS16_CNF */
483extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_CS16_CND_EO); /**< @see BS3_SEL_R0_CS16_CNF_EO */
484extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_CS32_EO); /**< @see BS3_SEL_R0_CS32_EO */
485extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_CS32_CNF); /**< @see BS3_SEL_R0_CS32_CNF */
486extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_CS32_CNF_EO); /**< @see BS3_SEL_R0_CS32_CNF_EO */
487extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_CS64_EO); /**< @see BS3_SEL_R0_CS64_EO */
488extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_CS64_CNF); /**< @see BS3_SEL_R0_CS64_CNF */
489extern X86DESC BS3_DATA_NM(Bs3Gdte_R0_CS64_CNF_EO); /**< @see BS3_SEL_R0_CS64_CNF_EO */
490
491extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_First); /**< @see BS3_SEL_R1_FIRST */
492extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_CS16); /**< @see BS3_SEL_R1_CS16 */
493extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_DS16); /**< @see BS3_SEL_R1_DS16 */
494extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_SS16); /**< @see BS3_SEL_R1_SS16 */
495extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_CS32); /**< @see BS3_SEL_R1_CS32 */
496extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_DS32); /**< @see BS3_SEL_R1_DS32 */
497extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_SS32); /**< @see BS3_SEL_R1_SS32 */
498extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_CS64); /**< @see BS3_SEL_R1_CS64 */
499extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_DS64); /**< @see BS3_SEL_R1_DS64 */
500extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_CS16_EO); /**< @see BS3_SEL_R1_CS16_EO */
501extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_CS16_CNF); /**< @see BS3_SEL_R1_CS16_CNF */
502extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_CS16_CND_EO); /**< @see BS3_SEL_R1_CS16_CNF_EO */
503extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_CS32_EO); /**< @see BS3_SEL_R1_CS32_EO */
504extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_CS32_CNF); /**< @see BS3_SEL_R1_CS32_CNF */
505extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_CS32_CNF_EO); /**< @see BS3_SEL_R1_CS32_CNF_EO */
506extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_CS64_EO); /**< @see BS3_SEL_R1_CS64_EO */
507extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_CS64_CNF); /**< @see BS3_SEL_R1_CS64_CNF */
508extern X86DESC BS3_DATA_NM(Bs3Gdte_R1_CS64_CNF_EO); /**< @see BS3_SEL_R1_CS64_CNF_EO */
509
510extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_First); /**< @see BS3_SEL_R2_FIRST */
511extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_CS16); /**< @see BS3_SEL_R2_CS16 */
512extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_DS16); /**< @see BS3_SEL_R2_DS16 */
513extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_SS16); /**< @see BS3_SEL_R2_SS16 */
514extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_CS32); /**< @see BS3_SEL_R2_CS32 */
515extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_DS32); /**< @see BS3_SEL_R2_DS32 */
516extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_SS32); /**< @see BS3_SEL_R2_SS32 */
517extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_CS64); /**< @see BS3_SEL_R2_CS64 */
518extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_DS64); /**< @see BS3_SEL_R2_DS64 */
519extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_CS16_EO); /**< @see BS3_SEL_R2_CS16_EO */
520extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_CS16_CNF); /**< @see BS3_SEL_R2_CS16_CNF */
521extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_CS16_CND_EO); /**< @see BS3_SEL_R2_CS16_CNF_EO */
522extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_CS32_EO); /**< @see BS3_SEL_R2_CS32_EO */
523extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_CS32_CNF); /**< @see BS3_SEL_R2_CS32_CNF */
524extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_CS32_CNF_EO); /**< @see BS3_SEL_R2_CS32_CNF_EO */
525extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_CS64_EO); /**< @see BS3_SEL_R2_CS64_EO */
526extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_CS64_CNF); /**< @see BS3_SEL_R2_CS64_CNF */
527extern X86DESC BS3_DATA_NM(Bs3Gdte_R2_CS64_CNF_EO); /**< @see BS3_SEL_R2_CS64_CNF_EO */
528
529extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_First); /**< @see BS3_SEL_R3_FIRST */
530extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_CS16); /**< @see BS3_SEL_R3_CS16 */
531extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_DS16); /**< @see BS3_SEL_R3_DS16 */
532extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_SS16); /**< @see BS3_SEL_R3_SS16 */
533extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_CS32); /**< @see BS3_SEL_R3_CS32 */
534extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_DS32); /**< @see BS3_SEL_R3_DS32 */
535extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_SS32); /**< @see BS3_SEL_R3_SS32 */
536extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_CS64); /**< @see BS3_SEL_R3_CS64 */
537extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_DS64); /**< @see BS3_SEL_R3_DS64 */
538extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_CS16_EO); /**< @see BS3_SEL_R3_CS16_EO */
539extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_CS16_CNF); /**< @see BS3_SEL_R3_CS16_CNF */
540extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_CS16_CND_EO); /**< @see BS3_SEL_R3_CS16_CNF_EO */
541extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_CS32_EO); /**< @see BS3_SEL_R3_CS32_EO */
542extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_CS32_CNF); /**< @see BS3_SEL_R3_CS32_CNF */
543extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_CS32_CNF_EO); /**< @see BS3_SEL_R3_CS32_CNF_EO */
544extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_CS64_EO); /**< @see BS3_SEL_R3_CS64_EO */
545extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_CS64_CNF); /**< @see BS3_SEL_R3_CS64_CNF */
546extern X86DESC BS3_DATA_NM(Bs3Gdte_R3_CS64_CNF_EO); /**< @see BS3_SEL_R3_CS64_CNF_EO */
547
548extern X86DESC BS3_DATA_NM(Bs3GdteSpare00); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_00 */
549extern X86DESC BS3_DATA_NM(Bs3GdteSpare01); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_01 */
550extern X86DESC BS3_DATA_NM(Bs3GdteSpare02); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_02 */
551extern X86DESC BS3_DATA_NM(Bs3GdteSpare03); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_03 */
552extern X86DESC BS3_DATA_NM(Bs3GdteSpare04); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_04 */
553extern X86DESC BS3_DATA_NM(Bs3GdteSpare05); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_05 */
554extern X86DESC BS3_DATA_NM(Bs3GdteSpare06); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_06 */
555extern X86DESC BS3_DATA_NM(Bs3GdteSpare07); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_07 */
556extern X86DESC BS3_DATA_NM(Bs3GdteSpare08); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_08 */
557extern X86DESC BS3_DATA_NM(Bs3GdteSpare09); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_09 */
558extern X86DESC BS3_DATA_NM(Bs3GdteSpare0a); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0a */
559extern X86DESC BS3_DATA_NM(Bs3GdteSpare0b); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0b */
560extern X86DESC BS3_DATA_NM(Bs3GdteSpare0c); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0c */
561extern X86DESC BS3_DATA_NM(Bs3GdteSpare0d); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0d */
562extern X86DESC BS3_DATA_NM(Bs3GdteSpare0e); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0e */
563extern X86DESC BS3_DATA_NM(Bs3GdteSpare0f); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0f */
564extern X86DESC BS3_DATA_NM(Bs3GdteSpare10); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_10 */
565extern X86DESC BS3_DATA_NM(Bs3GdteSpare11); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_11 */
566extern X86DESC BS3_DATA_NM(Bs3GdteSpare12); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_12 */
567extern X86DESC BS3_DATA_NM(Bs3GdteSpare13); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_13 */
568extern X86DESC BS3_DATA_NM(Bs3GdteSpare14); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_14 */
569extern X86DESC BS3_DATA_NM(Bs3GdteSpare15); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_15 */
570extern X86DESC BS3_DATA_NM(Bs3GdteSpare16); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_16 */
571extern X86DESC BS3_DATA_NM(Bs3GdteSpare17); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_17 */
572extern X86DESC BS3_DATA_NM(Bs3GdteSpare18); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_18 */
573extern X86DESC BS3_DATA_NM(Bs3GdteSpare19); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_19 */
574extern X86DESC BS3_DATA_NM(Bs3GdteSpare1a); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1a */
575extern X86DESC BS3_DATA_NM(Bs3GdteSpare1b); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1b */
576extern X86DESC BS3_DATA_NM(Bs3GdteSpare1c); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1c */
577extern X86DESC BS3_DATA_NM(Bs3GdteSpare1d); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1d */
578extern X86DESC BS3_DATA_NM(Bs3GdteSpare1e); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1e */
579extern X86DESC BS3_DATA_NM(Bs3GdteSpare1f); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1f */
580
581/** GDTs setting up the tiled 16-bit access to the first 16 MBs of memory.
582 * @see BS3_SEL_TILED, BS3_SEL_TILED_LAST, BS3_SEL_TILED_AREA_SIZE */
583extern X86DESC BS3_DATA_NM(Bs3GdteTiled)[256];
584/** Free GDTes, part \#1. */
585extern X86DESC BS3_DATA_NM(Bs3GdteFreePart1)[64];
586/** The BS3CODE16 GDT entry. @see BS3_SEL_TEXT16 */
587extern X86DESC BS3_DATA_NM(Bs3Gdte_CODE16);
588/** Free GDTes, part \#2. */
589extern X86DESC BS3_DATA_NM(Bs3GdteFreePart2)[511];
590/** The BS3SYSTEM16 GDT entry. */
591extern X86DESC BS3_DATA_NM(Bs3Gdte_SYSTEM16);
592/** Free GDTes, part \#3. */
593extern X86DESC BS3_DATA_NM(Bs3GdteFreePart3)[223];
594/** The BS3DATA16 GDT entry. */
595extern X86DESC BS3_DATA_NM(Bs3Gdte_DATA16);
596/** The end of the GDT (exclusive). */
597extern X86DESC BS3_DATA_NM(Bs3GdtEnd);
598
599/** The default 16-bit TSS. */
600extern X86TSS16 BS3_DATA_NM(Bs3Tss16);
601extern X86TSS16 BS3_DATA_NM(Bs3Tss16DoubleFault);
602extern X86TSS16 BS3_DATA_NM(Bs3Tss16Spare0);
603extern X86TSS16 BS3_DATA_NM(Bs3Tss16Spare1);
604/** The default 32-bit TSS. */
605extern X86TSS32 BS3_DATA_NM(Bs3Tss32);
606extern X86TSS32 BS3_DATA_NM(Bs3Tss32DoubleFault);
607extern X86TSS32 BS3_DATA_NM(Bs3Tss32Spare0);
608extern X86TSS32 BS3_DATA_NM(Bs3Tss32Spare1);
609/** The default 64-bit TSS. */
610extern X86TSS64 BS3_DATA_NM(Bs3Tss64);
611extern X86TSS64 BS3_DATA_NM(Bs3Tss64Spare0);
612extern X86TSS64 BS3_DATA_NM(Bs3Tss64Spare1);
613extern X86TSS64 BS3_DATA_NM(Bs3Tss64WithIopb);
614extern X86TSS32 BS3_DATA_NM(Bs3Tss32WithIopb);
615/** Interrupt redirection bitmap used by Bs3Tss32WithIopb. */
616extern uint8_t BS3_DATA_NM(Bs3SharedIntRedirBm)[32];
617/** I/O permission bitmap used by Bs3Tss32WithIopb and Bs3Tss64WithIopb. */
618extern uint8_t BS3_DATA_NM(Bs3SharedIobp)[8192+2];
619/** End of the I/O permission bitmap (exclusive). */
620extern uint8_t BS3_DATA_NM(Bs3SharedIobpEnd);
621/** 16-bit IDT. */
622extern X86DESC BS3_DATA_NM(Bs3Idt16)[256];
623/** 32-bit IDT. */
624extern X86DESC BS3_DATA_NM(Bs3Idt32)[256];
625/** 64-bit IDT. */
626extern X86DESC64 BS3_DATA_NM(Bs3Idt64)[256];
627/** Structure for the LIDT instruction for loading the 16-bit IDT. */
628extern X86XDTR64 BS3_DATA_NM(Bs3Lidt_Idt16);
629/** Structure for the LIDT instruction for loading the 32-bit IDT. */
630extern X86XDTR64 BS3_DATA_NM(Bs3Lidt_Idt32);
631/** Structure for the LIDT instruction for loading the 64-bit IDT. */
632extern X86XDTR64 BS3_DATA_NM(Bs3Lidt_Idt64);
633/** Structure for the LIDT instruction for loading the real mode interrupt
634 * vector table.. */
635extern X86XDTR64 BS3_DATA_NM(Bs3Lidt_Ivt);
636/** Structure for the LGDT instruction for loading the GDT. */
637extern X86XDTR64 BS3_DATA_NM(Bs3Lgdt_Gdt);
638/** The LDT (all entries are empty, fill in for testing). */
639extern X86DESC BS3_DATA_NM(Bs3Ldt)[118];
640/** The end of the LDT (exclusive). */
641extern X86DESC BS3_DATA_NM(Bs3LdtEnd);
642
643/** @} */
644
645
646/** @name Segment start and end markers, sizes.
647 * @{ */
648/** Start of the BS3TEXT16 segment. */
649extern uint8_t BS3_DATA_NM(Bs3Text16_StartOfSegment);
650/** End of the BS3TEXT16 segment. */
651extern uint8_t BS3_DATA_NM(Bs3Text16_EndOfSegment);
652/** The size of the BS3TEXT16 segment. */
653extern uint16_t BS3_DATA_NM(Bs3Text16_Size);
654
655/** Start of the BS3SYSTEM16 segment. */
656extern uint8_t BS3_DATA_NM(Bs3System16_StartOfSegment);
657/** End of the BS3SYSTEM16 segment. */
658extern uint8_t BS3_DATA_NM(Bs3System16_EndOfSegment);
659
660/** Start of the BS3DATA16 segment. */
661extern uint8_t BS3_DATA_NM(Bs3Data16_StartOfSegment);
662/** End of the BS3DATA16 segment. */
663extern uint8_t BS3_DATA_NM(Bs3Data16_EndOfSegment);
664
665/** Start of the BS3TEXT32 segment. */
666extern uint8_t BS3_DATA_NM(Bs3Text32_StartOfSegment);
667/** Start of the BS3TEXT32 segment. */
668extern uint8_t BS3_DATA_NM(Bs3Text32_EndOfSegment);
669
670/** Start of the BS3DATA32 segment. */
671extern uint8_t BS3_DATA_NM(Bs3Data32_StartOfSegment);
672/** Start of the BS3DATA32 segment. */
673extern uint8_t BS3_DATA_NM(Bs3Data32_EndOfSegment);
674
675/** Start of the BS3TEXT64 segment. */
676extern uint8_t BS3_DATA_NM(Bs3Text64_StartOfSegment);
677/** Start of the BS3TEXT64 segment. */
678extern uint8_t BS3_DATA_NM(Bs3Text64_EndOfSegment);
679
680/** Start of the BS3DATA64 segment. */
681extern uint8_t BS3_DATA_NM(Bs3Data64_StartOfSegment);
682/** Start of the BS3DATA64 segment. */
683extern uint8_t BS3_DATA_NM(Bs3Data64_EndOfSegment);
684
685/** The size of the Data16, Text32, Text64, Data32 and Data64 blob. */
686extern uint32_t BS3_DATA_NM(Bs3Data16Thru64Text32And64_TotalSize);
687/** The total image size (from Text16 thu Data64). */
688extern uint32_t BS3_DATA_NM(Bs3TotalImageSize);
689/** @} */
690
691
692/** Lower case hex digits. */
693extern char const BS3_DATA_NM(g_achBs3HexDigits)[16+1];
694/** Upper case hex digits. */
695extern char const BS3_DATA_NM(g_achBs3HexDigitsUpper)[16+1];
696
697
698#ifdef __WATCOMC__
699/**
700 * Executes the SMSW instruction and returns the value.
701 *
702 * @returns Machine status word.
703 */
704uint16_t Bs3AsmSmsw(void);
705# pragma aux Bs3AsmSmsw = \
706 "smsw ax" \
707 value [ax] modify exact [ax] nomemory;
708#endif
709
710
711/** @def BS3_IS_PROTECTED_MODE
712 * @returns true if protected mode, false if not. */
713#if ARCH_BITS != 16
714# define BS3_IS_PROTECTED_MODE() (true)
715#else
716# define BS3_IS_PROTECTED_MODE() (Bs3AsmSmsw() & 1 /*PE*/)
717#endif
718
719
720/** @defgroup bs3kit_cross_ptr Cross context pointer type
721 *
722 * The cross context pointer type is
723 *
724 * @{ */
725
726/**
727 * Cross context pointer base type.
728 */
729#pragma pack(4)
730typedef union BS3XPTR
731{
732 /** The flat pointer. */
733 uint32_t uFlat;
734 /** 16-bit view. */
735 struct
736 {
737 uint16_t uLow;
738 uint16_t uHigh;
739 } u;
740#if ARCH_BITS == 16
741 /** 16-bit near pointer. */
742 void __near *pvNear;
743#elif ARCH_BITS == 32
744 /** 32-bit pointer. */
745 void *pvRaw;
746#endif
747} BS3XPTR;
748#pragma pack()
749
750
751/** @def BS3_XPTR_DEF_INTERNAL
752 * Internal worker.
753 *
754 * @param a_Scope RT_NOTHING if structure or global, static or extern
755 * otherwise.
756 * @param a_Type The type we're pointing to.
757 * @param a_Name The member or variable name.
758 * @internal
759 */
760#if ARCH_BITS == 16
761# define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \
762 a_Scope union \
763 { \
764 BS3XPTR XPtr; \
765 a_Type __near *pNearTyped; \
766 } a_Name
767#elif ARCH_BITS == 32
768# define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \
769 a_Scope union \
770 { \
771 BS3XPTR XPtr; \
772 a_Type *pTyped; \
773 } a_Name
774#elif ARCH_BITS == 64
775# define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \
776 a_Scope union \
777 { \
778 BS3XPTR XPtr; \
779 a_Type *pTyped; \
780 } a_Name
781#else
782# error "ARCH_BITS"
783#endif
784
785/** @def BS3_XPTR_DEF_MEMBER
786 * Defines a pointer member that can be shared by all CPU modes.
787 *
788 * @param a_Type The type we're pointing to.
789 * @param a_Name The member or variable name.
790 */
791#define BS3_XPTR_MEMBER(a_Type, a_Name) BS3_XPTR_DEF_INTERNAL(RT_NOTHING, a_Type, a_Name)
792
793/** @def BS3_XPTR_DEF_AUTO
794 * Defines a pointer static variable for working with an XPTR.
795 *
796 * This is typically used to convert flat pointers into context specific
797 * pointers.
798 *
799 * @param a_Type The type we're pointing to.
800 * @param a_Name The member or variable name.
801 */
802#define BS3_XPTR_AUTO(a_Type, a_Name) BS3_XPTR_DEF_INTERNAL(RT_NOTHING, a_Type, a_Name)
803
804/** @def BS3_XPTR_SET
805 * Sets a cross context pointer.
806 *
807 * @param a_Type The type we're pointing to.
808 * @param a_Name The member or variable name.
809 * @param a_uFlatPtr The flat pointer value to assign. If the x-pointer is
810 * used in real mode, this must be less than 1MB.
811 * Otherwise the limit is 16MB (due to selector tiling).
812 */
813#define BS3_XPTR_SET_FLAT(a_Type, a_Name, a_uFlatPtr) \
814 do { a_Name.XPtr.uFlat = (a_uFlatPtr); } while (0)
815
816/** @def BS3_XPTR_GET_FLAT
817 * Gets the flat address of a cross context pointer.
818 *
819 * @returns 32-bit flat pointer.
820 * @param a_Type The type we're pointing to.
821 * @param a_Name The member or variable name.
822 */
823#define BS3_XPTR_GET_FLAT(a_Type, a_Name) (a_Name.XPtr.uFlat)
824
825/** @def BS3_XPTR_GET_FLAT_LOW
826 * Gets the low 16 bits of the flat address.
827 *
828 * @returns Low 16 bits of the flat pointer.
829 * @param a_Type The type we're pointing to.
830 * @param a_Name The member or variable name.
831 */
832#define BS3_XPTR_GET_FLAT_LOW(a_Type, a_Name) (a_Name.XPtr.u.uLow)
833
834
835#if ARCH_BITS == 16
836
837/**
838 * Gets the current ring number.
839 * @returns Ring number.
840 */
841DECLINLINE(uint16_t) Bs3Sel16GetCurRing(void);
842# pragma aux Bs3Sel16GetCurRing = \
843 "mov ax, ss" \
844 "and ax, 3" \
845 value [ax] modify exact [ax] nomemory;
846
847/**
848 * Converts the high word of a flat pointer into a 16-bit selector.
849 *
850 * This makes use of the tiled area. It also handles real mode.
851 *
852 * @returns Segment selector value.
853 * @param uHigh The high part of flat pointer.
854 * @sa BS3_XPTR_GET, BS3_XPTR_SET
855 */
856DECLINLINE(__segment) Bs3Sel16HighFlatPtrToSelector(uint16_t uHigh)
857{
858 if (BS3_IS_PROTECTED_MODE())
859 return (__segment)(((uHigh << 3) + BS3_SEL_TILED) | Bs3Sel16GetCurRing());
860 return (__segment)(uHigh << 12);
861}
862
863#endif /* ARCH_BITS == 16*/
864
865/** @def BS3_XPTR_GET
866 * Gets the current context pointer value.
867 *
868 * @returns Usable pointer.
869 * @param a_Type The type we're pointing to.
870 * @param a_Name The member or variable name.
871 */
872#if ARCH_BITS == 16
873# define BS3_XPTR_GET(a_Type, a_Name) \
874 ((a_Type BS3_FAR *)BS3_FP_MAKE(Bs3Sel16HighFlatPtrToSelector((a_Name).XPtr.u.uHigh), (a_Name).pNearTyped))
875#elif ARCH_BITS == 32
876# define BS3_XPTR_GET(a_Type, a_Name) ((a_Name).pTyped)
877#elif ARCH_BITS == 64
878# define BS3_XPTR_GET(a_Type, a_Name) ((a_Type *)(uintptr_t)(a_Name).XPtr.uFlat)
879#else
880# error "ARCH_BITS"
881#endif
882
883/** @def BS3_XPTR_SET
884 * Gets the current context pointer value.
885 *
886 * @returns Usable pointer.
887 * @param a_Type The type we're pointing to.
888 * @param a_Name The member or variable name.
889 * @param a_pValue The new pointer value, current context pointer.
890 */
891#if ARCH_BITS == 16
892# define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \
893 do { \
894 a_Type BS3_FAR *pTypeCheck = (a_pValue); \
895 if (BS3_IS_PROTECTED_MODE()) \
896 { \
897 (a_Name).XPtr.u.uLow = BS3_FP_OFF(pTypeCheck); \
898 (a_Name).XPtr.u.uHigh = ((BS3_FP_SEG(pTypeCheck) & UINT16_C(0xfff8)) - BS3_SEL_TILED) >> 3; \
899 } \
900 else \
901 (a_Name).XPtr.uFlat = BS3_FP_OFF(pTypeCheck) + ((uint32_t)BS3_FP_SEG(pTypeCheck) << 4); \
902 } while (0)
903#elif ARCH_BITS == 32
904# define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \
905 do { (a_Name).pTyped = (a_pValue); } while (0)
906#elif ARCH_BITS == 64
907# define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \
908 do { \
909 a_Type *pTypeCheck = (a_pValue); \
910 (a_Name).XPtr.uFlat = (uint32_t)(uintptr_t)pTypeCheck; \
911 } while (0)
912#else
913# error "ARCH_BITS"
914#endif
915
916
917/** @def BS3_XPTR_IS_NULL
918 * Checks if the cross context pointer is NULL.
919 *
920 * @returns true if NULL, false if not.
921 * @param a_Type The type we're pointing to.
922 * @param a_Name The member or variable name.
923 */
924#define BS3_XPTR_IS_NULL(a_Type, a_Name) ((a_Name).XPtr.uFlat == 0)
925/** @} */
926
927
928
929/** @defgroup grp_bs3kit_cmn Common Functions and Data
930 *
931 * The common functions comes in three variations: 16-bit, 32-bit and 64-bit.
932 * Templated code uses the #BS3_CMN_NM macro to mangle the name according to the
933 * desired
934 *
935 * @{
936 */
937
938#ifdef BS3_STRICT
939# define BS3_ASSERT(a_Expr) do { if (!!(a_Expr)) { /* likely */ } else { Bs3Panic(); } } while (0) /**< @todo later */
940#else
941# define BS3_ASSERT(a_Expr) do { } while (0)
942#endif
943
944/**
945 * Panic, never return.
946 *
947 * The current implementation will only halt the CPU.
948 */
949BS3_DECL(void) Bs3Panic_c16(void);
950BS3_DECL(void) Bs3Panic_c32(void); /**< @copydoc Bs3Panic_c16 */
951BS3_DECL(void) Bs3Panic_c64(void); /**< @copydoc Bs3Panic_c16 */
952#define Bs3Panic BS3_CMN_NM(Bs3Panic) /**< Selects #Bs3Panic_c16, #Bs3Panic_c32 or #Bs3Panic_c64. */
953
954/**
955 * Shutdown the system, never returns.
956 *
957 * This currently only works for VMs. When running on real systems it will
958 * just halt the CPU.
959 */
960BS3_DECL(void) Bs3Shutdown_c16(void);
961BS3_DECL(void) Bs3Shutdown_c32(void); /**< @copydoc Bs3Shutdown_c16 */
962BS3_DECL(void) Bs3Shutdown_c64(void); /**< @copydoc Bs3Shutdown_c16 */
963#define Bs3Shutdown BS3_CMN_NM(Bs3Shutdown) /**< Selects #Bs3Shutdown_c16, #Bs3Shutdown_c32 or #Bs3Shutdown_c64. */
964
965/**
966 * Prints a 32-bit unsigned value as decimal to the screen.
967 *
968 * @param uValue The 32-bit value.
969 */
970BS3_DECL(void) Bs3PrintU32_c16(uint32_t uValue);
971BS3_DECL(void) Bs3PrintU32_c32(uint32_t uValue); /**< @copydoc Bs3PrintU32_c16 */
972BS3_DECL(void) Bs3PrintU32_c64(uint32_t uValue); /**< @copydoc Bs3PrintU32_c16 */
973#define Bs3PrintU32 BS3_CMN_NM(Bs3PrintU32) /**< Selects #Bs3PrintU32_c16, #Bs3PrintU32_c32 or #Bs3PrintU32_c64. */
974
975/**
976 * Prints a 32-bit unsigned value as hex to the screen.
977 *
978 * @param uValue The 32-bit value.
979 */
980BS3_DECL(void) Bs3PrintX32_c16(uint32_t uValue);
981BS3_DECL(void) Bs3PrintX32_c32(uint32_t uValue); /**< @copydoc Bs3PrintX32_c16 */
982BS3_DECL(void) Bs3PrintX32_c64(uint32_t uValue); /**< @copydoc Bs3PrintX32_c16 */
983#define Bs3PrintX32 BS3_CMN_NM(Bs3PrintX32) /**< Selects #Bs3PrintX32_c16, #Bs3PrintX32_c32 or #Bs3PrintX32_c64. */
984
985/**
986 * Formats and prints a string to the screen.
987 *
988 * See #Bs3StrFormatV_c16 for supported format types.
989 *
990 * @param pszFormat The format string.
991 * @param ... Format arguments.
992 */
993BS3_DECL(size_t) Bs3Printf_c16(const char BS3_FAR *pszFormat, ...);
994BS3_DECL(size_t) Bs3Printf_c32(const char BS3_FAR *pszFormat, ...); /**< @copydoc Bs3Printf_c16 */
995BS3_DECL(size_t) Bs3Printf_c64(const char BS3_FAR *pszFormat, ...); /**< @copydoc Bs3Printf_c16 */
996#define Bs3Printf BS3_CMN_NM(Bs3Printf) /**< Selects #Bs3Printf_c16, #Bs3Printf_c32 or #Bs3Printf_c64. */
997
998/**
999 * Formats and prints a string to the screen, va_list version.
1000 *
1001 * See #Bs3Format_c16 for supported format types.
1002 *
1003 * @param pszFormat The format string.
1004 * @param va Format arguments.
1005 */
1006BS3_DECL(size_t) Bs3PrintfV_c16(const char BS3_FAR *pszFormat, va_list va);
1007BS3_DECL(size_t) Bs3PrintfV_c32(const char BS3_FAR *pszFormat, va_list va); /**< @copydoc Bs3PrintfV_c16 */
1008BS3_DECL(size_t) Bs3PrintfV_c64(const char BS3_FAR *pszFormat, va_list va); /**< @copydoc Bs3PrintfV_c16 */
1009#define Bs3PrintfV BS3_CMN_NM(Bs3PrintfV) /**< Selects #Bs3PrintfV_c16, #Bs3PrintfV_c32 or #Bs3PrintfV_c64. */
1010
1011/**
1012 * Prints a string to the screen.
1013 *
1014 * @param pszString The string to print.
1015 */
1016BS3_DECL(void) Bs3PrintStr_c16(const char BS3_FAR *pszString);
1017BS3_DECL(void) Bs3PrintStr_c32(const char BS3_FAR *pszString); /**< @copydoc Bs3PrintStr_c16 */
1018BS3_DECL(void) Bs3PrintStr_c64(const char BS3_FAR *pszString); /**< @copydoc Bs3PrintStr_c16 */
1019#define Bs3PrintStr BS3_CMN_NM(Bs3PrintStr) /**< Selects #Bs3PrintStr_c16, #Bs3PrintStr_c32 or #Bs3PrintStr_c64. */
1020
1021/**
1022 * Prints a char to the screen.
1023 *
1024 * @param ch The character to print.
1025 */
1026BS3_DECL(void) Bs3PrintChr_c16(char ch);
1027BS3_DECL(void) Bs3PrintChr_c32(char ch); /**< @copydoc Bs3PrintChr_c16 */
1028BS3_DECL(void) Bs3PrintChr_c64(char ch); /**< @copydoc Bs3PrintChr_c16 */
1029#define Bs3PrintChr BS3_CMN_NM(Bs3PrintChr) /**< Selects #Bs3PrintChr_c16, #Bs3PrintChr_c32 or #Bs3PrintChr_c64. */
1030
1031
1032/**
1033 * An output function for #Bs3StrFormatV.
1034 *
1035 * @returns Number of characters written.
1036 * @param ch The character to write. Zero in the final call.
1037 * @param pvUser User argument supplied to #Bs3StrFormatV.
1038 */
1039typedef size_t BS3_CALL FNBS3STRFORMATOUTPUT(char ch, void BS3_FAR *pvUser);
1040/** Pointer to an output function for #Bs3StrFormatV. */
1041typedef FNBS3STRFORMATOUTPUT BS3_NEAR_CODE *PFNBS3STRFORMATOUTPUT;
1042
1043/**
1044 * Formats a string, sending the output to @a pfnOutput.
1045 *
1046 * Supported types:
1047 * - %RI8, %RI16, %RI32, %RI64
1048 * - %RU8, %RU16, %RU32, %RU64
1049 * - %RX8, %RX16, %RX32, %RX64
1050 * - %i, %d
1051 * - %u
1052 * - %x
1053 * - %c
1054 * - %p (far pointer)
1055 * - %s (far pointer)
1056 *
1057 * @returns Sum of @a pfnOutput return values.
1058 * @param pszFormat The format string.
1059 * @param va Format arguments.
1060 * @param pfnOutput The output function.
1061 * @param pvUser The user argument for the output function.
1062 */
1063BS3_DECL(size_t) Bs3StrFormatV_c16(const char BS3_FAR *pszFormat, va_list va,
1064 PFNBS3STRFORMATOUTPUT pfnOutput, void BS3_FAR *pvUser);
1065/** @copydoc Bs3StrFormatV_c16 */
1066BS3_DECL(size_t) Bs3StrFormatV_c32(const char BS3_FAR *pszFormat, va_list va,
1067 PFNBS3STRFORMATOUTPUT pfnOutput, void BS3_FAR *pvUser);
1068/** @copydoc Bs3StrFormatV_c16 */
1069BS3_DECL(size_t) Bs3StrFormatV_c64(const char BS3_FAR *pszFormat, va_list va,
1070 PFNBS3STRFORMATOUTPUT pfnOutput, void BS3_FAR *pvUser);
1071#define Bs3StrFormatV BS3_CMN_NM(Bs3StrFormatV) /**< Selects #Bs3StrFormatV_c16, #Bs3StrFormatV_c32 or #Bs3StrFormatV_c64. */
1072
1073/**
1074 * Formats a string into a buffer.
1075 *
1076 * See #Bs3Format_c16 for supported format types.
1077 *
1078 * @returns The length of the formatted string (excluding terminator).
1079 * This will be higher or equal to @c cbBuf in case of an overflow.
1080 * @param pszBuf The output buffer.
1081 * @param cbBuf The size of the output buffer.
1082 * @param pszFormat The format string.
1083 * @param va Format arguments.
1084 */
1085BS3_DECL(size_t) Bs3StrPrintfV_c16(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, va_list va);
1086/** @copydoc Bs3StrPrintfV_c16 */
1087BS3_DECL(size_t) Bs3StrPrintfV_c32(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, va_list va);
1088/** @copydoc Bs3StrPrintfV_c16 */
1089BS3_DECL(size_t) Bs3StrPrintfV_c64(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, va_list va);
1090#define Bs3StrPrintfV BS3_CMN_NM(Bs3StrPrintfV) /**< Selects #Bs3StrPrintfV_c16, #Bs3StrPrintfV_c32 or #Bs3StrPrintfV_c64. */
1091
1092/**
1093 * Formats a string into a buffer.
1094 *
1095 * See #Bs3Format_c16 for supported format types.
1096 *
1097 * @returns The length of the formatted string (excluding terminator).
1098 * This will be higher or equal to @c cbBuf in case of an overflow.
1099 * @param pszBuf The output buffer.
1100 * @param cbBuf The size of the output buffer.
1101 * @param pszFormat The format string.
1102 * @param ... Format arguments.
1103 */
1104BS3_DECL(size_t) Bs3StrPrintf_c16(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, ...);
1105/** @copydoc Bs3StrPrintf_c16 */
1106BS3_DECL(size_t) Bs3StrPrintf_c32(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, ...);
1107/** @copydoc Bs3StrPrintf_c16 */
1108BS3_DECL(size_t) Bs3StrPrintf_c64(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, ...);
1109#define Bs3StrPrintf BS3_CMN_NM(Bs3StrPrintf) /**< Selects #Bs3StrPrintf_c16, #Bs3StrPrintf_c32 or #Bs3StrPrintf_c64. */
1110
1111
1112/**
1113 * Finds the length of a zero terminated string.
1114 *
1115 * @returns String length in chars/bytes.
1116 * @param pszString The string to examine.
1117 */
1118BS3_DECL(size_t) Bs3StrLen_c16(const char BS3_FAR *pszString);
1119BS3_DECL(size_t) Bs3StrLen_c32(const char BS3_FAR *pszString); /** @copydoc Bs3StrLen_c16 */
1120BS3_DECL(size_t) Bs3StrLen_c64(const char BS3_FAR *pszString); /** @copydoc Bs3StrLen_c16 */
1121#define Bs3StrLen BS3_CMN_NM(Bs3StrLen) /**< Selects #Bs3StrLen_c16, #Bs3StrLen_c32 or #Bs3StrLen_c64. */
1122
1123/**
1124 * Finds the length of a zero terminated string, but with a max length.
1125 *
1126 * @returns String length in chars/bytes, or @a cchMax if no zero-terminator
1127 * was found before we reached the limit.
1128 * @param pszString The string to examine.
1129 * @param cchMax The max length to examine.
1130 */
1131BS3_DECL(size_t) Bs3StrNLen_c16(const char BS3_FAR *pszString, size_t cchMax);
1132BS3_DECL(size_t) Bs3StrNLen_c32(const char BS3_FAR *pszString, size_t cchMax); /** @copydoc Bs3StrNLen_c16 */
1133BS3_DECL(size_t) Bs3StrNLen_c64(const char BS3_FAR *pszString, size_t cchMax); /** @copydoc Bs3StrNLen_c16 */
1134#define Bs3StrNLen BS3_CMN_NM(Bs3StrNLen) /**< Selects #Bs3StrNLen_c16, #Bs3StrNLen_c32 or #Bs3StrNLen_c64. */
1135
1136/**
1137 * CRT style unsafe strcpy.
1138 *
1139 * @returns pszDst.
1140 * @param pszDst The destination buffer. Must be large enough to
1141 * hold the source string.
1142 * @param pszSrc The source string.
1143 */
1144BS3_DECL(char BS3_FAR *) Bs3StrCpy_c16(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc);
1145BS3_DECL(char BS3_FAR *) Bs3StrCpy_c32(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc); /** @copydoc Bs3StrCpy_c16 */
1146BS3_DECL(char BS3_FAR *) Bs3StrCpy_c64(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc); /** @copydoc Bs3StrCpy_c16 */
1147#define Bs3StrCpy BS3_CMN_NM(Bs3StrCpy) /**< Selects #Bs3StrCpy_c16, #Bs3StrCpy_c32 or #Bs3StrCpy_c64. */
1148
1149/**
1150 * CRT style memcpy.
1151 *
1152 * @returns pvDst
1153 * @param pvDst The destination buffer.
1154 * @param pvSrc The source buffer.
1155 * @param cbCopy The number of bytes to copy.
1156 */
1157BS3_DECL(void BS3_FAR *) Bs3MemCpy_c16(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy);
1158BS3_DECL(void BS3_FAR *) Bs3MemCpy_c32(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemCpy_c16 */
1159BS3_DECL(void BS3_FAR *) Bs3MemCpy_c64(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemCpy_c16 */
1160#define Bs3MemCpy BS3_CMN_NM(Bs3MemCpy) /**< Selects #Bs3MemCpy_c16, #Bs3MemCpy_c32 or #Bs3MemCpy_c64. */
1161
1162/**
1163 * GNU (?) style mempcpy.
1164 *
1165 * @returns pvDst + cbCopy
1166 * @param pvDst The destination buffer.
1167 * @param pvSrc The source buffer.
1168 * @param cbCopy The number of bytes to copy.
1169 */
1170BS3_DECL(void BS3_FAR *) Bs3MemPCpy_c16(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy);
1171BS3_DECL(void BS3_FAR *) Bs3MemPCpy_c32(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemPCpy_c16 */
1172BS3_DECL(void BS3_FAR *) Bs3MemPCpy_c64(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemPCpy_c16 */
1173#define Bs3MemPCpy BS3_CMN_NM(Bs3MemPCpy) /**< Selects #Bs3MemPCpy_c16, #Bs3MemPCpy_c32 or #Bs3MemPCpy_c64. */
1174
1175/**
1176 * CRT style memmove (overlapping buffers is fine).
1177 *
1178 * @returns pvDst
1179 * @param pvDst The destination buffer.
1180 * @param pvSrc The source buffer.
1181 * @param cbCopy The number of bytes to copy.
1182 */
1183BS3_DECL(void BS3_FAR *) Bs3MemMove_c16(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy);
1184BS3_DECL(void BS3_FAR *) Bs3MemMove_c32(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemMove_c16 */
1185BS3_DECL(void BS3_FAR *) Bs3MemMove_c64(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemMove_c16 */
1186#define Bs3MemMove BS3_CMN_NM(Bs3MemMove) /**< Selects #Bs3MemMove_c16, #Bs3MemMove_c32 or #Bs3MemMove_c64. */
1187
1188/**
1189 * BSD style bzero.
1190 *
1191 * @param pvDst The buffer to be zeroed.
1192 * @param cbDst The number of bytes to zero.
1193 */
1194BS3_DECL(void) Bs3MemZero_c16(void BS3_FAR *pvDst, size_t cbDst);
1195BS3_DECL(void) Bs3MemZero_c32(void BS3_FAR *pvDst, size_t cbDst); /** @copydoc Bs3MemZero_c16 */
1196BS3_DECL(void) Bs3MemZero_c64(void BS3_FAR *pvDst, size_t cbDst); /** @copydoc Bs3MemZero_c16 */
1197#define Bs3MemZero BS3_CMN_NM(Bs3MemZero) /**< Selects #Bs3MemZero_c16, #Bs3MemZero_c32 or #Bs3MemZero_c64. */
1198
1199
1200
1201/**
1202 * Equivalent to RTTestCreate + RTTestBanner.
1203 *
1204 * @param pszTest The test name.
1205 */
1206BS3_DECL(void) Bs3TestInit_c16(const char BS3_FAR *pszTest);
1207BS3_DECL(void) Bs3TestInit_c32(const char BS3_FAR *pszTest); /**< @copydoc Bs3TestInit_c16 */
1208BS3_DECL(void) Bs3TestInit_c64(const char BS3_FAR *pszTest); /**< @copydoc Bs3TestInit_c16 */
1209#define Bs3TestInit BS3_CMN_NM(Bs3TestInit) /**< Selects #Bs3TestInit_c16, #Bs3TestInit_c32 or #Bs3TestInit_c64. */
1210
1211
1212/**
1213 * Slab control structure list head.
1214 *
1215 * The slabs on the list must all have the same chunk size.
1216 */
1217typedef struct BS3SLABHEAD
1218{
1219 /** Pointer to the first slab. */
1220 BS3_XPTR_MEMBER(struct BS3SLABCTL, pFirst);
1221 /** The allocation chunk size. */
1222 uint16_t cbChunk;
1223 /** Number of slabs in the list. */
1224 uint16_t cSlabs;
1225 /** Number of chunks in the list. */
1226 uint32_t cChunks;
1227 /** Number of free chunks. */
1228 uint32_t cFreeChunks;
1229} BS3SLABHEAD;
1230/** Pointer to a slab list head. */
1231typedef BS3SLABHEAD BS3_FAR *PBS3SLABHEAD;
1232
1233/**
1234 * Allocation slab control structure.
1235 *
1236 * This may live at the start of the slab for 4KB slabs, while in a separate
1237 * static location for the larger ones.
1238 */
1239typedef struct BS3SLABCTL
1240{
1241 /** Pointer to the next slab control structure in this list. */
1242 BS3_XPTR_MEMBER(struct BS3SLABCTL, pNext);
1243 /** Pointer to the slab list head. */
1244 BS3_XPTR_MEMBER(BS3SLABHEAD, pHead);
1245 /** The base address of the slab. */
1246 BS3_XPTR_MEMBER(uint8_t, pbStart);
1247 /** Number of chunks in this slab. */
1248 uint16_t cChunks;
1249 /** Number of currently free chunks. */
1250 uint16_t cFreeChunks;
1251 /** The chunk size. */
1252 uint16_t cbChunk;
1253 /** The shift count corresponding to cbChunk.
1254 * This is for turning a chunk number into a byte offset and vice versa. */
1255 uint16_t cChunkShift;
1256 /** Bitmap where set bits indicates allocated blocks (variable size,
1257 * multiple of 4). */
1258 uint8_t bmAllocated[4];
1259} BS3SLABCTL;
1260/** Pointer to a bs3kit slab control structure. */
1261typedef BS3SLABCTL BS3_FAR *PBS3SLABCTL;
1262
1263/** The chunks must all be in the same 16-bit segment tile. */
1264#define BS3_SLAB_ALLOC_F_SAME_TILE UINT16_C(0x0001)
1265
1266/**
1267 * Initializes a slab.
1268 *
1269 * @param pSlabCtl The slab control structure to initialize.
1270 * @param cbSlabCtl The size of the slab control structure.
1271 * @param uFlatSlabPtr The base address of the slab.
1272 * @param cbSlab The size of the slab.
1273 * @param cbChunk The chunk size.
1274 */
1275BS3_DECL(void) Bs3SlabInit_c16(PBS3SLABCTL pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk);
1276/** @copydoc Bs3SlabInit_c16 */
1277BS3_DECL(void) Bs3SlabInit_c32(PBS3SLABCTL pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk);
1278/** @copydoc Bs3SlabInit_c16 */
1279BS3_DECL(void) Bs3SlabInit_c64(PBS3SLABCTL pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk);
1280#define Bs3SlabInit BS3_CMN_NM(Bs3SlabInit) /**< Selects #Bs3SlabInit_c16, #Bs3SlabInit_c32 or #Bs3SlabInit_c64. */
1281
1282/**
1283 * Allocates one chunk from a slab.
1284 *
1285 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
1286 * @param pSlabCtl The slab constrol structure to allocate from.
1287 */
1288BS3_DECL(void BS3_FAR *) Bs3SlabAlloc_c16(PBS3SLABCTL pSlabCtl);
1289BS3_DECL(void BS3_FAR *) Bs3SlabAlloc_c32(PBS3SLABCTL pSlabCtl); /**< @copydoc Bs3SlabAlloc_c16 */
1290BS3_DECL(void BS3_FAR *) Bs3SlabAlloc_c64(PBS3SLABCTL pSlabCtl); /**< @copydoc Bs3SlabAlloc_c16 */
1291#define Bs3SlabAlloc BS3_CMN_NM(Bs3SlabAlloc) /**< Selects #Bs3SlabAlloc_c16, #Bs3SlabAlloc_c32 or #Bs3SlabAlloc_c64. */
1292
1293/**
1294 * Allocates one or more chunks rom a slab.
1295 *
1296 * @returns Pointer to the request number of chunks on success, NULL if we're
1297 * out of chunks.
1298 * @param pSlabCtl The slab constrol structure to allocate from.
1299 * @param cChunks The number of contiguous chunks we want.
1300 * @param fFlags Flags, see BS3_SLAB_ALLOC_F_XXX
1301 */
1302BS3_DECL(void BS3_FAR *) Bs3SlabAllocEx_c16(PBS3SLABCTL pSlabCtl, uint16_t cChunks, uint16_t fFlags);
1303BS3_DECL(void BS3_FAR *) Bs3SlabAllocEx_c32(PBS3SLABCTL pSlabCtl, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabAllocEx_c16 */
1304BS3_DECL(void BS3_FAR *) Bs3SlabAllocEx_c64(PBS3SLABCTL pSlabCtl, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabAllocEx_c16 */
1305#define Bs3SlabAllocEx BS3_CMN_NM(Bs3SlabAllocEx) /**< Selects #Bs3SlabAllocEx_c16, #Bs3SlabAllocEx_c32 or #Bs3SlabAllocEx_c64. */
1306
1307/**
1308 * Frees one or more chunks from a slab.
1309 *
1310 * @returns Number of chunks actually freed. When correctly used, this will
1311 * match the @a cChunks parameter, of course.
1312 * @param pSlabCtl The slab constrol structure to free from.
1313 * @param uFlatChunkPtr The flat address of the chunks to free.
1314 * @param cChunks The number of contiguous chunks to free.
1315 */
1316BS3_DECL(uint16_t) Bs3SlabFree_c16(PBS3SLABCTL pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks);
1317BS3_DECL(uint16_t) Bs3SlabFree_c32(PBS3SLABCTL pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks); /**< @copydoc Bs3SlabFree_c16 */
1318BS3_DECL(uint16_t) Bs3SlabFree_c64(PBS3SLABCTL pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks); /**< @copydoc Bs3SlabFree_c16 */
1319#define Bs3SlabFree BS3_CMN_NM(Bs3SlabFree) /**< Selects #Bs3SlabFree_c16, #Bs3SlabFree_c32 or #Bs3SlabFree_c64. */
1320
1321
1322/**
1323 * Initializes the given slab list head.
1324 *
1325 * @param pHead The slab list head.
1326 * @param cbChunk The chunk size.
1327 */
1328BS3_DECL(void) Bs3SlabListInit_c16(PBS3SLABHEAD pHead, uint16_t cbChunk);
1329BS3_DECL(void) Bs3SlabListInit_c32(PBS3SLABHEAD pHead, uint16_t cbChunk); /**< @copydoc Bs3SlabListInit_c16 */
1330BS3_DECL(void) Bs3SlabListInit_c64(PBS3SLABHEAD pHead, uint16_t cbChunk); /**< @copydoc Bs3SlabListInit_c16 */
1331#define Bs3SlabListInit BS3_CMN_NM(Bs3SlabListInit) /**< Selects #Bs3SlabListInit_c16, #Bs3SlabListInit_c32 or #Bs3SlabListInit_c64. */
1332
1333/**
1334 * Adds an initialized slab control structure to the list.
1335 *
1336 * @param pHead The slab list head to add it to.
1337 * @param pSlabCtl The slab control structure to add.
1338 */
1339BS3_DECL(void) Bs3SlabListAdd_c16(PBS3SLABHEAD pHead, PBS3SLABCTL pSlabCtl);
1340/** @copydoc Bs3SlabListAdd_c16 */
1341BS3_DECL(void) Bs3SlabListAdd_c32(PBS3SLABHEAD pHead, PBS3SLABCTL pSlabCtl);
1342/** @copydoc Bs3SlabListAdd_c16 */
1343BS3_DECL(void) Bs3SlabListAdd_c64(PBS3SLABHEAD pHead, PBS3SLABCTL pSlabCtl);
1344#define Bs3SlabListAdd BS3_CMN_NM(Bs3SlabListAdd) /**< Selects #Bs3SlabListAdd_c16, #Bs3SlabListAdd_c32 or #Bs3SlabListAdd_c64. */
1345
1346/**
1347 * Allocates one chunk.
1348 *
1349 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
1350 * @param pHead The slab list to allocate from.
1351 */
1352BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c16(PBS3SLABHEAD pHead);
1353BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c32(PBS3SLABHEAD pHead); /**< @copydoc Bs3SlabListAlloc_c16 */
1354BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c64(PBS3SLABHEAD pHead); /**< @copydoc Bs3SlabListAlloc_c16 */
1355#define Bs3SlabListAlloc BS3_CMN_NM(Bs3SlabListAlloc) /**< Selects #Bs3SlabListAlloc_c16, #Bs3SlabListAlloc_c32 or #Bs3SlabListAlloc_c64. */
1356
1357/**
1358 * Allocates one or more chunks.
1359 *
1360 * @returns Pointer to the request number of chunks on success, NULL if we're
1361 * out of chunks.
1362 * @param pHead The slab list to allocate from.
1363 * @param cChunks The number of contiguous chunks we want.
1364 * @param fFlags Flags, see BS3_SLAB_ALLOC_F_XXX
1365 */
1366BS3_DECL(void BS3_FAR *) Bs3SlabListAllocEx_c16(PBS3SLABHEAD pHead, uint16_t cChunks, uint16_t fFlags);
1367BS3_DECL(void BS3_FAR *) Bs3SlabListAllocEx_c32(PBS3SLABHEAD pHead, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabListAllocEx_c16 */
1368BS3_DECL(void BS3_FAR *) Bs3SlabListAllocEx_c64(PBS3SLABHEAD pHead, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabListAllocEx_c16 */
1369#define Bs3SlabListAllocEx BS3_CMN_NM(Bs3SlabListAllocEx) /**< Selects #Bs3SlabListAllocEx_c16, #Bs3SlabListAllocEx_c32 or #Bs3SlabListAllocEx_c64. */
1370
1371/**
1372 * Frees one or more chunks from a slab list.
1373 *
1374 * @param pHead The slab list to allocate from.
1375 * @param pvChunks Pointer to the first chunk to free.
1376 * @param cChunks The number of contiguous chunks to free.
1377 */
1378BS3_DECL(void) Bs3SlabListFree_c16(PBS3SLABHEAD pHead, void BS3_FAR *pvChunks, uint16_t cChunks);
1379BS3_DECL(void) Bs3SlabListFree_c32(PBS3SLABHEAD pHead, void BS3_FAR *pvChunks, uint16_t cChunks); /**< @copydoc Bs3SlabListFree_c16 */
1380BS3_DECL(void) Bs3SlabListFree_c64(PBS3SLABHEAD pHead, void BS3_FAR *pvChunks, uint16_t cChunks); /**< @copydoc Bs3SlabListFree_c16 */
1381#define Bs3SlabListFree BS3_CMN_NM(Bs3SlabListFree) /**< Selects #Bs3SlabListFree_c16, #Bs3SlabListFree_c32 or #Bs3SlabListFree_c64. */
1382
1383/**
1384 * Allocation addressing constraints.
1385 */
1386typedef enum BS3MEMKIND
1387{
1388 /** Invalid zero type. */
1389 BS3MEMKIND_INVALID = 0,
1390 /** Real mode addressable memory. */
1391 BS3MEMKIND_REAL,
1392 /** Memory addressable using the 16-bit protected mode tiling. */
1393 BS3MEMKIND_TILED,
1394 /** Memory addressable using 32-bit flat addressing. */
1395 BS3MEMKIND_FLAT32,
1396 /** Memory addressable using 64-bit flat addressing. */
1397 BS3MEMKIND_FLAT64,
1398 /** End of valid types. */
1399 BS3MEMKIND_END,
1400} BS3MEMKIND;
1401
1402/**
1403 * Allocates low memory.
1404 *
1405 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
1406 * @param enmKind The kind of addressing constraints imposed on the
1407 * allocation.
1408 * @param cb How much to allocate. Must be 4KB or less.
1409 */
1410BS3_DECL(void BS3_FAR *) Bs3MemAlloc_c16(BS3MEMKIND enmKind, size_t cb);
1411BS3_DECL(void BS3_FAR *) Bs3MemAlloc_c32(BS3MEMKIND enmKind, size_t cb); /**< @copydoc Bs3MemAlloc_c16 */
1412BS3_DECL(void BS3_FAR *) Bs3MemAlloc_c64(BS3MEMKIND enmKind, size_t cb); /**< @copydoc Bs3MemAlloc_c16 */
1413#define Bs3MemAlloc BS3_CMN_NM(Bs3MemAlloc) /**< Selects #Bs3MemAlloc_c16, #Bs3MemAlloc_c32 or #Bs3MemAlloc_c64. */
1414
1415/**
1416 * Allocates zero'ed memory.
1417 *
1418 * @param enmKind The kind of addressing constraints imposed on the
1419 * allocation.
1420 * @param cb How much to allocate. Must be 4KB or less.
1421 */
1422BS3_DECL(void BS3_FAR *) Bs3MemAllocZ_c16(BS3MEMKIND enmKind, size_t cb);
1423BS3_DECL(void BS3_FAR *) Bs3MemAllocZ_c32(BS3MEMKIND enmKind, size_t cb); /**< @copydoc Bs3MemAllocZ_c16 */
1424BS3_DECL(void BS3_FAR *) Bs3MemAllocZ_c64(BS3MEMKIND enmKind, size_t cb); /**< @copydoc Bs3MemAllocZ_c16 */
1425#define Bs3MemAllocZ BS3_CMN_NM(Bs3MemAllocZ) /**< Selects #Bs3MemAllocZ_c16, #Bs3MemAllocZ_c32 or #Bs3MemAllocZ_c64. */
1426
1427/**
1428 * Frees memory.
1429 *
1430 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
1431 * @param pv The memory to free (returned by #Bs3MemAlloc).
1432 * @param cb The size of the allocation.
1433 */
1434BS3_DECL(void) Bs3MemFree_c16(void BS3_FAR *pv, size_t cb);
1435BS3_DECL(void) Bs3MemFree_c32(void BS3_FAR *pv, size_t cb); /**< @copydoc Bs3MemFree_c16 */
1436BS3_DECL(void) Bs3MemFree_c64(void BS3_FAR *pv, size_t cb); /**< @copydoc Bs3MemFree_c16 */
1437#define Bs3MemFree BS3_CMN_NM(Bs3MemFree) /**< Selects #Bs3MemFree_c16, #Bs3MemFree_c32 or #Bs3MemFree_c64. */
1438
1439
1440/**
1441 * Enables the A20 gate.
1442 */
1443BS3_DECL(void) Bs3A20Enable_c16(void);
1444BS3_DECL(void) Bs3A20Enable_c32(void); /**< @copydoc Bs3A20Enable_c16 */
1445BS3_DECL(void) Bs3A20Enable_c64(void); /**< @copydoc Bs3A20Enable_c16 */
1446#define Bs3A20Enable BS3_CMN_NM(Bs3A20Enable) /**< Selects #Bs3A20Enable_c16, #Bs3A20Enable_c32 or #Bs3A20Enable_c64. */
1447
1448/**
1449 * Enables the A20 gate via the keyboard controller
1450 */
1451BS3_DECL(void) Bs3A20EnableViaKbd_c16(void);
1452BS3_DECL(void) Bs3A20EnableViaKbd_c32(void); /**< @copydoc Bs3A20EnableViaKbd_c16 */
1453BS3_DECL(void) Bs3A20EnableViaKbd_c64(void); /**< @copydoc Bs3A20EnableViaKbd_c16 */
1454#define Bs3A20EnableViaKbd BS3_CMN_NM(Bs3A20EnableViaKbd) /**< Selects #Bs3A20EnableViaKbd_c16, #Bs3A20EnableViaKbd_c32 or #Bs3A20EnableViaKbd_c64. */
1455
1456/**
1457 * Enables the A20 gate via the PS/2 control port A.
1458 */
1459BS3_DECL(void) Bs3A20EnableViaPortA_c16(void);
1460BS3_DECL(void) Bs3A20EnableViaPortA_c32(void); /**< @copydoc Bs3A20EnableViaPortA_c16 */
1461BS3_DECL(void) Bs3A20EnableViaPortA_c64(void); /**< @copydoc Bs3A20EnableViaPortA_c16 */
1462#define Bs3A20EnableViaPortA BS3_CMN_NM(Bs3A20EnableViaPortA) /**< Selects #Bs3A20EnableViaPortA_c16, #Bs3A20EnableViaPortA_c32 or #Bs3A20EnableViaPortA_c64. */
1463
1464/**
1465 * Disables the A20 gate.
1466 */
1467BS3_DECL(void) Bs3A20Disable_c16(void);
1468BS3_DECL(void) Bs3A20Disable_c32(void); /**< @copydoc Bs3A20Disable_c16 */
1469BS3_DECL(void) Bs3A20Disable_c64(void); /**< @copydoc Bs3A20Disable_c16 */
1470#define Bs3A20Disable BS3_CMN_NM(Bs3A20Disable) /**< Selects #Bs3A20Disable_c16, #Bs3A20Disable_c32 or #Bs3A20Disable_c64. */
1471
1472/**
1473 * Disables the A20 gate via the keyboard controller
1474 */
1475BS3_DECL(void) Bs3A20DisableViaKbd_c16(void);
1476BS3_DECL(void) Bs3A20DisableViaKbd_c32(void); /**< @copydoc Bs3A20DisableViaKbd_c16 */
1477BS3_DECL(void) Bs3A20DisableViaKbd_c64(void); /**< @copydoc Bs3A20DisableViaKbd_c16 */
1478#define Bs3A20DisableViaKbd BS3_CMN_NM(Bs3A20DisableViaKbd) /**< Selects #Bs3A20DisableViaKbd_c16, #Bs3A20DisableViaKbd_c32 or #Bs3A20DisableViaKbd_c64. */
1479
1480/**
1481 * Disables the A20 gate via the PS/2 control port A.
1482 */
1483BS3_DECL(void) Bs3A20DisableViaPortA_c16(void);
1484BS3_DECL(void) Bs3A20DisableViaPortA_c32(void); /**< @copydoc Bs3A20DisableViaPortA_c16 */
1485BS3_DECL(void) Bs3A20DisableViaPortA_c64(void); /**< @copydoc Bs3A20DisableViaPortA_c16 */
1486#define Bs3A20DisableViaPortA BS3_CMN_NM(Bs3A20DisableViaPortA) /**< Selects #Bs3A20DisableViaPortA_c16, #Bs3A20DisableViaPortA_c32 or #Bs3A20DisableViaPortA_c64. */
1487
1488
1489/**
1490 * Initializes root page tables for page protected mode (PP16, PP32).
1491 *
1492 * @returns IPRT status code.
1493 * @remarks Must not be called in real-mode!
1494 */
1495BS3_DECL(int) Bs3PagingInitRootForPP_c16(void);
1496BS3_DECL(int) Bs3PagingInitRootForPP_c32(void); /**< @copydoc Bs3PagingInitRootForPP_c16 */
1497BS3_DECL(int) Bs3PagingInitRootForPP_c64(void); /**< @copydoc Bs3PagingInitRootForPP_c16 */
1498#define Bs3PagingInitRootForPP BS3_CMN_NM(Bs3PagingInitRootForPP) /**< Selects #Bs3PagingInitRootForPP_c16, #Bs3PagingInitRootForPP_c32 or #Bs3PagingInitRootForPP_c64. */
1499
1500/**
1501 * Initializes root page tables for PAE page protected mode (PAE16, PAE32).
1502 *
1503 * @returns IPRT status code.
1504 * @remarks The default long mode page tables depends on the PAE ones.
1505 * @remarks Must not be called in real-mode!
1506 */
1507BS3_DECL(int) Bs3PagingInitRootForPAE_c16(void);
1508BS3_DECL(int) Bs3PagingInitRootForPAE_c32(void); /**< @copydoc Bs3PagingInitRootForPAE_c16 */
1509BS3_DECL(int) Bs3PagingInitRootForPAE_c64(void); /**< @copydoc Bs3PagingInitRootForPAE_c16 */
1510#define Bs3PagingInitRootForPAE BS3_CMN_NM(Bs3PagingInitRootForPAE) /**< Selects #Bs3PagingInitRootForPAE_c16, #Bs3PagingInitRootForPAE_c32 or #Bs3PagingInitRootForPAE_c64. */
1511
1512/**
1513 * Initializes root page tables for long mode (LM16, LM32, LM64).
1514 *
1515 * @returns IPRT status code.
1516 * @remarks The default long mode page tables depends on the PAE ones.
1517 * @remarks Must not be called in real-mode!
1518 */
1519BS3_DECL(int) Bs3PagingInitRootForLM_c16(void);
1520BS3_DECL(int) Bs3PagingInitRootForLM_c32(void); /**< @copydoc Bs3PagingInitRootForLM_c16 */
1521BS3_DECL(int) Bs3PagingInitRootForLM_c64(void); /**< @copydoc Bs3PagingInitRootForLM_c16 */
1522#define Bs3PagingInitRootForLM BS3_CMN_NM(Bs3PagingInitRootForLM) /**< Selects #Bs3PagingInitRootForLM_c16, #Bs3PagingInitRootForLM_c32 or #Bs3PagingInitRootForLM_c64. */
1523
1524
1525/**
1526 * Waits for the keyboard controller to become ready.
1527 */
1528BS3_DECL(void) Bs3KbdWait_c16(void);
1529BS3_DECL(void) Bs3KbdWait_c32(void); /**< @copydoc Bs3KbdWait_c16 */
1530BS3_DECL(void) Bs3KbdWait_c64(void); /**< @copydoc Bs3KbdWait_c16 */
1531#define Bs3KbdWait BS3_CMN_NM(Bs3KbdWait) /**< Selects #Bs3KbdWait_c16, #Bs3KbdWait_c32 or #Bs3KbdWait_c64. */
1532
1533/**
1534 * Sends a read command to the keyboard controller and gets the result.
1535 *
1536 * The caller is responsible for making sure the keyboard controller is ready
1537 * for a command (call #Bs3KbdWait if unsure).
1538 *
1539 * @returns The value read is returned (in al).
1540 * @param bCmd The read command.
1541 */
1542BS3_DECL(uint8_t) Bs3KbdRead_c16(uint8_t bCmd);
1543BS3_DECL(uint8_t) Bs3KbdRead_c32(uint8_t bCmd); /**< @copydoc Bs3KbdRead_c16 */
1544BS3_DECL(uint8_t) Bs3KbdRead_c64(uint8_t bCmd); /**< @copydoc Bs3KbdRead_c16 */
1545#define Bs3KbdRead BS3_CMN_NM(Bs3KbdRead) /**< Selects #Bs3KbdRead_c16, #Bs3KbdRead_c32 or #Bs3KbdRead_c64. */
1546
1547/**
1548 * Sends a write command to the keyboard controller and then sends the data.
1549 *
1550 * The caller is responsible for making sure the keyboard controller is ready
1551 * for a command (call #Bs3KbdWait if unsure).
1552 *
1553 * @param bCmd The write command.
1554 * @param bData The data to write.
1555 */
1556BS3_DECL(void) Bs3KbdWrite_c16(uint8_t bCmd, uint8_t bData);
1557BS3_DECL(void) Bs3KbdWrite_c32(uint8_t bCmd, uint8_t bData); /**< @copydoc Bs3KbdWrite_c16 */
1558BS3_DECL(void) Bs3KbdWrite_c64(uint8_t bCmd, uint8_t bData); /**< @copydoc Bs3KbdWrite_c16 */
1559#define Bs3KbdWrite BS3_CMN_NM(Bs3KbdWrite) /**< Selects #Bs3KbdWrite_c16, #Bs3KbdWrite_c32 or #Bs3KbdWrite_c64. */
1560
1561/** @} */
1562
1563
1564/**
1565 * Initializes the REAL and TILED memory pools.
1566 */
1567BS3_DECL(void) Bs3InitMemory_rm(void);
1568
1569
1570/** @defgroup grp_bs3kit_mode Mode Specific Functions and Data
1571 *
1572 * The mode specific functions come in bit count variations and CPU mode
1573 * variations. The bs3kit-template-header.h/mac defines the BS3_NM macro to
1574 * mangle a function or variable name according to the target CPU mode. In
1575 * non-templated code, it's common to spell the name out in full.
1576 *
1577 * @{
1578 */
1579
1580
1581/** @} */
1582
1583RT_C_DECLS_END
1584
1585
1586#endif
1587
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