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.

230 lines
7.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. ORG 0x7c00
  2. BITS 16
  3. %define DISK_SERVICE 0x0050:0x0000
  4. %define KERNEL 0x2500:0x0000 ;0x0050:0x0512
  5. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6. ; Volume Boot Record
  7. ; This will start SingOS from the disk
  8. ; The disk format has to be LessSimpleFileSystem
  9. ; Loading /kernel/kernel.bin which should contain the kernel for the system
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11. ; Ensure that the data segment and extra segment is set to 0x00
  12. mov ax, 0x00
  13. mov ds, ax
  14. mov es, ax
  15. ; Setup stack
  16. mov ax, 0x8fc0
  17. mov ss, ax ; Set 'ss' to this location (the beginning of our stack region)
  18. mov sp, 0xffff ; Set 'ss:sp' to the top of our 8K stack
  19. mov bp, sp
  20. mov [global_disk_identifier], dl ; saving disk_identifier, this is the number the disk that we are booting from.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ; The system has to support int13 bios extended system calls, otherwise is SingOS not supporting the hardware.
  23. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  24. mov ah, 0x41 ;Set AH = 0x41
  25. mov bx, 0x55aa ;BX = 0x55AA
  26. mov dl, [global_disk_identifier] ;DL = disk_id
  27. int 0x13 ;Issue an INT 0x13.
  28. jnc ext_disk_supported
  29. ; The System does support exented read write
  30. mov si, vbr_lsfs_disk_error_msg
  31. call 0x00:tmp_print
  32. cli
  33. hlt
  34. ;Routine for printing a 'ax' as hex
  35. ;tmp_dumpax:
  36. ;pusha ; save registers
  37. ;mov bx, ax
  38. ;mov ah, 0xE ; Teletype output
  39. ;mov cx, 4 ; 4 nipples in a 16 bit word
  40. ;.loop:
  41. ;rol bx, 4 ; rotate to next nipple
  42. ;mov al, bl ; we copy to al because we need to mask only the low 4 bits
  43. ;and al, 1111b ; Do the masking
  44. ;add al, '0' ; convert to ASCII
  45. ;cmp al, '9' ; If we are greater than 9 ascii, we add 7 to make digit 10 be represented as 'A'
  46. ;jbe .skip ; -|-
  47. ;add al, 7 ; -|-
  48. ;.skip: ; -|-
  49. ;int 0x10 ; BIOS call 'output'
  50. ;loop .loop
  51. ;popa ; restore registers
  52. ;retf
  53. tmp_print:
  54. ; Prints string in si
  55. ; IN si: zero terminated string to print
  56. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  57. ;mov ax, 0x7e55
  58. ;mov ax, si
  59. ;call 0x00:tmp_dumpax
  60. mov ah, 0xE ; Specify 'int 0x10' 'teletype output' function
  61. ; [AL = Character, BH = Page Number, BL = Colour (in graphics mode)]
  62. .printchar:
  63. lodsb ; Load byte at address SI into AL, and increment SI
  64. test al, al
  65. jz .done ; If the character is zero (NUL), stop writing the string
  66. int 0x10 ; Otherwise, print the character via 'int 0x10'
  67. jmp .printchar ; Repeat for the next character
  68. .done:
  69. retf
  70. ; loading essentials for SingOS to run
  71. ; starting by loading the rest of the VBR:
  72. ext_disk_supported:
  73. mov si, vbr_message
  74. call 0x00:tmp_print
  75. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  76. ; The system is suportted
  77. ; We are now loading the kernel "/kernel/kernel.bin"
  78. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  79. ; INPUT
  80. ; ax = sector index for the FSCI that has to be loaded.
  81. ; bx = segment
  82. ;mov ax, [vbr_LBA_FSCI]
  83. ;mov bx, 0x00
  84. ;call lsfs_load_fsci_info;
  85. ;INPUT
  86. ; ax = filename
  87. ; bx = pointer to buffer
  88. ; cx = buffer_size
  89. ; dx = offset in file
  90. ; es = segment to read in data
  91. ;call lsfs_read_file
  92. ; RETURN
  93. ; ax preserved
  94. ; bx preserved
  95. ; cx preserved
  96. ; dx data read
  97. ; es = remember to restore es if this has to be saved.
  98. mov ax, [vbr_LBA_address]
  99. inc ax
  100. mov dl, [global_disk_identifier]
  101. mov WORD [DAPACK.lba_addr_dw_low], ax
  102. mov WORD [DAPACK.blkcnt], 0x10
  103. mov WORD [DAPACK.db_addr_segment], 0x7e0
  104. mov WORD [DAPACK.db_addr_offset], 0x00
  105. mov si, DAPACK ; address of "disk address packet"
  106. mov ah, 0x42 ; READ
  107. mov dl, [global_disk_identifier]
  108. int 0x13
  109. mov cx, [vbr_LBA_FSCI]
  110. mov bx, ds
  111. mov ax, 0x1
  112. push cx
  113. push bx
  114. push ax
  115. mov cx, 0x7e0
  116. mov ds, cx
  117. mov es, cx
  118. call 0x7e0:0x00
  119. add sp, 0x6 ; skip the paramerts
  120. mov cx, 0x0
  121. mov ds, cx
  122. mov es, cx
  123. ; Set the Parameter_Struct
  124. mov ax, lsfs_path
  125. mov [Parameter_Struct.path], ax
  126. mov WORD [Parameter_Struct.buffer_segment], 0x50
  127. mov WORD [Parameter_Struct.buffer_address], 0x00
  128. mov WORD [Parameter_Struct.buffer_size], 0xFFFF
  129. mov WORD [Parameter_Struct.byte_offset_into_file], 0x00
  130. mov cx, Parameter_Struct
  131. mov bx, ds
  132. mov ax, 0x2
  133. push cx
  134. push bx
  135. push ax
  136. mov cx, 0x7e0
  137. mov ds, cx
  138. mov es, cx
  139. call 0x7e0:0x00
  140. add sp, 0x6 ; skip the paramerts
  141. mov cx, 0x0
  142. mov ds, cx
  143. mov es, cx
  144. ; Set the Parameter_Struct
  145. mov ax, kernel_path
  146. mov [Parameter_Struct.path], ax
  147. mov WORD [Parameter_Struct.buffer_segment], 0x2500
  148. mov WORD [Parameter_Struct.buffer_address], 0x00
  149. mov WORD [Parameter_Struct.buffer_size], 0xFFFF
  150. mov WORD [Parameter_Struct.byte_offset_into_file], 0x00
  151. mov cx, Parameter_Struct
  152. mov bx, ds
  153. mov ax, 0x2
  154. push cx
  155. push bx
  156. push ax
  157. mov cx, 0x7e0
  158. mov ds, cx
  159. mov es, cx
  160. call 0x7e0:0x00
  161. add sp, 0x6 ; skip the paramerts
  162. mov cx, 0x0
  163. mov ds, cx
  164. mov es, cx
  165. ; ready to jump to the kernel
  166. mov bx, [vbr_LBA_FSCI]
  167. mov dl, [global_disk_identifier]
  168. jmp KERNEL
  169. nop
  170. cli
  171. hlt
  172. DAPACK:
  173. .dap_Size: db 0x10 ; This is always 16 bytes (0x10)
  174. .rev_byte: db 0x0 ; reserved byte, should always be zero
  175. .blkcnt: dw 0x0 ; int 13 resets this to # of blocks actually read/written
  176. .db_addr_offset: dw 0x0 ; memory buffer destination address (0:7c00)
  177. .db_addr_segment: dw 0x0 ; in memory page zero
  178. .lba_addr_dw_low: dd 0x0 ; put the lba to read in this spot
  179. .lba_addr_dw_high: dd 0x0 ; more storage bytes only for big lba's ( > 4 bytes )
  180. Parameter_Struct:
  181. .path dw 0x00 ; char*
  182. .new_path dw 0x00 ; char*
  183. .buffer_segment dw 0x00 ; int
  184. .buffer_address dw 0x00 ; int
  185. .buffer_size dw 0x00 ; int
  186. .data_length dw 0x00 ; int
  187. .byte_offset_into_file dw 0x00 ; int
  188. .entry_kind dw 0x00 ; Table_Entry_Kind
  189. global_disk_identifier db 0
  190. vbr_message db 'VBR: Less Simple File System', 13, 10, 'Loading system', 13, 10, 0
  191. vbr_lsfs_disk_error_msg db 'The system does not support disk operations', 0
  192. lsfs_path db '/kernel/utils/lsfs.bin', 0
  193. kernel_path db '/kernel/kernel.bin', 0
  194. times 446-($-$$) db 0
  195. vbr_size_in_bytes dw 0x00, 0x00, 0x00, 0x00 ; size of the VBR in secotrs (Such that we can load the rest of the VBR)
  196. vbr_LBA_address dw 0x00, 0x00, 0x00, 0x00 ; Abselout LBA adress of this VBR, such that we know where to find the FSCI (offset 1MB)
  197. vbr_LBA_FSCI dw 0x00, 0x00, 0x00, 0x00
  198. times 510-($-$$) db 0
  199. dw 0x1818; Signature, homemade, sshould it be 0xAA55?
  200. ; rest of VBR, which has to be loaded in the first part of the VBR
  201. ;%include "filesystems/lsfs/lsfs.nasm"
  202. incbin "../lsfs_16-bit/disk.out"
  203. ; By specification the max size can be 1MB of the compiled file.