assembly - How to boot kernel that is appended end of kernel?

时间:2015-06-15 14:46:28

标签: assembly kernel nasm 16-bit mbr

I am trying to boot my assembly kernel on assembly bootloader/MBR. I am reading kernel from offset 0x7e00 to offset 0x8000 (sector 1) into memory; and jumping offset 0x7e00. Why it is not jumps into my kernel?

; Boot.asm
[org 0x7c00]
[bits 16]

ReadDisk:
    push ax
    push bx
    push cx
    push dx

    mov bx, 0x0000
    mov es, bx
    mov bx, 0x0000

    mov ah, 0x02
    mov al, 0x01
    mov ch, 0x00
    mov cl, 0x02
    mov dh, 0x00
    mov dl, 0x80
    int 0x13
    jc ReadDisk
    jmp 0x7e00


times 510 - ($ - $$) db 0
dw 0xaa55

~~~~

; Kernel.asm
; Print dot on screen and hang
[org 0x7e00]
[bits 16]

mov ah, 0x0e ; BIOS teletype subfunction
mov al, '.'
int 10h
jmp $ ; hang

times 512 - ($ - $$) db 0 ; Fill sector.

Environment : NASM, QEMU, Windows 7 64 bit.

1 个答案:

答案 0 :(得分:2)

根据您的上一条评论,我无法弥补您更换的mov bx, 0x0000以解决问题。这是解决方案:

mov bx, 0x0000
mov es, bx
mov bx, 0x7E00

当BIOS报告错误时,您应该中止,而不是冒无休止的重试风险! 最好带一条消息。

幸运的是,你正在模拟环境中完成所有这些工作,因为否则玩第一个硬盘(mov dl, 0x80)从来都不是一个好主意。