memory: fix paging_map_PageAllocated/2M
This commit is contained in:
parent
ddc08cabaf
commit
5a7e1863e8
@ -3,6 +3,7 @@
|
|||||||
#include "paging_internal.h"
|
#include "paging_internal.h"
|
||||||
#include "../runtime/panic_assert.h"
|
#include "../runtime/panic_assert.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
#include "../util/minmax.h"
|
||||||
|
|
||||||
|
|
||||||
// some learning:
|
// some learning:
|
||||||
@ -113,35 +114,39 @@ void paging_map_Page1G(uint64_t physical, uint64_t virtual, int pageCount, int p
|
|||||||
void paging_map_PageAllocated(uint64_t virtual, int pageCount, int protectionFlags) {
|
void paging_map_PageAllocated(uint64_t virtual, int pageCount, int protectionFlags) {
|
||||||
assert(virtual % SYSTEM_PAGE_SIZE == 0 && "Virtual address not page-aligned");
|
assert(virtual % SYSTEM_PAGE_SIZE == 0 && "Virtual address not page-aligned");
|
||||||
|
|
||||||
// skip the first 1M
|
uint64_t *buf = (uint64_t *)Buffer;
|
||||||
int i = 1024 / 4 / BITMAP_BITS;
|
int bufSize = HELOS_BUFFER_SIZE / sizeof(uint64_t *);
|
||||||
while (pageCount--) {
|
|
||||||
uint64_t freshPage = 0;
|
|
||||||
|
|
||||||
// this code is in sync with paging_physical.c, paging_physical_AllocateOneFrame, so you have to modify both
|
while (pageCount > 0) {
|
||||||
for (; i < paging_EndPhysicalPage / BITMAP_BITS; i++)
|
int pageCur = intmin(pageCount, bufSize);
|
||||||
if (paging_physical_Bitmap[i] != ~0ull)
|
int allocated = paging_physical_AllocateFrames(pageCur, buf);
|
||||||
for (int j = 0; j < BITMAP_BITS; j++)
|
for (int i = 0; i < allocated; i++) {
|
||||||
if ((paging_physical_Bitmap[i] & (1ull << j)) == 0) {
|
io_Printf("paging_map_PageAllocated: mapping physical %llx to virtual %llx\n", buf[i], virtual);
|
||||||
paging_physical_Bitmap[i] |= (1ull << j);
|
paging_map_Page(buf[i], virtual, 1, protectionFlags);
|
||||||
freshPage = (((uint64_t)i) * BITMAP_BITS + j) * SYSTEM_PAGE_SIZE;
|
|
||||||
memset((void *)freshPage, 0, SYSTEM_PAGE_SIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
paging_map_Page(freshPage, virtual, 1, protectionFlags);
|
virtual += SYSTEM_PAGE_SIZE * allocated;
|
||||||
virtual += SYSTEM_PAGE_SIZE;
|
pageCount -= allocated;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void paging_map_PageAllocated2M(uint64_t virtual, int pageCount, int protectionFlags) {
|
void paging_map_PageAllocated2M(uint64_t virtual, int pageCount, int protectionFlags) {
|
||||||
assert(pageCount > HELOS_BUFFER_SIZE / SYSTEM_PAGE_2M_SIZE * 8 && "helos_Buffer unable to hold all pointers");
|
|
||||||
assert(virtual % SYSTEM_PAGE_2M_SIZE == 0 && "Virtual address not page-aligned");
|
assert(virtual % SYSTEM_PAGE_2M_SIZE == 0 && "Virtual address not page-aligned");
|
||||||
|
|
||||||
uint64_t *buf = (uint64_t *)Buffer;
|
uint64_t *buf = (uint64_t *)Buffer;
|
||||||
|
int bufSize = HELOS_BUFFER_SIZE / sizeof(uint64_t *);
|
||||||
|
|
||||||
int allocated = paging_physical_AllocateFrames2M(pageCount, buf);
|
while (pageCount > 0) {
|
||||||
for (int i = 0; i < allocated; i++)
|
int pageCur = intmin(pageCount, bufSize);
|
||||||
paging_map_Page2M(buf[i], virtual + SYSTEM_PAGE_2M_SIZE * i, 1, protectionFlags);
|
int allocated = paging_physical_AllocateFrames2M(pageCur, buf);
|
||||||
|
for (int i = 0; i < allocated; i++) {
|
||||||
|
io_Printf("paging_map_PageAllocated: mapping physical %llx to virtual %llx\n", buf[i], virtual);
|
||||||
|
paging_map_Page2M(buf[i], virtual, 1, protectionFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual += SYSTEM_PAGE_2M_SIZE * allocated;
|
||||||
|
pageCount -= allocated;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void paging_map_FreeAllocated(uint64_t virtual, uint64_t end) {
|
void paging_map_FreeAllocated(uint64_t virtual, uint64_t end) {
|
||||||
|
Loading…
Reference in New Issue
Block a user