build: 1.44MB and 2.88MB floppy

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-04-04 12:13:02 +02:00
parent 0cf565c93c
commit d70a9436a0
6 changed files with 194 additions and 159 deletions

View file

@ -17,7 +17,7 @@ MK_COMMIT := \"$(shell git rev-parse --short HEAD)\"
SUBDIRS := external tools include boot kernel lib bin
TARGET = stupid.tar.gz floppy_boot.img
TARGET = stupid.tar.gz floppy1440.img floppy2880.img
ifneq ($(OS),Windows_NT)
EXEXT =
TARGET += stupid.iso stupid.hdd
@ -48,14 +48,23 @@ stupid.hdd: $(SUBDIRS)
stupid.tar.gz: $(SUBDIRS)
tar -czvf $@ sysroot
.PHONY: floppy_boot.img
floppy_boot.img: $(SUBDIRS)
.PHONY: floppy1440.img
floppy1440.img: $(SUBDIRS)
dd if=/dev/zero of=$@ bs=512 count=1440
mformat -C -f 1440 -i $@
dd if=boot/bootsect/bootsector.bin of=$@ conv=notrunc
dd if=boot/bootsect/boot_floppy1440.bin of=$@ conv=notrunc
mcopy -i $@ boot/loader/stpdldr.sys ::/STPDLDR.SYS
mcopy -i $@ kernel/vmstupid.sys ::/VMSTUPID.SYS
.PHONY: floppy2880.img
floppy2880.img: $(SUBDIRS)
dd if=/dev/zero of=$@ bs=512 count=2880
mformat -C -f 2880 -i $@
dd if=boot/bootsect/boot_floppy2880.bin of=$@ conv=notrunc
mcopy -i $@ boot/loader/stpdldr.sys ::/STPDLDR.SYS
mcopy -i $@ kernel/vmstupid.sys ::/VMSTUPID.SYS
OVMF32.fd:
wget 'https://retrage.github.io/edk2-nightly/bin/DEBUGIa32_OVMF.fd' -O $@
@ -63,7 +72,7 @@ OVMF32.fd:
run: all
qemu-system-i386 \
-rtc base=localtime \
-drive file=floppy_boot.img,if=none,format=raw,id=boot \
-drive file=floppy1440.img,if=none,format=raw,id=boot \
-drive file=fat:rw:./sysroot,if=none,id=hdd \
-device floppy,drive=boot \
-device ide-hd,drive=hdd \

View file

@ -1,4 +1,5 @@
TARGET = bootsector.bin
TARGET = boot_floppy1440.bin \
boot_floppy2880.bin
FLOPPY_SRCS = floppy.asm \
../common/const.inc \
@ -7,9 +8,12 @@ FLOPPY_SRCS = floppy.asm \
.PHONY: all
all: $(TARGET)
bootsector.bin: $(FLOPPY_SRCS)
boot_floppy1440.bin: $(FLOPPY_SRCS)
$(AS) floppy.asm $@
boot_floppy2880.bin: $(FLOPPY_SRCS)
$(AS) -DFLOPPY_SIZE=FLOPPY_2880 floppy.asm $@
.PHONY: clean
clean:
$(RM) $(TARGET)

View file

@ -3,30 +3,42 @@
use16
include '../common/const.inc'
include '../common/macro.inc'
org BOOTSECT_BASE
jmp short _start
nop
if FLOPPY_SIZE eq FLOPPY_2880
SECTORS_PER_CLUSTER = 2
ROOT_DIR_ENTRIES = 240
TOTAL_SECTORS = 5760
SECTORS_PER_TRACK = 36
else
SECTORS_PER_CLUSTER = 1
ROOT_DIR_ENTRIES = 224
TOTAL_SECTORS = 2880
SECTORS_PER_TRACK = 18
end if
; Boot Record
OEM_identifier db 'STUPID '
bytes_per_sector dw 512
sectors_per_cluster db 1
sectors_per_cluster db SECTORS_PER_CLUSTER
reserved_sectors dw 1
FAT_count db 2
root_dir_entries dw 224
total_sectors dw 2880
root_dir_entries dw ROOT_DIR_ENTRIES
total_sectors dw TOTAL_SECTORS
media_desc_type db 0xF0
sectors_per_FAT dw 9
sectors_per_track dw 18
sectors_per_track dw SECTORS_PER_TRACK
heads_per_cylinder dw 2
hidden_sectors dd 0
large_sector_count dd 0
; Extended Boot Record
drive_number db 0x0
reserved db 0x0
drive_number db 0
reserved db 0
signature db 0x29 ; 0x28 or 0x29
volume_id dd 0xB00B135 ; hope mine will grow :'(
volume_label db 'Stupid Boot'

