summaryrefslogtreecommitdiffstats
path: root/private/ntos/fw/alpha/jensen/alpha/selftest.c
blob: 1623acbf945645b229e5407794fcf362a073f5c0 (plain) (blame)
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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
/*++

Copyright (c) 1990  Microsoft Corporation
Copyright (c) 1993  Digital Equipment Corporation

Module Name:

    selftest.c

Abstract:

    This module contains the routines that perform the selftest of
    the IO devices.

Author:

    Lluis Abello (lluis) 03-Jan-1991

Environment:


Revision History:

    23-April-1992	John DeRosa [DEC]

    Added Alpha/Jensen modifications.  For Jensen, the VMS/OSF console
    front-end will be running the ROM-based diagnostics so this code
    does not have to do it.


--*/

#include "fwp.h"
#include "iodevice.h"
#include "led.h"
#include "selftest.h"
#include "fwpexcpt.h"
#include "fwstring.h"

BOOLEAN ConfigurationBit;      // read value from diagnostic register

PRTL_ALLOCATE_STRING_ROUTINE RtlAllocateStringRoutine =
    (PRTL_ALLOCATE_STRING_ROUTINE)FwAllocatePool;
PRTL_FREE_STRING_ROUTINE RtlFreeStringRoutine = FwpFreeStub;


VOID
FwInstallKd(
    IN VOID
    );


#ifdef ALPHA_FW_SERDEB
//
// Variable that enables printing on the COM1 line.
//
extern BOOLEAN SerSnapshot;
#endif


// This variable is initialized to the size of the memory in bytes.
ULONG MemorySize;


//
// This receives the type of video card installed into the system.
// It is a static because memory is intialized near the bottom of the
// program execute calling chain (FwExecute, FwPrivateExecute, FwResetMemory,
// FwInitializeMemory), and the calling interface to FwExecute is
// frozen by the ARCS specification.
//
// This is valid only on a successful intialization of the graphics card.
//
ALPHA_VIDEO_TYPE VideoType;


// The indicator of a bad Firmware stack for _RtlCheckStack 
ULONG FwRtlStackPanic;

#ifdef ALPHA_FW_VDB
//
// Debugging Aid
//
extern UCHAR DebugAid[2][150];
#endif

extern ULONG EISABufferListPointer;

//
// Alpha AXP PALcode static variables
//

// The processor type
ULONG ProcessorId;

// The processor revision number.
ULONG ProcessorRevision;

// The number of physical address bits.
ULONG NumberOfPhysicalAddressBits;

// The maximum address space number.
ULONG MaximumAddressSpaceNumber;

// The processor cycle counter period.
ULONG ProcessorCycleCounterPeriod;

// Number of processor cycles per microsecond.
ULONG CyclesPerMicrosecond;

// The processor page size, in bytes.
ULONG ProcessorPageSize;

// The system revision number
ULONG SystemRevisionId;

//
// Declare function prototypes.
//

VOID
PutLedDisplay(
    IN UCHAR Value
    );

ULONG
RomInitISP (
    VOID
    );

ARC_STATUS
SerialBootWrite(
    CHAR  Char,
    ULONG SP
    );

VOID
WildZeroMemory(
    ULONG StartAddress,
    ULONG Size
    );

VOID
FwBootSystem (
    VOID
    );

VOID
FwEntry(
    IN ULONG Cause,
    IN PFW_PROCESSOR_INFORMATION ProcessorInfo,
    IN PFW_SYSTEM_INFORMATION SystemInfo
    )
/*++

Routine Description:

    This routine is the c routine called from the ROM. It must be placed
    at the beginning of the C code because the ROM copies the code from this
    point to the end and then jumps to it.

    This has a different calling interface than the Jazz code.

    
Arguments:

    Cause		0 on a normal reset/powerup.
         		1 on a softreset.

    ProcessorInfo	Pointer to processor information block.
                        Valid only if Cause = 0.

    SystemInfo		Pointer to system information block.
                        Valid only if Cause = 0.


Return Value:

    Never returns.

--*/

