1 | /* $Id: DBGFAddr.cpp 4198 2007-08-17 00:45:19Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VMM DBGF - Debugger Facility, Mixed Address Methods.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
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 as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*******************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *******************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_DBGF
|
---|
23 | #include <VBox/dbgf.h>
|
---|
24 | #include <VBox/selm.h>
|
---|
25 | #include "DBGFInternal.h"
|
---|
26 | #include <VBox/vm.h>
|
---|
27 | #include <VBox/mm.h>
|
---|
28 | #include <VBox/err.h>
|
---|
29 | #include <VBox/log.h>
|
---|
30 |
|
---|
31 |
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Checks if an address is in the HMA or not.
|
---|
35 | * @returns true if it's inside the HMA.
|
---|
36 | * @returns flase if it's not inside the HMA.
|
---|
37 | * @param pVM The VM handle.
|
---|
38 | * @param FlatPtr The address in question.
|
---|
39 | */
|
---|
40 | DECLINLINE(bool) dbgfR3IsHMA(PVM pVM, RTGCUINTPTR FlatPtr)
|
---|
41 | {
|
---|
42 | return MMHyperIsInsideArea(pVM, FlatPtr);
|
---|
43 | }
|
---|
44 |
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Creates a mixed address from a Sel:off pair.
|
---|
48 | *
|
---|
49 | * @returns VBox status code.
|
---|
50 | * @param pVM The VM handle.
|
---|
51 | * @param pAddress Where to store the mixed address.
|
---|
52 | * @param Sel The selector part.
|
---|
53 | * @param off The offset part.
|
---|
54 | */
|
---|
55 | DBGFR3DECL(int) DBGFR3AddrFromSelOff(PVM pVM, PDBGFADDRESS pAddress, RTSEL Sel, RTUINTPTR off)
|
---|
56 | {
|
---|
57 | pAddress->Sel = Sel;
|
---|
58 | pAddress->off = off;
|
---|
59 | if (Sel != DBGF_SEL_FLAT)
|
---|
60 | {
|
---|
61 | SELMSELINFO SelInfo;
|
---|
62 | int rc = SELMR3GetSelectorInfo(pVM, Sel, &SelInfo);
|
---|
63 | if (VBOX_FAILURE(rc))
|
---|
64 | return rc;
|
---|
65 |
|
---|
66 | /* check limit. */
|
---|
67 | if ( (SelInfo.Raw.Gen.u4Type & X86_SEL_TYPE_DOWN)
|
---|
68 | && SelInfo.Raw.Gen.u1DescType
|
---|
69 | && ( SelInfo.Raw.Gen.u4Type == X86_SEL_TYPE_RO_DOWN
|
---|
70 | || SelInfo.Raw.Gen.u4Type == X86_SEL_TYPE_RO_DOWN_ACC
|
---|
71 | || SelInfo.Raw.Gen.u4Type == X86_SEL_TYPE_RW_DOWN
|
---|
72 | || SelInfo.Raw.Gen.u4Type == X86_SEL_TYPE_RW_DOWN_ACC))
|
---|
73 | {
|
---|
74 | if (!SelInfo.Raw.Gen.u1Granularity && off > UINT32_C(0xffff))
|
---|
75 | return VERR_OUT_OF_SELECTOR_BOUNDS;
|
---|
76 | if (off <= SelInfo.cbLimit)
|
---|
77 | return VERR_OUT_OF_SELECTOR_BOUNDS;
|
---|
78 | }
|
---|
79 | else if (off > SelInfo.cbLimit)
|
---|
80 | return VERR_OUT_OF_SELECTOR_BOUNDS;
|
---|
81 |
|
---|
82 | pAddress->FlatPtr = SelInfo.GCPtrBase + off;
|
---|
83 | /** @todo fix this flat selector test! */
|
---|
84 | if ( !SelInfo.GCPtrBase
|
---|
85 | && SelInfo.Raw.Gen.u1Granularity
|
---|
86 | && SelInfo.Raw.Gen.u1DefBig)
|
---|
87 | pAddress->fFlags = DBGFADDRESS_FLAGS_FLAT;
|
---|
88 | else if (SelInfo.cbLimit <= UINT32_C(0xffff))
|
---|
89 | pAddress->fFlags = DBGFADDRESS_FLAGS_FAR16;
|
---|
90 | else if (SelInfo.cbLimit <= UINT32_C(0xffffffff))
|
---|
91 | pAddress->fFlags = DBGFADDRESS_FLAGS_FAR32;
|
---|
92 | else
|
---|
93 | pAddress->fFlags = DBGFADDRESS_FLAGS_FAR64;
|
---|
94 | }
|
---|
95 | else
|
---|
96 | {
|
---|
97 | pAddress->FlatPtr = off;
|
---|
98 | pAddress->fFlags = DBGFADDRESS_FLAGS_FLAT;
|
---|
99 | }
|
---|
100 | pAddress->fFlags |= DBGFADDRESS_FLAGS_VALID;
|
---|
101 | if (dbgfR3IsHMA(pVM, pAddress->FlatPtr))
|
---|
102 | pAddress->fFlags |= DBGFADDRESS_FLAGS_HMA;
|
---|
103 |
|
---|
104 | return VINF_SUCCESS;
|
---|
105 | }
|
---|
106 |
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Creates a mixed address from a flat address.
|
---|
110 | *
|
---|
111 | * @param pVM The VM handle.
|
---|
112 | * @param pAddress Where to store the mixed address.
|
---|
113 | * @param FlatPtr The flat pointer.
|
---|
114 | */
|
---|
115 | DBGFR3DECL(void) DBGFR3AddrFromFlat(PVM pVM, PDBGFADDRESS pAddress, RTGCUINTPTR FlatPtr)
|
---|
116 | {
|
---|
117 | pAddress->Sel = DBGF_SEL_FLAT;
|
---|
118 | pAddress->off = FlatPtr;
|
---|
119 | pAddress->FlatPtr = FlatPtr;
|
---|
120 | pAddress->fFlags = DBGFADDRESS_FLAGS_FLAT | DBGFADDRESS_FLAGS_VALID;
|
---|
121 | if (dbgfR3IsHMA(pVM, pAddress->FlatPtr))
|
---|
122 | pAddress->fFlags |= DBGFADDRESS_FLAGS_HMA;
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Checks if the specified address is valid (checks the structure pointer too).
|
---|
128 | *
|
---|
129 | * @returns true if valid.
|
---|
130 | * @returns false if invalid.
|
---|
131 | * @param pVM The VM handle.
|
---|
132 | * @param pAddress The address to validate.
|
---|
133 | */
|
---|
134 | DBGFR3DECL(bool) DBGFR3AddrIsValid(PVM pVM, PCDBGFADDRESS pAddress)
|
---|
135 | {
|
---|
136 | if (!VALID_PTR(pAddress))
|
---|
137 | return false;
|
---|
138 | if (!DBGFADDRESS_IS_VALID(pAddress))
|
---|
139 | return false;
|
---|
140 | /* more? */
|
---|
141 | return true;
|
---|
142 | }
|
---|