Ejemplo n.º 1
0
int klog(char* component, int is_good, const char *fmt, ...) {
    acquire_klog_lock();
    if(is_good != KLOG_ERR) {
       ST->ConOut->SetAttribute(ST->ConOut,EFI_TEXT_ATTR(EFI_GREEN|0x8,EFI_BACKGROUND_BLACK));
    } else {
       ST->ConOut->SetAttribute(ST->ConOut,EFI_TEXT_ATTR(EFI_RED|0x8,EFI_BACKGROUND_BLACK));
    }
    char temp_buf[15];
    char comp_buf[15];
    snprintf(comp_buf,15,"[%s]",component);
    snprintf(temp_buf,15,"%-10s ",comp_buf);
    int i;
    CHAR16 str[] = {0,0};
    for(i=0; i<strlen(temp_buf); i++) {
       str[0] = (CHAR16)(temp_buf[i]);
       ST->ConOut->OutputString(ST->ConOut,str);
    }
    ST->ConOut->SetAttribute(ST->ConOut,EFI_TEXT_ATTR(EFI_LIGHTGRAY,EFI_BACKGROUND_BLACK));
    va_list ap;
    va_start(ap, fmt);
    int retval = kvprintf(fmt,ap);
    va_end(ap);
    if(is_good != KLOG_PROG) {
       kprintf("\n");
    }
    release_klog_lock();
}
Ejemplo n.º 2
0
static void
efi_text_cons_display(struct vis_consdisplay *da)
{
	EFI_STATUS st;
	UINTN attr;
	UINTN row, col;
	tem_char_t *data;
	int i;

	(void)conout->QueryMode(conout, conout->Mode->Mode, &col, &row);

	/* reduce clear line on bottom row by one to prevent autoscroll */
	if (row - 1 == da->row && da->col == 0 && da->width == col)
		da->width--;

	data = (tem_char_t *)da->data;
	attr = EFI_TEXT_ATTR(solaris_color_to_efi_color[da->fg_color & 0xf],
	    solaris_color_to_efi_color[da->bg_color & 0xf]);
	st = conout->SetAttribute(conout, attr);
	if (EFI_ERROR(st))
		return;
	row = da->row;
	col = da->col;
	conout->SetCursorPosition(conout, col, row);
	for (i = 0; i < da->width; i++)
		efi_cons_efiputchar(data[i]);
}
Ejemplo n.º 3
0
/**
  Event handler registered with the Data Hub to parse EFI_DEBUG_CODE. This
  handler reads the Data Hub and sends any DEBUG info to StdErr.

  @param Event      The event that occured, not used
  @param Context    DataHub Protocol Pointer
**/
VOID
EFIAPI
DataHubStdErrEventHandler (
  IN EFI_EVENT Event,
  IN VOID      *Context
  )
{
  EFI_STATUS                           Status;
  EFI_DATA_HUB_PROTOCOL                *DataHub;
  EFI_DATA_RECORD_HEADER               *Record;
  DATA_HUB_STATUS_CODE_DATA_RECORD     *DataRecord;
  UINT64                               Mtc;
  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL      *Sto;
  INT32                                OldAttribute;

  DataHub = (EFI_DATA_HUB_PROTOCOL *) Context;

  //
  // If StdErr is not yet initialized just return a DEBUG print in the BDS
  // after consoles are connect will make sure data gets flushed properly
  // when StdErr is available.
  //
  if (gST == NULL) {
    return ;
  }

  if (gST->StdErr == NULL) {
    return ;
  }

  //
  // Mtc of zero means return the next record that has not been read by the
  // event handler.
  //
  Mtc = 0;
  do {
    Status = DataHub->GetNextRecord (DataHub, &Mtc, &mDataHubStdErrEvent, &Record);
    if (!EFI_ERROR (Status)) {
      if (CompareGuid (&Record->DataRecordGuid, &gEfiDataHubStatusCodeRecordGuid)) {
        DataRecord = (DATA_HUB_STATUS_CODE_DATA_RECORD *) (((CHAR8 *) Record) + Record->HeaderSize);

        if (DataRecord->Data.HeaderSize > 0) {
          if (CompareGuid (&DataRecord->Data.Type, &gEfiStatusCodeDataTypeDebugGuid)) {
            //
            // If the Data record is from a DEBUG () then send it to Standard Error
            //
            Sto           = gST->StdErr;
            OldAttribute  = Sto->Mode->Attribute;
            Sto->SetAttribute (Sto, EFI_TEXT_ATTR (EFI_MAGENTA, EFI_BLACK));
            Sto->OutputString (Sto, (CHAR16 *) (DataRecord + 1));
            Sto->SetAttribute (Sto, OldAttribute);
          }
        }
      }
    }
  } while ((Mtc != 0) && !EFI_ERROR (Status));
}
Ejemplo n.º 4
0
/**
  Clear Screen to the initial state.
**/
VOID
EFIAPI 
ClearDisplayPage (
  VOID
  )
{
  gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
  gST->ConOut->ClearScreen (gST->ConOut);
  gLibIsFirstForm = TRUE;
}
Ejemplo n.º 5
0
static int
efi_text_cons_clear(struct vis_consclear *ca)
{
	EFI_STATUS st;
	UINTN attr = conout->Mode->Attribute & 0x0F;

	attr = EFI_TEXT_ATTR(attr,
	    solaris_color_to_efi_color[ca->bg_color & 0xF]);
	st = conout->SetAttribute(conout, attr);
	if (EFI_ERROR(st))
		return (1);
	st = conout->ClearScreen(conout);
	if (EFI_ERROR(st))
		return (1);
	return (0);
}
Ejemplo n.º 6
0
EFI_STATUS
EFIAPI
TextOutReset (
  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,
  IN BOOLEAN                          ExtendedVerification
  )
{
  EFI_STATUS            Status;

  This->SetAttribute(
        This,
        EFI_TEXT_ATTR(This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK)
        );

  Status = This->SetMode (This, 0);

  return Status;
}
Ejemplo n.º 7
0
static int
efi_cons_init(struct console *cp, int arg __unused)
{
	struct efi_console_data *ecd;
	void *coninex;
	EFI_STATUS status;
	int rc;

	conout->SetAttribute(conout, EFI_TEXT_ATTR(DEFAULT_FGCOLOR,
	    DEFAULT_BGCOLOR));
	memset(keybuf, 0, KEYBUFSZ);

	ecd = cp->c_private;
	coninex = NULL;
	/*
	 * Try to set up for SimpleTextInputEx protocol. If not available,
	 * we will use SimpleTextInput protocol.
	 */
	status = BS->OpenProtocol(ST->ConsoleInHandle, &simple_input_ex_guid,
	    &coninex, IH, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
	if (status == EFI_SUCCESS)
		ecd->ecd_coninex = coninex;

	gfx_framework_init(&fb_ops);
	rc = tem_info_init(cp);

	if (rc == 0 && tem == NULL) {
		tem = tem_init();
		if (tem != NULL)
			tem_activate(tem, B_TRUE);
	}

	if (tem == NULL)
		panic("Failed to set up console terminal");

	return (0);
}
Ejemplo n.º 8
0
    HiiConfigRoutingExportConfig,
    HiiConfigRoutingRouteConfig, 
    HiiBlockToConfig,
    HiiConfigToBlock,
    HiiGetAltCfg
  },      
  {
    (struct _EFI_LIST_ENTRY *) NULL,
    (struct _EFI_LIST_ENTRY *) NULL
  },
  0,
  {
    (struct _EFI_LIST_ENTRY *) NULL,
    (struct _EFI_LIST_ENTRY *) NULL
  },
  EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK),
  {
    0x00000000,
    0x0000,
    0x0000,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  },
  NULL
};