{
#if 0
// Diagnostic bits turned off in final product.
    CHAR Diag;
#endif

    FwRtlStackPanic = 0;

    // Register exception handler with the firmware PALcode
    RegisterExceptionHandler();

    // Reset EISA memory buffer list.
    EISABufferListPointer = 0;

    // Clear out upper EISA address bits.
    WRITE_PORT_UCHAR((PUCHAR)HAE, 0x0);

    // Announce that the NT firmware has gotten control of the horizontal.
    PutLedDisplay(LED_NT_BOOT_START);

    // We cannot rely on the static C initialization of this if we are
    // doing a soft-reset.
    FwConsoleInitialized = FALSE;

    //
    // Deposit Alpha AXP architectural values into global variables if
    // this is a hard reset.
    //

    if (Cause == 0) {
	ProcessorId = ProcessorInfo->ProcessorId;
	ProcessorRevision = ProcessorInfo->ProcessorRevision;
	ProcessorPageSize = ProcessorInfo->PageSize;
	NumberOfPhysicalAddressBits = ProcessorInfo->PhysicalAddressBits;
	MaximumAddressSpaceNumber = ProcessorInfo->MaximumAddressSpaceNumber;
	SystemRevisionId = SystemInfo->SystemRevisionId;
	
	switch (SystemInfo->SystemCycleClockPeriod) {

	    //
	    // A bad cycle clock period would cause a system hang.
	    //
	    case 0:
	    case 8000:
	    default:
	      ProcessorCycleCounterPeriod = 8000;
	      break;

	    //
	    // This is an AX04 SROM bug: the number for a 6.667ns machine is
	    // passed in as 6600, not 6667.
	    //
	    case 6600:
	    case 6667:
	      ProcessorCycleCounterPeriod = 6667;
	      break;
	}

	//
	// Load the number of machine cycles per usecond, for use by
	// FwStallExecution.  The +1 ensures that this value is never
	// too optimistic, due to the float->integer truncation.
	//

	CyclesPerMicrosecond = (1000000 / ProcessorCycleCounterPeriod) + 1;

        MemorySize = SystemInfo->MemorySizeInBytes;
    }

    //
    // Set variables according to the bits in configuration register
    //
    ConfigurationBit = FALSE;
    DisplayOutput = FALSE;
    SerialOutput = FALSE;

    //
    // Look for configuration register.
    //

#if 0
//
// The ConfigurationBit is disabled in the product.
//
    HalpWriteVti(RTC_APORT, RTC_RAM_NT_FLAGS0);
    Diag = HalpReadVti(RTC_DPORT);
    if (((PRTC_RAM_NT_FLAGS_0)(&Diag))->ConfigurationBit) {
	ConfigurationBit = TRUE;
    }
#endif


    //
    // Set interrupt lines to a known state.
    //

    WRITE_PORT_UCHAR((PUCHAR)&SP1_WRITE->ModemControl,0x08);
    WRITE_PORT_UCHAR((PUCHAR)&SP2_WRITE->ModemControl,0x08);
    WRITE_PORT_UCHAR((PUCHAR)&FLOPPY_WRITE->DigitalOutput,0x08);
    READ_PORT_UCHAR((PUCHAR)&PARALLEL_READ->Status);

    //
    // Initialize the system parameter block.
    //

    SYSTEM_BLOCK->Signature = 0x53435241;
    SYSTEM_BLOCK->Length = sizeof(SYSTEM_PARAMETER_BLOCK);
    SYSTEM_BLOCK->Version = ARC_VERSION;
    SYSTEM_BLOCK->Revision = ARC_REVISION;
    SYSTEM_BLOCK->DebugBlock = NULL;

    SYSTEM_BLOCK->FirmwareVectorLength = (ULONG)MaximumRoutine * sizeof(ULONG);
    SYSTEM_BLOCK->FirmwareVector =
                (PVOID)((PUCHAR)SYSTEM_BLOCK + sizeof(SYSTEM_PARAMETER_BLOCK));
    SYSTEM_BLOCK->VendorVectorLength = (ULONG)MaximumVendorRoutine * sizeof(ULONG);
    SYSTEM_BLOCK->VendorVector =
                (PVOID)((PUCHAR)SYSTEM_BLOCK->FirmwareVector +
                                SYSTEM_BLOCK->FirmwareVectorLength);

    //
    // Always init the serial ports, because the NT Setup utility sends
    // diagnostics there.
    //

    PutLedDisplay(LED_SERIAL_INIT);
    SerialBootSetup(COMPORT1_VIRTUAL_BASE);
    SerialBootSetup(COMPORT2_VIRTUAL_BASE);

#ifdef ALPHA_FW_KDHOOKS

    //
    // Initialize the kernel debugger stub.  This can be called anytime
    // after the serial lines are inited.
    //

    FwInstallKd();

#endif

    //
    // If:  the configuration bit is set, or
    //      the video card initialization fails,
    // ...output to the serial line.  Otherwise, output to video.
    //

    PutLedDisplay (LED_KEYBOARD_CTRL);
    if (ConfigurationBit || (DisplayBootInitialize(&VideoType) != ESUCCESS)) {
        SerialOutput = TRUE;
        PutLedDisplay(LED_BROKEN_VIDEO_OR_KB);
        FwClearScreen();
    } else {
        // Video is ready to display messages.
        PutLedDisplay(LED_VIDEO_OK);
        DisplayOutput = TRUE;
    }


    //
    // If: the keyboard controller initialization fails, or
    //     the keyboard initialization fails,
    // ...send an error message to the output device and direct future output
    // to the serial port.
    //

    if (InitKeyboardController() || InitKeyboard()) {
	FwPrint(ST_ALL_IO_TO_SERIAL_LINES_MSG);
	PutLedDisplay(LED_BROKEN_VIDEO_OR_KB);
	DisplayOutput = FALSE;
	SerialOutput = TRUE;
    }


#ifdef ALPHA_FW_SERDEB
#ifdef ALPHA_FW_VDB

{
    //
    // Graphics debugging assistance.  Print pre-init and post-init video
    // state.
    //

    ULONG H, I, J;

    SerSnapshot = TRUE;

    for (J = 0; J < 8; J++) {

	for (H = 0; H < 2; H++) {

	    SerFwPrint("[%d:%d] = ", H, J*16);

	    for (I = J*16; I < (J+1)*16; I++) {
		SerFwPrint("%x ", DebugAid[H][I]);
	    }
	    
	    SerFwPrint("\r\n");
	}

    }

}

#endif
#endif


    //
    // Check for Alpha AXP architectural values that are obviously bad.
    //

    if (Cause == 0) {
	if (ProcessorInfo->PageSize != PAGE_SIZE) {
	    FwPrint(ST_BAD_PAGE_SIZE_MSG, ProcessorInfo->PageSize);
	    FwStallExecution(5 * 1000 * 1000);
	}
	if (SystemInfo->MemorySizeInBytes < FOUR_MB) {
	    FwPrint(ST_BAD_MEMORY_SIZE_MSG, SystemInfo->MemorySizeInBytes);
	    FwStallExecution(5 * 1000 * 1000);
	}
	if (SystemInfo->SystemCycleClockPeriod == 0) {
	    FwPrint(ST_BAD_CLOCK_PERIOD_MSG, ProcessorCycleCounterPeriod);
	    FwStallExecution(5 * 1000 * 1000);
	}
    }

    if (RomInitISP()) {
      FwPrint(ST_EISA_ISP_ERROR_MSG);
    }


#if 0

    //
    // This is not necessary.
    //

    //
    // Zero unused memory.
    //
    // This is dependent on the firmware memory map.
    // This could be made more independent via using #define's.
    //

    WildZeroMemory(
                   (KSEG0_BASE | 0x0),
                   (FW_BOTTOM_ADDRESS - 0x40000)
                  );

    WildZeroMemory(
                   (KSEG0_BASE | FW_TOP_ADDRESS),
                   (MemorySize - FW_TOP_ADDRESS)
                  );

#endif

    FwBootSystem();

    //
    // Hang if we come back.
    //

    for (;;) {
        PutLedDisplay(LED_OMEGA);
    }

}

