i've finaly wrote a primitive paging code. but like ever it did not worke.
the pc / emulator reboots again and again.
have you an idee?
Code: Select all
/*
;
;---------------------------------------------------------------+
; .__ __ ?
;______ |__|___________ _/ |_ ____ ______ ?
;\____ \| \_ __ \__ \\ __\ ______ / _ \/ ___/ ?
;| |_> > || | \// __ \| | /_____/ ( <_> )___ \ ?
;| __/|__||__| (____ /__| \____/____ > ?
;|__| \/ \/ ?
;---------------------------------------------------------------+
;
;[1] Informations
;
; Last Modified: 21. Oktober 2004
; Begin: 15. Juni 2004
; Version: 0.000
; Coder: z4ck
;
;
;[2] Tasks
;
; Task Done Coder
;----------------------------------------------------------------
; - [ 0%] z4ck
;----------------------------------------------------------------
; TOTAL [ 0%] z4ck
;================================================================
*/
#include <memory.h>
#include <io.h>
/***************************************/
//Defines
#define PAGE_PRE 0x01
#define PAGE_RW 0x02
#define PAGE_US 0x04
#define PAGE_PWT 0x08
#define PAGE_PCD 0x10
#define PAGE_ACC 0x20
#define PAGE_DTY 0x40
#define PAGE_PAT 0x80
#define PAGE_GLB 0x100
/***************************************/
//Structs
typedef struct
{
unsigned long PageFrame[1024];
} __attribute__ ((packed)) PageTbl;
typedef struct
{
PageTbl *PageTable;
} __attribute__ ((packed)) PageDir;
/***************************************/
//Global Variables
PageDir *PageDirectory;
PageTbl *PageTable;
void SetupPaging()
{
PageDirectory = (PageDir *) 0x100000;
PageTable = (PageTbl *) 0x101000;
unsigned long i = 0;
for (; i < 1024; i++)
{
PageDirectory[i].PageTable = (PageTbl *)((unsigned long)&PageTable[i] | PAGE_RW | PAGE_PRE);
}
MapMemory ( 0, 0, 1024 * 4, PAGE_RW | PAGE_PRE);
WriteCr( PageDirectory, 3);
WriteCr( (ReadCr(0) | 0x80000000) , 0);
};
int SetPage ( unsigned long _phyAdress, unsigned long _vAdress, unsigned long _opt)
{
unsigned long table = _vAdress >> 22;
unsigned long entry = ( (_vAdress & 0xFFFFF000) << 10) >> 22;
if (table < 1024 && entry < 1024)
{
PageDirectory[table].PageTable->PageFrame[entry] = _phyAdress | _opt;
return 1;
}
return 0;
};
int MapMemory ( unsigned long _phyAdress, unsigned long _vAdress, unsigned long _lenght, unsigned long _opt)
{
while (_lenght > 0)
{
SetPage (_phyAdress, _vAdress, _opt);
_vAdress += 4096;
_phyAdress += 4096;
_lenght--;
}
return 0;
};
void *malloc(unsigned long _size)
{
return (void *) 0;
};
void free()
{
};
void memcpy(unsigned *_dest, unsigned *_src, unsigned long _lenght)
{
unsigned long i = 0;
for (; i < _lenght; i++)
_dest[i] = _src[i];
};