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

问题描述 投票:0回答:1

我可以提供一个具体且有用的例子吗

Int 13H AH=00h
。一个在 16 位模式下运行的处理器上用 nasm 编写的示例,以便我在实践中能够理解,
Int 13H AH=00h
一定会对代码产生影响,如果我删除它,则会导致错误或更改

我在 virtualbox 上使用 img 软盘,并且位于引导扇区

我理解了这个理论:

Int 13H AH=00h
重置磁盘系统 强制控制器重新校准驱动头(寻求跟踪 0)

我想比理论更进一步,并通过实际使用的示例代码来理解

Int 13H AH=00h

下面的教程使用

Int 13H AH=00h
,但它对代码没有影响,没有用,相反我需要一个真正有用和影响的实际例子
Int 13H AH=00h

assembly virtualbox interrupt x86-16 bios
1个回答
0
投票

例如,这是 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
© www.soinside.com 2019 - 2024. All rights reserved.