Would it be smart to map all physical addresses to virtua...

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Would it be smart to map all physical addresses to virtua...

Post by Ycep »

...l while boot? If not, why? What would be pros and cons of it?
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Would it be smart to map all physical addresses to virtu

Post by BrightLight »

It makes perfect sense to map all physical addresses to virtual address during booting. It makes some things (e.g. ACPI table access, PCIe configuration, ...) easier to do. For 64-bit systems, it makes sense to leave the lower half of the 48-bit address space for general purpose use, and the upper half to map all physical addresses.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Re: Would it be smart to map all physical addresses to virtu

Post by Ycep »

What is wrong with this then...

Code: Select all

PageDir* d=(PageDir*)AllocBlock(12288);
memclr(d,sizeof(PageDir));
uint page=0, frame=0;
for(uint j=0;j<SystemBootInfo->memoryLo/4096;j++)
{
	PageTable* t=new PageTable;
	for(uint i=0;i<1024;i++,frame+=4096)
	{
		AddAtrib(&page,pteUser);
		SetFrame(&page,(uint)frame);
		AddAtrib(&page,ptePresent);
		t->entries[pteIndex(frame)]=frame;
	}
	AddAtrib(&d->entries[j], pdeWritable);
	AddAtrib(&d->entries[j], pdePresent);
	SetFrame(&d->entries[j], (uint)t);
}
AddAtrib(), SetFrame() and pteIndex() are checked to be working.
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Would it be smart to map all physical addresses to virtu

Post by iansjack »

What makes you think anything is wrong with it? Have you checked the generated page table to make sure it is correct?
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Re: Would it be smart to map all physical addresses to virtu

Post by Ycep »

Finally I finished the skeleton of my memory managament. ( I sound nerdy)
Post Reply