2017-05-17 3 views
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: 
+0

포럼 규칙에 따라, 여기에 코드를 제공해야합니다. –

+1

'REP MOVSB'를 사용하여 전체 LODSB/STOSB를 단순화 할 수있었습니다. 그러나이 협약은 STOSB가 _ES_ 설정에 의존한다고 말했다. 당신은'mov ds, ax'와 함께'mov es, ax'를 보여줍니다. 그게 문제가되지 않을 수도 있지만 그 첫 번째로 고정해야합니다 (그것은 모든 하드웨어에서 작동하지 않을 수 있습니다)하지만 많은 가상 환경에서 아마 이미 0입니다. –

+0

나는 당신이 파티션 테이블을 부트 로더로 복사한다고 가정합니다. 이 코드에서 MBR을 만든 후 다른 곳에서? –

답변

0

내 코드는 괜찮 밝혀 : 사람이 내가 잘못하고있는 중이 야 무엇을 알 수 있습니까, 13 실패 인터럽트, 지금

내 부트 로더 코드는 그 어떤 바보 같은 시간 동안 그것을 해결하기 위해 노력하고 확신 마이클 페치 (Michael Petch)가 제안한 몇 가지 사항을 변경했지만 실제 로딩은 좋았습니다. 문제는 linux의 "dd"프로그램을 사용하여 부트 섹터를 복사 할 때 전체 파일을 잘라 버리는 것이 었습니다. 나는자를 방지하기위한 플래그를 활성화하여이를 해결했습니다.

관련 문제