title: Disk Read Error while loading sectors into memory
body: <p>I tried to develop a bootloader using <a href="https://www.cs.bham.ac.uk/~exr/lectures/opsys/10_11/lectures/os-dev.pdf">this</a>, but when it is run it shows:</p>
  
  <pre><code>disk read error!
  </code></pre>
  
  <p>If I ignore it, in a later part, it shows me wrong memory mapping. I also followed some other sources too but in vain. It feels like I'm just copying what they are doing. If I do even a little different a new kind of error generates every time.</p>
  
  <p>Should I use an already built bootloader or what to do?</p>
  
  <p>The code of disk load error is as follow:</p>
  
  <pre><code>[org 0x7c00]
  
      KERNEL_OFFSET equ 0x1000    
      mov [BOOT_DRIVE], dl        
      mov bp, 0x9000          
      mov sp, bp  
      mov bx, MSG_REAL_MODE       
      call print_string           
      call load_kernel            
      jmp $
  
  print_string:
      pusha
      mov ah, 0x0e
  
  loop:
      mov al,[bx]
      cmp al, 0
      je return
      int 0x10
      inc bx
      jmp loop
  
  return:
      popa
      ret
  
  disk_load: 
      push dx                                              
      mov ah, 0x02                                   
      mov al, dh                                          
      mov ch, 0x00                                    
      mov dh, 0x00                                     
      mov cl, 0x02                                    
      int 0x13                                           
      jc disk_error                                  
      pop dx                                               
      cmp dh, al                                         
      jne disk_error                                 
      ret
  
   disk_error :
     mov bx, DISK_ERROR_MSG 
     call print_string 
     jmp $
  
  DISK_ERROR_MSG db "Disk read error!", 0
  
  [bits 16]
  
  load_kernel: 
      mov bx, KERNEL_OFFSET       
      mov dh, 15           
      mov dl, [BOOT_DRIVE]                      
      call disk_load                                                  
      ret
  
  ; Global variables
  BOOT_DRIVE     db 0 
  MSG_REAL_MODE db "Started in 16-bit Real Mode", 0 
  
  ; Bootsector padding 
  times 510-($-$$) db 0 
  dw 0xaa55
  </code></pre>
  
  <p>I use this command to assemble and run my bootloader:</p>
  
  <pre><code>nasm boot.asm -f bin -o boot.bin &amp;&amp; qemu-system-i386 boot.bin
  </code></pre>
  
  <p>I get stuck at this point. My bootloader display <code>disk read error</code>. If I ignore it at this point in time, then it creates problems while executing my kernel.c It seems to use wrong memory mapping.</p>