Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

217 linhas
5.9 KiB

há 6 anos
há 5 anos
há 5 anos
há 5 anos
há 5 anos
há 5 anos
há 5 anos
há 5 anos
há 6 anos
há 6 anos
há 6 anos
há 6 anos
há 6 anos
  1. ORG 0x7C00
  2. BITS 16
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4. ; Bootloader for SingOS
  5. ; version 0.1.0.10-exp
  6. ;
  7. ; Please edit the version number if any changes is made, the last number
  8. ; represent the build number.
  9. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10. cli
  11. jmp long 0x0000:start
  12. start:
  13. xor ax, ax
  14. mov ds, ax
  15. mov es, ax
  16. mov ss, ax
  17. mov [disk_identifier], dl
  18. ; initialize stack
  19. ; Set up 4K stack after this bootloader
  20. ; [Remember: Effective Address = Segment*16 + Offset]
  21. mov ax, 0x7C0 ; Set 'ax' equal to the location of this bootloader divided by 16
  22. add ax, 0x20 ; Skip over the size of the bootloader divided by 16
  23. mov ss, ax ; Set 'ss' to this location (the beginning of our stack region)
  24. mov sp, 8192 ; Set 'ss:sp' to the top of our 8K stack
  25. sti
  26. mov si, message ; Put address of the null-terminated string to output into 'si'
  27. call print ; Call our string-printing routine
  28. mov si, enter_debug_mode
  29. call print
  30. call printCRLF
  31. %IF 0
  32. ; here goes wait call, for the user to enter debug mode.
  33. ; Wating for 2 seconds:
  34. mov ah, 0x86 ; code for waiting interupt call
  35. mov cx, 0x001e ; high count of microseconds
  36. mov dx, 0x8480 ; low count
  37. int 0x15
  38. .busy_wait_for_key:
  39. xor ax, ax
  40. mov ah, 0x01 ; BIOS call to wait for key
  41. int 0x16
  42. jnz debug_mode
  43. %ENDIF
  44. ; entering system check:
  45. mov si, enter_system_check
  46. mov si, sys_check_ok ; Put address of the null-terminated string to output into 'si'
  47. call print ; Call our string-printing routine
  48. mov si, boot_system ; Put address of the null-terminated string to output into 'si'
  49. call print ; Call our string-printing routine
  50. ;This goes first as to now overwrite %ah and %al.
  51. mov ax, 0x0050
  52. mov es, ax ;Section to write into
  53. mov ah, 0x2 ;Read sectors from drive
  54. mov al, 0x08 ;Number of sectors to read (31 * 512 = 15872 bytes)
  55. mov ch, 0x0 ;Low 8 bits of cylinder
  56. mov cl, 0x11 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
  57. mov dh, 0x0 ;Head number
  58. mov dl, [disk_identifier] ;Drive number
  59. mov bx, 0x0000 ;Offset into section
  60. int 0x13 ;Low level disk services
  61. jnc notcarry
  62. mov si, error_str
  63. call print
  64. jmp endcarrycheck
  65. notcarry:
  66. mov si, success_str
  67. call print
  68. call printCRLF
  69. ;call printCRLF
  70. ;mov ax, cs
  71. ;call dumpax
  72. ;mov ax, start
  73. ;call dumpax
  74. ;call printCRLF
  75. mov dl, [disk_identifier]
  76. xor ax, ax
  77. mov al, dl
  78. call dumpax
  79. call printCRLF
  80. mov ax, 0x50
  81. mov ds, ax
  82. mov ax, 89 ; lba adress
  83. jmp 0x50:0x0000 ; Jump to the kernel
  84. endcarrycheck:
  85. cli ; Clear the Interrupt Flag (disable external interrupts)
  86. hlt ; Halt the CPU (until the next external interrupt)
  87. debug_mode:
  88. mov si, .welcome_debug
  89. call print
  90. cli ; Clear the Interrupt Flag (disable external interrupts)
  91. hlt
  92. .welcome_debug db 'This is debug mode', 0
  93. ;Routine for printing a 'ax' as hex
  94. dumpax:
  95. pusha ; save registers
  96. mov bx, ax
  97. mov ah, 0xE ; Teletype output
  98. mov cx, 4 ; 4 nipples in a 16 bit word
  99. .loop:
  100. rol bx, 4 ; rotate to next nipple
  101. mov al, bl ; we copy to al because we need to mask only the low 4 bits
  102. and al, 1111b ; Do the masking
  103. add al, '0' ; convert to ASCII
  104. cmp al, '9' ; If we are greater than 9 ascii, we add 7 to make digit 10 be represented as 'A'
  105. jbe .skip ; -|-
  106. add al, 7 ; -|-
  107. .skip: ; -|-
  108. int 0x10 ; BIOS call 'output'
  109. loop .loop
  110. popa ; restore registers
  111. ret
  112. printCRLF:
  113. mov ah, 0xE
  114. mov al, 13
  115. int 0x10
  116. mov al, 10
  117. int 0x10
  118. ret
  119. ; Routine for outputting string in 'si' register to screen
  120. print:
  121. mov ah, 0xE ; Specify 'int 0x10' 'teletype output' function
  122. ; [AL = Character, BH = Page Number, BL = Colour (in graphics mode)]
  123. .printchar:
  124. lodsb ; Load byte at address SI into AL, and increment SI
  125. cmp al, 0
  126. je .done ; If the character is zero (NUL), stop writing the string
  127. int 0x10 ; Otherwise, print the character via 'int 0x10'
  128. jmp .printchar ; Repeat for the next character
  129. .done:
  130. ret
  131. data:
  132. message db 'Bootloader for SingOS! v0.1.0.10-exp',13,10,0
  133. enter_debug_mode db 'Press d to enter bootloader debug mode',13,10,0
  134. enter_system_check db 'Performing system check:',13,10,0
  135. sys_check_ok db 'System check ok', 13, 10, 0
  136. boot_system db 'Read SingOS from disk', 13, 10, 0
  137. error_str db 'Error', 0
  138. success_str db 'Success', 0
  139. disk_identifier db 0
  140. ; Pad to 510 bytes (boot sector size minus 2) with 0s, and finish with the two-byte standard boot signature
  141. times 446-($-$$) db 0 ; First partion entry
  142. db 0x80 ; active partition
  143. db 0, 0x00, 0x17 ; First sector CHS
  144. db 0x18 ; Disk type (Other) (Why 18, answer ':' ^ ')' )
  145. db 0xff, 0xff, 0xff ; Ending CHS values
  146. db 0x18, 0, 0, 0x00 ; Staring LBA
  147. db 0, 0xff, 0xff, 0xff ; Size
  148. db 0x00
  149. db 0x0, 0x0, 0x0
  150. db 0x0
  151. db 0x0, 0x0, 0x0
  152. db 0x00, 0x00, 0x00, 0x00
  153. db 0x0, 0x00, 0x00, 0x00
  154. times 478-($-$$) db 0 ; Third partion entry
  155. times 494-($-$$) db 0 ; Forth partion entry
  156. times 510-($-$$) db 0
  157. dw 0xAA55 ; => 0x55 0xAA (little endian byte order)
  158. ; bootloder debug_mode goes here
  159. times 8192-($-$$) db 0
  160. ; From Version 0.0.3 we are concatinate the bootloader and the kernel after compile time
  161. ;%include "kernel.nasm"
  162. ;times 8192-($-$$) db 0
  163. ;80
  164. ;00 01 00
  165. ;00
  166. ;3F 60 21
  167. ;00 00 00 00
  168. ;00 10 09 00
  169. ;00
  170. ;FE FF FF
  171. ;EF
  172. ;FE FF FF
  173. ;B0 0E 00 00
  174. ;40 03 00 00
  175. ;00
  176. ;00 00 00
  177. ;00
  178. ;00 00 00
  179. ;00 00 00 00
  180. ;00 00 00 00
  181. ;00
  182. ;00
  183. ;00 00 00 00
  184. ;00 00 00 00
  185. ;00 00 00