assembly Int 13 H AH= 00 h的具体和有用示例

ncgqoxb0  于 11个月前  发布在  其他
关注(0)|答案(2)|浏览(103)

我可以有一个具体的和有用的例子Int 13H AH=00h .一个例子在nasm编码的处理器上运行在16位模式,使我可以理解在实践中,Int 13H AH=00h必须有一个影响的代码,如果我删除它会导致错误或更改.
我在virtualbox上使用img软盘,我在 Boot 扇区上。
我理解了这个理论:Int 13H AH=00h磁盘系统迫使控制器重新校准驱动器磁头(寻找磁道0)。
我想走得比理论更远,用真实的使用Int 13H AH=00h的示例代码来理解。
我下面的tutorial使用了Int 13H AH=00h,但它对代码没有影响,没有用,相反,我需要一个对Int 13H AH=00h有真实的用处和影响的实际示例

46scxncf

46scxncf1#

例如,这是qemu mbr代码。检查******之间的部分。
di = 5是从磁盘读取的尝试次数。因此,如果错误发生CF = 1,代码递减di,并在5次尝试后,我们有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

字符串

kr98yfug

kr98yfug2#

Int 13H AH=00h在像VirtualBox这样的虚拟机上是无用的,就像这个文档说的那样。
如果Int 13H AH=00h稍后在VM之外使用,则需要保留它。
不可能有一个具体的和有用的例子对虚拟机上的Int 13 H AH= 00 h的代码有真实的影响。在google,stackoverflow,chatgpt上没有工作的例子
随着SSD驱动器的出现,该功能不再真正有任何用途,特别是因为int 0x13不再用于使用UEFI的现代操作系统,其中实模式BIOS功能仍然存在以实现向后兼容性。

相关问题