Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

235 wiersze
5.9 KiB

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