⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 grub-0.97-patch1-startups

📁 grub for dos ,people can use it in dos for calling linux
💻 97-PATCH1-STARTUPS
📖 第 1 页 / 共 5 页
字号:
+//----------------------------------------------------------------------------+	cmpl	$0, ABS(backup_mbr)+	jz	1f		# will not backup++	movl	$ABS(mbr_63_sectors), %esi+	movl	$ABS(mbr_63_sectors + 0x200), %edi+	movl	$0x80, %ecx	# 0x80 dwords = 0x200 bytes++	cld+	repz movsl++1:++//----------------------------------------------------------------------------+	/* copy byte 0000 to 01b7 of grldr.mbr to ABS(mbr_63_sectors) */++	movl	$ABS(_start1), %esi+	movl	$ABS(mbr_63_sectors), %edi+	movl	$0x6e, %ecx	# 0x6e dwords = 0x1b8 bytes++	cld+	repz movsl++	/* modify ABS(mbr_floppy) bit */++	movb	ABS(mbr_floppy), %al+	andb	$0x01, %al+	movb	%al, ABS(mbr_63_sectors + 2)++	/* modify ABS(mbr_osbr) bit */++	movb	ABS(mbr_osbr), %al+	andb	$0x01, %al+	shlb	$1, %al+	orb	%al, ABS(mbr_63_sectors + 2)++	/* modify ABS(boot_prevmbr) bit */++	movb	ABS(boot_prevmbr), %al+	notb	%al+	andb	$0x01, %al+	rorb	$1, %al+	orb	%al, ABS(mbr_63_sectors) + 2++	/* modify ABS(time_out) byte */++	movb	ABS(time_out), %al+	movb	%al, ABS(mbr_63_sectors) + 3++	/* modify ABS(hot_key) byte */++	movw	ABS(hot_key), %ax+	movw	%ax, ABS(mbr_63_sectors) + 4++	/* modify ABS(preferred_drive) byte */++	movb	ABS(preferred_drive), %al+	movb	%al, ABS(mbr_63_sectors) + 6++	/* modify ABS(preferred_partition) byte */++	movb	ABS(preferred_partition), %al+	movb	%al, ABS(mbr_63_sectors) + 7++	/* copy byte 0400 and the rest of grldr.mbr to ABS(mbr_63_sectors) */++	movl	$ABS(_start1 + 0x400), %esi+	movl	$ABS(mbr_63_sectors + 0x400), %edi+	movl	$((pre_stage2_start - _start1 - 0x400) / 4), %ecx++	cld+	repz movsl++//----------------------------------------------------------------------------+2:	/* label for the above floppy code to jump */++	/* OK. Now write file! */++	xorl	%eax, %eax+	+	cmpw	$2, ABS(read_only)+	jne	3f++	pushl	%ebx		# file descriptor, or 0 if specified BIOS drive++	/* for safety, don't write too many sectors */+	cmpl	$0xffffffff, ABS(install_partition)+	jne	1f+	cmpl	$0xffffffff, ABS(floppy)+	je	2f+1:+	cmpl	$4, ABS(sectors_to_write)+	jbe	1f+	movl	$4, ABS(sectors_to_write)+	jmp	1f+2:+	cmpl	$((pre_stage2_start - _start1) / 512), ABS(sectors_to_write)+	jbe	1f+	movl	$((pre_stage2_start - _start1) / 512), ABS(sectors_to_write)+1:+#ifdef __DOS_16++	xorl	%eax, %eax+	cmpl	$0xff, ABS(bios_drive_number)+	je	1f+	movb	$0x03, %ah	# write to disk+	movb	ABS(sectors_to_write), %al+//	cmpl	$0xffffffff, ABS(floppy)+//	je	2f+//	movb	$4, %al		# write 4 sectors if it is floppy+//2:+	movw	$ABS(mbr_63_sectors), %bx+	movw	$1, %cx+	movw	ABS(bios_drive_number), %dx+	int	$0x13+	jmp	2f+1:+	//WRITE TO FILE OR DEVICE++	//AH = 40h+	//BX = file handle+	//CX = number of bytes to write+	//DS:DX -> data to write++	//Return:+	//CF clear if successful AX = number of bytes actually written+	//CF set on error AX = error code (05h,06h) +	movl	$0x4000, %eax+	movl	ABS(sectors_to_write), %ecx+	shll	$9, %ecx+	//movl	$(pre_stage2_start - _start1), %ecx+//	cmpl	$0xffffffff, ABS(floppy)+//	je	1f+//	movl	$0x800, %ecx	# write 4 sectors if it is floppy+//1:+	movl	$ABS(mbr_63_sectors), %edx+	int	$0x21+2:+	jnc	1f+	negl	%eax+1:+#else+	/* ssize_t write(int fd, const void *buf, size_t count) */++	movl	$4, %eax	# sys_write+	movl	$ABS(mbr_63_sectors), %ecx+	movl	ABS(sectors_to_write), %edx+	shll	$9, %edx+	//movl	$(pre_stage2_start - _start1), %edx	# length of grldr.mbr+//	cmpl	$0xffffffff, ABS(floppy)+//	je	1f+//	movl	$0x800, %edx	# write 4 sectors if it is floppy+//1:+	int	$0x80+#endif++	popl	%ebx		# file descriptor, or 0 if specified BIOS drive+3:+	cmpl	$0xffffffff, ABS(install_partition)+	je	3f+	+	/* for install_partition, SF=0 when success, SF=1 when failure */+	testl	%eax, %eax+	ret+3:+	testl	%eax, %eax+	movl	$ABS(msg_write_file), %ecx+	js	4f	/* error */++//----------------------------------------------------------------------------+	cmpl	$0xffffffff, ABS(floppy)+	jne	3f++	movl	$ABS(msg_geometry_S), %ecx+	call	8f	/* linux_print */++	movl	ABS(probed_sectors_per_track), %eax+	call	6f	/* print decimal number */++	movl	$ABS(msg_geometry_H), %ecx+	call	8f	/* linux_print */++	movl	ABS(probed_heads), %eax+	call	6f	/* print decimal number */++	movl	$ABS(msg_success), %ecx+	call	8f	/* linux_print */+3:+//success:++	# EBX=file descriptor, or 0 if specified BIOS drive+	+	xorl	%eax, %eax	# exit code = 0++	jmp	1f+	+//error:+4:+	# EBX=file descriptor, or 0 if specified BIOS drive+	+	testl	%ecx, %ecx+	jz	2f+	call	8f	/* linux_print */+2:+	movl	$ABS(msg_usage), %ecx+	call	8f	/* linux_print */++	movl	$1, %eax	# exit code = 1++1:+	testl	%ebx, %ebx+	jz	1f++	pushl	%eax		# exit code++#ifdef __DOS_16++	movb	$0x3e, %ah	// close file (BX = file handle)+	int	$0x21+	jnc	2f+	negl	%eax		/* EAX < 0 */+2:+#else++	/* int close(int fd); */+	movl	$6, %eax	# sys_close+	int	$0x80+#endif+	movl	$ABS(msg_close_file), %ecx+	testl	%eax, %eax+	+	popl	%eax		# exit code++	jns	1f++	call	8f	/* linux_print */++//exit:+1:+#ifdef __DOS_16+	+	movb	$0x4c, %ah	// EXIT - TERMINATE WITH RETURN CODE in AL+	int	$0x21		// call DOS++#else+	xchgl	%eax, %ebx	# move exit code in EAX to EBX+	movl	$1, %eax	# sys_exit+	int	$0x80+#endif+		+	ret++//----------------------------------------------------------------------------+//floppy:+5:++	pushal++	/* First, try ext2 */++	cmpw	$0xEF53, 0x438(iSI)	/* Magic signature */+	jnz	1f+	xorl	%eax, %eax+	cmpl	%eax, 0x400(iSI)	/* s_inodes_count */+	jz	1f+	cmpl	%eax, 0x404(iSI)	/* s_blocks_count */+	jz	1f+	cmpw	%ax, 0x458(iSI)		/* s_inode_size, usually 0x80 */+	jz	1f+	cmpl	%eax, 0x420(iSI)	/* s_blocks_per_group */+	jz	1f+	cmpl	%eax, 0x428(iSI)	/* s_inodes_per_group */+	jz	1f+	movl	0x414(iSI), %eax	/* s_first_data_block */+	movw	%ax, %bx		/* BX=1 for 1K block, 0 otherwise */+	shrl	$1, %eax		/* must be 0 */+	jnz	1f+	movl	0x418(iSI), %ecx	/* s_log_block_size */+	cmpl	$4, %ecx		/* max size of block is 16K */+	ja	1f+	negw	%cx			/* CF clear for 1K block, set otherwise */+	adcw	%ax, %bx+	decw	%bx+	jnz	1f++	/* BX = 0 */++	/* super block is sane */++	/* is EXT2 allowed write? */++	testl	$0x10, ABS(fstypes)+	jnz	2f+	/* EXT2 write not allowed */+	+	movl	$0, ABS(sectors_to_write)+	+	movl	$ABS(msg_fstype_ext2_deny), %ecx+	call	8f	/* linux_print */+	+	stc+	popal+	ret+2:+	/* write to ext2 boot area */++	cld+	movl	$ABS(_start1 + 0x800), %esi	/* points to the 5th sector */+	movl	$ABS(mbr_63_sectors), %edi+	lodsw				/* The first 2 byte: short jmp */+	LEAL	0x400(%edi), %esi	/* ESI points to super block */+	stosw++	/* lba indicator byte is not used. so we shouldn't touch it. */++	/* check lba-chs-mode specified, 1 byte */+	cmpl	$-1, ABS(lba)		/* lba-chs-mode  not specified? */+	je	2f			/* yes, do nothing. */++#if 0+	movb	$0x42, %al		/* initialize to lba mode. */+	cmpl	$0, ABS(lba)		/* chs ? */+	jnz	10f			/* no, it is not chs.*/+	movb	$0x02, %al		/* yes, it is chs. */+10:+#else+	/* if specified lba or chs, we simply place a 0x90. */+	movb	$0x90, %al+#endif+	stosb+	decl	%edi+2:++	addl	$(1+10), %edi		/* skip 10-byte OEM name */+	+	/* Sectors per block, byte */+	+	movb	0x18(iSI), %cl		/* s_log_block_size */+	movl	$2, %eax+	shlw	%cl, %ax+	stosb+	+	/* Bytes per block, word */+	+	shlw	$9, %ax			/* block size is word wide */+	stosw++	/* Pointers covered by an indirect block, dword */+	/* Pointers per block, dword */+	+	shrw	$2, %ax+	pushl	%eax		/* Pointers per block */+	addb	$8, %cl+	shll	%cl, %eax+	stosl			/* Pointers covered by an indirect block */+	popl	%eax+	stosl			/* Pointers per block */+	+	/* Sectors per track, word */++	cmpl	$0xFFFFFF3F, ABS(sectors_per_track)+	je	10f+	movb	ABS(sectors_per_track), %al+	cbw+	stosw+	subl	$2, %edi+10:+	addl	$2, %edi++	/* Number of heads, word */+	+	cmpl	$0xFFFF00FF, ABS(heads)+	je	10f+	movw	ABS(heads), %ax+	stosw+	subl	$2, %edi+10:+	addl	$2, %edi+	+	/* hidden sectors(i.e., partition start), dword */+	+	movb	ABS(floppy), %al	/* partition number(0xFF for floppy) */+	cmpb	$0xff, %al+	jne	10f+	/* real floppy */+	cmpl	$0xffffffff, ABS(start_sector)+	sete	%al+	movzbl	%al, %eax+	addl	ABS(start_sector), %eax+	stosl+	jmp	11f+10:+	/* hard drive partition */+	addl	$4, %edi+	cmpl	$0xffffffff, ABS(start_sector)+	je	11f+	movl	ABS(start_sector), %eax+	subl	$4, %edi+	stosl+11:+	+	/* total sectors, dword */++	movl	%es:(%edi), %eax+	cmpl	%eax, ABS(total_sectors)+	jbe	10f+	movl	ABS(total_sectors), %eax+10:+	stosl+	+	/* drive number, byte */++	//this byte is not used.+	incl	%edi++	/* partition number, byte */++	movb	ABS(floppy), %al+	stosb+	+	/* reserved, word */++	incl	%edi+	incl	%edi++	/* Number of inodes per group, dword */++	movl	0x28(iSI), %eax		/* s_inodes_per_group */+	stosl+	+	/* block number for group descriptors, dword */++	movl	0x14(iSI), %eax		/* s_first_data_block */+	incw	%ax+	stosl+	+	/* Machine code begins at offset 0x30, 462 bytes plus +	 * 2 bytes of boot signature */++	movl	$ABS(_start1 + 0x830), %esi+	movl	$(464 / 4), %ecx+	repz movsl+	+	movl	$1, ABS(sectors_to_write)+	+	movl	$ABS(msg_fstype_ext2_allow), %ecx+	call	8f	/* linux_print */+	+	clc+	popal+	ret++1:+	/* Secondly, try FAT12/16/32/NTFS */+	+	cld+	cmpw	$0xAA55, 0x1fe(iSI)	/* boot signature */+	jne	1f			/* not a normal BPB */+	cmpw	$0x200, 0x0b(iSI)	/* bytes per sector */+	jne	1f			/* not a normal BPB */+	movb	0x0d(iSI), %al		/* sectors per cluster */+	testb	%al, %al+	jz	1f			/* invalid if = 0 */+	movb	%al, %cl+	movw	$128, %ax+	divb	%cl			/* quo=AL, rem=AH */+	testb	%ah, %ah+	jnz	1f			/* invalid if not 2^n */+	movw	0x18(iSI), %ax		/* sectors per track */+	testw	%ax, %ax+	jz	1f			/* invalid if = 0 */+	cmpw	$63, %ax+	ja	1f			/* invalid if > 63 */+	movw	0x1a(iSI), %ax		/* number of heads */+	decw	%ax			/* Max head number, should be a byte */+	testb	%ah, %ah		/* should be 0 */+	jnz	1f			/* invalid if number of heads > 256 */+	cmpb	$0xf0, 0x15(iSI)	/* media descriptor */+	jb	1f++//	movw	$0x0600, %bx		/* FAT12/FAT16 */+//	movw	$0x003c, %cx		/* FAT12/FAT16 */++	movb	0x10(iSI), %al		/* number of FATs(NTFS:0, FAT:1,2) */+	cmpb	$2, %al+	ja	1f			/* abnormal FAT */+	movw	0x11(iSI), %ax		/* max root entries */+	testw	%ax, %ax+	jnz	2f			/* FAT12/FAT16 */++	/* FAT32 or NTFS */+	movw	0x13(iSI), %ax		/* total sectors(small) */+	testw	%ax, %ax+	jnz	1f			/* invalid FAT32 BPB */+	movw	0x16(iSI), %ax		/* sectors per FAT(small) */+	testw	%ax, %ax+	jnz	1f			/* invalid FAT32 BPB */+	movb	0x10(iSI), %al		/* number of FATs(NTFS:0, FAT:1,2) */+	testb	%al, %al+	jz	4f			/* NTFS */++	/* FAT32 */+	movl	0x20(iSI), %eax		/* FAT32 total sectors */+	testl	%eax, %eax+	jz	1f+	movl	0x24(iSI), %eax		/* FAT32 sectors per FAT */+	testl	%eax, %eax+	jz	1f+	/* sure it is FAT32 */++	/* is FAT32 allowed write? */++	testl	$0x04, ABS(fstypes)+	jnz	3f+	/* FAT32 write not allowed */+	movl	$0, ABS(sectors_to_write)+	+	movl	$ABS(msg_fstype_fat32_deny), %ecx+	call	8f	/* linux_print */+	+	stc+	popal+	ret+3:+	/* write to FAT32 boot area */+	+	cld+	movl	$ABS(_start1 + 0x400), %esi	/* points to the 3rd sector */+	movl	$ABS(mbr_63_sectors), %edi+	lodsw				/* The first 2 byte: short jmp */+	//leal	0x400(%edi), %esi	/* ESI points to super block */+	stosw++	/* check lba-chs-mode specified, 1 byte */+	cmpl	$-1, ABS(lba)		/* lba-chs-mode  not specified? */+	je	3f			/* yes, do nothing. */+	movb	$0x0e, %al		/* initialize to lba mode. */+	cmpl	$0, ABS(lba)		/* chs ? */+	jnz	10f			/* no, it is not chs.*/+	movb	$0x90, %al		/* yes, it is chs. */+10:+	stosb+	decl	%edi+3:+	addl	$(1+8+2+1+2+1+2+2+1+2), %edi+	addl	$(1+8+2+1+2+1+2+2+1+2), %esi+				/* skip 8-byte OEM name and Bytes per sector */+	+				/* and Sectors per cluster, byte */+				/* and Reserved sectors, word */+				/* and Number of FATs, byte */+				/* (Max root dir entries)Must be 0, word */+				/* (Total sectors small)Must be 0, word */+				/* Media descriptor, byte */+				/* (Sectors per FAT)Must be 0, word */+	/* sectors per track, word */+	lodsw+	addl	$2, %edi+	cmpl	$0xffffff3f, ABS(sectors_per_track)+	je	3f+	movb	ABS(sectors_per_track), %al+	cbw+	subl	$2, %edi+	stosw+3:+	+	/* number of heads, word */+	lodsw+	addl	$2, %edi+	cmpl	$0xffff00ff, ABS(heads)+	je	3f+	movw	ABS(heads), %ax+	subl	$2, %edi+	stosw+3:+	+	/* hidden sectors(i.e., part

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -