VirtualBox

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

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

bs3kit: move real mode version of Bs3TestDoModes out of the default 16-bit code segment.

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