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