Changeset 58720 in vbox for trunk/src/VBox/ValidationKit/bootsectors
- Timestamp:
- Nov 17, 2015 1:03:19 PM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 104151
- Location:
- trunk/src/VBox/ValidationKit/bootsectors/bs3kit
- Files:
-
- 5 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk
r58713 r58720 373 373 bs3-cmn-MemPCpy.c \ 374 374 bs3-cmn-MemMove.c \ 375 bs3-cmn-MemZero.asm \ 376 bs3-cmn-SlabInit.c \ 377 bs3-cmn-SlabListInit.c \ 378 bs3-cmn-SlabListAdd.c \ 379 bs3-cmn-SlabListAlloc.c \ 375 380 bs3-cmn-TestData.c \ 376 381 bs3-cmn-TestInit.c \ -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h
r58715 r58720 38 38 #include <iprt/x86.h> 39 39 40 RT_C_DECLS_BEGIN 40 41 41 42 /** @defgroup grp_bs3kit BS3Kit … … 686 687 * Otherwise the limit is 16MB (due to selector tiling). 687 688 */ 688 #define BS3_XPTR_SET (a_Type, a_Name, a_uFlatPtr) \689 #define BS3_XPTR_SET_FLAT(a_Type, a_Name, a_uFlatPtr) \ 689 690 do { a_Name.XPtr.uFlat = (a_uFlatPtr); } while (0) 691 692 /** @def BS3_XPTR_GET_FLAT 693 * Gets the flat address of a cross context pointer. 694 * 695 * @param a_Type The type we're pointing to. 696 * @param a_Name The member or variable name. 697 */ 698 #define BS3_XPTR_GET_FLAT(a_Type, a_Name) (a_Name.XPtr.uFlat) 690 699 691 700 … … 738 747 #endif 739 748 749 /** @def BS3_XPTR_SET 750 * Gets the current context pointer value. 751 * 752 * @returns Usable pointer. 753 * @param a_Type The type we're pointing to. 754 * @param a_Name The member or variable name. 755 * @param a_pValue The new pointer value, current context pointer. 756 */ 757 #if ARCH_BITS == 16 758 # define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \ 759 do { \ 760 a_Type BS3_FAR *pTypeCheck = (a_pValue); \ 761 if (BS3_IS_PROTECTED_MODE()) \ 762 { \ 763 (a_Name).XPtr.u.Low = BS3_FP_OFF(pTypeCheck); \ 764 (a_Name).XPtr.u.High = (BS3_FP_SEG(pTypeCheck) & UINT16_C(0xfff8)) - BS3_SEL_TILED; \ 765 } \ 766 else \ 767 (a_Name).XPtr.uFlat = BS3_FP_OFF(pTypeCheck) + (BS3_FP_SEG(pTypeCheck) << 4); \ 768 } while (0) 769 #elif ARCH_BITS == 32 770 # define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \ 771 do { (a_Name).pTyped = (a_pValue); } while (0) 772 #elif ARCH_BITS == 64 773 # define BS3_XPTR_SET(a_Type, a_Name, a_pValue) \ 774 do { \ 775 a_Type *pTypeCheck = (a_pValue); \ 776 (a_Name).XPtr.uFlat = (uint32_t)(uintptr_t)pTypeCheck; \ 777 } while (0) 778 #else 779 # error "ARCH_BITS" 780 #endif 781 740 782 741 783 /** @def BS3_XPTR_IS_NULL … … 759 801 * @{ 760 802 */ 803 804 #define BS3_ASSERT(a_Expr) do { } while (0) /**< @todo later */ 761 805 762 806 /** … … 923 967 #define Bs3MemMove BS3_CMN_NM(Bs3MemMove) /**< Selects #Bs3MemMove_c16, #Bs3MemMove_c32 or #Bs3MemMove_c64. */ 924 968 969 /** 970 * BSD style bzero. 971 * 972 * @param pvDst The buffer to be zeroed. 973 * @param cbDst The number of bytes to zero. 974 */ 975 BS3_DECL(void) Bs3MemZero_c16(void BS3_FAR *pvDst, size_t cbDst); 976 BS3_DECL(void) Bs3MemZero_c32(void BS3_FAR *pvDst, size_t cbDst); /** @copydoc Bs3MemZero_c16 */ 977 BS3_DECL(void) Bs3MemZero_c64(void BS3_FAR *pvDst, size_t cbDst); /** @copydoc Bs3MemZero_c16 */ 978 #define Bs3MemZero BS3_CMN_NM(Bs3MemZero) /**< Selects #Bs3MemZero_c16, #Bs3MemZero_c32 or #Bs3MemZero_c64. */ 979 925 980 926 981 … … 936 991 937 992 938 typedef struct BS3SLABLIST 993 /** 994 * Slab control structure list head. 995 * 996 * The slabs on the list must all have the same chunk size. 997 */ 998 typedef struct BS3SLABHEAD 939 999 { 940 1000 /** Pointer to the first slab. */ 941 BS3_XPTR_MEMBER(struct BS3SLAB *, pNext);1001 BS3_XPTR_MEMBER(struct BS3SLABCLT, pFirst); 942 1002 /** The allocation chunk size. */ 943 uint16_t cbBlock; 944 945 } BS3SLABLIST; 946 947 typedef struct BS3SLAB 1003 uint16_t cbChunk; 1004 /** Number of slabs in the list. */ 1005 uint16_t cSlabs; 1006 /** Number of chunks in the list. */ 1007 uint32_t cChunks; 1008 /** Number of free chunks. */ 1009 uint32_t cFreeChunks; 1010 } BS3SLABHEAD; 1011 /** Pointer to a slab list head. */ 1012 typedef BS3SLABHEAD BS3_FAR *PBS3SLABHEAD; 1013 1014 /** 1015 * Allocation slab control structure. 1016 * 1017 * This may live at the start of the slab for 4KB slabs, while in a separate 1018 * static location for the larger ones. 1019 */ 1020 typedef struct BS3SLABCLT 948 1021 { 949 /** Pointer to the next slab in this list. */ 950 BS3_XPTR_MEMBER(struct BS3SLAB *, pNext); 951 952 } BS3SLAB; 1022 /** Pointer to the next slab control structure in this list. */ 1023 BS3_XPTR_MEMBER(struct BS3SLABCLT, pNext); 1024 /** Pointer to the slab list head. */ 1025 BS3_XPTR_MEMBER(BS3SLABHEAD, pHead); 1026 /** The base address of the slab. */ 1027 BS3_XPTR_MEMBER(uint8_t, pbStart); 1028 /** Number of chunks in this slab. */ 1029 uint16_t cChunks; 1030 /** Number of currently free chunks. */ 1031 uint16_t cFreeChunks; 1032 /** The chunk size. */ 1033 uint16_t cbChunk; 1034 /** Number of bits in the bitmap (cChunks rounded up to 32). */ 1035 uint16_t cBits; 1036 /** Bitmap where set bits indicates allocated blocks (variable size, 1037 * multiple of 4). */ 1038 uint8_t bmAllocated[4]; 1039 } BS3SLABCLT; 1040 /** Pointer to a bs3kit slab control structure. */ 1041 typedef BS3SLABCLT BS3_FAR *PBS3SLABCLT; 1042 1043 /** 1044 * Initializes a slab. 1045 * 1046 * @param pSlabCtl The slab control structure to initialize. 1047 * @param cbSlabCtl The size of the slab control structure. 1048 * @param uFlatSlabPtr The base address of the slab. 1049 * @param cbSlab The size of the slab. 1050 * @param cbChunk The chunk size. 1051 */ 1052 BS3_DECL(void) Bs3SlabInit_c16(PBS3SLABCLT pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk); 1053 /** @copydoc Bs3SlabInit_c16 */ 1054 BS3_DECL(void) Bs3SlabInit_c32(PBS3SLABCLT pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk); 1055 /** @copydoc Bs3SlabInit_c16 */ 1056 BS3_DECL(void) Bs3SlabInit_c64(PBS3SLABCLT pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk); 1057 #define Bs3SlabInit BS3_CMN_NM(Bs3SlabInit) /**< Selects #Bs3SlabInit_c16, #Bs3SlabInit_c32 or #Bs3SlabInit_c64. */ 1058 1059 1060 /** 1061 * Initializes the given slab list head. 1062 * 1063 * @param pHead The slab list head. 1064 * @param cbChunk The chunk size. 1065 */ 1066 BS3_DECL(void) Bs3SlabListInit_c16(PBS3SLABHEAD pHead, uint16_t cbChunk); 1067 BS3_DECL(void) Bs3SlabListInit_c32(PBS3SLABHEAD pHead, uint16_t cbChunk); /**< @copydoc Bs3SlabListInit_c16 */ 1068 BS3_DECL(void) Bs3SlabListInit_c64(PBS3SLABHEAD pHead, uint16_t cbChunk); /**< @copydoc Bs3SlabListInit_c16 */ 1069 #define Bs3SlabListInit BS3_CMN_NM(Bs3SlabListInit) /**< Selects #Bs3SlabListInit_c16, #Bs3SlabListInit_c32 or #Bs3SlabListInit_c64. */ 1070 1071 /** 1072 * Adds an initialized slab control structure to the list. 1073 * 1074 * @param pHead The slab list head to add it to. 1075 * @param pSlabCtl The slab control structure to add. 1076 */ 1077 BS3_DECL(void) Bs3SlabListAdd_c16(PBS3SLABHEAD pHead, PBS3SLABCLT pSlabCtl); 1078 /** @copydoc Bs3SlabListAdd_c16 */ 1079 BS3_DECL(void) Bs3SlabListAdd_c32(PBS3SLABHEAD pHead, PBS3SLABCLT pSlabCtl); 1080 /** @copydoc Bs3SlabListAdd_c16 */ 1081 BS3_DECL(void) Bs3SlabListAdd_c64(PBS3SLABHEAD pHead, PBS3SLABCLT pSlabCtl); 1082 #define Bs3SlabListAdd BS3_CMN_NM(Bs3SlabListAdd) /**< Selects #Bs3SlabListAdd_c16, #Bs3SlabListAdd_c32 or #Bs3SlabListAdd_c64. */ 1083 1084 /** 1085 * Allocates one or more chunks. 1086 * 1087 * @returns Pointer to a chunk on success, NULL if we're out of chunks. 1088 * @param pHead The slab list to allocate from. 1089 * @param cChunks The number of contiguous chunks we want. 1090 */ 1091 BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c16(PBS3SLABHEAD pHead, uint16_t cChunks); 1092 BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c32(PBS3SLABHEAD pHead, uint16_t cChunks); /**< @copydoc Bs3SlabListAlloc_c16 */ 1093 BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c64(PBS3SLABHEAD pHead, uint16_t cChunks); /**< @copydoc Bs3SlabListAlloc_c16 */ 1094 #define Bs3SlabListAlloc BS3_CMN_NM(Bs3SlabListAlloc) /**< Selects #Bs3SlabListAlloc_c16, #Bs3SlabListAlloc_c32 or #Bs3SlabListAlloc_c64. */ 1095 1096 /** 1097 * Frees one or more chunks. 1098 * 1099 * @param pHead The slab list to allocate from. 1100 * @param pvChunks Pointer to the first chunk to free. 1101 * @param cChunks The number of contiguous chunks we want. 1102 */ 1103 BS3_DECL(void) Bs3SlabListFree_c16(PBS3SLABHEAD pHead, void BS3_FAR *pvChunks, uint16_t cChunks); 1104 BS3_DECL(void) Bs3SlabListFree_c32(PBS3SLABHEAD pHead, void BS3_FAR *pvChunks, uint16_t cChunks); /**< @copydoc Bs3SlabListFree_c16 */ 1105 BS3_DECL(void) Bs3SlabListFree_c64(PBS3SLABHEAD pHead, void BS3_FAR *pvChunks, uint16_t cChunks); /**< @copydoc Bs3SlabListFree_c16 */ 1106 #define Bs3SlabListFree BS3_CMN_NM(Bs3SlabListFree) /**< Selects #Bs3SlabListFree_c16, #Bs3SlabListFree_c32 or #Bs3SlabListFree_c64. */ 1107 1108 /** 1109 * Allocation addressing constraints. 1110 */ 1111 typedef enum BS3MEMKIND 1112 { 1113 /** Invalid zero type. */ 1114 BS3MEMKIND_INVALID = 0, 1115 /** Real mode addressable memory. */ 1116 BS3MEMKIND_REAL, 1117 /** Memory addressable using the 16-bit protected mode tiling. */ 1118 BS3MEMKIND_TILED, 1119 /** Memory addressable using 32-bit flat addressing. */ 1120 BS3MEMKIND_FLAT32, 1121 /** Memory addressable using 64-bit flat addressing. */ 1122 BS3MEMKIND_FLAT64, 1123 /** End of valid types. */ 1124 BS3MEMKIND_END, 1125 } BS3MEMKIND; 1126 1127 /** 1128 * Allocates low memory. 1129 * 1130 * @returns Pointer to a chunk on success, NULL if we're out of chunks. 1131 * @param enmKind The kind of addressing constraints imposed on the 1132 * allocation. 1133 * @param cb How much to allocate. Must be 4KB or less. 1134 */ 1135 BS3_DECL(void BS3_FAR *) Bs3MemAlloc_c16(BS3MEMKIND enmKind, size_t cb); 1136 BS3_DECL(void BS3_FAR *) Bs3MemAlloc_c32(BS3MEMKIND enmKind, size_t cb); /**< @copydoc Bs3MemAlloc_c16 */ 1137 BS3_DECL(void BS3_FAR *) Bs3MemAlloc_c64(BS3MEMKIND enmKind, size_t cb); /**< @copydoc Bs3MemAlloc_c16 */ 1138 #define Bs3MemAlloc BS3_CMN_NM(Bs3MemAlloc) /**< Selects #Bs3MemAlloc_c16, #Bs3MemAlloc_c32 or #Bs3MemAlloc_c64. */ 1139 1140 /** 1141 * Allocates zero'ed memory. 1142 * 1143 * @param enmKind The kind of addressing constraints imposed on the 1144 * allocation. 1145 * @param cb How much to allocate. Must be 4KB or less. 1146 */ 1147 BS3_DECL(void BS3_FAR *) Bs3MemAllocZ_c16(BS3MEMKIND enmKind, size_t cb); 1148 BS3_DECL(void BS3_FAR *) Bs3MemAllocZ_c32(BS3MEMKIND enmKind, size_t cb); /**< @copydoc Bs3MemAllocZ_c16 */ 1149 BS3_DECL(void BS3_FAR *) Bs3MemAllocZ_c64(BS3MEMKIND enmKind, size_t cb); /**< @copydoc Bs3MemAllocZ_c16 */ 1150 #define Bs3MemAllocZ BS3_CMN_NM(Bs3MemAllocZ) /**< Selects #Bs3MemAllocZ_c16, #Bs3MemAllocZ_c32 or #Bs3MemAllocZ_c64. */ 1151 1152 /** 1153 * Frees memory. 1154 * 1155 * @returns Pointer to a chunk on success, NULL if we're out of chunks. 1156 * @param pv The memory to free (returned by #Bs3MemAlloc). 1157 * @param cb The size of the allocation. 1158 */ 1159 BS3_DECL(void) Bs3MemFree_c16(void BS3_FAR *pv, size_t cb); 1160 BS3_DECL(void) Bs3MemFree_c32(void BS3_FAR *pv, size_t cb); /**< @copydoc Bs3MemFree_c16 */ 1161 BS3_DECL(void) Bs3MemFree_c64(void BS3_FAR *pv, size_t cb); /**< @copydoc Bs3MemFree_c16 */ 1162 #define Bs3MemFree BS3_CMN_NM(Bs3MemFree) /**< Selects #Bs3MemFree_c16, #Bs3MemFree_c32 or #Bs3MemFree_c64. */ 953 1163 954 1164 /** @} */ … … 969 1179 /** @} */ 970 1180 971 #endif 972 1181 RT_C_DECLS_END 1182 1183 #endif 1184
Note:
See TracChangeset
for help on using the changeset viewer.