INT 13h - 扩展读取 - DAPS故障

时间:2013-02-13 16:19:48

标签: assembly bootloader

亲爱的Stackoverflowers,

我写了一些汇编代码,最终应该读取根目录。但问题是扩展读取功能不会将readed数据放在正确的位置。或者我的细分和偏移有问题。

我从这段代码中得到的结果是:A | |,这意味着Print Function找到了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

1 个答案:

答案 0 :(得分:1)

最终我发现我必须在读取功能之前放入“mov dl,0x80”。 我仍然不知道为什么因为在启动过程开始时DL应该根据大多数规格具有正确的驱动器号。

相关问题