首页 > 解决方案 > 长模式 1GB 分页

问题描述

我想在长模式下使用 1GB 页面,因为 4KB/2MB 让事情变得比我需要的更复杂。所以我只是从 OSDev 复制了这个例子: https ://wiki.osdev.org/Entering_Long_Mode_Directly

这在 VirtualBox 上运行良好。然后我尝试按照 AMD64 手册第 2 卷第 137 页中的说明进行操作:https: //support.amd.com/TechDocs/24593.pdf ,带有 2 个分页表

(是的,我检查了 cpuid 8000_0001h /EDX bit 26)

%define PAGE_PRESENT    (1 << 0)
%define PAGE_WRITE      (1 << 1)
%define PS_BIT      (1<<7)
;1GB Pages avec 2 tables
; Build the Page Map Level 4.
; di points to the Page Map Level 4 table.
lea eax, [di + 0x1000]         ; Put the address of the Page Directory Pointer Table in to EAX.
or eax, PAGE_PRESENT | PAGE_WRITE ; Or EAX with the flags - present flag, writable flag.
mov [di], eax                  ; Store the value of EAX as the first PML4E.

lea di, [di + 0x1000]             
mov eax, PAGE_PRESENT | PAGE_WRITE | PS_BIT    ; Move the flags into EAX - and point it to 0x0000.
mov ebx,0
mov ecx,512

; Build the Page Table.
.LoopPageTable:
mov [di], eax
add di,2
mov [di],ebx
add ebx,2^14 ;so this adds 1GB(2^30) to the table entry
add di, 6
loop .LoopPageTable

;continue Enter long mode.

但现在 VirtualBox 崩溃了。

我希望有人可以在这里帮助我:) 等待。

标签: assemblyx86-64paging

解决方案


好吧,prl 是对的。我已经将 2^14 替换为 16384,并且能够将 jmp 转换为 64 位代码。非常感谢您

彼得也是对的,VirtualBox 然后崩溃了

[BITS 64]      
LongMode:
mov ax, DATA_SEG
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax

; Blank out the screen to a blue color.
mov edi, 0xB8000
mov rcx, 500                      ; 500=80*25*2/8
mov rax, 0x1F201F201F201F20       ; Set the value to set the screen to: Blue background, white foreground, blank spaces.

尝试“rep stosq”时它崩溃了

rep stosq  
hlt

©osdev.org

我不知道为什么,但是在使用我的计算机时它可以工作(将字节码复制到 USB 并重新启动)

所以谢谢你的时间,这已经解决了。


推荐阅读