VirtualBox

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

Last change on this file since 95638 was 93470, checked in by vboxsync, 3 years ago

DbgPlugInDiggers,VMM,Main: Refactored the diggers and related interfaces to work via the VMM function table. Removed non-working tstVBoxDbg (needs proper COM now). bugref:10072

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 47.9 KB
Line 
1/* $Id: DBGPlugInOS2.cpp 93470 2022-01-27 23:51:28Z vboxsync $ */
2/** @file
3 * DBGPlugInOS2 - Debugger and Guest OS Digger Plugin For OS/2.
4 */
5
6/*
7 * Copyright (C) 2009-2022 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/vmmr3vtable.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
36typedef enum DBGDIGGEROS2VER
37{
38 DBGDIGGEROS2VER_UNKNOWN,
39 DBGDIGGEROS2VER_1_x,
40 DBGDIGGEROS2VER_2_x,
41 DBGDIGGEROS2VER_3_0,
42 DBGDIGGEROS2VER_4_0,
43 DBGDIGGEROS2VER_4_5
44} DBGDIGGEROS2VER;
45
46/**
47 * OS/2 guest OS digger instance data.
48 */
49typedef struct DBGDIGGEROS2
50{
51 /** The user-mode VM handle for use in info handlers. */
52 PUVM pUVM;
53 /** The VMM function table for use in info handlers. */
54 PCVMMR3VTABLE pVMM;
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 /** The 16:16 address of the LIS. */
70 RTFAR32 Lis;
71
72 /** The kernel virtual address (excluding DOSMVDMINSTDATA & DOSSWAPINSTDATA). */
73 uint32_t uKernelAddr;
74 /** The kernel size. */
75 uint32_t cbKernel;
76
77} DBGDIGGEROS2;
78/** Pointer to the OS/2 guest OS digger instance data. */
79typedef DBGDIGGEROS2 *PDBGDIGGEROS2;
80
81/**
82 * 32-bit OS/2 loader module table entry.
83 */
84typedef struct LDRMTE
85{
86 uint16_t mte_flags2;
87 uint16_t mte_handle;
88 uint32_t mte_swapmte; /**< Pointer to LDRSMTE. */
89 uint32_t mte_link; /**< Pointer to next LDRMTE. */
90 uint32_t mte_flags1;
91 uint32_t mte_impmodcnt;
92 uint16_t mte_sfn;
93 uint16_t mte_usecnt;
94 char mte_modname[8];
95 uint32_t mte_RAS; /**< added later */
96 uint32_t mte_modver; /**< added even later. */
97} LDRMTE;
98/** @name LDRMTE::mte_flag2 values
99 * @{ */
100#define MTEFORMATMASK UINT16_C(0x0003)
101#define MTEFORMATR1 UINT16_C(0x0000)
102#define MTEFORMATNE UINT16_C(0x0001)
103#define MTEFORMATLX UINT16_C(0x0002)
104#define MTEFORMATR2 UINT16_C(0x0003)
105#define MTESYSTEMDLL UINT16_C(0x0004)
106#define MTELOADORATTACH UINT16_C(0x0008)
107#define MTECIRCLEREF UINT16_C(0x0010)
108#define MTEFREEFIXUPS UINT16_C(0x0020) /* had different meaning earlier */
109#define MTEPRELOADED UINT16_C(0x0040)
110#define MTEGETMTEDONE UINT16_C(0x0080)
111#define MTEPACKSEGDONE UINT16_C(0x0100)
112#define MTE20LIELIST UINT16_C(0x0200)
113#define MTESYSPROCESSED UINT16_C(0x0400)
114#define MTEPSDMOD UINT16_C(0x0800)
115#define MTEDLLONEXTLST UINT16_C(0x1000)
116#define MTEPDUMPCIRCREF UINT16_C(0x2000)
117/** @} */
118/** @name LDRMTE::mte_flag1 values
119 * @{ */
120#define MTE1_NOAUTODS UINT32_C(0x00000000)
121#define MTE1_SOLO UINT32_C(0x00000001)
122#define MTE1_INSTANCEDS UINT32_C(0x00000002)
123#define MTE1_INSTLIBINIT UINT32_C(0x00000004)
124#define MTE1_GINISETUP UINT32_C(0x00000008)
125#define MTE1_NOINTERNFIXUPS UINT32_C(0x00000010)
126#define MTE1_NOEXTERNFIXUPS UINT32_C(0x00000020)
127#define MTE1_CLASS_ALL UINT32_C(0x00000000)
128#define MTE1_CLASS_PROGRAM UINT32_C(0x00000040)
129#define MTE1_CLASS_GLOBAL UINT32_C(0x00000080)
130#define MTE1_CLASS_SPECIFIC UINT32_C(0x000000c0)
131#define MTE1_CLASS_MASK UINT32_C(0x000000c0)
132#define MTE1_MTEPROCESSED UINT32_C(0x00000100)
133#define MTE1_USED UINT32_C(0x00000200)
134#define MTE1_DOSLIB UINT32_C(0x00000400)
135#define MTE1_DOSMOD UINT32_C(0x00000800) /**< The OS/2 kernel (DOSCALLS).*/
136#define MTE1_MEDIAFIXED UINT32_C(0x00001000)
137#define MTE1_LDRINVALID UINT32_C(0x00002000)
138#define MTE1_PROGRAMMOD UINT32_C(0x00000000)
139#define MTE1_DEVDRVMOD UINT32_C(0x00004000)
140#define MTE1_LIBRARYMOD UINT32_C(0x00008000)
141#define MTE1_VDDMOD UINT32_C(0x00010000)
142#define MTE1_MVDMMOD UINT32_C(0x00020000)
143#define MTE1_INGRAPH UINT32_C(0x00040000)
144#define MTE1_GINIDONE UINT32_C(0x00080000)
145#define MTE1_ADDRALLOCED UINT32_C(0x00100000)
146#define MTE1_FSDMOD UINT32_C(0x00200000)
147#define MTE1_FSHMOD UINT32_C(0x00400000)
148#define MTE1_LONGNAMES UINT32_C(0x00800000)
149#define MTE1_MEDIACONTIG UINT32_C(0x01000000)
150#define MTE1_MEDIA16M UINT32_C(0x02000000)
151#define MTE1_SWAPONLOAD UINT32_C(0x04000000)
152#define MTE1_PORTHOLE UINT32_C(0x08000000)
153#define MTE1_MODPROT UINT32_C(0x10000000)
154#define MTE1_NEWMOD UINT32_C(0x20000000)
155#define MTE1_DLLTERM UINT32_C(0x40000000)
156#define MTE1_SYMLOADED UINT32_C(0x80000000)
157/** @} */
158
159
160/**
161 * 32-bit OS/2 swappable module table entry.
162 */
163typedef struct LDRSMTE
164{
165 uint32_t smte_mpages; /**< 0x00: module page count. */
166 uint32_t smte_startobj; /**< 0x04: Entrypoint segment number. */
167 uint32_t smte_eip; /**< 0x08: Entrypoint offset value. */
168 uint32_t smte_stackobj; /**< 0x0c: Stack segment number. */
169 uint32_t smte_esp; /**< 0x10: Stack offset value*/
170 uint32_t smte_pageshift; /**< 0x14: Page shift value. */
171 uint32_t smte_fixupsize; /**< 0x18: Size of the fixup section. */
172 uint32_t smte_objtab; /**< 0x1c: Pointer to LDROTE array. */
173 uint32_t smte_objcnt; /**< 0x20: Number of segments. */
174 uint32_t smte_objmap; /**< 0x20: Address of the object page map. */
175 uint32_t smte_itermap; /**< 0x20: File offset of the iterated data map*/
176 uint32_t smte_rsrctab; /**< 0x20: Pointer to resource table? */
177 uint32_t smte_rsrccnt; /**< 0x30: Number of resource table entries. */
178 uint32_t smte_restab; /**< 0x30: Pointer to the resident name table. */
179 uint32_t smte_enttab; /**< 0x30: Possibly entry point table address, if not file offset. */
180 uint32_t smte_fpagetab; /**< 0x30 */
181 uint32_t smte_frectab; /**< 0x40 */
182 uint32_t smte_impmod; /**< 0x44 */
183 uint32_t smte_impproc; /**< 0x48 */
184 uint32_t smte_datapage; /**< 0x4c */
185 uint32_t smte_nrestab; /**< 0x50 */
186 uint32_t smte_cbnrestab; /**< 0x54 */
187 uint32_t smte_autods; /**< 0x58 */
188 uint32_t smte_debuginfo; /**< 0x5c */
189 uint32_t smte_debuglen; /**< 0x60 */
190 uint32_t smte_heapsize; /**< 0x64 */
191 uint32_t smte_path; /**< 0x68 Address of full name string. */
192 uint16_t smte_semcount; /**< 0x6c */
193 uint16_t smte_semowner; /**< 0x6e */
194 uint32_t smte_pfilecache; /**< 0x70: Address of cached data if replace-module is used. */
195 uint32_t smte_stacksize; /**< 0x74: Stack size for .exe thread 1. */
196 uint16_t smte_alignshift; /**< 0x78: */
197 uint16_t smte_NEexpver; /**< 0x7a: */
198 uint16_t smte_pathlen; /**< 0x7c: Length of smte_path */
199 uint16_t smte_NEexetype; /**< 0x7e: */
200 uint16_t smte_csegpack; /**< 0x80: */
201 uint8_t smte_major_os; /**< 0x82: added later to lie about OS version */
202 uint8_t smte_minor_os; /**< 0x83: added later to lie about OS version */
203} LDRSMTE;
204AssertCompileSize(LDRSMTE, 0x84);
205
206typedef struct LDROTE
207{
208 uint32_t ote_size;
209 uint32_t ote_base;
210 uint32_t ote_flags;
211 uint32_t ote_pagemap;
212 uint32_t ote_mapsize;
213 union
214 {
215 uint32_t ote_vddaddr;
216 uint32_t ote_krnaddr;
217 struct
218 {
219 uint16_t ote_selector;
220 uint16_t ote_handle;
221 } s;
222 };
223} LDROTE;
224AssertCompileSize(LDROTE, 24);
225
226
227/**
228 * 32-bit system anchor block segment header.
229 */
230typedef struct SAS
231{
232 uint8_t SAS_signature[4];
233 uint16_t SAS_tables_data; /**< Offset to SASTABLES. */
234 uint16_t SAS_flat_sel; /**< 32-bit kernel DS (flat). */
235 uint16_t SAS_config_data; /**< Offset to SASCONFIG. */
236 uint16_t SAS_dd_data; /**< Offset to SASDD. */
237 uint16_t SAS_vm_data; /**< Offset to SASVM. */
238 uint16_t SAS_task_data; /**< Offset to SASTASK. */
239 uint16_t SAS_RAS_data; /**< Offset to SASRAS. */
240 uint16_t SAS_file_data; /**< Offset to SASFILE. */
241 uint16_t SAS_info_data; /**< Offset to SASINFO. */
242 uint16_t SAS_mp_data; /**< Offset to SASMP. SMP only. */
243} SAS;
244#define SAS_SIGNATURE "SAS "
245
246typedef struct SASTABLES
247{
248 uint16_t SAS_tbl_GDT;
249 uint16_t SAS_tbl_LDT;
250 uint16_t SAS_tbl_IDT;
251 uint16_t SAS_tbl_GDTPOOL;
252} SASTABLES;
253
254typedef struct SASCONFIG
255{
256 uint16_t SAS_config_table;
257} SASCONFIG;
258
259typedef struct SASDD
260{
261 uint16_t SAS_dd_bimodal_chain;
262 uint16_t SAS_dd_real_chain;
263 uint16_t SAS_dd_DPB_segment;
264 uint16_t SAS_dd_CDA_anchor_p;
265 uint16_t SAS_dd_CDA_anchor_r;
266 uint16_t SAS_dd_FSC;
267} SASDD;
268
269typedef struct SASVM
270{
271 uint32_t SAS_vm_arena;
272 uint32_t SAS_vm_object;
273 uint32_t SAS_vm_context;
274 uint32_t SAS_vm_krnl_mte; /**< Flat address of kernel MTE. */
275 uint32_t SAS_vm_glbl_mte; /**< Flat address of global MTE list head pointer variable. */
276 uint32_t SAS_vm_pft;
277 uint32_t SAS_vm_prt;
278 uint32_t SAS_vm_swap;
279 uint32_t SAS_vm_idle_head;
280 uint32_t SAS_vm_free_head;
281 uint32_t SAS_vm_heap_info;
282 uint32_t SAS_vm_all_mte; /**< Flat address of global MTE list head pointer variable. */
283} SASVM;
284
285
286#pragma pack(1)
287typedef struct SASTASK
288{
289 uint16_t SAS_task_PTDA; /**< Current PTDA selector. */
290 uint32_t SAS_task_ptdaptrs; /**< Flat address of process tree root. */
291 uint32_t SAS_task_threadptrs; /**< Flat address array of thread pointer array. */
292 uint32_t SAS_task_tasknumber; /**< Flat address of the TaskNumber variable. */
293 uint32_t SAS_task_threadcount; /**< Flat address of the ThreadCount variable. */
294} SASTASK;
295#pragma pack()
296
297
298#pragma pack(1)
299typedef struct SASRAS
300{
301 uint16_t SAS_RAS_STDA_p;
302 uint16_t SAS_RAS_STDA_r;
303 uint16_t SAS_RAS_event_mask;
304 uint32_t SAS_RAS_Perf_Buff;
305} SASRAS;
306#pragma pack()
307
308typedef struct SASFILE
309{
310 uint32_t SAS_file_MFT; /**< Handle. */
311 uint16_t SAS_file_SFT; /**< Selector. */
312 uint16_t SAS_file_VPB; /**< Selector. */
313 uint16_t SAS_file_CDS; /**< Selector. */
314 uint16_t SAS_file_buffers; /**< Selector. */
315} SASFILE;
316
317#pragma pack(1)
318typedef struct SASINFO
319{
320 uint16_t SAS_info_global; /**< GIS selector. */
321 uint32_t SAS_info_local; /**< 16:16 address of LIS for current task. */
322 uint32_t SAS_info_localRM;
323 uint16_t SAS_info_CDIB; /**< Selector. */
324} SASINFO;
325#pragma pack()
326
327typedef struct SASMP
328{
329 uint32_t SAS_mp_PCBFirst; /**< Flat address of PCB head. */
330 uint32_t SAS_mp_pLockHandles; /**< Flat address of lock handles. */
331 uint32_t SAS_mp_cProcessors; /**< Flat address of CPU count variable. */
332 uint32_t SAS_mp_pIPCInfo; /**< Flat address of IPC info pointer variable. */
333 uint32_t SAS_mp_pIPCHistory; /**< Flat address of IPC history pointer. */
334 uint32_t SAS_mp_IPCHistoryIdx; /**< Flat address of IPC history index variable. */
335 uint32_t SAS_mp_pFirstPSA; /**< Flat address of PSA. Added later. */
336 uint32_t SAS_mp_pPSAPages; /**< Flat address of PSA pages. */
337} SASMP;
338
339
340typedef struct OS2GIS
341{
342 uint32_t time;
343 uint32_t msecs;
344 uint8_t hour;
345 uint8_t minutes;
346 uint8_t seconds;
347 uint8_t hundredths;
348 int16_t timezone;
349 uint16_t cusecTimerInterval;
350 uint8_t day;
351 uint8_t month;
352 uint16_t year;
353 uint8_t weekday;
354 uint8_t uchMajorVersion;
355 uint8_t uchMinorVersion;
356 uint8_t chRevisionLetter;
357 uint8_t sgCurrent;
358 uint8_t sgMax;
359 uint8_t cHugeShift;
360 uint8_t fProtectModeOnly;
361 uint16_t pidForeground;
362 uint8_t fDynamicSched;
363 uint8_t csecMaxWait;
364 uint16_t cmsecMinSlice;
365 uint16_t cmsecMaxSlice;
366 uint16_t bootdrive;
367 uint8_t amecRAS[32];
368 uint8_t csgWindowableVioMax;
369 uint8_t csgPMMax;
370 uint16_t SIS_Syslog;
371 uint16_t SIS_MMIOBase;
372 uint16_t SIS_MMIOAddr;
373 uint8_t SIS_MaxVDMs;
374 uint8_t SIS_Reserved;
375} OS2GIS;
376
377typedef struct OS2LIS
378{
379 uint16_t pidCurrent;
380 uint16_t pidParent;
381 uint16_t prtyCurrent;
382 uint16_t tidCurrent;
383 uint16_t sgCurrent;
384 uint8_t rfProcStatus;
385 uint8_t bReserved1;
386 uint16_t fForeground;
387 uint8_t typeProcess;
388 uint8_t bReserved2;
389 uint16_t selEnvironment;
390 uint16_t offCmdLine;
391 uint16_t cbDataSegment;
392 uint16_t cbStack;
393 uint16_t cbHeap;
394 uint16_t hmod;
395 uint16_t selDS;
396} OS2LIS;
397
398
399/*********************************************************************************************************************************
400* Defined Constants And Macros *
401*********************************************************************************************************************************/
402/** The 'SAS ' signature. */
403#define DIG_OS2_SAS_SIG RT_MAKE_U32_FROM_U8('S','A','S',' ')
404
405/** OS/2Warp on little endian ASCII systems. */
406#define DIG_OS2_MOD_TAG UINT64_C(0x43532f3257617270)
407
408
409/*********************************************************************************************************************************
410* Internal Functions *
411*********************************************************************************************************************************/
412static DECLCALLBACK(int) dbgDiggerOS2Init(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData);
413
414
415static int dbgDiggerOS2DisplaySelectorAndInfoEx(PDBGDIGGEROS2 pThis, PCDBGFINFOHLP pHlp, uint16_t uSel, uint32_t off,
416 int cchWidth, const char *pszMessage, PDBGFSELINFO pSelInfo)
417{
418 RT_ZERO(*pSelInfo);
419 int rc = pThis->pVMM->pfnDBGFR3SelQueryInfo(pThis->pUVM, 0 /*idCpu*/, uSel, DBGFSELQI_FLAGS_DT_GUEST, pSelInfo);
420 if (RT_SUCCESS(rc))
421 {
422 if (off == UINT32_MAX)
423 pHlp->pfnPrintf(pHlp, "%*s: %#06x (%RGv LB %#RX64 flags=%#x)\n",
424 cchWidth, pszMessage, uSel, pSelInfo->GCPtrBase, pSelInfo->cbLimit, pSelInfo->fFlags);
425 else
426 pHlp->pfnPrintf(pHlp, "%*s: %04x:%04x (%RGv LB %#RX64 flags=%#x)\n",
427 cchWidth, pszMessage, uSel, off, pSelInfo->GCPtrBase + off, pSelInfo->cbLimit - off, pSelInfo->fFlags);
428 }
429 else if (off == UINT32_MAX)
430 pHlp->pfnPrintf(pHlp, "%*s: %#06x (%Rrc)\n", cchWidth, pszMessage, uSel, rc);
431 else
432 pHlp->pfnPrintf(pHlp, "%*s: %04x:%04x (%Rrc)\n", cchWidth, pszMessage, uSel, off, rc);
433 return rc;
434}
435
436DECLINLINE(int) dbgDiggerOS2DisplaySelectorAndInfo(PDBGDIGGEROS2 pThis, PCDBGFINFOHLP pHlp, uint16_t uSel, uint32_t off,
437 int cchWidth, const char *pszMessage)
438{
439 DBGFSELINFO SelInfo;
440 return dbgDiggerOS2DisplaySelectorAndInfoEx(pThis, pHlp, uSel, off, cchWidth, pszMessage, &SelInfo);
441}
442
443
444/**
445 * @callback_method_impl{FNDBGFHANDLEREXT,
446 * Display the OS/2 system anchor segment}
447 */
448static DECLCALLBACK(void) dbgDiggerOS2InfoSas(void *pvUser, PCDBGFINFOHLP pHlp, const char *pszArgs)
449{
450 RT_NOREF(pszArgs);
451 PDBGDIGGEROS2 const pThis = (PDBGDIGGEROS2)pvUser;
452 PUVM const pUVM = pThis->pUVM;
453 PCVMMR3VTABLE const pVMM = pThis->pVMM;
454
455 DBGFSELINFO SelInfo;
456 int rc = pVMM->pfnDBGFR3SelQueryInfo(pUVM, 0 /*idCpu*/, 0x70, DBGFSELQI_FLAGS_DT_GUEST, &SelInfo);
457 if (RT_FAILURE(rc))
458 {
459 pHlp->pfnPrintf(pHlp, "DBGFR3SelQueryInfo failed on selector 0x70: %Rrc\n", rc);
460 return;
461 }
462 pHlp->pfnPrintf(pHlp, "Selector 0x70: %RGv LB %#RX64 (flags %#x)\n",
463 SelInfo.GCPtrBase, (uint64_t)SelInfo.cbLimit, SelInfo.fFlags);
464
465 /*
466 * The SAS header.
467 */
468 union
469 {
470 SAS Sas;
471 uint16_t au16Sas[sizeof(SAS) / sizeof(uint16_t)];
472 };
473 DBGFADDRESS Addr;
474 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0 /*idCpu*/, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, SelInfo.GCPtrBase),
475 &Sas, sizeof(Sas));
476 if (RT_FAILURE(rc))
477 {
478 pHlp->pfnPrintf(pHlp, "Failed to read SAS header: %Rrc\n", rc);
479 return;
480 }
481 if (memcmp(&Sas.SAS_signature[0], SAS_SIGNATURE, sizeof(Sas.SAS_signature)) != 0)
482 {
483 pHlp->pfnPrintf(pHlp, "Invalid SAS signature: %#x %#x %#x %#x (expected %#x %#x %#x %#x)\n",
484 Sas.SAS_signature[0], Sas.SAS_signature[1], Sas.SAS_signature[2], Sas.SAS_signature[3],
485 SAS_SIGNATURE[0], SAS_SIGNATURE[1], SAS_SIGNATURE[2], SAS_SIGNATURE[3]);
486 return;
487 }
488 dbgDiggerOS2DisplaySelectorAndInfo(pThis, pHlp, Sas.SAS_flat_sel, UINT32_MAX, 15, "Flat kernel DS");
489 pHlp->pfnPrintf(pHlp, "SAS_tables_data: %#06x (%#RGv)\n", Sas.SAS_tables_data, SelInfo.GCPtrBase + Sas.SAS_tables_data);
490 pHlp->pfnPrintf(pHlp, "SAS_config_data: %#06x (%#RGv)\n", Sas.SAS_config_data, SelInfo.GCPtrBase + Sas.SAS_config_data);
491 pHlp->pfnPrintf(pHlp, " SAS_dd_data: %#06x (%#RGv)\n", Sas.SAS_dd_data, SelInfo.GCPtrBase + Sas.SAS_dd_data);
492 pHlp->pfnPrintf(pHlp, " SAS_vm_data: %#06x (%#RGv)\n", Sas.SAS_vm_data, SelInfo.GCPtrBase + Sas.SAS_vm_data);
493 pHlp->pfnPrintf(pHlp, " SAS_task_data: %#06x (%#RGv)\n", Sas.SAS_task_data, SelInfo.GCPtrBase + Sas.SAS_task_data);
494 pHlp->pfnPrintf(pHlp, " SAS_RAS_data: %#06x (%#RGv)\n", Sas.SAS_RAS_data, SelInfo.GCPtrBase + Sas.SAS_RAS_data);
495 pHlp->pfnPrintf(pHlp, " SAS_file_data: %#06x (%#RGv)\n", Sas.SAS_file_data, SelInfo.GCPtrBase + Sas.SAS_file_data);
496 pHlp->pfnPrintf(pHlp, " SAS_info_data: %#06x (%#RGv)\n", Sas.SAS_info_data, SelInfo.GCPtrBase + Sas.SAS_info_data);
497 bool fIncludeMP = true;
498 if (Sas.SAS_mp_data < sizeof(Sas))
499 fIncludeMP = false;
500 else
501 for (unsigned i = 2; i < RT_ELEMENTS(au16Sas) - 1; i++)
502 if (au16Sas[i] < sizeof(SAS))
503 {
504 fIncludeMP = false;
505 break;
506 }
507 if (fIncludeMP)
508 pHlp->pfnPrintf(pHlp, " SAS_mp_data: %#06x (%#RGv)\n", Sas.SAS_mp_data, SelInfo.GCPtrBase + Sas.SAS_mp_data);
509
510 /* shared databuf */
511 union
512 {
513 SASINFO Info;
514 } u;
515
516 /*
517 * Info data.
518 */
519 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0 /*idCpu*/,
520 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, SelInfo.GCPtrBase + Sas.SAS_info_data),
521 &u.Info, sizeof(u.Info));
522 if (RT_SUCCESS(rc))
523 {
524 pHlp->pfnPrintf(pHlp, "SASINFO:\n");
525 dbgDiggerOS2DisplaySelectorAndInfo(pThis, pHlp, u.Info.SAS_info_global, UINT32_MAX, 28, "Global info segment");
526 pHlp->pfnPrintf(pHlp, "%28s: %#010x\n", "Local info segment", u.Info.SAS_info_local);
527 pHlp->pfnPrintf(pHlp, "%28s: %#010x\n", "Local info segment (RM)", u.Info.SAS_info_localRM);
528 dbgDiggerOS2DisplaySelectorAndInfo(pThis, pHlp, u.Info.SAS_info_CDIB, UINT32_MAX, 28, "SAS_info_CDIB");
529 }
530 else
531 pHlp->pfnPrintf(pHlp, "Failed to read SAS info data: %Rrc\n", rc);
532
533 /** @todo more */
534}
535
536
537/**
538 * @callback_method_impl{FNDBGFHANDLEREXT,
539 * Display the OS/2 global info segment}
540 */
541static DECLCALLBACK(void) dbgDiggerOS2InfoGis(void *pvUser, PCDBGFINFOHLP pHlp, const char *pszArgs)
542{
543 RT_NOREF(pszArgs);
544 PDBGDIGGEROS2 const pThis = (PDBGDIGGEROS2)pvUser;
545 PUVM const pUVM = pThis->pUVM;
546 PCVMMR3VTABLE const pVMM = pThis->pVMM;
547
548 DBGFSELINFO SelInfo;
549 int rc = dbgDiggerOS2DisplaySelectorAndInfoEx(pThis, pHlp, pThis->selGis, UINT32_MAX, 0, "Global info segment", &SelInfo);
550 if (RT_FAILURE(rc))
551 return;
552
553 /*
554 * Read the GIS.
555 */
556 DBGFADDRESS Addr;
557 OS2GIS Gis;
558 RT_ZERO(Gis);
559 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0 /*idCpu*/, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, SelInfo.GCPtrBase), &Gis,
560 RT_MIN(sizeof(Gis), SelInfo.cbLimit + 1));
561 if (RT_FAILURE(rc))
562 {
563 pHlp->pfnPrintf(pHlp, "Failed to read GIS: %Rrc\n", rc);
564 return;
565 }
566 pHlp->pfnPrintf(pHlp, " time: %#010x\n", Gis.time);
567 pHlp->pfnPrintf(pHlp, " msecs: %#010x\n", Gis.msecs);
568 pHlp->pfnPrintf(pHlp, " timestamp: %04u-%02u-%02u %02u:%02u:%02u.%02u\n",
569 Gis.year, Gis.month, Gis.day, Gis.hour, Gis.minutes, Gis.seconds, Gis.hundredths);
570 pHlp->pfnPrintf(pHlp, " timezone: %+2d (min delta)\n", (int)Gis.timezone);
571 pHlp->pfnPrintf(pHlp, " weekday: %u\n", Gis.weekday);
572 pHlp->pfnPrintf(pHlp, " cusecTimerInterval: %u\n", Gis.cusecTimerInterval);
573 pHlp->pfnPrintf(pHlp, " version: %u.%u\n", Gis.uchMajorVersion, Gis.uchMinorVersion);
574 pHlp->pfnPrintf(pHlp, " revision: %#04x (%c)\n", Gis.chRevisionLetter, Gis.chRevisionLetter);
575 pHlp->pfnPrintf(pHlp, " current screen grp: %#04x (%u)\n", Gis.sgCurrent, Gis.sgCurrent);
576 pHlp->pfnPrintf(pHlp, " max screen groups: %#04x (%u)\n", Gis.sgMax, Gis.sgMax);
577 pHlp->pfnPrintf(pHlp, "csgWindowableVioMax: %#x (%u)\n", Gis.csgWindowableVioMax, Gis.csgWindowableVioMax);
578 pHlp->pfnPrintf(pHlp, " csgPMMax: %#x (%u)\n", Gis.csgPMMax, Gis.csgPMMax);
579 pHlp->pfnPrintf(pHlp, " cHugeShift: %#04x\n", Gis.cHugeShift);
580 pHlp->pfnPrintf(pHlp, " fProtectModeOnly: %d\n", Gis.fProtectModeOnly);
581 pHlp->pfnPrintf(pHlp, " pidForeground: %#04x (%u)\n", Gis.pidForeground, Gis.pidForeground);
582 pHlp->pfnPrintf(pHlp, " fDynamicSched: %u\n", Gis.fDynamicSched);
583 pHlp->pfnPrintf(pHlp, " csecMaxWait: %u\n", Gis.csecMaxWait);
584 pHlp->pfnPrintf(pHlp, " cmsecMinSlice: %u\n", Gis.cmsecMinSlice);
585 pHlp->pfnPrintf(pHlp, " cmsecMaxSlice: %u\n", Gis.cmsecMaxSlice);
586 pHlp->pfnPrintf(pHlp, " bootdrive: %#x\n", Gis.bootdrive);
587 pHlp->pfnPrintf(pHlp, " amecRAS: %.32Rhxs\n", &Gis.amecRAS[0]);
588 pHlp->pfnPrintf(pHlp, " SIS_Syslog: %#06x (%u)\n", Gis.SIS_Syslog, Gis.SIS_Syslog);
589 pHlp->pfnPrintf(pHlp, " SIS_MMIOBase: %#06x\n", Gis.SIS_MMIOBase);
590 pHlp->pfnPrintf(pHlp, " SIS_MMIOAddr: %#06x\n", Gis.SIS_MMIOAddr);
591 pHlp->pfnPrintf(pHlp, " SIS_MaxVDMs: %#04x (%u)\n", Gis.SIS_MaxVDMs, Gis.SIS_MaxVDMs);
592 pHlp->pfnPrintf(pHlp, " SIS_Reserved: %#04x\n", Gis.SIS_Reserved);
593}
594
595
596/**
597 * @callback_method_impl{FNDBGFHANDLEREXT,
598 * Display the OS/2 local info segment}
599 */
600static DECLCALLBACK(void) dbgDiggerOS2InfoLis(void *pvUser, PCDBGFINFOHLP pHlp, const char *pszArgs)
601{
602 RT_NOREF(pszArgs);
603 PDBGDIGGEROS2 const pThis = (PDBGDIGGEROS2)pvUser;
604 PUVM const pUVM = pThis->pUVM;
605 PCVMMR3VTABLE const pVMM = pThis->pVMM;
606
607 DBGFSELINFO SelInfo;
608 int rc = dbgDiggerOS2DisplaySelectorAndInfoEx(pThis, pHlp, pThis->Lis.sel, pThis->Lis.off, 19, "Local info segment", &SelInfo);
609 if (RT_FAILURE(rc))
610 return;
611
612 /*
613 * Read the LIS.
614 */
615 DBGFADDRESS Addr;
616 OS2LIS Lis;
617 RT_ZERO(Lis);
618 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0 /*idCpu*/, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, SelInfo.GCPtrBase + pThis->Lis.off),
619 &Lis, sizeof(Lis));
620 if (RT_FAILURE(rc))
621 {
622 pHlp->pfnPrintf(pHlp, "Failed to read LIS: %Rrc\n", rc);
623 return;
624 }
625 pHlp->pfnPrintf(pHlp, " pidCurrent: %#06x (%u)\n", Lis.pidCurrent, Lis.pidCurrent);
626 pHlp->pfnPrintf(pHlp, " pidParent: %#06x (%u)\n", Lis.pidParent, Lis.pidParent);
627 pHlp->pfnPrintf(pHlp, " prtyCurrent: %#06x (%u)\n", Lis.prtyCurrent, Lis.prtyCurrent);
628 pHlp->pfnPrintf(pHlp, " tidCurrent: %#06x (%u)\n", Lis.tidCurrent, Lis.tidCurrent);
629 pHlp->pfnPrintf(pHlp, " sgCurrent: %#06x (%u)\n", Lis.sgCurrent, Lis.sgCurrent);
630 pHlp->pfnPrintf(pHlp, " rfProcStatus: %#04x\n", Lis.rfProcStatus);
631 if (Lis.bReserved1)
632 pHlp->pfnPrintf(pHlp, " bReserved1: %#04x\n", Lis.bReserved1);
633 pHlp->pfnPrintf(pHlp, " fForeground: %#04x (%u)\n", Lis.fForeground, Lis.fForeground);
634 pHlp->pfnPrintf(pHlp, " typeProcess: %#04x (%u)\n", Lis.typeProcess, Lis.typeProcess);
635 if (Lis.bReserved2)
636 pHlp->pfnPrintf(pHlp, " bReserved2: %#04x\n", Lis.bReserved2);
637 dbgDiggerOS2DisplaySelectorAndInfo(pThis, pHlp, Lis.selEnvironment, UINT32_MAX, 19, "selEnvironment");
638 pHlp->pfnPrintf(pHlp, " offCmdLine: %#06x (%u)\n", Lis.offCmdLine, Lis.offCmdLine);
639 pHlp->pfnPrintf(pHlp, " cbDataSegment: %#06x (%u)\n", Lis.cbDataSegment, Lis.cbDataSegment);
640 pHlp->pfnPrintf(pHlp, " cbStack: %#06x (%u)\n", Lis.cbStack, Lis.cbStack);
641 pHlp->pfnPrintf(pHlp, " cbHeap: %#06x (%u)\n", Lis.cbHeap, Lis.cbHeap);
642 pHlp->pfnPrintf(pHlp, " hmod: %#06x\n", Lis.hmod); /** @todo look up the name*/
643 dbgDiggerOS2DisplaySelectorAndInfo(pThis, pHlp, Lis.selDS, UINT32_MAX, 19, "selDS");
644}
645
646
647/**
648 * @callback_method_impl{FNDBGFHANDLEREXT,
649 * Display the OS/2 panic message}
650 */
651static DECLCALLBACK(void) dbgDiggerOS2InfoPanic(void *pvUser, PCDBGFINFOHLP pHlp, const char *pszArgs)
652{
653 RT_NOREF(pszArgs);
654 PDBGDIGGEROS2 const pThis = (PDBGDIGGEROS2)pvUser;
655 PUVM const pUVM = pThis->pUVM;
656 PCVMMR3VTABLE const pVMM = pThis->pVMM;
657
658 DBGFADDRESS HitAddr;
659 int rc = pVMM->pfnDBGFR3MemScan(pUVM, 0 /*idCpu*/, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &HitAddr, pThis->uKernelAddr),
660 pThis->cbKernel, 1, RT_STR_TUPLE("Exception in module:"), &HitAddr);
661 if (RT_FAILURE(rc))
662 rc = pVMM->pfnDBGFR3MemScan(pUVM, 0 /*idCpu&*/, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &HitAddr, pThis->uKernelAddr),
663 pThis->cbKernel, 1, RT_STR_TUPLE("Exception in device driver:"), &HitAddr);
664 /** @todo support pre-2001 kernels w/o the module/drivce name. */
665 if (RT_SUCCESS(rc))
666 {
667 char szMsg[728 + 1];
668 RT_ZERO(szMsg);
669 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &HitAddr, szMsg, sizeof(szMsg) - 1);
670 if (szMsg[0] != '\0')
671 {
672 RTStrPurgeEncoding(szMsg);
673 char *psz = szMsg;
674 while (*psz != '\0')
675 {
676 char *pszEol = strchr(psz, '\r');
677 if (pszEol)
678 *pszEol = '\0';
679 pHlp->pfnPrintf(pHlp, "%s\n", psz);
680 if (!pszEol)
681 break;
682 psz = ++pszEol;
683 if (*psz == '\n')
684 psz++;
685 }
686 }
687 else
688 pHlp->pfnPrintf(pHlp, "DBGFR3MemRead -> %Rrc\n", rc);
689 }
690 else
691 pHlp->pfnPrintf(pHlp, "Unable to locate OS/2 panic message. (%Rrc)\n", rc);
692}
693
694
695
696/**
697 * @copydoc DBGFOSREG::pfnStackUnwindAssist
698 */
699static DECLCALLBACK(int) dbgDiggerOS2StackUnwindAssist(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData, VMCPUID idCpu,
700 PDBGFSTACKFRAME pFrame, PRTDBGUNWINDSTATE pState, PCCPUMCTX pInitialCtx,
701 RTDBGAS hAs, uint64_t *puScratch)
702{
703 RT_NOREF(pUVM, pVMM, pvData, idCpu, pFrame, pState, pInitialCtx, hAs, puScratch);
704 return VINF_SUCCESS;
705}
706
707
708/**
709 * @copydoc DBGFOSREG::pfnQueryInterface
710 */
711static DECLCALLBACK(void *) dbgDiggerOS2QueryInterface(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData, DBGFOSINTERFACE enmIf)
712{
713 RT_NOREF(pUVM, pVMM, pvData, enmIf);
714 return NULL;
715}
716
717
718/**
719 * @copydoc DBGFOSREG::pfnQueryVersion
720 */
721static DECLCALLBACK(int) dbgDiggerOS2QueryVersion(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData,
722 char *pszVersion, size_t cchVersion)
723{
724 PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
725 RT_NOREF(pUVM, pVMM);
726 Assert(pThis->fValid);
727
728 char *achOS2ProductType[32];
729 char *pszOS2ProductType = (char *)achOS2ProductType;
730
731 if (pThis->OS2MajorVersion == 10)
732 {
733 RTStrPrintf(pszOS2ProductType, sizeof(achOS2ProductType), "OS/2 1.%02d", pThis->OS2MinorVersion);
734 pThis->enmVer = DBGDIGGEROS2VER_1_x;
735 }
736 else if (pThis->OS2MajorVersion == 20)
737 {
738 if (pThis->OS2MinorVersion < 30)
739 {
740 RTStrPrintf(pszOS2ProductType, sizeof(achOS2ProductType), "OS/2 2.%02d", pThis->OS2MinorVersion);
741 pThis->enmVer = DBGDIGGEROS2VER_2_x;
742 }
743 else if (pThis->OS2MinorVersion < 40)
744 {
745 RTStrPrintf(pszOS2ProductType, sizeof(achOS2ProductType), "OS/2 Warp");
746 pThis->enmVer = DBGDIGGEROS2VER_3_0;
747 }
748 else if (pThis->OS2MinorVersion == 40)
749 {
750 RTStrPrintf(pszOS2ProductType, sizeof(achOS2ProductType), "OS/2 Warp 4");
751 pThis->enmVer = DBGDIGGEROS2VER_4_0;
752 }
753 else
754 {
755 RTStrPrintf(pszOS2ProductType, sizeof(achOS2ProductType), "OS/2 Warp %d.%d",
756 pThis->OS2MinorVersion / 10, pThis->OS2MinorVersion % 10);
757 pThis->enmVer = DBGDIGGEROS2VER_4_5;
758 }
759 }
760 RTStrPrintf(pszVersion, cchVersion, "%u.%u (%s)", pThis->OS2MajorVersion, pThis->OS2MinorVersion, pszOS2ProductType);
761 return VINF_SUCCESS;
762}
763
764
765/**
766 * @copydoc DBGFOSREG::pfnTerm
767 */
768static DECLCALLBACK(void) dbgDiggerOS2Term(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
769{
770 PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
771 Assert(pThis->fValid);
772
773 pVMM->pfnDBGFR3InfoDeregisterExternal(pUVM, "sas");
774 pVMM->pfnDBGFR3InfoDeregisterExternal(pUVM, "gis");
775 pVMM->pfnDBGFR3InfoDeregisterExternal(pUVM, "lis");
776 pVMM->pfnDBGFR3InfoDeregisterExternal(pUVM, "panic");
777
778 pThis->fValid = false;
779}
780
781
782/**
783 * @copydoc DBGFOSREG::pfnRefresh
784 */
785static DECLCALLBACK(int) dbgDiggerOS2Refresh(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
786{
787 PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
788 NOREF(pThis);
789 Assert(pThis->fValid);
790
791 /*
792 * For now we'll flush and reload everything.
793 */
794 RTDBGAS hDbgAs = pVMM->pfnDBGFR3AsResolveAndRetain(pUVM, DBGF_AS_KERNEL);
795 if (hDbgAs != NIL_RTDBGAS)
796 {
797 uint32_t iMod = RTDbgAsModuleCount(hDbgAs);
798 while (iMod-- > 0)
799 {
800 RTDBGMOD hMod = RTDbgAsModuleByIndex(hDbgAs, iMod);
801 if (hMod != NIL_RTDBGMOD)
802 {
803 if (RTDbgModGetTag(hMod) == DIG_OS2_MOD_TAG)
804 {
805 int rc = RTDbgAsModuleUnlink(hDbgAs, hMod);
806 AssertRC(rc);
807 }
808 RTDbgModRelease(hMod);
809 }
810 }
811 RTDbgAsRelease(hDbgAs);
812 }
813
814 dbgDiggerOS2Term(pUVM, pVMM, pvData);
815 return dbgDiggerOS2Init(pUVM, pVMM, pvData);
816}
817
818
819/** Buffer shared by dbgdiggerOS2ProcessModule and dbgDiggerOS2Init.*/
820typedef union DBGDIGGEROS2BUF
821{
822 uint8_t au8[0x2000];
823 uint16_t au16[0x2000/2];
824 uint32_t au32[0x2000/4];
825 RTUTF16 wsz[0x2000/2];
826 char ach[0x2000];
827 LDROTE aOtes[0x2000 / sizeof(LDROTE)];
828 SAS sas;
829 SASVM sasvm;
830 LDRMTE mte;
831 LDRSMTE smte;
832 LDROTE ote;
833} DBGDIGGEROS2BUF;
834
835/** Arguments dbgdiggerOS2ProcessModule passes to the module open callback. */
836typedef struct
837{
838 const char *pszModPath;
839 const char *pszModName;
840 LDRMTE const *pMte;
841 LDRSMTE const *pSwapMte;
842} DBGDIGGEROS2OPEN;
843
844
845/**
846 * @callback_method_impl{FNRTDBGCFGOPEN, Debug image/image searching callback.}
847 */
848static DECLCALLBACK(int) dbgdiggerOs2OpenModule(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2)
849{
850 DBGDIGGEROS2OPEN *pArgs = (DBGDIGGEROS2OPEN *)pvUser1;
851
852 RTDBGMOD hDbgMod = NIL_RTDBGMOD;
853 int rc = RTDbgModCreateFromImage(&hDbgMod, pszFilename, pArgs->pszModName, RTLDRARCH_WHATEVER, hDbgCfg);
854 if (RT_SUCCESS(rc))
855 {
856 /** @todo Do some info matching before using it? */
857
858 *(PRTDBGMOD)pvUser2 = hDbgMod;
859 return VINF_CALLBACK_RETURN;
860 }
861 LogRel(("DbgDiggerOs2: dbgdiggerOs2OpenModule: %Rrc - %s\n", rc, pszFilename));
862 return rc;
863}
864
865
866static void dbgdiggerOS2ProcessModule(PUVM pUVM, PCVMMR3VTABLE pVMM, PDBGDIGGEROS2 pThis, DBGDIGGEROS2BUF *pBuf,
867 const char *pszCacheSubDir, RTDBGAS hAs, RTDBGCFG hDbgCfg)
868{
869 RT_NOREF(pThis);
870
871 /*
872 * Save the MTE.
873 */
874 static const char * const s_apszMteFmts[4] = { "Reserved1", "NE", "LX", "Reserved2" };
875 LDRMTE const Mte = pBuf->mte;
876 if ((Mte.mte_flags2 & MTEFORMATMASK) != MTEFORMATLX)
877 {
878 LogRel(("DbgDiggerOs2: MTE format not implemented: %s (%d)\n",
879 s_apszMteFmts[(Mte.mte_flags2 & MTEFORMATMASK)], Mte.mte_flags2 & MTEFORMATMASK));
880 return;
881 }
882
883 /*
884 * Don't load program modules into the global address spaces.
885 */
886 if ((Mte.mte_flags1 & MTE1_CLASS_MASK) == MTE1_CLASS_PROGRAM)
887 {
888 LogRel(("DbgDiggerOs2: Program module, skipping.\n"));
889 return;
890 }
891
892 /*
893 * Try read the swappable MTE. Save it too.
894 */
895 DBGFADDRESS Addr;
896 int rc = pVMM->pfnDBGFR3MemRead(pUVM, 0 /*idCpu*/, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, Mte.mte_swapmte),
897 &pBuf->smte, sizeof(pBuf->smte));
898 if (RT_FAILURE(rc))
899 {
900 LogRel(("DbgDiggerOs2: Error reading swap mte @ %RX32: %Rrc\n", Mte.mte_swapmte, rc));
901 return;
902 }
903 LDRSMTE const SwapMte = pBuf->smte;
904
905 /* Ignore empty modules or modules with too many segments. */
906 if (SwapMte.smte_objcnt == 0 || SwapMte.smte_objcnt > RT_ELEMENTS(pBuf->aOtes))
907 {
908 LogRel(("DbgDiggerOs2: Skipping: smte_objcnt= %#RX32\n", SwapMte.smte_objcnt));
909 return;
910 }
911
912 /*
913 * Try read the path name, falling back on module name.
914 */
915 char szModPath[260];
916 rc = VERR_READ_ERROR;
917 if (SwapMte.smte_path != 0 && SwapMte.smte_pathlen > 0)
918 {
919 uint32_t cbToRead = RT_MIN(SwapMte.smte_path, sizeof(szModPath) - 1);
920 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0 /*idCpu*/, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, SwapMte.smte_path),
921 szModPath, cbToRead);
922 szModPath[cbToRead] = '\0';
923 }
924 if (RT_FAILURE(rc))
925 {
926 memcpy(szModPath, Mte.mte_modname, sizeof(Mte.mte_modname));
927 szModPath[sizeof(Mte.mte_modname)] = '\0';
928 RTStrStripR(szModPath);
929 }
930 LogRel(("DbgDiggerOS2: szModPath='%s'\n", szModPath));
931
932 /*
933 * Sanitize the module name.
934 */
935 char szModName[16];
936 memcpy(szModName, Mte.mte_modname, sizeof(Mte.mte_modname));
937 szModName[sizeof(Mte.mte_modname)] = '\0';
938 RTStrStripR(szModName);
939
940 /*
941 * Read the object table into the buffer.
942 */
943 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0 /*idCpu*/, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, SwapMte.smte_objtab),
944 &pBuf->aOtes[0], sizeof(pBuf->aOtes[0]) * SwapMte.smte_objcnt);
945 if (RT_FAILURE(rc))
946 {
947 LogRel(("DbgDiggerOs2: Error reading object table @ %#RX32 LB %#zx: %Rrc\n",
948 SwapMte.smte_objtab, sizeof(pBuf->aOtes[0]) * SwapMte.smte_objcnt, rc));
949 return;
950 }
951 for (uint32_t i = 0; i < SwapMte.smte_objcnt; i++)
952 {
953 LogRel(("DbgDiggerOs2: seg%u: %RX32 LB %#x\n", i, pBuf->aOtes[i].ote_base, pBuf->aOtes[i].ote_size));
954 /** @todo validate it. */
955 }
956
957 /*
958 * If it is the kernel, take down the general address range so we can easily search
959 * it all in one go when looking for panic messages and such.
960 */
961 if (Mte.mte_flags1 & MTE1_DOSMOD)
962 {
963 uint32_t uMax = 0;
964 uint32_t uMin = UINT32_MAX;
965 for (uint32_t i = 0; i < SwapMte.smte_objcnt; i++)
966 if (pBuf->aOtes[i].ote_base > _512M)
967 {
968 if (pBuf->aOtes[i].ote_base < uMin)
969 uMin = pBuf->aOtes[i].ote_base;
970 uint32_t uTmp = pBuf->aOtes[i].ote_base + pBuf->aOtes[i].ote_size;
971 if (uTmp > uMax)
972 uMax = uTmp;
973 }
974 if (uMax != 0)
975 {
976 pThis->uKernelAddr = uMin;
977 pThis->cbKernel = uMax - uMin;
978 LogRel(("DbgDiggerOs2: High kernel range: %#RX32 LB %#RX32 (%#RX32)\n", uMin, pThis->cbKernel, uMax));
979 }
980 }
981
982 /*
983 * No need to continue without an address space (shouldn't happen).
984 */
985 if (hAs == NIL_RTDBGAS)
986 return;
987
988 /*
989 * Try find a debug file for this module.
990 */
991 RTDBGMOD hDbgMod = NIL_RTDBGMOD;
992 if (hDbgCfg != NIL_RTDBGCFG)
993 {
994 DBGDIGGEROS2OPEN Args = { szModPath, szModName, &Mte, &SwapMte };
995 RTDbgCfgOpenEx(hDbgCfg, szModPath, pszCacheSubDir, NULL,
996 RT_OPSYS_OS2 | RTDBGCFG_O_CASE_INSENSITIVE | RTDBGCFG_O_EXECUTABLE_IMAGE
997 | RTDBGCFG_O_RECURSIVE | RTDBGCFG_O_NO_SYSTEM_PATHS,
998 dbgdiggerOs2OpenModule, &Args, &hDbgMod);
999 }
1000
1001 /*
1002 * Fallback is a simple module into which we insert sections.
1003 */
1004 uint32_t cSegments = SwapMte.smte_objcnt;
1005 if (hDbgMod == NIL_RTDBGMOD)
1006 {
1007 rc = RTDbgModCreate(&hDbgMod, szModName, 0 /*cbSeg*/, 0 /*fFlags*/);
1008 if (RT_SUCCESS(rc))
1009 {
1010 uint32_t uRva = 0;
1011 for (uint32_t i = 0; i < SwapMte.smte_objcnt; i++)
1012 {
1013 char szSegNm[16];
1014 RTStrPrintf(szSegNm, sizeof(szSegNm), "seg%u", i);
1015 rc = RTDbgModSegmentAdd(hDbgMod, uRva, pBuf->aOtes[i].ote_size, szSegNm, 0 /*fFlags*/, NULL);
1016 if (RT_FAILURE(rc))
1017 {
1018 LogRel(("DbgDiggerOs2: RTDbgModSegmentAdd failed (i=%u, ote_size=%#x): %Rrc\n",
1019 i, pBuf->aOtes[i].ote_size, rc));
1020 cSegments = i;
1021 break;
1022 }
1023 uRva += RT_ALIGN_32(pBuf->aOtes[i].ote_size, _4K);
1024 }
1025 }
1026 else
1027 {
1028 LogRel(("DbgDiggerOs2: RTDbgModCreate failed: %Rrc\n", rc));
1029 return;
1030 }
1031 }
1032
1033 /*
1034 * Tag the module and link its segments.
1035 */
1036 rc = RTDbgModSetTag(hDbgMod, DIG_OS2_MOD_TAG);
1037 if (RT_SUCCESS(rc))
1038 {
1039 for (uint32_t i = 0; i < SwapMte.smte_objcnt; i++)
1040 if (pBuf->aOtes[i].ote_base != 0)
1041 {
1042 rc = RTDbgAsModuleLinkSeg(hAs, hDbgMod, i, pBuf->aOtes[i].ote_base, RTDBGASLINK_FLAGS_REPLACE /*fFlags*/);
1043 if (RT_FAILURE(rc))
1044 LogRel(("DbgDiggerOs2: RTDbgAsModuleLinkSeg failed (i=%u, ote_base=%#x): %Rrc\n",
1045 i, pBuf->aOtes[i].ote_base, rc));
1046 }
1047 }
1048 else
1049 LogRel(("DbgDiggerOs2: RTDbgModSetTag failed: %Rrc\n", rc));
1050 RTDbgModRelease(hDbgMod);
1051}
1052
1053
1054/**
1055 * @copydoc DBGFOSREG::pfnInit
1056 */
1057static DECLCALLBACK(int) dbgDiggerOS2Init(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
1058{
1059 PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
1060 Assert(!pThis->fValid);
1061
1062 DBGDIGGEROS2BUF uBuf;
1063 DBGFADDRESS Addr;
1064 int rc;
1065
1066 /*
1067 * Determine the OS/2 version.
1068 */
1069 /* Version info is at GIS:15h (major/minor/revision). */
1070 rc = pVMM->pfnDBGFR3AddrFromSelOff(pUVM, 0 /*idCpu*/, &Addr, pThis->selGis, 0x15);
1071 if (RT_FAILURE(rc))
1072 return VERR_NOT_SUPPORTED;
1073 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0 /*idCpu*/, &Addr, uBuf.au32, sizeof(uint32_t));
1074 if (RT_FAILURE(rc))
1075 return VERR_NOT_SUPPORTED;
1076
1077 pThis->OS2MajorVersion = uBuf.au8[0];
1078 pThis->OS2MinorVersion = uBuf.au8[1];
1079
1080 pThis->fValid = true;
1081
1082 /*
1083 * Try use SAS to find the module list.
1084 */
1085 rc = pVMM->pfnDBGFR3AddrFromSelOff(pUVM, 0 /*idCpu*/, &Addr, 0x70, 0x00);
1086 if (RT_SUCCESS(rc))
1087 {
1088 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0 /*idCpu*/, &Addr, &uBuf.sas, sizeof(uBuf.sas));
1089 if (RT_SUCCESS(rc))
1090 {
1091 rc = pVMM->pfnDBGFR3AddrFromSelOff(pUVM, 0 /*idCpu*/, &Addr, 0x70, uBuf.sas.SAS_vm_data);
1092 if (RT_SUCCESS(rc))
1093 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0 /*idCpu*/, &Addr, &uBuf.sasvm, sizeof(uBuf.sasvm));
1094 if (RT_SUCCESS(rc))
1095 {
1096 /*
1097 * Work the module list.
1098 */
1099 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0 /*idCpu*/, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, uBuf.sasvm.SAS_vm_all_mte),
1100 &uBuf.au32[0], sizeof(uBuf.au32[0]));
1101 if (RT_SUCCESS(rc))
1102 {
1103 uint32_t uOs2Krnl = UINT32_MAX;
1104 RTDBGCFG hDbgCfg = pVMM->pfnDBGFR3AsGetConfig(pUVM); /* (don't release this) */
1105 RTDBGAS hAs = pVMM->pfnDBGFR3AsResolveAndRetain(pUVM, DBGF_AS_GLOBAL);
1106
1107 char szCacheSubDir[24];
1108 RTStrPrintf(szCacheSubDir, sizeof(szCacheSubDir), "os2-%u.%u", pThis->OS2MajorVersion, pThis->OS2MinorVersion);
1109
1110 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, uBuf.au32[0]);
1111 while (Addr.FlatPtr != 0 && Addr.FlatPtr != UINT32_MAX)
1112 {
1113 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0 /*idCpu*/, &Addr, &uBuf.mte, sizeof(uBuf.mte));
1114 if (RT_FAILURE(rc))
1115 break;
1116 LogRel(("DbgDiggerOs2: Module @ %#010RX32: %.8s %#x %#x\n", (uint32_t)Addr.FlatPtr,
1117 uBuf.mte.mte_modname, uBuf.mte.mte_flags1, uBuf.mte.mte_flags2));
1118 if (uBuf.mte.mte_flags1 & MTE1_DOSMOD)
1119 uOs2Krnl = (uint32_t)Addr.FlatPtr;
1120
1121 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, uBuf.mte.mte_link);
1122 dbgdiggerOS2ProcessModule(pUVM, pVMM, pThis, &uBuf, szCacheSubDir, hAs, hDbgCfg);
1123 }
1124
1125 /* Load the kernel again. To make sure we didn't drop any segments due
1126 to overlap/conflicts/whatever. */
1127 if (uOs2Krnl != UINT32_MAX)
1128 {
1129 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0 /*idCpu*/, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, uOs2Krnl),
1130 &uBuf.mte, sizeof(uBuf.mte));
1131 if (RT_SUCCESS(rc))
1132 {
1133 LogRel(("DbgDiggerOs2: Module @ %#010RX32: %.8s %#x %#x [again]\n", (uint32_t)Addr.FlatPtr,
1134 uBuf.mte.mte_modname, uBuf.mte.mte_flags1, uBuf.mte.mte_flags2));
1135 dbgdiggerOS2ProcessModule(pUVM, pVMM, pThis, &uBuf, szCacheSubDir, hAs, hDbgCfg);
1136 }
1137 }
1138
1139 RTDbgAsRelease(hAs);
1140 }
1141 }
1142 }
1143 }
1144
1145 /*
1146 * Register info handlers.
1147 */
1148 pVMM->pfnDBGFR3InfoRegisterExternal(pUVM, "sas", "Dumps the OS/2 system anchor block (SAS).", dbgDiggerOS2InfoSas, pThis);
1149 pVMM->pfnDBGFR3InfoRegisterExternal(pUVM, "gis", "Dumps the OS/2 global info segment (GIS).", dbgDiggerOS2InfoGis, pThis);
1150 pVMM->pfnDBGFR3InfoRegisterExternal(pUVM, "lis", "Dumps the OS/2 local info segment (current process).", dbgDiggerOS2InfoLis, pThis);
1151 pVMM->pfnDBGFR3InfoRegisterExternal(pUVM, "panic", "Dumps the OS/2 system panic message.", dbgDiggerOS2InfoPanic, pThis);
1152
1153 return VINF_SUCCESS;
1154}
1155
1156
1157/**
1158 * @copydoc DBGFOSREG::pfnProbe
1159 */
1160static DECLCALLBACK(bool) dbgDiggerOS2Probe(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
1161{
1162 PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
1163 DBGFADDRESS Addr;
1164 int rc;
1165 uint16_t offInfo;
1166 union
1167 {
1168 uint8_t au8[8192];
1169 uint16_t au16[8192/2];
1170 uint32_t au32[8192/4];
1171 RTUTF16 wsz[8192/2];
1172 } u;
1173
1174 /*
1175 * If the DWORD at 70:0 is 'SAS ' it's quite unlikely that this wouldn't be OS/2.
1176 * Note: The SAS layout is similar between 16-bit and 32-bit OS/2, but not identical.
1177 * 32-bit OS/2 will have the flat kernel data selector at SAS:06. The selector is 168h
1178 * or similar. For 16-bit OS/2 the field contains a table offset into the SAS which will
1179 * be much smaller. Fun fact: The global infoseg selector in the SAS is bimodal in 16-bit
1180 * OS/2 and will work in real mode as well.
1181 */
1182 do {
1183 rc = pVMM->pfnDBGFR3AddrFromSelOff(pUVM, 0 /*idCpu*/, &Addr, 0x70, 0x00);
1184 if (RT_FAILURE(rc))
1185 break;
1186 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0 /*idCpu*/, &Addr, u.au32, 256);
1187 if (RT_FAILURE(rc))
1188 break;
1189 if (u.au32[0] != DIG_OS2_SAS_SIG)
1190 break;
1191
1192 /* This sure looks like OS/2, but a bit of paranoia won't hurt. */
1193 if (u.au16[2] >= u.au16[4])
1194 break;
1195
1196 /* If 4th word is bigger than 5th, it's the flat kernel mode selector. */
1197 if (u.au16[3] > u.au16[4])
1198 pThis->f32Bit = true;
1199
1200 /* Offset into info table is either at SAS:14h or SAS:16h. */
1201 if (pThis->f32Bit)
1202 offInfo = u.au16[0x14/2];
1203 else
1204 offInfo = u.au16[0x16/2];
1205
1206 /* The global infoseg selector is the first entry in the info table. */
1207 SASINFO const *pInfo = (SASINFO const *)&u.au8[offInfo];
1208 pThis->selGis = pInfo->SAS_info_global;
1209 pThis->Lis.sel = RT_HI_U16(pInfo->SAS_info_local);
1210 pThis->Lis.off = RT_LO_U16(pInfo->SAS_info_local);
1211 return true;
1212 } while (0);
1213
1214 return false;
1215}
1216
1217
1218/**
1219 * @copydoc DBGFOSREG::pfnDestruct
1220 */
1221static DECLCALLBACK(void) dbgDiggerOS2Destruct(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
1222{
1223 RT_NOREF(pUVM, pVMM, pvData);
1224}
1225
1226
1227/**
1228 * @copydoc DBGFOSREG::pfnConstruct
1229 */
1230static DECLCALLBACK(int) dbgDiggerOS2Construct(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
1231{
1232 PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
1233 pThis->fValid = false;
1234 pThis->f32Bit = false;
1235 pThis->enmVer = DBGDIGGEROS2VER_UNKNOWN;
1236 pThis->pUVM = pUVM;
1237 pThis->pVMM = pVMM;
1238 return VINF_SUCCESS;
1239}
1240
1241
1242const DBGFOSREG g_DBGDiggerOS2 =
1243{
1244 /* .u32Magic = */ DBGFOSREG_MAGIC,
1245 /* .fFlags = */ 0,
1246 /* .cbData = */ sizeof(DBGDIGGEROS2),
1247 /* .szName = */ "OS/2",
1248 /* .pfnConstruct = */ dbgDiggerOS2Construct,
1249 /* .pfnDestruct = */ dbgDiggerOS2Destruct,
1250 /* .pfnProbe = */ dbgDiggerOS2Probe,
1251 /* .pfnInit = */ dbgDiggerOS2Init,
1252 /* .pfnRefresh = */ dbgDiggerOS2Refresh,
1253 /* .pfnTerm = */ dbgDiggerOS2Term,
1254 /* .pfnQueryVersion = */ dbgDiggerOS2QueryVersion,
1255 /* .pfnQueryInterface = */ dbgDiggerOS2QueryInterface,
1256 /* .pfnStackUnwindAssist = */ dbgDiggerOS2StackUnwindAssist,
1257 /* .u32EndMagic = */ DBGFOSREG_MAGIC
1258};
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