Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
BITS 16
start:
mov ax, 07C0h ; Set data segment to where we're loaded
mov ds, ax ;
mov ax,9000h ;initlise the stack
mov ss,ax ;
mov sp,100h ;
call read_sector;
read_sector:
.Reset:
mov ah, 0 ; reset floppy disk function
mov dl, 0 ; drive 0 is floppy drive
int 0x13 ; call BIOS
jc .Reset ; If Carry Flag (CF) is set, there was an error. Try resetting again
mov ax, 0x1000 ; we are going to read sector to into address 0x1000:0
mov es, ax
xor bx, bx
.Read:
mov ah, 0x02 ; function 2
mov al, 1 ; read 1 sector
mov ch, 1 ; we are reading the second sector past us, so its still on track 1
mov cl, 2 ; sector to read (The second sector)
mov dh, 0 ; head number
mov dl, 0 ; drive number. Remember Drive 0 is floppy drive.
int 0x13 ; call BIOS - Read the sector
jc .Read ; Error, so try again
jmp 0x1000:0x0 ; jump to execute the sector!
;---------------------------------------------------------------------------------------
times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
dw 0xAA55 ; The standard PC boot signature
mov al,41h;
mov ah,0eh;
int 10h;
Also note that it's possible that your emu crashes because you IMG is less than 2 sectors... If you load a sector that is incomplete QEmu will crash! Also some other emu doesn't like images less than 360kb...
QEmu will load this successfully if I pad out the second sector, and adjust the track number (first track isn't 1).
If your floppy image is not the full 1.44MB, emu's will indeed blow up in various degrees of nastiness.
Try bochs as your emulator, it will complain whenever you screw up your write commands instead of silently doing something unexpected - in this case it would probably have saved you from asking the question altogether.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
At any case, the 'read sector' function shouldn't have failed at all(unless you are reading from a defective media). So I'm assuming the original issue is with loading the kernel/2nd stage loader(and not loading the sector) which shall be worked out by correcting the cylinder no.
Cheers.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !