1 | /* $Id: bs3-cpu-basic-2-pf.c32 64735 2016-11-22 09:14:13Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * BS3Kit - bs3-cpu-basic-2, 32-bit C code.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2016 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*********************************************************************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *********************************************************************************************************************************/
|
---|
31 | #include <bs3kit.h>
|
---|
32 |
|
---|
33 |
|
---|
34 | /*********************************************************************************************************************************
|
---|
35 | * Internal Functions *
|
---|
36 | *********************************************************************************************************************************/
|
---|
37 | FNBS3TESTDOMODE bs3CpuBasic2_RaiseXcpt0e_c32;
|
---|
38 |
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Worker for bs3CpuBasic2_RaiseXcpt0e_c32 that does the actual testing.
|
---|
42 | *
|
---|
43 | * Caller does all the cleaning up.
|
---|
44 | *
|
---|
45 | * @returns Error count.
|
---|
46 | * @param bMode The mode to test.
|
---|
47 | * @param pbTestOrg Pointer to the actual memory allocation (low
|
---|
48 | * memory) where it is identity mapped (virtual
|
---|
49 | * address == physical address). This function
|
---|
50 | * will not touch paging structures here.
|
---|
51 | * @param pbTest Pointer to the aliased allocation in high
|
---|
52 | * memory. This is aligned on a gigabyte boundrary
|
---|
53 | * so that 1GB pages can be tested (later).
|
---|
54 | * @param cbTest The size of the memory allocated for testing.
|
---|
55 | * @param pPgInfo The paging info for @a pbTest.
|
---|
56 | */
|
---|
57 | static uint8_t bs3CpuBasic2_RaiseXcpt0eWorker(uint8_t bMode, uint8_t *pbTestOrg, uint8_t *pbTest, uint32_t cbTest,
|
---|
58 | PBS3PAGINGINFO4ADDR pPgInfo)
|
---|
59 | {
|
---|
60 |
|
---|
61 |
|
---|
62 | return 0;
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | BS3_DECL_CALLBACK(uint8_t) bs3CpuBasic2_RaiseXcpt0e_c32(uint8_t bMode)
|
---|
67 | {
|
---|
68 | void *pvTestUnaligned;
|
---|
69 | uint32_t cbTestUnaligned = _8M;
|
---|
70 | uint32_t cbTest;
|
---|
71 | uint8_t *pbTest;
|
---|
72 | uint8_t *pbAlias;
|
---|
73 | uint8_t bRet = 1;
|
---|
74 | int rc;
|
---|
75 |
|
---|
76 | /*
|
---|
77 | * Allocate a some memory we can play around with, then carve a size aligned
|
---|
78 | * chunk out of it so we might be able to maybe play with 2/4MB pages too.
|
---|
79 | */
|
---|
80 | cbTestUnaligned = _8M * 2;
|
---|
81 | while ((pvTestUnaligned = Bs3MemAlloc(BS3MEMKIND_FLAT32, cbTestUnaligned)) == NULL)
|
---|
82 | {
|
---|
83 | cbTestUnaligned >>= 1;
|
---|
84 | if (cbTestUnaligned <= _8K)
|
---|
85 | {
|
---|
86 | Bs3TestFailed("Failed to allocate memory to play around with\n");
|
---|
87 | return 1;
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | if ((uintptr_t)pvTestUnaligned & (cbTestUnaligned - 1))
|
---|
92 | {
|
---|
93 | cbTest = cbTestUnaligned >> 1;
|
---|
94 | pbTest = (uint8_t *)(((uintptr_t)pvTestUnaligned + cbTest - 1) & ~(cbTest - 1));
|
---|
95 | }
|
---|
96 | else
|
---|
97 | {
|
---|
98 | pbTest = pvTestUnaligned;
|
---|
99 | cbTest = cbTestUnaligned;
|
---|
100 | }
|
---|
101 |
|
---|
102 | /*
|
---|
103 | * Alias this memory far away from where our code and data lives.
|
---|
104 | */
|
---|
105 | pbAlias = (uint8_t *)UINT32_C(0x80000000);
|
---|
106 | rc = Bs3PagingAlias((uintptr_t)pbAlias, (uintptr_t)pbTest, cbTest, X86_PTE_P | X86_PTE_RW | X86_PTE_US);
|
---|
107 | if (RT_SUCCESS(rc))
|
---|
108 | {
|
---|
109 | BS3PAGINGINFO4ADDR PgInfo;
|
---|
110 | rc = Bs3PagingQueryAddressInfo((uintptr_t)pbTest, &PgInfo);
|
---|
111 | if (RT_SUCCESS(rc))
|
---|
112 | {
|
---|
113 | /*
|
---|
114 | * Setup a 16-bit selector for accessing the alias.
|
---|
115 | */
|
---|
116 | // ==> office //
|
---|
117 |
|
---|
118 | Bs3TestPrintf("RaiseXcpt0e_c32: bMode=%#x/%#x cbTest=%#x pbTest=%p pbAlias=%p\n",
|
---|
119 | bMode, g_bBs3CurrentMode, cbTest, pbTest, pbAlias);
|
---|
120 | bRet = bs3CpuBasic2_RaiseXcpt0eWorker(bMode, pbTest, pbAlias, cbTest, &PgInfo);
|
---|
121 |
|
---|
122 | }
|
---|
123 | else
|
---|
124 | Bs3TestFailedF("Bs3PagingQueryAddressInfo failed: %d\n", rc);
|
---|
125 | Bs3PagingUnalias((uintptr_t)pbAlias, cbTest);
|
---|
126 | }
|
---|
127 | else
|
---|
128 | Bs3TestFailedF("Bs3PagingAlias failed! rc=%d\n", rc);
|
---|
129 | Bs3MemFree(pvTestUnaligned, cbTestUnaligned);
|
---|
130 | return bRet;
|
---|
131 | }
|
---|
132 |
|
---|