VirtualBox

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

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

bs3kit: working on 32-bit IDT.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 30.5 KB
Line 
1; $Id: bs3kit.mac 59258 2016-01-05 17:37:22Z 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;; Wrapper around BITS.
39; Updates __BITS__ (built-in variable in nasm, we work it for yasm).
40; @param %1 The CPU bit count: 16, 32 or 64
41; @remarks ARCH_BITS is not modified and will remain what it was on the
42; assembler command line.
43%macro BS3_SET_BITS 1
44 BITS %1
45
46 %ifdef __YASM__
47 %undef __BITS__
48 %define __BITS__ %1
49 %endif
50
51 %undef BS3_NAME_UNDERSCORE
52 %if %1 == 64
53 %define BS3_NAME_UNDERSCORE
54 %else
55 %define BS3_NAME_UNDERSCORE _
56 %endif
57
58 %undef BS3_ONLY_16BIT
59 %if %1 == 16
60 %define BS3_ONLY_16BIT(a_Expr) a_Expr
61 %else
62 %define BS3_ONLY_16BIT(a_Expr)
63 %endif
64
65 %undef BS3_WRT_RIP
66 %if %1 == 64
67 %define BS3_WRT_RIP wrt rip
68 %else
69 %define BS3_WRT_RIP
70 %endif
71%endmacro
72
73;; Emulate the __BITS__ macro in NASM 2.0+. Follows BS3_SET_BITS.
74%ifdef __YASM__
75 %define __BITS__ ARCH_BITS
76%endif
77
78;; Mostly internal macro. Follows BS3_SET_BITS.
79%if ARCH_BITS == 64
80 %define BS3_NAME_UNDERSCORE
81%else
82 %define BS3_NAME_UNDERSCORE _
83%endif
84
85;; For RIP relative addressing in 64-bit mode and absolute addressing in
86; other modes. Follows BS3_SET_BITS.
87%if ARCH_BITS == 64
88 %define BS3_WRT_RIP wrt rip
89%else
90 %define BS3_WRT_RIP
91%endif
92
93;; For segment overrides and stuff. Follows BS3_SET_BITS.
94%if ARCH_BITS == 16
95 %define BS3_ONLY_16BIT(a_Expr) a_Expr
96%else
97 %define BS3_ONLY_16BIT(a_Expr)
98%endif
99
100;;
101; For instruction that should only be emitted in 16-bit mode. Follows BS3_SET_BITS.
102%macro BS3_ONLY_16BIT_STMT 1+
103 %if __BITS__ == 16
104 %1
105 %endif
106%endmacro
107
108;;
109; For instruction that should only be emitted in 32-bit mode. Follows BS3_SET_BITS.
110%macro BS3_ONLY_32BIT_STMT 1+
111 %if __BITS__ == 32
112 %1
113 %endif
114%endmacro
115
116;;
117; For instruction that should only be emitted in 64-bit mode. Follows BS3_SET_BITS.
118%macro BS3_ONLY_64BIT_STMT 1+
119 %if __BITS__ == 64
120 %1
121 %endif
122%endmacro
123
124
125
126;; @name Segment definitions.
127;; @{
128
129%ifdef ASM_FORMAT_OMF
130; !!HACK ALERT!!
131;
132; To make FLAT actually be flat, i.e. have a base of 0 rather than the same as
133; the target (?) segment, we tweak it a little bit here. We associate a segment
134; with it so that we can get at it in the class/segment ordering directives
135; we pass to the linker. The segment does not contain any data or anything, it
136; is just an empty one which we assign the address of zero.
137;
138; Look for 'clname BS3FLAT segaddr=0x0000' and 'segment BS3FLAT segaddr=0x0000'
139; in the makefile.
140;
141; !!HACK ALERT!!
142segment BS3FLAT use32 class=BS3FLAT
143GROUP FLAT BS3FLAT
144%endif
145
146%macro BS3_BEGIN_TEXT16 0
147 %ifndef BS3_BEGIN_TEXT16_NOT_FIRST
148 %define BS3_BEGIN_TEXT16_NOT_FIRST
149 %ifdef ASM_FORMAT_ELF
150 section BS3TEXT16 align=2 progbits alloc exec nowrite
151 %else
152 section BS3TEXT16 align=2 CLASS=BS3CODE16 PUBLIC USE16
153 %endif
154 %else
155 section BS3TEXT16
156 %endif
157 BS3_SET_BITS 16
158%endmacro
159
160%macro BS3_BEGIN_DATA16 0
161 %ifndef BS3_BEGIN_DATA16_NOT_FIRST
162 %define BS3_BEGIN_DATA16_NOT_FIRST
163 %ifdef ASM_FORMAT_ELF
164 section BS3DATA16 align=2 progbits alloc noexec write
165 %else
166 section BS3DATA16 align=2 CLASS=FAR_DATA PUBLIC USE16
167 %endif
168 %else
169 section BS3DATA16
170 %endif
171 BS3_SET_BITS 16
172%endmacro
173
174%macro BS3_BEGIN_TEXT32 0
175 %ifndef BS3_BEGIN_TEXT32_NOT_FIRST
176 %define BS3_BEGIN_TEXT32_NOT_FIRST
177 %ifdef ASM_FORMAT_ELF
178 section BS3TEXT32 align=1 progbits alloc exec nowrite
179 %else
180 section BS3TEXT32 align=1 CLASS=BS3CODE32 PUBLIC USE32 FLAT
181 %endif
182 %else
183 section BS3TEXT32
184 %endif
185 BS3_SET_BITS 32
186%endmacro
187
188%macro BS3_BEGIN_DATA32 0
189 %ifndef BS3_BEGIN_DATA32_NOT_FIRST
190 %define BS3_BEGIN_DATA32_NOT_FIRST
191 %ifdef ASM_FORMAT_ELF
192 section BS3DATA32 align=16 progbits alloc noexec write
193 %else
194 section BS3DATA32 align=16 CLASS=FAR_DATA PUBLIC USE32 ;FLAT - compiler doesn't make data flat.
195 %endif
196 %else
197 section BS3DATA32
198 %endif
199 BS3_SET_BITS 32
200%endmacro
201
202%macro BS3_BEGIN_TEXT64 0
203 %ifndef BS3_BEGIN_TEXT64_NOT_FIRST
204 %define BS3_BEGIN_TEXT64_NOT_FIRST
205 %ifdef ASM_FORMAT_ELF
206 section BS3TEXT64 align=1 progbits alloc exec nowrite
207 %else
208 section BS3TEXT64 align=1 CLASS=CODE PUBLIC USE32 FLAT ; class=CODE here because of 64-bit cl and/or wlink.exe
209 %endif
210 %else
211 section BS3TEXT64
212 %endif
213 BS3_SET_BITS 64
214%endmacro
215
216%macro BS3_BEGIN_DATA64 0
217 %ifndef BS3_BEGIN_DATA64_NOT_FIRST
218 %define BS3_BEGIN_DATA64_NOT_FIRST
219 %ifdef ASM_FORMAT_ELF
220 section BS3DATA64 align=16 progbits alloc noexec write
221 %else
222 section BS3DATA64 align=16 CLASS=DATA PUBLIC USE32 ;FLAT (see DATA32) ; class=DATA here because of 64-bit cl and/or wlink.exe
223 %endif
224 %else
225 section BS3DATA64
226 %endif
227 BS3_SET_BITS 64
228%endmacro
229
230;; The system data segment containing the GDT, TSSes and IDTs.
231%macro BS3_BEGIN_SYSTEM16 0
232 %ifndef BS3_BEGIN_SYSTEM16_NOT_FIRST
233 %define BS3_BEGIN_SYSTEM16_NOT_FIRST
234 %ifdef ASM_FORMAT_ELF
235 section BS3SYSTEM16 align=16 progbits alloc noexec write
236 %else
237 section BS3SYSTEM16 align=16 CLASS=BS3SYSTEM16 PUBLIC USE16
238 %endif
239 %else
240 section BS3SYSTEM16
241 %endif
242 BS3_SET_BITS 16
243%endmacro
244
245;; Default text section.
246%macro BS3_BEGIN_DEFAULT_TEXT 0
247 %if ARCH_BITS == 16
248 BS3_BEGIN_TEXT16
249 %elif ARCH_BITS == 32
250 BS3_BEGIN_TEXT32
251 %elif ARCH_BITS == 64
252 BS3_BEGIN_TEXT64
253 %else
254 %error "ARCH_BITS must be defined as either 16, 32, or 64!"
255 INVALID_ARCH_BITS
256 %endif
257%endmacro
258
259;; @}
260
261
262;
263; Now, ditch the default 'text' section and define our own NAME macro.
264;
265%ifndef ASM_FORMAT_BIN
266 BS3_BEGIN_DEFAULT_TEXT
267 BS3_BEGIN_DEFAULT_TEXT ; stupid nasm automagically repeats the segment attributes.
268%endif
269
270;; When using watcom + OMF, we're using __cdecl by default, which
271; get an underscore added in front.
272%ifdef ASM_FORMAT_OMF
273 %define NAME(name) _ %+ NAME_OVERLOAD(name)
274%endif
275
276
277;
278; Include the standard headers from iprt.
279;
280
281
282%include "iprt/asmdefs.mac"
283%include "iprt/x86.mac"
284
285
286;;
287; Extern macro which mangles the name using NAME().
288%macro EXTERN 1
289 extern NAME(%1)
290%endmacro
291
292;;
293; Mangles a common name according to the current cpu bit count.
294; @remarks Requires the use of the BS3_SET_BITS macro instead of the BITS directive.
295%define BS3_CMN_NM(a_Name) BS3_NAME_UNDERSCORE %+ a_Name %+ _c %+ __BITS__
296
297;;
298; Extern macro which mangles the common name correctly, redefining the unmangled
299; name to the mangled one for ease of use.
300;
301; @param %1 The unmangled common name.
302;
303; @remarks Must enter the segment in which this name is defined.
304;
305%macro BS3_EXTERN_CMN 1
306 extern BS3_CMN_NM(%1)
307 %undef %1
308 %define %1 BS3_CMN_NM(%1)
309%endmacro
310
311;;
312; Mangles a 16-bit and 32-bit accessible data name.
313; @remarks Requires the use of the BS3_SET_BITS macro instead of the BITS directive.
314%define BS3_DATA_NM(a_Name) _ %+ a_Name
315
316;;
317; Extern macro which mangles a DATA16 symbol correctly, redefining the
318; unmangled name to the mangled one for ease of use.
319;
320; @param %1 The unmangled common name.
321;
322; @remarks Will change to the DATA16 segment, use must switch back afterwards!
323;
324%macro BS3_EXTERN_DATA16 1
325 BS3_BEGIN_DATA16
326 extern _ %+ %1
327 %undef %1
328 %define %1 _ %+ %1
329%endmacro
330
331;;
332; Extern macro which mangles a BS3SYSTEM16 symbol correctly, redefining the
333; unmangled name to the mangled one for ease of use.
334;
335; @param %1 The unmangled common name.
336;
337; @remarks Will change to the SYSTEM16 segment, use must switch back afterwards!
338;
339%macro BS3_EXTERN_SYSTEM16 1
340 BS3_BEGIN_SYSTEM16
341 extern _ %+ %1
342 %undef %1
343 %define %1 _ %+ %1
344%endmacro
345
346
347;;
348; Global name with ELF attributes and size.
349;
350; This differs from GLOBALNAME_EX in that it expects a mangled symbol name,
351; and allows for nasm style symbol size expressions.
352;
353; @param %1 The mangled name.
354; @param %2 Symbol attributes.
355; @param %3 The size expression.
356;
357%macro BS3_GLOBAL_NAME_EX 3
358%ifdef ASM_FORMAT_ELF
359 %ifdef __NASM__
360global %1:%2 %3
361 %else
362global %1:%2
363 %endif
364%else
365global %1
366%endif
367%1:
368%endmacro
369
370;;
371; Global data unmangled label.
372;
373; @param %1 The unmangled name.
374; @param %2 The size (0 is fine).
375;
376%macro BS3_GLOBAL_DATA 2
377BS3_GLOBAL_NAME_EX BS3_DATA_NM(%1), , %2
378%endmacro
379
380;;
381; Starts a procedure.
382;
383; This differs from BEGINPROC in that it expects a mangled symbol name and
384; does the NASM symbol size stuff.
385;
386; @param %1 The mangled name.
387;
388%macro BS3_PROC_BEGIN 1
389BS3_GLOBAL_NAME_EX %1, function, (%1 %+ _EndProc - %1)
390%endmacro
391
392;;
393; Ends a procedure.
394;
395; Counter part to BS3_PROC_BEGIN.
396;
397; @param %1 The mangled name.
398;
399%macro BS3_PROC_END 1
400BS3_GLOBAL_NAME_EX %1 %+ _EndProc, function hidden, (%1 %+ _EndProc - %1)
401 %ifdef ASM_FORMAT_ELF
402 %ifdef __YASM__
403size %1 %1 %+ _EndProc - %1
404size %1 %+ _EndProc 0
405 %endif
406 %endif
407 int3 ; handy and avoids overlapping labels.
408%endmacro
409
410
411;; Convenience macro for defining common procedures.
412%macro BS3_PROC_BEGIN_CMN 1
413 BS3_PROC_BEGIN BS3_CMN_NM(%1)
414%endmacro
415
416;; Convenience macro for defining common procedures.
417%macro BS3_PROC_END_CMN 1
418 BS3_PROC_END BS3_CMN_NM(%1)
419%endmacro
420
421
422;; Convenience macro for defining mode specific procedures.
423%macro BS3_PROC_BEGIN_MODE 1
424 BS3_PROC_BEGIN TMPL_NM(%1)
425%endmacro
426
427;; Convenience macro for defining mode specific procedures.
428%macro BS3_PROC_END_MODE 1
429 BS3_PROC_END TMPL_NM(%1)
430%endmacro
431
432
433;;
434; Prologue hacks for 64-bit code.
435;
436; This saves the four register parameters onto the stack so we can pretend
437; the calling convention is stack based. The 64-bit calling convension is
438; the microsoft one, so this is straight forward.
439;
440; Pairs with BS3_CALL_CONV_EPILOG.
441;
442; @param %1 The number of parameters.
443;
444; @remarks Must be invoked before any stack changing instructions are emitted.
445;
446%macro BS3_CALL_CONV_PROLOG 1
447 %undef BS3_CALL_CONV_PROLOG_PARAMS
448 %define BS3_CALL_CONV_PROLOG_PARAMS %1
449 %if __BITS__ == 64
450 %if %1 >= 1
451 mov [rsp + 008h], rcx
452 %elifdef BS3_STRICT
453 and qword [rsp + 008h], 1
454 %endif
455 %if %1 >= 2
456 mov [rsp + 010h], rdx
457 %elifdef BS3_STRICT
458 and qword [rsp + 010h], 2
459 %endif
460 %if %1 >= 3
461 mov [rsp + 018h], r8
462 %elifdef BS3_STRICT
463 and qword [rsp + 018h], 3
464 %endif
465 %if %1 >= 4
466 mov [rsp + 020h], r9
467 %elifdef BS3_STRICT
468 and qword [rsp + 020h], 4
469 %endif
470 %endif
471%endmacro
472
473;;
474; Epilogue hacks for 64-bit code.
475;
476; Counter part to BS3_CALL_CONV_PROLOG.
477;
478; @param %1 The number of parameters.
479;
480; @remarks Must be invoked right before the return instruction as it uses RSP.
481;
482%macro BS3_CALL_CONV_EPILOG 1
483 %if BS3_CALL_CONV_PROLOG_PARAMS != %1
484 %error "BS3_CALL_CONV_EPILOG argument differs from BS3_CALL_CONV_PROLOG."
485 %endif
486 %if __BITS__ == 64
487 %ifdef BS3_STRICT
488 mov dword [rsp + 008h], 31h
489 mov dword [rsp + 010h], 32h
490 mov dword [rsp + 018h], 33h
491 mov dword [rsp + 020h], 34h
492 %endif
493 %endif
494%endmacro
495
496;;
497; Wrapper for the call instruction that hides calling convension differences.
498;
499; This always calls %1.
500; In 64-bit code, it will load up to 4 parameters into register.
501;
502; @param %1 The function to call (mangled).
503; @param %2 The number of parameters.
504;
505%macro BS3_CALL 2
506 %if __BITS__ == 64
507 %if %2 >= 1
508 mov rcx, [rsp + 008h]
509 %ifdef BS3_STRICT
510 and qword [rsp + 008h], 11h
511 %endif
512 %endif
513 %if %2 >= 2
514 mov rdx, [rsp + 010h]
515 %ifdef BS3_STRICT
516 and qword [rsp + 010h], 12h
517 %endif
518 %endif
519 %if %2 >= 3
520 mov r8, [rsp + 018h]
521 %ifdef BS3_STRICT
522 and qword [rsp + 018h], 13h
523 %endif
524 %endif
525 %if %2 >= 4
526 mov r9, [rsp + 020h]
527 %ifdef BS3_STRICT
528 and qword [rsp + 020h], 14h
529 %endif
530 %endif
531 %endif
532 call %1
533%endmacro
534
535
536;; @name Static Memory Allocation
537; @{
538;; The flat load address for the code after the bootsector.
539%define BS3_ADDR_LOAD 010000h
540;; Where we save the boot registers during init.
541; Located right before the code.
542%define BS3_ADDR_REG_SAVE (BS3_ADDR_LOAD - BS3REGS_size - 8)
543;; Where the stack starts (initial RSP value).
544; Located 16 bytes (assumed by boot sector) before the saved registers. SS.BASE=0.
545%define BS3_ADDR_STACK (BS3_ADDR_REG_SAVE - 16)
546;; The ring-0 stack (8KB) for ring transitions.
547%define BS3_ADDR_STACK_R0 006000h
548;; The ring-1 stack (8KB) for ring transitions.
549%define BS3_ADDR_STACK_R1 004000h
550;; The ring-2 stack (8KB) for ring transitions.
551%define BS3_ADDR_STACK_R2 002000h
552;; IST1 ring-0 stack for long mode (4KB), used for double faults elsewhere.
553%define BS3_ADDR_STACK_R0_IST1 009000h
554;; IST2 ring-0 stack for long mode (3KB), used for spare 0 stack elsewhere.
555%define BS3_ADDR_STACK_R0_IST2 008000h
556;; IST3 ring-0 stack for long mode (1KB).
557%define BS3_ADDR_STACK_R0_IST3 007400h
558;; IST4 ring-0 stack for long mode (1KB), used for spare 1 stack elsewhere.
559%define BS3_ADDR_STACK_R0_IST4 007000h
560;; IST5 ring-0 stack for long mode (1KB).
561%define BS3_ADDR_STACK_R0_IST5 006c00h
562;; IST6 ring-0 stack for long mode (1KB).
563%define BS3_ADDR_STACK_R0_IST6 006800h
564;; IST7 ring-0 stack for long mode (1KB).
565%define BS3_ADDR_STACK_R0_IST7 006400h
566
567;; The base address of the BS3TEXT16 segment (same as BS3_LOAD_ADDR).
568;; @sa BS3_SEL_TEXT16
569%define BS3_ADDR_BS3TEXT16 010000h
570;; The base address of the BS3SYSTEM16 segment.
571;; @sa BS3_SEL_SYSTEM16
572%define BS3_ADDR_BS3SYSTEM16 020000h
573;; The base address of the BS3DATA16 segment.
574;; @sa BS3_SEL_DATA16
575%define BS3_ADDR_BS3DATA16 027000h
576;; @}
577
578
579;;
580; Registers. Used by traps and such.
581;
582struc BS3REGS
583 .rax resq 1
584 .rbx resq 1
585 .rcx resq 1
586 .rdx resq 1
587 .rdi resq 1
588 .rsi resq 1
589 .rbp resq 1
590 .rsp resq 1
591 .rip resq 1
592 .r8 resq 1
593 .r9 resq 1
594 .r10 resq 1
595 .r11 resq 1
596 .r12 resq 1
597 .r13 resq 1
598 .r14 resq 1
599 .r15 resq 1
600 .rflags resq 1
601 .cs resw 1
602 .ds resw 1
603 .es resw 1
604 .fs resw 1
605 .gs resw 1
606 .ss resw 1
607 .cBits resb 1
608 .pad resb 3
609 .cr0 resq 1
610 .cr2 resq 1
611 .cr3 resq 1
612 .cr4 resq 1
613 .cr8 resq 1
614 ;; @todo Add floating point registers when they are active.
615endstruc
616
617
618
619;;
620; Trap record.
621;
622struc BS3TRAPREC
623 ;; The trap location relative to the base address given at
624 ; registration time.
625 .offWhere resd 1
626 ;; What to add to .offWhere to calculate the resume address.
627 .offResumeAddend resb 1
628 ;; The trap number.
629 .u8TrapNo resb 1
630 ;; The error code if the trap takes one.
631 .u16ErrCd resw 1
632endstruc
633
634;; The size shift.
635%define BS3TRAPREC_SIZE_SHIFT 3
636
637
638;; The system call vector.
639%define BS3_TRAP_SYSCALL 20h
640
641;; @name System call numbers
642;; @{
643;; Print char (cl).
644%define BS3_SYSCALL_PRINT_CHR 0ca110001h
645;; Switch to ring-0.
646%define BS3_SYSCALL_TO_RING0 0ca110002h
647;; Switch to ring-1.
648%define BS3_SYSCALL_TO_RING1 0ca110003h
649;; Switch to ring-2.
650%define BS3_SYSCALL_TO_RING2 0ca110004h
651;; Switch to ring-3.
652%define BS3_SYSCALL_TO_RING3 0ca110005h
653;; @}
654
655
656
657;; @name BS3_SEL_XXX - GDT selectors
658;; @{
659
660%define BS3_SEL_LDT 0010h ;;< The LDT selector (requires setting up).
661%define BS3_SEL_TSS16 0020h ;;< The 16-bit TSS selector.
662%define BS3_SEL_TSS16_DF 0028h ;;< The 16-bit TSS selector for double faults.
663%define BS3_SEL_TSS16_SPARE0 0030h ;;< The 16-bit TSS selector for testing.
664%define BS3_SEL_TSS16_SPARE1 0038h ;;< The 16-bit TSS selector for testing.
665%define BS3_SEL_TSS32 0040h ;;< The 32-bit TSS selector.
666%define BS3_SEL_TSS32_DF 0048h ;;< The 32-bit TSS selector for double faults.
667%define BS3_SEL_TSS32_SPARE0 0050h ;;< The 32-bit TSS selector for testing.
668%define BS3_SEL_TSS32_SPARE1 0058h ;;< The 32-bit TSS selector for testing.
669%define BS3_SEL_TSS32_IOBP_IRB 0060h ;;< The 32-bit TSS selector with I/O permission and interrupt redirection bitmaps.
670%define BS3_SEL_TSS32_IRB 0068h ;;< The 32-bit TSS selector with only interrupt redirection bitmap (IOPB stripped by limit).
671%define BS3_SEL_TSS64 0070h ;;< The 64-bit TSS selector.
672%define BS3_SEL_TSS64_SPARE0 0080h ;;< The 64-bit TSS selector.
673%define BS3_SEL_TSS64_SPARE1 0090h ;;< The 64-bit TSS selector.
674%define BS3_SEL_TSS64_IOBP 00a0h ;;< The 64-bit TSS selector.
675
676%define BS3_SEL_VMMDEV_MMIO16 00f8h ;;< Selector for accessing the VMMDev MMIO segment at 0100000h from 16-bit code.
677
678%define BS3_SEL_RING_SHIFT 8 ;;< For the formula: BS3_SEL_R0_XXX + ((cs & 3) << BS3_SEL_RING_SHIFT)
679
680%define BS3_SEL_R0_FIRST 0100h ;;< The first selector in the ring-0 block.
681%define BS3_SEL_R0_CS16 0100h ;;< ring-0: 16-bit code selector, base 0x10000.
682%define BS3_SEL_R0_DS16 0108h ;;< ring-0: 16-bit data selector, base 0x23000.
683%define BS3_SEL_R0_SS16 0110h ;;< ring-0: 16-bit stack selector, base 0x00000.
684%define BS3_SEL_R0_CS32 0118h ;;< ring-0: 32-bit flat code selector.
685%define BS3_SEL_R0_DS32 0120h ;;< ring-0: 32-bit flat data selector.
686%define BS3_SEL_R0_SS32 0128h ;;< ring-0: 32-bit flat stack selector.
687%define BS3_SEL_R0_CS64 0130h ;;< ring-0: 64-bit flat code selector.
688%define BS3_SEL_R0_DS64 0138h ;;< ring-0: 64-bit flat data & stack selector.
689%define BS3_SEL_R0_CS16_EO 0140h ;;< ring-0: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base.
690%define BS3_SEL_R0_CS16_CNF 0148h ;;< ring-0: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base.
691%define BS3_SEL_R0_CS16_CNF_EO 0150h ;;< ring-0: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base.
692%define BS3_SEL_R0_CS32_EO 0158h ;;< ring-0: 32-bit execute-only code selector, not accessed, flat.
693%define BS3_SEL_R0_CS32_CNF 0160h ;;< ring-0: 32-bit conforming code selector, not accessed, flat.
694%define BS3_SEL_R0_CS32_CNF_EO 0168h ;;< ring-0: 32-bit execute-only conforming code selector, not accessed, flat.
695%define BS3_SEL_R0_CS64_EO 0170h ;;< ring-0: 64-bit execute-only code selector, not accessed, flat.
696%define BS3_SEL_R0_CS64_CNF 0178h ;;< ring-0: 64-bit conforming code selector, not accessed, flat.
697%define BS3_SEL_R0_CS64_CNF_EO 0180h ;;< ring-0: 64-bit execute-only conforming code selector, not accessed, flat.
698
699%define BS3_SEL_R1_FIRST 0200h ;;< The first selector in the ring-1 block.
700%define BS3_SEL_R1_CS16 0200h ;;< ring-1: 16-bit code selector, base 0x10000.
701%define BS3_SEL_R1_DS16 0208h ;;< ring-1: 16-bit data selector, base 0x23000.
702%define BS3_SEL_R1_SS16 0210h ;;< ring-1: 16-bit stack selector, base 0x00000.
703%define BS3_SEL_R1_CS32 0218h ;;< ring-1: 32-bit flat code selector.
704%define BS3_SEL_R1_DS32 0220h ;;< ring-1: 32-bit flat data selector.
705%define BS3_SEL_R1_SS32 0228h ;;< ring-1: 32-bit flat stack selector.
706%define BS3_SEL_R1_CS64 0230h ;;< ring-1: 64-bit flat code selector.
707%define BS3_SEL_R1_DS64 0238h ;;< ring-1: 64-bit flat data & stack selector.
708%define BS3_SEL_R1_CS16_EO 0240h ;;< ring-1: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base.
709%define BS3_SEL_R1_CS16_CNF 0248h ;;< ring-1: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base.
710%define BS3_SEL_R1_CS16_CNF_EO 0250h ;;< ring-1: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base.
711%define BS3_SEL_R1_CS32_EO 0258h ;;< ring-1: 32-bit execute-only code selector, not accessed, flat.
712%define BS3_SEL_R1_CS32_CNF 0260h ;;< ring-1: 32-bit conforming code selector, not accessed, flat.
713%define BS3_SEL_R1_CS32_CNF_EO 0268h ;;< ring-1: 32-bit execute-only conforming code selector, not accessed, flat.
714%define BS3_SEL_R1_CS64_EO 0270h ;;< ring-1: 64-bit execute-only code selector, not accessed, flat.
715%define BS3_SEL_R1_CS64_CNF 0278h ;;< ring-1: 64-bit conforming code selector, not accessed, flat.
716%define BS3_SEL_R1_CS64_CNF_EO 0280h ;;< ring-1: 64-bit execute-only conforming code selector, not accessed, flat.
717
718%define BS3_SEL_R2_FIRST 0300h ;;< The first selector in the ring-2 block.
719%define BS3_SEL_R2_CS16 0300h ;;< ring-2: 16-bit code selector, base 0x10000.
720%define BS3_SEL_R2_DS16 0308h ;;< ring-2: 16-bit data selector, base 0x23000.
721%define BS3_SEL_R2_SS16 0310h ;;< ring-2: 16-bit stack selector, base 0x00000.
722%define BS3_SEL_R2_CS32 0318h ;;< ring-2: 32-bit flat code selector.
723%define BS3_SEL_R2_DS32 0320h ;;< ring-2: 32-bit flat data selector.
724%define BS3_SEL_R2_SS32 0328h ;;< ring-2: 32-bit flat stack selector.
725%define BS3_SEL_R2_CS64 0330h ;;< ring-2: 64-bit flat code selector.
726%define BS3_SEL_R2_DS64 0338h ;;< ring-2: 64-bit flat data & stack selector.
727%define BS3_SEL_R2_CS16_EO 0340h ;;< ring-2: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base.
728%define BS3_SEL_R2_CS16_CNF 0348h ;;< ring-2: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base.
729%define BS3_SEL_R2_CS16_CNF_EO 0350h ;;< ring-2: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base.
730%define BS3_SEL_R2_CS32_EO 0358h ;;< ring-2: 32-bit execute-only code selector, not accessed, flat.
731%define BS3_SEL_R2_CS32_CNF 0360h ;;< ring-2: 32-bit conforming code selector, not accessed, flat.
732%define BS3_SEL_R2_CS32_CNF_EO 0368h ;;< ring-2: 32-bit execute-only conforming code selector, not accessed, flat.
733%define BS3_SEL_R2_CS64_EO 0370h ;;< ring-2: 64-bit execute-only code selector, not accessed, flat.
734%define BS3_SEL_R2_CS64_CNF 0378h ;;< ring-2: 64-bit conforming code selector, not accessed, flat.
735%define BS3_SEL_R2_CS64_CNF_EO 0380h ;;< ring-2: 64-bit execute-only conforming code selector, not accessed, flat.
736
737%define BS3_SEL_R3_FIRST 0400h ;;< The first selector in the ring-3 block.
738%define BS3_SEL_R3_CS16 0400h ;;< ring-3: 16-bit code selector, base 0x10000.
739%define BS3_SEL_R3_DS16 0408h ;;< ring-3: 16-bit data selector, base 0x23000.
740%define BS3_SEL_R3_SS16 0410h ;;< ring-3: 16-bit stack selector, base 0x00000.
741%define BS3_SEL_R3_CS32 0418h ;;< ring-3: 32-bit flat code selector.
742%define BS3_SEL_R3_DS32 0420h ;;< ring-3: 32-bit flat data selector.
743%define BS3_SEL_R3_SS32 0428h ;;< ring-3: 32-bit flat stack selector.
744%define BS3_SEL_R3_CS64 0430h ;;< ring-3: 64-bit flat code selector.
745%define BS3_SEL_R3_DS64 0438h ;;< ring-3: 64-bit flat data & stack selector.
746%define BS3_SEL_R3_CS16_EO 0440h ;;< ring-3: 16-bit execute-only code selector, not accessed, 0xfffe limit, CS16 base.
747%define BS3_SEL_R3_CS16_CNF 0448h ;;< ring-3: 16-bit conforming code selector, not accessed, 0xfffe limit, CS16 base.
748%define BS3_SEL_R3_CS16_CNF_EO 0450h ;;< ring-3: 16-bit execute-only conforming code selector, not accessed, 0xfffe limit, CS16 base.
749%define BS3_SEL_R3_CS32_EO 0458h ;;< ring-3: 32-bit execute-only code selector, not accessed, flat.
750%define BS3_SEL_R3_CS32_CNF 0460h ;;< ring-3: 32-bit conforming code selector, not accessed, flat.
751%define BS3_SEL_R3_CS32_CNF_EO 0468h ;;< ring-3: 32-bit execute-only conforming code selector, not accessed, flat.
752%define BS3_SEL_R3_CS64_EO 0470h ;;< ring-3: 64-bit execute-only code selector, not accessed, flat.
753%define BS3_SEL_R3_CS64_CNF 0478h ;;< ring-3: 64-bit conforming code selector, not accessed, flat.
754%define BS3_SEL_R3_CS64_CNF_EO 0480h ;;< ring-3: 64-bit execute-only conforming code selector, not accessed, flat.
755
756%define BS3_SEL_SPARE_FIRST 0500h ;;< The first selector in the spare block
757%define BS3_SEL_SPARE_00 0500h ;;< Spare selector number 00h.
758%define BS3_SEL_SPARE_01 0508h ;;< Spare selector number 01h.
759%define BS3_SEL_SPARE_02 0510h ;;< Spare selector number 02h.
760%define BS3_SEL_SPARE_03 0518h ;;< Spare selector number 03h.
761%define BS3_SEL_SPARE_04 0520h ;;< Spare selector number 04h.
762%define BS3_SEL_SPARE_05 0528h ;;< Spare selector number 05h.
763%define BS3_SEL_SPARE_06 0530h ;;< Spare selector number 06h.
764%define BS3_SEL_SPARE_07 0538h ;;< Spare selector number 07h.
765%define BS3_SEL_SPARE_08 0540h ;;< Spare selector number 08h.
766%define BS3_SEL_SPARE_09 0548h ;;< Spare selector number 09h.
767%define BS3_SEL_SPARE_0a 0550h ;;< Spare selector number 0ah.
768%define BS3_SEL_SPARE_0b 0558h ;;< Spare selector number 0bh.
769%define BS3_SEL_SPARE_0c 0560h ;;< Spare selector number 0ch.
770%define BS3_SEL_SPARE_0d 0568h ;;< Spare selector number 0dh.
771%define BS3_SEL_SPARE_0e 0570h ;;< Spare selector number 0eh.
772%define BS3_SEL_SPARE_0f 0578h ;;< Spare selector number 0fh.
773%define BS3_SEL_SPARE_10 0580h ;;< Spare selector number 10h.
774%define BS3_SEL_SPARE_11 0588h ;;< Spare selector number 11h.
775%define BS3_SEL_SPARE_12 0590h ;;< Spare selector number 12h.
776%define BS3_SEL_SPARE_13 0598h ;;< Spare selector number 13h.
777%define BS3_SEL_SPARE_14 05a0h ;;< Spare selector number 14h.
778%define BS3_SEL_SPARE_15 05a8h ;;< Spare selector number 15h.
779%define BS3_SEL_SPARE_16 05b0h ;;< Spare selector number 16h.
780%define BS3_SEL_SPARE_17 05b8h ;;< Spare selector number 17h.
781%define BS3_SEL_SPARE_18 05c0h ;;< Spare selector number 18h.
782%define BS3_SEL_SPARE_19 05c8h ;;< Spare selector number 19h.
783%define BS3_SEL_SPARE_1a 05d0h ;;< Spare selector number 1ah.
784%define BS3_SEL_SPARE_1b 05d8h ;;< Spare selector number 1bh.
785%define BS3_SEL_SPARE_1c 05e0h ;;< Spare selector number 1ch.
786%define BS3_SEL_SPARE_1d 05e8h ;;< Spare selector number 1dh.
787%define BS3_SEL_SPARE_1e 05f0h ;;< Spare selector number 1eh.
788%define BS3_SEL_SPARE_1f 05f8h ;;< Spare selector number 1fh.
789
790%define BS3_SEL_TILED 0600h ;;< 16-bit data tiling: First - base=0x00000000, limit=64KB.
791%define BS3_SEL_TILED_LAST 0df8h ;;< 16-bit data tiling: Last - base=0x00ff0000, limit=64KB.
792%define BS3_SEL_TILED_AREA_SIZE 001000000h ;;< 16-bit data tiling: Size of addressable area, in bytes. (16 MB)
793
794%define BS3_SEL_FREE_PART1 0e00h ;;< Free selector space - part \#1.
795%define BS3_SEL_FREE_PART1_LAST 0ff8h ;;< Free selector space - part \#1, last entry.
796
797%define BS3_SEL_TEXT16 1000h ;;< The BS3TEXT16 selector.
798
799%define BS3_SEL_FREE_PART2 1008h ;;< Free selector space - part \#2.
800%define BS3_SEL_FREE_PART2_LAST 1ff8h ;;< Free selector space - part \#2, last entry.
801
802%define BS3_SEL_SYSTEM16 2000h ;;< The BS3SYSTEM16 selector.
803
804%define BS3_SEL_FREE_PART3 2008h ;;< Free selector space - part \#3.
805%define BS3_SEL_FREE_PART3_LAST 26f8h ;;< Free selector space - part \#3, last entry.
806
807%define BS3_SEL_DATA16 2700h ;;< The BS3DATA16 selector.
808
809%define BS3_SEL_GDT_LIMIT 2707h ;;< The GDT limit.
810
811;; @}
812
813
814;
815; Sanity checks.
816;
817%if BS3_ADDR_BS3TEXT16 != BS3_ADDR_LOAD
818 %error "BS3_ADDR_BS3TEXT16 and BS3_ADDR_LOAD are out of sync"
819%endif
820%if (BS3_ADDR_BS3TEXT16 / 16) != BS3_SEL_TEXT16
821 %error "BS3_ADDR_BS3TEXT16 and BS3_SEL_TEXT16 are out of sync"
822%endif
823%if (BS3_ADDR_BS3DATA16 / 16) != BS3_SEL_DATA16
824 %error "BS3_ADDR_BS3DATA16 and BS3_SEL_DATA16 are out of sync"
825%endif
826%if (BS3_ADDR_BS3SYSTEM16 / 16) != BS3_SEL_SYSTEM16
827 %error "BS3_ADDR_BS3SYSTEM16 and BS3_SEL_SYSTEM16 are out of sync"
828%endif
829
830;
831; BS3 register context (without FPU).
832;
833struc BS3REGCTX
834 .rax resq 1
835 .rcx resq 1
836 .rdx resq 1
837 .rbx resq 1
838 .rsp resq 1
839 .rbp resq 1
840 .rsi resq 1
841 .rdi resq 1
842 .r8 resq 1
843 .r9 resq 1
844 .r10 resq 1
845 .r11 resq 1
846 .r12 resq 1
847 .r13 resq 1
848 .r14 resq 1
849 .r15 resq 1
850 .rflags resq 1
851 .rip resq 1
852 .cs resw 1
853 .ds resw 1
854 .es resw 1
855 .fs resw 1
856 .gs resw 1
857 .ss resw 1
858 .cBits resb 1
859 .abPadding resb 3
860 .cr0 resq 1
861 .cr2 resq 1
862 .cr3 resq 1
863 .cr4 resq 1
864endstruc
865
866;;
867; BS3 Trap Frame.
868;
869struc BS3TRAPFRAME
870 .bXcpt resb 1
871 .bAlignment resb 1
872 .uHandlerCs resw 1
873 .uHandlerSs resw 1
874 .uHandlerRsp resq 1
875 .fHandlerRfl resq 1
876 .uErrCd resq 1
877 .Ctx resb BS3REGCTX_size
878endstruc
879
880;; Flag for Bs3TrapXxResumeFrame methods.
881%define BS3TRAPRESUME_F_SKIP_CRX 1
882
883%endif
884
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