Advertisement
Guest User

Untitled

a guest
Aug 10th, 2024
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | Source Code | 0 0
  1. ; first_stage.asm
  2. [org 0x7C00]
  3. SECOND_STAGE_ADDRESS equ 0x7E00 ; Just after the first stage
  4.  
  5. ; Basic setup
  6. cli
  7. xor ax, ax
  8. mov ds, ax
  9. mov es, ax
  10. mov ss, ax
  11. mov sp, 0x7C00
  12.  
  13. ; Print debug message: "F" for First stage
  14. mov ah, 0x0E
  15. mov al, 'F'
  16. int 0x10
  17.  
  18. ; Print newline
  19. mov al, 0x0D
  20. int 0x10
  21. mov al, 0x0A
  22. int 0x10
  23.  
  24. ; Save boot drive number
  25. mov [0x7C1E], dl
  26.  
  27. ; Print debug message: "L" for Loading second stage
  28. mov ah, 0x0E
  29. mov al, 'L'
  30. int 0x10
  31.  
  32. ; Load the second stage
  33. mov ah, 0x02 ; BIOS read function
  34. mov al, 2 ; Number of sectors to read
  35. mov ch, 0 ; Cylinder 0
  36. mov cl, 2 ; Sector 2 (1-indexed)
  37. mov dh, 0 ; Head 0
  38. mov dl, [0x7C1E] ; Drive number
  39. mov bx, SECOND_STAGE_ADDRESS ; Where to load the second stage
  40.  
  41. int 0x13 ; BIOS interrupt to read sectors
  42. jc error ; If carry flag was set, there was an error
  43.  
  44. ; Print debug message: "S" for Switching to second stage
  45. mov ah, 0x0E
  46. mov al, 'S'
  47. int 0x10
  48.  
  49. ; Jump to second stage
  50. jmp SECOND_STAGE_ADDRESS
  51.  
  52. error:
  53. ; Print E for error
  54. mov ah, 0x0E
  55. mov al, 'E'
  56. int 0x10
  57. jmp $
  58.  
  59. BOOT_DRIVE db 0
  60.  
  61. times 510-($-$$) db 0
  62. dw 0xAA55
Tags: assembly
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement