summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-06-09 21:40:05 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-06-09 21:40:05 +0200
commit0be74eeee017b7116126e258b97df5a857dac4ab (patch)
tree5f1e1b5ac76e74214abb111ab2a0dac64ef2ecef
parent2a83f352967435beb05582e5119b9e9e0cfefe3a (diff)
downloadabaos-0be74eeee017b7116126e258b97df5a857dac4ab.tar.gz
abaos-0be74eeee017b7116126e258b97df5a857dac4ab.tar.bz2
tried to probe disk geometry with mixed success (emulated FDD mode
on USB not working). Code in stage1 gets too complex to fit 512 bytes, so we most likely must load stage2 with a simple algorithm (maybe 8 sectors every bios 13h/2h function is able to deliver). Then we load the kernel in a second, more complex loading step
-rw-r--r--doc/LINKS.TODO1
-rw-r--r--doc/README.DISK_GEOMETRY66
-rw-r--r--src/Makefile4
-rw-r--r--src/boot.asm4
-rw-r--r--src/stage1_functions.asm33
5 files changed, 43 insertions, 65 deletions
diff --git a/doc/LINKS.TODO b/doc/LINKS.TODO
index 81e0466..c51106b 100644
--- a/doc/LINKS.TODO
+++ b/doc/LINKS.TODO
@@ -70,6 +70,7 @@ https://www.cs.cmu.edu/~410-s07/p4/p4-boot.pdf
http://www.osdever.net/tutorials/view/loading-sectors
http://www.osdever.net/tutorials/view/lba-to-chs
LILO boot loader
+http://www.uruk.org/orig-grub/PC_partitioning.txt
C:
http://www.drdobbs.com/extending-c-for-object-oriented-programm/184402731
diff --git a/doc/README.DISK_GEOMETRY b/doc/README.DISK_GEOMETRY
index 54f6092..5001679 100644
--- a/doc/README.DISK_GEOMETRY
+++ b/doc/README.DISK_GEOMETRY
@@ -2,69 +2,15 @@ This affects the boot loader in stage 1 using
BIOS functions to read stage 2 and the kernel
Geometry Specification
-
-360 KB 5.25"
-
+(emulated) floppy gives us
-1.2 MB 5.25"
-
+0x0101, 0x4f12
-720 KB 3.5"
-
+which is 2 heads, 80 sectors, 18 sectors, sounds good
-1.44 MB 3.5"
-
+Asus, Eeepc 701, pendrive 16 gb:
-2.88 MB 3.5"
+0x0000, 0x0012
-Tracks (Cylinders)
-
-
-40
-
-
-80
-
-
-80
-
-
-80
-
-
-80
-
-Sectors Per Track/Cylinder
-
-
-9
-
-
-15
-
-
-9
-
-
-18
-
-
-36
-
-Total Sectors Per Disk
-
-
-720
-
-
-2,400
-
-
-1,440
-
-
-2,880
-
-
-5,760
+mmh? \ No newline at end of file
diff --git a/src/Makefile b/src/Makefile
index 0fbf658..55f8975 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -97,6 +97,10 @@ setjmp.o: setjmp.asm
clean:
-rm -f boot.bin kernel.bin kernel.sym kernel.elf image.bin magic.bin *.o boot.map image.tmp
+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: 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 3f9c127..88f7404 100644
--- a/src/boot.asm
+++ b/src/boot.asm
@@ -40,6 +40,10 @@
mov si, MESSAGE_LOADING_STAGE_2
call print_string
+; detect disk geometry
+ mov dl, [BOOT_DRIVE]
+ call detect_disk_geometry
+
; load stage 2 and the kernel together to 0x7e00 (directly
; after the boot sector)
mov dl, [BOOT_DRIVE]
diff --git a/src/stage1_functions.asm b/src/stage1_functions.asm
index c17feeb..e9281c4 100644
--- a/src/stage1_functions.asm
+++ b/src/stage1_functions.asm
@@ -91,6 +91,10 @@ current_row:
ret
; data sections used for reading from disk
+SECTORS_PER_CYLINDER:
+ db 0x13 ; detect parameters enters the correct value here (sectors + 1)
+NOF_HEADS:
+ db 0x02 ; number of heads + 1
SECTORS_TO_LOAD:
db NOF_LOAD_SECTORS ; load NOF_LOAD_SECTORS sectors in total
CURRENT_SECTOR:
@@ -100,6 +104,23 @@ CURRENT_CYLINDER:
CURRENT_HEAD:
db 0
+; detect disk geometry
+; IN dl: drive
+detect_disk_geometry:
+ mov dx, 0
+ mov es, dx
+ mov ah, 0x08
+ int 0x13
+ add dh, 1
+ mov [NOF_HEADS], BYTE dh
+; call print_hex
+; mov dx, cx
+; call print_hex
+ and cl, 0x3F
+ add cl, 1
+ mov [SECTORS_PER_CYLINDER], BYTE cl
+ ret
+
; read the whole stage2 and kernel from the disk
; IN dl: drive to read from
read_from_disk:
@@ -118,14 +139,16 @@ read_from_disk:
add bx, 0x200 ; advance write buffer position
add [CURRENT_SECTOR], BYTE 1 ; next sector
- cmp [CURRENT_SECTOR], BYTE 0x13 ; assuming 18 sectors per track for now
+ mov ch, [SECTORS_PER_CYLINDER]
+ cmp [CURRENT_SECTOR], ch ; assuming 18 sectors per track for now
je .next_head
jmp .read_next_sector
.next_head:
mov [CURRENT_SECTOR], BYTE 1 ; start from first sector again
add [CURRENT_HEAD], BYTE 1 ; advance head
- cmp [CURRENT_HEAD], BYTE 0x02 ; 2 heads on floppies
+ mov ch, [NOF_HEADS]
+ cmp [CURRENT_HEAD], ch ; 2 heads on floppies
je .next_track
jmp .read_next_sector
@@ -177,7 +200,7 @@ read_one_sector_from_disk:
jmp $
kill_motor:
- mov dx, 0x3F2
- mov al, 0x00
- out dx, al
+ mov dx, 0x3F2
+ mov al, 0x00
+ out dx, al
ret