Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:09

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSBSPsX8664AMD64EFI
0007  *
0008  * @brief EFI Simple Text Output implementation
0009  */
0010 
0011 /*
0012  * Copyright (C) 2023 Karel Gardas
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #include <bsp.h>
0037 
0038 #include <efi.h>
0039 #include <efilib.h>
0040 
0041 #include <rtems/bspIo.h>
0042 
0043 #include <efistop.h>
0044 
0045 #include <stdio.h>
0046 #include <string.h>
0047 
0048 #ifdef BSP_USE_EFI_BOOT_SERVICES
0049 
0050 static void
0051 print_stop_info(SIMPLE_TEXT_OUTPUT_INTERFACE* stop);
0052 
0053 void
0054 efi_init_text_output(int hint)
0055 {
0056     int maxval = ST->ConOut->Mode->MaxMode - 1;
0057     int curval = ST->ConOut->Mode->Mode;
0058     ST->ConOut->Reset(ST->ConOut, true);
0059     if (hint != -1) {
0060         /* hint got from command-line does have highest priority */
0061         ST->ConOut->SetMode(ST->ConOut, hint);
0062     }
0063     else if (strcmp(BSP_EFI_SIMPLE_TEXT_OUTPUT_MODE_VALUE, "MAX") == 0) {
0064         ST->ConOut->SetMode(ST->ConOut, maxval);
0065     }
0066     else if (strcmp(BSP_EFI_SIMPLE_TEXT_OUTPUT_MODE_VALUE, "AUTO") == 0) {
0067         ST->ConOut->SetMode(ST->ConOut, curval);
0068     }
0069     else {
0070         ST->ConOut->SetMode(ST->ConOut, atoi(BSP_EFI_SIMPLE_TEXT_OUTPUT_MODE_VALUE));
0071     }
0072     ST->ConOut->EnableCursor(ST->ConOut, TRUE);
0073     print_stop_info(ST->ConOut);
0074     ST->ConOut->ClearScreen(ST->ConOut);
0075 }
0076 
0077 void
0078 efi_text_output_char(char c)
0079 {
0080     EFI_STATUS status;
0081     char tocpy[2];
0082     tocpy[0] = c;
0083     tocpy[1] = 0;
0084     CHAR16 str[2];
0085     cpy8to16(tocpy, str, 2);
0086     status = ST->ConOut->TestString(ST->ConOut, str);
0087     if (EFI_ERROR(status))
0088         str[0] = '?';
0089     ST->ConOut->OutputString(ST->ConOut, str);
0090 }
0091 
0092 static void
0093 print_stop_info(SIMPLE_TEXT_OUTPUT_INTERFACE* stop)
0094 {
0095     EFI_STATUS status;
0096     int max_mode = stop->Mode->MaxMode;
0097     int current_mode = stop->Mode->Mode;
0098     printf("RTEMS: text output: current mode: %d, max mode: %d\n", current_mode, (max_mode - 1));
0099     UINTN columns = 0;
0100     UINTN rows = 0;
0101     for (int i = 0; i < max_mode; i++) {
0102         if (current_mode == i)
0103             printf(" -> ");
0104         else
0105             printf("    ");
0106         status = stop->QueryMode(stop, i, &columns, &rows);
0107         if (EFI_ERROR(status))
0108             printf("%d. mode: error: can't obtain column x row values.\n", i);
0109         else {
0110             printf("%d. mode: %ld * %ld\n", i, columns, rows);
0111         }
0112     }
0113 }
0114 
0115 #endif