Working on page allocator #67
This commit is contained in:
parent
08d7de2b40
commit
6a054a4b67
2
Makefile
2
Makefile
|
@ -115,7 +115,7 @@ KernSources = kernel/ke/cpuid.c kernel/mm/paging.c \
|
|||
kernel/sh/shell.c kernel/sh/shcmds.c \
|
||||
kernel/sh/musage.c kernel/io/ata.c \
|
||||
kernel/sh/argv.c kernel/ke/pit.c \
|
||||
kernel/sh/testcmds.c
|
||||
kernel/sh/testcmds.c kernel/mm/palloc.c
|
||||
|
||||
KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources))
|
||||
KernDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(KernSources))
|
||||
|
|
|
@ -98,7 +98,6 @@
|
|||
│ │ │ ├── ata.c
|
||||
│ │ │ ├── cursor.c
|
||||
│ │ │ ├── keyb.c
|
||||
│ │ │ ├── scan.c
|
||||
│ │ │ ├── spkr.c
|
||||
│ │ │ └── vga.c
|
||||
│ │ ├── ke
|
||||
|
@ -160,4 +159,4 @@
|
|||
├── ProjectTree
|
||||
└── README.md
|
||||
|
||||
28 directories, 107 files
|
||||
28 directories, 106 files
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
#define KPAGESIZE (4 * KB)
|
||||
#define UPAGESIZE (4 * KB)
|
||||
#define USERSPACE 0x80000000
|
||||
#define USERSPACE 0x100000000
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ void MmInitPaging(void)
|
|||
//DebugLog("\tPaging gap : %u MB (%p)\n\tLast virtual address %p\n", diffKernUsr / MB, diffKernUsr, MmVirtLastAddress);
|
||||
|
||||
memzero((void *)&MmPageMapLevel4[0], sizeof(MmPageMapLevel4));
|
||||
phDirSize = ((phRamSize / KPAGESIZE)*sizeof(ulong) + KPAGESIZE) & ( ~(KPAGESIZE - 1));
|
||||
phDirSize = ((phRamSize / KPAGESIZE)*sizeof(ulong) + KPAGESIZE) & ( ~((KPAGESIZE - 1) | NX));
|
||||
|
||||
MmPhysicalPageTable = (ulong*)malloc(phDirSize);
|
||||
//DebugLog("\t\tRam %u MB, pagesize %u KB, size %u MB\n", phRamSize / MB, KPAGESIZE / KB, phDirSize / MB);
|
||||
|
@ -179,7 +179,7 @@ void MmInitPaging(void)
|
|||
}
|
||||
// SECTION .RODATA PROTECTION
|
||||
else if ((ulong)curAddrPT >= (ulong)&_rodata && (ulong)curAddrPT <= (ulong)&_rodata_end) {
|
||||
MmPT[index] = (ulong)curAddrPT | PRESENT | WRITETHR | NX;
|
||||
MmPT[index] = (ulong)curAddrPT | PRESENT | NX;
|
||||
MmPhysicalPageTable[xedni] = (ulong)curAddrPT;
|
||||
//DebugLog("\tSection .rodata at %p\n", curAddrPT);
|
||||
}
|
||||
|
@ -224,17 +224,17 @@ void MmInitPaging(void)
|
|||
//
|
||||
static pte_t *MmGetPageDescriptorFromVirtual(void *virtualAddr)
|
||||
{
|
||||
ulong virtAddrPage = (ulong)virtualAddr & ( ~(KPAGESIZE - 1));
|
||||
ulong virtAddrPage = (ulong)virtualAddr & ( ~((KPAGESIZE - 1) | NX));
|
||||
|
||||
if (virtAddrPage > MmVirtLastAddress) {
|
||||
KeStartPanic("MmSetPage() Out of bound of the address space !");
|
||||
}
|
||||
|
||||
pdpe_t *pdp = (pdpe_t*)((ulong)MmPageMapLevel4[(virtAddrPage / ((ulong)KPAGESIZE * 0x8000000)) % 512] & ~(KPAGESIZE - 1));
|
||||
pdpe_t *pdp = (pdpe_t*)((ulong)MmPageMapLevel4[(virtAddrPage / ((ulong)KPAGESIZE * 0x8000000)) % 512] & ~((KPAGESIZE - 1) | NX | NX));
|
||||
//DebugLog("pdp\t: %p\n", pdp);
|
||||
pde_t *pd = (pde_t*)( (ulong)pdp[(virtAddrPage / ((ulong)KPAGESIZE * 0x40000)) % 512] & ~(KPAGESIZE - 1));
|
||||
pde_t *pd = (pde_t*)( (ulong)pdp[(virtAddrPage / ((ulong)KPAGESIZE * 0x40000)) % 512] & ~((KPAGESIZE - 1) | NX));
|
||||
//DebugLog("pd\t: %p\n", pd);
|
||||
pte_t *pt = (pte_t*)( (ulong)pd[(virtAddrPage / ((ulong)KPAGESIZE * 0x200)) % 512] & ~(KPAGESIZE - 1));
|
||||
pte_t *pt = (pte_t*)( (ulong)pd[(virtAddrPage / ((ulong)KPAGESIZE * 0x200)) % 512] & ~((KPAGESIZE - 1) | NX));
|
||||
//DebugLog("pt\t: %p\n", pt);
|
||||
|
||||
pte_t *page = &pt[(virtAddrPage / ((ulong)KPAGESIZE)) % 512];
|
||||
|
@ -249,19 +249,19 @@ static pte_t *MmGetPageDescriptorFromVirtual(void *virtualAddr)
|
|||
//
|
||||
void *MmTransVirtToPhyAddr(void* virtualAddr)
|
||||
{
|
||||
ulong virtAddrPage = (ulong)virtualAddr & ( ~(KPAGESIZE - 1));
|
||||
ulong virtAddrPage = (ulong)virtualAddr & ( ~((KPAGESIZE - 1) | NX));
|
||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
|
||||
if (*page == (*page & ~(KPAGESIZE - 1))) {
|
||||
if (*page == (*page & ~((KPAGESIZE - 1) | NX))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (void*)((*page & ~(KPAGESIZE - 1))+ ((ulong)virtualAddr - (ulong)virtAddrPage));
|
||||
return (void*)((*page & ~((KPAGESIZE - 1) | NX))+ ((ulong)virtualAddr - (ulong)virtAddrPage));
|
||||
}
|
||||
|
||||
void *MmTransPhyToVirtAddr(void* physicalAddr)
|
||||
{
|
||||
ulong phyAddrPage = (ulong)physicalAddr & ( ~(KPAGESIZE - 1));
|
||||
ulong phyAddrPage = (ulong)physicalAddr & ( ~((KPAGESIZE - 1) | NX));
|
||||
return (void*)( MmPhysicalPageTable[(ulong)physicalAddr
|
||||
/ ((ulong)KPAGESIZE)
|
||||
] + ((ulong)physicalAddr - phyAddrPage));
|
||||
|
@ -298,7 +298,7 @@ void MmMapPage(void* virtualAddr, void* physicalAddr, ulong flags)
|
|||
{
|
||||
pte_t *page = MmGetPageDescriptorFromVirtual(virtualAddr);
|
||||
|
||||
*page = ((ulong)physicalAddr & ~(KPAGESIZE - 1)) | flags;
|
||||
*page = ((ulong)physicalAddr & ~((KPAGESIZE - 1) | NX)) | flags;
|
||||
|
||||
KeFlushTlbSingle(*page);
|
||||
}
|
||||
|
|
|
@ -31,8 +31,29 @@
|
|||
|
||||
//---------
|
||||
|
||||
enum
|
||||
{
|
||||
Whatever = 1UL << 52,
|
||||
Whatever2 = 1UL << 62
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
void **FramePtr;
|
||||
int pageNumber;
|
||||
} FramePtr_t;
|
||||
|
||||
//---------
|
||||
|
||||
|
||||
//
|
||||
// Returns a structure that describes a pageframe
|
||||
//
|
||||
/* FramePtr_t MmAllocPageBlock(size_t size) { */
|
||||
/* ulong pageNumber = (ulong)size / KPAGESIZE; */
|
||||
|
||||
|
||||
/* return (FramePtr_t)0; */
|
||||
/* } */
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue