VESA模式,操作系统开发

3

我目前正在从头开始编写操作系统(包括制作自己的引导程序等),并尝试适应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。

以上代码是16位而不是32位。 - phuclv
1个回答

1
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分配给段。
远指针以字大小的偏移量和字大小的段存储在内存中。
偏移量存储在vbe_info_block.video_modes,段存储在下一个字中,其地址比前一个字高2,因此在[vbe_info_block.video_modes + 2]处。
mov dx, [fs:si]
add si, 2
mov [.offset], si
我们并没有将偏移量和段落赋值给DX寄存器!
我们检索到的远指针(并放置在FS:SI中)指向一个字大小的模式号列表。我们加载模式号到DX寄存器中。而"add si, 2" 和 "mov [.offset], si"是为了使循环能够遍历列表中的所有单词。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接