summaryrefslogtreecommitdiffstats
path: root/efi_memtest/MemtestEfi.c
diff options
context:
space:
mode:
Diffstat (limited to 'efi_memtest/MemtestEfi.c')
-rw-r--r--efi_memtest/MemtestEfi.c130
1 files changed, 98 insertions, 32 deletions
diff --git a/efi_memtest/MemtestEfi.c b/efi_memtest/MemtestEfi.c
index b0511a5..0d2d472 100644
--- a/efi_memtest/MemtestEfi.c
+++ b/efi_memtest/MemtestEfi.c
@@ -3,58 +3,124 @@
#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;
-short logflag = 1;
-short log_fine = 0;
-short log_memspeed = 0;
-short log_mem_tbl = 1;
-short log_comp_seg = 0;
-short log_print_pmap = 0;
+// TODO remove
+int global = 1;
+
+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
- )
+ 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");
-
+ SystemTable->ConOut->ClearScreen(SystemTable->ConOut);
+ SystemTable->ConOut->SetCursorPosition(SystemTable->ConOut, 0, 0);
- //SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Hello World!!\n");
+ trace_init("Starting MemtestEfi");
- init_logger();
-
- //while(1);
-
-
- if (logflag) {
- char msg[] = "MemtestEfi started";
- print_log(msg, sizeof(msg) - 1);
- }
+ init_logger();
+
+ if (logflag) {
+ char msg[] = "MemtestEfi started";
+ print_log(msg, sizeof(msg) - 1);
+ }
- test_start();
+ if (logflag) {
+ char log[41] = "Address of UefiMain: ";
+ int length = 21;
+ int_to_charr((unsigned long)UefiMain, log, &length);
+ print_log(log, length);
+ }
+
+ 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);
+ }
+
+ 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);
+ }
+ }
+
+ if (logflag) {
+ char log[45] = "Address of SystemTable = ";
+ int length = 25;
+ int_to_charr((unsigned long) SystemTable, log, &length);
+ print_log(log, length);
+ }
+
+ 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);
+ }
+
+ stack_check();
+
+ 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);
- }
+ if (logflag) {
+ char msg[] = "MemtestEfi finished!\n";
+ print_log(msg, sizeof(msg) - 1);
+ }
- // while(1) {}
+ //while(1) {}
- SystemTable->ConOut->SetCursorPosition(SystemTable->ConOut, 0, 25);
+ SystemTable->ConOut->SetCursorPosition(SystemTable->ConOut, 0, 25);
- return EFI_SUCCESS;
+ return EFI_SUCCESS;
}