Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2023
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. bits 16
  2. org 0x7C00
  3.  
  4. ; Set up the stack
  5. mov ax, 0x9000
  6. mov ss, ax
  7. mov sp, 0xFFFF
  8.  
  9. ; Load kernel from first sector of drive
  10. mov bx, 0x1000 ; Destination address for kernel
  11. mov dh, 2 ; Number of sectors to read
  12. mov dl, 0 ; Drive number (0 = first drive)
  13. call diskLoad
  14.  
  15. ; Jump to the kernel
  16. jmp 0x1000
  17.  
  18. diskLoad:
  19. pusha
  20. push dx
  21. mov ah, 0x02 ; BIOS read function
  22. mov al, dh ; Number of sectors to read
  23. mov cl, 0x02 ; Starting sector (2 since sector 1 is boot sector)
  24. mov ch, 0x00 ; Starting cylinder (0)
  25. mov dh, 0x00 ; Starting head (0)
  26. int 0x13 ; BIOS interrupt to read from disk
  27.  
  28. jc diskError ; Check carry flag for error
  29. pop dx ; Restore original number of sectors to read
  30. cmp al, dh ; Compare number of sectors read to original value
  31. jne sectorsError
  32. popa
  33. ret
  34.  
  35. diskError:
  36. mov si, diskErrorMsg
  37. call printString
  38. jmp $
  39.  
  40. sectorsError:
  41. mov si, sectorsErrorMsg
  42. call printString
  43. jmp $
  44.  
  45. printString:
  46. mov ah, 0x0E
  47. .loop:
  48. lodsb
  49. cmp al, 0
  50. je .done
  51. int 0x10
  52. jmp .loop
  53. .done:
  54. ret
  55.  
  56. diskErrorMsg: db "Disk error", 0
  57. sectorsErrorMsg: db "Sectors read error", 0
  58.  
  59. times 510-($-$$) db 0
  60. dw 0xAA55
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement