たなしょのメモ

日々勉強していることをつらつらと

OS作成奮闘記day2

二日目もアセンブラを書くところからスタートです。
MOV命令やHLT命令などを詳しく学習しました。
以下はその際記載したソース

; hello-os
; TAB=4

        ORG     0x7c00

; FAT12 foramt floppy

        JMP     entry
        DB      0x90
        DB      "HELLOTPL"
        DW      512
        DB      1
        DW      1
        DB      2
        DW      224
        DW      2880
        DB      0xf0
        DW      9
        DW      18
        DW      2
        DD      0
        DD      2880
        DB      0,0,0x29
        DD      0xffffffff
        DB      "HELLO-OS   "
        DB      "FAT12   "
        RESB    18

; program

entry:
        MOV     AX,0
        MOV     SS,AX
        MOV     SP,0x7c00
        MOV     DS,AX
        MOV     ES,AX

        MOV     SI,msg
putloop:
        MOV     AL,[SI]
        ADD     SI,1
        CMP     AL,0
        JE      fin
        MOV     AH,0x0e
        MOV     BX,15
        INT     0x10
        JMP     putloop
fin:
        HLT
        JMP     fin

; message
msg:
        DB      0x0a, 0x0a
        DB      "hello, world3"
        DB      0x0a
        DB      0

        RESB    0x7dfe-$

        DB      0x55, 0xaa

; boot sector

        DB      0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00
        RESB    4600
        DB      0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00
        RESB    1469432

0x00007c00-oxoooo7dffはブートセクタが読み込まれたアドレスらしいです。
だから0x7c00を指定しているのか。
helloos4では各種バッチファイルをいじってosを作りました。
ipl.nasというアセンブラソースファイルを作りました。helloos.nasとの違いはboot sectorの部分がないことです。
makefileを作成してさらに使いやすくしました。

# file making rule

default:
    ..\..\z_tools\make.exe img

ipl.bin : ipl.nas Makefile
    ..\..\z_tools\nask.exe ipl.nas ipl.bin ipl.lst

helloos.img : ipl.bin Makefile
    ..\..\z_tools\edimg.exe imgin:..\..\z_tools\fdimg0at.tek \
        wbinimg src:ipl.bin len:512 from:0 to:0 imgout:helloos.img

img :
    ..\..\z_tools\make.exe -r helloos.img

asm :
    ..\..\z_tools\make.exe -r ipl.bin

run :
    ..\..\z_tools\make.exe img
    cmd.exe /C copy helloos.img ..\..\z_tools\qemu\fdimage0.bin
    ..\..\z_tools\make.exe -C ..\..\z_tools\qemu

install :
    ..\..\z_tools\make.exe img
    ..\..\z_tools\imgtol.com w a: helloos.img

clean :
    rm -f ipl.bin
    rm -f ipl.lst

src_only :
    make clean
    rm -f helloos.img

途中meke runコマンドで下記エラーが出てしまい苦労しました。

copy helloos.img ..\..\z_tools\qemu\fdimage0.bin
process_begin: CreateProcess((null), copy helloos.img ..\..\z_tools\qemu\fdimage0.bin, ...) failed.
make (e=2): 指定されたファイル
が見つかりません。
..\..\z_tools\make.exe: *** [run] Error 2

この記事をみてソースを修正しました。

cmd.exe /C copy helloos.img ..\..\z_tools\qemu\fdimage0.bin

原因は恐らくgitbashとwindowsのcopyコマンドが干渉しているからかなと思います。
要するにディレクトリから直接batファイルたたけば書籍に書かれているソースでも問題なく叩けたのかなと思います。

day2のgithubのコミットログはありません。ごめんなさい。