-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemoryUefi.c
66 lines (56 loc) · 1.77 KB
/
MemoryUefi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <Setup.h>
#include <Tools.h>
EFI_STATUS AllocatePage(UINT64 pages, address *addr)
{
// EfiBootServicesData
EFI_STATUS status = gBS->AllocatePages(AllocateAnyPages, EfiLoaderData, pages, addr);
return CHECK_ERROR_BEFORELOG(status, L"Allocate page");
}
EFI_STATUS AllocateM(UINTN size, void **addr)
{
// EfiBootServicesData
EFI_STATUS status = gBS->AllocatePool(EfiRuntimeServicesData,size, addr);
return CHECK_ERROR_BEFORELOG(status, L"Allocate pool");
}
EFI_STATUS FreePage(UINT64 pages, address addr)
{
EFI_STATUS status = gBS->FreePages(addr, pages);
return CHECK_ERROR_BEFORELOG(status, L"Free page");
}
EFI_STATUS FreeM(VOID *addr)
{
EFI_STATUS status = gBS->FreePool(addr);
return CHECK_ERROR_BEFORELOG(status, L"Free pool");
}
EFI_STATUS ReserveMemory(ADDRESS *addr, UINT64 size, UINTN width, UINTN height, UINTN offset)
{
#ifdef LOG
Print(L"get size to reserve: %d\n", size);
#endif //LOG
ADDRESS old = *addr + offset;
size = size - offset;
ADDRESS new;
UINT64 pageSize = calPage(size);
EFI_STATUS status = AllocatePage(pageSize, &new);
if (RETRURN_IF_ERROR(status, L"Reserve"))
{
return status;
}
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *PixelToBuffer = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)new;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *PixelFromFile = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)(old + size);
for (UINTN i = 0; i < height; i++)
{
PixelFromFile -= width;
for (UINTN j = 0; j < width; j++)
{
*PixelToBuffer = *PixelFromFile;
PixelToBuffer++;
PixelFromFile++;
}
PixelFromFile -= width;
}
*addr = new;
//free
status = FreePage(pageSize, old-offset);
return CHECK_ERROR_BEFORELOG(status, L"Free old addr");
}