如何将控件从我的引导加载程序传输到位于硬盘驱动器中的应用程序

问题描述 投票:1回答:1

我在Windows上使用NASM并在vmware上测试它,并成功制作了我的启动加载器,但现在我希望我的启动加载器将控件转移到某个应用程序(比如说我想模拟内核的工作)但是我想要的不是内核加载一些应用?你能不能给我一些提示如何在扇区,磁头等方面找到HDD中的文件,然后加载到ram中。

我知道内核位于地址2000h也是一个中断13h,它将硬盘信息加载到ram但是如何找到确切的扇区,前往该文件?

先感谢您

assembly x86 hard-drive bootloader bios
1个回答
0
投票

如果您可以访问Logical Block Addressing扩展,那么将扇区加载到内存中要容易得多。您仍然使用INT 0x13中断,但AH设置为0x42。您只需指定起始扇区索引和要加载的连续扇区数以及位置。

如果不实现文件系统,则必须将应用程序放在磁盘映像开头的某个已知偏移处。加载后,您只需跳转到加载扇区的地址即可。

获得单个细节错误会使模拟CPU出现三重故障,因此请确保手头有print string function工作。


BIOS将从0区加载到0x7c00。您可以简单地将应用程序放在扇区大小的某个倍数上。假设扇区大小为512字节,那么它看起来应该是这样的:

  • 扇区0(偏移0):引导装载程序 - > 0x7c00
  • 扇区1(偏移512):应用程序 - > 0x7e00或您选择的任何地址

如果您将应用程序加载到0x7e00,那么您只需执行jmp 0x0:0x7e00即可运行它。

我不知道用于Windows创建磁盘映像的任何工具,但如果您希望所有内容都在同一个文件中,则可以始终使用汇编程序正确填充偏移量。


因为我有一段时间前我写过的启动加载器的代码,所以我不妨分享一些例子(NASM语法):

BITS 16

ORG 0x7c00

entry:
    xor ax, ax      ; Explicitly set DS=0 
    mov ds, ax
    mov ss, ax      ; Set SS:SP out the way (below the bootloader) at 0x0000:0x7c00
    mov sp, 0x7c00

    mov ah, 0x42 ; set to lba extended read
    mov dl, 0x80 ; first hard drive
    mov si, dap  ; address of disk address package

    int 0x13     ; execute

    jc .load_failed ; do something on failure

    jmp 0x0:0x7e00 ; jump to the destination address


ALIGN 16

; this is the disk address package used by the lba extensions
dap:
db 0x10   ; size of this package
db 0x0    ; reserved
dw 0x1    ; number of sectors to load
dd 0x7e00 ; destination address
dq 0x1    ; sector index to load

; pad to assumed sector size. this will overwrite the partition table
TIMES 510 - ($ - $$) db 0

; boot signature
dw 0xaa55

; either write your app here or concatenate a separate .bin file
© www.soinside.com 2019 - 2024. All rights reserved.