assembly - BIOS int 13h/AH=42 未读取磁盘或未读取到内存中的正确位置
问题描述
编辑:请。为了上帝的爱。[BITS 16]
如果您在真实模式下执行,请记住添加。它会拯救你。
我试图让 BIOS 从磁盘中读取一小部分并执行它。到目前为止我有
; Boot sector if you didn't know. The entire purpose of this is to jump to protected mode setup (PMS)
%define BIOS_ERROR_FREQUENCY 440
%define ERR_LBA_NOT_FOUND 1
%define ERR_BIOS_WRITE 2
extern BIOS_BLOCK_SIZE
extern boot_sector_e
extern pms_s
extern pms_e
extern pms_number_of_blocks
section .boot
; Check if the BIOS supports LBA
mov ah, 0x41
mov bx, 0x55AA
; dl has already been set to the boot drive
int 0x13
; Error handle
mov al, ERR_LBA_NOT_FOUND
jc boot_error
; If it does support LBA, we read in PMS to memory and start executing it
mov ah, 0x42
; dl already set
mov si, bios_lba_packet_s
int 0x13
mov al, ERR_BIOS_WRITE
jc boot_error
jmp pms_s
; Please note that this will overwrite and read extra from the disk. We don't know what this is however, we can just ignore it :)
; Misc
bios_lba_packet_s:
db bios_lba_packet_e - bios_lba_packet_s ; Size
db 0 ; Reserved
dw pms_number_of_blocks
dw boot_sector_e ; Offset of transfer buffer location
dw 0x0 ; Section
dq 0 ; Starting block. We have the ability to hardcode this because it's at the set position of one sector off (boot sector is 0)
bios_lba_packet_e:
boot_error: ; Will just print out a upon error
mov ah, 0x0E
mov al, "a"
int 0x10
jmp $
section .boot-header
dw 0xAA55 ; 55AA tells the BIOS that this is bootable (reversed because of endians)
和
section .pms
mov ah, 0x0E
mov al, "w"
int 0x10
这是我要加载的内容,并且在工作时只需打印出“w”
我把它和
SECTIONS {
.boot ORG : {
boot_sector_s = .;
*( .boot );
}
. += BIOS_BLOCK_SIZE - boot_header_size - boot_size;
.boot-header : {
*( .boot-header );
boot_sector_e = .;
}
.pms : {
pms_s = .;
*( .pms );
pms_e = .;
}
}
/* Constants */
BIOS_BLOCK_SIZE = 512;
ORG = 0x7C00;
boot_size = SIZEOF( .boot );
boot_header_size = SIZEOF( .boot-header ); /* This has be defined after the .boot-header section has been defined (it's weird, I know) */
pms_number_of_blocks = ((pms_e - pms_s) + BIOS_BLOCK_SIZE) / BIOS_BLOCK_SIZE;
我已经倾倒了内存,并且没有找到加载的部分。我还检查了进位标志,它们没有设置。它是否与我的最终二进制文件没有填充有关,以便使我要加载的部分成为完整的 512 字节?
解决方案
InstallationCheck 功能 41h 报告的CF=0
事实并不意味着一切。
您仍然需要验证是否确实安装BX=AA55h
了 IBM/MS INT 13 Extensions 。并
检查. _ 如果设置了位 0,则支持ExtendedRead 功能 42h 。CX
CX
pms_number_of_blocks = ((pms_e - pms_s) + BIOS_BLOCK_SIZE) / BIOS_BLOCK_SIZE;
这会将您的pms_number_of_blocks设置为 1。您需要将StartingAbsoluteBlockNumber设置为 1 而不是 0。(0 将重新读取引导扇区。)
bios_lba_packet_s:
db 16
db 0
dw pms_number_of_blocks
dd 0:pms_s
dq 1
它是否与我的最终二进制文件没有填充有关,以便使我要加载的部分成为完整的 512 字节?
来吧,垫它!无论如何,您应该始终这样做。
奇怪的是,在读取的函数上报告了“ERR_BIOS_WRITE”。
BIOS.Teletype 函数 0Eh 使用
BH
DisplayPage 参数。将其设置为 0。section .pms mov bh, 0 mov ax, 0x0E * 256 + "w" int 0x10 times (512 - 7) db 0
BIOS 仅将
DL
寄存器中的引导驱动器传递给您。没有其他的!不要相信段寄存器的任何特定设置。DS=0
明确设置。始终在安全的地方设置堆栈。在这里将其设置在引导扇区下方:
xor ax, ax mov ds, ax mov ss, ax mov sp, 0x7C00
推荐阅读
- google-apps-script - 根据输入生成多行并将 SUM 公式添加到最后一行
- javascript - 将行另存为文本文件,从单元格中获取文件名
- javascript - 有没有办法过滤另一个数组中的数组中的项目
- c++ - 将返回类型的函数参数的常量与概念匹配
- firebase-cloud-messaging - 触发 click_action 后在服务人员中捕获 FCM 通知消息
- reactjs - 无法在 react-native 中设置 BottomTabNavigator 颜色
- python - 从内部重新启动 python 脚本时,我收到导入错误。“ImportError:没有名为 cv2 的模块”
- python - geopy.exc.GeocoderServiceError:[SSL:CERTIFICATE_VERIFY_FAILED]
- qt - 在 qt 小部件中绘制半圆
- cluster-analysis - RDKit:从 ZINC 数据库生成指纹用于聚类分析