NASM:磁盘读取超时

2024-01-14

尝试从磁盘(从同一文件)读取数据,将另外 2 个 512 字节扇区加载到内存中。磁盘读取功能如下:

; read DH sectors to ES:BX from drive DL
disk_read:
    push dx 

    push bx  ; Tried to check if disk is ready first, this code runs without errors
    mov ah, 0x10
    int 0x13
    jc disk_not_ready
    mov bx , DISK_CURRENT_STATUS_MSG
    call print_string
    mov bx, 0
    mov bl , ah
    call print_hex
    pop bx

    mov ah , 0x42   ; BIOS read sector function
    mov al , dh     ; Read DH sectors
    mov ch , 0x00   ; Select cylinder 0
    mov dh , 0x00   ; Select head 0
    mov cl , 0x02   ; Start reading from second sector (i.e.
                    ; after the boot sector)

    int 0x13        ; BIOS interrupt to read from disk
    jc disk_read_error_general  ; Jump if error (i.e. carry flag set)
    pop dx                      ; Restore DX from the stack
    cmp dh , al                 ; if AL (sectors read) != DH (sectors expected)
    jne disk_read_error_number_of_sectors_read_differs  ; display error message
    cmp dh , al                 ; if AL (sectors read) != DH (sectors expected)
    je disk_read_success        ; display success message

    disk_read_exit:
        ret

disk_read_success:
    mov bx , DISK_READ_SUCCESS_MSG
    call print_string
    jmp disk_read_exit

disk_read_error_general:
    mov bx , DISK_READ_ERROR_GENERAL_FAIL_MSG
    call print_string
    mov bx , DISK_CURRENT_STATUS_MSG
    call print_string
    mov bx, 0
    mov bl , ah
    call print_hex
    jmp $

disk_not_ready:
    mov bx , DISK_NOT_READY_ERROR_MSG
    call print_string
    jmp $

disk_read_error_number_of_sectors_read_differs:
    mov bx , DISK_READ_ERROR_NUMBER_OF_SECTORS_DIFFERS_MSG
    call print_string
    jmp $

; Variables
DISK_READ_SUCCESS_MSG:
    db "Disk read were successful!" , 0

DISK_NOT_READY_ERROR_MSG:
    db "Disk is not ready for reading!" , 0

DISK_READ_ERROR_GENERAL_FAIL_MSG:
    db "Disk read error, carry in CF were not set!" , 0

DISK_READ_ERROR_NUMBER_OF_SECTORS_DIFFERS_MSG:
    db "Disk read error, number of sectors read differs from requested!" , 0

DISK_CURRENT_STATUS_MSG:
    db "Disk status:" , 0

调用代码:

; Read some sectors from the boot disk using our disk_read function
[org 0x7c00]


mov [BOOT_DRIVE] , dl

mov bp , 0x8000
mov sp , bp 
mov bx , 0x9000

mov dh , 3  ; Load 3 sectors to 0x0000 (ES):0x9000 (BX)
            ; from the boot disk.

mov dl , [BOOT_DRIVE]
call disk_read

mov dx , [0x9000]
call print_hex  ; Print out the first loaded word , which
                ; we expect to be 0xdada , stored
                ; at address 0x9000

mov dx , [0x9000+512]   ; Also , print the first word from the
call print_hex          ; 2 nd loaded sector : should be 0xface
jmp $

%include "print_string.asm" 
%include "print_hex.asm"    
%include "disk_read.asm"

; Global variables
BOOT_DRIVE: db 0

; Bootsector padding
times 510-($-$$) db 0
dw 0xaa55

times 256 dw 0xdada
times 256 dw 0xface

