0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

x86 VBEのVRAM開始アドレスを調べる

0
Last updated at Posted at 2026-08-25

VBEを研究しています。VRAMがVGAのように固定ではなく、BIOSから返ってくる値を使用するようなので、VRAMの開始アドレスを調べるプログラムを書きました。

VBE800×600 24bpp表示
自作OS Windowを表示する為の準備

nasm -f bin boot.asm -o boot.bin
qemu-system-i386 -fda boot.bin
boot.asm
[org 0x7C00]
bits 16

start:
    cli
    xor ax, ax
    mov es, ax
    mov ds, ax
    mov es, ax
    mov ss, ax
    mov sp, 0x7C00
    sti

    ; CS=0x0000,IP=0x7C00へ設定
    jmp 0x0000:real_start
real_start:

    mov ax, 0x4F01
    mov cx, 0x115          ; 聞きたいモード
    mov di, modeinfo       ; リアルモード下のオフセット(1MB 内)
    int 0x10

    ; 表示の為にMODE3へ戻す
    mov ax, 0x0003
    int 0x10
    
    mov eax, [modeinfo + 0x28]   ; EAX = VRAM 物理アドレス
    
    call print_eax_hex

hang:
    cli
    hlt
    jmp hang
    
print_eax_hex:
    pusha
    mov edi, 0xB8000     ; テキストVRAM
    mov ecx, 8           ; EAXは32bit = 8桁
.loop:
    rol eax, 4           ; 上位4ビットを下位へ
    mov bl, al
    and bl, 0x0F
    cmp bl, 10
    jl .digit
    add bl, 'A' - 10
    jmp .store
.digit:
    add bl, '0'
.store:
    mov [edi], bl
    inc edi
    mov byte [edi], 0x07 ; 文字属性
    inc edi
    loop .loop
    popa
    ret
    
; BIOSの返り値分の44バイト確保
modeinfo: resb 0x2C

times 510-($-$$) db 0
dw 0xAA55

图片.png

大連出張中で記事が雑になっています。今後への備忘録です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?