PAGING

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
z4ck
Member
Member
Posts: 28
Joined: Thu Oct 21, 2004 11:00 pm
Location: swiss
Contact:

PAGING

Post by z4ck »

hellou

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];	
};
char *autor="I don't know english!! :(";
blackcatcoder
Member
Member
Posts: 132
Joined: Wed Nov 03, 2004 12:00 am
Location: Austria
Contact:

Re: PAGING

Post by blackcatcoder »

Have you used e820 to detect memory ?

Do you set up the pagedir correctly and so on ??

Have you intialized a pagedir before you got into p-mode ?

If you need an example code that works give me your E-Mail-Address
and I well send you my paging routine to compare it !
z4ck
Member
Member
Posts: 28
Joined: Thu Oct 21, 2004 11:00 pm
Location: swiss
Contact:

Re: PAGING

Post by z4ck »

1. what is e820?
2. thats the point wich i'm not sure.
3. i initialize it after the jump into p-mode.
4. yes, yes, yes please. i've send you a email -> hackin at uboot.com.

thanks and greez
char *autor="I don't know english!! :(";
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: PAGING

Post by JAAman »

get the RBIL:
[url=http://www.cs.cmu.edu/~ralf/files.html]
## ---- ----- RBIL[/url]

it tells you lots of information about the computer including full specs on int15/e820:

int15/e820 is a RMode soft-interupt that reports how much memory your computer has and where its located (and where some other things are that a more advanced OS will NEED to find)

there are alternatives that are supported on older computers (only more recent ones support e820) but if you only support one method it should be this one -- the others are flawed since they only report amount of ram and therefore cannot tell you what memory location may be dangerous to use (they can be anywhere in the address space -- although they are usually above 1GB) if you have large amounts of ram (not uncommon these days) you may think your writing to valid ram but your actually writting to some device (most commonly the video card ram but could be controller chips -- and can, theoretically, permenantly damage your computer)

this is why JaaOS doesn't support more than 128MB of RAM if relying on the older methods -- and doesn't support probing at all--except to find common holes(512k,15MB)
blackcatcoder
Member
Member
Posts: 132
Joined: Wed Nov 03, 2004 12:00 am
Location: Austria
Contact:

Re: PAGING

Post by blackcatcoder »

i will send you the mail on saturday !

mail:

will include an asm file with e820 detection and 1 pagedir before jumping into pmode and one c file called paging where all the mapping and mm functions are
Last edited by blackcatcoder on Thu Oct 20, 2005 11:00 pm, edited 1 time in total.
Post Reply