2021-09-14 15:48:57 +00:00
|
|
|
/*
|
|
|
|
* memory-add.h
|
|
|
|
*
|
|
|
|
* Created on: Aug 27, 2011
|
|
|
|
* Author: Tiberiu
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MEMORY_ADD_H_
|
|
|
|
#define MEMORY_ADD_H_
|
|
|
|
|
|
|
|
#include <memory.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <debugio.h>
|
2021-09-14 15:52:47 +00:00
|
|
|
#include <array.h>
|
2021-09-14 15:48:57 +00:00
|
|
|
|
|
|
|
/***************************************************
|
|
|
|
* Paging *
|
|
|
|
***************************************************/
|
|
|
|
typedef uint32 Page;
|
|
|
|
|
|
|
|
enum PageFlags
|
|
|
|
{
|
|
|
|
PagePresent = 0x1,
|
|
|
|
PageWriteable = 0x2,
|
|
|
|
PageUser = 0x4,
|
|
|
|
PageWriteThough = 0x8,
|
|
|
|
PageNotCacheable = 0x10,
|
|
|
|
PageAccessed = 0x20,
|
|
|
|
PageDirty = 0x40,
|
|
|
|
PagePAT = 0x80,
|
|
|
|
PageCpuGlobal = 0x100,
|
|
|
|
PageLvl4Global = 0x200,
|
|
|
|
PageFrame = 0xFFFFF000
|
|
|
|
};
|
|
|
|
|
2021-09-14 16:02:20 +00:00
|
|
|
|
|
|
|
|
2021-09-14 15:48:57 +00:00
|
|
|
typedef struct {
|
|
|
|
Page Pages[1024];
|
|
|
|
} PageTable;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PageTable* Tables[1024];
|
|
|
|
uint32 TablesPhysical[1024];
|
|
|
|
uint32 PhysicalAddr;
|
|
|
|
} PageDirectory;
|
|
|
|
|
|
|
|
extern PageDirectory* CurrentDirectory;
|
|
|
|
extern PageDirectory* KernelDirectory;
|
|
|
|
|
2021-09-14 16:02:20 +00:00
|
|
|
extern void PagingInitialize(volatile uint32* SystemMemory);
|
|
|
|
extern void PagingSwitchPageDirectory (PageDirectory* dir);
|
|
|
|
extern Page* PagingGetPage(uint32 addr, uint8 make, PageDirectory* dir);
|
|
|
|
extern void PagingCopyPagePhysical (uint32, uint32);
|
|
|
|
extern PageTable* PagingCloneTable (PageTable* src, uint32* physAddr);
|
|
|
|
extern PageDirectory* PagingCloneDirectory (PageDirectory* src);
|
|
|
|
|
2021-09-14 15:48:57 +00:00
|
|
|
|
|
|
|
/***************************************************
|
|
|
|
* Physical memory manager *
|
|
|
|
***************************************************/
|
2021-09-14 16:02:20 +00:00
|
|
|
extern uint32 TotalFrames;
|
2021-09-14 15:48:57 +00:00
|
|
|
extern uint32 TotalMemory;
|
2021-09-14 16:02:20 +00:00
|
|
|
extern uint32 UsedFrames;
|
2021-09-14 15:48:57 +00:00
|
|
|
|
2021-09-14 16:02:20 +00:00
|
|
|
void MemPhInitialize(uint32 SystemMemoryKb);
|
|
|
|
extern void MemPhSetFrame (uint32 frame, uint8 value);
|
|
|
|
uint32 MemPhGetFrame (uint32 frame);
|
|
|
|
uint32 MemPhFindFreeFrame();
|
|
|
|
void MemPhAllocFrame(Page* page, uint8 isKernel, uint8 isWriteable);
|
|
|
|
void MemPhFreeFrame(Page* page);
|
|
|
|
void MemPhReserveFrames (uint32 address, uint32 length);
|
2021-09-14 15:48:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***************************************************
|
|
|
|
* Memory heap *
|
|
|
|
***************************************************/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
OrderedArray Index;
|
|
|
|
uint32 StartAddress, EndAddress, MaxAddress;
|
|
|
|
// bit 0: supervisor-only bit 1: read-only
|
|
|
|
uint8 Flags;
|
|
|
|
} MemHeap;
|
|
|
|
|
|
|
|
extern MemHeap* KernelHeap;
|
|
|
|
|
2021-09-14 16:02:20 +00:00
|
|
|
extern uint32 MemHeapFindSmallestHole (uint32 size, uint8 page_align, MemHeap* heap);
|
|
|
|
extern int32 MemHeapCompare (uint32 a, uint32 b);
|
|
|
|
extern MemHeap* MemHeapCreate(uint32 start, uint32 end, uint32 max, uint8 flags);
|
|
|
|
extern void MemHeapExpand(uint32 newsz, MemHeap* heap, PageDirectory* pd);
|
|
|
|
extern uint32 MemHeapContract(uint32 newsz, MemHeap* heap, PageDirectory* pd);
|
|
|
|
extern uint32 MemHeapAlloc (uint32 size, uint8 isPageAligned, MemHeap* heap, PageDirectory* pd);
|
|
|
|
extern void MemHeapFree (uint32 address, MemHeap* heap, PageDirectory* pd);
|
2021-09-14 15:48:57 +00:00
|
|
|
|
|
|
|
#endif /* MEMORY_ADD_H_ */
|