diff options
-rw-r--r-- | efi_memtest/Makefile | 2 | ||||
-rw-r--r-- | efi_memtest/memtest86+/efi/memory_tables.c | 17 | ||||
-rw-r--r-- | efi_memtest/memtest86+/efi/page_allocator.c | 175 | ||||
-rw-r--r-- | efi_memtest/memtest86+/efi/page_allocator.h | 17 | ||||
-rw-r--r-- | efi_memtest/memtest86+/main.c | 97 |
5 files changed, 303 insertions, 5 deletions
diff --git a/efi_memtest/Makefile b/efi_memtest/Makefile index 7cefc0c..ab3a34b 100644 --- a/efi_memtest/Makefile +++ b/efi_memtest/Makefile @@ -36,7 +36,7 @@ PREPROCESSOR=-DUEFI -DUSING_LTO -Os \ -D DISABLE_NEW_DEPRECATED_INTERFACES "-DEFIAPI=__attribute__((ms_abi))" OBJS=Efi_Defs.obj config.o controller.o cpuid.o display.o dmi.o error.o init.o \ - lib.o logger.o main.o memory_tables.o memsize.o patn.o pci.o reloc.o \ + lib.o logger.o main.o memory_tables.o memsize.o page_allocator.o patn.o pci.o reloc.o \ screen_buffer.o random.o smp.o spd.o test.o vmem.o \ BaseLib.o BaseMemoryLib.o BasePrintLib.o \ UefiDebugLibStdErr.o UefiDevicePathLib2.o UefiLib2.o ApplicationEntryPoint.o \ diff --git a/efi_memtest/memtest86+/efi/memory_tables.c b/efi_memtest/memtest86+/efi/memory_tables.c index 25d209f..89f3ad5 100644 --- a/efi_memtest/memtest86+/efi/memory_tables.c +++ b/efi_memtest/memtest86+/efi/memory_tables.c @@ -100,7 +100,7 @@ int query_memory_table(void) { Print(L" VirtualStart: %X\n", desc->VirtualStart); Print(L" Attribute: %X\n", desc->Attribute);*/ - if (logflag && log_mem_tbl) { // TODO print as hex? + /* if (logflag && log_mem_tbl) { // TODO print as hex? char log[100] = "\nquery_memory_table(): New EfiConventionalMemory segment found.\nPhysical Start = "; int length = 81; int_to_charr(desc->PhysicalStart, log, &length); @@ -119,6 +119,21 @@ int query_memory_table(void) { int length = 12; int_to_charr(desc->Attribute, log, &length); print_log(log, length); + }*/ + + EFI_STATUS status = gST->BootServices->AllocatePages( + AllocateAddress, EfiBootServicesData, desc->NumberOfPages, (EFI_PHYSICAL_ADDRESS *)desc->PhysicalStart); + + if (logflag) { + char log[19] = "STATUS = "; + int length = 9; + int_to_charr(status, log, &length); + print_log(log, length); + } + + if (status == EFI_SUCCESS) { + gST->BootServices->FreePages(desc->PhysicalStart, desc->NumberOfPages); + print_log("Freed pages", 11); } mem_info.e820[mem_info.e820_nr].addr = desc->PhysicalStart; diff --git a/efi_memtest/memtest86+/efi/page_allocator.c b/efi_memtest/memtest86+/efi/page_allocator.c new file mode 100644 index 0000000..3aa4a55 --- /dev/null +++ b/efi_memtest/memtest86+/efi/page_allocator.c @@ -0,0 +1,175 @@ +#include "Uefi.h" +#include "Library/UefiLib.h" + +#include "page_allocator.h" + +#include "logger.h" + +extern EFI_SYSTEM_TABLE *gST; +extern short logflag; + +extern struct allocation_map * const alloc_map; + +int d_n_c_level = 0; + +void print_alloc_map() { + + if (!logflag) return; + + { + char log[30] = "alloc_map->length = "; + int length = 20; + int_to_charr(alloc_map->length, log, &length); + print_log(log, length); + } + + for (int i = 0; i < alloc_map->length; i++) { + + { + char log[33] = "alloc_map->iteration = "; + int length = 23; + int_to_charr(alloc_map->entry[i].iteration, log, &length); + print_log(log, length); + } + + { + char log[30] = "alloc_map->window = "; + int length = 20; + int_to_charr(alloc_map->entry[i].window, log, &length); + print_log(log, length); + } + + { + char log[32] = "alloc_map->testpatn = "; + int length = 22; + int_to_charr(alloc_map->entry[i].testpatn, log, &length); + print_log(log, length); + } + + { + char log[29] = "alloc_map->start = "; + int length = 19; + int_to_charr((unsigned long) alloc_map->entry[i].start, log, &length); + print_log(log, length); + } + + { + char log[35] = "alloc_map->no_of_pages = "; + int length = 25; + int_to_charr(alloc_map->entry[i].no_of_pages, log, &length); + print_log(log, length); + } + + } +} + +void sequential_allocation(int page_no, unsigned long * p) { + for (int i = 0; i < page_no; i ++) { + + EFI_PHYSICAL_ADDRESS * q = (EFI_PHYSICAL_ADDRESS *)(p + i*512); + + EFI_STATUS status = gST->BootServices->AllocatePages(AllocateAddress, EfiBootServicesData, 1, q); + + if (status != EFI_SUCCESS) { + //print_log("no success", 10); + } else { + + if (logflag) { + print_log("SUCCESS!!!!", 11); + char log[24] = "q = "; + int length = 4; + int_to_charr((unsigned long) q, log, &length); + print_log(log, length); + } + } + } +} + +void divide_n_conquer_allocation(int page_no, unsigned long *p) { + + if (page_no <= 1) return; + + d_n_c_level += 1; + + /*if (logflag) { + char log[21] = "\npage_no = "; + int length = 11; + int_to_charr(page_no, log, &length); + print_log(log, length); + } + + if (logflag) { + char log[24] = "p = "; + int length = 4; + int_to_charr((unsigned long) p, log, &length); + print_log(log, length); + }*/ + + EFI_STATUS status = gST->BootServices->AllocatePages( + AllocateAddress, EfiBootServicesData, page_no, (EFI_PHYSICAL_ADDRESS *)p); + + if (status != EFI_SUCCESS ) { + + if (logflag) { + char log[19] = "STATUS = "; + int length = 9; + int_to_charr(status, log, &length); + print_log(log, length); + } + + /*if (page_no >= 2) { + int first = page_no / 2; + int scnd = page_no - first; + + divide_n_conquer_allocation(first, p); + divide_n_conquer_allocation(scnd, (p + first*512)); + }*/ + + } else { + + if (logflag) { + + alloc_map->entry[alloc_map->length].start = p; + alloc_map->entry[alloc_map->length].no_of_pages = page_no; + alloc_map->length++; + + print_log("SUCCESS!!!!", 11); + char log[24] = "q = "; + int length = 4; + int_to_charr((unsigned long) p, log, &length); + print_log(log, length); + } + + // TODO store in data structure + } + +} + +void allocate_pages(int page_no, unsigned long * p) { + + if (logflag) { + char log[21] = "\npage_no = "; + int length = 11; + int_to_charr(page_no, log, &length); + print_log(log, length); + } + + if (logflag) { + char log[24] = "p = "; + int length = 4; + int_to_charr((unsigned long) p, log, &length); + print_log(log, length); + } + + d_n_c_level = 0; + + // sequential_allocation(page_no, p); + divide_n_conquer_allocation(page_no, p); + + print_alloc_map(); + +} + +void free_pages(unsigned long *p) { + +} diff --git a/efi_memtest/memtest86+/efi/page_allocator.h b/efi_memtest/memtest86+/efi/page_allocator.h new file mode 100644 index 0000000..427ae05 --- /dev/null +++ b/efi_memtest/memtest86+/efi/page_allocator.h @@ -0,0 +1,17 @@ +#define MAX_ALLOCATION_MAP_ENTRIES 100 + +struct allocation_map_entry { + int iteration; // As there are loops over the tests and windows, we want to track WHEN this page could be allocated + int window; + int testpatn; + int d_n_c_depth; // track how many divide steps were needed to allocate this pages + unsigned long * start; + int no_of_pages; +}; + +struct allocation_map { + int length; + struct allocation_map_entry entry[MAX_ALLOCATION_MAP_ENTRIES]; +}; + +void allocate_pages(int page_no, unsigned long * p); diff --git a/efi_memtest/memtest86+/main.c b/efi_memtest/memtest86+/main.c index 437bfb3..7ea7d66 100644 --- a/efi_memtest/memtest86+/main.c +++ b/efi_memtest/memtest86+/main.c @@ -21,6 +21,8 @@ #include "main_asm.h" #include "memory_tables.h" +#include "page_allocator.h" + #undef TEST_TIMES #define DEFTESTS 9 #define FIRST_DIVISER 3 @@ -62,6 +64,7 @@ int find_chunks(int test); static void test_setup(void); static int compute_segments(struct pmap map, int cpu); int do_test(int ord); +int pages_allocated = 0; struct tseq tseq[] = { @@ -112,6 +115,9 @@ volatile static ulong win0_start; /* Start test address for window 0 */ volatile static ulong win1_end; /* End address for relocation */ volatile static struct pmap winx; /* Window struct for mapping windows */ +struct allocation_map am = {}; +struct allocation_map * const alloc_map = &am; + ulong no_of_tests = 0; // TODO remove ulong no_of_segment_tests = 0; ulong no_of_ticks = 0; @@ -711,12 +717,12 @@ void test_start(void) run_cpus = tseq[test].cpu_sel; } } - /*if (logflag) { + if (logflag) { char log[50] = "test_start(): mstr_cpu in switch stmt = "; int length = 40; int_to_charr(mstr_cpu, log, &length); print_log(log, length); - }*/ + } mstr_cpu = 0; // TODO remove. Hope that it is set when smp is enabled break; } @@ -1073,6 +1079,51 @@ int do_test(int my_ord) print_log(log, length); } + if (1 /*pages_allocated == 1*/) { + + print_pmap(); + + print_map(); + + + if (logflag) { + char log[18] = "msegs = "; + int length = 8; + int_to_charr(vv->msegs, log, &length); + print_log(log, length); + } + + if (logflag) { + char log[21] = "iteration: "; + int length = 11; + int_to_charr(pages_allocated, log, &length); + print_log(log, length); + } + + //for (int i = 0; i < vv->msegs; i++) { + for (int j = 0; j < 10; j++) { + int i = 5; + ulong * p = (ulong *) (vv->pmap[i].start * 4096); + ulong page_no = ((ulong) vv->pmap[i].end - (ulong) vv->pmap[i].start); + + allocate_pages(page_no, p); // TODO provide allocate-map structure + } + + } + + pages_allocated += 1; + + + /* + for (int i = 0; i < segs; i++) { + ulong * p = vv->map[i].start; + ulong diff = ((ulong) vv->map[i].end - (ulong) vv->map[i].end); + if (diff % 4096 != 0) continue; + int page_no = diff / 4096; + allocate_pages(page_no, p); // TODO provide allocate-map structure + }*/ + + switch(tseq[test].pat) { /* do the testing according to the selected pattern */ @@ -1545,7 +1596,47 @@ static int compute_segments(struct pmap win, int me) if (end >= wend) { end = wend; } - +#if 0 + cprint(LINE_SCROLL+(2*i), 0, " ("); + hprint(LINE_SCROLL+(2*i), 2, start); + cprint(LINE_SCROLL+(2*i), 10, ", "); + hprint(LINE_SCROLL+(2*i), 12, end); + cprint(LINE_SCROLL+(2*i), 20, ") "); + + cprint(LINE_SCROLL+(2*i), 22, "r("); + hprint(LINE_SCROLL+(2*i), 24, wstart); + cprint(LINE_SCROLL+(2*i), 32, ", "); + hprint(LINE_SCROLL+(2*i), 34, wend); + cprint(LINE_SCROLL+(2*i), 42, ") "); + + cprint(LINE_SCROLL+(2*i), 44, "p("); + hprint(LINE_SCROLL+(2*i), 46, vv->plim_lower); + cprint(LINE_SCROLL+(2*i), 54, ", "); + hprint(LINE_SCROLL+(2*i), 56, vv->plim_upper); + cprint(LINE_SCROLL+(2*i), 64, ") "); + + cprint(LINE_SCROLL+(2*i+1), 0, "w("); + hprint(LINE_SCROLL+(2*i+1), 2, win.start); + cprint(LINE_SCROLL+(2*i+1), 10, ", "); + hprint(LINE_SCROLL+(2*i+1), 12, win.end); + cprint(LINE_SCROLL+(2*i+1), 20, ") "); + + cprint(LINE_SCROLL+(2*i+1), 22, "m("); + hprint(LINE_SCROLL+(2*i+1), 24, vv->pmap[i].start); + cprint(LINE_SCROLL+(2*i+1), 32, ", "); + hprint(LINE_SCROLL+(2*i+1), 34, vv->pmap[i].end); + cprint(LINE_SCROLL+(2*i+1), 42, ") "); + + cprint(LINE_SCROLL+(2*i+1), 44, "i="); + hprint(LINE_SCROLL+(2*i+1), 46, i); + + cprint(LINE_SCROLL+(2*i+2), 0, + " " + " "); + cprint(LINE_SCROLL+(2*i+3), 0, + " " + " "); +#endif if (logflag && log_comp_seg) { char log[49] = "\ncompute_segments(): start = "; int length = 29; |