ajtgarber

bootload(simple sector) asm

Aug 24th, 2011
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [BITS 16]
  2. [ORG 0x7C00]
  3.  
  4. bootload_main:
  5.     mov si, HelloWorld
  6.     call printk
  7.  
  8.     call loadSector
  9.  
  10.     cli
  11.     hlt
  12.  
  13. printk:
  14.     lodsb
  15.     or al, al
  16.     jz .done
  17.     mov ah, 0x0E
  18.     int 0x10
  19.     jmp printk
  20. .done
  21.     ret
  22.  
  23. loadSector:
  24.     mov ah, 0x01
  25.     int 0x13
  26.     jnz loadSector ; loop if an error occured (or not ready, shouldn't happen under qemu)
  27.     ; for the values below I've played around with 1's and 0's trying to
  28.     ; guess to see if I can get it to work without some conversion function
  29.     mov ah, 0x02 ; read sector
  30.     mov al, 1
  31.     mov ch, 1 ; track
  32.     mov cl, 1 ; sector
  33.     mov dh, 1 ; head
  34.     mov dl, 0x80 ; read from first hd
  35.     mov bx, 0x7E00
  36.     cmp al, 0x00
  37.     je .successful
  38.     mov si, LoadSectorUnsuccessful
  39.     call printk
  40.     ret
  41. .successful
  42.     mov si, LoadSectorSuccessful
  43.     call printk
  44.     ret
  45.  
  46.  
  47. HelloWorld db 'Hello, World!', 13, 10, 0
  48. LoadSectorSuccessful db 'Loaded Sector Successfully!', 13, 10, 0
  49. LoadSectorUnsuccessful db 'Unsuccessful Sector load :(', 13, 10, 0
  50.  
  51. times 510-($-$$) db 0
  52. dw 0xAA55
  53.  
  54. times 512 db 0
Advertisement
Add Comment
Please, Sign In to add comment