the virtual address points to the wrong physical address!
Posted: Mon Jul 05, 2021 7:18 am
Hi:
I developed a os, in one user process,I had loaded cr3 register in the corresponding kernel thread,the code is follow:
here is the code which I use 'info tab' in the Bochs
everything is as I expected,but when the code write data to the '804b000' virtual address,it always write into '0x000010109000' physical address, not the '0x00001010a000'.
I don't know why, could anyone help me, thanks a lot!
I developed a os, in one user process,I had loaded cr3 register in the corresponding kernel thread,the code is follow:
Code: Select all
/* 激活页表 */
void page_dir_activate(struct task_struct* p_thread) {
/********************************************************************
* 执行此函数时,当前任务可能是线程
* 之所以对线程也要重新安装页表,原因是上一次被调度的可能是进程,
* 否则不恢复页表的话,线程就会使用进程的页表了。
* *****************************************************/
/* 若为内核线程,需要重新填充页表为 0x100000 */
uint32_t pagedir_phy_addr = 0x100000; // 默认为内核的页目录物理地址,也就是内核线程所用的页目录表
if(p_thread->pgdir != NULL) { // 用户态进程有自己的页目录表
pagedir_phy_addr = addr_v2p((uint32_t)p_thread->pgdir);
}
/* 更新页目录寄存器 cr3, 使新页表生效 */
asm volatile ("movl %0, %%cr3" : : "r" (pagedir_phy_addr) : "memory");
}
Code: Select all
<bochs:25> info tab
cr3: 0x00000025a000
0x0000000008048000-0x0000000008049fff -> 0x000010105000-0x000010106fff
0x000000000804a000-0x000000000804afff -> 0x000010108000-0x000010108fff
0x000000000804b000-0x000000000804bfff -> 0x00001010a000-0x00001010afff
0x00000000080a0000-0x00000000080a0fff -> 0x000010109000-0x000010109fff
0x00000000bffff000-0x00000000bfffffff -> 0x000010107000-0x000010107fff
0x00000000c0000000-0x00000000c00fffff -> 0x000000000000-0x0000000fffff
0x00000000c0100000-0x00000000c011dfff -> 0x000000200000-0x00000021dfff
0x00000000c011e000-0x00000000c0138fff -> 0x000000220000-0x00000023afff
0x00000000c0139000-0x00000000c013dfff -> 0x00000023d000-0x000000241fff
0x00000000c013f000-0x00000000c0156fff -> 0x000000243000-0x00000025afff
0x00000000ffc20000-0x00000000ffc20fff -> 0x00000025b000-0x00000025bfff
0x00000000ffeff000-0x00000000ffefffff -> 0x00000025c000-0x00000025cfff
0x00000000fff00000-0x00000000ffffefff -> 0x000000101000-0x0000001fffff
0x00000000fffff000-0x00000000ffffffff -> 0x00000025a000-0x00000025afff
<bochs:26>
I don't know why, could anyone help me, thanks a lot!