summaryrefslogblamecommitdiffstats
path: root/private/sdktools/dumpexam/da_alpha.c
blob: 448bce5a8dbb68cca4d3d2eb5fa88a2a5e82c3ee (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443


























































































































































































































































































































































































































































                                                                                               
#define TARGET_ALPHA
#include <platform.h>
#include <imagehlp.h>
#include <crash.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "dumpexam.h"


#define GetContext(p,c)    GetContextALPHA(p,c)
#define MAX_STACK_FRAMES   100
#define SAVE_EBP(f)        f.Reserved[0]
#define TRAP_TSS(f)        f.Reserved[1]
#define TRAP_EDITED(f)     f.Reserved[1]
#define SAVE_TRAP(f)       f.Reserved[2]


extern FILE *FileOut;

VOID
PrintRegisters(
    ULONG       Processor,
    PCONTEXT    Context
    );


static
DWORD
GetStackTrace(
    PDUMP_HEADER    DmpHeader,
    ULONG           Processor,
    LPSTACKFRAME    Frames,
    ULONG           MaxFrames,
    PCONTEXT        Context
    )
{
    BOOL            rVal;
    STACKFRAME      StackFrame;
    DWORD           FrameCnt;


    FrameCnt = 0;
    ZeroMemory( &StackFrame, sizeof(STACKFRAME) );

    do {
        rVal = StackWalk(
            IMAGE_FILE_MACHINE_ALPHA,
            (HANDLE)DmpHeader,
            (HANDLE)Processor,
            &StackFrame,
            Context,
            SwReadMemory,
            SwFunctionTableAccess,
            SwGetModuleBase,
            NULL
            );
        if (rVal) {
            CopyMemory(
                &Frames[FrameCnt],
                &StackFrame,
                sizeof(STACKFRAME)
                );
            Frames[FrameCnt].Reserved[0] = (DWORD)Context->IntSp;
            FrameCnt += 1;
        }
    } while( rVal && FrameCnt < MaxFrames );

    return FrameCnt;
}

static
VOID
PrintStackTrace(
    PDUMP_HEADER    DmpHeader,
    ULONG           Processor,
    LPSTACKFRAME    StackFrames,
    ULONG           FrameCnt
    )
{
    PFPO_DATA           pFpoData;
    PIMAGEHLP_SYMBOL    Symbol;
    ULONG               i;
    ULONG               Displacement;
    CHAR                SymBuf[512];


    PrintHeading( "Stack Trace" );
    fprintf( FileOut, "Callee-SP           Arguments to Callee                 Call Site\n");

    for (i=0; i<FrameCnt; i++) {

        if (SymGetSymFromAddr( DmpHeader, StackFrames[i].AddrPC.Offset, &Displacement, sym )) {
            strcpy( SymBuf, sym->Name );
        } else {
            sprintf( SymBuf, "0x%08x", StackFrames[i].AddrPC.Offset );
        }

        fprintf(
            FileOut,
            "%08lx %08lx : %08lx %08lx %08lx %08lx %s",
            StackFrames[i].AddrFrame.Offset,
            StackFrames[i].AddrReturn.Offset,
            StackFrames[i].Params[0],
            StackFrames[i].Params[1],
            StackFrames[i].Params[2],
            StackFrames[i].Params[3],
            SymBuf
           );

        if (Displacement) {
            fprintf( FileOut, "+0x%x", Displacement );
        }

        fprintf( FileOut, "\n" );
    }

    fprintf( FileOut, "\n" );

}

VOID
PrintStackTraceALPHA(
    PDUMP_HEADER    DmpHeader,
    ULONG           Processor
    )
{
    PFPO_DATA           pFpoData;
    CONTEXT             Context;
    STACKFRAME          StackFrames[MAX_STACK_FRAMES];
    ULONG               FrameCnt;
    ULONG               i;
    CHAR                buf[32];


    GetContext( Processor, &Context );

    FrameCnt = GetStackTrace(
        DmpHeader,
        Processor,
        StackFrames,
        MAX_STACK_FRAMES,
        &Context
        );

    PrintStackTrace(
        DmpHeader,
        Processor,
        StackFrames,
        FrameCnt
        );
}

VOID
BugCheckHeuristicsALPHA(
    PDUMP_HEADER    DmpHeader,
    ULONG           Processor
    )
{
    STACKFRAME          StackFrames[MAX_STACK_FRAMES];
    ULONG               FrameCnt;
    PIMAGEHLP_SYMBOL    Symbol;
    ULONG               i;
    ULONG               cb;
    CHAR                buf[32];
    ULONG               Ptrs[4];
    CONTEXT             Context;


    if (DmpHeader->BugCheckCode == KMODE_EXCEPTION_NOT_HANDLED) {
        PrintHeading(
            "Dump Analysis Heuristics for Bugcode %s",
            GetBugText(DmpHeader->BugCheckCode)
            );
        fprintf(
            FileOut,
            "Exception Code:              0x%08x\n",
            DmpHeader->BugCheckParameter1
            );
        fprintf(
            FileOut,
            "Address of Exception:        0x%08x\n",
            DmpHeader->BugCheckParameter2
            );
        fprintf(
            FileOut,
            "Parameter #0:                0x%08x\n",
            DmpHeader->BugCheckParameter3
            );
        fprintf(
            FileOut,
            "Parameter #1:                0x%08x\n\n",
            DmpHeader->BugCheckParameter4
            );
        if (!SymGetSymFromName( DmpHeader, "PspUnhandledExceptionInSystemThread", sym )) {
            return;
        }
        GetContext( Processor, &Context );
        FrameCnt = GetStackTrace(
            DmpHeader,
            Processor,
            StackFrames,
            MAX_STACK_FRAMES,
            &Context
            );
        for (i=0; i<FrameCnt; i++) {
            if (StackFrames[i].AddrPC.Offset >= sym->Address &&
                    StackFrames[i].AddrPC.Offset < sym->Address + sym->Size) {
                break;
            }
        }
        if (i == FrameCnt) {
            return;
        }
        GetContext( Processor, &Context );
        cb = DmpReadMemory( (PVOID)(StackFrames[i+1].Reserved[0]+16), Ptrs, sizeof(Ptrs) );
        if (cb != sizeof(Ptrs)) {
            return;
        }
        sprintf( buf, "%08x", Ptrs[0] );
        DoExtension( "exr", buf, Processor, (DWORD)GetRegisterValue( &Context, REG_IP ) );
        cb = DmpReadMemory( (PVOID)Ptrs[2], &Context, sizeof(Context) );
        if (cb != sizeof(Context)) {
            return;
        }
        PrintRegisters( Processor, &Context );
        FrameCnt = GetStackTrace(
            DmpHeader,
            Processor,
            StackFrames,
            MAX_STACK_FRAMES,
            &Context
            );
        PrintStackTrace(
            DmpHeader,
            Processor,
            StackFrames,
            FrameCnt
            );
        DoDisassemble( (DWORD)Context.Fir );
    }

    if (DmpHeader->BugCheckCode == IRQL_NOT_LESS_OR_EQUAL) {
        PrintHeading(
            "Dump Analysis Heuristics for Bugcode %s",
            GetBugText(DmpHeader->BugCheckCode)
            );
        fprintf(
            FileOut,
            "Invalid Address Referenced:  0x%08x\n",
            DmpHeader->BugCheckParameter1
            );
        fprintf(
            FileOut,
            "IRQL:                        %d\n",
            DmpHeader->BugCheckParameter2
            );
        fprintf(
            FileOut,
            "Access Type:                 %s\n",
            DmpHeader->BugCheckParameter3 ? "Read" : "Write"
            );
        fprintf(
            FileOut,
            "Code Address:                0x%08x\n\n",
            DmpHeader->BugCheckParameter4
            );
        sprintf( buf, "%08x", DmpHeader->BugCheckParameter1 );
        GetContext( Processor, &Context );
        DoExtension( "pool", buf, Processor, (DWORD)GetRegisterValue( &Context, REG_IP ) );
    }
}

ULONGLONG
GetRegisterValueALPHA(
    PCONTEXT        Context,
    ULONG           Register
    )
{
    ULONGLONG   Value = 0;

    switch( Register ) {
        case REG_IP:
            Value = Context->Fir;
            break;

        case REG_FP:
            Value = Context->IntSp;
            break;

        case REG_SP:
            Value = Context->IntSp;
            break;
    }

    return Value;
}

#define FLAGMODE    1
#define FLAGIE      2
#define FLAGIRQL    3

static
ULONG
GetFlag(
    ULONGLONG FlagsReg,
    ULONG Flag
    )
{
    switch( Flag ) {
        case FLAGMODE:    return (DWORD)((FlagsReg >> 0) & 1);
        case FLAGIE:      return (DWORD)((FlagsReg >> 1) & 1);
        case FLAGIRQL:    return (DWORD)((FlagsReg >> 2) & 7);
    }
    return 0;
}

static
VOID
PrintRegisters(
    ULONG       Processor,
    PCONTEXT    Context
    )
{
    PrintHeading( "Register Dump For Processor #%d", Processor );

    fprintf(
        FileOut,
        "v0=%016Lx t0=%016Lx t1=%016Lx t2=%016Lx\n",
        Context->IntV0,
        Context->IntT0,
        Context->IntT1,
        Context->IntT2
        );
    fprintf(
        FileOut,
        "t3=%016x t4=%016x t5=%016x t6=%016x\n",
        Context->IntT3,
        Context->IntT4,
        Context->IntT5,
        Context->IntT6
        );

    fprintf(
        FileOut,
        "t7=%016x s0=%016x s1=%016x s2=%016x\n",
        Context->IntT7,
        Context->IntS0,
        Context->IntS1,
        Context->IntS2
        );

    fprintf(
        FileOut,
        "s3=%016x s4=%016x s5=%016x fp=%016x\n",
        Context->IntS3,
        Context->IntS4,
        Context->IntS5,
        Context->IntFp
        );

    fprintf(
        FileOut,
        "a0=%016x a1=%016x a2=%016x a3=%016x\n",
        Context->IntA0,
        Context->IntA1,
        Context->IntA2,
        Context->IntA3
        );

    fprintf(
        FileOut,
        "a4=%016x a5=%016x t16=%016x t9=%016x\n",
        Context->IntA4,
        Context->IntA5,
        Context->IntT8,
        Context->IntT9
        );

    fprintf(
        FileOut,
        "t10=%016x t11=%016x ra=%016x t12=%016x\n",
        Context->IntT10,
        Context->IntT11,
        Context->IntRa,
        Context->IntT12
        );

    fprintf(
        FileOut,
        "at=%016x gp=%016x sp=%016x zero=%x\n",
        Context->IntAt,
        Context->IntGp,
        Context->IntSp,
        Context->IntZero
        );

    fprintf(
        FileOut,
        "pcr=%016x softfpcr=%016x fir=%016x\n",
        Context->Fpcr,
        Context->SoftFpcr,
        Context->Fir
        );

    fprintf(
        FileOut,
        "psr=%08x\n",
        Context->Psr
        );

    fprintf(
        FileOut,
        "mode=%1x ie=%1x irql=%1x\n",
        GetFlag(Context->Psr,FLAGMODE),
        GetFlag(Context->Psr,FLAGIE),
        GetFlag(Context->Psr,FLAGIRQL)
        );

    fprintf( FileOut, "\n" );
}

VOID
GetContextALPHA(
    ULONG   Processor,
    PVOID   Context
    )
{
    DmpGetContext( Processor, Context );
}


VOID
PrintRegistersALPHA(
    ULONG   Processor
    )
{
    CONTEXT             Context;

    GetContext( Processor, &Context );
    PrintRegisters( Processor, &Context );
}