页面错误后重新启动指令
我正在用 C 语言开发一个操作系统,但我在分页方面遇到了困难。我通过分配内存并输出处理物理和虚拟页面分配的低级内存分配输出来循环测试我的内核堆。
当 PDE 0
时,页面 0-1023
一切正常,但一旦分配移动到 PDE 1
,就会引发页面错误当前标志设置,如果我从不同的物理地址开始分配,有时也会设置 rw 标志。
我是否需要从 cr2
获取错误地址并将其映射回 PDE
及其所属页面,然后将地址设置为 3?之后我需要重新启动指令,但我该怎么做呢?有什么建议吗?
I'm developing an operating system in C and I'm struggling on paging. I'm testing my kernel heap in a loop by allocating memory and outputting the low level memory allocation output that handles physical and virtual page allocation.
When PDE 0
, everything works great for pages 0-1023
but as soon as the allocation moves to PDE 1
, a page fault is raised with the present flag set, and sometimes the rw
flag too if I start allocating from a different physical address.
Do I need to get the faulting address from cr2
and map it back to the PDE
and page it belongs to and then set or the address with 3? After that I need to restart the instruction but how do I do that? Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
页面错误是一种错误异常,这意味着处理器直接调用页面错误处理程序,就像发生中断一样。
处理完页面错误并希望返回调用者后,您需要通过 IRET 指令从错误中返回。这会将代码段、eflags 寄存器和 EIP(如果故障来自环 3,则可能还包括用户模式 SS 和 ESP)返回到触发故障的指令。
Page Fault is a fault exception, which means your page-fault handler is called directly by the processor as if an interrupt occurred.
After you have serviced the page-fault and would like to go back to the caller, you need to return from the fault via the IRET instruction. This will return the code-segment, eflags register and EIP (and potentially the user-mode SS and ESP if the fault was from ring 3) back to the instruction that triggered the fault.