diff options
-rw-r--r-- | doc/LINKS.TODO | 1 | ||||
-rw-r--r-- | doc/README.DISK_GEOMETRY | 66 | ||||
-rw-r--r-- | src/Makefile | 4 | ||||
-rw-r--r-- | src/boot.asm | 4 | ||||
-rw-r--r-- | src/stage1_functions.asm | 33 |
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 |