123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- org 0x7c00
- BaseOfStack equ 0x7c00
- BaseOfLoader equ 0x1000
- OffsetOfLoader equ 0x00
- RootDirSectors equ 14
- SectorNumOfRootDirStart equ 19
- SectorNumOfFAT1Start equ 1
- SectorBalance equ 17
- jmp short Label_Start
- nop
- BS_OEMName db 'DragonOS'
- BPB_BytesPerSec dw 512
- BPB_SecPerClus db 1
- BPB_RsvdSecCnt dw 1
- BPB_NumFATs db 2
- BPB_RootEntCnt dw 224
- BPB_TotSec16 dw 2880
- BPB_Media db 0xf0
- BPB_FATSz16 dw 9
- BPB_SecPerTrk dw 18
- BPB_NumHeads dw 2
- BPB_HiddSec dd 0
- BPB_TotSec32 dd 0
- BS_DrvNum db 0
- BS_Reserved1 db 0
- BS_BootSig db 0x29
- BS_VolID dd 0
- BS_VolLab db 'boot loader'
- BS_FileSysType db 'FAT12 '
- Label_Start:
-
- mov ax, cs
- mov ds, ax
- mov es, ax
- mov ss, ax
- mov sp, BaseOfStack
-
- mov ax, 0x0600
- mov bx, 0x0700
- mov cx, 0
- mov dx, 0184fh
- int 0x10
-
- mov ax, 0x0200
- mov bx, 0x0000
- mov dx, 0x0000
- int 10h
-
- mov ax, 0x1301
- mov bx, 0x000a
- mov dx, 0x0000
- mov cx, 24
- push ax
- mov ax, ds
- mov es, ax
- pop ax
- mov bp, StartBootMessage
- int 0x10
-
- xor ah, ah
- xor dl, dl
- int 0x13
- mov word [SectorNo], SectorNumOfRootDirStart
- Label_Search_In_Root_Dir_Begin:
- cmp word [RootDirSizeForLoop], 0
- jz Label_No_LoaderBin
- dec word [RootDirSizeForLoop]
- mov ax, 0x00
- mov es, ax
- mov bx, 0x8000
- mov ax, [SectorNo]
- mov cl, 1
- call Func_ReadOneSector
- mov si, LoaderFileName
- mov di, 0x8000
- cld
- mov dx, 0x10
- Label_Search_For_LoaderBin:
- cmp dx, 0
- jz Label_Goto_Next_Sector_In_Root_Dir
- dec dx
- mov cx, 11
- Label_Cmp_FileName:
- cmp cx, 0
- jz Label_FileName_Found
- dec cx
- lodsb
- cmp al, byte [es:di]
- jz Label_Go_On
- jmp Label_Different
- Label_Go_On:
- inc di
- jmp Label_Cmp_FileName
- Label_Different:
- and di, 0xffe0
- add di, 0x20
- mov si, LoaderFileName
- jmp Label_Search_For_LoaderBin
- Label_Goto_Next_Sector_In_Root_Dir:
- add word [SectorNo], 1
- jmp Label_Search_In_Root_Dir_Begin
- Label_No_LoaderBin:
-
- mov ax, 0x1301
- mov bx, 0x000c
- mov dx, 0x0100
- mov cx, 24
- push ax
- mov ax, ds
- mov es, ax
- pop ax
- mov bp, NoLoaderMessage
- int 0x10
- jmp $
- Label_FileName_Found:
- mov ax, RootDirSectors
-
- and di, 0xffe0
- add di, 0x1a
- mov cx, word [es:di]
- push cx
- add cx, ax
- add cx, SectorBalance
- mov ax, BaseOfLoader
- mov es, ax
- mov bx, OffsetOfLoader
- mov ax, cx
- Label_Go_On_Loading_File:
- push ax
- push bx
-
- mov ah, 0x0e
- mov al, "."
- mov bl, 0x0f
- int 0x10
- pop bx
- pop ax
-
- mov cl, 1
- call Func_ReadOneSector
- pop ax
- call Func_GetFATEntry
- cmp ax, 0xfff
- jz Label_File_Loaded
- push ax
- mov dx, RootDirSectors
- add ax, dx
- add ax, SectorBalance
- add bx, [BPB_BytesPerSec]
- jmp Label_Go_On_Loading_File
- Label_File_Loaded:
-
-
- jmp BaseOfLoader:OffsetOfLoader
- Func_ReadOneSector:
- push bp
- mov bp, sp
- sub esp, 2
- mov byte [bp-2], cl
- push bx
- mov bl, [BPB_SecPerTrk]
- div bl
- inc ah
- mov cl, ah
- mov dh, al
- shr al, 1
- mov ch, al
- and dh, 1
- pop bx
- mov dl, [BS_DrvNum]
-
-
- Label_Go_On_Reading:
-
- mov ah, 2
- mov al, byte [bp-2]
- int 0x13
- jc Label_Go_On_Reading
- add esp, 2
- pop bp
- ret
- Func_GetFATEntry:
-
-
- push es
- push bx
- push ax
-
- mov ax, 00
- mov es, ax
- pop ax
- mov byte [Odd], 0
-
- mov bx, 3
- mul bx
- mov bx, 2
- div bx
- cmp dx, 0
- jz Label_Even
- mov byte [Odd], 1
- Label_Even:
- xor dx, dx
-
- mov bx, [BPB_BytesPerSec]
- div bx
- push dx
-
- mov bx, 0x8000
- add ax, SectorNumOfFAT1Start
- mov cl, 2
- call Func_ReadOneSector
- pop dx
- add bx, dx
- mov ax, [es:bx]
- cmp byte [Odd], 1
- jnz Label_Even_2
- shr ax, 4
- Label_Even_2:
- and ax, 0x0fff
- pop bx
- pop es
- ret
- RootDirSizeForLoop dw RootDirSectors
- SectorNo dw 0
- Odd db 0
- StartBootMessage: db "[DragonOS] Start Booting"
- NoLoaderMessage: db "[ERROR] No LOADER Found."
- LoaderFileName: db "LOADER BIN",0
- times 510 - ( $ - $$ ) db 0
- dw 0xaa55
|