boot_sect_disk.asm 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ; load 'dh' sectors from drive 'dl' into ES:BX
  2. disk_load:
  3. pusha
  4. ; reading from disk requires setting specific values in all registers
  5. ; so we will overwrite our input parameters from 'dx'. Let's save it
  6. ; to the stack for later use.
  7. push dx
  8. mov ah, 0x02 ; ah <- int 0x13 function. 0x02 = 'read'
  9. mov al, dh ; al <- number of sectors to read (0x01 .. 0x80)
  10. mov cl, 0x02 ; cl <- sector (0x01 .. 0x11)
  11. ; 0x01 is our boot sector, 0x02 is the first 'available' sector
  12. mov ch, 0x00 ; ch <- cylinder (0x0 .. 0x3FF, upper 2 bits in 'cl')
  13. ; dl <- drive number. Our caller sets it as a parameter and gets it from BIOS
  14. ; (0 = floppy, 1 = floppy2, 0x80 = hdd, 0x81 = hdd2)
  15. mov dh, 0x00 ; dh <- head number (0x0 .. 0xF)
  16. ; [es:bx] <- pointer to buffer where the data will be stored
  17. ; caller sets it up for us, and it is actually the standard location for int 13h
  18. int 0x13 ; BIOS interrupt
  19. jc disk_error ; if error (stored in the carry bit)
  20. pop dx
  21. cmp al, dh ; BIOS also sets 'al' to the # of sectors read. Compare it.
  22. jne sectors_error
  23. popa
  24. ret
  25. disk_error:
  26. mov bx, DISK_ERROR
  27. call print
  28. call print_nl
  29. mov dh, ah ; ah = error code, dl = disk drive that dropped the error
  30. call print_hex ; check out the code at http://stanislavs.org/helppc/int_13-1.html
  31. jmp disk_loop
  32. sectors_error:
  33. mov bx, SECTORS_ERROR
  34. call print
  35. disk_loop:
  36. jmp $
  37. DISK_ERROR: db "Disk read error", 0
  38. SECTORS_ERROR: db "Incorrect number of sectors read", 0