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 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) ifneq ($(OS),Windows_NT)
EXEXT = EXEXT =
TARGET += stupid.iso stupid.hdd TARGET += stupid.iso stupid.hdd
@ -48,14 +48,23 @@ stupid.hdd: $(SUBDIRS)
stupid.tar.gz: $(SUBDIRS) stupid.tar.gz: $(SUBDIRS)
tar -czvf $@ sysroot tar -czvf $@ sysroot
.PHONY: floppy_boot.img .PHONY: floppy1440.img
floppy_boot.img: $(SUBDIRS) floppy1440.img: $(SUBDIRS)
dd if=/dev/zero of=$@ bs=512 count=1440 dd if=/dev/zero of=$@ bs=512 count=1440
mformat -C -f 1440 -i $@ 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 $@ boot/loader/stpdldr.sys ::/STPDLDR.SYS
mcopy -i $@ kernel/vmstupid.sys ::/VMSTUPID.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: OVMF32.fd:
wget 'https://retrage.github.io/edk2-nightly/bin/DEBUGIa32_OVMF.fd' -O $@ wget 'https://retrage.github.io/edk2-nightly/bin/DEBUGIa32_OVMF.fd' -O $@
@ -63,7 +72,7 @@ OVMF32.fd:
run: all run: all
qemu-system-i386 \ qemu-system-i386 \
-rtc base=localtime \ -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 \ -drive file=fat:rw:./sysroot,if=none,id=hdd \
-device floppy,drive=boot \ -device floppy,drive=boot \
-device ide-hd,drive=hdd \ -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 \ FLOPPY_SRCS = floppy.asm \
../common/const.inc \ ../common/const.inc \
@ -7,9 +8,12 @@ FLOPPY_SRCS = floppy.asm \
.PHONY: all .PHONY: all
all: $(TARGET) all: $(TARGET)
bootsector.bin: $(FLOPPY_SRCS) boot_floppy1440.bin: $(FLOPPY_SRCS)
$(AS) floppy.asm $@ $(AS) floppy.asm $@
boot_floppy2880.bin: $(FLOPPY_SRCS)
$(AS) -DFLOPPY_SIZE=FLOPPY_2880 floppy.asm $@
.PHONY: clean .PHONY: clean
clean: clean:
$(RM) $(TARGET) $(RM) $(TARGET)

View file

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

View file

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

View file

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