📄 bootstorm.asm
字号:
;====================================================
; 2004 Thundersoft(c) Storm OS
; Visit www.stormos.net
; This file is copyrighted by Thundersoft
;
; FAT12 FS Bootloader
;===================================================
jmp short start
nop
;------- BIOS Parameter Block and BS FAT12 --------
%include "STORMFAT.inc" ;整理者修改 include "FAT.inc"
;---------------------MAIN CODE--------------------
start:
jmp 0x7C0:write_cs
write_cs:
mov ax,cs
mov ds,ax
mov es,ax
mov gs,ax
mov fs,ax
mov ax,0x7B0
mov ss,ax
mov sp,0xF0 ; stack linear addr 0x7BFF
mov si, Loading
call PrintMsg
; copy root dir to 0x7E00 linear
mov cx,[RootSize]
call ReadSectors
mov bx,0x7C0
mov es,bx
Search:
mov cx, word [MaxRootEntries]
mov di, 0x200
.1:
push cx
mov cx,11
mov si,LoaderName
push di
rep cmpsb
pop di
je Found
pop cx
add di,32
loop .1
jmp Error
Found:
mov ax,[di+26]
call FAT_to_LBA
mov [FileStart],ax
mov ax,[di+28]
call Bytes_to_Sectors
mov cx,ax
mov ax,[FileStart]
mov [LBA],ax
mov [LoaderSegment], word 0x840
call ReadSectors
mov bx,0x7C0
mov es,bx
Search1:
mov cx, word [MaxRootEntries]
mov di, 0x200
.1:
push cx
mov cx,11
mov si,KernelName
push di
rep cmpsb
pop di
je Found1
pop cx
add di,32
loop .1
jmp Error
Found1:
mov ax,[di+26]
call FAT_to_LBA
mov [FileStart],ax
mov ax,[di+28]
call Bytes_to_Sectors
mov cx,ax
mov ax,[FileStart]
mov [LBA],ax
; mov [LoaderSegment], word 0x900
; mov [LoaderOffset], word 0x0
mov [LoaderSegment], word 0xFFFF
mov [LoaderOffset], word 0x10
call ReadSectors
jmp 0x840:0x0
hlt
;---------------------FUNCTIONS-----------------------
testas:
add al,48
mov ah,0x0E
mov bh,0
mov bl,15
int 0x10
ret
Bytes_to_Sectors:
xor dx,dx
div word [BytesPerSector]
cmp dx,0
je .1
inc ax
.1
ret
Error:
mov si,ErrorMsg
call PrintMsg
xor ax,ax
int 0x16
mov ax,0x64
out 0x64,ax
cli
hlt
PrintMsg:
mov ah,0x0E
mov bh,0
mov bl,15
.1
lodsb
cmp al,0
je .2
int 0x10
jmp .1
.2
ret
ReadSectors:
mov ax,[LBA]
.1:
push cx
call LBA_to_CHS
.2
mov es,[LoaderSegment] ; segment to load data
mov bx,[LoaderOffset] ; offset to load data
mov ax,0x0201 ; read sector int and read 1 sector
mov dl,[DriveNumber] ; drive number
int 0x13 ; read it!
jc .2
add bx,[BytesPerSector]
mov [LoaderOffset],bx ; calculate new offset
mov si, Dot ; after successful read write dot
call PrintMsg
mov ax,[LBA]
inc ax
mov [LBA],ax
pop cx
loop .1
mov [LoaderOffset], word 0
mov dx,0x3F2 ; stop the motor
mov al,0x0C ; from spinning
out dx,al
ret
LBA_to_CHS: ;input ax=LBA sector
xor dx,dx ; zero dx
mov bx, [SectorsPerTrack]
div bx ; dx=(ax mod bx)+1
inc dx
push dx ; this will be absolute sector
xor dx,dx ; zero dx
mov bx, [NumHeads]
div bx
mov ch,al ; track
mov dh,dl ; head
pop ax
mov cl,al ; sector
ret
FAT_to_LBA:
sub ax,0x2
add ax,[DataStart]
ret
;-----------------VARS----------------------------
RootSize dw 14
RootStart dw 19
DataStart dw 33
LBA dw 19
LoaderSegment dw 0x7E0
LoaderOffset dw 0x0
FileStart dw 0
LoaderName db "LOADER SYS"
KernelName db "KERNEL SYS"
Loading db 13,10,"Loading Storm OS ",0
ErrorMsg db 13,10,"Error: file not found! Any key to restart"
Dot db '.',0
;============================
times 510-($-$$) db 0
sign dw 0xAA55
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -