summaryrefslogblamecommitdiffstats
path: root/private/ntos/nthals/halncr/i386/ncrnmi.c
blob: 09714236542d2bddba83df4bc2e62869e3b6607a (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





































































































































































































































































































































































































































                                                                              
/*++

Copyright (c) 1991  Microsoft Corporation

Module Name:

    ncrnmi.c

Abstract:

    Provides ncr x86 NMI handler

Author:

    kenr

Revision History:

--*/
#include "halp.h"
#include "bugcodes.h"
#include "ncr.h"
#include "ncrnls.h"

#define SYSTEM_CONTROL_PORT_A        0x92
#define SYSTEM_CONTROL_PORT_B        0x61
#define EISA_EXTENDED_NMI_STATUS    0x461

extern  ULONG   NCRPlatform;

VOID HalpDumpAsicPorts (UCHAR *p, ULONG arg, ...);
VOID HalpDumpBitsField (UCHAR bits, char *BitMsgs[]);
VOID HexSubPort (PUCHAR *o, ULONG l);
VOID HalpDumpFred (UCHAR FredId);
VOID HalpDumpVMC (UCHAR VMCId);
VOID HalpDumpMCADDR (UCHAR MCADDRId);
VOID HalpDumpArbiter (UCHAR ArbiterId);

BOOLEAN HalpSUSSwNmi();

ULONG NmiLock;
UCHAR HexString[] = "0123456789ABCDEF";

char *NmiStatusRegisterBits[] = {
    MSG_GLOBAL_NMI,                     // 0
    MSG_SHUTDOWN_OCCURRED,              // 1
    MSG_LOCAL_EXTERNAL_ERROR,           // 2
    MSG_SB_READ_DATA_PARITY_ERROR,      // 3
    MSG_SB_ERROR_L_TERMINATION,         // 4
    MSG_P5_INTERNAL_ERROR,              // 5
    NULL,                               // 6
    MSG_PROCESSOR_HALTED                // 7
};

char *ParityErrorIntStatusBits[] = {
    MSG_SB_ADDRESS_PARITY_ERROR,        // 0
    MSG_SB_DATA_PARITY_ERROR,           // 1
    NULL,                               // 2
    NULL,                               // 3
    NULL,                               // 4
    MSG_SHUTDOWN_ERROR_INT_L,           // 5
    MSG_EXTERNAL_ERROR_INT_L,           // 6
    MSG_P_IERR_L_ERROR_INT_L            // 7
};

char *VMCErrorStatusZeroBits[] = {
    MSG_VDLC_DATA_ERROR,                // 0
    MSG_LST_ERROR,                      // 1
    MSG_BUS_A_DATA_PARITY_ERROR,        // 2
    MSG_BUS_B_DATA_PARITY_ERROR,        // 3
    MSG_LST_UNCORRECTABLE_ERROR,        // 4
    NULL,                               // 5
    NULL,                               // 6
    NULL                                // 7
};

char *SBErrorIntStatusBits[] = {
    MSG_MC_MASTER_ERROR,                // 0
    MSG_SA_MASTER_ERROR,                // 1
    MSG_SA_MASTER_ERROR,                // 2
    MSG_MC_TOE_ERROR,                   // 3
    MSG_ASYNC_ERROR,                    // 4
    MSG_SYNC_ERROR,                     // 5
    MSG_REFRESH_ERROR,                  // 6
    MSG_SXERROR_L                       // 7
};

char *InterruptStatusOneBits[] = {
    "PAR_INT_B",                        // 0
    "PAR_INT_A",                        // 1
    "ELATCHD_B",                        // 2
    "ELATCHD_A",                        // 3
    "TOE_B",                            // 4
    "TOE_A",                            // 5
    "PROTO_ERR_B",                      // 6
    "PROTO_ERR_A"                       // 7
};

char *InterruptStatusTwoBits[] = {
    "MC_TOE",                           // 0
    "COUGAR_NMI",                       // 1
    "EXP_MC_TOE",                       // 2
    "EXP_COUGAR_NMI",                   // 3
    "POWER_FAIL",                       // 4
    "ERROR_INT",                        // 5
    "SW_NMI",                           // 6
    NULL                                // 7
};

VOID
HalHandleNMI(
    IN OUT PVOID NmiInfo
    )
/*++

Routine Description:

    Called DURING an NMI.  The system will BugCheck when an NMI occurs.
    This function can return the proper bugcheck code, bugcheck itself,
    or return success which will cause the system to iret from the nmi.

    This function is called during an NMI - no system services are available.
    In addition, you don't want to touch any spinlock which is normally
    used since we may have been interrupted while owning it, etc, etc...

Warnings:

    Do NOT:
      Make any system calls
      Attempt to acquire any spinlock used by any code outside the NMI handler
      Change the interrupt state.  Do not execute any IRET inside this code

    Passing data to non-NMI code must be done using manual interlocked
    functions.  (xchg instructions).

Arguments:

    NmiInfo - Pointer to NMI information structure  (TBD)
            - NULL means no NMI information structure was passed

Return Value:

    BugCheck code

--*/
{
    UCHAR   StatusByte;

    _asm {
nmi00:
        lock bts NmiLock, 0
        jnc     nmilocked

nmi10:
        test    NmiLock, 1
        jnz     short nmi10
        jmp     short nmi00
nmilocked:
    }

    if (NmiLock & 2) {
        // some other processor has already processed the Nmi and
        // determined that the machine should crash - just stop
        // this processor



        NmiLock = 2;        // free busy bit
        KeEnterKernelDebugger ();
        return;
    }


    if (NCRPlatform != NCR3360) {

//
// If is this is the Dump switch
//
        if (HalpSUSSwNmi() == TRUE) {
            NmiLock = 2;
            KeEnterKernelDebugger();
            return;
        }
    }

    HalDisplayString (MSG_HARDWARE_ERROR1);
    HalDisplayString (MSG_HARDWARE_ERROR3);

    StatusByte = READ_PORT_UCHAR((PUCHAR) SYSTEM_CONTROL_PORT_B);

    if (StatusByte & 0x80) {
        HalDisplayString (MSG_NMI_PARITY);
    }

    if (StatusByte & 0x40) {
        HalDisplayString (MSG_NMI_CHANNEL_CHECK);
    }

    if (NCRPlatform == NCR3360) {
        HalpDumpFred (0x41);        // fred 1
        HalpDumpFred (0x61);        // fred 2

        HalpDumpVMC  (0x81);        // memory 1
        HalpDumpVMC  (0x91);        // memory 2

        HalpDumpArbiter (0xC1);     // arbiter
        HalpDumpMCADDR (0xC0);      // mcaddr
    } else {
//
// For 3450 and 3550 let SUS go do FRU analysis and log the error to SUS
// error log.  After SUS logs the error the system will reboot and the
// HwMon service will copy the SUS error log to the NT error log.
//

        HalDisplayString ("NMI: 345x/35xx SUS Logging Error\n");
        HalpSUSLogError();
    }

    HalDisplayString (MSG_HALT);
    NmiLock = 2;
    KeEnterKernelDebugger ();
}


VOID HalpDumpFred (UCHAR FredId)
{
    UCHAR   c;

    WRITE_PORT_UCHAR ((PUCHAR) 0x97, FredId);
    c = READ_PORT_UCHAR ((PUCHAR) 0xf801);
    if (c & 0xf0 != 0x20) {
        return ;
    }

    HalpDumpAsicPorts (MSG_FRED, FredId, 0xf808, 0xf80d);

    c = READ_PORT_UCHAR ((PUCHAR) 0xf809);
    HalpDumpBitsField (c, NmiStatusRegisterBits);

    c = READ_PORT_UCHAR ((PUCHAR) 0xf80b);
    HalpDumpBitsField (c, ParityErrorIntStatusBits);
    HalDisplayString("\n");
}

VOID HalpDumpVMC (UCHAR VMCId)
{
    UCHAR   c;

    WRITE_PORT_UCHAR ((PUCHAR) 0x97, VMCId);
    c = READ_PORT_UCHAR ((PUCHAR) 0xf800);
    if (c != 0x81  &&  c != VMCId) {
        return ;
    }

    HalpDumpAsicPorts ("VMC %x: S0 = %p  S1 = %p  S2 = %p  BD/D = %p\n",
        VMCId, 0xf804, 0xf808, 0xf809, 0xf80a);

    c = READ_PORT_UCHAR ((PUCHAR) 0xf80d);
    HalpDumpBitsField (c, VMCErrorStatusZeroBits);

    if (c & 0x04) {
        HalpDumpAsicPorts (MSG_A_PARITY, 0x13, 0x14, 0x18, 0x19);
    }

    if (c & 0x08) {
        HalpDumpAsicPorts (MSG_B_PARITY, 0x23, 0x24, 0x28, 0x29);
    }

    WRITE_PORT_UCHAR ((PUCHAR) 0x97, 0xc1);  // select arbiter
    c = READ_PORT_UCHAR ((PUCHAR) 0xf808);
    WRITE_PORT_UCHAR ((PUCHAR) 0x97, VMCId);

    if (c & 0x20) {                     // check for s_error
        HalpDumpAsicPorts (MSG_A_TOE, 0x1d, 0x1e);

    }

    if (c & 0x10) {                     // check for s_error
        HalpDumpAsicPorts (MSG_B_TOE, 0x2d, 0x2e);
    }
    HalDisplayString("\n");
}

VOID HalpDumpMCADDR (UCHAR MCADDRId)
{
    UCHAR   c;

    WRITE_PORT_UCHAR ((PUCHAR) 0x97, MCADDRId);
    c = READ_PORT_UCHAR ((PUCHAR) 0xf800);
    if (c != MCADDRId) {
        return ;
    }
    WRITE_PORT_UCHAR ((PUCHAR) 0xF807, 0);

    HalpDumpAsicPorts ("MCADDR: %x\n", MCADDRId);
    HalpDumpAsicPorts (MSG_A_GOOD, 0x40, 0x43, 0x44);
    HalpDumpAsicPorts (MSG_B_GOOD, 0x45, 0x48, 0x49);
    HalpDumpAsicPorts (MSG_A_LAST, 0x4a, 0x4d);
    HalpDumpAsicPorts (MSG_B_LAST, 0x4e, 0x51);

    WRITE_PORT_UCHAR ((PUCHAR) 0xF806, 0x55);
    c = READ_PORT_UCHAR((PUCHAR) 0xF803);
    HalpDumpBitsField (c, SBErrorIntStatusBits);
    HalpDumpAsicPorts (MSG_MC_ADDRESS, 0x55, 0x5c, 0x5d);
        // status bits decode as:
        //      0x04 = 1 is memory, 0 is I/O

    if (c & 0x08) {
        HalpDumpAsicPorts (MSG_MC_TIMEOUT, 0x58);
    }

    HalpDumpAsicPorts (MSG_MC_PARITY, 0x5e, 0x5e);
    HalDisplayString ("\n");
}

VOID HalpDumpArbiter (UCHAR ArbiterId)
{
    UCHAR   c;

    WRITE_PORT_UCHAR ((PUCHAR) 0x97, ArbiterId);
    c = READ_PORT_UCHAR ((PUCHAR) 0xf800);
    if (c != ArbiterId) {
        return ;
    }

    HalpDumpAsicPorts ("Aribter: %x\n", ArbiterId);

    c = READ_PORT_UCHAR((PUCHAR) 0xF808);
    HalpDumpBitsField (c, InterruptStatusOneBits);

    c = READ_PORT_UCHAR((PUCHAR) 0xF809);
    HalpDumpBitsField (c, InterruptStatusTwoBits);
    HalDisplayString ("\n");
}



VOID HalpDumpBitsField (UCHAR bits, char *BitMsgs[])
{
    UCHAR   i;

    for (i=0; i < 8; i++) {
        if (bits & 1  &&  BitMsgs[i]) {
            HalDisplayString ("    ");
            HalDisplayString (BitMsgs[i]);
            HalDisplayString ("\n");
        }
        bits >>= 1;
    }
}


VOID HalpDumpAsicPorts (PUCHAR p, ULONG arg, ...)
{
    UCHAR   c;
    PUCHAR  o;
    UCHAR   s[150];
    PULONG  stack;
    ULONG   l;

    o = s;
    stack = &arg;
    while (*p) {
        if (*p == '%') {
            p++;
            l = *(stack++);
            switch (*(p++)) {

                // truncate sting if bit-0 is not set
                case '1':
                    WRITE_PORT_UCHAR ((PUCHAR) 0xF806, (UCHAR) l);
                    c = READ_PORT_UCHAR((PUCHAR) 0xF803);
                    if ((c & 1) == 0) {
                        return ;
                    }
                    break;

                case 'p':                                   // port value
                    c = READ_PORT_UCHAR((PUCHAR) l);
                    *(o++) = HexString[c >> 4];
                    *(o++) = HexString[c & 0xF];
                    break;

                case 's':                                   // sub-port value
                    HexSubPort (&o, l);
                    break;

                case 'A':                                   // address at
                    HexSubPort (&o, l);                     // sub-port
                    HexSubPort (&o, l-1);
                    HexSubPort (&o, l-2);
                    HexSubPort (&o, l-3);
                    break;

                case 'x':                                   // hex byte
                    *(o++) = HexString[l >> 4];
                    *(o++) = HexString[l & 0xF];
                    break;

                default:
                    *(o++) = '?';
                    break;
            }
        } else {
            *(o++) = *(p++);
        }
    }
    *o = 0;
    HalDisplayString (s);
}

VOID HexSubPort (PUCHAR *o, ULONG l)
{
    UCHAR   c;

    WRITE_PORT_UCHAR ((PUCHAR) 0xF806, (UCHAR) l);
    c = READ_PORT_UCHAR((PUCHAR) 0xF803);

    o[0][0] = HexString[c >> 4];
    o[0][1] = HexString[c & 0xF];
    *o += 2;
}