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