我正在研究我的操作系统项目。入门代码已经跳转到长模式并设置临时页表。我现在已经设置并填充了我自己的页表,并按照我需要的方式完成了内存映射。现在我需要在 CR3 寄存器中设置 PML4T 的物理地址。
238 void setcr3(void * addr){
239 uint64_t temp=(uint64_t)addr;
240
241 __asm__ ("movq %0, %%cr3;"::"b"(temp));
242 }
这在执行该指令时崩溃。GDB一步一步附上
0x0000000000000000 in ?? ()
(gdb) b setcr3
Breakpoint 1 at 0xffffffff80201205: file sys/paging.c, line 238.
(gdb) c
Continuing.
Breakpoint 1, setcr3 (addr=0x221000) at sys/paging.c:238
238 void setcr3(void * addr){
(gdb) si
241 __asm__ ("movq %0, %%cr3;"::"b"(temp));
(gdb) si
0xffffffff80201209 241 __asm__ ("movq %0, %%cr3;"::"b"(temp));
(gdb) si
242 }
(gdb) si
Remote connection closed
(gdb)
244 #define write_cr3(x) \
245 __asm__ __volatile__("movl %0,%%cr3": :"r" (x))
Error while compiling
sys/paging.c: Assembler messages:
sys/paging.c:271: Error: unsupported instruction `mov'
编辑:
printf("address in cr3 %x\n", (uint64_t)pml4t - 0xffffffff80200000 + physbase);
setcr3( (void *) ( (uint64_t)pml4t - 0xffffffff80200000 + physbase) );
line 1 prints:
address in cr3 221000