VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac@ 99443

Last change on this file since 99443 was 99443, checked in by vboxsync, 20 months ago

ValidationKit/bs3kit: Fix single-line macro definition to work with more recent nasm versions, bugref:8551

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 65.6 KB
Line 
1; $Id: bs3kit.mac 99443 2023-04-18 13:33:20Z vboxsync $
2;; @file
3; BS3Kit - structures, symbols, macros and stuff.
4;
5
6;
7; Copyright (C) 2007-2023 Oracle and/or its affiliates.
8;
9; This file is part of VirtualBox base platform packages, as
10; available from https://www.virtualbox.org.
11;
12; This program is free software; you can redistribute it and/or
13; modify it under the terms of the GNU General Public License
14; as published by the Free Software Foundation, in version 3 of the
15; License.
16;
17; This program is distributed in the hope that it will be useful, but
18; WITHOUT ANY WARRANTY; without even the implied warranty of
19; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20; General Public License for more details.
21;
22; You should have received a copy of the GNU General Public License
23; along with this program; if not, see <https://www.gnu.org/licenses>.
24;
25; The contents of this file may alternatively be used under the terms
26; of the Common Development and Distribution License Version 1.0
27; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28; in the VirtualBox distribution, in which case the provisions of the
29; CDDL are applicable instead of those of the GPL.
30;
31; You may elect to license modified versions of this file under the
32; terms and conditions of either the GPL or the CDDL or both.
33;
34; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35;
36
37%ifndef ___bs3kit_mac___
38%define ___bs3kit_mac___
39
40;
41; Before we can include anything, we need to override NAME and switch section.
42; If we don't do the latter we end up with an unused 'text' section.
43;
44
45; Drop the asmdefs-first.mac header for native bs3kit files.
46%undef RT_ASMDEFS_INC_FIRST_FILE
47
48;;
49; Macro for setting register aliases according to the bit count given by %1.
50;
51%macro BS3_SET_REG_ALIASES 1
52 ;
53 ; Register aliases.
54 ;
55 %if %1 == 64
56 %define xCB 8
57 %define xDEF dq
58 %define xRES resq
59 %define xPRE qword
60 %define xSP rsp
61 %define xBP rbp
62 %define xAX rax
63 %define xBX rbx
64 %define xCX rcx
65 %define xDX rdx
66 %define xDI rdi
67 %define xSI rsi
68 %define xWrtRIP wrt rip
69 %define xPUSHF pushfq
70 %define xPOPF popfq
71 %define xRETF o64 retf
72 %elif %1 == 32
73 %define xCB 4
74 %define xDEF dd
75 %define xRES resd
76 %define xPRE dword
77 %define xSP esp
78 %define xBP ebp
79 %define xAX eax
80 %define xBX ebx
81 %define xCX ecx
82 %define xDX edx
83 %define xDI edi
84 %define xSI esi
85 %define xWrtRIP
86 %define xPUSHF pushfd
87 %define xPOPF popfd
88 %define xRETF retf
89 %elif %1 == 16
90 %define xCB 2
91 %define xDEF dw
92 %define xRES resw
93 %define xPRE word
94 %define xSP sp
95 %define xBP bp
96 %define xAX ax
97 %define xBX bx
98 %define xCX cx
99 %define xDX dx
100 %define xDI di
101 %define xSI si
102 %define xWrtRIP
103 %define xPUSHF pushf
104 %define xPOPF popf
105 %define xRETF retf
106 %else
107 %error "Invalid BS3_SET_REG_ALIASES argument:" %1
108 %endif
109
110
111 ;
112 ; Register names corresponding to the max size for pop/push <reg>.
113 ;
114 ; 16-bit can push both 32-bit and 16-bit registers. This 's' prefixed variant
115 ; is used when 16-bit should use the 32-bit register.
116 ;
117 %if %1 == 64
118 %define sCB 8
119 %define sDEF dq
120 %define sRES resq
121 %define sPRE qword
122 %define sSP rsp
123 %define sBP rbp
124 %define sAX rax
125 %define sBX rbx
126 %define sCX rcx
127 %define sDX rdx
128 %define sDI rdi
129 %define sSI rsi
130 %define sPUSHF pushfq
131 %define sPOPF popfq
132 %else
133 %define sCB 4
134 %define sDEF dd
135 %define sRES resd
136 %define sPRE dword
137 %define sSP esp
138 %define sBP ebp
139 %define sAX eax
140 %define sBX ebx
141 %define sCX ecx
142 %define sDX edx
143 %define sDI edi
144 %define sSI esi
145 %define sPUSHF pushfd
146 %define sPOPF popfd
147 %endif
148%endmacro
149
150;;
151; Redefines macros that follows __BITS__.
152%macro BS3_SET_BITS_MACROS 1
153 ;; Emulate the __BITS__ macro in NASM 2.0+. Follows BS3_SET_BITS.
154 %ifdef __YASM__
155 %undef __BITS__
156 %define __BITS__ %1
157 %endif
158
159 ;; Mostly internal macro. Follows BS3_SET_BITS.
160 %undef BS3_NAME_UNDERSCORE
161 %define BS3_NAME_UNDERSCORE _
162
163 ;; For segment overrides and stuff. Follows BS3_SET_BITS.
164 %undef BS3_ONLY_16BIT
165 %if %1 == 16
166 %define BS3_ONLY_16BIT(a_Expr) a_Expr
167 %else
168 %define BS3_ONLY_16BIT(a_Expr)
169 %endif
170
171 ;; For odd 64-bit stuff. Follows BS3_SET_BITS.
172 %undef BS3_ONLY_64BIT
173 %if %1 == 64
174 %define BS3_ONLY_64BIT(a_Expr) a_Expr
175 %else
176 %define BS3_ONLY_64BIT(a_Expr)
177 %endif
178
179 ;; For segment overrides and stuff. Follows BS3_SET_BITS.
180 %undef BS3_NOT_64BIT
181 %if %1 == 64
182 %define BS3_NOT_64BIT(a_Expr)
183 %else
184 %define BS3_NOT_64BIT(a_Expr) a_Expr
185 %endif
186
187 ;; For stack cleanups and similar where each bit mode is different. Follows BS3_SET_BITS.
188 %undef BS3_IF_16_32_64BIT
189 %if %1 == 16
190 %define BS3_IF_16_32_64BIT(a_16BitExpr, a_32BitExpr, a_64BitExpr) a_16BitExpr
191 %elif %1 == 32
192 %define BS3_IF_16_32_64BIT(a_16BitExpr, a_32BitExpr, a_64BitExpr) a_32BitExpr
193 %else
194 %define BS3_IF_16_32_64BIT(a_16BitExpr, a_32BitExpr, a_64BitExpr) a_64BitExpr
195 %endif
196
197 ;; For RIP relative addressing in 64-bit mode and absolute addressing in
198 ; other modes. Follows BS3_SET_BITS.
199 %undef BS3_WRT_RIP
200 %if %1 == 64
201 %define BS3_WRT_RIP(a_Sym) rel a_Sym
202 %else
203 %define BS3_WRT_RIP(a_Sym) a_Sym
204 %endif
205
206 %undef BS3_LEA_MOV_WRT_RIP
207 %if %1 == 64
208 %define BS3_LEA_MOV_WRT_RIP(a_DstReg, a_Sym) lea a_DstReg, [BS3_WRT_RIP(a_Sym)]
209 %else
210 %define BS3_LEA_MOV_WRT_RIP(a_DstReg, a_Sym) mov a_DstReg, a_Sym
211 %endif
212
213 ;; @def BS3_DATA16_WRT
214 ; For accessing BS3DATA16 correctly.
215 ; @param a_Var The BS3DATA16 variable.
216 %undef BS3_DATA16_WRT
217 %if %1 == 16
218 %define BS3_DATA16_WRT(a_Var) a_Var wrt BS3KIT_GRPNM_DATA16
219 %elif %1 == 32
220 %define BS3_DATA16_WRT(a_Var) a_Var wrt FLAT
221 %else
222 %define BS3_DATA16_WRT(a_Var) BS3_WRT_RIP(a_Var) wrt FLAT
223 %endif
224
225 ;; @def BS3_TEXT16_WRT
226 ; For accessing BS3DATA16 correctly.
227 ; @param a_Label The BS3TEXT16 label.
228 %undef BS3_TEXT16_WRT
229 %if %1 == 16
230 %define BS3_TEXT16_WRT(a_Label) a_Label wrt CGROUP16
231 %elif %1 == 32
232 %define BS3_TEXT16_WRT(a_Label) a_Label wrt FLAT
233 %else
234 %define BS3_TEXT16_WRT(a_Label) BS3_WRT_RIP(a_Label) wrt FLAT
235 %endif
236
237 %undef BS3_IF_16BIT_OTHERWISE
238 %if %1 == 16
239 %define BS3_IF_16BIT_OTHERWISE(a_16BitExpr, a_OtherwiseExpr) a_16BitExpr
240 %else
241 %define BS3_IF_16BIT_OTHERWISE(a_16BitExpr, a_OtherwiseExpr) a_OtherwiseExpr
242 %endif
243
244 %undef BS3_IF_32BIT_OTHERWISE
245 %if %1 == 32
246 %define BS3_IF_32BIT_OTHERWISE(a_32BitExpr, a_OtherwiseExpr) a_32BitExpr
247 %else
248 %define BS3_IF_32BIT_OTHERWISE(a_32BitExpr, a_OtherwiseExpr) a_OtherwiseExpr
249 %endif
250
251 %undef BS3_IF_64BIT_OTHERWISE
252 %if %1 == 64
253 %define BS3_IF_64BIT_OTHERWISE(a_64BitExpr, a_OtherwiseExpr) a_64BitExpr
254 %else
255 %define BS3_IF_64BIT_OTHERWISE(a_64BitExpr, a_OtherwiseExpr) a_OtherwiseExpr
256 %endif
257
258 ;;
259 ; Same as BS3_CMN_NM except in 16-bit mode, it will generate the far name.
260 ; (16-bit code generally have both near and far callable symbols, so we won't
261 ; be restricted to 64KB test code.)
262 %if %1 == 16
263 %define BS3_CMN_NM_FAR(a_Name) BS3_NAME_UNDERSCORE %+ a_Name %+ _f %+ __BITS__
264 %else
265 %define BS3_CMN_NM_FAR(a_Name) BS3_CMN_NM(a_Name)
266 %endif
267
268%endmacro
269
270; Default to register aliases for ARCH_BITS.
271BS3_SET_REG_ALIASES ARCH_BITS
272
273; Define macros for ARCH_BITS.
274BS3_SET_BITS_MACROS ARCH_BITS
275
276
277;; Wrapper around BITS.
278; Updates __BITS__ (built-in variable in nasm, we work it for yasm) as well
279; a number of convenient macros and register aliases.
280;
281; @param %1 The CPU bit count: 16, 32 or 64
282; @remarks ARCH_BITS is not modified and will remain what it was on the
283; assembler command line.
284%macro BS3_SET_BITS 1
285 BITS %1
286 BS3_SET_BITS_MACROS %1
287 BS3_SET_REG_ALIASES %1
288%endmacro
289
290;;
291; For instruction that should only be emitted in 16-bit mode. Follows BS3_SET_BITS.
292; BONLY16 normally goes in column 1.
293%macro BONLY16 1+
294 %if __BITS__ == 16
295 %1
296 %endif
297%endmacro
298
299;;
300; For instruction that should only be emitted in 32-bit mode. Follows BS3_SET_BITS.
301; BONLY32 normally goes in column 1.
302%macro BONLY32 1+
303 %if __BITS__ == 32
304 %1
305 %endif
306%endmacro
307
308;;
309; For instruction that should only be emitted in 64-bit mode. Follows BS3_SET_BITS.
310; BONLY64 normally goes in column 1.
311%macro BONLY64 1+
312 %if __BITS__ == 64
313 %1
314 %endif
315%endmacro
316
317
318
319;; @name Segment definitions.
320;; @{
321
322%ifndef ASM_FORMAT_BIN
323; !!HACK ALERT!!
324;
325; To make FLAT actually be flat, i.e. have a base of 0 rather than the same as
326; the target (?) segment, we tweak it a little bit here. We associate a segment
327; with it so that we can get at it in the class/segment ordering directives
328; we pass to the linker. The segment does not contain any data or anything, it
329; is just an empty one which we assign the address of zero.
330;
331; Look for 'clname BS3FLAT segaddr=0x0000' and 'segment BS3FLAT segaddr=0x0000'
332; in the makefile.
333;
334; !!HACK ALERT!!
335segment BS3FLAT use32 class=BS3FLAT
336GROUP FLAT BS3FLAT
337%endif
338
339
340;;
341; Changes to the BS3TEXT16 segment, defining it if necessary.
342; @param %1 The bitcount to invoke BS3_SET_BITS with, default is 16.
343%macro BS3_BEGIN_TEXT16 0-1 16
344 %ifndef BS3_BEGIN_TEXT16_NOT_FIRST
345 %define BS3_BEGIN_TEXT16_NOT_FIRST
346 section BS3TEXT16 align=2 CLASS=BS3CLASS16CODE PUBLIC USE16
347 %ifndef BS3_BEGIN_TEXT16_WITHOUT_GROUP ; bs3-first-common.mac trick.
348 %ifndef BS3_BEGIN_TEXT16_NEARSTUBS_NOT_FIRST
349 %define BS3_BEGIN_TEXT16_NEARSTUBS_NOT_FIRST
350 section BS3TEXT16_NEARSTUBS align=1 CLASS=BS3CLASS16CODE PUBLIC USE16
351 %endif
352 %ifndef BS3_BEGIN_TEXT16_FARSTUBS_NOT_FIRST
353 %define BS3_BEGIN_TEXT16_FARSTUBS_NOT_FIRST
354 section BS3TEXT16_FARSTUBS align=1 CLASS=BS3CLASS16CODE PUBLIC USE16
355 %endif
356 GROUP CGROUP16 BS3TEXT16 BS3TEXT16_NEARSTUBS BS3TEXT16_FARSTUBS
357 section BS3TEXT16
358 %endif
359 %else
360 section BS3TEXT16
361 %endif
362 %undef BS3_CUR_SEG_BEGIN_MACRO
363 %xdefine BS3_CUR_SEG_BEGIN_MACRO BS3_BEGIN_TEXT16
364 BS3_SET_BITS %1
365%endmacro
366
367%macro BS3_BEGIN_TEXT16_NEARSTUBS 0
368 %ifndef BS3_BEGIN_TEXT16_NEARSTUBS_NOT_FIRST
369 %define BS3_BEGIN_TEXT16_NEARSTUBS_NOT_FIRST
370 section BS3TEXT16_NEARSTUBS align=1 CLASS=BS3CLASS16CODE PUBLIC USE16
371 %else
372 section BS3TEXT16_NEARSTUBS
373 %endif
374 %undef BS3_CUR_SEG_BEGIN_MACRO
375 %xdefine BS3_CUR_SEG_BEGIN_MACRO BS3_BEGIN_TEXT16_NEARSTUBS
376 BS3_SET_BITS 16
377%endmacro
378
379%macro BS3_BEGIN_TEXT16_FARSTUBS 0
380 %ifndef BS3_BEGIN_TEXT16_FARSTUBS_NOT_FIRST
381 %define BS3_BEGIN_TEXT16_FARSTUBS_NOT_FIRST
382 section BS3TEXT16_FARSTUBS align=1 CLASS=BS3CLASS16CODE PUBLIC USE16
383 %else
384 section BS3TEXT16_FARSTUBS
385 %endif
386 %undef BS3_CUR_SEG_BEGIN_MACRO
387 %xdefine BS3_CUR_SEG_BEGIN_MACRO BS3_BEGIN_TEXT16_FARSTUBS
388 BS3_SET_BITS 16
389%endmacro
390
391%macro BS3_BEGIN_RMTEXT16 0-1 2
392 %ifndef BS3_BEGIN_RMTEXT16_NOT_FIRST
393 %define BS3_BEGIN_RMTEXT16_NOT_FIRST
394 section BS3RMTEXT16 align=%1 CLASS=BS3CLASS16RMCODE PUBLIC USE16
395 %ifndef BS3_BEGIN_RMTEXT16_WITHOUT_GROUP ; bs3-first-common.mac trick.
396 GROUP BS3GROUPRMTEXT16 BS3RMTEXT16
397 %endif
398 %else
399 section BS3RMTEXT16
400 %endif
401 %undef BS3_CUR_SEG_BEGIN_MACRO
402 %xdefine BS3_CUR_SEG_BEGIN_MACRO BS3_BEGIN_RMTEXT16
403 BS3_SET_BITS 16
404%endmacro
405
406%macro BS3_BEGIN_X0TEXT16 0-1 2
407 %ifndef BS3_BEGIN_X0TEXT16_NOT_FIRST
408 %define BS3_BEGIN_X0TEXT16_NOT_FIRST
409 section BS3X0TEXT16 align=%1 CLASS=BS3CLASS16X0CODE PUBLIC USE16
410 %ifndef BS3_BEGIN_X0TEXT16_WITHOUT_GROUP ; bs3-first-common.mac trick.
411 GROUP BS3GROUPX0TEXT16 BS3X0TEXT16
412 %endif
413 %else
414 section BS3X0TEXT16
415 %endif
416 %undef BS3_CUR_SEG_BEGIN_MACRO
417 %xdefine BS3_CUR_SEG_BEGIN_MACRO BS3_BEGIN_X0TEXT16
418 BS3_SET_BITS 16
419%endmacro
420
421%macro BS3_BEGIN_X1TEXT16 0-1 2
422 %ifndef BS3_BEGIN_X1TEXT16_NOT_FIRST
423 %define BS3_BEGIN_X1TEXT16_NOT_FIRST
424 section BS3X1TEXT16 align=%1 CLASS=BS3CLASS16X1CODE PUBLIC USE16
425 %ifndef BS3_BEGIN_X1TEXT16_WITHOUT_GROUP ; bs3-first-common.mac trick.
426 GROUP BS3GROUPX1TEXT16 BS3X1TEXT16
427 %endif
428 %else
429 section BS3X1TEXT16
430 %endif
431 %undef BS3_CUR_SEG_BEGIN_MACRO
432 %xdefine BS3_CUR_SEG_BEGIN_MACRO BS3_BEGIN_X1TEXT16
433 BS3_SET_BITS 16
434%endmacro
435
436
437%macro BS3_BEGIN_DATA16 0-1 2
438 %ifndef BS3_BEGIN_DATA16_NOT_FIRST
439 %define BS3_BEGIN_DATA16_NOT_FIRST
440 section BS3DATA16 align=%1 CLASS=BS3KIT_CLASS_DATA16 PUBLIC USE16
441 %ifndef BS3_BEGIN_DATA16_WITHOUT_GROUP ; bs3-first-common.mac trick.
442 GROUP BS3KIT_GRPNM_DATA16 BS3DATA16
443 %endif
444 %else
445 section BS3DATA16
446 %endif
447 %undef BS3_CUR_SEG_BEGIN_MACRO
448 %xdefine BS3_CUR_SEG_BEGIN_MACRO BS3_BEGIN_DATA16
449 BS3_SET_BITS 16
450%endmacro
451
452%macro BS3_BEGIN_TEXT32 0-1 2
453 %ifndef BS3_BEGIN_TEXT32_NOT_FIRST
454 %define BS3_BEGIN_TEXT32_NOT_FIRST
455 section BS3TEXT32 align=%1 CLASS=BS3CLASS32CODE PUBLIC USE32 FLAT
456 %else
457 section BS3TEXT32
458 %endif
459 %undef BS3_CUR_SEG_BEGIN_MACRO
460 %xdefine BS3_CUR_SEG_BEGIN_MACRO BS3_BEGIN_TEXT32
461 BS3_SET_BITS 32
462%endmacro
463
464%macro BS3_BEGIN_DATA32 0-1 16
465 %ifndef BS3_BEGIN_DATA32_NOT_FIRST
466 %define BS3_BEGIN_DATA32_NOT_FIRST
467 section BS3DATA32 align=%1 CLASS=FAR_DATA PUBLIC USE32 ;FLAT - compiler doesn't make data flat.
468 %else
469 section BS3DATA32
470 %endif
471 %undef BS3_CUR_SEG_BEGIN_MACRO
472 %xdefine BS3_CUR_SEG_BEGIN_MACRO BS3_BEGIN_DATA32
473 BS3_SET_BITS 32
474%endmacro
475
476%macro BS3_BEGIN_TEXT64 0-1 2
477 %ifndef BS3_BEGIN_TEXT64_NOT_FIRST
478 %define BS3_BEGIN_TEXT64_NOT_FIRST
479 section BS3TEXT64 align=%1 CLASS=BS3CLASS64CODE PUBLIC USE32 FLAT
480 %else
481 section BS3TEXT64
482 %endif
483 %undef BS3_CUR_SEG_BEGIN_MACRO
484 %xdefine BS3_CUR_SEG_BEGIN_MACRO BS3_BEGIN_TEXT64
485 BS3_SET_BITS 64
486%endmacro
487
488%macro BS3_BEGIN_DATA64 0-1 16
489 %ifndef BS3_BEGIN_DATA64_NOT_FIRST
490 %define BS3_BEGIN_DATA64_NOT_FIRST
491 section BS3DATA64 align=%1 CLASS=FAR_DATA PUBLIC USE32 ;FLAT (see DATA32)
492 %else
493 section BS3DATA64
494 %endif
495 %undef BS3_CUR_SEG_BEGIN_MACRO
496 %xdefine BS3_CUR_SEG_BEGIN_MACRO BS3_BEGIN_DATA64
497 BS3_SET_BITS 64
498%endmacro
499
500;; The system data segment containing the GDT, TSSes and IDTs.
501%macro BS3_BEGIN_SYSTEM16 0-1 16
502 %ifndef BS3_BEGIN_SYSTEM16_NOT_FIRST
503 %define BS3_BEGIN_SYSTEM16_NOT_FIRST
504 section BS3SYSTEM16 align=%1 CLASS=BS3SYSTEM16 PUBLIC USE16
505 %else
506 section BS3SYSTEM16
507 %endif
508 %undef BS3_CUR_SEG_BEGIN_MACRO
509 %xdefine BS3_CUR_SEG_BEGIN_MACRO BS3_BEGIN_SYSTEM16
510 BS3_SET_BITS 16
511%endmacro
512
513;; Default text section.
514%macro BS3_BEGIN_DEFAULT_TEXT 0
515 %if ARCH_BITS == 16
516 BS3_BEGIN_TEXT16
517 %elif ARCH_BITS == 32
518 BS3_BEGIN_TEXT32
519 %elif ARCH_BITS == 64
520 BS3_BEGIN_TEXT64
521 %else
522 %error "ARCH_BITS must be defined as either 16, 32, or 64!"
523 INVALID_ARCH_BITS
524 %endif
525%endmacro
526
527;; @}
528
529
530;
531; Now, ditch the default 'text' section and define our own NAME macro.
532;
533%ifndef ASM_FORMAT_BIN
534 BS3_BEGIN_DEFAULT_TEXT
535 BS3_BEGIN_DEFAULT_TEXT ; stupid nasm automagically repeats the segment attributes.
536%endif
537
538;; When using watcom + OMF, we're using __cdecl by default, which
539; get an underscore added in front.
540%define NAME(name) _ %+ NAME_OVERLOAD(name)
541
542
543;
544; Include the standard headers from iprt.
545;
546
547
548%include "iprt/asmdefs.mac"
549%include "iprt/x86.mac"
550
551
552;;
553; Extern macro which mangles the name using NAME().
554%macro EXTERN 1
555 extern NAME(%1)
556%endmacro
557
558;;
559; Mangles a common name according to the current cpu bit count.
560; @remarks Requires the use of the BS3_SET_BITS macro instead of the BITS directive.
561%define BS3_CMN_NM(a_Name) BS3_NAME_UNDERSCORE %+ a_Name %+ _c %+ __BITS__
562
563;;
564; Extern macro which mangles the common name correctly, redefining the unmangled
565; name to the mangled one for ease of use.
566;
567; @param %1 The unmangled common name.
568;
569; @remarks Must enter the segment in which this name is defined.
570;
571%macro BS3_EXTERN_CMN 1
572 extern BS3_CMN_NM(%1)
573 %undef %1
574 %define %1 BS3_CMN_NM(%1)
575%endmacro
576
577;;
578; Same as BS3_EXTERN_CMN except it picks the far variant in 16-bit code.
579;
580; @param %1 The unmangled common name.
581;
582; @remarks Must enter the segment in which this name is defined.
583;
584%macro BS3_EXTERN_CMN_FAR 1
585 extern BS3_CMN_NM_FAR(%1)
586 %undef %1
587 %define %1 BS3_CMN_NM_FAR(%1)
588%endmacro
589
590;; @def BS3_EXTERN_TMPL
591; Mangles the given name into a template specific one. For ease of use, the
592; name is redefined to the mangled one, just like BS3_EXTERN_CMN does.
593; @note Segment does not change.
594%macro BS3_EXTERN_TMPL 1
595 extern TMPL_NM(%1)
596 %undef %1
597 %define %1 TMPL_NM(%1)
598%endmacro
599
600
601;;
602; Mangles a 16-bit and 32-bit accessible data name.
603; @remarks Requires the use of the BS3_SET_BITS macro instead of the BITS directive.
604%define BS3_DATA_NM(a_Name) _ %+ a_Name
605
606;;
607; Extern macro which mangles a DATA16 symbol correctly, redefining the
608; unmangled name to the mangled one for ease of use.
609;
610; @param %1 The unmangled common name.
611;
612; @remarks Will change to the DATA16 segment, use must switch back afterwards!
613;
614%macro BS3_EXTERN_DATA16 1
615 BS3_BEGIN_DATA16
616 extern _ %+ %1
617 %undef %1
618 %xdefine %1 _ %+ %1
619%endmacro
620
621;;
622; Extern macro which mangles a BS3SYSTEM16 symbol correctly, redefining the
623; unmangled name to the mangled one for ease of use.
624;
625; @param %1 The unmangled common name.
626;
627; @remarks Will change to the SYSTEM16 segment, use must switch back afterwards!
628;
629%macro BS3_EXTERN_SYSTEM16 1
630 BS3_BEGIN_SYSTEM16
631 extern _ %+ %1
632 %undef %1
633 %xdefine %1 _ %+ %1
634%endmacro
635
636
637;;
638; Global name with ELF attributes and size.
639;
640; This differs from GLOBALNAME_EX in that it expects a mangled symbol name,
641; and allows for nasm style symbol size expressions.
642;
643; @param %1 The mangled name.
644; @param %2 Symbol attributes.
645; @param %3 The size expression.
646;
647%macro BS3_GLOBAL_NAME_EX 3
648global %1
649%1:
650%undef BS3_LAST_LABEL
651%xdefine BS3_LAST_LABEL %1
652%endmacro
653
654;;
655; Global local label.
656;
657; This should be used when switching segments and jumping to it via a local lable.
658; It makes the lable visible to the debugger and map file.
659;
660%macro BS3_GLOBAL_LOCAL_LABEL 1
661global RT_CONCAT(BS3_LAST_LABEL,%1)
662%1:
663%endmacro
664
665;;
666; Global data unmangled label.
667;
668; @param %1 The unmangled name.
669; @param %2 The size (0 is fine).
670;
671%macro BS3_GLOBAL_DATA 2
672BS3_GLOBAL_NAME_EX BS3_DATA_NM(%1), , %2
673%endmacro
674
675;;
676; Starts a procedure.
677;
678; This differs from BEGINPROC in that it expects a mangled symbol name and
679; does the NASM symbol size stuff.
680;
681; @param %1 The mangled name.
682;
683%macro BS3_PROC_BEGIN 1
684BS3_GLOBAL_NAME_EX %1, function, (%1 %+ _EndProc - %1)
685%endmacro
686
687;;
688; Ends a procedure.
689;
690; Counter part to BS3_PROC_BEGIN.
691;
692; @param %1 The mangled name.
693;
694%macro BS3_PROC_END 1
695BS3_GLOBAL_NAME_EX %1 %+ _EndProc, function hidden, (%1 %+ _EndProc - %1)
696 int3 ; handy and avoids overlapping labels.
697%endmacro
698
699
700;; @name BS3_PBC_XXX - For use as the 2nd parameter to BS3_PROC_BEGIN_CMN and BS3_PROC_BEGIN_MODE.
701;; @{
702%define BS3_PBC_NEAR 1 ;;< Only near.
703%define BS3_PBC_FAR 2 ;;< Only far.
704%define BS3_PBC_HYBRID 3 ;;< Hybrid near/far procedure, trashing AX. Use BS3_HYBRID_RET to return.
705%define BS3_PBC_HYBRID_SAFE 4 ;;< Hybrid near/far procedure, no trashing but slower. Use BS3_HYBRID_RET to return.
706%define BS3_PBC_HYBRID_0_ARGS 5 ;;< Hybrid near/far procedure, no parameters so separate far stub, no trashing, fast near calls.
707;; @}
708
709;; Internal begin procedure macro.
710;
711; @param 1 The near name.
712; @param 2 The far name
713; @param 3 BS3_PBC_XXX.
714%macro BS3_PROC_BEGIN_INT 3
715 ;%warning "BS3_PROC_BEGIN_INT:" 1=%1 2=%2 3=%3
716 %undef BS3_CUR_PROC_FLAGS
717 %if __BITS__ == 16
718 %if %3 == BS3_PBC_NEAR
719 %xdefine BS3_CUR_PROC_FLAGS BS3_PBC_NEAR
720 %xdefine cbCurRetAddr 2
721 BS3_PROC_BEGIN %1
722
723 %elif %3 == BS3_PBC_FAR
724 %xdefine BS3_CUR_PROC_FLAGS BS3_PBC_FAR
725 %xdefine cbCurRetAddr 4
726 BS3_PROC_BEGIN %2
727
728 %elif %3 == BS3_PBC_HYBRID
729 %xdefine BS3_CUR_PROC_FLAGS BS3_PBC_HYBRID
730 %xdefine cbCurRetAddr 4
731 BS3_GLOBAL_NAME_EX %1, function, 3
732 pop ax
733 push cs
734 push ax
735 BS3_PROC_BEGIN %2
736
737 %elif %3 == BS3_PBC_HYBRID_SAFE
738 %xdefine BS3_CUR_PROC_FLAGS BS3_PBC_HYBRID_SAFE
739 %xdefine cbCurRetAddr 4
740 BS3_GLOBAL_NAME_EX %1, function, 3
741 extern Bs3CreateHybridFarRet_c16
742 call Bs3CreateHybridFarRet_c16
743 BS3_PROC_BEGIN %2
744
745 %elif %3 == BS3_PBC_HYBRID_0_ARGS
746 %xdefine BS3_CUR_PROC_FLAGS BS3_PBC_NEAR
747 %xdefine cbCurRetAddr 2
748 %xdefine TMP_BEGIN_PREV_SEG BS3_CUR_SEG_BEGIN_MACRO
749
750 BS3_BEGIN_TEXT16_FARSTUBS
751 BS3_PROC_BEGIN %2
752 call %1
753 retf
754 BS3_PROC_END %2
755
756 TMP_BEGIN_PREV_SEG
757 BS3_PROC_BEGIN %1
758 %undef TMP_BEGIN_PREV_SEG
759
760 %else
761 %error BS3_PROC_BEGIN_CMN parameter 2 value %3 is not recognized.
762
763 %xdefine BS3_CUR_PROC_FLAGS BS3_PBC_NEAR
764 %xdefine cbCurRetAddr 4
765 BS3_PROC_BEGIN %1
766 %endif
767 %else
768 %xdefine BS3_CUR_PROC_FLAGS BS3_PBC_NEAR
769 %xdefine cbCurRetAddr xCB
770 BS3_PROC_BEGIN %1
771 %endif
772%endmacro
773
774;; Internal end procedure macro
775;
776; @param 1 The near name.
777; @param 2 The far name
778;
779%macro BS3_PROC_END_INT 2
780 %if __BITS__ == 16
781 %if BS3_CUR_PROC_FLAGS == BS3_PBC_NEAR
782 BS3_PROC_END %1
783 %else
784 BS3_PROC_END %2
785 %endif
786 %else
787 BS3_PROC_END %1
788 %endif
789 %undef BS3_CUR_PROC_FLAGS
790 %undef cbCurRetAddr
791%endmacro
792
793
794;; Convenience macro for defining common procedures.
795; This will emit both near and far 16-bit symbols according to parameter %2 (BS3_PBC_XXX).
796%macro BS3_PROC_BEGIN_CMN 2
797 BS3_PROC_BEGIN_INT BS3_CMN_NM(%1), BS3_CMN_NM_FAR(%1), %2
798%endmacro
799
800;; Convenience macro for defining common procedures.
801%macro BS3_PROC_END_CMN 1
802 BS3_PROC_END_INT BS3_CMN_NM(%1), BS3_CMN_NM_FAR(%1)
803%endmacro
804
805;;
806; Generate a safe 16-bit far stub for function %1, shuffling %2 bytes of parameters.
807;
808; This does absolutely nothing in 32-bit and 64-bit mode.
809;
810; @param 1 The function basename.
811; @param 2 The number of bytes of parameters on the stack, must be a multiple of 2.
812; @remarks Changes the segment to TEXT16.
813;
814%macro BS3_CMN_FAR_STUB 2
815 %if %2 <= 1 || (%2 & 1)
816 %error Invalid parameter frame size passed to BS3_CMN_FAR_STUB: %2
817 %endif
818 %if __BITS__ == 16
819BS3_BEGIN_TEXT16_FARSTUBS
820BS3_PROC_BEGIN_CMN %1, BS3_PBC_FAR
821 CPU 8086
822 inc bp ; Odd bp is far call indicator.
823 push bp
824 mov bp, sp
825 %assign offParam %2
826 %rep %2/2
827 push word [bp + xCB + cbCurRetAddr + offParam - 2]
828 %assign offParam offParam - 2
829 %endrep
830 call BS3_CMN_NM(%1)
831 add sp, %2
832 pop bp
833 dec bp
834 retf
835BS3_PROC_END_CMN %1
836BS3_BEGIN_TEXT16
837 %endif
838%endmacro
839
840
841;; Convenience macro for defining mode specific procedures.
842%macro BS3_PROC_BEGIN_MODE 2
843 ;%warning "BS3_PROC_BEGIN_MODE: 1=" %1 "2=" %2
844 BS3_PROC_BEGIN_INT TMPL_NM(%1), TMPL_FAR_NM(%1), %2
845%endmacro
846
847;; Convenience macro for defining mode specific procedures.
848%macro BS3_PROC_END_MODE 1
849 BS3_PROC_END_INT TMPL_NM(%1), TMPL_FAR_NM(%1)
850%endmacro
851
852;; Does a far return in 16-bit code, near return in 32-bit and 64-bit.
853; This is for use with BS3_PBC_XXX
854%macro BS3_HYBRID_RET 0-1
855 %if __BITS__ == 16
856 %if %0 > 0
857 %if BS3_CUR_PROC_FLAGS == BS3_PBC_NEAR || BS3_CUR_PROC_FLAGS == BS3_PBC_HYBRID_0_ARGS
858 ret %1
859 %else
860 retf %1
861 %endif
862 %else
863 %if BS3_CUR_PROC_FLAGS == BS3_PBC_NEAR || BS3_CUR_PROC_FLAGS == BS3_PBC_HYBRID_0_ARGS
864 ret
865 %else
866 retf
867 %endif
868 %endif
869 %else
870 %if BS3_CUR_PROC_FLAGS != BS3_PBC_NEAR
871 %error Expected BS3_CUR_PROC_FLAGS to be BS3_PBC_NEAR in non-16-bit code.
872 %endif
873 %if %0 > 0
874 ret %1
875 %else
876 ret
877 %endif
878 %endif
879%endmacro
880
881
882;;
883; Prologue hacks for 64-bit code.
884;
885; This saves the four register parameters onto the stack so we can pretend
886; the calling convention is stack based. The 64-bit calling convension is
887; the microsoft one, so this is straight forward.
888;
889; Pairs with BS3_CALL_CONV_EPILOG.
890;
891; @param %1 The number of parameters.
892;
893; @remarks Must be invoked before any stack changing instructions are emitted.
894;
895%macro BS3_CALL_CONV_PROLOG 1
896 %undef BS3_CALL_CONV_PROLOG_PARAMS
897 %define BS3_CALL_CONV_PROLOG_PARAMS %1
898 %if __BITS__ == 64
899 %if %1 >= 1
900 mov [rsp + 008h], rcx
901 %elifdef BS3_STRICT
902 and qword [rsp + 008h], 1
903 %endif
904 %if %1 >= 2
905 mov [rsp + 010h], rdx
906 %elifdef BS3_STRICT
907 and qword [rsp + 010h], 2
908 %endif
909 %if %1 >= 3
910 mov [rsp + 018h], r8
911 %elifdef BS3_STRICT
912 and qword [rsp + 018h], 3
913 %endif
914 %if %1 >= 4
915 mov [rsp + 020h], r9
916 %elifdef BS3_STRICT
917 and qword [rsp + 020h], 4
918 %endif
919 %endif
920%endmacro
921
922;;
923; Epilogue hacks for 64-bit code.
924;
925; Counter part to BS3_CALL_CONV_PROLOG.
926;
927; @param %1 The number of parameters.
928;
929; @remarks Must be invoked right before the return instruction as it uses RSP.
930;
931%macro BS3_CALL_CONV_EPILOG 1
932 %if BS3_CALL_CONV_PROLOG_PARAMS != %1
933 %error "BS3_CALL_CONV_EPILOG argument differs from BS3_CALL_CONV_PROLOG."
934 %endif
935 %if __BITS__ == 64
936 %ifdef BS3_STRICT
937 mov dword [rsp + 008h], 31h
938 mov dword [rsp + 010h], 32h
939 mov dword [rsp + 018h], 33h
940 mov dword [rsp + 020h], 34h
941 %endif
942 %endif
943%endmacro
944
945;;
946; Wrapper for the call instruction that hides calling convension differences.
947;
948; This always calls %1.
949; In 64-bit code, it will load up to 4 parameters into register.
950;
951; @param %1 The function to call (mangled).
952; @param %2 The number of parameters.
953;
954%macro BS3_CALL 2
955 %if __BITS__ == 64
956 %if %2 >= 1
957 mov rcx, [rsp]
958 %ifdef BS3_STRICT
959 and qword [rsp], 11h
960 %endif
961 %endif
962 %if %2 >= 2
963 mov rdx, [rsp + 008h]
964 %ifdef BS3_STRICT
965 and qword [rsp + 008h], 12h
966 %endif
967 %endif
968 %if %2 >= 3
969 mov r8, [rsp + 010h]
970 %ifdef BS3_STRICT
971 and qword [rsp + 010h], 13h
972 %endif
973 %endif
974 %if %2 >= 4
975 mov r9, [rsp + 018h]
976 %ifdef BS3_STRICT
977 and qword [rsp + 018h], 14h
978 %endif
979 %endif
980 %endif
981 call %1
982%endmacro
983
984
985;; @name Execution Modes
986; @{
987%define BS3_MODE_INVALID 000h
988%define BS3_MODE_RM 001h ;;< real mode.
989%define BS3_MODE_PE16 011h ;;< 16-bit protected mode kernel+tss, running 16-bit code, unpaged.
990%define BS3_MODE_PE16_32 012h ;;< 16-bit protected mode kernel+tss, running 32-bit code, unpaged.
991%define BS3_MODE_PE16_V86 018h ;;< 16-bit protected mode kernel+tss, running virtual 8086 mode code, unpaged.
992%define BS3_MODE_PE32 022h ;;< 32-bit protected mode kernel+tss, running 32-bit code, unpaged.
993%define BS3_MODE_PE32_16 021h ;;< 32-bit protected mode kernel+tss, running 16-bit code, unpaged.
994%define BS3_MODE_PEV86 028h ;;< 32-bit protected mode kernel+tss, running virtual 8086 mode code, unpaged.
995%define BS3_MODE_PP16 031h ;;< 16-bit protected mode kernel+tss, running 16-bit code, paged.
996%define BS3_MODE_PP16_32 032h ;;< 16-bit protected mode kernel+tss, running 32-bit code, paged.
997%define BS3_MODE_PP16_V86 038h ;;< 16-bit protected mode kernel+tss, running virtual 8086 mode code, paged.
998%define BS3_MODE_PP32 042h ;;< 32-bit protected mode kernel+tss, running 32-bit code, paged.
999%define BS3_MODE_PP32_16 041h ;;< 32-bit protected mode kernel+tss, running 16-bit code, paged.
1000%define BS3_MODE_PPV86 048h ;;< 32-bit protected mode kernel+tss, running virtual 8086 mode code, paged.
1001%define BS3_MODE_PAE16 051h ;;< 16-bit protected mode kernel+tss, running 16-bit code, PAE paging.
1002%define BS3_MODE_PAE16_32 052h ;;< 16-bit protected mode kernel+tss, running 32-bit code, PAE paging.
1003%define BS3_MODE_PAE16_V86 058h ;;< 16-bit protected mode kernel+tss, running virtual 8086 mode, PAE paging.
1004%define BS3_MODE_PAE32 062h ;;< 32-bit protected mode kernel+tss, running 32-bit code, PAE paging.
1005%define BS3_MODE_PAE32_16 061h ;;< 32-bit protected mode kernel+tss, running 16-bit code, PAE paging.
1006%define BS3_MODE_PAEV86 068h ;;< 32-bit protected mode kernel+tss, running virtual 8086 mode, PAE paging.
1007%define BS3_MODE_LM16 071h ;;< 16-bit long mode (paged), kernel+tss always 64-bit.
1008%define BS3_MODE_LM32 072h ;;< 32-bit long mode (paged), kernel+tss always 64-bit.
1009%define BS3_MODE_LM64 074h ;;< 64-bit long mode (paged), kernel+tss always 64-bit.
1010
1011%define BS3_MODE_CODE_MASK 00fh ;;< Running code mask.
1012%define BS3_MODE_CODE_16 001h ;;< Running 16-bit code.
1013%define BS3_MODE_CODE_32 002h ;;< Running 32-bit code.
1014%define BS3_MODE_CODE_64 004h ;;< Running 64-bit code.
1015%define BS3_MODE_CODE_V86 008h ;;< Running 16-bit virtual 8086 code.
1016
1017%define BS3_MODE_SYS_MASK 0f0h ;;< kernel+tss mask.
1018%define BS3_MODE_SYS_RM 000h ;;< Real mode kernel+tss.
1019%define BS3_MODE_SYS_PE16 010h ;;< 16-bit protected mode kernel+tss.
1020%define BS3_MODE_SYS_PE32 020h ;;< 32-bit protected mode kernel+tss.
1021%define BS3_MODE_SYS_PP16 030h ;;< 16-bit paged protected mode kernel+tss.
1022%define BS3_MODE_SYS_PP32 040h ;;< 32-bit paged protected mode kernel+tss.
1023%define BS3_MODE_SYS_PAE16 050h ;;< 16-bit PAE paged protected mode kernel+tss.
1024%define BS3_MODE_SYS_PAE32 060h ;;< 32-bit PAE paged protected mode kernel+tss.
1025%define BS3_MODE_SYS_LM 070h ;;< 64-bit (paged) long mode protected mode kernel+tss.
1026
1027;; Whether the mode has paging enabled.
1028%define BS3_MODE_IS_PAGED(a_fMode) ((a_fMode) >= BS3_MODE_PP16)
1029
1030;; Whether the mode is running v8086 code.
1031%define BS3_MODE_IS_V86(a_fMode) (((a_fMode) & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_V86)
1032;; Whether the we're executing in real mode or v8086 mode.
1033%define BS3_MODE_IS_RM_OR_V86(a_fMode) ((a_fMode) == BS3_MODE_RM || BS3_MODE_IS_V86(a_fMode))
1034;; Whether the mode is running 16-bit code, except v8086.
1035%define BS3_MODE_IS_16BIT_CODE_NO_V86(a_fMode) (((a_fMode) & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_16)
1036;; Whether the mode is running 16-bit code (includes v8086).
1037%define BS3_MODE_IS_16BIT_CODE(a_fMode) (BS3_MODE_IS_16BIT_CODE_NO_V86(a_fMode) || BS3_MODE_IS_V86(a_fMode))
1038;; Whether the mode is running 32-bit code.
1039%define BS3_MODE_IS_32BIT_CODE(a_fMode) (((a_fMode) & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_32)
1040;; Whether the mode is running 64-bit code.
1041%define BS3_MODE_IS_64BIT_CODE(a_fMode) (((a_fMode) & BS3_MODE_CODE_MASK) == BS3_MODE_CODE_64)
1042
1043;; Whether the system is in real mode.
1044%define BS3_MODE_IS_RM_SYS(a_fMode) (((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_RM)
1045;; Whether the system is some 16-bit mode that isn't real mode.
1046%define BS3_MODE_IS_16BIT_SYS_NO_RM(a_fMode) ( ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PE16 \
1047 || ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PP16 \
1048 || ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PAE16)
1049;; Whether the system is some 16-bit mode (includes real mode).
1050%define BS3_MODE_IS_16BIT_SYS(a_fMode) (BS3_MODE_IS_16BIT_SYS_NO_RM(a_fMode) || BS3_MODE_IS_RM_SYS(a_fMode))
1051;; Whether the system is some 32-bit mode.
1052%define BS3_MODE_IS_32BIT_SYS(a_fMode) ( ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PE32 \
1053 || ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PP32 \
1054 || ((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_PAE32)
1055;; Whether the system is long mode.
1056%define BS3_MODE_IS_64BIT_SYS(a_fMode) (((a_fMode) & BS3_MODE_SYS_MASK) == BS3_MODE_SYS_LM)
1057
1058;; @}
1059
1060;; @name For mode specfic lookups:
1061;; %[BS3_MODE_NM %+ BS3_MODE_PE32](SomeBaseName)
1062;; %[BS3_MODE_LNAME_ %+ TMPL_MODE]
1063;; @{
1064%define BS3_MODE_NM_001h(a_Name) _ %+ a_Name %+ _rm
1065%define BS3_MODE_NM_011h(a_Name) _ %+ a_Name %+ _pe16
1066%define BS3_MODE_NM_012h(a_Name) _ %+ a_Name %+ _pe16_32
1067%define BS3_MODE_NM_018h(a_Name) _ %+ a_Name %+ _pe16_v86
1068%define BS3_MODE_NM_022h(a_Name) _ %+ a_Name %+ _pe32
1069%define BS3_MODE_NM_021h(a_Name) _ %+ a_Name %+ _pe32_16
1070%define BS3_MODE_NM_028h(a_Name) _ %+ a_Name %+ _pev86
1071%define BS3_MODE_NM_031h(a_Name) _ %+ a_Name %+ _pp16
1072%define BS3_MODE_NM_032h(a_Name) _ %+ a_Name %+ _pp16_32
1073%define BS3_MODE_NM_038h(a_Name) _ %+ a_Name %+ _pp16_v86
1074%define BS3_MODE_NM_042h(a_Name) _ %+ a_Name %+ _pp32
1075%define BS3_MODE_NM_041h(a_Name) _ %+ a_Name %+ _pp32_16
1076%define BS3_MODE_NM_048h(a_Name) _ %+ a_Name %+ _ppv86
1077%define BS3_MODE_NM_051h(a_Name) _ %+ a_Name %+ _pae16
1078%define BS3_MODE_NM_052h(a_Name) _ %+ a_Name %+ _pae16_32
1079%define BS3_MODE_NM_058h(a_Name) _ %+ a_Name %+ _pae16_v86
1080%define BS3_MODE_NM_062h(a_Name) _ %+ a_Name %+ _pae32
1081%define BS3_MODE_NM_061h(a_Name) _ %+ a_Name %+ _pae32_16
1082%define BS3_MODE_NM_068h(a_Name) _ %+ a_Name %+ _paev86
1083%define BS3_MODE_NM_071h(a_Name) _ %+ a_Name %+ _lm16
1084%define BS3_MODE_NM_072h(a_Name) _ %+ a_Name %+ _lm32
1085%define BS3_MODE_NM_074h(a_Name) _ %+ a_Name %+ _lm64
1086
1087%define BS3_MODE_LNAME_001h rm
1088%define BS3_MODE_LNAME_011h pe16
1089%define BS3_MODE_LNAME_012h pe16_32
1090%define BS3_MODE_LNAME_018h pe16_v86
1091%define BS3_MODE_LNAME_022h pe32
1092%define BS3_MODE_LNAME_021h pe32_16
1093%define BS3_MODE_LNAME_028h pev86
1094%define BS3_MODE_LNAME_031h pp16
1095%define BS3_MODE_LNAME_032h pp16_32
1096%define BS3_MODE_LNAME_038h pp16_v86
1097%define BS3_MODE_LNAME_042h pp32
1098%define BS3_MODE_LNAME_041h pp32_16
1099%define BS3_MODE_LNAME_048h ppv86
1100%define BS3_MODE_LNAME_051h pae16
1101%define BS3_MODE_LNAME_052h pae16_32
1102%define BS3_MODE_LNAME_058h pae16_v86
1103%define BS3_MODE_LNAME_062h pae32
1104%define BS3_MODE_LNAME_061h pae32_16
1105%define BS3_MODE_LNAME_068h paev86
1106%define BS3_MODE_LNAME_071h lm16
1107%define BS3_MODE_LNAME_072h lm32
1108%define BS3_MODE_LNAME_074h lm64
1109
1110%define BS3_MODE_UNAME_001h RM
1111%define BS3_MODE_UNAME_011h PE16
1112%define BS3_MODE_UNAME_012h PE16_32
1113%define BS3_MODE_UNAME_018h PE16_V86
1114%define BS3_MODE_UNAME_022h PE32
1115%define BS3_MODE_UNAME_021h PE32_16
1116%define BS3_MODE_UNAME_028h PEV86
1117%define BS3_MODE_UNAME_031h PP16
1118%define BS3_MODE_UNAME_032h PP16_32
1119%define BS3_MODE_UNAME_038h PP16_V86
1120%define BS3_MODE_UNAME_042h PP32
1121%define BS3_MODE_UNAME_041h PP32_16
1122%define BS3_MODE_UNAME_048h PPV86
1123%define BS3_MODE_UNAME_051h PAE16
1124%define BS3_MODE_UNAME_052h PAE16_32
1125%define BS3_MODE_UNAME_058h PAE16_V86
1126%define BS3_MODE_UNAME_062h PAE32
1127%define BS3_MODE_UNAME_061h PAE32_16
1128%define BS3_MODE_UNAME_068h PAEV86
1129%define BS3_MODE_UNAME_071h LM16
1130%define BS3_MODE_UNAME_072h LM32
1131%define BS3_MODE_UNAME_074h LM64
1132
1133%define BS3_MODE_UNDERSCORE_001h _
1134%define BS3_MODE_UNDERSCORE_011h _
1135%define BS3_MODE_UNDERSCORE_012h _
1136%define BS3_MODE_UNDERSCORE_018h _
1137%define BS3_MODE_UNDERSCORE_022h _
1138%define BS3_MODE_UNDERSCORE_021h _
1139%define BS3_MODE_UNDERSCORE_028h _
1140%define BS3_MODE_UNDERSCORE_031h _
1141%define BS3_MODE_UNDERSCORE_032h _
1142%define BS3_MODE_UNDERSCORE_038h _
1143%define BS3_MODE_UNDERSCORE_042h _
1144%define BS3_MODE_UNDERSCORE_041h _
1145%define BS3_MODE_UNDERSCORE_048h _
1146%define BS3_MODE_UNDERSCORE_051h _
1147%define BS3_MODE_UNDERSCORE_052h _
1148%define BS3_MODE_UNDERSCORE_058h _
1149%define BS3_MODE_UNDERSCORE_062h _
1150%define BS3_MODE_UNDERSCORE_061h _
1151%define BS3_MODE_UNDERSCORE_068h _
1152%define BS3_MODE_UNDERSCORE_071h _
1153%define BS3_MODE_UNDERSCORE_072h _
1154%define BS3_MODE_UNDERSCORE_074h _
1155
1156%define BS3_MODE_CNAME_001h c16
1157%define BS3_MODE_CNAME_011h c16
1158%define BS3_MODE_CNAME_012h c32
1159%define BS3_MODE_CNAME_018h c16
1160%define BS3_MODE_CNAME_022h c32
1161%define BS3_MODE_CNAME_021h c16
1162%define BS3_MODE_CNAME_028h c16
1163%define BS3_MODE_CNAME_031h c16
1164%define BS3_MODE_CNAME_032h c32
1165%define BS3_MODE_CNAME_038h c16
1166%define BS3_MODE_CNAME_042h c32
1167%define BS3_MODE_CNAME_041h c16
1168%define BS3_MODE_CNAME_048h c16
1169%define BS3_MODE_CNAME_051h c16
1170%define BS3_MODE_CNAME_052h c32
1171%define BS3_MODE_CNAME_058h c16
1172%define BS3_MODE_CNAME_062h c32
1173%define BS3_MODE_CNAME_061h c16
1174%define BS3_MODE_CNAME_068h c16
1175%define BS3_MODE_CNAME_071h c16
1176%define BS3_MODE_CNAME_072h c32
1177%define BS3_MODE_CNAME_074h c64
1178;; @}
1179
1180;; @name For getting the ring-0 mode for v86 modes: %[BS3_MODE_R0_NM_001h %+ TMPL_MODE](Bs3SwitchToRM)
1181;; @{
1182%define BS3_MODE_R0_NM_001h(a_Name) _ %+ a_Name %+ _rm
1183%define BS3_MODE_R0_NM_011h(a_Name) _ %+ a_Name %+ _pe16
1184%define BS3_MODE_R0_NM_012h(a_Name) _ %+ a_Name %+ _pe16_32
1185%define BS3_MODE_R0_NM_018h(a_Name) _ %+ a_Name %+ _pe16
1186%define BS3_MODE_R0_NM_022h(a_Name) _ %+ a_Name %+ _pe32
1187%define BS3_MODE_R0_NM_021h(a_Name) _ %+ a_Name %+ _pe32_16
1188%define BS3_MODE_R0_NM_028h(a_Name) _ %+ a_Name %+ _pe32_16
1189%define BS3_MODE_R0_NM_031h(a_Name) _ %+ a_Name %+ _pp16
1190%define BS3_MODE_R0_NM_032h(a_Name) _ %+ a_Name %+ _pp16_32
1191%define BS3_MODE_R0_NM_038h(a_Name) _ %+ a_Name %+ _pp16
1192%define BS3_MODE_R0_NM_042h(a_Name) _ %+ a_Name %+ _pp32
1193%define BS3_MODE_R0_NM_041h(a_Name) _ %+ a_Name %+ _pp32_16
1194%define BS3_MODE_R0_NM_048h(a_Name) _ %+ a_Name %+ _pp32_16
1195%define BS3_MODE_R0_NM_051h(a_Name) _ %+ a_Name %+ _pae16
1196%define BS3_MODE_R0_NM_052h(a_Name) _ %+ a_Name %+ _pae16_32
1197%define BS3_MODE_R0_NM_058h(a_Name) _ %+ a_Name %+ _pae16
1198%define BS3_MODE_R0_NM_062h(a_Name) _ %+ a_Name %+ _pae32
1199%define BS3_MODE_R0_NM_061h(a_Name) _ %+ a_Name %+ _pae32_16
1200%define BS3_MODE_R0_NM_068h(a_Name) _ %+ a_Name %+ _pae32_16
1201%define BS3_MODE_R0_NM_071h(a_Name) _ %+ a_Name %+ _lm16
1202%define BS3_MODE_R0_NM_072h(a_Name) _ %+ a_Name %+ _lm32
1203%define BS3_MODE_R0_NM_074h(a_Name) _ %+ a_Name %+ _lm64
1204;; @}
1205
1206
1207;;
1208; Includes the file %1 with TMPL_MODE set to all possible value.
1209; @param 1 Double quoted include file name.
1210%macro BS3_INSTANTIATE_TEMPLATE_WITH_WEIRD_ONES 1
1211 %define BS3_INSTANTIATING_MODE
1212 %define BS3_INSTANTIATING_ALL_MODES
1213
1214 %define TMPL_MODE BS3_MODE_RM
1215 %include %1
1216
1217 %define TMPL_MODE BS3_MODE_PE16
1218 %include %1
1219 %define TMPL_MODE BS3_MODE_PE16_32
1220 %include %1
1221 %define TMPL_MODE BS3_MODE_PE16_V86
1222 %include %1
1223
1224 %define TMPL_MODE BS3_MODE_PE32
1225 %include %1
1226 %define TMPL_MODE BS3_MODE_PE32_16
1227 %include %1
1228 %define TMPL_MODE BS3_MODE_PEV86
1229 %include %1
1230
1231 %define TMPL_MODE BS3_MODE_PP16
1232 %include %1
1233 %define TMPL_MODE BS3_MODE_PP16_32
1234 %include %1
1235 %define TMPL_MODE BS3_MODE_PP16_V86
1236 %include %1
1237
1238 %define TMPL_MODE BS3_MODE_PP32
1239 %include %1
1240 %define TMPL_MODE BS3_MODE_PP32_16
1241 %include %1
1242 %define TMPL_MODE BS3_MODE_PPV86
1243 %include %1
1244
1245 %define TMPL_MODE BS3_MODE_PAE16
1246 %include %1
1247 %define TMPL_MODE BS3_MODE_PAE16_32
1248 %include %1
1249 %define TMPL_MODE BS3_MODE_PAE16_V86
1250 %include %1
1251
1252 %define TMPL_MODE BS3_MODE_PAE32
1253 %include %1
1254 %define TMPL_MODE BS3_MODE_PAE32_16
1255 %include %1
1256 %define TMPL_MODE BS3_MODE_PAEV86
1257 %include %1
1258
1259 %define TMPL_MODE BS3_MODE_LM16
1260 %include %1
1261 %define TMPL_MODE BS3_MODE_LM32
1262 %include %1
1263 %define TMPL_MODE BS3_MODE_LM64
1264 %include %1
1265
1266 %undef BS3_INSTANTIATING_MODE
1267 %undef BS3_INSTANTIATING_ALL_MODES
1268%endmacro
1269
1270
1271;;
1272; Includes the file %1 with TMPL_MODE set to all but the "weird" value.
1273; @param 1 Double quoted include file name.
1274%macro BS3_INSTANTIATE_TEMPLATE_ESSENTIALS 1
1275 %define BS3_INSTANTIATING_MODE
1276 %define BS3_INSTANTIATING_ESSENTIAL_MODES
1277
1278 %define TMPL_MODE BS3_MODE_RM
1279 %include %1
1280
1281 %define TMPL_MODE BS3_MODE_PE16
1282 %include %1
1283
1284 %define TMPL_MODE BS3_MODE_PE32
1285 %include %1
1286 %define TMPL_MODE BS3_MODE_PEV86
1287 %include %1
1288
1289 %define TMPL_MODE BS3_MODE_PP16
1290 %include %1
1291
1292 %define TMPL_MODE BS3_MODE_PP32
1293 %include %1
1294 %define TMPL_MODE BS3_MODE_PPV86
1295 %include %1
1296
1297 %define TMPL_MODE BS3_MODE_PAE16
1298 %include %1
1299
1300 %define TMPL_MODE BS3_MODE_PAE32
1301 %include %1
1302 %define TMPL_MODE BS3_MODE_PAEV86
1303 %include %1
1304
1305 %define TMPL_MODE BS3_MODE_LM16
1306 %include %1
1307 %define TMPL_MODE BS3_MODE_LM32
1308 %include %1
1309 %define TMPL_MODE BS3_MODE_LM64
1310 %include %1
1311
1312 %undef BS3_INSTANTIATING_MODE
1313 %undef BS3_INSTANTIATING_ESSENTIAL_MODES
1314%endmacro
1315
1316;;
1317; Includes the file %1 with TMPL_MODE set to a 16-bit, a 32-bit and a 64-bit value.
1318; @param 1 Double quoted include file name.
1319%macro BS3_INSTANTIATE_COMMON_TEMPLATE 1
1320 %define BS3_INSTANTIATING_CMN
1321
1322 %define TMPL_MODE BS3_MODE_RM
1323 %include %1
1324 %define TMPL_MODE BS3_MODE_PE32
1325 %include %1
1326 %define TMPL_MODE BS3_MODE_LM64
1327 %include %1
1328
1329 %undef BS3_INSTANTIATING_CMN
1330%endmacro
1331
1332
1333;; @name Static Memory Allocation
1334; @{
1335;; The flat load address for the code after the bootsector.
1336%define BS3_ADDR_LOAD 010000h
1337;; Where we save the boot registers during init.
1338; Located right before the code.
1339%define BS3_ADDR_REG_SAVE (BS3_ADDR_LOAD - BS3REGCTX_size - 8)
1340;; Where the stack starts (initial RSP value).
1341; Located 16 bytes (assumed by boot sector) before the saved registers. SS.BASE=0.
1342%define BS3_ADDR_STACK (BS3_ADDR_REG_SAVE - 16)
1343;; The ring-0 stack (8KB) for ring transitions.
1344%define BS3_ADDR_STACK_R0 006000h
1345;; The ring-1 stack (8KB) for ring transitions.
1346%define BS3_ADDR_STACK_R1 004000h
1347;; The ring-2 stack (8KB) for ring transitions.
1348%define BS3_ADDR_STACK_R2 002000h
1349;; IST1 ring-0 stack for long mode (4KB), used for double faults elsewhere.
1350%define BS3_ADDR_STACK_R0_IST1 009000h
1351;; IST2 ring-0 stack for long mode (3KB), used for spare 0 stack elsewhere.
1352%define BS3_ADDR_STACK_R0_IST2 008000h
1353;; IST3 ring-0 stack for long mode (1KB).
1354%define BS3_ADDR_STACK_R0_IST3 007400h
1355;; IST4 ring-0 stack for long mode (1KB), used for spare 1 stack elsewhere.
1356%define BS3_ADDR_STACK_R0_IST4 007000h
1357;; IST5 ring-0 stack for long mode (1KB).
1358%define BS3_ADDR_STACK_R0_IST5 006c00h
1359;; IST6 ring-0 stack for long mode (1KB).
1360%define BS3_ADDR_STACK_R0_IST6 006800h
1361;; IST7 ring-0 stack for long mode (1KB).
1362%define BS3_ADDR_STACK_R0_IST7 006400h
1363
1364;; The base address of the BS3TEXT16 segment (same as BS3_LOAD_ADDR).
1365;; @sa BS3_SEL_TEXT16
1366%define BS3_ADDR_BS3TEXT16 010000h
1367;; The base address of the BS3SYSTEM16 segment.
1368;; @sa BS3_SEL_SYSTEM16
1369%define BS3_ADDR_BS3SYSTEM16 020000h
1370;; The base address of the BS3DATA16/BS3KIT_GRPNM_DATA16 segment.
1371;; @sa BS3_SEL_DATA16
1372%define BS3_ADDR_BS3DATA16 029000h
1373;; @}
1374
1375
1376;;
1377; BS3 register context. Used by traps and such.
1378;
1379struc BS3REGCTX
1380 .rax resq 1 ; BS3REG rax; /**< 0x00 */
1381 .rcx resq 1 ; BS3REG rcx; /**< 0x08 */
1382 .rdx resq 1 ; BS3REG rdx; /**< 0x10 */
1383 .rbx resq 1 ; BS3REG rbx; /**< 0x18 */
1384 .rsp resq 1 ; BS3REG rsp; /**< 0x20 */
1385 .rbp resq 1 ; BS3REG rbp; /**< 0x28 */
1386 .rsi resq 1 ; BS3REG rsi; /**< 0x30 */
1387 .rdi resq 1 ; BS3REG rdi; /**< 0x38 */
1388 .r8 resq 1 ; BS3REG r8; /**< 0x40 */
1389 .r9 resq 1 ; BS3REG r9; /**< 0x48 */
1390 .r10 resq 1 ; BS3REG r10; /**< 0x50 */
1391 .r11 resq 1 ; BS3REG r11; /**< 0x58 */
1392 .r12 resq 1 ; BS3REG r12; /**< 0x60 */
1393 .r13 resq 1 ; BS3REG r13; /**< 0x68 */
1394 .r14 resq 1 ; BS3REG r14; /**< 0x70 */
1395 .r15 resq 1 ; BS3REG r15; /**< 0x78 */
1396 .rflags resq 1 ; BS3REG rflags; /**< 0x80 */
1397 .rip resq 1 ; BS3REG rip; /**< 0x88 */
1398 .cs resw 1 ; uint16_t cs; /**< 0x90 */
1399 .ds resw 1 ; uint16_t ds; /**< 0x92 */
1400 .es resw 1 ; uint16_t es; /**< 0x94 */
1401 .fs resw 1 ; uint16_t fs; /**< 0x96 */
1402 .gs resw 1 ; uint16_t gs; /**< 0x98 */
1403 .ss resw 1 ; uint16_t ss; /**< 0x9a */
1404 .tr resw 1 ; uint16_t tr; /**< 0x9c */
1405 .ldtr resw 1 ; uint16_t ldtr; /**< 0x9e */
1406 .bMode resb 1 ; uint8_t bMode; /**< 0xa0: BS3_MODE_XXX. */
1407 .bCpl resb 1 ; uint8_t bCpl; /**< 0xa1: 0-3, 0 is used for real mode. */
1408 .fbFlags resb 1 ; uint8_t fbFlags; /**< 0xa2: BS3REG_CTX_F_XXX */
1409 .abPadding resb 5 ; uint8_t abPadding[5]; /**< 0xa4 */
1410 .cr0 resq 1 ; BS3REG cr0; /**< 0xa8 */
1411 .cr2 resq 1 ; BS3REG cr2; /**< 0xb0 */
1412 .cr3 resq 1 ; BS3REG cr3; /**< 0xb8 */
1413 .cr4 resq 1 ; BS3REG cr4; /**< 0xc0 */
1414 .uUnused resq 1 ; BS3REG uUnused; /**< 0xc8 */
1415endstruc
1416AssertCompileSize(BS3REGCTX, 0xd0)
1417
1418;; @name BS3REG_CTX_F_XXX - BS3REGCTX::fbFlags masks.
1419; @{
1420;; The CR0 is MSW (only low 16-bit). */
1421%define BS3REG_CTX_F_NO_CR0_IS_MSW 0x01
1422;; No CR2 and CR3 values. Not in CPL 0 or CPU too old for CR2 & CR3.
1423%define BS3REG_CTX_F_NO_CR2_CR3 0x02
1424;; No CR4 value. The CPU is too old for CR4.
1425%define BS3REG_CTX_F_NO_CR4 0x04
1426;; No TR and LDTR values. Context gathered in real mode or v8086 mode.
1427%define BS3REG_CTX_F_NO_TR_LDTR 0x08
1428;; The context doesn't have valid values for AMD64 GPR extensions.
1429%define BS3REG_CTX_F_NO_AMD64 0x10
1430;; @}
1431
1432
1433;; @name Flags for Bs3RegCtxRestore
1434; @{
1435;; Skip restoring the CRx registers.
1436%define BS3REGCTXRESTORE_F_SKIP_CRX 1
1437;; Sets g_fBs3TrapNoV86Assist.
1438%define BS3REGCTXRESTORE_F_NO_V86_ASSIST 2
1439;; @}
1440
1441
1442;;
1443; BS3 extended register context (FPU, SSE, AVX, ++)
1444;
1445struc BS3EXTCTX
1446 .u16Magic resw 1 ; uint16_t u16Magic;
1447 .cb resw 1 ; uint16_t cb;
1448 .enmMethod resb 1 ; uint8_t enmMethod;
1449 alignb 8
1450 .fXcr0Nominal resq 1 ; uint64_t fXcr0Nominal;
1451 .fXcr0Saved resq 1 ; uint64_t fXcr0Saved;
1452 alignb 64
1453 .Ctx resb 512
1454endstruc
1455%define BS3EXTCTXMETHOD_ANCIENT 1
1456%define BS3EXTCTXMETHOD_FXSAVE 2
1457%define BS3EXTCTXMETHOD_XSAVE 3
1458
1459;;
1460; BS3 Trap Frame.
1461;
1462struc BS3TRAPFRAME
1463 .bXcpt resb 1
1464 .cbIretFrame resb 1
1465 .uHandlerCs resw 1
1466 .uHandlerSs resw 1
1467 .usAlignment resw 1
1468 .uHandlerRsp resq 1
1469 .fHandlerRfl resq 1
1470 .uErrCd resq 1
1471 .Ctx resb BS3REGCTX_size
1472endstruc
1473AssertCompileSize(BS3TRAPFRAME, 0x20 + 0xd0)
1474
1475;;
1476; Trap record.
1477;
1478struc BS3TRAPREC
1479 ;; The trap location relative to the base address given at
1480 ; registration time.
1481 .offWhere resd 1
1482 ;; What to add to .offWhere to calculate the resume address.
1483 .offResumeAddend resb 1
1484 ;; The trap number.
1485 .u8TrapNo resb 1
1486 ;; The error code if the trap takes one.
1487 .u16ErrCd resw 1
1488endstruc
1489
1490;; The size shift.
1491%define BS3TRAPREC_SIZE_SHIFT 3
1492
1493
1494;; The system call vector.
1495%define BS3_TRAP_SYSCALL 20h
1496
1497;; @name System call numbers (ax)
1498;; @note Pointers are always passed in cx:xDI.
1499;; @{
1500;; Print char (cl).
1501%define BS3_SYSCALL_PRINT_CHR 0001h
1502;; Print string (pointer in cx:xDI, length in xDX).
1503%define BS3_SYSCALL_PRINT_STR 0002h
1504;; Switch to ring-0.
1505%define BS3_SYSCALL_TO_RING0 0003h
1506;; Switch to ring-1.
1507%define BS3_SYSCALL_TO_RING1 0004h
1508;; Switch to ring-2.
1509%define BS3_SYSCALL_TO_RING2 0005h
1510;; Switch to ring-3.
1511%define BS3_SYSCALL_TO_RING3 0006h
1512;; Restore context (pointer in cx:xDI, flags in dx).
1513%define BS3_SYSCALL_RESTORE_CTX 0007h
1514;; Set DRx register (value in ESI, register number in dl).
1515%define BS3_SYSCALL_SET_DRX 0008h
1516;; GET DRx register (register number in dl, value returned in ax:dx).
1517%define BS3_SYSCALL_GET_DRX 0009h
1518;; Set CRx register (value in ESI, register number in dl).
1519%define BS3_SYSCALL_SET_CRX 000ah
1520;; Get CRx register (register number in dl, value returned in ax:dx).
1521%define BS3_SYSCALL_GET_CRX 000bh
1522;; Set the task register (value in dx). */
1523%define BS3_SYSCALL_SET_TR 000ch
1524;; Get the task register (value returned in ax).
1525%define BS3_SYSCALL_GET_TR 000dh
1526;; Set the LDT register (value in dx).
1527%define BS3_SYSCALL_SET_LDTR 000eh
1528;; Get the LDT register (value returned in ax).
1529%define BS3_SYSCALL_GET_LDTR 000fh
1530;; Set XCR0 register (value in edx:esi).
1531%define BS3_SYSCALL_SET_XCR0 0010h
1532;; Get XCR0 register (value returned in edx:eax).
1533%define BS3_SYSCALL_GET_XCR0 0011h
1534;; The last system call value.
1535%define BS3_SYSCALL_LAST BS3_SYSCALL_GET_XCR0
1536;; @}
1537
1538
1539
1540;; @name BS3_SEL_XXX - GDT selectors
1541;; @{
1542
1543%define BS3_SEL_LDT 0010h ;;< The LDT selector (requires setting up).
1544%define BS3_SEL_TSS16 0020h ;;< The 16-bit TSS selector.
1545%define BS3_SEL_TSS16_DF 0028h ;;< The 16-bit TSS selector for double faults.
1546%define BS3_SEL_TSS16_SPARE0 0030h ;;< The 16-bit TSS selector for testing.
1547%define BS3_SEL_TSS16_SPARE1 0038h ;;< The 16-bit TSS selector for testing.
1548%define BS3_SEL_TSS32 0040h ;;< The 32-bit TSS selector.
1549%define BS3_SEL_TSS32_DF 0048h ;;< The 32-bit TSS selector for double faults.
1550%define BS3_SEL_TSS32_SPARE0 0050h ;;< The 32-bit TSS selector for testing.
1551%define BS3_SEL_TSS32_SPARE1 0058h ;;< The 32-bit TSS selector for testing.
1552%define BS3_SEL_TSS32_IOBP_IRB 0060h ;;< The 32-bit TSS selector with I/O permission and interrupt redirection bitmaps.
1553%define BS3_SEL_TSS32_IRB 0068h ;;< The 32-bit TSS selector with only interrupt redirection bitmap (IOPB stripped by limit).
1554%define BS3_SEL_TSS64 0070h ;;< The 64-bit TSS selector.
1555%define BS3_SEL_TSS64_SPARE0 0080h ;;< The 64-bit TSS selector.
1556%define BS3_SEL_TSS64_SPARE1 0090h ;;< The 64-bit TSS selector.
1557%define BS3_SEL_TSS64_IOBP 00a0h ;;< The 64-bit TSS selector.
1558
1559%define BS3_SEL_RMTEXT16_CS 00e0h ;;< Conforming code selector for accessing the BS3RMTEXT16 segment. Runtime config.
1560%define BS3_SEL_X0TEXT16_CS 00e8h ;;< Conforming code selector for accessing the BS3X0TEXT16 segment. Runtime config.
1561%define BS3_SEL_X1TEXT16_CS 00f0h ;;< Conforming code selector for accessing the BS3X1TEXT16 segment. Runtime config.
1562%define BS3_SEL_VMMDEV_MMIO16 00f8h ;;< Selector for accessing the VMMDev MMIO segment at 0100000h from 16-bit code.
1563
1564%define BS3_SEL_RING_SHIFT 8 ;;< For the formula: BS3_SEL_R0_XXX + ((cs & 3) << BS3_SEL_RING_SHIFT)
1565
1566%define BS3_SEL_R0_FIRST 0100h ;;< The first selector in the ring-0 block.
1567%define BS3_SEL_R0_CS16 0100h ;;< ring-0: 16-bit code selector, base 0x10000.
1568%define BS3_SEL_R0_DS16 0108h ;;< ring-0: 16-bit data selector, base 0x23000.
1569%define BS3_SEL_R0_SS16 0110h ;;< ring-0: 16-bit stack selector, base 0x00000.
1570%define BS3_SEL_R0_CS32 0118h ;;< ring-0: 32-bit flat code selector.
1571%define BS3_SEL_R0_DS32 0120h ;;< ring-0: 32-bit flat data selector.
1572%define BS3_SEL_R0_SS32 0128h ;;< ring-0: 32-bit flat stack selector.
1573%define BS3_SEL_R0_CS64 0130h ;;< ring-0: 64-bit flat code selector.
1574%define BS3_SEL_R0_DS64 0138h ;;< ring-0: 64-bit flat data & stack selector.
1575%define BS3_SEL_R0_CS16_EO 0140h ;;< ring-0: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base.
1576%define BS3_SEL_R0_CS16_CNF 0148h ;;< ring-0: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base.
1577%define BS3_SEL_R0_CS16_CNF_EO 0150h ;;< ring-0: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base.
1578%define BS3_SEL_R0_CS32_EO 0158h ;;< ring-0: 32-bit execute-only code selector, not accessed, flat.
1579%define BS3_SEL_R0_CS32_CNF 0160h ;;< ring-0: 32-bit conforming code selector, not accessed, flat.
1580%define BS3_SEL_R0_CS32_CNF_EO 0168h ;;< ring-0: 32-bit execute-only conforming code selector, not accessed, flat.
1581%define BS3_SEL_R0_CS64_EO 0170h ;;< ring-0: 64-bit execute-only code selector, not accessed, flat.
1582%define BS3_SEL_R0_CS64_CNF 0178h ;;< ring-0: 64-bit conforming code selector, not accessed, flat.
1583%define BS3_SEL_R0_CS64_CNF_EO 0180h ;;< ring-0: 64-bit execute-only conforming code selector, not accessed, flat.
1584
1585%define BS3_SEL_R1_FIRST 0200h ;;< The first selector in the ring-1 block.
1586%define BS3_SEL_R1_CS16 0200h ;;< ring-1: 16-bit code selector, base 0x10000.
1587%define BS3_SEL_R1_DS16 0208h ;;< ring-1: 16-bit data selector, base 0x23000.
1588%define BS3_SEL_R1_SS16 0210h ;;< ring-1: 16-bit stack selector, base 0x00000.
1589%define BS3_SEL_R1_CS32 0218h ;;< ring-1: 32-bit flat code selector.
1590%define BS3_SEL_R1_DS32 0220h ;;< ring-1: 32-bit flat data selector.
1591%define BS3_SEL_R1_SS32 0228h ;;< ring-1: 32-bit flat stack selector.
1592%define BS3_SEL_R1_CS64 0230h ;;< ring-1: 64-bit flat code selector.
1593%define BS3_SEL_R1_DS64 0238h ;;< ring-1: 64-bit flat data & stack selector.
1594%define BS3_SEL_R1_CS16_EO 0240h ;;< ring-1: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base.
1595%define BS3_SEL_R1_CS16_CNF 0248h ;;< ring-1: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base.
1596%define BS3_SEL_R1_CS16_CNF_EO 0250h ;;< ring-1: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base.
1597%define BS3_SEL_R1_CS32_EO 0258h ;;< ring-1: 32-bit execute-only code selector, not accessed, flat.
1598%define BS3_SEL_R1_CS32_CNF 0260h ;;< ring-1: 32-bit conforming code selector, not accessed, flat.
1599%define BS3_SEL_R1_CS32_CNF_EO 0268h ;;< ring-1: 32-bit execute-only conforming code selector, not accessed, flat.
1600%define BS3_SEL_R1_CS64_EO 0270h ;;< ring-1: 64-bit execute-only code selector, not accessed, flat.
1601%define BS3_SEL_R1_CS64_CNF 0278h ;;< ring-1: 64-bit conforming code selector, not accessed, flat.
1602%define BS3_SEL_R1_CS64_CNF_EO 0280h ;;< ring-1: 64-bit execute-only conforming code selector, not accessed, flat.
1603
1604%define BS3_SEL_R2_FIRST 0300h ;;< The first selector in the ring-2 block.
1605%define BS3_SEL_R2_CS16 0300h ;;< ring-2: 16-bit code selector, base 0x10000.
1606%define BS3_SEL_R2_DS16 0308h ;;< ring-2: 16-bit data selector, base 0x23000.
1607%define BS3_SEL_R2_SS16 0310h ;;< ring-2: 16-bit stack selector, base 0x00000.
1608%define BS3_SEL_R2_CS32 0318h ;;< ring-2: 32-bit flat code selector.
1609%define BS3_SEL_R2_DS32 0320h ;;< ring-2: 32-bit flat data selector.
1610%define BS3_SEL_R2_SS32 0328h ;;< ring-2: 32-bit flat stack selector.
1611%define BS3_SEL_R2_CS64 0330h ;;< ring-2: 64-bit flat code selector.
1612%define BS3_SEL_R2_DS64 0338h ;;< ring-2: 64-bit flat data & stack selector.
1613%define BS3_SEL_R2_CS16_EO 0340h ;;< ring-2: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base.
1614%define BS3_SEL_R2_CS16_CNF 0348h ;;< ring-2: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base.
1615%define BS3_SEL_R2_CS16_CNF_EO 0350h ;;< ring-2: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base.
1616%define BS3_SEL_R2_CS32_EO 0358h ;;< ring-2: 32-bit execute-only code selector, not accessed, flat.
1617%define BS3_SEL_R2_CS32_CNF 0360h ;;< ring-2: 32-bit conforming code selector, not accessed, flat.
1618%define BS3_SEL_R2_CS32_CNF_EO 0368h ;;< ring-2: 32-bit execute-only conforming code selector, not accessed, flat.
1619%define BS3_SEL_R2_CS64_EO 0370h ;;< ring-2: 64-bit execute-only code selector, not accessed, flat.
1620%define BS3_SEL_R2_CS64_CNF 0378h ;;< ring-2: 64-bit conforming code selector, not accessed, flat.
1621%define BS3_SEL_R2_CS64_CNF_EO 0380h ;;< ring-2: 64-bit execute-only conforming code selector, not accessed, flat.
1622
1623%define BS3_SEL_R3_FIRST 0400h ;;< The first selector in the ring-3 block.
1624%define BS3_SEL_R3_CS16 0400h ;;< ring-3: 16-bit code selector, base 0x10000.
1625%define BS3_SEL_R3_DS16 0408h ;;< ring-3: 16-bit data selector, base 0x23000.
1626%define BS3_SEL_R3_SS16 0410h ;;< ring-3: 16-bit stack selector, base 0x00000.
1627%define BS3_SEL_R3_CS32 0418h ;;< ring-3: 32-bit flat code selector.
1628%define BS3_SEL_R3_DS32 0420h ;;< ring-3: 32-bit flat data selector.
1629%define BS3_SEL_R3_SS32 0428h ;;< ring-3: 32-bit flat stack selector.
1630%define BS3_SEL_R3_CS64 0430h ;;< ring-3: 64-bit flat code selector.
1631%define BS3_SEL_R3_DS64 0438h ;;< ring-3: 64-bit flat data & stack selector.
1632%define BS3_SEL_R3_CS16_EO 0440h ;;< ring-3: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base.
1633%define BS3_SEL_R3_CS16_CNF 0448h ;;< ring-3: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base.
1634%define BS3_SEL_R3_CS16_CNF_EO 0450h ;;< ring-3: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base.
1635%define BS3_SEL_R3_CS32_EO 0458h ;;< ring-3: 32-bit execute-only code selector, not accessed, flat.
1636%define BS3_SEL_R3_CS32_CNF 0460h ;;< ring-3: 32-bit conforming code selector, not accessed, flat.
1637%define BS3_SEL_R3_CS32_CNF_EO 0468h ;;< ring-3: 32-bit execute-only conforming code selector, not accessed, flat.
1638%define BS3_SEL_R3_CS64_EO 0470h ;;< ring-3: 64-bit execute-only code selector, not accessed, flat.
1639%define BS3_SEL_R3_CS64_CNF 0478h ;;< ring-3: 64-bit conforming code selector, not accessed, flat.
1640%define BS3_SEL_R3_CS64_CNF_EO 0480h ;;< ring-3: 64-bit execute-only conforming code selector, not accessed, flat.
1641
1642%define BS3_SEL_SPARE_FIRST 0500h ;;< The first selector in the spare block
1643%define BS3_SEL_SPARE_00 0500h ;;< Spare selector number 00h.
1644%define BS3_SEL_SPARE_01 0508h ;;< Spare selector number 01h.
1645%define BS3_SEL_SPARE_02 0510h ;;< Spare selector number 02h.
1646%define BS3_SEL_SPARE_03 0518h ;;< Spare selector number 03h.
1647%define BS3_SEL_SPARE_04 0520h ;;< Spare selector number 04h.
1648%define BS3_SEL_SPARE_05 0528h ;;< Spare selector number 05h.
1649%define BS3_SEL_SPARE_06 0530h ;;< Spare selector number 06h.
1650%define BS3_SEL_SPARE_07 0538h ;;< Spare selector number 07h.
1651%define BS3_SEL_SPARE_08 0540h ;;< Spare selector number 08h.
1652%define BS3_SEL_SPARE_09 0548h ;;< Spare selector number 09h.
1653%define BS3_SEL_SPARE_0a 0550h ;;< Spare selector number 0ah.
1654%define BS3_SEL_SPARE_0b 0558h ;;< Spare selector number 0bh.
1655%define BS3_SEL_SPARE_0c 0560h ;;< Spare selector number 0ch.
1656%define BS3_SEL_SPARE_0d 0568h ;;< Spare selector number 0dh.
1657%define BS3_SEL_SPARE_0e 0570h ;;< Spare selector number 0eh.
1658%define BS3_SEL_SPARE_0f 0578h ;;< Spare selector number 0fh.
1659%define BS3_SEL_SPARE_10 0580h ;;< Spare selector number 10h.
1660%define BS3_SEL_SPARE_11 0588h ;;< Spare selector number 11h.
1661%define BS3_SEL_SPARE_12 0590h ;;< Spare selector number 12h.
1662%define BS3_SEL_SPARE_13 0598h ;;< Spare selector number 13h.
1663%define BS3_SEL_SPARE_14 05a0h ;;< Spare selector number 14h.
1664%define BS3_SEL_SPARE_15 05a8h ;;< Spare selector number 15h.
1665%define BS3_SEL_SPARE_16 05b0h ;;< Spare selector number 16h.
1666%define BS3_SEL_SPARE_17 05b8h ;;< Spare selector number 17h.
1667%define BS3_SEL_SPARE_18 05c0h ;;< Spare selector number 18h.
1668%define BS3_SEL_SPARE_19 05c8h ;;< Spare selector number 19h.
1669%define BS3_SEL_SPARE_1a 05d0h ;;< Spare selector number 1ah.
1670%define BS3_SEL_SPARE_1b 05d8h ;;< Spare selector number 1bh.
1671%define BS3_SEL_SPARE_1c 05e0h ;;< Spare selector number 1ch.
1672%define BS3_SEL_SPARE_1d 05e8h ;;< Spare selector number 1dh.
1673%define BS3_SEL_SPARE_1e 05f0h ;;< Spare selector number 1eh.
1674%define BS3_SEL_SPARE_1f 05f8h ;;< Spare selector number 1fh.
1675
1676%define BS3_SEL_TILED 0600h ;;< 16-bit data tiling: First - base=0x00000000, limit=64KB, DPL=3.
1677%define BS3_SEL_TILED_LAST 0df8h ;;< 16-bit data tiling: Last - base=0x00ff0000, limit=64KB, DPL=3.
1678%define BS3_SEL_TILED_AREA_SIZE 001000000h ;;< 16-bit data tiling: Size of addressable area, in bytes. (16 MB)
1679
1680%define BS3_SEL_FREE_PART1 0e00h ;;< Free selector space - part \%1.
1681%define BS3_SEL_FREE_PART1_LAST 0ff8h ;;< Free selector space - part \%1, last entry.
1682
1683%define BS3_SEL_TEXT16 1000h ;;< The BS3TEXT16 selector.
1684
1685%define BS3_SEL_FREE_PART2 1008h ;;< Free selector space - part \#2.
1686%define BS3_SEL_FREE_PART2_LAST 17f8h ;;< Free selector space - part \#2, last entry.
1687
1688%define BS3_SEL_TILED_R0 1800h ;;< 16-bit data/stack tiling: First - base=0x00000000, limit=64KB, DPL=0.
1689%define BS3_SEL_TILED_R0_LAST 1ff8h ;;< 16-bit data/stack tiling: Last - base=0x00ff0000, limit=64KB, DPL=0.
1690
1691%define BS3_SEL_SYSTEM16 2000h ;;< The BS3SYSTEM16 selector.
1692
1693%define BS3_SEL_FREE_PART3 2008h ;;< Free selector space - part \%3.
1694%define BS3_SEL_FREE_PART3_LAST 28f8h ;;< Free selector space - part \%3, last entry.
1695
1696%define BS3_SEL_DATA16 2900h ;;< The BS3DATA16/BS3KIT_GRPNM_DATA16 selector.
1697
1698%define BS3_SEL_FREE_PART4 2908h ;;< Free selector space - part \#4.
1699%define BS3_SEL_FREE_PART4_LAST 2f98h ;;< Free selector space - part \#4, last entry.
1700
1701%define BS3_SEL_PRE_TEST_PAGE_08 2fa0h ;;< Selector located 8 selectors before the test page.
1702%define BS3_SEL_PRE_TEST_PAGE_07 2fa8h ;;< Selector located 7 selectors before the test page.
1703%define BS3_SEL_PRE_TEST_PAGE_06 2fb0h ;;< Selector located 6 selectors before the test page.
1704%define BS3_SEL_PRE_TEST_PAGE_05 2fb8h ;;< Selector located 5 selectors before the test page.
1705%define BS3_SEL_PRE_TEST_PAGE_04 2fc0h ;;< Selector located 4 selectors before the test page.
1706%define BS3_SEL_PRE_TEST_PAGE_03 2fc8h ;;< Selector located 3 selectors before the test page.
1707%define BS3_SEL_PRE_TEST_PAGE_02 2fd0h ;;< Selector located 2 selectors before the test page.
1708%define BS3_SEL_PRE_TEST_PAGE_01 2fd8h ;;< Selector located 1 selector before the test page.
1709%define BS3_SEL_TEST_PAGE 2fe0h ;;< Start of the test page intended for playing around with paging and GDT.
1710%define BS3_SEL_TEST_PAGE_00 2fe0h ;;< Test page selector number 00h (convenience).
1711%define BS3_SEL_TEST_PAGE_01 2fe8h ;;< Test page selector number 01h (convenience).
1712%define BS3_SEL_TEST_PAGE_02 2ff0h ;;< Test page selector number 02h (convenience).
1713%define BS3_SEL_TEST_PAGE_03 2ff8h ;;< Test page selector number 03h (convenience).
1714%define BS3_SEL_TEST_PAGE_04 3000h ;;< Test page selector number 04h (convenience).
1715%define BS3_SEL_TEST_PAGE_05 3008h ;;< Test page selector number 05h (convenience).
1716%define BS3_SEL_TEST_PAGE_06 3010h ;;< Test page selector number 06h (convenience).
1717%define BS3_SEL_TEST_PAGE_07 3018h ;;< Test page selector number 07h (convenience).
1718%define BS3_SEL_TEST_PAGE_LAST 3fd0h ;;< The last selector in the spare page.
1719
1720%define BS3_SEL_GDT_LIMIT 3fd8h ;;< The GDT limit.
1721
1722;; @}
1723
1724
1725;
1726; Sanity checks.
1727;
1728%if BS3_ADDR_BS3TEXT16 != BS3_ADDR_LOAD
1729 %error "BS3_ADDR_BS3TEXT16 and BS3_ADDR_LOAD are out of sync"
1730%endif
1731%if (BS3_ADDR_BS3TEXT16 / 16) != BS3_SEL_TEXT16
1732 %error "BS3_ADDR_BS3TEXT16 and BS3_SEL_TEXT16 are out of sync"
1733%endif
1734%if (BS3_ADDR_BS3DATA16 / 16) != BS3_SEL_DATA16
1735 %error "BS3_ADDR_BS3DATA16 and BS3_SEL_DATA16 are out of sync"
1736%endif
1737%if (BS3_ADDR_BS3SYSTEM16 / 16) != BS3_SEL_SYSTEM16
1738 %error "BS3_ADDR_BS3SYSTEM16 and BS3_SEL_SYSTEM16 are out of sync"
1739%endif
1740
1741
1742;; @name BS3CPU_XXX - Bs3CpuDetect_mmm return value and g_bBs3CpuDetected.
1743;; @{
1744%define BS3CPU_8086 0x0001
1745%define BS3CPU_V20 0x0002
1746%define BS3CPU_80186 0x0003
1747%define BS3CPU_80286 0x0004
1748%define BS3CPU_80386 0x0005
1749%define BS3CPU_80486 0x0006
1750%define BS3CPU_Pentium 0x0007
1751%define BS3CPU_PPro 0x0008
1752%define BS3CPU_PProOrNewer 0x0009
1753%define BS3CPU_TYPE_MASK 0x00ff
1754%define BS3CPU_F_CPUID 0x0100
1755%define BS3CPU_F_CPUID_EXT_LEAVES 0x0200
1756%define BS3CPU_F_PAE 0x0400
1757%define BS3CPU_F_PAE_BIT 10
1758%define BS3CPU_F_PSE 0x0800
1759%define BS3CPU_F_PSE_BIT 11
1760%define BS3CPU_F_LONG_MODE 0x1000
1761%define BS3CPU_F_LONG_MODE_BIT 12
1762%define BS3CPU_F_NX 0x2000
1763%define BS3CPU_F_NX_BIT 13
1764;; @}
1765
1766%endif
1767
Note: See TracBrowser for help on using the repository browser.

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