summaryrefslogblamecommitdiffstats
path: root/efi_memtest/MemtestEfi.c
blob: 82438b00265457afc9ddc276621fe75c98ddc0e9 (plain) (tree)
1
2
3
4
5
6
7
8
9


                                              
                                
                                 
 

                                            
                               
                          
 

                             

                                  
 

                                  





                                                  
   
 


          


                                     
 
 

                                                                      
 
                                      
 





                                          
 

                                      

                                               

                                                            
       
 

                                      



                                                              
       
 

                                      







                                                                
                                                                  


                                                                             
                      





                                                             
                      




                                             
       
 

                                      



                                                                
       
 

                                      



                                                                                                    
       
 

                                      
 

                                      



                                                            
       

                 
 



                                              
 
                                                                       
 
                       
 
#include "Uefi.h"
#include "Library/UefiLib.h"
#include "Library/UefiApplicationEntryPoint.h"
#include "Guid/FileSystemInfo.h"
#include "Protocol/LoadedImage.h"

#include "main.h" // TODO move into main dir
#include "memtest86+/logger.h"
#include "memtest86+/display.h"
#include "logger_config.h"

extern EFI_SYSTEM_TABLE *gST;

// TODO remove. Just for debugging
/*int global = 1;*/

// TODO remove. Just for debugging
/*void stack_check() {
    int i;
    int *p = &i;
    char log[32] = "stack ptr = ";
    int length = 12;
    int_to_charr((unsigned long) p, log, &length);
    print_log(log, length);
}*/

EFI_STATUS
EFIAPI
UefiMain (
    IN EFI_HANDLE        ImageHandle,
    IN EFI_SYSTEM_TABLE  *SystemTable
    )
{

    SystemTable->ConOut->ClearScreen(SystemTable->ConOut);
    SystemTable->ConOut->SetCursorPosition(SystemTable->ConOut, 0, 0);

    trace_init("Starting MemtestEfi");

    init_logger();
    
    if (logflag) {
        char msg[] = "MemtestEfi started";
        print_log(msg, sizeof(msg) - 1);
    }

    // TODO remove. Just for debugging
/*    if (logflag) {
        char log[41] = "Address of UefiMain: ";
        int length = 21;
        int_to_charr((unsigned long)UefiMain, log, &length);
        print_log(log, length);
    }*/

    // TODO remove. Just for debugging
/*    if (logflag) {
        char log[43] = "Address of test_start: ";
        int length = 23;
        int_to_charr((unsigned long)test_start, log, &length);
        print_log(log, length);
    }*/

    // TODO remove. Just for debugging
/*    VOID *LoadedImage;
    EFI_STATUS status = SystemTable->BootServices->OpenProtocol(
        ImageHandle,
        &gEfiLoadedImageProtocolGuid,
        &LoadedImage,
        ImageHandle,
        NULL,
        EFI_OPEN_PROTOCOL_GET_PROTOCOL);
    if (status != EFI_SUCCESS) {
        if (logflag) print_log("Failed to open LoadedImage.", 27);
    } else {
        VOID *base = ((EFI_LOADED_IMAGE_PROTOCOL *) LoadedImage)->ImageBase;
        UINT64 size = ((EFI_LOADED_IMAGE_PROTOCOL *) LoadedImage)->ImageSize;
        if (logflag) {
            char log[31] = "ImageBase: ";
            int length = 11;
            int_to_charr((unsigned long) base, log, &length);
            print_log(log, length);
        }

        if (logflag) {
            char log[31] = "ImageSize: ";
            int length = 11;
            int_to_charr(size, log, &length);
            print_log(log, length);
        }
    }*/

    // TODO remove. Just for debugging
/*    if (logflag) {
        char log[45] = "Address of SystemTable = ";
        int length = 25;
        int_to_charr((unsigned long) SystemTable, log, &length);
        print_log(log, length);
    }*/

    // TODO remove. Just for debugging
/*    if (logflag) {
        char log[45] = "Current return address = ";
        int length = 25;
        int_to_charr((unsigned long) ((unsigned long *) __builtin_return_address(0)), log, &length);
        print_log(log, length);
    }*/

    // TODO remove. Just for debugging
/*    stack_check();*/

    // TODO remove. Just for debugging
/*    if (logflag) {
        char log[49] = "Address of global variable = ";
        int length = 29;
        int_to_charr((unsigned long) &global, log, &length);
        print_log(log, length);
    }*/
  
    test_start();

    if (logflag) {
        char msg[] = "MemtestEfi finished!\n";
        print_log(msg, sizeof(msg) - 1);
    }

    SystemTable->ConOut->SetCursorPosition(SystemTable->ConOut, 0, 25);

    return EFI_SUCCESS;
}