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?

VGAレジスタの初期値ダンプと解析

Last updated at Posted at 2025-06-07

「手探りでCUI OS作成に挑む」連載

この記事は「手探りでCUI OS作成に挑む」連載の一部です。
全体の目次は「手探りでCUI OS作成に挑む」連載目次を御覧下さい。

目的

将来BIOS開発するにあたりVGAレジスタに適切な値を入れ、自力で初期化しなければなりません。
そこでBIOSを呼び出してテキストモードで初期化し、その直後のレジスタの値をダンプします。
今回はVGAの初期化まではやりません。
まだ勉強中でよく分かっておらず、初期化に失敗したので今回はダンプだけしておき、初期化は次回挑戦します。

検証コード

まずint 0x10 AH=03H(テキストモード)で初期化します。
その後順番にレジスタの値を読み出し0x2000〜へ書き込みます。

boot.bin
org 0x7C00

bits 16

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

    ; --- set text mode 03h ---
    mov ax, 0x0003
    int 0x10

    ; --- set up segment to write to 0x2000 ---
    mov ax, 0x0000
    mov es, ax
    mov di, 0x2000

    ; --- dump misc output register (read-only) ---
    in al, 0x3CC
    stosb ; [0] = MISC

    ; --- dump sequencer (5 regs) ---
    mov cx, 5
    mov bx, 0
seq_loop:
    mov dx, 0x3C4  ; index port
    mov al, bl
    out dx, al
    inc dx         ; 0x3C5
    in al, dx
    stosb
    inc bx
    loop seq_loop

    ; --- dump CRTC (25 regs) ---
    mov cx, 25
    mov bx, 0
crtc_loop:
    mov dx, 0x3D4
    mov al, bl
    out dx, al
    inc dx         ; 0x3D5
    in al, dx
    stosb
    inc bx
    loop crtc_loop

    ; --- dump graphics controller (9 regs) ---
    mov cx, 9
    mov bx, 0
gc_loop:
    mov dx, 0x3CE
    mov al, bl
    out dx, al
    inc dx         ; 0x3CF
    in al, dx
    stosb
    inc bx
    loop gc_loop

    ; --- dump attribute controller (20 regs) ---
    mov cx, 20
    mov bx, 0
ac_loop:
    in al, 0x3DA      ; reset flip-flop
    mov dx, 0x3C0
    mov al, bl
    out dx, al        ; write index
    in al, 0x3C1      ; read data
    stosb
    inc bx
    loop ac_loop   

    ; --- hang ---
    cli
hang:
    hlt
    jmp hang

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

取り出したデータの確認

nasm -f bin boot.asm -o boot.bin
qemu-system-i386 -fda boot.bin -monitor stdio
(qemu) pmemsave 0x2000 56 dump.bin
hexdump -v -C dump.bin

結果は以下のようになりました。

ubuntu@ubuntu:~/kaihatsu/test4$ hexdump -v -C dump.bin
00000000  00 03 00 03 00 02 5f 4f  50 82 55 81 bf 1f 00 4f  |......_OP.U....O|
00000010  0d 0e 00 00 00 00 9c 8e  8f 28 1f 96 b9 a3 ff 00  |.........(......|
00000020  00 00 00 00 10 0e 0f ff  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00                           |........|
00000038

これだけでは正しいか分からないですが、次回はこれらのデータを基にVGAを初期化していきます。

以下のように値が並んでいる筈です。

  • 0x0000 : MISCレジスタ値
  • 0x0001〜0x0005 : シーケンサ5レジスタ
  • 0x0006〜0x001A : CRTC 25レジスタ
  • 0x001B〜0x0023 : グラフィックスコントローラ9レジスタ
  • 0x0024〜0x0037 : アトリビュートコントローラ20レジスタ

最後の方が殆ど0なので少し嫌な気はします。

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?