You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

237 line
5.9 KiB

5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
  1. ORG 0x600
  2. BITS 16
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4. ; SLRboot
  5. ; Bootloader for SingOS
  6. ; version 0.3.0.0
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. cli
  9. ;jmp long 0x0000:start
  10. mov ax, 0x1000
  11. mov ss, ax
  12. mov sp, 0xb000
  13. push dx
  14. mov ax, 0x0
  15. mov ds, ax ; ds is used by si
  16. mov es, ax ; es is used by di
  17. sti
  18. mov si, 0x7c00
  19. mov di, 0x600
  20. mov cx, 0x100
  21. rep movsw
  22. jmp 0x0000:relocated
  23. relocated:
  24. mov ax, 0x0
  25. mov ds, ax
  26. mov es, ax
  27. pop dx
  28. mov [disk_identifier], dl
  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 bx, 1
  75. mov ax, partition_1
  76. .loop:
  77. cmp bx, 1
  78. je break
  79. add ax, 0x10
  80. dec bx
  81. jmp .loop
  82. break:
  83. add ax, 8 ; This is the offset to fetch the LBA start adress of the partition record
  84. mov bx, ax
  85. xor ax, ax
  86. mov ax, [bx] ; first part of LBA
  87. mov WORD [DAPACK.lba_addr_dw_low], ax
  88. ;call dumpax
  89. add bx, 2 ; next part
  90. mov ax, [bx]
  91. mov WORD [DAPACK.lba_addr_dw_low + 2], ax
  92. ;call dumpax
  93. ;mov WORD [DAPACK.lba_addr_dw_low], 2048
  94. mov WORD [DAPACK.blkcnt], 0x01
  95. mov WORD [DAPACK.db_addr_offset], 0x7c00
  96. mov WORD [DAPACK.db_addr_segment], 0x0000
  97. mov si, DAPACK ; address of "disk address packet"
  98. xor ax, ax
  99. mov ah, 0x42 ; READ
  100. mov dl, [disk_identifier]
  101. int 0x13
  102. jc endcarrycheck ; An error ocurred when reading from disk.
  103. ; If no error then jump to volume boot record
  104. notcarry:
  105. mov dl, [disk_identifier]
  106. jmp long 0x0:0x7c00
  107. cli
  108. hlt
  109. ; If we did not suceed to read from disk
  110. endcarrycheck:
  111. mov si, error_str
  112. call print
  113. cli ; Clear the Interrupt Flag (disable external interrupts)
  114. hlt ; Halt the CPU (until the next external interrupt)
  115. debug_mode:
  116. mov si, welcome_debug
  117. call print
  118. cli ; Clear the Interrupt Flag (disable external interrupts)
  119. hlt
  120. ;Routine for printing a 'ax' as hex
  121. dumpax:
  122. pusha ; save registers
  123. mov bx, ax
  124. mov ah, 0xE ; Teletype output
  125. mov cx, 4 ; 4 nipples in a 16 bit word
  126. .loop:
  127. rol bx, 4 ; rotate to next nipple
  128. mov al, bl ; we copy to al because we need to mask only the low 4 bits
  129. and al, 1111b ; Do the masking
  130. add al, '0' ; convert to ASCII
  131. cmp al, '9' ; If we are greater than 9 ascii, we add 7 to make digit 10 be represented as 'A'
  132. jbe .skip ; -|-
  133. add al, 7 ; -|-
  134. .skip: ; -|-
  135. int 0x10 ; BIOS call 'output'
  136. loop .loop
  137. popa ; restore registers
  138. ret
  139. printCRLF:
  140. mov ah, 0xE
  141. mov al, 13
  142. int 0x10
  143. mov al, 10
  144. int 0x10
  145. ret
  146. ; Routine for outputting string in 'si' register to screen
  147. print:
  148. mov ah, 0xE ; Specify 'int 0x10' 'teletype output' function
  149. ; [AL = Character, BH = Page Number, BL = Colour (in graphics mode)]
  150. .printchar:
  151. lodsb ; Load byte at address SI into AL, and increment SI
  152. cmp al, 0
  153. je .done ; If the character is zero (NUL), stop writing the string
  154. int 0x10 ; Otherwise, print the character via 'int 0x10'
  155. jmp .printchar ; Repeat for the next character
  156. .done:
  157. ret
  158. data:
  159. message db 'SLRboot for SingOS! v0.3.0.0',13,10,0
  160. enter_debug_mode db 'Press d to enter bootloader debug mode',13,10,0
  161. welcome_debug db 'Debug mode v.0.0.1:',13,10,0
  162. error_str db 'Error', 0
  163. boot_this_partition: dw 0
  164. disk_identifier db 0
  165. DAPACK:
  166. .dap_Size: db 0x10 ; This is always 16 bytes (0x10)
  167. .rev_byte: db 0x0 ; reserved byte, should always be zero
  168. .blkcnt: dw 0x0 ; int 13 resets this to # of blocks actually read/written
  169. .db_addr_offset: dw 0x0 ; memory buffer destination address (0:7c00)
  170. .db_addr_segment: dw 0x0 ; in memory page zero
  171. .lba_addr_dw_low: dd 0x0 ; put the lba to read in this spot
  172. .lba_addr_dw_high: dd 0x0 ; more storage bytes only for big lba's ( > 4 bytes )
  173. ; Pad to 510 bytes (boot sector size minus 2) with 0s, and finish with the two-byte standard boot signature
  174. times 446-($-$$) db 0 ; First partion entry
  175. partition_1:
  176. .active_partition db 0x80
  177. .start_CHS db 0x00, 0x00, 0x11;0x20, 0x21, 0x00
  178. .disk_type db 0x83
  179. .end_CHS db 0x8C, 0x3D, 0x0F
  180. .start_LBA db 0x10, 0x00, 0x00, 0x00
  181. .size db 0x00, 0xC8, 0x03, 0x00
  182. ; sector number for 2.nd SingOS -> 16480
  183. partition_2:
  184. .active_partition db 0x80
  185. .start_CHS db 0x8C, 0x3E, 0x0F
  186. .disk_type db 0x83
  187. .end_CHS db 0xFF, 0xFF, 0xFF
  188. .start_LBA db 0x61, 0x40, 0x00, 0x00 ;0x00, 0xD0, 0x03, 0x00
  189. .size db 0x00, 0x28, 0x1C, 0x03
  190. partition_3:
  191. .active_partition db 0x00
  192. .start_CHS db 0x00, 0x00, 0x00
  193. .disk_type db 0x00
  194. .end_CHS db 0x00, 0x00, 0x00
  195. .start_LBA db 0x00, 0x00, 0x00, 0x00
  196. .size db 0x00, 0x00, 0x00, 0x00
  197. partition_4:
  198. .active_partition db 0x00
  199. .start_CHS db 0x00, 0x00, 0x00
  200. .disk_type db 0x00
  201. .end_CHS db 0x00, 0x00, 0x00
  202. .start_LBA db 0x00, 0x00, 0x00, 0x00
  203. .size db 0x00, 0x00, 0x00, 0x00
  204. times 510-($-$$) db 0
  205. dw 0xAA55 ; => 0x55 0xAA (little endian byte order)
  206. ; bootloder debug_mode goes here
  207. times 8192-($-$$) db 0