VirtualBox

source: vbox/trunk/src/VBox/Debugger/DBGPlugInOS2.cpp@ 62840

Last change on this file since 62840 was 62840, checked in by vboxsync, 9 years ago

Debugger: warnings

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 KB
Line 
1/* $Id: DBGPlugInOS2.cpp 62840 2016-08-01 17:15:19Z vboxsync $ */
2/** @file
3 * DBGPlugInOS2 - Debugger and Guest OS Digger Plugin For OS/2.
4 */
5
6/*
7 * Copyright (C) 2009-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
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_DBGF ///@todo add new log group.
23#include "DBGPlugIns.h"
24#include <VBox/vmm/dbgf.h>
25#include <VBox/err.h>
26#include <VBox/param.h>
27#include <iprt/string.h>
28#include <iprt/mem.h>
29#include <iprt/stream.h>
30
31
32/*********************************************************************************************************************************
33* Structures and Typedefs *
34*********************************************************************************************************************************/
35
36/** @name Internal OS/2 structures */
37
38/** @} */
39
40
41typedef enum DBGDIGGEROS2VER
42{
43 DBGDIGGEROS2VER_UNKNOWN,
44 DBGDIGGEROS2VER_1_x,
45 DBGDIGGEROS2VER_2_x,
46 DBGDIGGEROS2VER_3_0,
47 DBGDIGGEROS2VER_4_0,
48 DBGDIGGEROS2VER_4_5
49} DBGDIGGEROS2VER;
50
51/**
52 * OS/2 guest OS digger instance data.
53 */
54typedef struct DBGDIGGEROS2
55{
56 /** Whether the information is valid or not.
57 * (For fending off illegal interface method calls.) */
58 bool fValid;
59 /** 32-bit (true) or 16-bit (false) */
60 bool f32Bit;
61
62 /** The OS/2 guest version. */
63 DBGDIGGEROS2VER enmVer;
64 uint8_t OS2MajorVersion;
65 uint8_t OS2MinorVersion;
66
67 /** Guest's Global Info Segment selector. */
68 uint16_t selGIS;
69
70} DBGDIGGEROS2;
71/** Pointer to the OS/2 guest OS digger instance data. */
72typedef DBGDIGGEROS2 *PDBGDIGGEROS2;
73
74
75/*********************************************************************************************************************************
76* Defined Constants And Macros *
77*********************************************************************************************************************************/
78/** The 'SAS ' signature. */
79#define DIG_OS2_SAS_SIG RT_MAKE_U32_FROM_U8('S','A','S',' ')
80
81/** OS/2Warp on little endian ASCII systems. */
82#define DIG_OS2_MOD_TAG UINT64_C(0x43532f3257617270)
83
84
85/*********************************************************************************************************************************
86* Internal Functions *
87*********************************************************************************************************************************/
88static DECLCALLBACK(int) dbgDiggerOS2Init(PUVM pUVM, void *pvData);
89
90
91/*********************************************************************************************************************************
92* Global Variables *
93*********************************************************************************************************************************/
94
95
96/**
97 * Process a PE image found in guest memory.
98 *
99 * @param pThis The instance data.
100 * @param pUVM The user mode VM handle.
101 * @param pszName The image name.
102 * @param pImageAddr The image address.
103 * @param cbImage The size of the image.
104 * @param pbBuf Scratch buffer containing the first
105 * RT_MIN(cbBuf, cbImage) bytes of the image.
106 * @param cbBuf The scratch buffer size.
107 */
108static void dbgDiggerOS2ProcessImage(PDBGDIGGEROS2 pThis, PUVM pUVM, const char *pszName,
109 PCDBGFADDRESS pImageAddr, uint32_t cbImage,
110 uint8_t *pbBuf, size_t cbBuf)
111{
112 RT_NOREF7(pThis, pUVM, pszName, pImageAddr, cbImage, pbBuf, cbBuf);
113 LogFlow(("DigOS2: %RGp %#x %s\n", pImageAddr->FlatPtr, cbImage, pszName));
114
115 /* To be implemented.*/
116}
117
118
119/**
120 * @copydoc DBGFOSREG::pfnQueryInterface
121 */
122static DECLCALLBACK(void *) dbgDiggerOS2QueryInterface(PUVM pUVM, void *pvData, DBGFOSINTERFACE enmIf)
123{
124 RT_NOREF3(pUVM, pvData, enmIf);
125 return NULL;
126}
127
128
129/**
130 * @copydoc DBGFOSREG::pfnQueryVersion
131 */
132static DECLCALLBACK(int) dbgDiggerOS2QueryVersion(PUVM pUVM, void *pvData, char *pszVersion, size_t cchVersion)
133{
134 RT_NOREF1(pUVM);
135 PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
136 Assert(pThis->fValid);
137 char *achOS2ProductType[32];
138 char *pszOS2ProductType = (char *)achOS2ProductType;
139
140 if (pThis->OS2MajorVersion == 10)
141 {
142 RTStrPrintf(pszOS2ProductType, sizeof(achOS2ProductType), "OS/2 1.%02d", pThis->OS2MinorVersion);
143 pThis->enmVer = DBGDIGGEROS2VER_1_x;
144 }
145 else if (pThis->OS2MajorVersion == 20)
146 {
147 if (pThis->OS2MinorVersion < 30)
148 {
149 RTStrPrintf(pszOS2ProductType, sizeof(achOS2ProductType), "OS/2 2.%02d", pThis->OS2MinorVersion);
150 pThis->enmVer = DBGDIGGEROS2VER_2_x;
151 }
152 else if (pThis->OS2MinorVersion < 40)
153 {
154 RTStrPrintf(pszOS2ProductType, sizeof(achOS2ProductType), "OS/2 Warp");
155 pThis->enmVer = DBGDIGGEROS2VER_3_0;
156 }
157 else if (pThis->OS2MinorVersion == 40)
158 {
159 RTStrPrintf(pszOS2ProductType, sizeof(achOS2ProductType), "OS/2 Warp 4");
160 pThis->enmVer = DBGDIGGEROS2VER_4_0;
161 }
162 else
163 {
164 RTStrPrintf(pszOS2ProductType, sizeof(achOS2ProductType), "OS/2 Warp %d.%d",
165 pThis->OS2MinorVersion / 10, pThis->OS2MinorVersion % 10);
166 pThis->enmVer = DBGDIGGEROS2VER_4_5;
167 }
168 }
169 RTStrPrintf(pszVersion, cchVersion, "%u.%u (%s)", pThis->OS2MajorVersion, pThis->OS2MinorVersion, pszOS2ProductType);
170 return VINF_SUCCESS;
171}
172
173
174/**
175 * @copydoc DBGFOSREG::pfnTerm
176 */
177static DECLCALLBACK(void) dbgDiggerOS2Term(PUVM pUVM, void *pvData)
178{
179 RT_NOREF1(pUVM);
180 PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
181 Assert(pThis->fValid);
182
183 pThis->fValid = false;
184}
185
186
187/**
188 * @copydoc DBGFOSREG::pfnRefresh
189 */
190static DECLCALLBACK(int) dbgDiggerOS2Refresh(PUVM pUVM, void *pvData)
191{
192 PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
193 NOREF(pThis);
194 Assert(pThis->fValid);
195
196 /*
197 * For now we'll flush and reload everything.
198 */
199 RTDBGAS hDbgAs = DBGFR3AsResolveAndRetain(pUVM, DBGF_AS_KERNEL);
200 if (hDbgAs != NIL_RTDBGAS)
201 {
202 uint32_t iMod = RTDbgAsModuleCount(hDbgAs);
203 while (iMod-- > 0)
204 {
205 RTDBGMOD hMod = RTDbgAsModuleByIndex(hDbgAs, iMod);
206 if (hMod != NIL_RTDBGMOD)
207 {
208 if (RTDbgModGetTag(hMod) == DIG_OS2_MOD_TAG)
209 {
210 int rc = RTDbgAsModuleUnlink(hDbgAs, hMod);
211 AssertRC(rc);
212 }
213 RTDbgModRelease(hMod);
214 }
215 }
216 RTDbgAsRelease(hDbgAs);
217 }
218
219 dbgDiggerOS2Term(pUVM, pvData);
220 return dbgDiggerOS2Init(pUVM, pvData);
221}
222
223
224/**
225 * @copydoc DBGFOSREG::pfnInit
226 */
227static DECLCALLBACK(int) dbgDiggerOS2Init(PUVM pUVM, void *pvData)
228{
229 PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
230 Assert(!pThis->fValid);
231
232 union
233 {
234 uint8_t au8[0x2000];
235 uint16_t au16[0x2000/2];
236 uint32_t au32[0x2000/4];
237 RTUTF16 wsz[0x2000/2];
238 } u;
239 DBGFADDRESS Addr;
240 int rc;
241
242 /*
243 * Determine the OS/2 version.
244 */
245 do {
246 /* Version info is at GIS:15h (major/minor/revision). */
247 rc = DBGFR3AddrFromSelOff(pUVM, 0 /*idCpu*/, &Addr, pThis->selGIS, 0x15);
248 if (RT_FAILURE(rc))
249 break;
250 rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, &Addr, u.au32, sizeof(uint32_t));
251 if (RT_FAILURE(rc))
252 break;
253
254 pThis->OS2MajorVersion = u.au8[0];
255 pThis->OS2MinorVersion = u.au8[1];
256
257 pThis->fValid = true;
258 return VINF_SUCCESS;
259 } while (0);
260 return VERR_NOT_SUPPORTED;
261}
262
263
264/**
265 * @copydoc DBGFOSREG::pfnProbe
266 */
267static DECLCALLBACK(bool) dbgDiggerOS2Probe(PUVM pUVM, void *pvData)
268{
269 PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
270 DBGFADDRESS Addr;
271 int rc;
272 uint16_t offInfo;
273 union
274 {
275 uint8_t au8[8192];
276 uint16_t au16[8192/2];
277 uint32_t au32[8192/4];
278 RTUTF16 wsz[8192/2];
279 } u;
280
281 /*
282 * If the DWORD at 70:0 contains 'SAS ' it's quite unlikely that this wouldn't be OS/2.
283 * Note: The SAS layout is similar between 16-bit and 32-bit OS/2, but not identical.
284 * 32-bit OS/2 will have the flat kernel data selector at SAS:06. The selector is 168h
285 * or similar. For 16-bit OS/2 the field contains a table offset into the SAS which will
286 * be much smaller. Fun fact: The global infoseg selector in the SAS is bimodal in 16-bit
287 * OS/2 and will work in real mode as well.
288 */
289 do {
290 rc = DBGFR3AddrFromSelOff(pUVM, 0 /*idCpu*/, &Addr, 0x70, 0x00);
291 if (RT_FAILURE(rc))
292 break;
293 rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, &Addr, u.au32, 256);
294 if (RT_FAILURE(rc))
295 break;
296 if (u.au32[0] != DIG_OS2_SAS_SIG)
297 break;
298
299 /* This sure looks like OS/2, but a bit of paranoia won't hurt. */
300 if (u.au16[2] >= u.au16[4])
301 break;
302
303 /* If 4th word is bigger than 5th, it's the flat kernel mode selector. */
304 if (u.au16[3] > u.au16[4])
305 pThis->f32Bit = true;
306
307 /* Offset into info table is either at SAS:14h or SAS:16h. */
308 if (pThis->f32Bit)
309 offInfo = u.au16[0x14/2];
310 else
311 offInfo = u.au16[0x16/2];
312
313 /* The global infoseg selector is the first entry in the info table. */
314 pThis->selGIS = u.au16[offInfo/2];
315 return true;
316 } while (0);
317
318 return false;
319}
320
321
322/**
323 * @copydoc DBGFOSREG::pfnDestruct
324 */
325static DECLCALLBACK(void) dbgDiggerOS2Destruct(PUVM pUVM, void *pvData)
326{
327 RT_NOREF2(pUVM, pvData);
328}
329
330
331/**
332 * @copydoc DBGFOSREG::pfnConstruct
333 */
334static DECLCALLBACK(int) dbgDiggerOS2Construct(PUVM pUVM, void *pvData)
335{
336 RT_NOREF1(pUVM);
337 PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
338 pThis->fValid = false;
339 pThis->f32Bit = false;
340 pThis->enmVer = DBGDIGGEROS2VER_UNKNOWN;
341 return VINF_SUCCESS;
342}
343
344
345const DBGFOSREG g_DBGDiggerOS2 =
346{
347 /* .u32Magic = */ DBGFOSREG_MAGIC,
348 /* .fFlags = */ 0,
349 /* .cbData = */ sizeof(DBGDIGGEROS2),
350 /* .szName = */ "OS/2",
351 /* .pfnConstruct = */ dbgDiggerOS2Construct,
352 /* .pfnDestruct = */ dbgDiggerOS2Destruct,
353 /* .pfnProbe = */ dbgDiggerOS2Probe,
354 /* .pfnInit = */ dbgDiggerOS2Init,
355 /* .pfnRefresh = */ dbgDiggerOS2Refresh,
356 /* .pfnTerm = */ dbgDiggerOS2Term,
357 /* .pfnQueryVersion = */ dbgDiggerOS2QueryVersion,
358 /* .pfnQueryInterface = */ dbgDiggerOS2QueryInterface,
359 /* .u32EndMagic = */ DBGFOSREG_MAGIC
360};
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette