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?

IRQ1(キーボード割り込み)によるHLT復帰の検証

Last updated at Posted at 2025-06-06

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

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

目的

将来のBIOS開発に備え、割り込みの基本動作を可視化して理解を深める。
一旦HLTでCPUを止め、キーボードで任意のキーを押すとPICから割り込みが発生しCPUが再び動き始める筈である。
TESTの文字が画面に表示されることで、割り込みが発生したことを目視で確認できる。

検証コード

起動直後に他の割り込みが発生し、HLTで止まったままにならず、すぐに再開してしまうのを防ぐため、IRQ1(キーボード)のみを有効にした。

org 0x7C00
bits 16

    xor ax, ax
    mov ds, ax
    mov ss, ax
    mov sp, 0x7C00
    
    ; 0xFD = 11111101(IRQ1のみ0にする。0:有効 1:無効)
    mov al, 0xFD     
    out 0x21, al

    sti
    hlt

    mov si, teststr
    call print_string

    jmp $

print_string:
    push ax
    mov ah, 0x0E
.print_loop:
    lodsb
    or al, al
    jz .done
    int 0x10
    jmp .print_loop
.done:
    pop ax
    ret
    
teststr db 'TEST',0x0D,0x0A,0

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

動作確認

コンパイルしてコンパクトフラッシュへ書き込む

nasm -f bin boot.asm -o boot.bin
sudo dd if=boot.bin of=/dev/sdc bs=512 count=1 conv=notrunc

どうしてもGIFのアップロードに失敗するので写真を貼る。
始めは何も表示されておらず適当なキーを押すと割り込みが発生してHLTを抜けることが確認できた。

起動直後
9aadb475b24b1ee8906702b8d3a740d.jpg
キー押下後(TESTが表示され、HLTから復帰した)
5703a365de34f051c0569bdae02c9a0.jpg

最後に

今後はIVTを変更し割り込みの処理も自分で実装する予定

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?