【发布时间】:2021-12-20 11:03:51
【问题描述】:
编辑:
请。为了上帝的爱。如果您在真实模式下执行,请记得添加[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 字节?
【问题讨论】:
-
您确定 DS 就是您认为的那样吗? Rumor has it 你不应该假设引导加载程序时寄存器中的内容(DL 除外)。
-
dl 是 0x80,这是默认的 HDA & ds 是 0x0。
-
dq 0表示您将加载第一个扇区。 -
是的,我用
dq 0和dq 1尝试过,但无济于事
标签: assembly x86 operating-system nasm bios