STATIC
VOID
EFIAPI
KeyboardLayoutChangeNullEvent (
  IN EFI_EVENT                Event,
  IN VOID                     *Context
Ejemplo n.º 9
0
/**
  This funtion defines Page Frame and Backgroud. 
  
  Based on the above layout, it will be responsible for HeaderHeight, FooterHeight, 
  StatusBarHeight and Backgroud. And, it will reserve Screen for Statement. 

  @param[in]  FormData             Form Data to be shown in Page.
  @param[out] ScreenForStatement   Screen to be used for Statement. (Prompt, Value and Help)
  
  @return Status
**/
EFI_STATUS
EFIAPI
DisplayPageFrame (
  IN FORM_DISPLAY_ENGINE_FORM       *FormData,
  OUT EFI_SCREEN_DESCRIPTOR         *ScreenForStatement
  )
{
  EFI_STATUS             Status;

  ASSERT (FormData != NULL && ScreenForStatement != NULL);
  if (FormData == NULL || ScreenForStatement == NULL) {
    return EFI_INVALID_PARAMETER;
  }

  Status = ScreenDiemensionInfoValidate (FormData);
  if (EFI_ERROR (Status)) {
    return Status;
  }

  gClassOfVfr = FORMSET_CLASS_PLATFORM_SETUP;

  ProcessExternedOpcode(FormData);

  //
  // Calculate the ScreenForStatement.
  //
  ScreenForStatement->BottomRow   = gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight;
  if (gClassOfVfr == FORMSET_CLASS_FRONT_PAGE) {
    ScreenForStatement->TopRow    = gScreenDimensions.TopRow + FRONT_PAGE_HEADER_HEIGHT;
  } else {
    ScreenForStatement->TopRow    = gScreenDimensions.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT;
  }
  ScreenForStatement->LeftColumn  = gScreenDimensions.LeftColumn;
  ScreenForStatement->RightColumn = gScreenDimensions.RightColumn;

  if ((gLibIsFirstForm) || ((FormData->Attribute & HII_DISPLAY_MODAL) != 0)) {
    //
    // Ensure we are in Text mode
    //
    gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
    ClearLines (0, gScreenDimensions.RightColumn, 0, gScreenDimensions.BottomRow, KEYHELP_BACKGROUND);
    gLibIsFirstForm = FALSE;
  }

  //
  // Don't print frame for modal form.
  //
  if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
    return EFI_SUCCESS;
  }

  if (gClassOfVfr == FORMSET_CLASS_FRONT_PAGE) {
    PrintBannerInfo (FormData);
  }

  PrintFramework (FormData);

  UpdateStatusBar(NV_UPDATE_REQUIRED, FormData->SettingChangedFlag);

  return EFI_SUCCESS;
}
Ejemplo n.º 10
0
/**
  This call back function is registered with Boot Manager formset.
  When user selects a boot option, this call back function will
  be triggered. The boot option is saved for later processing.


  @param This            Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
  @param Action          Specifies the type of action taken by the browser.
  @param QuestionId      A unique value which is sent to the original exporting driver
                         so that it can identify the type of data to expect.
  @param Type            The type of value for the question.
  @param Value           A pointer to the data being sent to the original exporting driver.
  @param ActionRequest   On return, points to the action requested by the callback function.

  @retval  EFI_SUCCESS           The callback successfully handled the action.
  @retval  EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.

**/
EFI_STATUS
EFIAPI
BootManagerCallback (
  IN  CONST EFI_HII_CONFIG_ACCESS_PROTOCOL   *This,
  IN  EFI_BROWSER_ACTION                     Action,
  IN  EFI_QUESTION_ID                        QuestionId,
  IN  UINT8                                  Type,
  IN  EFI_IFR_TYPE_VALUE                     *Value,
  OUT EFI_BROWSER_ACTION_REQUEST             *ActionRequest
  )
{
  EFI_BOOT_MANAGER_LOAD_OPTION *BootOption;
  UINTN                        BootOptionCount;
  EFI_INPUT_KEY                Key;

  if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {
    //
    //Means enter the boot manager form.
    //Update the boot manage page,because the boot option may changed.
    //
    if (QuestionId == 0x1212){
      UpdateBootManager();
    }
    return EFI_SUCCESS;
  }

  if (Action != EFI_BROWSER_ACTION_CHANGED) {
    //
    // Do nothing for other UEFI Action. Only do call back when data is changed.
    //
    return EFI_UNSUPPORTED;
  }

  if ((Value == NULL) || (ActionRequest == NULL)) {
    return EFI_INVALID_PARAMETER;
  }

  BootOption = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);

  //
  // Clear  the  screen  before.
  //
  gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
  gST->ConOut->ClearScreen (gST->ConOut);

  //
  // parse the selected option
  //
  BmBdsSetConsoleMode (FALSE);
  EfiBootManagerBoot (&BootOption[QuestionId - 1]);
  BmBdsSetConsoleMode (TRUE);

  if (EFI_ERROR (BootOption[QuestionId - 1].Status)) {
    gST->ConOut->OutputString (
                  gST->ConOut,
                  HiiGetString (gBootManagerPrivate.HiiHandle, STRING_TOKEN (STR_ANY_KEY_CONTINUE), NULL)
                  );
    gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
  }

  EfiBootManagerFreeLoadOptions (BootOption, BootOptionCount);

  return EFI_SUCCESS;
}
Ejemplo n.º 11
0
static int
efi_cons_init(int arg)
{
	conout->SetAttribute(conout, EFI_TEXT_ATTR(EFI_LIGHTGRAY, EFI_BLACK));
	return 0;
}
Ejemplo n.º 12
0
/**
  Get string or password input from user.

  @param  MenuOption        Pointer to the current input menu.
  @param  Prompt            The prompt string shown on popup window.
  @param  StringPtr         Old user input and destination for use input string.

  @retval EFI_SUCCESS       If string input is read successfully
  @retval EFI_DEVICE_ERROR  If operation fails

**/
EFI_STATUS
ReadString (
    IN     UI_MENU_OPTION              *MenuOption,
    IN     CHAR16                      *Prompt,
    IN OUT CHAR16                      *StringPtr
)
{
    EFI_STATUS              Status;
    EFI_INPUT_KEY           Key;
    CHAR16                  NullCharacter;
    UINTN                   ScreenSize;
    CHAR16                  Space[2];
    CHAR16                  KeyPad[2];
    CHAR16                  *TempString;
    CHAR16                  *BufferedString;
    UINTN                   Index;
    UINTN                   Index2;
    UINTN                   Count;
    UINTN                   Start;
    UINTN                   Top;
    UINTN                   DimensionsWidth;
    UINTN                   DimensionsHeight;
    UINTN                   CurrentCursor;
    BOOLEAN                 CursorVisible;
    UINTN                   Minimum;
    UINTN                   Maximum;
    FORM_BROWSER_STATEMENT  *Question;
    BOOLEAN                 IsPassword;

    DimensionsWidth  = gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn;
    DimensionsHeight = gScreenDimensions.BottomRow - gScreenDimensions.TopRow;

    NullCharacter    = CHAR_NULL;
    ScreenSize       = GetStringWidth (Prompt) / sizeof (CHAR16);
    Space[0]         = L' ';
    Space[1]         = CHAR_NULL;

    Question         = MenuOption->ThisTag;
    Minimum          = (UINTN) Question->Minimum;
    Maximum          = (UINTN) Question->Maximum;

    if (Question->Operand == EFI_IFR_PASSWORD_OP) {
        IsPassword = TRUE;
    } else {
        IsPassword = FALSE;
    }

    TempString = AllocateZeroPool ((Maximum + 1)* sizeof (CHAR16));
    ASSERT (TempString);

    if (ScreenSize < (Maximum + 1)) {
        ScreenSize = Maximum + 1;
    }

    if ((ScreenSize + 2) > DimensionsWidth) {
        ScreenSize = DimensionsWidth - 2;
    }

    BufferedString = AllocateZeroPool (ScreenSize * 2);
    ASSERT (BufferedString);

    Start = (DimensionsWidth - ScreenSize - 2) / 2 + gScreenDimensions.LeftColumn + 1;
    Top   = ((DimensionsHeight - 6) / 2) + gScreenDimensions.TopRow - 1;

    //
    // Display prompt for string
    //
    CreateMultiStringPopUp (ScreenSize, 4, &NullCharacter, Prompt, Space, &NullCharacter);

    gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_BLACK, EFI_LIGHTGRAY));

    CursorVisible = gST->ConOut->Mode->CursorVisible;
    gST->ConOut->EnableCursor (gST->ConOut, TRUE);

    CurrentCursor = GetStringWidth (StringPtr) / 2 - 1;
    if (CurrentCursor != 0) {
        //
        // Show the string which has beed saved before.
        //
        SetUnicodeMem (BufferedString, ScreenSize - 1, L' ');
        PrintStringAt (Start + 1, Top + 3, BufferedString);

        if ((GetStringWidth (StringPtr) / 2) > (DimensionsWidth - 2)) {
            Index = (GetStringWidth (StringPtr) / 2) - DimensionsWidth + 2;
        } else {
            Index = 0;
        }

        if (IsPassword) {
            gST->ConOut->SetCursorPosition (gST->ConOut, Start + 1, Top + 3);
        }

        for (Count = 0; Index + 1 < GetStringWidth (StringPtr) / 2; Index++, Count++) {
            BufferedString[Count] = StringPtr[Index];

            if (IsPassword) {
                PrintChar (L'*');
            }
        }

        if (!IsPassword) {
            PrintStringAt (Start + 1, Top + 3, BufferedString);
        }

        gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
        gST->ConOut->SetCursorPosition (gST->ConOut, Start + GetStringWidth (StringPtr) / 2, Top + 3);
    }

    do {
        Status = WaitForKeyStroke (&Key);
        ASSERT_EFI_ERROR (Status);

        gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_BLACK, EFI_LIGHTGRAY));
        switch (Key.UnicodeChar) {
        case CHAR_NULL:
            switch (Key.ScanCode) {
            case SCAN_LEFT:
                if (CurrentCursor > 0) {
                    CurrentCursor--;
                }
                break;

            case SCAN_RIGHT:
                if (CurrentCursor < (GetStringWidth (StringPtr) / 2 - 1)) {
                    CurrentCursor++;
                }
                break;

            case SCAN_ESC:
                FreePool (TempString);
                FreePool (BufferedString);
                gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
                gST->ConOut->EnableCursor (gST->ConOut, CursorVisible);
                return EFI_DEVICE_ERROR;

            default:
                break;
            }

            break;

        case CHAR_CARRIAGE_RETURN:
            if (GetStringWidth (StringPtr) >= ((Minimum + 1) * sizeof (CHAR16))) {

                FreePool (TempString);
                FreePool (BufferedString);
                gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
                gST->ConOut->EnableCursor (gST->ConOut, CursorVisible);
                return EFI_SUCCESS;
            } else {
                //
                // Simply create a popup to tell the user that they had typed in too few characters.
                // To save code space, we can then treat this as an error and return back to the menu.
                //
                do {
                    CreateDialog (4, TRUE, 0, NULL, &Key, &NullCharacter, gMiniString, gPressEnter, &NullCharacter);
                } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);

                FreePool (TempString);
                FreePool (BufferedString);
                gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
                gST->ConOut->EnableCursor (gST->ConOut, CursorVisible);
                return EFI_DEVICE_ERROR;
            }

            break;

        case CHAR_BACKSPACE:
            if (StringPtr[0] != CHAR_NULL && CurrentCursor != 0) {
                for (Index = 0; Index < CurrentCursor - 1; Index++) {
                    TempString[Index] = StringPtr[Index];
                }
                Count = GetStringWidth (StringPtr) / 2 - 1;
                if (Count >= CurrentCursor) {
                    for (Index = CurrentCursor - 1, Index2 = CurrentCursor; Index2 < Count; Index++, Index2++) {
                        TempString[Index] = StringPtr[Index2];
                    }
                    TempString[Index] = CHAR_NULL;
                }
                //
                // Effectively truncate string by 1 character
                //
                StrCpy (StringPtr, TempString);
                CurrentCursor --;
            }

        default:
            //
            // If it is the beginning of the string, don't worry about checking maximum limits
            //
            if ((StringPtr[0] == CHAR_NULL) && (Key.UnicodeChar != CHAR_BACKSPACE)) {
                StrnCpy (StringPtr, &Key.UnicodeChar, 1);
                CurrentCursor++;
            } else if ((GetStringWidth (StringPtr) < ((Maximum + 1) * sizeof (CHAR16))) && (Key.UnicodeChar != CHAR_BACKSPACE)) {
                KeyPad[0] = Key.UnicodeChar;
                KeyPad[1] = CHAR_NULL;
                Count = GetStringWidth (StringPtr) / 2 - 1;
                if (CurrentCursor < Count) {
                    for (Index = 0; Index < CurrentCursor; Index++) {
                        TempString[Index] = StringPtr[Index];
                    }
                    TempString[Index] = CHAR_NULL;
                    StrCat (TempString, KeyPad);
                    StrCat (TempString, StringPtr + CurrentCursor);
                    StrCpy (StringPtr, TempString);
                } else {
                    StrCat (StringPtr, KeyPad);
                }
                CurrentCursor++;
            }

            //
            // If the width of the input string is now larger than the screen, we nee to
            // adjust the index to start printing portions of the string
            //
            SetUnicodeMem (BufferedString, ScreenSize - 1, L' ');
            PrintStringAt (Start + 1, Top + 3, BufferedString);

            if ((GetStringWidth (StringPtr) / 2) > (DimensionsWidth - 2)) {
                Index = (GetStringWidth (StringPtr) / 2) - DimensionsWidth + 2;
            } else {
                Index = 0;
            }

            if (IsPassword) {
                gST->ConOut->SetCursorPosition (gST->ConOut, Start + 1, Top + 3);
            }

            for (Count = 0; Index + 1 < GetStringWidth (StringPtr) / 2; Index++, Count++) {
                BufferedString[Count] = StringPtr[Index];

                if (IsPassword) {
                    PrintChar (L'*');
                }
            }

            if (!IsPassword) {
                PrintStringAt (Start + 1, Top + 3, BufferedString);
            }
            break;
        }

        gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
        gST->ConOut->SetCursorPosition (gST->ConOut, Start + CurrentCursor + 1, Top + 3);
    } while (TRUE);

}
Ejemplo n.º 13
0
#define BRIGHT_CONTROL_OFFSET     2
#define FOREGROUND_CONTROL_OFFSET 6
#define BACKGROUND_CONTROL_OFFSET 11
#define ROW_OFFSET                2
#define COLUMN_OFFSET             5

