VirtualBox

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


Ignore:
Timestamp:
Nov 20, 2015 3:38:25 AM (9 years ago)
Author:
vboxsync
Message:

bs3kit: Worst bugs out of memory routines and related functions.

Location:
trunk/src/VBox/ValidationKit/bootsectors/bs3kit
Files:
5 added
14 edited
1 copied

Legend:

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

    r58785 r58789  
    364364        bs3-cmn-PrintChr.asm \
    365365        bs3-cmn-PrintU32.asm \
     366        bs3-cmn-PrintX32.asm \
    366367        bs3-cmn-PrintStr.c \
    367368       bs3-cmn-PrintStrColonSpaces.asm \
     
    374375       bs3-cmn-MemMove.c \
    375376       bs3-cmn-MemZero.asm \
     377       bs3-cmn-MemAlloc.c \
     378       bs3-cmn-MemAllocZ.c \
     379       bs3-cmn-MemFree.c \
    376380       bs3-cmn-SlabInit.c \
     381       bs3-cmn-SlabAlloc.c \
     382       bs3-cmn-SlabAllocEx.c \
    377383       bs3-cmn-SlabFree.c \
    378384       bs3-cmn-SlabListInit.c \
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PrintU32.asm

    r58628 r58789  
    3333; Prints a 32-bit unsigned integer value.
    3434;
    35 ; @param    [xSP + xCB]     32-bit value to format and print.
     35; @param    [xBP + xCB*2]   32-bit value to format and print.
    3636;
    3737BS3_PROC_BEGIN_CMN Bs3PrintU32
     
    4343        push    sCX
    4444        push    sBX
     45        BS3_ONLY_16BIT_STMT push ds
    4546
    4647        mov     eax, [xBP + xCB*2]
     
    4849        ; Allocate a stack buffer and terminate it. ds:bx points ot the end.
    4950        sub     xSP, 30h
     51        BS3_ONLY_16BIT_STMT mov bx, ss
     52        BS3_ONLY_16BIT_STMT mov ds, bx
    5053        mov     xBX, xSP
    5154        add     xBX, 2fh
     
    6871
    6972        add     xSP, 30h + BS3_ONLY_16BIT(2 + ) xCB
     73        BS3_ONLY_16BIT_STMT pop ds
    7074        pop     sBX
    7175        pop     sCX
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PrintX32.asm

    r58779 r58789  
    3131
    3232;;
    33 ; Prints a 32-bit unsigned integer value.
     33; Prints a 32-bit unsigned integer value as hex.
    3434;
    35 ; @param    [xSP + xCB]     32-bit value to format and print.
     35; @param    [xBP + xCB*2]   32-bit value to format and print.
    3636;
    37 BS3_PROC_BEGIN_CMN Bs3PrintU32
     37BS3_PROC_BEGIN_CMN Bs3PrintX32
    3838        BS3_CALL_CONV_PROLOG 1
    3939        push    xBP
     
    4343        push    sCX
    4444        push    sBX
     45        BS3_ONLY_16BIT_STMT push ds
    4546
    4647        mov     eax, [xBP + xCB*2]
     
    4849        ; Allocate a stack buffer and terminate it. ds:bx points ot the end.
    4950        sub     xSP, 30h
     51        BS3_ONLY_16BIT_STMT mov bx, ss
     52        BS3_ONLY_16BIT_STMT mov ds, bx
    5053        mov     xBX, xSP
    5154        add     xBX, 2fh
    5255        mov     byte [xBX], 0
    5356
    54         mov     ecx, 10                 ; what to divide by
     57        mov     ecx, 16                 ; what to divide by
    5558.next:
    5659        xor     edx, edx
    5760        div     ecx                     ; edx:eax / ecx -> eax and rest in edx.
     61        cmp     dl, 10
     62        jb      .decimal
     63        add     dl, 'a' - '0' - 10
     64.decimal:
    5865        add     dl, '0'
    5966        dec     xBX
     
    6875
    6976        add     xSP, 30h + BS3_ONLY_16BIT(2 + ) xCB
     77        BS3_ONLY_16BIT_STMT pop ds
    7078        pop     sBX
    7179        pop     sCX
     
    7583        BS3_CALL_CONV_EPILOG 1
    7684        ret
    77 BS3_PROC_END_CMN   Bs3PrintU32
     85BS3_PROC_END_CMN   Bs3PrintX32
    7886
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SlabFree.c

    r58777 r58789  
    2929
    3030
    31 BS3_DECL(uint16_t) Bs3SlabFree(PBS3SLABCLT pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks)
     31BS3_DECL(uint16_t) Bs3SlabFree(PBS3SLABCTL pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks)
    3232{
    3333    uint16_t cFreed = 0;
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SlabInit.c

    r58777 r58789  
    2929
    3030
    31 BS3_DECL(void) Bs3SlabInit(PBS3SLABCLT pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk)
     31BS3_DECL(void) Bs3SlabInit(PBS3SLABCTL pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk)
    3232{
    3333    uint16_t cBits;
     
    3636    BS3_ASSERT(!(uFlatSlabPtr & (cbChunk - 1)));
    3737
    38     BS3_XPTR_SET_FLAT(BS3SLABCLT, pSlabCtl->pNext, 0);
    39     BS3_XPTR_SET_FLAT(BS3SLABCLT, pSlabCtl->pHead, 0);
    40     BS3_XPTR_SET_FLAT(BS3SLABCLT, pSlabCtl->pbStart, uFlatSlabPtr);
     38    BS3_XPTR_SET_FLAT(BS3SLABCTL, pSlabCtl->pNext, 0);
     39    BS3_XPTR_SET_FLAT(BS3SLABCTL, pSlabCtl->pHead, 0);
     40    BS3_XPTR_SET_FLAT(BS3SLABCTL, pSlabCtl->pbStart, uFlatSlabPtr);
    4141    pSlabCtl->cbChunk           = cbChunk;
    4242    pSlabCtl->cChunkShift       = ASMBitFirstSetU16(cbChunk) - 1;
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SlabListAdd.c

    r58720 r58789  
    2828
    2929
    30 BS3_DECL(void) Bs3SlabListAdd(PBS3SLABHEAD pHead, PBS3SLABCLT pSlabCtl)
     30BS3_DECL(void) Bs3SlabListAdd(PBS3SLABHEAD pHead, PBS3SLABCTL pSlabCtl)
    3131{
    3232    BS3_ASSERT(pHead->cbChunk == pSlabCtl->cbChunk);
    3333    BS3_ASSERT(BS3_XPTR_IS_NULL(BS3SLABHEAD, pSlabCtl->pNext));
    3434
    35     BS3_XPTR_SET_FLAT(BS3SLABCLT, pSlabCtl->pNext, BS3_XPTR_GET_FLAT(BS3SLABCLT, pHead->pFirst));
    36     BS3_XPTR_SET(BS3SLABCLT, pHead->pFirst, pSlabCtl);
     35    BS3_XPTR_SET_FLAT(BS3SLABCTL, pSlabCtl->pNext, BS3_XPTR_GET_FLAT(BS3SLABCTL, pHead->pFirst));
     36    BS3_XPTR_SET(BS3SLABCTL, pHead->pFirst, pSlabCtl);
     37
    3738    pHead->cSlabs      += 1;
    3839    pHead->cChunks     += pSlabCtl->cChunks;
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SlabListAlloc.c

    r58777 r58789  
    3333    if (pHead->cFreeChunks)
    3434    {
    35         PBS3SLABCLT pCur;
    36         for (pCur = BS3_XPTR_GET(BS3SLABCLT, pHead->pFirst);
     35        PBS3SLABCTL pCur;
     36        for (pCur = BS3_XPTR_GET(BS3SLABCTL, pHead->pFirst);
    3737             pCur != NULL;
    38              pCur = BS3_XPTR_GET(BS3SLABCLT, pCur->pNext))
     38             pCur = BS3_XPTR_GET(BS3SLABCTL, pCur->pNext))
    3939        {
    4040            if (pCur->cFreeChunks)
    4141            {
    42                 int32_t iBit = ASMBitFirstClear(&pCur->bmAllocated, pCur->cChunks);
    43                 if (iBit >= 0)
     42                void BS3_FAR *pvRet = Bs3SlabAlloc(pCur);
     43                if (pvRet)
    4444                {
    45                     BS3_XPTR_AUTO(void, pvRet);
    46                     ASMBitSet(&pCur->bmAllocated, iBit);
    47                     pCur->cFreeChunks  -= 1;
    4845                    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);
     46                    return pvRet;
    5347                }
    5448            }
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SlabListAllocEx.c

    r58777 r58789  
    3434    if (pHead->cFreeChunks >= cChunks)
    3535    {
    36         PBS3SLABCLT pCur;
    37         for (pCur = BS3_XPTR_GET(BS3SLABCLT, pHead->pFirst);
     36        PBS3SLABCTL pCur;
     37        for (pCur = BS3_XPTR_GET(BS3SLABCTL, pHead->pFirst);
    3838             pCur != NULL;
    39              pCur = BS3_XPTR_GET(BS3SLABCLT, pCur->pNext))
     39             pCur = BS3_XPTR_GET(BS3SLABCTL, pCur->pNext))
    4040        {
    4141            if (pCur->cFreeChunks >= cChunks)
    4242            {
    43                 int32_t iBit = ASMBitFirstClear(&pCur->bmAllocated, pCur->cChunks);
    44                 if (iBit >= 0)
     43                void BS3_FAR *pvRet = Bs3SlabAllocEx(pCur, cChunks, fFlags);
     44                if (pvRet)
    4545                {
    46                     while ((uint32_t)iBit + cChunks <= pCur->cChunks)
    47                     {
    48                         /* Check that we've got the requested number of free chunks here. */
    49                         uint16_t i;
    50                         for (i = 1; i < cChunks; i++)
    51                             if (!ASMBitTest(&pCur->bmAllocated, iBit + i))
    52                                 break;
    53                         if (i == cChunks)
    54                         {
    55                             BS3_XPTR_AUTO(void, pvRet);
    56 
    57                             /* Check if the chunks are all in the same tiled segment. */
    58                             BS3_XPTR_SET_FLAT(void, pvRet,
    59                                               BS3_XPTR_GET_FLAT(uint8_t, pCur->pbStart) + ((uint32_t)iBit << pCur->cChunkShift));
    60                             if (   !(fFlags & BS3_SLAB_ALLOC_F_SAME_TILE)
    61                                 ||    (BS3_XPTR_GET_FLAT(void, pvRet) >> 16)
    62                                    == (BS3_XPTR_GET_FLAT(void, pvRet) + ((uint32_t)cChunks << pCur->cChunkShift)) )
    63                             {
    64                                 /* Complete the allocation. */
    65                                 for (i = 0; i < cChunks; i++)
    66                                     ASMBitSet(&pCur->bmAllocated, iBit + i);
    67                                 pCur->cFreeChunks  -= cChunks;
    68                                 pHead->cFreeChunks -= cChunks;
    69 
    70                                 return BS3_XPTR_GET(void, pvRet);
    71                             }
    72 
    73                             /*
    74                              * We're crossing a tiled segment boundrary.
    75                              * Skip to the start of the next segment and retry there.
    76                              * (We already know that the first chunk in the next tiled
    77                              * segment is free, otherwise we wouldn't have a crossing.)
    78                              */
    79                             BS3_ASSERT(((uint32_t)cChunks << pCur->cChunkShift) <= _64K);
    80                             i = BS3_XPTR_GET_FLAT_LOW(void, pvRet);
    81                             i = UINT16_C(0) - i;
    82                             i >>= pCur->cChunkShift;
    83                             iBit += i;
    84                         }
    85                         else
    86                         {
    87                             /*
    88                              * Continue searching.
    89                              */
    90                             iBit = ASMBitNextClear(&pCur->bmAllocated, pCur->cChunks, iBit + i);
    91                             if (iBit < 0)
    92                                 break;
    93                         }
    94                     }
     46                    pHead->cFreeChunks -= cChunks;
     47                    return pvRet;
    9548                }
    9649            }
     
    10053}
    10154
    102 
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SlabListFree.c

    r58777 r58789  
    3333    if (cChunks > 0)
    3434    {
    35         PBS3SLABCLT         pCur;
     35        PBS3SLABCTL         pCur;
    3636        BS3_XPTR_AUTO(void, pvFlatChunk);
    3737        BS3_XPTR_SET(void,  pvFlatChunk, pvChunks);
    3838
    39         for (pCur = BS3_XPTR_GET(BS3SLABCLT, pHead->pFirst);
     39        for (pCur = BS3_XPTR_GET(BS3SLABCTL, pHead->pFirst);
    4040             pCur != NULL;
    41              pCur = BS3_XPTR_GET(BS3SLABCLT, pCur->pNext))
     41             pCur = BS3_XPTR_GET(BS3SLABCTL, pCur->pNext))
    4242        {
    4343            if (  ((BS3_XPTR_GET_FLAT(void, pvFlatChunk) - BS3_XPTR_GET_FLAT(uint8_t, pCur->pbStart)) >> pCur->cChunkShift)
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SlabListInit.c

    r58720 r58789  
    3131{
    3232    BS3_ASSERT(RT_IS_POWER_OF_TWO(cbChunk));
    33     BS3_XPTR_SET(struct BS3SLABCLT, pHead->pFirst, 0);
     33    BS3_XPTR_SET(struct BS3SLABCTL, pHead->pFirst, 0);
    3434    pHead->cbChunk     = cbChunk;
    3535    pHead->cSlabs      = 0;
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-memory.h

    r58785 r58789  
    2929
    3030#include "bs3kit.h"
     31#include <iprt/asm.h>
    3132
    3233RT_C_DECLS_BEGIN;
    3334
    3435
    35 typedef union BS3SLABCLTLOW
     36typedef union BS3SLABCTLLOW
    3637{
    37     BS3SLABCLT  Core;
    38     uint32_t    au32Alloc[(sizeof(BS3SLABCLT) + (0xA0000 / _4K / 8) ) / 4];
    39 } BS3SLABCLTLOW;
    40 extern BS3SLABCLTLOW            BS3_DATA_NM(g_LowMemory);
     38    BS3SLABCTL  Core;
     39    uint32_t    au32Alloc[(sizeof(BS3SLABCTL) + (0xA0000 / _4K / 8) ) / 4];
     40} BS3SLABCTLLOW;
     41extern BS3SLABCTLLOW            BS3_DATA_NM(g_Bs3Mem4KLow);
    4142
    4243
    4344typedef union BS3SLABCTLUPPERTILED
    4445{
    45     BS3SLABCLT  Core;
    46     uint32_t    au32Alloc[(sizeof(BS3SLABCLT) + ((BS3_SEL_TILED_AREA_SIZE - _1M) / _4K / 8) ) / 4];
     46    BS3SLABCTL  Core;
     47    uint32_t    au32Alloc[(sizeof(BS3SLABCTL) + ((BS3_SEL_TILED_AREA_SIZE - _1M) / _4K / 8) ) / 4];
    4748} BS3SLABCTLUPPERTILED;
    48 extern BS3SLABCTLUPPERTILED     BS3_DATA_NM(g_UpperTiledMemory);
     49extern BS3SLABCTLUPPERTILED     BS3_DATA_NM(g_Bs3Mem4KUpperTiled);
    4950
    5051
     
    5354#define BS3_MEM_SLAB_LIST_COUNT 6
    5455
     56extern uint8_t const            BS3_DATA_NM(g_aiBs3SlabListsByPowerOfTwo)[12];
    5557extern uint16_t const           BS3_DATA_NM(g_acbBs3SlabLists)[BS3_MEM_SLAB_LIST_COUNT];
    5658extern BS3SLABHEAD              BS3_DATA_NM(g_aBs3LowSlabLists)[BS3_MEM_SLAB_LIST_COUNT];
    5759extern BS3SLABHEAD              BS3_DATA_NM(g_aBs3UpperTiledSlabLists)[BS3_MEM_SLAB_LIST_COUNT];
     60extern uint16_t const           BS3_DATA_NM(g_cbBs3SlabCtlSizesforLists)[BS3_MEM_SLAB_LIST_COUNT];
     61
     62
     63/**
     64 * Translates a allocation request size to a slab list index.
     65 *
     66 * @returns Slab list index if small request, UINT8_MAX if large.
     67 * @param   cbRequest   The number of bytes requested.
     68 */
     69DECLINLINE(uint8_t) bs3MemSizeToSlabListIndex(size_t cbRequest)
     70{
     71    if (cbRequest <= BS3_DATA_NM(g_acbBs3SlabLists)[BS3_MEM_SLAB_LIST_COUNT - 1])
     72        return BS3_DATA_NM(g_aiBs3SlabListsByPowerOfTwo)[cbRequest ? ASMBitLastSetU16((uint16_t)(cbRequest - 1)) : 0];
     73    return UINT8_MAX;
     74}
    5875
    5976
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-first-rm.asm

    r58785 r58789  
    4545%endif
    4646
    47 BS3_GLOBAL_DATA Bs3Text16_Size, 2
    48     dw  BS3_DATA_NM(Bs3Text16_EndOfSegment) wrt BS3TEXT16
    4947BS3_GLOBAL_DATA Bs3Text16_EndOfSegment, 0
    5048
     
    5755BS3_GLOBAL_DATA Bs3Data16_StartOfSegment, 0
    5856    db      10,13,'eye-catcher: BS3DATA16',10,13
     57
     58ALIGNDATA(16)
     59BS3_GLOBAL_DATA Bs3Data16_Size, 4
     60    dd  BS3_DATA_NM(Bs3Data16_EndOfSegment) wrt BS3DATA16_GROUP
     61BS3_GLOBAL_DATA Bs3Data16Thru64Text32And64_TotalSize, 4
     62    dd  BS3_DATA_NM(Bs3Data64_EndOfSegment) wrt BS3DATA16_GROUP
     63BS3_GLOBAL_DATA Bs3TotalImageSize, 4
     64    dd  BS3_DATA_NM(Bs3Data64_EndOfSegment) wrt CGROUP16
     65BS3_GLOBAL_DATA Bs3Text16_Size, 2
     66    dd  BS3_DATA_NM(Bs3Text16_EndOfSegment) wrt CGROUP16
     67
    5968%ifdef ASM_FORMAT_ELF
    6069section BS3DATA16CONST  align=2   progbits alloc noexec write
     
    8594section BS3TEXT32_END   align=1 CLASS=BS3CODE32 PUBLIC USE32 FLAT
    8695%endif
    87 BS3_GLOBAL_DATA Bs3Data16_Size, 4
    88     dd  BS3_DATA_NM(Bs3Data16_EndOfSegment) wrt BS3DATA16
     96
    8997BS3_GLOBAL_DATA Bs3Text32_EndOfSegment, 0
    9098
     
    121129section BS3DATA64_END   align=16   CLASS=DATA PUBLIC USE32 FLAT
    122130%endif
    123 
    124 ALIGNDATA(16)
    125     db      10,13,'eye-catcher: sizes  ',10,13
    126 BS3_GLOBAL_DATA Bs3Data16Thru64Text32And64_TotalSize, 4
    127     dd  BS3_DATA_NM(Bs3Data64_EndOfSegment) wrt BS3DATA16
    128 BS3_GLOBAL_DATA Bs3TotalImageSize, 4
    129     dd  BS3_DATA_NM(Bs3Data64_EndOfSegment) wrt BS3TEXT16
    130131BS3_GLOBAL_DATA Bs3Data64_EndOfSegment, 0
    131132
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitMemory.c

    r58785 r58789  
    9999*********************************************************************************************************************************/
    100100/** Slab control structure for the 4K management of low memory (< 1MB). */
    101 BS3SLABCLTLOW           BS3_DATA_NM(g_Bs3Mem4KLow);
     101BS3SLABCTLLOW           BS3_DATA_NM(g_Bs3Mem4KLow);
    102102/** Slab control structure for the 4K management of tiled upper memory,
    103103 *  between 1 MB and 16MB. */
    104104BS3SLABCTLUPPERTILED    BS3_DATA_NM(g_Bs3Mem4KUpperTiled);
     105
     106
     107/** Translates a power of two request size to an slab list index. */
     108uint8_t const           BS3_DATA_NM(g_aiBs3SlabListsByPowerOfTwo)[12] =
     109{
     110    /* 2^0  =    1 */  0,
     111    /* 2^1  =    2 */  0,
     112    /* 2^2  =    4 */  0,
     113    /* 2^3  =    8 */  0,
     114    /* 2^4  =   16 */  0,
     115    /* 2^5  =   32 */  1,
     116    /* 2^6  =   64 */  2,
     117    /* 2^7  =  128 */  3,
     118    /* 2^8  =  256 */  4,
     119    /* 2^9  =  512 */  5,
     120    /* 2^10 = 1024 */  -1
     121    /* 2^11 = 2048 */  -1
     122};
    105123
    106124/** The slab list chunk sizes. */
     
    114132    512,
    115133};
     134
    116135/** Low memory slab lists, sizes given by g_acbBs3SlabLists. */
    117136BS3SLABHEAD             BS3_DATA_NM(g_aBs3LowSlabLists)[BS3_MEM_SLAB_LIST_COUNT];
    118137/** Upper tiled memory slab lists, sizes given by g_acbBs3SlabLists. */
    119138BS3SLABHEAD             BS3_DATA_NM(g_aBs3UpperTiledSlabLists)[BS3_MEM_SLAB_LIST_COUNT];
     139
     140/** Slab control structure sizes for the slab lists.
     141 * This is to help the allocator when growing a list. */
     142uint16_t const          BS3_DATA_NM(g_cbBs3SlabCtlSizesforLists)[BS3_MEM_SLAB_LIST_COUNT] =
     143{
     144    RT_ALIGN(sizeof(BS3SLABCTL) - 4 + (4096 / 16  / 8 /*=32*/), 16),
     145    RT_ALIGN(sizeof(BS3SLABCTL) - 4 + (4096 / 32  / 8 /*=16*/), 32),
     146    RT_ALIGN(sizeof(BS3SLABCTL) - 4 + (4096 / 64  / 8 /*=8*/),  64),
     147    RT_ALIGN(sizeof(BS3SLABCTL) - 4 + (4096 / 128 / 8 /*=4*/), 128),
     148    RT_ALIGN(sizeof(BS3SLABCTL) - 4 + (4096 / 256 / 8 /*=2*/), 256),
     149    RT_ALIGN(sizeof(BS3SLABCTL) - 4 + (4096 / 512 / 8 /*=1*/), 512),
     150};
    120151
    121152
     
    141172     *      - 0xf0000 to 0xfffff - PC BIOS.
    142173     */
    143     Bs3SlabInit(&g_Bs3Mem4KLow.Core, sizeof(g_Bs3Mem4KLow), 0 /*uFlatSlabPtr*/, 0xA0000 /* 640 KB*/, _4K);
     174    Bs3SlabInit(&BS3_DATA_NM(g_Bs3Mem4KLow).Core, sizeof(BS3_DATA_NM(g_Bs3Mem4KLow)),
     175                0 /*uFlatSlabPtr*/, 0xA0000 /* 640 KB*/, _4K);
    144176
    145177    /* Mark the stacks and whole image as allocated. */
    146178    cPages  = (BS3_DATA_NM(Bs3TotalImageSize) + _4K - 1U) >> 12;
    147     ASMBitSetRange(g_Bs3Mem4KLow.Core.bmAllocated, 0, 0x10 + cPages);
     179    ASMBitSetRange(BS3_DATA_NM(g_Bs3Mem4KLow).Core.bmAllocated, 0, 0x10 + cPages);
    148180
    149181    /* Mark any unused pages between BS3TEXT16 and BS3SYSTEM16 as free. */
    150182    cPages = (BS3_DATA_NM(Bs3Text16_Size) + _4K - 1U) >> 12;
    151     ASMBitClearRange(g_Bs3Mem4KLow.Core.bmAllocated, 0x10U + cPages, 0x20U);
     183    ASMBitClearRange(BS3_DATA_NM(g_Bs3Mem4KLow).Core.bmAllocated, 0x10U + cPages, 0x20U);
    152184
    153185    /* In case the system has less than 640KB of memory, check the BDA variable for it. */
     
    156188    {
    157189        cPages = 640 - cPages;
     190        cPages = RT_ALIGN(cPages, 4);
    158191        cPages >>= 2;
    159         ASMBitSetRange(g_Bs3Mem4KLow.Core.bmAllocated, 0xA0 - cPages, 0xA0);
     192        ASMBitSetRange(BS3_DATA_NM(g_Bs3Mem4KLow).Core.bmAllocated, 0xA0 - cPages, 0xA0);
    160193    }
    161194    else
    162         ASMBitSet(g_Bs3Mem4KLow.Core.bmAllocated, 0x9F);
     195        ASMBitSet(BS3_DATA_NM(g_Bs3Mem4KLow).Core.bmAllocated, 0x9F);
    163196
    164197    /* Recalc free pages. */
    165198    cPages = 0;
    166     i = g_Bs3Mem4KLow.Core.cChunks;
     199    i = BS3_DATA_NM(g_Bs3Mem4KLow).Core.cChunks;
    167200    while (i-- > 0)
    168         cPages += ASMBitTest(g_Bs3Mem4KLow.Core.bmAllocated, i);
    169     g_Bs3Mem4KLow.Core.cFreeChunks = cPages;
    170 
     201        cPages += !ASMBitTest(BS3_DATA_NM(g_Bs3Mem4KLow).Core.bmAllocated, i);
     202    BS3_DATA_NM(g_Bs3Mem4KLow).Core.cFreeChunks = cPages;
    171203
    172204    /*
    173205     * First 16 MB of memory above 1MB.  We start out by marking it all allocated.
    174206     */
    175     Bs3SlabInit(&g_Bs3Mem4KUpperTiled.Core, sizeof(g_Bs3Mem4KUpperTiled), _1M, BS3_SEL_TILED_AREA_SIZE - _1M, _4K);
    176 
    177     ASMBitSetRange(g_Bs3Mem4KUpperTiled.Core.bmAllocated, 0, g_Bs3Mem4KUpperTiled.Core.cChunks);
    178     g_Bs3Mem4KUpperTiled.Core.cFreeChunks = 0;
     207    Bs3SlabInit(&BS3_DATA_NM(g_Bs3Mem4KUpperTiled).Core, sizeof(BS3_DATA_NM(g_Bs3Mem4KUpperTiled)),
     208                _1M, BS3_SEL_TILED_AREA_SIZE - _1M, _4K);
     209
     210    ASMBitSetRange(BS3_DATA_NM(g_Bs3Mem4KUpperTiled).Core.bmAllocated, 0, BS3_DATA_NM(g_Bs3Mem4KUpperTiled).Core.cChunks);
     211    BS3_DATA_NM(g_Bs3Mem4KUpperTiled).Core.cFreeChunks = 0;
    179212
    180213    /* Ask the BIOS about where there's memory, and make pages in between 1MB
     
    235268                            while (cPages-- > 0)
    236269                            {
    237                                 g_Bs3Mem4KUpperTiled.Core.cFreeChunks += !ASMBitTestAndSet(g_Bs3Mem4KUpperTiled.Core.bmAllocated,
    238                                                                                             i);
     270                                uint16_t uLineToLong = ASMBitTestAndClear(g_Bs3Mem4KUpperTiled.Core.bmAllocated, i);
     271                                BS3_DATA_NM(g_Bs3Mem4KUpperTiled).Core.cFreeChunks += uLineToLong;
    239272                                i++;
    240273                            }
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-shutdown.c

    r58785 r58789  
    1111BS3_DECL(void) Main_rm(void)
    1212{
     13    void BS3_FAR *pvTmp1;
     14    void BS3_FAR *pvTmp2;
     15    void BS3_FAR *pvTmp3;
     16    void BS3_FAR *pvTmp4;
    1317    Bs3InitMemory_rm();
    1418
    1519    Bs3TestInit("bs3-shutdown");
     20
     21Bs3PrintStr("Bs3PrintX32:");
     22Bs3PrintX32(UINT32_C(0xfdb97531));
     23Bs3PrintStr("\r\n");
     24
     25pvTmp2 = Bs3MemAlloc(BS3MEMKIND_REAL, _4K);
     26Bs3PrintStr("pvTmp2=");
     27Bs3PrintX32((uintptr_t)pvTmp2);
     28Bs3PrintStr("\r\n");
     29
     30pvTmp3 = Bs3MemAlloc(BS3MEMKIND_REAL, _4K);
     31Bs3PrintStr("pvTmp3=");
     32Bs3PrintX32((uintptr_t)pvTmp3);
     33Bs3PrintStr("\r\n");
     34Bs3MemFree(pvTmp2, _4K);
     35
     36pvTmp4 = Bs3MemAlloc(BS3MEMKIND_REAL, _4K);
     37Bs3PrintStr("pvTmp4=");
     38Bs3PrintX32((uintptr_t)pvTmp4);
     39Bs3PrintStr("\r\n");
     40Bs3PrintStr("\r\n");
     41
     42pvTmp1 = Bs3MemAlloc(BS3MEMKIND_REAL, 31);
     43Bs3PrintStr("pvTmp1=");
     44Bs3PrintX32((uintptr_t)pvTmp1);
     45Bs3PrintStr("\r\n");
     46
     47pvTmp2 = Bs3MemAlloc(BS3MEMKIND_REAL, 17);
     48Bs3PrintStr("pvTmp2=");
     49Bs3PrintX32((uintptr_t)pvTmp2);
     50Bs3PrintStr("\r\n");
     51
     52Bs3MemFree(pvTmp1, 31);
     53pvTmp3 = Bs3MemAlloc(BS3MEMKIND_REAL, 17);
     54Bs3PrintStr("pvTmp3=");
     55Bs3PrintX32((uintptr_t)pvTmp3);
     56Bs3PrintStr("\r\n");
     57
    1658
    1759Bs3Panic();
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h

    r58785 r58789  
    599599 * @{ */
    600600/** Start of the BS3TEXT16 segment.   */
    601 extern uint8_t BS3_DATA_NM(Bs3Text16_StartOfSegment);
     601extern uint8_t  BS3_DATA_NM(Bs3Text16_StartOfSegment);
    602602/** End of the BS3TEXT16 segment.   */
    603 extern uint8_t BS3_DATA_NM(Bs3Text16_EndOfSegment);
     603extern uint8_t  BS3_DATA_NM(Bs3Text16_EndOfSegment);
    604604/** The size of the BS3TEXT16 segment.   */
    605 extern uint8_t BS3_DATA_NM(Bs3Text16_Size);
     605extern uint16_t BS3_DATA_NM(Bs3Text16_Size);
    606606
    607607/** Start of the BS3SYSTEM16 segment.   */
    608 extern uint8_t BS3_DATA_NM(Bs3System16_StartOfSegment);
     608extern uint8_t  BS3_DATA_NM(Bs3System16_StartOfSegment);
    609609/** End of the BS3SYSTEM16 segment.   */
    610 extern uint8_t BS3_DATA_NM(Bs3System16_EndOfSegment);
     610extern uint8_t  BS3_DATA_NM(Bs3System16_EndOfSegment);
    611611
    612612/** Start of the BS3DATA16 segment.   */
    613 extern uint8_t BS3_DATA_NM(Bs3Data16_StartOfSegment);
     613extern uint8_t  BS3_DATA_NM(Bs3Data16_StartOfSegment);
    614614/** End of the BS3DATA16 segment.   */
    615 extern uint8_t BS3_DATA_NM(Bs3Data16_EndOfSegment);
     615extern uint8_t  BS3_DATA_NM(Bs3Data16_EndOfSegment);
    616616
    617617/** Start of the BS3TEXT32 segment.   */
    618 extern uint8_t BS3_DATA_NM(Bs3Text32_StartOfSegment);
     618extern uint8_t  BS3_DATA_NM(Bs3Text32_StartOfSegment);
    619619/** Start of the BS3TEXT32 segment.   */
    620 extern uint8_t BS3_DATA_NM(Bs3Text32_EndOfSegment);
     620extern uint8_t  BS3_DATA_NM(Bs3Text32_EndOfSegment);
    621621
    622622/** Start of the BS3DATA32 segment.   */
    623 extern uint8_t BS3_DATA_NM(Bs3Data32_StartOfSegment);
     623extern uint8_t  BS3_DATA_NM(Bs3Data32_StartOfSegment);
    624624/** Start of the BS3DATA32 segment.   */
    625 extern uint8_t BS3_DATA_NM(Bs3Data32_EndOfSegment);
     625extern uint8_t  BS3_DATA_NM(Bs3Data32_EndOfSegment);
    626626
    627627/** Start of the BS3TEXT64 segment.   */
    628 extern uint8_t BS3_DATA_NM(Bs3Text64_StartOfSegment);
     628extern uint8_t  BS3_DATA_NM(Bs3Text64_StartOfSegment);
    629629/** Start of the BS3TEXT64 segment.   */
    630 extern uint8_t BS3_DATA_NM(Bs3Text64_EndOfSegment);
     630extern uint8_t  BS3_DATA_NM(Bs3Text64_EndOfSegment);
    631631
    632632/** Start of the BS3DATA64 segment.   */
    633 extern uint8_t BS3_DATA_NM(Bs3Data64_StartOfSegment);
     633extern uint8_t  BS3_DATA_NM(Bs3Data64_StartOfSegment);
    634634/** Start of the BS3DATA64 segment.   */
    635 extern uint8_t BS3_DATA_NM(Bs3Data64_EndOfSegment);
     635extern uint8_t  BS3_DATA_NM(Bs3Data64_EndOfSegment);
    636636
    637637/** The size of the Data16, Text32, Text64, Data32 and Data64 blob. */
    638 extern uint8_t BS3_DATA_NM(Bs3Data16Thru64Text32And64_TotalSize);
     638extern uint32_t BS3_DATA_NM(Bs3Data16Thru64Text32And64_TotalSize);
    639639/** The total image size (from Text16 thu Data64). */
    640 extern uint8_t BS3_DATA_NM(Bs3TotalImageSize);
     640extern uint32_t BS3_DATA_NM(Bs3TotalImageSize);
    641641/** @} */
    642642
     
    845845        } \
    846846        else \
    847             (a_Name).XPtr.uFlat = BS3_FP_OFF(pTypeCheck) + (BS3_FP_SEG(pTypeCheck) << 4); \
     847            (a_Name).XPtr.uFlat = BS3_FP_OFF(pTypeCheck) + ((uint32_t)BS3_FP_SEG(pTypeCheck) << 4); \
    848848    } while (0)
    849849#elif ARCH_BITS == 32
     
    911911
    912912/**
    913  * Prints a 32-bit unsigned value as hex to the screen.
     913 * Prints a 32-bit unsigned value as decimal to the screen.
    914914 *
    915915 * @param   uValue      The 32-bit value.
     
    919919BS3_DECL(void) Bs3PrintU32_c64(uint32_t uValue); /**< @copydoc Bs3PrintU32_c16 */
    920920#define Bs3PrintU32 BS3_CMN_NM(Bs3PrintU32) /**< Selects #Bs3PrintU32_c16, #Bs3PrintU32_c32 or #Bs3PrintU32_c64. */
     921
     922/**
     923 * Prints a 32-bit unsigned value as hex to the screen.
     924 *
     925 * @param   uValue      The 32-bit value.
     926 */
     927BS3_DECL(void) Bs3PrintX32_c16(uint32_t uValue);
     928BS3_DECL(void) Bs3PrintX32_c32(uint32_t uValue); /**< @copydoc Bs3PrintX32_c16 */
     929BS3_DECL(void) Bs3PrintX32_c64(uint32_t uValue); /**< @copydoc Bs3PrintX32_c16 */
     930#define Bs3PrintX32 BS3_CMN_NM(Bs3PrintX32) /**< Selects #Bs3PrintX32_c16, #Bs3PrintX32_c32 or #Bs3PrintX32_c64. */
    921931
    922932/**
     
    10841094{
    10851095    /** Pointer to the first slab. */
    1086     BS3_XPTR_MEMBER(struct BS3SLABCLT, pFirst);
     1096    BS3_XPTR_MEMBER(struct BS3SLABCTL, pFirst);
    10871097    /** The allocation chunk size. */
    10881098    uint16_t                        cbChunk;
     
    11031113 * static location for the larger ones.
    11041114 */
    1105 typedef struct BS3SLABCLT
     1115typedef struct BS3SLABCTL
    11061116{
    11071117    /** Pointer to the next slab control structure in this list. */
    1108     BS3_XPTR_MEMBER(struct BS3SLABCLT, pNext);
     1118    BS3_XPTR_MEMBER(struct BS3SLABCTL, pNext);
    11091119    /** Pointer to the slab list head. */
    11101120    BS3_XPTR_MEMBER(BS3SLABHEAD,    pHead);
     
    11231133     * multiple of 4). */
    11241134    uint8_t                         bmAllocated[4];
    1125 } BS3SLABCLT;
     1135} BS3SLABCTL;
    11261136/** Pointer to a bs3kit slab control structure. */
    1127 typedef BS3SLABCLT BS3_FAR *PBS3SLABCLT;
     1137typedef BS3SLABCTL BS3_FAR *PBS3SLABCTL;
     1138
     1139/** The chunks must all be in the same 16-bit segment tile. */
     1140#define BS3_SLAB_ALLOC_F_SAME_TILE      UINT16_C(0x0001)
    11281141
    11291142/**
     
    11361149 * @param   cbChunk         The chunk size.
    11371150 */
    1138 BS3_DECL(void) Bs3SlabInit_c16(PBS3SLABCLT pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk);
     1151BS3_DECL(void) Bs3SlabInit_c16(PBS3SLABCTL pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk);
    11391152/** @copydoc Bs3SlabInit_c16 */
    1140 BS3_DECL(void) Bs3SlabInit_c32(PBS3SLABCLT pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk);
     1153BS3_DECL(void) Bs3SlabInit_c32(PBS3SLABCTL pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk);
    11411154/** @copydoc Bs3SlabInit_c16 */
    1142 BS3_DECL(void) Bs3SlabInit_c64(PBS3SLABCLT pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk);
     1155BS3_DECL(void) Bs3SlabInit_c64(PBS3SLABCTL pSlabCtl, size_t cbSlabCtl, uint32_t uFlatSlabPtr, uint32_t cbSlab, uint16_t cbChunk);
    11431156#define Bs3SlabInit BS3_CMN_NM(Bs3SlabInit) /**< Selects #Bs3SlabInit_c16, #Bs3SlabInit_c32 or #Bs3SlabInit_c64. */
     1157
     1158/**
     1159 * Allocates one chunk from a slab.
     1160 *
     1161 * @returns Pointer to a chunk on success, NULL if we're out of chunks.
     1162 * @param   pSlabCtl        The slab constrol structure to allocate from.
     1163 */
     1164BS3_DECL(void BS3_FAR *) Bs3SlabAlloc_c16(PBS3SLABCTL pSlabCtl);
     1165BS3_DECL(void BS3_FAR *) Bs3SlabAlloc_c32(PBS3SLABCTL pSlabCtl); /**< @copydoc Bs3SlabAlloc_c16 */
     1166BS3_DECL(void BS3_FAR *) Bs3SlabAlloc_c64(PBS3SLABCTL pSlabCtl); /**< @copydoc Bs3SlabAlloc_c16 */
     1167#define Bs3SlabAlloc BS3_CMN_NM(Bs3SlabAlloc) /**< Selects #Bs3SlabAlloc_c16, #Bs3SlabAlloc_c32 or #Bs3SlabAlloc_c64. */
     1168
     1169/**
     1170 * Allocates one or more chunks rom a slab.
     1171 *
     1172 * @returns Pointer to the request number of chunks on success, NULL if we're
     1173 *          out of chunks.
     1174 * @param   pSlabCtl        The slab constrol structure to allocate from.
     1175 * @param   cChunks         The number of contiguous chunks we want.
     1176 * @param   fFlags          Flags, see BS3_SLAB_ALLOC_F_XXX
     1177 */
     1178BS3_DECL(void BS3_FAR *) Bs3SlabAllocEx_c16(PBS3SLABCTL pSlabCtl, uint16_t cChunks, uint16_t fFlags);
     1179BS3_DECL(void BS3_FAR *) Bs3SlabAllocEx_c32(PBS3SLABCTL pSlabCtl, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabAllocEx_c16 */
     1180BS3_DECL(void BS3_FAR *) Bs3SlabAllocEx_c64(PBS3SLABCTL pSlabCtl, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabAllocEx_c16 */
     1181#define Bs3SlabAllocEx BS3_CMN_NM(Bs3SlabAllocEx) /**< Selects #Bs3SlabAllocEx_c16, #Bs3SlabAllocEx_c32 or #Bs3SlabAllocEx_c64. */
     1182
     1183/**
     1184 * Frees one or more chunks from a slab.
     1185 *
     1186 * @returns Number of chunks actually freed.  When correctly used, this will
     1187 *          match the @a cChunks parameter, of course.
     1188 * @param   pSlabCtl        The slab constrol structure to free from.
     1189 * @param   uFlatChunkPtr   The flat address of the chunks to free.
     1190 * @param   cChunks         The number of contiguous chunks to free.
     1191 */
     1192BS3_DECL(uint16_t) Bs3SlabFree_c16(PBS3SLABCTL pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks);
     1193BS3_DECL(uint16_t) Bs3SlabFree_c32(PBS3SLABCTL pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks); /**< @copydoc Bs3SlabFree_c16 */
     1194BS3_DECL(uint16_t) Bs3SlabFree_c64(PBS3SLABCTL pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks); /**< @copydoc Bs3SlabFree_c16 */
     1195#define Bs3SlabFree BS3_CMN_NM(Bs3SlabFree) /**< Selects #Bs3SlabFree_c16, #Bs3SlabFree_c32 or #Bs3SlabFree_c64. */
    11441196
    11451197
     
    11611213 * @param   pSlabCtl        The slab control structure to add.
    11621214 */
    1163 BS3_DECL(void) Bs3SlabListAdd_c16(PBS3SLABHEAD pHead, PBS3SLABCLT pSlabCtl);
     1215BS3_DECL(void) Bs3SlabListAdd_c16(PBS3SLABHEAD pHead, PBS3SLABCTL pSlabCtl);
    11641216/** @copydoc Bs3SlabListAdd_c16 */
    1165 BS3_DECL(void) Bs3SlabListAdd_c32(PBS3SLABHEAD pHead, PBS3SLABCLT pSlabCtl);
     1217BS3_DECL(void) Bs3SlabListAdd_c32(PBS3SLABHEAD pHead, PBS3SLABCTL pSlabCtl);
    11661218/** @copydoc Bs3SlabListAdd_c16 */
    1167 BS3_DECL(void) Bs3SlabListAdd_c64(PBS3SLABHEAD pHead, PBS3SLABCLT pSlabCtl);
     1219BS3_DECL(void) Bs3SlabListAdd_c64(PBS3SLABHEAD pHead, PBS3SLABCTL pSlabCtl);
    11681220#define Bs3SlabListAdd BS3_CMN_NM(Bs3SlabListAdd) /**< Selects #Bs3SlabListAdd_c16, #Bs3SlabListAdd_c32 or #Bs3SlabListAdd_c64. */
    11691221
     
    11921244BS3_DECL(void BS3_FAR *) Bs3SlabListAllocEx_c64(PBS3SLABHEAD pHead, uint16_t cChunks, uint16_t fFlags); /**< @copydoc Bs3SlabListAllocEx_c16 */
    11931245#define Bs3SlabListAllocEx BS3_CMN_NM(Bs3SlabListAllocEx) /**< Selects #Bs3SlabListAllocEx_c16, #Bs3SlabListAllocEx_c32 or #Bs3SlabListAllocEx_c64. */
    1194 /** The chunks must all be in the same 16-bit segment tile. */
    1195 #define BS3_SLAB_ALLOC_F_SAME_TILE      UINT16_C(0x0001)
    1196 
    1197 /**
    1198  * Frees one or more chunks from a slab.
    1199  *
    1200  * @returns Number of chunks actually freed.  When correctly used, this will
    1201  *          match the @a cChunks parameter, of course.
    1202  * @param   pSlabCtl        The slab constrol structure to free from.
    1203  * @param   uFlatChunkPtr   The flat address of the chunks to free.
    1204  * @param   cChunks         The number of contiguous chunks to free.
    1205  */
    1206 BS3_DECL(uint16_t) Bs3SlabFree_c16(PBS3SLABCLT pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks);
    1207 BS3_DECL(uint16_t) Bs3SlabFree_c32(PBS3SLABCLT pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks); /**< @copydoc Bs3SlabFree_c16 */
    1208 BS3_DECL(uint16_t) Bs3SlabFree_c64(PBS3SLABCLT pSlabCtl, uint32_t uFlatChunkPtr, uint16_t cChunks); /**< @copydoc Bs3SlabFree_c16 */
    1209 #define Bs3SlabFree BS3_CMN_NM(Bs3SlabFree) /**< Selects #Bs3SlabFree_c16, #Bs3SlabFree_c32 or #Bs3SlabFree_c64. */
    12101246
    12111247/**
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