git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
KernelLand - Better node chaching code
[tpg/acess2.git]
/
KernelLand
/
Kernel
/
arch
/
x86
/
mm_virt.c
diff --git
a/KernelLand/Kernel/arch/x86/mm_virt.c
b/KernelLand/Kernel/arch/x86/mm_virt.c
index
bd7b1df
..
0eb60a1
100644
(file)
--- a/
KernelLand/Kernel/arch/x86/mm_virt.c
+++ b/
KernelLand/Kernel/arch/x86/mm_virt.c
@@
-171,6
+171,7
@@
void MM_PageFault(tVAddr Addr, Uint ErrorCode, tRegs *Regs)
&& gaPageTable[Addr>>12] & PF_COW )
{
tPAddr paddr;
&& gaPageTable[Addr>>12] & PF_COW )
{
tPAddr paddr;
+ __asm__ __volatile__ ("sti");
if(MM_GetRefCount( gaPageTable[Addr>>12] & ~0xFFF ) == 1)
{
gaPageTable[Addr>>12] &= ~PF_COW;
if(MM_GetRefCount( gaPageTable[Addr>>12] & ~0xFFF ) == 1)
{
gaPageTable[Addr>>12] &= ~PF_COW;
@@
-197,6
+198,7
@@
void MM_PageFault(tVAddr Addr, Uint ErrorCode, tRegs *Regs)
// If it was a user, tell the thread handler
if(ErrorCode & 4) {
// If it was a user, tell the thread handler
if(ErrorCode & 4) {
+ __asm__ __volatile__ ("sti");
Log_Warning("MMVirt", "User %s %s memory%s",
(ErrorCode&2?"write to":"read from"),
(ErrorCode&1?"bad/locked":"non-present"),
Log_Warning("MMVirt", "User %s %s memory%s",
(ErrorCode&2?"write to":"read from"),
(ErrorCode&1?"bad/locked":"non-present"),
@@
-412,13
+414,14
@@
void MM_Deallocate(tVAddr VAddr)
* \fn tPAddr MM_GetPhysAddr(tVAddr Addr)
* \brief Checks if the passed address is accesable
*/
* \fn tPAddr MM_GetPhysAddr(tVAddr Addr)
* \brief Checks if the passed address is accesable
*/
-tPAddr MM_GetPhysAddr(
tVAddr
Addr)
+tPAddr MM_GetPhysAddr(
volatile const void *
Addr)
{
{
- if( !(gaPageDir[Addr >> 22] & 1) )
+ tVAddr addr = (tVAddr)Addr;
+ if( !(gaPageDir[addr >> 22] & 1) )
return 0;
return 0;
- if( !(gaPageTable[
A
ddr >> 12] & 1) )
+ if( !(gaPageTable[
a
ddr >> 12] & 1) )
return 0;
return 0;
- return (gaPageTable[
Addr >> 12] & ~0xFFF) | (A
ddr & 0xFFF);
+ return (gaPageTable[
addr >> 12] & ~0xFFF) | (a
ddr & 0xFFF);
}
/**
}
/**
@@
-439,7
+442,8
@@
int MM_Map(tVAddr VAddr, tPAddr PAddr)
//ENTER("xVAddr xPAddr", VAddr, PAddr);
// Sanity check
if( PAddr & 0xFFF || VAddr & 0xFFF ) {
//ENTER("xVAddr xPAddr", VAddr, PAddr);
// Sanity check
if( PAddr & 0xFFF || VAddr & 0xFFF ) {
- Log_Warning("MM_Virt", "MM_Map - Physical or Virtual Addresses are not aligned");
+ Log_Warning("MM_Virt", "MM_Map - Physical or Virtual Addresses are not aligned (0x%P and %p)",
+ PAddr, VAddr);
//LEAVE('i', 0);
return 0;
}
//LEAVE('i', 0);
return 0;
}
@@
-691,9
+695,9
@@
tPAddr MM_Clone(int bNoUserCopy)
MM_RefPhys( gaTmpTable[i*1024+j] & ~0xFFF );
MM_RefPhys( gaTmpTable[i*1024+j] & ~0xFFF );
- tmp =
(void *)
MM_MapTemp( gaTmpTable[i*1024+j] & ~0xFFF );
+ tmp = MM_MapTemp( gaTmpTable[i*1024+j] & ~0xFFF );
memcpy( tmp, (void *)( (i*1024+j)*0x1000 ), 0x1000 );
memcpy( tmp, (void *)( (i*1024+j)*0x1000 ), 0x1000 );
- MM_FreeTemp(
(Uint)
tmp );
+ MM_FreeTemp( tmp );
}
}
}
}
@@
-714,7
+718,8
@@
tVAddr MM_NewKStack(void)
for(base = MM_KERNEL_STACKS; base < MM_KERNEL_STACKS_END; base += MM_KERNEL_STACK_SIZE)
{
// Check if space is free
for(base = MM_KERNEL_STACKS; base < MM_KERNEL_STACKS_END; base += MM_KERNEL_STACK_SIZE)
{
// Check if space is free
- if(MM_GetPhysAddr(base) != 0) continue;
+ if(MM_GetPhysAddr( (void*) base) != 0)
+ continue;
// Allocate
//for(i = MM_KERNEL_STACK_SIZE; i -= 0x1000 ; )
for(i = 0; i < MM_KERNEL_STACK_SIZE; i += 0x1000 )
// Allocate
//for(i = MM_KERNEL_STACK_SIZE; i -= 0x1000 ; )
for(i = 0; i < MM_KERNEL_STACK_SIZE; i += 0x1000 )
@@
-801,9
+806,9
@@
tVAddr MM_NewWorkerStack(Uint *StackContents, size_t ContentsSize)
// NOTE: Max of 1 page
// `page` is the last allocated page from the previious for loop
// NOTE: Max of 1 page
// `page` is the last allocated page from the previious for loop
- tmpPage = MM_MapTemp( page );
+ tmpPage =
(tVAddr)
MM_MapTemp( page );
memcpy( (void*)( tmpPage + (0x1000 - ContentsSize) ), StackContents, ContentsSize);
memcpy( (void*)( tmpPage + (0x1000 - ContentsSize) ), StackContents, ContentsSize);
- MM_FreeTemp(
tmpPage);
+ MM_FreeTemp(
(void*)tmpPage );
//Log("MM_NewWorkerStack: RETURN 0x%x", base);
return base + WORKER_STACK_SIZE;
//Log("MM_NewWorkerStack: RETURN 0x%x", base);
return base + WORKER_STACK_SIZE;
@@
-932,7
+937,7
@@
int MM_IsValidBuffer(tVAddr Addr, size_t Size)
tPAddr MM_DuplicatePage(tVAddr VAddr)
{
tPAddr ret;
tPAddr MM_DuplicatePage(tVAddr VAddr)
{
tPAddr ret;
-
Uint
temp;
+
void *
temp;
int wasRO = 0;
//ENTER("xVAddr", VAddr);
int wasRO = 0;
//ENTER("xVAddr", VAddr);
@@
-957,7
+962,7
@@
tPAddr MM_DuplicatePage(tVAddr VAddr)
// Copy Data
temp = MM_MapTemp(ret);
// Copy Data
temp = MM_MapTemp(ret);
- memcpy(
(void*)
temp, (void*)VAddr, 0x1000 );
+ memcpy( temp, (void*)VAddr, 0x1000 );
MM_FreeTemp(temp);
// Restore Writeable status
MM_FreeTemp(temp);
// Restore Writeable status
@@
-973,7
+978,7
@@
tPAddr MM_DuplicatePage(tVAddr VAddr)
* \brief Create a temporary memory mapping
* \todo Show Luigi Barone (C Lecturer) and see what he thinks
*/
* \brief Create a temporary memory mapping
* \todo Show Luigi Barone (C Lecturer) and see what he thinks
*/
-
tVAddr
MM_MapTemp(tPAddr PAddr)
+
void *
MM_MapTemp(tPAddr PAddr)
{
int i;
{
int i;
@@
-996,7
+1001,7
@@
tVAddr MM_MapTemp(tPAddr PAddr)
INVLPG( TEMP_MAP_ADDR + (i << 12) );
//LEAVE('p', TEMP_MAP_ADDR + (i << 12));
Mutex_Release( &glTempMappings );
INVLPG( TEMP_MAP_ADDR + (i << 12) );
//LEAVE('p', TEMP_MAP_ADDR + (i << 12));
Mutex_Release( &glTempMappings );
- return
TEMP_MAP_ADDR + (i << 12
);
+ return
(void*)( TEMP_MAP_ADDR + (i << 12)
);
}
Mutex_Release( &glTempMappings );
Threads_Yield(); // TODO: Use a sleep queue here instead
}
Mutex_Release( &glTempMappings );
Threads_Yield(); // TODO: Use a sleep queue here instead
@@
-1007,9
+1012,9
@@
tVAddr MM_MapTemp(tPAddr PAddr)
* \fn void MM_FreeTemp(tVAddr PAddr)
* \brief Free's a temp mapping
*/
* \fn void MM_FreeTemp(tVAddr PAddr)
* \brief Free's a temp mapping
*/
-void MM_FreeTemp(
tVAddr
VAddr)
+void MM_FreeTemp(
void *
VAddr)
{
{
- int i = VAddr >> 12;
+ int i =
(tVAddr)
VAddr >> 12;
//ENTER("xVAddr", VAddr);
if(i >= (TEMP_MAP_ADDR >> 12))
//ENTER("xVAddr", VAddr);
if(i >= (TEMP_MAP_ADDR >> 12))
@@
-1022,7
+1027,7
@@
void MM_FreeTemp(tVAddr VAddr)
* \fn tVAddr MM_MapHWPages(tPAddr PAddr, Uint Number)
* \brief Allocates a contigous number of pages
*/
* \fn tVAddr MM_MapHWPages(tPAddr PAddr, Uint Number)
* \brief Allocates a contigous number of pages
*/
-
tVAddr
MM_MapHWPages(tPAddr PAddr, Uint Number)
+
void *
MM_MapHWPages(tPAddr PAddr, Uint Number)
{
int i, j;
{
int i, j;
@@
-1049,7
+1054,7
@@
tVAddr MM_MapHWPages(tPAddr PAddr, Uint Number)
MM_RefPhys( PAddr + (j<<12) );
gaPageTable[ (HW_MAP_ADDR >> 12) + i + j ] = (PAddr + (j<<12)) | 3;
}
MM_RefPhys( PAddr + (j<<12) );
gaPageTable[ (HW_MAP_ADDR >> 12) + i + j ] = (PAddr + (j<<12)) | 3;
}
- return
HW_MAP_ADDR + (i<<12
);
+ return
(void*)(HW_MAP_ADDR + (i<<12)
);
}
}
// If we don't find any, return NULL
}
}
// If we don't find any, return NULL
@@
-1064,32
+1069,31
@@
tVAddr MM_MapHWPages(tPAddr PAddr, Uint Number)
* \param PhysAddr Pointer to the location to place the physical address allocated
* \return Virtual address allocate
*/
* \param PhysAddr Pointer to the location to place the physical address allocated
* \return Virtual address allocate
*/
-
tVAddr
MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr)
+
void *
MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr)
{
{
- tPAddr maxCheck = (1 << MaxBits);
tPAddr phys;
tPAddr phys;
-
tVAddr
ret;
+
void *
ret;
ENTER("iPages iMaxBits pPhysAddr", Pages, MaxBits, PhysAddr);
ENTER("iPages iMaxBits pPhysAddr", Pages, MaxBits, PhysAddr);
+ if(MaxBits == -1)
+ MaxBits = PHYS_BITS;
+
// Sanity Check
// Sanity Check
- if(MaxBits < 12
|| !PhysAddr
) {
+ if(MaxBits < 12) {
LEAVE('i', 0);
return 0;
}
LEAVE('i', 0);
return 0;
}
- // Bound
- if(MaxBits >= PHYS_BITS) maxCheck = -1;
-
// Fast Allocate
if(Pages == 1 && MaxBits >= PHYS_BITS)
{
phys = MM_AllocPhys();
// Fast Allocate
if(Pages == 1 && MaxBits >= PHYS_BITS)
{
phys = MM_AllocPhys();
+ if( PhysAddr )
+ *PhysAddr = phys;
if( !phys ) {
if( !phys ) {
- *PhysAddr = 0;
LEAVE_RET('i', 0);
}
LEAVE_RET('i', 0);
}
- *PhysAddr = phys;
ret = MM_MapHWPages(phys, 1);
if(ret == 0) {
MM_DerefPhys(phys);
ret = MM_MapHWPages(phys, 1);
if(ret == 0) {
MM_DerefPhys(phys);
@@
-1097,7
+1101,7
@@
tVAddr MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr)
return 0;
}
LEAVE('x', ret);
return 0;
}
LEAVE('x', ret);
- return ret;
+ return
(void*)
ret;
}
// Slow Allocate
}
// Slow Allocate
@@
-1118,9
+1122,10
@@
tVAddr MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr)
return 0;
}
return 0;
}
- *PhysAddr = phys;
+ if( PhysAddr )
+ *PhysAddr = phys;
LEAVE('x', ret);
LEAVE('x', ret);
- return ret;
+ return
(void*)
ret;
}
/**
}
/**
@@
-1144,6
+1149,7
@@
void MM_UnmapHWPages(tVAddr VAddr, Uint Number)
{
MM_DerefPhys( gaPageTable[ i + j ] & ~0xFFF );
gaPageTable[ i + j ] = 0;
{
MM_DerefPhys( gaPageTable[ i + j ] & ~0xFFF );
gaPageTable[ i + j ] = 0;
+ INVLPG( (tVAddr)(i+j) << 12 );
}
Mutex_Release( &glTempMappings );
}
Mutex_Release( &glTempMappings );
UCC
git Repository :: git.ucc.asn.au