0
MBRブートローダを書きましたが、パーティションを検出してもロードできません。ハードディスクからセクタをロードする際の問題
[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:
フォーラムのルールにしたがって、ここでコードを提供してください。 –
'REP MOVSB'を使ってLODSB/STOSB全体を単純化できました。しかし、その看板では、「STOSB」は、設定されている_ES_に依存していると言いました。あなたは 'mov ds、ax'と一緒に' mov es、ax'を表示します。これは問題ではないかもしれませんが、まず目立つのは修正する必要があります(すべてのハードウェアで動作しない可能性があります)が、多くの仮想環境ではすでに0になっている可能性があります。 –
パーティションテーブルをブートローダにこのコードからMBRを作成した後のどこかで? –