SHARE
TWEET

A

a guest Aug 8th, 2019 154 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. org 0x7C00
  3. %define SECTOR_AMOUNT 0x10  ;Precompiler defined value for easy changing
  4. jmp short start
  5. nop
  6.  
  7. ; BPB
  8. OEMLabel        db "Example "    ; Disk label
  9. BytesPerSector        dw 512        ; Bytes per sector
  10. SectorsPerCluster    db 1        ; Sectors per cluster
  11. ReservedForBoot        dw 1        ; Reserved sectors for boot record
  12. NumberOfFats        db 2        ; Number of copies of the FAT
  13. RootDirEntries        dw 224        ; Number of entries in root dir
  14. LogicalSectors        dw 2880        ; Number of logical sectors
  15. MediumByte        db 0F0h            ; Medium descriptor byte
  16. SectorsPerFat        dw 9        ; Sectors per FAT
  17. SectorsPerTrack        dw 18        ; Sectors per track (36/cylinder)
  18. Sides            dw 2            ; Number of sides/heads
  19. HiddenSectors        dd 0        ; Number of hidden sectors
  20. LargeSectors        dd 0        ; Number of LBA sectors
  21. DriveNo            dw 0            ; Drive No: 0
  22. Signature        db 41            ; Drive signature: 41 for floppy
  23. VolumeID        dd 00000000h    ; Volume ID: any number
  24. VolumeLabel        db "Example    "; Volume Label: any 11 chars
  25. FileSystem        db "FAT12   "    ; File system type: don't change!
  26. start:
  27. ; ------------------------------------------------------------------
  28.  
  29. ;Initialize Registers
  30. cli
  31. xor ax, ax
  32. mov ds, ax
  33. mov ss, ax
  34. mov es, ax
  35. mov fs, ax
  36. mov gs, ax
  37. mov sp, 0x6ef0 ; setup the stack like qemu does
  38. sti
  39.  
  40. ;Reset disk system
  41. mov ah, 0
  42. int 0x13              ; 0x13 ah=0 dl = drive number
  43. jc errorpart
  44. ;Read from harddrive and write to RAM
  45. mov bx, 0x8000        ; bx = address to write the kernel to
  46. mov al, SECTOR_AMOUNT ; al = amount of sectors to read
  47. mov ch, 0             ; cylinder/track = 0
  48. mov dh, 0             ; head           = 0
  49. mov cl, 2             ; sector         = 2
  50. mov ah, 2             ; ah = 2: read from drive
  51. int 0x13                 ; => ah = status, al = amount read
  52. jc errorpart
  53. jmp 0x8000
  54.  
  55.  
  56. errorpart:            ;if stuff went wrong you end here so let's display a message
  57. mov si, errormsg
  58. mov bh, 0x00          ;page 0
  59. mov bl, 0x07          ;text attribute
  60. mov ah, 0x0E          ;tells BIOS to print char
  61. .part:
  62. lodsb
  63. sub al, 0
  64. jz end
  65. int 0x10              ;interrupt
  66. jmp .part
  67. end:
  68. jmp $
  69.  
  70. errormsg db "Failed to load...",0
  71. times 510-($-$$) db 0    ; Pad remainder of boot sector with 0s
  72. dw 0xAA55        ; The standard PC boot signature
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top