Skip to content

Instantly share code, notes, and snippets.

@7shi
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7shi/9848017 to your computer and use it in GitHub Desktop.
Save 7shi/9848017 to your computer and use it in GitHub Desktop.
NetBSD/i386 6.0.1のブートをトレース

スタート低レイヤー #6 発表資料(未完)

COM(シリアルポート)版の起動ディスク(boot-com1~5.fs)
http://ftp.jp.netbsd.org/pub/NetBSD/NetBSD-6.0.1/i386/installation/floppy/

VRAMのエミュレートが面倒なのでシリアルポート版を使用

ディスクイメージの作成箇所

build.sh releaseで作られる個所をmaster_qさんに教えていただきました。

とりあえず起動してみる

作りかけのエミュレータ: 80386run

$ ./80386run.exe boot-com1.fs
(snip)
00007C3E  31C9              xor cx,cx
00007C40  8ED1              mov ss,cx
00007C42  89CC              mov sp,cx
00007C44  8EC1              mov es,cx
00007C46  663D21475054      cmp eax,0x54504721
00007C4C  0F840E01          jz word 0x7d5e
00007C50  8ED9              mov ds,cx
00007C52  31C0              xor ax,ax
00007C54  52                push dx
00007C55  CD13              int 0x13
00007C57  5A                pop dx
00007C58  41                inc cx
00007C59  88EE              mov dh,ch
00007C5B  E8F700            call word 0x7d55
 AX   BX   CX   DX   SP   BP   SI   DI    FLAGS    ES   SS   DS   CS   IP  dump
0000 0000 0000 0000-0000 0000 0000 0000 -----Z-P- 0000 0000 0000 0000:7c46 663d
not implemented: 663d21

32bit命令の実装にまで手が回っていないためブートセクタで撃沈

逆アセンブルは自前ではなくndisasmを使っている

ソースを探す

逆アセンブルからコードを特定

[TODO] やたらに色々なブートコードがあるのは何?

sys/arch/i386/stand/bootxx/pbr.S

落ちた箇所

#ifndef BOOT_FROM_FAT
	cmpl	$0x54504721, %eax	/* did a GPT hybrid MBR start us? */
	je	boot_gpt
#endif

GPTかどうかのチェックをしているらしい

BIOSでマジックナンバーがセットされるというプロトコル

今後

  • GDT/IDTの具体的な値をセットする所までトレースしたい。
  • OSを起動させる所までは目指していない。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment