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

📄 bootlace.inc

📁 grub4dos-0.4.4-2008- 08-src.zip
💻 INC
📖 第 1 页 / 共 5 页
字号:
	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	lodsl	movb	ABS(floppy), %cl	/* partition number(0xFF for floppy) */	cmpb	$0xff, %cl	jne	10f	/* real floppy */	cmpl	$0x90C031FC, %eax	/* FC=cld; 31 C0=xor ax,ax; 90=nop */	jne	10f	movl	$0x99C031FC, %eax	/* FC=cld; 31 C0=xor ax,ax; 99=cwd */10:	stosl		movl	$((464 / 4) - 1), %ecx	repz movsl		movl	$1, ABS(sectors_to_write)		movl	$ABS(msg_fstype_ext2_allow), %ecx	call	8f	/* linux_print */		clc	popal	ret1:	/* 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	ret3:	/* 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	%edi3:	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	stosw3:		/* number of heads, word */	lodsw	addl	$2, %edi	cmpl	$0xffff00ff, ABS(heads)	je	3f	movw	ABS(heads), %ax	subl	$2, %edi	stosw3:		/* hidden sectors(i.e., partition start), dword */	lodsl	addl	$4, %edi	cmpl	$0xffffffff, ABS(start_sector)	je	3f	movl	ABS(start_sector), %eax	subl	$4, %edi	stosl3:		/* total sectors, dword */	lodsl	addl	$4, %edi	cmpl	$0, ABS(total_sectors)	je	3f	movl	ABS(total_sectors), %eax	subl	$4, %edi	stosl3:		/* FAT32 sectors per FAT, dword, etc... */	addl	$(4+2+2+4+2+2+12+1+1+1+4+11+8), %esi	addl	$(4+2+2+4+2+2+12+1+1+1+4+11+8), %edi	//movl	$0xFFB6FCFA, %eax	/* CLI, CLD, MOV DH,FF */	lodsw	stosw	lodsb	stosb	lodsb		//decl	%edi	/* partition number, byte */	movb	ABS(floppy), %al	stosb		/* Machine code begins at offset 0x5e, 416 bytes without 	 * the ending 2 bytes of boot signature */	//movl	$ABS(_start1 + 0x45e), %esi	movl	$(416 / 4), %ecx	repz movsl		movl	$1, ABS(sectors_to_write)		movl	$ABS(msg_fstype_fat32_allow), %ecx	call	8f	/* linux_print */		clc	popal	ret4:	/* NTFS */	movl	0x20(iSI), %eax		/* FAT32 total sectors */	testl	%eax, %eax	jnz	1f	//movw	0x11(%si), %ax		/* max root entries */	//testw	%ax, %ax	//jnz	1f	movw	0x0e(iSI), %ax		/* reserved sectors */	testw	%ax, %ax	jnz	1f	/* sure it is NTFS */	/* is NTFS allowed write? */	testl	$0x08, ABS(fstypes)	jnz	3f	/* NTFS write not allowed */	movl	$0, ABS(sectors_to_write)		movl	$ABS(msg_fstype_ntfs_deny), %ecx	call	8f	/* linux_print */		stc	popal	ret3:#if 1	/* write to NTFS boot area */	cld	movl	$ABS(_start1 + 0xA00), %esi	/* points to the 6th sector */	movl	$ABS(mbr_63_sectors), %edi	lodsw				/* The first 2 byte: short jmp */	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	%edi3:	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	stosw3:		/* number of heads, word */	lodsw	addl	$2, %edi	cmpl	$0xffff00ff, ABS(heads)	je	3f	movw	ABS(heads), %ax	subl	$2, %edi	stosw3:		/* hidden sectors(i.e., partition start), dword */	lodsl	addl	$4, %edi	cmpl	$0xffffffff, ABS(start_sector)	je	3f	movl	ABS(start_sector), %eax	subl	$4, %edi	stosl3:		addl	$(4+1+1+1+1+8), %esi	addl	$(4+1+1+1+1+8), %edi			/* total sectors, unused, dword */			/* drive number, byte, and another 3 bytes; Usually 80 00 80 00 */			/* Number of sectors in the volume, qword */				//lodsl				//lodsl				//addl	$8, %edi	cmpl	$0, ABS(total_sectors)	je	3f	movl	ABS(total_sectors), %eax	subl	$8, %edi	stosl	xorl	%eax, %eax	/* high 32 bits */	stosl3:		addl	$(8+8+4+4+8+4), %esi	addl	$(8+8+4+4+8+4), %edi			/* 30 - LCN of VCN 0 of the $MFT, qword */			/* 38 - LCN of VCN 0 of the $MFTMirr, qword */			/* 40 - Clusters per MFT Record, dword */			/* 44 - Clusters per Index Record, dword */			/* 48 - Volume serial number, qword */			/* 50 - Checksum, usually 0, dword */	//movl	$0xFFB6FCFA, %eax	/* CLI, CLD, MOV DH,FF */	lodsw	stosw	lodsb	stosb	lodsb		//decl	%edi	/* partition number, byte */	movb	ABS(floppy), %al	stosb		/* Machine code begins at offset 0x58, ending at 0x7FF, where 	 * we assume that NTFS boot record takes up 4 sectors. */	movl	$((0x800 - 0x58)/ 4), %ecx	repz movsl		movl	$4, ABS(sectors_to_write)		movl	$ABS(msg_fstype_ntfs_allow), %ecx	call	8f	/* linux_print */		clc	popal	ret#else	/* write to NTFS boot area */	movl	$ABS(mbr_63_sectors), %edi	LEAL	0x400(%edi), %esi	/* ESI points to super block */		/* hidden sectors(i.e., partition start), dword */	cmpl	$0xffffffff, ABS(start_sector)	je	3f	movl	ABS(start_sector), %eax	movl	%eax, 0x1c(iDI)3:		/* drive number needn't touch */	/* partition number */	call	4f	jc	5f	movl	0x06(iSI), %eax		/* NT 4 */	cmpl	$0x03E8B800, %eax	/* MOV ES,AX */	jnz	3f	cmpl	$0x680007E8, 0x84(iDI)	/* call 008e; push (0D00) */	jnz	3f	movb	$0xB6, %al		/* 0xB6="MOV DH,imm8" */	movb	ABS(floppy), %ah	/* partition number */	movw	%ax, 0x0a(iSI)		movl	$4, ABS(sectors_to_write)		movl	$ABS(msg_fstype_ntfs_allow), %ecx	call	8f	/* linux_print */		clc	popal	ret3:		/* NT 5.0 */	cmpl	$0x680053E8, 0x71(iDI)	/* call 00C7; push (0D00) */	jnz	5f		movl	$0x4b, %ebx	movl	(iBX, iSI), %eax		/* NT 5 */	cmpl	$0x03E8B800, %eax		/* MOV ES,AX */	jz	3f		movl	$0x79, %ebx	movl	(iBX, iSI), %eax		/* NT 5p */	cmpl	$0x03E8B800, %eax		/* MOV ES,AX */	jnz	5f3:	movb	$0xB6, %al		/* 0xB6="MOV DH,imm8" */	movb	ABS(floppy), %ah	/* partition number */	movw	%ax, 4(iBX, iSI)		movl	$4, ABS(sectors_to_write)		movl	$ABS(msg_fstype_ntfs_allow), %ecx	call	8f	/* linux_print */		clc	popal	ret5:	/* No NTFS boot record present */	movl	$0, ABS(sectors_to_write)		movl	$ABS(msg_no_ntfs_boot_record), %ecx	call	8f	/* linux_print */		stc	popal	ret4:	/* change NT to GR */		pushal	cld	movl	$0x00520047, 0x202(iDI)	/* G R L D R */	addl	$0x0100, %edi	movl	$0x00fa, %ecx	movw	$0x014e, %ax    /* AL="N", AH=Carry for SAHF below */	movl	$0x52444c54, %ebx       /* "TLDR" */3:	repnz scasb		/* find "N" */	jcxz	4f		/* gets the end, exit */	cmpl	%ebx, (iDI)	/* is it "NTLDR"? */	jnz	3b		/* no, continue to find */	/* "NTLDR" is found, so we believe it is NT boot sector. */	movw	$0x5247, -1(iDI)	/* change "NT" to "GR" */	/* CF=0 for now */	lahf			/* Load Flags into AH */				/* AH = SF:ZF:xx:AF:xx:PF:xx:CF */				/* AH = binary xxxxxxx0 */	jmp	3b4:	sahf		/* Store AH into flags SF ZF xx AF xx PF xx CF */	/* CF=0 means "NTLDR" is found, CF=1 means "NTLDR" is not found. */	popal	ret#endif2:	/* FAT12/FAT16 */	movb	0x10(iSI), %al		/* number of FATs(NTFS:0, FAT:1,2) */	testb	%al, %al	jz	1f	movw	0x16(iSI), %ax		/* sectors per FAT(small) */	testw	%ax, %ax	jz	1f//	movw	$(FAT16_message - _start1), %si	cmpw	$12, %ax	ja	4f			/* FAT16 */	/* sure it is FAT12 */	/* is FAT12 allowed write? */	testl	$0x01, ABS(fstypes)	jnz	2f	/* FAT12 write not allowed */	movl	$0, ABS(sectors_to_write)		movl	$ABS(msg_fstype_fat12_deny), %ecx	call	8f	/* linux_print */		stc	popal	ret2:	/* write to FAT12 boot area */		cld	movl	$ABS(_start1 + 0x600), %esi	/* points to the 4th 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	2f			/* 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	%edi2:	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	2f	movb	ABS(sectors_per_track), %al	cbw	subl	$2, %edi	stosw2:		/* number of heads, word */	lodsw	addl	$2, %edi	cmpl	$0xffff00ff, ABS(heads)	je	2f	movw	ABS(heads), %ax	subl	$2, %edi	stosw2:		/* hidden sectors(i.e., partition start), dword */	lodsl	addl	$4, %edi	cmpl	$0xffffffff, ABS(start_sector)	je	2f	movl	ABS(start_sector), %eax	subl	$4, %edi	stosl2:		/* total sectors, dword */	lodsl	addl	$4, %edi	cmpl	$0, ABS(total_sectors)	je	2f	movl	ABS(total_sectors), %eax	subl	$4, %edi	stosl2:	/* drive number, byte, etc... */	addl	$(1+1+1+4+11+8), %esi	addl	$(1+1+1+4+11+8), %edi	//movl	$0xFFB6FCFA, %eax	/* CLI, CLD, MOV DH,FF */	lodsw	stosw	lodsb	stosb	lodsb		//decl	%edi	/* partition number, byte */	movb	ABS(floppy), %al	stosb		/* Machine code begins at offset 0x42, 444 bytes without 	 * the ending 2 bytes of boot signature */	//movl	$ABS(_start1 + 0x642), %esi	movl	$(444 / 4), %ecx	repz movsl		movl	$1, ABS(sectors_to_write)		movl	$ABS(msg_fstype_fat12_allow), %ecx	call	8f	/* linux_print */		clc	popal	ret4:	/* sure it is FAT16 */	/* is FAT16 allowed write? */	testl	$0x02, ABS(fstypes)	jnz	2f	/* FAT16 write not allowed */	movl	$0, ABS(sectors_to_write)		movl	$ABS(msg_fstype_fat16_deny), %ecx	call	8f	/* linux_print */		stc	popal	ret2:	/* write to FAT16 boot area */		cld	movl	$ABS(_start1 + 0x600), %esi	/* points to the 4th 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	2f			/* 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	%edi2:	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	2f	movb	ABS(sectors_per_track), %al	cbw	subl	$2, %edi	stosw2:		/* number of heads, word */	lodsw	addl	$2, %edi	cmpl	$0xffff00ff, ABS(heads)	je	2f	movw	ABS(heads), %ax	subl	$2, %edi	stosw2:		/* hidden sectors(i.e., partition start), dword */	lodsl	addl	$4, %edi	cmpl	$0xffffffff, ABS(start_sector)	je	2f	movl	ABS(start_sector), %eax	subl	$4, %edi	stosl2:			/* total sectors, dword */	lodsl	addl	$4, %edi	cmpl	$0, ABS(total_sectors)	je	2f

⌨️ 快捷键说明

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