efi_char16_t mSetModeString[]            = { ESC, '[', '=', '3', 'h', 0 };
efi_char16_t mSetAttributeString[]       = { ESC, '[', '0', 'm', ESC, '[', '4', '0', 'm', ESC, '[', '4', '0', 'm', 0 };
efi_char16_t mClearScreenString[]        = { ESC, '[', '2', 'J', 0 };
efi_char16_t mSetCursorPositionString[]  = { ESC, '[', '0', '0', ';', '0', '0', 'H', 0 };
static bool output_escape_char = false;

static efi_simple_text_output_mode_t efi_simpletext_out_mode = {
  .max_mode = 1,
  .mode = 0,
  .attribute = EFI_TEXT_ATTR(EFI_LIGHTGRAY, EFI_BLACK),
  .cursor_column = 0,
  .cursor_row = 0,
  .cursor_visible = true
};

static bool TextOutIsValidAscii(efi_char16_t c) {
	//
	// valid ASCII code lies in the extent of 0x20 - 0x7F
	//
	if ((c >= 0x20) && (c <= 0x7F))
		return true;

	return false;
}
Ejemplo n.º 14
0
/**
  Select the boot menu by user's input.

  @param[in]  Private         Pointer to PxeBc private data.
  @param[out] Type            The type of the menu.
  @param[in]  UseDefaultItem  Use default item or not.

  @retval EFI_ABORTED     User cancel operation.
  @retval EFI_SUCCESS     Select the boot menu success.
  @retval EFI_NOT_READY   Read the input key from the keybroad has not finish.

**/
EFI_STATUS
PxeBcSelectBootMenu (
  IN  PXEBC_PRIVATE_DATA              *Private,
  OUT UINT16                          *Type,
  IN  BOOLEAN                         UseDefaultItem
  )
{
  EFI_PXE_BASE_CODE_MODE     *Mode;
  PXEBC_DHCP_PACKET_CACHE    *Cache;
  PXEBC_VENDOR_OPTION        *VendorOpt;
  EFI_INPUT_KEY              InputKey;
  UINT32                     OfferType;
  UINT8                      MenuSize;
  UINT8                      MenuNum;
  INT32                      TopRow;
  UINT16                     Select;
  UINT16                     LastSelect;
  UINT8                      Index;
  BOOLEAN                    Finish;
  CHAR8                      Blank[PXEBC_DISPLAY_MAX_LINE];
  PXEBC_BOOT_MENU_ENTRY      *MenuItem;
  PXEBC_BOOT_MENU_ENTRY      *MenuArray[PXEBC_MENU_MAX_NUM];

  Finish    = FALSE;
  Select    = 0;
  Index     = 0;
  *Type     = 0;
  Mode      = Private->PxeBc.Mode;
  Cache     = Mode->ProxyOfferReceived ? &Private->ProxyOffer : &Private->DhcpAck;
  OfferType = Mode->UsingIpv6 ? Cache->Dhcp6.OfferType : Cache->Dhcp4.OfferType;

  //
  // There is no specified DhcpPxe10/ProxyPxe10 for IPv6 in PXE and UEFI spec.
  //
  ASSERT (!Mode->UsingIpv6);
  ASSERT (OfferType == PxeOfferTypeProxyPxe10 || OfferType == PxeOfferTypeDhcpPxe10);

  VendorOpt = &Cache->Dhcp4.VendorOpt;
  if (!IS_VALID_BOOT_MENU (VendorOpt->BitMap)) {
    return EFI_SUCCESS;
  }

  //
  // Display the boot menu on the screen.
  //
  SetMem (Blank, sizeof(Blank), ' ');

  MenuSize  = VendorOpt->BootMenuLen;
  MenuItem  = VendorOpt->BootMenu;

  if (MenuSize == 0) {
    return EFI_DEVICE_ERROR;
  }

  while (MenuSize > 0 && Index < PXEBC_MENU_MAX_NUM) {
    ASSERT (MenuItem != NULL);
    MenuArray[Index]  = MenuItem;
    MenuSize          = (UINT8) (MenuSize - (MenuItem->DescLen + 3));
    MenuItem          = (PXEBC_BOOT_MENU_ENTRY *) ((UINT8 *) MenuItem + MenuItem->DescLen + 3);
    Index++;
  }

  if (UseDefaultItem) {
    ASSERT (MenuArray[0] != NULL);
    CopyMem (Type, &MenuArray[0]->Type, sizeof (UINT16));
    *Type = NTOHS (*Type);
    return EFI_SUCCESS;
  }

  MenuNum = Index;

  for (Index = 0; Index < MenuNum; Index++) {
    ASSERT (MenuArray[Index] != NULL);
    PxeBcDisplayBootItem (MenuArray[Index]->DescStr, MenuArray[Index]->DescLen);
  }

  TopRow = gST->ConOut->Mode->CursorRow - MenuNum;

  //
  // Select the boot item by user in the boot menu.
  //
  do {
    //
    // Highlight selected row.
    //
    gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_BLACK, EFI_LIGHTGRAY));
    gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + Select);
    ASSERT (Select < PXEBC_MENU_MAX_NUM);
    ASSERT (MenuArray[Select] != NULL);
    Blank[MenuArray[Select]->DescLen] = 0;
    AsciiPrint ("%a\r", Blank);
    PxeBcDisplayBootItem (MenuArray[Select]->DescStr, MenuArray[Select]->DescLen);
    gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + MenuNum);
    LastSelect = Select;

    while (gST->ConIn->ReadKeyStroke (gST->ConIn, &InputKey) == EFI_NOT_READY) {
      gBS->Stall (10 * TICKS_PER_MS);
    }

    if (InputKey.ScanCode == 0) {
      switch (InputKey.UnicodeChar) {
      case CTRL ('c'):
        InputKey.ScanCode = SCAN_ESC;
        break;

      case CTRL ('j'):  /* linefeed */
      case CTRL ('m'):  /* return */
        Finish = TRUE;
        break;

      case CTRL ('i'):  /* tab */
      case ' ':
      case 'd':
      case 'D':
        InputKey.ScanCode = SCAN_DOWN;
        break;

      case CTRL ('h'):  /* backspace */
      case 'u':
      case 'U':
        InputKey.ScanCode = SCAN_UP;
        break;

      default:
        InputKey.ScanCode = 0;
      }
    }

    switch (InputKey.ScanCode) {
    case SCAN_LEFT:
    case SCAN_UP:
      if (Select != 0) {
        Select--;
      }
      break;

    case SCAN_DOWN:
    case SCAN_RIGHT:
      if (++Select == MenuNum) {
        Select--;
      }
      break;

    case SCAN_PAGE_UP:
    case SCAN_HOME:
      Select = 0;
      break;

    case SCAN_PAGE_DOWN:
    case SCAN_END:
      Select = (UINT16) (MenuNum - 1);
      break;

    case SCAN_ESC:
      return EFI_ABORTED;
    }

    //
    // Unhighlight the last selected row.
    //
    gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
    gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + LastSelect);
    ASSERT (LastSelect < PXEBC_MENU_MAX_NUM);
    ASSERT (MenuArray[LastSelect] != NULL);
    Blank[MenuArray[LastSelect]->DescLen] = 0;
    AsciiPrint ("%a\r", Blank);
    PxeBcDisplayBootItem (MenuArray[LastSelect]->DescStr, MenuArray[LastSelect]->DescLen);
    gST->ConOut->SetCursorPosition (gST->ConOut, 0, TopRow + MenuNum);
  } while (!Finish);

  //
  // Swap the byte order.
  //
  ASSERT (Select < PXEBC_MENU_MAX_NUM);
  ASSERT (MenuArray[Select] != NULL);
  CopyMem (Type, &MenuArray[Select]->Type, sizeof (UINT16));
  *Type = NTOHS (*Type);

  return EFI_SUCCESS;
}
Ejemplo n.º 15
0
/**
  This call back function is registered with Boot Manager formset.
  When user selects a boot option, this call back function will
  be triggered. The boot option is saved for later processing.


  @param This            Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
  @param Action          Specifies the type of action taken by the browser.
  @param QuestionId      A unique value which is sent to the original exporting driver
                         so that it can identify the type of data to expect.
  @param Type            The type of value for the question.
  @param Value           A pointer to the data being sent to the original exporting driver.
  @param ActionRequest   On return, points to the action requested by the callback function.

  @retval  EFI_SUCCESS           The callback successfully handled the action.
  @retval  EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.

**/
EFI_STATUS
EFIAPI
BootManagerCallback (
  IN  CONST EFI_HII_CONFIG_ACCESS_PROTOCOL   *This,
  IN  EFI_BROWSER_ACTION                     Action,
  IN  EFI_QUESTION_ID                        QuestionId,
  IN  UINT8                                  Type,
  IN  EFI_IFR_TYPE_VALUE                     *Value,
  OUT EFI_BROWSER_ACTION_REQUEST             *ActionRequest
  )
{
  UINTN                         Index;
  EFI_BOOT_MANAGER_LOAD_OPTION  *BootOption;
  UINTN                         BootOptionCount;
  UINT16                        KeyCount;
  EFI_INPUT_KEY                 Key;
  EFI_BOOT_MANAGER_LOAD_OPTION  Option;

  if (Action != EFI_BROWSER_ACTION_CHANGED) {
    //
    // Do nothing for other UEFI Action. Only do call back when data is changed.
    //
    return EFI_UNSUPPORTED;
  }

  if ((Value == NULL) || (ActionRequest == NULL)) {
    return EFI_INVALID_PARAMETER;
  }

  //
  // Initialize the key count
  //
  KeyCount = 0;
  Option.Attributes = 0;
  BootOption = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);

  for (Index = 0; Index < BootOptionCount; Index++) {
    KeyCount++;

    EfiBootManagerInitializeLoadOption (
      &Option,
      BootOption[Index].OptionNumber,
      BootOption[Index].OptionType,
      BootOption[Index].Attributes,
      BootOption[Index].Description,
      BootOption[Index].FilePath,
      BootOption[Index].OptionalData,
      BootOption[Index].OptionalDataSize
      );

    //
    // Is this device the one chosen?
    //
    if (KeyCount == QuestionId) {
      //
      // Clear  the  screen  before.
      //
      gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
      gST->ConOut->ClearScreen (gST->ConOut);
      //
      // Check any reset required change is applied? if yes, reset system
      //
      SetupResetReminder();
      //
      // Parse the selected option.
      //
      BdsSetConsoleMode(FALSE);
      EfiBootManagerBoot (&Option);
      BdsSetConsoleMode(TRUE);

      if (EFI_ERROR (Option.Status)) {
        gST->ConOut->OutputString (
                      gST->ConOut,
                      GetStringById (STRING_TOKEN (STR_ANY_KEY_CONTINUE))
                      );
        gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
      }
      break;
    }
  }
  EfiBootManagerFreeLoadOptions (BootOption, BootOptionCount);

  return EFI_SUCCESS;
}
Ejemplo n.º 16
0
EFI_STATUS
DialogRefresh (
  IN EFI_DIALOG                     *Dialog,
  IN EFI_DIALOG_CONTEXT             *Context,
  IN BOOLEAN                        RefreshAll
  )
