VirtualBox

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

Last change on this file since 78286 was 76784, checked in by vboxsync, 6 years ago

DBGPlugInOS2: updates

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