Guest User

LBA

a guest
Feb 27th, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Use LBA.
  2. use_lba:
  3.     ; Get the drive parameters.
  4.     mov ah, 0x48
  5.     mov si, 0x1000      ; This is where stage2 will be parse,
  6.                     ; but we won't need this data by then.
  7.     mov dl, [device]    ; Use the BIOS device.
  8.     int 0x13
  9.     cmp ah, 0
  10.     je  lba_ctd         ; Success.
  11.     ; Error... Print the error bytes and hang the machine.
  12.     mov al, ah
  13.     call    puterr
  14.     jmp hang
  15. lba_ctd:
  16.     ; Find the LBA of the active partition
  17.     mov bx, 0x7dbe      ; Address of partition table in memory
  18.                     ; (0x7c00 + 446).
  19.     .ptable_loop:
  20.         mov ah, [bx]    ; Partition status byte.
  21.         cmp ah, 0x80
  22.         je  .bootable_found ; Found bootable partition.
  23.         add bx, 16  ; Next entry.
  24.         jmp .ptable_loop
  25.     .bootable_found:
  26.         mov ax,     [bx + 0x0c]
  27.         mov [dap.offset],   ax
  28.     ; Get the number of bytes per block
  29.     mov ax, [si + 0x18]
  30.     ; Calculate the number of blocks to read (STAGE2_BYTES / block size).
  31.     push    ax
  32.     mov ax, STAGE2_BYTES
  33.     pop bx
  34.     div bx
  35.     mov [dap.block_count],  ax
  36.     ; Now we can actually perform the read.
  37.     mov ah, 0x42        ; Extended read.
  38.     mov dl, [device]    ; Use the BIOS device.
  39.     mov si, dap     ; DS:SI = Disk Address Packet (DAP)
  40.     int 0x13
  41.     cmp ah, 0
  42.     je  parse           ; Success.
  43.     ; Error... Print the error bytes and hang the machine.
  44.     mov al, ah
  45.     call    puterr
  46.     jmp hang
Advertisement
Add Comment
Please, Sign In to add comment