/*++

Routine Description:

  refresh the Dialog.

Arguments:

  FileDialog  - The EFI_FILE_DIALOG instance pointer.

Returns:

  EFI_SUCCESS           - the FileDialog was rendered successfully.
  EFI_INVALID_PARAMETER - the Parameter is Invalid

--*/
{
  UINTN                                  Index;
  UINTN                                  SubIndex;
  CHAR16                                 Buffer[EFI_MAX_LINE_LENGTH +1 ];
  UINTN                                  X0;
  UINTN                                  Y0;
  UINTN                                  X1;
  UINTN                                  Y1;

  EFI_STATUS                             Status;


  if (Dialog == NULL) {
    return EFI_INVALID_PARAMETER;
  }

  if (Context == NULL) {
    return EFI_INVALID_PARAMETER;
  }

  X0 = Dialog->BodyRect.TopLeft.Col;
  Y0 = Dialog->BodyRect.TopLeft.Row;
  X1 = Dialog->BodyRect.BottomRight.Col;
  Y1 = Dialog->BodyRect.BottomRight.Row;

  if ((X1 < X0 + 15) || (Y1 < Y0 + 5)) {
    return EFI_INVALID_PARAMETER;
  }

  Status = EFI_SUCCESS;
  ST->ConOut->EnableCursor (
                ST->ConOut,
                FALSE
                );
  ST->ConOut->SetAttribute (
                ST->ConOut,
                EFI_TEXT_ATTR(Dialog->ForeColor,
                Dialog->BackColor)
                );

  if (RefreshAll) {

    for (Index = 0; Index < X1 - X0 + 1; Index++) {
      Buffer[Index] = L' ';
    }
    Buffer[Index] = L'\0';
    //
    //clear the Dialog Rect Area.
    //
    for (SubIndex = Y0; SubIndex <= Y1; SubIndex++) {
      Status = TestPrintAt (X0, SubIndex, Buffer);
      if (EFI_ERROR(Status)) {
        return Status;
      }
    }
    //
    //display the title
    //
    if (Dialog->Title != NULL) {
      Status = DisplayMessage(X0 + 4, Y0 + 1, X1 - 3, Y1 - 4, Dialog->Title);
    }
    if (EFI_ERROR (Status)) {
      return Status;
    }
    //
    // than we draw the four corner.
    //
    Buffer[1] = L'\0';
    Buffer[0] = BOXDRAW_DOWN_RIGHT;
    Status = TestPrintAt (X0, Y0, Buffer);
    if (EFI_ERROR (Status)) {
      return Status;
    }
    Buffer[0] = BOXDRAW_UP_RIGHT;
    Status = TestPrintAt (X0, Y1, Buffer);
    if (EFI_ERROR (Status)) {
      return Status;
    }
    Buffer[0] = BOXDRAW_DOWN_LEFT;
    Status = TestPrintAt (X1, Y0, Buffer);
    if (EFI_ERROR (Status)) {
      return Status;
    }
    Buffer[0] = BOXDRAW_UP_LEFT;
    Status = TestPrintAt (X1, Y1, Buffer);
    if (EFI_ERROR (Status) ) {
      return Status;
    }

    //
    //draw  left-right line.
    //
    for (Index = 0; Index < X1 - X0 - 1; Index++) {
      Buffer[Index] = BOXDRAW_HORIZONTAL;
    }
    Buffer[Index] = L'\0';

    Status = TestPrintAt (X0 + 1, Y0, Buffer);
    if (EFI_ERROR (Status)) {
      return Status;
    }
    Status = TestPrintAt (X0 + 1 , Y1, Buffer);
    if (EFI_ERROR (Status)) {
      return Status;
    }
    //
    //draw  up-down line.
    //

    Buffer[0] = BOXDRAW_VERTICAL;
    Buffer[1] = L'\0';
    for (Index= Y0 + 1; Index < Y1; Index++) {
      Status = TestPrintAt (X0, Index, Buffer);
      if (EFI_ERROR (Status) ) {
        return Status;
      }
      Status = TestPrintAt (X1, Index, Buffer);
      if (EFI_ERROR (Status) ) {
        return Status;
      }
    }

    if (Context->Type == EFI_DIALOG_TYPE_MESSAGE) {
      StrCpy (Buffer, L"[ OK ]");
      Status = TestPrintAt (X0 + (X1 - X0) / 2 - 2 , Y1 - 2, Buffer);
    }

    if (Context->Type == EFI_DIALOG_TYPE_YES_OR_NO) {
      if (Context -> ChooseNumber == 1) {
        StrCpy (Buffer, L"[ No ]");
        Status = TestPrintAt (X0 + (X1 - X0) / 4 * 3 - 4, Y1 - 2, Buffer);
        if (EFI_ERROR (Status)) {
          return Status;
        }
        ST->ConOut->SetAttribute (
            ST->ConOut,
            EFI_TEXT_ATTR(EFI_YELLOW,
            Dialog->BackColor)
            );
        StrCpy (Buffer, L"[ Yes ]");
        Status = TestPrintAt (X0+ (X1 - X0) / 4 - 2, Y1 - 2, Buffer);
        if (EFI_ERROR (Status)) {
          return Status;
        }
        ST->ConOut->SetAttribute (
            ST->ConOut,
            EFI_TEXT_ATTR(Dialog->ForeColor,
            Dialog->BackColor)
            );
      } else {
        StrCpy (Buffer, L"[ Yes ]");
        Status = TestPrintAt (X0 + (X1 - X0) / 4 - 2, Y1 - 2, Buffer);
        if (EFI_ERROR (Status)) {
          return Status;
        }
        ST->ConOut->SetAttribute (
            ST->ConOut,
            EFI_TEXT_ATTR(EFI_YELLOW,
            Dialog->BackColor)
            );

        StrCpy (Buffer, L"[ No ]");
        Status = TestPrintAt (X0 + (X1 - X0) / 4 * 3 - 4, Y1 - 2, Buffer);
        if (EFI_ERROR (Status)) {
          return Status;
        }
        ST->ConOut->SetAttribute (
            ST->ConOut,
            EFI_TEXT_ATTR(Dialog->ForeColor,
            Dialog->BackColor)
            );
      }
    }

  } else {
    ST->ConOut->SetAttribute (
          ST->ConOut,
          EFI_TEXT_ATTR(Dialog->ForeColor,
          Dialog->BackColor)
          );
    if (Context -> ChooseNumber == 1) {
      StrCpy (Buffer, L"[ No ]");
      Status = TestPrintAt (X0 + (X1 - X0) / 4 * 3 - 4, Y1 - 2, Buffer);
      if (EFI_ERROR (Status)) {
        return Status;
      }
      ST->ConOut->SetAttribute (
          ST->ConOut,
          EFI_TEXT_ATTR(EFI_YELLOW,
          Dialog->BackColor)
          );
      StrCpy (Buffer, L"[ Yes ]");
      Status = TestPrintAt (X0 + (X1 - X0) / 4 - 2 , Y1 - 2, Buffer);
      if (EFI_ERROR (Status)) {
        return Status;
      }
      ST->ConOut->SetAttribute (
          ST->ConOut,
          EFI_TEXT_ATTR(Dialog->ForeColor,
          Dialog->BackColor)
          );
    } else {
      StrCpy (Buffer, L"[ Yes ]");
      Status = TestPrintAt (X0 + (X1 - X0) / 4 - 2, Y1 - 2, Buffer);

      if (EFI_ERROR (Status)) {
        return Status;
      }
      ST->ConOut->SetAttribute (
          ST->ConOut,
          EFI_TEXT_ATTR(EFI_YELLOW,
          Dialog->BackColor)
          );
      StrCpy (Buffer, L"[ No ]");
      Status = TestPrintAt (X0 + (X1 - X0) / 4 * 3 - 4, Y1 - 2, Buffer);
      if (EFI_ERROR (Status)) {
        return Status;
      }
      ST->ConOut->SetAttribute (
          ST->ConOut,
          EFI_TEXT_ATTR(Dialog->ForeColor,
          Dialog->BackColor)
          );
    }
  }

  return Status;
}
Ejemplo n.º 17
0
UINTN
ErrorPrint (
  IN CONST CHAR16 *ErrorString,
  IN CONST CHAR8  *Format,
  ...
  )
