1 | /* $Id: bs3kit.h 60777 2016-05-02 08:36:54Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * BS3Kit - structures, symbols, macros and stuff.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2016 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 | #define RT_NO_STRICT /* Don't drag in IPRT assertion code in inline code we may use (asm.h). */
|
---|
34 | #include <iprt/cdefs.h>
|
---|
35 | #include <iprt/types.h>
|
---|
36 | #ifndef DOXYGEN_RUNNING
|
---|
37 | # undef IN_RING0
|
---|
38 | #endif
|
---|
39 |
|
---|
40 |
|
---|
41 |
|
---|
42 | /** @def BS3_USE_ALT_16BIT_TEXT_SEG
|
---|
43 | * @ingroup grp_bs3kit
|
---|
44 | * Combines the BS3_USE_RM_TEXT_SEG, BS3_USE_X0_TEXT_SEG, and
|
---|
45 | * BS3_USE_X1_TEXT_SEG indicators into a single one.
|
---|
46 | */
|
---|
47 | #if defined(BS3_USE_RM_TEXT_SEG) || defined(BS3_USE_X0_TEXT_SEG) || defined(BS3_USE_X1_TEXT_SEG)
|
---|
48 | # define BS3_USE_ALT_16BIT_TEXT_SEG
|
---|
49 | #else
|
---|
50 | # undef BS3_USE_ALT_16BIT_TEXT_SEG
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | /** @def BS3_USE_X0_TEXT_SEG
|
---|
54 | * @ingroup grp_bs3kit
|
---|
55 | * Emit 16-bit code to the BS3X0TEXT16 segment - ignored for 32-bit and 64-bit.
|
---|
56 | *
|
---|
57 | * Calling directly into the BS3X0TEXT16 segment is only possible in real-mode
|
---|
58 | * and v8086 mode. In protected mode the real far pointer have to be converted
|
---|
59 | * to a protected mode pointer that uses BS3_SEL_X0TEXT16_CS, Bs3TestDoModes and
|
---|
60 | * associates does this automatically.
|
---|
61 | */
|
---|
62 | #ifdef DOXYGEN_RUNNING
|
---|
63 | # define BS3_USE_X0_TEXT_SEG
|
---|
64 | #endif
|
---|
65 |
|
---|
66 | /** @def BS3_USE_X1_TEXT_SEG
|
---|
67 | * @ingroup grp_bs3kit
|
---|
68 | * Emit 16-bit code to the BS3X1TEXT16 segment - ignored for 32-bit and 64-bit.
|
---|
69 | *
|
---|
70 | * Calling directly into the BS3X1TEXT16 segment is only possible in real-mode
|
---|
71 | * and v8086 mode. In protected mode the real far pointer have to be converted
|
---|
72 | * to a protected mode pointer that uses BS3_SEL_X1TEXT16_CS, Bs3TestDoModes and
|
---|
73 | * associates does this automatically.
|
---|
74 | */
|
---|
75 | #ifdef DOXYGEN_RUNNING
|
---|
76 | # define BS3_USE_X1_TEXT_SEG
|
---|
77 | #endif
|
---|
78 |
|
---|
79 | /** @def BS3_USE_RM_TEXT_SEG
|
---|
80 | * @ingroup grp_bs3kit
|
---|
81 | * Emit 16-bit code to the BS3RMTEXT16 segment - ignored for 32-bit and 64-bit.
|
---|
82 | *
|
---|
83 | * This segment is normally used for real-mode only code, though
|
---|
84 | * BS3_SEL_RMTEXT16_CS can be used to call it from protected mode. Unlike the
|
---|
85 | * BS3X0TEXT16 and BS3X1TEXT16 segments which are empty by default, this segment
|
---|
86 | * is used by common BS3Kit code.
|
---|
87 | */
|
---|
88 | #ifdef DOXYGEN_RUNNING
|
---|
89 | # define BS3_USE_X0_TEXT_SEG
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | /** @def BS3_MODEL_FAR_CODE
|
---|
93 | * @ingroup grp_bs3kit
|
---|
94 | * Default compiler model indicates far code.
|
---|
95 | */
|
---|
96 | #ifdef DOXYGEN_RUNNING
|
---|
97 | # define BS3_MODEL_FAR_CODE
|
---|
98 | #elif !defined(BS3_MODEL_FAR_CODE) && (defined(__LARGE__) || defined(__MEDIUM__) || defined(__HUGE__)) && ARCH_BITS == 16
|
---|
99 | # define BS3_MODEL_FAR_CODE
|
---|
100 | #endif
|
---|
101 |
|
---|
102 |
|
---|
103 | /*
|
---|
104 | * We normally don't want the noreturn / aborts attributes as they mess up stack traces.
|
---|
105 | *
|
---|
106 | * Note! pragma aux <fnname> aborts can only be used with functions
|
---|
107 | * implemented in C and functions that does not have parameters.
|
---|
108 | */
|
---|
109 | #define BS3_KIT_WITH_NO_RETURN
|
---|
110 | #ifndef BS3_KIT_WITH_NO_RETURN
|
---|
111 | # undef DECL_NO_RETURN
|
---|
112 | # define DECL_NO_RETURN(type) type
|
---|
113 | #endif
|
---|
114 |
|
---|
115 |
|
---|
116 | /*
|
---|
117 | * We may want to reuse some IPRT code in the common name space, so we
|
---|
118 | * redefine the RT_MANGLER to work like BS3_CMN_NM. (We cannot use
|
---|
119 | * BS3_CMN_NM yet, as we need to include IPRT headers with function
|
---|
120 | * declarations before we can define it. Thus the duplciate effort.)
|
---|
121 | */
|
---|
122 | #if ARCH_BITS == 16
|
---|
123 | # undef RTCALL
|
---|
124 | # if defined(BS3_USE_ALT_16BIT_TEXT_SEG)
|
---|
125 | # define RTCALL __cdecl __far
|
---|
126 | # define RT_MANGLER(a_Name) RT_CONCAT(a_Name,_f16)
|
---|
127 | # else
|
---|
128 | # define RTCALL __cdecl __near
|
---|
129 | # define RT_MANGLER(a_Name) RT_CONCAT(a_Name,_c16)
|
---|
130 | # endif
|
---|
131 | #else
|
---|
132 | # define RT_MANGLER(a_Name) RT_CONCAT3(a_Name,_c,ARCH_BITS)
|
---|
133 | #endif
|
---|
134 | #include <iprt/mangling.h>
|
---|
135 | #include <iprt/x86.h>
|
---|
136 | #include <iprt/err.h>
|
---|
137 |
|
---|
138 | /*
|
---|
139 | * Include data symbol mangling (function mangling/mapping must be done
|
---|
140 | * after the protypes).
|
---|
141 | */
|
---|
142 | #include "bs3kit-mangling-data.h"
|
---|
143 |
|
---|
144 |
|
---|
145 |
|
---|
146 | RT_C_DECLS_BEGIN
|
---|
147 |
|
---|
148 | /** @defgroup grp_bs3kit BS3Kit - Boot Sector Kit \#3
|
---|
149 | *
|
---|
150 | * The BS3Kit is a framework for bare metal floppy/usb image tests,
|
---|
151 | * see the @ref pg_bs3kit "doc page" for more.
|
---|
152 | *
|
---|
153 | * @{ */
|
---|
154 |
|
---|
155 | /** @name Execution modes.
|
---|
156 | * @{ */
|
---|
157 | #define BS3_MODE_INVALID UINT8_C(0x00)
|
---|
158 | #define BS3_MODE_RM UINT8_C(0x01) /**< real mode. */
|
---|
159 | #define BS3_MODE_PE16 UINT8_C(0x11) /**< 16-bit protected mode kernel+tss, running 16-bit code, unpaged. */
|
---|
160 | #define BS3_MODE_PE16_32 UINT8_C(0x12) /**< 16-bit protected mode kernel+tss, running 32-bit code, unpaged. */
|
---|
161 | #define BS3_MODE_PE16_V86 UINT8_C(0x18) /**< 16-bit protected mode kernel+tss, running virtual 8086 mode code, unpaged. */
|
---|
162 | #define BS3_MODE_PE32 UINT8_C(0x22) /**< 32-bit protected mode kernel+tss, running 32-bit code, unpaged. */
|
---|
163 | #define BS3_MODE_PE32_16 UINT8_C(0x21) /**< 32-bit protected mode kernel+tss, running 16-bit code, unpaged. */
|
---|
164 | #define BS3_MODE_PEV86 UINT8_C(0x28) /**< 32-bit protected mode kernel+tss, running virtual 8086 mode code, unpaged. */
|
---|
165 | #define BS3_MODE_PP16 UINT8_C(0x31) /**< 16-bit protected mode kernel+tss, running 16-bit code, paged. */
|
---|
166 | #define BS3_MODE_PP16_32 UINT8_C(0x32) /**< 16-bit protected mode kernel+tss, running 32-bit code, paged. */
|
---|
167 | #define BS3_MODE_PP16_V86 UINT8_C(0x38) /**< 16-bit protected mode kernel+tss, running virtual 8086 mode code, paged. */
|
---|
168 | #define BS3_MODE_PP32 UINT8_C(0x42) /**< 32-bit protected mode kernel+tss, running 32-bit code, paged. */
|
---|
169 | #define BS3_MODE_PP32_16 UINT8_C(0x41) /**< 32-bit protected mode kernel+tss, running 16-bit code, paged. */
|
---|
170 | #define BS3_MODE_PPV86 UINT8_C(0x48) /**< 32-bit protected mode kernel+tss, running virtual 8086 mode code, paged. */
|
---|
171 | #define BS3_MODE_PAE16 UINT8_C(0x51) /**< 16-bit protected mode kernel+tss, running 16-bit code, PAE paging. */
|
---|
172 | #define BS3_MODE_PAE16_32 UINT8_C(0x52) /**< 16-bit protected mode kernel+tss, running 32-bit code, PAE paging. */
|
---|
173 | #define BS3_MODE_PAE16_V86 UINT8_C(0x58) /**< 16-bit protected mode kernel+tss, running virtual 8086 mode, PAE paging. */
|
---|
174 | #define BS3_MODE_PAE32 UINT8_C(0x62) /**< 32-bit protected mode kernel+tss, running 32-bit code, PAE paging. */
|
---|
175 | #define BS3_MODE_PAE32_16 UINT8_C(0x61) /**< 32-bit protected mode kernel+tss, running 16-bit code, PAE paging. */
|
---|
176 | #define BS3_MODE_PAEV86 UINT8_C(0x68) /**< 32-bit protected mode kernel+tss, running virtual 8086 mode, PAE paging. */
|
---|
177 | #define BS3_MODE_LM16 UINT8_C(0x71) /**< 16-bit long mode (paged), kernel+tss always 64-bit. */
|
---|
178 | #define BS3_MODE_LM32 UINT8_C(0x72) /**< 32-bit long mode (paged), kernel+tss always 64-bit. */
|
---|
179 | #define BS3_MODE_LM64 UINT8_C(0x74) /**< 64-bit long mode (paged), kernel+tss always 64-bit. */
|
---|
180 |
|
---|
181 | #define BS3_MODE_CODE_MASK UINT8_C(0x0f) /**< Running code mask. */
|
---|
182 | #define BS3_MODE_CODE_16 UINT8_C(0x01) /**< Running 16-bit code. */
|
---|
183 | #define BS3_MODE_CODE_32 UINT8_C(0x02) /**< Running 32-bit code. */
|
---|
184 | #define BS3_MODE_CODE_64 UINT8_C(0x04) /**< Running 64-bit code. */
|
---|
185 | #define BS3_MODE_CODE_V86 UINT8_C(0x08) /**< Running 16-bit virtual 8086 code. */
|
---|
186 |
|
---|
187 | #define BS3_MODE_SYS_MASK UINT8_C(0xf0) /**< kernel+tss mask. */
|
---|
188 | #define BS3_MODE_SYS_RM UINT8_C(0x00) /**< Real mode kernel+tss. */
|
---|
189 | #define BS3_MODE_SYS_PE16 UINT8_C(0x10) /**< 16-bit protected mode kernel+tss. */
|
---|
190 | #define BS3_MODE_SYS_PE32 UINT8_C(0x20) /**< 32-bit protected mode kernel+tss. */
|
---|
191 | #define BS3_MODE_SYS_PP16 UINT8_C(0x30) /**< 16-bit paged protected mode kernel+tss. */
|
---|
192 | #define BS3_MODE_SYS_PP32 UINT8_C(0x40) /**< 32-bit paged protected mode kernel+tss. */
|
---|
193 | #define BS3_MODE_SYS_PAE16 UINT8_C(0x50) /**< 16-bit PAE paged protected mode kernel+tss. */
|
---|
194 | #define BS3_MODE_SYS_PAE32 UINT8_C(0x60) /**< 32-bit PAE paged protected mode kernel+tss. */
|
---|
195 | #define BS3_MODE_SYS_LM UINT8_C(0x70) /**< 64-bit (paged) long mode protected mode kernel+tss. */
|
---|
196 |
|
---|
197 | /** Whether the mode has paging enabled. */
|
---|
198 | #define BS3_MODE_IS_PAGED(a_fMode) ((a_fMode) >= BS3_MODE_PP16)
|
---|
199 | /** Whether the mode has legacy paging enabled (legacy as opposed to PAE or
|
---|
200 | * long mode). */
|
---|
201 | #define BS3_MODE_IS_LEGACY_PAGING(a_fMode) ((a_fMode) >= BS3_MODE_PP16 && (a_fMode) < BS3_MODE_PAE16)
|
---|
202 |
|
---|
203 | /** Whether the mode is running v8086 code. */
|
---|
204 | #define BS3_MODE_IS_V86(a_fMode) (((a_fMode) & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_V86)
|
---|
205 | /** Whether the we're executing in real mode or v8086 mode. */
|
---|
206 | #define BS3_MODE_IS_RM_OR_V86(a_fMode) ((a_fMode) == BS3_MODE_RM || BS3_MODE_IS_V86(a_fMode))
|
---|
207 | /** Whether the mode is running 16-bit code, except v8086. */
|
---|
208 | #define BS3_MODE_IS_16BIT_CODE_NO_V86(a_fMode) (((a_fMode) & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_16)
|
---|
209 | /** Whether the mode is running 16-bit code (includes v8086). */
|
---|
210 | #define BS3_MODE_IS_16BIT_CODE(a_fMode) (BS3_MODE_IS_16BIT_CODE_NO_V86(a_fMode) || BS3_MODE_IS_V86(a_fMode))
|
---|
211 | /** Whether the mode is running 32-bit code. */
|
---|
212 | #define BS3_MODE_IS_32BIT_CODE(a_fMode) (((a_fMode) & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_32)
|
---|
213 | /** Whether the mode is running 64-bit code. */
|
---|
214 | #define BS3_MODE_IS_64BIT_CODE(a_fMode) (((a_fMode) & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_64)
|
---|
215 |
|
---|
216 | /** Whether the system is in real mode. */
|
---|
217 | #define BS3_MODE_IS_RM_SYS(a_fMode) (((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_RM)
|
---|
218 | /** Whether the system is some 16-bit mode that isn't real mode. */
|
---|
219 | #define BS3_MODE_IS_16BIT_SYS_NO_RM(a_fMode) ( ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PE16 \
|
---|
220 | || ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PP16 \
|
---|
221 | || ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PAE16)
|
---|
222 | /** Whether the system is some 16-bit mode (includes real mode). */
|
---|
223 | #define BS3_MODE_IS_16BIT_SYS(a_fMode) (BS3_MODE_IS_16BIT_SYS_NO_RM(a_fMode) || BS3_MODE_IS_RM_SYS(a_fMode))
|
---|
224 | /** Whether the system is some 32-bit mode. */
|
---|
225 | #define BS3_MODE_IS_32BIT_SYS(a_fMode) ( ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PE32 \
|
---|
226 | || ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PP32 \
|
---|
227 | || ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PAE32)
|
---|
228 | /** Whether the system is long mode. */
|
---|
229 | #define BS3_MODE_IS_64BIT_SYS(a_fMode) (((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_LM)
|
---|
230 |
|
---|
231 | /** @todo testcase: How would long-mode handle a 16-bit TSS loaded prior to the switch? (mainly stack switching wise) Hopefully, it will tripple fault, right? */
|
---|
232 | /** @} */
|
---|
233 |
|
---|
234 |
|
---|
235 | /** @name BS3_ADDR_XXX - Static Memory Allocation
|
---|
236 | * @{ */
|
---|
237 | /** The flat load address for the code after the bootsector. */
|
---|
238 | #define BS3_ADDR_LOAD 0x10000
|
---|
239 | /** Where we save the boot registers during init.
|
---|
240 | * Located right before the code. */
|
---|
241 | #define BS3_ADDR_REG_SAVE (BS3_ADDR_LOAD - sizeof(BS3REGCTX) - 8)
|
---|
242 | /** Where the stack starts (initial RSP value).
|
---|
243 | * Located 16 bytes (assumed by boot sector) before the saved registers.
|
---|
244 | * SS.BASE=0. The size is a little short of 32KB */
|
---|
245 | #define BS3_ADDR_STACK (BS3_ADDR_REG_SAVE - 16)
|
---|
246 | /** The ring-0 stack (8KB) for ring transitions. */
|
---|
247 | #define BS3_ADDR_STACK_R0 0x06000
|
---|
248 | /** The ring-1 stack (8KB) for ring transitions. */
|
---|
249 | #define BS3_ADDR_STACK_R1 0x04000
|
---|
250 | /** The ring-2 stack (8KB) for ring transitions. */
|
---|
251 | #define BS3_ADDR_STACK_R2 0x02000
|
---|
252 | /** IST1 ring-0 stack for long mode (4KB), used for double faults elsewhere. */
|
---|
253 | #define BS3_ADDR_STACK_R0_IST1 0x09000
|
---|
254 | /** IST2 ring-0 stack for long mode (3KB), used for spare 0 stack elsewhere. */
|
---|
255 | #define BS3_ADDR_STACK_R0_IST2 0x08000
|
---|
256 | /** IST3 ring-0 stack for long mode (1KB). */
|
---|
257 | #define BS3_ADDR_STACK_R0_IST3 0x07400
|
---|
258 | /** IST4 ring-0 stack for long mode (1KB), used for spare 1 stack elsewhere. */
|
---|
259 | #define BS3_ADDR_STACK_R0_IST4 0x07000
|
---|
260 | /** IST5 ring-0 stack for long mode (1KB). */
|
---|
261 | #define BS3_ADDR_STACK_R0_IST5 0x06c00
|
---|
262 | /** IST6 ring-0 stack for long mode (1KB). */
|
---|
263 | #define BS3_ADDR_STACK_R0_IST6 0x06800
|
---|
264 | /** IST7 ring-0 stack for long mode (1KB). */
|
---|
265 | #define BS3_ADDR_STACK_R0_IST7 0x06400
|
---|
266 |
|
---|
267 | /** The base address of the BS3TEXT16 segment (same as BS3_LOAD_ADDR).
|
---|
268 | * @sa BS3_SEL_TEXT16 */
|
---|
269 | #define BS3_ADDR_BS3TEXT16 0x10000
|
---|
270 | /** The base address of the BS3SYSTEM16 segment.
|
---|
271 | * @sa BS3_SEL_SYSTEM16 */
|
---|
272 | #define BS3_ADDR_BS3SYSTEM16 0x20000
|
---|
273 | /** The base address of the BS3DATA16/BS3KIT_GRPNM_DATA16 segment.
|
---|
274 | * @sa BS3_SEL_DATA16 */
|
---|
275 | #define BS3_ADDR_BS3DATA16 0x29000
|
---|
276 | /** @} */
|
---|
277 |
|
---|
278 | /** @name BS3_SEL_XXX - GDT selector assignments.
|
---|
279 | *
|
---|
280 | * The real mode segment numbers for BS16TEXT, BS16DATA and BS16SYSTEM are
|
---|
281 | * present in the GDT, this allows the 16-bit C/C++ and assembly code to
|
---|
282 | * continue using the real mode segment values in ring-0 protected mode.
|
---|
283 | *
|
---|
284 | * The three segments have fixed locations:
|
---|
285 | * | segment | flat address | real mode segment |
|
---|
286 | * | ----------- | ------------ | ----------------- |
|
---|
287 | * | BS3TEXT16 | 0x00010000 | 1000h |
|
---|
288 | * | BS3SYSTEM16 | 0x00020000 | 2000h |
|
---|
289 | * | BS3DATA16 | 0x00029000 | 2900h |
|
---|
290 | *
|
---|
291 | * This means that we've got a lot of GDT space to play around with.
|
---|
292 | *
|
---|
293 | * @{ */
|
---|
294 | #define BS3_SEL_LDT 0x0010 /**< The LDT selector for Bs3Ldt. */
|
---|
295 | #define BS3_SEL_TSS16 0x0020 /**< The 16-bit TSS selector. */
|
---|
296 | #define BS3_SEL_TSS16_DF 0x0028 /**< The 16-bit TSS selector for double faults. */
|
---|
297 | #define BS3_SEL_TSS16_SPARE0 0x0030 /**< The 16-bit TSS selector for testing. */
|
---|
298 | #define BS3_SEL_TSS16_SPARE1 0x0038 /**< The 16-bit TSS selector for testing. */
|
---|
299 | #define BS3_SEL_TSS32 0x0040 /**< The 32-bit TSS selector. */
|
---|
300 | #define BS3_SEL_TSS32_DF 0x0048 /**< The 32-bit TSS selector for double faults. */
|
---|
301 | #define BS3_SEL_TSS32_SPARE0 0x0050 /**< The 32-bit TSS selector for testing. */
|
---|
302 | #define BS3_SEL_TSS32_SPARE1 0x0058 /**< The 32-bit TSS selector for testing. */
|
---|
303 | #define BS3_SEL_TSS32_IOBP_IRB 0x0060 /**< The 32-bit TSS selector with I/O permission and interrupt redirection bitmaps. */
|
---|
304 | #define BS3_SEL_TSS32_IRB 0x0068 /**< The 32-bit TSS selector with only interrupt redirection bitmap (IOPB stripped by limit). */
|
---|
305 | #define BS3_SEL_TSS64 0x0070 /**< The 64-bit TSS selector. */
|
---|
306 | #define BS3_SEL_TSS64_SPARE0 0x0080 /**< The 64-bit TSS selector. */
|
---|
307 | #define BS3_SEL_TSS64_SPARE1 0x0090 /**< The 64-bit TSS selector. */
|
---|
308 | #define BS3_SEL_TSS64_IOBP 0x00a0 /**< The 64-bit TSS selector. */
|
---|
309 |
|
---|
310 | #define BS3_SEL_RMTEXT16_CS 0x00e0 /**< Conforming code selector for accessing the BS3RMTEXT16 segment. Runtime config. */
|
---|
311 | #define BS3_SEL_X0TEXT16_CS 0x00e8 /**< Conforming code selector for accessing the BS3X0TEXT16 segment. Runtime config. */
|
---|
312 | #define BS3_SEL_X1TEXT16_CS 0x00f0 /**< Conforming code selector for accessing the BS3X1TEXT16 segment. Runtime config. */
|
---|
313 | #define BS3_SEL_VMMDEV_MMIO16 0x00f8 /**< Selector for accessing the VMMDev MMIO segment at 0100000h from 16-bit code. */
|
---|
314 |
|
---|
315 | /** Checks if @a uSel is in the BS3_SEL_RX_XXX range. */
|
---|
316 | #define BS3_SEL_IS_IN_RING_RANGE(uSel) ( (unsigned)(uSel - BS3_SEL_R0_FIRST) < (unsigned)(4 << BS3_SEL_RING_SHIFT) )
|
---|
317 | #define BS3_SEL_RING_SHIFT 8 /**< For the formula: BS3_SEL_R0_XXX + ((cs & 3) << BS3_SEL_RING_SHIFT) */
|
---|
318 | #define BS3_SEL_RING_SUB_MASK 0x00f8 /**< Mask for getting the sub-selector. For use with BS3_SEL_R*_FIRST. */
|
---|
319 |
|
---|
320 | /** Checks if @a uSel is in the BS3_SEL_R0_XXX range. */
|
---|
321 | #define BS3_SEL_IS_IN_R0_RANGE(uSel) ( (unsigned)(uSel - BS3_SEL_R0_FIRST) < (unsigned)(1 << BS3_SEL_RING_SHIFT) )
|
---|
322 | #define BS3_SEL_R0_FIRST 0x0100 /**< The first selector in the ring-0 block. */
|
---|
323 | #define BS3_SEL_R0_CS16 0x0100 /**< ring-0: 16-bit code selector, base 0x10000. */
|
---|
324 | #define BS3_SEL_R0_DS16 0x0108 /**< ring-0: 16-bit data selector, base 0x23000. */
|
---|
325 | #define BS3_SEL_R0_SS16 0x0110 /**< ring-0: 16-bit stack selector, base 0x00000. */
|
---|
326 | #define BS3_SEL_R0_CS32 0x0118 /**< ring-0: 32-bit flat code selector. */
|
---|
327 | #define BS3_SEL_R0_DS32 0x0120 /**< ring-0: 32-bit flat data selector. */
|
---|
328 | #define BS3_SEL_R0_SS32 0x0128 /**< ring-0: 32-bit flat stack selector. */
|
---|
329 | #define BS3_SEL_R0_CS64 0x0130 /**< ring-0: 64-bit flat code selector. */
|
---|
330 | #define BS3_SEL_R0_DS64 0x0138 /**< ring-0: 64-bit flat data & stack selector. */
|
---|
331 | #define BS3_SEL_R0_CS16_EO 0x0140 /**< ring-0: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base. */
|
---|
332 | #define BS3_SEL_R0_CS16_CNF 0x0148 /**< ring-0: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base. */
|
---|
333 | #define BS3_SEL_R0_CS16_CNF_EO 0x0150 /**< ring-0: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base. */
|
---|
334 | #define BS3_SEL_R0_CS32_EO 0x0158 /**< ring-0: 32-bit execute-only code selector, not accessed, flat. */
|
---|
335 | #define BS3_SEL_R0_CS32_CNF 0x0160 /**< ring-0: 32-bit conforming code selector, not accessed, flat. */
|
---|
336 | #define BS3_SEL_R0_CS32_CNF_EO 0x0168 /**< ring-0: 32-bit execute-only conforming code selector, not accessed, flat. */
|
---|
337 | #define BS3_SEL_R0_CS64_EO 0x0170 /**< ring-0: 64-bit execute-only code selector, not accessed, flat. */
|
---|
338 | #define BS3_SEL_R0_CS64_CNF 0x0178 /**< ring-0: 64-bit conforming code selector, not accessed, flat. */
|
---|
339 | #define BS3_SEL_R0_CS64_CNF_EO 0x0180 /**< ring-0: 64-bit execute-only conforming code selector, not accessed, flat. */
|
---|
340 |
|
---|
341 | #define BS3_SEL_R1_FIRST 0x0200 /**< The first selector in the ring-1 block. */
|
---|
342 | #define BS3_SEL_R1_CS16 0x0200 /**< ring-1: 16-bit code selector, base 0x10000. */
|
---|
343 | #define BS3_SEL_R1_DS16 0x0208 /**< ring-1: 16-bit data selector, base 0x23000. */
|
---|
344 | #define BS3_SEL_R1_SS16 0x0210 /**< ring-1: 16-bit stack selector, base 0x00000. */
|
---|
345 | #define BS3_SEL_R1_CS32 0x0218 /**< ring-1: 32-bit flat code selector. */
|
---|
346 | #define BS3_SEL_R1_DS32 0x0220 /**< ring-1: 32-bit flat data selector. */
|
---|
347 | #define BS3_SEL_R1_SS32 0x0228 /**< ring-1: 32-bit flat stack selector. */
|
---|
348 | #define BS3_SEL_R1_CS64 0x0230 /**< ring-1: 64-bit flat code selector. */
|
---|
349 | #define BS3_SEL_R1_DS64 0x0238 /**< ring-1: 64-bit flat data & stack selector. */
|
---|
350 | #define BS3_SEL_R1_CS16_EO 0x0240 /**< ring-1: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base. */
|
---|
351 | #define BS3_SEL_R1_CS16_CNF 0x0248 /**< ring-1: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base. */
|
---|
352 | #define BS3_SEL_R1_CS16_CNF_EO 0x0250 /**< ring-1: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base. */
|
---|
353 | #define BS3_SEL_R1_CS32_EO 0x0258 /**< ring-1: 32-bit execute-only code selector, not accessed, flat. */
|
---|
354 | #define BS3_SEL_R1_CS32_CNF 0x0260 /**< ring-1: 32-bit conforming code selector, not accessed, flat. */
|
---|
355 | #define BS3_SEL_R1_CS32_CNF_EO 0x0268 /**< ring-1: 32-bit execute-only conforming code selector, not accessed, flat. */
|
---|
356 | #define BS3_SEL_R1_CS64_EO 0x0270 /**< ring-1: 64-bit execute-only code selector, not accessed, flat. */
|
---|
357 | #define BS3_SEL_R1_CS64_CNF 0x0278 /**< ring-1: 64-bit conforming code selector, not accessed, flat. */
|
---|
358 | #define BS3_SEL_R1_CS64_CNF_EO 0x0280 /**< ring-1: 64-bit execute-only conforming code selector, not accessed, flat. */
|
---|
359 |
|
---|
360 | #define BS3_SEL_R2_FIRST 0x0300 /**< The first selector in the ring-2 block. */
|
---|
361 | #define BS3_SEL_R2_CS16 0x0300 /**< ring-2: 16-bit code selector, base 0x10000. */
|
---|
362 | #define BS3_SEL_R2_DS16 0x0308 /**< ring-2: 16-bit data selector, base 0x23000. */
|
---|
363 | #define BS3_SEL_R2_SS16 0x0310 /**< ring-2: 16-bit stack selector, base 0x00000. */
|
---|
364 | #define BS3_SEL_R2_CS32 0x0318 /**< ring-2: 32-bit flat code selector. */
|
---|
365 | #define BS3_SEL_R2_DS32 0x0320 /**< ring-2: 32-bit flat data selector. */
|
---|
366 | #define BS3_SEL_R2_SS32 0x0328 /**< ring-2: 32-bit flat stack selector. */
|
---|
367 | #define BS3_SEL_R2_CS64 0x0330 /**< ring-2: 64-bit flat code selector. */
|
---|
368 | #define BS3_SEL_R2_DS64 0x0338 /**< ring-2: 64-bit flat data & stack selector. */
|
---|
369 | #define BS3_SEL_R2_CS16_EO 0x0340 /**< ring-2: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base. */
|
---|
370 | #define BS3_SEL_R2_CS16_CNF 0x0348 /**< ring-2: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base. */
|
---|
371 | #define BS3_SEL_R2_CS16_CNF_EO 0x0350 /**< ring-2: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base. */
|
---|
372 | #define BS3_SEL_R2_CS32_EO 0x0358 /**< ring-2: 32-bit execute-only code selector, not accessed, flat. */
|
---|
373 | #define BS3_SEL_R2_CS32_CNF 0x0360 /**< ring-2: 32-bit conforming code selector, not accessed, flat. */
|
---|
374 | #define BS3_SEL_R2_CS32_CNF_EO 0x0368 /**< ring-2: 32-bit execute-only conforming code selector, not accessed, flat. */
|
---|
375 | #define BS3_SEL_R2_CS64_EO 0x0370 /**< ring-2: 64-bit execute-only code selector, not accessed, flat. */
|
---|
376 | #define BS3_SEL_R2_CS64_CNF 0x0378 /**< ring-2: 64-bit conforming code selector, not accessed, flat. */
|
---|
377 | #define BS3_SEL_R2_CS64_CNF_EO 0x0380 /**< ring-2: 64-bit execute-only conforming code selector, not accessed, flat. */
|
---|
378 |
|
---|
379 | #define BS3_SEL_R3_FIRST 0x0400 /**< The first selector in the ring-3 block. */
|
---|
380 | #define BS3_SEL_R3_CS16 0x0400 /**< ring-3: 16-bit code selector, base 0x10000. */
|
---|
381 | #define BS3_SEL_R3_DS16 0x0408 /**< ring-3: 16-bit data selector, base 0x23000. */
|
---|
382 | #define BS3_SEL_R3_SS16 0x0410 /**< ring-3: 16-bit stack selector, base 0x00000. */
|
---|
383 | #define BS3_SEL_R3_CS32 0x0418 /**< ring-3: 32-bit flat code selector. */
|
---|
384 | #define BS3_SEL_R3_DS32 0x0420 /**< ring-3: 32-bit flat data selector. */
|
---|
385 | #define BS3_SEL_R3_SS32 0x0428 /**< ring-3: 32-bit flat stack selector. */
|
---|
386 | #define BS3_SEL_R3_CS64 0x0430 /**< ring-3: 64-bit flat code selector. */
|
---|
387 | #define BS3_SEL_R3_DS64 0x0438 /**< ring-3: 64-bit flat data & stack selector. */
|
---|
388 | #define BS3_SEL_R3_CS16_EO 0x0440 /**< ring-3: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base. */
|
---|
389 | #define BS3_SEL_R3_CS16_CNF 0x0448 /**< ring-3: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base. */
|
---|
390 | #define BS3_SEL_R3_CS16_CNF_EO 0x0450 /**< ring-3: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base. */
|
---|
391 | #define BS3_SEL_R3_CS32_EO 0x0458 /**< ring-3: 32-bit execute-only code selector, not accessed, flat. */
|
---|
392 | #define BS3_SEL_R3_CS32_CNF 0x0460 /**< ring-3: 32-bit conforming code selector, not accessed, flat. */
|
---|
393 | #define BS3_SEL_R3_CS32_CNF_EO 0x0468 /**< ring-3: 32-bit execute-only conforming code selector, not accessed, flat. */
|
---|
394 | #define BS3_SEL_R3_CS64_EO 0x0470 /**< ring-3: 64-bit execute-only code selector, not accessed, flat. */
|
---|
395 | #define BS3_SEL_R3_CS64_CNF 0x0478 /**< ring-3: 64-bit conforming code selector, not accessed, flat. */
|
---|
396 | #define BS3_SEL_R3_CS64_CNF_EO 0x0480 /**< ring-3: 64-bit execute-only conforming code selector, not accessed, flat. */
|
---|
397 |
|
---|
398 | #define BS3_SEL_R3_LAST 0x04f8 /**< ring-3: Last of the BS3_SEL_RX_XXX range. */
|
---|
399 |
|
---|
400 | #define BS3_SEL_SPARE_FIRST 0x0500 /**< The first selector in the spare block */
|
---|
401 | #define BS3_SEL_SPARE_00 0x0500 /**< Spare selector number 00h. */
|
---|
402 | #define BS3_SEL_SPARE_01 0x0508 /**< Spare selector number 01h. */
|
---|
403 | #define BS3_SEL_SPARE_02 0x0510 /**< Spare selector number 02h. */
|
---|
404 | #define BS3_SEL_SPARE_03 0x0518 /**< Spare selector number 03h. */
|
---|
405 | #define BS3_SEL_SPARE_04 0x0520 /**< Spare selector number 04h. */
|
---|
406 | #define BS3_SEL_SPARE_05 0x0528 /**< Spare selector number 05h. */
|
---|
407 | #define BS3_SEL_SPARE_06 0x0530 /**< Spare selector number 06h. */
|
---|
408 | #define BS3_SEL_SPARE_07 0x0538 /**< Spare selector number 07h. */
|
---|
409 | #define BS3_SEL_SPARE_08 0x0540 /**< Spare selector number 08h. */
|
---|
410 | #define BS3_SEL_SPARE_09 0x0548 /**< Spare selector number 09h. */
|
---|
411 | #define BS3_SEL_SPARE_0a 0x0550 /**< Spare selector number 0ah. */
|
---|
412 | #define BS3_SEL_SPARE_0b 0x0558 /**< Spare selector number 0bh. */
|
---|
413 | #define BS3_SEL_SPARE_0c 0x0560 /**< Spare selector number 0ch. */
|
---|
414 | #define BS3_SEL_SPARE_0d 0x0568 /**< Spare selector number 0dh. */
|
---|
415 | #define BS3_SEL_SPARE_0e 0x0570 /**< Spare selector number 0eh. */
|
---|
416 | #define BS3_SEL_SPARE_0f 0x0578 /**< Spare selector number 0fh. */
|
---|
417 | #define BS3_SEL_SPARE_10 0x0580 /**< Spare selector number 10h. */
|
---|
418 | #define BS3_SEL_SPARE_11 0x0588 /**< Spare selector number 11h. */
|
---|
419 | #define BS3_SEL_SPARE_12 0x0590 /**< Spare selector number 12h. */
|
---|
420 | #define BS3_SEL_SPARE_13 0x0598 /**< Spare selector number 13h. */
|
---|
421 | #define BS3_SEL_SPARE_14 0x05a0 /**< Spare selector number 14h. */
|
---|
422 | #define BS3_SEL_SPARE_15 0x05a8 /**< Spare selector number 15h. */
|
---|
423 | #define BS3_SEL_SPARE_16 0x05b0 /**< Spare selector number 16h. */
|
---|
424 | #define BS3_SEL_SPARE_17 0x05b8 /**< Spare selector number 17h. */
|
---|
425 | #define BS3_SEL_SPARE_18 0x05c0 /**< Spare selector number 18h. */
|
---|
426 | #define BS3_SEL_SPARE_19 0x05c8 /**< Spare selector number 19h. */
|
---|
427 | #define BS3_SEL_SPARE_1a 0x05d0 /**< Spare selector number 1ah. */
|
---|
428 | #define BS3_SEL_SPARE_1b 0x05d8 /**< Spare selector number 1bh. */
|
---|
429 | #define BS3_SEL_SPARE_1c 0x05e0 /**< Spare selector number 1ch. */
|
---|
430 | #define BS3_SEL_SPARE_1d 0x05e8 /**< Spare selector number 1dh. */
|
---|
431 | #define BS3_SEL_SPARE_1e 0x05f0 /**< Spare selector number 1eh. */
|
---|
432 | #define BS3_SEL_SPARE_1f 0x05f8 /**< Spare selector number 1fh. */
|
---|
433 |
|
---|
434 | #define BS3_SEL_TILED 0x0600 /**< 16-bit data tiling: First - base=0x00000000, limit=64KB, DPL=3. */
|
---|
435 | #define BS3_SEL_TILED_LAST 0x0df8 /**< 16-bit data tiling: Last - base=0x00ff0000, limit=64KB, DPL=3. */
|
---|
436 | #define BS3_SEL_TILED_AREA_SIZE 0x001000000 /**< 16-bit data tiling: Size of addressable area, in bytes. (16 MB) */
|
---|
437 |
|
---|
438 | #define BS3_SEL_FREE_PART1 0x0e00 /**< Free selector space - part \#1. */
|
---|
439 | #define BS3_SEL_FREE_PART1_LAST 0x0ff8 /**< Free selector space - part \#1, last entry. */
|
---|
440 |
|
---|
441 | #define BS3_SEL_TEXT16 0x1000 /**< The BS3TEXT16 selector. */
|
---|
442 |
|
---|
443 | #define BS3_SEL_FREE_PART2 0x1008 /**< Free selector space - part \#2. */
|
---|
444 | #define BS3_SEL_FREE_PART2_LAST 0x17f8 /**< Free selector space - part \#2, last entry. */
|
---|
445 |
|
---|
446 | #define BS3_SEL_TILED_R0 0x1800 /**< 16-bit data/stack tiling: First - base=0x00000000, limit=64KB, DPL=0. */
|
---|
447 | #define BS3_SEL_TILED_R0_LAST 0x1ff8 /**< 16-bit data/stack tiling: Last - base=0x00ff0000, limit=64KB, DPL=0. */
|
---|
448 |
|
---|
449 | #define BS3_SEL_SYSTEM16 0x2000 /**< The BS3SYSTEM16 selector. */
|
---|
450 |
|
---|
451 | #define BS3_SEL_FREE_PART3 0x2008 /**< Free selector space - part \#3. */
|
---|
452 | #define BS3_SEL_FREE_PART3_LAST 0x28f8 /**< Free selector space - part \#3, last entry. */
|
---|
453 |
|
---|
454 | #define BS3_SEL_DATA16 0x2900 /**< The BS3DATA16/BS3KIT_GRPNM_DATA16 selector. */
|
---|
455 |
|
---|
456 | #define BS3_SEL_FREE_PART4 0x2908 /**< Free selector space - part \#4. */
|
---|
457 | #define BS3_SEL_FREE_PART4_LAST 0x2f98 /**< Free selector space - part \#4, last entry. */
|
---|
458 |
|
---|
459 | #define BS3_SEL_PRE_TEST_PAGE_08 0x2fa0 /**< Selector located 8 selectors before the test page. */
|
---|
460 | #define BS3_SEL_PRE_TEST_PAGE_07 0x2fa8 /**< Selector located 7 selectors before the test page. */
|
---|
461 | #define BS3_SEL_PRE_TEST_PAGE_06 0x2fb0 /**< Selector located 6 selectors before the test page. */
|
---|
462 | #define BS3_SEL_PRE_TEST_PAGE_05 0x2fb8 /**< Selector located 5 selectors before the test page. */
|
---|
463 | #define BS3_SEL_PRE_TEST_PAGE_04 0x2fc0 /**< Selector located 4 selectors before the test page. */
|
---|
464 | #define BS3_SEL_PRE_TEST_PAGE_03 0x2fc8 /**< Selector located 3 selectors before the test page. */
|
---|
465 | #define BS3_SEL_PRE_TEST_PAGE_02 0x2fd0 /**< Selector located 2 selectors before the test page. */
|
---|
466 | #define BS3_SEL_PRE_TEST_PAGE_01 0x2fd8 /**< Selector located 1 selector before the test page. */
|
---|
467 | #define BS3_SEL_TEST_PAGE 0x2fe0 /**< Start of the test page intended for playing around with paging and GDT. */
|
---|
468 | #define BS3_SEL_TEST_PAGE_00 0x2fe0 /**< Test page selector number 00h (convenience). */
|
---|
469 | #define BS3_SEL_TEST_PAGE_01 0x2fe8 /**< Test page selector number 01h (convenience). */
|
---|
470 | #define BS3_SEL_TEST_PAGE_02 0x2ff0 /**< Test page selector number 02h (convenience). */
|
---|
471 | #define BS3_SEL_TEST_PAGE_03 0x2ff8 /**< Test page selector number 03h (convenience). */
|
---|
472 | #define BS3_SEL_TEST_PAGE_04 0x3000 /**< Test page selector number 04h (convenience). */
|
---|
473 | #define BS3_SEL_TEST_PAGE_05 0x3008 /**< Test page selector number 05h (convenience). */
|
---|
474 | #define BS3_SEL_TEST_PAGE_06 0x3010 /**< Test page selector number 06h (convenience). */
|
---|
475 | #define BS3_SEL_TEST_PAGE_07 0x3018 /**< Test page selector number 07h (convenience). */
|
---|
476 | #define BS3_SEL_TEST_PAGE_LAST 0x3fd0 /**< The last selector in the spare page. */
|
---|
477 |
|
---|
478 | #define BS3_SEL_GDT_LIMIT 0x3fd8 /**< The GDT limit. */
|
---|
479 | /** @} */
|
---|
480 |
|
---|
481 |
|
---|
482 | /** @def BS3_FAR
|
---|
483 | * For indicating far pointers in 16-bit code.
|
---|
484 | * Does nothing in 32-bit and 64-bit code. */
|
---|
485 | /** @def BS3_NEAR
|
---|
486 | * For indicating near pointers in 16-bit code.
|
---|
487 | * Does nothing in 32-bit and 64-bit code. */
|
---|
488 | /** @def BS3_FAR_CODE
|
---|
489 | * For indicating far 16-bit functions.
|
---|
490 | * Does nothing in 32-bit and 64-bit code. */
|
---|
491 | /** @def BS3_NEAR_CODE
|
---|
492 | * For indicating near 16-bit functions.
|
---|
493 | * Does nothing in 32-bit and 64-bit code. */
|
---|
494 | /** @def BS3_FAR_DATA
|
---|
495 | * For indicating far 16-bit external data, i.e. in a segment other than DATA16.
|
---|
496 | * Does nothing in 32-bit and 64-bit code. */
|
---|
497 | #ifdef M_I86
|
---|
498 | # define BS3_FAR __far
|
---|
499 | # define BS3_NEAR __near
|
---|
500 | # define BS3_FAR_CODE __far
|
---|
501 | # define BS3_NEAR_CODE __near
|
---|
502 | # define BS3_FAR_DATA __far
|
---|
503 | #else
|
---|
504 | # define BS3_FAR
|
---|
505 | # define BS3_NEAR
|
---|
506 | # define BS3_FAR_CODE
|
---|
507 | # define BS3_NEAR_CODE
|
---|
508 | # define BS3_FAR_DATA
|
---|
509 | #endif
|
---|
510 |
|
---|
511 | #if ARCH_BITS == 16 || defined(DOXYGEN_RUNNING)
|
---|
512 | /** @def BS3_FP_SEG
|
---|
513 | * Get the selector (segment) part of a far pointer.
|
---|
514 | *
|
---|
515 | * @returns selector.
|
---|
516 | * @param a_pv Far pointer.
|
---|
517 | */
|
---|
518 | # define BS3_FP_SEG(a_pv) ((uint16_t)(__segment)(void BS3_FAR *)(a_pv))
|
---|
519 | /** @def BS3_FP_OFF
|
---|
520 | * Get the segment offset part of a far pointer.
|
---|
521 | *
|
---|
522 | * For sake of convenience, this works like a uintptr_t cast in 32-bit and
|
---|
523 | * 64-bit code.
|
---|
524 | *
|
---|
525 | * @returns offset.
|
---|
526 | * @param a_pv Far pointer.
|
---|
527 | */
|
---|
528 | # define BS3_FP_OFF(a_pv) ((uint16_t)(void __near *)(a_pv))
|
---|
529 | /** @def BS3_FP_MAKE
|
---|
530 | * Create a far pointer.
|
---|
531 | *
|
---|
532 | * @returns Far pointer.
|
---|
533 | * @param a_uSeg The selector/segment.
|
---|
534 | * @param a_off The offset into the segment.
|
---|
535 | */
|
---|
536 | # define BS3_FP_MAKE(a_uSeg, a_off) (((__segment)(a_uSeg)) :> ((void __near *)(a_off)))
|
---|
537 | #else
|
---|
538 | # define BS3_FP_OFF(a_pv) ((uintptr_t)(a_pv))
|
---|
539 | #endif
|
---|
540 |
|
---|
541 | /** @def BS3_MAKE_PROT_PTR_FROM_FLAT
|
---|
542 | * Creates a protected mode pointer from a flat address.
|
---|
543 | *
|
---|
544 | * For sake of convenience, this macro also works in 32-bit and 64-bit mode,
|
---|
545 | * only there it doesn't return a far pointer but a flat point.
|
---|
546 | *
|
---|
547 | * @returns far void pointer if 16-bit code, near/flat void pointer in 32-bit
|
---|
548 | * and 64-bit.
|
---|
549 | * @param a_uFlat Flat address in the first 16MB. */
|
---|
550 | #if ARCH_BITS == 16
|
---|
551 | # define BS3_MAKE_PROT_R0PTR_FROM_FLAT(a_uFlat) \
|
---|
552 | BS3_FP_MAKE(((uint16_t)(a_uFlat >> 16) << 3) + BS3_SEL_TILED, (uint16_t)(a_uFlat))
|
---|
553 | #else
|
---|
554 | # define BS3_MAKE_PROT_R0PTR_FROM_FLAT(a_uFlat) ((void *)(uintptr_t)(a_uFlat))
|
---|
555 | #endif
|
---|
556 |
|
---|
557 | /** @def BS3_MAKE_PROT_R0PTR_FROM_REAL
|
---|
558 | * Creates a protected mode pointer from a far real mode address.
|
---|
559 | *
|
---|
560 | * For sake of convenience, this macro also works in 32-bit and 64-bit mode,
|
---|
561 | * only there it doesn't return a far pointer but a flat point.
|
---|
562 | *
|
---|
563 | * @returns far void pointer if 16-bit code, near/flat void pointer in 32-bit
|
---|
564 | * and 64-bit.
|
---|
565 | * @param a_uSeg The selector/segment.
|
---|
566 | * @param a_off The offset into the segment.
|
---|
567 | */
|
---|
568 | #if ARCH_BITS == 16
|
---|
569 | # define BS3_MAKE_PROT_R0PTR_FROM_REAL(a_uSeg, a_off) BS3_MAKE_PROT_R0PTR_FROM_FLAT(((uint32_t)(a_uSeg) << 4) + (uint16_t)(a_off))
|
---|
570 | #else
|
---|
571 | # define BS3_MAKE_PROT_R0PTR_FROM_REAL(a_uSeg, a_off) ( (void *)(uintptr_t)(((uint32_t)(a_uSeg) << 4) + (uint16_t)(a_off)) )
|
---|
572 | #endif
|
---|
573 |
|
---|
574 |
|
---|
575 | /** @def BS3_CALL
|
---|
576 | * The calling convension used by BS3 functions. */
|
---|
577 | #if ARCH_BITS != 64
|
---|
578 | # define BS3_CALL __cdecl
|
---|
579 | #elif !defined(_MSC_VER)
|
---|
580 | # define BS3_CALL __attribute__((__ms_abi__))
|
---|
581 | #else
|
---|
582 | # define BS3_CALL
|
---|
583 | #endif
|
---|
584 |
|
---|
585 | /** @def IN_BS3KIT
|
---|
586 | * Indicates that we're in the same link job as the BS3Kit code. */
|
---|
587 | #ifdef DOXYGEN_RUNNING
|
---|
588 | # define IN_BS3KIT
|
---|
589 | #endif
|
---|
590 |
|
---|
591 | /** @def BS3_DECL
|
---|
592 | * Declares a BS3Kit function with default far/near.
|
---|
593 | *
|
---|
594 | * Until we outgrow BS3TEXT16, we use all near functions in 16-bit.
|
---|
595 | *
|
---|
596 | * @param a_Type The return type. */
|
---|
597 | #if ARCH_BITS != 16 || !defined(BS3_USE_ALT_16BIT_TEXT_SEG)
|
---|
598 | # define BS3_DECL(a_Type) BS3_DECL_NEAR(a_Type)
|
---|
599 | #else
|
---|
600 | # define BS3_DECL(a_Type) BS3_DECL_FAR(a_Type)
|
---|
601 | #endif
|
---|
602 |
|
---|
603 | /** @def BS3_DECL_NEAR
|
---|
604 | * Declares a BS3Kit function, always near everywhere.
|
---|
605 | *
|
---|
606 | * Until we outgrow BS3TEXT16, we use all near functions in 16-bit.
|
---|
607 | *
|
---|
608 | * @param a_Type The return type. */
|
---|
609 | #ifdef IN_BS3KIT
|
---|
610 | # define BS3_DECL_NEAR(a_Type) DECLEXPORT(a_Type) BS3_NEAR_CODE BS3_CALL
|
---|
611 | #else
|
---|
612 | # define BS3_DECL_NEAR(a_Type) DECLIMPORT(a_Type) BS3_NEAR_CODE BS3_CALL
|
---|
613 | #endif
|
---|
614 |
|
---|
615 | /** @def BS3_DECL_FAR
|
---|
616 | * Declares a BS3Kit function, far 16-bit, otherwise near.
|
---|
617 | *
|
---|
618 | * Until we outgrow BS3TEXT16, we use all near functions in 16-bit.
|
---|
619 | *
|
---|
620 | * @param a_Type The return type. */
|
---|
621 | #ifdef IN_BS3KIT
|
---|
622 | # define BS3_DECL_FAR(a_Type) DECLEXPORT(a_Type) BS3_FAR_CODE BS3_CALL
|
---|
623 | #else
|
---|
624 | # define BS3_DECL_FAR(a_Type) DECLIMPORT(a_Type) BS3_FAR_CODE BS3_CALL
|
---|
625 | #endif
|
---|
626 |
|
---|
627 | /** @def BS3_DECL_CALLBACK
|
---|
628 | * Declares a BS3Kit callback function (typically static).
|
---|
629 | *
|
---|
630 | * Until we outgrow BS3TEXT16, we use all near functions in 16-bit.
|
---|
631 | *
|
---|
632 | * @param a_Type The return type. */
|
---|
633 | #ifdef IN_BS3KIT
|
---|
634 | # define BS3_DECL_CALLBACK(a_Type) a_Type BS3_FAR_CODE BS3_CALL
|
---|
635 | #else
|
---|
636 | # define BS3_DECL_CALLBACK(a_Type) a_Type BS3_FAR_CODE BS3_CALL
|
---|
637 | #endif
|
---|
638 |
|
---|
639 | /**
|
---|
640 | * Constructs a common name.
|
---|
641 | *
|
---|
642 | * Example: BS3_CMN_NM(Bs3Shutdown)
|
---|
643 | *
|
---|
644 | * @param a_Name The name of the function or global variable.
|
---|
645 | */
|
---|
646 | #define BS3_CMN_NM(a_Name) RT_CONCAT3(a_Name,_c,ARCH_BITS)
|
---|
647 |
|
---|
648 | /**
|
---|
649 | * Constructs a common function name, far in 16-bit code.
|
---|
650 | *
|
---|
651 | * Example: BS3_CMN_FAR_NM(Bs3Shutdown)
|
---|
652 | *
|
---|
653 | * @param a_Name The name of the function.
|
---|
654 | */
|
---|
655 | #if ARCH_BITS == 16
|
---|
656 | # define BS3_CMN_FAR_NM(a_Name) RT_CONCAT(a_Name,_f16)
|
---|
657 | #else
|
---|
658 | # define BS3_CMN_FAR_NM(a_Name) RT_CONCAT3(a_Name,_c,ARCH_BITS)
|
---|
659 | #endif
|
---|
660 |
|
---|
661 | /**
|
---|
662 | * Constructs a common function name, far or near as defined by the source.
|
---|
663 | *
|
---|
664 | * Which to use in 16-bit mode is defined by BS3_USE_ALT_16BIT_TEXT_SEG. In
|
---|
665 | * 32-bit and 64-bit mode there are no far symbols, only near ones.
|
---|
666 | *
|
---|
667 | * Example: BS3_CMN_FN_NM(Bs3Shutdown)
|
---|
668 | *
|
---|
669 | * @param a_Name The name of the function.
|
---|
670 | */
|
---|
671 | #if ARCH_BITS != 16 || !defined(BS3_USE_ALT_16BIT_TEXT_SEG)
|
---|
672 | # define BS3_CMN_FN_NM(a_Name) BS3_CMN_NM(a_Name)
|
---|
673 | #else
|
---|
674 | # define BS3_CMN_FN_NM(a_Name) BS3_CMN_FAR_NM(a_Name)
|
---|
675 | #endif
|
---|
676 |
|
---|
677 |
|
---|
678 | /**
|
---|
679 | * Constructs a data name.
|
---|
680 | *
|
---|
681 | * This glosses over the underscore prefix usage of our 16-bit, 32-bit and
|
---|
682 | * 64-bit compilers.
|
---|
683 | *
|
---|
684 | * Example: @code{.c}
|
---|
685 | * \#define Bs3Gdt BS3_DATA_NM(Bs3Gdt)
|
---|
686 | * extern X86DESC BS3_FAR_DATA Bs3Gdt
|
---|
687 | * @endcode
|
---|
688 | *
|
---|
689 | * @param a_Name The name of the global variable.
|
---|
690 | * @remarks Mainly used in bs3kit-mangling.h, internal headers and templates.
|
---|
691 | */
|
---|
692 | //converter does this now//#if ARCH_BITS == 64
|
---|
693 | //converter does this now//# define BS3_DATA_NM(a_Name) RT_CONCAT(_,a_Name)
|
---|
694 | //converter does this now//#else
|
---|
695 | # define BS3_DATA_NM(a_Name) a_Name
|
---|
696 | //converter does this now//#endif
|
---|
697 |
|
---|
698 | /**
|
---|
699 | * Template for createing a pointer union type.
|
---|
700 | * @param a_BaseName The base type name.
|
---|
701 | * @param a_Modifier The type modifier.
|
---|
702 | */
|
---|
703 | #define BS3_PTR_UNION_TEMPLATE(a_BaseName, a_Modifiers) \
|
---|
704 | typedef union a_BaseName \
|
---|
705 | { \
|
---|
706 | /** Pointer into the void. */ \
|
---|
707 | a_Modifiers void BS3_FAR *pv; \
|
---|
708 | /** As a signed integer. */ \
|
---|
709 | intptr_t i; \
|
---|
710 | /** As an unsigned integer. */ \
|
---|
711 | uintptr_t u; \
|
---|
712 | /** Pointer to char value. */ \
|
---|
713 | a_Modifiers char BS3_FAR *pch; \
|
---|
714 | /** Pointer to char value. */ \
|
---|
715 | a_Modifiers unsigned char BS3_FAR *puch; \
|
---|
716 | /** Pointer to a int value. */ \
|
---|
717 | a_Modifiers int BS3_FAR *pi; \
|
---|
718 | /** Pointer to a unsigned int value. */ \
|
---|
719 | a_Modifiers unsigned int BS3_FAR *pu; \
|
---|
720 | /** Pointer to a long value. */ \
|
---|
721 | a_Modifiers long BS3_FAR *pl; \
|
---|
722 | /** Pointer to a long value. */ \
|
---|
723 | a_Modifiers unsigned long BS3_FAR *pul; \
|
---|
724 | /** Pointer to a memory size value. */ \
|
---|
725 | a_Modifiers size_t BS3_FAR *pcb; \
|
---|
726 | /** Pointer to a byte value. */ \
|
---|
727 | a_Modifiers uint8_t BS3_FAR *pb; \
|
---|
728 | /** Pointer to a 8-bit unsigned value. */ \
|
---|
729 | a_Modifiers uint8_t BS3_FAR *pu8; \
|
---|
730 | /** Pointer to a 16-bit unsigned value. */ \
|
---|
731 | a_Modifiers uint16_t BS3_FAR *pu16; \
|
---|
732 | /** Pointer to a 32-bit unsigned value. */ \
|
---|
733 | a_Modifiers uint32_t BS3_FAR *pu32; \
|
---|
734 | /** Pointer to a 64-bit unsigned value. */ \
|
---|
735 | a_Modifiers uint64_t BS3_FAR *pu64; \
|
---|
736 | /** Pointer to a UTF-16 character. */ \
|
---|
737 | a_Modifiers RTUTF16 BS3_FAR *pwc; \
|
---|
738 | /** Pointer to a UUID character. */ \
|
---|
739 | a_Modifiers RTUUID BS3_FAR *pUuid; \
|
---|
740 | } a_BaseName; \
|
---|
741 | /** Pointer to a pointer union. */ \
|
---|
742 | typedef a_BaseName *RT_CONCAT(P,a_BaseName)
|
---|
743 | BS3_PTR_UNION_TEMPLATE(BS3PTRUNION, RT_NOTHING);
|
---|
744 | BS3_PTR_UNION_TEMPLATE(BS3CPTRUNION, const);
|
---|
745 | BS3_PTR_UNION_TEMPLATE(BS3VPTRUNION, volatile);
|
---|
746 | BS3_PTR_UNION_TEMPLATE(BS3CVPTRUNION, const volatile);
|
---|
747 |
|
---|
748 | /** Generic far function type. */
|
---|
749 | typedef BS3_DECL_FAR(void) FNBS3FAR(void);
|
---|
750 | /** Generic far function pointer type. */
|
---|
751 | typedef FNBS3FAR *FPFNBS3FAR;
|
---|
752 |
|
---|
753 | /** Generic near function type. */
|
---|
754 | typedef BS3_DECL_NEAR(void) FNBS3NEAR(void);
|
---|
755 | /** Generic near function pointer type. */
|
---|
756 | typedef FNBS3NEAR *PFNBS3NEAR;
|
---|
757 |
|
---|
758 | /** Generic far 16:16 function pointer type for address conversion functions. */
|
---|
759 | #if ARCH_BITS == 16
|
---|
760 | typedef FPFNBS3FAR PFNBS3FARADDRCONV;
|
---|
761 | #else
|
---|
762 | typedef uint32_t PFNBS3FARADDRCONV;
|
---|
763 | #endif
|
---|
764 |
|
---|
765 | /** The system call vector. */
|
---|
766 | #define BS3_TRAP_SYSCALL UINT8_C(0x20)
|
---|
767 |
|
---|
768 | /** @name System call numbers (ax).
|
---|
769 | * Paramenters are generally passed in registers specific to each system call,
|
---|
770 | * however cx:xSI is used for passing a pointer parameter.
|
---|
771 | * @{ */
|
---|
772 | /** Print char (cl). */
|
---|
773 | #define BS3_SYSCALL_PRINT_CHR UINT16_C(0x0001)
|
---|
774 | /** Print string (pointer in cx:xSI, length in dx). */
|
---|
775 | #define BS3_SYSCALL_PRINT_STR UINT16_C(0x0002)
|
---|
776 | /** Switch to ring-0. */
|
---|
777 | #define BS3_SYSCALL_TO_RING0 UINT16_C(0x0003)
|
---|
778 | /** Switch to ring-1. */
|
---|
779 | #define BS3_SYSCALL_TO_RING1 UINT16_C(0x0004)
|
---|
780 | /** Switch to ring-2. */
|
---|
781 | #define BS3_SYSCALL_TO_RING2 UINT16_C(0x0005)
|
---|
782 | /** Switch to ring-3. */
|
---|
783 | #define BS3_SYSCALL_TO_RING3 UINT16_C(0x0006)
|
---|
784 | /** Restore context (pointer in cx:xSI, flags in dx). */
|
---|
785 | #define BS3_SYSCALL_RESTORE_CTX UINT16_C(0x0007)
|
---|
786 | /** @} */
|
---|
787 |
|
---|
788 |
|
---|
789 |
|
---|
790 | /** @defgroup grp_bs3kit_system System Structures
|
---|
791 | * @{ */
|
---|
792 | /** The GDT, indexed by BS3_SEL_XXX shifted by 3. */
|
---|
793 | extern X86DESC BS3_FAR_DATA Bs3Gdt[(BS3_SEL_GDT_LIMIT + 1) / 8];
|
---|
794 |
|
---|
795 | extern X86DESC64 BS3_FAR_DATA Bs3Gdt_Ldt; /**< @see BS3_SEL_LDT */
|
---|
796 | extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss16; /**< @see BS3_SEL_TSS16 */
|
---|
797 | extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss16DoubleFault; /**< @see BS3_SEL_TSS16_DF */
|
---|
798 | extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss16Spare0; /**< @see BS3_SEL_TSS16_SPARE0 */
|
---|
799 | extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss16Spare1; /**< @see BS3_SEL_TSS16_SPARE1 */
|
---|
800 | extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss32; /**< @see BS3_SEL_TSS32 */
|
---|
801 | extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss32DoubleFault; /**< @see BS3_SEL_TSS32_DF */
|
---|
802 | extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss32Spare0; /**< @see BS3_SEL_TSS32_SPARE0 */
|
---|
803 | extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss32Spare1; /**< @see BS3_SEL_TSS32_SPARE1 */
|
---|
804 | extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss32IobpIntRedirBm; /**< @see BS3_SEL_TSS32_IOBP_IRB */
|
---|
805 | extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss32IntRedirBm; /**< @see BS3_SEL_TSS32_IRB */
|
---|
806 | extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss64; /**< @see BS3_SEL_TSS64 */
|
---|
807 | extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss64Spare0; /**< @see BS3_SEL_TSS64_SPARE0 */
|
---|
808 | extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss64Spare1; /**< @see BS3_SEL_TSS64_SPARE1 */
|
---|
809 | extern X86DESC BS3_FAR_DATA Bs3Gdte_Tss64Iobp; /**< @see BS3_SEL_TSS64_IOBP */
|
---|
810 | extern X86DESC BS3_FAR_DATA Bs3Gdte_RMTEXT16_CS; /**< @see BS3_SEL_RMTEXT16_CS */
|
---|
811 | extern X86DESC BS3_FAR_DATA Bs3Gdte_X0TEXT16_CS; /**< @see BS3_SEL_X0TEXT16_CS */
|
---|
812 | extern X86DESC BS3_FAR_DATA Bs3Gdte_X1TEXT16_CS; /**< @see BS3_SEL_X1TEXT16_CS */
|
---|
813 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_MMIO16; /**< @see BS3_SEL_VMMDEV_MMIO16 */
|
---|
814 |
|
---|
815 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_First; /**< @see BS3_SEL_R0_FIRST */
|
---|
816 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS16; /**< @see BS3_SEL_R0_CS16 */
|
---|
817 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_DS16; /**< @see BS3_SEL_R0_DS16 */
|
---|
818 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_SS16; /**< @see BS3_SEL_R0_SS16 */
|
---|
819 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS32; /**< @see BS3_SEL_R0_CS32 */
|
---|
820 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_DS32; /**< @see BS3_SEL_R0_DS32 */
|
---|
821 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_SS32; /**< @see BS3_SEL_R0_SS32 */
|
---|
822 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS64; /**< @see BS3_SEL_R0_CS64 */
|
---|
823 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_DS64; /**< @see BS3_SEL_R0_DS64 */
|
---|
824 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS16_EO; /**< @see BS3_SEL_R0_CS16_EO */
|
---|
825 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS16_CNF; /**< @see BS3_SEL_R0_CS16_CNF */
|
---|
826 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS16_CND_EO; /**< @see BS3_SEL_R0_CS16_CNF_EO */
|
---|
827 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS32_EO; /**< @see BS3_SEL_R0_CS32_EO */
|
---|
828 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS32_CNF; /**< @see BS3_SEL_R0_CS32_CNF */
|
---|
829 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS32_CNF_EO; /**< @see BS3_SEL_R0_CS32_CNF_EO */
|
---|
830 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS64_EO; /**< @see BS3_SEL_R0_CS64_EO */
|
---|
831 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS64_CNF; /**< @see BS3_SEL_R0_CS64_CNF */
|
---|
832 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R0_CS64_CNF_EO; /**< @see BS3_SEL_R0_CS64_CNF_EO */
|
---|
833 |
|
---|
834 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_First; /**< @see BS3_SEL_R1_FIRST */
|
---|
835 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS16; /**< @see BS3_SEL_R1_CS16 */
|
---|
836 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_DS16; /**< @see BS3_SEL_R1_DS16 */
|
---|
837 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_SS16; /**< @see BS3_SEL_R1_SS16 */
|
---|
838 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS32; /**< @see BS3_SEL_R1_CS32 */
|
---|
839 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_DS32; /**< @see BS3_SEL_R1_DS32 */
|
---|
840 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_SS32; /**< @see BS3_SEL_R1_SS32 */
|
---|
841 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS64; /**< @see BS3_SEL_R1_CS64 */
|
---|
842 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_DS64; /**< @see BS3_SEL_R1_DS64 */
|
---|
843 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS16_EO; /**< @see BS3_SEL_R1_CS16_EO */
|
---|
844 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS16_CNF; /**< @see BS3_SEL_R1_CS16_CNF */
|
---|
845 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS16_CND_EO; /**< @see BS3_SEL_R1_CS16_CNF_EO */
|
---|
846 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS32_EO; /**< @see BS3_SEL_R1_CS32_EO */
|
---|
847 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS32_CNF; /**< @see BS3_SEL_R1_CS32_CNF */
|
---|
848 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS32_CNF_EO; /**< @see BS3_SEL_R1_CS32_CNF_EO */
|
---|
849 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS64_EO; /**< @see BS3_SEL_R1_CS64_EO */
|
---|
850 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS64_CNF; /**< @see BS3_SEL_R1_CS64_CNF */
|
---|
851 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R1_CS64_CNF_EO; /**< @see BS3_SEL_R1_CS64_CNF_EO */
|
---|
852 |
|
---|
853 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_First; /**< @see BS3_SEL_R2_FIRST */
|
---|
854 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS16; /**< @see BS3_SEL_R2_CS16 */
|
---|
855 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_DS16; /**< @see BS3_SEL_R2_DS16 */
|
---|
856 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_SS16; /**< @see BS3_SEL_R2_SS16 */
|
---|
857 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS32; /**< @see BS3_SEL_R2_CS32 */
|
---|
858 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_DS32; /**< @see BS3_SEL_R2_DS32 */
|
---|
859 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_SS32; /**< @see BS3_SEL_R2_SS32 */
|
---|
860 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS64; /**< @see BS3_SEL_R2_CS64 */
|
---|
861 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_DS64; /**< @see BS3_SEL_R2_DS64 */
|
---|
862 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS16_EO; /**< @see BS3_SEL_R2_CS16_EO */
|
---|
863 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS16_CNF; /**< @see BS3_SEL_R2_CS16_CNF */
|
---|
864 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS16_CND_EO; /**< @see BS3_SEL_R2_CS16_CNF_EO */
|
---|
865 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS32_EO; /**< @see BS3_SEL_R2_CS32_EO */
|
---|
866 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS32_CNF; /**< @see BS3_SEL_R2_CS32_CNF */
|
---|
867 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS32_CNF_EO; /**< @see BS3_SEL_R2_CS32_CNF_EO */
|
---|
868 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS64_EO; /**< @see BS3_SEL_R2_CS64_EO */
|
---|
869 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS64_CNF; /**< @see BS3_SEL_R2_CS64_CNF */
|
---|
870 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R2_CS64_CNF_EO; /**< @see BS3_SEL_R2_CS64_CNF_EO */
|
---|
871 |
|
---|
872 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_First; /**< @see BS3_SEL_R3_FIRST */
|
---|
873 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS16; /**< @see BS3_SEL_R3_CS16 */
|
---|
874 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_DS16; /**< @see BS3_SEL_R3_DS16 */
|
---|
875 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_SS16; /**< @see BS3_SEL_R3_SS16 */
|
---|
876 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS32; /**< @see BS3_SEL_R3_CS32 */
|
---|
877 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_DS32; /**< @see BS3_SEL_R3_DS32 */
|
---|
878 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_SS32; /**< @see BS3_SEL_R3_SS32 */
|
---|
879 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS64; /**< @see BS3_SEL_R3_CS64 */
|
---|
880 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_DS64; /**< @see BS3_SEL_R3_DS64 */
|
---|
881 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS16_EO; /**< @see BS3_SEL_R3_CS16_EO */
|
---|
882 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS16_CNF; /**< @see BS3_SEL_R3_CS16_CNF */
|
---|
883 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS16_CND_EO; /**< @see BS3_SEL_R3_CS16_CNF_EO */
|
---|
884 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS32_EO; /**< @see BS3_SEL_R3_CS32_EO */
|
---|
885 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS32_CNF; /**< @see BS3_SEL_R3_CS32_CNF */
|
---|
886 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS32_CNF_EO; /**< @see BS3_SEL_R3_CS32_CNF_EO */
|
---|
887 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS64_EO; /**< @see BS3_SEL_R3_CS64_EO */
|
---|
888 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS64_CNF; /**< @see BS3_SEL_R3_CS64_CNF */
|
---|
889 | extern X86DESC BS3_FAR_DATA Bs3Gdte_R3_CS64_CNF_EO; /**< @see BS3_SEL_R3_CS64_CNF_EO */
|
---|
890 |
|
---|
891 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare00; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_00 */
|
---|
892 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare01; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_01 */
|
---|
893 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare02; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_02 */
|
---|
894 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare03; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_03 */
|
---|
895 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare04; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_04 */
|
---|
896 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare05; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_05 */
|
---|
897 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare06; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_06 */
|
---|
898 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare07; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_07 */
|
---|
899 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare08; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_08 */
|
---|
900 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare09; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_09 */
|
---|
901 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare0a; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0a */
|
---|
902 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare0b; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0b */
|
---|
903 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare0c; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0c */
|
---|
904 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare0d; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0d */
|
---|
905 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare0e; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0e */
|
---|
906 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare0f; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_0f */
|
---|
907 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare10; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_10 */
|
---|
908 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare11; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_11 */
|
---|
909 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare12; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_12 */
|
---|
910 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare13; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_13 */
|
---|
911 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare14; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_14 */
|
---|
912 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare15; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_15 */
|
---|
913 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare16; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_16 */
|
---|
914 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare17; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_17 */
|
---|
915 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare18; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_18 */
|
---|
916 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare19; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_19 */
|
---|
917 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare1a; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1a */
|
---|
918 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare1b; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1b */
|
---|
919 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare1c; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1c */
|
---|
920 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare1d; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1d */
|
---|
921 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare1e; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1e */
|
---|
922 | extern X86DESC BS3_FAR_DATA Bs3GdteSpare1f; /**< GDT entry for playing with in testcases. @see BS3_SEL_SPARE_1f */
|
---|
923 |
|
---|
924 | /** GDTs setting up the tiled 16-bit access to the first 16 MBs of memory.
|
---|
925 | * @see BS3_SEL_TILED, BS3_SEL_TILED_LAST, BS3_SEL_TILED_AREA_SIZE */
|
---|
926 | extern X86DESC BS3_FAR_DATA Bs3GdteTiled[256];
|
---|
927 | /** Free GDTes, part \#1. */
|
---|
928 | extern X86DESC BS3_FAR_DATA Bs3GdteFreePart1[64];
|
---|
929 | /** The BS3TEXT16/BS3CLASS16CODE GDT entry. @see BS3_SEL_TEXT16 */
|
---|
930 | extern X86DESC BS3_FAR_DATA Bs3Gdte_CODE16;
|
---|
931 | /** Free GDTes, part \#2. */
|
---|
932 | extern X86DESC BS3_FAR_DATA Bs3GdteFreePart2[511];
|
---|
933 | /** The BS3SYSTEM16 GDT entry. */
|
---|
934 | extern X86DESC BS3_FAR_DATA Bs3Gdte_SYSTEM16;
|
---|
935 | /** Free GDTes, part \#3. */
|
---|
936 | extern X86DESC BS3_FAR_DATA Bs3GdteFreePart3[223];
|
---|
937 | /** The BS3DATA16/BS3KIT_GRPNM_DATA16 GDT entry. */
|
---|
938 | extern X86DESC BS3_FAR_DATA Bs3Gdte_DATA16;
|
---|
939 |
|
---|
940 | /** Free GDTes, part \#4. */
|
---|
941 | extern X86DESC BS3_FAR_DATA Bs3GdteFreePart4[211];
|
---|
942 |
|
---|
943 | extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage08; /**< GDT entry 8 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_08 */
|
---|
944 | extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage07; /**< GDT entry 7 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_07 */
|
---|
945 | extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage06; /**< GDT entry 6 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_06 */
|
---|
946 | extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage05; /**< GDT entry 5 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_05 */
|
---|
947 | extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage04; /**< GDT entry 4 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_04 */
|
---|
948 | extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage03; /**< GDT entry 3 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_03 */
|
---|
949 | extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage02; /**< GDT entry 2 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_02 */
|
---|
950 | extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage01; /**< GDT entry 1 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_01 */
|
---|
951 | /** Array of GDT entries starting on a page boundrary and filling (almost) the
|
---|
952 | * whole page. This is for playing with paging and GDT usage.
|
---|
953 | * @see BS3_SEL_TEST_PAGE */
|
---|
954 | extern X86DESC BS3_FAR_DATA Bs3GdteTestPage[2043];
|
---|
955 | extern X86DESC BS3_FAR_DATA Bs3GdteTestPage00; /**< GDT entry 0 on the test page (convenience). @see BS3_SEL_TEST_PAGE_00 */
|
---|
956 | extern X86DESC BS3_FAR_DATA Bs3GdteTestPage01; /**< GDT entry 1 on the test page (convenience). @see BS3_SEL_TEST_PAGE_01 */
|
---|
957 | extern X86DESC BS3_FAR_DATA Bs3GdteTestPage02; /**< GDT entry 2 on the test page (convenience). @see BS3_SEL_TEST_PAGE_02 */
|
---|
958 | extern X86DESC BS3_FAR_DATA Bs3GdteTestPage03; /**< GDT entry 3 on the test page (convenience). @see BS3_SEL_TEST_PAGE_03 */
|
---|
959 | extern X86DESC BS3_FAR_DATA Bs3GdteTestPage04; /**< GDT entry 4 on the test page (convenience). @see BS3_SEL_TEST_PAGE_04 */
|
---|
960 | extern X86DESC BS3_FAR_DATA Bs3GdteTestPage05; /**< GDT entry 5 on the test page (convenience). @see BS3_SEL_TEST_PAGE_05 */
|
---|
961 | extern X86DESC BS3_FAR_DATA Bs3GdteTestPage06; /**< GDT entry 6 on the test page (convenience). @see BS3_SEL_TEST_PAGE_06 */
|
---|
962 | extern X86DESC BS3_FAR_DATA Bs3GdteTestPage07; /**< GDT entry 7 on the test page (convenience). @see BS3_SEL_TEST_PAGE_07 */
|
---|
963 |
|
---|
964 | /** The end of the GDT (exclusive - contains eye-catcher string). */
|
---|
965 | extern X86DESC BS3_FAR_DATA Bs3GdtEnd;
|
---|
966 |
|
---|
967 | /** The default 16-bit TSS. */
|
---|
968 | extern X86TSS16 BS3_FAR_DATA Bs3Tss16;
|
---|
969 | extern X86TSS16 BS3_FAR_DATA Bs3Tss16DoubleFault;
|
---|
970 | extern X86TSS16 BS3_FAR_DATA Bs3Tss16Spare0;
|
---|
971 | extern X86TSS16 BS3_FAR_DATA Bs3Tss16Spare1;
|
---|
972 | /** The default 32-bit TSS. */
|
---|
973 | extern X86TSS32 BS3_FAR_DATA Bs3Tss32;
|
---|
974 | extern X86TSS32 BS3_FAR_DATA Bs3Tss32DoubleFault;
|
---|
975 | extern X86TSS32 BS3_FAR_DATA Bs3Tss32Spare0;
|
---|
976 | extern X86TSS32 BS3_FAR_DATA Bs3Tss32Spare1;
|
---|
977 | /** The default 64-bit TSS. */
|
---|
978 | extern X86TSS64 BS3_FAR_DATA Bs3Tss64;
|
---|
979 | extern X86TSS64 BS3_FAR_DATA Bs3Tss64Spare0;
|
---|
980 | extern X86TSS64 BS3_FAR_DATA Bs3Tss64Spare1;
|
---|
981 | extern X86TSS64 BS3_FAR_DATA Bs3Tss64WithIopb;
|
---|
982 | extern X86TSS32 BS3_FAR_DATA Bs3Tss32WithIopb;
|
---|
983 | /** Interrupt redirection bitmap used by Bs3Tss32WithIopb. */
|
---|
984 | extern uint8_t BS3_FAR_DATA Bs3SharedIntRedirBm[32];
|
---|
985 | /** I/O permission bitmap used by Bs3Tss32WithIopb and Bs3Tss64WithIopb. */
|
---|
986 | extern uint8_t BS3_FAR_DATA Bs3SharedIobp[8192+2];
|
---|
987 | /** End of the I/O permission bitmap (exclusive). */
|
---|
988 | extern uint8_t BS3_FAR_DATA Bs3SharedIobpEnd;
|
---|
989 | /** 16-bit IDT. */
|
---|
990 | extern X86DESC BS3_FAR_DATA Bs3Idt16[256];
|
---|
991 | /** 32-bit IDT. */
|
---|
992 | extern X86DESC BS3_FAR_DATA Bs3Idt32[256];
|
---|
993 | /** 64-bit IDT. */
|
---|
994 | extern X86DESC64 BS3_FAR_DATA Bs3Idt64[256];
|
---|
995 | /** Structure for the LIDT instruction for loading the 16-bit IDT. */
|
---|
996 | extern X86XDTR64 BS3_FAR_DATA Bs3Lidt_Idt16;
|
---|
997 | /** Structure for the LIDT instruction for loading the 32-bit IDT. */
|
---|
998 | extern X86XDTR64 BS3_FAR_DATA Bs3Lidt_Idt32;
|
---|
999 | /** Structure for the LIDT instruction for loading the 64-bit IDT. */
|
---|
1000 | extern X86XDTR64 BS3_FAR_DATA Bs3Lidt_Idt64;
|
---|
1001 | /** Structure for the LIDT instruction for loading the real mode interrupt
|
---|
1002 | * vector table.. */
|
---|
1003 | extern X86XDTR64 BS3_FAR_DATA Bs3Lidt_Ivt;
|
---|
1004 | /** Structure for the LGDT instruction for loading the current GDT. */
|
---|
1005 | extern X86XDTR64 BS3_FAR_DATA Bs3Lgdt_Gdt;
|
---|
1006 | /** Structure for the LGDT instruction for loading the default GDT. */
|
---|
1007 | extern X86XDTR64 BS3_FAR_DATA Bs3LgdtDef_Gdt;
|
---|
1008 | /** The LDT (all entries are empty, fill in for testing). */
|
---|
1009 | extern X86DESC BS3_FAR_DATA Bs3Ldt[116];
|
---|
1010 | /** The end of the LDT (exclusive). */
|
---|
1011 | extern X86DESC BS3_FAR_DATA Bs3LdtEnd;
|
---|
1012 |
|
---|
1013 | /** @} */
|
---|
1014 |
|
---|
1015 |
|
---|
1016 | /** @name Segment start and end markers, sizes.
|
---|
1017 | * @{ */
|
---|
1018 | /** Start of the BS3TEXT16 segment. */
|
---|
1019 | extern uint8_t BS3_FAR_DATA Bs3Text16_StartOfSegment;
|
---|
1020 | /** End of the BS3TEXT16 segment. */
|
---|
1021 | extern uint8_t BS3_FAR_DATA Bs3Text16_EndOfSegment;
|
---|
1022 | /** The size of the BS3TEXT16 segment. */
|
---|
1023 | extern uint16_t BS3_FAR_DATA Bs3Text16_Size;
|
---|
1024 |
|
---|
1025 | /** Start of the BS3SYSTEM16 segment. */
|
---|
1026 | extern uint8_t BS3_FAR_DATA Bs3System16_StartOfSegment;
|
---|
1027 | /** End of the BS3SYSTEM16 segment. */
|
---|
1028 | extern uint8_t BS3_FAR_DATA Bs3System16_EndOfSegment;
|
---|
1029 |
|
---|
1030 | /** Start of the BS3DATA16/BS3KIT_GRPNM_DATA16 segment. */
|
---|
1031 | extern uint8_t BS3_FAR_DATA Bs3Data16_StartOfSegment;
|
---|
1032 | /** End of the BS3DATA16/BS3KIT_GRPNM_DATA16 segment. */
|
---|
1033 | extern uint8_t BS3_FAR_DATA Bs3Data16_EndOfSegment;
|
---|
1034 |
|
---|
1035 | /** Start of the BS3RMTEXT16 segment. */
|
---|
1036 | extern uint8_t BS3_FAR_DATA Bs3RmText16_StartOfSegment;
|
---|
1037 | /** End of the BS3RMTEXT16 segment. */
|
---|
1038 | extern uint8_t BS3_FAR_DATA Bs3RmText16_EndOfSegment;
|
---|
1039 | /** The size of the BS3RMTEXT16 segment. */
|
---|
1040 | extern uint16_t BS3_FAR_DATA Bs3RmText16_Size;
|
---|
1041 | /** The flat start address of the BS3X0TEXT16 segment. */
|
---|
1042 | extern uint32_t BS3_FAR_DATA Bs3RmText16_FlatAddr;
|
---|
1043 |
|
---|
1044 | /** Start of the BS3X0TEXT16 segment. */
|
---|
1045 | extern uint8_t BS3_FAR_DATA Bs3X0Text16_StartOfSegment;
|
---|
1046 | /** End of the BS3X0TEXT16 segment. */
|
---|
1047 | extern uint8_t BS3_FAR_DATA Bs3X0Text16_EndOfSegment;
|
---|
1048 | /** The size of the BS3X0TEXT16 segment. */
|
---|
1049 | extern uint16_t BS3_FAR_DATA Bs3X0Text16_Size;
|
---|
1050 | /** The flat start address of the BS3X0TEXT16 segment. */
|
---|
1051 | extern uint32_t BS3_FAR_DATA Bs3X0Text16_FlatAddr;
|
---|
1052 |
|
---|
1053 | /** Start of the BS3X1TEXT16 segment. */
|
---|
1054 | extern uint8_t BS3_FAR_DATA Bs3X1Text16_StartOfSegment;
|
---|
1055 | /** End of the BS3X1TEXT16 segment. */
|
---|
1056 | extern uint8_t BS3_FAR_DATA Bs3X1Text16_EndOfSegment;
|
---|
1057 | /** The size of the BS3X1TEXT16 segment. */
|
---|
1058 | extern uint16_t BS3_FAR_DATA Bs3X1Text16_Size;
|
---|
1059 | /** The flat start address of the BS3X1TEXT16 segment. */
|
---|
1060 | extern uint32_t BS3_FAR_DATA Bs3X1Text16_FlatAddr;
|
---|
1061 |
|
---|
1062 | /** Start of the BS3TEXT32 segment. */
|
---|
1063 | extern uint8_t BS3_FAR_DATA Bs3Text32_StartOfSegment;
|
---|
1064 | /** Start of the BS3TEXT32 segment. */
|
---|
1065 | extern uint8_t BS3_FAR_DATA Bs3Text32_EndOfSegment;
|
---|
1066 |
|
---|
1067 | /** Start of the BS3DATA32 segment. */
|
---|
1068 | extern uint8_t BS3_FAR_DATA Bs3Data32_StartOfSegment;
|
---|
1069 | /** Start of the BS3DATA32 segment. */
|
---|
1070 | extern uint8_t BS3_FAR_DATA Bs3Data32_EndOfSegment;
|
---|
1071 |
|
---|
1072 | /** Start of the BS3TEXT64 segment. */
|
---|
1073 | extern uint8_t BS3_FAR_DATA Bs3Text64_StartOfSegment;
|
---|
1074 | /** Start of the BS3TEXT64 segment. */
|
---|
1075 | extern uint8_t BS3_FAR_DATA Bs3Text64_EndOfSegment;
|
---|
1076 |
|
---|
1077 | /** Start of the BS3DATA64 segment. */
|
---|
1078 | extern uint8_t BS3_FAR_DATA Bs3Data64_StartOfSegment;
|
---|
1079 | /** Start of the BS3DATA64 segment. */
|
---|
1080 | extern uint8_t BS3_FAR_DATA Bs3Data64_EndOfSegment;
|
---|
1081 |
|
---|
1082 | /** The size of the Data16, Text32, Text64, Data32 and Data64 blob. */
|
---|
1083 | extern uint32_t BS3_FAR_DATA Bs3Data16Thru64Text32And64_TotalSize;
|
---|
1084 | /** The total image size (from Text16 thu Data64). */
|
---|
1085 | extern uint32_t BS3_FAR_DATA Bs3TotalImageSize;
|
---|
1086 | /** @} */
|
---|
1087 |
|
---|
1088 |
|
---|
1089 | /** Lower case hex digits. */
|
---|
1090 | extern char const g_achBs3HexDigits[16+1];
|
---|
1091 | /** Upper case hex digits. */
|
---|
1092 | extern char const g_achBs3HexDigitsUpper[16+1];
|
---|
1093 |
|
---|
1094 |
|
---|
1095 | /** The current mode (BS3_MODE_XXX) of CPU \#0. */
|
---|
1096 | extern uint8_t g_bBs3CurrentMode;
|
---|
1097 |
|
---|
1098 | /** Hint for 16-bit trap handlers regarding the high word of EIP. */
|
---|
1099 | extern uint32_t g_uBs3TrapEipHint;
|
---|
1100 |
|
---|
1101 | /** Copy of the original real-mode interrupt vector table. */
|
---|
1102 | extern RTFAR16 g_aBs3RmIvtOriginal[256];
|
---|
1103 |
|
---|
1104 |
|
---|
1105 | #ifdef __WATCOMC__
|
---|
1106 | /**
|
---|
1107 | * Executes the SMSW instruction and returns the value.
|
---|
1108 | *
|
---|
1109 | * @returns Machine status word.
|
---|
1110 | */
|
---|
1111 | uint16_t Bs3AsmSmsw(void);
|
---|
1112 | # pragma aux Bs3AsmSmsw = \
|
---|
1113 | ".286" \
|
---|
1114 | "smsw ax" \
|
---|
1115 | value [ax] modify exact [ax] nomemory;
|
---|
1116 | #endif
|
---|
1117 |
|
---|
1118 |
|
---|
1119 | /** @defgroup bs3kit_cross_ptr Cross Context Pointer Type
|
---|
1120 | *
|
---|
1121 | * The cross context pointer type is
|
---|
1122 | *
|
---|
1123 | * @{ */
|
---|
1124 |
|
---|
1125 | /**
|
---|
1126 | * Cross context pointer base type.
|
---|
1127 | */
|
---|
1128 | typedef union BS3XPTR
|
---|
1129 | {
|
---|
1130 | /** The flat pointer. */
|
---|
1131 | uint32_t uFlat;
|
---|
1132 | /** 16-bit view. */
|
---|
1133 | struct
|
---|
1134 | {
|
---|
1135 | uint16_t uLow;
|
---|
1136 | uint16_t uHigh;
|
---|
1137 | } u;
|
---|
1138 | #if ARCH_BITS == 16
|
---|
1139 | /** 16-bit near pointer. */
|
---|
1140 | void __near *pvNear;
|
---|
1141 | #elif ARCH_BITS == 32
|
---|
1142 | /** 32-bit pointer. */
|
---|
1143 | void *pvRaw;
|
---|
1144 | #endif
|
---|
1145 | } BS3XPTR;
|
---|
1146 | AssertCompileSize(BS3XPTR, 4);
|
---|
1147 |
|
---|
1148 |
|
---|
1149 | /** @def BS3_XPTR_DEF_INTERNAL
|
---|
1150 | * Internal worker.
|
---|
1151 | *
|
---|
1152 | * @param a_Scope RT_NOTHING if structure or global, static or extern
|
---|
1153 | * otherwise.
|
---|
1154 | * @param a_Type The type we're pointing to.
|
---|
1155 | * @param a_Name The member or variable name.
|
---|
1156 | * @internal
|
---|
1157 | */
|
---|
1158 | #if ARCH_BITS == 16
|
---|
1159 | # define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \
|
---|
1160 | a_Scope union \
|
---|
1161 | { \
|
---|
1162 | BS3XPTR XPtr; \
|
---|
1163 | a_Type __near *pNearTyped; \
|
---|
1164 | } a_Name
|
---|
1165 | #elif ARCH_BITS == 32
|
---|
1166 | # define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \
|
---|
1167 | a_Scope union \
|
---|
1168 | { \
|
---|
1169 | BS3XPTR XPtr; \
|
---|
1170 | a_Type *pTyped; \
|
---|
1171 | } a_Name
|
---|
1172 | #elif ARCH_BITS == 64
|
---|
1173 | # define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \
|
---|
1174 | a_Scope union \
|
---|
1175 | { \
|
---|
1176 | BS3XPTR XPtr; \
|
---|
1177 | } a_Name
|
---|
1178 | #else
|
---|
1179 | # error "ARCH_BITS"
|
---|
1180 | #endif
|
---|
1181 |
|
---|
1182 | /** @def BS3_XPTR_DEF_MEMBER
|
---|
1183 | * Defines a pointer member that can be shared by all CPU modes.
|
---|
1184 | *
|
---|
1185 | * @param a_Type The type we're pointing to.
|
---|
1186 | * @param a_Name The member or variable name.
|
---|
1187 | */
|
---|
1188 | #define BS3_XPTR_MEMBER(a_Type, a_Name) BS3_XPTR_DEF_INTERNAL(RT_NOTHING, a_Type, a_Name)
|
---|
1189 |
|
---|
1190 | /** @def BS3_XPTR_DEF_AUTO
|
---|
1191 | * Defines a pointer static variable for working with an XPTR.
|
---|
1192 | *
|
---|
1193 | * This is typically used to convert flat pointers into context specific
|
---|
1194 | * pointers.
|
---|
1195 | *
|
---|
1196 | * @param a_Type The type we're pointing to.
|
---|
1197 | * @param a_Name The member or variable name.
|
---|
1198 | */
|
---|
1199 | #define BS3_XPTR_AUTO(a_Type, a_Name) BS3_XPTR_DEF_INTERNAL(RT_NOTHING, a_Type, a_Name)
|
---|
1200 |
|
---|
1201 | /** @def BS3_XPTR_SET
|
---|
1202 | * Sets a cross context pointer.
|
---|
1203 | *
|
---|
1204 | * @param a_Type The type we're pointing to.
|
---|
1205 | * @param a_Name The member or variable name.
|
---|
1206 | * @param a_uFlatPtr The flat pointer value to assign. If the x-pointer is
|
---|
1207 | * used in real mode, this must be less than 1MB.
|
---|
1208 | * Otherwise the limit is 16MB (due to selector tiling).
|
---|
1209 | */
|
---|
1210 | #define BS3_XPTR_SET_FLAT(a_Type, a_Name, a_uFlatPtr) \
|
---|
1211 | do { a_Name.XPtr.uFlat = (a_uFlatPtr); } while (0)
|
---|
1212 |
|
---|
1213 | /** @def BS3_XPTR_GET_FLAT
|
---|
1214 | * Gets the flat address of a cross context pointer.
|
---|
1215 | *
|
---|
1216 | * @returns 32-bit flat pointer.
|
---|
1217 | * @param a_Type The type we're pointing to.
|
---|
1218 | * @param a_Name The member or variable name.
|
---|
1219 | */
|
---|
1220 | #define BS3_XPTR_GET_FLAT(a_Type, a_Name) (a_Name.XPtr.uFlat)
|
---|
1221 |
|
---|
1222 | /** @def BS3_XPTR_GET_FLAT_LOW
|
---|
1223 | * Gets the low 16 bits of the flat address.
|
---|
1224 | *
|
---|
1225 | * @returns Low 16 bits of the flat pointer.
|
---|
1226 | * @param a_Type The type we're pointing to.
|
---|
1227 | * @param a_Name The member or variable name.
|
---|
1228 | */
|
---|
1229 | #define BS3_XPTR_GET_FLAT_LOW(a_Type, a_Name) (a_Name.XPtr.u.uLow)
|
---|
1230 |
|
---|
1231 |
|
---|
1232 | #if ARCH_BITS == 16
|
---|
1233 |
|
---|
1234 | /**
|
---|
1235 | * Gets the current ring number.
|
---|
1236 | * @returns Ring number.
|
---|
1237 | */
|
---|
1238 | DECLINLINE(uint16_t) Bs3Sel16GetCurRing(void);
|
---|
1239 | # pragma aux Bs3Sel16GetCurRing = \
|
---|
1240 | "mov ax, ss" \
|
---|
1241 | "and ax, 3" \
|
---|
1242 | value [ax] modify exact [ax] nomemory;
|
---|
1243 |
|
---|
1244 | /**
|
---|
1245 | * Converts the high word of a flat pointer into a 16-bit selector.
|
---|
1246 | *
|
---|
1247 | * This makes use of the tiled area. It also handles real mode.
|
---|
1248 | *
|
---|
1249 | * @returns Segment selector value.
|
---|
1250 | * @param uHigh The high part of flat pointer.
|
---|
1251 | * @sa BS3_XPTR_GET, BS3_XPTR_SET
|
---|
1252 | */
|
---|
1253 | DECLINLINE(__segment) Bs3Sel16HighFlatPtrToSelector(uint16_t uHigh)
|
---|
1254 | {
|
---|
1255 | if (!BS3_MODE_IS_RM_OR_V86(g_bBs3CurrentMode))
|
---|
1256 | return (__segment)(((uHigh << 3) + BS3_SEL_TILED) | Bs3Sel16GetCurRing());
|
---|
1257 | return (__segment)(uHigh << 12);
|
---|
1258 | }
|
---|
1259 |
|
---|
1260 | #endif /* ARCH_BITS == 16 */
|
---|
1261 |
|
---|
1262 | /** @def BS3_XPTR_GET
|
---|
1263 | * Gets the current context pointer value.
|
---|
1264 | *
|
---|
1265 | * @returns Usable pointer.
|
---|
1266 | * @param a_Type The type we're pointing to.
|
---|
1267 | * @param a_Name The member or variable name.
|
---|
1268 | */
|
---|
1269 | #if ARCH_BITS == 16
|
---|
1270 | # define BS3_XPTR_GET(a_Type, a_Name) \
|
---|
1271 | ((a_Type BS3_FAR *)BS3_FP_MAKE(Bs3Sel16HighFlatPtrToSelector((a_Name).XPtr.u.uHigh), (a_Name).pNearTyped))
|
---|
1272 | #elif ARCH_BITS == 32
|
---|
1273 | # define BS3_XPTR_GET(a_Type, a_Name) ((a_Name).pTyped)
|
---|
1274 | #elif ARCH_BITS == 64
|
---|
1275 | # define BS3_XPTR_GET(a_Type, a_Name) ((a_Type *)(uintptr_t)(a_Name).XPtr.uFlat)
|
---|
1276 | #else
|
---|
1277 | # error "ARCH_BITS"
|
---|
1278 | #endif
|
---|
1279 |
|
---|
1280 | /** @def BS3_XPTR_SET
|
---|
1281 | * Gets the current context pointer value.
|
---|
1282 | *
|
---|
1283 | * @returns Usable pointer.
|
---|
1284 | * @param a_Type The type we're pointing to.
|
---|
1285 | * @param a_Name The member or variable name.
|
---|
1286 | * @param a_pValue The new pointer value, current context pointer.
|
---|
1287 | */
|
---|
1288 | #if ARCH_BITS == 16
|
---|
1289 | # define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \
|
---|
1290 | do { \
|
---|
1291 | a_Type BS3_FAR *pTypeCheck = (a_pValue); \
|
---|
1292 | if (BS3_MODE_IS_RM_OR_V86(g_bBs3CurrentMode)) \
|
---|
1293 | (a_Name).XPtr.uFlat = BS3_FP_OFF(pTypeCheck) + ((uint32_t)BS3_FP_SEG(pTypeCheck) << 4); \
|
---|
1294 | else \
|
---|
1295 | { \
|
---|
1296 | (a_Name).XPtr.u.uLow = BS3_FP_OFF(pTypeCheck); \
|
---|
1297 | (a_Name).XPtr.u.uHigh = ((BS3_FP_SEG(pTypeCheck) & UINT16_C(0xfff8)) - BS3_SEL_TILED) >> 3; \
|
---|
1298 | } \
|
---|
1299 | } while (0)
|
---|
1300 | #elif ARCH_BITS == 32
|
---|
1301 | # define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \
|
---|
1302 | do { (a_Name).pTyped = (a_pValue); } while (0)
|
---|
1303 | #elif ARCH_BITS == 64
|
---|
1304 | # define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \
|
---|
1305 | do { \
|
---|
1306 | a_Type *pTypeCheck = (a_pValue); \
|
---|
1307 | (a_Name).XPtr.uFlat = (uint32_t)(uintptr_t)pTypeCheck; \
|
---|
1308 | } while (0)
|
---|
1309 | #else
|
---|
1310 | # error "ARCH_BITS"
|
---|
1311 | #endif
|
---|
1312 |
|
---|
1313 |
|
---|
1314 | /** @def BS3_XPTR_IS_NULL
|
---|
1315 | * Checks if the cross context pointer is NULL.
|
---|
1316 | *
|
---|
1317 | * @returns true if NULL, false if not.
|
---|
1318 | * @param a_Type The type we're pointing to.
|
---|
1319 | * @param a_Name The member or variable name.
|
---|
1320 | */
|
---|
1321 | #define BS3_XPTR_IS_NULL(a_Type, a_Name) ((a_Name).XPtr.uFlat == 0)
|
---|
1322 |
|
---|
1323 | /**
|
---|
1324 | * Gets a working pointer from a flat address.
|
---|
1325 | *
|
---|
1326 | * @returns Current context pointer.
|
---|
1327 | * @param uFlatPtr The flat address to convert (32-bit or 64-bit).
|
---|
1328 | */
|
---|
1329 | DECLINLINE(void BS3_FAR *) Bs3XptrFlatToCurrent(RTCCUINTXREG uFlatPtr)
|
---|
1330 | {
|
---|
1331 | BS3_XPTR_AUTO(void, pTmp);
|
---|
1332 | BS3_XPTR_SET_FLAT(void, pTmp, uFlatPtr);
|
---|
1333 | return BS3_XPTR_GET(void, pTmp);
|
---|
1334 | }
|
---|
1335 |
|
---|
1336 | /** @} */
|
---|
1337 |
|
---|
1338 |
|
---|
1339 |
|
---|
1340 | /** @defgroup grp_bs3kit_cmn Common Functions and Data
|
---|
1341 | *
|
---|
1342 | * The common functions comes in three variations: 16-bit, 32-bit and 64-bit.
|
---|
1343 | * Templated code uses the #BS3_CMN_NM macro to mangle the name according to the
|
---|
1344 | * desired
|
---|
1345 | *
|
---|
1346 | * @{
|
---|
1347 | */
|
---|
1348 |
|
---|
1349 | /** @def BS3_CMN_PROTO_INT
|
---|
1350 | * Internal macro for prototyping all the variations of a common function.
|
---|
1351 | * @param a_RetType The return type.
|
---|
1352 | * @param a_Name The function basename.
|
---|
1353 | * @param a_Params The parameter list (in parentheses).
|
---|
1354 | * @sa BS3_CMN_PROTO_STUB, BS3_CMN_PROTO_NOSB
|
---|
1355 | */
|
---|
1356 | #if ARCH_BITS == 16
|
---|
1357 | # ifndef BS3_USE_ALT_16BIT_TEXT_SEG
|
---|
1358 | # define BS3_CMN_PROTO_INT(a_RetType, a_Name, a_Params) \
|
---|
1359 | BS3_DECL_NEAR(a_RetType) BS3_CMN_NM(a_Name) a_Params; \
|
---|
1360 | BS3_DECL_FAR(a_RetType) BS3_CMN_FAR_NM(a_Name) a_Params
|
---|
1361 | # else
|
---|
1362 | # define BS3_CMN_PROTO_INT(a_RetType, a_Name, a_Params) \
|
---|
1363 | BS3_DECL_FAR(a_RetType) BS3_CMN_FAR_NM(a_Name) a_Params
|
---|
1364 | # endif
|
---|
1365 | #else
|
---|
1366 | # define BS3_CMN_PROTO_INT(a_RetType, a_Name, a_Params) \
|
---|
1367 | BS3_DECL_NEAR(a_RetType) BS3_CMN_NM(a_Name) a_Params
|
---|
1368 | #endif
|
---|
1369 |
|
---|
1370 | /** @BS3_CMN_PROTO_STUB
|
---|
1371 | * Macro for prototyping all the variations of a common function with automatic
|
---|
1372 | * near -> far stub.
|
---|
1373 | *
|
---|
1374 | * @param a_RetType The return type.
|
---|
1375 | * @param a_Name The function basename.
|
---|
1376 | * @param a_Params The parameter list (in parentheses).
|
---|
1377 | * @sa BS3_CMN_PROTO_NOSB
|
---|
1378 | */
|
---|
1379 | #define BS3_CMN_PROTO_STUB(a_RetType, a_Name, a_Params) BS3_CMN_PROTO_INT(a_RetType, a_Name, a_Params)
|
---|
1380 |
|
---|
1381 | /** @BS3_CMN_PROTO_NOSB
|
---|
1382 | * Macro for prototyping all the variations of a common function without any
|
---|
1383 | * near > far stub.
|
---|
1384 | *
|
---|
1385 | * @param a_RetType The return type.
|
---|
1386 | * @param a_Name The function basename.
|
---|
1387 | * @param a_Params The parameter list (in parentheses).
|
---|
1388 | * @sa BS3_CMN_PROTO_STUB
|
---|
1389 | */
|
---|
1390 | #define BS3_CMN_PROTO_NOSB(a_RetType, a_Name, a_Params) BS3_CMN_PROTO_INT(a_RetType, a_Name, a_Params)
|
---|
1391 |
|
---|
1392 | /** @BS3_CMN_PROTO_FRST
|
---|
1393 | * Macro for prototyping all the variations of a common function with automatic
|
---|
1394 | * far -> near stub.
|
---|
1395 | *
|
---|
1396 | * @param a_cbParam16 The size of the 16-bit parameter list in bytes.
|
---|
1397 | * @param a_RetType The return type.
|
---|
1398 | * @param a_Name The function basename.
|
---|
1399 | * @param a_Params The parameter list (in parentheses).
|
---|
1400 | * @sa BS3_CMN_PROTO_STUB
|
---|
1401 | */
|
---|
1402 | #define BS3_CMN_PROTO_FARSTUB(a_cbParam16, a_RetType, a_Name, a_Params) BS3_CMN_PROTO_INT(a_RetType, a_Name, a_Params)
|
---|
1403 |
|
---|
1404 |
|
---|
1405 | /** @def BS3_CMN_DEF
|
---|
1406 | * Macro for defining a common function.
|
---|
1407 | *
|
---|
1408 | * This makes 16-bit common function far, while 32-bit and 64-bit are near.
|
---|
1409 | *
|
---|
1410 | * @param a_RetType The return type.
|
---|
1411 | * @param a_Name The function basename.
|
---|
1412 | * @param a_Params The parameter list (in parentheses).
|
---|
1413 | */
|
---|
1414 | #if ARCH_BITS == 16
|
---|
1415 | # define BS3_CMN_DEF(a_RetType, a_Name, a_Params) \
|
---|
1416 | BS3_DECL_FAR(a_RetType) BS3_CMN_FAR_NM(a_Name) a_Params
|
---|
1417 | #else
|
---|
1418 | # define BS3_CMN_DEF(a_RetType, a_Name, a_Params) \
|
---|
1419 | BS3_DECL_NEAR(a_RetType) BS3_CMN_NM(a_Name) a_Params
|
---|
1420 | #endif
|
---|
1421 |
|
---|
1422 | /** @def BS3_ASSERT
|
---|
1423 | * Assert that an expression is true.
|
---|
1424 | *
|
---|
1425 | * Calls Bs3Panic if false and it's a strict build. Does nothing in
|
---|
1426 | * non-strict builds. */
|
---|
1427 | #ifdef BS3_STRICT
|
---|
1428 | # define BS3_ASSERT(a_Expr) do { if (!!(a_Expr)) { /* likely */ } else { Bs3Panic(); } } while (0) /**< @todo later */
|
---|
1429 | #else
|
---|
1430 | # define BS3_ASSERT(a_Expr) do { } while (0)
|
---|
1431 | #endif
|
---|
1432 |
|
---|
1433 | /**
|
---|
1434 | * Panic, never return.
|
---|
1435 | *
|
---|
1436 | * The current implementation will only halt the CPU.
|
---|
1437 | */
|
---|
1438 | BS3_CMN_PROTO_NOSB(DECL_NO_RETURN(void), Bs3Panic,(void));
|
---|
1439 | #if !defined(BS3_KIT_WITH_NO_RETURN) && defined(__WATCOMC__)
|
---|
1440 | # pragma aux Bs3Panic_c16 __aborts
|
---|
1441 | # pragma aux Bs3Panic_f16 __aborts
|
---|
1442 | # pragma aux Bs3Panic_c32 __aborts
|
---|
1443 | #endif
|
---|
1444 |
|
---|
1445 |
|
---|
1446 | /**
|
---|
1447 | * Translate a mode into a string.
|
---|
1448 | *
|
---|
1449 | * @returns Pointer to read-only mode name string.
|
---|
1450 | * @param bMode The mode value (BS3_MODE_XXX).
|
---|
1451 | */
|
---|
1452 | BS3_CMN_PROTO_STUB(const char BS3_FAR *, Bs3GetModeName,(uint8_t bMode));
|
---|
1453 |
|
---|
1454 | /**
|
---|
1455 | * Shutdown the system, never returns.
|
---|
1456 | *
|
---|
1457 | * This currently only works for VMs. When running on real systems it will
|
---|
1458 | * just halt the CPU.
|
---|
1459 | */
|
---|
1460 | BS3_CMN_PROTO_NOSB(void, Bs3Shutdown,(void));
|
---|
1461 |
|
---|
1462 | /**
|
---|
1463 | * Prints a 32-bit unsigned value as decimal to the screen.
|
---|
1464 | *
|
---|
1465 | * @param uValue The 32-bit value.
|
---|
1466 | */
|
---|
1467 | BS3_CMN_PROTO_NOSB(void, Bs3PrintU32,(uint32_t uValue));
|
---|
1468 |
|
---|
1469 | /**
|
---|
1470 | * Prints a 32-bit unsigned value as hex to the screen.
|
---|
1471 | *
|
---|
1472 | * @param uValue The 32-bit value.
|
---|
1473 | */
|
---|
1474 | BS3_CMN_PROTO_NOSB(void, Bs3PrintX32,(uint32_t uValue));
|
---|
1475 |
|
---|
1476 | /**
|
---|
1477 | * Formats and prints a string to the screen.
|
---|
1478 | *
|
---|
1479 | * See #Bs3StrFormatV_c16 for supported format types.
|
---|
1480 | *
|
---|
1481 | * @param pszFormat The format string.
|
---|
1482 | * @param ... Format arguments.
|
---|
1483 | */
|
---|
1484 | BS3_CMN_PROTO_STUB(size_t, Bs3Printf,(const char BS3_FAR *pszFormat, ...));
|
---|
1485 |
|
---|
1486 | /**
|
---|
1487 | * Formats and prints a string to the screen, va_list version.
|
---|
1488 | *
|
---|
1489 | * See #Bs3Format_c16 for supported format types.
|
---|
1490 | *
|
---|
1491 | * @param pszFormat The format string.
|
---|
1492 | * @param va Format arguments.
|
---|
1493 | */
|
---|
1494 | BS3_CMN_PROTO_STUB(size_t, Bs3PrintfV,(const char BS3_FAR *pszFormat, va_list va));
|
---|
1495 |
|
---|
1496 | /**
|
---|
1497 | * Prints a string to the screen.
|
---|
1498 | *
|
---|
1499 | * @param pszString The string to print.
|
---|
1500 | */
|
---|
1501 | BS3_CMN_PROTO_STUB(void, Bs3PrintStr,(const char BS3_FAR *pszString));
|
---|
1502 |
|
---|
1503 | /**
|
---|
1504 | * Prints a string to the screen.
|
---|
1505 | *
|
---|
1506 | * @param pchString The string to print. Any terminator charss will be printed.
|
---|
1507 | * @param cchString The exact number of characters to print.
|
---|
1508 | */
|
---|
1509 | BS3_CMN_PROTO_NOSB(void, Bs3PrintStrN,(const char BS3_FAR *pszString, size_t cchString));
|
---|
1510 |
|
---|
1511 | /**
|
---|
1512 | * Prints a char to the screen.
|
---|
1513 | *
|
---|
1514 | * @param ch The character to print.
|
---|
1515 | */
|
---|
1516 | BS3_CMN_PROTO_NOSB(void, Bs3PrintChr,(char ch));
|
---|
1517 |
|
---|
1518 |
|
---|
1519 | /**
|
---|
1520 | * An output function for #Bs3StrFormatV.
|
---|
1521 | *
|
---|
1522 | * @returns Number of characters written.
|
---|
1523 | * @param ch The character to write. Zero in the final call.
|
---|
1524 | * @param pvUser User argument supplied to #Bs3StrFormatV.
|
---|
1525 | */
|
---|
1526 | typedef BS3_DECL_CALLBACK(size_t) FNBS3STRFORMATOUTPUT(char ch, void BS3_FAR *pvUser);
|
---|
1527 | /** Pointer to an output function for #Bs3StrFormatV. */
|
---|
1528 | typedef FNBS3STRFORMATOUTPUT *PFNBS3STRFORMATOUTPUT;
|
---|
1529 |
|
---|
1530 | /**
|
---|
1531 | * Formats a string, sending the output to @a pfnOutput.
|
---|
1532 | *
|
---|
1533 | * Supported types:
|
---|
1534 | * - %RI8, %RI16, %RI32, %RI64
|
---|
1535 | * - %RU8, %RU16, %RU32, %RU64
|
---|
1536 | * - %RX8, %RX16, %RX32, %RX64
|
---|
1537 | * - %i, %d
|
---|
1538 | * - %u
|
---|
1539 | * - %x
|
---|
1540 | * - %c
|
---|
1541 | * - %p (far pointer)
|
---|
1542 | * - %s (far pointer)
|
---|
1543 | *
|
---|
1544 | * @returns Sum of @a pfnOutput return values.
|
---|
1545 | * @param pszFormat The format string.
|
---|
1546 | * @param va Format arguments.
|
---|
1547 | * @param pfnOutput The output function.
|
---|
1548 | * @param pvUser The user argument for the output function.
|
---|
1549 | */
|
---|
1550 | BS3_CMN_PROTO_STUB(size_t, Bs3StrFormatV,(const char BS3_FAR *pszFormat, va_list va,
|
---|
1551 | PFNBS3STRFORMATOUTPUT pfnOutput, void BS3_FAR *pvUser));
|
---|
1552 |
|
---|
1553 | /**
|
---|
1554 | * Formats a string into a buffer.
|
---|
1555 | *
|
---|
1556 | * See #Bs3Format_c16 for supported format types.
|
---|
1557 | *
|
---|
1558 | * @returns The length of the formatted string (excluding terminator).
|
---|
1559 | * This will be higher or equal to @c cbBuf in case of an overflow.
|
---|
1560 | * @param pszBuf The output buffer.
|
---|
1561 | * @param cbBuf The size of the output buffer.
|
---|
1562 | * @param pszFormat The format string.
|
---|
1563 | * @param va Format arguments.
|
---|
1564 | */
|
---|
1565 | BS3_CMN_PROTO_STUB(size_t, Bs3StrPrintfV,(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, va_list va));
|
---|
1566 |
|
---|
1567 | /**
|
---|
1568 | * Formats a string into a buffer.
|
---|
1569 | *
|
---|
1570 | * See #Bs3Format_c16 for supported format types.
|
---|
1571 | *
|
---|
1572 | * @returns The length of the formatted string (excluding terminator).
|
---|
1573 | * This will be higher or equal to @c cbBuf in case of an overflow.
|
---|
1574 | * @param pszBuf The output buffer.
|
---|
1575 | * @param cbBuf The size of the output buffer.
|
---|
1576 | * @param pszFormat The format string.
|
---|
1577 | * @param ... Format arguments.
|
---|
1578 | */
|
---|
1579 | BS3_CMN_PROTO_STUB(size_t, Bs3StrPrintf,(char BS3_FAR *pszBuf, size_t cbBuf, const char BS3_FAR *pszFormat, ...));
|
---|
1580 |
|
---|
1581 |
|
---|
1582 | /**
|
---|
1583 | * Finds the length of a zero terminated string.
|
---|
1584 | *
|
---|
1585 | * @returns String length in chars/bytes.
|
---|
1586 | * @param pszString The string to examine.
|
---|
1587 | */
|
---|
1588 | BS3_CMN_PROTO_STUB(size_t, Bs3StrLen,(const char BS3_FAR *pszString));
|
---|
1589 |
|
---|
1590 | /**
|
---|
1591 | * Finds the length of a zero terminated string, but with a max length.
|
---|
1592 | *
|
---|
1593 | * @returns String length in chars/bytes, or @a cchMax if no zero-terminator
|
---|
1594 | * was found before we reached the limit.
|
---|
1595 | * @param pszString The string to examine.
|
---|
1596 | * @param cchMax The max length to examine.
|
---|
1597 | */
|
---|
1598 | BS3_CMN_PROTO_STUB(size_t, Bs3StrNLen,(const char BS3_FAR *pszString, size_t cchMax));
|
---|
1599 |
|
---|
1600 | /**
|
---|
1601 | * CRT style unsafe strcpy.
|
---|
1602 | *
|
---|
1603 | * @returns pszDst.
|
---|
1604 | * @param pszDst The destination buffer. Must be large enough to
|
---|
1605 | * hold the source string.
|
---|
1606 | * @param pszSrc The source string.
|
---|
1607 | */
|
---|
1608 | BS3_CMN_PROTO_STUB(char BS3_FAR *, Bs3StrCpy,(char BS3_FAR *pszDst, const char BS3_FAR *pszSrc));
|
---|
1609 |
|
---|
1610 | /**
|
---|
1611 | * CRT style memcpy.
|
---|
1612 | *
|
---|
1613 | * @returns pvDst
|
---|
1614 | * @param pvDst The destination buffer.
|
---|
1615 | * @param pvSrc The source buffer.
|
---|
1616 | * @param cbCopy The number of bytes to copy.
|
---|
1617 | */
|
---|
1618 | BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemCpy,(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy));
|
---|
1619 |
|
---|
1620 | /**
|
---|
1621 | * GNU (?) style mempcpy.
|
---|
1622 | *
|
---|
1623 | * @returns pvDst + cbCopy
|
---|
1624 | * @param pvDst The destination buffer.
|
---|
1625 | * @param pvSrc The source buffer.
|
---|
1626 | * @param cbCopy The number of bytes to copy.
|
---|
1627 | */
|
---|
1628 | BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemPCpy,(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy));
|
---|
1629 |
|
---|
1630 | /**
|
---|
1631 | * CRT style memmove (overlapping buffers is fine).
|
---|
1632 | *
|
---|
1633 | * @returns pvDst
|
---|
1634 | * @param pvDst The destination buffer.
|
---|
1635 | * @param pvSrc The source buffer.
|
---|
1636 | * @param cbCopy The number of bytes to copy.
|
---|
1637 | */
|
---|
1638 | BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemMove,(void BS3_FAR *pvDst, const void BS3_FAR *pvSrc, size_t cbToCopy));
|
---|
1639 |
|
---|
1640 | /**
|
---|
1641 | * BSD style bzero.
|
---|
1642 | *
|
---|
1643 | * @param pvDst The buffer to be zeroed.
|
---|
1644 | * @param cbDst The number of bytes to zero.
|
---|
1645 | */
|
---|
1646 | BS3_CMN_PROTO_NOSB(void, Bs3MemZero,(void BS3_FAR *pvDst, size_t cbDst));
|
---|
1647 |
|
---|
1648 | /**
|
---|
1649 | * CRT style memset.
|
---|
1650 | *
|
---|
1651 | * @param pvDst The buffer to be fill.
|
---|
1652 | * @param bFiller The filler byte.
|
---|
1653 | * @param cbDst The number of bytes to fill.
|
---|
1654 | */
|
---|
1655 | BS3_CMN_PROTO_NOSB(void, Bs3MemSet,(void BS3_FAR *pvDst, uint8_t bFiller, size_t cbDst));
|
---|
1656 |
|
---|
1657 | /**
|
---|
1658 | * CRT style memchr.
|
---|
1659 | *
|
---|
1660 | * @param pvHaystack The memory to scan for @a bNeedle.
|
---|
1661 | * @param bNeedle The byte to search for.
|
---|
1662 | * @param cbHaystack The amount of memory to search.
|
---|
1663 | */
|
---|
1664 | BS3_CMN_PROTO_NOSB(void BS3_FAR *, Bs3MemChr,(void const BS3_FAR *pvHaystack, uint8_t bNeedle, size_t cbHaystack));
|
---|
1665 |
|
---|
1666 | /**
|
---|
1667 | * CRT style memcmp.
|
---|
1668 | *
|
---|
1669 | * @returns 0 if equal. Negative if the left side is 'smaller' than the right
|
---|
1670 | * side, and positive in the other case.
|
---|
1671 | * @param pv1 The left hand memory.
|
---|
1672 | * @param pv2 The right hand memory.
|
---|
1673 | * @param bNeedle The number of bytes to compare.
|
---|
1674 | */
|
---|
1675 | BS3_CMN_PROTO_NOSB(int, Bs3MemCmp,(void const BS3_FAR *pv1, void const BS3_FAR *pv2, size_t cb));
|
---|
1676 |
|
---|
1677 | BS3_CMN_PROTO_STUB(void, Bs3UInt64Div,(RTUINT64U uDividend, RTUINT64U uDivisor, RTUINT64U BS3_FAR *paQuotientReminder));
|
---|
1678 | BS3_CMN_PROTO_STUB(void, Bs3UInt32Div,(RTUINT32U uDividend, RTUINT32U uDivisor, RTUINT32U BS3_FAR *paQuotientReminder));
|
---|
1679 |
|
---|
1680 |
|
---|
1681 | /**
|
---|
1682 | * Converts a protected mode 32-bit far pointer to a 32-bit flat address.
|
---|
1683 | *
|
---|
1684 | * @returns 32-bit flat address.
|
---|
1685 | * @param off The segment offset.
|
---|
1686 | * @param uSel The protected mode segment selector.
|
---|
1687 | */
|
---|
1688 | BS3_CMN_PROTO_STUB(uint32_t, Bs3SelProtFar32ToFlat32,(uint32_t off, uint16_t uSel));
|
---|
1689 |
|
---|
1690 | /**
|
---|
1691 | * Converts a current mode 32-bit far pointer to a 32-bit flat address.
|
---|
1692 | *
|
---|
1693 | * @returns 32-bit flat address.
|
---|
1694 | * @param off The segment offset.
|
---|
1695 | * @param uSel The current mode segment selector.
|
---|
1696 | */
|
---|
1697 | BS3_CMN_PROTO_STUB(uint32_t, Bs3SelFar32ToFlat32,(uint32_t off, uint16_t uSel));
|
---|
1698 |
|
---|
1699 | /**
|
---|
1700 | * Wrapper around Bs3SelFar32ToFlat32 that makes it easier to use in tight
|
---|
1701 | * assembly spots.
|
---|
1702 | *
|
---|
1703 | * @returns 32-bit flat address.
|
---|
1704 | * @param off The segment offset.
|
---|
1705 | * @param uSel The current mode segment selector.
|
---|
1706 | * @remarks All register are preserved, except return.
|
---|
1707 | * @remarks No 20h scratch space required in 64-bit mode.
|
---|
1708 | */
|
---|
1709 | BS3_CMN_PROTO_FARSTUB(6, uint32_t, Bs3SelFar32ToFlat32NoClobber,(uint32_t off, uint16_t uSel));
|
---|
1710 |
|
---|
1711 | /**
|
---|
1712 | * Converts a real mode code segment to a protected mode code segment selector.
|
---|
1713 | *
|
---|
1714 | * @returns protected mode segment selector.
|
---|
1715 | * @param uRealSeg Real mode code segment.
|
---|
1716 | * @remarks All register are preserved, except return and parameter.
|
---|
1717 | */
|
---|
1718 | BS3_CMN_PROTO_NOSB(uint16_t, Bs3SelRealModeCodeToProtMode,(uint16_t uRealSeg));
|
---|
1719 |
|
---|
1720 | /**
|
---|
1721 | * Converts a real mode code segment to a protected mode code segment selector.
|
---|
1722 | *
|
---|
1723 | * @returns protected mode segment selector.
|
---|
1724 | * @param uProtSel Real mode code segment.
|
---|
1725 | * @remarks All register are preserved, except return and parameter.
|
---|
1726 | */
|
---|
1727 | BS3_CMN_PROTO_NOSB(uint16_t, Bs3SelProtModeCodeToRealMode,(uint16_t uProtSel));
|
---|
1728 |
|
---|
1729 | /**
|
---|
1730 | * Converts a flat code address to a real mode segment and offset.
|
---|
1731 | *
|
---|
1732 | * @returns Far real mode address (high 16-bit is segment, low is offset).
|
---|
1733 | * @param uFlatAddr Flat code address.
|
---|
1734 | * @remarks All register are preserved, except return and parameter.
|
---|
1735 | */
|
---|
1736 | BS3_CMN_PROTO_NOSB(uint32_t, Bs3SelFlatCodeToRealMode,(uint32_t uFlatAddr));
|
---|
1737 |
|
---|
1738 | /**
|
---|
1739 | * Converts a flat code address to a protected mode 16-bit far pointer (ring-0).
|
---|
1740 | *
|
---|
1741 | * @returns Far 16-bit protected mode address (high 16-bit is segment selector,
|
---|
1742 | * low is segment offset).
|
---|
1743 | * @param uFlatAddr Flat code address.
|
---|
1744 | * @remarks All register are preserved, except return and parameter.
|
---|
1745 | */
|
---|
1746 | BS3_CMN_PROTO_NOSB(uint32_t, Bs3SelFlatCodeToProtFar16,(uint32_t uFlatAddr));
|
---|
1747 |
|
---|
1748 | /**
|
---|
1749 | * Converts a far 16:16 real mode (code) address to a flat address.
|
---|
1750 | *
|
---|
1751 | * @returns 32-bit flat address.
|
---|
1752 | * @param uFar1616 Far real mode address (high 16-bit is segment, low
|
---|
1753 | * is offset).
|
---|
1754 | * @remarks All register are preserved, except return.
|
---|
1755 | * @remarks No 20h scratch space required in 64-bit mode.
|
---|
1756 | * @remarks Exactly the same as Bs3SelRealModeDataToFlat, except for param.
|
---|
1757 | */
|
---|
1758 | BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelRealModeCodeToFlat,(PFNBS3FARADDRCONV uFar1616));
|
---|
1759 |
|
---|
1760 | /**
|
---|
1761 | * Converts a flat data address to a real mode segment and offset.
|
---|
1762 | *
|
---|
1763 | * @returns Far real mode address (high 16-bit is segment, low is offset)
|
---|
1764 | * @param uFlatAddr Flat code address.
|
---|
1765 | * @remarks All register are preserved, except return.
|
---|
1766 | * @remarks No 20h scratch space required in 64-bit mode.
|
---|
1767 | */
|
---|
1768 | BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelFlatDataToRealMode,(uint32_t uFlatAddr));
|
---|
1769 |
|
---|
1770 | /**
|
---|
1771 | * Converts a flat data address to a real mode segment and offset.
|
---|
1772 | *
|
---|
1773 | * @returns Far 16-bit protected mode address (high 16-bit is segment selector,
|
---|
1774 | * low is segment offset).
|
---|
1775 | * @param uFlatAddr Flat code address.
|
---|
1776 | * @remarks All register are preserved, except return.
|
---|
1777 | * @remarks No 20h scratch space required in 64-bit mode.
|
---|
1778 | */
|
---|
1779 | BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelFlatDataToProtFar16,(uint32_t uFlatAddr));
|
---|
1780 |
|
---|
1781 | /**
|
---|
1782 | * Converts a far 16:16 data address to a real mode segment and offset.
|
---|
1783 | *
|
---|
1784 | * @returns Far real mode address (high 16-bit is segment, low is offset)
|
---|
1785 | * @param uFar1616 Far 16-bit protected mode address (high 16-bit is
|
---|
1786 | * segment selector, low is segment offset).
|
---|
1787 | * @remarks All register are preserved, except return.
|
---|
1788 | * @remarks No 20h scratch space required in 64-bit mode.
|
---|
1789 | */
|
---|
1790 | BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelProtFar16DataToRealMode,(uint32_t uFar1616));
|
---|
1791 |
|
---|
1792 | /**
|
---|
1793 | * Converts a far 16:16 real mode address to a 16-bit protected mode address.
|
---|
1794 | *
|
---|
1795 | * @returns Far real mode address (high 16-bit is segment, low is offset)
|
---|
1796 | * @param uFar1616 Far real mode address (high 16-bit is segment, low
|
---|
1797 | * is offset).
|
---|
1798 | * @remarks All register are preserved, except return.
|
---|
1799 | * @remarks No 20h scratch space required in 64-bit mode.
|
---|
1800 | */
|
---|
1801 | BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelRealModeDataToProtFar16,(uint32_t uFar1616));
|
---|
1802 |
|
---|
1803 | /**
|
---|
1804 | * Converts a far 16:16 data address to a flat 32-bit address.
|
---|
1805 | *
|
---|
1806 | * @returns 32-bit flat address.
|
---|
1807 | * @param uFar1616 Far 16-bit protected mode address (high 16-bit is
|
---|
1808 | * segment selector, low is segment offset).
|
---|
1809 | * @remarks All register are preserved, except return.
|
---|
1810 | * @remarks No 20h scratch space required in 64-bit mode.
|
---|
1811 | */
|
---|
1812 | BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelProtFar16DataToFlat,(uint32_t uFar1616));
|
---|
1813 |
|
---|
1814 | /**
|
---|
1815 | * Converts a far 16:16 real mode address to a flat address.
|
---|
1816 | *
|
---|
1817 | * @returns 32-bit flat address.
|
---|
1818 | * @param uFar1616 Far real mode address (high 16-bit is segment, low
|
---|
1819 | * is offset).
|
---|
1820 | * @remarks All register are preserved, except return.
|
---|
1821 | * @remarks No 20h scratch space required in 64-bit mode.
|
---|
1822 | */
|
---|
1823 | BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelRealModeDataToFlat,(uint32_t uFar1616));
|
---|
1824 |
|
---|
1825 | /**
|
---|
1826 | * Gets a flat address from a working poitner.
|
---|
1827 | *
|
---|
1828 | * @returns flat address (32-bit or 64-bit).
|
---|
1829 | * @param pv Current context pointer.
|
---|
1830 | */
|
---|
1831 | DECLINLINE(RTCCUINTXREG) Bs3SelPtrToFlat(void BS3_FAR *pv)
|
---|
1832 | {
|
---|
1833 | #if ARCH_BITS == 16
|
---|
1834 | return BS3_CMN_FN_NM(Bs3SelFar32ToFlat32)(BS3_FP_OFF(pv), BS3_FP_SEG(pv));
|
---|
1835 | #else
|
---|
1836 | return (uintptr_t)pv;
|
---|
1837 | #endif
|
---|
1838 | }
|
---|
1839 |
|
---|
1840 |
|
---|
1841 | /**
|
---|
1842 | * Slab control structure list head.
|
---|
1843 | *
|
---|
1844 | * The slabs on the list must all have the same chunk size.
|
---|
1845 | */
|
---|
1846 | typedef struct BS3SLABHEAD
|
---|
1847 | {
|
---|
1848 | /** Pointer to the first slab. */
|
---|
1849 | BS3_XPTR_MEMBER(struct BS3SLABCTL, pFirst);
|
---|
1850 | /** The allocation chunk size. */
|
---|
1851 | uint16_t cbChunk;
|
---|
1852 | /** Number of slabs in the list. */
|
---|
1853 | uint16_t cSlabs;
|
---|
1854 | /** Number of chunks in the list. */
|
---|
1855 | uint32_t cChunks;
|
---|
1856 | /** Number of free chunks. */
|
---|
1857 | uint32_t cFreeChunks;
|
---|
1858 | } BS3SLABHEAD;
|
---|
1859 | AssertCompileSize(BS3SLABHEAD, 16);
|
---|
1860 | /** Pointer to a slab list head. */
|
---|
1861 | typedef BS3SLABHEAD BS3_FAR *PBS3SLABHEAD;
|
---|
1862 |
|
---|
1863 | /**
|
---|
1864 | * Allocation slab control structure.
|
---|
1865 | *
|
---|
1866 | * This may live at the start of the slab for 4KB slabs, while in a separate
|
---|
1867 | * static location for the larger ones.
|
---|
1868 | */
|
---|
1869 | typedef struct BS3SLABCTL
|
---|
1870 | {
|
---|
1871 | /** Pointer to the next slab control structure in this list. */
|
---|
1872 | BS3_XPTR_MEMBER(struct BS3SLABCTL, pNext);
|
---|
1873 | /** Pointer to the slab list head. */
|
---|
1874 | BS3_XPTR_MEMBER(BS3SLABHEAD, pHead);
|
---|
1875 | /** The base address of the slab. */
|
---|
1876 | BS3_XPTR_MEMBER(uint8_t, pbStart);
|
---|
1877 | /** Number of chunks in this slab. */
|
---|
1878 | uint16_t cChunks;
|
---|
1879 | /** Number of currently free chunks. */
|
---|
1880 | uint16_t cFreeChunks;
|
---|
1881 | /** The chunk size. */
|
---|
1882 | uint16_t cbChunk;
|
---|
1883 | /** The shift count corresponding to cbChunk.
|
---|
1884 | * This is for turning a chunk number into a byte offset and vice versa. */
|
---|
1885 | uint16_t cChunkShift;
|
---|
1886 | /** Bitmap where set bits indicates allocated blocks (variable size,
|
---|
1887 | * multiple of 4). */
|
---|
1888 | uint8_t bmAllocated[4];
|
---|
1889 | } BS3SLABCTL;
|
---|
1890 | /** Pointer to a bs3kit slab control structure. */
|
---|
1891 | typedef BS3SLABCTL BS3_FAR *PBS3SLABCTL;
|
---|
1892 |
|
---|
1893 | /** The chunks must all be in the same 16-bit segment tile. */
|
---|
1894 | #define BS3_SLAB_ALLOC_F_SAME_TILE UINT16_C(0x0001)
|
---|
1895 |
|
---|
1896 | /**
|
---|
1897 | * Initializes a slab.
|
---|
1898 | *
|
---|
1899 | * @param pSlabCtl The slab control structure to initialize.
|
---|
1900 | * @param cbSlabCtl The size of the slab control structure.
|
---|
1901 | * @param uFlatSlabPtr The base address of the slab.
|
---|
1902 | * @param cbSlab The size of the slab.
|
---|
1903 | * @param cbChunk The chunk size.
|
---|
1904 | */
|
---|
1905 | BS3_CMN_PROTO_STUB(void, Bs3SlabInit,(PBS3SLABCTL pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr,
|
---|
1906 | uint32_t cbSlab, uint16_t cbChunk));
|
---|
1907 |
|
---|
1908 | /**
|
---|
1909 | * Allocates one chunk from a slab.
|
---|
1910 | *
|
---|
1911 | * @returns Pointer to a chunk on success, NULL if we're out of chunks.
|
---|
1912 | * @param pSlabCtl The slab constrol structure to allocate from.
|
---|
1913 | */
|
---|
1914 | BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3SlabAlloc,(PBS3SLABCTL pSlabCtl));
|
---|
1915 |
|
---|
1916 | /**
|
---|
1917 | * Allocates one or more chunks rom a slab.
|
---|
1918 | *
|
---|
1919 | * @returns Pointer to the request number of chunks on success, NULL if we're
|
---|
1920 | * out of chunks.
|
---|
1921 | * @param pSlabCtl The slab constrol structure to allocate from.
|
---|
1922 | * @param cChunks The number of contiguous chunks we want.
|
---|
1923 | * @param fFlags Flags, see BS3_SLAB_ALLOC_F_XXX
|
---|
1924 | */
|
---|
1925 | BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3SlabAllocEx,(PBS3SLABCTL pSlabCtl, uint16_t cChunks, uint16_t fFlags));
|
---|
1926 |
|
---|
1927 | /**
|
---|
1928 | * Frees one or more chunks from a slab.
|
---|
1929 | *
|
---|
1930 | * @returns Number of chunks actually freed. When correctly used, this will
|
---|
1931 | * match the @a cChunks parameter, of course.
|
---|
1932 | * @param pSlabCtl The slab constrol structure to free from.
|
---|
1933 | * @param uFlatChunkPtr The flat address of the chunks to free.
|
---|
1934 | * @param cChunks The number of contiguous chunks to free.
|
---|
1935 | */
|
---|
1936 | BS3_CMN_PROTO_STUB(uint16_t, Bs3SlabFree,(PBS3SLABCTL pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks));
|
---|
1937 |
|
---|
1938 |
|
---|
1939 | /**
|
---|
1940 | * Initializes the given slab list head.
|
---|
1941 | *
|
---|
1942 | * @param pHead The slab list head.
|
---|
1943 | * @param cbChunk The chunk size.
|
---|
1944 | */
|
---|
1945 | BS3_CMN_PROTO_STUB(void, Bs3SlabListInit,(PBS3SLABHEAD pHead, uint16_t cbChunk));
|
---|
1946 |
|
---|
1947 | /**
|
---|
1948 | * Adds an initialized slab control structure to the list.
|
---|
1949 | *
|
---|
1950 | * @param pHead The slab list head to add it to.
|
---|
1951 | * @param pSlabCtl The slab control structure to add.
|
---|
1952 | */
|
---|
1953 | BS3_CMN_PROTO_STUB(void, Bs3SlabListAdd,(PBS3SLABHEAD pHead, PBS3SLABCTL pSlabCtl));
|
---|
1954 |
|
---|
1955 | /**
|
---|
1956 | * Allocates one chunk.
|
---|
1957 | *
|
---|
1958 | * @returns Pointer to a chunk on success, NULL if we're out of chunks.
|
---|
1959 | * @param pHead The slab list to allocate from.
|
---|
1960 | */
|
---|
1961 | BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3SlabListAlloc,(PBS3SLABHEAD pHead));
|
---|
1962 |
|
---|
1963 | /**
|
---|
1964 | * Allocates one or more chunks.
|
---|
1965 | *
|
---|
1966 | * @returns Pointer to the request number of chunks on success, NULL if we're
|
---|
1967 | * out of chunks.
|
---|
1968 | * @param pHead The slab list to allocate from.
|
---|
1969 | * @param cChunks The number of contiguous chunks we want.
|
---|
1970 | * @param fFlags Flags, see BS3_SLAB_ALLOC_F_XXX
|
---|
1971 | */
|
---|
1972 | BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3SlabListAllocEx,(PBS3SLABHEAD pHead, uint16_t cChunks, uint16_t fFlags));
|
---|
1973 |
|
---|
1974 | /**
|
---|
1975 | * Frees one or more chunks from a slab list.
|
---|
1976 | *
|
---|
1977 | * @param pHead The slab list to allocate from.
|
---|
1978 | * @param pvChunks Pointer to the first chunk to free.
|
---|
1979 | * @param cChunks The number of contiguous chunks to free.
|
---|
1980 | */
|
---|
1981 | BS3_CMN_PROTO_STUB(void, Bs3SlabListFree,(PBS3SLABHEAD pHead, void BS3_FAR *pvChunks, uint16_t cChunks));
|
---|
1982 |
|
---|
1983 | /**
|
---|
1984 | * Allocation addressing constraints.
|
---|
1985 | */
|
---|
1986 | typedef enum BS3MEMKIND
|
---|
1987 | {
|
---|
1988 | /** Invalid zero type. */
|
---|
1989 | BS3MEMKIND_INVALID = 0,
|
---|
1990 | /** Real mode addressable memory. */
|
---|
1991 | BS3MEMKIND_REAL,
|
---|
1992 | /** Memory addressable using the 16-bit protected mode tiling. */
|
---|
1993 | BS3MEMKIND_TILED,
|
---|
1994 | /** Memory addressable using 32-bit flat addressing. */
|
---|
1995 | BS3MEMKIND_FLAT32,
|
---|
1996 | /** Memory addressable using 64-bit flat addressing. */
|
---|
1997 | BS3MEMKIND_FLAT64,
|
---|
1998 | /** End of valid types. */
|
---|
1999 | BS3MEMKIND_END,
|
---|
2000 | } BS3MEMKIND;
|
---|
2001 |
|
---|
2002 | /**
|
---|
2003 | * Allocates low memory.
|
---|
2004 | *
|
---|
2005 | * @returns Pointer to a chunk on success, NULL if we're out of chunks.
|
---|
2006 | * @param enmKind The kind of addressing constraints imposed on the
|
---|
2007 | * allocation.
|
---|
2008 | * @param cb How much to allocate. Must be 4KB or less.
|
---|
2009 | */
|
---|
2010 | BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemAlloc,(BS3MEMKIND enmKind, size_t cb));
|
---|
2011 |
|
---|
2012 | /**
|
---|
2013 | * Allocates zero'ed memory.
|
---|
2014 | *
|
---|
2015 | * @param enmKind The kind of addressing constraints imposed on the
|
---|
2016 | * allocation.
|
---|
2017 | * @param cb How much to allocate. Must be 4KB or less.
|
---|
2018 | */
|
---|
2019 | BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemAllocZ,(BS3MEMKIND enmKind, size_t cb));
|
---|
2020 |
|
---|
2021 | /**
|
---|
2022 | * Frees memory.
|
---|
2023 | *
|
---|
2024 | * @returns Pointer to a chunk on success, NULL if we're out of chunks.
|
---|
2025 | * @param pv The memory to free (returned by #Bs3MemAlloc).
|
---|
2026 | * @param cb The size of the allocation.
|
---|
2027 | */
|
---|
2028 | BS3_CMN_PROTO_STUB(void, Bs3MemFree,(void BS3_FAR *pv, size_t cb));
|
---|
2029 |
|
---|
2030 | /**
|
---|
2031 | * Allocates a page with non-present pages on each side.
|
---|
2032 | *
|
---|
2033 | * @returns Pointer to the usable page. NULL on failure. Use
|
---|
2034 | * Bs3MemGuardedTestPageFree to free the allocation.
|
---|
2035 | * @param enmKind The kind of addressing constraints imposed on the
|
---|
2036 | * allocation.
|
---|
2037 | */
|
---|
2038 | BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemGuardedTestPageAlloc,(BS3MEMKIND enmKind));
|
---|
2039 |
|
---|
2040 | /**
|
---|
2041 | * Allocates a page with pages on each side to the @a fPte specification.
|
---|
2042 | *
|
---|
2043 | * @returns Pointer to the usable page. NULL on failure. Use
|
---|
2044 | * Bs3MemGuardedTestPageFree to free the allocation.
|
---|
2045 | * @param enmKind The kind of addressing constraints imposed on the
|
---|
2046 | * allocation.
|
---|
2047 | * @param fPte The page table entry specification for the guard pages.
|
---|
2048 | */
|
---|
2049 | BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemGuardedTestPageAllocEx,(BS3MEMKIND enmKind, uint64_t fPte));
|
---|
2050 |
|
---|
2051 | /**
|
---|
2052 | * Frees guarded page allocated by Bs3MemGuardedTestPageAlloc or
|
---|
2053 | * Bs3MemGuardedTestPageAllocEx.
|
---|
2054 | *
|
---|
2055 | * @param pvGuardedPage Pointer returned by Bs3MemGuardedTestPageAlloc or
|
---|
2056 | * Bs3MemGuardedTestPageAllocEx. NULL is ignored.
|
---|
2057 | */
|
---|
2058 | BS3_CMN_PROTO_STUB(void, Bs3MemGuardedTestPageFree,(void BS3_FAR *pvGuardedPage));
|
---|
2059 |
|
---|
2060 | /** Highes RAM byte below 4G. */
|
---|
2061 | extern uint32_t g_uBs3EndOfRamBelow4G;
|
---|
2062 |
|
---|
2063 |
|
---|
2064 | /**
|
---|
2065 | * Enables the A20 gate.
|
---|
2066 | */
|
---|
2067 | BS3_CMN_PROTO_NOSB(void, Bs3A20Enable,(void));
|
---|
2068 |
|
---|
2069 | /**
|
---|
2070 | * Enables the A20 gate via the keyboard controller
|
---|
2071 | */
|
---|
2072 | BS3_CMN_PROTO_NOSB(void, Bs3A20EnableViaKbd,(void));
|
---|
2073 |
|
---|
2074 | /**
|
---|
2075 | * Enables the A20 gate via the PS/2 control port A.
|
---|
2076 | */
|
---|
2077 | BS3_CMN_PROTO_NOSB(void, Bs3A20EnableViaPortA,(void));
|
---|
2078 |
|
---|
2079 | /**
|
---|
2080 | * Disables the A20 gate.
|
---|
2081 | */
|
---|
2082 | BS3_CMN_PROTO_NOSB(void, Bs3A20Disable,(void));
|
---|
2083 |
|
---|
2084 | /**
|
---|
2085 | * Disables the A20 gate via the keyboard controller
|
---|
2086 | */
|
---|
2087 | BS3_CMN_PROTO_NOSB(void, Bs3A20DisableViaKbd,(void));
|
---|
2088 |
|
---|
2089 | /**
|
---|
2090 | * Disables the A20 gate via the PS/2 control port A.
|
---|
2091 | */
|
---|
2092 | BS3_CMN_PROTO_NOSB(void, Bs3A20DisableViaPortA,(void));
|
---|
2093 |
|
---|
2094 |
|
---|
2095 | /**
|
---|
2096 | * Initializes root page tables for page protected mode (PP16, PP32).
|
---|
2097 | *
|
---|
2098 | * @returns IPRT status code.
|
---|
2099 | * @remarks Must not be called in real-mode!
|
---|
2100 | */
|
---|
2101 | BS3_CMN_PROTO_STUB(int, Bs3PagingInitRootForPP,(void));
|
---|
2102 |
|
---|
2103 | /**
|
---|
2104 | * Initializes root page tables for PAE page protected mode (PAE16, PAE32).
|
---|
2105 | *
|
---|
2106 | * @returns IPRT status code.
|
---|
2107 | * @remarks The default long mode page tables depends on the PAE ones.
|
---|
2108 | * @remarks Must not be called in real-mode!
|
---|
2109 | */
|
---|
2110 | BS3_CMN_PROTO_STUB(int, Bs3PagingInitRootForPAE,(void));
|
---|
2111 |
|
---|
2112 | /**
|
---|
2113 | * Initializes root page tables for long mode (LM16, LM32, LM64).
|
---|
2114 | *
|
---|
2115 | * @returns IPRT status code.
|
---|
2116 | * @remarks The default long mode page tables depends on the PAE ones.
|
---|
2117 | * @remarks Must not be called in real-mode!
|
---|
2118 | */
|
---|
2119 | BS3_CMN_PROTO_STUB(int, Bs3PagingInitRootForLM,(void));
|
---|
2120 |
|
---|
2121 | /**
|
---|
2122 | * Modifies the page table protection of an address range.
|
---|
2123 | *
|
---|
2124 | * This only works on the lowest level of the page tables in the current mode.
|
---|
2125 | *
|
---|
2126 | * Since we generally use the largest pages available when setting up the
|
---|
2127 | * initial page tables, this function will usually have to allocate and create
|
---|
2128 | * more tables. This may fail if we're low on memory.
|
---|
2129 | *
|
---|
2130 | * @returns IPRT status code.
|
---|
2131 | * @param uFlat The flat address of the first page in the range (rounded
|
---|
2132 | * down nearest page boundrary).
|
---|
2133 | * @param cb The range size from @a pv (rounded up to nearest page boundrary).
|
---|
2134 | * @param fSet Mask of zero or more X86_PTE_XXX values to set for the range.
|
---|
2135 | * @param fClear Mask of zero or more X86_PTE_XXX values to clear for the range.
|
---|
2136 | */
|
---|
2137 | BS3_CMN_PROTO_STUB(int, Bs3PagingProtect,(uint64_t uFlat, uint64_t cb, uint64_t fSet, uint64_t fClear));
|
---|
2138 |
|
---|
2139 | /**
|
---|
2140 | * Modifies the page table protection of an address range.
|
---|
2141 | *
|
---|
2142 | * This only works on the lowest level of the page tables in the current mode.
|
---|
2143 | *
|
---|
2144 | * Since we generally use the largest pages available when setting up the
|
---|
2145 | * initial page tables, this function will usually have to allocate and create
|
---|
2146 | * more tables. This may fail if we're low on memory.
|
---|
2147 | *
|
---|
2148 | * @returns IPRT status code.
|
---|
2149 | * @param pv The address of the first page in the range (rounded
|
---|
2150 | * down nearest page boundrary).
|
---|
2151 | * @param cb The range size from @a pv (rounded up to nearest page boundrary).
|
---|
2152 | * @param fSet Mask of zero or more X86_PTE_XXX values to set for the range.
|
---|
2153 | * @param fClear Mask of zero or more X86_PTE_XXX values to clear for the range.
|
---|
2154 | */
|
---|
2155 | BS3_CMN_PROTO_STUB(int, Bs3PagingProtectPtr,(void BS3_FAR *pv, size_t cb, uint64_t fSet, uint64_t fClear));
|
---|
2156 |
|
---|
2157 | /**
|
---|
2158 | * Aliases (maps) one or more contiguous physical pages to a virtual range.
|
---|
2159 | *
|
---|
2160 | * @returns VBox status code.
|
---|
2161 | * @retval VERR_INVALID_PARAMETER if we're in legacy paging mode and @a uDst or
|
---|
2162 | * @a uPhysToAlias are not compatible with legacy paging.
|
---|
2163 | * @retval VERR_OUT_OF_RANGE if we cannot traverse the page tables in this mode
|
---|
2164 | * (typically real mode or v86, maybe 16-bit PE).
|
---|
2165 | * @retval VERR_NO_MEMORY if we cannot allocate page tables for splitting up
|
---|
2166 | * the necessary large pages. No aliasing was performed.
|
---|
2167 | *
|
---|
2168 | * @param uDst The virtual address to map it at. Rounded down
|
---|
2169 | * to the nearest page (@a cbHowMuch is adjusted
|
---|
2170 | * up).
|
---|
2171 | * @param uPhysToAlias The physical address of the first page in the
|
---|
2172 | * (contiguous) range to map. Chopped down to
|
---|
2173 | * nearest page boundrary (@a cbHowMuch is not
|
---|
2174 | * adjusted).
|
---|
2175 | * @param cbHowMuch How much to map. Rounded up to nearest page.
|
---|
2176 | * @param fPte The PTE flags.
|
---|
2177 | */
|
---|
2178 | BS3_CMN_PROTO_STUB(int, Bs3PagingAlias,(uint64_t uDst, uint64_t uPhysToAlias, uint32_t cbHowMuch, uint64_t fPte));
|
---|
2179 |
|
---|
2180 | /**
|
---|
2181 | * Unaliases memory, i.e. restores the 1:1 mapping.
|
---|
2182 | *
|
---|
2183 | * @returns VBox status code. Cannot fail if @a uDst and @a cbHowMuch specify
|
---|
2184 | * the range of a successful Bs3PagingAlias call, however it may run
|
---|
2185 | * out of memory if it's breaking new ground.
|
---|
2186 | *
|
---|
2187 | * @param uDst The virtual address to restore to 1:1 mapping.
|
---|
2188 | * Rounded down to the nearest page (@a cbHowMuch
|
---|
2189 | * is adjusted up).
|
---|
2190 | * @param cbHowMuch How much to restore. Rounded up to nearest page.
|
---|
2191 | */
|
---|
2192 | BS3_CMN_PROTO_STUB(int, Bs3PagingUnalias,(uint64_t uDst, uint32_t cbHowMuch));
|
---|
2193 |
|
---|
2194 |
|
---|
2195 | /** The physical / flat address of the buffer backing the canonical traps.
|
---|
2196 | * This buffer is spread equally on each side of the 64-bit non-canonical
|
---|
2197 | * address divide. Non-64-bit code can use this to setup trick shots and
|
---|
2198 | * inspect their results. */
|
---|
2199 | extern uint32_t g_uBs3PagingCanonicalTrapsAddr;
|
---|
2200 | /** The size of the buffer at g_uPagingCanonicalTraps (both sides). */
|
---|
2201 | extern uint16_t g_cbBs3PagingCanonicalTraps;
|
---|
2202 | /** The size of one trap buffer (low or high).
|
---|
2203 | * This is g_cbBs3PagingCanonicalTraps divided by two. */
|
---|
2204 | extern uint16_t g_cbBs3PagingOneCanonicalTrap;
|
---|
2205 |
|
---|
2206 | /**
|
---|
2207 | * Sets up the 64-bit canonical address space trap buffers, if neceessary.
|
---|
2208 | *
|
---|
2209 | * @returns Pointer to the buffers (i.e. the first page of the low one) on
|
---|
2210 | * success. NULL on failure.
|
---|
2211 | */
|
---|
2212 | BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3PagingSetupCanonicalTraps,(void));
|
---|
2213 |
|
---|
2214 | /**
|
---|
2215 | * Waits for the keyboard controller to become ready.
|
---|
2216 | */
|
---|
2217 | BS3_CMN_PROTO_NOSB(void, Bs3KbdWait,(void));
|
---|
2218 |
|
---|
2219 | /**
|
---|
2220 | * Sends a read command to the keyboard controller and gets the result.
|
---|
2221 | *
|
---|
2222 | * The caller is responsible for making sure the keyboard controller is ready
|
---|
2223 | * for a command (call #Bs3KbdWait if unsure).
|
---|
2224 | *
|
---|
2225 | * @returns The value read is returned (in al).
|
---|
2226 | * @param bCmd The read command.
|
---|
2227 | */
|
---|
2228 | BS3_CMN_PROTO_NOSB(uint8_t, Bs3KbdRead,(uint8_t bCmd));
|
---|
2229 |
|
---|
2230 | /**
|
---|
2231 | * Sends a write command to the keyboard controller and then sends the data.
|
---|
2232 | *
|
---|
2233 | * The caller is responsible for making sure the keyboard controller is ready
|
---|
2234 | * for a command (call #Bs3KbdWait if unsure).
|
---|
2235 | *
|
---|
2236 | * @param bCmd The write command.
|
---|
2237 | * @param bData The data to write.
|
---|
2238 | */
|
---|
2239 | BS3_CMN_PROTO_NOSB(void, Bs3KbdWrite,(uint8_t bCmd, uint8_t bData));
|
---|
2240 |
|
---|
2241 |
|
---|
2242 | /**
|
---|
2243 | * Disables all IRQs on the PIC.
|
---|
2244 | */
|
---|
2245 | BS3_CMN_PROTO_STUB(void, Bs3PicMaskAll,(void));
|
---|
2246 |
|
---|
2247 |
|
---|
2248 | /**
|
---|
2249 | * Call 16-bit prot mode function from v8086 mode.
|
---|
2250 | *
|
---|
2251 | * This switches from v8086 mode to 16-bit protected mode (code) and executed
|
---|
2252 | * @a fpfnCall with @a cbParams bytes of parameters pushed on the stack.
|
---|
2253 | * Afterwards it switches back to v8086 mode and returns a 16-bit status code.
|
---|
2254 | *
|
---|
2255 | * @returns 16-bit status code if the function returned anything.
|
---|
2256 | * @param fpfnCall Far real mode pointer to the function to call.
|
---|
2257 | * @param cbParams The size of the parameter list, in bytes.
|
---|
2258 | * @param ... The parameters.
|
---|
2259 | */
|
---|
2260 | BS3_CMN_PROTO_STUB(int, Bs3SwitchFromV86To16BitAndCallC,(FPFNBS3FAR fpfnCall, unsigned cbParams, ...));
|
---|
2261 |
|
---|
2262 |
|
---|
2263 | /**
|
---|
2264 | * BS3 integer register.
|
---|
2265 | */
|
---|
2266 | typedef union BS3REG
|
---|
2267 | {
|
---|
2268 | /** 8-bit unsigned integer. */
|
---|
2269 | uint8_t u8;
|
---|
2270 | /** 16-bit unsigned integer. */
|
---|
2271 | uint16_t u16;
|
---|
2272 | /** 32-bit unsigned integer. */
|
---|
2273 | uint32_t u32;
|
---|
2274 | /** 64-bit unsigned integer. */
|
---|
2275 | uint64_t u64;
|
---|
2276 | /** Full unsigned integer. */
|
---|
2277 | uint64_t u;
|
---|
2278 | /** High/low byte view. */
|
---|
2279 | struct
|
---|
2280 | {
|
---|
2281 | uint8_t bLo;
|
---|
2282 | uint8_t bHi;
|
---|
2283 | } b;
|
---|
2284 | /** 8-bit view. */
|
---|
2285 | uint8_t au8[8];
|
---|
2286 | /** 16-bit view. */
|
---|
2287 | uint16_t au16[4];
|
---|
2288 | /** 32-bit view. */
|
---|
2289 | uint32_t au32[2];
|
---|
2290 | } BS3REG;
|
---|
2291 | /** Pointer to an integer register. */
|
---|
2292 | typedef BS3REG BS3_FAR *PBS3REG;
|
---|
2293 | /** Pointer to a const integer register. */
|
---|
2294 | typedef BS3REG const BS3_FAR *PCBS3REG;
|
---|
2295 |
|
---|
2296 | /**
|
---|
2297 | * Register context (without FPU).
|
---|
2298 | */
|
---|
2299 | typedef struct BS3REGCTX
|
---|
2300 | {
|
---|
2301 | BS3REG rax; /**< 0x00 */
|
---|
2302 | BS3REG rcx; /**< 0x08 */
|
---|
2303 | BS3REG rdx; /**< 0x10 */
|
---|
2304 | BS3REG rbx; /**< 0x18 */
|
---|
2305 | BS3REG rsp; /**< 0x20 */
|
---|
2306 | BS3REG rbp; /**< 0x28 */
|
---|
2307 | BS3REG rsi; /**< 0x30 */
|
---|
2308 | BS3REG rdi; /**< 0x38 */
|
---|
2309 | BS3REG r8; /**< 0x40 */
|
---|
2310 | BS3REG r9; /**< 0x48 */
|
---|
2311 | BS3REG r10; /**< 0x50 */
|
---|
2312 | BS3REG r11; /**< 0x58 */
|
---|
2313 | BS3REG r12; /**< 0x60 */
|
---|
2314 | BS3REG r13; /**< 0x68 */
|
---|
2315 | BS3REG r14; /**< 0x70 */
|
---|
2316 | BS3REG r15; /**< 0x78 */
|
---|
2317 | BS3REG rflags; /**< 0x80 */
|
---|
2318 | BS3REG rip; /**< 0x88 */
|
---|
2319 | uint16_t cs; /**< 0x90 */
|
---|
2320 | uint16_t ds; /**< 0x92 */
|
---|
2321 | uint16_t es; /**< 0x94 */
|
---|
2322 | uint16_t fs; /**< 0x96 */
|
---|
2323 | uint16_t gs; /**< 0x98 */
|
---|
2324 | uint16_t ss; /**< 0x9a */
|
---|
2325 | uint16_t tr; /**< 0x9c */
|
---|
2326 | uint16_t ldtr; /**< 0x9e */
|
---|
2327 | uint8_t bMode; /**< 0xa0: BS3_MODE_XXX. */
|
---|
2328 | uint8_t bCpl; /**< 0xa1: 0-3, 0 is used for real mode. */
|
---|
2329 | uint8_t fbFlags; /**< 0xa2: BS3REG_CTX_F_XXX */
|
---|
2330 | uint8_t abPadding[5]; /**< 0xa3 */
|
---|
2331 | BS3REG cr0; /**< 0xa8 */
|
---|
2332 | BS3REG cr2; /**< 0xb0 */
|
---|
2333 | BS3REG cr3; /**< 0xb8 */
|
---|
2334 | BS3REG cr4; /**< 0xc0 */
|
---|
2335 | uint64_t uUnused; /**< 0xc8 */
|
---|
2336 | } BS3REGCTX;
|
---|
2337 | AssertCompileSize(BS3REGCTX, 0xd0);
|
---|
2338 | /** Pointer to a register context. */
|
---|
2339 | typedef BS3REGCTX BS3_FAR *PBS3REGCTX;
|
---|
2340 | /** Pointer to a const register context. */
|
---|
2341 | typedef BS3REGCTX const BS3_FAR *PCBS3REGCTX;
|
---|
2342 |
|
---|
2343 | /** @name BS3REG_CTX_F_XXX - BS3REGCTX::fbFlags masks.
|
---|
2344 | * @{ */
|
---|
2345 | /** The CR0 is MSW (only low 16-bit). */
|
---|
2346 | #define BS3REG_CTX_F_NO_CR0_IS_MSW UINT8_C(0x01)
|
---|
2347 | /** No CR2 and CR3 values. Not in CPL 0 or CPU too old for CR2 & CR3. */
|
---|
2348 | #define BS3REG_CTX_F_NO_CR2_CR3 UINT8_C(0x02)
|
---|
2349 | /** No CR4 value. The CPU is too old for CR4. */
|
---|
2350 | #define BS3REG_CTX_F_NO_CR4 UINT8_C(0x04)
|
---|
2351 | /** No TR and LDTR values. Context gathered in real mode or v8086 mode. */
|
---|
2352 | #define BS3REG_CTX_F_NO_TR_LDTR UINT8_C(0x08)
|
---|
2353 | /** The context doesn't have valid values for AMD64 GPR extensions. */
|
---|
2354 | #define BS3REG_CTX_F_NO_AMD64 UINT8_C(0x10)
|
---|
2355 | /** @} */
|
---|
2356 |
|
---|
2357 | /**
|
---|
2358 | * Saves the current register context.
|
---|
2359 | *
|
---|
2360 | * @param pRegCtx Where to store the register context.
|
---|
2361 | */
|
---|
2362 | BS3_CMN_PROTO_NOSB(void, Bs3RegCtxSave,(PCBS3REGCTX pRegCtx));
|
---|
2363 |
|
---|
2364 | /**
|
---|
2365 | * Switch to the specified CPU bitcount, reserve additional stack and save the
|
---|
2366 | * CPU context.
|
---|
2367 | *
|
---|
2368 | * This is for writing more flexible test drivers that can test more than the
|
---|
2369 | * CPU bitcount (16-bit, 32-bit, 64-bit, and virtual 8086) of the driver itself.
|
---|
2370 | * For instance a 32-bit driver can do V86 and 16-bit testing, thus saving more
|
---|
2371 | * precious and problematic 16-bit code.
|
---|
2372 | *
|
---|
2373 | * @param pRegCtx Where to store the register context.
|
---|
2374 | * @param bBitMode Bit mode to switch to, BS3_MODE_CODE_XXX. Only
|
---|
2375 | * BS3_MODE_CODE_MASK is used, other bits are ignored
|
---|
2376 | * to make it possible to pass a full mode value.
|
---|
2377 | * @param cbExtraStack Number of bytes of additional stack to allocate.
|
---|
2378 | */
|
---|
2379 | BS3_CMN_PROTO_FARSTUB(8, void, Bs3RegCtxSaveEx,(PCBS3REGCTX pRegCtx, uint8_t bBitMode, uint16_t cbExtraStack));
|
---|
2380 |
|
---|
2381 | /**
|
---|
2382 | * Transforms a register context to a different ring.
|
---|
2383 | *
|
---|
2384 | * @param pRegCtx The register context.
|
---|
2385 | * @param bRing The target ring (0..3).
|
---|
2386 | */
|
---|
2387 | BS3_CMN_PROTO_STUB(void, Bs3RegCtxConvertToRingX,(PBS3REGCTX pRegCtx, uint8_t bRing));
|
---|
2388 |
|
---|
2389 | /**
|
---|
2390 | * Restores a register context.
|
---|
2391 | *
|
---|
2392 | * @param pRegCtx The register context to be restored and resumed.
|
---|
2393 | * @param fFlags BS3REGCTXRESTORE_F_XXX.
|
---|
2394 | *
|
---|
2395 | * @remarks Will switch to ring-0.
|
---|
2396 | * @remarks Does not return.
|
---|
2397 | */
|
---|
2398 | BS3_CMN_PROTO_NOSB(DECL_NO_RETURN(void), Bs3RegCtxRestore,(PCBS3REGCTX pRegCtx, uint16_t fFlags));
|
---|
2399 | #if !defined(BS3_KIT_WITH_NO_RETURN) && defined(__WATCOMC__)
|
---|
2400 | # pragma aux Bs3RegCtxRestore_c16 "_Bs3RegCtxRestore_aborts_c16" __aborts
|
---|
2401 | # pragma aux Bs3RegCtxRestore_f16 "_Bs3RegCtxRestore_aborts_f16" __aborts
|
---|
2402 | # pragma aux Bs3RegCtxRestore_c32 "_Bs3RegCtxRestore_aborts_c32" __aborts
|
---|
2403 | #endif
|
---|
2404 |
|
---|
2405 | /** Skip restoring the CRx registers. */
|
---|
2406 | #define BS3REGCTXRESTORE_F_SKIP_CRX UINT16_C(0x0001)
|
---|
2407 |
|
---|
2408 | /**
|
---|
2409 | * Prints the register context.
|
---|
2410 | *
|
---|
2411 | * @param pRegCtx The register context to be printed.
|
---|
2412 | */
|
---|
2413 | BS3_CMN_PROTO_STUB(void, Bs3RegCtxPrint,(PCBS3REGCTX pRegCtx));
|
---|
2414 |
|
---|
2415 | /**
|
---|
2416 | * Sets a GPR and segment register to point at the same location as @a uFlat.
|
---|
2417 | *
|
---|
2418 | * @param pRegCtx The register context.
|
---|
2419 | * @param pGpr The general purpose register to set (points within
|
---|
2420 | * @a pRegCtx).
|
---|
2421 | * @param pSel The selector register (points within @a pRegCtx).
|
---|
2422 | * @param uFlat Flat location address.
|
---|
2423 | */
|
---|
2424 | BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetGrpSegFromFlat,(PBS3REGCTX pRegCtx, PBS3REG pGpr, PRTSEL pSel, RTCCUINTXREG uFlat));
|
---|
2425 |
|
---|
2426 | /**
|
---|
2427 | * Sets a GPR and segment register to point at the same location as @a ovPtr.
|
---|
2428 | *
|
---|
2429 | * @param pRegCtx The register context.
|
---|
2430 | * @param pGpr The general purpose register to set (points within
|
---|
2431 | * @a pRegCtx).
|
---|
2432 | * @param pSel The selector register (points within @a pRegCtx).
|
---|
2433 | * @param pvPtr Current context pointer.
|
---|
2434 | */
|
---|
2435 | BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetGrpSegFromCurPtr,(PBS3REGCTX pRegCtx, PBS3REG pGpr, PRTSEL pSel, void BS3_FAR *pvPtr));
|
---|
2436 |
|
---|
2437 | /**
|
---|
2438 | * Sets a GPR and DS to point at the same location as @a ovPtr.
|
---|
2439 | *
|
---|
2440 | * @param pRegCtx The register context.
|
---|
2441 | * @param pGpr The general purpose register to set (points within
|
---|
2442 | * @a pRegCtx).
|
---|
2443 | * @param pvPtr Current context pointer.
|
---|
2444 | */
|
---|
2445 | BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetGrpDsFromCurPtr,(PBS3REGCTX pRegCtx, PBS3REG pGpr, void BS3_FAR *pvPtr));
|
---|
2446 |
|
---|
2447 | /**
|
---|
2448 | * Sets CS:RIP to point at the same piece of code as @a uFlatCode.
|
---|
2449 | *
|
---|
2450 | * @param pRegCtx The register context.
|
---|
2451 | * @param uFlatCode Flat code pointer
|
---|
2452 | * @sa Bs3RegCtxSetRipCsFromLnkPtr, Bs3RegCtxSetRipCsFromCurPtr
|
---|
2453 | */
|
---|
2454 | BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetRipCsFromFlat,(PBS3REGCTX pRegCtx, RTCCUINTXREG uFlatCode));
|
---|
2455 |
|
---|
2456 | /**
|
---|
2457 | * Sets CS:RIP to point at the same piece of code as @a pfnCode.
|
---|
2458 | *
|
---|
2459 | * The 16-bit edition of this function expects a far 16:16 address as written by
|
---|
2460 | * the linker (i.e. real mode).
|
---|
2461 | *
|
---|
2462 | * @param pRegCtx The register context.
|
---|
2463 | * @param pfnCode Pointer to the code. In 32-bit and 64-bit mode this is a
|
---|
2464 | * flat address, while in 16-bit it's a far 16:16 address
|
---|
2465 | * as fixed up by the linker (real mode selector). This
|
---|
2466 | * address is converted to match the mode of the context.
|
---|
2467 | * @sa Bs3RegCtxSetRipCsFromCurPtr, Bs3RegCtxSetRipCsFromFlat
|
---|
2468 | */
|
---|
2469 | BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetRipCsFromLnkPtr,(PBS3REGCTX pRegCtx, FPFNBS3FAR pfnCode));
|
---|
2470 |
|
---|
2471 | /**
|
---|
2472 | * Sets CS:RIP to point at the same piece of code as @a pfnCode.
|
---|
2473 | *
|
---|
2474 | * @param pRegCtx The register context.
|
---|
2475 | * @param pfnCode Pointer to the code. Current mode pointer.
|
---|
2476 | * @sa Bs3RegCtxSetRipCsFromLnkPtr, Bs3RegCtxSetRipCsFromFlat
|
---|
2477 | */
|
---|
2478 | BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetRipCsFromCurPtr,(PBS3REGCTX pRegCtx, FPFNBS3FAR pfnCode));
|
---|
2479 |
|
---|
2480 |
|
---|
2481 | /**
|
---|
2482 | * Trap frame.
|
---|
2483 | */
|
---|
2484 | typedef struct BS3TRAPFRAME
|
---|
2485 | {
|
---|
2486 | /** 0x00: Exception/interrupt number. */
|
---|
2487 | uint8_t bXcpt;
|
---|
2488 | /** 0x01: The size of the IRET frame. */
|
---|
2489 | uint8_t cbIretFrame;
|
---|
2490 | /** 0x02: The handler CS. */
|
---|
2491 | uint16_t uHandlerCs;
|
---|
2492 | /** 0x04: The handler SS. */
|
---|
2493 | uint16_t uHandlerSs;
|
---|
2494 | /** 0x06: Explicit alignment. */
|
---|
2495 | uint16_t usAlignment;
|
---|
2496 | /** 0x08: The handler RSP (pointer to the iret frame, skipping ErrCd). */
|
---|
2497 | uint64_t uHandlerRsp;
|
---|
2498 | /** 0x10: The handler RFLAGS value. */
|
---|
2499 | uint64_t fHandlerRfl;
|
---|
2500 | /** 0x18: The error code (if applicable). */
|
---|
2501 | uint64_t uErrCd;
|
---|
2502 | /** 0x20: The register context. */
|
---|
2503 | BS3REGCTX Ctx;
|
---|
2504 | } BS3TRAPFRAME;
|
---|
2505 | AssertCompileSize(BS3TRAPFRAME, 0x20 + 0xd0);
|
---|
2506 | /** Pointer to a trap frame. */
|
---|
2507 | typedef BS3TRAPFRAME BS3_FAR *PBS3TRAPFRAME;
|
---|
2508 | /** Pointer to a const trap frame. */
|
---|
2509 | typedef BS3TRAPFRAME const BS3_FAR *PCBS3TRAPFRAME;
|
---|
2510 |
|
---|
2511 |
|
---|
2512 | /**
|
---|
2513 | * Re-initializes the trap handling for the current mode.
|
---|
2514 | *
|
---|
2515 | * Useful after a test that messes with the IDT/IVT.
|
---|
2516 | *
|
---|
2517 | * @sa Bs3TrapInit
|
---|
2518 | */
|
---|
2519 | BS3_CMN_PROTO_STUB(void, Bs3TrapReInit,(void));
|
---|
2520 |
|
---|
2521 | /**
|
---|
2522 | * Initializes real mode and v8086 trap handling.
|
---|
2523 | *
|
---|
2524 | * @remarks Does not install RM/V86 trap handling, just initializes the
|
---|
2525 | * structures.
|
---|
2526 | */
|
---|
2527 | BS3_CMN_PROTO_STUB(void, Bs3TrapRmV86Init,(void));
|
---|
2528 |
|
---|
2529 | /**
|
---|
2530 | * Initializes real mode and v8086 trap handling, extended version.
|
---|
2531 | *
|
---|
2532 | * @param f386Plus Set if the CPU is 80386 or later and
|
---|
2533 | * extended registers should be saved. Once initialized
|
---|
2534 | * with this parameter set to @a true, the effect cannot be
|
---|
2535 | * reversed.
|
---|
2536 | *
|
---|
2537 | * @remarks Does not install RM/V86 trap handling, just initializes the
|
---|
2538 | * structures.
|
---|
2539 | */
|
---|
2540 | BS3_CMN_PROTO_STUB(void, Bs3TrapRmV86InitEx,(bool f386Plus));
|
---|
2541 |
|
---|
2542 | /**
|
---|
2543 | * Initializes 16-bit (protected mode) trap handling.
|
---|
2544 | *
|
---|
2545 | * @remarks Does not install 16-bit trap handling, just initializes the
|
---|
2546 | * structures.
|
---|
2547 | */
|
---|
2548 | BS3_CMN_PROTO_STUB(void, Bs3Trap16Init,(void));
|
---|
2549 |
|
---|
2550 | /**
|
---|
2551 | * Initializes 16-bit (protected mode) trap handling, extended version.
|
---|
2552 | *
|
---|
2553 | * @param f386Plus Set if the CPU is 80386 or later and
|
---|
2554 | * extended registers should be saved. Once initialized
|
---|
2555 | * with this parameter set to @a true, the effect cannot be
|
---|
2556 | * reversed.
|
---|
2557 | *
|
---|
2558 | * @remarks Does not install 16-bit trap handling, just initializes the
|
---|
2559 | * structures.
|
---|
2560 | */
|
---|
2561 | BS3_CMN_PROTO_STUB(void, Bs3Trap16InitEx,(bool f386Plus));
|
---|
2562 |
|
---|
2563 | /**
|
---|
2564 | * Initializes 32-bit trap handling.
|
---|
2565 | *
|
---|
2566 | * @remarks Does not install 32-bit trap handling, just initializes the
|
---|
2567 | * structures.
|
---|
2568 | */
|
---|
2569 | BS3_CMN_PROTO_STUB(void, Bs3Trap32Init,(void));
|
---|
2570 |
|
---|
2571 | /**
|
---|
2572 | * Initializes 64-bit trap handling
|
---|
2573 | *
|
---|
2574 | * @remarks Does not install 64-bit trap handling, just initializes the
|
---|
2575 | * structures.
|
---|
2576 | */
|
---|
2577 | BS3_CMN_PROTO_STUB(void, Bs3Trap64Init,(void));
|
---|
2578 |
|
---|
2579 | /**
|
---|
2580 | * Modifies the real-mode / V86 IVT entry specified by @a iIvt.
|
---|
2581 | *
|
---|
2582 | * @param iIvt The index of the IDT entry to set.
|
---|
2583 | * @param uSel The handler real-mode segment.
|
---|
2584 | * @param off The handler offset.
|
---|
2585 | */
|
---|
2586 | BS3_CMN_PROTO_STUB(void, Bs3TrapRmV86SetGate,(uint8_t iIvt, uint16_t uSeg, uint16_t off));
|
---|
2587 |
|
---|
2588 | /**
|
---|
2589 | * Modifies the 16-bit IDT entry (protected mode) specified by @a iIdt.
|
---|
2590 | *
|
---|
2591 | * @param iIdt The index of the IDT entry to set.
|
---|
2592 | * @param bType The gate type (X86_SEL_TYPE_SYS_XXX).
|
---|
2593 | * @param bDpl The DPL.
|
---|
2594 | * @param uSel The handler selector.
|
---|
2595 | * @param off The handler offset (if applicable).
|
---|
2596 | * @param cParams The parameter count (for call gates).
|
---|
2597 | */
|
---|
2598 | BS3_CMN_PROTO_STUB(void, Bs3Trap16SetGate,(uint8_t iIdt, uint8_t bType, uint8_t bDpl,
|
---|
2599 | uint16_t uSel, uint16_t off, uint8_t cParams));
|
---|
2600 |
|
---|
2601 | /** The address of Bs3Trap16GenericEntries.
|
---|
2602 | * Bs3Trap16GenericEntries is an array of interrupt/trap/whatever entry
|
---|
2603 | * points, 8 bytes each, that will create a register frame and call the generic
|
---|
2604 | * C compatible trap handlers. */
|
---|
2605 | extern uint32_t g_Bs3Trap16GenericEntriesFlatAddr;
|
---|
2606 |
|
---|
2607 | /**
|
---|
2608 | * Modifies the 32-bit IDT entry specified by @a iIdt.
|
---|
2609 | *
|
---|
2610 | * @param iIdt The index of the IDT entry to set.
|
---|
2611 | * @param bType The gate type (X86_SEL_TYPE_SYS_XXX).
|
---|
2612 | * @param bDpl The DPL.
|
---|
2613 | * @param uSel The handler selector.
|
---|
2614 | * @param off The handler offset (if applicable).
|
---|
2615 | * @param cParams The parameter count (for call gates).
|
---|
2616 | */
|
---|
2617 | BS3_CMN_PROTO_STUB(void, Bs3Trap32SetGate,(uint8_t iIdt, uint8_t bType, uint8_t bDpl,
|
---|
2618 | uint16_t uSel, uint32_t off, uint8_t cParams));
|
---|
2619 |
|
---|
2620 | /** The address of Bs3Trap32GenericEntries.
|
---|
2621 | * Bs3Trap32GenericEntries is an array of interrupt/trap/whatever entry
|
---|
2622 | * points, 10 bytes each, that will create a register frame and call the generic
|
---|
2623 | * C compatible trap handlers. */
|
---|
2624 | extern uint32_t g_Bs3Trap32GenericEntriesFlatAddr;
|
---|
2625 |
|
---|
2626 | /**
|
---|
2627 | * Modifies the 64-bit IDT entry specified by @a iIdt.
|
---|
2628 | *
|
---|
2629 | * @param iIdt The index of the IDT entry to set.
|
---|
2630 | * @param bType The gate type (X86_SEL_TYPE_SYS_XXX).
|
---|
2631 | * @param bDpl The DPL.
|
---|
2632 | * @param uSel The handler selector.
|
---|
2633 | * @param off The handler offset (if applicable).
|
---|
2634 | * @param bIst The interrupt stack to use.
|
---|
2635 | */
|
---|
2636 | BS3_CMN_PROTO_STUB(void, Bs3Trap64SetGate,(uint8_t iIdt, uint8_t bType, uint8_t bDpl, uint16_t uSel, uint64_t off, uint8_t bIst));
|
---|
2637 |
|
---|
2638 | /** The address of Bs3Trap64GenericEntries.
|
---|
2639 | * Bs3Trap64GenericEntries is an array of interrupt/trap/whatever entry
|
---|
2640 | * points, 8 bytes each, that will create a register frame and call the generic
|
---|
2641 | * C compatible trap handlers. */
|
---|
2642 | extern uint32_t g_Bs3Trap64GenericEntriesFlatAddr;
|
---|
2643 |
|
---|
2644 | /**
|
---|
2645 | * C-style trap handler.
|
---|
2646 | *
|
---|
2647 | * Upon return Bs3Trap16ResumeFrame_c16, #Bs3Trap32ResumeFrame_c32, or
|
---|
2648 | * Bs3Trap64ResumeFrame_c64 will be called depending on the current template
|
---|
2649 | * context.
|
---|
2650 | *
|
---|
2651 | * @param pTrapFrame The trap frame. Registers can be modified.
|
---|
2652 | */
|
---|
2653 | typedef BS3_DECL_CALLBACK(void) FNBS3TRAPHANDLER(PBS3TRAPFRAME pTrapFrame);
|
---|
2654 | /** Pointer to a trap handler (current template context). */
|
---|
2655 | typedef FNBS3TRAPHANDLER *PFNBS3TRAPHANDLER;
|
---|
2656 |
|
---|
2657 | /**
|
---|
2658 | * Sets a trap handler (C/C++/assembly) for the current bitcount.
|
---|
2659 | *
|
---|
2660 | * When using a 32-bit IDT, only #Bs3TrapSetHandler_c32 will have any effect.
|
---|
2661 | * Likewise, when using a 16-bit IDT, only Bs3TrapSetHandler_c16 will make any
|
---|
2662 | * difference. Ditto 64-bit.
|
---|
2663 | *
|
---|
2664 | * Rational: It's mainly a C API, can't easily mix function pointers from other
|
---|
2665 | * bit counts in C. Use assembly helpers or something if that is necessary.
|
---|
2666 | * Besides, most of the real trap handling goes thru the default handler with
|
---|
2667 | * help of trap records.
|
---|
2668 | *
|
---|
2669 | * @returns Previous handler.
|
---|
2670 | * @param iIdt The index of the IDT entry to set.
|
---|
2671 | * @param pfnHandler Pointer to the handler.
|
---|
2672 | */
|
---|
2673 | BS3_CMN_PROTO_STUB(PFNBS3TRAPHANDLER, Bs3TrapSetHandler,(uint8_t iIdt, PFNBS3TRAPHANDLER pfnHandler));
|
---|
2674 |
|
---|
2675 | /**
|
---|
2676 | * Default C/C++ trap handler.
|
---|
2677 | *
|
---|
2678 | * This will check trap record and panic if no match was found.
|
---|
2679 | *
|
---|
2680 | * @param pTrapFrame Trap frame of the trap to handle.
|
---|
2681 | */
|
---|
2682 | BS3_CMN_PROTO_STUB(void, Bs3TrapDefaultHandler,(PBS3TRAPFRAME pTrapFrame));
|
---|
2683 |
|
---|
2684 | /**
|
---|
2685 | * Prints the trap frame (to screen).
|
---|
2686 | * @param pTrapFrame Trap frame to print.
|
---|
2687 | */
|
---|
2688 | BS3_CMN_PROTO_STUB(void, Bs3TrapPrintFrame,(PCBS3TRAPFRAME pTrapFrame));
|
---|
2689 |
|
---|
2690 | /**
|
---|
2691 | * Sets up a long jump from a trap handler.
|
---|
2692 | *
|
---|
2693 | * The long jump will only be performed onced, but will catch any kind of trap,
|
---|
2694 | * fault, interrupt or irq.
|
---|
2695 | *
|
---|
2696 | * @retval true on the initial call.
|
---|
2697 | * @retval false on trap return.
|
---|
2698 | * @param pTrapFrame Where to store the trap information when
|
---|
2699 | * returning @c false.
|
---|
2700 | * @sa #Bs3TrapUnsetJmp
|
---|
2701 | */
|
---|
2702 | BS3_CMN_PROTO_NOSB(DECL_RETURNS_TWICE(bool),Bs3TrapSetJmp,(PBS3TRAPFRAME pTrapFrame));
|
---|
2703 |
|
---|
2704 | /**
|
---|
2705 | * Combination of #Bs3TrapSetJmp and #Bs3RegCtxRestore.
|
---|
2706 | *
|
---|
2707 | * @param pCtxRestore The context to restore.
|
---|
2708 | * @param pTrapFrame Where to store the trap information.
|
---|
2709 | */
|
---|
2710 | BS3_CMN_PROTO_STUB(void, Bs3TrapSetJmpAndRestore,(PCBS3REGCTX pCtxRestore, PBS3TRAPFRAME pTrapFrame));
|
---|
2711 |
|
---|
2712 | /**
|
---|
2713 | * Disables a previous #Bs3TrapSetJmp call.
|
---|
2714 | */
|
---|
2715 | BS3_CMN_PROTO_STUB(void, Bs3TrapUnsetJmp,(void));
|
---|
2716 |
|
---|
2717 |
|
---|
2718 | /**
|
---|
2719 | * The current test step.
|
---|
2720 | */
|
---|
2721 | extern uint16_t g_usBs3TestStep;
|
---|
2722 |
|
---|
2723 | /**
|
---|
2724 | * Equivalent to RTTestCreate + RTTestBanner.
|
---|
2725 | *
|
---|
2726 | * @param pszTest The test name.
|
---|
2727 | */
|
---|
2728 | BS3_CMN_PROTO_STUB(void, Bs3TestInit,(const char BS3_FAR *pszTest));
|
---|
2729 |
|
---|
2730 |
|
---|
2731 | /**
|
---|
2732 | * Equivalent to RTTestSummaryAndDestroy.
|
---|
2733 | */
|
---|
2734 | BS3_CMN_PROTO_STUB(void, Bs3TestTerm,(void));
|
---|
2735 |
|
---|
2736 | /**
|
---|
2737 | * Equivalent to RTTestISub.
|
---|
2738 | */
|
---|
2739 | BS3_CMN_PROTO_STUB(void, Bs3TestSub,(const char BS3_FAR *pszSubTest));
|
---|
2740 |
|
---|
2741 | /**
|
---|
2742 | * Equivalent to RTTestIFailedF.
|
---|
2743 | */
|
---|
2744 | BS3_CMN_PROTO_STUB(void, Bs3TestSubF,(const char BS3_FAR *pszFormat, ...));
|
---|
2745 |
|
---|
2746 | /**
|
---|
2747 | * Equivalent to RTTestISubV.
|
---|
2748 | */
|
---|
2749 | BS3_CMN_PROTO_STUB(void, Bs3TestSubV,(const char BS3_FAR *pszFormat, va_list va));
|
---|
2750 |
|
---|
2751 | /**
|
---|
2752 | * Equivalent to RTTestISubDone.
|
---|
2753 | */
|
---|
2754 | BS3_CMN_PROTO_STUB(void, Bs3TestSubDone,(void));
|
---|
2755 |
|
---|
2756 | /**
|
---|
2757 | * Equivalent to RTTestSubErrorCount.
|
---|
2758 | */
|
---|
2759 | BS3_CMN_PROTO_STUB(uint16_t, Bs3TestSubErrorCount,(void));
|
---|
2760 |
|
---|
2761 | /**
|
---|
2762 | * Equivalent to RTTestIPrintf with RTTESTLVL_ALWAYS.
|
---|
2763 | *
|
---|
2764 | * @param pszFormat What to print, format string. Explicit newline char.
|
---|
2765 | * @param ... String format arguments.
|
---|
2766 | */
|
---|
2767 | BS3_CMN_PROTO_STUB(void, Bs3TestPrintf,(const char BS3_FAR *pszFormat, ...));
|
---|
2768 |
|
---|
2769 | /**
|
---|
2770 | * Equivalent to RTTestIPrintfV with RTTESTLVL_ALWAYS.
|
---|
2771 | *
|
---|
2772 | * @param pszFormat What to print, format string. Explicit newline char.
|
---|
2773 | * @param va String format arguments.
|
---|
2774 | */
|
---|
2775 | BS3_CMN_PROTO_STUB(void, Bs3TestPrintfV,(const char BS3_FAR *pszFormat, va_list va));
|
---|
2776 |
|
---|
2777 | /**
|
---|
2778 | * Equivalent to RTTestIFailed.
|
---|
2779 | */
|
---|
2780 | BS3_CMN_PROTO_STUB(void, Bs3TestFailed,(const char BS3_FAR *pszMessage));
|
---|
2781 |
|
---|
2782 | /**
|
---|
2783 | * Equivalent to RTTestIFailedF.
|
---|
2784 | */
|
---|
2785 | BS3_CMN_PROTO_STUB(void, Bs3TestFailedF,(const char BS3_FAR *pszFormat, ...));
|
---|
2786 |
|
---|
2787 | /**
|
---|
2788 | * Equivalent to RTTestIFailedV.
|
---|
2789 | */
|
---|
2790 | BS3_CMN_PROTO_STUB(void, Bs3TestFailedV,(const char BS3_FAR *pszFormat, va_list va));
|
---|
2791 |
|
---|
2792 | /**
|
---|
2793 | * Equivalent to RTTestISkipped.
|
---|
2794 | *
|
---|
2795 | * @param pszWhy Optional reason why it's being skipped.
|
---|
2796 | */
|
---|
2797 | BS3_CMN_PROTO_STUB(void, Bs3TestSkipped,(const char BS3_FAR *pszWhy));
|
---|
2798 |
|
---|
2799 | /**
|
---|
2800 | * Equivalent to RTTestISkippedF.
|
---|
2801 | *
|
---|
2802 | * @param pszFormat Optional reason why it's being skipped.
|
---|
2803 | * @param ... Format arguments.
|
---|
2804 | */
|
---|
2805 | BS3_CMN_PROTO_STUB(void, Bs3TestSkippedF,(const char BS3_FAR *pszFormat, ...));
|
---|
2806 |
|
---|
2807 | /**
|
---|
2808 | * Equivalent to RTTestISkippedV.
|
---|
2809 | *
|
---|
2810 | * @param pszFormat Optional reason why it's being skipped.
|
---|
2811 | * @param va Format arguments.
|
---|
2812 | */
|
---|
2813 | BS3_CMN_PROTO_STUB(void, Bs3TestSkippedV,(const char BS3_FAR *pszFormat, va_list va));
|
---|
2814 |
|
---|
2815 | /**
|
---|
2816 | * Compares two register contexts, with PC and SP adjustments.
|
---|
2817 | *
|
---|
2818 | * Differences will be reported as test failures.
|
---|
2819 | *
|
---|
2820 | * @returns true if equal, false if not.
|
---|
2821 | * @param pActualCtx The actual register context.
|
---|
2822 | * @param pExpectedCtx Expected register context.
|
---|
2823 | * @param cbPcAdjust Program counter adjustment (applied to @a pExpectedCtx).
|
---|
2824 | * @param cbSpAdjust Stack pointer adjustment (applied to @a pExpectedCtx).
|
---|
2825 | * @param fExtraEfl Extra EFLAGS to OR into @a pExepctedCtx.
|
---|
2826 | * @param pszMode CPU mode or some other helpful text.
|
---|
2827 | * @param idTestStep Test step identifier.
|
---|
2828 | */
|
---|
2829 | BS3_CMN_PROTO_STUB(bool, Bs3TestCheckRegCtxEx,(PCBS3REGCTX pActualCtx, PCBS3REGCTX pExpectedCtx, uint16_t cbPcAdjust,
|
---|
2830 | int16_t cbSpAdjust, uint32_t fExtraEfl, const char *pszMode, uint16_t idTestStep));
|
---|
2831 |
|
---|
2832 | /**
|
---|
2833 | * Performs the testing for the given mode.
|
---|
2834 | *
|
---|
2835 | * This is called with the CPU already switch to that mode.
|
---|
2836 | *
|
---|
2837 | * @returns 0 on success or directly Bs3TestFailed calls, non-zero to indicate
|
---|
2838 | * where the test when wrong. Special value BS3TESTDOMODE_SKIPPED
|
---|
2839 | * should be returned to indicate that the test has been skipped.
|
---|
2840 | * @param bMode The current CPU mode.
|
---|
2841 | */
|
---|
2842 | typedef BS3_DECL_CALLBACK(uint8_t) FNBS3TESTDOMODE(uint8_t bMode);
|
---|
2843 | /** Pointer (far) to a test (for 32-bit and 64-bit code, will be flatten). */
|
---|
2844 | typedef FNBS3TESTDOMODE *PFNBS3TESTDOMODE;
|
---|
2845 |
|
---|
2846 | /** Special FNBS3TESTDOMODE return code for indicating a skipped mode test. */
|
---|
2847 | #define BS3TESTDOMODE_SKIPPED UINT8_MAX
|
---|
2848 |
|
---|
2849 | /**
|
---|
2850 | * Mode sub-test entry.
|
---|
2851 | *
|
---|
2852 | * This can only be passed around to functions with the same bit count, as it
|
---|
2853 | * contains function pointers. In 16-bit mode, the 16-bit pointers are near and
|
---|
2854 | * implies BS3TEXT16, whereas the 32-bit and 64-bit pointers are far real mode
|
---|
2855 | * addresses that will be converted to flat address prior to calling them.
|
---|
2856 | * Similarly, in 32-bit and 64-bit the addresses are all flat and the 16-bit
|
---|
2857 | * ones will be converted to BS3TEXT16 based addresses prior to calling.
|
---|
2858 | */
|
---|
2859 | typedef struct BS3TESTMODEENTRY
|
---|
2860 | {
|
---|
2861 | const char * BS3_FAR pszSubTest;
|
---|
2862 |
|
---|
2863 | PFNBS3TESTDOMODE pfnDoRM;
|
---|
2864 |
|
---|
2865 | PFNBS3TESTDOMODE pfnDoPE16;
|
---|
2866 | PFNBS3TESTDOMODE pfnDoPE16_32;
|
---|
2867 | PFNBS3TESTDOMODE pfnDoPE16_V86;
|
---|
2868 | PFNBS3TESTDOMODE pfnDoPE32;
|
---|
2869 | PFNBS3TESTDOMODE pfnDoPE32_16;
|
---|
2870 | PFNBS3TESTDOMODE pfnDoPEV86;
|
---|
2871 |
|
---|
2872 | PFNBS3TESTDOMODE pfnDoPP16;
|
---|
2873 | PFNBS3TESTDOMODE pfnDoPP16_32;
|
---|
2874 | PFNBS3TESTDOMODE pfnDoPP16_V86;
|
---|
2875 | PFNBS3TESTDOMODE pfnDoPP32;
|
---|
2876 | PFNBS3TESTDOMODE pfnDoPP32_16;
|
---|
2877 | PFNBS3TESTDOMODE pfnDoPPV86;
|
---|
2878 |
|
---|
2879 | PFNBS3TESTDOMODE pfnDoPAE16;
|
---|
2880 | PFNBS3TESTDOMODE pfnDoPAE16_32;
|
---|
2881 | PFNBS3TESTDOMODE pfnDoPAE16_V86;
|
---|
2882 | PFNBS3TESTDOMODE pfnDoPAE32;
|
---|
2883 | PFNBS3TESTDOMODE pfnDoPAE32_16;
|
---|
2884 | PFNBS3TESTDOMODE pfnDoPAEV86;
|
---|
2885 |
|
---|
2886 | PFNBS3TESTDOMODE pfnDoLM16;
|
---|
2887 | PFNBS3TESTDOMODE pfnDoLM32;
|
---|
2888 | PFNBS3TESTDOMODE pfnDoLM64;
|
---|
2889 |
|
---|
2890 | } BS3TESTMODEENTRY;
|
---|
2891 | /** Pointer to a mode sub-test entry. */
|
---|
2892 | typedef BS3TESTMODEENTRY const *PCBS3TESTMODEENTRY;
|
---|
2893 |
|
---|
2894 | /** @def BS3TESTMODEENTRY_CMN
|
---|
2895 | * Produces a BS3TESTMODEENTRY initializer for common (c16,c32,c64) test
|
---|
2896 | * functions. */
|
---|
2897 | #define BS3TESTMODEENTRY_CMN(a_szTest, a_BaseNm) \
|
---|
2898 | { /*pszSubTest =*/ a_szTest, \
|
---|
2899 | /*RM*/ RT_CONCAT(a_BaseNm, _c16), \
|
---|
2900 | /*PE16*/ RT_CONCAT(a_BaseNm, _c16), \
|
---|
2901 | /*PE16_32*/ RT_CONCAT(a_BaseNm, _c32), \
|
---|
2902 | /*PE16_V86*/ RT_CONCAT(a_BaseNm, _c16), \
|
---|
2903 | /*PE32*/ RT_CONCAT(a_BaseNm, _c32), \
|
---|
2904 | /*PE32_16*/ RT_CONCAT(a_BaseNm, _c16), \
|
---|
2905 | /*PEV86*/ RT_CONCAT(a_BaseNm, _c16), \
|
---|
2906 | /*PP16*/ RT_CONCAT(a_BaseNm, _c16), \
|
---|
2907 | /*PP16_32*/ RT_CONCAT(a_BaseNm, _c32), \
|
---|
2908 | /*PP16_V86*/ RT_CONCAT(a_BaseNm, _c16), \
|
---|
2909 | /*PP32*/ RT_CONCAT(a_BaseNm, _c32), \
|
---|
2910 | /*PP32_16*/ RT_CONCAT(a_BaseNm, _c16), \
|
---|
2911 | /*PPV86*/ RT_CONCAT(a_BaseNm, _c16), \
|
---|
2912 | /*PAE16*/ RT_CONCAT(a_BaseNm, _c16), \
|
---|
2913 | /*PAE16_32*/ RT_CONCAT(a_BaseNm, _c32), \
|
---|
2914 | /*PAE16_V86*/ RT_CONCAT(a_BaseNm, _c16), \
|
---|
2915 | /*PAE32*/ RT_CONCAT(a_BaseNm, _c32), \
|
---|
2916 | /*PAE32_16*/ RT_CONCAT(a_BaseNm, _c16), \
|
---|
2917 | /*PAEV86*/ RT_CONCAT(a_BaseNm, _c16), \
|
---|
2918 | /*LM16*/ RT_CONCAT(a_BaseNm, _c16), \
|
---|
2919 | /*LM32*/ RT_CONCAT(a_BaseNm, _c32), \
|
---|
2920 | /*LM64*/ RT_CONCAT(a_BaseNm, _c64), \
|
---|
2921 | }
|
---|
2922 |
|
---|
2923 | /** @def BS3TESTMODE_PROTOTYPES_CMN
|
---|
2924 | * A set of standard protypes to go with #BS3TESTMODEENTRY_CMN. */
|
---|
2925 | #define BS3TESTMODE_PROTOTYPES_CMN(a_BaseNm) \
|
---|
2926 | FNBS3TESTDOMODE BS3_FAR_CODE RT_CONCAT(a_BaseNm, _c16); \
|
---|
2927 | FNBS3TESTDOMODE BS3_FAR_CODE RT_CONCAT(a_BaseNm, _c32); \
|
---|
2928 | FNBS3TESTDOMODE BS3_FAR_CODE RT_CONCAT(a_BaseNm, _c64)
|
---|
2929 |
|
---|
2930 | /** @def BS3TESTMODEENTRY_MODE
|
---|
2931 | * Produces a BS3TESTMODEENTRY initializer for a full set of mode test
|
---|
2932 | * functions. */
|
---|
2933 | #define BS3TESTMODEENTRY_MODE(a_szTest, a_BaseNm) \
|
---|
2934 | { /*pszSubTest =*/ a_szTest, \
|
---|
2935 | /*RM*/ RT_CONCAT(a_BaseNm, _rm), \
|
---|
2936 | /*PE16*/ RT_CONCAT(a_BaseNm, _pe16), \
|
---|
2937 | /*PE16_32*/ RT_CONCAT(a_BaseNm, _pe16_32), \
|
---|
2938 | /*PE16_V86*/ RT_CONCAT(a_BaseNm, _pe16_v86), \
|
---|
2939 | /*PE32*/ RT_CONCAT(a_BaseNm, _pe32), \
|
---|
2940 | /*PE32_16*/ RT_CONCAT(a_BaseNm, _pe32_16), \
|
---|
2941 | /*PEV86*/ RT_CONCAT(a_BaseNm, _pev86), \
|
---|
2942 | /*PP16*/ RT_CONCAT(a_BaseNm, _pp16), \
|
---|
2943 | /*PP16_32*/ RT_CONCAT(a_BaseNm, _pp16_32), \
|
---|
2944 | /*PP16_V86*/ RT_CONCAT(a_BaseNm, _pp16_v86), \
|
---|
2945 | /*PP32*/ RT_CONCAT(a_BaseNm, _pp32), \
|
---|
2946 | /*PP32_16*/ RT_CONCAT(a_BaseNm, _pp32_16), \
|
---|
2947 | /*PPV86*/ RT_CONCAT(a_BaseNm, _ppv86), \
|
---|
2948 | /*PAE16*/ RT_CONCAT(a_BaseNm, _pae16), \
|
---|
2949 | /*PAE16_32*/ RT_CONCAT(a_BaseNm, _pae16_32), \
|
---|
2950 | /*PAE16_V86*/ RT_CONCAT(a_BaseNm, _pae16_v86), \
|
---|
2951 | /*PAE32*/ RT_CONCAT(a_BaseNm, _pae32), \
|
---|
2952 | /*PAE32_16*/ RT_CONCAT(a_BaseNm, _pae32_16), \
|
---|
2953 | /*PAEV86*/ RT_CONCAT(a_BaseNm, _paev86), \
|
---|
2954 | /*LM16*/ RT_CONCAT(a_BaseNm, _lm16), \
|
---|
2955 | /*LM32*/ RT_CONCAT(a_BaseNm, _lm32), \
|
---|
2956 | /*LM64*/ RT_CONCAT(a_BaseNm, _lm64), \
|
---|
2957 | }
|
---|
2958 |
|
---|
2959 | /** @def BS3TESTMODE_PROTOTYPES_MODE
|
---|
2960 | * A set of standard protypes to go with #BS3TESTMODEENTRY_MODE. */
|
---|
2961 | #define BS3TESTMODE_PROTOTYPES_MODE(a_BaseNm) \
|
---|
2962 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _rm); \
|
---|
2963 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe16); \
|
---|
2964 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe16_32); \
|
---|
2965 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe16_v86); \
|
---|
2966 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe32); \
|
---|
2967 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pe32_16); \
|
---|
2968 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pev86); \
|
---|
2969 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp16); \
|
---|
2970 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp16_32); \
|
---|
2971 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp16_v86); \
|
---|
2972 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp32); \
|
---|
2973 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pp32_16); \
|
---|
2974 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _ppv86); \
|
---|
2975 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae16); \
|
---|
2976 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae16_32); \
|
---|
2977 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae16_v86); \
|
---|
2978 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae32); \
|
---|
2979 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _pae32_16); \
|
---|
2980 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _paev86); \
|
---|
2981 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _lm16); \
|
---|
2982 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _lm32); \
|
---|
2983 | FNBS3TESTDOMODE RT_CONCAT(a_BaseNm, _lm64)
|
---|
2984 |
|
---|
2985 |
|
---|
2986 | /**
|
---|
2987 | * One worker drives all modes.
|
---|
2988 | *
|
---|
2989 | * This is an alternative to BS3TESTMODEENTRY where one worker, typically
|
---|
2990 | * 16-bit, does all the test driver work. It's called repeatedly from all
|
---|
2991 | * the modes being tested.
|
---|
2992 | */
|
---|
2993 | typedef struct BS3TESTMODEBYONEENTRY
|
---|
2994 | {
|
---|
2995 | const char * BS3_FAR pszSubTest;
|
---|
2996 | PFNBS3TESTDOMODE pfnWorker;
|
---|
2997 | uint32_t u32Reserved;
|
---|
2998 | } BS3TESTMODEBYONEENTRY;
|
---|
2999 | /** Pointer to a mode-by-one sub-test entry. */
|
---|
3000 | typedef BS3TESTMODEBYONEENTRY const *PCBS3TESTMODEBYONEENTRY;
|
---|
3001 |
|
---|
3002 |
|
---|
3003 | /**
|
---|
3004 | * Sets the full GDTR register.
|
---|
3005 | *
|
---|
3006 | * @param cbLimit The limit.
|
---|
3007 | * @param uBase The base address - 24, 32 or 64 bit depending on the
|
---|
3008 | * CPU mode.
|
---|
3009 | */
|
---|
3010 | BS3_CMN_PROTO_NOSB(void, Bs3UtilSetFullGdtr,(uint16_t cbLimit, uint64_t uBase));
|
---|
3011 |
|
---|
3012 | /**
|
---|
3013 | * Sets the full IDTR register.
|
---|
3014 | *
|
---|
3015 | * @param cbLimit The limit.
|
---|
3016 | * @param uBase The base address - 24, 32 or 64 bit depending on the
|
---|
3017 | * CPU mode.
|
---|
3018 | */
|
---|
3019 | BS3_CMN_PROTO_NOSB(void, Bs3UtilSetFullIdtr,(uint16_t cbLimit, uint64_t uBase));
|
---|
3020 |
|
---|
3021 |
|
---|
3022 | /** @} */
|
---|
3023 |
|
---|
3024 |
|
---|
3025 | /**
|
---|
3026 | * Initializes all of boot sector kit \#3.
|
---|
3027 | */
|
---|
3028 | BS3_DECL(void) Bs3InitAll_rm(void);
|
---|
3029 |
|
---|
3030 | /**
|
---|
3031 | * Initializes the REAL and TILED memory pools.
|
---|
3032 | *
|
---|
3033 | * For proper operation on OLDer CPUs, call #Bs3CpuDetect_mmm first.
|
---|
3034 | */
|
---|
3035 | BS3_DECL_FAR(void) Bs3InitMemory_rm_far(void);
|
---|
3036 |
|
---|
3037 | /**
|
---|
3038 | * Initialized the X0TEXT16 and X1TEXT16 GDT entries.
|
---|
3039 | */
|
---|
3040 | BS3_DECL_FAR(void) Bs3InitGdt_rm_far(void);
|
---|
3041 |
|
---|
3042 |
|
---|
3043 |
|
---|
3044 | /** @defgroup grp_bs3kit_mode Mode Specific Functions and Data
|
---|
3045 | *
|
---|
3046 | * The mode specific functions come in bit count variations and CPU mode
|
---|
3047 | * variations. The bs3kit-template-header.h/mac defines the BS3_NM macro to
|
---|
3048 | * mangle a function or variable name according to the target CPU mode. In
|
---|
3049 | * non-templated code, it's common to spell the name out in full.
|
---|
3050 | *
|
---|
3051 | * @{
|
---|
3052 | */
|
---|
3053 |
|
---|
3054 |
|
---|
3055 | /** @def BS3_MODE_PROTO_INT
|
---|
3056 | * Internal macro for emitting prototypes for mode functions.
|
---|
3057 | *
|
---|
3058 | * @param a_RetType The return type.
|
---|
3059 | * @param a_Name The function basename.
|
---|
3060 | * @param a_Params The parameter list (in parentheses).
|
---|
3061 | * @sa BS3_MODE_PROTO_STUB, BS3_MODE_PROTO_NOSB
|
---|
3062 | */
|
---|
3063 | #define BS3_MODE_PROTO_INT(a_RetType, a_Name, a_Params) \
|
---|
3064 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_rm) a_Params; \
|
---|
3065 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe16) a_Params; \
|
---|
3066 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe16_32) a_Params; \
|
---|
3067 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe16_v86) a_Params; \
|
---|
3068 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe32) a_Params; \
|
---|
3069 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe32_16) a_Params; \
|
---|
3070 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pev86) a_Params; \
|
---|
3071 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp16) a_Params; \
|
---|
3072 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp16_32) a_Params; \
|
---|
3073 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp16_v86) a_Params; \
|
---|
3074 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp32) a_Params; \
|
---|
3075 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp32_16) a_Params; \
|
---|
3076 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_ppv86) a_Params; \
|
---|
3077 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae16) a_Params; \
|
---|
3078 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae16_32) a_Params; \
|
---|
3079 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae16_v86) a_Params; \
|
---|
3080 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae32) a_Params; \
|
---|
3081 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae32_16) a_Params; \
|
---|
3082 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_paev86) a_Params; \
|
---|
3083 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_lm16) a_Params; \
|
---|
3084 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_lm32) a_Params; \
|
---|
3085 | BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_lm64) a_Params; \
|
---|
3086 | BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_rm_far) a_Params; \
|
---|
3087 | BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pe16_far) a_Params; \
|
---|
3088 | BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pe16_v86_far) a_Params; \
|
---|
3089 | BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pe32_16_far) a_Params; \
|
---|
3090 | BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pev86_far) a_Params; \
|
---|
3091 | BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pp16_far) a_Params; \
|
---|
3092 | BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pp16_v86_far) a_Params; \
|
---|
3093 | BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pp32_16_far) a_Params; \
|
---|
3094 | BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_ppv86_far) a_Params; \
|
---|
3095 | BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pae16_far) a_Params; \
|
---|
3096 | BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pae16_v86_far)a_Params; \
|
---|
3097 | BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_pae32_16_far) a_Params; \
|
---|
3098 | BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_paev86_far) a_Params; \
|
---|
3099 | BS3_DECL_FAR(a_RetType) RT_CONCAT(a_Name,_lm16_far) a_Params
|
---|
3100 |
|
---|
3101 | /** @def BS3_MODE_PROTO_STUB
|
---|
3102 | * Macro for prototyping all the variations of a mod function with automatic
|
---|
3103 | * near -> far stub.
|
---|
3104 | *
|
---|
3105 | * @param a_RetType The return type.
|
---|
3106 | * @param a_Name The function basename.
|
---|
3107 | * @param a_Params The parameter list (in parentheses).
|
---|
3108 | * @sa BS3_MODE_PROTO_STUB, BS3_MODE_PROTO_NOSB
|
---|
3109 | */
|
---|
3110 | #define BS3_MODE_PROTO_STUB(a_RetType, a_Name, a_Params) BS3_MODE_PROTO_INT(a_RetType, a_Name, a_Params)
|
---|
3111 |
|
---|
3112 | /** @def BS3_MODE_PROTO_STUB
|
---|
3113 | * Macro for prototyping all the variations of a mod function without any
|
---|
3114 | * near -> far stub.
|
---|
3115 | *
|
---|
3116 | * @param a_RetType The return type.
|
---|
3117 | * @param a_Name The function basename.
|
---|
3118 | * @param a_Params The parameter list (in parentheses).
|
---|
3119 | * @sa BS3_MODE_PROTO_STUB, BS3_MODE_PROTO_NOSB
|
---|
3120 | */
|
---|
3121 | #define BS3_MODE_PROTO_NOSB(a_RetType, a_Name, a_Params) BS3_MODE_PROTO_INT(a_RetType, a_Name, a_Params)
|
---|
3122 |
|
---|
3123 |
|
---|
3124 | /**
|
---|
3125 | * Macro for reducing typing.
|
---|
3126 | *
|
---|
3127 | * Doxygen knows how to expand this, well, kind of.
|
---|
3128 | *
|
---|
3129 | * @remarks Variables instantiated in assembly code should define two labels,
|
---|
3130 | * with and without leading underscore. Variables instantiated from
|
---|
3131 | * C/C++ code doesn't need to as the object file convert does this for
|
---|
3132 | * 64-bit object files.
|
---|
3133 | */
|
---|
3134 | #define BS3_MODE_EXPAND_EXTERN_DATA16(a_VarType, a_VarName, a_Suffix) \
|
---|
3135 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_rm) a_Suffix; \
|
---|
3136 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pe16) a_Suffix; \
|
---|
3137 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pe16_32) a_Suffix; \
|
---|
3138 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pe16_v86) a_Suffix; \
|
---|
3139 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pe32) a_Suffix; \
|
---|
3140 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pe32_16) a_Suffix; \
|
---|
3141 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pev86) a_Suffix; \
|
---|
3142 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pp16) a_Suffix; \
|
---|
3143 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pp16_32) a_Suffix; \
|
---|
3144 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pp16_v86) a_Suffix; \
|
---|
3145 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pp32) a_Suffix; \
|
---|
3146 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pp32_16) a_Suffix; \
|
---|
3147 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_ppv86) a_Suffix; \
|
---|
3148 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pae16) a_Suffix; \
|
---|
3149 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pae16_32) a_Suffix; \
|
---|
3150 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pae16_v86)a_Suffix; \
|
---|
3151 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pae32) a_Suffix; \
|
---|
3152 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_pae32_16) a_Suffix; \
|
---|
3153 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_paev86) a_Suffix; \
|
---|
3154 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_lm16) a_Suffix; \
|
---|
3155 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_lm32) a_Suffix; \
|
---|
3156 | extern a_VarType BS3_FAR_DATA RT_CONCAT(a_VarName,_lm64) a_Suffix
|
---|
3157 |
|
---|
3158 |
|
---|
3159 | /** The TMPL_MODE_STR value for each mode.
|
---|
3160 | * These are all in DATA16 so they can be accessed from any code. */
|
---|
3161 | BS3_MODE_EXPAND_EXTERN_DATA16(const char, g_szBs3ModeName, []);
|
---|
3162 |
|
---|
3163 | /**
|
---|
3164 | * Basic CPU detection.
|
---|
3165 | *
|
---|
3166 | * This sets the #g_bBs3CpuDetected global variable to the return value.
|
---|
3167 | *
|
---|
3168 | * @returns BS3CPU_XXX value with the BS3CPU_F_CPUID flag set depending on
|
---|
3169 | * capabilities.
|
---|
3170 | */
|
---|
3171 | BS3_MODE_PROTO_NOSB(uint8_t, Bs3CpuDetect,(void));
|
---|
3172 |
|
---|
3173 | /** @name BS3CPU_XXX - CPU detected by BS3CpuDetect_c16() and friends.
|
---|
3174 | * @{ */
|
---|
3175 | #define BS3CPU_8086 UINT16_C(0x0001) /**< Both 8086 and 8088. */
|
---|
3176 | #define BS3CPU_V20 UINT16_C(0x0002) /**< Both NEC V20, V30 and relatives. */
|
---|
3177 | #define BS3CPU_80186 UINT16_C(0x0003) /**< Both 80186 and 80188. */
|
---|
3178 | #define BS3CPU_80286 UINT16_C(0x0004)
|
---|
3179 | #define BS3CPU_80386 UINT16_C(0x0005)
|
---|
3180 | #define BS3CPU_80486 UINT16_C(0x0006)
|
---|
3181 | #define BS3CPU_Pentium UINT16_C(0x0007)
|
---|
3182 | #define BS3CPU_PPro UINT16_C(0x0008)
|
---|
3183 | #define BS3CPU_PProOrNewer UINT16_C(0x0009)
|
---|
3184 | /** CPU type mask. This is a full byte so it's possible to use byte access
|
---|
3185 | * without and AND'ing to get the type value. */
|
---|
3186 | #define BS3CPU_TYPE_MASK UINT16_C(0x00ff)
|
---|
3187 | /** Flag indicating that the CPUID instruction is supported by the CPU. */
|
---|
3188 | #define BS3CPU_F_CPUID UINT16_C(0x0100)
|
---|
3189 | /** Flag indicating that extend CPUID leaves are available (at least two). */
|
---|
3190 | #define BS3CPU_F_CPUID_EXT_LEAVES UINT16_C(0x0200)
|
---|
3191 | /** Flag indicating that the CPU supports PAE. */
|
---|
3192 | #define BS3CPU_F_PAE UINT16_C(0x0400)
|
---|
3193 | /** Flag indicating that the CPU supports the page size extension (4MB pages). */
|
---|
3194 | #define BS3CPU_F_PSE UINT16_C(0x0800)
|
---|
3195 | /** Flag indicating that the CPU supports long mode. */
|
---|
3196 | #define BS3CPU_F_LONG_MODE UINT16_C(0x1000)
|
---|
3197 | /** @} */
|
---|
3198 |
|
---|
3199 | /** The return value of #Bs3CpuDetect_mmm. (Initial value is BS3CPU_TYPE_MASK.) */
|
---|
3200 | extern uint16_t g_uBs3CpuDetected;
|
---|
3201 |
|
---|
3202 | /**
|
---|
3203 | * Initializes trap handling for the current system.
|
---|
3204 | *
|
---|
3205 | * Calls the appropriate Bs3Trap16Init, Bs3Trap32Init or Bs3Trap64Init function.
|
---|
3206 | */
|
---|
3207 | BS3_MODE_PROTO_STUB(void, Bs3TrapInit,(void));
|
---|
3208 |
|
---|
3209 | /**
|
---|
3210 | * Executes the array of tests in every possibly mode.
|
---|
3211 | *
|
---|
3212 | * @param paEntries The mode sub-test entries.
|
---|
3213 | * @param cEntries The number of sub-test entries.
|
---|
3214 | */
|
---|
3215 | BS3_MODE_PROTO_NOSB(void, Bs3TestDoModes,(PCBS3TESTMODEENTRY paEntries, size_t cEntries));
|
---|
3216 |
|
---|
3217 | /**
|
---|
3218 | * Executes the array of tests in every possibly mode, unitifed driver.
|
---|
3219 | *
|
---|
3220 | * This requires much less code space than Bs3TestDoModes as there is only one
|
---|
3221 | * instace of each sub-test driver code, instead of 3 (cmn) or 22 (per-mode)
|
---|
3222 | * copies.
|
---|
3223 | *
|
---|
3224 | * @param paEntries The mode sub-test-by-one entries.
|
---|
3225 | * @param cEntries The number of sub-test-by-one entries.
|
---|
3226 | * @param fFlags Reserved for the future, MBZ.
|
---|
3227 | */
|
---|
3228 | BS3_MODE_PROTO_NOSB(void, Bs3TestDoModesByOne,(PCBS3TESTMODEBYONEENTRY paEntries, size_t cEntries, uint32_t fFlags));
|
---|
3229 |
|
---|
3230 |
|
---|
3231 | /** @} */
|
---|
3232 |
|
---|
3233 | RT_C_DECLS_END
|
---|
3234 |
|
---|
3235 |
|
---|
3236 | /*
|
---|
3237 | * Include default function symbol mangling.
|
---|
3238 | */
|
---|
3239 | #include "bs3kit-mangling-code.h"
|
---|
3240 |
|
---|
3241 | /*
|
---|
3242 | * Change 16-bit text segment if requested.
|
---|
3243 | */
|
---|
3244 | #if defined(BS3_USE_ALT_16BIT_TEXT_SEG) && ARCH_BITS == 16 && !defined(BS3_DONT_CHANGE_TEXT_SEG)
|
---|
3245 | # if (defined(BS3_USE_RM_TEXT_SEG) + defined(BS3_USE_X0_TEXT_SEG) + defined(BS3_USE_X1_TEXT_SEG)) != 1
|
---|
3246 | # error "Cannot set more than one alternative 16-bit text segment!"
|
---|
3247 | # elif defined(BS3_USE_RM_TEXT_SEG)
|
---|
3248 | # pragma code_seg("BS3RMTEXT16", "BS3CLASS16RMCODE")
|
---|
3249 | # elif defined(BS3_USE_X0_TEXT_SEG)
|
---|
3250 | # pragma code_seg("BS3X0TEXT16", "BS3CLASS16X0CODE")
|
---|
3251 | # elif defined(BS3_USE_X1_TEXT_SEG)
|
---|
3252 | # pragma code_seg("BS3X1TEXT16", "BS3CLASS16X1CODE")
|
---|
3253 | # else
|
---|
3254 | # error "Huh? Which alternative text segment did you want again?"
|
---|
3255 | # endif
|
---|
3256 | #endif
|
---|
3257 |
|
---|
3258 | #endif
|
---|
3259 |
|
---|