VirtualBox

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

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

bs3kit: Working 16 and 64 bit PrintChr system call, fixed/documented 64-bit calls.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 88.7 KB
 
1/* $Id: bs3kit.h 59287 2016-01-08 10:08: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.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef ___bs3kit_h
28#define ___bs3kit_h
29
30#ifndef DOXYGEN_RUNNING
31# define IN_RING0
32#endif
33#include <iprt/cdefs.h>
34#include <iprt/types.h>
35#ifndef DOXYGEN_RUNNING
36# undef IN_RING0
37#endif
38
39/*
40 * We may want to reuse some IPRT code in the common name space, so we
41 * redefine the RT_MANGLER to work like BS3_CMN_NM. (We cannot use
42 * BS3_CMN_NM yet, as we need to include IPRT headers with function
43 * declarations before we can define it. Thus the duplciate effort.)
44 */
45#define RT_MANGLER(a_Name) RT_CONCAT3(a_Name,_c,ARCH_BITS)
46#include <iprt/mangling.h>
47#include <iprt/x86.h>
48#include <iprt/err.h>
49
50
51
52RT_C_DECLS_BEGIN
53
54/** @defgroup grp_bs3kit BS3Kit
55 * @{ */
56
57
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/** @def BS3_FAR_DATA
283 * For indicating far 16-bit external data, i.e. in a segment other than DATA16.
284 * Does nothing in 32-bit and 64-bit code. */
285#ifdef M_I86
286# define BS3_FAR __far
287# define BS3_NEAR __near
288# define BS3_FAR_CODE __far
289# define BS3_NEAR_CODE __near
290# define BS3_FAR_DATA __far
291#else
292# define BS3_FAR
293# define BS3_NEAR
294# define BS3_FAR_CODE
295# define BS3_NEAR_CODE
296# define BS3_FAR_DATA
297#endif
298
299#if ARCH_BITS == 16 || defined(DOXYGEN_RUNNING)
300/** @def BS3_FP_SEG
301 * Get the selector (segment) part of a far pointer.
302 * @returns selector.
303 * @param a_pv Far pointer.
304 */
305# define BS3_FP_SEG(a_pv) ((uint16_t)(__segment)(void BS3_FAR *)(a_pv))
306/** @def BS3_FP_OFF
307 * Get the segment offset part of a far pointer.
308 * @returns offset.
309 * @param a_pv Far pointer.
310 */
311# define BS3_FP_OFF(a_pv) ((uint16_t)(void __near *)(a_pv))
312/** @def BS3_FP_MAKE
313 * Create a far pointer.
314 * @returns selector.
315 * @param a_pv Far pointer.
316 */
317# define BS3_FP_MAKE(a_uSeg, a_off) (((__segment)(a_uSeg)) :> ((void __near *)(a_off)))
318#endif
319
320/** @def BS3_CALL
321 * The calling convension used by BS3 functions. */
322#if ARCH_BITS != 64
323# define BS3_CALL __cdecl
324#elif !defined(_MSC_VER)
325# define BS3_CALL __attribute__((__ms_abi__))
326#else
327# define BS3_CALL
328#endif
329
330/** @def IN_BS3KIT
331 * Indicates that we're in the same link job as the BS3Kit code. */
332#ifdef DOXYGEN_RUNNING
333# define IN_BS3KIT
334#endif
335
336/** @def BS3_DECL
337 * Declares a BS3Kit function.
338 *
339 * Until we outgrow BS3TEXT16, we use all near functions in 16-bit.
340 *
341 * @param a_Type The return type. */
342#ifdef IN_BS3KIT
343# define BS3_DECL(a_Type) DECLEXPORT(a_Type) BS3_NEAR_CODE BS3_CALL
344#else
345# define BS3_DECL(a_Type) DECLIMPORT(a_Type) BS3_NEAR_CODE BS3_CALL
346#endif
347
348/** @def BS3_DECL_CALLBACK
349 * Declares a BS3Kit callback function (typically static).
350 *
351 * Until we outgrow BS3TEXT16, we use all near functions in 16-bit.
352 *
353 * @param a_Type The return type. */
354#ifdef IN_BS3KIT
355# define BS3_DECL_CALLBACK(a_Type) a_Type BS3_NEAR_CODE BS3_CALL
356#else
357# define BS3_DECL_CALLBACK(a_Type) a_Type BS3_NEAR_CODE BS3_CALL
358#endif
359
360/**
361 * Constructs a common name.
362 *
363 * Example: BS3_CMN_NM(Bs3Shutdown)
364 *
365 * @param a_Name The name of the function or global variable.
366 */
367#define BS3_CMN_NM(a_Name) RT_CONCAT3(a_Name,_c,ARCH_BITS)
368
369/**
370 * Constructs a data name.
371 *
372 * Example: extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdt)
373 *
374 * @param a_Name The name of the global variable.
375 */
376#if ARCH_BITS == 64
377# define BS3_DATA_NM(a_Name) RT_CONCAT(_,a_Name)
378#else
379# define BS3_DATA_NM(a_Name) a_Name
380#endif
381
382/** @def BS3_MSC64_FIXUP_HACK
383 * Used to avoid IMAGE_REL_AMD64_ADDR32NB fixups where the compiler tries to
384 * make use of __ImageBase as a base pointer instead of emitting rip relative
385 * accesses. Happens when there are a bunch of global data accesses in the same
386 * function, probably to save space.
387 *
388 * The volatile variable in the lambda fixes it.
389 */
390#if _MSC_VER && ARCH_BITS == 64
391# define BS3_MSC64_FIXUP_HACK(a_BaseType, a_Data) \
392 ([]() -> a_BaseType * \
393 { \
394 a_BaseType * volatile x = a_Data; \
395 return x; \
396 }())
397
398#else
399# define BS3_MSC64_FIXUP_HACK(a_BaseType, a_Data) (a_Data)
400#endif
401
402
403/**
404 * Template for createing a pointer union type.
405 * @param a_BaseName The base type name.
406 * @param a_Modifier The type modifier.
407 */
408#define BS3_PTR_UNION_TEMPLATE(a_BaseName, a_Modifiers) \
409 typedef union a_BaseName \
410 { \
411 /** Pointer into the void. */ \
412 a_Modifiers void BS3_FAR *pv; \
413 /** As a signed integer. */ \
414 intptr_t i; \
415 /** As an unsigned integer. */ \
416 uintptr_t u; \
417 /** Pointer to char value. */ \
418 a_Modifiers char BS3_FAR *pch; \
419 /** Pointer to char value. */ \
420 a_Modifiers unsigned char BS3_FAR *puch; \
421 /** Pointer to a int value. */ \
422 a_Modifiers int BS3_FAR *pi; \
423 /** Pointer to a unsigned int value. */ \
424 a_Modifiers unsigned int BS3_FAR *pu; \
425 /** Pointer to a long value. */ \
426 a_Modifiers long BS3_FAR *pl; \
427 /** Pointer to a long value. */ \
428 a_Modifiers unsigned long BS3_FAR *pul; \
429 /** Pointer to a memory size value. */ \
430 a_Modifiers size_t BS3_FAR *pcb; \
431 /** Pointer to a byte value. */ \
432 a_Modifiers uint8_t BS3_FAR *pb; \
433 /** Pointer to a 8-bit unsigned value. */ \
434 a_Modifiers uint8_t BS3_FAR *pu8; \
435 /** Pointer to a 16-bit unsigned value. */ \
436 a_Modifiers uint16_t BS3_FAR *pu16; \
437 /** Pointer to a 32-bit unsigned value. */ \
438 a_Modifiers uint32_t BS3_FAR *pu32; \
439 /** Pointer to a 64-bit unsigned value. */ \
440 a_Modifiers uint64_t BS3_FAR *pu64; \
441 /** Pointer to a UTF-16 character. */ \
442 a_Modifiers RTUTF16 BS3_FAR *pwc; \
443 /** Pointer to a UUID character. */ \
444 a_Modifiers RTUUID BS3_FAR *pUuid; \
445 } a_BaseName; \
446 /** Pointer to a pointer union. */ \
447 typedef a_BaseName *RT_CONCAT(P,a_BaseName)
448BS3_PTR_UNION_TEMPLATE(BS3PTRUNION, RT_NOTHING);
449BS3_PTR_UNION_TEMPLATE(BS3CPTRUNION, const);
450BS3_PTR_UNION_TEMPLATE(BS3VPTRUNION, volatile);
451BS3_PTR_UNION_TEMPLATE(BS3CVPTRUNION, const volatile);
452
453
454/** The system call vector. */
455#define BS3_TRAP_SYSCALL UINT8_C(0x20)
456
457/** @name System call numbers (ax).
458 * Paramenters are generally passed in registers specific to each system call.
459 * @{ */
460/** Print char (cl). */
461#define BS3_SYSCALL_PRINT_CHR UINT16_C(0x0001)
462/** Print string (pointer in ds:[e]si, length in cx). */
463#define BS3_SYSCALL_PRINT_STR UINT16_C(0x0002)
464/** Switch to ring-0. */
465#define BS3_SYSCALL_TO_RING0 UINT16_C(0x0003)
466/** Switch to ring-1. */
467#define BS3_SYSCALL_TO_RING1 UINT16_C(0x0004)
468/** Switch to ring-2. */
469#define BS3_SYSCALL_TO_RING2 UINT16_C(0x0005)
470/** Switch to ring-3. */
471#define BS3_SYSCALL_TO_RING3 UINT16_C(0x0006)
472/** @} */
473
474
475
476/** @defgroup grp_bs3kit_system System structures
477 * @{ */
478/** The GDT, indexed by BS3_SEL_XXX shifted by 3. */
479extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdt)[(BS3_SEL_GDT_LIMIT + 1) / 8];
480
481extern X86DESC64 BS3_FAR_DATA BS3_DATA_NM(Bs3Gdt_Ldt); /**< @see BS3_SEL_LDT */
482extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss16); /**< @see BS3_SEL_TSS16 */
483extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss16DoubleFault); /**< @see BS3_SEL_TSS16_DF */
484extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss16Spare0); /**< @see BS3_SEL_TSS16_SPARE0 */
485extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss16Spare1); /**< @see BS3_SEL_TSS16_SPARE1 */
486extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss32); /**< @see BS3_SEL_TSS32 */
487extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss32DoubleFault); /**< @see BS3_SEL_TSS32_DF */
488extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss32Spare0); /**< @see BS3_SEL_TSS32_SPARE0 */
489extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss32Spare1); /**< @see BS3_SEL_TSS32_SPARE1 */
490extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss32IobpIntRedirBm); /**< @see BS3_SEL_TSS32_IOBP_IRB */
491extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss32IntRedirBm); /**< @see BS3_SEL_TSS32_IRB */
492extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss64); /**< @see BS3_SEL_TSS64 */
493extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss64Spare0); /**< @see BS3_SEL_TSS64_SPARE0 */
494extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss64Spare1); /**< @see BS3_SEL_TSS64_SPARE1 */
495extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_Tss64Iobp); /**< @see BS3_SEL_TSS64_IOBP */
496extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_MMIO16); /**< @see BS3_SEL_VMMDEV_MMIO16 */
497
498extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_First); /**< @see BS3_SEL_R0_FIRST */
499extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS16); /**< @see BS3_SEL_R0_CS16 */
500extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_DS16); /**< @see BS3_SEL_R0_DS16 */
501extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_SS16); /**< @see BS3_SEL_R0_SS16 */
502extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS32); /**< @see BS3_SEL_R0_CS32 */
503extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_DS32); /**< @see BS3_SEL_R0_DS32 */
504extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_SS32); /**< @see BS3_SEL_R0_SS32 */
505extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS64); /**< @see BS3_SEL_R0_CS64 */
506extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_DS64); /**< @see BS3_SEL_R0_DS64 */
507extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS16_EO); /**< @see BS3_SEL_R0_CS16_EO */
508extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS16_CNF); /**< @see BS3_SEL_R0_CS16_CNF */
509extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS16_CND_EO); /**< @see BS3_SEL_R0_CS16_CNF_EO */
510extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS32_EO); /**< @see BS3_SEL_R0_CS32_EO */
511extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS32_CNF); /**< @see BS3_SEL_R0_CS32_CNF */
512extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS32_CNF_EO); /**< @see BS3_SEL_R0_CS32_CNF_EO */
513extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS64_EO); /**< @see BS3_SEL_R0_CS64_EO */
514extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS64_CNF); /**< @see BS3_SEL_R0_CS64_CNF */
515extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R0_CS64_CNF_EO); /**< @see BS3_SEL_R0_CS64_CNF_EO */
516
517extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_First); /**< @see BS3_SEL_R1_FIRST */
518extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS16); /**< @see BS3_SEL_R1_CS16 */
519extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_DS16); /**< @see BS3_SEL_R1_DS16 */
520extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_SS16); /**< @see BS3_SEL_R1_SS16 */
521extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS32); /**< @see BS3_SEL_R1_CS32 */
522extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_DS32); /**< @see BS3_SEL_R1_DS32 */
523extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_SS32); /**< @see BS3_SEL_R1_SS32 */
524extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS64); /**< @see BS3_SEL_R1_CS64 */
525extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_DS64); /**< @see BS3_SEL_R1_DS64 */
526extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS16_EO); /**< @see BS3_SEL_R1_CS16_EO */
527extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS16_CNF); /**< @see BS3_SEL_R1_CS16_CNF */
528extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS16_CND_EO); /**< @see BS3_SEL_R1_CS16_CNF_EO */
529extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS32_EO); /**< @see BS3_SEL_R1_CS32_EO */
530extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS32_CNF); /**< @see BS3_SEL_R1_CS32_CNF */
531extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS32_CNF_EO); /**< @see BS3_SEL_R1_CS32_CNF_EO */
532extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS64_EO); /**< @see BS3_SEL_R1_CS64_EO */
533extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS64_CNF); /**< @see BS3_SEL_R1_CS64_CNF */
534extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R1_CS64_CNF_EO); /**< @see BS3_SEL_R1_CS64_CNF_EO */
535
536extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_First); /**< @see BS3_SEL_R2_FIRST */
537extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS16); /**< @see BS3_SEL_R2_CS16 */
538extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_DS16); /**< @see BS3_SEL_R2_DS16 */
539extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_SS16); /**< @see BS3_SEL_R2_SS16 */
540extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS32); /**< @see BS3_SEL_R2_CS32 */
541extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_DS32); /**< @see BS3_SEL_R2_DS32 */
542extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_SS32); /**< @see BS3_SEL_R2_SS32 */
543extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS64); /**< @see BS3_SEL_R2_CS64 */
544extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_DS64); /**< @see BS3_SEL_R2_DS64 */
545extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS16_EO); /**< @see BS3_SEL_R2_CS16_EO */
546extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS16_CNF); /**< @see BS3_SEL_R2_CS16_CNF */
547extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS16_CND_EO); /**< @see BS3_SEL_R2_CS16_CNF_EO */
548extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS32_EO); /**< @see BS3_SEL_R2_CS32_EO */
549extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS32_CNF); /**< @see BS3_SEL_R2_CS32_CNF */
550extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS32_CNF_EO); /**< @see BS3_SEL_R2_CS32_CNF_EO */
551extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS64_EO); /**< @see BS3_SEL_R2_CS64_EO */
552extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS64_CNF); /**< @see BS3_SEL_R2_CS64_CNF */
553extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R2_CS64_CNF_EO); /**< @see BS3_SEL_R2_CS64_CNF_EO */
554
555extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_First); /**< @see BS3_SEL_R3_FIRST */
556extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS16); /**< @see BS3_SEL_R3_CS16 */
557extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_DS16); /**< @see BS3_SEL_R3_DS16 */
558extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_SS16); /**< @see BS3_SEL_R3_SS16 */
559extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS32); /**< @see BS3_SEL_R3_CS32 */
560extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_DS32); /**< @see BS3_SEL_R3_DS32 */
561extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_SS32); /**< @see BS3_SEL_R3_SS32 */
562extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS64); /**< @see BS3_SEL_R3_CS64 */
563extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_DS64); /**< @see BS3_SEL_R3_DS64 */
564extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS16_EO); /**< @see BS3_SEL_R3_CS16_EO */
565extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS16_CNF); /**< @see BS3_SEL_R3_CS16_CNF */
566extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS16_CND_EO); /**< @see BS3_SEL_R3_CS16_CNF_EO */
567extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS32_EO); /**< @see BS3_SEL_R3_CS32_EO */
568extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS32_CNF); /**< @see BS3_SEL_R3_CS32_CNF */
569extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS32_CNF_EO); /**< @see BS3_SEL_R3_CS32_CNF_EO */
570extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS64_EO); /**< @see BS3_SEL_R3_CS64_EO */
571extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS64_CNF); /**< @see BS3_SEL_R3_CS64_CNF */
572extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_R3_CS64_CNF_EO); /**< @see BS3_SEL_R3_CS64_CNF_EO */
573
574extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare00); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_00 */
575extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare01); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_01 */
576extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare02); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_02 */
577extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare03); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_03 */
578extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare04); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_04 */
579extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare05); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_05 */
580extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare06); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_06 */
581extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare07); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_07 */
582extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare08); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_08 */
583extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare09); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_09 */
584extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare0a); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0a */
585extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare0b); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0b */
586extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare0c); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0c */
587extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare0d); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0d */
588extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare0e); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0e */
589extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare0f); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0f */
590extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare10); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_10 */
591extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare11); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_11 */
592extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare12); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_12 */
593extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare13); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_13 */
594extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare14); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_14 */
595extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare15); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_15 */
596extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare16); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_16 */
597extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare17); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_17 */
598extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare18); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_18 */
599extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare19); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_19 */
600extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare1a); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1a */
601extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare1b); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1b */
602extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare1c); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1c */
603extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare1d); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1d */
604extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare1e); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1e */
605extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteSpare1f); /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1f */
606
607/** GDTs setting up the tiled 16-bit access to the first 16 MBs of memory.
608 * @see BS3_SEL_TILED, BS3_SEL_TILED_LAST, BS3_SEL_TILED_AREA_SIZE */
609extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteTiled)[256];
610/** Free GDTes, part \#1. */
611extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteFreePart1)[64];
612/** The BS3CODE16 GDT entry. @see BS3_SEL_TEXT16 */
613extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_CODE16);
614/** Free GDTes, part \#2. */
615extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteFreePart2)[511];
616/** The BS3SYSTEM16 GDT entry. */
617extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_SYSTEM16);
618/** Free GDTes, part \#3. */
619extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteFreePart3)[223];
620/** The BS3DATA16 GDT entry. */
621extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_DATA16);
622/** The end of the GDT (exclusive). */
623extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdtEnd);
624
625/** The default 16-bit TSS. */
626extern X86TSS16 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss16);
627extern X86TSS16 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss16DoubleFault);
628extern X86TSS16 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss16Spare0);
629extern X86TSS16 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss16Spare1);
630/** The default 32-bit TSS. */
631extern X86TSS32 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss32);
632extern X86TSS32 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss32DoubleFault);
633extern X86TSS32 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss32Spare0);
634extern X86TSS32 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss32Spare1);
635/** The default 64-bit TSS. */
636extern X86TSS64 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss64);
637extern X86TSS64 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss64Spare0);
638extern X86TSS64 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss64Spare1);
639extern X86TSS64 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss64WithIopb);
640extern X86TSS32 BS3_FAR_DATA BS3_DATA_NM(Bs3Tss32WithIopb);
641/** Interrupt redirection bitmap used by Bs3Tss32WithIopb. */
642extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3SharedIntRedirBm)[32];
643/** I/O permission bitmap used by Bs3Tss32WithIopb and Bs3Tss64WithIopb. */
644extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3SharedIobp)[8192+2];
645/** End of the I/O permission bitmap (exclusive). */
646extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3SharedIobpEnd);
647/** 16-bit IDT. */
648extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Idt16)[256];
649/** 32-bit IDT. */
650extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Idt32)[256];
651/** 64-bit IDT. */
652extern X86DESC64 BS3_FAR_DATA BS3_DATA_NM(Bs3Idt64)[256];
653/** Structure for the LIDT instruction for loading the 16-bit IDT. */
654extern X86XDTR64 BS3_FAR_DATA BS3_DATA_NM(Bs3Lidt_Idt16);
655/** Structure for the LIDT instruction for loading the 32-bit IDT. */
656extern X86XDTR64 BS3_FAR_DATA BS3_DATA_NM(Bs3Lidt_Idt32);
657/** Structure for the LIDT instruction for loading the 64-bit IDT. */
658extern X86XDTR64 BS3_FAR_DATA BS3_DATA_NM(Bs3Lidt_Idt64);
659/** Structure for the LIDT instruction for loading the real mode interrupt
660 * vector table.. */
661extern X86XDTR64 BS3_FAR_DATA BS3_DATA_NM(Bs3Lidt_Ivt);
662/** Structure for the LGDT instruction for loading the GDT. */
663extern X86XDTR64 BS3_FAR_DATA BS3_DATA_NM(Bs3Lgdt_Gdt);
664/** The LDT (all entries are empty, fill in for testing). */
665extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Ldt)[118];
666/** The end of the LDT (exclusive). */
667extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3LdtEnd);
668
669/** @} */
670
671
672/** @name Segment start and end markers, sizes.
673 * @{ */
674/** Start of the BS3TEXT16 segment. */
675extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Text16_StartOfSegment);
676/** End of the BS3TEXT16 segment. */
677extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Text16_EndOfSegment);
678/** The size of the BS3TEXT16 segment. */
679extern uint16_t BS3_FAR_DATA BS3_DATA_NM(Bs3Text16_Size);
680
681/** Start of the BS3SYSTEM16 segment. */
682extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3System16_StartOfSegment);
683/** End of the BS3SYSTEM16 segment. */
684extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3System16_EndOfSegment);
685
686/** Start of the BS3DATA16 segment. */
687extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Data16_StartOfSegment);
688/** End of the BS3DATA16 segment. */
689extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Data16_EndOfSegment);
690
691/** Start of the BS3TEXT32 segment. */
692extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Text32_StartOfSegment);
693/** Start of the BS3TEXT32 segment. */
694extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Text32_EndOfSegment);
695
696/** Start of the BS3DATA32 segment. */
697extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Data32_StartOfSegment);
698/** Start of the BS3DATA32 segment. */
699extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Data32_EndOfSegment);
700
701/** Start of the BS3TEXT64 segment. */
702extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Text64_StartOfSegment);
703/** Start of the BS3TEXT64 segment. */
704extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Text64_EndOfSegment);
705
706/** Start of the BS3DATA64 segment. */
707extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Data64_StartOfSegment);
708/** Start of the BS3DATA64 segment. */
709extern uint8_t BS3_FAR_DATA BS3_DATA_NM(Bs3Data64_EndOfSegment);
710
711/** The size of the Data16, Text32, Text64, Data32 and Data64 blob. */
712extern uint32_t BS3_FAR_DATA BS3_DATA_NM(Bs3Data16Thru64Text32And64_TotalSize);
713/** The total image size (from Text16 thu Data64). */
714extern uint32_t BS3_FAR_DATA BS3_DATA_NM(Bs3TotalImageSize);
715/** @} */
716
717
718/** Lower case hex digits. */
719extern char const BS3_DATA_NM(g_achBs3HexDigits)[16+1];
720/** Upper case hex digits. */
721extern char const BS3_DATA_NM(g_achBs3HexDigitsUpper)[16+1];
722
723
724#ifdef __WATCOMC__
725/**
726 * Executes the SMSW instruction and returns the value.
727 *
728 * @returns Machine status word.
729 */
730uint16_t Bs3AsmSmsw(void);
731# pragma aux Bs3AsmSmsw = \
732 "smsw ax" \
733 value [ax] modify exact [ax] nomemory;
734#endif
735
736
737/** @def BS3_IS_PROTECTED_MODE
738 * @returns true if protected mode, false if not. */
739#if ARCH_BITS != 16
740# define BS3_IS_PROTECTED_MODE() (true)
741#else
742# define BS3_IS_PROTECTED_MODE() (Bs3AsmSmsw() & 1 /*PE*/)
743#endif
744
745
746/** @defgroup bs3kit_cross_ptr Cross context pointer type
747 *
748 * The cross context pointer type is
749 *
750 * @{ */
751
752/**
753 * Cross context pointer base type.
754 */
755#pragma pack(4)
756typedef union BS3XPTR
757{
758 /** The flat pointer. */
759 uint32_t uFlat;
760 /** 16-bit view. */
761 struct
762 {
763 uint16_t uLow;
764 uint16_t uHigh;
765 } u;
766#if ARCH_BITS == 16
767 /** 16-bit near pointer. */
768 void __near *pvNear;
769#elif ARCH_BITS == 32
770 /** 32-bit pointer. */
771 void *pvRaw;
772#endif
773} BS3XPTR;
774#pragma pack()
775
776
777/** @def BS3_XPTR_DEF_INTERNAL
778 * Internal worker.
779 *
780 * @param a_Scope RT_NOTHING if structure or global, static or extern
781 * otherwise.
782 * @param a_Type The type we're pointing to.
783 * @param a_Name The member or variable name.
784 * @internal
785 */
786#if ARCH_BITS == 16
787# define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \
788 a_Scope union \
789 { \
790 BS3XPTR XPtr; \
791 a_Type __near *pNearTyped; \
792 } a_Name
793#elif ARCH_BITS == 32
794# define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \
795 a_Scope union \
796 { \
797 BS3XPTR XPtr; \
798 a_Type *pTyped; \
799 } a_Name
800#elif ARCH_BITS == 64
801# define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \
802 a_Scope union \
803 { \
804 BS3XPTR XPtr; \
805 a_Type *pTyped; \
806 } a_Name
807#else
808# error "ARCH_BITS"
809#endif
810
811/** @def BS3_XPTR_DEF_MEMBER
812 * Defines a pointer member that can be shared by all CPU modes.
813 *
814 * @param a_Type The type we're pointing to.
815 * @param a_Name The member or variable name.
816 */
817#define BS3_XPTR_MEMBER(a_Type, a_Name) BS3_XPTR_DEF_INTERNAL(RT_NOTHING, a_Type, a_Name)
818
819/** @def BS3_XPTR_DEF_AUTO
820 * Defines a pointer static variable for working with an XPTR.
821 *
822 * This is typically used to convert flat pointers into context specific
823 * pointers.
824 *
825 * @param a_Type The type we're pointing to.
826 * @param a_Name The member or variable name.
827 */
828#define BS3_XPTR_AUTO(a_Type, a_Name) BS3_XPTR_DEF_INTERNAL(RT_NOTHING, a_Type, a_Name)
829
830/** @def BS3_XPTR_SET
831 * Sets a cross context pointer.
832 *
833 * @param a_Type The type we're pointing to.
834 * @param a_Name The member or variable name.
835 * @param a_uFlatPtr The flat pointer value to assign. If the x-pointer is
836 * used in real mode, this must be less than 1MB.
837 * Otherwise the limit is 16MB (due to selector tiling).
838 */
839#define BS3_XPTR_SET_FLAT(a_Type, a_Name, a_uFlatPtr) \
840 do { a_Name.XPtr.uFlat = (a_uFlatPtr); } while (0)
841
842/** @def BS3_XPTR_GET_FLAT
843 * Gets the flat address of a cross context pointer.
844 *
845 * @returns 32-bit flat pointer.
846 * @param a_Type The type we're pointing to.
847 * @param a_Name The member or variable name.
848 */
849#define BS3_XPTR_GET_FLAT(a_Type, a_Name) (a_Name.XPtr.uFlat)
850
851/** @def BS3_XPTR_GET_FLAT_LOW
852 * Gets the low 16 bits of the flat address.
853 *
854 * @returns Low 16 bits of the flat pointer.
855 * @param a_Type The type we're pointing to.
856 * @param a_Name The member or variable name.
857 */
858#define BS3_XPTR_GET_FLAT_LOW(a_Type, a_Name) (a_Name.XPtr.u.uLow)
859
860
861#if ARCH_BITS == 16
862
863/**
864 * Gets the current ring number.
865 * @returns Ring number.
866 */
867DECLINLINE(uint16_t) Bs3Sel16GetCurRing(void);
868# pragma aux Bs3Sel16GetCurRing = \
869 "mov ax, ss" \
870 "and ax, 3" \
871 value [ax] modify exact [ax] nomemory;
872
873/**
874 * Converts the high word of a flat pointer into a 16-bit selector.
875 *
876 * This makes use of the tiled area. It also handles real mode.
877 *
878 * @returns Segment selector value.
879 * @param uHigh The high part of flat pointer.
880 * @sa BS3_XPTR_GET, BS3_XPTR_SET
881 */
882DECLINLINE(__segment) Bs3Sel16HighFlatPtrToSelector(uint16_t uHigh)
883{
884 if (BS3_IS_PROTECTED_MODE())
885 return (__segment)(((uHigh << 3) + BS3_SEL_TILED) | Bs3Sel16GetCurRing());
886 return (__segment)(uHigh << 12);
887}
888
889#endif /* ARCH_BITS == 16*/
890
891/** @def BS3_XPTR_GET
892 * Gets the current context pointer value.
893 *
894 * @returns Usable pointer.
895 * @param a_Type The type we're pointing to.
896 * @param a_Name The member or variable name.
897 */
898#if ARCH_BITS == 16
899# define BS3_XPTR_GET(a_Type, a_Name) \
900 ((a_Type BS3_FAR *)BS3_FP_MAKE(Bs3Sel16HighFlatPtrToSelector((a_Name).XPtr.u.uHigh), (a_Name).pNearTyped))
901#elif ARCH_BITS == 32
902# define BS3_XPTR_GET(a_Type, a_Name) ((a_Name).pTyped)
903#elif ARCH_BITS == 64
904# define BS3_XPTR_GET(a_Type, a_Name) ((a_Type *)(uintptr_t)(a_Name).XPtr.uFlat)
905#else
906# error "ARCH_BITS"
907#endif
908
909/** @def BS3_XPTR_SET
910 * Gets the current context pointer value.
911 *
912 * @returns Usable pointer.
913 * @param a_Type The type we're pointing to.
914 * @param a_Name The member or variable name.
915 * @param a_pValue The new pointer value, current context pointer.
916 */
917#if ARCH_BITS == 16
918# define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \
919 do { \
920 a_Type BS3_FAR *pTypeCheck = (a_pValue); \
921 if (BS3_IS_PROTECTED_MODE()) \
922 { \
923 (a_Name).XPtr.u.uLow = BS3_FP_OFF(pTypeCheck); \
924 (a_Name).XPtr.u.uHigh = ((BS3_FP_SEG(pTypeCheck) & UINT16_C(0xfff8)) - BS3_SEL_TILED) >> 3; \
925 } \
926 else \
927 (a_Name).XPtr.uFlat = BS3_FP_OFF(pTypeCheck) + ((uint32_t)BS3_FP_SEG(pTypeCheck) << 4); \
928 } while (0)
929#elif ARCH_BITS == 32
930# define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \
931 do { (a_Name).pTyped = (a_pValue); } while (0)
932#elif ARCH_BITS == 64
933# define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \
934 do { \
935 a_Type *pTypeCheck = (a_pValue); \
936 (a_Name).XPtr.uFlat = (uint32_t)(uintptr_t)pTypeCheck; \
937 } while (0)
938#else
939# error "ARCH_BITS"
940#endif
941
942
943/** @def BS3_XPTR_IS_NULL
944 * Checks if the cross context pointer is NULL.
945 *
946 * @returns true if NULL, false if not.
947 * @param a_Type The type we're pointing to.
948 * @param a_Name The member or variable name.
949 */
950#define BS3_XPTR_IS_NULL(a_Type, a_Name) ((a_Name).XPtr.uFlat == 0)
951/** @} */
952
953
954
955/** @defgroup grp_bs3kit_cmn Common Functions and Data
956 *
957 * The common functions comes in three variations: 16-bit, 32-bit and 64-bit.
958 * Templated code uses the #BS3_CMN_NM macro to mangle the name according to the
959 * desired
960 *
961 * @{
962 */
963
964#ifdef BS3_STRICT
965# define BS3_ASSERT(a_Expr) do { if (!!(a_Expr)) { /* likely */ } else { Bs3Panic(); } } while (0) /**< @todo later */
966#else
967# define BS3_ASSERT(a_Expr) do { } while (0)
968#endif
969
970/**
971 * Panic, never return.
972 *
973 * The current implementation will only halt the CPU.
974 */
975BS3_DECL(void) Bs3Panic_c16(void);
976BS3_DECL(void) Bs3Panic_c32(void); /**< @copydoc Bs3Panic_c16 */
977BS3_DECL(void) Bs3Panic_c64(void); /**< @copydoc Bs3Panic_c16 */
978#define Bs3Panic BS3_CMN_NM(Bs3Panic) /**< Selects #Bs3Panic_c16, #Bs3Panic_c32 or #Bs3Panic_c64. */
979
980/**
981 * Shutdown the system, never returns.
982 *
983 * This currently only works for VMs. When running on real systems it will
984 * just halt the CPU.
985 */
986BS3_DECL(void) Bs3Shutdown_c16(void);
987BS3_DECL(void) Bs3Shutdown_c32(void); /**< @copydoc Bs3Shutdown_c16 */
988BS3_DECL(void) Bs3Shutdown_c64(void); /**< @copydoc Bs3Shutdown_c16 */
989#define Bs3Shutdown BS3_CMN_NM(Bs3Shutdown) /**< Selects #Bs3Shutdown_c16, #Bs3Shutdown_c32 or #Bs3Shutdown_c64. */
990
991/**
992 * Prints a 32-bit unsigned value as decimal to the screen.
993 *
994 * @param uValue The 32-bit value.
995 */
996BS3_DECL(void) Bs3PrintU32_c16(uint32_t uValue);
997BS3_DECL(void) Bs3PrintU32_c32(uint32_t uValue); /**< @copydoc Bs3PrintU32_c16 */
998BS3_DECL(void) Bs3PrintU32_c64(uint32_t uValue); /**< @copydoc Bs3PrintU32_c16 */
999#define Bs3PrintU32 BS3_CMN_NM(Bs3PrintU32) /**< Selects #Bs3PrintU32_c16, #Bs3PrintU32_c32 or #Bs3PrintU32_c64. */
1000
1001/**
1002 * Prints a 32-bit unsigned value as hex to the screen.
1003 *
1004 * @param uValue The 32-bit value.
1005 */
1006BS3_DECL(void) Bs3PrintX32_c16(uint32_t uValue);
1007BS3_DECL(void) Bs3PrintX32_c32(uint32_t uValue); /**< @copydoc Bs3PrintX32_c16 */
1008BS3_DECL(void) Bs3PrintX32_c64(uint32_t uValue); /**< @copydoc Bs3PrintX32_c16 */
1009#define Bs3PrintX32 BS3_CMN_NM(Bs3PrintX32) /**< Selects #Bs3PrintX32_c16, #Bs3PrintX32_c32 or #Bs3PrintX32_c64. */
1010
1011/**
1012 * Formats and prints a string to the screen.
1013 *
1014 * See #Bs3StrFormatV_c16 for supported format types.
1015 *
1016 * @param pszFormat The format string.
1017 * @param ... Format arguments.
1018 */
1019BS3_DECL(size_t) Bs3Printf_c16(const char BS3_FAR *pszFormat, ...);
1020BS3_DECL(size_t) Bs3Printf_c32(const char BS3_FAR *pszFormat, ...); /**< @copydoc Bs3Printf_c16 */
1021BS3_DECL(size_t) Bs3Printf_c64(const char BS3_FAR *pszFormat, ...); /**< @copydoc Bs3Printf_c16 */
1022#define Bs3Printf BS3_CMN_NM(Bs3Printf) /**< Selects #Bs3Printf_c16, #Bs3Printf_c32 or #Bs3Printf_c64. */
1023
1024/**
1025 * Formats and prints a string to the screen, va_list version.
1026 *
1027 * See #Bs3Format_c16 for supported format types.
1028 *
1029 * @param pszFormat The format string.
1030 * @param va Format arguments.
1031 */
1032BS3_DECL(size_t) Bs3PrintfV_c16(const char BS3_FAR *pszFormat, va_list va);
1033BS3_DECL(size_t) Bs3PrintfV_c32(const char BS3_FAR *pszFormat, va_list va); /**< @copydoc Bs3PrintfV_c16 */
1034BS3_DECL(size_t) Bs3PrintfV_c64(const char BS3_FAR *pszFormat, va_list va); /**< @copydoc Bs3PrintfV_c16 */
1035#define Bs3PrintfV BS3_CMN_NM(Bs3PrintfV) /**< Selects #Bs3PrintfV_c16, #Bs3PrintfV_c32 or #Bs3PrintfV_c64. */
1036
1037/**
1038 * Prints a string to the screen.
1039 *
1040 * @param pszString The string to print.
1041 */
1042BS3_DECL(void) Bs3PrintStr_c16(const char BS3_FAR *pszString);
1043BS3_DECL(void) Bs3PrintStr_c32(const char BS3_FAR *pszString); /**< @copydoc Bs3PrintStr_c16 */
1044BS3_DECL(void) Bs3PrintStr_c64(const char BS3_FAR *pszString); /**< @copydoc Bs3PrintStr_c16 */
1045#define Bs3PrintStr BS3_CMN_NM(Bs3PrintStr) /**< Selects #Bs3PrintStr_c16, #Bs3PrintStr_c32 or #Bs3PrintStr_c64. */
1046
1047/**
1048 * Prints a char to the screen.
1049 *
1050 * @param ch The character to print.
1051 */
1052BS3_DECL(void) Bs3PrintChr_c16(char ch);
1053BS3_DECL(void) Bs3PrintChr_c32(char ch); /**< @copydoc Bs3PrintChr_c16 */
1054BS3_DECL(void) Bs3PrintChr_c64(char ch); /**< @copydoc Bs3PrintChr_c16 */
1055#define Bs3PrintChr BS3_CMN_NM(Bs3PrintChr) /**< Selects #Bs3PrintChr_c16, #Bs3PrintChr_c32 or #Bs3PrintChr_c64. */
1056
1057
1058/**
1059 * An output function for #Bs3StrFormatV.
1060 *
1061 * @returns Number of characters written.
1062 * @param ch The character to write. Zero in the final call.
1063 * @param pvUser User argument supplied to #Bs3StrFormatV.
1064 */
1065typedef size_t BS3_CALL FNBS3STRFORMATOUTPUT(char ch, void BS3_FAR *pvUser);
1066/** Pointer to an output function for #Bs3StrFormatV. */
1067typedef FNBS3STRFORMATOUTPUT BS3_NEAR_CODE *PFNBS3STRFORMATOUTPUT;
1068
1069/**
1070 * Formats a string, sending the output to @a pfnOutput.
1071 *
1072 * Supported types:
1073 * - %RI8, %RI16, %RI32, %RI64
1074 * - %RU8, %RU16, %RU32, %RU64
1075 * - %RX8, %RX16, %RX32, %RX64
1076 * - %i, %d
1077 * - %u
1078 * - %x
1079 * - %c
1080 * - %p (far pointer)
1081 * - %s (far pointer)
1082 *
1083 * @returns Sum of @a pfnOutput return values.
1084 * @param pszFormat The format string.
1085 * @param va Format arguments.
1086 * @param pfnOutput The output function.
1087 * @param pvUser The user argument for the output function.
1088 */
1089BS3_DECL(size_t) Bs3StrFormatV_c16(const char BS3_FAR *pszFormat, va_list va,
1090 PFNBS3STRFORMATOUTPUT pfnOutput, void BS3_FAR *pvUser);
1091/** @copydoc Bs3StrFormatV_c16 */
1092BS3_DECL(size_t) Bs3StrFormatV_c32(const char BS3_FAR *pszFormat, va_list va,
1093 PFNBS3STRFORMATOUTPUT pfnOutput, void BS3_FAR *pvUser);
1094/** @copydoc Bs3StrFormatV_c16 */
1095BS3_DECL(size_t) Bs3StrFormatV_c64(const char BS3_FAR *pszFormat, va_list va,
1096 PFNBS3STRFORMATOUTPUT pfnOutput, void BS3_FAR *pvUser);
1097#define Bs3StrFormatV BS3_CMN_NM(Bs3StrFormatV) /**< Selects #Bs3StrFormatV_c16, #Bs3StrFormatV_c32 or #Bs3StrFormatV_c64. */
1098
1099/**
1100 * Formats a string into a buffer.
1101 *
1102 * See #Bs3Format_c16 for supported format types.
1103 *
1104 * @returns The length of the formatted string (excluding terminator).
1105 * This will be higher or equal to @c cbBuf in case of an overflow.
1106 * @param pszBuf The output buffer.
1107 * @param cbBuf The size of the output buffer.
1108 * @param pszFormat The format string.
1109 * @param va Format arguments.
1110 */
1111BS3_DECL(size_t) Bs3StrPrintfV_c16(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, va_list va);
1112/** @copydoc Bs3StrPrintfV_c16 */
1113BS3_DECL(size_t) Bs3StrPrintfV_c32(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, va_list va);
1114/** @copydoc Bs3StrPrintfV_c16 */
1115BS3_DECL(size_t) Bs3StrPrintfV_c64(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, va_list va);
1116#define Bs3StrPrintfV BS3_CMN_NM(Bs3StrPrintfV) /**< Selects #Bs3StrPrintfV_c16, #Bs3StrPrintfV_c32 or #Bs3StrPrintfV_c64. */
1117
1118/**
1119 * Formats a string into a buffer.
1120 *
1121 * See #Bs3Format_c16 for supported format types.
1122 *
1123 * @returns The length of the formatted string (excluding terminator).
1124 * This will be higher or equal to @c cbBuf in case of an overflow.
1125 * @param pszBuf The output buffer.
1126 * @param cbBuf The size of the output buffer.
1127 * @param pszFormat The format string.
1128 * @param ... Format arguments.
1129 */
1130BS3_DECL(size_t) Bs3StrPrintf_c16(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, ...);
1131/** @copydoc Bs3StrPrintf_c16 */
1132BS3_DECL(size_t) Bs3StrPrintf_c32(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, ...);
1133/** @copydoc Bs3StrPrintf_c16 */
1134BS3_DECL(size_t) Bs3StrPrintf_c64(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, ...);
1135#define Bs3StrPrintf BS3_CMN_NM(Bs3StrPrintf) /**< Selects #Bs3StrPrintf_c16, #Bs3StrPrintf_c32 or #Bs3StrPrintf_c64. */
1136
1137
1138/**
1139 * Finds the length of a zero terminated string.
1140 *
1141 * @returns String length in chars/bytes.
1142 * @param pszString The string to examine.
1143 */
1144BS3_DECL(size_t) Bs3StrLen_c16(const char BS3_FAR *pszString);
1145BS3_DECL(size_t) Bs3StrLen_c32(const char BS3_FAR *pszString); /** @copydoc Bs3StrLen_c16 */
1146BS3_DECL(size_t) Bs3StrLen_c64(const char BS3_FAR *pszString); /** @copydoc Bs3StrLen_c16 */
1147#define Bs3StrLen BS3_CMN_NM(Bs3StrLen) /**< Selects #Bs3StrLen_c16, #Bs3StrLen_c32 or #Bs3StrLen_c64. */
1148
1149/**
1150 * Finds the length of a zero terminated string, but with a max length.
1151 *
1152 * @returns String length in chars/bytes, or @a cchMax if no zero-terminator
1153 * was found before we reached the limit.
1154 * @param pszString The string to examine.
1155 * @param cchMax The max length to examine.
1156 */
1157BS3_DECL(size_t) Bs3StrNLen_c16(const char BS3_FAR *pszString, size_t cchMax);
1158BS3_DECL(size_t) Bs3StrNLen_c32(const char BS3_FAR *pszString, size_t cchMax); /** @copydoc Bs3StrNLen_c16 */
1159BS3_DECL(size_t) Bs3StrNLen_c64(const char BS3_FAR *pszString, size_t cchMax); /** @copydoc Bs3StrNLen_c16 */
1160#define Bs3StrNLen BS3_CMN_NM(Bs3StrNLen) /**< Selects #Bs3StrNLen_c16, #Bs3StrNLen_c32 or #Bs3StrNLen_c64. */
1161
1162/**
1163 * CRT style unsafe strcpy.
1164 *
1165 * @returns pszDst.
1166 * @param pszDst The destination buffer. Must be large enough to
1167 * hold the source string.
1168 * @param pszSrc The source string.
1169 */
1170BS3_DECL(char BS3_FAR *) Bs3StrCpy_c16(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc);
1171BS3_DECL(char BS3_FAR *) Bs3StrCpy_c32(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc); /** @copydoc Bs3StrCpy_c16 */
1172BS3_DECL(char BS3_FAR *) Bs3StrCpy_c64(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc); /** @copydoc Bs3StrCpy_c16 */
1173#define Bs3StrCpy BS3_CMN_NM(Bs3StrCpy) /**< Selects #Bs3StrCpy_c16, #Bs3StrCpy_c32 or #Bs3StrCpy_c64. */
1174
1175/**
1176 * CRT style memcpy.
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 *) Bs3MemCpy_c16(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy);
1184BS3_DECL(void BS3_FAR *) Bs3MemCpy_c32(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemCpy_c16 */
1185BS3_DECL(void BS3_FAR *) Bs3MemCpy_c64(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemCpy_c16 */
1186#define Bs3MemCpy BS3_CMN_NM(Bs3MemCpy) /**< Selects #Bs3MemCpy_c16, #Bs3MemCpy_c32 or #Bs3MemCpy_c64. */
1187
1188/**
1189 * GNU (?) style mempcpy.
1190 *
1191 * @returns pvDst + cbCopy
1192 * @param pvDst The destination buffer.
1193 * @param pvSrc The source buffer.
1194 * @param cbCopy The number of bytes to copy.
1195 */
1196BS3_DECL(void BS3_FAR *) Bs3MemPCpy_c16(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy);
1197BS3_DECL(void BS3_FAR *) Bs3MemPCpy_c32(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemPCpy_c16 */
1198BS3_DECL(void BS3_FAR *) Bs3MemPCpy_c64(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemPCpy_c16 */
1199#define Bs3MemPCpy BS3_CMN_NM(Bs3MemPCpy) /**< Selects #Bs3MemPCpy_c16, #Bs3MemPCpy_c32 or #Bs3MemPCpy_c64. */
1200
1201/**
1202 * CRT style memmove (overlapping buffers is fine).
1203 *
1204 * @returns pvDst
1205 * @param pvDst The destination buffer.
1206 * @param pvSrc The source buffer.
1207 * @param cbCopy The number of bytes to copy.
1208 */
1209BS3_DECL(void BS3_FAR *) Bs3MemMove_c16(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy);
1210BS3_DECL(void BS3_FAR *) Bs3MemMove_c32(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemMove_c16 */
1211BS3_DECL(void BS3_FAR *) Bs3MemMove_c64(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy); /** @copydoc Bs3MemMove_c16 */
1212#define Bs3MemMove BS3_CMN_NM(Bs3MemMove) /**< Selects #Bs3MemMove_c16, #Bs3MemMove_c32 or #Bs3MemMove_c64. */
1213
1214/**
1215 * BSD style bzero.
1216 *
1217 * @param pvDst The buffer to be zeroed.
1218 * @param cbDst The number of bytes to zero.
1219 */
1220BS3_DECL(void) Bs3MemZero_c16(void BS3_FAR *pvDst, size_t cbDst);
1221BS3_DECL(void) Bs3MemZero_c32(void BS3_FAR *pvDst, size_t cbDst); /** @copydoc Bs3MemZero_c16 */
1222BS3_DECL(void) Bs3MemZero_c64(void BS3_FAR *pvDst, size_t cbDst); /** @copydoc Bs3MemZero_c16 */
1223#define Bs3MemZero BS3_CMN_NM(Bs3MemZero) /**< Selects #Bs3MemZero_c16, #Bs3MemZero_c32 or #Bs3MemZero_c64. */
1224
1225
1226
1227/**
1228 * Equivalent to RTTestCreate + RTTestBanner.
1229 *
1230 * @param pszTest The test name.
1231 */
1232BS3_DECL(void) Bs3TestInit_c16(const char BS3_FAR *pszTest);
1233BS3_DECL(void) Bs3TestInit_c32(const char BS3_FAR *pszTest); /**< @copydoc Bs3TestInit_c16 */
1234BS3_DECL(void) Bs3TestInit_c64(const char BS3_FAR *pszTest); /**< @copydoc Bs3TestInit_c16 */
1235#define Bs3TestInit BS3_CMN_NM(Bs3TestInit) /**< Selects #Bs3TestInit_c16, #Bs3TestInit_c32 or #Bs3TestInit_c64. */
1236
1237
1238/**
1239 * Slab control structure list head.
1240 *
1241 * The slabs on the list must all have the same chunk size.
1242 */
1243typedef struct BS3SLABHEAD
1244{
1245 /** Pointer to the first slab. */
1246 BS3_XPTR_MEMBER(struct BS3SLABCTL, pFirst);
1247 /** The allocation chunk size. */
1248 uint16_t cbChunk;
1249 /** Number of slabs in the list. */
1250 uint16_t cSlabs;
1251 /** Number of chunks in the list. */
1252 uint32_t cChunks;
1253 /** Number of free chunks. */
1254 uint32_t cFreeChunks;
1255} BS3SLABHEAD;
1256/** Pointer to a slab list head. */
1257typedef BS3SLABHEAD BS3_FAR *PBS3SLABHEAD;
1258
1259/**
1260 * Allocation slab control structure.
1261 *
1262 * This may live at the start of the slab for 4KB slabs, while in a separate
1263 * static location for the larger ones.
1264 */
1265typedef struct BS3SLABCTL
1266{
1267 /** Pointer to the next slab control structure in this list. */
1268 BS3_XPTR_MEMBER(struct BS3SLABCTL, pNext);
1269 /** Pointer to the slab list head. */
1270 BS3_XPTR_MEMBER(BS3SLABHEAD, pHead);
1271 /** The base address of the slab. */
1272 BS3_XPTR_MEMBER(uint8_t, pbStart);
1273 /** Number of chunks in this slab. */
1274 uint16_t cChunks;
1275 /** Number of currently free chunks. */
1276 uint16_t cFreeChunks;
1277 /** The chunk size. */
1278 uint16_t cbChunk;
1279 /** The shift count corresponding to cbChunk.
1280 * This is for turning a chunk number into a byte offset and vice versa. */
1281 uint16_t cChunkShift;
1282 /** Bitmap where set bits indicates allocated blocks (variable size,
1283 * multiple of 4). */
1284 uint8_t bmAllocated[4];
1285} BS3SLABCTL;
1286/** Pointer to a bs3kit slab control structure. */
1287typedef BS3SLABCTL BS3_FAR *PBS3SLABCTL;
1288
1289/** The chunks must all be in the same 16-bit segment tile. */
1290#define BS3_SLAB_ALLOC_F_SAME_TILE UINT16_C(0x0001)
1291
1292/**
1293 * Initializes a slab.
1294 *
1295 * @param pSlabCtl The slab control structure to initialize.
1296 * @param cbSlabCtl The size of the slab control structure.
1297 * @param uFlatSlabPtr The base address of the slab.
1298 * @param cbSlab The size of the slab.
1299 * @param cbChunk The chunk size.
1300 */
1301BS3_DECL(void) Bs3SlabInit_c16(PBS3SLABCTL pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk);
1302/** @copydoc Bs3SlabInit_c16 */
1303BS3_DECL(void) Bs3SlabInit_c32(PBS3SLABCTL pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk);
1304/** @copydoc Bs3SlabInit_c16 */
1305BS3_DECL(void) Bs3SlabInit_c64(PBS3SLABCTL pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk);
1306#define Bs3SlabInit BS3_CMN_NM(Bs3SlabInit) /**< Selects #Bs3SlabInit_c16, #Bs3SlabInit_c32 or #Bs3SlabInit_c64. */
1307
1308/**
1309 * Allocates one chunk from a slab.
1310 *
1311 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
1312 * @param pSlabCtl The slab constrol structure to allocate from.
1313 */
1314BS3_DECL(void BS3_FAR *) Bs3SlabAlloc_c16(PBS3SLABCTL pSlabCtl);
1315BS3_DECL(void BS3_FAR *) Bs3SlabAlloc_c32(PBS3SLABCTL pSlabCtl); /**< @copydoc Bs3SlabAlloc_c16 */
1316BS3_DECL(void BS3_FAR *) Bs3SlabAlloc_c64(PBS3SLABCTL pSlabCtl); /**< @copydoc Bs3SlabAlloc_c16 */
1317#define Bs3SlabAlloc BS3_CMN_NM(Bs3SlabAlloc) /**< Selects #Bs3SlabAlloc_c16, #Bs3SlabAlloc_c32 or #Bs3SlabAlloc_c64. */
1318
1319/**
1320 * Allocates one or more chunks rom a slab.
1321 *
1322 * @returns Pointer to the request number of chunks on success, NULL if we're
1323 * out of chunks.
1324 * @param pSlabCtl The slab constrol structure to allocate from.
1325 * @param cChunks The number of contiguous chunks we want.
1326 * @param fFlags Flags, see BS3_SLAB_ALLOC_F_XXX
1327 */
1328BS3_DECL(void BS3_FAR *) Bs3SlabAllocEx_c16(PBS3SLABCTL pSlabCtl, uint16_t cChunks, uint16_t fFlags);
1329BS3_DECL(void BS3_FAR *) Bs3SlabAllocEx_c32(PBS3SLABCTL pSlabCtl, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabAllocEx_c16 */
1330BS3_DECL(void BS3_FAR *) Bs3SlabAllocEx_c64(PBS3SLABCTL pSlabCtl, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabAllocEx_c16 */
1331#define Bs3SlabAllocEx BS3_CMN_NM(Bs3SlabAllocEx) /**< Selects #Bs3SlabAllocEx_c16, #Bs3SlabAllocEx_c32 or #Bs3SlabAllocEx_c64. */
1332
1333/**
1334 * Frees one or more chunks from a slab.
1335 *
1336 * @returns Number of chunks actually freed. When correctly used, this will
1337 * match the @a cChunks parameter, of course.
1338 * @param pSlabCtl The slab constrol structure to free from.
1339 * @param uFlatChunkPtr The flat address of the chunks to free.
1340 * @param cChunks The number of contiguous chunks to free.
1341 */
1342BS3_DECL(uint16_t) Bs3SlabFree_c16(PBS3SLABCTL pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks);
1343BS3_DECL(uint16_t) Bs3SlabFree_c32(PBS3SLABCTL pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks); /**< @copydoc Bs3SlabFree_c16 */
1344BS3_DECL(uint16_t) Bs3SlabFree_c64(PBS3SLABCTL pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks); /**< @copydoc Bs3SlabFree_c16 */
1345#define Bs3SlabFree BS3_CMN_NM(Bs3SlabFree) /**< Selects #Bs3SlabFree_c16, #Bs3SlabFree_c32 or #Bs3SlabFree_c64. */
1346
1347
1348/**
1349 * Initializes the given slab list head.
1350 *
1351 * @param pHead The slab list head.
1352 * @param cbChunk The chunk size.
1353 */
1354BS3_DECL(void) Bs3SlabListInit_c16(PBS3SLABHEAD pHead, uint16_t cbChunk);
1355BS3_DECL(void) Bs3SlabListInit_c32(PBS3SLABHEAD pHead, uint16_t cbChunk); /**< @copydoc Bs3SlabListInit_c16 */
1356BS3_DECL(void) Bs3SlabListInit_c64(PBS3SLABHEAD pHead, uint16_t cbChunk); /**< @copydoc Bs3SlabListInit_c16 */
1357#define Bs3SlabListInit BS3_CMN_NM(Bs3SlabListInit) /**< Selects #Bs3SlabListInit_c16, #Bs3SlabListInit_c32 or #Bs3SlabListInit_c64. */
1358
1359/**
1360 * Adds an initialized slab control structure to the list.
1361 *
1362 * @param pHead The slab list head to add it to.
1363 * @param pSlabCtl The slab control structure to add.
1364 */
1365BS3_DECL(void) Bs3SlabListAdd_c16(PBS3SLABHEAD pHead, PBS3SLABCTL pSlabCtl);
1366/** @copydoc Bs3SlabListAdd_c16 */
1367BS3_DECL(void) Bs3SlabListAdd_c32(PBS3SLABHEAD pHead, PBS3SLABCTL pSlabCtl);
1368/** @copydoc Bs3SlabListAdd_c16 */
1369BS3_DECL(void) Bs3SlabListAdd_c64(PBS3SLABHEAD pHead, PBS3SLABCTL pSlabCtl);
1370#define Bs3SlabListAdd BS3_CMN_NM(Bs3SlabListAdd) /**< Selects #Bs3SlabListAdd_c16, #Bs3SlabListAdd_c32 or #Bs3SlabListAdd_c64. */
1371
1372/**
1373 * Allocates one chunk.
1374 *
1375 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
1376 * @param pHead The slab list to allocate from.
1377 */
1378BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c16(PBS3SLABHEAD pHead);
1379BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c32(PBS3SLABHEAD pHead); /**< @copydoc Bs3SlabListAlloc_c16 */
1380BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c64(PBS3SLABHEAD pHead); /**< @copydoc Bs3SlabListAlloc_c16 */
1381#define Bs3SlabListAlloc BS3_CMN_NM(Bs3SlabListAlloc) /**< Selects #Bs3SlabListAlloc_c16, #Bs3SlabListAlloc_c32 or #Bs3SlabListAlloc_c64. */
1382
1383/**
1384 * Allocates one or more chunks.
1385 *
1386 * @returns Pointer to the request number of chunks on success, NULL if we're
1387 * out of chunks.
1388 * @param pHead The slab list to allocate from.
1389 * @param cChunks The number of contiguous chunks we want.
1390 * @param fFlags Flags, see BS3_SLAB_ALLOC_F_XXX
1391 */
1392BS3_DECL(void BS3_FAR *) Bs3SlabListAllocEx_c16(PBS3SLABHEAD pHead, uint16_t cChunks, uint16_t fFlags);
1393BS3_DECL(void BS3_FAR *) Bs3SlabListAllocEx_c32(PBS3SLABHEAD pHead, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabListAllocEx_c16 */
1394BS3_DECL(void BS3_FAR *) Bs3SlabListAllocEx_c64(PBS3SLABHEAD pHead, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabListAllocEx_c16 */
1395#define Bs3SlabListAllocEx BS3_CMN_NM(Bs3SlabListAllocEx) /**< Selects #Bs3SlabListAllocEx_c16, #Bs3SlabListAllocEx_c32 or #Bs3SlabListAllocEx_c64. */
1396
1397/**
1398 * Frees one or more chunks from a slab list.
1399 *
1400 * @param pHead The slab list to allocate from.
1401 * @param pvChunks Pointer to the first chunk to free.
1402 * @param cChunks The number of contiguous chunks to free.
1403 */
1404BS3_DECL(void) Bs3SlabListFree_c16(PBS3SLABHEAD pHead, void BS3_FAR *pvChunks, uint16_t cChunks);
1405BS3_DECL(void) Bs3SlabListFree_c32(PBS3SLABHEAD pHead, void BS3_FAR *pvChunks, uint16_t cChunks); /**< @copydoc Bs3SlabListFree_c16 */
1406BS3_DECL(void) Bs3SlabListFree_c64(PBS3SLABHEAD pHead, void BS3_FAR *pvChunks, uint16_t cChunks); /**< @copydoc Bs3SlabListFree_c16 */
1407#define Bs3SlabListFree BS3_CMN_NM(Bs3SlabListFree) /**< Selects #Bs3SlabListFree_c16, #Bs3SlabListFree_c32 or #Bs3SlabListFree_c64. */
1408
1409/**
1410 * Allocation addressing constraints.
1411 */
1412typedef enum BS3MEMKIND
1413{
1414 /** Invalid zero type. */
1415 BS3MEMKIND_INVALID = 0,
1416 /** Real mode addressable memory. */
1417 BS3MEMKIND_REAL,
1418 /** Memory addressable using the 16-bit protected mode tiling. */
1419 BS3MEMKIND_TILED,
1420 /** Memory addressable using 32-bit flat addressing. */
1421 BS3MEMKIND_FLAT32,
1422 /** Memory addressable using 64-bit flat addressing. */
1423 BS3MEMKIND_FLAT64,
1424 /** End of valid types. */
1425 BS3MEMKIND_END,
1426} BS3MEMKIND;
1427
1428/**
1429 * Allocates low memory.
1430 *
1431 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
1432 * @param enmKind The kind of addressing constraints imposed on the
1433 * allocation.
1434 * @param cb How much to allocate. Must be 4KB or less.
1435 */
1436BS3_DECL(void BS3_FAR *) Bs3MemAlloc_c16(BS3MEMKIND enmKind, size_t cb);
1437BS3_DECL(void BS3_FAR *) Bs3MemAlloc_c32(BS3MEMKIND enmKind, size_t cb); /**< @copydoc Bs3MemAlloc_c16 */
1438BS3_DECL(void BS3_FAR *) Bs3MemAlloc_c64(BS3MEMKIND enmKind, size_t cb); /**< @copydoc Bs3MemAlloc_c16 */
1439#define Bs3MemAlloc BS3_CMN_NM(Bs3MemAlloc) /**< Selects #Bs3MemAlloc_c16, #Bs3MemAlloc_c32 or #Bs3MemAlloc_c64. */
1440
1441/**
1442 * Allocates zero'ed memory.
1443 *
1444 * @param enmKind The kind of addressing constraints imposed on the
1445 * allocation.
1446 * @param cb How much to allocate. Must be 4KB or less.
1447 */
1448BS3_DECL(void BS3_FAR *) Bs3MemAllocZ_c16(BS3MEMKIND enmKind, size_t cb);
1449BS3_DECL(void BS3_FAR *) Bs3MemAllocZ_c32(BS3MEMKIND enmKind, size_t cb); /**< @copydoc Bs3MemAllocZ_c16 */
1450BS3_DECL(void BS3_FAR *) Bs3MemAllocZ_c64(BS3MEMKIND enmKind, size_t cb); /**< @copydoc Bs3MemAllocZ_c16 */
1451#define Bs3MemAllocZ BS3_CMN_NM(Bs3MemAllocZ) /**< Selects #Bs3MemAllocZ_c16, #Bs3MemAllocZ_c32 or #Bs3MemAllocZ_c64. */
1452
1453/**
1454 * Frees memory.
1455 *
1456 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
1457 * @param pv The memory to free (returned by #Bs3MemAlloc).
1458 * @param cb The size of the allocation.
1459 */
1460BS3_DECL(void) Bs3MemFree_c16(void BS3_FAR *pv, size_t cb);
1461BS3_DECL(void) Bs3MemFree_c32(void BS3_FAR *pv, size_t cb); /**< @copydoc Bs3MemFree_c16 */
1462BS3_DECL(void) Bs3MemFree_c64(void BS3_FAR *pv, size_t cb); /**< @copydoc Bs3MemFree_c16 */
1463#define Bs3MemFree BS3_CMN_NM(Bs3MemFree) /**< Selects #Bs3MemFree_c16, #Bs3MemFree_c32 or #Bs3MemFree_c64. */
1464
1465
1466/**
1467 * Enables the A20 gate.
1468 */
1469BS3_DECL(void) Bs3A20Enable_c16(void);
1470BS3_DECL(void) Bs3A20Enable_c32(void); /**< @copydoc Bs3A20Enable_c16 */
1471BS3_DECL(void) Bs3A20Enable_c64(void); /**< @copydoc Bs3A20Enable_c16 */
1472#define Bs3A20Enable BS3_CMN_NM(Bs3A20Enable) /**< Selects #Bs3A20Enable_c16, #Bs3A20Enable_c32 or #Bs3A20Enable_c64. */
1473
1474/**
1475 * Enables the A20 gate via the keyboard controller
1476 */
1477BS3_DECL(void) Bs3A20EnableViaKbd_c16(void);
1478BS3_DECL(void) Bs3A20EnableViaKbd_c32(void); /**< @copydoc Bs3A20EnableViaKbd_c16 */
1479BS3_DECL(void) Bs3A20EnableViaKbd_c64(void); /**< @copydoc Bs3A20EnableViaKbd_c16 */
1480#define Bs3A20EnableViaKbd BS3_CMN_NM(Bs3A20EnableViaKbd) /**< Selects #Bs3A20EnableViaKbd_c16, #Bs3A20EnableViaKbd_c32 or #Bs3A20EnableViaKbd_c64. */
1481
1482/**
1483 * Enables the A20 gate via the PS/2 control port A.
1484 */
1485BS3_DECL(void) Bs3A20EnableViaPortA_c16(void);
1486BS3_DECL(void) Bs3A20EnableViaPortA_c32(void); /**< @copydoc Bs3A20EnableViaPortA_c16 */
1487BS3_DECL(void) Bs3A20EnableViaPortA_c64(void); /**< @copydoc Bs3A20EnableViaPortA_c16 */
1488#define Bs3A20EnableViaPortA BS3_CMN_NM(Bs3A20EnableViaPortA) /**< Selects #Bs3A20EnableViaPortA_c16, #Bs3A20EnableViaPortA_c32 or #Bs3A20EnableViaPortA_c64. */
1489
1490/**
1491 * Disables the A20 gate.
1492 */
1493BS3_DECL(void) Bs3A20Disable_c16(void);
1494BS3_DECL(void) Bs3A20Disable_c32(void); /**< @copydoc Bs3A20Disable_c16 */
1495BS3_DECL(void) Bs3A20Disable_c64(void); /**< @copydoc Bs3A20Disable_c16 */
1496#define Bs3A20Disable BS3_CMN_NM(Bs3A20Disable) /**< Selects #Bs3A20Disable_c16, #Bs3A20Disable_c32 or #Bs3A20Disable_c64. */
1497
1498/**
1499 * Disables the A20 gate via the keyboard controller
1500 */
1501BS3_DECL(void) Bs3A20DisableViaKbd_c16(void);
1502BS3_DECL(void) Bs3A20DisableViaKbd_c32(void); /**< @copydoc Bs3A20DisableViaKbd_c16 */
1503BS3_DECL(void) Bs3A20DisableViaKbd_c64(void); /**< @copydoc Bs3A20DisableViaKbd_c16 */
1504#define Bs3A20DisableViaKbd BS3_CMN_NM(Bs3A20DisableViaKbd) /**< Selects #Bs3A20DisableViaKbd_c16, #Bs3A20DisableViaKbd_c32 or #Bs3A20DisableViaKbd_c64. */
1505
1506/**
1507 * Disables the A20 gate via the PS/2 control port A.
1508 */
1509BS3_DECL(void) Bs3A20DisableViaPortA_c16(void);
1510BS3_DECL(void) Bs3A20DisableViaPortA_c32(void); /**< @copydoc Bs3A20DisableViaPortA_c16 */
1511BS3_DECL(void) Bs3A20DisableViaPortA_c64(void); /**< @copydoc Bs3A20DisableViaPortA_c16 */
1512#define Bs3A20DisableViaPortA BS3_CMN_NM(Bs3A20DisableViaPortA) /**< Selects #Bs3A20DisableViaPortA_c16, #Bs3A20DisableViaPortA_c32 or #Bs3A20DisableViaPortA_c64. */
1513
1514
1515/**
1516 * Initializes root page tables for page protected mode (PP16, PP32).
1517 *
1518 * @returns IPRT status code.
1519 * @remarks Must not be called in real-mode!
1520 */
1521BS3_DECL(int) Bs3PagingInitRootForPP_c16(void);
1522BS3_DECL(int) Bs3PagingInitRootForPP_c32(void); /**< @copydoc Bs3PagingInitRootForPP_c16 */
1523BS3_DECL(int) Bs3PagingInitRootForPP_c64(void); /**< @copydoc Bs3PagingInitRootForPP_c16 */
1524#define Bs3PagingInitRootForPP BS3_CMN_NM(Bs3PagingInitRootForPP) /**< Selects #Bs3PagingInitRootForPP_c16, #Bs3PagingInitRootForPP_c32 or #Bs3PagingInitRootForPP_c64. */
1525
1526/**
1527 * Initializes root page tables for PAE page protected mode (PAE16, PAE32).
1528 *
1529 * @returns IPRT status code.
1530 * @remarks The default long mode page tables depends on the PAE ones.
1531 * @remarks Must not be called in real-mode!
1532 */
1533BS3_DECL(int) Bs3PagingInitRootForPAE_c16(void);
1534BS3_DECL(int) Bs3PagingInitRootForPAE_c32(void); /**< @copydoc Bs3PagingInitRootForPAE_c16 */
1535BS3_DECL(int) Bs3PagingInitRootForPAE_c64(void); /**< @copydoc Bs3PagingInitRootForPAE_c16 */
1536#define Bs3PagingInitRootForPAE BS3_CMN_NM(Bs3PagingInitRootForPAE) /**< Selects #Bs3PagingInitRootForPAE_c16, #Bs3PagingInitRootForPAE_c32 or #Bs3PagingInitRootForPAE_c64. */
1537
1538/**
1539 * Initializes root page tables for long mode (LM16, LM32, LM64).
1540 *
1541 * @returns IPRT status code.
1542 * @remarks The default long mode page tables depends on the PAE ones.
1543 * @remarks Must not be called in real-mode!
1544 */
1545BS3_DECL(int) Bs3PagingInitRootForLM_c16(void);
1546BS3_DECL(int) Bs3PagingInitRootForLM_c32(void); /**< @copydoc Bs3PagingInitRootForLM_c16 */
1547BS3_DECL(int) Bs3PagingInitRootForLM_c64(void); /**< @copydoc Bs3PagingInitRootForLM_c16 */
1548#define Bs3PagingInitRootForLM BS3_CMN_NM(Bs3PagingInitRootForLM) /**< Selects #Bs3PagingInitRootForLM_c16, #Bs3PagingInitRootForLM_c32 or #Bs3PagingInitRootForLM_c64. */
1549
1550
1551/**
1552 * Waits for the keyboard controller to become ready.
1553 */
1554BS3_DECL(void) Bs3KbdWait_c16(void);
1555BS3_DECL(void) Bs3KbdWait_c32(void); /**< @copydoc Bs3KbdWait_c16 */
1556BS3_DECL(void) Bs3KbdWait_c64(void); /**< @copydoc Bs3KbdWait_c16 */
1557#define Bs3KbdWait BS3_CMN_NM(Bs3KbdWait) /**< Selects #Bs3KbdWait_c16, #Bs3KbdWait_c32 or #Bs3KbdWait_c64. */
1558
1559/**
1560 * Sends a read command to the keyboard controller and gets the result.
1561 *
1562 * The caller is responsible for making sure the keyboard controller is ready
1563 * for a command (call #Bs3KbdWait if unsure).
1564 *
1565 * @returns The value read is returned (in al).
1566 * @param bCmd The read command.
1567 */
1568BS3_DECL(uint8_t) Bs3KbdRead_c16(uint8_t bCmd);
1569BS3_DECL(uint8_t) Bs3KbdRead_c32(uint8_t bCmd); /**< @copydoc Bs3KbdRead_c16 */
1570BS3_DECL(uint8_t) Bs3KbdRead_c64(uint8_t bCmd); /**< @copydoc Bs3KbdRead_c16 */
1571#define Bs3KbdRead BS3_CMN_NM(Bs3KbdRead) /**< Selects #Bs3KbdRead_c16, #Bs3KbdRead_c32 or #Bs3KbdRead_c64. */
1572
1573/**
1574 * Sends a write command to the keyboard controller and then sends the data.
1575 *
1576 * The caller is responsible for making sure the keyboard controller is ready
1577 * for a command (call #Bs3KbdWait if unsure).
1578 *
1579 * @param bCmd The write command.
1580 * @param bData The data to write.
1581 */
1582BS3_DECL(void) Bs3KbdWrite_c16(uint8_t bCmd, uint8_t bData);
1583BS3_DECL(void) Bs3KbdWrite_c32(uint8_t bCmd, uint8_t bData); /**< @copydoc Bs3KbdWrite_c16 */
1584BS3_DECL(void) Bs3KbdWrite_c64(uint8_t bCmd, uint8_t bData); /**< @copydoc Bs3KbdWrite_c16 */
1585#define Bs3KbdWrite BS3_CMN_NM(Bs3KbdWrite) /**< Selects #Bs3KbdWrite_c16, #Bs3KbdWrite_c32 or #Bs3KbdWrite_c64. */
1586
1587
1588/**
1589 * BS3 integer register.
1590 */
1591typedef union BS3REG
1592{
1593 /** 8-bit unsigned integer. */
1594 uint8_t u8;
1595 /** 16-bit unsigned integer. */
1596 uint16_t u16;
1597 /** 32-bit unsigned integer. */
1598 uint32_t u32;
1599 /** 64-bit unsigned integer. */
1600 uint64_t u64;
1601 /** Full unsigned integer. */
1602 uint64_t u;
1603 /** High/low byte view. */
1604 struct
1605 {
1606 uint8_t bLo;
1607 uint8_t bHi;
1608 } b;
1609 /** 8-bit view. */
1610 uint8_t au8[8];
1611 /** 16-bit view. */
1612 uint16_t au16[4];
1613 /** 32-bit view. */
1614 uint32_t au32[2];
1615} BS3REG;
1616/** Pointer to an integer register. */
1617typedef BS3REG BS3_FAR *PBS3REG;
1618/** Pointer to a const integer register. */
1619typedef BS3REG const BS3_FAR *PCBS3REG;
1620
1621/**
1622 * Register context (without FPU).
1623 */
1624typedef struct BS3REGCTX
1625{
1626 BS3REG rax;
1627 BS3REG rcx;
1628 BS3REG rdx;
1629 BS3REG rbx;
1630 BS3REG rsp;
1631 BS3REG rbp;
1632 BS3REG rsi;
1633 BS3REG rdi;
1634 BS3REG r8;
1635 BS3REG r9;
1636 BS3REG r10;
1637 BS3REG r11;
1638 BS3REG r12;
1639 BS3REG r13;
1640 BS3REG r14;
1641 BS3REG r15;
1642 BS3REG rflags;
1643 BS3REG rip;
1644 uint16_t cs;
1645 uint16_t ds;
1646 uint16_t es;
1647 uint16_t fs;
1648 uint16_t gs;
1649 uint16_t ss;
1650 uint16_t tr;
1651 uint16_t ldtr;
1652 uint8_t cBits;
1653 uint8_t abPadding[7];
1654 BS3REG cr0;
1655 BS3REG cr2;
1656 BS3REG cr3;
1657 BS3REG cr4;
1658} BS3REGCTX;
1659/** Pointer to a register context. */
1660typedef BS3REGCTX BS3_FAR *PBS3REGCTX;
1661/** Pointer to a const register context. */
1662typedef BS3REGCTX const BS3_FAR *PCBS3REGCTX;
1663
1664
1665/**
1666 * Trap frame.
1667 */
1668typedef struct BS3TRAPFRAME
1669{
1670 /** Exception/interrupt number. */
1671 uint8_t bXcpt;
1672 /** Explicit alignment. */
1673 uint8_t bAlignment;
1674 /** The handler CS. */
1675 uint16_t uHandlerCc;
1676 /** The handler SS. */
1677 uint16_t uHandlerSs;
1678 /** The handler RSP (top of iret frame). */
1679 uint64_t uHandlerRsp;
1680 /** The handler RFLAGS value. */
1681 uint64_t fHandlerRfl;
1682 /** The error code (if applicable). */
1683 uint64_t uErrCd;
1684 /** The register context. */
1685 BS3REGCTX Ctx;
1686} BS3TRAPFRAME;
1687/** Pointer to a trap frame. */
1688typedef BS3TRAPFRAME BS3_FAR *PBS3TRAPFRAME;
1689/** Pointer to a const trap frame. */
1690typedef BS3TRAPFRAME const BS3_FAR *PCBS3TRAPFRAME;
1691
1692/**
1693 * Resumes execution of a 32-bit trap frame.
1694 *
1695 * @param pTrapFrame Trap frame to resume.
1696 * @param fFlags Flags, BS3TRAPRESUME_F_XXX.
1697 */
1698BS3_DECL(void) Bs3Trap32ResumeFrame_c32(BS3TRAPFRAME BS3_FAR *pTrapFrame, uint16_t fFlags);
1699#define Bs3Trap32ResumeFrame BS3_CMN_NM(Bs3Trap32ResumeFrame) /**< Selects Bs3Trap32ResumeFrame_c16 (not implemented), #Bs3Trap32ResumeFrame_c32 or Bs3Trap32ResumeFrame_c64 (not implemented). */
1700
1701/** Skip restoring the CRx registers. */
1702#define BS3TRAPRESUME_F_SKIP_CRX UINT16_C(0x0001)
1703
1704/**
1705 * Initializes 16-bit (protected mode) trap handling.
1706 *
1707 * @remarks Does not install 16-bit trap handling, just initializes the
1708 * structures.
1709 */
1710BS3_DECL(void) Bs3Trap16Init_c16(void);
1711BS3_DECL(void) Bs3Trap16Init_c32(void); /**< @copydoc Bs3Trap16Init_c16 */
1712BS3_DECL(void) Bs3Trap16Init_c64(void); /**< @copydoc Bs3Trap16Init_c16 */
1713#define Bs3Trap16Init BS3_CMN_NM(Bs3Trap16Init) /**< Selects #Bs3Trap16Init_c16, #Bs3Trap16Init_c32 or #Bs3Trap16Init_c64. */
1714
1715/**
1716 * Initializes 32-bit trap handling.
1717 *
1718 * @remarks Does not install 32-bit trap handling, just initializes the
1719 * structures.
1720 */
1721BS3_DECL(void) Bs3Trap32Init_c16(void);
1722BS3_DECL(void) Bs3Trap32Init_c32(void); /**< @copydoc Bs3Trap32Init_c16 */
1723BS3_DECL(void) Bs3Trap32Init_c64(void); /**< @copydoc Bs3Trap32Init_c16 */
1724#define Bs3Trap32Init BS3_CMN_NM(Bs3Trap32Init) /**< Selects #Bs3Trap32Init_c16, #Bs3Trap32Init_c32 or #Bs3Trap32Init_c64. */
1725
1726/**
1727 * Initializes 64-bit trap handling
1728 *
1729 * @remarks Does not install 64-bit trap handling, just initializes the
1730 * structures.
1731 */
1732BS3_DECL(void) Bs3Trap64Init_c16(void);
1733BS3_DECL(void) Bs3Trap64Init_c32(void); /**< @copydoc Bs3Trap64Init_c16 */
1734BS3_DECL(void) Bs3Trap64Init_c64(void); /**< @copydoc Bs3Trap64Init_c16 */
1735#define Bs3Trap64Init BS3_CMN_NM(Bs3Trap64Init) /**< Selects #Bs3Trap64Init_c16, #Bs3Trap64Init_c32 or #Bs3Trap64Init_c64. */
1736
1737/**
1738 * Modifies the 16-bit IDT entry (protected mode) specified by @a iIdt.
1739 *
1740 * @param iIdt The index of the IDT entry to set.
1741 * @param bType The gate type (X86_SEL_TYPE_SYS_XXX).
1742 * @param bDpl The DPL.
1743 * @param uSel The handler selector.
1744 * @param off The handler offset (if applicable).
1745 * @param cParams The parameter count (for call gates).
1746 */
1747BS3_DECL(void) Bs3Trap16SetGate_c16(uint8_t iIdt, uint8_t bType, uint8_t bDpl, uint16_t uSel, uint16_t off, uint8_t cParams);
1748BS3_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 */
1749BS3_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 */
1750#define Bs3Trap16SetGate BS3_CMN_NM(Bs3Trap16SetGate) /**< Selects #Bs3Trap16SetGate_c16, #Bs3Trap16SetGate_c32 or #Bs3Trap16SetGate_c64. */
1751
1752/** The address of Bs3Trap16GenericEntries.
1753 * Bs3Trap16GenericEntries is an array of interrupt/trap/whatever entry
1754 * points, 8 bytes each, that will create a register frame and call the generic
1755 * C compatible trap handlers. */
1756extern uint32_t BS3_DATA_NM(g_Bs3Trap16GenericEntriesFlatAddr);
1757
1758/**
1759 * Modifies the 32-bit IDT entry specified by @a iIdt.
1760 *
1761 * @param iIdt The index of the IDT entry to set.
1762 * @param bType The gate type (X86_SEL_TYPE_SYS_XXX).
1763 * @param bDpl The DPL.
1764 * @param uSel The handler selector.
1765 * @param off The handler offset (if applicable).
1766 * @param cParams The parameter count (for call gates).
1767 */
1768BS3_DECL(void) Bs3Trap32SetGate_c16(uint8_t iIdt, uint8_t bType, uint8_t bDpl, uint16_t uSel, uint32_t off, uint8_t cParams);
1769BS3_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 */
1770BS3_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 */
1771#define Bs3Trap32SetGate BS3_CMN_NM(Bs3Trap32SetGate) /**< Selects #Bs3Trap32SetGate_c16, #Bs3Trap32SetGate_c32 or #Bs3Trap32SetGate_c64. */
1772
1773/** The address of Bs3Trap32GenericEntries.
1774 * Bs3Trap32GenericEntries is an array of interrupt/trap/whatever entry
1775 * points, 8 bytes each, that will create a register frame and call the generic
1776 * C compatible trap handlers. */
1777extern uint32_t BS3_DATA_NM(g_Bs3Trap32GenericEntriesFlatAddr);
1778
1779/**
1780 * Modifies the 64-bit IDT entry specified by @a iIdt.
1781 *
1782 * @param iIdt The index of the IDT entry to set.
1783 * @param bType The gate type (X86_SEL_TYPE_SYS_XXX).
1784 * @param bDpl The DPL.
1785 * @param uSel The handler selector.
1786 * @param off The handler offset (if applicable).
1787 * @param bIst The interrupt stack to use.
1788 */
1789BS3_DECL(void) Bs3Trap64SetGate_c16(uint8_t iIdt, uint8_t bType, uint8_t bDpl, uint16_t uSel, uint64_t off, uint8_t bIst);
1790BS3_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 */
1791BS3_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 */
1792#define Bs3Trap64SetGate BS3_CMN_NM(Bs3Trap64SetGate) /**< Selects #Bs3Trap64SetGate_c16, #Bs3Trap64SetGate_c32 or #Bs3Trap64SetGate_c64. */
1793
1794/** The address of Bs3Trap64GenericEntries.
1795 * Bs3Trap64GenericEntries is an array of interrupt/trap/whatever entry
1796 * points, 8 bytes each, that will create a register frame and call the generic
1797 * C compatible trap handlers. */
1798extern uint32_t BS3_DATA_NM(g_Bs3Trap64GenericEntriesFlatAddr);
1799
1800/**
1801 * C-style trap handler.
1802 *
1803 * Upon return Bs3Trap16ResumeFrame_c16, #Bs3Trap32ResumeFrame_c32, or
1804 * Bs3Trap64ResumeFrame_c64 will be called depending on the current template
1805 * context.
1806 *
1807 * @param pTrapFrame The trap frame. Registers can be modified.
1808 */
1809typedef BS3_DECL_CALLBACK(void) FNBS3TRAPHANDLER(PBS3TRAPFRAME pTrapFrame);
1810/** Pointer to a trap handler (current template context). */
1811typedef FNBS3TRAPHANDLER *PFNBS3TRAPHANDLER;
1812
1813/**
1814 * Sets a trap handler (C/C++/assembly) for the current bitness.
1815 *
1816 * When using a 32-bit IDT, only #Bs3TrapSetHandler_c32 will have any effect.
1817 * Likewise, when using a 16-bit IDT, only Bs3TrapSetHandler_c16 will make any
1818 * difference. Ditto 64-bit.
1819 *
1820 * Rational: It's mainly a C API, can't easily mix function pointers from other
1821 * bit counts in C. Use assembly helpers or something if that is necessary.
1822 * Besides, most of the real trap handling goes thru the default handler with
1823 * help of trap records.
1824 *
1825 * @returns Previous handler.
1826 * @param iIdt The index of the IDT entry to set.
1827 * @param pfnHandler Pointer to the handler.
1828 */
1829BS3_DECL(PFNBS3TRAPHANDLER) Bs3TrapSetHandler_c16(uint8_t iIdt, PFNBS3TRAPHANDLER pfnHandler);
1830BS3_DECL(PFNBS3TRAPHANDLER) Bs3TrapSetHandler_c32(uint8_t iIdt, PFNBS3TRAPHANDLER pfnHandler); /**< @copydoc Bs3Trap32SetHandler_c16 */
1831BS3_DECL(PFNBS3TRAPHANDLER) Bs3TrapSetHandler_c64(uint8_t iIdt, PFNBS3TRAPHANDLER pfnHandler); /**< @copydoc Bs3Trap32SetHandler_c16 */
1832#define Bs3Trap32SetHandler BS3_CMN_NM(Bs3Trap32SetHandler) /**< Selects #Bs3Trap32SetHandler_c16, #Bs3Trap32SetHandler_c32 or #Bs3Trap32SetHandler_c64. */
1833
1834/**
1835 * Default C/C++ trap handler.
1836 *
1837 * This will check trap record and panic if no match was found.
1838 *
1839 * @param pTrapFrame Trap frame of the trap to handle.
1840 */
1841BS3_DECL(void) Bs3TrapDefaultHandler_c16(PBS3TRAPFRAME pTrapFrame);
1842BS3_DECL(void) Bs3TrapDefaultHandler_c32(PBS3TRAPFRAME pTrapFrame); /**< @copydoc Bs3TrapDefaultHandler_c16 */
1843BS3_DECL(void) Bs3TrapDefaultHandler_c64(PBS3TRAPFRAME pTrapFrame); /**< @copydoc Bs3TrapDefaultHandler_c16 */
1844#define Bs3TrapDefaultHandler BS3_CMN_NM(Bs3TrapDefaultHandler) /**< Selects #Bs3TrapDefaultHandler_c16, #Bs3TrapDefaultHandler_c32 or #Bs3TrapDefaultHandler_c64. */
1845
1846/**
1847 * Prints the trap frame (to screen).
1848 * @param pTrapFrame Trap frame to print.
1849 */
1850BS3_DECL(void) Bs3TrapPrintFrame_c16(PCBS3TRAPFRAME pTrapFrame);
1851BS3_DECL(void) Bs3TrapPrintFrame_c32(PCBS3TRAPFRAME pTrapFrame); /**< @copydoc Bs3TrapPrintFrame_c16 */
1852BS3_DECL(void) Bs3TrapPrintFrame_c64(PCBS3TRAPFRAME pTrapFrame); /**< @copydoc Bs3TrapPrintFrame_c16 */
1853#define Bs3TrapPrintFrame BS3_CMN_NM(Bs3TrapPrintFrame) /**< Selects #Bs3TrapPrintFrame_c16, #Bs3TrapPrintFrame_c32 or #Bs3TrapPrintFrame_c64. */
1854
1855/** @} */
1856
1857
1858/**
1859 * Initializes the REAL and TILED memory pools.
1860 */
1861BS3_DECL(void) Bs3InitMemory_rm(void);
1862
1863
1864/** @defgroup grp_bs3kit_mode Mode Specific Functions and Data
1865 *
1866 * The mode specific functions come in bit count variations and CPU mode
1867 * variations. The bs3kit-template-header.h/mac defines the BS3_NM macro to
1868 * mangle a function or variable name according to the target CPU mode. In
1869 * non-templated code, it's common to spell the name out in full.
1870 *
1871 * @{
1872 */
1873
1874
1875/** @} */
1876
1877RT_C_DECLS_END
1878
1879
1880#endif
1881
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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