Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # bootblock.s
  2.  
  3. # .equ symbol, expression.
  4. # This directive sets the value of symbol to expression
  5. .equ    BOOT_SEGMENT,       0x7c00
  6. .equ    DISPLAY_SEGMENT,    0xb800
  7.  
  8. .text                  # Code segment
  9. .globl  _start         # The entry point must be global
  10. .code16                # Real mode
  11. #
  12. # The first instruction to execute in a program is called the entry
  13. # point. The linker expects to find the entry point in the "symbol" _start
  14. # (with underscore).
  15. #
  16. _start:
  17.     jmp over
  18. #
  19. # Do not add any instructions before or in os_size.
  20. #
  21.  
  22. os_size:
  23.     # area reserved for createimage to write the OS size
  24.     .word   0
  25.     .word   0
  26. over:
  27.     #xchg   %bx, %bx
  28.     #print_string is now working, kernel isn't
  29.  
  30.     # set up segments
  31.     mov  $0x0, %ax
  32.     mov %ax, %ds
  33.     mov %ax, %es
  34.     mov %ax, %ss     # setup stack
  35.     mov $BOOT_SEGMENT, %sp # stack grows downwards from 0x7C00
  36.  
  37.     #xchg   %bx, %bx
  38.     mov $hellostring, %si
  39.     add $BOOT_SEGMENT, %si
  40.     call print_string
  41.  
  42. #INT 13h AH=00h: Reset Disk Drive
  43.     #xchg   %bx, %bx
  44.     movb    $0x00, %ah
  45.     int     $0x13
  46.  
  47.  
  48. #INT 13h AH=08h: Read Drive Parameters
  49.     #xchg   %bx, %bx
  50.     xor %ax, %ax
  51.     mov %ax, %es
  52.     mov %ax, %di
  53.  
  54.     mov $0x08, %ah
  55.     mov $0x80, %dl
  56.  
  57.     int $0x13
  58.  
  59. #INT 13h AH=02h: Read Sectors From Drive
  60.     #xchg   %bx, %bx
  61.  
  62.     xor %ax, %ax
  63.     mov %ax, %es
  64.     mov $0x0550, %bx
  65.  
  66.     movb    $0x02, %ah
  67.     movb    $0x01, %al
  68.     movb    $0x00, %ch
  69.     movb    $0x01, %cl
  70.     movb    $0x00, %dh
  71.     movb    $0x80, %dl
  72.  
  73.     #xchg   %bx, %bx
  74.     int $0x13
  75.  
  76. #INT 13h AH=02h: Read Sectors From Drive
  77.     #xchg   %bx, %bx
  78.  
  79.     xor %ax, %ax
  80.     mov %ax, %es
  81.     mov $0x8000, %bx
  82.  
  83.     movb    $0x02, %ah
  84.     movb    $0x01, %al
  85.     movb    $0x00, %ch
  86.     movb    $0x02, %cl
  87.     movb    $0x00, %dh
  88.     movb    $0x80, %dl
  89.  
  90.     int $0x13
  91.  
  92.     #xchg   %bx, %bx
  93.     mov $0x00, %ax
  94.     mov %ax, %ds
  95.     #invoke kernel at 0x00008000
  96.     ljmp $0x0, $0x8000
  97.  
  98. print_string:
  99.     mov $0x0e, %ah
  100. .repeat:
  101.     lodsb
  102.  
  103.     cmp $0x00, %al
  104.     je .done
  105.     int $0x10
  106.     jmp .repeat
  107. .done:
  108.     ret
  109.  
  110. forever:
  111.     jmp     forever                 # Loop forever
  112.  
  113.  
  114. hellostring:
  115.     .asciz  "Hello\r\n"
  116.  
  117. . = _start + 510 #mov to 510th byte from 0 pos
  118. .byte 0x55 #append boot signature
  119. .byte 0xaa #append boot signature
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement