Changeset 58715 in vbox for trunk/src/VBox
- Timestamp:
- Nov 16, 2015 11:14:16 PM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 104143
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h
r58695 r58715 273 273 * @param a_pv Far pointer. 274 274 */ 275 # define BS3_FP_SEG(a_pv) ((uint16_t)( void __seg *)(void BS3_FAR *)(a_pv))275 # define BS3_FP_SEG(a_pv) ((uint16_t)(__segment)(void BS3_FAR *)(a_pv)) 276 276 /** @def BS3_FP_OFF 277 277 * Get the segment offset part of a far pointer. … … 285 285 * @param a_pv Far pointer. 286 286 */ 287 # define BS3_FP_MAKE(a_uSeg, a_off) (( void __seg *)(a_uSeg) + (void __near *)(a_off))287 # define BS3_FP_MAKE(a_uSeg, a_off) (((__segment)(a_uSeg)) :> ((void __near *)(a_off))) 288 288 #endif 289 289 … … 579 579 extern X86DESC BS3_DATA_NM(Bs3LdtEnd); 580 580 581 /** @} */ 582 583 584 #ifdef __WATCOMC__ 585 /** 586 * Executes the SMSW instruction and returns the value. 587 * 588 * @returns Machine status word. 589 */ 590 uint16_t Bs3AsmSmsw(void); 591 # pragma aux Bs3AsmSmsw = \ 592 "smsw ax" \ 593 value [ax] modify exact [ax] nomemory; 594 #endif 595 596 597 /** @def BS3_IS_PROTECTED_MODE 598 * @returns true if protected mode, false if not. */ 599 #if ARCH_BITS != 16 600 # define BS3_IS_PROTECTED_MODE() (true) 601 #else 602 # define BS3_IS_PROTECTED_MODE() (Bs3AsmSmsw() & 1 /*PE*/) 603 #endif 604 605 606 /** @defgroup bs3kit_cross_ptr Cross context pointer type 607 * 608 * The cross context pointer type is 609 * 610 * @{ */ 611 612 /** 613 * Cross context pointer base type. 614 */ 615 #pragma pack(4) 616 typedef union BS3XPTR 617 { 618 /** The flat pointer. */ 619 uint32_t uFlat; 620 /** 16-bit view. */ 621 struct 622 { 623 uint16_t uLow; 624 uint16_t uHigh; 625 } u; 626 #if ARCH_BITS == 16 627 /** 16-bit near pointer. */ 628 void __near *pvNear; 629 #elif ARCH_BITS == 32 630 /** 32-bit pointer. */ 631 void *pvRaw; 632 #endif 633 } BS3XPTR; 634 #pragma pack() 635 636 637 /** @def BS3_XPTR_DEF_INTERNAL 638 * Internal worker. 639 * 640 * @param a_Scope RT_NOTHING if structure or global, static or extern 641 * otherwise. 642 * @param a_Type The type we're pointing to. 643 * @param a_Name The member or variable name. 644 * @internal 645 */ 646 #if ARCH_BITS == 16 647 # define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \ 648 a_Scope union \ 649 { \ 650 BS3XPTR XPtr; \ 651 a_Type __near *pNearTyped; \ 652 } a_Name 653 #elif ARCH_BITS == 32 654 # define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \ 655 a_Scope union \ 656 { \ 657 BS3XPTR XPtr; \ 658 a_Type *pTyped; \ 659 } a_Name 660 #elif ARCH_BITS == 64 661 # define BS3_XPTR_DEF_INTERNAL(a_Scope, a_Type, a_Name) \ 662 a_Scope union \ 663 { \ 664 BS3XPTR XPtr; \ 665 a_Type *pTyped; \ 666 } a_Name 667 #else 668 # error "ARCH_BITS" 669 #endif 670 671 /** @def BS3_XPTR_DEF_MEMB 672 * Defines a pointer member that can be shared by all CPU modes. 673 * 674 * @param a_Type The type we're pointing to. 675 * @param a_Name The member or variable name. 676 */ 677 #define BS3_XPTR_MEMBER(a_Type, a_Name) BS3_XPTR_DEF_INTERNAL(RT_NOTHING, a_Type, a_Name) 678 679 /** @def BS3_XPTR_SET 680 * Sets a cross context pointer. 681 * 682 * @param a_Type The type we're pointing to. 683 * @param a_Name The member or variable name. 684 * @param a_uFlatPtr The flat pointer value to assign. If the x-pointer is 685 * used in real mode, this must be less than 1MB. 686 * Otherwise the limit is 16MB (due to selector tiling). 687 */ 688 #define BS3_XPTR_SET(a_Type, a_Name, a_uFlatPtr) \ 689 do { a_Name.XPtr.uFlat = (a_uFlatPtr); } while (0) 690 691 692 #if ARCH_BITS == 16 693 694 /** 695 * Gets the current ring number. 696 * @returns Ring number. 697 */ 698 DECLINLINE(uint16_t) Bs3Sel16GetCurRing(void); 699 # pragma aux Bs3Sel16GetCurRing = \ 700 "mov ax, ss" \ 701 "and ax, 3" \ 702 value [ax dx] modify exact [ax] nomemory; 703 704 /** 705 * Converts the high word of a flat pointer into a 16-bit selector. 706 * 707 * This makes use of the tiled area. It also handles real mode. 708 * 709 * @returns Segment selector value. 710 * @param uHigh The high part of flat pointer. 711 * @sa BS3_XPTR_GET, BS3_XPTR_SET 712 */ 713 DECLINLINE(__segment) Bs3Sel16HighFlatPtrToSelector(uint16_t uHigh) 714 { 715 if (BS3_IS_PROTECTED_MODE()) 716 return (__segment)(((uHigh << 3) + BS3_SEL_TILED) | Bs3Sel16GetCurRing()); 717 return (__segment)(uHigh << 12); 718 } 719 720 #endif /* ARCH_BITS == 16*/ 721 722 /** @def BS3_XPTR_GET 723 * Gets the current context pointer value. 724 * 725 * @returns Usable pointer. 726 * @param a_Type The type we're pointing to. 727 * @param a_Name The member or variable name. 728 */ 729 #if ARCH_BITS == 16 730 # define BS3_XPTR_GET(a_Type, a_Name) \ 731 ((a_Type BS3_FAR *)BS3_FP_MAKE(Bs3Sel16HighFlatPtrToSelector((a_Name).XPtr.u.uHigh), (a_Name).pNearTyped)) 732 #elif ARCH_BITS == 32 733 # define BS3_XPTR_GET(a_Type, a_Name) ((a_Name).pTyped) 734 #elif ARCH_BITS == 64 735 # define BS3_XPTR_GET(a_Type, a_Name) ((a_Type *)(uintptr_t)(a_Name).XPtr.uFlat)) 736 #else 737 # error "ARCH_BITS" 738 #endif 739 740 741 /** @def BS3_XPTR_IS_NULL 742 * Checks if the cross context pointer is NULL. 743 * 744 * @returns true if NULL, false if not. 745 * @param a_Type The type we're pointing to. 746 * @param a_Name The member or variable name. 747 */ 748 #define BS3_XPTR_IS_NULL(a_Type, a_Name) ((a_Name).XPtr.uFlat == 0) 749 /** @} */ 581 750 582 751 … … 767 936 768 937 938 typedef struct BS3SLABLIST 939 { 940 /** Pointer to the first slab. */ 941 BS3_XPTR_MEMBER(struct BS3SLAB *, pNext); 942 /** The allocation chunk size. */ 943 uint16_t cbBlock; 944 945 } BS3SLABLIST; 946 947 typedef struct BS3SLAB 948 { 949 /** Pointer to the next slab in this list. */ 950 BS3_XPTR_MEMBER(struct BS3SLAB *, pNext); 951 952 } BS3SLAB; 953 769 954 /** @} */ 770 955
Note:
See TracChangeset
for help on using the changeset viewer.