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?

ブートローダーから第二セクタへ跳ぶ

Posted at

プログラム

boot.asm
[org 0x7C00]
[bits 16]

    xor ax, ax
    mov ds, ax     ; データセグメントを0に初期化
    mov es, ax     ; 追加セグメントも0に初期化

    mov ss, ax
    mov sp, 0x7C00

    ; 第2セクタを0x7E00番地に読み込む
    mov ah, 0x02   ; BIOSのディスク読み込み機能
    mov al, 1      ; 1セクタ分読み込む
    mov ch, 0      ; シリンダ0
    mov cl, 2      ; セクタ2
    mov dh, 0      ; ヘッド0
    mov bx, 0x7E00 ; 読み込み先のメモリアドレス
    int 0x13       ; BIOSのディスクサービスを呼び出す

    jc disk_error  

    jmp 0x7E00     ; 2つ目のセクタへ跳ぶ

disk_error:
    mov si, error_msg
    call print_string
    jmp $

print_string:
    lodsb
    or al, al
    jz .done
    mov ah, 0x0E
    int 0x10
    jmp print_string
.done:
    ret

error_msg db "Disk read error!", 0  ; 表示するエラーメッセージ(0で終端)

times 510-($-$$) db 0
dw 0xAA55
stage2.asm
[org 0x7E00]
[bits 16]

    mov si, msg
    call print_string
    jmp $

print_string:
    lodsb
    or al, al
    jz .done
    mov ah, 0x0E
    int 0x10
    jmp print_string
.done:
    ret

msg db "Hello from stage2!", 0

times 512 db 0
nasm -f bin boot.asm -o boot.bin        ## コンパイル
nasm -f bin stage2.asm -o stage2.bin    ## コンパイル
cat boot.bin stage2.bin > os-image.bin  ## 結合

sudo dd if=os-image.bin of=/dev/sdc bs=512 count=2 conv=notrunc ## CFカードに書き込み
sync

8086実機で動かす為にCFカードに書き込みました。
image.png

動作確認

image.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?