aboutsummaryrefslogtreecommitdiffstats
path: root/mbr/mbr.S
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2007-04-10 15:23:30 -0700
committerH. Peter Anvin <hpa@zytor.com>2007-04-10 15:23:30 -0700
commit2621cc62fd4c10b2b60c8335242b7e02b618448f (patch)
treece69946cb67a95f81762d441f803b8503f091122 /mbr/mbr.S
parente93773c42fcf550bed275187d872c6e6ee7599bc (diff)
downloadlwip-2621cc62fd4c10b2b60c8335242b7e02b618448f.tar.gz
lwip-2621cc62fd4c10b2b60c8335242b7e02b618448f.tar.xz
lwip-2621cc62fd4c10b2b60c8335242b7e02b618448f.zip
MBR: fix problems when LBA > 65535*sectors.
Fix division overflow bug when LBA > 65535*sectors. Bug report by Devin Bayer.
Diffstat (limited to 'mbr/mbr.S')
-rw-r--r--mbr/mbr.S35
1 files changed, 17 insertions, 18 deletions
diff --git a/mbr/mbr.S b/mbr/mbr.S
index 3eff0708..1e6842bd 100644
--- a/mbr/mbr.S
+++ b/mbr/mbr.S
@@ -29,10 +29,10 @@
.text
.globl bootsec
-stack = 0x7c00
-driveno = (stack-6)
-heads = (stack-8)
-sectors = (stack-10)
+stack = 0x7c00
+driveno = (stack-6)
+sectors = (stack-8)
+secpercyl = (stack-10)
BIOS_page = 0x462
@@ -89,12 +89,13 @@ next:
/* Get (C)HS geometry */
movb $0x08, %ah
int $0x13
+ andw $0x3f, %cx /* Sector count */
+ pushw %cx /* Save sectors on the stack */
xorw %ax, %ax
movb %dh, %al /* dh = number of heads */
incw %ax /* From 0-based to count */
- pushw %ax /* Save heads on the stack */
- andw $0x3f, %cx /* Sector count */
- pushw %cx /* Save sectors on the stack */
+ mulw %cx /* Heads*sectors -> sectors per cylinder */
+ pushw %ax /* Save sectors/cylinder on the stack */
xorl %eax, %eax
pushl %eax /* Base */
@@ -112,18 +113,16 @@ read_sector:
read_sector_cbios:
movl %eax, %edx
shrl $16, %edx
- divw (sectors)
- incw %dx
- movw %dx, %cx
- xorw %dx, %dx
- divw (heads)
- /* dx = head, ax = cylinder */
+ divw (secpercyl)
+ rorb %ah
+ rorb %ah
+ movb %ah, %cl
movb %al, %ch
- shrw $2, %ax
- shrw %ax
- andb $0xc0, %al
- orb %al, %cl
- movb %dl, %dh
+ movw %dx, %ax
+ divb (sectors)
+ movb %al, %dh
+ incb %ah
+ orb %ah, %cl
movw $bootsec, %bx
movw $0x0201, %ax
jmp read_common