📄 pm3_tmp.c
字号:
/***************************************************************************
** File name : pm3_tmp.c
** Author : x.cheng
** Create date :
**
** Comment:
** 内存分页管理模块中负责对内核空间的临时空间进行分页管理
** 临时空间是内核本身未使用的,但是内核在进行其他的管理工作时会使用到
** 的临时映射数据的保留空间,比方说在创建进程的虚拟空间时使用。
**
** Revisions:
** $Log: pm3_tmp.c,v $
** Revision 1.1.1.1 2005/07/27 06:53:15 x.cheng
** add into repositories
**
**
***************************************************************************/
#include "const.h"
#include "type.h"
#include "stdarg.h"
#include "..\..\Inc\i386\system.h"
#include "..\..\Inc\i386\page.h"
#include "..\..\Inc\i386\map.h"
#include "..\..\Inc\i386\mmx.h"
#include "..\..\Inc\spinlock.h"
#include "..\..\inc\tui.h"
#define __PMM_SRC__
#include "..\inc\def_pmm.h"
//! Spinlock for mutual exclusion of temporary pages.
DECLARE_SPINLOCK( stTemporaryMemoryLock );
/************************************************************
*************************************************************
** Function Name: pvPm3GetOneFreeTmpPage()
** Author: x.cheng
**
** Comment:
** Get a free virtual page from the temporary memory area.
**
** List of parameters:
** no
**
** Return value:
** The address of the temporary page or NULL if out of memory.
**
** Revisions:
**
*************************************************************
*************************************************************/
void *pvPm3GetOneFreeTmpPage()
{
unsigned char *pucTmpPage = (unsigned char*)KERNEL_TEMP_START_ADDRESS;
unsigned long ulPfn;
unsigned long ulFlags;
SpinlockDisableIrqAndLock(&stTemporaryMemoryLock, ulFlags);
while ( 1 ) {
if ( *pulAddressToPde( (unsigned long)pucTmpPage ) ) {
if ( *pulAddressToPte( (unsigned long)pucTmpPage ) ) {
pucTmpPage += PAGE_SIZE;
if ( pucTmpPage >= (unsigned char*)KERNEL_TEMP_END_ADDRESS ) {
//out of temporary memory
SpinlockEnableIrqAndUnlock(&stTemporaryMemoryLock, ulFlags);
return NULL;
}
continue;
}
}
// OK! A free temporary page has been found!
// Now map this page to a free frame and return the
// virtual address of this page, or NULL if there is
// no free frame.
ulPfn = ulPm2GetOneFreePage();
if ( NULL == ulPfn ) {
pucTmpPage = NULL;
} else if ( !ulPm2MapPageToVirtualAddress( ulPfn, (unsigned long)pucTmpPage, P_PRESENT | P_WRITE) ) {
pucTmpPage = NULL;
}
SpinlockEnableIrqAndUnlock(&stTemporaryMemoryLock, ulFlags);
return ( (void *)pucTmpPage );
}
}
/************************************************************
*************************************************************
** Function Name: vPm3FreeOneTmpPage()
** Author: x.cheng
**
** Comment:
** Free a virtual temporary page allocated by pvPm3GetOneFreeTmpPage.
**
** List of parameters:
** void * - the temporary page virtual address
** bool
** TRUE - free the page and also the physical frame
** FALSE - unmapp the page only, do not free the physical frame.
**
** Return value:
** none.
**
** Revisions:
** bool类型定义在type.h中,是int
*************************************************************
*************************************************************/
void vPm3FreeOneTmpPage(void *pvTmpPage, bool bFreeFrame)
{
unsigned long ulFlags;
SpinlockDisableIrqAndLock(&stTemporaryMemoryLock, ulFlags);
// is the page into the temporary memory range?!
if ( ((unsigned long)pvTmpPage >= KERNEL_TEMP_START_ADDRESS) &&
((unsigned long)pvTmpPage < KERNEL_TEMP_END_ADDRESS) ) {
if ( TRUE == bFreeFrame ) {
//delete_page( (uint32_t)p );
} else {
//unmap_page( (uint32_t)p );
}
}
SpinlockEnableIrqAndUnlock(&stTemporaryMemoryLock, ulFlags);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -