长模式1GB分页

时间:2018-08-04 08:41:38

标签: assembly x86-64 paging

我想在长模式下使用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位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崩溃了。

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

1 个答案:

答案 0 :(得分:0)

嗯,prl是对的。我已经通过16384替换了2 ^ 14,并且能够将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并重新启动)

因此,这很容易解决。