Bootloader - LBA28 in Long Mode not working

Viewed 80

After entering long mode from bootloader, copying the second sector in memory using LBA28 crashes the PC. The second sector was copied successfully in memory in 32 bit mode. The crash happens when executing the instruction

 rep insw

Is there a separate instruction for 64 bit mode?

I'm using Bochs as emualtor

Code:

; ---------------------------------- Load Data From Disk --------------------------------------

mov     dx,0x1F1
mov     al,0h
out     dx,al

mov     dx,1f2h
mov     al,2          ; number of sectors to read
out     dx,al


mov     dx,1f3h
mov     al,1        
out     dx,al

mov     dx,1f4h
mov     al,0       
out     dx,al

mov     dx,1f5h      
mov     al,0
out     dx,al

mov     dx,0x1F6
mov     al,0xE0
out     dx,al


mov     dx,1f7h
mov     al,20h   ; 20h read   30h write
out     dx,al

mov ecx, 4

loop1:
        mov dx, 1F7h
        in al, dx

        test al, 10000000b
        jnz short retry
        test al, 00001000b
        jnz short data_ready
retry:
        dec ecx
        jg short loop1
loop2:
        mov dx, 1F7h
        in al, dx

        test al, 10000000b   ; Check BSY
        jnz short loop2
        test al, 00100001b   ; Check ERR and DF
        jnz short fail
data_ready:

        mov dx, 0x1F0
        mov cx, 256*2
        mov edi, 2000000

        rep insw

        mov     rax,'L O N G '
        mov     [0B8000h],rax

      hlt

fail:
        mov     rax,'F A I L '
        mov     [0B8000h],rax
hlt
0 Answers
Related