【问题标题】:INT 13h - Extended Read - DAPS faultINT 13h - 扩展读取 - DAPS 故障
【发布时间】:2013-01-29 06:17:34
【问题描述】:

亲爱的 Stackoverflowers,

我写了一些汇编代码,最终应该读取根目录。然而问题是扩展读取功能没有将读取的数据放在正确的位置。或者我的段和偏移量有问题。

我从这段代码中得到的结果是:A| |,这意味着打印函数找到了一个 0,同时期望第一个扇区的一些随机值。

我真的不知道自己做错了什么

BIOS_ReadFile.inc

;*************************************************
;   Name: BIOS_ReadFile.inc
;   Description: Reads File from the FAT32 System
;*************************************************
[bits 16]

%ifndef BIOS_READFILE.INC
%define BIOS_READFILE.INC

%include "Constants.inc"

;-----------------------------------------------------------------  
; BIOS_ReadSectors function
;-----------------------------------------------------------------
ReadStatus: db UNKNOWN              ; 0 - Not Supported, 1 - Supported,     255 - Not known at given time

BIOS_ReadSectors:
mov si, DAPS                    ; Load DAPS Struct to DS:SI
mov ah, 0x42                    ; Read Functions
int 0x13                        ; Call the interrupt
jc .Failure                     ; If the read fails.
mov byte [ReadStatus], TRUE     ; Set the ReadStatus to True
ret                             ; Return

.Failure:
mov byte [ReadStatus], FALSE    ; Set the ReadStatus to False

mov ah, 0x0E                ; Print Letter B, Gives Indication of Failure
mov bh, 0x00
mov bl, 0x07
mov al, 'B'
int 0x10

ret 
; Return

;-----------------------------------------------------------------  
; BIOS_ReadFile function
;-----------------------------------------------------------------
FirstDataSector:     dw 0x0
RootDirectorySector: dw 0x0

BIOS_ReadFile:
; Calculating the First Data Sector
xor ax, ax
mov byte al, [Bios_Parameter_Block.FATS]
mul word [Extended_Bios_Parameter_Block.LargeSectorsPerFAT]
add word ax, [Bios_Parameter_Block.ReservedSectors]
mov word [FirstDataSector], ax

; Calculating the Root Directory Sector
mov word ax, [Extended_Bios_Parameter_Block.RootDirectory]
sub word ax, 2
mul byte [Bios_Parameter_Block.SectorsPerCluster]
add word ax, [FirstDataSector]
mov word [RootDirectorySector], ax

; Load Directory
;mov word [DAPS.SectorsToRead], 1

;mov word ax, [RootDirectorySector]
;mov word [DAPS.SectorStart], ax

call BIOS_ReadSectors

mov ah, 0x0E                ; Print Letter A, Gives Indication of Failure
mov bh, 0x00
mov bl, 0x07
mov al, 'A'
int 0x10

ret

;-----------------------------------------------------------------  
; Memory Data Structures and Other Variables
;-----------------------------------------------------------------
; Disk Address Packet Structure (Used For Loading Rest of OS)
DAPS:            db 0x10               ; Size of Structure (16 bytes)
                 db 0                  ; Always 0
.SectorsToRead   dw 1                  ; Number of Sectors to Read (1x512)
.Offset          dw 0x7E00             ; Offset to load to.
.Segment         dw 0x0000             ; Segment to load to.
.SectorStart     dq 0                  ; Read from Second Block


;----------------------------------------------------------------------------------------------------

%endif

Bootloader.asm

[bits 16]
[org 0x0]

jmp Start

%include "BIOS_Parameter_Block.inc"
%include "BIOS_Extensions.inc"
%include "BIOS_ReadFile.inc"
%include "Print.inc"

; Prepare stack segment
;-----------------------------------------------------------------
Start:
cli
mov ax, 0x07C0
mov ds, ax                  ; Load segments with 0
mov fs, ax
mov es, ax
mov gs, ax

mov     ax, 0x0000              ; set the stack
mov     ss, ax
mov     sp, 0xFFFF
mov     bp, 0xFFFF
sti

; Check support for extensions
;-----------------------------------------------------------------
call CheckExtensions
cmp byte [ExtensionsSupported], FALSE
jz short unsupported

; Read from the device.
;-----------------------------------------------------------------
call BIOS_ReadFile

mov ah, 0x0E                ; Print Letter B, Gives Indication of Failure
mov bh, 0x00
mov bl, 0x07
mov al, '|'
int 0x10

mov si, 0x200
call PrintString

mov ah, 0x0E                ; Print Letter B, Gives Indication of Failure
mov bh, 0x00
mov bl, 0x07
mov al, '|'
int 0x10

cli
hlt

jmp 0x0:0x7E00                  ; Jump to main

; Errors 
;-----------------------------------------------------------------
unsupported:
mov ah, 0x0E                ; Print Letter F, Gives Indication of Failure
mov bh, 0x00
mov bl, 0x07
mov al, 'F'
int 0x10

clc
hlt 

; Fill Out Rest of Bootloader
;-----------------------------------------------------------------
times 510-($-$$) db 0

db 0x55, 0xAA               ; Add Boot Record Signature

Print.inc

;*************************************************
;   Name: Print.inc
;   Description: Printing on console using INT 10h
;   Function: PrintString(DS::SI nullTerminatedString)
;*************************************************
[bits 16]

%ifndef PRINT.INC
%define PRINT.INC

;---------------------------------------------------------------------------------
PrintString: 
lodsb               ; Load next byte from DI::SI to AL and increment SI by one
or  al, al          ; Null-Terminator check
jz  .Done           ; If found jump to end
mov ah, 0Eh         ; Move Function number in AH
int 10h             ; Else print character
jmp PrintString     ; Repeat until null terminator found

.Done:
mov ah, 0x0E                ; Print Letter B, Gives Indication of Failure
mov bh, 0x00
mov bl, 0x07
int 0x10

ret                 ; Return
;--------------------------------------------------------------------------------- 

%endif

【问题讨论】:

  • DAPS 中的段和偏移量与引导扇区其余部分中的段和偏移量不匹配。参考相同的记忆,所以我认为这不是你的问题(无论如何,你会在最后一次跳转时回到第 0 段) - 但这就是我跳出来的全部......
  • 最终我不得不在读取函数之前放置“mov dl, 0x80”

标签: assembly bootloader


【解决方案1】:

最终我不得不在读取函数之前放置“mov dl, 0x80”。 我仍然不知道为什么在启动过程开始时,根据大多数规范,DL 应该具有正确的驱动器号。

【讨论】:

  • dl 在引导加载程序启动时确实设置为正确的值。但是,在 int 0x13 之前,您使用的是 mul 指令,该指令存储结果 dx:ax 覆盖 BIOS 放在那里的值。
猜你喜欢
  • 2021-03-23
  • 2020-01-04
  • 2013-02-01
  • 2010-12-31
  • 2014-09-16
  • 2012-02-20
  • 2016-03-04
  • 2013-11-20
  • 2012-04-01
相关资源
最近更新 更多