int main(int argc, char **argv) {
  struct NaClApp app;
  struct GioMemoryFileSnapshot gio_file;

  /* Register file-local handler first (so it ends up second in the chain). */
  if (strcmp(argv[1], "unforwarded_trusted") != 0) {
    RegisterExceptionHandler();
  }

  /* Install untrusted exception catcher after local handler. */
  CHECK(NaClInterceptMachExceptions());

  if (argc == 2 && strcmp(argv[1], "early_trusted") == 0) {
    g_expect_crash = 1;
    /* Cause a crash. */
    *(volatile int *) 0 = 0;
  }

  if (argc != 3) {
    NaClLog(LOG_FATAL, "Expected 1 or 2 arguments\n");
  }

  if (strcmp(argv[1], "trusted") == 0) {
    g_expect_crash = 1;
  } else if (strcmp(argv[1], "unforwarded_trusted") == 0) {
    fprintf(stderr, "** intended_exit_status=-10\n");
    g_expect_crash = 0;
  } else if (strcmp(argv[1], "untrusted") == 0) {
    /* Expect the test to crash; untrusted crashes shouldn't be propagated. */
    fprintf(stderr, "** intended_exit_status=-10\n");
    g_expect_crash = 0;
  } else if (strcmp(argv[1], "untrusted_caught") == 0) {
    g_expect_crash = 0;
  } else {
    NaClLog(LOG_FATAL, "1st argument (%s) not recognised\n", argv[1]);
  }

  NaClAllModulesInit();

  NaClFileNameForValgrind(argv[1]);
  CHECK(GioMemoryFileSnapshotCtor(&gio_file, argv[2]));
  CHECK(NaClAppCtor(&app));
  app.enable_exception_handling = 1;
  CHECK(NaClAppLoadFile((struct Gio *) &gio_file, &app) == LOAD_OK);
  CHECK(NaClAppPrepareToLaunch(&app) == LOAD_OK);
  CHECK(NaClCreateMainThread(&app, 0, NULL, NULL));
  CHECK(NaClWaitForMainThreadToExit(&app) == 0);

  if (g_expect_crash) {
    NaClLog(LOG_FATAL, "Did not expect the guest code to exit\n");
    return 1;
  } else {
    fprintf(stderr, "No crashes, as intended.\n");
    fprintf(stderr, "** intended_exit_status=0\n");
    return 0;
  }
}
예제 #2
0
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);
    }

}
예제 #3
0
파일: jnfs.c 프로젝트: BillTheBest/WinNT4
VOID
FailSafeEntry(
    IN ULONG Unused0,
    IN PFW_PROCESSOR_INFORMATION Unused1,
    IN PFW_SYSTEM_INFORMATION SystemInfo
    )
/*++

Routine Description:

    This function gets control from the serial ROM if the serial ROM
    detects a corrupted VMS Console boot image.  (In actuality, the
    serial ROM passes control the the linked firmware PALcode, which
    passes control to this function.)


Arguments:

    Unused0,		This keeps the PALcode interface identical to
    Unused1		the firmware.
    			
    SystemInfo		Contains Alpha_AXP information from the PALcode.
                        Since this module is only executed on a hard reset,
			there is no need to check the "Cause" argument.
    
Return Value:

    Never returns.

--*/

{
    UNREFERENCED_PARAMETER(Unused0);
    UNREFERENCED_PARAMETER(Unused1);

    FwRtlStackPanic = 0;

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

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

    switch (SystemInfo->SystemCycleClockPeriod) {

      //
      // A bad cycle clock period would cause a system hang.
      //
      case 0:
      case 8000:
      default:
	CyclesPerMicrosecond = 125 + 1;
        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:
	CyclesPerMicrosecond = 150 + 1;
        break;
    }

    // Initialize MemorySize to the size of memory in MegaBytes.
    MemorySize = SystemInfo->MemorySizeInBytes;


    //
    // 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->RestartBlock = NULL;
    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);

    SerialBootSetup(COMPORT1_VIRTUAL_BASE);
    SerialBootSetup(COMPORT2_VIRTUAL_BASE);	// This may not be needed.

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

    if (DisplayBootInitialize(&VideoType) != ESUCCESS) {
        SerialOutput = TRUE;
	FwClearScreen();
    } else {
        // Video is ready to display messages.
        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);
	DisplayOutput = FALSE;
	SerialOutput = TRUE;
    }


    PutLedDisplay(LED_VIDEO_OK);

    //
    // hang on error
    //

    while (RomInitISP()) {
    }


#if 0

    //
    // This is believed to not be 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

    //
    // Now try to complete the upgrade.
    //

    JnFsUpgradeSystem();

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

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

}