1 | /* $Id: DBGPlugInOS2.cpp 75242 2018-11-03 02:59:35Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DBGPlugInOS2 - Debugger and Guest OS Digger Plugin For OS/2.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2017 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 |
|
---|
41 | typedef 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 | */
|
---|
54 | typedef 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. */
|
---|
72 | typedef DBGDIGGEROS2 *PDBGDIGGEROS2;
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * 32-bit OS/2 loader module table entry.
|
---|
76 | */
|
---|
77 | typedef struct LDRMTE
|
---|
78 | {
|
---|
79 | uint16_t mte_flags2;
|
---|
80 | uint16_t mte_handle;
|
---|
81 | uint32_t mte_swapmte; /**< Pointer to LDRSMTE. */
|
---|
82 | uint32_t mte_link; /**< Pointer to next LDRMTE. */
|
---|
83 | uint32_t mte_flags1;
|
---|
84 | uint32_t mte_impmodcnt;
|
---|
85 | uint16_t mte_sfn;
|
---|
86 | uint16_t mte_usecnt;
|
---|
87 | char mte_modname[8];
|
---|
88 | uint32_t mte_RAS; /**< added later */
|
---|
89 | uint32_t mte_modver; /**< added even later. */
|
---|
90 | } LDRMTE;
|
---|
91 | /** @name LDRMTE::mte_flag2 values
|
---|
92 | * @{ */
|
---|
93 | #define MTEFORMATMASK UINT16_C(0x0003)
|
---|
94 | #define MTEFORMATR1 UINT16_C(0x0000)
|
---|
95 | #define MTEFORMATNE UINT16_C(0x0001)
|
---|
96 | #define MTEFORMATLX UINT16_C(0x0002)
|
---|
97 | #define MTEFORMATR2 UINT16_C(0x0003)
|
---|
98 | #define MTESYSTEMDLL UINT16_C(0x0004)
|
---|
99 | #define MTELOADORATTACH UINT16_C(0x0008)
|
---|
100 | #define MTECIRCLEREF UINT16_C(0x0010)
|
---|
101 | #define MTEFREEFIXUPS UINT16_C(0x0020) /* had different meaning earlier */
|
---|
102 | #define MTEPRELOADED UINT16_C(0x0040)
|
---|
103 | #define MTEGETMTEDONE UINT16_C(0x0080)
|
---|
104 | #define MTEPACKSEGDONE UINT16_C(0x0100)
|
---|
105 | #define MTE20LIELIST UINT16_C(0x0200)
|
---|
106 | #define MTESYSPROCESSED UINT16_C(0x0400)
|
---|
107 | #define MTEPSDMOD UINT16_C(0x0800)
|
---|
108 | #define MTEDLLONEXTLST UINT16_C(0x1000)
|
---|
109 | #define MTEPDUMPCIRCREF UINT16_C(0x2000)
|
---|
110 | /** @} */
|
---|
111 | /** @name LDRMTE::mte_flag1 values
|
---|
112 | * @{ */
|
---|
113 | #define MTE1_NOAUTODS UINT32_C(0x00000000)
|
---|
114 | #define MTE1_SOLO UINT32_C(0x00000001)
|
---|
115 | #define MTE1_INSTANCEDS UINT32_C(0x00000002)
|
---|
116 | #define MTE1_INSTLIBINIT UINT32_C(0x00000004)
|
---|
117 | #define MTE1_GINISETUP UINT32_C(0x00000008)
|
---|
118 | #define MTE1_NOINTERNFIXUPS UINT32_C(0x00000010)
|
---|
119 | #define MTE1_NOEXTERNFIXUPS UINT32_C(0x00000020)
|
---|
120 | #define MTE1_CLASS_ALL UINT32_C(0x00000000)
|
---|
121 | #define MTE1_CLASS_PROGRAM UINT32_C(0x00000040)
|
---|
122 | #define MTE1_CLASS_GLOBAL UINT32_C(0x00000080)
|
---|
123 | #define MTE1_CLASS_SPECIFIC UINT32_C(0x000000c0)
|
---|
124 | #define MTE1_CLASS_MASK UINT32_C(0x000000c0)
|
---|
125 | #define MTE1_MTEPROCESSED UINT32_C(0x00000100)
|
---|
126 | #define MTE1_USED UINT32_C(0x00000200)
|
---|
127 | #define MTE1_DOSLIB UINT32_C(0x00000400)
|
---|
128 | #define MTE1_DOSMOD UINT32_C(0x00000800) /**< The OS/2 kernel (DOSCALLS).*/
|
---|
129 | #define MTE1_MEDIAFIXED UINT32_C(0x00001000)
|
---|
130 | #define MTE1_LDRINVALID UINT32_C(0x00002000)
|
---|
131 | #define MTE1_PROGRAMMOD UINT32_C(0x00000000)
|
---|
132 | #define MTE1_DEVDRVMOD UINT32_C(0x00004000)
|
---|
133 | #define MTE1_LIBRARYMOD UINT32_C(0x00008000)
|
---|
134 | #define MTE1_VDDMOD UINT32_C(0x00010000)
|
---|
135 | #define MTE1_MVDMMOD UINT32_C(0x00020000)
|
---|
136 | #define MTE1_INGRAPH UINT32_C(0x00040000)
|
---|
137 | #define MTE1_GINIDONE UINT32_C(0x00080000)
|
---|
138 | #define MTE1_ADDRALLOCED UINT32_C(0x00100000)
|
---|
139 | #define MTE1_FSDMOD UINT32_C(0x00200000)
|
---|
140 | #define MTE1_FSHMOD UINT32_C(0x00400000)
|
---|
141 | #define MTE1_LONGNAMES UINT32_C(0x00800000)
|
---|
142 | #define MTE1_MEDIACONTIG UINT32_C(0x01000000)
|
---|
143 | #define MTE1_MEDIA16M UINT32_C(0x02000000)
|
---|
144 | #define MTE1_SWAPONLOAD UINT32_C(0x04000000)
|
---|
145 | #define MTE1_PORTHOLE UINT32_C(0x08000000)
|
---|
146 | #define MTE1_MODPROT UINT32_C(0x10000000)
|
---|
147 | #define MTE1_NEWMOD UINT32_C(0x20000000)
|
---|
148 | #define MTE1_DLLTERM UINT32_C(0x40000000)
|
---|
149 | #define MTE1_SYMLOADED UINT32_C(0x80000000)
|
---|
150 | /** @} */
|
---|
151 |
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * 32-bit OS/2 swappable module table entry.
|
---|
155 | */
|
---|
156 | typedef struct LDRSMTE
|
---|
157 | {
|
---|
158 | uint32_t smte_mpages; /**< 0x00: module page count. */
|
---|
159 | uint32_t smte_startobj; /**< 0x04: Entrypoint segment number. */
|
---|
160 | uint32_t smte_eip; /**< 0x08: Entrypoint offset value. */
|
---|
161 | uint32_t smte_stackobj; /**< 0x0c: Stack segment number. */
|
---|
162 | uint32_t smte_esp; /**< 0x10: Stack offset value*/
|
---|
163 | uint32_t smte_pageshift; /**< 0x14: Page shift value. */
|
---|
164 | uint32_t smte_fixupsize; /**< 0x18: Size of the fixup section. */
|
---|
165 | uint32_t smte_objtab; /**< 0x1c: Pointer to LDROTE array. */
|
---|
166 | uint32_t smte_objcnt; /**< 0x20: Number of segments. */
|
---|
167 | uint32_t smte_objmap; /**< 0x20: Address of the object page map. */
|
---|
168 | uint32_t smte_itermap; /**< 0x20: File offset of the iterated data map*/
|
---|
169 | uint32_t smte_rsrctab; /**< 0x20: Pointer to resource table? */
|
---|
170 | uint32_t smte_rsrccnt; /**< 0x30: Number of resource table entries. */
|
---|
171 | uint32_t smte_restab; /**< 0x30: Pointer to the resident name table. */
|
---|
172 | uint32_t smte_enttab; /**< 0x30: Possibly entry point table address, if not file offset. */
|
---|
173 | uint32_t smte_fpagetab; /**< 0x30 */
|
---|
174 | uint32_t smte_frectab; /**< 0x40 */
|
---|
175 | uint32_t smte_impmod; /**< 0x44 */
|
---|
176 | uint32_t smte_impproc; /**< 0x48 */
|
---|
177 | uint32_t smte_datapage; /**< 0x4c */
|
---|
178 | uint32_t smte_nrestab; /**< 0x50 */
|
---|
179 | uint32_t smte_cbnrestab; /**< 0x54 */
|
---|
180 | uint32_t smte_autods; /**< 0x58 */
|
---|
181 | uint32_t smte_debuginfo; /**< 0x5c */
|
---|
182 | uint32_t smte_debuglen; /**< 0x60 */
|
---|
183 | uint32_t smte_heapsize; /**< 0x64 */
|
---|
184 | uint32_t smte_path; /**< 0x68 Address of full name string. */
|
---|
185 | uint16_t smte_semcount; /**< 0x6c */
|
---|
186 | uint16_t smte_semowner; /**< 0x6e */
|
---|
187 | uint32_t smte_pfilecache; /**< 0x70: Address of cached data if replace-module is used. */
|
---|
188 | uint32_t smte_stacksize; /**< 0x74: Stack size for .exe thread 1. */
|
---|
189 | uint16_t smte_alignshift; /**< 0x78: */
|
---|
190 | uint16_t smte_NEexpver; /**< 0x7a: */
|
---|
191 | uint16_t smte_pathlen; /**< 0x7c: Length of smte_path */
|
---|
192 | uint16_t smte_NEexetype; /**< 0x7e: */
|
---|
193 | uint16_t smte_csegpack; /**< 0x80: */
|
---|
194 | uint8_t smte_major_os; /**< 0x82: added later to lie about OS version */
|
---|
195 | uint8_t smte_minor_os; /**< 0x83: added later to lie about OS version */
|
---|
196 | } LDRSMTE;
|
---|
197 | AssertCompileSize(LDRSMTE, 0x84);
|
---|
198 |
|
---|
199 | typedef struct LDROTE
|
---|
200 | {
|
---|
201 | uint32_t ote_size;
|
---|
202 | uint32_t ote_base;
|
---|
203 | uint32_t ote_flags;
|
---|
204 | uint32_t ote_pagemap;
|
---|
205 | uint32_t ote_mapsize;
|
---|
206 | union
|
---|
207 | {
|
---|
208 | uint32_t ote_vddaddr;
|
---|
209 | uint32_t ote_krnaddr;
|
---|
210 | struct
|
---|
211 | {
|
---|
212 | uint16_t ote_selector;
|
---|
213 | uint16_t ote_handle;
|
---|
214 | } s;
|
---|
215 | };
|
---|
216 | } LDROTE;
|
---|
217 | AssertCompileSize(LDROTE, 24);
|
---|
218 |
|
---|
219 |
|
---|
220 | /**
|
---|
221 | * 32-bit system anchor block segment header.
|
---|
222 | */
|
---|
223 | typedef struct SAS
|
---|
224 | {
|
---|
225 | uint8_t SAS_signature[4];
|
---|
226 | uint16_t SAS_tables_data; /**< Offset to SASTABLES. */
|
---|
227 | uint16_t SAS_flat_sel; /**< 32-bit kernel DS (flat). */
|
---|
228 | uint16_t SAS_config_data; /**< Offset to SASCONFIG. */
|
---|
229 | uint16_t SAS_dd_data; /**< Offset to SASDD. */
|
---|
230 | uint16_t SAS_vm_data; /**< Offset to SASVM. */
|
---|
231 | uint16_t SAS_task_data; /**< Offset to SASTASK. */
|
---|
232 | uint16_t SAS_RAS_data; /**< Offset to SASRAS. */
|
---|
233 | uint16_t SAS_file_data; /**< Offset to SASFILE. */
|
---|
234 | uint16_t SAS_info_data; /**< Offset to SASINFO. */
|
---|
235 | uint16_t SAS_mp_data; /**< Offset to SASMP. SMP only. */
|
---|
236 | } SAS;
|
---|
237 | #define SAS_SIGNATURE "SAS "
|
---|
238 |
|
---|
239 | typedef struct SASTABLES
|
---|
240 | {
|
---|
241 | uint16_t SAS_tbl_GDT;
|
---|
242 | uint16_t SAS_tbl_LDT;
|
---|
243 | uint16_t SAS_tbl_IDT;
|
---|
244 | uint16_t SAS_tbl_GDTPOOL;
|
---|
245 | } SASTABLES;
|
---|
246 |
|
---|
247 | typedef struct SASCONFIG
|
---|
248 | {
|
---|
249 | uint16_t SAS_config_table;
|
---|
250 | } SASCONFIG;
|
---|
251 |
|
---|
252 | typedef struct SASDD
|
---|
253 | {
|
---|
254 | uint16_t SAS_dd_bimodal_chain;
|
---|
255 | uint16_t SAS_dd_real_chain;
|
---|
256 | uint16_t SAS_dd_DPB_segment;
|
---|
257 | uint16_t SAS_dd_CDA_anchor_p;
|
---|
258 | uint16_t SAS_dd_CDA_anchor_r;
|
---|
259 | uint16_t SAS_dd_FSC;
|
---|
260 | } SASDD;
|
---|
261 |
|
---|
262 | typedef struct SASVM
|
---|
263 | {
|
---|
264 | uint32_t SAS_vm_arena;
|
---|
265 | uint32_t SAS_vm_object;
|
---|
266 | uint32_t SAS_vm_context;
|
---|
267 | uint32_t SAS_vm_krnl_mte; /**< Flat address of kernel MTE. */
|
---|
268 | uint32_t SAS_vm_glbl_mte; /**< Flat address of global MTE list head pointer variable. */
|
---|
269 | uint32_t SAS_vm_pft;
|
---|
270 | uint32_t SAS_vm_prt;
|
---|
271 | uint32_t SAS_vm_swap;
|
---|
272 | uint32_t SAS_vm_idle_head;
|
---|
273 | uint32_t SAS_vm_free_head;
|
---|
274 | uint32_t SAS_vm_heap_info;
|
---|
275 | uint32_t SAS_vm_all_mte; /**< Flat address of global MTE list head pointer variable. */
|
---|
276 | } SASVM;
|
---|
277 |
|
---|
278 |
|
---|
279 | #pragma pack(1)
|
---|
280 | typedef struct SASTASK
|
---|
281 | {
|
---|
282 | uint16_t SAS_task_PTDA; /**< Current PTDA selector. */
|
---|
283 | uint32_t SAS_task_ptdaptrs; /**< Flat address of process tree root. */
|
---|
284 | uint32_t SAS_task_threadptrs; /**< Flat address array of thread pointer array. */
|
---|
285 | uint32_t SAS_task_tasknumber; /**< Flat address of the TaskNumber variable. */
|
---|
286 | uint32_t SAS_task_threadcount; /**< Flat address of the ThreadCount variable. */
|
---|
287 | } SASTASK;
|
---|
288 | #pragma pack()
|
---|
289 |
|
---|
290 |
|
---|
291 | #pragma pack(1)
|
---|
292 | typedef struct SASRAS
|
---|
293 | {
|
---|
294 | uint16_t SAS_RAS_STDA_p;
|
---|
295 | uint16_t SAS_RAS_STDA_r;
|
---|
296 | uint16_t SAS_RAS_event_mask;
|
---|
297 | uint32_t SAS_RAS_Perf_Buff;
|
---|
298 | } SASRAS;
|
---|
299 | #pragma pack()
|
---|
300 |
|
---|
301 | typedef struct SASFILE
|
---|
302 | {
|
---|
303 | uint32_t SAS_file_MFT; /**< Handle. */
|
---|
304 | uint16_t SAS_file_SFT; /**< Selector. */
|
---|
305 | uint16_t SAS_file_VPB; /**< Selector. */
|
---|
306 | uint16_t SAS_file_CDS; /**< Selector. */
|
---|
307 | uint16_t SAS_file_buffers; /**< Selector. */
|
---|
308 | } SASFILE;
|
---|
309 |
|
---|
310 | #pragma pack(1)
|
---|
311 | typedef struct SASINFO
|
---|
312 | {
|
---|
313 | uint16_t SAS_info_global; /**< GIS selector. */
|
---|
314 | uint32_t SAS_info_local; /**< Flat address of LIS for current task. */
|
---|
315 | uint32_t SAS_info_localRM;
|
---|
316 | uint16_t SAS_info_CDIB; /**< Selector. */
|
---|
317 | } SASINFO;
|
---|
318 | #pragma pack()
|
---|
319 |
|
---|
320 | typedef struct SASMP
|
---|
321 | {
|
---|
322 | uint32_t SAS_mp_PCBFirst; /**< Flat address of PCB head. */
|
---|
323 | uint32_t SAS_mp_pLockHandles; /**< Flat address of lock handles. */
|
---|
324 | uint32_t SAS_mp_cProcessors; /**< Flat address of CPU count variable. */
|
---|
325 | uint32_t SAS_mp_pIPCInfo; /**< Flat address of IPC info pointer variable. */
|
---|
326 | uint32_t SAS_mp_pIPCHistory; /**< Flat address of IPC history pointer. */
|
---|
327 | uint32_t SAS_mp_IPCHistoryIdx; /**< Flat address of IPC history index variable. */
|
---|
328 | uint32_t SAS_mp_pFirstPSA; /**< Flat address of PSA. Added later. */
|
---|
329 | uint32_t SAS_mp_pPSAPages; /**< Flat address of PSA pages. */
|
---|
330 | } SASMP;
|
---|
331 |
|
---|
332 |
|
---|
333 |
|
---|
334 | /*********************************************************************************************************************************
|
---|
335 | * Defined Constants And Macros *
|
---|
336 | *********************************************************************************************************************************/
|
---|
337 | /** The 'SAS ' signature. */
|
---|
338 | #define DIG_OS2_SAS_SIG RT_MAKE_U32_FROM_U8('S','A','S',' ')
|
---|
339 |
|
---|
340 | /** OS/2Warp on little endian ASCII systems. */
|
---|
341 | #define DIG_OS2_MOD_TAG UINT64_C(0x43532f3257617270)
|
---|
342 |
|
---|
343 |
|
---|
344 | /*********************************************************************************************************************************
|
---|
345 | * Internal Functions *
|
---|
346 | *********************************************************************************************************************************/
|
---|
347 | static DECLCALLBACK(int) dbgDiggerOS2Init(PUVM pUVM, void *pvData);
|
---|
348 |
|
---|
349 |
|
---|
350 |
|
---|
351 | #if 0 /* unused */
|
---|
352 | /**
|
---|
353 | * Process a PE image found in guest memory.
|
---|
354 | *
|
---|
355 | * @param pThis The instance data.
|
---|
356 | * @param pUVM The user mode VM handle.
|
---|
357 | * @param pszName The image name.
|
---|
358 | * @param pImageAddr The image address.
|
---|
359 | * @param cbImage The size of the image.
|
---|
360 | * @param pbBuf Scratch buffer containing the first
|
---|
361 | * RT_MIN(cbBuf, cbImage) bytes of the image.
|
---|
362 | * @param cbBuf The scratch buffer size.
|
---|
363 | */
|
---|
364 | static void dbgDiggerOS2ProcessImage(PDBGDIGGEROS2 pThis, PUVM pUVM, const char *pszName,
|
---|
365 | PCDBGFADDRESS pImageAddr, uint32_t cbImage,
|
---|
366 | uint8_t *pbBuf, size_t cbBuf)
|
---|
367 | {
|
---|
368 | RT_NOREF7(pThis, pUVM, pszName, pImageAddr, cbImage, pbBuf, cbBuf);
|
---|
369 | LogFlow(("DigOS2: %RGp %#x %s\n", pImageAddr->FlatPtr, cbImage, pszName));
|
---|
370 |
|
---|
371 | /* To be implemented.*/
|
---|
372 | }
|
---|
373 | #endif
|
---|
374 |
|
---|
375 |
|
---|
376 | /**
|
---|
377 | * @copydoc DBGFOSREG::pfnStackUnwindAssist
|
---|
378 | */
|
---|
379 | static DECLCALLBACK(int) dbgDiggerOS2StackUnwindAssist(PUVM pUVM, void *pvData, VMCPUID idCpu, PDBGFSTACKFRAME pFrame,
|
---|
380 | PRTDBGUNWINDSTATE pState, PCCPUMCTX pInitialCtx, RTDBGAS hAs,
|
---|
381 | uint64_t *puScratch)
|
---|
382 | {
|
---|
383 | RT_NOREF(pUVM, pvData, idCpu, pFrame, pState, pInitialCtx, hAs, puScratch);
|
---|
384 | return VINF_SUCCESS;
|
---|
385 | }
|
---|
386 |
|
---|
387 |
|
---|
388 | /**
|
---|
389 | * @copydoc DBGFOSREG::pfnQueryInterface
|
---|
390 | */
|
---|
391 | static DECLCALLBACK(void *) dbgDiggerOS2QueryInterface(PUVM pUVM, void *pvData, DBGFOSINTERFACE enmIf)
|
---|
392 | {
|
---|
393 | RT_NOREF3(pUVM, pvData, enmIf);
|
---|
394 | return NULL;
|
---|
395 | }
|
---|
396 |
|
---|
397 |
|
---|
398 | /**
|
---|
399 | * @copydoc DBGFOSREG::pfnQueryVersion
|
---|
400 | */
|
---|
401 | static DECLCALLBACK(int) dbgDiggerOS2QueryVersion(PUVM pUVM, void *pvData, char *pszVersion, size_t cchVersion)
|
---|
402 | {
|
---|
403 | RT_NOREF1(pUVM);
|
---|
404 | PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
|
---|
405 | Assert(pThis->fValid);
|
---|
406 | char *achOS2ProductType[32];
|
---|
407 | char *pszOS2ProductType = (char *)achOS2ProductType;
|
---|
408 |
|
---|
409 | if (pThis->OS2MajorVersion == 10)
|
---|
410 | {
|
---|
411 | RTStrPrintf(pszOS2ProductType, sizeof(achOS2ProductType), "OS/2 1.%02d", pThis->OS2MinorVersion);
|
---|
412 | pThis->enmVer = DBGDIGGEROS2VER_1_x;
|
---|
413 | }
|
---|
414 | else if (pThis->OS2MajorVersion == 20)
|
---|
415 | {
|
---|
416 | if (pThis->OS2MinorVersion < 30)
|
---|
417 | {
|
---|
418 | RTStrPrintf(pszOS2ProductType, sizeof(achOS2ProductType), "OS/2 2.%02d", pThis->OS2MinorVersion);
|
---|
419 | pThis->enmVer = DBGDIGGEROS2VER_2_x;
|
---|
420 | }
|
---|
421 | else if (pThis->OS2MinorVersion < 40)
|
---|
422 | {
|
---|
423 | RTStrPrintf(pszOS2ProductType, sizeof(achOS2ProductType), "OS/2 Warp");
|
---|
424 | pThis->enmVer = DBGDIGGEROS2VER_3_0;
|
---|
425 | }
|
---|
426 | else if (pThis->OS2MinorVersion == 40)
|
---|
427 | {
|
---|
428 | RTStrPrintf(pszOS2ProductType, sizeof(achOS2ProductType), "OS/2 Warp 4");
|
---|
429 | pThis->enmVer = DBGDIGGEROS2VER_4_0;
|
---|
430 | }
|
---|
431 | else
|
---|
432 | {
|
---|
433 | RTStrPrintf(pszOS2ProductType, sizeof(achOS2ProductType), "OS/2 Warp %d.%d",
|
---|
434 | pThis->OS2MinorVersion / 10, pThis->OS2MinorVersion % 10);
|
---|
435 | pThis->enmVer = DBGDIGGEROS2VER_4_5;
|
---|
436 | }
|
---|
437 | }
|
---|
438 | RTStrPrintf(pszVersion, cchVersion, "%u.%u (%s)", pThis->OS2MajorVersion, pThis->OS2MinorVersion, pszOS2ProductType);
|
---|
439 | return VINF_SUCCESS;
|
---|
440 | }
|
---|
441 |
|
---|
442 |
|
---|
443 | /**
|
---|
444 | * @copydoc DBGFOSREG::pfnTerm
|
---|
445 | */
|
---|
446 | static DECLCALLBACK(void) dbgDiggerOS2Term(PUVM pUVM, void *pvData)
|
---|
447 | {
|
---|
448 | RT_NOREF1(pUVM);
|
---|
449 | PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
|
---|
450 | Assert(pThis->fValid);
|
---|
451 |
|
---|
452 | pThis->fValid = false;
|
---|
453 | }
|
---|
454 |
|
---|
455 |
|
---|
456 | /**
|
---|
457 | * @copydoc DBGFOSREG::pfnRefresh
|
---|
458 | */
|
---|
459 | static DECLCALLBACK(int) dbgDiggerOS2Refresh(PUVM pUVM, void *pvData)
|
---|
460 | {
|
---|
461 | PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
|
---|
462 | NOREF(pThis);
|
---|
463 | Assert(pThis->fValid);
|
---|
464 |
|
---|
465 | /*
|
---|
466 | * For now we'll flush and reload everything.
|
---|
467 | */
|
---|
468 | RTDBGAS hDbgAs = DBGFR3AsResolveAndRetain(pUVM, DBGF_AS_KERNEL);
|
---|
469 | if (hDbgAs != NIL_RTDBGAS)
|
---|
470 | {
|
---|
471 | uint32_t iMod = RTDbgAsModuleCount(hDbgAs);
|
---|
472 | while (iMod-- > 0)
|
---|
473 | {
|
---|
474 | RTDBGMOD hMod = RTDbgAsModuleByIndex(hDbgAs, iMod);
|
---|
475 | if (hMod != NIL_RTDBGMOD)
|
---|
476 | {
|
---|
477 | if (RTDbgModGetTag(hMod) == DIG_OS2_MOD_TAG)
|
---|
478 | {
|
---|
479 | int rc = RTDbgAsModuleUnlink(hDbgAs, hMod);
|
---|
480 | AssertRC(rc);
|
---|
481 | }
|
---|
482 | RTDbgModRelease(hMod);
|
---|
483 | }
|
---|
484 | }
|
---|
485 | RTDbgAsRelease(hDbgAs);
|
---|
486 | }
|
---|
487 |
|
---|
488 | dbgDiggerOS2Term(pUVM, pvData);
|
---|
489 | return dbgDiggerOS2Init(pUVM, pvData);
|
---|
490 | }
|
---|
491 |
|
---|
492 | /** Buffer shared by dbgdiggerOS2ProcessModule and dbgDiggerOS2Init.*/
|
---|
493 | typedef union DBGDIGGEROS2BUF
|
---|
494 | {
|
---|
495 | uint8_t au8[0x2000];
|
---|
496 | uint16_t au16[0x2000/2];
|
---|
497 | uint32_t au32[0x2000/4];
|
---|
498 | RTUTF16 wsz[0x2000/2];
|
---|
499 | char ach[0x2000];
|
---|
500 | LDROTE aOtes[0x2000 / sizeof(LDROTE)];
|
---|
501 | SAS sas;
|
---|
502 | SASVM sasvm;
|
---|
503 | LDRMTE mte;
|
---|
504 | LDRSMTE smte;
|
---|
505 | LDROTE ote;
|
---|
506 | } DBGDIGGEROS2BUF;
|
---|
507 |
|
---|
508 | /** Arguments dbgdiggerOS2ProcessModule passes to the module open callback. */
|
---|
509 | typedef struct
|
---|
510 | {
|
---|
511 | const char *pszModPath;
|
---|
512 | const char *pszModName;
|
---|
513 | LDRMTE const *pMte;
|
---|
514 | LDRSMTE const *pSwapMte;
|
---|
515 | } DBGDIGGEROS2OPEN;
|
---|
516 |
|
---|
517 |
|
---|
518 | /**
|
---|
519 | * @callback_method_impl{FNRTDBGCFGOPEN, Debug image/image searching callback.}
|
---|
520 | */
|
---|
521 | static DECLCALLBACK(int) dbgdiggerOs2OpenModule(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2)
|
---|
522 | {
|
---|
523 | DBGDIGGEROS2OPEN *pArgs = (DBGDIGGEROS2OPEN *)pvUser1;
|
---|
524 |
|
---|
525 | RTDBGMOD hDbgMod = NIL_RTDBGMOD;
|
---|
526 | int rc = RTDbgModCreateFromImage(&hDbgMod, pszFilename, pArgs->pszModName, RTLDRARCH_WHATEVER, hDbgCfg);
|
---|
527 | if (RT_SUCCESS(rc))
|
---|
528 | {
|
---|
529 | /** @todo Do some info matching before using it? */
|
---|
530 |
|
---|
531 | *(PRTDBGMOD)pvUser2 = hDbgMod;
|
---|
532 | return VINF_CALLBACK_RETURN;
|
---|
533 | }
|
---|
534 | LogRel(("DbgDiggerOs2: dbgdiggerOs2OpenModule: %Rrc - %s\n", rc, pszFilename));
|
---|
535 | return rc;
|
---|
536 | }
|
---|
537 |
|
---|
538 |
|
---|
539 | static void dbgdiggerOS2ProcessModule(PUVM pUVM, PDBGDIGGEROS2 pThis, DBGDIGGEROS2BUF *pBuf,
|
---|
540 | const char *pszCacheSubDir, RTDBGAS hAs, RTDBGCFG hDbgCfg)
|
---|
541 | {
|
---|
542 | RT_NOREF(pThis);
|
---|
543 |
|
---|
544 | /*
|
---|
545 | * Save the MTE.
|
---|
546 | */
|
---|
547 | static const char * const s_apszMteFmts[4] = { "Reserved1", "NE", "LX", "Reserved2" };
|
---|
548 | LDRMTE const Mte = pBuf->mte;
|
---|
549 | if ((Mte.mte_flags2 & MTEFORMATMASK) != MTEFORMATLX)
|
---|
550 | {
|
---|
551 | LogRel(("DbgDiggerOs2: MTE format not implemented: %s (%d)\n",
|
---|
552 | s_apszMteFmts[(Mte.mte_flags2 & MTEFORMATMASK)], Mte.mte_flags2 & MTEFORMATMASK));
|
---|
553 | return;
|
---|
554 | }
|
---|
555 |
|
---|
556 | /*
|
---|
557 | * Try read the swappable MTE. Save it too.
|
---|
558 | */
|
---|
559 | DBGFADDRESS Addr;
|
---|
560 | int rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, DBGFR3AddrFromFlat(pUVM, &Addr, Mte.mte_swapmte), &pBuf->smte, sizeof(pBuf->smte));
|
---|
561 | if (RT_FAILURE(rc))
|
---|
562 | {
|
---|
563 | LogRel(("DbgDiggerOs2: Error reading swap mte @ %RX32: %Rrc\n", Mte.mte_swapmte, rc));
|
---|
564 | return;
|
---|
565 | }
|
---|
566 | LDRSMTE const SwapMte = pBuf->smte;
|
---|
567 |
|
---|
568 | /* Ignore empty modules or modules with too many segments. */
|
---|
569 | if (SwapMte.smte_objcnt == 0 || SwapMte.smte_objcnt > RT_ELEMENTS(pBuf->aOtes))
|
---|
570 | {
|
---|
571 | LogRel(("DbgDiggerOs2: Skipping: smte_objcnt= %#RX32\n", SwapMte.smte_objcnt));
|
---|
572 | return;
|
---|
573 | }
|
---|
574 |
|
---|
575 | /*
|
---|
576 | * Try read the path name, falling back on module name.
|
---|
577 | */
|
---|
578 | char szModPath[260];
|
---|
579 | rc = VERR_READ_ERROR;
|
---|
580 | if (SwapMte.smte_path != 0 && SwapMte.smte_pathlen > 0)
|
---|
581 | {
|
---|
582 | uint32_t cbToRead = RT_MIN(SwapMte.smte_path, sizeof(szModPath) - 1);
|
---|
583 | rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, DBGFR3AddrFromFlat(pUVM, &Addr, SwapMte.smte_path), szModPath, cbToRead);
|
---|
584 | szModPath[cbToRead] = '\0';
|
---|
585 | }
|
---|
586 | if (RT_FAILURE(rc))
|
---|
587 | {
|
---|
588 | memcpy(szModPath, Mte.mte_modname, sizeof(Mte.mte_modname));
|
---|
589 | szModPath[sizeof(Mte.mte_modname)] = '\0';
|
---|
590 | RTStrStripR(szModPath);
|
---|
591 | }
|
---|
592 | LogRel(("DbgDiggerOS2: szModPath='%s'\n", szModPath));
|
---|
593 |
|
---|
594 | /*
|
---|
595 | * Sanitize the module name.
|
---|
596 | */
|
---|
597 | char szModName[16];
|
---|
598 | memcpy(szModName, Mte.mte_modname, sizeof(Mte.mte_modname));
|
---|
599 | szModName[sizeof(Mte.mte_modname)] = '\0';
|
---|
600 | RTStrStripR(szModName);
|
---|
601 |
|
---|
602 | /*
|
---|
603 | * Read the object table into the buffer.
|
---|
604 | */
|
---|
605 | rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, DBGFR3AddrFromFlat(pUVM, &Addr, SwapMte.smte_objtab),
|
---|
606 | &pBuf->aOtes[0], sizeof(pBuf->aOtes[0]) * SwapMte.smte_objcnt);
|
---|
607 | if (RT_FAILURE(rc))
|
---|
608 | {
|
---|
609 | LogRel(("DbgDiggerOs2: Error reading object table @ %#RX32 LB %#zx: %Rrc\n",
|
---|
610 | SwapMte.smte_objtab, sizeof(pBuf->aOtes[0]) * SwapMte.smte_objcnt, rc));
|
---|
611 | return;
|
---|
612 | }
|
---|
613 | for (uint32_t i = 0; i < SwapMte.smte_objcnt; i++)
|
---|
614 | {
|
---|
615 | LogRel(("DbgDiggerOs2: seg%u: %RX32 LB %#x\n", i, pBuf->aOtes[i].ote_base, pBuf->aOtes[i].ote_size));
|
---|
616 | /** @todo validate it. */
|
---|
617 | }
|
---|
618 |
|
---|
619 | /* No need to continue without an address space (shouldn't happen). */
|
---|
620 | if (hAs == NIL_RTDBGAS)
|
---|
621 | return;
|
---|
622 |
|
---|
623 | /*
|
---|
624 | * Try find a debug file for this module.
|
---|
625 | */
|
---|
626 | RTDBGMOD hDbgMod = NIL_RTDBGMOD;
|
---|
627 | if (hDbgCfg != NIL_RTDBGCFG)
|
---|
628 | {
|
---|
629 | DBGDIGGEROS2OPEN Args = { szModPath, szModName, &Mte, &SwapMte };
|
---|
630 | RTDbgCfgOpenEx(hDbgCfg, szModPath, pszCacheSubDir, NULL,
|
---|
631 | RT_OPSYS_OS2 | RTDBGCFG_O_CASE_INSENSITIVE | RTDBGCFG_O_EXECUTABLE_IMAGE
|
---|
632 | | RTDBGCFG_O_RECURSIVE | RTDBGCFG_O_NO_SYSTEM_PATHS,
|
---|
633 | dbgdiggerOs2OpenModule, &Args, &hDbgMod);
|
---|
634 | }
|
---|
635 |
|
---|
636 | /*
|
---|
637 | * Fallback is a simple module into which we insert sections.
|
---|
638 | */
|
---|
639 | uint32_t cSegments = SwapMte.smte_objcnt;
|
---|
640 | if (hDbgMod == NIL_RTDBGMOD)
|
---|
641 | {
|
---|
642 | rc = RTDbgModCreate(&hDbgMod, szModName, 0 /*cbSeg*/, 0 /*fFlags*/);
|
---|
643 | if (RT_SUCCESS(rc))
|
---|
644 | {
|
---|
645 | uint32_t uRva = 0;
|
---|
646 | for (uint32_t i = 0; i < SwapMte.smte_objcnt; i++)
|
---|
647 | {
|
---|
648 | char szSegNm[16];
|
---|
649 | RTStrPrintf(szSegNm, sizeof(szSegNm), "seg%u", i);
|
---|
650 | rc = RTDbgModSegmentAdd(hDbgMod, uRva, pBuf->aOtes[i].ote_size, szSegNm, 0 /*fFlags*/, NULL);
|
---|
651 | if (RT_FAILURE(rc))
|
---|
652 | {
|
---|
653 | LogRel(("DbgDiggerOs2: RTDbgModSegmentAdd failed (i=%u, ote_size=%#x): %Rrc\n",
|
---|
654 | i, pBuf->aOtes[i].ote_size, rc));
|
---|
655 | cSegments = i;
|
---|
656 | break;
|
---|
657 | }
|
---|
658 | uRva += RT_ALIGN_32(pBuf->aOtes[i].ote_size, _4K);
|
---|
659 | }
|
---|
660 | }
|
---|
661 | else
|
---|
662 | {
|
---|
663 | LogRel(("DbgDiggerOs2: RTDbgModCreate failed: %Rrc\n", rc));
|
---|
664 | return;
|
---|
665 | }
|
---|
666 | }
|
---|
667 |
|
---|
668 | /*
|
---|
669 | * Tag the module and link its segments.
|
---|
670 | */
|
---|
671 | rc = RTDbgModSetTag(hDbgMod, DIG_OS2_MOD_TAG);
|
---|
672 | if (RT_SUCCESS(rc))
|
---|
673 | {
|
---|
674 | for (uint32_t i = 0; i < SwapMte.smte_objcnt; i++)
|
---|
675 | {
|
---|
676 | rc = RTDbgAsModuleLinkSeg(hAs, hDbgMod, i, pBuf->aOtes[i].ote_base, RTDBGASLINK_FLAGS_REPLACE /*fFlags*/);
|
---|
677 | if (RT_FAILURE(rc))
|
---|
678 | LogRel(("DbgDiggerOs2: RTDbgAsModuleLinkSeg failed (i=%u, ote_base=%#x): %Rrc\n",
|
---|
679 | i, pBuf->aOtes[i].ote_base, rc));
|
---|
680 | }
|
---|
681 | }
|
---|
682 | else
|
---|
683 | LogRel(("DbgDiggerOs2: RTDbgModSetTag failed: %Rrc\n", rc));
|
---|
684 | RTDbgModRelease(hDbgMod);
|
---|
685 | }
|
---|
686 |
|
---|
687 |
|
---|
688 | /**
|
---|
689 | * @copydoc DBGFOSREG::pfnInit
|
---|
690 | */
|
---|
691 | static DECLCALLBACK(int) dbgDiggerOS2Init(PUVM pUVM, void *pvData)
|
---|
692 | {
|
---|
693 | PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
|
---|
694 | Assert(!pThis->fValid);
|
---|
695 |
|
---|
696 | DBGDIGGEROS2BUF uBuf;
|
---|
697 | DBGFADDRESS Addr;
|
---|
698 | int rc;
|
---|
699 |
|
---|
700 | /*
|
---|
701 | * Determine the OS/2 version.
|
---|
702 | */
|
---|
703 | /* Version info is at GIS:15h (major/minor/revision). */
|
---|
704 | rc = DBGFR3AddrFromSelOff(pUVM, 0 /*idCpu*/, &Addr, pThis->selGIS, 0x15);
|
---|
705 | if (RT_FAILURE(rc))
|
---|
706 | return VERR_NOT_SUPPORTED;
|
---|
707 | rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, &Addr, uBuf.au32, sizeof(uint32_t));
|
---|
708 | if (RT_FAILURE(rc))
|
---|
709 | return VERR_NOT_SUPPORTED;
|
---|
710 |
|
---|
711 | pThis->OS2MajorVersion = uBuf.au8[0];
|
---|
712 | pThis->OS2MinorVersion = uBuf.au8[1];
|
---|
713 |
|
---|
714 | pThis->fValid = true;
|
---|
715 |
|
---|
716 | /*
|
---|
717 | * Try use SAS to find the module list.
|
---|
718 | */
|
---|
719 | rc = DBGFR3AddrFromSelOff(pUVM, 0 /*idCpu*/, &Addr, 0x70, 0x00);
|
---|
720 | if (RT_SUCCESS(rc))
|
---|
721 | {
|
---|
722 | rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, &Addr, &uBuf.sas, sizeof(uBuf.sas));
|
---|
723 | if (RT_SUCCESS(rc))
|
---|
724 | {
|
---|
725 | rc = DBGFR3AddrFromSelOff(pUVM, 0 /*idCpu*/, &Addr, 0x70, uBuf.sas.SAS_vm_data);
|
---|
726 | if (RT_SUCCESS(rc))
|
---|
727 | rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, &Addr, &uBuf.sasvm, sizeof(uBuf.sasvm));
|
---|
728 | if (RT_SUCCESS(rc))
|
---|
729 | {
|
---|
730 | /*
|
---|
731 | * Work the module list.
|
---|
732 | */
|
---|
733 | rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, DBGFR3AddrFromFlat(pUVM, &Addr, uBuf.sasvm.SAS_vm_all_mte),
|
---|
734 | &uBuf.au32[0], sizeof(uBuf.au32[0]));
|
---|
735 | if (RT_SUCCESS(rc))
|
---|
736 | {
|
---|
737 | uint32_t uOs2Krnl = UINT32_MAX;
|
---|
738 | RTDBGCFG hDbgCfg = DBGFR3AsGetConfig(pUVM); /* (don't release this) */
|
---|
739 | RTDBGAS hAs = DBGFR3AsResolveAndRetain(pUVM, DBGF_AS_GLOBAL);
|
---|
740 |
|
---|
741 | char szCacheSubDir[24];
|
---|
742 | RTStrPrintf(szCacheSubDir, sizeof(szCacheSubDir), "os2-%u.%u", pThis->OS2MajorVersion, pThis->OS2MinorVersion);
|
---|
743 |
|
---|
744 | DBGFR3AddrFromFlat(pUVM, &Addr, uBuf.au32[0]);
|
---|
745 | while (Addr.FlatPtr != 0 && Addr.FlatPtr != UINT32_MAX)
|
---|
746 | {
|
---|
747 | rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, &Addr, &uBuf.mte, sizeof(uBuf.mte));
|
---|
748 | if (RT_FAILURE(rc))
|
---|
749 | break;
|
---|
750 | LogRel(("DbgDiggerOs2: Module @ %#010RX32: %.8s %#x %#x\n", (uint32_t)Addr.FlatPtr,
|
---|
751 | uBuf.mte.mte_modname, uBuf.mte.mte_flags1, uBuf.mte.mte_flags2));
|
---|
752 | if (uBuf.mte.mte_flags1 & MTE1_DOSMOD)
|
---|
753 | uOs2Krnl = (uint32_t)Addr.FlatPtr;
|
---|
754 |
|
---|
755 | DBGFR3AddrFromFlat(pUVM, &Addr, uBuf.mte.mte_link);
|
---|
756 | dbgdiggerOS2ProcessModule(pUVM, pThis, &uBuf, szCacheSubDir, hAs, hDbgCfg);
|
---|
757 | }
|
---|
758 |
|
---|
759 | /* Load the kernel again. To make sure we didn't drop any segments due
|
---|
760 | to overlap/conflicts/whatever. */
|
---|
761 | if (uOs2Krnl != UINT32_MAX)
|
---|
762 | {
|
---|
763 | rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, DBGFR3AddrFromFlat(pUVM, &Addr, uOs2Krnl),
|
---|
764 | &uBuf.mte, sizeof(uBuf.mte));
|
---|
765 | if (RT_SUCCESS(rc))
|
---|
766 | {
|
---|
767 | LogRel(("DbgDiggerOs2: Module @ %#010RX32: %.8s %#x %#x [again]\n", (uint32_t)Addr.FlatPtr,
|
---|
768 | uBuf.mte.mte_modname, uBuf.mte.mte_flags1, uBuf.mte.mte_flags2));
|
---|
769 | dbgdiggerOS2ProcessModule(pUVM, pThis, &uBuf, szCacheSubDir, hAs, hDbgCfg);
|
---|
770 | }
|
---|
771 | }
|
---|
772 |
|
---|
773 | RTDbgAsRelease(hAs);
|
---|
774 | }
|
---|
775 | }
|
---|
776 | }
|
---|
777 | }
|
---|
778 |
|
---|
779 | return VINF_SUCCESS;
|
---|
780 | }
|
---|
781 |
|
---|
782 |
|
---|
783 | /**
|
---|
784 | * @copydoc DBGFOSREG::pfnProbe
|
---|
785 | */
|
---|
786 | static DECLCALLBACK(bool) dbgDiggerOS2Probe(PUVM pUVM, void *pvData)
|
---|
787 | {
|
---|
788 | PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
|
---|
789 | DBGFADDRESS Addr;
|
---|
790 | int rc;
|
---|
791 | uint16_t offInfo;
|
---|
792 | union
|
---|
793 | {
|
---|
794 | uint8_t au8[8192];
|
---|
795 | uint16_t au16[8192/2];
|
---|
796 | uint32_t au32[8192/4];
|
---|
797 | RTUTF16 wsz[8192/2];
|
---|
798 | } u;
|
---|
799 |
|
---|
800 | /*
|
---|
801 | * If the DWORD at 70:0 contains 'SAS ' it's quite unlikely that this wouldn't be OS/2.
|
---|
802 | * Note: The SAS layout is similar between 16-bit and 32-bit OS/2, but not identical.
|
---|
803 | * 32-bit OS/2 will have the flat kernel data selector at SAS:06. The selector is 168h
|
---|
804 | * or similar. For 16-bit OS/2 the field contains a table offset into the SAS which will
|
---|
805 | * be much smaller. Fun fact: The global infoseg selector in the SAS is bimodal in 16-bit
|
---|
806 | * OS/2 and will work in real mode as well.
|
---|
807 | */
|
---|
808 | do {
|
---|
809 | rc = DBGFR3AddrFromSelOff(pUVM, 0 /*idCpu*/, &Addr, 0x70, 0x00);
|
---|
810 | if (RT_FAILURE(rc))
|
---|
811 | break;
|
---|
812 | rc = DBGFR3MemRead(pUVM, 0 /*idCpu*/, &Addr, u.au32, 256);
|
---|
813 | if (RT_FAILURE(rc))
|
---|
814 | break;
|
---|
815 | if (u.au32[0] != DIG_OS2_SAS_SIG)
|
---|
816 | break;
|
---|
817 |
|
---|
818 | /* This sure looks like OS/2, but a bit of paranoia won't hurt. */
|
---|
819 | if (u.au16[2] >= u.au16[4])
|
---|
820 | break;
|
---|
821 |
|
---|
822 | /* If 4th word is bigger than 5th, it's the flat kernel mode selector. */
|
---|
823 | if (u.au16[3] > u.au16[4])
|
---|
824 | pThis->f32Bit = true;
|
---|
825 |
|
---|
826 | /* Offset into info table is either at SAS:14h or SAS:16h. */
|
---|
827 | if (pThis->f32Bit)
|
---|
828 | offInfo = u.au16[0x14/2];
|
---|
829 | else
|
---|
830 | offInfo = u.au16[0x16/2];
|
---|
831 |
|
---|
832 | /* The global infoseg selector is the first entry in the info table. */
|
---|
833 | pThis->selGIS = u.au16[offInfo/2];
|
---|
834 | return true;
|
---|
835 | } while (0);
|
---|
836 |
|
---|
837 | return false;
|
---|
838 | }
|
---|
839 |
|
---|
840 |
|
---|
841 | /**
|
---|
842 | * @copydoc DBGFOSREG::pfnDestruct
|
---|
843 | */
|
---|
844 | static DECLCALLBACK(void) dbgDiggerOS2Destruct(PUVM pUVM, void *pvData)
|
---|
845 | {
|
---|
846 | RT_NOREF2(pUVM, pvData);
|
---|
847 | }
|
---|
848 |
|
---|
849 |
|
---|
850 | /**
|
---|
851 | * @copydoc DBGFOSREG::pfnConstruct
|
---|
852 | */
|
---|
853 | static DECLCALLBACK(int) dbgDiggerOS2Construct(PUVM pUVM, void *pvData)
|
---|
854 | {
|
---|
855 | RT_NOREF1(pUVM);
|
---|
856 | PDBGDIGGEROS2 pThis = (PDBGDIGGEROS2)pvData;
|
---|
857 | pThis->fValid = false;
|
---|
858 | pThis->f32Bit = false;
|
---|
859 | pThis->enmVer = DBGDIGGEROS2VER_UNKNOWN;
|
---|
860 | return VINF_SUCCESS;
|
---|
861 | }
|
---|
862 |
|
---|
863 |
|
---|
864 | const DBGFOSREG g_DBGDiggerOS2 =
|
---|
865 | {
|
---|
866 | /* .u32Magic = */ DBGFOSREG_MAGIC,
|
---|
867 | /* .fFlags = */ 0,
|
---|
868 | /* .cbData = */ sizeof(DBGDIGGEROS2),
|
---|
869 | /* .szName = */ "OS/2",
|
---|
870 | /* .pfnConstruct = */ dbgDiggerOS2Construct,
|
---|
871 | /* .pfnDestruct = */ dbgDiggerOS2Destruct,
|
---|
872 | /* .pfnProbe = */ dbgDiggerOS2Probe,
|
---|
873 | /* .pfnInit = */ dbgDiggerOS2Init,
|
---|
874 | /* .pfnRefresh = */ dbgDiggerOS2Refresh,
|
---|
875 | /* .pfnTerm = */ dbgDiggerOS2Term,
|
---|
876 | /* .pfnQueryVersion = */ dbgDiggerOS2QueryVersion,
|
---|
877 | /* .pfnQueryInterface = */ dbgDiggerOS2QueryInterface,
|
---|
878 | /* .pfnStackUnwindAssist = */ dbgDiggerOS2StackUnwindAssist,
|
---|
879 | /* .u32EndMagic = */ DBGFOSREG_MAGIC
|
---|
880 | };
|
---|