Bad version (?)

This commit is contained in:
2021-09-14 19:02:20 +03:00
parent f551ca29ce
commit a58fee7200
58 changed files with 555 additions and 11189 deletions

View File

@ -28,7 +28,8 @@ uint32 _malloc_init2 (uint32 size, uint8 page_aligned, uint32* phys)
if (phys)
{
*phys = PagingGetPhysical(ret, KernelDirectory) + (ret & 0xFFF);
Page *pg = PagingGetPage(ret, 0, KernelDirectory);
*phys = (*pg & PageFrame) + (ret & 0xFFF);
Log("Mem","%#Allocated %u bytes (%spage aligned) at address 0x%x (phys=%x).\n", ColorLightMagenta, size, ((page_aligned) ? "" : "not "), ret, *phys);
}

View File

@ -6,6 +6,7 @@
*/
#include <memory-add.h>
// MemoryGetFree(), MemoryGetTotal(), MemoryGet blah blah...
// Returns total physical memory in bytes
uint32 MemoryGetTotal()
@ -16,13 +17,13 @@ uint32 MemoryGetTotal()
// Returns total free physical memory in bytes
uint32 MemoryGetFree()
{
return (TotalBlocks - UsedBlocks) * 0x4;
return (TotalFrames - UsedFrames) * 0x4;
}
// Total used physical memory in bytes
uint32 MemoryGetUsed()
{
return UsedBlocks * 0x4;
return UsedFrames * 0x4;
}
// Same as above functions, but in frames
@ -33,15 +34,15 @@ uint32 MemoryGetFrameSize()
uint32 MemoryGetFramesTotal()
{
return TotalBlocks;
return TotalFrames;
}
uint32 MemoryGetFramesUsed()
{
return UsedBlocks;
return UsedFrames;
}
uint32 MemoryGetFramesFree()
{
return (TotalBlocks - UsedBlocks);
}
return (TotalFrames - UsedFrames);
}

View File

@ -10,6 +10,7 @@
#include "../../drivers/cmos/cmos.h"
#include <stdio.h>
uint32 mem_kernel_end = 0;
uint8 mem_initialized = 0;
@ -41,7 +42,7 @@ void _memory_reserve_system(MultibootInfo* info)
while ((uint32)location < (info->MemoryMapAddress + info->MemoryMapLength))
{
if (location->Type > 1)
MemPhReserveBlocks((uint32)location->Address, (uint32)location->Length);
MemPhReserveFrames((uint32)location->Address, (uint32)location->Length);
location = (MultibootMemoryMapEntry*) ((uint32)location + location->Size + sizeof(uint32));
}
@ -52,35 +53,29 @@ void _memory_reserve_system(MultibootInfo* info)
Error("Mem", "%#Missing %#memory map%# info from bootloader.\n", ColorLightRed, ColorWhite, ColorLightRed);
// Standard memory hole at 15mb
MemPhReserveBlocks(0x00F00000, 0x00100000);
MemPhReserveFrames(0x00F00000, 0x00100000);
}
// Standard reserved memory areas
MemPhReserveFrames(0x0, 0x400 + 256); // Real mode IVT, BDA
MemPhReserveFrames(0x1000, 0x2400); // DMA buffer
MemPhReserveFrames(0x9FC00, 385*1024); // EBDA, Video memory, ROM area
}
void MemoryInitialize (MultibootInfo* info)
{
// Get total system memory
uint32 totalSystemMemory = _memory_get_total_mem(info);
// Initialize physical & virtual memory managers
uint32 end = mem_kernel_end + 0x80000;
MemPhInitialize(totalSystemMemory);
PagingInitialize(&end);
PagingInitialize((volatile uint32*)&mem_kernel_end);
// Reserve physical blocks
_memory_reserve_system(info);
uint32 i;
// Allocate some space for the kernel heap
for (i = KERNEL_HEAP_START; i <= KERNEL_HEAP_END; i += 0x1000)
PagingMapPage(MemPhAllocateBlock(), i, PageWriteable, KernelDirectory);
// Create the kernel heap
KernelHeap = MemHeapCreate(KERNEL_HEAP_START, KERNEL_HEAP_START
+ KERNEL_HEAP_INITIAL_SIZE, 0xCFFFF000, 3); // is kernel, writeable
Log("Mem", "Done initializing memory!\n");
Log("Mem", "Done initializing memory!");
mem_initialized = 2;
}
@ -89,5 +84,5 @@ void MemoryTempInitialize (uint32 kernel_end)
{
mem_initialized = 1;
mem_kernel_end = kernel_end;
Log("Mem", "Initialized temporary memory manager, allocating from %#0x%x.\n", ColorWhite, mem_kernel_end);
Log("Mem", "Initialized temporary memory manager, allocating from %#0x%x.\n", kernel_end);
}