View file

@ -4,7 +4,7 @@
;;
;; Parameters:
;;
;; si - null-terminated string to print
;; SI - null-terminated string to print
;;
bios_print:
lodsb

View file

@ -1,180 +1,189 @@
ATTR_READ_ONLY = 0x01
ATTR_HIDDEN = 0x02
ATTR_SYSTEM = 0x04
ATTR_VOLUME_ID = 0x08
ATTR_DIRECTORY = 0x10
ATTR_ARCHIVE = 0x20
;; File: fat12.inc
struc fat_entry
{
.name db 8 dup ?
.ext db 3 dup ?
.attrs db ?
.reserved dw ?
.creation_time dw ?
.creation_date dw ?
.access_date dw ?
.reserved2 dw ?
.mod_time dw ?
.mod_date dw ?
.start dw ?
.size dd ?
}
ATTR_READ_ONLY = 0x01
ATTR_HIDDEN = 0x02
ATTR_SYSTEM = 0x04
ATTR_VOLUME_ID = 0x08
ATTR_DIRECTORY = 0x10
ATTR_ARCHIVE = 0x20
virtual at di
struc fat_entry
{
.name db 8 dup ?
.ext db 3 dup ?
.attrs db ?
.reserved dw ?
.creation_time dw ?
.creation_date dw ?
.access_date dw ?
.reserved2 dw ?
.mod_time dw ?
.mod_date dw ?
.start dw ?
.size dd ?
}
defn fat_entry
fat_entry fat_entry
end virtual
; CHS to LBA
; LBA = (C * HPC + H) * SPT + (S - 1)
; CHS to LBA
; LBA = (C * HPC + H) * SPT + (S - 1)
;;; Read sectors from disk to buffer
;;;
;;; @param AX LBA starting sector
;;; @param CX sector count
;;; @param ES:BX buffer
;;;
;; Function: disk_read_sectors
;; Read sectors from disk to buffer
;;
;; Parameters:
;;
;; AX - LBA starting sector
;; CX - sector count
;; ES:BX - buffer
;;
disk_read_sectors:
; https://en.wikipedia.org/wiki/Logical_block_addressing
; convert LBA to CHS
; HPC = Head per Cluster
; SPT = Sector per Track
; https://en.wikipedia.org/wiki/Logical_block_addressing
; convert LBA to CHS
; HPC = Head per Cluster
; SPT = Sector per Track
; S = (LBA % SPT) + 1
push ax
push bx
push cx
xor dx, dx
div word [sectors_per_track]
inc dx
mov [S], dx
; S = (LBA % SPT) + 1
push ax
push bx
push cx
xor dx, dx
div word [sectors_per_track]
inc dx
mov [S], dx
; H = (LBA / SPT) % HPC
; C = LBA / (HPC * SPT)
xor dx, dx
div word [heads_per_cylinder]
mov [C], ax
mov [H], dx
; H = (LBA / SPT) % HPC
; C = LBA / (HPC * SPT)
xor dx, dx
div word [heads_per_cylinder]
mov [C], ax
mov [H], dx
; read sectors
mov ah, 0x2
mov al, 0x1
mov ch, byte [C]
mov cl, byte [S]
mov dh, byte [H]
mov dl, [drive_number]
; read sectors
mov ah, 0x2
mov al, 0x1
mov ch, byte [C]
mov cl, byte [S]
mov dh, byte [H]
mov dl, [drive_number]
int 0x13
jc @f
pop cx
pop bx
pop ax
add bx, word [bytes_per_sector]
inc ax
loop disk_read_sectors
ret
int 0x13
jc @f
pop cx
pop bx
pop ax
add bx, word [bytes_per_sector]
inc ax
loop disk_read_sectors
ret
@@:
mov si, msg_error_sector
call bios_print
ret
mov si, msg_error_sector
call bios_print
ret
C dw 0x00
H dw 0x00
S dw 0x00
;; Function: fat_load_root
fat_load_root:
mov ax, DISK_BUFFER/0x10
mov es, ax
mov ax, DISK_BUFFER/0x10
mov es, ax
; load root directory
mov ax, [sectors_per_FAT]
xor cx, cx
mov cl, [FAT_count]
mul cx
add ax, [reserved_sectors]
push ax
; load root directory
mov ax, [sectors_per_FAT]
xor cx, cx
mov cl, [FAT_count]
mul cx
add ax, [reserved_sectors]
push ax
mov bx, [bytes_per_sector]
mov cl, 0x5
shr bx, cl
mov ax, [root_dir_entries]
xor dx, dx
div bx
mov cx, ax
pop ax
mov bx, [bytes_per_sector]
mov cl, 0x5
shr bx, cl
mov ax, [root_dir_entries]
xor dx, dx
div bx
mov cx, ax
pop ax
mov [data_start], ax
add [data_start], cx
mov [data_start], ax
add [data_start], cx
xor bx, bx
xor bx, bx
call disk_read_sectors
call disk_read_sectors
ret
ret
;; @param SI filename to search
;; Function: fat_search_root
;;
;; Parameters:
;;
;; SI - file to search
;;
fat_search_root:
mov cx, [root_dir_entries]
mov di, 0x0
mov cx, [root_dir_entries]
mov di, 0x0
@@:
push si
push cx
mov cx, 0xB ; name(8) + ext(3)
push di
rep cmpsb
pop di
pop cx
pop si
je .file_found
add di, 0x20
loop @b
; set carry if not found
stc
ret
push si
push cx
mov cx, 0xB ; name(8) + ext(3)
push di
rep cmpsb
pop di
pop cx
pop si
je .file_found
add di, 0x20
loop @b
; set carry if not found
stc
ret
.file_found:
mov ax, [es:fat_entry.start]
clc
ret
mov ax, [es:di + fat_entry.start]
clc
ret
;;; @param AX cluster
;;; @param ES:BX buffer
;; Function: fat_load_binary
;;
;; Parameters:
;; AX - cluster
;; ES:BX - buffer
fat_load_binary:
push ax
sub ax, 0x2
xor cx, cx
mov cl, [sectors_per_cluster]
mul cx
push ax
sub ax, 0x2
xor cx, cx
mov cl, [sectors_per_cluster]
mul cx
add ax, [data_start]
xor cx, cx
mov cl, [sectors_per_cluster]
call disk_read_sectors
add ax, [data_start]
xor cx, cx
mov cl, [sectors_per_cluster]
call disk_read_sectors
pop ax
mov cx, ax
mov dx, ax
shr dx, 0x1
add cx, dx
push bx
mov bx, DISK_BUFFER
add bx, cx
mov dx, [bx]
pop bx
pop ax
mov cx, ax
mov dx, ax
shr dx, 0x1
add cx, dx
push bx
mov bx, DISK_BUFFER
add bx, cx
mov dx, [bx]
pop bx
test ax, 0x1
jnz .odd_cluster
test ax, 0x1
jnz .odd_cluster
.even_cluster:
and dx, 0xFFF
jmp .end
and dx, 0xFFF
jmp .end
.odd_cluster:
shr dx, 0x4
shr dx, 0x4
.end:
mov ax, dx
cmp dx, 0xFF0
jb fat_load_binary
ret
mov ax, dx
cmp dx, 0xFF0
jb fat_load_binary
ret
msg_error_sector db "ERROR: reading sector", CR, LF, 0

View file

@ -20,7 +20,7 @@ Timestamp: Updated yyyy/mm/dd
# These are indexes you deleted, so Natural Docs will not add them again
# unless you remove them from this line.
Don't Index: Macros, Variables, Classes
Don't Index: Variables, Macros, Classes
# --------------------------------------------------------------------------
@ -65,6 +65,7 @@ Group: BootLoader {
Group: Common {
File: bios.inc (boot/common/bios.inc)
File: fat12.inc (boot/common/fat12.inc)
} # Group: Common
Group: EFI {