vidmodes.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <uefi.h>
  2. /**
  3. * List or set GOP video modes
  4. */
  5. int main(int argc, char **argv)
  6. {
  7. efi_status_t status;
  8. efi_guid_t gopGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
  9. efi_gop_t *gop = NULL;
  10. efi_gop_mode_info_t *info = NULL;
  11. uintn_t isiz = sizeof(efi_gop_mode_info_t), currentMode, i;
  12. status = BS->LocateProtocol(&gopGuid, NULL, (void**)&gop);
  13. if(!EFI_ERROR(status) && gop) {
  14. /* if mode given on command line, set it */
  15. if(argc > 1) {
  16. status = gop->SetMode(gop, atoi(argv[1]));
  17. /* changing the resolution might mess up ConOut and StdErr, better to reset them */
  18. ST->ConOut->Reset(ST->ConOut, 0);
  19. ST->StdErr->Reset(ST->StdErr, 0);
  20. if(EFI_ERROR(status)) {
  21. fprintf(stderr, "unable to set video mode\n");
  22. return 0;
  23. }
  24. }
  25. /* we got the interface, get current mode */
  26. status = gop->QueryMode(gop, gop->Mode ? gop->Mode->Mode : 0, &isiz, &info);
  27. if(status == EFI_NOT_STARTED || !gop->Mode) {
  28. status = gop->SetMode(gop, 0);
  29. ST->ConOut->Reset(ST->ConOut, 0);
  30. ST->StdErr->Reset(ST->StdErr, 0);
  31. }
  32. if(EFI_ERROR(status)) {
  33. fprintf(stderr, "unable to get current video mode\n");
  34. return 0;
  35. }
  36. currentMode = gop->Mode->Mode;
  37. /* iterate on modes and print info */
  38. for(i = 0; i < gop->Mode->MaxMode; i++) {
  39. status = gop->QueryMode(gop, i, &isiz, &info);
  40. if(EFI_ERROR(status) || info->PixelFormat > PixelBitMask) continue;
  41. printf(" %c%3d. %4d x%4d (pitch %4d fmt %d r:%06x g:%06x b:%06x)\n",
  42. i == currentMode ? '*' : ' ', i,
  43. info->HorizontalResolution, info->VerticalResolution, info->PixelsPerScanLine, info->PixelFormat,
  44. info->PixelFormat==PixelRedGreenBlueReserved8BitPerColor?0xff:(
  45. info->PixelFormat==PixelBlueGreenRedReserved8BitPerColor?0xff0000:(
  46. info->PixelFormat==PixelBitMask?info->PixelInformation.RedMask:0)),
  47. info->PixelFormat==PixelRedGreenBlueReserved8BitPerColor ||
  48. info->PixelFormat==PixelBlueGreenRedReserved8BitPerColor?0xff00:(
  49. info->PixelFormat==PixelBitMask?info->PixelInformation.GreenMask:0),
  50. info->PixelFormat==PixelRedGreenBlueReserved8BitPerColor?0xff0000:(
  51. info->PixelFormat==PixelBlueGreenRedReserved8BitPerColor?0xff:(
  52. info->PixelFormat==PixelBitMask?info->PixelInformation.BlueMask:0)));
  53. }
  54. } else
  55. fprintf(stderr, "unable to get graphics output protocol\n");
  56. return 0;
  57. }