Import backup from 2003-08-03
This commit is contained in:
commit
7a4586bb06
283
bootsect.asm
Normal file
283
bootsect.asm
Normal file
@ -0,0 +1,283 @@
|
||||
|
||||
%define FAT_SEG 0x07E0 ;right after boot sector
|
||||
%define ROOT_SEG 0x0900 ;right after FAT
|
||||
%define KERNEL_SEG 0x0AC0 ;right after ROOT_DIR
|
||||
%define KERNEL_ADD 0x100000 ;1mb - kernel final address
|
||||
|
||||
[bits 16]
|
||||
|
||||
org 0x7c00
|
||||
|
||||
jmp short start
|
||||
|
||||
; --------------------------------------------------
|
||||
; data portion of the "DOS BOOT RECORD"
|
||||
; ----------------------------------------------------------------------
|
||||
brINT13Flag DB 90H ; 0002h - 0EH for INT13 AH=42 READ
|
||||
brOEM DB 'MSDOS5.0' ; 0003h - OEM ID - Windows 95B
|
||||
brBPS DW 512 ; 000Bh - Bytes per sector
|
||||
brSPC DB 1 ; 000Dh - Sector per cluster
|
||||
brSc_b4_fat DW 1 ; 000Eh - Reserved sectors
|
||||
brFATs DB 2 ; 0010h - FAT copies
|
||||
brRootEntries DW 0E0H ; 0011h - Root directory entries
|
||||
brSectorCount DW 2880 ; 0013h - Sectors in volume, < 32MB
|
||||
brMedia DB 240 ; 0015h - Media descriptor
|
||||
brSPF DW 9 ; 0016h - Sectors per FAT
|
||||
brSc_p_trk DW 18 ; 0018h - Sectors per head/track
|
||||
brHPC DW 2 ; 001Ah - Heads per cylinder
|
||||
brSc_b4_prt DD 0 ; 001Ch - Hidden sectors
|
||||
brSectors DD 0 ; 0020h - Total number of sectors
|
||||
brDrive DB 0 ; 0024h - Physical drive no.
|
||||
DB 0 ; 0025h - Reserved (FAT32)
|
||||
DB 29H ; 0026h - Extended boot record sig (FAT32)
|
||||
brSerialNum DD 404418EAH ; 0027h - Volume serial number
|
||||
brLabel DB 'HOS 0.1.1 ' ; 002Bh - Volume label
|
||||
brFSID DB 'FAT12 ' ; 0036h - File System ID
|
||||
;------------------------------------------------------------------------
|
||||
|
||||
start:
|
||||
;dl=drive number, save it!
|
||||
mov [brDrive], dl
|
||||
cli
|
||||
xor ax, ax
|
||||
mov ss, ax
|
||||
mov sp, 0x7Bfe ;right under boot sector
|
||||
sti
|
||||
|
||||
mov ax, 0xb800
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
|
||||
xor di, di
|
||||
mov ax, 0x0700
|
||||
mov cx, 2000
|
||||
cls:
|
||||
stosw
|
||||
loop cls
|
||||
|
||||
enable_a20:
|
||||
in al, 0x64
|
||||
test al, 2
|
||||
jnz enable_a20
|
||||
mov al, 0xD1
|
||||
out 0x64, al
|
||||
ea20_2: in al, 0x64
|
||||
and ax, byte 2
|
||||
jnz ea20_2
|
||||
mov al, 0xDF
|
||||
out 0x60, al
|
||||
|
||||
unreal:
|
||||
xor ax, ax
|
||||
mov es, ax
|
||||
mov ds, ax
|
||||
|
||||
lgdt [gdtr] ;load gdt
|
||||
cli
|
||||
push es
|
||||
push ds ;save segment values
|
||||
mov ebx, cr0
|
||||
inc bl
|
||||
mov cr0, ebx ;pmode!
|
||||
mov ax, 8
|
||||
mov es, ax
|
||||
mov ds, ax ;load segment limits
|
||||
dec bl
|
||||
mov cr0, ebx ;back to real mode!
|
||||
pop ds
|
||||
pop es ;segments back, with 4gb limits!
|
||||
sti
|
||||
|
||||
;now lets read in the FAT and root directory so we can search for the kernel file...
|
||||
mov ax, 0x0209 ;FAT1
|
||||
mov cx, 0x0002
|
||||
xor dh, dh
|
||||
mov dl, [brDrive]
|
||||
mov bx, FAT_SEG
|
||||
mov es, bx
|
||||
xor bx, bx
|
||||
int 0x13
|
||||
|
||||
mov ax, 0x020E ;root directory
|
||||
mov cx, 0x0002 ;cyl/sect
|
||||
mov dh, 0x01 ;head
|
||||
mov dl, [brDrive] ;drive
|
||||
mov bx, ROOT_SEG
|
||||
mov es, bx
|
||||
xor bx, bx
|
||||
int 0x13
|
||||
|
||||
;k now read root directory
|
||||
mov bx, ROOT_SEG
|
||||
mov ds, bx
|
||||
xor si, si ;k now ds:si points to beginning of root directory
|
||||
mov es, si
|
||||
mov cx, 224 ;max root entries
|
||||
loop_compare:
|
||||
mov di, kernel
|
||||
push cx
|
||||
push si ;save pointer to root dir entry
|
||||
mov cx, 11
|
||||
loop_name:
|
||||
cmpsb
|
||||
loopnz loop_name
|
||||
jnz goon ;cx didn't get to zero, bad file
|
||||
pop si
|
||||
pop cx
|
||||
jmp found_file ;good file, ds:si points to start of root directory entry
|
||||
goon:
|
||||
pop si
|
||||
pop cx
|
||||
loop loop_compare
|
||||
|
||||
error:
|
||||
jmp $ ;halt! no kernel file found!
|
||||
|
||||
found_file: ;ds:si points to root dir entry of kernel file
|
||||
mov di, 160 ;;;;;;;
|
||||
|
||||
mov ax, KERNEL_SEG
|
||||
mov es, ax
|
||||
mov ax, [ds:si+26] ;first logical cluster
|
||||
mov bx, FAT_SEG
|
||||
mov ds, bx
|
||||
xor bx, bx
|
||||
loop_readkernel:
|
||||
cmp ax, 0xFF7
|
||||
jg donereadkernel
|
||||
push ax ;<> save cluster#
|
||||
push bx ;<> save index
|
||||
call getCHSfromCluster
|
||||
mov ax, 0x0201
|
||||
mov dl, [brDrive]
|
||||
int 0x13
|
||||
pop bx
|
||||
add bx, 512
|
||||
pop ax ;<> restore cluster#
|
||||
cmp bx, 0 ;if bx=0 then it wrapped, 64k loaded, increment es by 64k
|
||||
jne loop_readkernel_goon
|
||||
mov bx, es
|
||||
add bx, 0x1000
|
||||
mov es, bx
|
||||
xor bx, bx
|
||||
loop_readkernel_goon:
|
||||
mov cx, ax ;save backup of cluster#
|
||||
mov dx, 3
|
||||
mul dx ;ax=logical cluster*3
|
||||
shr ax, 1 ;ax=logical cluster*3/2
|
||||
mov si, ax ;ds:si points to first byte of word containing FAT entry
|
||||
test cl, 1 ;is cluster# odd?
|
||||
jnz odd_cluster
|
||||
even_cluster:
|
||||
mov cl, [ds:si+1]
|
||||
and cl, 0x0f
|
||||
shl cx, 8
|
||||
mov cl, [ds:si]
|
||||
jmp got_cluster
|
||||
odd_cluster:
|
||||
xor cx, cx
|
||||
mov cl, [ds:si+1]
|
||||
shl cx, 4
|
||||
xor dx, dx
|
||||
mov dl, [ds:si]
|
||||
shr dl, 4
|
||||
add cx, dx
|
||||
got_cluster:
|
||||
push es ;;;;;;;
|
||||
mov ax, 0xb800
|
||||
mov es, ax
|
||||
mov al, ch
|
||||
call puthex
|
||||
mov al, cl
|
||||
call puthex
|
||||
inc di
|
||||
inc di ;;;;;;;
|
||||
|
||||
mov ax, cx
|
||||
jmp loop_readkernel
|
||||
|
||||
donereadkernel: ;done reading kernel!
|
||||
mov ax, 0xb800
|
||||
mov es, ax
|
||||
xor di, di
|
||||
mov al, bh
|
||||
call puthex
|
||||
mov al, bl
|
||||
call puthex
|
||||
|
||||
jmp $
|
||||
|
||||
;------------------------------------------------------
|
||||
getCHSfromCluster:
|
||||
;input: ax=lba of sector on floppy (0-2879)
|
||||
add ax, 31 ;convert logical cluster# to lba#
|
||||
xor dx, dx ;lba->chs
|
||||
mov bx, 18
|
||||
div bx
|
||||
inc dx
|
||||
mov cl, dl ;sector# (1-18)
|
||||
xor dx, dx
|
||||
mov bx, 2
|
||||
div bx
|
||||
mov ch, al ;cylinder# (0-79)
|
||||
mov dh, dl ;head# (0-1)
|
||||
ret
|
||||
|
||||
;------------------------------------------------------
|
||||
puthex:
|
||||
;es:di points to video memory
|
||||
;al holds hex value
|
||||
|
||||
push ax
|
||||
mov ah, al
|
||||
shr ax, 4
|
||||
and al, 0x0F
|
||||
add al, '0'
|
||||
cmp al, '9'
|
||||
jle puthex_goon1
|
||||
add al, 'A'-'9'-1
|
||||
puthex_goon1:
|
||||
stosb
|
||||
mov al, 7
|
||||
stosb
|
||||
pop ax
|
||||
push ax
|
||||
and al, 0x0F
|
||||
add al, '0'
|
||||
cmp al, '9'
|
||||
jle puthex_goon2
|
||||
add al, 'A'-'9'-1
|
||||
puthex_goon2:
|
||||
stosb
|
||||
mov al, 7
|
||||
stosb
|
||||
pop ax
|
||||
ret
|
||||
|
||||
;-------------------------------------------------------
|
||||
gdtr:
|
||||
dw gdt_end-gdt-1
|
||||
dd gdt
|
||||
gdt:
|
||||
dd 0
|
||||
dd 0
|
||||
|
||||
db 0xff ;segment 8 = 4gb data
|
||||
db 0xff
|
||||
db 0x00
|
||||
db 0x00
|
||||
db 0x00
|
||||
db 0x92
|
||||
db 0xcf ;cf
|
||||
db 0x00
|
||||
|
||||
gdt_end:
|
||||
|
||||
kernel: db "KERNEL BIN"
|
||||
|
||||
times 510-($-$$) db 0
|
||||
|
||||
|
||||
|
||||
db 0x55, 0xaa
|
||||
|
Loading…
x
Reference in New Issue
Block a user