提问人:Bastien Portigo 提问时间:11/13/2023 最后编辑:Michael PetchBastien Portigo 更新时间:11/16/2023 访问量:174
Int 13H AH=00h 的具体和有用的例子
Concrete and useful example of Int 13H AH=00h
问:
我能举一个具体而有用的例子吗?在以 16 位模式运行的处理器上用 nasm 编码的示例,以便我在实践中能够理解,必须对代码产生影响,如果我删除它会导致错误或更改。Int 13H AH=00h
Int 13H AH=00h
我在 virtualbox 上使用 img 软盘,我在引导扇区。
我明白了这个理论:RESET DISK SYSTEM
强制控制器重新校准驱动器磁头(寻求跟踪 0)。Int 13H AH=00h
我想比理论走得更远,并通过实际使用的示例代码来理解。Int 13H AH=00h
我正在遵循的教程使用,但它对代码没有影响,它没有用,相反,我需要一个真正有用和影响的实际示例Int 13H AH=00h
Int 13H AH=00h
答:
好吧,例如,这是 qemu mbr 代码。检查之间的部分。******
di = 5
是尝试从磁盘读取的次数。因此,如果发生错误,代码会递减,经过 5 次尝试,我们会在下一步代码中生成消息。CF = 1
di
di = 0
"Error loading operating system"
+ fa cli ; clear IF
+ 33 c0 xor ax,ax ; ax = 0000
+ 8e d0 mov ss,ax ; ss = 0000
+ bc 00 7c mov sp,7c00 ; sp = 7c00
+ 8b f4 mov si,sp ; si = 7c00
+ 50 push ax ; ↑ ax = 0000
+ 07 pop es ; ↓ es = 0000
+ 50 push ax ; ↑ ax = 0000
+ 1f pop ds ; ↓ ds = 0000
+ fb sti ; set IF
+ fc cld ; clear DF
// copy 512 bytes (2 * 256), ds:si [0000:7c00] -> es:di [0000:0600]
+ bf 00 06 mov di,0600 ; di = 0600
+ b9 00 01 mov cx,0100 ; cx = 0100(256)
+ f2 repnz ; if != 0
+ a5 movsw ; copy 256 words
+ ea 1d 06 00 00 jmp 0000:061d
+ be be 07 mov si,07be ; partition table offset
+ b3 04 mov bl,04 ; 4 entries
+3 80 3c 80 cmp byte ptr [si],80 ; 80 = active partiton
+1> 74 0e jz +14 ; 80 found
+ 80 3c 00 cmp byte ptr [si],00 ; no entry
+2> 75 1c jnz +28 ; other system
+ 83 c6 10 add si,+10 ; check next entry
+ fe cb dec bl ; dec number of records
+3> 75 ef jnz -17 ; if nothing found, check again, next record
+ cd 18 int 18 ; rom bios
// read from partition table record
+1 8b 14 mov dx,[si] ; [07be] = dh(head) = 01 dl(drive number) = 80
+ 8b 4c 02 mov cx,[si + 02] ; [07c0] = ch(cylinder) = 00 cl(sector number ) = 01
+ 8b ee mov bp,si ; bp = 07be, first partition table entry
+5 83 c6 10 add si,+10 ; move to next record
+ fe cb dec bl ; dec number of records
+4> 74 1a jz +26 ; no more records, read sector
+ 80 3c 00 cmp byte ptr [si],00 ; no entry? check next or show "invalid partition table"
+5> 74 f4 jz -12 ; 1111 0100 , 0000 1011, 0000 1100, -0c
+2 be 8b 06 mov si,068b ; "invalid partition table"
+7,9,11 ac lodsb ; al = ds:si
+ 3c 00 cmp al,00 ; end of string?
+6> 74 0b jz +11 ; go infinity loop
+ 56 push si ; ↑ si = 07fe, offset 55 AA
+ bb 07 00 mov bx,0007 ;
+ b4 0e mov ah,0e ; tty show char
+ cd 10 int 10 ; graphics int
+ 5e pop si ; ↓ si = 07fe, 55 aa
+7> eb f0 jmp -16 ; load next char, 1111 0000, 0000 1111, 0001 0000, -16
+6> eb fe jmp -2 ; infinity loop, stop working
*********************************************************
+4 bf 05 00 mov di,0005 ; di = 0005, if disk error, we have 5 tries
+10 bb 00 7c mov bx,7c00 ; buffer, es:bx = 0000:7c00
+ b8 01 02 mov ax,0201 ; ah = 02 read, al = 01 1 sector
+ 57 push di ; ↑ di = 0005
+ cd 13 int 13h ; disk int
+ 5f pop di ; ↓ di = 0005
+8> 73 0c jnb +12 ; no errors?
+ 33 c0 xor ax,ax ; error, ax = 0000, reset disk system
+ cd 13 int 13h ; disk int
+ 4f dec di ; decrement number of tries
+10> 75 ed jnz -19 ; if not 0, try again, 1110 1101, 0001 0011, -19
+ be a3 06 mov si,06a3 ; si = offset "Error loading operating system"
+11> eb d3 jmp -45 ; go lodsb, 1101 0011, 0010 1101, -45
*********************************************************
+8 be c2 06 mov si, 06c2 ; si = offset "Missing operating system"
+ bf fe 7d mov di,7dfe ; di = offset 55 AA
+ 81 3d 55 aa cmp word ptr [di],aa55 ; [di] == 55 aa?
+9> 75 c7 jnz -57 ; go lodsb, 1100 0111, 0011 1001, -57
+ 8b f5 mov si,bp ; si = 07be, first partition table entry
+ ea 00 7c 00 00 jmp 0000:7c00 ; jmp to new loaded data
评论
正如本文档所述,Int 13H AH=00h 在像 VirtualBox 这样的虚拟机上是无用的
如果稍后在 VM 外部使用 Int 13H AH=00h,则保留它是相关的。
不可能有一个具体且有用的示例对虚拟机上的 Int 13H AH=00h 代码产生实际影响。谷歌、stackoverflow、chatgpt 上没有工作示例
随着 SSD 驱动器的出现,该功能不再真正有任何用途,尤其是因为 int 0x13 不再用于使用 UEFI 的现代操作系统,其中真实模式 BIOS 功能仍然存在以实现向后兼容性。
评论
065E BF0500
评论