Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

233 righe
5.8 KiB

5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
5 anni fa
  1. ORG 0x7C00
  2. BITS 16
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4. ; SLRboot
  5. ; Bootloader for SingOS
  6. ; version 0.2.1.0-exp
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. cli
  9. jmp long 0x0000:start
  10. start:
  11. mov ax, 0x1000
  12. mov ss, ax
  13. mov sp, 0xb000
  14. mov ax, 0
  15. mov ds, ax
  16. mov es, ax
  17. mov [disk_identifier], dl
  18. sti
  19. mov si, 0x7c00
  20. mov di, 0x600
  21. mov cx, 0x100
  22. rep movsw
  23. mov bx, relocated
  24. sub bx, 0x7600 ; Calculate the offset.
  25. push bx
  26. ret ; Return far
  27. ;jmp long 0:bx
  28. relocated:
  29. mov si, message ; Put address of the null-terminated string to output into 'si'
  30. call print ; Call our string-printing routine
  31. ; Check for more than one active partition that we can start from.
  32. xor bx, bx
  33. xor cx, cx
  34. mov ax, [partition_1.active_partition]
  35. cmp al, 0x80
  36. jne check_p_2
  37. mov bx, 0x01 ; Partion 1 active
  38. inc cx
  39. check_p_2:
  40. mov ax, [partition_2.active_partition]
  41. cmp al, 0x80
  42. jne check_p_3
  43. inc cx
  44. mov bx, 0x02 ; Partion 2 active
  45. check_p_3:
  46. mov ax, [partition_3.active_partition]
  47. cmp al, 0x80
  48. jne check_p_4
  49. inc cx
  50. mov bx, 0x03 ; Partion 3 active
  51. check_p_4:
  52. mov al, [partition_4.active_partition]
  53. cmp ax, 0x80
  54. jne eval_active_partion_number
  55. inc cx
  56. mov bx, 0x04 ; Partion 4 active
  57. cli
  58. hlt
  59. eval_active_partion_number:
  60. cmp cx, 1
  61. je boot_partition
  62. ; here goes wait call, for the user to enter debug mode.
  63. ; Wating for 2 seconds:
  64. mov ah, 0x86 ; code for waiting interupt call
  65. mov cx, 0x001e ; high count of microseconds
  66. mov dx, 0x8480 ; low count
  67. int 0x15
  68. .busy_wait_for_key:
  69. xor ax, ax
  70. mov ah, 0x01 ; BIOS call to wait for key
  71. int 0x16
  72. boot_partition:
  73. ; IMPORTANT bx, has to hold the value 1-4 for the partiotion that wanted to be booted.
  74. mov ax, partition_1
  75. .loop:
  76. cmp bx, 1
  77. je break
  78. add ax, 0x10
  79. dec bx
  80. jmp .loop
  81. break:
  82. add ax, 8 ; This is the offset to fetch the LBA start adress of the partition record
  83. mov bx, ax
  84. xor ax, ax
  85. mov ax, [bx] ; first part of LBA
  86. mov WORD [DAPACK.lba_addr_dw_low], ax
  87. call dumpax
  88. add bx, 2 ; next part
  89. mov ax, [bx]
  90. mov WORD [DAPACK.lba_addr_dw_low + 1], ax
  91. call dumpax
  92. mov WORD [DAPACK.blkcnt], 0x01
  93. mov WORD [DAPACK.db_addr_segment], 0x0000
  94. mov WORD [DAPACK.db_addr_offset], 0x7c00
  95. mov si, DAPACK ; address of "disk address packet"
  96. xor ax, ax
  97. mov ah, 0x42 ; READ
  98. mov dl, [disk_identifier]
  99. int 0x13
  100. jc endcarrycheck ; An error ocurred when reading from disk.
  101. ; If no error then jump to volume boot record
  102. notcarry:
  103. jmp long 0x0:0x7c00
  104. cli
  105. hlt
  106. ; If we did not suceed to read from disk
  107. endcarrycheck:
  108. mov si, error_str
  109. call print
  110. cli ; Clear the Interrupt Flag (disable external interrupts)
  111. hlt ; Halt the CPU (until the next external interrupt)
  112. debug_mode:
  113. mov si, welcome_debug
  114. call print
  115. cli ; Clear the Interrupt Flag (disable external interrupts)
  116. hlt
  117. ;Routine for printing a 'ax' as hex
  118. dumpax:
  119. pusha ; save registers
  120. mov bx, ax
  121. mov ah, 0xE ; Teletype output
  122. mov cx, 4 ; 4 nipples in a 16 bit word
  123. .loop:
  124. rol bx, 4 ; rotate to next nipple
  125. mov al, bl ; we copy to al because we need to mask only the low 4 bits
  126. and al, 1111b ; Do the masking
  127. add al, '0' ; convert to ASCII
  128. cmp al, '9' ; If we are greater than 9 ascii, we add 7 to make digit 10 be represented as 'A'
  129. jbe .skip ; -|-
  130. add al, 7 ; -|-
  131. .skip: ; -|-
  132. int 0x10 ; BIOS call 'output'
  133. loop .loop
  134. popa ; restore registers
  135. ret
  136. printCRLF:
  137. mov ah, 0xE
  138. mov al, 13
  139. int 0x10
  140. mov al, 10
  141. int 0x10
  142. ret
  143. ; Routine for outputting string in 'si' register to screen
  144. print:
  145. mov ah, 0xE ; Specify 'int 0x10' 'teletype output' function
  146. ; [AL = Character, BH = Page Number, BL = Colour (in graphics mode)]
  147. .printchar:
  148. lodsb ; Load byte at address SI into AL, and increment SI
  149. cmp al, 0
  150. je .done ; If the character is zero (NUL), stop writing the string
  151. int 0x10 ; Otherwise, print the character via 'int 0x10'
  152. jmp .printchar ; Repeat for the next character
  153. .done:
  154. ret
  155. data:
  156. message db 'SLRboot for SingOS! v0.2.1.0-exp',13,10,0
  157. enter_debug_mode db 'Press d to enter bootloader debug mode',13,10,0
  158. welcome_debug db 'Debug mode v.0.0.1:',13,10,0
  159. error_str db 'Error', 0
  160. boot_this_partition: dw 0
  161. disk_identifier db 0
  162. DAPACK:
  163. .dap_Size: db 0x10 ; This is always 16 bytes (0x10)
  164. .rev_byte: db 0x0 ; reserved byte, should always be zero
  165. .blkcnt: dw 0x0 ; int 13 resets this to # of blocks actually read/written
  166. .db_addr_offset: dw 0x0 ; memory buffer destination address (0:7c00)
  167. .db_addr_segment: dw 0x0 ; in memory page zero
  168. .lba_addr_dw_low: dd 0x0 ; put the lba to read in this spot
  169. .lba_addr_dw_high: dd 0x0 ; more storage bytes only for big lba's ( > 4 bytes )
  170. ; Pad to 510 bytes (boot sector size minus 2) with 0s, and finish with the two-byte standard boot signature
  171. times 446-($-$$) db 0 ; First partion entry
  172. partition_1:
  173. .active_partition db 0x80
  174. .start_CHS db 0x00, 0x00, 0x11;0x20, 0x21, 0x00
  175. .disk_type db 0x83
  176. .end_CHS db 0x8C, 0x3D, 0x0F
  177. .start_LBA db 0x10, 0x00, 0x00, 0x00
  178. .size db 0x00, 0xC8, 0x03, 0x00
  179. partition_2:
  180. .active_partition db 0x00
  181. .start_CHS db 0x8C, 0x3E, 0x0F
  182. .disk_type db 0x83
  183. .end_CHS db 0xFF, 0xFF, 0xFF
  184. .start_LBA db 0x00, 0xD0, 0x03, 0x00
  185. .size db 0x00, 0x28, 0x1C, 0x03
  186. partition_3:
  187. .active_partition db 0x00
  188. .start_CHS db 0x00, 0x00, 0x00
  189. .disk_type db 0x00
  190. .end_CHS db 0x00, 0x00, 0x00
  191. .start_LBA db 0x00, 0x00, 0x00, 0x00
  192. .size db 0x00, 0x00, 0x00, 0x00
  193. partition_4:
  194. .active_partition db 0x00
  195. .start_CHS db 0x00, 0x00, 0x00
  196. .disk_type db 0x00
  197. .end_CHS db 0x00, 0x00, 0x00
  198. .start_LBA db 0x00, 0x00, 0x00, 0x00
  199. .size db 0x00, 0x00, 0x00, 0x00
  200. times 510-($-$$) db 0
  201. dw 0xAA55 ; => 0x55 0xAA (little endian byte order)
  202. ; bootloder debug_mode goes here
  203. times 8192-($-$$) db 0