fasm完成一個簡單的FAT12的鏡像檔案,方便裸機編程,以自己動手寫作業系統的FAT12布局為例。
;-----------------------------------------------------------------------;--===-- FAT12 image file make By G-Spider;--===-- fasm startOS.asm startOS.img;-----------------------------------------------------------------------; here is map of how the FAT12 system is laid out ;|----------------------------------------------------------------------| ;|BootSector| FAT table 1| FAT table 2 | Root Directory| Data Region | ;|512 bytes | 4,608 bytes| 4,608 bytes | 7,168 bytes | 1,457,664 bytes| ;|1 sector | 9 sectors | 9 sectors | 14 sectors | 2,847 sectors | ;|______________________________________________________________________| ;-----------------------------------------------------------------------;BootSector;-----------------------------------------------------------------------file 'myboot.bin' ;0號扇區 512Byte;-----------------------------------------------------------------------;FAT table 1;-----------------------------------------------------------------------FATEntry:db 00h,00h,00h,0ffh,0fh ;有效位 奇:0ffh,0fh 偶:0f0h,0ffhFATEntrySize = $-FATEntrydb 9*512-FATEntrySize dup(0) ;FAT1 01~09號扇區;-----------------------------------------------------------------------;FAT table 2;-----------------------------------------------------------------------db 00h,00h,00h,0ffh,0fhdb 9*512-FATEntrySize dup(0) ;FAT2 10~18號扇區;-----------------------------------------------------------------------;Root Directory;-----------------------------------------------------------------------RootDir: ;19號扇區 .Name db "LOADER BIN" .Attr db 20h .Reserved db 0,0,0,0,0,0,0,0,0,0 .WrtTime dw 7a5bh .WrtDate dw 3185h .FstClus dw 0002h ;開始簇號2 (對應FAT table 1的第3位元組處) .FileSize dd 0000000fh ;loader.bin檔案大小RootDirSize =$-RootDir ;32 Bytedb 14*512-RootDirSize dup(0);-----------------------------------------------------------------------;Data Region;-----------------------------------------------------------------------LOADER:file 'loader.bin' ;34號扇區LOADERSIZE = $-LOADERdb (2880-1-9-9-14)*512 -LOADERSIZE dup (0);-----------------------------------------------------------------------
效果(日期隨便設定一下):
vmware載入效果:
升級一下:
;-----------------------------------------------------------------------;--===-- FAT12 image file make By G-Spider;--===-- fasm startOS.asm startOS.img;-----------------------------------------------------------------------; here is map of how the FAT12 system is laid out ;|----------------------------------------------------------------------| ;|BootSector| FAT table 1| FAT table 2 | Root Directory| Data Region | ;|512 bytes | 4,608 bytes| 4,608 bytes | 7,168 bytes | 1,457,664 bytes| ;|1 sector | 9 sectors | 9 sectors | 14 sectors | 2,847 sectors | ;|______________________________________________________________________| struc _DATA def{ match d1=,d2=,d3, def \{ .Data dw ((d1-1980) shl 9) or ((d2 and 0fh) shl 5) or (d3 and 1fh) \} }struc _TIME def{ match d1:d2:d3, def \{ .Data dw (d1 shl 11) or ((d2 and 3fh) shl 5) or ((d3 and 0fh) shr 1) \} };-----------------------------------------------------------------------;BootSector;-----------------------------------------------------------------------file 'boot.bin' ;0號扇區 512Byte;-----------------------------------------------------------------------;FAT table 1;-----------------------------------------------------------------------FATEntry:db 00h,00h,00h,0ffh,0fh ;有效位 奇:0ffh,0fh 偶:0f0h,0ffhFATEntrySize = $-FATEntrydb 9*512-FATEntrySize dup(0) ;FAT1 01~09號扇區;-----------------------------------------------------------------------;FAT table 2;-----------------------------------------------------------------------db 00h,00h,00h,0ffh,0fhdb 9*512-FATEntrySize dup(0) ;FAT2 10~18號扇區;-----------------------------------------------------------------------;Root Directory;-----------------------------------------------------------------------RootDir: ;19號扇區 .Name db "EXAMPLE COM" .Attr db 20h .Reserved db 0,0,0,0,0,0,0,0,0,0 .WrtTime _TIME <15:56:12> .WrtDate _DATA <2011,10,26> .FstClus dw 0002h ;開始簇號2 (對應FAT table 1的第3位元組處) .FileSize dd LOADERSIZE ;loader.bin檔案大小RootDirSize =$-RootDir ;32 Bytedb 14*512-RootDirSize dup(0);-----------------------------------------------------------------------;Data Region;-----------------------------------------------------------------------LOADER:file 'loader.bin' ;33號扇區LOADERSIZE = $-LOADERdb (2880-1-9-9-14)*512 -LOADERSIZE dup (0);-----------------------------------------------------------------------
再升級一下:
;-----------------------------------------------------------------------;--===-- FAT12 image file make By G-Spider;--===-- fasm startOS.asm startOS.img;-----------------------------------------------------------------------; here is map of how the FAT12 system is laid out ;|----------------------------------------------------------------------| ;|BootSector| FAT table 1| FAT table 2 | Root Directory| Data Region | ;|512 bytes | 4,608 bytes| 4,608 bytes | 7,168 bytes | 1,457,664 bytes| ;|1 sector | 9 sectors | 9 sectors | 14 sectors | 2,847 sectors | ;|______________________________________________________________________| struc _DATA def{ match d1=,d2=,d3, def \{ .Data dw ((d1-1980) shl 9) or ((d2 and 0fh) shl 5) or (d3 and 1fh) \} }struc _TIME def{ match d1:d2:d3, def \{ .Data dw (d1 shl 11) or ((d2 and 3fh) shl 5) or ((d3 and 0fh) shr 1) \} };-----------------------------------------------------------------------;BootSector;-----------------------------------------------------------------------file 'BOOTER.SYS' ;0號扇區 512Byte;-----------------------------------------------------------------------;FAT table 1;-----------------------------------------------------------------------FATEntry1:;db 00h,00h,00h,0ffh,0fh ;有效位 奇:0ffh,0fh 偶:0f0h,0ffh;佔用5個扇區2,3,4,5,6;佔用扇區7db 00h,00h,00h,03h,40h,00h,05h,60h,00h,0ffh,0ffh,0ffhFATEntrySize = $-FATEntry1db 9*512-FATEntrySize dup(0) ;FAT1 01~09號扇區;-----------------------------------------------------------------------;FAT table 2;-----------------------------------------------------------------------FATEntry2: rb FATEntrySize repeat FATEntrySize load a byte from FATEntry1+%-1 store byte a at FATEntry2+%-1end repeatdb 9*512-FATEntrySize dup(0) ;FAT1 10~18號扇區;-----------------------------------------------------------------------;Root Directory 根目錄;-----------------------------------------------------------------------RootDir1: ;19號扇區 .Name db "SYSTEM SYS" .Attr db 20h .Reserved db 0,0,0,0,0,0,0,0,0,0 .WrtTime _TIME <21:06:12> .WrtDate _DATA <2011,10,27> .FstClus dw 0002h ;開始簇號2 (對應FAT table 1的第3位元組處) .FileSize dd LOADERSIZE1RootDir2: ;19號扇區 .Name db "EXAMPLE1X3D" .Attr db 20h .Reserved db 0,0,0,0,0,0,0,0,0,0 .WrtTime _TIME <21:06:12> .WrtDate _DATA <2011,10,27> .FstClus dw 0007h ;開始簇號7 .FileSize dd LOADERSIZE2 db 14*512-($-RootDir1) dup(0);-----------------------------------------------------------------------;Data Region;-----------------------------------------------------------------------LOADER1:file 'SYSTEM.SYS' ;33號扇區 ;2347位元組 佔用5個扇區2,3,4,5,6LOADERSIZE1 = $-LOADER1LOADER2:file 'EXAMPLE1.X3D' ; *號扇區 ;69位元組 扇區7LOADERSIZE2 = $-LOADER2db (2880-1-18-14)*512 -($-LOADER1) dup (0);-----------------------------------------------------------------------