Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 24 additions & 28 deletions stage2/grldrstart.S
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,7 @@ Entry_32:
movb $0x41, %ah
movw $0x55AA, %bx
int $0x13
movl 0x8(%si), %eax /* partition_table_entry.start_sector_ofs (LBA) */
popw %ds
jc 1f /* No EBIOS */
cmpw $0xAA55, %bx
Expand All @@ -1052,6 +1053,7 @@ Entry_32:
jnc 1f /* No EBIOS */
/* EBIOS supported */
movb $0x42, (ebios_32 - 1 - Entry_32 + 0x7c00)
movl %eax, 0x1c(%bp) /* copy partition_table_entry.start_sector_ofs to hidden sectors */
1:
// movb (Loadusb_32 - Entry_32 + 0x7c00 +1), %al
// decb %al //al=1,When dl = 00 load
Expand Down Expand Up @@ -1473,6 +1475,7 @@ Entry_12_16:
movw $0x7c00, %bp
movw %bp, %sp
movw %ax, %ss /* stack and BP-relative moves up, too */
pushl 0x8(%si) /* partition_table_entry.start_sector_ofs (LBA) */
movw %ax, %ds
movw %ax, %es
sti /* after stack setup, we can use stack */
Expand All @@ -1487,13 +1490,15 @@ Entry_12_16:
int $0x13
popw %es
popw %ds
popl %eax /* partition_table_entry.start_sector_ofs (LBA) */
jc 1f /* No EBIOS */
cmpw $0xAA55, %bx
jne 1f /* No EBIOS */
rorb $1, %cl
jnc 1f /* No EBIOS */
/* EBIOS supported */
movb $0x42, (ebios_12_16 - 1 - Entry_12_16 + 0x7c00)
movl %eax, 0x1c(%bp) /* copy partition_table_entry.start_sector_ofs to hidden sectors */
1:
/* GET DRIVE PARMS: Calculate start of some disk areas */
movzwl 0x0e(%bp), %ebx /* reserved sectors */
Expand Down Expand Up @@ -2720,8 +2725,8 @@ Entry_exfat:
// movw %ax, %ds
// movw %ax, %es
movw %bp, %sp /* ss:sp=0000:7c00 */
pushl 0x8(%si) /* partition_table_entry.start_sector_ofs (LBA) */
sti
pushw %ax

movw %dx, 0x24(%bp) /* BIOS passes drive number in DL */

Expand All @@ -2733,10 +2738,12 @@ Entry_exfat:
movb $0x41, %ah
movw $0x55AA, %bx
int $0x13
popl %eax /* partition_table_entry.start_sector_ofs (LBA) */
jc 1f # No EBIOS
rorb %cl # ror cl: D0 C9
jnc 1f # No EBIOS
orb $0x80, 0x16(%bp) /* EBIOS supported */
movl %eax, 0x40(%bp) /* copy partition_table_entry.start_sector_ofs to hidden sectors */
jmp 2f
1:
movb $0x08, %ah
Expand All @@ -2745,6 +2752,7 @@ Entry_exfat:
andb $0x3f, %cl
movb %cl, 0x18(%bp)
2:
pushw %ss
popw %ds

movl 0x50(%bp), %eax
Expand Down Expand Up @@ -3244,7 +3252,7 @@ FAT_Address:
#define NT_FG_GPOS 8

#define nt_boot_drive -2(%bp)
#define nt_blocksize -4(%bp)
#define nt_blocksize 0xb(%bp)
#define nt_spc -5(%bp)
#define nt_mft_size -6(%bp)
#define nt_idx_size -7(%bp)
Expand Down Expand Up @@ -3325,7 +3333,8 @@ nt_part_ofs:
movw $0x7c00, %bp

movw %ax, %ss /* stack and BP-relative moves up, too */
leaw -0x20(%bp), %sp
leaw -0x20(%bp), %sp /* We need 0x20 bytes for the local variables nt_boot_drive etc. */
pushl 0x8(%si) /* partition_table_entry.start_sector_ofs (LBA) */
sti

movw %dx, nt_boot_drive
Expand All @@ -3338,6 +3347,7 @@ nt_part_ofs:
int $0x13

popw %ds /* DS=0 */
popl %eax /* partition_table_entry.start_sector_ofs (LBA) */

jc 1f /* No EBIOS */
cmpw $0xAA55, %bx
Expand All @@ -3348,6 +3358,7 @@ nt_part_ofs:
jnc 1f # No EBIOS
/* EBIOS supported */
movb $0x42, (ebios_nt - 1 - Entry_nt)(%bp)
movl %eax, 0x1c(%bp) /* copy partition_table_entry.start_sector_ofs to hidden sectors */
1:

pushw %ss /* SS=0 */
Expand All @@ -3364,9 +3375,7 @@ nt_part_ofs:
call readDisk_nt
1:

xorl %eax, %eax
movw 0xb(%bp), %ax // Bytes per sector (blocksize)
movw %ax, nt_blocksize
movzwl nt_blocksize, %eax // Bytes per sector (blocksize)

call convert_to_power_2
movb %cl, %bl
Expand Down Expand Up @@ -3538,6 +3547,8 @@ readDisk_nt:
pushw %bx /* buffer offset */
pushw $1 /* 1 sector to read */
pushw $16 /* size of this parameter block */
cmpb $0x42, (ebios_nt - 1 - Entry_nt)(%bp)
je 9f /* skip both of division by 0 below, avoiding crash caused by fatal interrupt */

xorl %ecx, %ecx
pushl 0x18(%bp) /* lo:sectors per track, hi:number of heads */
Expand All @@ -3558,6 +3569,7 @@ readDisk_nt:
shlb $6, %ah /* hi 2bit cylinder ... */
orb %ah, %cl /* ... should be in CL */

9:
movw $0x201, %ax /* read 1 sector */
ebios_nt: /* ebios_nt - 1 points to 0x02 that can be changed to 0x42 */

Expand Down Expand Up @@ -3594,15 +3606,6 @@ NTFS_Error:
jmp disk_error_nt


// Kernel load address, located at 0x1E8
// . = Entry_nt + 0x1e8

//nt_boot_image_end:

nt_loadseg_off:
.word 0
.word LOADSEG_NT

// Boot image offset and length, located at 0x1EE
// Lower 11 bit is offset, higher 5 bit is length
// . = Entry_nt + 0x1ec
Expand All @@ -3629,13 +3632,8 @@ print_ntfs:
int $0x10 /* via TTY mode */
cmpb $0, %al /* end of string? */
jne 1b /* until done */

/* The caller will change this to
* ljmp $0x9400, $(try_next_partition - _start1)
*/
jmp 1f

. = Entry_nt + 0x1e0
2:
jmp 2b

msg_NTFS_Not_Found_Error:
.ascii "No "
Expand All @@ -3646,18 +3644,16 @@ nt_boot_image:
msg_DiskReadError_nt:
.ascii "0\0"

. = Entry_nt + 0x1f4

error_go_back:
1:
jmp 1b

. = Entry_nt + 0x1fc

.word 0, 0xAA55

// Here starts sector #2

nt_loadseg_off:
.word 0
.word LOADSEG_NT

// Input:
// DI - current mft
ntfs_search:
Expand Down