VirtualBox

Changeset 15667 in vbox


Ignore:
Timestamp:
Dec 18, 2008 5:41:26 PM (16 years ago)
Author:
vboxsync
Message:

DevVGA: Made the ubuntu live cd boot screen fast on darwin. Fixed broken vram size restriction in the read byte mmio handler, would return a status code where the value goes and nobody would notice (rawmode + darwin/VT-x). Fixed a couple of vram boundrary checks, mostly for rawmode & darwin-VT-x, but some also applies to all modes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Graphics/DevVGA.cpp

    r15665 r15667  
    8484/** Some fixes to ensure that logical scan-line lengths are not overwritten. */
    8585#define KEEP_SCAN_LINE_LENGTH
     86
     87/** Check buffer if an VRAM offset is within the right range or not. */
     88#if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
     89# define VERIFY_VRAM_WRITE_OFF_RETURN(pThis, off) \
     90    do { \
     91        if ((off) >= VGA_MAPPING_SIZE) \
     92        { \
     93            AssertMsgReturn((off) < (pThis)->vram_size, ("%RX32 !< %RX32\n", (uint32_t)(off), (pThis)->vram_size), VINF_SUCCESS); \
     94            Log2(("%Rfn[%d]: %RX32 -> R3\n", __PRETTY_FUNCTION__, __LINE__, (off))); \
     95            return VINF_IOM_HC_MMIO_WRITE; \
     96        } \
     97    } while (0)
     98#else
     99# define VERIFY_VRAM_WRITE_OFF_RETURN(pThis, off) \
     100        AssertMsgReturn((off) < (pThis)->vram_size, ("%RX32 !< %RX32\n", (uint32_t)(off), (pThis)->vram_size), VINF_SUCCESS)
     101#endif
     102
     103/** Check buffer if an VRAM offset is within the right range or not. */
     104#if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
     105# define VERIFY_VRAM_READ_OFF_RETURN(pThis, off, rcVar) \
     106    do { \
     107        if ((off) >= VGA_MAPPING_SIZE) \
     108        { \
     109            AssertMsgReturn((off) < (pThis)->vram_size, ("%RX32 !< %RX32\n", (uint32_t)(off), (pThis)->vram_size), 0xff); \
     110            Log2(("%Rfn[%d]: %RX32 -> R3\n", __PRETTY_FUNCTION__, __LINE__, (off))); \
     111            (rcVar) = VINF_IOM_HC_MMIO_READ; \
     112            return 0; \
     113        } \
     114    } while (0)
     115#else
     116# define VERIFY_VRAM_READ_OFF_RETURN(pThis, off, rcVar) \
     117        AssertMsgReturn((off) < (pThis)->vram_size, ("%RX32 !< %RX32\n", (uint32_t)(off), (pThis)->vram_size), 0xff)
     118#endif
    86119
    87120
     
    11091142/* called for accesses between 0xa0000 and 0xc0000 */
    11101143#ifdef VBOX
    1111 static
     1144static uint32_t vga_mem_readb(void *opaque, target_phys_addr_t addr, int *prc)
     1145#else
     1146uint32_t vga_mem_readb(void *opaque, target_phys_addr_t addr)
    11121147#endif /* VBOX */
    1113 uint32_t vga_mem_readb(void *opaque, target_phys_addr_t addr)
    11141148{
    11151149    VGAState *s = (VGAState*)opaque;
     
    11471181    }
    11481182
    1149 #if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
    1150     if (addr >= VGA_MAPPING_SIZE)
    1151         return VINF_IOM_HC_MMIO_WRITE;
    1152 #endif
    1153 
    11541183    if (s->sr[4] & 0x08) {
    11551184        /* chain 4 mode : simplest access */
     
    11571186        ret = s->vram_ptr[addr];
    11581187#else /* VBOX */
    1159         ret = s->CTX_SUFF(vram_ptr)[addr];
    11601188# ifdef IN_RING0
    11611189        /* If all planes are accessible, then map the page to the frame buffer and make it writable. */
    11621190        if ((s->sr[2] & 3) == 3)
    11631191        {
    1164             /* @todo only allow read access (doesn't work now) */
     1192            /** @todo only allow read access (doesn't work now) */
    11651193            IOMMMIOModifyPage(PDMDevHlpGetVM(s->CTX_SUFF(pDevIns)), GCPhys, s->GCPhysVRAM + addr, X86_PTE_RW|X86_PTE_P);
    11661194            vga_set_dirty(s, addr);
     
    11681196        }
    11691197# endif /* IN_RING0 */
     1198        VERIFY_VRAM_READ_OFF_RETURN(s, addr, *prc);
     1199        ret = s->CTX_SUFF(vram_ptr)[addr];
    11701200#endif /* VBOX */
    11711201    } else if (!(s->sr[4] & 0x04)) {    /* Host access is controlled by SR4, not GR5! */
     
    11761206#else /* VBOX */
    11771207        /* See the comment for a similar line in vga_mem_writeb. */
    1178         ret = s->CTX_SUFF(vram_ptr)[((addr & ~1) << 2) | plane];
     1208        RTGCPHYS off = ((addr & ~1) << 2) | plane;
     1209        VERIFY_VRAM_READ_OFF_RETURN(s, off, *prc);
     1210        ret = s->CTX_SUFF(vram_ptr)[off];
    11791211#endif /* VBOX */
    11801212    } else {
     
    11831215        s->latch = ((uint32_t *)s->vram_ptr)[addr];
    11841216#else /* VBOX */
     1217        VERIFY_VRAM_READ_OFF_RETURN(s, addr, *prc);
    11851218        s->latch = ((uint32_t *)s->CTX_SUFF(vram_ptr))[addr];
    11861219#endif /* VBOX */
     
    12841317            s->vram_ptr[addr] = val;
    12851318#else /* VBOX */
    1286 # if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
    1287             if (addr >= VGA_MAPPING_SIZE)
    1288                 return VINF_IOM_HC_MMIO_WRITE;
    1289 # else
    1290             if (addr >= s->vram_size)
    1291             {
    1292                 AssertMsgFailed(("addr=%RGp - this needs to be done in HC! bank_offset=%08x memory_map_mode=%d\n",
    1293                                  addr, s->bank_offset, memory_map_mode));
    1294                 return VINF_SUCCESS;
    1295             }
    1296 # endif
    1297             s->CTX_SUFF(vram_ptr)[addr] = val;
    1298 
    12991319# ifdef IN_RING0
    13001320            /* If all planes are accessible, then map the page to the frame buffer and make it writable. */
     
    13061326# endif /* IN_RING0 */
    13071327
     1328            VERIFY_VRAM_WRITE_OFF_RETURN(s, addr);
     1329            s->CTX_SUFF(vram_ptr)[addr] = val;
    13081330#endif /* VBOX */
    13091331#ifdef DEBUG_VGA_MEM
     
    13351357            s->vram_ptr[addr] = val;
    13361358#else /* VBOX */
    1337 # if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
    1338             if (addr >= VGA_MAPPING_SIZE)
    1339                 return VINF_IOM_HC_MMIO_WRITE;
    1340 # else
    1341             if (addr >= s->vram_size)
    1342             {
    1343                 AssertMsgFailed(("addr=%RGp - this needs to be done in HC! bank_offset=%08x memory_map_mode=%d\n",
    1344                                  addr, s->bank_offset, memory_map_mode));
    1345                 return VINF_SUCCESS;
    1346             }
    1347 # endif
     1359            VERIFY_VRAM_WRITE_OFF_RETURN(s, addr);
    13481360            s->CTX_SUFF(vram_ptr)[addr] = val;
    13491361#endif /* VBOX */
     
    13591371        }
    13601372    } else {
    1361 #if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
    1362         if (addr * 4 >= VGA_MAPPING_SIZE)
    1363             return VINF_IOM_HC_MMIO_WRITE;
    1364 #else
    1365         if (addr * 4 >= s->vram_size)
    1366         {
    1367             AssertMsgFailed(("addr=%RGp - this needs to be done in HC! bank_offset=%08x memory_map_mode=%d\n",
    1368                              addr * 4, s->bank_offset, memory_map_mode));
    1369             return VINF_SUCCESS;
    1370         }
    1371 #endif
    1372 
    13731373        /* standard VGA latched access */
     1374        VERIFY_VRAM_WRITE_OFF_RETURN(s, addr * 4 + 3);
     1375
    13741376        write_mode = s->gr[5] & 3;
    13751377        switch(write_mode) {
     
    33203322    if (pThis->sr[4] & 0x08) {
    33213323        /* chain 4 mode : simplest access */
    3322 #if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
    3323         if (GCPhysAddr + cItems * cbItem >= VGA_MAPPING_SIZE)
    3324             return VINF_IOM_HC_MMIO_WRITE;
    3325 #else
    3326         if (GCPhysAddr + cItems * cbItem >= pThis->vram_size)
    3327         {
    3328             AssertMsgFailed(("GCPhysAddr=%RGp cItems=%#x cbItem=%d\n", GCPhysAddr, cItems, cbItem));
    3329             return VINF_SUCCESS;
    3330         }
    3331 #endif
     3324        VERIFY_VRAM_WRITE_OFF_RETURN(pThis, GCPhysAddr + cItems * cbItem - 1);
    33323325
    33333326        while (cItems-- > 0)
     
    33433336    } else if (pThis->gr[5] & 0x10) {
    33443337        /* odd/even mode (aka text mode mapping) */
    3345 #if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
    3346         if (GCPhysAddr * 2 + cItems * cbItem >= VGA_MAPPING_SIZE)
    3347             return VINF_IOM_HC_MMIO_WRITE;
    3348 #else
    3349         if (GCPhysAddr * 2 + cItems * cbItem >= pThis->vram_size)
    3350         {
    3351             AssertMsgFailed(("GCPhysAddr=%RGp cItems=%#x cbItem=%d\n", GCPhysAddr, cItems, cbItem));
    3352             return VINF_SUCCESS;
    3353         }
    3354 #endif
     3338        VERIFY_VRAM_WRITE_OFF_RETURN(pThis, GCPhysAddr * 2 + cItems * cbItem - 1);
    33553339        while (cItems-- > 0)
    33563340            for (i = 0; i < cbItem; i++)
     
    33653349            }
    33663350    } else {
    3367 #if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
    3368         if (GCPhysAddr + cItems * cbItem >= VGA_MAPPING_SIZE)
    3369             return VINF_IOM_HC_MMIO_WRITE;
    3370 #else
    3371         if (GCPhysAddr + cItems * cbItem >= pThis->vram_size)
    3372         {
    3373             AssertMsgFailed(("GCPhysAddr=%RGp cItems=%#x cbItem=%d\n", GCPhysAddr, cItems, cbItem));
    3374             return VINF_SUCCESS;
    3375         }
    3376 #endif
    3377 
    33783351        /* standard VGA latched access */
     3352        VERIFY_VRAM_WRITE_OFF_RETURN(pThis, GCPhysAddr + cItems * cbItem - 1);
     3353
    33793354        switch(pThis->gr[5] & 3) {
    33803355        default:
     
    34913466    PVGASTATE pThis = PDMINS_2_DATA(pDevIns, PVGASTATE);
    34923467    STAM_PROFILE_START(&pThis->CTX_MID_Z(Stat,MemoryRead), a);
     3468    int rc = VINF_SUCCESS;
    34933469    NOREF(pvUser);
    34943470    switch (cb)
    34953471    {
    34963472        case 1:
    3497             *(uint8_t  *)pv = vga_mem_readb(pThis, GCPhysAddr); break;
     3473            *(uint8_t  *)pv = vga_mem_readb(pThis, GCPhysAddr, &rc); break;
    34983474        case 2:
    3499             *(uint16_t *)pv = vga_mem_readb(pThis, GCPhysAddr)
    3500                            | (vga_mem_readb(pThis, GCPhysAddr + 1) << 8);
     3475            *(uint16_t *)pv = vga_mem_readb(pThis, GCPhysAddr, &rc)
     3476                           | (vga_mem_readb(pThis, GCPhysAddr + 1, &rc) << 8);
    35013477            break;
    35023478        case 4:
    3503             *(uint32_t *)pv = vga_mem_readb(pThis, GCPhysAddr)
    3504                            | (vga_mem_readb(pThis, GCPhysAddr + 1) <<  8)
    3505                            | (vga_mem_readb(pThis, GCPhysAddr + 2) << 16)
    3506                            | (vga_mem_readb(pThis, GCPhysAddr + 3) << 24);
     3479            *(uint32_t *)pv = vga_mem_readb(pThis, GCPhysAddr, &rc)
     3480                           | (vga_mem_readb(pThis, GCPhysAddr + 1, &rc) <<  8)
     3481                           | (vga_mem_readb(pThis, GCPhysAddr + 2, &rc) << 16)
     3482                           | (vga_mem_readb(pThis, GCPhysAddr + 3, &rc) << 24);
    35073483            break;
    35083484
    35093485        case 8:
    3510             *(uint64_t *)pv = (uint64_t)vga_mem_readb(pThis, GCPhysAddr)
    3511                            | ((uint64_t)vga_mem_readb(pThis, GCPhysAddr + 1) <<  8)
    3512                            | ((uint64_t)vga_mem_readb(pThis, GCPhysAddr + 2) << 16)
    3513                            | ((uint64_t)vga_mem_readb(pThis, GCPhysAddr + 3) << 24)
    3514                            | ((uint64_t)vga_mem_readb(pThis, GCPhysAddr + 4) << 32)
    3515                            | ((uint64_t)vga_mem_readb(pThis, GCPhysAddr + 5) << 40)
    3516                            | ((uint64_t)vga_mem_readb(pThis, GCPhysAddr + 6) << 48)
    3517                            | ((uint64_t)vga_mem_readb(pThis, GCPhysAddr + 7) << 56);
     3486            *(uint64_t *)pv = (uint64_t)vga_mem_readb(pThis, GCPhysAddr, &rc)
     3487                           | ((uint64_t)vga_mem_readb(pThis, GCPhysAddr + 1, &rc) <<  8)
     3488                           | ((uint64_t)vga_mem_readb(pThis, GCPhysAddr + 2, &rc) << 16)
     3489                           | ((uint64_t)vga_mem_readb(pThis, GCPhysAddr + 3, &rc) << 24)
     3490                           | ((uint64_t)vga_mem_readb(pThis, GCPhysAddr + 4, &rc) << 32)
     3491                           | ((uint64_t)vga_mem_readb(pThis, GCPhysAddr + 5, &rc) << 40)
     3492                           | ((uint64_t)vga_mem_readb(pThis, GCPhysAddr + 6, &rc) << 48)
     3493                           | ((uint64_t)vga_mem_readb(pThis, GCPhysAddr + 7, &rc) << 56);
    35183494            break;
    35193495
     
    35223498            uint8_t *pu8Data = (uint8_t *)pv;
    35233499            while (cb-- > 0)
    3524                 *pu8Data++ = vga_mem_readb(pThis, GCPhysAddr++);
     3500            {
     3501                *pu8Data++ = vga_mem_readb(pThis, GCPhysAddr++, &rc);
     3502                if (RT_UNLIKELY(rc != VINF_SUCCESS))
     3503                    break;
     3504            }
    35253505        }
    35263506    }
    35273507    STAM_PROFILE_STOP(&pThis->CTX_MID_Z(Stat,MemoryRead), a);
    3528     return VINF_SUCCESS;
     3508    return rc;
    35293509}
    35303510
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