为什么第一个磁盘状态为 0x0380 以及如何修复此超时错误(从此处检查错误代码:http://www.ctyme.com/intr/rb-0606.htm http://www.ctyme.com/intr/rb-0606.htm)? 硬盘驱动器是 SSD 类型,但可能与此无关,因为可向后移植到常规驱动器(NASM:如何正确访问SSD驱动器? https://stackoverflow.com/questions/59336069/nasm-how-to-access-ssd-drive-correctly). Update打印字符串:

; Print string function, note that this code written after jmp $ instruction,
; otherwise the string were printed twice
print_string:
    push ax     ; pushing two registers that used onto a stack
    push bx

    mov ah , 0x0e       ; int 10/ ah = 0 eh -> scrolling teletype BIOS routine

    loop:
        mov al, [bx]    ; put ascii value in bx (lower bits) into al
        int 0x10        ; print what in al
        inc bx          ; increment bx through the string
        cmp al, 0       ; check if passed null-terminator
        jnz loop        ; loop until null terminator met

    mov al, 0x0a    ; line feed and carriage return added after line
    int 0x10
    mov al, 0x0d
    int 0x10

    pop bx ; popping two registers that used from stack
    pop ax
    ret

打印十六进制:

; Print hex function, note that this code written after jmp $ instruction,
; otherwise the string were printed twice
print_hex:
    push ax     ; pushing registers that used onto a stack
    push dx
    push bx
    push cx
    push si

    mov si, 4
    mov bx, dx

    print_hex_loop:
        dec si
        cmp si, -1
        je print_hex_loop_exit
        mov dx, 0
        mov ax, bx
        mov cx, 16
        div cx
        mov bx, ax
        mov ah, 0x0e    ; int 10/ ah = 0 eh -> scrolling teletype BIOS routine
        add dx, 0x0030
        cmp dx, 0x0039
        jg add_0x27_to_letter

    print_hex_loop_continue:
        mov al, dl
        ;int 0x10       ; print what in al
        mov [HEX_OUTPUT_STR+si+2], al
        jmp print_hex_loop

    add_0x27_to_letter:
        add dx, 0x0027
        jmp print_hex_loop_continue

    print_hex_loop_exit:
        mov bx, HEX_OUTPUT_STR
        call print_string

    pop si ; popping registers that used from stack
    pop cx  ; popping registers that used from stack
    pop bx
    pop dx
    pop ax
    ret

HEX_OUTPUT_STR:
    db "0x0000", 0

更新2:修复 print_hex 函数以使用 dx 而不是 bx 打印后(在 disk_read.asm 中)(在使用时小心地从堆栈中推送和弹出),并从整数 13/ah=0x42 to 整数 13/ah=0x02(否则我会得到状态01h="AH 中的函数无效或参数无效"),我有磁盘状态0Ch这是“不支持的轨道或无效媒体”。有什么想法为什么会这样吗?


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

NASM:磁盘读取超时 的相关文章

随机推荐

  • RestAdapter(改造)在android中无法解析

    所以我尝试在我的项目中使用 Retrofit 正如该网站所说 我已经包括了compile com squareup retrofit retrofit 2 0 0 beta1 in build gradle 我正在阅读此教程link htt
  • Windows - 无法强制关闭网络文件句柄 - 无法关闭系统(Pid 4)文件句柄

    首先 很抱歉问了这么长的问题 但我想提供足够的细节 概要 在 Windows 中 似乎无法强制关闭通过网络共享打开的文件句柄 因此 通过网络共享打开的文件无法移动 重命名 删除 我用的是Win 7 问题 任何人都可以看到我做错了什么 或者有
  • 以角度动态更改 css 变量

    在我的角度项目中 我在顶层定义了一些 css 变量样式 scss像这样的文件 我在很多地方使用这些变量来保持整个主题的一致性 root theme color 1 f7f7f7 theme color 2 ec4d3b theme colo
  • Android启动意图查看apk

    在我的应用程序中 我下载一个 apk 并将其保存到 SD 卡 然后我想开始安装该 apk 我正在使用以下代码来尝试此操作 Intent intent new Intent intent setAction Intent ACTION VIE
  • Mathematica 中的变换分布

    我开发了一些代码来从 LogNormalDistribution 和 StableDistribution 的乘积生成随机变量 LNStableRV Alpha Beta Gamma Sigma Delta n Module LNRV SD
  • 如何找到相交矩形的交点矩形(点)

    如果我有两个相交的矩形 x1 y1 x2 y2 x3 y3 x4 y4 由两个顶点描述 如何找到一个由它们的交集产生的矩形 得到这些矩形相交的 2 个点 编程语言并不重要 可能是伪代码 PS 矩形与 OXY 平行 你可以使用矩形 交集 ht
  • 让 VertexRenderingFunction 缩放(不缩放)

    我在自定义 VertexRenderingFunction 以不同尺寸显示不同图形时遇到问题 下面是一个示例 默认的顶点渲染函数具有所需的行为 因为顶点在所有图中看起来都相同 有什么建议如何使用自定义顶点来实现这一点吗 source yar
  • 软件生成的中断和软件生成的异常有什么区别?

    我正在阅读英特尔手册 3A 第 6 章中断和异常处理 中断和异常分别有3个来源 对于软件生成的中断 它说 INT n 指令允许从内部产生中断 软件通过提供中断向量号作为操作数 为了 例如 INT 35 指令强制隐式调用 中断 35 的中断处
  • urllib2 中重复主机查找失败

    我的代码使用 Python 的 urllib2 在多个线程中发出许多 HTTP GET 请求 将响应写入文件 每个线程一个 在执行过程中 看起来许多主机查找失败 导致名称或服务未知错误 请参阅附加的错误日志以获取示例 这是由于 DNS 服务
  • Google Analytics API 在示例代码中返回 401

    我正在尝试从谷歌分析的内容实验中检索数据 我正在使用以下代码 我的信用良好 并且已针对这篇文章进行了审查
  • 查找 exe 是否动态链接(Windows)

    windows下如何判断一个exe是动态链接还是静态链接 所有 Windows 应用程序都动态链接到 Windows API 如果您需要确定特定的非 Windows 库 如 libxml 或类似库 的链接方式 Visual Studio 包
  • 使用 YouTube API v3 检查视频是否有年龄限制

    有没有办法使用 YouTube API v3 来检查视频是否有年龄限制 查看文档我无法确认这一点 我发现了一些与此相关的内容 请检查 https www googleapis com youtube v3 videos part conte
  • 错误 [ERR_REQUIRE_ESM]:如何在节点 12 中使用 es6 模块?

    From https 2ality com 2019 04 nodejs esm impl html https 2ality com 2019 04 nodejs esm impl htmlNode 12应该支持es6模块 但是 我不断收
  • python-tz 是我错了还是它是一个错误

    这似乎有点奇怪 当我想用 pytz 获取欧洲 巴黎时区时 它让我进入 PMT 时区 而不是 GMT 1 当它似乎适用于欧洲 柏林时 不清楚 看看这个片段 usr bin python import os import datetime fr
  • `numpy.argmax()` 的理论平均情况运行时复杂度

    我正在看代码numpy argmax功能 我很困惑哪种数据结构numpy维持为argmax功能 https numpy org doc stable reference generated numpy argmax html https n
  • 使用 VS 项目检查代码的 xslt 将 Xml 转换为 html

    我有一个InspectionResults xml当我运行时生成的inspectcode exe from JetbrainsCommandLine Tool Analysis 有没有xslt提供的文件Jetbrains将此 xml 转换为
  • 使用 setuptools 创建 python 可执行文件

    我有一个小的 python 应用程序 我想将其制作为类 UNIX 系统的可下载 可安装的可执行文件 我的印象是安装工具将是实现这一目标的最佳方法 但不知何故 这似乎不是一项常见任务 我的目录结构如下所示 myappname setup py
  • Kafka 连接到节点 ubuntukafka 时出错:9092(id:0 机架:null)(org.apache.kafka.clients.NetworkClient)java.net.UnknownHostException:

    我在 VirtualBox 来宾上有两台服务器 每个服务器都是 ubuntu 我可以从我的主机通过 SSH 连接到两台机器 以及两台机器之间的 SSH 这样它们都具有 natnetwork 我在一台服务器 kafka 上运行 如下所述 ht
  • Python 格式最佳实践

    我刚刚熟悉 Python 并且有一个关于在字符串上使用 format 的最佳实践 或至少是常见实践 的问题 我的问题主要是关于何时使用空白大括号 索引号和名称 例如 如果您想将一个变量包含在字符串中 您会选择哪一个 print I Stac
  • NASM:磁盘读取超时

    尝试从磁盘 从同一文件 读取数据 将另外 2 个 512 字节扇区加载到内存中 磁盘读取功能如下 read DH sectors to ES BX from drive DL disk read push dx push bx Tried