luxos/Kernel/include/memory-add.h
Tiberiu Chibici 852cf1bb17 [GOOD] BUILD 0.1.0.590 DATE 9/05/2011 AT 2:40 PM
====================================================
Mainly changed: FS.Initrd
+ (kind of) refractored VFS, bugfixed
+ Rewrote 'initrd' file system, fixed many problems
+ Working 'cat' and 'dir' console commands
+ Wrote 'initrd' image write application (for windows), however it may
be bugged
2021-09-14 18:52:47 +03:00

94 lines
2.5 KiB
C

/*
* 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>
#include <array.h>
/***************************************************
* 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
};
typedef struct {
Page Pages[1024];
} PageTable;
typedef struct {
PageTable* Tables[1024];
uint32 TablesPhysical[1024];
uint32 PhysicalAddr;
} PageDirectory;
extern PageDirectory* CurrentDirectory;
extern PageDirectory* KernelDirectory;
extern void PagingInitialize(uint32 SystemMemory);
extern void PagingSwitchPageDirectory (PageDirectory* dir);
extern Page* PagingGetPage(uint32 addr, uint8 make, PageDirectory* dir);
/***************************************************
* Physical memory manager *
***************************************************/
extern uint32 TotalFrames;
extern uint32 TotalMemory;
extern uint32 UsedFrames;
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);
/***************************************************
* Memory heap *
***************************************************/
typedef struct
{
OrderedArray Index;
uint32 StartAddress, EndAddress, MaxAddress;
// bit 0: supervisor-only bit 1: read-only
uint8 Flags;
} MemHeap;
extern MemHeap* KernelHeap;
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);
#endif /* MEMORY_ADD_H_ */