Advertisement
Guest User

Untitled

a guest
Apr 14th, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. BITS 16
  2.  
  3. header:
  4.     jmp boot
  5.     nop
  6.  
  7. OEMLabel                db "LABEL   "       ; Disk label
  8. BytesPerSector          dw 512              ; Bytes per sector
  9. SectorsPerCluster       db 1                ; Sectors per cluster
  10. ReservedForBoot         dw 1                ; Reserved sectors for boot record
  11. NumberOfFats            db 2                ; Number of copies of the FAT
  12. RootDirEntries          dw 0                ; Number of entries in root dir
  13.                                             ; (224 * 32 = 7168 = 14 sectors to read)
  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 "OS         "    ; Volume Label: any 11 chars
  25. FileSystem              db "FAT12   "       ; File system type: don't change!
  26.  
  27. boot:
  28.     mov ax, 07C0h     ; Set up 4K stack space after this bootloader
  29.     add ax, 288       ; (4096 + 512) / 16 bytes per paragraph
  30.     mov ss, ax
  31.     mov sp, 4096
  32.  
  33.     mov ax, 07C0h     ; Set data segment to where we're loaded
  34.     mov ds, ax
  35.     ; xor ax, ax        ; not sure if setting DS=0 is better than above
  36.     ; mov ds, ax
  37.  
  38.     mov ah, 02h
  39.     mov al, 2         ; Num sectors to read
  40.     mov ch, 0         ; Cylinder
  41.     mov cl, 2         ; Sector
  42.     mov dh, 0         ; Head
  43.     mov dl, 0         ; Drive (0 is floppy)
  44.  
  45.     ; mov ax, 80h     ; alternate way to specify 0x800?
  46.     ; mov es, ax
  47.     ; xor bx, bx
  48.     xor ax, ax
  49.     mov es, ax
  50.     mov bx, 800h
  51.     int 13h
  52.  
  53.     ; mov bx, 800h  ; alternate way to inspect memory, using
  54.     ; mov dx, [bx]  ; info registers
  55.     ; jmp $
  56.  
  57.     jnc goto_kernel
  58.     mov si, err_msg
  59.     call print_string
  60.  
  61. goto_kernel:
  62.     jmp 800h
  63.  
  64. err_msg db 'An error occurred reading from disk (int 13h)', 0
  65.  
  66. print_string:         ; Routine: output string in SI to screen
  67.     mov ah, 0Eh       ; int 10h 'print char' function
  68.  
  69. .repeat:
  70.     lodsb         ; Get character from string
  71.     cmp al, 0
  72.     je .done      ; If char is zero, end of string
  73.     int 10h           ; Otherwise, print it
  74.     jmp .repeat
  75. .done:
  76.     ret
  77.  
  78.     times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
  79.     dw 0xAA55     ; The standard PC boot signature
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement