繁体   English   中英

VESA 模式,OSDEV

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM