/* $Id: bs3-cpu-basic-2-pf.c32 64735 2016-11-22 09:14:13Z vboxsync $ */ /** @file * BS3Kit - bs3-cpu-basic-2, 32-bit C code. */ /* * Copyright (C) 2007-2016 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; * you can redistribute it and/or modify it under the terms of the GNU * General Public License (GPL) as published by the Free Software * Foundation, in version 2 as it comes in the "COPYING" file of the * VirtualBox OSE distribution. VirtualBox OSE is distributed in the * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. * * The contents of this file may alternatively be used under the terms * of the Common Development and Distribution License Version 1.0 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the * VirtualBox OSE distribution, in which case the provisions of the * CDDL are applicable instead of those of the GPL. * * You may elect to license modified versions of this file under the * terms and conditions of either the GPL or the CDDL or both. */ /********************************************************************************************************************************* * Header Files * *********************************************************************************************************************************/ #include /********************************************************************************************************************************* * Internal Functions * *********************************************************************************************************************************/ FNBS3TESTDOMODE bs3CpuBasic2_RaiseXcpt0e_c32; /** * Worker for bs3CpuBasic2_RaiseXcpt0e_c32 that does the actual testing. * * Caller does all the cleaning up. * * @returns Error count. * @param bMode The mode to test. * @param pbTestOrg Pointer to the actual memory allocation (low * memory) where it is identity mapped (virtual * address == physical address). This function * will not touch paging structures here. * @param pbTest Pointer to the aliased allocation in high * memory. This is aligned on a gigabyte boundrary * so that 1GB pages can be tested (later). * @param cbTest The size of the memory allocated for testing. * @param pPgInfo The paging info for @a pbTest. */ static uint8_t bs3CpuBasic2_RaiseXcpt0eWorker(uint8_t bMode, uint8_t *pbTestOrg, uint8_t *pbTest, uint32_t cbTest, PBS3PAGINGINFO4ADDR pPgInfo) { return 0; } BS3_DECL_CALLBACK(uint8_t) bs3CpuBasic2_RaiseXcpt0e_c32(uint8_t bMode) { void *pvTestUnaligned; uint32_t cbTestUnaligned = _8M; uint32_t cbTest; uint8_t *pbTest; uint8_t *pbAlias; uint8_t bRet = 1; int rc; /* * Allocate a some memory we can play around with, then carve a size aligned * chunk out of it so we might be able to maybe play with 2/4MB pages too. */ cbTestUnaligned = _8M * 2; while ((pvTestUnaligned = Bs3MemAlloc(BS3MEMKIND_FLAT32, cbTestUnaligned)) == NULL) { cbTestUnaligned >>= 1; if (cbTestUnaligned <= _8K) { Bs3TestFailed("Failed to allocate memory to play around with\n"); return 1; } } if ((uintptr_t)pvTestUnaligned & (cbTestUnaligned - 1)) { cbTest = cbTestUnaligned >> 1; pbTest = (uint8_t *)(((uintptr_t)pvTestUnaligned + cbTest - 1) & ~(cbTest - 1)); } else { pbTest = pvTestUnaligned; cbTest = cbTestUnaligned; } /* * Alias this memory far away from where our code and data lives. */ pbAlias = (uint8_t *)UINT32_C(0x80000000); rc = Bs3PagingAlias((uintptr_t)pbAlias, (uintptr_t)pbTest, cbTest, X86_PTE_P | X86_PTE_RW | X86_PTE_US); if (RT_SUCCESS(rc)) { BS3PAGINGINFO4ADDR PgInfo; rc = Bs3PagingQueryAddressInfo((uintptr_t)pbTest, &PgInfo); if (RT_SUCCESS(rc)) { /* * Setup a 16-bit selector for accessing the alias. */ // ==> office // Bs3TestPrintf("RaiseXcpt0e_c32: bMode=%#x/%#x cbTest=%#x pbTest=%p pbAlias=%p\n", bMode, g_bBs3CurrentMode, cbTest, pbTest, pbAlias); bRet = bs3CpuBasic2_RaiseXcpt0eWorker(bMode, pbTest, pbAlias, cbTest, &PgInfo); } else Bs3TestFailedF("Bs3PagingQueryAddressInfo failed: %d\n", rc); Bs3PagingUnalias((uintptr_t)pbAlias, cbTest); } else Bs3TestFailedF("Bs3PagingAlias failed! rc=%d\n", rc); Bs3MemFree(pvTestUnaligned, cbTestUnaligned); return bRet; }