From 82b2c8ddb429903da774b1a70585e6b47d60a2f4 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 10 Jun 2017 16:09:46 +0200 Subject: using int13h/8h only for floppies for now, geometry on emulated USB disks seems to be completly wrong. Probing on real machine for first non-readable sector hangs the machine or creates reboots, no clue. Writing a boot loader is not the scope of the project. For me it runs where it has to run for now.. --- src/Makefile | 6 +++++- src/boot.asm | 7 ++++++- src/stage2_real_functions.asm | 42 +++++++++++++++++++++++++----------------- 3 files changed, 36 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/Makefile b/src/Makefile index fed9fd3..1609299 100644 --- a/src/Makefile +++ b/src/Makefile @@ -9,7 +9,7 @@ MAGIC := $(shell printf '%x' `date +%s`) all: image.bin kernel.sym # truncate to correct number of sectors, we have -# 512 (boot, stage 1) + N * 512 (N currenty is 3, stage 2) = 2048 for boot.bin +# 512 (boot, stage 1) + N * 512 (N currenty is 3, stage 2) = 3072 for boot.bin # + M * 512 (M is currently 7) = 3144 for kernel.bin # + 1 * 512 = 512 for magic.bin # (M + N + 1 is the number of sectors to be read in stage 2, as stage 1 @@ -102,6 +102,10 @@ run-qemu-hd: image.bin qemu-system-i386 -net nic,model=ne2k_pci -d guest_errors -m 32 -drive "file=image.bin,if=ide,format=raw" \ -serial file:serial.log +run-qemu-usb: image.bin + qemu-system-i386 -net nic,model=ne2k_pci -d guest_errors -m 32 -usb -usbdevice disk:/dev/sde \ + -serial file:serial.log + run-qemu: image.bin qemu-system-i386 -net nic,model=ne2k_pci -d guest_errors -m 32 -drive "file=image.bin,if=floppy,format=raw" \ -serial file:serial.log diff --git a/src/boot.asm b/src/boot.asm index 73f1214..68cbb52 100644 --- a/src/boot.asm +++ b/src/boot.asm @@ -87,7 +87,11 @@ stage2: mov si, MESSAGE_STAGE_2_LOADED call print_string -; detect disk geometry +; detect disk geometry (works for real floppies only?) + mov cl, [BOOT_DRIVE] + and cl, 0x80 + jnz .not_a_floppy + mov si, MESSAGE_DETECTING_DISK_GEOMETRY call print_string mov dl, [BOOT_DRIVE] @@ -95,6 +99,7 @@ stage2: mov dl, [BOOT_DRIVE] call probe_and_fix_disk_geometry call print_newline +.not_a_floppy: ; print a message we are now loading the kernel mov si, MESSAGE_LOADING_KERNEL diff --git a/src/stage2_real_functions.asm b/src/stage2_real_functions.asm index f173ca3..1728b1a 100644 --- a/src/stage2_real_functions.asm +++ b/src/stage2_real_functions.asm @@ -9,7 +9,7 @@ SECTORS_PER_CYLINDER: db 0x3F ; detect parameters enters the correct value here (sectors + 1) ; if detection fails, force int13 to read ahead NOF_HEADS: - db 0x02 ; number of heads + 1 + db 0x01 ; number of heads + 1 SECTORS_TO_LOAD: db NOF_LOAD_SECTORS ; load NOF_LOAD_SECTORS sectors in total CURRENT_SECTOR: @@ -49,31 +49,39 @@ detect_disk_geometry: ret probe_and_fix_disk_geometry: - mov cl, 0xff ; from 63 down to 0 + mov cl, 0x1 ; from 1 to 63 + mov BYTE [SECTORS_PER_CYLINDER], cl .loop: + mov dl, [BOOT_DRIVE] mov ah, 0x02 ; read sectors from drive mov al, 1 ; read 1 sector + mov cl, BYTE [SECTORS_PER_CYLINDER] mov ch, BYTE 0 mov dh, BYTE 0 int 0x13 - jc .next_try - ; no errors anymore, so it must be the correct sector - inc cl - mov [SECTORS_PER_CYLINDER], BYTE cl - - mov al, '>' - call print_char - movzx dx, byte [SECTORS_PER_CYLINDER] - call print_hex - - ret - -.next_try: - dec cl ; next sector - jnz .loop + jnc .next_sector ; on error, remeber cl being the highest sector + +.fix_heads: + cmp [NOF_HEADS], BYTE 0 ; 0 heads, the BIOS is playing tricks to us! + je .illegal_heads + jmp .end + +.illegal_heads: + mov [NOF_HEADS], BYTE 1 + jmp .end + +.next_sector: + mov cl, BYTE [SECTORS_PER_CYLINDER] + inc cl ; next sector + mov BYTE [SECTORS_PER_CYLINDER], cl + cmp cl, 0x40 ; to a max of 63, if so, this is the default + jbe .loop + jmp .fix_heads + +.end: ret ; read the whole stage2 and kernel from the disk -- cgit v1.2.3-54-g00ecf