[英]VESA mode, OSDEV
我目前正在從頭開始編寫操作系統(制作我自己的引導加載程序等),並且我正在嘗試適應 VESA 模式。 我已經閱讀了文檔,這一切都很有意義..除了幾件事之外。
這直接來自文檔(我的實現方式不同):
vbe_set_mode:
mov [.width], ax
mov [.height], bx
mov [.bpp], cl
sti
push es ; some VESA BIOSes destroy ES, or so I read
mov ax, 0x4F00 ; get VBE BIOS info
mov di, vbe_info_block
int 0x10
pop es
cmp ax, 0x4F ; BIOS doesn't support VBE?
jne .error
mov ax, word[vbe_info_block.video_modes]
mov [.offset], ax
mov ax, word[vbe_info_block.video_modes+2]
mov [.segment], ax
mov ax, [.segment]
mov fs, ax
mov si, [.offset]
.find_mode:
mov dx, [fs:si]
add si, 2
mov [.offset], si
mov [.mode], dx
mov ax, 0
mov fs, ax
cmp [.mode], 0xFFFF ; end of list?
je .error
push es
mov ax, 0x4F01 ; get VBE mode info
mov cx, [.mode]
mov di, mode_info_block
int 0x10
pop es
cmp ax, 0x4F
jne .error
mov ax, [.width]
cmp ax, [mode_info_block.width]
jne .next_mode
mov ax, [.height]
cmp ax, [mode_info_block.height]
jne .next_mode
mov al, [.bpp]
cmp al, [mode_info_block.bpp]
jne .next_mode
; If we make it here, we've found the correct mode!
mov ax, [.width]
mov word[vbe_screen.width], ax
mov ax, [.height]
mov word[vbe_screen.height], ax
mov eax, [mode_info_block.framebuffer]
mov dword[vbe_screen.physical_buffer], eax
mov ax, [mode_info_block.pitch]
mov word[vbe_screen.bytes_per_line], ax
mov eax, 0
mov al, [.bpp]
mov byte[vbe_screen.bpp], al
shr eax, 3
mov dword[vbe_screen.bytes_per_pixel], eax
mov ax, [.width]
shr ax, 3
dec ax
mov word[vbe_screen.x_cur_max], ax
mov ax, [.height]
shr ax, 4
dec ax
mov word[vbe_screen.y_cur_max], ax
; Set the mode
push es
mov ax, 0x4F02
mov bx, [.mode]
or bx, 0x4000 ; enable LFB
mov di, 0 ; not sure if some BIOSes need this... anyway it doesn't hurt
int 0x10
pop es
cmp ax, 0x4F
jne .error
clc
ret
.next_mode:
mov ax, [.segment]
mov fs, ax
mov si, [.offset]
jmp .find_mode
.error:
stc
ret
.width dw 0
.height dw 0
.bpp db 0
.segment dw 0
.offset dw 0
.mode dw 0
我感到困惑的是,為什么它將段分配給視頻模式指針加2? 我知道視頻模式指針有一個偏移量:段,但我只是對為什么我們將視頻模式指針 + 2 分配給段以及為什么在我們將偏移量和段分配給dx
寄存器后將si
加 2 感到困惑.
mov ax, word[vbe_info_block.video_modes] mov [.offset], ax mov ax, word[vbe_info_block.video_modes+2] mov [.segment], ax
為什么它將段分配給視頻模式指針加2? 我知道視頻模式指針有一個偏移量:段,但我只是對為什么我們將視頻模式指針 + 2 分配給段感到困惑
遠指針存儲在 memory 中,字長偏移后跟字長段。
偏移量存儲在vbe_info_block.video_modes中,段存儲在地址多 2 個的后面的字中,所以在[vbe_info_block.video_modes + 2]
mov dx, [fs:si] add si, 2 mov [.offset], si
以及為什么我們在將偏移量和段分配給
dx
寄存器之后將si
加 2。
我們不會將偏移量和段分配給DX
寄存器!
我們檢索到的遠指針(並放入FS:SI
)指向一個字大小的模式編號列表。 這是我們在DX
寄存器中加載的模式編號。 並且add si, 2
mov [.offset], si
在那里,因此循環可以遍歷列表中的所有單詞。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.