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

145 views Asked by At

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

There are 1 answers

2
Sep Roland On BEST ANSWER

From your last comment I can't make up which mov bx, 0x0000 you replaced to fix the problem. Here's the solution:

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

In stead of risking endless retries you should abort when BIOS reports an error! Preferably with a message.

Luckily you are doing all of this in an simulated environment because otherwise toying with the first harddisk (mov dl, 0x80) is never a good idea.