1
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系CPUでのアセンブリによるPC再起動の検証

Posted at

目的

Linux0.01のソースを読んでいるとアセンブリ言語で書かれたPC再起動の処理を発見しました。
0x64番ポートに0xfcを送信するとCPUを再起動出来る様なので試してみます。

linux-0.01/blob/master/kernel/keyboard.s

keyboard.s
; 前略

reboot:
	call kb_wait
	movw $0x1234,0x472	/* don't do memory check */
	movb $0xfc,%al		/* pulse reset and A20 low */
	outb %al,$0x64

前回アセンブリでパソコンを再起動させる記事を書いたことがありますが、これはCPUをFFFF0h(CPUに電源を投入した時、初めに実行される場所)からもう一度実行しなおすだけのもので、本当の意味での再起動ではありませんでした。
https://qiita.com/earthen94/items/fcc6ed1cb4645bb22368

検証用のブートセクタ

test@test-fujitsu:~/kaihatsu/reboot$ nasm -f bin boot.asm -o boot.bin
test@test-fujitsu:~/kaihatsu/reboot$ qemu-system-x86_64 -drive format=raw,file=boot.bin
boot.asm
[ORG 0x7C00]

BITS 16

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

    call reboot       ; 再起動

; 再起動失敗
hltloop: 
    hlt
    jmp hltloop

; 再起動
reboot:
    mov  word [0x472], 0x1234  ; 再起動時にBIOSへメモリの動作点検を跳ばさせる
    mov  al, 0xFC              ; 再起動命令
    out  0x64, al
    ret

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

動作確認

書き込み

lsblk
sudo dd if=boot.bin of=/dev/sdb bs=512 count=1 conv=notrunc
sync

QEMU上での動作

qemu-system-x86_64 -drive format=raw,file=boot.bin

output.gif

ThinkPad X280上での動作

USBから起動すると即座にパソコンが再起動しました。

a242e9acd73788.jpg
4766ea209e28c.jpg

8086互換CPU(V30)上での動作

この画面で固まり、再起動しませんでした。
元のLinux0.01nのようにkb_waitを省略せずに書いて実行しても結果は同じでした。

3f95f55e823f08.jpg

1
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
1
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?