1. ホーム

2、ブートエリアをIPL化する

2022-04-16 03:21:59
<パス

ブート領域は最初の512バイトしか必要ないので、heloos.nasの後半を削除し、ファイル名をipl.nasに変更します。



ipl.nasの内容。

 ; hello-os
 ; TAB=4

         ORG 0x7c00 ; Specify the program load address

 The following code is specific to standard FAT32 floppy disks

         JMP entry
         DB 0x90
         DB "HELLOIPL" ; freeparam The name of the boot sector can be any string (8 bytes)
         DW 512 ; size of each sector (sector) (must be 512 bytes)
         DB 1 ; the size of the cluster (cluster) (must be 1 sector)
         DW 1 ; the starting position of the FAT (usually starting from the first sector)
         DB 2 ; Number of FATs (must be 2)
         DW 224 ; the size of the root directory (usually set to 224 items)
         DW 2880 ; the size of the disk (must be 2880 sectors)
         DB 0xf0 ; the type of disk (must be 0xf0)
         DW 9 ; the length of the FAT (must be 9 sectors)
        DW 18 ; 1 track (track) has several sectors (must be 18)
         DW 2 ; number of heads (must be 2)
         DD 0 ; no partitions used, must be 0
         DD 2880 ; rewrite the size of the disk once
         DB 0,0,0x29 ; Meaning unknown, fixed
         DD 0xffffff ; (probably) volume label number
         DB "HELLO-OS " ; name of freeparam disk (11 bytes)
         DB "FAT12 " ; disk format name (8 bytes)
         RESB 18 ; empty 18 bytes first

 ; program core

 entry:
         MOV AX,0 ; initialize register
         MOV SS,AX
         MOV SP,0x7c00 ;0x7c00 to 0x7dff is the load address of the boot area content
         MOV DS,AX ;DS must be specified as 0 because it is the default segment register and the value of the address will be added 16 times to this value

 putloop:
         MOV AL,[SI]
         ADD SI,1 ; Add 1 to SI
         CMP AL,0
         JE fin
         MOV AH,0x0e ; Display a text
         MOV BX,15 ; Specify the character color
         INT 0x10 ; Call the graphics card BIOS
         JMP putloop

 fin:
         HLT ; Stop CPU; wait for instruction
         JMP fin ; infinite loop


 msg: ; message display section
         DB 0x0a, 0x0a ; line feed 2 times
         DB "hello, world!" ; freeparam
         DB 0x0a ; line break
         DB 0

         RESB 0x7dfe-$ ; fill 0x00 until 0x001fe, to ensure that the 510th byte (i.e., the 0x1fe byte) starts at

is 55AA

         DB 0x55, 0xaa ; If the last 2 bytes of the boot area are not 0x55aa, the computer will think there is no program on the disk that needs to be started.




拡張子のないファイル "Makefile"を作成し、以下のように記述します。

default :
    ... /z_tools/make.exe img

#Make the file ipl.bin

ipl.bin : ipl.nas Makefile #To make the file ipl.bin, you need to check if the files ipl.nas and Makefile are ready first
    ... /z_tools/nask.exe ipl.nas ipl.bin ipl.lst

# Make the file helloos.img

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

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

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

run :
    ... /z_tools/make.exe img
    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


#Delete all intermediate generated files other than the final result and clean up the hard drive

clean :
    -del ipl.bin
    -del ipl.lst

#Delete all files other than the source program

src_only :
    ... /z_tools/make.exe clean
    -del helloos.img




こうすることで、asm.bat, run.bat, install.bat をすべて削除することができます。



make.exe経由でMakefileを動作させるために、make.batの中身は

... \z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9

.cons_nt.batをダブルクリックし、make_runと入力します。