VOID
PutLedDisplay(
    IN UCHAR Value
    )
/*++

Routine Description:

    This displays a 0--F in the single hexadecimal digit display in
    Jensen.
    
Arguments:

    Value		The lower four bits of this will be displayed
			in the Jensen LED.

Return Value:

    None.

--*/

{

  WRITE_PORT_UCHAR ((PUCHAR)SYSCTL,
			(READ_PORT_UCHAR((PUCHAR)SYSCTL) & 0xf0)
			|
			(Value & 0x0f)
			);
  }

ULONG
RomInitISP (
    VOID
    )

/*++

Routine Description:

    This routine initializes the EISA interrupt controller.

Arguments:

    None.

Return Value:

    Returns the number of errors found.

--*/

{

    UCHAR DataByte;
    UCHAR InterruptLevel;

    //
    // Initialize the EISA interrupt controller.  There are two cascaded
    // interrupt controllers, each of which must initialized with 4 initialize
    // control words.
    //

    DataByte = 0;
    ((PINITIALIZATION_COMMAND_1) &DataByte)->Icw4Needed = 1;
    ((PINITIALIZATION_COMMAND_1) &DataByte)->InitializationFlag = 1;

    WRITE_PORT_UCHAR((PUCHAR)&EISA_CONTROL->Interrupt1ControlPort0,DataByte);
    WRITE_PORT_UCHAR((PUCHAR)&EISA_CONTROL->Interrupt2ControlPort0,DataByte);

    //
    // The second intitialization control word sets the interrupt vector to
    // 0-15.
    //

    DataByte = 0;

    WRITE_PORT_UCHAR((PUCHAR)&EISA_CONTROL->Interrupt1ControlPort1,DataByte);

    DataByte = 0x08;

    WRITE_PORT_UCHAR((PUCHAR)&EISA_CONTROL->Interrupt2ControlPort1,DataByte);

    //
    // The third initialization control word set the controls for slave mode.
    // The master ICW3 uses bit position and the slave ICW3 uses a numeric.
    //

    DataByte = 1 << SLAVE_IRQL_LEVEL;

    WRITE_PORT_UCHAR((PUCHAR)&EISA_CONTROL->Interrupt1ControlPort1,DataByte);

    DataByte = SLAVE_IRQL_LEVEL;

    WRITE_PORT_UCHAR((PUCHAR)&EISA_CONTROL->Interrupt2ControlPort1,DataByte);

    //
    // The fourth initialization control word is used to specify normal
    // end-of-interrupt mode and not special-fully-nested mode.
    //

    DataByte = 0;
    ((PINITIALIZATION_COMMAND_4) &DataByte)->I80x86Mode = 1;

    WRITE_PORT_UCHAR((PUCHAR)&EISA_CONTROL->Interrupt1ControlPort1,DataByte);
    WRITE_PORT_UCHAR((PUCHAR)&EISA_CONTROL->Interrupt2ControlPort1,DataByte);


    //
    // Mask all the interrupts.
    //
    WRITE_PORT_UCHAR((PUCHAR)&EISA_CONTROL->Interrupt1ControlPort1,0xFF);
    WRITE_PORT_UCHAR((PUCHAR)&EISA_CONTROL->Interrupt2ControlPort1,0xFF);


#if 0
    //
    // Jazz code
    //

    //
    // Check that the interrupt level is 7 (i.e. no interrupt is pending)
    //
    InterruptLevel=READ_PORT_UCHAR((PUCHAR)&DMA_CONTROL->InterruptAcknowledge);
    InterruptLevel=READ_PORT_UCHAR((PUCHAR)&DMA_CONTROL->InterruptAcknowledge);

    if (InterruptLevel == 0x07) {
    return 0;
    } else {
    return 1;
    }
#else

    //
    // Alpha/Jensen code
    //
    
    //
    // Check that no interrupts are pending.
    //

    WRITE_PORT_UCHAR((PUCHAR)&EISA_CONTROL->Interrupt1ControlPort0, 0xA);
    InterruptLevel = READ_PORT_UCHAR((PUCHAR)&EISA_CONTROL->Interrupt1ControlPort0);
    WRITE_PORT_UCHAR((PUCHAR)&EISA_CONTROL->Interrupt2ControlPort0, 0xA);
    InterruptLevel |= READ_PORT_UCHAR((PUCHAR)&EISA_CONTROL->Interrupt2ControlPort0);

    return(InterruptLevel);
#endif

}