Improvements to the address space switching function.

It now only switches when needed and returns the old addr space.
This commit is contained in:
Jonas 'Sortie' Termansen 2011-08-07 00:47:36 +02:00
parent 66c058fba1
commit 90ebfe7f0a
2 changed files with 9 additions and 4 deletions

View File

@ -226,7 +226,7 @@ namespace Sortix
Table* BootstrapCreateTable(Dir* dir, addr_t where);
void BootstrapMap(Dir* dir, addr_t where, addr_t physical);
void BootstrapMapStructures(Dir* dir);
void SwitchDirectory(addr_t dir);
addr_t SwitchDirectory(addr_t dir);
addr_t CreateDirectory();
#endif
@ -356,16 +356,21 @@ namespace Sortix
return CreateDirectory();
}
void SwitchAddressSpace(addr_t addrspace)
addr_t SwitchAddressSpace(addr_t addrspace)
{
return SwitchDirectory(addrspace);
}
void SwitchDirectory(addr_t dir)
addr_t SwitchDirectory(addr_t dir)
{
// Don't switch if we are already there.
if ( dir == currentDirPhysical ) { return currentDirPhysical; }
addr_t previous = currentDirPhysical;
asm volatile("mov %0, %%cr3":: "r"(dir));
currentDirPhysical = dir;
Flush();
return previous;
}
addr_t CreateDirectory()

View File

@ -41,7 +41,7 @@ namespace Sortix
void Init();
void Flush();
addr_t CreateAddressSpace();
void SwitchAddressSpace(addr_t addrspace);
addr_t SwitchAddressSpace(addr_t addrspace);
void MapKernel(addr_t where, addr_t physical);
bool MapUser(addr_t where, addr_t physical);
addr_t UnmapKernel(addr_t where);