Advertisement
Guest User

bryoboot1.asm

a guest
Jan 22nd, 2025
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ---------------------------[bryoboot1.asm]--------------------
  2. ; 1. constants
  3. ; 2. directives
  4. ;       + fat12 header
  5. ; 3. main
  6. ; 4. functions
  7. ; 5. messages
  8. ; 6. footer
  9.  
  10.  
  11. ; ---------------------------[CONSTANTS]------------------------
  12. BL1_ADDR equ 0x7c00         ; origin address of loader1
  13.  
  14. BL2_ADDR equ 0x7fee         ; origin address of loader2
  15. BL2_c equ 0                 ; cylinder for bl2
  16. BL2_h equ 0                 ; head for bl2
  17. BL2_s equ 2                 ; sector for bl2
  18. BL2_sec_count equ 1         ; Number of sectors to read
  19. ;   Drive number is autoset by BIOS
  20.  
  21. CR equ 0x0d                 ; Carriage Return
  22. LF equ 0x0a                 ; Line feed/ Newline
  23.  
  24. ;----------------------------[DIRECTIVES]------------------------
  25. org BL1_ADDR                ; origin
  26. bits 16                     ; real mode 16 bit
  27.  
  28. ;----------------------------[FAT12 HEADER]----------------------
  29.  
  30. jmp main                    ; First two bytes - jump to main
  31. nop                         ; Null byte making the begining 3 bytes
  32.  
  33. bpb_oem: db 'bryoboot'       ; oem header 8 bytes
  34. bpb_bps: dw 512              ; bytes per sector
  35. bpb_sps: db 1                ; sectors per cluster
  36. bpb_rs:  dw 1                ; reserved sector - 1 for bryoboot1
  37. bpb_fc:  db 2                ; number of file allocation tables
  38. bpb_dir_ent: dw 0xe0         ; number of dir entries
  39. bpd_ts: dw 2880              ; Total sectors
  40. bpb_md: dw 0xf0              ; Type of disk/Media descriptor
  41. bpb_spt: dw 18               ; Sectors per track
  42. bpb_hc: dw 2                 ; head count
  43. bpb_hsc: dw 0                ; hidden sector count
  44. bpb_lsc: dw 0                ; Large sector count
  45.  
  46. drive_num: dw 0              ; Drive number, floppy 0
  47. db 0                         ; reserved
  48. signature: db  0x29
  49. volume_id:
  50.     db 0x0,0x0,0x0,0x0       ; volume id - irrelevant to functionality
  51. volume_label:
  52.      db ' BRYO BOOT '        ; space padded 11 bytes
  53. sysID: db 'FAT12   '         ; space padded 8 bytes
  54.  
  55. ;----------------------------[MAIN]------------------------------
  56. main:
  57.     ; Segmentation registers setup
  58.     xor ax,ax
  59.     mov ds,ax
  60.     mov es,ax
  61.     mov ss,ax
  62.  
  63.     ; Printing Initial Boot message
  64.     mov si,initial_boot_msg
  65.     call print
  66.  
  67.     ; Attempt to load bl2
  68.     call bl2_loader
  69.  
  70.     jmp $
  71.  
  72.  
  73. ;----------------------------[FUNCTIONS]--------------------------
  74.  
  75. print:
  76.     .loop:
  77.         lodsb
  78.         or al,al
  79.         jz .break
  80.         mov ah,0x0e
  81.         int 0x10
  82.         jmp .loop
  83.  
  84.     .break:
  85.         ret
  86.  
  87. bl2_loader:
  88.     mov al,0x02               ; BIOS Read function
  89.     mov al,BL2_sec_count      ;  How many Sectors to read
  90.    
  91.     ; CHS address
  92.     mov ch,BL2_c
  93.     mov dh,BL2_h
  94.     mov cl,BL2_s
  95.  
  96.     mov bx,BL2_ADDR/16        ; Loading second stage address
  97.     mov es,bx                 ; Pointing to extra segment from disk with es
  98.     xor bx,bx
  99.     int 0x13
  100.  
  101.     jc .drive_read_err
  102.     jmp BL2_ADDR/16 : 0       ; Jumping to second loader
  103.    
  104.     .drive_read_err:
  105.         mov si, drive_error_msg
  106.         call print
  107.         jmp $
  108.  
  109.  
  110.  
  111. ;-----------------------------[MESSAGES]--------------------------
  112. initial_boot_msg:
  113.      db '[BL1] BRYOBOOT loaded sucessfully',CR,LF,0
  114. drive_error_msg:
  115.      db '[BL1] DISK READING ERROR - Couldnt Load BL2',CR,LF,0
  116.  
  117. ;-----------------------------[FOOTER]----------------------------
  118. times 510-($-$$) db 0        ; Padding to 512 bytes
  119. dw 0xaa55                    ; Magic Number for BIOS identification
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement