/*
* read_sector: read a single sector pointed to by %eax to 0x7c00.
- * CF is set on error. All registers clobbered.
+ * CF is set on error. All registers saved.
*/
read_sector:
+ pushal
read_sector_cbios:
xorl %edx, %edx
divl (secpercyl)
read_common:
movb (driveno), %dl
int $0x13
+ popal
ret
/*
* read_partition_table:
* Read a partition table (pointed to by %eax), and copy
* the partition table into the ptab buffer.
- * Preserve registers.
+ * Clobbers %si, %di, and %cx, other registers preserved.
*/
ptab = _start+446
read_partition_table:
- pushal
call read_sector
jc 20f
movw $bootsec+446, %si
movw $(16*4/2), %cx
rep ; movsw
20:
- popal
ret
/*
movw %sp, %bp
/* Search for active partitions */
- movw $ptab, %di
+ movw $ptab, %bx
movw $4, %cx
xorw %ax, %ax
- push %di
+ push %bx
push %cx
5:
- testb $0x80, (%di)
+ testb $0x80, (%bx)
jz 6f
incw %ax
- movw %di, %si
+ movw %bx, %si
6:
- addw $16, %di
+ addw $16, %bx
loopw 5b
decw %ax /* Number of active partitions found */
jns too_many_active
/* No active partitions found, look for extended partitions */
- popw %di /* %di <- ptab */
+ popw %bx /* %bx <- ptab */
popw %cx /* %cx <- 4 */
7:
- movb 4(%di), %al
+ movb 4(%bx), %al
cmpb $0x0f, %al /* 0x0f = Win9x extended */
je 8f
andb $~0x80, %al /* 0x85 = Linux extended */
try to scan it. If the scan returns, re-load the current
partition table and resume scan. */
8:
- movl 8(%di), %eax /* Partition table offset */
+ movl 8(%bx), %eax /* Partition table offset */
movl 20(%bp), %edx /* "Root" */
addl %edx, %eax /* Compute location of new ptab */
andl %edx, %edx /* Is this the MBR? */
/* fall through */
9:
/* Not an extended partition */
- addw $16, %di
+ addw $16, %bx
loopw 7b
/* Nothing found, return */
movl 8(%si), %eax
addl 28(%bp), %eax
movl %eax, 8(%si) /* Adjust in-memory partition table entry */
- pushw %si
call read_sector
- popw %si /* ds:si -> partition table entry */
jc disk_error
cmpw $0xaa55, (bootsec+510)
jne missing_os /* Not a valid boot sector */