글
OS 제작의 원리 그리고 Codes - Ch 6. Memory Management
To calculate the size of physical memory
We could calculate in a simple way to check data. Writting data from the certain address then read it. Comparing that two data. If it's the same, there is memory. If not, there is no memory. // 실메모리의 크기를 구한다. byTe = pX[0]; // The start address of the memory. return( nSize * 0x100000 ); // 바이트 단위로 리턴한다.
// 실메모리의 크기를 구한다.
int nGetPhysMemSize()
{
int nI, nSize;
UCHAR *pX, byTe;;
// 메모리는 512메가부터 2기가 바이트까지 뒤진다.
for( nSize = nI = 512; nI < 2048; nI++ )
{
pX = (UCHAR*)( nI * (ULONG)0x100000 ); // nl * 1MB
byTe++; // Increasing the value of the start address.
pX[0] = byTe; // Writting the value on the start address.
if( byTe != pX[0] ) // Comparing between the increased data and the value of the start address.
break; // If it's not the same, there is no memory on that address.
else
nSize++; // If it's the same, there is memory. Keep calculating.
pX[0] -= 1; // Restoring to the previous value
}
}
Physical Memory Management Table
Assigning 1byte to save the status of physical memory. It's like Reference Counter.
When it's zero, it's not used and is available. When it's five, five processors are using it by mapping.
Each page has 1024 entries, which is 4 byte. It means 4 KB allocate to each page.
There are 256 pages In 1 MB Memory. That's why needing 256 byte per 1MB.
To save the counter for 1024MB Memory, 1024 * 256 bytes ( 256 KB ) are required.
Putting P.M.M.T right after kernel image. But, it is no matter where you put P.M.M.T.
Caution ) There is the space for ROM BIOS on 0xF0000. You must not write any data on that.
// allocate one physical page pTbl = bell.pPhysRefTbl; // Physical Memory Management Table // search after 64K if( pTbl[nI] == 0 ) |
int nFreePage( DWORD dwPhysAddr ) pTbl = bell.pPhysRefTbl; pTbl[dwI]--; // Decreasing the counter value with 1 return( 1 ); |
'Programming > OS Development' 카테고리의 다른 글
VGA 관련 (0) | 2009.06.19 |
---|---|
하드 디스크 드라이버 ( Hard Disk Driver ) (0) | 2009.05.29 |
메모리 주소별 용량. (0) | 2009.05.15 |
어셈블러에서 16진수 입력 (0) | 2009.05.15 |
naked 함수 (0) | 2009.05.11 |