fasm完成一个简单的FAT12的镜像文件

 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,0ffh

FATEntrySize = $-FATEntry

db 9*512-FATEntrySize dup(0)    ;FAT1 01~09号扇区

;-----------------------------------------------------------------------
;FAT table 2
;-----------------------------------------------------------------------
db 00h,00h,00h,0ffh,0fh

db 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 Byte

db 14*512-RootDirSize  dup(0)

;-----------------------------------------------------------------------
;Data Region
;-----------------------------------------------------------------------
LOADER:
file 'loader.bin'               ;34号扇区
LOADERSIZE = $-LOADER

db (2880-1-9-9-14)*512 -LOADERSIZE dup (0)
;-----------------------------------------------------------------------


效果(日期随便设置一下):

fasm完成一个简单的FAT12的镜像文件_第1张图片

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,0ffh

FATEntrySize = $-FATEntry

db 9*512-FATEntrySize dup(0)    ;FAT1 01~09号扇区

;-----------------------------------------------------------------------
;FAT table 2
;-----------------------------------------------------------------------
db 00h,00h,00h,0ffh,0fh

db 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 Byte

db 14*512-RootDirSize  dup(0)

;-----------------------------------------------------------------------
;Data Region
;-----------------------------------------------------------------------
LOADER:
file 'loader.bin'               ;33号扇区
LOADERSIZE = $-LOADER

db (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
;占用扇区7
db 00h,00h,00h,03h,40h,00h,05h,60h,00h,0ffh,0ffh,0ffh

FATEntrySize = $-FATEntry1

db 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+%-1
end repeat

db 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 LOADERSIZE1


RootDir2:                       ;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,6
LOADERSIZE1 = $-LOADER1

LOADER2:
file 'EXAMPLE1.X3D'             ; *号扇区 ;69字节 扇区7
LOADERSIZE2 = $-LOADER2

db (2880-1-18-14)*512 -($-LOADER1) dup (0)
;-----------------------------------------------------------------------



 

你可能感兴趣的:(vmware,image,File,table,System,byte)