如何使用 assembly(8086) 将 USB 驱动器的扇区加载到内存中?

How can I load the sectors of a usb drive into memory using assembly(8086)?

我正在研究多阶段引导加载程序,其中使用 INT 13h 从软盘加载扇区。现在我正在尝试使用相同的 INT 13h 将 usb 的扇区加载到内存中。

我假设我的代码如下....

mov ah,02h ;sub function 2 to read sectors to memory
mov al,2 ;to read two sectors
mov cl,01h
mov dl,81h ;the second fixed disk
int 13h

我猜上面的代码并不完全正确,但是,这是加载usb扇区的方法吗?我的意思是我可以使用相同的 13h 中断吗? 一种 任何源代码都可以欣赏..

我试着弄清楚你想做什么:

  • 学习多阶段引导程序
  • 编写 MBR 代码并将其加载到 USB 的第一个扇区
  • 能够使用此类程序启动 PC(在 BIOS 中启用传统选项)
  • 正在编写要存储在以下磁盘扇区中的第二阶段代码,您希望从 USB 读取这些代码并将其放入内存中,以便 运行 通过跳转到第一条指令[=23] =]

对吧? 如果您的 PC 可以从 USB 启动,那么以下 MBR 代码应该从同一设备读取一些扇区,将它们存储在内存中并跳转到第一个内存位置,它应该是第二阶段代码的第一条指令。这段代码要用nasm

组装

nasm -f bin filename

[bits 16]
[org 0x7c00]    ; this MBR code resides here (512 bytes)

boot:
mov ax,0x0100   ; stack lower bound
mov ss,ax       ; set stack at address 0x1000
mov sp,0x2000   ; 8KB stack

;load second stage code from disk to address 0x07e00 (just above)
read:
xor ax,ax       ; Floppy Reset BIOS Function
                ; DL -> device (BIOS left 0x0:floppy or 0x80:HDD)
int 0x13        ; unnecesary to set DL because BIOS did the work
jc read

mov ax,0x07e0
mov es,ax   ; SEGMENT
xor bx,bx   ; OFFSET
xor dh,dh   ; dh=0 (head); dl = device
mov cx,2    ; ch=0 (cilinder) ; cl = 2 (1st sector, number 2)
mov ax,2*256+17 ; ah=2 (read); al=17 (sectors)
int 0x13
jc read     ;retry jump in case of read error

stop:
mov dx,0x3F2 ; stop the motor from spinning
mov al,0x0C  ; unnecesary in case of USB, only for floppy
out dx,al 

;jump to second stage code (first intruction at very beggining)
mov ax,0x07e0
mov ds,ax
jmp 0x07e0:0x0


TIMES 510-($-$$) DB 0

SIGNATURE DW 0xAA55

希望对您有所帮助!