/*++

Routine Description:

  Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii 
  characters.

Arguments:

  ErrorString - String of error infomation.

  Format      - Ascii format string see file header for more details.

  ...         - Vararg list consumed by processing Format.

Returns: 

  Number of characters printed.

--*/
{
  UINTN   Return;
  VA_LIST Marker;
  UINTN   Index;
  UINTN   MaxIndex;
  CHAR16  Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];
  CHAR16  UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];

  MaxIndex = EfiAsciiStrLen ((CHAR8 *) Format);
  if (MaxIndex >= EFI_DRIVER_LIB_MAX_PRINT_BUFFER) {
    //
    // Format string was too long for use to process.
    //
    return 0;
  }

  if (ErrorString != '\0') {
    if (gST->StdErr != NULL) {
      //
      // To be extra safe make sure StdErr has been initialized
      //
      gST->StdErr->SetAttribute (gST->StdErr, EFI_TEXT_ATTR (EFI_RED, EFI_BLACK));
      gST->StdErr->OutputString (gST->StdErr, (CHAR16 *) ErrorString);
      gST->StdErr->SetAttribute (gST->StdErr, EFI_TEXT_ATTR (EFI_WHITE, EFI_BLACK));
    }
  }

  for (Index = 0; Index < MaxIndex; Index++) {
    UnicodeFormat[Index] = (CHAR16) Format[Index];
  }

  UnicodeFormat[Index] = 0;

  VA_START (Marker, Format);
  Return = VSPrint (Buffer, sizeof (Buffer), UnicodeFormat, Marker);
  VA_END (Marker);

  //
  // Need to convert to Unicode to do an OutputString
  //

  if (gST->StdErr != NULL) {
    //
    // To be extra safe make sure StdErr has been initialized
    //
    gST->StdErr->OutputString (gST->StdErr, Buffer);
  }

  return Return;
}
Ejemplo n.º 18
0
void
console_set_color(int32 foreground, int32 background)
{
	kSystemTable->ConOut->SetAttribute(kSystemTable->ConOut,
		EFI_TEXT_ATTR((foreground & 0xf), (background & 0xf)));
}