簡體   English   中英

從硬盤發出加載扇區

[英]Issue loading sector from hard disk

我已經編寫了MBR引導加載程序,它可以檢測分區,但無法加載它們。 中斷13失敗了,有人知道我在做什么錯嗎,我確信它已經愚蠢地嘗試修復了好幾個小時

我的引導程序代碼是:

[BITS 16]   ;tell the assembler that its a 16 bit code
[ORG 0]
%define PARTITION_TABLE_START 0x1be
%define PARTITION_TABLE_END 0x1ee
%define PARTITION_ENTRY_SIZE 16
%define COPY_DEST 0x7e00
_begin:
; We must copy the bootloader into a different area of memory
mov ax, 0
mov ds, ax
_copy:
mov si, 0x7c00+_begin
mov di, COPY_DEST
mov cx, 0
._continue:
lodsb
stosb
cmp cx, 0x200
je ._finish
inc cx  
jmp ._continue
._finish:
jmp 0x7e0:_start
_start:
; We are running at 0x7e00 now
mov ax, 0x7e0
mov ds, ax
mov es, ax
mov ss, ax

; Save drive number
mov byte[_drive_no], dl

mov si, _welcome_message
call _print


mov si, _find_message
call _print

mov bx, PARTITION_TABLE_START
_csearch:
cmp byte [bx], 0x80
je _bootable_found
cmp bx, PARTITION_TABLE_END
jae _no_bootable_found
add bx, PARTITION_ENTRY_SIZE
jmp _csearch


_bootable_found:
mov si, _found_message
call _print
; BX Contains current entry position
mov ah, 0x02
mov al, 1
mov dh, [bx+1], ; Head
mov cl, [bx+2] ; Sector
shr cl, 2 ; Ignore bit 6-7 they are not for us
mov ch, [bx+3] ; Cylinder (warning only 8 bits supported)
mov byte dl, [_drive_no] ; Drive number
; Destination: 0x7c00
push ax
mov ax, 0x7c0
mov es, ax
mov bx, 0
pop ax
int 0x13
jc _read_error
mov si, _press_any_key_to_load
call _print
mov ah, 0
int 0x16
; Read success lets jump to the new bootloader
jmp 0x7c0:0

_read_error:
mov si, _read_error_msg
call _print
jmp $

_no_bootable_found:
mov si, _no_partition
call _print
jmp $


_print:
    mov ah, 0x0e
._loop: 
    lodsb
    cmp al, 0
    je ._done
    int 0x10
    jmp ._loop
._done:
    ret
_welcome_message: db 'Welcome to NibbleBits bootloader', 10, 13, 0
_find_message: db 'Will find first active partition', 10, 13, 0
_found_message: db 'Active partition found', 10, 13, 0
_no_partition: db 'No active partition could be found', 10, 13, 0
_read_error_msg: db 'Failed to load partition', 10, 13, 0
_press_any_key_to_load: db 'Press any key to load the partition', 10, 13, 0
_drive_no: db 0

TIMES 510 - ($ - $$) db 0   ;fill the rest of sector with 0
DW 0xAA55           ; add boot signature at the end of bootloader
_end:

原來我的代碼很好,確實更改了Michael Petch提出的一些內容,但實際加載情況很好。 問題是,當我使用linux的“ dd”程序復制啟動扇區時,它會截斷整個文件。 我通過啟用一個標志來防止截斷來解決這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM