VirtualBox

Changeset 58777 in vbox for trunk/src/VBox/ValidationKit


Ignore:
Timestamp:
Nov 19, 2015 5:20:00 PM (9 years ago)
Author:
vboxsync
Message:

bs3kit: Core allocator code.

Location:
trunk/src/VBox/ValidationKit/bootsectors/bs3kit
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk

    r58761 r58777  
    136136define TOOL_Bs3Vcc64_COMPILE_C_CMDS
    137137$(TOOL_$(VBOX_VCC_TOOL_STEM)AMD64_COMPILE_C_CMDS)
    138         -$(VBoxBs3ObjConverter_1_TARGET) "$(obj)"
     138        $(QUIET)$(VBoxBs3ObjConverter_1_TARGET) "$(obj)"
    139139endef
    140140
     
    375375       bs3-cmn-MemZero.asm \
    376376       bs3-cmn-SlabInit.c \
     377       bs3-cmn-SlabFree.c \
    377378       bs3-cmn-SlabListInit.c \
    378379       bs3-cmn-SlabListAdd.c \
    379380       bs3-cmn-SlabListAlloc.c \
     381       bs3-cmn-SlabListAllocEx.c \
     382       bs3-cmn-SlabListFree.c \
    380383       bs3-cmn-TestData.c \
    381384       bs3-cmn-TestInit.c \
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SlabInit.c

    r58720 r58777  
    11/* $Id$ */
    22/** @file
    3  * BS3Kit - Bs3SlabListAdd
     3 * BS3Kit - Bs3SlabInit
    44 */
    55
     
    3131BS3_DECL(void) Bs3SlabInit(PBS3SLABCLT pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk)
    3232{
     33    uint16_t cBits;
    3334    BS3_ASSERT(RT_IS_POWER_OF_TWO(cbChunk));
    3435    BS3_ASSERT(cbSlab >= cbChunk * 4);
     
    3940    BS3_XPTR_SET_FLAT(BS3SLABCLT, pSlabCtl->pbStart, uFlatSlabPtr);
    4041    pSlabCtl->cbChunk           = cbChunk;
    41     pSlabCtl->cChunks           = cbSlab / cbChunk;
     42    pSlabCtl->cChunkShift       = ASMBitFirstSetU16(cbChunk) - 1;
     43    pSlabCtl->cChunks           = cbSlab >> pSlabCtl->cChunkShift;
    4244    pSlabCtl->cFreeChunks       = pSlabCtl->cChunks;
    43     pSlabCtl->cBits             = RT_ALIGN_T(pSlabCtl->cChunks, 32, uint16_t);
    44     BS3_ASSERT(cbSlabCtl >= RT_OFFSETOF(BS3SLABCTL, bmAllocated[pSlabCtl->cBits >> 3]));
    45     Bs3MemZero(&pSlabCtl->bmAllocated, pSlabCtl->cBits >> 3);
     45    cBits                       = RT_ALIGN_T(pSlabCtl->cChunks, 32, uint16_t);
     46    BS3_ASSERT(cbSlabCtl >= RT_OFFSETOF(BS3SLABCTL, bmAllocated[cBits >> 3]));
     47    Bs3MemZero(&pSlabCtl->bmAllocated, cBits >> 3);
    4648
    4749    /* Mark excess bitmap padding bits as allocated. */
    48     if (pSlabCtl->cBits != pSlabCtl->cChunks)
     50    if (cBits != pSlabCtl->cChunks)
    4951    {
    5052        uint16_t iBit;
    51         for (iBit = pSlabCtl->cChunks; iBit < pSlabCtl->cBits; iBit++)
     53        for (iBit = pSlabCtl->cChunks; iBit < cBits; iBit++)
    5254            ASMBitSet(pSlabCtl->bmAllocated, iBit);
    5355    }
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SlabListAlloc.c

    r58720 r58777  
    2626
    2727#include "bs3kit-template-header.h"
     28#include <iprt/asm.h>
    2829
    29 BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc(PBS3SLABHEAD pHead, uint16_t cChunks)
     30
     31BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc(PBS3SLABHEAD pHead)
    3032{
    31     if (pHead->cFreeChunks >= cChunks)
     33    if (pHead->cFreeChunks)
    3234    {
    3335        PBS3SLABCLT pCur;
     
    3638             pCur = BS3_XPTR_GET(BS3SLABCLT, pCur->pNext))
    3739        {
    38             if (pCur->cFreeChunks >= cChunks)
     40            if (pCur->cFreeChunks)
    3941            {
    40                 int32_t iBit = ASMBitFirstClear(&pCur->bmAllocated, pCur->cBits);
    41                 if (iBit >= )
     42                int32_t iBit = ASMBitFirstClear(&pCur->bmAllocated, pCur->cChunks);
     43                if (iBit >= 0)
    4244                {
     45                    BS3_XPTR_AUTO(void, pvRet);
     46                    ASMBitSet(&pCur->bmAllocated, iBit);
     47                    pCur->cFreeChunks  -= 1;
     48                    pHead->cFreeChunks -= 1;
     49
     50                    BS3_XPTR_SET_FLAT(void, pvRet,
     51                                      BS3_XPTR_GET_FLAT(uint8_t, pCur->pbStart) + ((uint32_t)iBit << pCur->cChunkShift));
     52                    return BS3_XPTR_GET(void, pvRet);
    4353                }
    4454            }
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h

    r58765 r58777  
    683683#endif
    684684
    685 /** @def BS3_XPTR_DEF_MEMB
     685/** @def BS3_XPTR_DEF_MEMBER
    686686 * Defines a pointer member that can be shared by all CPU modes.
    687687 *
     
    690690 */
    691691#define BS3_XPTR_MEMBER(a_Type, a_Name) BS3_XPTR_DEF_INTERNAL(RT_NOTHING, a_Type, a_Name)
     692
     693/** @def BS3_XPTR_DEF_AUTO
     694 * Defines a pointer static variable for working with an XPTR.
     695 *
     696 * This is typically used to convert flat pointers into context specific
     697 * pointers.
     698 *
     699 * @param   a_Type      The type we're pointing to.
     700 * @param   a_Name      The member or variable name.
     701 */
     702#define BS3_XPTR_AUTO(a_Type, a_Name) BS3_XPTR_DEF_INTERNAL(RT_NOTHING, a_Type, a_Name)
    692703
    693704/** @def BS3_XPTR_SET
     
    706717 * Gets the flat address of a cross context pointer.
    707718 *
     719 * @returns 32-bit flat pointer.
    708720 * @param   a_Type      The type we're pointing to.
    709721 * @param   a_Name      The member or variable name.
    710722 */
    711723#define BS3_XPTR_GET_FLAT(a_Type, a_Name) (a_Name.XPtr.uFlat)
     724
     725/** @def BS3_XPTR_GET_FLAT_LOW
     726 * Gets the low 16 bits of the flat address.
     727 *
     728 * @returns Low 16 bits of the flat pointer.
     729 * @param   a_Type      The type we're pointing to.
     730 * @param   a_Name      The member or variable name.
     731 */
     732#define BS3_XPTR_GET_FLAT_LOW(a_Type, a_Name) (a_Name.XPtr.u.uLow)
    712733
    713734
     
    815836 */
    816837
    817 #define BS3_ASSERT(a_Expr) do { } while (0) /**< @todo later */
     838#define BS3_STRICT  /**< @todo later */
     839#ifdef BS3_STRICT
     840# define BS3_ASSERT(a_Expr) do { } while (0) /**< @todo later */
     841#else
     842# define BS3_ASSERT(a_Expr) do { } while (0) /**< @todo later */
     843#endif
    818844
    819845/**
     
    10451071    /** The chunk size. */
    10461072    uint16_t                        cbChunk;
    1047     /** Number of bits in the bitmap (cChunks rounded up to 32). */
    1048     uint16_t                        cBits;
     1073    /** The shift count corresponding to cbChunk.
     1074     * This is for turning a chunk number into a byte offset and vice versa. */
     1075    uint16_t                        cChunkShift;
    10491076    /** Bitmap where set bits indicates allocated blocks (variable size,
    10501077     * multiple of 4). */
     
    10961123
    10971124/**
    1098  * Allocates one or more chunks.
     1125 * Allocates one chunk.
    10991126 *
    11001127 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
    11011128 * @param   pHead           The slab list to allocate from.
     1129 */
     1130BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c16(PBS3SLABHEAD pHead);
     1131BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c32(PBS3SLABHEAD pHead); /**< @copydoc Bs3SlabListAlloc_c16 */
     1132BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c64(PBS3SLABHEAD pHead); /**< @copydoc Bs3SlabListAlloc_c16 */
     1133#define Bs3SlabListAlloc BS3_CMN_NM(Bs3SlabListAlloc) /**< Selects #Bs3SlabListAlloc_c16, #Bs3SlabListAlloc_c32 or #Bs3SlabListAlloc_c64. */
     1134
     1135/**
     1136 * Allocates one or more chunks.
     1137 *
     1138 * @returns Pointer to the request number of chunks on success, NULL if we're
     1139 *          out of chunks.
     1140 * @param   pHead           The slab list to allocate from.
    11021141 * @param   cChunks         The number of contiguous chunks we want.
    1103  */
    1104 BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c16(PBS3SLABHEAD pHead, uint16_t cChunks);
    1105 BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c32(PBS3SLABHEAD pHead, uint16_t cChunks); /**< @copydoc Bs3SlabListAlloc_c16 */
    1106 BS3_DECL(void BS3_FAR *) Bs3SlabListAlloc_c64(PBS3SLABHEAD pHead, uint16_t cChunks); /**< @copydoc Bs3SlabListAlloc_c16 */
    1107 #define Bs3SlabListAlloc BS3_CMN_NM(Bs3SlabListAlloc) /**< Selects #Bs3SlabListAlloc_c16, #Bs3SlabListAlloc_c32 or #Bs3SlabListAlloc_c64. */
    1108 
    1109 /**
    1110  * Frees one or more chunks.
     1142 * @param   fFlags          Flags, see BS3_SLAB_ALLOC_F_XXX
     1143 */
     1144BS3_DECL(void BS3_FAR *) Bs3SlabListAllocEx_c16(PBS3SLABHEAD pHead, uint16_t cChunks, uint16_t fFlags);
     1145BS3_DECL(void BS3_FAR *) Bs3SlabListAllocEx_c32(PBS3SLABHEAD pHead, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabListAllocEx_c16 */
     1146BS3_DECL(void BS3_FAR *) Bs3SlabListAllocEx_c64(PBS3SLABHEAD pHead, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabListAllocEx_c16 */
     1147#define Bs3SlabListAllocEx BS3_CMN_NM(Bs3SlabListAllocEx) /**< Selects #Bs3SlabListAllocEx_c16, #Bs3SlabListAllocEx_c32 or #Bs3SlabListAllocEx_c64. */
     1148/** The chunks must all be in the same 16-bit segment tile. */
     1149#define BS3_SLAB_ALLOC_F_SAME_TILE      UINT16_C(0x0001)
     1150
     1151/**
     1152 * Frees one or more chunks from a slab.
     1153 *
     1154 * @returns Number of chunks actually freed.  When correctly used, this will
     1155 *          match the @a cChunks parameter, of course.
     1156 * @param   pSlabCtl        The slab constrol structure to free from.
     1157 * @param   uFlatChunkPtr   The flat address of the chunks to free.
     1158 * @param   cChunks         The number of contiguous chunks to free.
     1159 */
     1160BS3_DECL(uint16_t) Bs3SlabFree_c16(PBS3SLABCLT pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks);
     1161BS3_DECL(uint16_t) Bs3SlabFree_c32(PBS3SLABCLT pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks); /**< @copydoc Bs3SlabFree_c16 */
     1162BS3_DECL(uint16_t) Bs3SlabFree_c64(PBS3SLABCLT pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks); /**< @copydoc Bs3SlabFree_c16 */
     1163#define Bs3SlabFree BS3_CMN_NM(Bs3SlabFree) /**< Selects #Bs3SlabFree_c16, #Bs3SlabFree_c32 or #Bs3SlabFree_c64. */
     1164
     1165/**
     1166 * Frees one or more chunks from a slab list.
    11111167 *
    11121168 * @param   pHead           The slab list to allocate from.
    11131169 * @param   pvChunks        Pointer to the first chunk to free.
    1114  * @param   cChunks         The number of contiguous chunks we want.
     1170 * @param   cChunks         The number of contiguous chunks to free.
    11151171 */
    11161172BS3_DECL(void) Bs3SlabListFree_c16(PBS3SLABHEAD pHead, void BS3_FAR *pvChunks, uint16_t cChunks);
Note: See TracChangeset for help on using the changeset viewer.

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