📄 grub-0.95-patch4-emulation
字号:
diff -Naur grub-0.95_ntfs/ChangeLog grub-0.95_emulation/ChangeLog--- grub-0.95_ntfs/ChangeLog 2004-10-22 14:26:29.333877624 +0800+++ grub-0.95_emulation/ChangeLog 2004-10-22 17:43:06.671987456 +0800@@ -1,5 +1,19 @@ 2004-07-13 + From Tinybit <tinybit@163.net>:+ For disk drive emulation:+ * stage2/asm.S (int13_handler, etc): floppy and harddisk emulation++ * grub/asmstub.c: floppy and harddisk emulation++ * stage2/builtins.c: floppy and harddisk emulation++ * stage2/common.c: floppy and harddisk emulation++ * stage2/disk_io.c: floppy and harddisk emulation++ * stage2/shared.h: floppy and harddisk emulation+ From Gandalf <f22_storm@163.com>: NTFS support diff -Naur grub-0.95_ntfs/grub/asmstub.c grub-0.95_emulation/grub/asmstub.c--- grub-0.95_ntfs/grub/asmstub.c 2004-03-13 01:01:49.000000000 +0800+++ grub-0.95_emulation/grub/asmstub.c 2004-10-22 17:33:28.547875680 +0800@@ -338,11 +338,19 @@ /* Copy MAP to the drive map and set up the int13 handler. */ void-set_int13_handler (unsigned short *map)+set_int13_handler (struct drive_map_slot *map) { /* Nothing to do in the simulator. */ } +void+unset_int13_handler (void)+{+ /* Nothing to do in the simulator. */+}++struct drive_map_slot hooked_drive_map[DRIVE_MAP_SIZE + 1];+ int get_code_end (void) {diff -Naur grub-0.95_ntfs/stage2/asm.S grub-0.95_emulation/stage2/asm.S--- grub-0.95_ntfs/stage2/asm.S 2004-05-24 00:22:23.000000000 +0800+++ grub-0.95_emulation/stage2/asm.S 2004-10-22 18:36:49.010117600 +0800@@ -617,121 +617,1126 @@ pushl %esi /* copy MAP to the drive map */- movl $(DRIVE_MAP_SIZE * 2), %ecx- movl $ABS(drive_map), %edi+ movl $(DRIVE_MAP_SIZE * 12 / 4), %ecx /* sizeof(struct drive_map_slot) */+ movl $ABS(hooked_drive_map), %edi movl 8(%ebp), %esi cld rep- movsb+ movsl /* save the original int13 handler */ movl $0x4c, %edi- movw (%edi), %ax- movw %ax, ABS(int13_offset)- movw 2(%edi), %ax- movw %ax, ABS(int13_segment)+ movl (%edi), %eax+ movl %eax, ABS(int13_offset) /* decrease the lower memory size and set it to the BIOS memory */ movl $0x413, %edi decw (%edi)+ decw (%edi) xorl %eax, %eax movw (%edi), %ax - /* compute the segment */- shll $6, %eax+ /* compute the segment(high word); the offset(low word) should be 0 */+ shll $(16 + 6), %eax /* save the new int13 handler */ movl $0x4c, %edi- movw %ax, 2(%edi)- xorw %cx, %cx- movw %cx, (%edi)+ movl %eax, (%edi) /* copy int13_handler to the reserved area */- shll $4, %eax+ shrl $12, %eax movl %eax, %edi movl $ABS(int13_handler), %esi- movl $(int13_handler_end - int13_handler), %ecx+ movl $((int13_handler_end - int13_handler) / 4), %ecx rep- movsb+ movsl popl %esi popl %edi popl %ebp ret +/*+ * unset_int13_handler(void)+ *+ * Restore the original int13 handler+ */+ENTRY(unset_int13_handler)+ pushl %edi + /* check if int13_handler is set */+ movl $0x413, %edi+ xorl %eax, %eax+ movw (%edi), %ax+ cmpw $640, %ax+ jae 1f+ cmpw $632, %ax+ jb 1f+ shll $(16 + 6), %eax+ movl $0x4c, %edi+ cmpl %eax, (%edi)+ jne 1f+ shrl $12, %eax /* segment absolute address */+ movl %eax, %edi+ xorl %eax, %eax+ movw $(int13_offset - int13_handler), %ax+ addl %eax, %edi+ cmpl $0x9a006e8b, -4(%edi) /* movw (%bp), %bp; lcall */+ jnz 1f+ movl ABS(int13_offset), %eax+ cmpl (%edi), %eax+ jnz 1f+ cmpl $0xc0000000, %eax /* is it a BIOS vector? */+ jb 1f++ /* restore the original int13 handler */+ movl $0x4c, %edi+ stosl++ /* increase the lower memory size and set it to the BIOS memory */+ movl $0x413, %edi+ incw (%edi)+ incw (%edi)+1:+ popl %edi+ ret++ /* - * Map a drive to another drive.+ * Map a drive to another drive or a disk image file. */ .code16 int13_handler:- pushw %ax+#if 0+ /* for test only - direct far jmp to original int13 */+ ljmp %cs:*(int13_offset - int13_handler)+#endif+ cmpb $0x1a, %ah /* PS/2 low level format ESDI drive!!!! */+ je error_01_disable2 /* disabled in any case */+ pushl %eax pushw %bp movw %sp, %bp pushw %si /* set %si to the drive map */- movw $(drive_map - int13_handler), %si+ movw $(hooked_drive_map - int13_handler), %si /* find the drive number from the drive map */ cld+ subw $12, %sp 1: - lodsw %cs:(%si), %ax+ addw $12, %sp+ lodsl %cs:(%si), %eax+ pushl %eax+ lodsl %cs:(%si), %eax+ pushl %eax+ lodsl %cs:(%si), %eax+ pushl %eax++ movl -6(%bp), %eax /* FROM, TO, Hmax, Smax */+ /* check if this is the end */- testw %ax, %ax- jz 2f- /* check if this matches the drive number */- cmpb %al, %dl- jne 1b- /* if so, perform the mapping */- movb %ah, %dl+ testl %eax, %eax+ jnz 3f /* not end, continue */+ movl -10(%bp), %eax /* StartLBA */+ testl %eax, %eax+ jnz 3f /* not end, continue */+ movl -14(%bp), %eax /* S_count */+ testl %eax, %eax+ jz 2f /* map whole drive to itself signals the end */+3:+ /* Now this is a valid drive map slot */+ movw -6(%bp), %ax /* AL=FROM, AH=TO */+ cmpb %al, %dl /* check if this matches the drive number */+ jne 1b /* no, continue to check the next map */++ /* yes, found the map corresponding to drive DL */+ movl -10(%bp), %eax /* StartLBA */+ testl %eax, %eax+ jnz drive_emulation+ movl -14(%bp), %eax /* S_count */+ shrl $1, %eax+ jnz drive_emulation+ movw -4(%bp), %ax /* AL=Hmax, AH=Smax */+ testb $62, %ah /* Sectors > 1 means force geom, this -- */+ jnz drive_emulation /* -- also leads to drive emulation */++ /* ignore geom and directly map a whole drive */+ + /* bits of AH:+ * 7 bit set means readonly/fakewrite+ * 6 bit set means disable LBA+ * 5 - 1 bits already cleared(=0)+ * 0 bit cleared means disable CHS+ * So, if AH!=1, it is a restricted disk access;+ * and if AH=1, it is a normal disk access.+ */+ cmpb $1, %ah+ je 1f+ call restricted_map+1:+ /* map a whole drive, normal access */+ movw -6(%bp), %ax /* AL=FROM, AH=TO */+ movb %ah, %dl /* Let DL access TO instead of FROM */ 2:- /* restore %si */- popw %si- /* save %ax in the stack */- pushw %ax- /* simulate the interrupt call */- pushw 8(%bp)- /* set %ax and %bp to the original values */- movw 2(%bp), %ax- movw (%bp), %bp- /* lcall */- .byte 0x9a+ /* might map to itself, i.e., acturally not mapped */+ + movw -2(%bp), %si /* restore SI */++ pushw 10(%bp) /* pushfw, simulate the interrupt call */+ + movl 2(%bp), %eax /* restore EAX */+ movw (%bp), %bp /* restore BP */+ .byte 0x9a /* lcall, simulate the interrupt call */ int13_offset: .word 0 int13_segment: .word 0- /* save flags */- pushf- /* restore %bp */- movw %sp, %bp- /* save %ax */+ pushw %ax /* save AX */+ pushfw /* save flags returned by int13 */+ popw %ax+ movw %sp, %bp /* set new BP */+ movw %ax, 26(%bp) /* update the flags in the stack */+ + /* check if should restore(reversely map) the drive number */+ jc 1f /* restore DL on error */+ movw 18(%bp), %ax /* lower word of the saved EAX */+ cmpb $0x08, %ah /* int13 AH=08h, read drive parameters */+ je 3f /* DL==number of drives, should not restore */+ cmpb $0x15, %ah /* int13 AH=15h, read drive type */+ je 3f /* CX:DX==total sectors, should not restore */+1:+ /* try to restore DL if possible */+ movw 10(%bp), %ax /* get the drive mapping */+ cmpb %al, %ah /* check if the mapping was performed */+ je 3f /* not performed, so need not restore DL */+ cmpb %dl, %ah+ jne 3f /* DL changed by int13, so do not restore */+ movb %al, %dl /* restore DL back to the FROM drive */+3:+ movl 18(%bp), %eax /* restore the original EAX */+ popw %ax /* update the int13 status in AX */+ movw 16(%bp), %bp /* restore the original BP */+ addw $20, %sp+ iret++restricted_map:+ movw 2(%bp), %ax /* lower word of the saved EAX */++ /* CHS read functions */+ cmpb $0x02, %ah /* read sectors */+ je 2f+ cmpb $0x04, %ah /* verify sectors, also a read operation */+ je 2f+ cmpb $0x0a, %ah /* read long sectors */+ je 2f+ cmpb $0x0c, %ah /* seek to cylinder */+ je 2f+ cmpb $0x21, %ah /* PS/1 and newer PS/2 - read multiple disk sectors */+ jne 1f+2:+ movb -3(%bp), %ah /* AH=Smax */+ testb $63, %ah /* check if Sectors=0, i.e., disable CHS */+ jz error_01_disable+ ret+1:+ /* CHS write functions */+ cmpb $0x03, %ah /* CHS write sectors */+ je 2f+ cmpb $0x05, %ah /* PC/XT/AT/EISA format tracks */+ je 2f+ cmpb $0x06, %ah /* PC/XT format tracks with bad sectors */+ je 2f+ cmpb $0x07, %ah /* PC/XT format multiple cylinders */+ je 2f+ cmpb $0x0b, %ah /* PC/XT/AT/EISA write sectors with ECC */+ je 2f+ cmpb $0x0f, %ah /* PC/XT/PS/1 write sector buffer */+ je 2f+ cmpb $0x22, %ah /* PS/1 and newer PS/2 - write multiple disk sectors */+ jne 1f+2:+ movb -3(%bp), %ah /* AH=Smax */+ testb $63, %ah /* check if Sectors=0, i.e., disable CHS */+ jz error_01_disable+ testb $0x80, %ah /* readonly access? */+ jnz readonly_fakewrite+ ret+1:+ /* LBA read functions */+ cmpb $0x41, %ah /* Extensions - INSTALLATION CHECK */+ je 2f+ cmpb $0x42, %ah /* Extensions - EXTENDED READ */+ je 2f+ cmpb $0x44, %ah /* Extensions - verify sectors */+ je 2f+ cmpb $0x45, %ah /* Extensions - LOCK/UNLOCK DRIVE */+ je 2f+ cmpb $0x46, %ah /* Extensions - EJECT MEDIA */+ je 2f+ cmpb $0x47, %ah /* Extensions - EXTENDED SEEK */+ je 2f+ cmpb $0x48, %ah /* Extensions - GET DRIVE PARAMETERS */+ je 2f+ cmpb $0x49, %ah /* Extensions - detect media change */+ je 2f+ cmpb $0x4a, %ah /* Bootable CDROM - INITIATE DISK EMULATION */+ je 2f+ cmpb $0x4b, %ah /* Bootable CDROM - TERMINATE DISK EMULATION */+ je 2f+ cmpb $0x4c, %ah /* Bootable CDROM - INITIATE DISK EMULATION AND BOOT */+ je 2f+ cmpb $0x4d, %ah /* Bootable CDROM - RETURN BOOT CATALOG */+ je 2f+ cmpb $0x4e, %ah /* Extensions v2.1 - SET HARDWARE CONFIGURATION */+ jne 1f+2:+ movb -3(%bp), %ah /* AH=Smax */+ testb $64, %ah /* disable LBA? */+ jnz error_01_disable+ ret+1:+ /* LBA write functions */+ cmpb $0x43, %ah /* Extensions - EXTENDED WRITE */+ jne 1f+2:+ movb -3(%bp), %ah /* AH=Smax */+ testb $64, %ah /* disable LBA? */+ jnz error_01_disable+ testb $0x80, %ah /* readonly access? */+ jnz readonly_fakewrite+1:+ /* no restrictions, return and continue */+ ret++error_01_disable:+ /* function not supported, or the input CHS is invalid */+ addw $14, %sp /* adjust SP */+ popw %si+ popw %bp+ popl %eax+error_01_disable2:+ movb $0x01, %ah /* signal invalid function call */+ stc /* signal error */+ lret $2 /* far return discard the original flags */++readonly_fakewrite:+ addw $14, %sp /* adjust SP */+ popw %si+ testb $1, -14(%bp) /* lowest bit of S_count */+ popw %bp+ popl %eax+ jnz 1f+ /* read only */+ movb $0x03, %ah /* signal write protection */+ stc /* signal error */+ lret $2 /* far return discard the original flags */+1:+ /* fake write */+ xorb %ah, %ah /* signal write succeeded */+ /*clc*/ /* signal success, CF already cleared by XOR */+ lret $2 /* far return discard the original flags */+++drive_emulation:+ movw -4(%bp), %ax /* AL=Hmax, AH=Smax */+ testb $63, %ah /* disable CHS? */+ jz 2f /* yes, call restricted map */+ testb $0xc0, %ah /* readonly or disable LBA? */+ jz 1f+2:+ call restricted_map+1:+ movw 2(%bp), %ax /* get original AX */++ testb %ah, %ah /* reset disk system, always succeed */+ jnz 1f+ clc+ jmp int13_return+1:+ cmpb $0x01, %ah /* get status of last operation, always succeed */+ jnz 1f+ xorb %ah, %ah+ clc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -