文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>i386中线性地址到物理地址的转换

i386中线性地址到物理地址的转换

时间:2005-12-05  来源:rwen2012

介绍其转换过程
//la--linear address, pa -- physical address 
//以下片断实现i386中线性地址到物理地址的转换
// 下图为页地址的格式:
// 10bits 10bits 12bits
// ||----dir----||-----page-----||-------offset--------||

//其中CR3为页目录基址寄存器

uint translate (uint la, bool user, bool write)
{
uint pde;
pde = read_mem (%CR3 + 4*(la >> 22)); //页目录基址+目录偏移量(在最高10位), 乘4是因为每项为4个字节大小
access (pde, user, read);
pte = read_mem ( (pde & 0xfffff000) + 4*((la >> 12) & 0x3ff)); //页表基址+页表项偏移量(中间10位),得到的pte为所在页的位置
access (pte, user, read);
return (pte & 0xfffff000) + (la & 0xfff); //最终得到页面中的地址偏移量
}

// check protection. pxe is a pte or pde.
// user is true if CPL==3
//页表项的低12位记录着相关的一些读写信息,实现保护机制
void
access (uint pxe, bool user, bool write)
{
if (!(pxe & PG_P) //存在位
=> page fault -- page not present
if (!(pxe & PG_U) && user) // U/S位--用户或超级用户位
=> page fault -- not access for user

if (write && !(pxe & PG_W)) //读写位
if (user)
=> page fault -- not writable
else if (!(pxe & PG_U))
=> page fault -- not writable
else if (%CR0 & CR0_WP)
=> page fault -- not writable
}
相关阅读 更多 +
排行榜 更多 +
坦克冒险大师安卓版

坦克冒险大师安卓版

策略塔防 下载
自动防御

自动防御

策略塔防 下载
枪战大乱斗2

枪战大乱斗2

飞行射击 下载