2021-06-10 15:16:14 +00:00
|
|
|
CPU 8086
|
|
|
|
ORG 0x7c00
|
|
|
|
|
2021-06-08 12:25:17 +00:00
|
|
|
jmp start
|
2021-06-06 16:56:54 +00:00
|
|
|
nop
|
|
|
|
|
2021-06-10 15:16:14 +00:00
|
|
|
;Disk description tables
|
|
|
|
|
|
|
|
%ifdef F1440
|
2021-06-16 15:03:31 +00:00
|
|
|
;1.44 MB 3.5" floppy disk (enable with the argument -d F1440 when building)
|
2021-06-10 15:16:14 +00:00
|
|
|
oemlabel db "ETTINOS "
|
|
|
|
sectorsize dw 0x200 ;bytes
|
|
|
|
clustersize db 0x1 ;sectors
|
|
|
|
bootsectors dw 0x1
|
|
|
|
fats db 0x2
|
|
|
|
rootentries dw 0xe0
|
|
|
|
logicalsectors dw 0xb40
|
|
|
|
mediadescriptor db 0xf0
|
|
|
|
sectorsperfat dw 0x9
|
|
|
|
sectorspertrack dw 0x12
|
|
|
|
sides dw 0x2
|
|
|
|
hiddensectors dd 0x0
|
|
|
|
largesectors dd 0x0
|
|
|
|
driveid dw 0x0
|
|
|
|
drivesignature db 0x29
|
|
|
|
volumeid dd 0x0
|
|
|
|
volumelabel db "ETTINOS "
|
|
|
|
filesystem db "FAT12 "
|
|
|
|
|
|
|
|
%else
|
|
|
|
;360 KiB 5.25" floppy disk (default)
|
|
|
|
oemlabel db "ETTINOS "
|
|
|
|
sectorsize dw 0x200 ;bytes
|
|
|
|
clustersize db 0x2 ;sectors
|
|
|
|
bootsectors dw 0x1
|
|
|
|
fats db 0x2
|
|
|
|
rootentries dw 0x70
|
|
|
|
logicalsectors dw 0x2d0
|
|
|
|
mediadescriptor db 0xfd
|
|
|
|
sectorsperfat dw 0x2
|
|
|
|
sectorspertrack dw 0x9
|
|
|
|
sides dw 0x2
|
|
|
|
hiddensectors dd 0x0
|
|
|
|
largesectors dd 0x0
|
|
|
|
driveid dw 0x0
|
|
|
|
drivesignature db 0x29
|
|
|
|
volumeid dd 0x0
|
|
|
|
volumelabel db "ETTINOS "
|
|
|
|
filesystem db "FAT12 "
|
|
|
|
|
|
|
|
%endif
|
2021-06-06 16:56:54 +00:00
|
|
|
|
|
|
|
start:
|
|
|
|
|
2021-06-16 15:03:31 +00:00
|
|
|
;Setup
|
|
|
|
;Set up the data, stack, and extra segments
|
2021-06-06 16:56:54 +00:00
|
|
|
mov ax, 0x0
|
|
|
|
mov ds, ax
|
2021-06-16 15:03:31 +00:00
|
|
|
mov ss, ax
|
|
|
|
mov es, ax
|
2021-06-06 16:56:54 +00:00
|
|
|
;Set up the stack
|
|
|
|
cli
|
2021-06-16 15:03:31 +00:00
|
|
|
mov sp, stack
|
|
|
|
add sp, 0x100
|
2021-06-06 16:56:54 +00:00
|
|
|
sti
|
|
|
|
;Store the boot device number
|
|
|
|
mov [bootdev], dl
|
|
|
|
|
2021-06-10 15:16:14 +00:00
|
|
|
;Load the root
|
2021-06-06 16:56:54 +00:00
|
|
|
;Set the source
|
2021-06-10 15:16:14 +00:00
|
|
|
mov ah, 0x0
|
|
|
|
mov al, [fats]
|
|
|
|
mul word [sectorsperfat]
|
|
|
|
add ax, [bootsectors]
|
|
|
|
push ax
|
2021-06-06 16:56:54 +00:00
|
|
|
call calcsource
|
|
|
|
;Set the destination
|
2021-06-16 15:03:31 +00:00
|
|
|
mov si, 0x7f00
|
2021-06-06 16:56:54 +00:00
|
|
|
mov bx, si
|
|
|
|
;Set the size
|
2021-06-10 15:16:14 +00:00
|
|
|
push dx
|
|
|
|
mov ax, [rootentries]
|
|
|
|
mov dx, 0x20
|
|
|
|
mul dx
|
|
|
|
mov dx, 0x0
|
|
|
|
div word [sectorsize]
|
|
|
|
pop dx
|
|
|
|
push ax
|
2021-06-06 16:56:54 +00:00
|
|
|
;Load
|
|
|
|
mov ah, 0x2
|
|
|
|
int 0x13
|
|
|
|
|
2021-06-10 15:16:14 +00:00
|
|
|
;Search the root for the system
|
2021-06-16 15:03:31 +00:00
|
|
|
;Set DI to the root
|
|
|
|
mov di, 0x7f00
|
2021-06-06 16:56:54 +00:00
|
|
|
;Initialise the search loop
|
2021-06-10 15:16:14 +00:00
|
|
|
mov cx, word [rootentries]
|
2021-06-06 16:56:54 +00:00
|
|
|
mov ax, 0x0
|
|
|
|
search:
|
|
|
|
;Store CX in the stack
|
|
|
|
push cx
|
2021-06-08 12:25:17 +00:00
|
|
|
;Check for the system FAT
|
2021-06-06 16:56:54 +00:00
|
|
|
mov si, sysfile
|
|
|
|
mov cx, 0xb
|
|
|
|
rep cmpsb
|
2021-06-10 15:16:14 +00:00
|
|
|
je loadfat
|
2021-06-06 16:56:54 +00:00
|
|
|
;Set DI to the next entry
|
|
|
|
add ax, 0x20
|
2021-06-16 15:03:31 +00:00
|
|
|
mov di, 0x7f00
|
2021-06-06 16:56:54 +00:00
|
|
|
add di, ax
|
|
|
|
;Load CX from the stack
|
|
|
|
pop cx
|
|
|
|
loop search
|
|
|
|
|
2021-06-16 15:03:31 +00:00
|
|
|
;Load the system entry
|
2021-06-10 15:16:14 +00:00
|
|
|
loadfat:
|
|
|
|
;Load CX from the stack
|
|
|
|
pop cx
|
2021-06-08 12:25:17 +00:00
|
|
|
;Store the first cluster
|
2021-06-06 16:56:54 +00:00
|
|
|
mov ax, word [es:di+0xf]
|
|
|
|
mov word [cluster], ax
|
|
|
|
;Set the source
|
|
|
|
mov ax, 0x1
|
|
|
|
call calcsource
|
|
|
|
;Set the destination
|
2021-06-16 15:03:31 +00:00
|
|
|
mov di, 0x7f00
|
2021-06-06 16:56:54 +00:00
|
|
|
mov bx, di
|
|
|
|
;Set the size
|
2021-06-10 15:16:14 +00:00
|
|
|
mov ax, [sectorsperfat]
|
2021-06-06 16:56:54 +00:00
|
|
|
;Load
|
|
|
|
mov ah, 0x2
|
|
|
|
int 0x13
|
|
|
|
|
2021-06-10 15:16:14 +00:00
|
|
|
;Load the system file
|
|
|
|
|
|
|
|
;Load a cluster
|
|
|
|
loadcluster:
|
2021-06-06 16:56:54 +00:00
|
|
|
;Set the source
|
2021-06-16 15:03:31 +00:00
|
|
|
pop cx
|
2021-06-10 15:16:14 +00:00
|
|
|
pop bx
|
2021-06-16 15:03:31 +00:00
|
|
|
mov ax, word [cluster]
|
2021-06-10 15:16:14 +00:00
|
|
|
sub ax, 0x2
|
2021-06-16 15:03:31 +00:00
|
|
|
mul byte [clustersize]
|
|
|
|
add ax, bx
|
|
|
|
add ax, cx
|
|
|
|
push bx
|
|
|
|
push cx
|
2021-06-06 16:56:54 +00:00
|
|
|
call calcsource
|
|
|
|
;Set the destination
|
|
|
|
mov bx, word [pointer]
|
|
|
|
;Set the size
|
2021-06-16 15:03:31 +00:00
|
|
|
;mov al, 0x1
|
|
|
|
mov al, [clustersize]
|
2021-06-10 15:16:14 +00:00
|
|
|
;Load
|
2021-06-06 16:56:54 +00:00
|
|
|
mov ah, 0x2
|
|
|
|
int 0x13
|
|
|
|
|
|
|
|
;Calculate the next cluster
|
|
|
|
mov ax, [cluster]
|
|
|
|
mov dx, 0x0
|
|
|
|
mov bx, 0x3
|
|
|
|
mul bx
|
2021-06-10 15:16:14 +00:00
|
|
|
mov bx, 0x2
|
2021-06-06 16:56:54 +00:00
|
|
|
div bx
|
2021-06-16 15:03:31 +00:00
|
|
|
mov si, 0x7f00
|
2021-06-06 16:56:54 +00:00
|
|
|
add si, ax
|
|
|
|
mov ax, word [ds:si]
|
|
|
|
or dx, dx
|
|
|
|
jz even
|
|
|
|
odd:
|
2021-06-10 15:16:14 +00:00
|
|
|
shr ax, 1
|
|
|
|
shr ax, 1
|
|
|
|
shr ax, 1
|
|
|
|
shr ax, 1
|
|
|
|
jmp contcalc
|
2021-06-06 16:56:54 +00:00
|
|
|
even:
|
|
|
|
and ax, 0xfff
|
2021-06-10 15:16:14 +00:00
|
|
|
contcalc:
|
2021-06-06 16:56:54 +00:00
|
|
|
mov word [cluster], ax
|
|
|
|
cmp ax, 0xff8
|
|
|
|
jge boot
|
2021-06-16 15:03:31 +00:00
|
|
|
mov ax, [sectorsize]
|
|
|
|
mul word [clustersize]
|
|
|
|
add word [pointer], ax
|
2021-06-10 15:16:14 +00:00
|
|
|
jmp loadcluster
|
2021-06-06 16:56:54 +00:00
|
|
|
|
2021-06-16 15:03:31 +00:00
|
|
|
;Boot the system
|
2021-06-06 16:56:54 +00:00
|
|
|
boot:
|
2021-06-16 15:03:31 +00:00
|
|
|
jmp 0x0:0x500
|
2021-06-06 16:56:54 +00:00
|
|
|
|
2021-06-16 15:03:31 +00:00
|
|
|
;Data
|
2021-06-10 15:16:14 +00:00
|
|
|
bootdev db 0x0
|
2021-06-16 15:03:31 +00:00
|
|
|
sysfile db "SYSTEM BIN"
|
2021-06-10 15:16:14 +00:00
|
|
|
cluster dw 0x0
|
2021-06-16 15:03:31 +00:00
|
|
|
pointer dw 0x500
|
2021-06-06 16:56:54 +00:00
|
|
|
|
2021-06-16 15:03:31 +00:00
|
|
|
;Calculate the source arguments for loading data from the disk
|
2021-06-06 16:56:54 +00:00
|
|
|
calcsource:
|
|
|
|
push ax
|
|
|
|
push bx
|
|
|
|
mov bx, ax
|
|
|
|
mov dx, 0x0
|
2021-06-10 15:16:14 +00:00
|
|
|
div word [sectorspertrack]
|
2021-06-06 16:56:54 +00:00
|
|
|
add dl, 0x1
|
|
|
|
mov cl, dl
|
|
|
|
mov ax, bx
|
|
|
|
mov dx, 0x0
|
2021-06-10 15:16:14 +00:00
|
|
|
div word [sectorspertrack]
|
2021-06-06 16:56:54 +00:00
|
|
|
mov dx, 0x0
|
2021-06-10 15:16:14 +00:00
|
|
|
div word [sides]
|
2021-06-06 16:56:54 +00:00
|
|
|
mov dh, dl
|
|
|
|
mov ch, al
|
|
|
|
pop bx
|
|
|
|
pop ax
|
|
|
|
mov dl, byte [bootdev]
|
|
|
|
ret
|
|
|
|
|
2021-06-16 15:03:31 +00:00
|
|
|
;Pad the binary to a full sector and make the disk bootable
|
2021-06-06 16:56:54 +00:00
|
|
|
;Padding
|
|
|
|
times 0x1fe-($-$$) db 0x0
|
|
|
|
;Boot signature
|
|
|
|
dw 0xaa55
|
2021-06-16 15:03:31 +00:00
|
|
|
|
|
|
|
stack:
|